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

Commit 7e24127f authored by Aaron Liu's avatar Aaron Liu Committed by Android (Google) Code Review
Browse files

Merge "Home Controls: Add Device Controls settings" into tm-dev

parents 7565dfb9 e0f4e795
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -13343,6 +13343,10 @@
    <string name="lockscreen_privacy_controls_setting_toggle">Show device controls</string>
    <!-- Device controls summary [CHAR LIMIT=NONE] -->
    <string name="lockscreen_privacy_controls_summary">Access controls when locked</string>
    <!-- Trivial Device controls toggle name [CHAR LIMIT=60] -->
    <string name="lockscreen_trivial_controls_setting_toggle">Control from locked device</string>
    <!-- Trivial Device controls summary [CHAR LIMIT=NONE] -->
    <string name="lockscreen_trivial_controls_summary">Control external devices without unlocking your phone or tablet if allowed by the device controls app</string>
    <!-- Lockscreen double-line clock summary [CHAR LIMIT=NONE] -->
    <string name="lockscreen_double_line_clock_summary">Show double-line clock when available</string>
    <!-- Lockscreen double-line clock toggle [CHAR LIMIT=60] -->
+7 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@
            settings:keywords="@string/keywords_lock_screen_notif"/>

        <SwitchPreference
            android:key="security_dispaly_lockscreen_bypass"
            android:key="security_display_lockscreen_bypass"
            android:title="@string/lockscreen_bypass_title"
            android:summary="@string/lockscreen_bypass_summary"
            settings:searchable="false"
@@ -63,6 +63,12 @@
            android:summary="@string/lockscreen_privacy_controls_summary"
            settings:controller="com.android.settings.display.ControlsPrivacyPreferenceController" />

        <SwitchPreference
            android:key="lockscreen_trivial_controls_switch"
            android:title="@string/lockscreen_trivial_controls_setting_toggle"
            android:summary="@string/lockscreen_trivial_controls_summary"
            settings:controller="com.android.settings.display.ControlsTrivialPrivacyPreferenceController"/>

        <SwitchPreference
            android:key="lockscreen_double_line_clock_switch"
            android:title="@string/lockscreen_double_line_clock_setting_toggle"
+3 −0
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ import com.android.settings.overlay.FeatureFactory;

/**
 * Preference for showing/hiding sensitive device controls content while the device is locked.
 *
 * Note that ControlsTrivialPrivacyPreferenceController depends on the preferenceKey
 * of this controller.
 */
public class ControlsPrivacyPreferenceController extends TogglePreferenceController {

+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.display;

import android.content.Context;
import android.provider.Settings;

import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

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

/**
 * Preference for requiring authorization to use home controls for certain devices.
 */
public class ControlsTrivialPrivacyPreferenceController extends TogglePreferenceController {

    private static final String SETTING_KEY = Settings.Secure.LOCKSCREEN_ALLOW_TRIVIAL_CONTROLS;
    private static final String DEPENDENCY_SETTING_KEY = Settings.Secure.LOCKSCREEN_SHOW_CONTROLS;

    public ControlsTrivialPrivacyPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
    }

    @Override
    public boolean isChecked() {
        return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 0) != 0;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        return Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY,
                isChecked ? 1 : 0);
    }

    @Override
    public CharSequence getSummary() {
        return mContext.getText(R.string.lockscreen_trivial_controls_summary);
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        preference.setEnabled(getAvailabilityStatus() != DISABLED_DEPENDENT_SETTING);
        refreshSummary(preference);
    }

    @Override
    public int getSliceHighlightMenuRes() {
        return R.string.menu_key_display;
    }

    @Override
    public int getAvailabilityStatus() {
        return showDeviceControlsSettingsEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
    }

    private boolean showDeviceControlsSettingsEnabled() {
        return Settings.Secure.getInt(mContext.getContentResolver(), DEPENDENCY_SETTING_KEY, 0)
                != 0;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        Preference currentPreference = screen.findPreference(getPreferenceKey());
        currentPreference.setDependency("lockscreen_privacy_controls_switch");
    }
}
+28 −0
Original line number Diff line number Diff line
@@ -21,8 +21,13 @@ import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROF

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.database.ContentObserver;
import android.hardware.display.AmbientDisplayConfiguration;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;

import androidx.annotation.VisibleForTesting;

@@ -68,6 +73,8 @@ public class LockscreenDashboardFragment extends DashboardFragment

    private AmbientDisplayConfiguration mConfig;
    private OwnerInfoPreferenceController mOwnerInfoPreferenceController;
    @VisibleForTesting
    ContentObserver mControlsContentObserver;

    @Override
    public int getMetricsCategory() {
@@ -106,6 +113,27 @@ public class LockscreenDashboardFragment extends DashboardFragment
        use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context));
        use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context));
        use(PickupGesturePreferenceController.class).setConfig(getConfig(context));

        mControlsContentObserver = new ContentObserver(
                new Handler(Looper.getMainLooper())) {
            @Override
            public void onChange(boolean selfChange, Uri uri) {
                super.onChange(selfChange, uri);
                updatePreferenceStates();
            }
        };
        context.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.LOCKSCREEN_SHOW_CONTROLS),
                false /* notifyForDescendants */, mControlsContentObserver);
    }

    @Override
    public void onDetach() {
        if (mControlsContentObserver != null) {
            getContext().getContentResolver().unregisterContentObserver(mControlsContentObserver);
            mControlsContentObserver = null;
        }
        super.onDetach();
    }

    @Override
Loading