EBS: Don't disable vibration when accessibility is on
Note the unit test is a bit stale; I'll fix that separately, which is tracked in b/79123174. Bug: 78174280 Test: Manual test with accessibility ON/OFF Change-Id: I60aa130bbda7d7cd5bfa1146e8ab1c2b63f2c60a
This commit is contained in:
@@ -29,6 +29,7 @@ import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.KeyValueListParser;
|
||||
import android.util.Slog;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
@@ -98,7 +99,14 @@ public class BatterySaverPolicy extends ContentObserver {
|
||||
* @see #KEY_VIBRATION_DISABLED
|
||||
*/
|
||||
@GuardedBy("mLock")
|
||||
private boolean mVibrationDisabled;
|
||||
private boolean mVibrationDisabledConfig;
|
||||
|
||||
/**
|
||||
* Whether vibration should *really* be disabled -- i.e. {@link #mVibrationDisabledConfig}
|
||||
* is true *and* {@link #mAccessibilityEnabled} is false.
|
||||
*/
|
||||
@GuardedBy("mLock")
|
||||
private boolean mVibrationDisabledEffective;
|
||||
|
||||
/**
|
||||
* {@code true} if animation is disabled in battery saver mode.
|
||||
@@ -225,6 +233,9 @@ public class BatterySaverPolicy extends ContentObserver {
|
||||
@GuardedBy("mLock")
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private AccessibilityManager mAccessibilityManager;
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private final List<BatterySaverPolicyListener> mListeners = new ArrayList<>();
|
||||
|
||||
@@ -246,6 +257,12 @@ public class BatterySaverPolicy extends ContentObserver {
|
||||
@GuardedBy("mLock")
|
||||
private ArrayMap<String, String> mFilesForNoninteractive;
|
||||
|
||||
/**
|
||||
* Whether accessibility is enabled or not.
|
||||
*/
|
||||
@GuardedBy("mLock")
|
||||
private boolean mAccessibilityEnabled;
|
||||
|
||||
public interface BatterySaverPolicyListener {
|
||||
void onBatterySaverPolicyChanged(BatterySaverPolicy policy);
|
||||
}
|
||||
@@ -259,10 +276,16 @@ public class BatterySaverPolicy extends ContentObserver {
|
||||
mContext = context;
|
||||
mContentResolver = context.getContentResolver();
|
||||
|
||||
mAccessibilityManager = context.getSystemService(AccessibilityManager.class);
|
||||
|
||||
mContentResolver.registerContentObserver(Settings.Global.getUriFor(
|
||||
Settings.Global.BATTERY_SAVER_CONSTANTS), false, this);
|
||||
mContentResolver.registerContentObserver(Settings.Global.getUriFor(
|
||||
Global.BATTERY_SAVER_DEVICE_SPECIFIC_CONSTANTS), false, this);
|
||||
|
||||
mAccessibilityManager.addAccessibilityStateChangeListener((enabled) -> {
|
||||
refreshSettings();
|
||||
});
|
||||
}
|
||||
onChange(true, null);
|
||||
}
|
||||
@@ -289,6 +312,10 @@ public class BatterySaverPolicy extends ContentObserver {
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
refreshSettings();
|
||||
}
|
||||
|
||||
private void refreshSettings() {
|
||||
final BatterySaverPolicyListener[] listeners;
|
||||
synchronized (mLock) {
|
||||
// Load the non-device-specific setting.
|
||||
@@ -340,7 +367,7 @@ public class BatterySaverPolicy extends ContentObserver {
|
||||
Slog.wtf(TAG, "Bad battery saver constants: " + setting);
|
||||
}
|
||||
|
||||
mVibrationDisabled = parser.getBoolean(KEY_VIBRATION_DISABLED, true);
|
||||
mVibrationDisabledConfig = parser.getBoolean(KEY_VIBRATION_DISABLED, true);
|
||||
mAnimationDisabled = parser.getBoolean(KEY_ANIMATION_DISABLED, false);
|
||||
mSoundTriggerDisabled = parser.getBoolean(KEY_SOUNDTRIGGER_DISABLED, true);
|
||||
mFullBackupDeferred = parser.getBoolean(KEY_FULLBACKUP_DEFERRED, true);
|
||||
@@ -375,12 +402,18 @@ public class BatterySaverPolicy extends ContentObserver {
|
||||
mFilesForNoninteractive = (new CpuFrequencies()).parseString(
|
||||
parser.getString(KEY_CPU_FREQ_NONINTERACTIVE, "")).toSysFileMap();
|
||||
|
||||
// Update the effective policy.
|
||||
mAccessibilityEnabled = mAccessibilityManager.isEnabled();
|
||||
|
||||
mVibrationDisabledEffective = mVibrationDisabledConfig
|
||||
&& !mAccessibilityEnabled; // Don't disable vibration when accessibility is on.
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (mForceAllAppsStandby) sb.append("A");
|
||||
if (mForceBackgroundCheck) sb.append("B");
|
||||
|
||||
if (mVibrationDisabled) sb.append("v");
|
||||
if (mVibrationDisabledEffective) sb.append("v");
|
||||
if (mAnimationDisabled) sb.append("a");
|
||||
if (mSoundTriggerDisabled) sb.append("s");
|
||||
if (mFullBackupDeferred) sb.append("F");
|
||||
@@ -446,7 +479,7 @@ public class BatterySaverPolicy extends ContentObserver {
|
||||
return builder.setBatterySaverEnabled(mSoundTriggerDisabled)
|
||||
.build();
|
||||
case ServiceType.VIBRATION:
|
||||
return builder.setBatterySaverEnabled(mVibrationDisabled)
|
||||
return builder.setBatterySaverEnabled(mVibrationDisabledEffective)
|
||||
.build();
|
||||
case ServiceType.FORCE_ALL_APPS_STANDBY:
|
||||
return builder.setBatterySaverEnabled(mForceAllAppsStandby)
|
||||
@@ -504,7 +537,9 @@ public class BatterySaverPolicy extends ContentObserver {
|
||||
pw.println(" value: " + mDeviceSpecificSettings);
|
||||
|
||||
pw.println();
|
||||
pw.println(" " + KEY_VIBRATION_DISABLED + "=" + mVibrationDisabled);
|
||||
pw.println(" mAccessibilityEnabled=" + mAccessibilityEnabled);
|
||||
pw.println(" " + KEY_VIBRATION_DISABLED + ":config=" + mVibrationDisabledConfig);
|
||||
pw.println(" " + KEY_VIBRATION_DISABLED + ":effective=" + mVibrationDisabledEffective);
|
||||
pw.println(" " + KEY_ANIMATION_DISABLED + "=" + mAnimationDisabled);
|
||||
pw.println(" " + KEY_FULLBACKUP_DEFERRED + "=" + mFullBackupDeferred);
|
||||
pw.println(" " + KEY_KEYVALUE_DEFERRED + "=" + mKeyValueBackupDeferred);
|
||||
|
||||
Reference in New Issue
Block a user