Use DPM.uninstallPackageWithActiveAdmins()
... so that uninstall won't fail even if the package has other active admins. It's pretty much an edge case, so we don't show the deactivation confirmation in this case. Bug 27107878 Change-Id: I7e8b0843ac6e39e3db3bfc643eed6940e8577417
This commit is contained in:
@@ -75,8 +75,6 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
private static final int MAX_ADD_MSG_LINES_LANDSCAPE = 2;
|
private static final int MAX_ADD_MSG_LINES_LANDSCAPE = 2;
|
||||||
private static final int MAX_ADD_MSG_LINES = 15;
|
private static final int MAX_ADD_MSG_LINES = 15;
|
||||||
|
|
||||||
private static final int REQUEST_CODE_UNINSTALL = 1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional key to map to the package name of the Device Admin.
|
* Optional key to map to the package name of the Device Admin.
|
||||||
* Currently only used when uninstalling an active device admin.
|
* Currently only used when uninstalling an active device admin.
|
||||||
@@ -325,7 +323,8 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
EventLog.writeEvent(EventLogTags.EXP_DET_DEVICE_ADMIN_UNINSTALLED_BY_USER,
|
EventLog.writeEvent(EventLogTags.EXP_DET_DEVICE_ADMIN_UNINSTALLED_BY_USER,
|
||||||
mDeviceAdmin.getActivityInfo().applicationInfo.uid);
|
mDeviceAdmin.getActivityInfo().applicationInfo.uid);
|
||||||
uninstall();
|
mDPM.uninstallPackageWithActiveAdmins(mDeviceAdmin.getPackageName());
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -486,18 +485,6 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
switch (requestCode) {
|
|
||||||
case REQUEST_CODE_UNINSTALL:
|
|
||||||
if (resultCode == RESULT_OK) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateInterface() {
|
void updateInterface() {
|
||||||
mAdminIcon.setImageDrawable(mDeviceAdmin.loadIcon(getPackageManager()));
|
mAdminIcon.setImageDrawable(mDeviceAdmin.loadIcon(getPackageManager()));
|
||||||
mAdminName.setText(mDeviceAdmin.loadLabel(getPackageManager()));
|
mAdminName.setText(mDeviceAdmin.loadLabel(getPackageManager()));
|
||||||
@@ -626,12 +613,4 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
// System apps can't be uninstalled.
|
// System apps can't be uninstalled.
|
||||||
return !mDeviceAdmin.getActivityInfo().applicationInfo.isSystemApp();
|
return !mDeviceAdmin.getActivityInfo().applicationInfo.isSystemApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void uninstall() {
|
|
||||||
final Uri packageURI = Uri.parse("package:" + mDeviceAdmin.getPackageName());
|
|
||||||
final Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
|
|
||||||
uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false);
|
|
||||||
uninstallIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
|
|
||||||
startActivityForResult(uninstallIntent, REQUEST_CODE_UNINSTALL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user