Remove Settings from recents after app uninstall
SettingsActivity now calls finishAndRemoveTask instead of only finish() to prevent blank recent task from showing in overview. Test: Visually inspected bug doesn't exist. Wrote Roboelectric tests Fixes: 129733119 Change-Id: I5b73c1b611e6eb52bb6665c215276efdc85c19b2
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import static com.android.settings.applications.appinfo.AppButtonsPreferenceController.KEY_REMOVE_TASK_WHEN_FINISHING;
|
||||||
|
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@@ -542,7 +544,12 @@ public class SettingsActivity extends SettingsBaseActivity
|
|||||||
*/
|
*/
|
||||||
public void finishPreferencePanel(int resultCode, Intent resultData) {
|
public void finishPreferencePanel(int resultCode, Intent resultData) {
|
||||||
setResult(resultCode, resultData);
|
setResult(resultCode, resultData);
|
||||||
finish();
|
if (resultData != null &&
|
||||||
|
resultData.getBooleanExtra(KEY_REMOVE_TASK_WHEN_FINISHING, false)) {
|
||||||
|
finishAndRemoveTask();
|
||||||
|
} else {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -80,6 +80,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
PreferenceControllerMixin, LifecycleObserver, OnResume, OnDestroy,
|
PreferenceControllerMixin, LifecycleObserver, OnResume, OnDestroy,
|
||||||
ApplicationsState.Callbacks {
|
ApplicationsState.Callbacks {
|
||||||
public static final String APP_CHG = "chg";
|
public static final String APP_CHG = "chg";
|
||||||
|
public static final String KEY_REMOVE_TASK_WHEN_FINISHING = "remove_task_when_finishing";
|
||||||
|
|
||||||
private static final String TAG = "AppButtonsPrefCtl";
|
private static final String TAG = "AppButtonsPrefCtl";
|
||||||
private static final String KEY_ACTION_BUTTONS = "action_buttons";
|
private static final String KEY_ACTION_BUTTONS = "action_buttons";
|
||||||
@@ -196,7 +197,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
mActivity, UserManager.DISALLOW_APPS_CONTROL, mUserId);
|
mActivity, UserManager.DISALLOW_APPS_CONTROL, mUserId);
|
||||||
|
|
||||||
if (!refreshUi()) {
|
if (!refreshUi()) {
|
||||||
setIntentAndFinish(true);
|
setIntentAndFinish(true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,9 +279,9 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
AsyncTask.execute(new DisableChangerRunnable(mPm, mAppEntry.info.packageName,
|
AsyncTask.execute(new DisableChangerRunnable(mPm, mAppEntry.info.packageName,
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER));
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER));
|
||||||
}
|
}
|
||||||
refreshAndFinishIfPossible();
|
refreshAndFinishIfPossible(true);
|
||||||
} else if (requestCode == mRequestRemoveDeviceAdmin) {
|
} else if (requestCode == mRequestRemoveDeviceAdmin) {
|
||||||
refreshAndFinishIfPossible();
|
refreshAndFinishIfPossible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,19 +467,20 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
/**
|
/**
|
||||||
* Finish this fragment and return data if possible
|
* Finish this fragment and return data if possible
|
||||||
*/
|
*/
|
||||||
private void setIntentAndFinish(boolean appChanged) {
|
private void setIntentAndFinish(boolean appChanged, boolean removeTaskWhenFinishing) {
|
||||||
if (LOCAL_LOGV) {
|
if (LOCAL_LOGV) {
|
||||||
Log.i(TAG, "appChanged=" + appChanged);
|
Log.i(TAG, "appChanged=" + appChanged);
|
||||||
}
|
}
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(APP_CHG, appChanged);
|
intent.putExtra(APP_CHG, appChanged);
|
||||||
|
intent.putExtra(KEY_REMOVE_TASK_WHEN_FINISHING, removeTaskWhenFinishing);
|
||||||
mActivity.finishPreferencePanel(Activity.RESULT_OK, intent);
|
mActivity.finishPreferencePanel(Activity.RESULT_OK, intent);
|
||||||
mFinishing = true;
|
mFinishing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshAndFinishIfPossible() {
|
private void refreshAndFinishIfPossible(boolean removeTaskWhenFinishing) {
|
||||||
if (!refreshUi()) {
|
if (!refreshUi()) {
|
||||||
setIntentAndFinish(true);
|
setIntentAndFinish(true, removeTaskWhenFinishing);
|
||||||
} else {
|
} else {
|
||||||
startListeningToPackageRemove();
|
startListeningToPackageRemove();
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.applications.appinfo;
|
package com.android.settings.applications.appinfo;
|
||||||
|
|
||||||
|
import static com.android.settings.applications.appinfo.AppButtonsPreferenceController.KEY_REMOVE_TASK_WHEN_FINISHING;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@@ -450,6 +452,30 @@ public class AppButtonsPreferenceControllerTest {
|
|||||||
AppButtonsPreferenceController.DISABLED_FOR_USER);
|
AppButtonsPreferenceController.DISABLED_FOR_USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handleActivityResult_onAppUninstall_removeTask() {
|
||||||
|
mController.handleActivityResult(REQUEST_UNINSTALL, 0, new Intent());
|
||||||
|
|
||||||
|
ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
verify(mSettingsActivity).finishPreferencePanel(anyInt(), argumentCaptor.capture());
|
||||||
|
|
||||||
|
final Intent i = argumentCaptor.getValue();
|
||||||
|
assertThat(i).isNotNull();
|
||||||
|
assertThat(i.getBooleanExtra(KEY_REMOVE_TASK_WHEN_FINISHING, false)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handleActivityResult_onAppNotUninstall_persistTask() {
|
||||||
|
mController.handleActivityResult(REQUEST_UNINSTALL + 1, 0, new Intent());
|
||||||
|
|
||||||
|
ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
verify(mSettingsActivity).finishPreferencePanel(anyInt(), argumentCaptor.capture());
|
||||||
|
|
||||||
|
final Intent i = argumentCaptor.getValue();
|
||||||
|
assertThat(i).isNotNull();
|
||||||
|
assertThat(i.getBooleanExtra(KEY_REMOVE_TASK_WHEN_FINISHING, false)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The test fragment which implements
|
* The test fragment which implements
|
||||||
* {@link ButtonActionDialogFragment.AppButtonsDialogListener}
|
* {@link ButtonActionDialogFragment.AppButtonsDialogListener}
|
||||||
|
Reference in New Issue
Block a user