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

Commit 2a5dd0e2 authored by Evan Severson's avatar Evan Severson
Browse files

Disable the mic/cam toggles when admin disallows

Test: Use test DPC app
Bug: 184927615
Change-Id: Ib3825967b2e7ddb6d4768abbc2e17fd39b936371
parent 150ed0b0
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -64,14 +64,14 @@
    </Preference>

    <!-- Camera toggle -->
    <SwitchPreference
    <com.android.settingslib.RestrictedSwitchPreference
        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
    <com.android.settingslib.RestrictedSwitchPreference
        android:key="privacy_mic_toggle"
        android:title="@string/mic_toggle_title"
        android:summary="@string/sensor_toggle_description"
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.privacy;

import static android.os.UserManager.DISALLOW_CAMERA_TOGGLE;

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

import android.content.Context;
@@ -40,4 +42,9 @@ public class CameraToggleController extends SensorToggleController {
                && DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, "camera_toggle_enabled",
                true) ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
    }

    @Override
    protected String getRestriction() {
        return DISALLOW_CAMERA_TOGGLE;
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.privacy;

import static android.os.UserManager.DISALLOW_MICROPHONE_TOGGLE;

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

import android.content.Context;
@@ -41,4 +43,8 @@ public class MicToggleController extends SensorToggleController {
                true) ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
    }

    @Override
    protected String getRestriction() {
        return DISALLOW_MICROPHONE_TOGGLE;
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import androidx.preference.PreferenceScreen;

import com.android.settings.core.TogglePreferenceController;
import com.android.settings.utils.SensorPrivacyManagerHelper;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedSwitchPreference;

import java.util.concurrent.Executor;

@@ -44,6 +46,10 @@ public abstract class SensorToggleController extends TogglePreferenceController
     */
    public abstract int getSensor();

    protected String getRestriction() {
        return null;
    }

    @Override
    public boolean isChecked() {
        return !mSensorPrivacyManagerHelper.isSensorBlocked(getSensor());
@@ -58,6 +64,14 @@ public abstract class SensorToggleController extends TogglePreferenceController
    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);

        RestrictedSwitchPreference preference =
                (RestrictedSwitchPreference) screen.findPreference(getPreferenceKey());
        if (preference != null) {
            preference.setDisabledByAdmin(RestrictedLockUtilsInternal
                    .checkIfRestrictionEnforced(mContext, getRestriction(), mContext.getUserId()));
        }

        mSensorPrivacyManagerHelper.addSensorBlockedListener(
                getSensor(),
                (sensor, blocked) -> updateState(screen.findPreference(mPreferenceKey)),