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

Commit 6dbc4a14 authored by Robert Horvath's avatar Robert Horvath
Browse files

Set the Low Power Standby enabled setting when unassigned

SettingsSnapshot metrics allow collecting data on the current value of
Settings, but if the Setting has never been written to, a Setting will
be logged as <notassigned>.

We want to track the standby mode users are using. We can do that by
collecting data on the LOW_POWER_STANDBY_ENABLED setting, but since
some devices may have LPS enabled by default while others don't, we
can't tell from a <notassigned> value whether LPS is enabled or not on a
device.

With this change, when the Setting hasn't been written yet, then the
Setting is updated to the actual value. Any <notassigned> value then
means that LPS is not supported, as otherwise the value would've been
assigned.

Test: manual - check whether setting gets written
Bug: 234771100
Change-Id: I62ebe69d01bce99c78ed21326538e38fa6f21428
parent 0c867c02
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -201,6 +201,7 @@ public class LowPowerStandbyController {
            mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(
                    Settings.Global.LOW_POWER_STANDBY_ACTIVE_DURING_MAINTENANCE),
                    false, mSettingsObserver, UserHandle.USER_ALL);
            initSettingsLocked();
            updateSettingsLocked();

            if (mIsEnabled) {
@@ -211,6 +212,23 @@ public class LowPowerStandbyController {
        LocalServices.addService(LowPowerStandbyControllerInternal.class, mLocalService);
    }

    @GuardedBy("mLock")
    private void initSettingsLocked() {
        final ContentResolver resolver = mContext.getContentResolver();
        if (mSupportedConfig) {
            final int enabledSetting = Settings.Global.getInt(resolver,
                    Settings.Global.LOW_POWER_STANDBY_ENABLED, /* def= */ -1);

            // If the ENABLED setting hasn't been assigned yet, set it to its default value.
            // This ensures reading the setting reflects the enabled state, without having to know
            // the default value for this device.
            if (enabledSetting == -1) {
                Settings.Global.putInt(resolver, Settings.Global.LOW_POWER_STANDBY_ENABLED,
                        /* value= */ mEnabledByDefaultConfig ? 1 : 0);
            }
        }
    }

    @GuardedBy("mLock")
    private void updateSettingsLocked() {
        final ContentResolver resolver = mContext.getContentResolver();