summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-05-22 16:57:52 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-05-22 16:57:59 +0000
commitf9b25d48b7cadff8cb8eead96114f8b6725cc800 (patch)
treea1ad39b409bc285d42004960b92432ccfc5c03fd
parenta3e8c64fb19018c0a5ed0c8faf1dfe22a49aa17b (diff)
parent0f257d8ab5787450bdd24119ad809ffdfd29f98d (diff)
Merge "WifiServiceImpl: add packageName to startLOHS call" into oc-dev
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java6
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java19
2 files changed, 14 insertions, 11 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index aa1316d4e..51ade7234 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -1117,6 +1117,7 @@ public class WifiServiceImpl extends IWifiManager.Stub {
*
* @param messenger Messenger to send messages to the corresponding WifiManager.
* @param binder IBinder instance to allow cleanup if the app dies
+ * @param packageName String name of the calling package
*
* @return int return code for attempt to start LocalOnlyHotspot.
*
@@ -1126,15 +1127,14 @@ public class WifiServiceImpl extends IWifiManager.Stub {
* have an outstanding request.
*/
@Override
- public int startLocalOnlyHotspot(Messenger messenger, IBinder binder) {
+ public int startLocalOnlyHotspot(Messenger messenger, IBinder binder, String packageName) {
// first check if the caller has permission to start a local only hotspot
// need to check for WIFI_STATE_CHANGE and location permission
final int uid = Binder.getCallingUid();
final int pid = Binder.getCallingPid();
- final String pkgName = mContext.getOpPackageName();
enforceChangePermission();
- enforceLocationPermission(pkgName, uid);
+ enforceLocationPermission(packageName, uid);
// also need to verify that Locations services are enabled.
if (mSettingsStore.getLocationModeSetting(mContext) == Settings.Secure.LOCATION_MODE_OFF) {
throw new SecurityException("Location mode is not enabled.");
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 65869aad1..0c608d9ea 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -751,7 +751,8 @@ public class WifiServiceImplTest {
.thenReturn(LOCATION_MODE_HIGH_ACCURACY);
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING))
.thenReturn(false);
- int result = mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder);
+ int result = mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder,
+ TEST_PACKAGE_NAME);
assertEquals(LocalOnlyHotspotCallback.REQUEST_REGISTERED, result);
}
@@ -773,7 +774,7 @@ public class WifiServiceImplTest {
doThrow(new SecurityException()).when(mContext)
.enforceCallingOrSelfPermission(eq(android.Manifest.permission.CHANGE_WIFI_STATE),
eq("WifiService"));
- mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder);
+ mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder, TEST_PACKAGE_NAME);
}
/**
@@ -786,7 +787,7 @@ public class WifiServiceImplTest {
doThrow(new SecurityException())
.when(mWifiPermissionsUtil).enforceLocationPermission(eq(TEST_PACKAGE_NAME),
anyInt());
- mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder);
+ mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder, TEST_PACKAGE_NAME);
}
/**
@@ -796,7 +797,7 @@ public class WifiServiceImplTest {
@Test(expected = SecurityException.class)
public void testStartLocalOnlyHotspotThrowsSecurityExceptionWithoutLocationEnabled() {
when(mSettingsStore.getLocationModeSetting(mContext)).thenReturn(LOCATION_MODE_OFF);
- mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder);
+ mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder, TEST_PACKAGE_NAME);
}
/**
@@ -808,7 +809,8 @@ public class WifiServiceImplTest {
.thenReturn(LOCATION_MODE_HIGH_ACCURACY);
mWifiServiceImpl.updateInterfaceIpState(WIFI_IFACE_NAME, IFACE_IP_MODE_TETHERED);
mLooper.dispatchAll();
- int returnCode = mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder);
+ int returnCode = mWifiServiceImpl.startLocalOnlyHotspot(
+ mAppMessenger, mAppBinder, TEST_PACKAGE_NAME);
assertEquals(ERROR_INCOMPATIBLE_MODE, returnCode);
}
@@ -821,7 +823,8 @@ public class WifiServiceImplTest {
.thenReturn(LOCATION_MODE_HIGH_ACCURACY);
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING))
.thenReturn(true);
- int returnCode = mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder);
+ int returnCode = mWifiServiceImpl.startLocalOnlyHotspot(
+ mAppMessenger, mAppBinder, TEST_PACKAGE_NAME);
assertEquals(ERROR_TETHERING_DISALLOWED, returnCode);
}
@@ -833,7 +836,7 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
// now do the second request that will fail
- mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder);
+ mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder, TEST_PACKAGE_NAME);
}
/**
@@ -1395,7 +1398,7 @@ public class WifiServiceImplTest {
Messenger messenger2 = new Messenger(mHandler);
IBinder binder2 = mock(IBinder.class);
- int result = mWifiServiceImpl.startLocalOnlyHotspot(messenger2, binder2);
+ int result = mWifiServiceImpl.startLocalOnlyHotspot(messenger2, binder2, TEST_PACKAGE_NAME);
assertEquals(LocalOnlyHotspotCallback.REQUEST_REGISTERED, result);
mLooper.dispatchAll();