mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-07-05 19:11:15 +00:00
d98f33a337
TODO: - f/w/b - settings Signed-off-by: Tavi <tavi@divested.dev>
375 lines
15 KiB
Diff
375 lines
15 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dmitry Muhomor <muhomor.dmitry@gmail.com>
|
|
Date: Thu, 5 Oct 2023 09:39:18 +0300
|
|
Subject: [PATCH] ConnectivityManager: pretend that network is down to
|
|
INTERNET-unaware callers
|
|
|
|
---
|
|
.../src/android/net/ConnectivityManager.java | 129 ++++++++++++++++++
|
|
1 file changed, 129 insertions(+)
|
|
|
|
diff --git a/framework/src/android/net/ConnectivityManager.java b/framework/src/android/net/ConnectivityManager.java
|
|
index fa27d0e010..d7431bd192 100644
|
|
--- a/framework/src/android/net/ConnectivityManager.java
|
|
+++ b/framework/src/android/net/ConnectivityManager.java
|
|
@@ -43,6 +43,7 @@ import android.compat.annotation.UnsupportedAppUsage;
|
|
import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
+import android.content.pm.SpecialRuntimePermAppUtils;
|
|
import android.net.ConnectivityDiagnosticsManager.DataStallReport.DetectionMethod;
|
|
import android.net.IpSecManager.UdpEncapsulationSocket;
|
|
import android.net.SocketKeepalive.Callback;
|
|
@@ -1382,6 +1383,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@Nullable
|
|
public NetworkInfo getActiveNetworkInfo() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getActiveNetworkInfo();
|
|
} catch (RemoteException e) {
|
|
@@ -1403,6 +1408,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@Nullable
|
|
public Network getActiveNetwork() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getActiveNetwork();
|
|
} catch (RemoteException e) {
|
|
@@ -1636,6 +1645,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@Nullable
|
|
public NetworkInfo getNetworkInfo(int networkType) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getNetworkInfo(networkType);
|
|
} catch (RemoteException e) {
|
|
@@ -1657,6 +1670,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@Nullable
|
|
public NetworkInfo getNetworkInfo(@Nullable Network network) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
return getNetworkInfoForUid(network, Process.myUid(), false);
|
|
}
|
|
|
|
@@ -1683,6 +1700,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@NonNull
|
|
public NetworkInfo[] getAllNetworkInfo() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return new NetworkInfo[0];
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getAllNetworkInfo();
|
|
} catch (RemoteException e) {
|
|
@@ -1722,6 +1743,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@UnsupportedAppUsage
|
|
public Network getNetworkForType(int networkType) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getNetworkForType(networkType);
|
|
} catch (RemoteException e) {
|
|
@@ -1745,6 +1770,10 @@ public class ConnectivityManager {
|
|
@NonNull
|
|
@Deprecated
|
|
public Network[] getAllNetworks() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return new Network[0];
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getAllNetworks();
|
|
} catch (RemoteException e) {
|
|
@@ -1783,6 +1812,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 109783091)
|
|
public LinkProperties getActiveLinkProperties() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getActiveLinkProperties();
|
|
} catch (RemoteException e) {
|
|
@@ -1808,6 +1841,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 130143562)
|
|
public LinkProperties getLinkProperties(int networkType) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getLinkPropertiesForType(networkType);
|
|
} catch (RemoteException e) {
|
|
@@ -1825,6 +1862,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@Nullable
|
|
public LinkProperties getLinkProperties(@Nullable Network network) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getLinkProperties(network);
|
|
} catch (RemoteException e) {
|
|
@@ -1879,6 +1920,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@Nullable
|
|
public NetworkCapabilities getNetworkCapabilities(@Nullable Network network) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getNetworkCapabilities(
|
|
network, mContext.getOpPackageName(), getAttributionTag());
|
|
@@ -2891,6 +2936,10 @@ public class ConnectivityManager {
|
|
@UnsupportedAppUsage
|
|
@Deprecated
|
|
public String[] getTetherableIfaces() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return new String[0];
|
|
+ }
|
|
+
|
|
return getTetheringManager().getTetherableIfaces();
|
|
}
|
|
|
|
@@ -2906,6 +2955,10 @@ public class ConnectivityManager {
|
|
@UnsupportedAppUsage
|
|
@Deprecated
|
|
public String[] getTetheredIfaces() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return new String[0];
|
|
+ }
|
|
+
|
|
return getTetheringManager().getTetheredIfaces();
|
|
}
|
|
|
|
@@ -2927,6 +2980,10 @@ public class ConnectivityManager {
|
|
@UnsupportedAppUsage
|
|
@Deprecated
|
|
public String[] getTetheringErroredIfaces() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return new String[0];
|
|
+ }
|
|
+
|
|
return getTetheringManager().getTetheringErroredIfaces();
|
|
}
|
|
|
|
@@ -3233,6 +3290,10 @@ public class ConnectivityManager {
|
|
@UnsupportedAppUsage
|
|
@Deprecated
|
|
public String[] getTetherableUsbRegexs() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return new String[0];
|
|
+ }
|
|
+
|
|
return getTetheringManager().getTetherableUsbRegexs();
|
|
}
|
|
|
|
@@ -3251,6 +3312,10 @@ public class ConnectivityManager {
|
|
@UnsupportedAppUsage
|
|
@Deprecated
|
|
public String[] getTetherableWifiRegexs() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return new String[0];
|
|
+ }
|
|
+
|
|
return getTetheringManager().getTetherableWifiRegexs();
|
|
}
|
|
|
|
@@ -3270,6 +3335,10 @@ public class ConnectivityManager {
|
|
@UnsupportedAppUsage
|
|
@Deprecated
|
|
public String[] getTetherableBluetoothRegexs() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return new String[0];
|
|
+ }
|
|
+
|
|
return getTetheringManager().getTetherableBluetoothRegexs();
|
|
}
|
|
|
|
@@ -3410,6 +3479,10 @@ public class ConnectivityManager {
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
|
|
@Deprecated
|
|
public int getLastTetherError(String iface) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return TetheringManager.TETHER_ERROR_UNKNOWN_IFACE;
|
|
+ }
|
|
+
|
|
int error = getTetheringManager().getLastTetherError(iface);
|
|
if (error == TetheringManager.TETHER_ERROR_UNKNOWN_TYPE) {
|
|
// TETHER_ERROR_UNKNOWN_TYPE was introduced with TetheringManager and has never been
|
|
@@ -3552,6 +3625,10 @@ public class ConnectivityManager {
|
|
* Internet using {@code network} or {@code false} if not.
|
|
*/
|
|
public void reportNetworkConnectivity(@Nullable Network network, boolean hasConnectivity) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
printStackTrace();
|
|
try {
|
|
mService.reportNetworkConnectivity(network, hasConnectivity);
|
|
@@ -3658,6 +3735,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 130143562)
|
|
public boolean isNetworkSupported(int networkType) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.isNetworkSupported(networkType);
|
|
} catch (RemoteException e) {
|
|
@@ -3678,6 +3759,10 @@ public class ConnectivityManager {
|
|
*/
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
public boolean isActiveNetworkMetered() {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.isActiveNetworkMetered();
|
|
} catch (RemoteException e) {
|
|
@@ -4745,6 +4830,10 @@ public class ConnectivityManager {
|
|
* corresponding NetworkRequest you'd like to remove. Cannot be null.
|
|
*/
|
|
public void releaseNetworkRequest(@NonNull PendingIntent operation) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
printStackTrace();
|
|
checkPendingIntentNotNull(operation);
|
|
try {
|
|
@@ -4792,6 +4881,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
public void registerNetworkCallback(@NonNull NetworkRequest request,
|
|
@NonNull NetworkCallback networkCallback) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
registerNetworkCallback(request, networkCallback, getDefaultHandler());
|
|
}
|
|
|
|
@@ -4820,6 +4913,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
public void registerNetworkCallback(@NonNull NetworkRequest request,
|
|
@NonNull NetworkCallback networkCallback, @NonNull Handler handler) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
CallbackHandler cbHandler = new CallbackHandler(handler);
|
|
NetworkCapabilities nc = request.networkCapabilities;
|
|
sendRequestForNetwork(nc, networkCallback, 0, LISTEN, TYPE_NONE, cbHandler);
|
|
@@ -4868,6 +4965,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
public void registerNetworkCallback(@NonNull NetworkRequest request,
|
|
@NonNull PendingIntent operation) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
printStackTrace();
|
|
checkPendingIntentNotNull(operation);
|
|
try {
|
|
@@ -4903,6 +5004,10 @@ public class ConnectivityManager {
|
|
*/
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
public void registerDefaultNetworkCallback(@NonNull NetworkCallback networkCallback) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
registerDefaultNetworkCallback(networkCallback, getDefaultHandler());
|
|
}
|
|
|
|
@@ -4929,6 +5034,10 @@ public class ConnectivityManager {
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
public void registerDefaultNetworkCallback(@NonNull NetworkCallback networkCallback,
|
|
@NonNull Handler handler) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
registerDefaultNetworkCallbackForUid(Process.INVALID_UID, networkCallback, handler);
|
|
}
|
|
|
|
@@ -5034,6 +5143,10 @@ public class ConnectivityManager {
|
|
@SuppressLint("ExecutorRegistration")
|
|
public void registerBestMatchingNetworkCallback(@NonNull NetworkRequest request,
|
|
@NonNull NetworkCallback networkCallback, @NonNull Handler handler) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
final NetworkCapabilities nc = request.networkCapabilities;
|
|
final CallbackHandler cbHandler = new CallbackHandler(handler);
|
|
sendRequestForNetwork(nc, networkCallback, 0, LISTEN_FOR_BEST, TYPE_NONE, cbHandler);
|
|
@@ -5052,6 +5165,10 @@ public class ConnectivityManager {
|
|
* @return {@code true} on success, {@code false} if the {@link Network} is no longer valid.
|
|
*/
|
|
public boolean requestBandwidthUpdate(@NonNull Network network) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.requestBandwidthUpdate(network);
|
|
} catch (RemoteException e) {
|
|
@@ -5072,6 +5189,10 @@ public class ConnectivityManager {
|
|
* @param networkCallback The {@link NetworkCallback} used when making the request.
|
|
*/
|
|
public void unregisterNetworkCallback(@NonNull NetworkCallback networkCallback) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
printStackTrace();
|
|
checkCallbackNotNull(networkCallback);
|
|
final List<NetworkRequest> reqs = new ArrayList<>();
|
|
@@ -5114,6 +5235,10 @@ public class ConnectivityManager {
|
|
* Cannot be null.
|
|
*/
|
|
public void unregisterNetworkCallback(@NonNull PendingIntent operation) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
releaseNetworkRequest(operation);
|
|
}
|
|
|
|
@@ -5333,6 +5458,10 @@ public class ConnectivityManager {
|
|
*/
|
|
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
|
|
public @MultipathPreference int getMultipathPreference(@Nullable Network network) {
|
|
+ if (SpecialRuntimePermAppUtils.isInternetCompatEnabled()) {
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
try {
|
|
return mService.getMultipathPreference(network);
|
|
} catch (RemoteException e) {
|