Merge "Fix race+logging issue in SystemStateHelper" into sc-dev
diff --git a/res/values-sw/strings.xml b/res/values-sw/strings.xml
index 8b8a40c..d1142f7 100644
--- a/res/values-sw/strings.xml
+++ b/res/values-sw/strings.xml
@@ -43,7 +43,7 @@
<string name="respond_via_sms_setting_title_2" msgid="4914853536609553457">"Hariri majibu ya haraka"</string>
<string name="respond_via_sms_setting_summary" msgid="8054571501085436868"></string>
<string name="respond_via_sms_edittext_dialog_title" msgid="6579353156073272157">"Majibu ya haraka"</string>
- <string name="respond_via_sms_confirmation_format" msgid="2932395476561267842">"Ujumbe uliotumwa kwa <xliff:g id="PHONE_NUMBER">%s</xliff:g> ."</string>
+ <string name="respond_via_sms_confirmation_format" msgid="2932395476561267842">"Ujumbe umetumwa kwa <xliff:g id="PHONE_NUMBER">%s</xliff:g>."</string>
<string name="respond_via_sms_failure_format" msgid="5198680980054596391">"Imeshindwa kutuma SMS kwa <xliff:g id="PHONE_NUMBER">%s</xliff:g>."</string>
<string name="enable_account_preference_title" msgid="6949224486748457976">"Akaunti za simu"</string>
<string name="outgoing_call_not_allowed_user_restriction" msgid="3424338207838851646">"Piga simu za dharura pekee."</string>
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 710c83b..fb3ff42 100755
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -3139,7 +3139,11 @@
Log.i(this, "Auto-unholding held foreground call (call doesn't support hold)");
foregroundCall.unhold();
}
- }, new LoggedHandlerExecutor(mHandler, "CM.mCAR", mLock));
+ }, new LoggedHandlerExecutor(mHandler, "CM.mCAR", mLock))
+ .exceptionally((throwable) -> {
+ Log.e(TAG, throwable, "Error while executing call removal");
+ return null;
+ });
}
/**
diff --git a/src/com/android/server/telecom/InCallController.java b/src/com/android/server/telecom/InCallController.java
index 8411512..08a64ca 100644
--- a/src/com/android/server/telecom/InCallController.java
+++ b/src/com/android/server/telecom/InCallController.java
@@ -1383,7 +1383,7 @@
/**
* Unbinds an existing bound connection to the in-call app.
*/
- private void unbindFromServices() {
+ public void unbindFromServices() {
try {
mContext.unregisterReceiver(mPackageChangedReceiver);
} catch (IllegalArgumentException e) {
diff --git a/src/com/android/server/telecom/SystemStateHelper.java b/src/com/android/server/telecom/SystemStateHelper.java
index e813f58..f78d21c 100644
--- a/src/com/android/server/telecom/SystemStateHelper.java
+++ b/src/com/android/server/telecom/SystemStateHelper.java
@@ -77,35 +77,39 @@
public void onReceive(Context context, Intent intent) {
Log.startSession("SSH.oR");
try {
- String action = intent.getAction();
- if (UiModeManager.ACTION_ENTER_CAR_MODE_PRIORITIZED.equals(action)) {
- int priority = intent.getIntExtra(UiModeManager.EXTRA_PRIORITY,
- UiModeManager.DEFAULT_PRIORITY);
- String callingPackage = intent.getStringExtra(
- UiModeManager.EXTRA_CALLING_PACKAGE);
- Log.i(SystemStateHelper.this, "ENTER_CAR_MODE_PRIORITIZED; priority=%d, pkg=%s",
- priority, callingPackage);
- onEnterCarMode(priority, callingPackage);
- } else if (UiModeManager.ACTION_EXIT_CAR_MODE_PRIORITIZED.equals(action)) {
- int priority = intent.getIntExtra(UiModeManager.EXTRA_PRIORITY,
- UiModeManager.DEFAULT_PRIORITY);
- String callingPackage = intent.getStringExtra(
- UiModeManager.EXTRA_CALLING_PACKAGE);
- Log.i(SystemStateHelper.this, "EXIT_CAR_MODE_PRIORITIZED; priority=%d, pkg=%s",
- priority, callingPackage);
- onExitCarMode(priority, callingPackage);
- } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
- Uri data = intent.getData();
- if (data == null) {
+ synchronized (mLock) {
+ String action = intent.getAction();
+ if (UiModeManager.ACTION_ENTER_CAR_MODE_PRIORITIZED.equals(action)) {
+ int priority = intent.getIntExtra(UiModeManager.EXTRA_PRIORITY,
+ UiModeManager.DEFAULT_PRIORITY);
+ String callingPackage = intent.getStringExtra(
+ UiModeManager.EXTRA_CALLING_PACKAGE);
+ Log.i(SystemStateHelper.this,
+ "ENTER_CAR_MODE_PRIORITIZED; priority=%d, pkg=%s",
+ priority, callingPackage);
+ onEnterCarMode(priority, callingPackage);
+ } else if (UiModeManager.ACTION_EXIT_CAR_MODE_PRIORITIZED.equals(action)) {
+ int priority = intent.getIntExtra(UiModeManager.EXTRA_PRIORITY,
+ UiModeManager.DEFAULT_PRIORITY);
+ String callingPackage = intent.getStringExtra(
+ UiModeManager.EXTRA_CALLING_PACKAGE);
+ Log.i(SystemStateHelper.this,
+ "EXIT_CAR_MODE_PRIORITIZED; priority=%d, pkg=%s",
+ priority, callingPackage);
+ onExitCarMode(priority, callingPackage);
+ } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
+ Uri data = intent.getData();
+ if (data == null) {
+ Log.w(SystemStateHelper.this,
+ "Got null data for package removed, ignoring");
+ return;
+ }
+ mListeners.forEach(
+ l -> l.onPackageUninstalled(data.getEncodedSchemeSpecificPart()));
+ } else {
Log.w(SystemStateHelper.this,
- "Got null data for package removed, ignoring");
- return;
+ "Unexpected intent received: %s", intent.getAction());
}
- mListeners.forEach(
- l -> l.onPackageUninstalled(data.getEncodedSchemeSpecificPart()));
- } else {
- Log.w(SystemStateHelper.this,
- "Unexpected intent received: %s", intent.getAction());
}
} finally {
Log.endSession();
@@ -133,9 +137,11 @@
private Set<SystemStateListener> mListeners = new CopyOnWriteArraySet<>();
private boolean mIsCarModeOrProjectionActive;
+ private final TelecomSystem.SyncRoot mLock;
- public SystemStateHelper(Context context) {
+ public SystemStateHelper(Context context, TelecomSystem.SyncRoot lock) {
mContext = context;
+ mLock = lock;
IntentFilter intentFilter1 = new IntentFilter(
UiModeManager.ACTION_ENTER_CAR_MODE_PRIORITIZED);
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index 96b8901..a18ae6d 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -1790,6 +1790,7 @@
mCallsManager.markCallAsRemoved(call);
}
}
+ mCallsManager.getInCallController().unbindFromServices();
});
}
} finally {
diff --git a/src/com/android/server/telecom/TelecomSystem.java b/src/com/android/server/telecom/TelecomSystem.java
index 5f6b62a..613f50d 100644
--- a/src/com/android/server/telecom/TelecomSystem.java
+++ b/src/com/android/server/telecom/TelecomSystem.java
@@ -238,7 +238,7 @@
mContext.registerReceiver(bluetoothStateReceiver, BluetoothStateReceiver.INTENT_FILTER);
WiredHeadsetManager wiredHeadsetManager = new WiredHeadsetManager(mContext);
- SystemStateHelper systemStateHelper = new SystemStateHelper(mContext);
+ SystemStateHelper systemStateHelper = new SystemStateHelper(mContext, mLock);
mMissedCallNotifier = missedCallNotifierImplFactory
.makeMissedCallNotifierImpl(mContext, mPhoneAccountRegistrar, defaultDialerCache,
diff --git a/src/com/android/server/telecom/ui/DisconnectedCallNotifier.java b/src/com/android/server/telecom/ui/DisconnectedCallNotifier.java
index 3f54689..66f9fe4 100644
--- a/src/com/android/server/telecom/ui/DisconnectedCallNotifier.java
+++ b/src/com/android/server/telecom/ui/DisconnectedCallNotifier.java
@@ -333,7 +333,8 @@
UserHandle userHandle) {
Intent intent = new Intent(action, data, mContext, TelecomBroadcastReceiver.class);
intent.putExtra(TelecomBroadcastIntentProcessor.EXTRA_USERHANDLE, userHandle);
- return PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ return PendingIntent.getBroadcast(mContext, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}
private boolean canRespondViaSms(@NonNull CallInfo call) {
@@ -354,7 +355,7 @@
TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(mContext);
taskStackBuilder.addNextIntent(intent);
- return taskStackBuilder.getPendingIntent(0, 0, null, userHandle);
+ return taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE, null, userHandle);
}
/**
diff --git a/testapps/src/com/android/server/telecom/testapps/TestInCallUI.java b/testapps/src/com/android/server/telecom/testapps/TestInCallUI.java
index 4bf6a12..bdd4c1a 100644
--- a/testapps/src/com/android/server/telecom/testapps/TestInCallUI.java
+++ b/testapps/src/com/android/server/telecom/testapps/TestInCallUI.java
@@ -29,6 +29,7 @@
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
+import android.telephony.ims.ImsCallProfile;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
@@ -260,6 +261,8 @@
.getIntentExtras().getParcelable(TelecomManager.EXTRA_LOCATION);
String subject = call.getDetails()
.getIntentExtras().getString(TelecomManager.EXTRA_CALL_SUBJECT);
+ boolean isBusiness = call.getDetails()
+ .getExtras().getBoolean(ImsCallProfile.EXTRA_IS_BUSINESS_CALL);
StringBuilder display = new StringBuilder();
display.append("priority=");
@@ -282,6 +285,7 @@
}
display.append(" subject=" + subject);
+ display.append(" isBusiness=" + isBusiness);
TextView attachmentsTextView = findViewById(R.id.incoming_composer_attachments);
attachmentsTextView.setText(display.toString());
break;
diff --git a/tests/src/com/android/server/telecom/tests/SystemStateHelperTest.java b/tests/src/com/android/server/telecom/tests/SystemStateHelperTest.java
index ad52625..94b8463 100644
--- a/tests/src/com/android/server/telecom/tests/SystemStateHelperTest.java
+++ b/tests/src/com/android/server/telecom/tests/SystemStateHelperTest.java
@@ -48,6 +48,7 @@
import com.android.server.telecom.SystemStateHelper;
import com.android.server.telecom.SystemStateHelper.SystemStateListener;
+import com.android.server.telecom.TelecomSystem;
import org.junit.After;
import org.junit.Before;
@@ -78,6 +79,7 @@
@Mock SensorManager mSensorManager;
@Mock Intent mIntentEnter;
@Mock Intent mIntentExit;
+ TelecomSystem.SyncRoot mLock = new TelecomSystem.SyncRoot() { };
@Override
@Before
@@ -109,7 +111,7 @@
@SmallTest
@Test
public void testListeners() throws Exception {
- SystemStateHelper systemStateHelper = new SystemStateHelper(mContext);
+ SystemStateHelper systemStateHelper = new SystemStateHelper(mContext, mLock);
assertFalse(systemStateHelper.removeListener(mSystemStateListener));
systemStateHelper.addListener(mSystemStateListener);
@@ -121,14 +123,14 @@
@Test
public void testQuerySystemForCarMode_True() {
when(mUiModeManager.getCurrentModeType()).thenReturn(Configuration.UI_MODE_TYPE_CAR);
- assertTrue(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertTrue(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@Test
public void testQuerySystemForCarMode_False() {
when(mUiModeManager.getCurrentModeType()).thenReturn(Configuration.UI_MODE_TYPE_NORMAL);
- assertFalse(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertFalse(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@@ -136,11 +138,11 @@
public void testQuerySystemForAutomotiveProjection_True() {
when(mUiModeManager.getActiveProjectionTypes())
.thenReturn(UiModeManager.PROJECTION_TYPE_AUTOMOTIVE);
- assertTrue(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertTrue(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
when(mUiModeManager.getActiveProjectionTypes())
.thenReturn(UiModeManager.PROJECTION_TYPE_ALL);
- assertTrue(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertTrue(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@@ -148,7 +150,7 @@
public void testQuerySystemForAutomotiveProjection_False() {
when(mUiModeManager.getActiveProjectionTypes())
.thenReturn(UiModeManager.PROJECTION_TYPE_NONE);
- assertFalse(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertFalse(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@@ -157,7 +159,7 @@
when(mUiModeManager.getCurrentModeType()).thenReturn(Configuration.UI_MODE_TYPE_CAR);
when(mUiModeManager.getActiveProjectionTypes())
.thenReturn(UiModeManager.PROJECTION_TYPE_AUTOMOTIVE);
- assertTrue(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertTrue(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@@ -166,7 +168,7 @@
when(mContext.getSystemService(UiModeManager.class))
.thenReturn(mUiModeManager) // Without this, class construction will throw NPE.
.thenReturn(null);
- assertFalse(new SystemStateHelper(mContext).isCarModeOrProjectionActive());
+ assertFalse(new SystemStateHelper(mContext, mLock).isCarModeOrProjectionActive());
}
@SmallTest
@@ -174,7 +176,7 @@
public void testPackageRemoved() {
ArgumentCaptor<BroadcastReceiver> receiver =
ArgumentCaptor.forClass(BroadcastReceiver.class);
- new SystemStateHelper(mContext).addListener(mSystemStateListener);
+ new SystemStateHelper(mContext, mLock).addListener(mSystemStateListener);
verify(mContext, atLeastOnce())
.registerReceiver(receiver.capture(), any(IntentFilter.class));
Intent packageRemovedIntent = new Intent(Intent.ACTION_PACKAGE_REMOVED);
@@ -188,7 +190,7 @@
public void testReceiverAndIntentFilter() {
ArgumentCaptor<IntentFilter> intentFilterCaptor =
ArgumentCaptor.forClass(IntentFilter.class);
- new SystemStateHelper(mContext);
+ new SystemStateHelper(mContext, mLock);
verify(mContext, times(2)).registerReceiver(
any(BroadcastReceiver.class), intentFilterCaptor.capture());
@@ -225,7 +227,7 @@
public void testOnEnterExitCarMode() {
ArgumentCaptor<BroadcastReceiver> receiver =
ArgumentCaptor.forClass(BroadcastReceiver.class);
- new SystemStateHelper(mContext).addListener(mSystemStateListener);
+ new SystemStateHelper(mContext, mLock).addListener(mSystemStateListener);
verify(mContext, atLeastOnce())
.registerReceiver(receiver.capture(), any(IntentFilter.class));
@@ -244,7 +246,7 @@
@SmallTest
@Test
public void testOnSetReleaseAutomotiveProjection() {
- SystemStateHelper systemStateHelper = new SystemStateHelper(mContext);
+ SystemStateHelper systemStateHelper = new SystemStateHelper(mContext, mLock);
// We don't care what listener is registered, that's an implementation detail, but we need
// to call methods on whatever it is.
ArgumentCaptor<UiModeManager.OnProjectionStateChangeListener> listenerCaptor =