Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f482447 authored by Ido Ofir's avatar Ido Ofir
Browse files

Moving the trust agents settings in the security settings menu and adding

personal unlock.

Change-Id: I0eeb3a32c55450af2435112a98aa44475159dc4f
parent 73f2110e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -3979,6 +3979,8 @@
    <string name="trusted_credentials">Trusted credentials</string>
    <!-- Summary of preference to display trusted credentials (aka CA certificates) [CHAR LIMIT=NONE] -->
    <string name="trusted_credentials_summary">Display trusted CA certificates</string>
    <!-- Title of preference group for advance security settings [CHAR LIMIT=30] -->
    <string name="advanced_security_title">Advanced</string>
    <!-- Title of preference of what type of credential storage this device has: hardware or software [CHAR LIMIT=30] -->
    <string name="credential_storage_type">Storage type</string>
    <!-- Summary text for preference showing what type of credential storage this device has when it is stored in a hardware-backed storage (as opposed to "software only") [CHAR LIMIT=NONE] -->
+10 −7
Original line number Diff line number Diff line
@@ -47,12 +47,6 @@
                android:persistent="false"
                android:fragment="com.android.settings.DeviceAdminSettings"/>

        <Preference android:key="manage_trust_agents"
                    android:title="@string/manage_trust_agents"
                    android:summary="@string/manage_trust_agents_summary"
                    android:persistent="false"
                    android:fragment="com.android.settings.TrustAgentSettings"/>

        <CheckBoxPreference android:key="toggle_install_applications"
                android:title="@string/install_applications"
                android:summaryOff="@string/install_unknown_applications"
@@ -64,7 +58,6 @@
                android:summaryOff="@string/verify_applications_summary"
                android:summaryOn="@string/verify_applications_summary"
                android:persistent="false" />

    </PreferenceCategory>

    <PreferenceCategory android:key="credentials_management"
@@ -99,4 +92,14 @@
                    android:targetClass="com.android.settings.CredentialStorage"/>
        </Preference>
    </PreferenceCategory>

    <PreferenceCategory android:key="advanced_security"
            android:title="@string/advanced_security_title"
            android:persistent="false">
        <Preference android:key="manage_trust_agents"
                android:title="@string/manage_trust_agents"
                android:summary="@string/manage_trust_agents_summary"
                android:persistent="false"
                android:fragment="com.android.settings.AdvancedSecuritySettings"/>
    </PreferenceCategory>
</PreferenceScreen>
+9 −70
Original line number Diff line number Diff line
@@ -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);
+52 −2
Original line number Diff line number Diff line
@@ -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() {
@@ -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();
    }
Loading