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

Commit 43866e0c authored by Doug Zongker's avatar Doug Zongker
Browse files

move some system services from gservices to secure settings

Change-Id: Ie2dfb99a2b42b2cc9310b858c044d8684e3493fa
parent 6414970a
Loading
Loading
Loading
Loading
+102 −85
Original line number Diff line number Diff line
@@ -2578,6 +2578,108 @@ public final class Settings {
         */
        public static final String REBOOT_WINDOW = "reboot_window";

        /**
         * Threshold values for the duration and level of a discharge cycle, under
         * which we log discharge cycle info.
         * @hide
         */
        public static final String BATTERY_DISCHARGE_DURATION_THRESHOLD =
                "battery_discharge_duration_threshold";
        /** @hide */
        public static final String BATTERY_DISCHARGE_THRESHOLD = "battery_discharge_threshold";

        /**
         * Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
         * on application crashes and ANRs. If this is disabled, the crash/ANR dialog
         * will never display the "Report" button.
         * Type: int ( 0 = disallow, 1 = allow )
         * @hide
         */
        public static final String SEND_ACTION_APP_ERROR = "send_action_app_error";

        /**
         * Nonzero causes Log.wtf() to crash.
         * @hide
         */
        public static final String WTF_IS_FATAL = "wtf_is_fatal";

        /**
         * Maximum age of entries kept by {@link android.os.IDropBox}.
         * @hide
         */
        public static final String DROPBOX_AGE_SECONDS =
                "dropbox_age_seconds";
        /**
         * Maximum amount of disk space used by {@link android.os.IDropBox} no matter what.
         * @hide
         */
        public static final String DROPBOX_QUOTA_KB =
                "dropbox_quota_kb";
        /**
         * Percent of free disk (excluding reserve) which {@link android.os.IDropBox} will use.
         * @hide
         */
        public static final String DROPBOX_QUOTA_PERCENT =
                "dropbox_quota_percent";
        /**
         * Percent of total disk which {@link android.os.IDropBox} will never dip into.
         * @hide
         */
        public static final String DROPBOX_RESERVE_PERCENT =
                "dropbox_reserve_percent";
        /**
         * Prefix for per-tag dropbox disable/enable settings.
         * @hide
         */
        public static final String DROPBOX_TAG_PREFIX =
                "dropbox:";


        /**
         * Screen timeout in milliseconds corresponding to the
         * PowerManager's POKE_LOCK_SHORT_TIMEOUT flag (i.e. the fastest
         * possible screen timeout behavior.)
         * @hide
         */
        public static final String SHORT_KEYLIGHT_DELAY_MS =
                "short_keylight_delay_ms";

        /**
         * The interval in minutes after which the amount of free storage left on the
         * device is logged to the event log
         * @hide
         */
        public static final String SYS_FREE_STORAGE_LOG_INTERVAL =
                "sys_free_storage_log_interval";

        /**
         * Threshold for the amount of change in disk free space required to report the amount of
         * free space. Used to prevent spamming the logs when the disk free space isn't changing
         * frequently.
         * @hide
         */
        public static final String DISK_FREE_CHANGE_REPORTING_THRESHOLD =
                "disk_free_change_reporting_threshold";


        /**
         * Minimum percentage of free storage on the device that is used to determine if
         * the device is running low on storage.
         * Say this value is set to 10, the device is considered running low on storage
         * if 90% or more of the device storage is filled up.
         * @hide
         */
        public static final String SYS_STORAGE_THRESHOLD_PERCENTAGE =
                "sys_storage_threshold_percentage";

        /**
         * The interval in milliseconds after which Wi-Fi is considered idle.
         * When idle, it is possible for the device to be switched from Wi-Fi to
         * the mobile data network.
         * @hide
         */
        public static final String WIFI_IDLE_MS = "wifi_idle_ms";

        /**
         * @hide
         */
@@ -3430,14 +3532,6 @@ public final class Settings {
        public static final String PARENTAL_CONTROL_REDIRECT_REGEX =
                "parental_control_redirect_regex";

        /**
         * Threshold for the amount of change in disk free space required to report the amount of
         * free space. Used to prevent spamming the logs when the disk free space isn't changing
         * frequently.
         */
        public static final String DISK_FREE_CHANGE_REPORTING_THRESHOLD =
                "disk_free_change_reporting_threshold";

        /**
         * Prefix for new Google services published by the checkin
         * server.
@@ -3452,22 +3546,6 @@ public final class Settings {
        public static final String SYNC_MAX_RETRY_DELAY_IN_SECONDS =
                "sync_max_retry_delay_in_seconds";

        /**
         * Minimum percentage of free storage on the device that is used to determine if
         * the device is running low on storage.
         * Say this value is set to 10, the device is considered running low on storage
         * if 90% or more of the device storage is filled up.
         */
        public static final String SYS_STORAGE_THRESHOLD_PERCENTAGE =
                "sys_storage_threshold_percentage";

        /**
         * The interval in minutes after which the amount of free storage left on the
         * device is logged to the event log
         */
        public static final String SYS_FREE_STORAGE_LOG_INTERVAL =
                "sys_free_storage_log_interval";

        /**
         * The interval in milliseconds at which to check the number of SMS sent
         * out without asking for use permit, to limit the un-authorized SMS
@@ -3551,21 +3629,6 @@ public final class Settings {
        public static final String GPRS_REGISTER_CHECK_PERIOD_MS =
                "gprs_register_check_period_ms";

        /**
         * The interval in milliseconds after which Wi-Fi is considered idle.
         * When idle, it is possible for the device to be switched from Wi-Fi to
         * the mobile data network.
         */
        public static final String WIFI_IDLE_MS = "wifi_idle_ms";

        /**
         * Screen timeout in milliseconds corresponding to the
         * PowerManager's POKE_LOCK_SHORT_TIMEOUT flag (i.e. the fastest
         * possible screen timeout behavior.)
         */
        public static final String SHORT_KEYLIGHT_DELAY_MS =
                "short_keylight_delay_ms";

        /**
         * List of test suites (local disk filename) for the automatic instrumentation test runner.
         * The file format is similar to automated_suites.xml, see AutoTesterService.
@@ -3587,14 +3650,6 @@ public final class Settings {
        public static final String AUTOTEST_REBOOT_SECONDS = "autotest_reboot_seconds";


        /**
         * Threshold values for the duration and level of a discharge cycle, under
         * which we log discharge cycle info.
         */
        public static final String BATTERY_DISCHARGE_DURATION_THRESHOLD =
                "battery_discharge_duration_threshold";
        public static final String BATTERY_DISCHARGE_THRESHOLD = "battery_discharge_threshold";

        /**
         * An email address that anr bugreports should be sent to.
         */
@@ -3694,50 +3749,12 @@ public final class Settings {
         */
        public static final String SEARCH_PER_SOURCE_CONCURRENT_QUERY_LIMIT =
                "search_per_source_concurrent_query_limit";
        /**
         * Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
         * on application crashes and ANRs. If this is disabled, the crash/ANR dialog
         * will never display the "Report" button.
         * Type: int ( 0 = disallow, 1 = allow )
         */
        public static final String SEND_ACTION_APP_ERROR = "send_action_app_error";

        /**
         * Maximum size of /proc/last_kmsg content to upload after reboot.
         */
        public static final String LAST_KMSG_KB = "last_kmsg_kb";

        /**
         * Maximum age of entries kept by {@link android.os.IDropBox}.
         */
        public static final String DROPBOX_AGE_SECONDS =
                "dropbox_age_seconds";
        /**
         * Maximum amount of disk space used by {@link android.os.IDropBox} no matter what.
         */
        public static final String DROPBOX_QUOTA_KB =
                "dropbox_quota_kb";
        /**
         * Percent of free disk (excluding reserve) which {@link android.os.IDropBox} will use.
         */
        public static final String DROPBOX_QUOTA_PERCENT =
                "dropbox_quota_percent";
        /**
         * Percent of total disk which {@link android.os.IDropBox} will never dip into.
         */
        public static final String DROPBOX_RESERVE_PERCENT =
                "dropbox_reserve_percent";
        /**
         * Prefix for per-tag dropbox disable/enable settings.
         */
        public static final String DROPBOX_TAG_PREFIX =
                "dropbox:";

        /**
         * Nonzero causes Log.wtf() to crash.
         */
        public static final String WTF_IS_FATAL = "wtf_is_fatal";

        /**
         * The length of time in milli-seconds that automatic small adjustments to
         * SystemClock are ignored if NITZ_UPDATE_DIFF is not exceeded.
+4 −4
Original line number Diff line number Diff line
@@ -413,10 +413,10 @@ class BatteryService extends Binder {

    private final void logOutlier(long duration) {
        ContentResolver cr = mContext.getContentResolver();
        String dischargeThresholdString = Settings.Gservices.getString(cr,
                Settings.Gservices.BATTERY_DISCHARGE_THRESHOLD);
        String durationThresholdString = Settings.Gservices.getString(cr,
                Settings.Gservices.BATTERY_DISCHARGE_DURATION_THRESHOLD);
        String dischargeThresholdString = Settings.Secure.getString(cr,
                Settings.Secure.BATTERY_DISCHARGE_THRESHOLD);
        String durationThresholdString = Settings.Secure.getString(cr,
                Settings.Secure.BATTERY_DISCHARGE_DURATION_THRESHOLD);

        if (dischargeThresholdString != null && durationThresholdString != null) {
            try {
+26 −22
Original line number Diff line number Diff line
@@ -34,25 +34,29 @@ import android.os.ServiceManager;
import android.os.StatFs;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Settings.Gservices;
import android.provider.Settings;
import android.util.Config;
import android.util.EventLog;
import android.util.Log;
import android.provider.Settings;

/**
 * This class implements a service to monitor the amount of disk storage space
 * on the device. If the free storage on device is less than a tunable threshold value
 * (default is 10%. this value is a gservices parameter) a low memory notification is
 * displayed to alert the user. If the user clicks on the low memory notification the
 * Application Manager application gets launched to let the user free storage space.
 * Event log events:
 * A low memory event with the free storage on device in bytes  is logged to the event log
 * when the device goes low on storage space.
 * The amount of free storage on the device is periodically logged to the event log. The log
 * interval is a gservices parameter with a default value of 12 hours
 * When the free storage differential goes below a threshold(again a gservices parameter with
 * a default value of 2MB), the free memory is logged to the event log
 * This class implements a service to monitor the amount of disk
 * storage space on the device.  If the free storage on device is less
 * than a tunable threshold value (a secure settings parameter;
 * default 10%) a low memory notification is displayed to alert the
 * user. If the user clicks on the low memory notification the
 * Application Manager application gets launched to let the user free
 * storage space.
 *
 * Event log events: A low memory event with the free storage on
 * device in bytes is logged to the event log when the device goes low
 * on storage space.  The amount of free storage on the device is
 * periodically logged to the event log. The log interval is a secure
 * settings parameter with a default value of 12 hours.  When the free
 * storage differential goes below a threshold (again a secure
 * settings parameter with a default value of 2MB), the free memory is
 * logged to the event log.
 */
class DeviceStorageMonitorService extends Binder {
    private static final String TAG = "DeviceStorageMonitorService";
@@ -131,9 +135,9 @@ class DeviceStorageMonitorService extends Binder {
        if (!"".equals(debugFreeMem)) {
            mFreeMem = Long.parseLong(debugFreeMem);
        }
        // Read the log interval from Gservices
        long freeMemLogInterval = Gservices.getLong(mContentResolver,
                Gservices.SYS_FREE_STORAGE_LOG_INTERVAL,
        // Read the log interval from secure settings
        long freeMemLogInterval = Settings.Secure.getLong(mContentResolver,
                Settings.Secure.SYS_FREE_STORAGE_LOG_INTERVAL,
                DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES)*60*1000;
        //log the amount of free memory in event log
        long currTime = SystemClock.elapsedRealtime();
@@ -159,9 +163,9 @@ class DeviceStorageMonitorService extends Binder {
            EventLog.writeEvent(EventLogTags.FREE_STORAGE_LEFT,
                                mFreeMem, mFreeSystem, mFreeCache);
        }
        // Read the reporting threshold from Gservices
        long threshold = Gservices.getLong(mContentResolver,
                Gservices.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
        // Read the reporting threshold from secure settings
        long threshold = Settings.Secure.getLong(mContentResolver,
                Settings.Secure.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
                DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD);
        // If mFree changed significantly log the new value
        long delta = mFreeMem - mLastReportedFreeMem;
@@ -247,13 +251,13 @@ class DeviceStorageMonitorService extends Binder {

    /*
     * just query settings to retrieve the memory threshold.
     * Preferred this over using a ContentObserver since Settings.Gservices caches the value
     * Preferred this over using a ContentObserver since Settings.Secure caches the value
     * any way
     */
    private long getMemThreshold() {
        int value = Settings.Gservices.getInt(
        int value = Settings.Secure.getInt(
                              mContentResolver,
                              Settings.Gservices.SYS_STORAGE_THRESHOLD_PERCENTAGE,
                              Settings.Secure.SYS_STORAGE_THRESHOLD_PERCENTAGE,
                              DEFAULT_THRESHOLD_PERCENTAGE);
        if(localLOGV) Log.v(TAG, "Threshold Percentage="+value);
        //evaluate threshold value
+21 −12
Original line number Diff line number Diff line
@@ -22,9 +22,11 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Debug;
import android.os.DropBoxManager;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.os.StatFs;
import android.os.SystemClock;
@@ -113,14 +115,21 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub {
     * @param context to use for receiving free space & gservices intents
     * @param path to store drop box entries in
     */
    public DropBoxManagerService(Context context, File path) {
    public DropBoxManagerService(final Context context, File path) {
        mDropBoxDir = path;

        // Set up intent receivers
        mContext = context;
        mContentResolver = context.getContentResolver();
        context.registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW));
        context.registerReceiver(mReceiver, new IntentFilter(Settings.Gservices.CHANGED_ACTION));

        mContentResolver.registerContentObserver(
            Settings.Secure.CONTENT_URI, true,
            new ContentObserver(new Handler()) {
                public void onChange(boolean selfChange) {
                    mReceiver.onReceive(context, (Intent) null);
                }
            });

        // The real work gets done lazily in init() -- that way service creation always
        // succeeds, and things like disk problems cause individual method failures.
@@ -205,8 +214,8 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub {
    }

    public boolean isTagEnabled(String tag) {
        return !"disabled".equals(Settings.Gservices.getString(
                mContentResolver, Settings.Gservices.DROPBOX_TAG_PREFIX + tag));
        return !"disabled".equals(Settings.Secure.getString(
                mContentResolver, Settings.Secure.DROPBOX_TAG_PREFIX + tag));
    }

    public synchronized DropBoxManager.Entry getNextEntry(String tag, long millis) {
@@ -611,8 +620,8 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub {
    private synchronized long trimToFit() {
        // Expunge aged items (including tombstones marking deleted data).

        int ageSeconds = Settings.Gservices.getInt(mContentResolver,
                Settings.Gservices.DROPBOX_AGE_SECONDS, DEFAULT_AGE_SECONDS);
        int ageSeconds = Settings.Secure.getInt(mContentResolver,
                Settings.Secure.DROPBOX_AGE_SECONDS, DEFAULT_AGE_SECONDS);
        long cutoffMillis = System.currentTimeMillis() - ageSeconds * 1000;
        while (!mAllFiles.contents.isEmpty()) {
            EntryFile entry = mAllFiles.contents.first();
@@ -631,12 +640,12 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub {

        long uptimeMillis = SystemClock.uptimeMillis();
        if (uptimeMillis > mCachedQuotaUptimeMillis + QUOTA_RESCAN_MILLIS) {
            int quotaPercent = Settings.Gservices.getInt(mContentResolver,
                    Settings.Gservices.DROPBOX_QUOTA_PERCENT, DEFAULT_QUOTA_PERCENT);
            int reservePercent = Settings.Gservices.getInt(mContentResolver,
                    Settings.Gservices.DROPBOX_RESERVE_PERCENT, DEFAULT_RESERVE_PERCENT);
            int quotaKb = Settings.Gservices.getInt(mContentResolver,
                    Settings.Gservices.DROPBOX_QUOTA_KB, DEFAULT_QUOTA_KB);
            int quotaPercent = Settings.Secure.getInt(mContentResolver,
                    Settings.Secure.DROPBOX_QUOTA_PERCENT, DEFAULT_QUOTA_PERCENT);
            int reservePercent = Settings.Secure.getInt(mContentResolver,
                    Settings.Secure.DROPBOX_RESERVE_PERCENT, DEFAULT_RESERVE_PERCENT);
            int quotaKb = Settings.Secure.getInt(mContentResolver,
                    Settings.Secure.DROPBOX_QUOTA_KB, DEFAULT_QUOTA_KB);

            mStatFs.restat(mDropBoxDir.getPath());
            int available = mStatFs.getAvailableBlocks();
+21 −30
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
@@ -36,9 +37,11 @@ import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.IMountService;
import android.os.IPowerManager;
import android.os.LocalPowerManager;
import android.os.Power;
@@ -46,8 +49,6 @@ import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.Environment;
import android.os.IMountService;
import android.os.SystemClock;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Settings;
@@ -88,7 +89,7 @@ class PowerManagerService extends IPowerManager.Stub
                                        | PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK;

    //                       time since last state:               time since last event:
    // The short keylight delay comes from Gservices; this is the default.
    // The short keylight delay comes from secure settings; this is the default.
    private static final int SHORT_KEYLIGHT_DELAY_DEFAULT = 6000; // t+6 sec
    private static final int MEDIUM_KEYLIGHT_DELAY = 15000;       // t+15 sec
    private static final int LONG_KEYLIGHT_DELAY = 6000;        // t+6 sec
@@ -103,7 +104,7 @@ class PowerManagerService extends IPowerManager.Stub
    // trigger proximity if distance is less than 5 cm
    private static final float PROXIMITY_THRESHOLD = 5.0f;

    // Cached Gservices settings; see updateGservicesValues()
    // Cached secure settings; see updateSettingsValues()
    private int mShortKeylightDelay = SHORT_KEYLIGHT_DELAY_DEFAULT;

    // flags for setPowerState
@@ -516,12 +517,15 @@ class PowerManagerService extends IPowerManager.Stub
        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
        mContext.registerReceiver(new BootCompletedReceiver(), filter);

        // Listen for Gservices changes
        IntentFilter gservicesChangedFilter =
                new IntentFilter(Settings.Gservices.CHANGED_ACTION);
        mContext.registerReceiver(new GservicesChangedReceiver(), gservicesChangedFilter);
        // And explicitly do the initial update of our cached settings
        updateGservicesValues();
        // Listen for secure settings changes
        mContext.getContentResolver().registerContentObserver(
            Settings.Secure.CONTENT_URI, true,
            new ContentObserver(new Handler()) {
                public void onChange(boolean selfChange) {
                    updateSettingsValues();
                }
            });
        updateSettingsValues();

        if (mUseSoftwareAutoBrightness) {
            // turn the screen on
@@ -2273,7 +2277,7 @@ class PowerManagerService extends IPowerManager.Stub
     * */
    private void setScreenOffTimeoutsLocked() {
        if ((mPokey & POKE_LOCK_SHORT_TIMEOUT) != 0) {
            mKeylightDelay = mShortKeylightDelay;  // Configurable via Gservices
            mKeylightDelay = mShortKeylightDelay;  // Configurable via secure settings
            mDimDelay = -1;
            mScreenOffDelay = 0;
        } else if ((mPokey & POKE_LOCK_MEDIUM_TIMEOUT) != 0) {
@@ -2308,28 +2312,15 @@ class PowerManagerService extends IPowerManager.Stub
    }

    /**
     * Refreshes cached Gservices settings.  Called once on startup, and
     * on subsequent Settings.Gservices.CHANGED_ACTION broadcasts (see
     * GservicesChangedReceiver).
     * Refreshes cached secure settings.  Called once on startup, and
     * on subsequent changes to secure settings.
     */
    private void updateGservicesValues() {
        mShortKeylightDelay = Settings.Gservices.getInt(
    private void updateSettingsValues() {
        mShortKeylightDelay = Settings.Secure.getInt(
                mContext.getContentResolver(),
                Settings.Gservices.SHORT_KEYLIGHT_DELAY_MS,
                Settings.Secure.SHORT_KEYLIGHT_DELAY_MS,
                SHORT_KEYLIGHT_DELAY_DEFAULT);
        // Log.i(TAG, "updateGservicesValues(): mShortKeylightDelay now " + mShortKeylightDelay);
    }

    /**
     * Receiver for the Gservices.CHANGED_ACTION broadcast intent,
     * which tells us we need to refresh our cached Gservices settings.
     */
    private class GservicesChangedReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            // Log.i(TAG, "GservicesChangedReceiver.onReceive(): " + intent);
            updateGservicesValues();
        }
        // Log.i(TAG, "updateSettingsValues(): mShortKeylightDelay now " + mShortKeylightDelay);
    }

    private class LockList extends ArrayList<WakeLock>
Loading