Merge "Initialize TetheringManager lazily" am: 7c5902df7e am: b0504221b4

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1736505

Change-Id: I828ded55c5d478808abffda4259248cfcad7586c
This commit is contained in:
Remi NGUYEN VAN
2021-06-21 10:34:22 +00:00
committed by Automerger Merge Worker

View File

@@ -936,7 +936,17 @@ public class ConnectivityManager {
private final Context mContext; private final Context mContext;
private final TetheringManager mTetheringManager; @GuardedBy("mTetheringEventCallbacks")
private TetheringManager mTetheringManager;
private TetheringManager getTetheringManager() {
synchronized (mTetheringEventCallbacks) {
if (mTetheringManager == null) {
mTetheringManager = mContext.getSystemService(TetheringManager.class);
}
return mTetheringManager;
}
}
/** /**
* Tests if a given integer represents a valid network type. * Tests if a given integer represents a valid network type.
@@ -2395,7 +2405,6 @@ public class ConnectivityManager {
public ConnectivityManager(Context context, IConnectivityManager service) { public ConnectivityManager(Context context, IConnectivityManager service) {
mContext = Objects.requireNonNull(context, "missing context"); mContext = Objects.requireNonNull(context, "missing context");
mService = Objects.requireNonNull(service, "missing IConnectivityManager"); mService = Objects.requireNonNull(service, "missing IConnectivityManager");
mTetheringManager = (TetheringManager) mContext.getSystemService(Context.TETHERING_SERVICE);
sInstance = this; sInstance = this;
} }
@@ -2466,7 +2475,7 @@ public class ConnectivityManager {
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated @Deprecated
public String[] getTetherableIfaces() { public String[] getTetherableIfaces() {
return mTetheringManager.getTetherableIfaces(); return getTetheringManager().getTetherableIfaces();
} }
/** /**
@@ -2481,7 +2490,7 @@ public class ConnectivityManager {
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated @Deprecated
public String[] getTetheredIfaces() { public String[] getTetheredIfaces() {
return mTetheringManager.getTetheredIfaces(); return getTetheringManager().getTetheredIfaces();
} }
/** /**
@@ -2502,7 +2511,7 @@ public class ConnectivityManager {
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated @Deprecated
public String[] getTetheringErroredIfaces() { public String[] getTetheringErroredIfaces() {
return mTetheringManager.getTetheringErroredIfaces(); return getTetheringManager().getTetheringErroredIfaces();
} }
/** /**
@@ -2546,7 +2555,7 @@ public class ConnectivityManager {
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@Deprecated @Deprecated
public int tether(String iface) { public int tether(String iface) {
return mTetheringManager.tether(iface); return getTetheringManager().tether(iface);
} }
/** /**
@@ -2570,7 +2579,7 @@ public class ConnectivityManager {
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated @Deprecated
public int untether(String iface) { public int untether(String iface) {
return mTetheringManager.untether(iface); return getTetheringManager().untether(iface);
} }
/** /**
@@ -2596,7 +2605,7 @@ public class ConnectivityManager {
@RequiresPermission(anyOf = {android.Manifest.permission.TETHER_PRIVILEGED, @RequiresPermission(anyOf = {android.Manifest.permission.TETHER_PRIVILEGED,
android.Manifest.permission.WRITE_SETTINGS}) android.Manifest.permission.WRITE_SETTINGS})
public boolean isTetheringSupported() { public boolean isTetheringSupported() {
return mTetheringManager.isTetheringSupported(); return getTetheringManager().isTetheringSupported();
} }
/** /**
@@ -2689,7 +2698,7 @@ public class ConnectivityManager {
final TetheringRequest request = new TetheringRequest.Builder(type) final TetheringRequest request = new TetheringRequest.Builder(type)
.setShouldShowEntitlementUi(showProvisioningUi).build(); .setShouldShowEntitlementUi(showProvisioningUi).build();
mTetheringManager.startTethering(request, executor, tetheringCallback); getTetheringManager().startTethering(request, executor, tetheringCallback);
} }
/** /**
@@ -2708,7 +2717,7 @@ public class ConnectivityManager {
@Deprecated @Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void stopTethering(int type) { public void stopTethering(int type) {
mTetheringManager.stopTethering(type); getTetheringManager().stopTethering(type);
} }
/** /**
@@ -2766,7 +2775,7 @@ public class ConnectivityManager {
synchronized (mTetheringEventCallbacks) { synchronized (mTetheringEventCallbacks) {
mTetheringEventCallbacks.put(callback, tetherCallback); mTetheringEventCallbacks.put(callback, tetherCallback);
mTetheringManager.registerTetheringEventCallback(executor, tetherCallback); getTetheringManager().registerTetheringEventCallback(executor, tetherCallback);
} }
} }
@@ -2788,7 +2797,7 @@ public class ConnectivityManager {
synchronized (mTetheringEventCallbacks) { synchronized (mTetheringEventCallbacks) {
final TetheringEventCallback tetherCallback = final TetheringEventCallback tetherCallback =
mTetheringEventCallbacks.remove(callback); mTetheringEventCallbacks.remove(callback);
mTetheringManager.unregisterTetheringEventCallback(tetherCallback); getTetheringManager().unregisterTetheringEventCallback(tetherCallback);
} }
} }
@@ -2808,7 +2817,7 @@ public class ConnectivityManager {
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated @Deprecated
public String[] getTetherableUsbRegexs() { public String[] getTetherableUsbRegexs() {
return mTetheringManager.getTetherableUsbRegexs(); return getTetheringManager().getTetherableUsbRegexs();
} }
/** /**
@@ -2826,7 +2835,7 @@ public class ConnectivityManager {
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated @Deprecated
public String[] getTetherableWifiRegexs() { public String[] getTetherableWifiRegexs() {
return mTetheringManager.getTetherableWifiRegexs(); return getTetheringManager().getTetherableWifiRegexs();
} }
/** /**
@@ -2845,7 +2854,7 @@ public class ConnectivityManager {
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated @Deprecated
public String[] getTetherableBluetoothRegexs() { public String[] getTetherableBluetoothRegexs() {
return mTetheringManager.getTetherableBluetoothRegexs(); return getTetheringManager().getTetherableBluetoothRegexs();
} }
/** /**
@@ -2869,7 +2878,7 @@ public class ConnectivityManager {
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated @Deprecated
public int setUsbTethering(boolean enable) { public int setUsbTethering(boolean enable) {
return mTetheringManager.setUsbTethering(enable); return getTetheringManager().setUsbTethering(enable);
} }
/** /**
@@ -2985,7 +2994,7 @@ public class ConnectivityManager {
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@Deprecated @Deprecated
public int getLastTetherError(String iface) { public int getLastTetherError(String iface) {
int error = mTetheringManager.getLastTetherError(iface); int error = getTetheringManager().getLastTetherError(iface);
if (error == TetheringManager.TETHER_ERROR_UNKNOWN_TYPE) { if (error == TetheringManager.TETHER_ERROR_UNKNOWN_TYPE) {
// TETHER_ERROR_UNKNOWN_TYPE was introduced with TetheringManager and has never been // TETHER_ERROR_UNKNOWN_TYPE was introduced with TetheringManager and has never been
// returned by ConnectivityManager. Convert it to the legacy TETHER_ERROR_UNKNOWN_IFACE // returned by ConnectivityManager. Convert it to the legacy TETHER_ERROR_UNKNOWN_IFACE
@@ -3067,7 +3076,7 @@ public class ConnectivityManager {
} }
}; };
mTetheringManager.requestLatestTetheringEntitlementResult(type, wrappedListener, getTetheringManager().requestLatestTetheringEntitlementResult(type, wrappedListener,
showEntitlementUi); showEntitlementUi);
} }
@@ -4849,7 +4858,7 @@ public class ConnectivityManager {
public void factoryReset() { public void factoryReset() {
try { try {
mService.factoryReset(); mService.factoryReset();
mTetheringManager.stopAllTethering(); getTetheringManager().stopAllTethering();
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }