Skip to content

Commit 3a525e0

Browse files
darkobasjhonboy121
authored andcommitted
base: Add option to enable AOD on charging only [1/2]
@ idoybh edits: Adapted to A11's settings backup [jhonboy121]: adapt to A12 changes in DozeParameters. Also in the og commit DOZE_ALWAYS_ON was being read from System namespace instead of Secure, fixed it here. Make use of SettingsProxy utlity classes for settings / getting values Change-Id: I831583fde68de15788e3d7ecab55d864726d140f Commit message #2: base: check whether device is charging when alwaysOnChargingEnabled is called * Using settings for this is quite redundant. And if you toggle aod on charge after plugging in then aod won't turn on unless you unplug and plug again (since DOZE_ON_CHARGE_NOW is set only if aod on charge is enabled and device is plugged in" Signed-off-by: jhonboy121 <[email protected]> Commit message #3: base: fix deadlock between activity manager and power manager * Using the battery manager intent to query plugged in status was the root cause of deadlock, so inside power manager, user mIsPowered and setting value instead of using the intent based power status Signed-off-by: jhonboy121 <[email protected]> [jhonboy121]: adapted to A13 [ghostrider-reborn]: keep default behaviour in power manager Change-Id: Idebd1f0922b0db5a5349f551ca0ba9e0afc15678 Signed-off-by: jhonboy121 <[email protected]> Signed-off-by: Adithya R <[email protected]> Co-Authored-By: jhonboy121 <[email protected]>
1 parent dcc3930 commit 3a525e0

File tree

6 files changed

+45
-9
lines changed

6 files changed

+45
-9
lines changed

core/java/android/hardware/display/AmbientDisplayConfiguration.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
import android.annotation.TestApi;
2222
import android.content.Context;
23+
import android.content.Intent;
24+
import android.content.IntentFilter;
2325
import android.hardware.biometrics.Flags;
26+
import android.os.BatteryManager;
2427
import android.os.Build;
2528
import android.os.SystemProperties;
2629
import android.provider.Settings;
@@ -41,6 +44,7 @@
4144
@TestApi
4245
public class AmbientDisplayConfiguration {
4346
private static final String TAG = "AmbientDisplayConfig";
47+
4448
private final Context mContext;
4549
private final boolean mAlwaysOnByDefault;
4650
private final boolean mPickupGestureEnabledByDefault;
@@ -55,7 +59,8 @@ public class AmbientDisplayConfiguration {
5559
Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
5660
Settings.Secure.DOZE_WAKE_LOCK_SCREEN_GESTURE,
5761
Settings.Secure.DOZE_WAKE_DISPLAY_GESTURE,
58-
Settings.Secure.DOZE_TAP_SCREEN_GESTURE
62+
Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
63+
Settings.Secure.DOZE_ON_CHARGE
5964
};
6065

6166
/** Non-user configurable doze settings */
@@ -244,8 +249,32 @@ private boolean pulseOnLongPressAvailable() {
244249
*/
245250
@TestApi
246251
public boolean alwaysOnEnabled(int user) {
247-
return boolSetting(Settings.Secure.DOZE_ALWAYS_ON, user, mAlwaysOnByDefault ? 1 : 0)
248-
&& alwaysOnAvailable() && !accessibilityInversionEnabled(user);
252+
return alwaysOnEnabledSetting(user) || alwaysOnChargingEnabled(user);
253+
}
254+
255+
/** @hide */
256+
public boolean alwaysOnEnabledSetting(int user) {
257+
final boolean alwaysOnEnabled = Settings.Secure.getIntForUser(
258+
mContext.getContentResolver(), Settings.Secure.DOZE_ALWAYS_ON,
259+
mAlwaysOnByDefault ? 1 : 0, user) == 1;
260+
return alwaysOnEnabled && alwaysOnAvailable() && !accessibilityInversionEnabled(user);
261+
}
262+
263+
/** @hide */
264+
public boolean alwaysOnChargingEnabledSetting(int user) {
265+
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
266+
Settings.Secure.DOZE_ON_CHARGE, 0, user) == 1;
267+
}
268+
269+
private boolean alwaysOnChargingEnabled(int user) {
270+
if (alwaysOnChargingEnabledSetting(user)) {
271+
final Intent intent = mContext.registerReceiver(null,
272+
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
273+
if (intent != null) {
274+
return intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
275+
}
276+
}
277+
return false;
249278
}
250279

251280
/**

core/java/android/provider/Settings.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13560,6 +13560,12 @@ public static boolean putFloatForUser(ContentResolver cr, String name, float val
1356013560
*/
1356113561
public static final String DOZE_PICK_UP_GESTURE_AMBIENT = "doze_pick_up_gesture_ambient";
1356213562

13563+
/**
13564+
* Whether to enable DOZE only when charging
13565+
* @hide
13566+
*/
13567+
public static final String DOZE_ON_CHARGE = "doze_on_charge";
13568+
1356313569
/**
1356413570
* These entries are considered common between the personal and the managed profile,
1356513571
* since the managed profile doesn't get to change them.

packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ public class SecureSettings {
306306
Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE,
307307
Settings.Secure.BERRY_BLACK_THEME,
308308
Settings.Secure.DOZE_PICK_UP_GESTURE_AMBIENT,
309-
Settings.Secure.DOZE_TAP_GESTURE_AMBIENT
309+
Settings.Secure.DOZE_TAP_GESTURE_AMBIENT,
310+
Settings.Secure.DOZE_ON_CHARGE
310311
};
311312
}

packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,5 +482,6 @@ public class SecureSettingsValidators {
482482
VALIDATORS.put(Secure.BERRY_BLACK_THEME, BOOLEAN_VALIDATOR);
483483
VALIDATORS.put(Secure.DOZE_TAP_GESTURE_AMBIENT, BOOLEAN_VALIDATOR);
484484
VALIDATORS.put(Secure.DOZE_PICK_UP_GESTURE_AMBIENT, BOOLEAN_VALIDATOR);
485+
VALIDATORS.put(Secure.DOZE_ON_CHARGE, BOOLEAN_VALIDATOR);
485486
}
486487
}

packages/SystemUI/src/com/android/systemui/statusbar/phone/DozeParameters.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public class DozeParameters implements
9393
private final UserTracker mUserTracker;
9494
private final SecureSettings mSecureSettings;
9595

96-
private boolean mDozeAlwaysOn;
9796
private boolean mControlScreenOffAnimation;
9897
private boolean mIsQuickPickupEnabled;
9998

@@ -275,7 +274,8 @@ public long getWallpaperFadeOutDuration() {
275274
* @return {@code true} if enabled and available.
276275
*/
277276
public boolean getAlwaysOn() {
278-
return mDozeAlwaysOn && !mBatteryController.isAodPowerSave();
277+
return mAmbientDisplayConfiguration.alwaysOnEnabled(mUserTracker.getUserId())
278+
&& !mBatteryController.isAodPowerSave();
279279
}
280280

281281
/**
@@ -422,8 +422,6 @@ public String[] brightnessNames() {
422422

423423
@Override
424424
public void onTuningChanged(String key, String newValue) {
425-
mDozeAlwaysOn = mAmbientDisplayConfiguration.alwaysOnEnabled(mUserTracker.getUserId());
426-
427425
if (key.equals(Settings.Secure.DOZE_ALWAYS_ON)) {
428426
updateControlScreenOff();
429427
}

services/core/java/com/android/server/power/PowerManagerService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,8 @@ private void updateSettingsLocked() {
16251625
Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC);
16261626
mTheaterModeEnabled = Settings.Global.getInt(mContext.getContentResolver(),
16271627
Settings.Global.THEATER_MODE_ON, 0) == 1;
1628-
mAlwaysOnEnabled = mAmbientDisplayConfiguration.alwaysOnEnabled(UserHandle.USER_CURRENT);
1628+
mAlwaysOnEnabled =
1629+
mAmbientDisplayConfiguration.alwaysOnEnabledSetting(UserHandle.USER_CURRENT);
16291630

16301631
if (mSupportsDoubleTapWakeConfig) {
16311632
boolean doubleTapWakeEnabled = Settings.Secure.getIntForUser(resolver,

0 commit comments

Comments
 (0)