Fix race+logging issue in SystemStateHelper

SystemStateHelper wasn't locking when entering the onProjectionChanged
logic. This occasionally causes a race condition that takes out the
system server during CTS.

Bug: 181057509
Test: atest CtsTelecomTestCases
Change-Id: I1460f0a048ed0bee553944f99ee4d406c1a257ae
diff --git a/src/com/android/server/telecom/SystemStateHelper.java b/src/com/android/server/telecom/SystemStateHelper.java
index 8fb6bc5..e813f58 100644
--- a/src/com/android/server/telecom/SystemStateHelper.java
+++ b/src/com/android/server/telecom/SystemStateHelper.java
@@ -75,7 +75,7 @@
     private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            Log.startSession("SSP.oR");
+            Log.startSession("SSH.oR");
             try {
                 String action = intent.getAction();
                 if (UiModeManager.ACTION_ENTER_CAR_MODE_PRIORITIZED.equals(action)) {
@@ -116,11 +116,19 @@
     @Override
     public void onProjectionStateChanged(int activeProjectionTypes,
             @NonNull Set<String> projectingPackages) {
-        if (projectingPackages.isEmpty()) {
-            onReleaseAutomotiveProjection();
-        } else {
-            onSetAutomotiveProjection(projectingPackages.iterator().next());
+        Log.startSession("SSH.oPSC");
+        try {
+            synchronized (mLock) {
+                if (projectingPackages.isEmpty()) {
+                    onReleaseAutomotiveProjection();
+                } else {
+                    onSetAutomotiveProjection(projectingPackages.iterator().next());
+                }
+            }
+        } finally {
+            Log.endSession();
         }
+
     }
 
     private Set<SystemStateListener> mListeners = new CopyOnWriteArraySet<>();