Clean up AppButtonsPreferenceController
mDisableAfterUninstall and mUpdatedSysApp is always false. And appChanged is always true. Bug: 236346018 Test: Manual with Settings App Change-Id: Icfb9fbea92d5c728cbef9d76569d59d5085a51e6
This commit is contained in:
@@ -102,8 +102,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String mPackageName;
|
String mPackageName;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mDisableAfterUninstall = false;
|
|
||||||
@VisibleForTesting
|
|
||||||
ActionButtonsPreference mButtonsPref;
|
ActionButtonsPreference mButtonsPref;
|
||||||
|
|
||||||
private final int mUserId;
|
private final int mUserId;
|
||||||
@@ -124,7 +122,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
private long mSessionId;
|
private long mSessionId;
|
||||||
private boolean mUpdatedSysApp = false;
|
|
||||||
private boolean mListeningToPackageRemove = false;
|
private boolean mListeningToPackageRemove = false;
|
||||||
private boolean mFinishing = false;
|
private boolean mFinishing = false;
|
||||||
private boolean mAppsControlDisallowedBySystem;
|
private boolean mAppsControlDisallowedBySystem;
|
||||||
@@ -197,7 +194,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, false);
|
setIntentAndFinish(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,14 +238,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mActivity, admin);
|
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mActivity, admin);
|
||||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||||
if (mAppEntry.info.enabled && !isDisabledUntilUsed()) {
|
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);
|
showDialogInner(ButtonActionDialogFragment.DialogType.DISABLE);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mMetricsFeatureProvider.action(
|
mMetricsFeatureProvider.action(
|
||||||
mActivity,
|
mActivity,
|
||||||
@@ -260,9 +250,9 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT));
|
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT));
|
||||||
}
|
}
|
||||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
|
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
|
||||||
uninstallPkg(packageName, true, false);
|
uninstallPkg(packageName, true);
|
||||||
} else {
|
} else {
|
||||||
uninstallPkg(packageName, false, false);
|
uninstallPkg(packageName, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,11 +282,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
|
|
||||||
public void handleActivityResult(int requestCode, int resultCode, Intent data) {
|
public void handleActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == mRequestUninstall) {
|
if (requestCode == mRequestUninstall) {
|
||||||
if (mDisableAfterUninstall) {
|
|
||||||
mDisableAfterUninstall = false;
|
|
||||||
AsyncTask.execute(new DisableChangerRunnable(mPm, mAppEntry.info.packageName,
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER));
|
|
||||||
}
|
|
||||||
refreshAndFinishIfPossible(true);
|
refreshAndFinishIfPossible(true);
|
||||||
} else if (requestCode == mRequestRemoveDeviceAdmin) {
|
} else if (requestCode == mRequestRemoveDeviceAdmin) {
|
||||||
refreshAndFinishIfPossible(false);
|
refreshAndFinishIfPossible(false);
|
||||||
@@ -311,11 +296,6 @@ 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));
|
||||||
break;
|
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:
|
case ButtonActionDialogFragment.DialogType.FORCE_STOP:
|
||||||
forceStopPackage(mAppEntry.info.packageName);
|
forceStopPackage(mAppEntry.info.packageName);
|
||||||
break;
|
break;
|
||||||
@@ -493,12 +473,9 @@ 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, boolean removeTaskWhenFinishing) {
|
private void setIntentAndFinish(boolean removeTaskWhenFinishing) {
|
||||||
if (LOCAL_LOGV) {
|
|
||||||
Log.i(TAG, "appChanged=" + appChanged);
|
|
||||||
}
|
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(APP_CHG, appChanged);
|
intent.putExtra(APP_CHG, true);
|
||||||
intent.putExtra(KEY_REMOVE_TASK_WHEN_FINISHING, removeTaskWhenFinishing);
|
intent.putExtra(KEY_REMOVE_TASK_WHEN_FINISHING, removeTaskWhenFinishing);
|
||||||
mActivity.finishPreferencePanel(Activity.RESULT_OK, intent);
|
mActivity.finishPreferencePanel(Activity.RESULT_OK, intent);
|
||||||
mFinishing = true;
|
mFinishing = true;
|
||||||
@@ -506,7 +483,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
|
|
||||||
private void refreshAndFinishIfPossible(boolean removeTaskWhenFinishing) {
|
private void refreshAndFinishIfPossible(boolean removeTaskWhenFinishing) {
|
||||||
if (!refreshUi()) {
|
if (!refreshUi()) {
|
||||||
setIntentAndFinish(true, removeTaskWhenFinishing);
|
setIntentAndFinish(removeTaskWhenFinishing);
|
||||||
} else {
|
} else {
|
||||||
startListeningToPackageRemove();
|
startListeningToPackageRemove();
|
||||||
}
|
}
|
||||||
@@ -547,17 +524,15 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void uninstallPkg(String packageName, boolean allUsers, boolean andDisable) {
|
void uninstallPkg(String packageName, boolean allUsers) {
|
||||||
stopListeningToPackageRemove();
|
stopListeningToPackageRemove();
|
||||||
// Create new intent to launch Uninstaller activity
|
// Create new intent to launch Uninstaller activity
|
||||||
Uri packageUri = Uri.parse("package:" + packageName);
|
Uri packageUri = Uri.parse("package:" + packageName);
|
||||||
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
|
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
|
||||||
uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, allUsers);
|
uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, allUsers);
|
||||||
|
|
||||||
mMetricsFeatureProvider.action(
|
mMetricsFeatureProvider.action(mActivity, SettingsEnums.ACTION_SETTINGS_UNINSTALL_APP);
|
||||||
mActivity, SettingsEnums.ACTION_SETTINGS_UNINSTALL_APP);
|
|
||||||
mFragment.startActivityForResult(uninstallIntent, mRequestUninstall);
|
mFragment.startActivityForResult(uninstallIntent, mRequestUninstall);
|
||||||
mDisableAfterUninstall = andDisable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -622,12 +597,6 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
newFragment.show(mActivity.getSupportFragmentManager(), "dialog " + id);
|
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() {
|
private final BroadcastReceiver mCheckKillProcessesReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@@ -666,8 +635,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
List<ResolveInfo> homeActivities = new ArrayList<>();
|
List<ResolveInfo> homeActivities = new ArrayList<>();
|
||||||
mPm.getHomeActivities(homeActivities);
|
mPm.getHomeActivities(homeActivities);
|
||||||
mHomePackages.clear();
|
mHomePackages.clear();
|
||||||
for (int i = 0, size = homeActivities.size(); i < size; i++) {
|
for (ResolveInfo ri : homeActivities) {
|
||||||
ResolveInfo ri = homeActivities.get(i);
|
|
||||||
final String activityPkg = ri.activityInfo.packageName;
|
final String activityPkg = ri.activityInfo.packageName;
|
||||||
mHomePackages.add(activityPkg);
|
mHomePackages.add(activityPkg);
|
||||||
|
|
||||||
@@ -694,8 +662,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initButtonPreference() {
|
private void initButtonPreference() {
|
||||||
mButtonsPref = ((ActionButtonsPreference) mScreen.findPreference(
|
mButtonsPref = ((ActionButtonsPreference) mScreen.findPreference(KEY_ACTION_BUTTONS))
|
||||||
KEY_ACTION_BUTTONS))
|
|
||||||
.setButton1Text(R.string.launch_instant_app)
|
.setButton1Text(R.string.launch_instant_app)
|
||||||
.setButton1Icon(R.drawable.ic_settings_open)
|
.setButton1Icon(R.drawable.ic_settings_open)
|
||||||
.setButton1OnClickListener(v -> launchApplication())
|
.setButton1OnClickListener(v -> launchApplication())
|
||||||
|
@@ -48,12 +48,10 @@ public class ButtonActionDialogFragment extends InstrumentedDialogFragment imple
|
|||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@IntDef({
|
@IntDef({
|
||||||
DialogType.DISABLE,
|
DialogType.DISABLE,
|
||||||
DialogType.SPECIAL_DISABLE,
|
|
||||||
DialogType.FORCE_STOP
|
DialogType.FORCE_STOP
|
||||||
})
|
})
|
||||||
public @interface DialogType {
|
public @interface DialogType {
|
||||||
int DISABLE = 0;
|
int DISABLE = 0;
|
||||||
int SPECIAL_DISABLE = 1;
|
|
||||||
int FORCE_STOP = 2;
|
int FORCE_STOP = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +103,6 @@ public class ButtonActionDialogFragment extends InstrumentedDialogFragment imple
|
|||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case DialogType.DISABLE:
|
case DialogType.DISABLE:
|
||||||
case DialogType.SPECIAL_DISABLE:
|
|
||||||
return new AlertDialog.Builder(context)
|
return new AlertDialog.Builder(context)
|
||||||
.setMessage(R.string.app_disable_dlg_text)
|
.setMessage(R.string.app_disable_dlg_text)
|
||||||
.setPositiveButton(R.string.app_disable_dlg_positive, this)
|
.setPositiveButton(R.string.app_disable_dlg_positive, this)
|
||||||
|
@@ -85,10 +85,8 @@ import java.util.Set;
|
|||||||
public class AppButtonsPreferenceControllerTest {
|
public class AppButtonsPreferenceControllerTest {
|
||||||
|
|
||||||
private static final String PACKAGE_NAME = "com.android.settings";
|
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 String RESOURCE_STRING = "string";
|
||||||
private static final boolean ALL_USERS = false;
|
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_UNINSTALL = 0;
|
||||||
private static final int REQUEST_REMOVE_DEVICE_ADMIN = 1;
|
private static final int REQUEST_REMOVE_DEVICE_ADMIN = 1;
|
||||||
private static final OverlayInfo OVERLAY_DISABLED = createFakeOverlay("overlay", false, 1);
|
private static final OverlayInfo OVERLAY_DISABLED = createFakeOverlay("overlay", false, 1);
|
||||||
@@ -401,14 +399,13 @@ public class AppButtonsPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uninstallPkg_intentSent() {
|
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));
|
verify(mFragment).startActivityForResult(any(), eq(REQUEST_UNINSTALL));
|
||||||
assertThat(
|
assertThat(
|
||||||
mUninstallIntent.getBooleanExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, true))
|
mUninstallIntent.getBooleanExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, true))
|
||||||
.isEqualTo(ALL_USERS);
|
.isEqualTo(ALL_USERS);
|
||||||
assertThat(mUninstallIntent.getAction()).isEqualTo(Intent.ACTION_UNINSTALL_PACKAGE);
|
assertThat(mUninstallIntent.getAction()).isEqualTo(Intent.ACTION_UNINSTALL_PACKAGE);
|
||||||
assertThat(mController.mDisableAfterUninstall).isEqualTo(DISABLE_AFTER_INSTALL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -50,8 +50,6 @@ public class ButtonActionDialogFragmentTest {
|
|||||||
|
|
||||||
private static final int FORCE_STOP_ID = ButtonActionDialogFragment.DialogType.FORCE_STOP;
|
private static final int FORCE_STOP_ID = ButtonActionDialogFragment.DialogType.FORCE_STOP;
|
||||||
private static final int DISABLE_ID = ButtonActionDialogFragment.DialogType.DISABLE;
|
private static final int DISABLE_ID = ButtonActionDialogFragment.DialogType.DISABLE;
|
||||||
private static final int SPECIAL_DISABLE_ID =
|
|
||||||
ButtonActionDialogFragment.DialogType.SPECIAL_DISABLE;
|
|
||||||
@Mock
|
@Mock
|
||||||
private TestFragment mTargetFragment;
|
private TestFragment mTargetFragment;
|
||||||
private ButtonActionDialogFragment mFragment;
|
private ButtonActionDialogFragment mFragment;
|
||||||
@@ -129,26 +127,6 @@ public class ButtonActionDialogFragmentTest {
|
|||||||
mShadowContext.getString(R.string.dlg_cancel));
|
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
|
* Test fragment that used as the target fragment, it must implement the
|
||||||
* {@link ButtonActionDialogFragment.AppButtonsDialogListener}
|
* {@link ButtonActionDialogFragment.AppButtonsDialogListener}
|
||||||
|
Reference in New Issue
Block a user