From d835625e4ae19f7ab2e4dcb047ee8fa01f4f4f8f Mon Sep 17 00:00:00 2001 From: Francois Campbell Date: Mon, 25 Apr 2016 23:12:17 -0400 Subject: [PATCH] Tentative fix for Project Fi. --- app/src/main/java/android/net/NetworkTemplate.java | 4 ++++ .../model/usage/DataUsageFetcherImpl.kt | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/android/net/NetworkTemplate.java b/app/src/main/java/android/net/NetworkTemplate.java index d900315..d1cc5da 100644 --- a/app/src/main/java/android/net/NetworkTemplate.java +++ b/app/src/main/java/android/net/NetworkTemplate.java @@ -12,4 +12,8 @@ public abstract class NetworkTemplate { public static NetworkTemplate buildTemplateMobileAll(String subscriberId) { throw new StubClassNotShadowedError(); } + + public static NetworkTemplate normalize(NetworkTemplate template, String[] merged) { + throw new StubClassNotShadowedError(); + } } diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/usage/DataUsageFetcherImpl.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/usage/DataUsageFetcherImpl.kt index b5c7aba..0851d90 100644 --- a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/usage/DataUsageFetcherImpl.kt +++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/usage/DataUsageFetcherImpl.kt @@ -5,7 +5,9 @@ import android.net.INetworkStatsService import android.net.NetworkPolicy import android.net.NetworkPolicyManager import android.net.NetworkTemplate +import android.os.Build import android.telephony.TelephonyManager +import de.robv.android.xposed.XposedHelpers import javax.inject.Inject import javax.inject.Named @@ -51,7 +53,16 @@ class DataUsageFetcherImpl private fun getCurrentNetworkTemplate(): NetworkTemplate? { val subscriberId = telephonyManager.subscriberId ?: return null - return NetworkTemplate.buildTemplateMobileAll(subscriberId) + var template = NetworkTemplate.buildTemplateMobileAll(subscriberId) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + val mergedSubscriberIds = XposedHelpers.callMethod(telephonyManager, "getMergedSubscriberIds") + if (mergedSubscriberIds != null) { + @Suppress("UNCHECKED_CAST") + return NetworkTemplate.normalize(template, mergedSubscriberIds as Array) + } + } + return template + } private fun getPolicyForTemplate(networkTemplate: NetworkTemplate): NetworkPolicy? {