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

Commit bde12fd4 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Hook up camera toggle QS tile to SensorPrivacyManager

Bug: 162549680
Test: Toggled tile and looked at 'dumpsys sensor_privacy`
Change-Id: I8b734adf3df7ef57b7c5c88f4b8fabe6ad60b96f
parent da6d30ab
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -3512,6 +3512,17 @@ public abstract class PackageManager {
    @SdkConstant(SdkConstantType.FEATURE)
    public static final String FEATURE_TUNER = "android.hardware.tv.tuner";

    /**
     * Feature for {@link #getSystemAvailableFeatures} and
     * {@link #hasSystemFeature}: The device supports a enabling/disabling sensor privacy for
     * camera. When sensory privacy for the camera is enabled no camera data is send to clients,
     * e.g. the view finder in a camera app would appear blank.
     *
     * @hide
     */
    @SdkConstant(SdkConstantType.FEATURE)
    public static final String FEATURE_CAMERA_TOGGLE = "android.hardware.camera.toggle";

    /**
     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device has
     * the necessary changes to support app enumeration.
+29 −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.
  -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportHeight="24">
    <path
        android:pathData="m18,12c-2.75,0 -5,2.25 -5,5 0,2.75 2.25,5 5,5 2.75,0 5,-2.25 5,-5 0,-2.75 -2.1667,-5 -5,-5zM15.5,17.8333h5v-1.6666h-5z"
        android:fillColor="#30302a"
        android:fillType="evenOdd"/>
    <path
        android:pathData="m16.4,5.5004h-2.536l-1.464,-1.6H7.6l-1.464,1.6H3.6c-0.88,0 -1.6,0.72 -1.6,1.6v9.6c0,0.88 0.72,1.6 1.6,1.6h8.5413C12.0488,17.8817 12,17.4465 12,17c0,-0.1005 0.0025,-0.2004 0.0073,-0.2996H3.6V7.1004H16.4V11.2157C16.9094,11.0751 17.4459,11 18,11V7.1004c0,-0.88 -0.72,-1.6 -1.6,-1.6zM6.8,11.9004c0,-1.768 1.432,-3.2 3.2,-3.2 1.768,0 3.2,1.432 3.2,3.2 0,1.768 -1.432,3.2 -3.2,3.2 -1.768,0 -3.2,-1.432 -3.2,-3.2z"
        android:fillColor="#30302a"
        android:fillType="evenOdd"/>
</vector>
+2 −0
Original line number Diff line number Diff line
@@ -821,6 +821,8 @@
    <string name="quick_settings_location_label">Location</string>
    <!-- QuickSettings: Location (Off) [CHAR LIMIT=NONE] -->
    <string name="quick_settings_location_off_label">Location Off</string>
    <!-- QuickSettings: Camera [CHAR LIMIT=NONE] -->
    <string name="quick_settings_camera_label">Block Camera</string>
    <!-- QuickSettings: Media device [CHAR LIMIT=NONE] -->
    <string name="quick_settings_media_device_label">Media device</string>
    <!-- QuickSettings: RSSI [CHAR LIMIT=NONE] -->
+12 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME
import static com.android.systemui.Dependency.LEAK_REPORT_EMAIL_NAME;

import android.content.Context;
import android.hardware.SensorPrivacyManager;
import android.os.Handler;
import android.os.PowerManager;

@@ -62,6 +63,8 @@ import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.DeviceProvisionedControllerImpl;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.SensorPrivacyController;
import com.android.systemui.statusbar.policy.SensorPrivacyControllerImpl;

import javax.inject.Named;

@@ -116,6 +119,15 @@ public abstract class SystemUIDefaultModule {
        return bC;
    }

    @Provides
    @SysUISingleton
    static SensorPrivacyController provideSensorPrivacyController(
            SensorPrivacyManager sensorPrivacyManager) {
        SensorPrivacyController spC = new SensorPrivacyControllerImpl(sensorPrivacyManager);
        spC.init();
        return spC;
    }

    @Binds
    @SysUISingleton
    public abstract QSFactory bindQSFactory(QSFactoryImpl qsFactoryImpl);
+26 −22
Original line number Diff line number Diff line
@@ -16,11 +16,12 @@

package com.android.systemui.qs.tiles;

import android.content.Context;
import static com.android.systemui.DejankUtils.whitelistIpcs;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.provider.DeviceConfig;
import android.service.quicksettings.Tile;
import android.widget.Switch;

@@ -38,7 +39,8 @@ import com.android.systemui.statusbar.policy.CameraToggleController;

import javax.inject.Inject;

public class CameraToggleTile extends QSTileImpl<QSTile.BooleanState> {
public class CameraToggleTile extends QSTileImpl<QSTile.BooleanState> implements
        CameraToggleController.Callback {

    private CameraToggleController mCameraToggleController;

@@ -54,7 +56,15 @@ public class CameraToggleTile extends QSTileImpl<QSTile.BooleanState> {
        super(host, backgroundLooper, mainHandler, metricsLogger, statusBarStateController,
                activityStarter, qsLogger);
        mCameraToggleController = cameraToggleController;
        mCameraToggleController.addCallback((b) -> refreshState());
        mCameraToggleController.observe(getLifecycle(), this);
    }

    @Override
    public boolean isAvailable() {
        return /*getHost().getContext().getPackageManager().hasSystemFeature(FEATURE_CAMERA_TOGGLE)
                && */whitelistIpcs(() -> DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
                "camera_toggle_enabled",
                false));
    }

    @Override
@@ -64,21 +74,18 @@ public class CameraToggleTile extends QSTileImpl<QSTile.BooleanState> {

    @Override
    protected void handleClick() {
        mCameraToggleController.setCameraEnabled(!mCameraToggleController.isCameraEnabled());
        mCameraToggleController.setCameraBlocked(!mCameraToggleController.isCameraBlocked());
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        state.icon = new CameraToggleTileIcon();
        state.state = mCameraToggleController.isCameraEnabled()
                ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
        state.value = mCameraToggleController.isCameraEnabled();
        state.label = "Camera";
        if (!mCameraToggleController.isCameraAvailable()) {
            state.secondaryLabel = "Currently in use";
        } else {
            state.secondaryLabel = null;
        }
        boolean isBlocked = arg == null ? mCameraToggleController.setCameraBlocked()
                : (boolean) arg;

        state.icon = ResourceIcon.get(R.drawable.ic_camera_blocked);
        state.state = isBlocked ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
        state.value = isBlocked;
        state.label = getTileLabel();
        state.handlesLongClick = false;
        state.contentDescription = state.label;
        state.expandedAccessibilityClassName = Switch.class.getName();
@@ -96,14 +103,11 @@ public class CameraToggleTile extends QSTileImpl<QSTile.BooleanState> {

    @Override
    public CharSequence getTileLabel() {
        return "Camera";
        return mContext.getString(R.string.quick_settings_camera_label);
    }

    class CameraToggleTileIcon extends Icon {

    @Override
        public Drawable getDrawable(Context context) {
            return context.getDrawable(R.drawable.ic_camera);
        }
    public void onCameraBlockedChanged(boolean enable) {
        refreshState(enable);
    }
}
Loading