summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ye Jiao <ye.jiao@mediatek.com> 2019-01-28 12:54:22 +0800
committer Iris Chang <iris.chang@mediatek.com> 2019-03-29 07:25:57 +0000
commit21f962585d4d1cd218b4d29bc5b436f13e48a265 (patch)
treedd624e747ba56437775ce7e733533005baa8dada
parent09e3d8c3eb7869df54e692ed8588e05ec445964b (diff)
Fix getWifiManager exception if phone is encrypted
[Issue Details] NetworkPolicyManagerService may invoke dispatchRestrictBackgroundChanged after reboot if settings changed, and invokes untetherAll in turn, which triggers ServiceNotFoundException indirectly if the device is under encryption. The cause is that WifiService is not running if the device is still locked. [Solution] In order to avoid ServiceNotFoundException in setWifiTethering, we add check on return value of getWifiManager. Moreover, check of UsbManager is also added to prevent potential similar issues of USB tethering. Bug: 123504004 Test: FrameworksNetTests adb shell am instrument -w com.android.frameworks.tests.net Test: CTS - CtsNetTestCases ANDROID_BUILD_droid-cts/tools/cts-tradefed run cts -m CtsNetTestCases Test: CTS - CtsNetTestCasesLegacyApi22 ANDROID_BUILD_droid-cts/tools/cts-tradefed run cts -m CtsNetTestCasesLegacyApi22 Test: CTS - CtsNetTestCasesLegacyPermission22 ANDROID_BUILD_droid-cts/tools/cts-tradefed run cts -m CtsNetTestCasesLegacyPermission22 Change-Id: I2643188b51900f97ba58c8614c66cb55ebfaa2f6
-rw-r--r--services/core/java/com/android/server/connectivity/Tethering.java17
1 files changed, 13 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java
index 35704d404ff3..6491cecdbed6 100644
--- a/services/core/java/com/android/server/connectivity/Tethering.java
+++ b/services/core/java/com/android/server/connectivity/Tethering.java
@@ -423,21 +423,25 @@ public class Tethering extends BaseNetworkObserver {
}
private int setWifiTethering(final boolean enable) {
- int rval = TETHER_ERROR_MASTER_ERROR;
final long ident = Binder.clearCallingIdentity();
try {
synchronized (mPublicSync) {
- mWifiTetherRequested = enable;
final WifiManager mgr = getWifiManager();
+ if (mgr == null) {
+ mLog.e("setWifiTethering: failed to get WifiManager!");
+ return TETHER_ERROR_SERVICE_UNAVAIL;
+ }
if ((enable && mgr.startSoftAp(null /* use existing wifi config */)) ||
(!enable && mgr.stopSoftAp())) {
- rval = TETHER_ERROR_NO_ERROR;
+ mWifiTetherRequested = enable;
+ return TETHER_ERROR_NO_ERROR;
}
}
} finally {
Binder.restoreCallingIdentity(ident);
}
- return rval;
+
+ return TETHER_ERROR_MASTER_ERROR;
}
private void setBluetoothTethering(final boolean enable, final ResultReceiver receiver) {
@@ -989,6 +993,11 @@ public class Tethering extends BaseNetworkObserver {
public int setUsbTethering(boolean enable) {
if (VDBG) Log.d(TAG, "setUsbTethering(" + enable + ")");
UsbManager usbManager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
+ if (usbManager == null) {
+ mLog.e("setUsbTethering: failed to get UsbManager!");
+ return TETHER_ERROR_SERVICE_UNAVAIL;
+ }
+
synchronized (mPublicSync) {
usbManager.setCurrentFunctions(enable ? UsbManager.FUNCTION_RNDIS
: UsbManager.FUNCTION_NONE);