diff options
author | 2022-12-06 17:30:51 +0000 | |
---|---|---|
committer | 2022-12-06 17:30:51 +0000 | |
commit | 81dcc19b7f717cfa575b1e9cfc86a5e47b83cc04 (patch) | |
tree | 2756cc2a85c7e87cbd891d2d17a18ecd8607c005 | |
parent | 4e9565b8c1a2b32c217974cb33051bed62ce0501 (diff) | |
parent | d7fa29fbc6d201b56c9a4481e87041183260cd90 (diff) |
Merge "Kill WifiDialog process from Wifi service" into tm-mainline-prod
4 files changed, 24 insertions, 30 deletions
diff --git a/WifiDialog/AndroidManifest.xml b/WifiDialog/AndroidManifest.xml index 66132822c6..dfeafabda0 100644 --- a/WifiDialog/AndroidManifest.xml +++ b/WifiDialog/AndroidManifest.xml @@ -42,6 +42,7 @@ android:configChanges="keyboardHidden|screenSize" android:hardwareAccelerated="true" android:launchMode="singleInstance" + android:excludeFromRecents="true" android:theme="@*android:style/Theme.DeviceDefault.Dialog.Alert.DayNight" /> </application> </manifest> diff --git a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java index 5afd315036..c73afa9134 100644 --- a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java +++ b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java @@ -37,7 +37,6 @@ import android.os.CountDownTimer; import android.os.Handler; import android.os.Looper; import android.os.PowerManager; -import android.os.Process; import android.os.SystemClock; import android.os.Vibrator; import android.text.Editable; @@ -72,8 +71,6 @@ import java.util.Set; * Main Activity of the WifiDialog application. All dialogs should be created and managed from here. */ public class WifiDialogActivity extends Activity { - private static int sNumActiveInstances = 0; - private static final String TAG = "WifiDialog"; private static final String KEY_DIALOG_INTENTS = "KEY_DIALOG_INTENTS"; private static final String EXTRA_DIALOG_EXPIRATION_TIME_MS = @@ -213,10 +210,6 @@ public class WifiDialogActivity extends Activity { @Override protected void onStart() { super.onStart(); - sNumActiveInstances++; - if (mIsVerboseLoggingEnabled) { - Log.v(TAG, "onStart() incrementing sActiveInstances to " + sNumActiveInstances); - } registerReceiver( mCloseSystemDialogsReceiver, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); ArraySet<Integer> invalidDialogIds = new ArraySet<>(); @@ -260,10 +253,6 @@ public class WifiDialogActivity extends Activity { @Override protected void onStop() { super.onStop(); - sNumActiveInstances--; - if (mIsVerboseLoggingEnabled) { - Log.v(TAG, "onStop() decrementing sActiveInstances to " + sNumActiveInstances); - } unregisterReceiver(mCloseSystemDialogsReceiver); if (isChangingConfigurations()) { @@ -328,23 +317,6 @@ public class WifiDialogActivity extends Activity { } } - @Override - protected void onDestroy() { - super.onDestroy(); - if (isFinishing()) { - if (sNumActiveInstances > 0) { - if (mIsVerboseLoggingEnabled) { - Log.v(TAG, "Finished with sNumActiveInstances: " + sNumActiveInstances); - } - return; - } - if (mIsVerboseLoggingEnabled) { - Log.v(TAG, "Finished with no active instances left. Killing process."); - } - Process.killProcess(android.os.Process.myPid()); - } - } - /** * Creates and shows a dialog for the given dialogId and Intent. * Returns {@code true} if the dialog was successfully created, {@code false} otherwise. diff --git a/service/java/com/android/server/wifi/WifiDialogManager.java b/service/java/com/android/server/wifi/WifiDialogManager.java index 80e66907b1..73e5c5c39e 100644 --- a/service/java/com/android/server/wifi/WifiDialogManager.java +++ b/service/java/com/android/server/wifi/WifiDialogManager.java @@ -16,6 +16,7 @@ package com.android.server.wifi; +import android.app.ActivityManager; import android.app.ActivityOptions; import android.app.AlertDialog; import android.content.BroadcastReceiver; @@ -331,7 +332,8 @@ public class WifiDialogManager { mActiveDialogIds.add(mDialogId); mActiveDialogHandles.put(mDialogId, this); if (mVerboseLoggingEnabled) { - Log.v(TAG, "Registered dialog with id=" + mDialogId); + Log.v(TAG, "Registered dialog with id=" + mDialogId + + ". Active dialogs ids: " + mActiveDialogIds); } } @@ -347,9 +349,22 @@ public class WifiDialogManager { mActiveDialogIds.remove(mDialogId); mActiveDialogHandles.remove(mDialogId); if (mVerboseLoggingEnabled) { - Log.v(TAG, "Unregistered dialog with id=" + mDialogId); + Log.v(TAG, "Unregistered dialog with id=" + mDialogId + + ". Active dialogs ids: " + mActiveDialogIds); } mDialogId = WifiManager.INVALID_DIALOG_ID; + if (mActiveDialogIds.isEmpty()) { + String wifiDialogApkPkgName = mContext.getWifiDialogApkPkgName(); + if (wifiDialogApkPkgName == null) { + Log.wtf(TAG, "Could not get WifiDialog APK package name to force stop!"); + return; + } + if (mVerboseLoggingEnabled) { + Log.v(TAG, "Force stopping WifiDialog app"); + } + mContext.getSystemService(ActivityManager.class) + .forceStopPackage(wifiDialogApkPkgName); + } } } diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiDialogManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiDialogManagerTest.java index c5b3d06b54..fca154f2bc 100644 --- a/service/tests/wifitests/src/com/android/server/wifi/WifiDialogManagerTest.java +++ b/service/tests/wifitests/src/com/android/server/wifi/WifiDialogManagerTest.java @@ -30,6 +30,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.app.ActivityManager; import android.app.ActivityOptions; import android.app.AlertDialog; import android.content.BroadcastReceiver; @@ -82,12 +83,14 @@ public class WifiDialogManagerTest extends WifiBaseTest { @Mock FrameworkFacade mFrameworkFacade; @Mock Resources mResources; @Mock PowerManager mPowerManager; + @Mock ActivityManager mActivityManager; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(mWifiContext.getWifiDialogApkPkgName()).thenReturn(WIFI_DIALOG_APK_PKG_NAME); when(mWifiContext.getSystemService(PowerManager.class)).thenReturn(mPowerManager); + when(mWifiContext.getSystemService(ActivityManager.class)).thenReturn(mActivityManager); when(mWifiContext.getResources()).thenReturn(mResources); when(mPowerManager.isInteractive()).thenReturn(true); doThrow(SecurityException.class).when(mWifiContext).startActivityAsUser(any(), any(), @@ -326,6 +329,7 @@ public class WifiDialogManagerTest extends WifiBaseTest { dismissDialogSynchronous(dialogHandle, mWifiThreadRunner); intent = verifyStartActivityAsUser(2, mWifiContext); verifyDismissIntent(intent); + verify(mActivityManager).forceStopPackage(WIFI_DIALOG_APK_PKG_NAME); // A reply to the same dialog id should not trigger callback wifiDialogManager.replyToSimpleDialog(dialogId, WifiManager.DIALOG_REPLY_POSITIVE); @@ -1004,6 +1008,7 @@ public class WifiDialogManagerTest extends WifiBaseTest { dismissDialogSynchronous(dialogHandle, mWifiThreadRunner); intent = verifyStartActivityAsUser(2, mWifiContext); verifyDismissIntent(intent); + verify(mActivityManager).forceStopPackage(WIFI_DIALOG_APK_PKG_NAME); // A reply to the same dialog id should not trigger callback wifiDialogManager.replyToP2pInvitationReceivedDialog(dialogId, true, null); @@ -1119,6 +1124,7 @@ public class WifiDialogManagerTest extends WifiBaseTest { TEST_DEVICE_NAME, null); dismissDialogSynchronous(dialogHandle, mWifiThreadRunner); verifyDismissIntent(verifyStartActivityAsUser(2, mWifiContext)); + verify(mActivityManager).forceStopPackage(WIFI_DIALOG_APK_PKG_NAME); // Another call to dismiss should not send another dismiss intent. dismissDialogSynchronous(dialogHandle, mWifiThreadRunner); |