summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings
diff options
context:
space:
mode:
authorIdo Ofir <iofir@google.com>2014-05-09 14:47:15 -0700
committerIdo Ofir <iofir@google.com>2014-05-28 13:36:11 -0700
commit6f482447b05492906755d91ac4c29ec505a8a544 (patch)
tree5d6ea907f8860b2960d08117494468eb18f30399 /src/com/android/settings
parent73f2110e0a31e252c76b3fa41d8014449a1da4b5 (diff)
downloadpackages_apps_Settings-6f482447b05492906755d91ac4c29ec505a8a544.zip
packages_apps_Settings-6f482447b05492906755d91ac4c29ec505a8a544.tar.gz
packages_apps_Settings-6f482447b05492906755d91ac4c29ec505a8a544.tar.bz2
Moving the trust agents settings in the security settings menu and adding
personal unlock. Change-Id: I0eeb3a32c55450af2435112a98aa44475159dc4f
Diffstat (limited to 'src/com/android/settings')
-rw-r--r--src/com/android/settings/AdvancedSecuritySettings.java (renamed from src/com/android/settings/TrustAgentSettings.java)79
-rw-r--r--src/com/android/settings/SecuritySettings.java54
-rw-r--r--src/com/android/settings/TrustAgentUtils.java103
3 files changed, 164 insertions, 72 deletions
diff --git a/src/com/android/settings/TrustAgentSettings.java b/src/com/android/settings/AdvancedSecuritySettings.java
index d31436d..c497ac4 100644
--- a/src/com/android/settings/TrustAgentSettings.java
+++ b/src/com/android/settings/AdvancedSecuritySettings.java
@@ -18,26 +18,17 @@ package com.android.settings;
import com.android.internal.widget.LockPatternUtils;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
import android.app.ListFragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.service.trust.TrustAgentService;
import android.util.ArrayMap;
import android.util.ArraySet;
-import android.util.AttributeSet;
-import android.util.Slog;
-import android.util.Xml;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -46,15 +37,12 @@ import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
-import java.io.IOException;
import java.util.List;
-public class TrustAgentSettings extends ListFragment implements View.OnClickListener {
- static final String TAG = "TrustAgentSettings";
+public class AdvancedSecuritySettings extends ListFragment implements View.OnClickListener {
+ static final String TAG = "AdvancedSecuritySettings";
private static final String SERVICE_INTERFACE = TrustAgentService.SERVICE_INTERFACE;
- private static final String TRUST_AGENT_META_DATA = TrustAgentService.TRUST_AGENT_META_DATA;
-
private final ArraySet<ComponentName> mActiveAgents = new ArraySet<ComponentName>();
private final ArrayMap<ComponentName, AgentInfo> mAvailableAgents
@@ -94,7 +82,7 @@ public class TrustAgentSettings extends ListFragment implements View.OnClickList
container.getContext().getApplicationContext());
}
setListAdapter(new AgentListAdapter());
- return inflater.inflate(R.layout.trust_agent_settings, container, false);
+ return inflater.inflate(R.layout.advanced_security_settings, container, false);
}
@Override
@@ -121,70 +109,21 @@ public class TrustAgentSettings extends ListFragment implements View.OnClickList
for (ResolveInfo resolveInfo : resolveInfos) {
if (resolveInfo.serviceInfo == null) continue;
- ComponentName name = getComponentName(resolveInfo);
+ ComponentName name = TrustAgentUtils.getComponentName(resolveInfo);
if (!mAvailableAgents.containsKey(name)) {
AgentInfo agentInfo = new AgentInfo();
agentInfo.label = resolveInfo.loadLabel(pm);
agentInfo.icon = resolveInfo.loadIcon(pm);
agentInfo.component = name;
- agentInfo.settings = getSettingsComponentName(pm, resolveInfo);
+ TrustAgentUtils.TrustAgentComponentInfo trustAgentComponentInfo =
+ TrustAgentUtils.getSettingsComponent(pm, resolveInfo);
+ agentInfo.settings = trustAgentComponentInfo.componentName;
mAvailableAgents.put(name, agentInfo);
}
}
((BaseAdapter) getListAdapter()).notifyDataSetChanged();
}
- private ComponentName getComponentName(ResolveInfo resolveInfo) {
- if (resolveInfo == null || resolveInfo.serviceInfo == null) return null;
- return new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
- }
-
- private ComponentName getSettingsComponentName(PackageManager pm, ResolveInfo resolveInfo) {
- if (resolveInfo == null || resolveInfo.serviceInfo == null
- || resolveInfo.serviceInfo.metaData == null) return null;
- String cn = null;
- XmlResourceParser parser = null;
- Exception caughtException = null;
- try {
- parser = resolveInfo.serviceInfo.loadXmlMetaData(pm, TRUST_AGENT_META_DATA);
- if (parser == null) {
- Slog.w(TAG, "Can't find " + TRUST_AGENT_META_DATA + " meta-data");
- return null;
- }
- Resources res = pm.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo);
- AttributeSet attrs = Xml.asAttributeSet(parser);
- int type;
- while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
- && type != XmlPullParser.START_TAG) {
- }
- String nodeName = parser.getName();
- if (!"trust-agent".equals(nodeName)) {
- Slog.w(TAG, "Meta-data does not start with trust-agent tag");
- return null;
- }
- TypedArray sa = res
- .obtainAttributes(attrs, com.android.internal.R.styleable.TrustAgent);
- cn = sa.getString(com.android.internal.R.styleable.TrustAgent_settingsActivity);
- sa.recycle();
- } catch (PackageManager.NameNotFoundException e) {
- caughtException = e;
- } catch (IOException e) {
- caughtException = e;
- } catch (XmlPullParserException e) {
- caughtException = e;
- } finally {
- if (parser != null) parser.close();
- }
- if (caughtException != null) {
- Slog.w(TAG, "Error parsing : " + resolveInfo.serviceInfo.packageName, caughtException);
- return null;
- }
- if (cn != null && cn.indexOf('/') < 0) {
- cn = resolveInfo.serviceInfo.packageName + "/" + cn;
- }
- return cn == null ? null : ComponentName.unflattenFromString(cn);
- }
-
@Override
public void onClick(View view) {
ViewHolder h = (ViewHolder) view.getTag();
@@ -282,10 +221,10 @@ public class TrustAgentSettings extends ListFragment implements View.OnClickList
h.name = (TextView)v.findViewById(R.id.name);
h.checkbox = (CheckBox)v.findViewById(R.id.checkbox);
h.clickable = v.findViewById(R.id.clickable);
- h.clickable.setOnClickListener(TrustAgentSettings.this);
+ h.clickable.setOnClickListener(AdvancedSecuritySettings.this);
h.description = (TextView)v.findViewById(R.id.description);
h.settings = v.findViewById(R.id.settings);
- h.settings.setOnClickListener(TrustAgentSettings.this);
+ h.settings.setOnClickListener(AdvancedSecuritySettings.this);
v.setTag(h);
h.settings.setTag(h);
h.clickable.setTag(h);
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index 00d1d89..ab03853 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -41,6 +41,7 @@ import android.preference.PreferenceScreen;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.security.KeyStore;
+import android.service.trust.TrustAgentService;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -58,6 +59,8 @@ import java.util.List;
public class SecuritySettings extends RestrictedSettingsFragment
implements OnPreferenceChangeListener, DialogInterface.OnClickListener, Indexable {
static final String TAG = "SecuritySettings";
+ private static final Intent TRUST_AGENT_INTENT =
+ new Intent(TrustAgentService.SERVICE_INTERFACE);
// Lock Settings
private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
@@ -74,6 +77,7 @@ public class SecuritySettings extends RestrictedSettingsFragment
private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
private static final int CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_IMPROVE_REQUEST = 124;
private static final int CONFIRM_EXISTING_FOR_BIOMETRIC_WEAK_LIVELINESS_OFF = 125;
+ private static final int CHANGE_TRUST_AGENT_SETTINGS = 126;
// Misc Settings
private static final String KEY_SIM_LOCK = "sim_lock";
@@ -86,6 +90,7 @@ public class SecuritySettings extends RestrictedSettingsFragment
private static final String KEY_POWER_INSTANTLY_LOCKS = "power_button_instantly_locks";
private static final String KEY_CREDENTIALS_MANAGER = "credentials_management";
private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
+ private static final String KEY_TRUST_AGENT = "trust_agent";
private DevicePolicyManager mDPM;
@@ -161,7 +166,7 @@ public class SecuritySettings extends RestrictedSettingsFragment
/**
* Important!
*
- * Dont forget to update the SecuritySearchIndexProvider if you are doing any change in the
+ * Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
* logic or adding/removing preferences here.
*/
private PreferenceScreen createPreferenceHierarchy() {
@@ -270,7 +275,7 @@ public class SecuritySettings extends RestrictedSettingsFragment
}
// Application install
- PreferenceGroup deviceAdminCategory= (PreferenceGroup)
+ PreferenceGroup deviceAdminCategory = (PreferenceGroup)
root.findPreference(KEY_DEVICE_ADMIN_CATEGORY);
mToggleAppInstallation = (CheckBoxPreference) findPreference(
KEY_TOGGLE_INSTALL_APPLICATIONS);
@@ -303,6 +308,36 @@ public class SecuritySettings extends RestrictedSettingsFragment
protectByRestrictions(root.findPreference(KEY_CREDENTIALS_INSTALL));
}
+ // Trust Agent preferences
+ PreferenceGroup securityCategory = (PreferenceGroup)
+ root.findPreference(KEY_SECURITY_CATEGORY);
+ if (securityCategory != null) {
+ PackageManager pm = getPackageManager();
+ List<ResolveInfo> resolveInfos = pm.queryIntentServices(TRUST_AGENT_INTENT,
+ PackageManager.GET_META_DATA);
+ for (ResolveInfo resolveInfo : resolveInfos) {
+ if (resolveInfo.serviceInfo == null) continue;
+ TrustAgentUtils.TrustAgentComponentInfo trustAgentComponentInfo =
+ TrustAgentUtils.getSettingsComponent(pm, resolveInfo);
+ if (trustAgentComponentInfo.componentName == null ||
+ trustAgentComponentInfo.title == null ||
+ trustAgentComponentInfo.title == "") continue;
+ Preference trustAgentPreference =
+ new Preference(securityCategory.getContext());
+ trustAgentPreference.setKey(KEY_TRUST_AGENT);
+ trustAgentPreference.setTitle(trustAgentComponentInfo.title);
+ trustAgentPreference.setSummary(trustAgentComponentInfo.summary);
+ // Create intent for this preference.
+ Intent intent = new Intent();
+ intent.setComponent(trustAgentComponentInfo.componentName);
+ intent.setAction(Intent.ACTION_MAIN);
+ trustAgentPreference.setIntent(intent);
+ // Add preference to the settings menu.
+ securityCategory.addPreference(trustAgentPreference);
+ break; // Only render the first one.
+ }
+ }
+
return root;
}
@@ -522,6 +557,13 @@ public class SecuritySettings extends RestrictedSettingsFragment
} else if (KEY_TOGGLE_VERIFY_APPLICATIONS.equals(key)) {
Settings.Global.putInt(getContentResolver(), Settings.Global.PACKAGE_VERIFIER_ENABLE,
mToggleVerifyApps.isChecked() ? 1 : 0);
+ } else if (KEY_TRUST_AGENT.equals(key)) {
+ ChooseLockSettingsHelper helper =
+ new ChooseLockSettingsHelper(this.getActivity(), this);
+ if (!helper.launchConfirmationActivity(CHANGE_TRUST_AGENT_SETTINGS, null, null)) {
+ // If this returns false, it means no password confirmation is required.
+ startActivity(preference.getIntent());
+ }
} else {
// If we didn't handle it, let preferences handle it.
return super.onPreferenceTreeClick(preferenceScreen, preference);
@@ -552,6 +594,14 @@ public class SecuritySettings extends RestrictedSettingsFragment
// is called by grabbing the value from lockPatternUtils. We can't set it here
// because mBiometricWeakLiveliness could be null
return;
+ } else if (requestCode == CHANGE_TRUST_AGENT_SETTINGS && resultCode == Activity.RESULT_OK) {
+ Preference preference = getPreferenceScreen().findPreference(KEY_TRUST_AGENT);
+ if (preference != null) {
+ Intent intent = preference.getIntent();
+ if (intent != null) {
+ startActivity(intent);
+ }
+ }
}
createPreferenceHierarchy();
}
diff --git a/src/com/android/settings/TrustAgentUtils.java b/src/com/android/settings/TrustAgentUtils.java
new file mode 100644
index 0000000..64829a2
--- /dev/null
+++ b/src/com/android/settings/TrustAgentUtils.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2014 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 android.content.ComponentName;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
+import android.service.trust.TrustAgentService;
+import android.util.AttributeSet;
+import android.util.Slog;
+import android.util.Xml;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
+
+public class TrustAgentUtils {
+ static final String TAG = "TrustAgentUtils";
+
+ private static final String TRUST_AGENT_META_DATA = TrustAgentService.TRUST_AGENT_META_DATA;
+
+ public static class TrustAgentComponentInfo {
+ ComponentName componentName;
+ String title;
+ String summary;
+ }
+
+ public static ComponentName getComponentName(ResolveInfo resolveInfo) {
+ if (resolveInfo == null || resolveInfo.serviceInfo == null) return null;
+ return new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
+ }
+
+ public static TrustAgentComponentInfo getSettingsComponent(
+ PackageManager pm, ResolveInfo resolveInfo) {
+ if (resolveInfo == null || resolveInfo.serviceInfo == null
+ || resolveInfo.serviceInfo.metaData == null) return null;
+ String cn = null;
+ TrustAgentComponentInfo trustAgentComponentInfo = new TrustAgentComponentInfo();
+ XmlResourceParser parser = null;
+ Exception caughtException = null;
+ try {
+ parser = resolveInfo.serviceInfo.loadXmlMetaData(pm, TRUST_AGENT_META_DATA);
+ if (parser == null) {
+ Slog.w(TAG, "Can't find " + TRUST_AGENT_META_DATA + " meta-data");
+ return null;
+ }
+ Resources res = pm.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo);
+ AttributeSet attrs = Xml.asAttributeSet(parser);
+ int type;
+ while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+ && type != XmlPullParser.START_TAG) {
+ }
+ String nodeName = parser.getName();
+ if (!"trust-agent".equals(nodeName)) {
+ Slog.w(TAG, "Meta-data does not start with trust-agent tag");
+ return null;
+ }
+ TypedArray sa =
+ res.obtainAttributes(attrs, com.android.internal.R.styleable.TrustAgent);
+ trustAgentComponentInfo.summary =
+ sa.getString(com.android.internal.R.styleable.TrustAgent_summary);
+ trustAgentComponentInfo.title =
+ sa.getString(com.android.internal.R.styleable.TrustAgent_title);
+ cn = sa.getString(com.android.internal.R.styleable.TrustAgent_settingsActivity);
+ sa.recycle();
+ } catch (PackageManager.NameNotFoundException e) {
+ caughtException = e;
+ } catch (IOException e) {
+ caughtException = e;
+ } catch (XmlPullParserException e) {
+ caughtException = e;
+ } finally {
+ if (parser != null) parser.close();
+ }
+ if (caughtException != null) {
+ Slog.w(TAG, "Error parsing : " + resolveInfo.serviceInfo.packageName, caughtException);
+ return null;
+ }
+ if (cn != null && cn.indexOf('/') < 0) {
+ cn = resolveInfo.serviceInfo.packageName + "/" + cn;
+ }
+ trustAgentComponentInfo.componentName = (cn == null) ? null : ComponentName.unflattenFromString(cn);
+ return trustAgentComponentInfo;
+ }
+}