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

Commit 04f98299 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

Remove DeviceConfig usage from NetworkStackClient

DeviceConfig API is not yet submitted. Use Settings.Global instead, to
still allow writing tests against AOSP code (a test would try to use
adb shell device_config, and fallback to adb shell settings).

This is not merged anywhere else, the merged-in is here to ensure this
does not end up in branches that use DeviceConfig. This change should be
lost when AOSP is updated.

Test: flashed, force-crashed NetworkStack with different setting values:
      observe rate-limited crash
Bug: 133725814
Merged-In: I423ca6ebb328f49b170baae0da9b8409a6429fcb
Change-Id: I399d3e37f1faaecb8a30428c1989fac8821379d8
(clean cherry-pick from aosp/977048)
parent 90b03956
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.text.format.DateUtils;
import android.util.ArraySet;
import android.util.Slog;
@@ -340,6 +340,8 @@ public class NetworkStackClient {
    private void maybeCrashWithTerribleFailure(@NonNull String message,
            @NonNull Context context, @Nullable String packageName) {
        logWtf(message, null);
        // Called DeviceConfig to minimize merge conflicts
        final DeviceConfigStub DeviceConfig = new DeviceConfigStub(context);
        // uptime is monotonic even after a framework restart
        final long uptime = SystemClock.elapsedRealtime();
        final long now = System.currentTimeMillis();
@@ -533,4 +535,36 @@ public class NetworkStackClient {
        pw.println();
        pw.println("pendingNetStackRequests length: " + requestsQueueLength);
    }

    /**
     * Stub class to replicate DeviceConfig behavior with minimal merge conflicts.
     */
    private class DeviceConfigStub {
        private final Context mContext;

        // Namespace is actually unused, but is here to replicate the final API.
        private static final String NAMESPACE_CONNECTIVITY = "connectivity";

        private DeviceConfigStub(Context context) {
            mContext = context;
        }

        private long getLong(
                @NonNull String namespace, @NonNull String key, long defaultVal) {
            // Temporary solution until DeviceConfig is available
            try {
                return Settings.Global.getLong(
                        mContext.getContentResolver(), TAG + "_" + key, defaultVal);
            } catch (Throwable e) {
                logWtf("Could not obtain setting " + key, e);
                return defaultVal;
            }
        }

        private boolean getBoolean(
                @NonNull String namespace, @NonNull String key, boolean defaultVal) {
            // Temporary solution until DeviceConfig is available
            return getLong(namespace, key, defaultVal ? 1 : 0) != 0;
        }
    }
}