Loading src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java +11 −44 Original line number Diff line number Diff line Loading @@ -102,8 +102,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp @VisibleForTesting String mPackageName; @VisibleForTesting boolean mDisableAfterUninstall = false; @VisibleForTesting ActionButtonsPreference mButtonsPref; private final int mUserId; Loading @@ -124,7 +122,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp private PreferenceScreen mScreen; private long mSessionId; private boolean mUpdatedSysApp = false; private boolean mListeningToPackageRemove = false; private boolean mFinishing = false; private boolean mAppsControlDisallowedBySystem; Loading Loading @@ -197,7 +194,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp mActivity, UserManager.DISALLOW_APPS_CONTROL, mUserId); if (!refreshUi()) { setIntentAndFinish(true, false); setIntentAndFinish(false); } } } Loading Loading @@ -241,14 +238,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mActivity, admin); } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { if (mAppEntry.info.enabled && !isDisabledUntilUsed()) { // If the system app has an update and this is the only user on the device, // then offer to downgrade the app, otherwise only offer to disable the // app for this user. if (mUpdatedSysApp && isSingleUser()) { showDialogInner(ButtonActionDialogFragment.DialogType.SPECIAL_DISABLE); } else { showDialogInner(ButtonActionDialogFragment.DialogType.DISABLE); } } else { mMetricsFeatureProvider.action( mActivity, Loading @@ -260,9 +250,9 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)); } } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) { uninstallPkg(packageName, true, false); uninstallPkg(packageName, true); } else { uninstallPkg(packageName, false, false); uninstallPkg(packageName, false); } } } Loading Loading @@ -292,11 +282,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp public void handleActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == mRequestUninstall) { if (mDisableAfterUninstall) { mDisableAfterUninstall = false; AsyncTask.execute(new DisableChangerRunnable(mPm, mAppEntry.info.packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)); } refreshAndFinishIfPossible(true); } else if (requestCode == mRequestRemoveDeviceAdmin) { refreshAndFinishIfPossible(false); Loading @@ -311,11 +296,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp AsyncTask.execute(new DisableChangerRunnable(mPm, mAppEntry.info.packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)); break; case ButtonActionDialogFragment.DialogType.SPECIAL_DISABLE: mMetricsFeatureProvider.action(mActivity, SettingsEnums.ACTION_SETTINGS_DISABLE_APP); uninstallPkg(mAppEntry.info.packageName, false, true); break; case ButtonActionDialogFragment.DialogType.FORCE_STOP: forceStopPackage(mAppEntry.info.packageName); break; Loading Loading @@ -493,12 +473,9 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp /** * Finish this fragment and return data if possible */ private void setIntentAndFinish(boolean appChanged, boolean removeTaskWhenFinishing) { if (LOCAL_LOGV) { Log.i(TAG, "appChanged=" + appChanged); } private void setIntentAndFinish(boolean removeTaskWhenFinishing) { Intent intent = new Intent(); intent.putExtra(APP_CHG, appChanged); intent.putExtra(APP_CHG, true); intent.putExtra(KEY_REMOVE_TASK_WHEN_FINISHING, removeTaskWhenFinishing); mActivity.finishPreferencePanel(Activity.RESULT_OK, intent); mFinishing = true; Loading @@ -506,7 +483,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp private void refreshAndFinishIfPossible(boolean removeTaskWhenFinishing) { if (!refreshUi()) { setIntentAndFinish(true, removeTaskWhenFinishing); setIntentAndFinish(removeTaskWhenFinishing); } else { startListeningToPackageRemove(); } Loading Loading @@ -547,17 +524,15 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp } @VisibleForTesting void uninstallPkg(String packageName, boolean allUsers, boolean andDisable) { void uninstallPkg(String packageName, boolean allUsers) { stopListeningToPackageRemove(); // Create new intent to launch Uninstaller activity Uri packageUri = Uri.parse("package:" + packageName); Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri); uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, allUsers); mMetricsFeatureProvider.action( mActivity, SettingsEnums.ACTION_SETTINGS_UNINSTALL_APP); mMetricsFeatureProvider.action(mActivity, SettingsEnums.ACTION_SETTINGS_UNINSTALL_APP); mFragment.startActivityForResult(uninstallIntent, mRequestUninstall); mDisableAfterUninstall = andDisable; } @VisibleForTesting Loading Loading @@ -622,12 +597,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp newFragment.show(mActivity.getSupportFragmentManager(), "dialog " + id); } /** Returns whether there is only one user on this device, not including the system-only user */ private boolean isSingleUser() { final int userCount = mUserManager.getUserCount(); return userCount == 1; } private final BroadcastReceiver mCheckKillProcessesReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading Loading @@ -666,8 +635,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp List<ResolveInfo> homeActivities = new ArrayList<>(); mPm.getHomeActivities(homeActivities); mHomePackages.clear(); for (int i = 0, size = homeActivities.size(); i < size; i++) { ResolveInfo ri = homeActivities.get(i); for (ResolveInfo ri : homeActivities) { final String activityPkg = ri.activityInfo.packageName; mHomePackages.add(activityPkg); Loading @@ -694,8 +662,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp } private void initButtonPreference() { mButtonsPref = ((ActionButtonsPreference) mScreen.findPreference( KEY_ACTION_BUTTONS)) mButtonsPref = ((ActionButtonsPreference) mScreen.findPreference(KEY_ACTION_BUTTONS)) .setButton1Text(R.string.launch_instant_app) .setButton1Icon(R.drawable.ic_settings_open) .setButton1OnClickListener(v -> launchApplication()) Loading src/com/android/settings/applications/appinfo/ButtonActionDialogFragment.java +0 −3 Original line number Diff line number Diff line Loading @@ -48,12 +48,10 @@ public class ButtonActionDialogFragment extends InstrumentedDialogFragment imple @Retention(RetentionPolicy.SOURCE) @IntDef({ DialogType.DISABLE, DialogType.SPECIAL_DISABLE, DialogType.FORCE_STOP }) public @interface DialogType { int DISABLE = 0; int SPECIAL_DISABLE = 1; int FORCE_STOP = 2; } Loading Loading @@ -105,7 +103,6 @@ public class ButtonActionDialogFragment extends InstrumentedDialogFragment imple final Context context = getContext(); switch (id) { case DialogType.DISABLE: case DialogType.SPECIAL_DISABLE: return new AlertDialog.Builder(context) .setMessage(R.string.app_disable_dlg_text) .setPositiveButton(R.string.app_disable_dlg_positive, this) Loading tests/robotests/src/com/android/settings/applications/appinfo/AppButtonsPreferenceControllerTest.java +1 −4 Original line number Diff line number Diff line Loading @@ -85,10 +85,8 @@ import java.util.Set; public class AppButtonsPreferenceControllerTest { private static final String PACKAGE_NAME = "com.android.settings"; private static final String RRO_PACKAGE_NAME = "com.android.settings.overlay"; private static final String RESOURCE_STRING = "string"; private static final boolean ALL_USERS = false; private static final boolean DISABLE_AFTER_INSTALL = true; private static final int REQUEST_UNINSTALL = 0; private static final int REQUEST_REMOVE_DEVICE_ADMIN = 1; private static final OverlayInfo OVERLAY_DISABLED = createFakeOverlay("overlay", false, 1); Loading Loading @@ -401,14 +399,13 @@ public class AppButtonsPreferenceControllerTest { @Test public void uninstallPkg_intentSent() { mController.uninstallPkg(PACKAGE_NAME, ALL_USERS, DISABLE_AFTER_INSTALL); mController.uninstallPkg(PACKAGE_NAME, ALL_USERS); verify(mFragment).startActivityForResult(any(), eq(REQUEST_UNINSTALL)); assertThat( mUninstallIntent.getBooleanExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, true)) .isEqualTo(ALL_USERS); assertThat(mUninstallIntent.getAction()).isEqualTo(Intent.ACTION_UNINSTALL_PACKAGE); assertThat(mController.mDisableAfterUninstall).isEqualTo(DISABLE_AFTER_INSTALL); } @Test Loading tests/robotests/src/com/android/settings/applications/appinfo/ButtonActionDialogFragmentTest.java +0 −22 Original line number Diff line number Diff line Loading @@ -50,8 +50,6 @@ public class ButtonActionDialogFragmentTest { private static final int FORCE_STOP_ID = ButtonActionDialogFragment.DialogType.FORCE_STOP; private static final int DISABLE_ID = ButtonActionDialogFragment.DialogType.DISABLE; private static final int SPECIAL_DISABLE_ID = ButtonActionDialogFragment.DialogType.SPECIAL_DISABLE; @Mock private TestFragment mTargetFragment; private ButtonActionDialogFragment mFragment; Loading Loading @@ -129,26 +127,6 @@ public class ButtonActionDialogFragmentTest { mShadowContext.getString(R.string.dlg_cancel)); } @Test public void testOnCreateDialog_specialDisableDialog() { ButtonActionDialogFragment fragment = ButtonActionDialogFragment.newInstance(SPECIAL_DISABLE_ID); FragmentController.setupFragment(fragment, FragmentActivity.class, 0 /* containerViewId */, null /* bundle */); final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(dialog).isNotNull(); ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog); assertThat(shadowDialog.getMessage()).isEqualTo( mShadowContext.getString(R.string.app_disable_dlg_text)); assertThat(dialog.getButton(DialogInterface.BUTTON_POSITIVE).getText()).isEqualTo( mShadowContext.getString(R.string.app_disable_dlg_positive)); assertThat(dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getText()).isEqualTo( mShadowContext.getString(R.string.dlg_cancel)); } /** * Test fragment that used as the target fragment, it must implement the * {@link ButtonActionDialogFragment.AppButtonsDialogListener} Loading Loading
src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java +11 −44 Original line number Diff line number Diff line Loading @@ -102,8 +102,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp @VisibleForTesting String mPackageName; @VisibleForTesting boolean mDisableAfterUninstall = false; @VisibleForTesting ActionButtonsPreference mButtonsPref; private final int mUserId; Loading @@ -124,7 +122,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp private PreferenceScreen mScreen; private long mSessionId; private boolean mUpdatedSysApp = false; private boolean mListeningToPackageRemove = false; private boolean mFinishing = false; private boolean mAppsControlDisallowedBySystem; Loading Loading @@ -197,7 +194,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp mActivity, UserManager.DISALLOW_APPS_CONTROL, mUserId); if (!refreshUi()) { setIntentAndFinish(true, false); setIntentAndFinish(false); } } } Loading Loading @@ -241,14 +238,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mActivity, admin); } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { if (mAppEntry.info.enabled && !isDisabledUntilUsed()) { // If the system app has an update and this is the only user on the device, // then offer to downgrade the app, otherwise only offer to disable the // app for this user. if (mUpdatedSysApp && isSingleUser()) { showDialogInner(ButtonActionDialogFragment.DialogType.SPECIAL_DISABLE); } else { showDialogInner(ButtonActionDialogFragment.DialogType.DISABLE); } } else { mMetricsFeatureProvider.action( mActivity, Loading @@ -260,9 +250,9 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)); } } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) { uninstallPkg(packageName, true, false); uninstallPkg(packageName, true); } else { uninstallPkg(packageName, false, false); uninstallPkg(packageName, false); } } } Loading Loading @@ -292,11 +282,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp public void handleActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == mRequestUninstall) { if (mDisableAfterUninstall) { mDisableAfterUninstall = false; AsyncTask.execute(new DisableChangerRunnable(mPm, mAppEntry.info.packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)); } refreshAndFinishIfPossible(true); } else if (requestCode == mRequestRemoveDeviceAdmin) { refreshAndFinishIfPossible(false); Loading @@ -311,11 +296,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp AsyncTask.execute(new DisableChangerRunnable(mPm, mAppEntry.info.packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)); break; case ButtonActionDialogFragment.DialogType.SPECIAL_DISABLE: mMetricsFeatureProvider.action(mActivity, SettingsEnums.ACTION_SETTINGS_DISABLE_APP); uninstallPkg(mAppEntry.info.packageName, false, true); break; case ButtonActionDialogFragment.DialogType.FORCE_STOP: forceStopPackage(mAppEntry.info.packageName); break; Loading Loading @@ -493,12 +473,9 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp /** * Finish this fragment and return data if possible */ private void setIntentAndFinish(boolean appChanged, boolean removeTaskWhenFinishing) { if (LOCAL_LOGV) { Log.i(TAG, "appChanged=" + appChanged); } private void setIntentAndFinish(boolean removeTaskWhenFinishing) { Intent intent = new Intent(); intent.putExtra(APP_CHG, appChanged); intent.putExtra(APP_CHG, true); intent.putExtra(KEY_REMOVE_TASK_WHEN_FINISHING, removeTaskWhenFinishing); mActivity.finishPreferencePanel(Activity.RESULT_OK, intent); mFinishing = true; Loading @@ -506,7 +483,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp private void refreshAndFinishIfPossible(boolean removeTaskWhenFinishing) { if (!refreshUi()) { setIntentAndFinish(true, removeTaskWhenFinishing); setIntentAndFinish(removeTaskWhenFinishing); } else { startListeningToPackageRemove(); } Loading Loading @@ -547,17 +524,15 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp } @VisibleForTesting void uninstallPkg(String packageName, boolean allUsers, boolean andDisable) { void uninstallPkg(String packageName, boolean allUsers) { stopListeningToPackageRemove(); // Create new intent to launch Uninstaller activity Uri packageUri = Uri.parse("package:" + packageName); Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri); uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, allUsers); mMetricsFeatureProvider.action( mActivity, SettingsEnums.ACTION_SETTINGS_UNINSTALL_APP); mMetricsFeatureProvider.action(mActivity, SettingsEnums.ACTION_SETTINGS_UNINSTALL_APP); mFragment.startActivityForResult(uninstallIntent, mRequestUninstall); mDisableAfterUninstall = andDisable; } @VisibleForTesting Loading Loading @@ -622,12 +597,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp newFragment.show(mActivity.getSupportFragmentManager(), "dialog " + id); } /** Returns whether there is only one user on this device, not including the system-only user */ private boolean isSingleUser() { final int userCount = mUserManager.getUserCount(); return userCount == 1; } private final BroadcastReceiver mCheckKillProcessesReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading Loading @@ -666,8 +635,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp List<ResolveInfo> homeActivities = new ArrayList<>(); mPm.getHomeActivities(homeActivities); mHomePackages.clear(); for (int i = 0, size = homeActivities.size(); i < size; i++) { ResolveInfo ri = homeActivities.get(i); for (ResolveInfo ri : homeActivities) { final String activityPkg = ri.activityInfo.packageName; mHomePackages.add(activityPkg); Loading @@ -694,8 +662,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp } private void initButtonPreference() { mButtonsPref = ((ActionButtonsPreference) mScreen.findPreference( KEY_ACTION_BUTTONS)) mButtonsPref = ((ActionButtonsPreference) mScreen.findPreference(KEY_ACTION_BUTTONS)) .setButton1Text(R.string.launch_instant_app) .setButton1Icon(R.drawable.ic_settings_open) .setButton1OnClickListener(v -> launchApplication()) Loading
src/com/android/settings/applications/appinfo/ButtonActionDialogFragment.java +0 −3 Original line number Diff line number Diff line Loading @@ -48,12 +48,10 @@ public class ButtonActionDialogFragment extends InstrumentedDialogFragment imple @Retention(RetentionPolicy.SOURCE) @IntDef({ DialogType.DISABLE, DialogType.SPECIAL_DISABLE, DialogType.FORCE_STOP }) public @interface DialogType { int DISABLE = 0; int SPECIAL_DISABLE = 1; int FORCE_STOP = 2; } Loading Loading @@ -105,7 +103,6 @@ public class ButtonActionDialogFragment extends InstrumentedDialogFragment imple final Context context = getContext(); switch (id) { case DialogType.DISABLE: case DialogType.SPECIAL_DISABLE: return new AlertDialog.Builder(context) .setMessage(R.string.app_disable_dlg_text) .setPositiveButton(R.string.app_disable_dlg_positive, this) Loading
tests/robotests/src/com/android/settings/applications/appinfo/AppButtonsPreferenceControllerTest.java +1 −4 Original line number Diff line number Diff line Loading @@ -85,10 +85,8 @@ import java.util.Set; public class AppButtonsPreferenceControllerTest { private static final String PACKAGE_NAME = "com.android.settings"; private static final String RRO_PACKAGE_NAME = "com.android.settings.overlay"; private static final String RESOURCE_STRING = "string"; private static final boolean ALL_USERS = false; private static final boolean DISABLE_AFTER_INSTALL = true; private static final int REQUEST_UNINSTALL = 0; private static final int REQUEST_REMOVE_DEVICE_ADMIN = 1; private static final OverlayInfo OVERLAY_DISABLED = createFakeOverlay("overlay", false, 1); Loading Loading @@ -401,14 +399,13 @@ public class AppButtonsPreferenceControllerTest { @Test public void uninstallPkg_intentSent() { mController.uninstallPkg(PACKAGE_NAME, ALL_USERS, DISABLE_AFTER_INSTALL); mController.uninstallPkg(PACKAGE_NAME, ALL_USERS); verify(mFragment).startActivityForResult(any(), eq(REQUEST_UNINSTALL)); assertThat( mUninstallIntent.getBooleanExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, true)) .isEqualTo(ALL_USERS); assertThat(mUninstallIntent.getAction()).isEqualTo(Intent.ACTION_UNINSTALL_PACKAGE); assertThat(mController.mDisableAfterUninstall).isEqualTo(DISABLE_AFTER_INSTALL); } @Test Loading
tests/robotests/src/com/android/settings/applications/appinfo/ButtonActionDialogFragmentTest.java +0 −22 Original line number Diff line number Diff line Loading @@ -50,8 +50,6 @@ public class ButtonActionDialogFragmentTest { private static final int FORCE_STOP_ID = ButtonActionDialogFragment.DialogType.FORCE_STOP; private static final int DISABLE_ID = ButtonActionDialogFragment.DialogType.DISABLE; private static final int SPECIAL_DISABLE_ID = ButtonActionDialogFragment.DialogType.SPECIAL_DISABLE; @Mock private TestFragment mTargetFragment; private ButtonActionDialogFragment mFragment; Loading Loading @@ -129,26 +127,6 @@ public class ButtonActionDialogFragmentTest { mShadowContext.getString(R.string.dlg_cancel)); } @Test public void testOnCreateDialog_specialDisableDialog() { ButtonActionDialogFragment fragment = ButtonActionDialogFragment.newInstance(SPECIAL_DISABLE_ID); FragmentController.setupFragment(fragment, FragmentActivity.class, 0 /* containerViewId */, null /* bundle */); final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(dialog).isNotNull(); ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog); assertThat(shadowDialog.getMessage()).isEqualTo( mShadowContext.getString(R.string.app_disable_dlg_text)); assertThat(dialog.getButton(DialogInterface.BUTTON_POSITIVE).getText()).isEqualTo( mShadowContext.getString(R.string.app_disable_dlg_positive)); assertThat(dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getText()).isEqualTo( mShadowContext.getString(R.string.dlg_cancel)); } /** * Test fragment that used as the target fragment, it must implement the * {@link ButtonActionDialogFragment.AppButtonsDialogListener} Loading