summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/DeviceAdminAdd.java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2010-01-25 18:56:17 -0800
committerDianne Hackborn <hackbod@google.com>2010-01-26 11:09:32 -0800
commit28429033375c3876af56528bfc9ea6b541052fcb (patch)
tree72130241ccf264388efec1c5b485b27b2a5fa260 /src/com/android/settings/DeviceAdminAdd.java
parente67c8810906285513d7d41113e362ea12415a735 (diff)
downloadpackages_apps_Settings-28429033375c3876af56528bfc9ea6b541052fcb.zip
packages_apps_Settings-28429033375c3876af56528bfc9ea6b541052fcb.tar.gz
packages_apps_Settings-28429033375c3876af56528bfc9ea6b541052fcb.tar.bz2
Work on the device admin settings UI.
Improve the look of the UI, and add the confirmation screen for enabling an administrator. This uses the new framework APIs to show its description and policies it will control.
Diffstat (limited to 'src/com/android/settings/DeviceAdminAdd.java')
-rw-r--r--src/com/android/settings/DeviceAdminAdd.java146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java
new file mode 100644
index 0000000..6763bd6
--- /dev/null
+++ b/src/com/android/settings/DeviceAdminAdd.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings;
+
+import org.xmlpull.v1.XmlPullParserException;
+
+import android.app.Activity;
+import android.app.DeviceAdminInfo;
+import android.app.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AppSecurityPermissions;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public class DeviceAdminAdd extends Activity {
+ static final String TAG = "DeviceAdminAdd";
+
+ DevicePolicyManager mDPM;
+ DeviceAdminInfo mDeviceAdmin;
+
+ ImageView mActiveIcon;
+ TextView mActiveName;
+ TextView mActiveDescription;
+ TextView mActiveWarning;
+ ViewGroup mAdminPolicies;
+
+ View mSelectLayout;
+ ArrayList<DeviceAdminInfo> mAvailablePolicies
+ = new ArrayList<DeviceAdminInfo>();
+
+ @Override
+ protected void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
+ DeviceAdminInfo activeAdmin = mDPM.getActiveAdminInfo();
+
+ ComponentName cn = (ComponentName)getIntent().getParcelableExtra(
+ DevicePolicyManager.EXTRA_DEVICE_ADMIN);
+ if (cn == null) {
+ Log.w(TAG, "No component specified in " + getIntent().getAction());
+ finish();
+ return;
+ }
+ if (cn.equals(activeAdmin)) {
+ setResult(Activity.RESULT_OK);
+ finish();
+ return;
+ }
+ if (activeAdmin != null) {
+ Log.w(TAG, "Admin already set, can't do " + getIntent().getAction());
+ finish();
+ return;
+ }
+
+ ActivityInfo ai;
+ try {
+ ai = getPackageManager().getReceiverInfo(cn,
+ PackageManager.GET_META_DATA);
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.w(TAG, "Unable to retrieve device policy " + cn, e);
+ finish();
+ return;
+ }
+
+ ResolveInfo ri = new ResolveInfo();
+ ri.activityInfo = ai;
+ try {
+ mDeviceAdmin= new DeviceAdminInfo(this, ri);
+ } catch (XmlPullParserException e) {
+ Log.w(TAG, "Unable to retrieve device policy " + cn, e);
+ finish();
+ return;
+ } catch (IOException e) {
+ Log.w(TAG, "Unable to retrieve device policy " + cn, e);
+ finish();
+ return;
+ }
+
+ setContentView(R.layout.device_admin_add);
+
+ mActiveIcon = (ImageView)findViewById(R.id.active_icon);
+ mActiveName = (TextView)findViewById(R.id.active_name);
+ mActiveDescription = (TextView)findViewById(R.id.active_description);
+ mActiveWarning = (TextView)findViewById(R.id.active_warning);
+ mAdminPolicies = (ViewGroup)findViewById(R.id.admin_policies);
+ findViewById(R.id.add_button).setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ mDPM.setActiveAdmin(mDeviceAdmin.getComponent());
+ setResult(Activity.RESULT_OK);
+ finish();
+ }
+ });
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ updateInterface();
+ }
+
+ void updateInterface() {
+ mActiveIcon.setImageDrawable(mDeviceAdmin.loadIcon(getPackageManager()));
+ mActiveName.setText(mDeviceAdmin.loadLabel(getPackageManager()));
+ try {
+ mActiveDescription.setText(
+ mDeviceAdmin.loadDescription(getPackageManager()));
+ } catch (Resources.NotFoundException e) {
+ }
+ mActiveWarning.setText(getString(R.string.device_admin_warning,
+ mDeviceAdmin.getActivityInfo().applicationInfo.loadLabel(getPackageManager())));
+ ArrayList<DeviceAdminInfo.PolicyInfo> policies = mDeviceAdmin.getUsedPolicies();
+ for (int i=0; i<policies.size(); i++) {
+ DeviceAdminInfo.PolicyInfo pi = policies.get(i);
+ mAdminPolicies.addView(AppSecurityPermissions.getPermissionItemView(
+ this, getText(pi.label), getText(pi.description), true));
+ }
+ }
+
+}