From 3a665ac5ecf601f371ba8b17e309be554b3e67d4 Mon Sep 17 00:00:00 2001 From: Michael Groover Date: Tue, 19 Mar 2019 19:13:17 -0700 Subject: [PATCH] Add Sensors Off QS developer tile This CL will replace the SensorPrivacyTile with a new tile that can be enabled from the developer settings. When this new tile is enabled only the camera, mic, and sensors controlled by the SensorManager will be disabled; the location and airplane mode tiles will not be modified. The user will be notified when this tile is enabled with the sensors off icon in the status bar. Fixes: 126618519 Test: Manually verified the Sensors Off tile was available in the QS page after being enabled from the developer settings. Change-Id: I028aa1c836b00e6a8d129e46a925d2d2c2d61759 --- AndroidManifest.xml | 11 +++++ res/drawable/tile_icon_sensors_off.xml | 39 +++++++++++++++ res/values/strings.xml | 3 ++ .../development/qstile/DevelopmentTiles.java | 48 ++++++++++++++++++- 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 res/drawable/tile_icon_sensors_off.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4bb1a8c530a..9929f8b27a5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2958,6 +2958,17 @@ + + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index aa43f12f4b6..9e3bc4b9094 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -9769,6 +9769,9 @@ Winscope Trace + + Sensors Off + Work profile settings diff --git a/src/com/android/settings/development/qstile/DevelopmentTiles.java b/src/com/android/settings/development/qstile/DevelopmentTiles.java index 5edbc7031ff..bb791abef81 100644 --- a/src/com/android/settings/development/qstile/DevelopmentTiles.java +++ b/src/com/android/settings/development/qstile/DevelopmentTiles.java @@ -16,9 +16,12 @@ package com.android.settings.development.qstile; +import android.app.settings.SettingsEnums; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; +import android.hardware.SensorPrivacyManager; +import android.app.KeyguardManager; import android.os.IBinder; import android.os.Parcel; import android.os.RemoteException; @@ -38,6 +41,8 @@ import androidx.annotation.VisibleForTesting; import com.android.internal.app.LocalePicker; import com.android.internal.statusbar.IStatusBarService; +import com.android.settings.overlay.FeatureFactory; +import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.development.DevelopmentSettingsEnabler; import com.android.settingslib.development.SystemPropPoker; @@ -273,4 +278,45 @@ public abstract class DevelopmentTiles extends TileService { } } } -} \ No newline at end of file + + /** + * Tile to toggle sensors off to control camera, mic, and sensors managed by the SensorManager. + */ + public static class SensorsOff extends DevelopmentTiles { + private Context mContext; + private SensorPrivacyManager mSensorPrivacyManager; + private KeyguardManager mKeyguardManager; + private MetricsFeatureProvider mMetricsFeatureProvider; + private boolean mIsEnabled; + + @Override + public void onCreate() { + super.onCreate(); + mContext = getApplicationContext(); + mSensorPrivacyManager = (SensorPrivacyManager) mContext.getSystemService( + Context.SENSOR_PRIVACY_SERVICE); + mIsEnabled = mSensorPrivacyManager.isSensorPrivacyEnabled(); + mMetricsFeatureProvider = FeatureFactory.getFactory( + mContext).getMetricsFeatureProvider(); + mKeyguardManager = (KeyguardManager) mContext.getSystemService( + Context.KEYGUARD_SERVICE); + } + + @Override + protected boolean isEnabled() { + return mIsEnabled; + } + + @Override + public void setIsEnabled(boolean isEnabled) { + // Don't allow sensors to be reenabled from the lock screen. + if (mIsEnabled && mKeyguardManager.isKeyguardLocked()) { + return; + } + mMetricsFeatureProvider.action(getApplicationContext(), SettingsEnums.QS_SENSOR_PRIVACY, + isEnabled); + mIsEnabled = isEnabled; + mSensorPrivacyManager.setSensorPrivacy(isEnabled); + } + } +}