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

Commit 6d3444ec authored by Daniel Colascione's avatar Daniel Colascione Committed by Android (Google) Code Review
Browse files

Merge "Wire up zram setting, system property"

parents a665af32 766b632e
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -11248,6 +11248,15 @@ public final class Settings {
         */
        public static final String ENABLE_GNSS_RAW_MEAS_FULL_TRACKING =
                "enable_gnss_raw_meas_full_tracking";

        /**
         * Whether we've enabled zram on this device. Takes effect on
         * reboot. The value "1" enables zram; "0" disables it, and
         * everything else is unspecified.
         * @hide
         */
        public static final String ZRAM_ENABLED =
                "zram_enabled";
    }

    /**
+2 −1
Original line number Diff line number Diff line
@@ -388,8 +388,9 @@ message GlobalSettingsProto {
    optional SettingProto enable_deletion_helper_no_threshold_toggle = 340;
    optional SettingProto notification_snooze_options = 341;
    optional SettingProto enable_gnss_raw_meas_full_tracking = 346;
    optional SettingProto zram_enabled = 347;

    // Next tag = 347;
    // Next tag = 348;
}

message SecureSettingsProto {
+2 −1
Original line number Diff line number Diff line
@@ -421,7 +421,8 @@ public class SettingsBackupTest {
                    Settings.Global.WTF_IS_FATAL,
                    Settings.Global.ZEN_MODE,
                    Settings.Global.ZEN_MODE_CONFIG_ETAG,
                    Settings.Global.ZEN_MODE_RINGER_LEVEL);
                    Settings.Global.ZEN_MODE_RINGER_LEVEL,
                    Settings.Global.ZRAM_ENABLED);

    private static final Set<String> BACKUP_BLACKLISTED_SECURE_SETTINGS =
             newHashSet(
+3 −0
Original line number Diff line number Diff line
@@ -1119,6 +1119,9 @@ class SettingsProtoDumpUtil {
        dumpSetting(s, p,
                Settings.Global.NOTIFICATION_SNOOZE_OPTIONS,
                GlobalSettingsProto.NOTIFICATION_SNOOZE_OPTIONS);
        dumpSetting(s, p,
                    Settings.Global.ZRAM_ENABLED,
                    GlobalSettingsProto.ZRAM_ENABLED);
    }

    /** Dump a single {@link SettingsState.Setting} to a proto buf */
+40 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.content.pm.ProviderInfo;
import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.content.res.ObbInfo;
import android.database.ContentObserver;
import android.net.TrafficStats;
import android.net.Uri;
import android.os.Binder;
@@ -170,6 +171,10 @@ class StorageManagerService extends IStorageManager.Stub
    // Static direct instance pointer for the tightly-coupled idle service to use
    static StorageManagerService sSelf = null;

    /* Read during boot to decide whether to enable zram when available */
    private static final String ZRAM_ENABLED_PROPERTY =
        "persist.sys.zram_enabled";

    public static class Lifecycle extends SystemService {
        private StorageManagerService mStorageManagerService;

@@ -733,6 +738,41 @@ class StorageManagerService extends IStorageManager.Stub

        // Start scheduling nominally-daily fstrim operations
        MountServiceIdler.scheduleIdlePass(mContext);

        // Toggle zram-enable system property in response to settings
        mContext.getContentResolver().registerContentObserver(
            Settings.Global.getUriFor(Settings.Global.ZRAM_ENABLED),
            false /*notifyForDescendants*/,
            new ContentObserver(null /* current thread */) {
                @Override
                public void onChange(boolean selfChange) {
                    refreshZramSettings();
                }
            });
        refreshZramSettings();
    }

    /**
     * Update the zram_enabled system property (which init reads to
     * decide whether to enable zram) to reflect the zram_enabled
     * preference (which we can change for experimentation purposes).
     */
    private void refreshZramSettings() {
        String propertyValue = SystemProperties.get(ZRAM_ENABLED_PROPERTY);
        if ("".equals(propertyValue)) {
            return;  // System doesn't have zram toggling support
        }
        String desiredPropertyValue =
            Settings.Global.getInt(mContext.getContentResolver(),
                                   Settings.Global.ZRAM_ENABLED,
                                   1) != 0
            ? "1" : "0";
        if (!desiredPropertyValue.equals(propertyValue)) {
            // Avoid redundant disk writes by setting only if we're
            // changing the property value. There's no race: we're the
            // sole writer.
            SystemProperties.set(ZRAM_ENABLED_PROPERTY, desiredPropertyValue);
        }
    }

    /**