summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
diff options
context:
space:
mode:
authorAbel Tesfaye <tesfaye@google.com>2021-06-03 23:19:44 +0000
committerAbel Tesfaye <tesfaye@google.com>2021-06-10 17:31:39 +0000
commit5131c691b54f8880cf48bf1ba7c9abfd660f7b11 (patch)
tree2aa6a799a7db76e3c05ca64b62f81a526901e18c /src/com/android/settings/display/SmartAutoRotatePreferenceController.java
parentc89b3afef5fe9efe22e7595abda3049166de8283 (diff)
downloadpackages_apps_Settings-5131c691b54f8880cf48bf1ba7c9abfd660f7b11.tar.gz
packages_apps_Settings-5131c691b54f8880cf48bf1ba7c9abfd660f7b11.tar.bz2
packages_apps_Settings-5131c691b54f8880cf48bf1ba7c9abfd660f7b11.zip
Check in auto rotate settings summary for rotation resolver service
Fixes issue where summary text would not properly describe the state of camera based auto rotation when permission is missing or when another state is blocking the feature Bug: 190095500 Test: locally with flame & make RunSettingsRoboTests -j$(nproc) ROBOTEST_FILTER=SmartAutoRotatePreferenceControllerTest Change-Id: I7609ca87658e08831f3bc37c839f00f63946ddec
Diffstat (limited to 'src/com/android/settings/display/SmartAutoRotatePreferenceController.java')
-rw-r--r--src/com/android/settings/display/SmartAutoRotatePreferenceController.java46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/com/android/settings/display/SmartAutoRotatePreferenceController.java b/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
index 8c25a05ca3..f8d5f96786 100644
--- a/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
+++ b/src/com/android/settings/display/SmartAutoRotatePreferenceController.java
@@ -16,15 +16,25 @@
package com.android.settings.display;
+import static android.hardware.SensorPrivacyManager.Sensors.CAMERA;
import static android.provider.Settings.Secure.CAMERA_AUTOROTATE;
+import static com.android.settings.display.SmartAutoRotateController.hasSufficientPermission;
+import static com.android.settings.display.SmartAutoRotateController.isRotationResolverServiceAvailable;
+
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.hardware.SensorPrivacyManager;
+import android.os.PowerManager;
import android.os.UserHandle;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.view.RotationPolicy;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
@@ -41,8 +51,21 @@ public class SmartAutoRotatePreferenceController extends BasePreferenceControlle
private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
private Preference mPreference;
+ private final SensorPrivacyManager mPrivacyManager;
+ private final PowerManager mPowerManager;
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ refreshSummary(mPreference);
+ }
+ };
+
public SmartAutoRotatePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
+ mPrivacyManager = SensorPrivacyManager.getInstance(context);
+ mPrivacyManager
+ .addSensorPrivacyListener(CAMERA, (sensor, enabled) -> refreshSummary(mPreference));
+ mPowerManager = context.getSystemService(PowerManager.class);
}
@Override
@@ -59,6 +82,8 @@ public class SmartAutoRotatePreferenceController extends BasePreferenceControlle
@Override
public void onStart() {
+ mContext.registerReceiver(mReceiver,
+ new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
if (mRotationPolicyListener == null) {
mRotationPolicyListener = new RotationPolicy.RotationPolicyListener() {
@Override
@@ -75,12 +100,27 @@ public class SmartAutoRotatePreferenceController extends BasePreferenceControlle
@Override
public void onStop() {
+ mContext.unregisterReceiver(mReceiver);
if (mRotationPolicyListener != null) {
RotationPolicy.unregisterRotationPolicyListener(mContext,
mRotationPolicyListener);
}
}
+ /**
+ * Need this because all controller tests use Roboelectric. No easy way to mock this service,
+ * so we mock the call we need
+ */
+ @VisibleForTesting
+ boolean isCameraLocked() {
+ return mPrivacyManager.isSensorPrivacyEnabled(SensorPrivacyManager.Sensors.CAMERA);
+ }
+
+ @VisibleForTesting
+ boolean isPowerSaveMode() {
+ return mPowerManager.isPowerSaveMode();
+ }
+
@Override
public CharSequence getSummary() {
int activeStringId = R.string.auto_rotate_option_off;
@@ -89,7 +129,11 @@ public class SmartAutoRotatePreferenceController extends BasePreferenceControlle
mContext.getContentResolver(),
CAMERA_AUTOROTATE,
0, UserHandle.USER_CURRENT);
- activeStringId = cameraRotate == 1 ? R.string.auto_rotate_option_face_based
+ activeStringId = cameraRotate == 1 && isRotationResolverServiceAvailable(mContext)
+ && hasSufficientPermission(mContext)
+ && !isCameraLocked()
+ && !isPowerSaveMode()
+ ? R.string.auto_rotate_option_face_based
: R.string.auto_rotate_option_on;
}
return mContext.getString(activeStringId);