From: Daniel Colascione Date: Tue, 9 Jan 2018 03:10:36 +0000 (-0800) Subject: Wire up zram setting, system property X-Git-Tag: android-x86-9.0-r1~265^2~89^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=766b632ebc03a3965cdf5ce96563e80b94bd2f4e;p=android-x86%2Fframeworks-base.git Wire up zram setting, system property The experiment framework toggles the system setting, which manipulates the system property that init reads during boot to determine whether we should enable zram. Test: manual Change-Id: I4b4f1b1673a5aa5e7f721c7dec7ebe3ea7908af2 --- diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 009fc395ff3b..4e34240704af 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -11221,6 +11221,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"; } /** diff --git a/core/proto/android/providers/settings.proto b/core/proto/android/providers/settings.proto index fb0ebed1545d..79c29427564d 100644 --- a/core/proto/android/providers/settings.proto +++ b/core/proto/android/providers/settings.proto @@ -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 { diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java index fc8650086cd8..c37ee5c33ac9 100644 --- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java +++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java @@ -418,7 +418,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 BACKUP_BLACKLISTED_SECURE_SETTINGS = newHashSet( diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java index 1d3f26eec56d..4e0c0abf7ef0 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java @@ -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 */ diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index dc2f2a5f53d5..7361e70a5bde 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -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); + } } /**