Merge "Adding an easy uninstall for active device admin" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
eee6c2c8b7
@@ -4587,6 +4587,8 @@
|
|||||||
<string name="remove_device_admin">Deactivate</string>
|
<string name="remove_device_admin">Deactivate</string>
|
||||||
<!-- Label for button to uninstall the device admin application [CHAR LIMIT=40] -->
|
<!-- Label for button to uninstall the device admin application [CHAR LIMIT=40] -->
|
||||||
<string name="uninstall_device_admin">Uninstall</string>
|
<string name="uninstall_device_admin">Uninstall</string>
|
||||||
|
<!-- Label for button to deactivate and uninstall the device admin [CHAR_LIMIT=50]-->
|
||||||
|
<string name="remove_and_uninstall_device_admin">Deactivate and Uninstall</string>
|
||||||
<!-- Label for screen showing to select device policy -->
|
<!-- Label for screen showing to select device policy -->
|
||||||
<string name="select_device_admin_msg">Device administrators</string>
|
<string name="select_device_admin_msg">Device administrators</string>
|
||||||
<!-- Message when there are no available device admins to display -->
|
<!-- Message when there are no available device admins to display -->
|
||||||
|
@@ -77,6 +77,13 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
|
|
||||||
private static final int REQUEST_CODE_UNINSTALL = 1;
|
private static final int REQUEST_CODE_UNINSTALL = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional key to map to the package name of the Device Admin.
|
||||||
|
* Currently only used when uninstalling an active device admin.
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_DEVICE_ADMIN_PACKAGE_NAME =
|
||||||
|
"android.app.extra.DEVICE_ADMIN_PACKAGE_NAME";
|
||||||
|
|
||||||
Handler mHandler;
|
Handler mHandler;
|
||||||
|
|
||||||
DevicePolicyManager mDPM;
|
DevicePolicyManager mDPM;
|
||||||
@@ -99,6 +106,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
Button mUninstallButton;
|
Button mUninstallButton;
|
||||||
Button mCancelButton;
|
Button mCancelButton;
|
||||||
|
|
||||||
|
boolean mUninstalling = false;
|
||||||
boolean mAdding;
|
boolean mAdding;
|
||||||
boolean mRefreshing;
|
boolean mRefreshing;
|
||||||
boolean mWaitingForRemoveMsg;
|
boolean mWaitingForRemoveMsg;
|
||||||
@@ -123,13 +131,24 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String action = getIntent().getAction();
|
String action = getIntent().getAction();
|
||||||
ComponentName who = (ComponentName)getIntent().getParcelableExtra(
|
ComponentName who = (ComponentName)getIntent().getParcelableExtra(
|
||||||
DevicePolicyManager.EXTRA_DEVICE_ADMIN);
|
DevicePolicyManager.EXTRA_DEVICE_ADMIN);
|
||||||
if (who == null) {
|
if (who == null) {
|
||||||
Log.w(TAG, "No component specified in " + action);
|
String packageName = getIntent().getStringExtra(EXTRA_DEVICE_ADMIN_PACKAGE_NAME);
|
||||||
finish();
|
for (ComponentName component : mDPM.getActiveAdmins()) {
|
||||||
return;
|
if (component.getPackageName().equals(packageName)) {
|
||||||
|
who = component;
|
||||||
|
mUninstalling = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (who == null) {
|
||||||
|
Log.w(TAG, "No component specified in " + action);
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action != null && action.equals(DevicePolicyManager.ACTION_SET_PROFILE_OWNER)) {
|
if (action != null && action.equals(DevicePolicyManager.ACTION_SET_PROFILE_OWNER)) {
|
||||||
@@ -329,6 +348,9 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
).show();
|
).show();
|
||||||
|
} else if (mUninstalling) {
|
||||||
|
mDPM.uninstallPackageWithActiveAdmins(mDeviceAdmin.getPackageName());
|
||||||
|
finish();
|
||||||
} else if (!mWaitingForRemoveMsg) {
|
} else if (!mWaitingForRemoveMsg) {
|
||||||
try {
|
try {
|
||||||
// Don't allow the admin to put a dialog up in front
|
// Don't allow the admin to put a dialog up in front
|
||||||
@@ -524,7 +546,11 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(
|
mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(
|
||||||
getPackageManager())));
|
getPackageManager())));
|
||||||
setTitle(R.string.active_device_admin_msg);
|
setTitle(R.string.active_device_admin_msg);
|
||||||
mActionButton.setText(R.string.remove_device_admin);
|
if (mUninstalling) {
|
||||||
|
mActionButton.setText(R.string.remove_and_uninstall_device_admin);
|
||||||
|
} else {
|
||||||
|
mActionButton.setText(R.string.remove_device_admin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String supportMessage = mDPM.getLongSupportMessageForUser(
|
String supportMessage = mDPM.getLongSupportMessageForUser(
|
||||||
mDeviceAdmin.getComponent(), UserHandle.myUserId());
|
mDeviceAdmin.getComponent(), UserHandle.myUserId());
|
||||||
@@ -606,7 +632,6 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
final Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
|
final Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
|
||||||
uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false);
|
uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false);
|
||||||
uninstallIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
|
uninstallIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
|
||||||
|
|
||||||
startActivityForResult(uninstallIntent, REQUEST_CODE_UNINSTALL);
|
startActivityForResult(uninstallIntent, REQUEST_CODE_UNINSTALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -68,6 +68,7 @@ import com.android.internal.logging.MetricsProto.MetricsEvent;
|
|||||||
import com.android.internal.os.BatterySipper;
|
import com.android.internal.os.BatterySipper;
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
import com.android.internal.os.BatteryStatsHelper;
|
||||||
import com.android.settings.AppHeader;
|
import com.android.settings.AppHeader;
|
||||||
|
import com.android.settings.DeviceAdminAdd;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
@@ -116,6 +117,8 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
|
|
||||||
// Result code identifiers
|
// Result code identifiers
|
||||||
public static final int REQUEST_UNINSTALL = 0;
|
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 SUB_INFO_FRAGMENT = 1;
|
||||||
|
|
||||||
private static final int LOADER_CHART_DATA = 2;
|
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.
|
// 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.
|
// 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;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,6 +221,11 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
enabled = false;
|
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
|
// Home apps need special handling. Bundled ones we don't risk downgrading
|
||||||
// because that can interfere with home-key resolution. Furthermore, we
|
// 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
|
// 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);
|
setIntentAndFinish(true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (requestCode == REQUEST_REMOVE_DEVICE_ADMIN) {
|
||||||
|
if (!refreshUi()) {
|
||||||
|
setIntentAndFinish(true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility method to set application label and icon.
|
// Utility method to set application label and icon.
|
||||||
@@ -717,6 +730,14 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
}
|
}
|
||||||
String packageName = mAppEntry.info.packageName;
|
String packageName = mAppEntry.info.packageName;
|
||||||
if(v == mUninstallButton) {
|
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(),
|
EnforcedAdmin admin = RestrictedLockUtils.checkIfUninstallBlocked(getActivity(),
|
||||||
packageName, mUserId);
|
packageName, mUserId);
|
||||||
if (admin != null) {
|
if (admin != null) {
|
||||||
|
Reference in New Issue
Block a user