Adding an easy uninstall for active device admin

Currently the uninstall button is disabled for a package
with an active device admin. This change enables the button,
which when clicked gives the user an option to deactivate
all the DAs in the package and then uninstall the package.

Bug: b/22359208

cherry pick of I8b955305927751185a4c982dadb5b1b6b07efe5e

Change-Id: Ib2ab0e35b74fc8dba7168174b2bc8fd383fe94fe
This commit is contained in:
Suprabh Shukla
2016-01-27 13:00:10 -08:00
parent d119f50314
commit 02a06eff42
3 changed files with 54 additions and 6 deletions

View File

@@ -68,6 +68,7 @@ import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.AppHeader;
import com.android.settings.DeviceAdminAdd;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
@@ -116,6 +117,8 @@ public class InstalledAppDetails extends AppInfoBase
// Result code identifiers
public static final int REQUEST_UNINSTALL = 0;
private static final int REQUEST_REMOVE_DEVICE_ADMIN = 1;
private static final int SUB_INFO_FRAGMENT = 1;
private static final int LOADER_CHART_DATA = 2;
@@ -207,7 +210,7 @@ public class InstalledAppDetails extends AppInfoBase
}
// If this is a device admin, it can't be uninstalled or disabled.
// We do this here so the text of the button is still set correctly.
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
if (isBundled && mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
enabled = false;
}
@@ -218,6 +221,11 @@ public class InstalledAppDetails extends AppInfoBase
enabled = false;
}
// If the uninstall intent is already queued, disable the uninstall button
if (mDpm.isUninstallInQueue(mPackageName)) {
enabled = false;
}
// Home apps need special handling. Bundled ones we don't risk downgrading
// because that can interfere with home-key resolution. Furthermore, we
// can't allow uninstallation of the only home app, and we don't want to
@@ -447,6 +455,11 @@ public class InstalledAppDetails extends AppInfoBase
setIntentAndFinish(true, true);
}
}
if (requestCode == REQUEST_REMOVE_DEVICE_ADMIN) {
if (!refreshUi()) {
setIntentAndFinish(true, true);
}
}
}
// Utility method to set application label and icon.
@@ -717,6 +730,14 @@ public class InstalledAppDetails extends AppInfoBase
}
String packageName = mAppEntry.info.packageName;
if(v == mUninstallButton) {
if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
Activity activity = getActivity();
Intent uninstallDAIntent = new Intent(activity, DeviceAdminAdd.class);
uninstallDAIntent.putExtra(DeviceAdminAdd.EXTRA_DEVICE_ADMIN_PACKAGE_NAME,
mPackageName);
activity.startActivityForResult(uninstallDAIntent, REQUEST_REMOVE_DEVICE_ADMIN);
return;
}
EnforcedAdmin admin = RestrictedLockUtils.checkIfUninstallBlocked(getActivity(),
packageName, mUserId);
if (admin != null) {