Add "Uninstall" button to device admin activation dialog.
Bug 25392386 Change-Id: I91259ddd69bc61a7dd23a2e8b4d08719bc5cacca
This commit is contained in:
@@ -149,6 +149,15 @@
|
|||||||
android:text="@string/cancel"
|
android:text="@string/cancel"
|
||||||
style="?android:attr/buttonBarButtonStyle"
|
style="?android:attr/buttonBarButtonStyle"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
<Button android:id="@+id/uninstall_button"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:text="@string/uninstall_device_admin"
|
||||||
|
style="?android:attr/buttonBarButtonStyle"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone" />
|
||||||
<Button android:id="@+id/action_button"
|
<Button android:id="@+id/action_button"
|
||||||
android:layout_width="0dip"
|
android:layout_width="0dip"
|
||||||
android:layout_gravity="start"
|
android:layout_gravity="start"
|
||||||
|
@@ -4474,6 +4474,8 @@
|
|||||||
<string name="active_device_admin_msg">Device administrator</string>
|
<string name="active_device_admin_msg">Device administrator</string>
|
||||||
<!-- Label for button to remove the active device admin -->
|
<!-- Label for button to remove the active device admin -->
|
||||||
<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] -->
|
||||||
|
<string name="uninstall_device_admin">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 -->
|
||||||
|
@@ -36,6 +36,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
|||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -74,6 +75,8 @@ 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;
|
||||||
|
|
||||||
Handler mHandler;
|
Handler mHandler;
|
||||||
|
|
||||||
DevicePolicyManager mDPM;
|
DevicePolicyManager mDPM;
|
||||||
@@ -93,6 +96,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
TextView mSupportMessage;
|
TextView mSupportMessage;
|
||||||
ViewGroup mAdminPolicies;
|
ViewGroup mAdminPolicies;
|
||||||
Button mActionButton;
|
Button mActionButton;
|
||||||
|
Button mUninstallButton;
|
||||||
Button mCancelButton;
|
Button mCancelButton;
|
||||||
|
|
||||||
boolean mAdding;
|
boolean mAdding;
|
||||||
@@ -285,6 +289,7 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
mAdminWarning = (TextView) findViewById(R.id.admin_warning);
|
mAdminWarning = (TextView) findViewById(R.id.admin_warning);
|
||||||
mAdminPolicies = (ViewGroup) findViewById(R.id.admin_policies);
|
mAdminPolicies = (ViewGroup) findViewById(R.id.admin_policies);
|
||||||
mSupportMessage = (TextView) findViewById(R.id.admin_support_message);
|
mSupportMessage = (TextView) findViewById(R.id.admin_support_message);
|
||||||
|
|
||||||
mCancelButton = (Button) findViewById(R.id.cancel_button);
|
mCancelButton = (Button) findViewById(R.id.cancel_button);
|
||||||
mCancelButton.setFilterTouchesWhenObscured(true);
|
mCancelButton.setFilterTouchesWhenObscured(true);
|
||||||
mCancelButton.setOnClickListener(new View.OnClickListener() {
|
mCancelButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@@ -294,6 +299,17 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mUninstallButton = (Button) findViewById(R.id.uninstall_button);
|
||||||
|
mUninstallButton.setFilterTouchesWhenObscured(true);
|
||||||
|
mUninstallButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
EventLog.writeEvent(EventLogTags.EXP_DET_DEVICE_ADMIN_UNINSTALLED_BY_USER,
|
||||||
|
mDeviceAdmin.getActivityInfo().applicationInfo.uid);
|
||||||
|
uninstall();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mActionButton = (Button) findViewById(R.id.action_button);
|
mActionButton = (Button) findViewById(R.id.action_button);
|
||||||
mActionButton.setFilterTouchesWhenObscured(true);
|
mActionButton.setFilterTouchesWhenObscured(true);
|
||||||
mActionButton.setOnClickListener(new View.OnClickListener() {
|
mActionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@@ -448,6 +464,18 @@ 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()));
|
||||||
@@ -516,6 +544,9 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
setTitle(getText(R.string.add_device_admin_msg));
|
setTitle(getText(R.string.add_device_admin_msg));
|
||||||
}
|
}
|
||||||
mActionButton.setText(getText(R.string.add_device_admin));
|
mActionButton.setText(getText(R.string.add_device_admin));
|
||||||
|
if (isAdminUninstallable()) {
|
||||||
|
mUninstallButton.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
mSupportMessage.setVisibility(View.GONE);
|
mSupportMessage.setVisibility(View.GONE);
|
||||||
mAdding = true;
|
mAdding = true;
|
||||||
}
|
}
|
||||||
@@ -564,4 +595,18 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
UserHandle.getUserId(adminInfo.getActivityInfo().applicationInfo.uid));
|
UserHandle.getUserId(adminInfo.getActivityInfo().applicationInfo.uid));
|
||||||
return info != null ? info.isManagedProfile() : false;
|
return info != null ? info.isManagedProfile() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isAdminUninstallable() {
|
||||||
|
// System apps can't be uninstalled.
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,3 +10,6 @@ option java_package com.android.settings
|
|||||||
|
|
||||||
# log whether user declined activation of device admin
|
# log whether user declined activation of device admin
|
||||||
90202 exp_det_device_admin_declined_by_user (app_signature|3)
|
90202 exp_det_device_admin_declined_by_user (app_signature|3)
|
||||||
|
|
||||||
|
# log whether user uninstalled device admin on activation screen
|
||||||
|
90203 exp_det_device_admin_uninstalled_by_user (app_signature|3)
|
||||||
|
Reference in New Issue
Block a user