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

Commit 0b47bb4b authored by Fan Zhang's avatar Fan Zhang
Browse files

Convert some security setting logic to PreferenceController

- Manage trust agent
- Show password
- Sim lock
- Screen pinning

Bug: 32953042
Test: robotests
Change-Id: I0c781a505238cae7a6643b701b750ca63a87a8a5
parent f314494f
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -63,8 +63,7 @@
    </PreferenceCategory>

    <Preference android:key="sim_lock_settings"
                android:title="@string/sim_lock_settings_category"
                android:persistent="false">
                android:title="@string/sim_lock_settings_category">

        <intent android:action="android.intent.action.MAIN"
                android:targetPackage="com.android.settings"
@@ -86,7 +85,7 @@
    <Preference
        android:key="screen_pinning_settings"
        android:title="@string/screen_pinning_title"
        android:summary="@string/switch_off_text"
        android:summary="@string/summary_placeholder"
        android:fragment="com.android.settings.security.ScreenPinningSettings"/>

    <Preference android:key="security_misc_usage_access"
+2 −2
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@
package com.android.settings.core;

import android.content.Context;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.TwoStatePreference;

/**
 * Abstract class that consolidates logic for updating toggle controllers.
@@ -45,7 +45,7 @@ public abstract class TogglePreferenceController extends BasePreferenceControlle

    @Override
    public final void updateState(Preference preference) {
        ((SwitchPreference) preference).setChecked(isChecked());
        ((TwoStatePreference) preference).setChecked(isChecked());
    }

    @Override
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.security;

import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;

public class ScreenPinningPreferenceController extends BasePreferenceController {

    private static final String KEY_SCREEN_PINNING = "screen_pinning_settings";

    public ScreenPinningPreferenceController(Context context) {
        super(context, KEY_SCREEN_PINNING);
    }

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        final Preference preference = screen.findPreference(getPreferenceKey());
        if (preference == null) {
            return;
        }
        if (Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
            preference.setSummary(
                    mContext.getString(R.string.switch_on_text));
        } else {
            preference.setSummary(
                    mContext.getString(R.string.switch_off_text));
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.support.v7.preference.PreferenceScreen;
import android.util.FeatureFlagUtils;

import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.FeatureFlags;
import com.android.settings.security.trustagent.TrustAgentManager;
import com.android.settingslib.drawer.DashboardCategory;
@@ -38,4 +39,9 @@ public interface SecurityFeatureProvider {

    /** Returns the {@link TrustAgentManager} bound to this {@link SecurityFeatureProvider}. */
    TrustAgentManager getTrustAgentManager();

    /**
     * Returns a {@link LockPatternUtils} instance bound to application context.
     */
    LockPatternUtils getLockPatternUtils(Context context);
}
+10 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Pair;

import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.security.trustagent.TrustAgentManager;
import com.android.settingslib.drawer.DashboardCategory;
@@ -43,6 +44,7 @@ import java.util.TreeMap;
public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {

    private TrustAgentManager mTrustAgentManager;
    private LockPatternUtils mLockPatternUtils;

    @VisibleForTesting
    static final Drawable DEFAULT_ICON = null;
@@ -195,4 +197,12 @@ public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
        }
        return mTrustAgentManager;
    }

    @Override
    public LockPatternUtils getLockPatternUtils(Context context) {
        if (mLockPatternUtils == null) {
            mLockPatternUtils = new LockPatternUtils(context.getApplicationContext());
        }
        return mLockPatternUtils;
    }
}
Loading