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

Commit aa67f684 authored by John Reck's avatar John Reck
Browse files

Fix a bunch of repeated reads of a ro.* property

SystemProperties.get() is not particularly fast,
especially if a string is returned. Since ro.* values
are unable to be changed, there's no need to
continously re-query them. Cache the value at
static init time to trivially fix this.

Test: refactoring CL.
Change-Id: Iccb021d3cb2ba3a4a1d0048ddec6811bb7409eec
parent d8a53abd
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.IBinder;
import android.os.ParcelFileDescriptor;

import com.android.internal.app.procstats.ProcessStats;
import com.android.internal.os.RoSystemProperties;
import com.android.internal.os.TransferPipe;
import com.android.internal.util.FastPrintWriter;

@@ -900,7 +901,7 @@ public class ActivityManager {

    /** @hide */
    public static boolean isLowRamDeviceStatic() {
        return "true".equals(SystemProperties.get("ro.config.low_ram", "false"));
        return RoSystemProperties.CONFIG_LOW_RAM;
    }

    /**
+4 −2
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.net;

import android.os.SystemProperties;
import android.util.Log;

import com.android.internal.os.RoSystemProperties;
import com.android.org.conscrypt.OpenSSLContextImpl;
import com.android.org.conscrypt.OpenSSLSocketImpl;
import com.android.org.conscrypt.SSLClientSessionCache;
@@ -221,8 +223,8 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory {
    }

    private static boolean isSslCheckRelaxed() {
        return "1".equals(SystemProperties.get("ro.debuggable")) &&
            "yes".equals(SystemProperties.get("socket.relaxsslcheck"));
        return RoSystemProperties.DEBUGGABLE &&
            SystemProperties.getBoolean("socket.relaxsslcheck", false);
    }

    private synchronized SSLSocketFactory getDelegate() {
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.os;

import com.android.internal.os.RoSystemProperties;

/**
 * Provides support for in-place factory test functions.
 *
@@ -36,7 +38,7 @@ public final class FactoryTest {
     * or {@link #FACTORY_TEST_HIGH_LEVEL}.
     */
    public static int getMode() {
        return SystemProperties.getInt("ro.factorytest", FACTORY_TEST_OFF);
        return RoSystemProperties.FACTORYTEST;
    }

    /**
+46 −2
Original line number Diff line number Diff line
@@ -16,7 +16,13 @@

package android.os;

import android.util.Log;
import android.util.MutableInt;

import com.android.internal.annotations.GuardedBy;

import java.util.ArrayList;
import java.util.HashMap;


/**
@@ -25,13 +31,45 @@ import java.util.ArrayList;
 *
 * {@hide}
 */
public class SystemProperties
{
public class SystemProperties {
    private static final String TAG = "SystemProperties";
    private static final boolean TRACK_KEY_ACCESS = false;

    public static final int PROP_NAME_MAX = 31;
    public static final int PROP_VALUE_MAX = 91;

    private static final ArrayList<Runnable> sChangeCallbacks = new ArrayList<Runnable>();

    @GuardedBy("sRoReads")
    private static final HashMap<String, MutableInt> sRoReads;
    static {
        if (TRACK_KEY_ACCESS) {
            sRoReads = new HashMap<>();
        } else {
            sRoReads = null;
        }
    }

    private static void onKeyAccess(String key) {
        if (!TRACK_KEY_ACCESS) return;

        if (key != null && key.startsWith("ro.")) {
            synchronized (sRoReads) {
                MutableInt numReads = sRoReads.getOrDefault(key, null);
                if (numReads == null) {
                    numReads = new MutableInt(0);
                    sRoReads.put(key, numReads);
                }
                numReads.value++;
                if (numReads.value > 3) {
                    Log.d(TAG, "Repeated read (count=" + numReads.value
                            + ") of a read-only system property '" + key + "'",
                            new Exception());
                }
            }
        }
    }

    private static native String native_get(String key);
    private static native String native_get(String key, String def);
    private static native int native_get_int(String key, int def);
@@ -49,6 +87,7 @@ public class SystemProperties
        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        if (TRACK_KEY_ACCESS) onKeyAccess(key);
        return native_get(key);
    }

@@ -61,6 +100,7 @@ public class SystemProperties
        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        if (TRACK_KEY_ACCESS) onKeyAccess(key);
        return native_get(key, def);
    }

@@ -76,6 +116,7 @@ public class SystemProperties
        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        if (TRACK_KEY_ACCESS) onKeyAccess(key);
        return native_get_int(key, def);
    }

@@ -91,6 +132,7 @@ public class SystemProperties
        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        if (TRACK_KEY_ACCESS) onKeyAccess(key);
        return native_get_long(key, def);
    }

@@ -111,6 +153,7 @@ public class SystemProperties
        if (key.length() > PROP_NAME_MAX) {
            throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
        }
        if (TRACK_KEY_ACCESS) onKeyAccess(key);
        return native_get_boolean(key, def);
    }

@@ -127,6 +170,7 @@ public class SystemProperties
            throw new IllegalArgumentException("val.length > " +
                PROP_VALUE_MAX);
        }
        if (TRACK_KEY_ACCESS) onKeyAccess(key);
        native_set(key, val);
    }

+2 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.telephony.TelephonyManager;
import android.view.WindowManager.LayoutParams;

import com.android.internal.R;
import com.android.internal.os.RoSystemProperties;

import java.io.IOException;
import java.lang.annotation.Retention;
@@ -746,7 +747,7 @@ public class UserManager {
     * a single owner user.  see @link {android.os.UserHandle#USER_OWNER}
     */
    public static boolean isSplitSystemUser() {
        return SystemProperties.getBoolean("ro.fw.system_user_split", false);
        return RoSystemProperties.FW_SYSTEM_USER_SPLIT;
    }

    /**
Loading