Allow system apps to be disabled

If it is a single-user device, keep earlier behavior
of disabling and offering to downgrade the system app. If there
are other users, then only disable the app.

Bug: 26694521
Change-Id: I4e62fec6bb186afa5d4c3f29f5524783494dfb06
This commit is contained in:
Amith Yamasani
2016-03-01 14:52:01 -08:00
parent 0792e2f4ad
commit b5545c8395

View File

@@ -485,18 +485,10 @@ public class InstalledAppDetails extends AppInfoBase
if (requestCode == REQUEST_UNINSTALL) { if (requestCode == REQUEST_UNINSTALL) {
if (mDisableAfterUninstall) { if (mDisableAfterUninstall) {
mDisableAfterUninstall = false; mDisableAfterUninstall = false;
try {
ApplicationInfo ainfo = getActivity().getPackageManager().getApplicationInfo(
mAppEntry.info.packageName, PackageManager.GET_UNINSTALLED_PACKAGES
| PackageManager.GET_DISABLED_COMPONENTS);
if ((ainfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0) {
new DisableChanger(this, mAppEntry.info, new DisableChanger(this, mAppEntry.info,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)
.execute((Object)null); .execute((Object)null);
} }
} catch (NameNotFoundException e) {
}
}
if (!refreshUi()) { if (!refreshUi()) {
setIntentAndFinish(true, true); setIntentAndFinish(true, true);
} }
@@ -656,11 +648,11 @@ public class InstalledAppDetails extends AppInfoBase
.create(); .create();
case DLG_SPECIAL_DISABLE: case DLG_SPECIAL_DISABLE:
return new AlertDialog.Builder(getActivity()) return new AlertDialog.Builder(getActivity())
.setMessage(getActivity().getText(R.string.app_special_disable_dlg_text)) .setMessage(getActivity().getText(R.string.app_disable_dlg_text))
.setPositiveButton(R.string.app_disable_dlg_positive, .setPositiveButton(R.string.app_disable_dlg_positive,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
// Clear user data here // Disable the app and ask for uninstall
uninstallPkg(mAppEntry.info.packageName, uninstallPkg(mAppEntry.info.packageName,
false, true); false, true);
} }
@@ -706,7 +698,7 @@ public class InstalledAppDetails extends AppInfoBase
} }
private void forceStopPackage(String pkgName) { private void forceStopPackage(String pkgName) {
ActivityManager am = (ActivityManager)getActivity().getSystemService( ActivityManager am = (ActivityManager) getActivity().getSystemService(
Context.ACTIVITY_SERVICE); Context.ACTIVITY_SERVICE);
am.forceStopPackage(pkgName); am.forceStopPackage(pkgName);
int userId = UserHandle.getUserId(mAppEntry.info.uid); int userId = UserHandle.getUserId(mAppEntry.info.uid);
@@ -779,7 +771,7 @@ public class InstalledAppDetails extends AppInfoBase
return; return;
} }
String packageName = mAppEntry.info.packageName; String packageName = mAppEntry.info.packageName;
if(v == mUninstallButton) { if (v == mUninstallButton) {
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) { if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
Activity activity = getActivity(); Activity activity = getActivity();
Intent uninstallDAIntent = new Intent(activity, DeviceAdminAdd.class); Intent uninstallDAIntent = new Intent(activity, DeviceAdminAdd.class);
@@ -796,7 +788,10 @@ public class InstalledAppDetails extends AppInfoBase
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(), admin); RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getActivity(), 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 (mUpdatedSysApp) { // 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(DLG_SPECIAL_DISABLE, 0); showDialogInner(DLG_SPECIAL_DISABLE, 0);
} else { } else {
showDialogInner(DLG_DISABLE, 0); showDialogInner(DLG_DISABLE, 0);
@@ -822,6 +817,13 @@ public class InstalledAppDetails extends AppInfoBase
} }
} }
/** 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
|| (mUserManager.isSplitSystemUser() && userCount == 2);
}
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
if (preference == mStoragePreference) { if (preference == mStoragePreference) {