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

Commit 175ca1c4 authored by Evan Severson's avatar Evan Severson
Browse files

Update the settings privacy page to the latest mocks

Add the mic and camera toggles to the page. Also create an helper class
to keep binder calls to the system_server at a minimum.

Test: make RunSettingsRoboTests
Test: atest SettingsUnitTests
Test: Manual
Bug: 183985427
Change-Id: Iff6ee1c9a2c30095307f636decbcfcf298ed31b0
parent c077b490
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -13285,4 +13285,11 @@
    <!-- Summary for UWB preference when airplane mode is disabled. [CHAR_LIMIT=NONE]-->
    <string name="uwb_settings_summary_airplane_mode">Turn off airplane mode to use UWB </string>
    <!-- Label for the camera use toggle [CHAR LIMIT=40] -->
    <string name="camera_toggle_title">Camera access</string>
    <!-- Label for the camera use toggle [CHAR LIMIT=40] -->
    <string name="mic_toggle_title">Microphone access</string>
    <!-- Describes what is affected by the camera or mic toggle [CHAR LIMIT=NONE] -->
    <string name="sensor_toggle_description">For all apps and services</string>
</resources>
+24 −10
Original line number Diff line number Diff line
@@ -48,26 +48,40 @@
        <intent android:action="android.intent.action.REVIEW_ACCESSIBILITY_SERVICES"/>
    </Preference>

    <!-- App permissions -->
    <Preference
        android:key="privacy_manage_perms"
        android:title="@string/app_permissions"
        android:summary="@string/runtime_permissions_summary_control_app_access"
        settings:allowDividerAbove="true"
        settings:searchable="false">
        <intent android:action="android.intent.action.MANAGE_PERMISSIONS"/>
    </Preference>

    <!-- Permissions usage -->
    <Preference
        android:key="privacy_permissions_usage"
        android:title="@string/permissions_usage_title"
        android:summary="@string/permissions_usage_summary"
        settings:allowDividerAbove="true"
        settings:searchable="false"
        settings:controller="com.android.settings.privacy.PrivacyHubPreferenceController">
        <intent android:action="android.intent.action.REVIEW_PERMISSION_USAGE"/>
    </Preference>

    <!-- App permissions -->
    <Preference
        android:key="privacy_manage_perms"
        android:title="@string/app_permissions"
        android:summary="@string/runtime_permissions_summary_control_app_access"
        settings:searchable="false">
        <intent android:action="android.intent.action.MANAGE_PERMISSIONS"/>
    </Preference>

    <!-- Camera toggle -->
    <SwitchPreference
        android:key="privacy_camera_toggle"
        android:title="@string/camera_toggle_title"
        android:summary="@string/sensor_toggle_description"
        settings:controller="com.android.settings.privacy.CameraToggleController"/>

    <!-- Microphone toggle -->
    <SwitchPreference
        android:key="privacy_mic_toggle"
        android:title="@string/mic_toggle_title"
        android:summary="@string/sensor_toggle_description"
        settings:controller="com.android.settings.privacy.MicToggleController"/>

    <!-- Show passwords -->
    <SwitchPreference
        android:key="show_password"
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.privacy;

import static com.android.settings.utils.SensorPrivacyManagerHelper.CAMERA;

import android.content.Context;
import android.provider.DeviceConfig;

/**
 * Controller for microphone toggle
 */
public class CameraToggleController extends SensorToggleController {
    public CameraToggleController(Context context, String preferenceKey) {
        super(context, preferenceKey);
    }

    @Override
    public int getSensor() {
        return CAMERA;
    }

    @Override
    public int getAvailabilityStatus() {
        return mSensorPrivacyManagerHelper.supportsSensorToggle(getSensor())
                && DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, "camera_toggle_enabled",
                true) ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
    }
}
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.privacy;

import static com.android.settings.utils.SensorPrivacyManagerHelper.MICROPHONE;

import android.content.Context;
import android.provider.DeviceConfig;

/**
 * Controller for camera toggle
 */
public class MicToggleController extends SensorToggleController {
    public MicToggleController(Context context, String preferenceKey) {
        super(context, preferenceKey);
    }

    @Override
    public int getSensor() {
        return MICROPHONE;
    }

    @Override
    public int getAvailabilityStatus() {
        return mSensorPrivacyManagerHelper.supportsSensorToggle(getSensor())
                && DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, "mic_toggle_enabled",
                true) ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
    }

}
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.privacy;

import android.content.Context;

import androidx.preference.PreferenceScreen;

import com.android.settings.core.TogglePreferenceController;
import com.android.settings.utils.SensorPrivacyManagerHelper;

import java.util.concurrent.Executor;

/**
 * Base class for sensor toggle controllers
 */
public abstract class SensorToggleController extends TogglePreferenceController {

    protected final SensorPrivacyManagerHelper mSensorPrivacyManagerHelper;
    private final Executor mCallbackExecutor;

    public SensorToggleController(Context context, String preferenceKey) {
        super(context, preferenceKey);
        mSensorPrivacyManagerHelper = SensorPrivacyManagerHelper.getInstance(context);
        mCallbackExecutor = context.getMainExecutor();
    }

    /**
     * The sensor id, defined in SensorPrivacyManagerHelper, which an implementing class controls
     */
    public abstract int getSensor();

    @Override
    public boolean isChecked() {
        return !mSensorPrivacyManagerHelper.isSensorBlocked(getSensor());
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        mSensorPrivacyManagerHelper.setSensorBlocked(getSensor(), !isChecked);
        return true;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mSensorPrivacyManagerHelper.addSensorBlockedListener(
                getSensor(),
                (sensor, blocked) -> updateState(screen.findPreference(mPreferenceKey)),
                mCallbackExecutor);
    }
}
Loading