More device admin work:
- Show a warning before removing an admin, if desired. - Additional message that can be shown when adding an admin.
This commit is contained in:
@@ -20,21 +20,6 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:background="@*android:drawable/title_bar_medium">
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:text="@string/add_device_admin_msg"
|
|
||||||
android:gravity="center"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:shadowColor="?android:attr/colorBackground"
|
|
||||||
android:shadowRadius="2" />
|
|
||||||
</LinearLayout>
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@@ -45,6 +30,21 @@
|
|||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:background="@*android:drawable/title_bar_medium">
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:text="@string/add_device_admin_msg"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:shadowColor="?android:attr/colorBackground"
|
||||||
|
android:shadowRadius="2" />
|
||||||
|
</LinearLayout>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -67,11 +67,6 @@
|
|||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:ellipsize="marquee" />
|
android:ellipsize="marquee" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<TextView android:id="@+id/active_description"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:padding="10dip" />
|
|
||||||
<TextView android:id="@+id/active_warning"
|
<TextView android:id="@+id/active_warning"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -82,6 +77,16 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingLeft="16dip"
|
android:paddingLeft="16dip"
|
||||||
android:paddingRight="12dip" />
|
android:paddingRight="12dip" />
|
||||||
|
<TextView android:id="@+id/active_description"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="10dip" />
|
||||||
|
<TextView android:id="@+id/add_msg"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="10dip" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<LinearLayout style="@android:style/ButtonBar"
|
<LinearLayout style="@android:style/ButtonBar"
|
||||||
|
@@ -43,10 +43,12 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
|
|
||||||
DevicePolicyManager mDPM;
|
DevicePolicyManager mDPM;
|
||||||
DeviceAdminInfo mDeviceAdmin;
|
DeviceAdminInfo mDeviceAdmin;
|
||||||
|
CharSequence mAddMsgText;
|
||||||
|
|
||||||
ImageView mActiveIcon;
|
ImageView mActiveIcon;
|
||||||
TextView mActiveName;
|
TextView mActiveName;
|
||||||
TextView mActiveDescription;
|
TextView mActiveDescription;
|
||||||
|
TextView mAddMsg;
|
||||||
TextView mActiveWarning;
|
TextView mActiveWarning;
|
||||||
ViewGroup mAdminPolicies;
|
ViewGroup mAdminPolicies;
|
||||||
|
|
||||||
@@ -103,11 +105,15 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mAddMsgText = getIntent().getCharSequenceExtra(
|
||||||
|
DevicePolicyManager.EXTRA_ADD_EXPLANATION);
|
||||||
|
|
||||||
setContentView(R.layout.device_admin_add);
|
setContentView(R.layout.device_admin_add);
|
||||||
|
|
||||||
mActiveIcon = (ImageView)findViewById(R.id.active_icon);
|
mActiveIcon = (ImageView)findViewById(R.id.active_icon);
|
||||||
mActiveName = (TextView)findViewById(R.id.active_name);
|
mActiveName = (TextView)findViewById(R.id.active_name);
|
||||||
mActiveDescription = (TextView)findViewById(R.id.active_description);
|
mActiveDescription = (TextView)findViewById(R.id.active_description);
|
||||||
|
mAddMsg = (TextView)findViewById(R.id.add_msg);
|
||||||
mActiveWarning = (TextView)findViewById(R.id.active_warning);
|
mActiveWarning = (TextView)findViewById(R.id.active_warning);
|
||||||
mAdminPolicies = (ViewGroup)findViewById(R.id.admin_policies);
|
mAdminPolicies = (ViewGroup)findViewById(R.id.admin_policies);
|
||||||
findViewById(R.id.add_button).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.add_button).setOnClickListener(new View.OnClickListener() {
|
||||||
@@ -131,7 +137,15 @@ public class DeviceAdminAdd extends Activity {
|
|||||||
try {
|
try {
|
||||||
mActiveDescription.setText(
|
mActiveDescription.setText(
|
||||||
mDeviceAdmin.loadDescription(getPackageManager()));
|
mDeviceAdmin.loadDescription(getPackageManager()));
|
||||||
|
mActiveDescription.setVisibility(View.VISIBLE);
|
||||||
} catch (Resources.NotFoundException e) {
|
} catch (Resources.NotFoundException e) {
|
||||||
|
mActiveDescription.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if (mAddMsgText != null) {
|
||||||
|
mAddMsg.setText(mAddMsgText);
|
||||||
|
mAddMsg.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
mAddMsg.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
mActiveWarning.setText(getString(R.string.device_admin_warning,
|
mActiveWarning.setText(getString(R.string.device_admin_warning,
|
||||||
mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(getPackageManager())));
|
mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(getPackageManager())));
|
||||||
|
@@ -19,17 +19,22 @@ package com.android.settings;
|
|||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.app.DeviceAdmin;
|
import android.app.DeviceAdmin;
|
||||||
import android.app.DeviceAdminInfo;
|
import android.app.DeviceAdminInfo;
|
||||||
import android.app.DevicePolicyManager;
|
import android.app.DevicePolicyManager;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.RemoteCallback;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -46,8 +51,11 @@ import java.util.List;
|
|||||||
public class DeviceAdminSettings extends ListActivity {
|
public class DeviceAdminSettings extends ListActivity {
|
||||||
static final String TAG = "DeviceAdminSettings";
|
static final String TAG = "DeviceAdminSettings";
|
||||||
|
|
||||||
|
static final int DIALOG_WARNING = 1;
|
||||||
|
|
||||||
DevicePolicyManager mDPM;
|
DevicePolicyManager mDPM;
|
||||||
DeviceAdminInfo mCurrentAdmin;
|
DeviceAdminInfo mCurrentAdmin;
|
||||||
|
Handler mHandler;
|
||||||
|
|
||||||
View mActiveLayout;
|
View mActiveLayout;
|
||||||
ImageView mActiveIcon;
|
ImageView mActiveIcon;
|
||||||
@@ -64,6 +72,7 @@ public class DeviceAdminSettings extends ListActivity {
|
|||||||
|
|
||||||
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
mCurrentAdmin = mDPM.getActiveAdminInfo();
|
mCurrentAdmin = mDPM.getActiveAdminInfo();
|
||||||
|
mHandler = new Handler(getMainLooper());
|
||||||
|
|
||||||
setContentView(R.layout.device_admin_settings);
|
setContentView(R.layout.device_admin_settings);
|
||||||
|
|
||||||
@@ -74,8 +83,23 @@ public class DeviceAdminSettings extends ListActivity {
|
|||||||
findViewById(R.id.remove_button).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.remove_button).setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mCurrentAdmin != null) {
|
if (mCurrentAdmin != null) {
|
||||||
mDPM.removeActiveAdmin(mCurrentAdmin.getComponent());
|
mDPM.getRemoveWarning(mCurrentAdmin.getComponent(),
|
||||||
finish();
|
new RemoteCallback(mHandler) {
|
||||||
|
@Override
|
||||||
|
protected void onResult(Bundle bundle) {
|
||||||
|
CharSequence msg = bundle != null
|
||||||
|
? bundle.getCharSequence(DeviceAdmin.EXTRA_DISABLE_WARNING)
|
||||||
|
: null;
|
||||||
|
if (msg == null) {
|
||||||
|
mDPM.removeActiveAdmin(mCurrentAdmin.getComponent());
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putCharSequence(DeviceAdmin.EXTRA_DISABLE_WARNING, msg);
|
||||||
|
showDialog(DIALOG_WARNING, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -118,6 +142,30 @@ public class DeviceAdminSettings extends ListActivity {
|
|||||||
updateLayout();
|
updateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Dialog onCreateDialog(int id, Bundle args) {
|
||||||
|
switch (id) {
|
||||||
|
case DIALOG_WARNING: {
|
||||||
|
CharSequence msg = args.getCharSequence(DeviceAdmin.EXTRA_DISABLE_WARNING);
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||||
|
DeviceAdminSettings.this);
|
||||||
|
builder.setMessage(msg);
|
||||||
|
builder.setPositiveButton(R.string.dlg_ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
mDPM.removeActiveAdmin(mCurrentAdmin.getComponent());
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(R.string.dlg_cancel, null);
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return super.onCreateDialog(id, args);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void updateLayout() {
|
void updateLayout() {
|
||||||
if (mCurrentAdmin != null) {
|
if (mCurrentAdmin != null) {
|
||||||
mActiveLayout.setVisibility(View.VISIBLE);
|
mActiveLayout.setVisibility(View.VISIBLE);
|
||||||
|
Reference in New Issue
Block a user