From 04f98299885ac7e976b8211e67e1795de6c9950d Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Wed, 5 Jun 2019 14:31:59 +0900 Subject: [PATCH] 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) --- .../java/android/net/NetworkStackClient.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/services/net/java/android/net/NetworkStackClient.java b/services/net/java/android/net/NetworkStackClient.java index 56b728c871808..787fda33717a3 100644 --- a/services/net/java/android/net/NetworkStackClient.java +++ b/services/net/java/android/net/NetworkStackClient.java @@ -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; + } + } }