Merge "WifiManager: get startLOHS packageName" into oc-dev

This commit is contained in:
Rebecca Silberstein
2017-05-22 16:57:52 +00:00
committed by Android (Google) Code Review
3 changed files with 35 additions and 30 deletions

View File

@@ -131,7 +131,7 @@ interface IWifiManager
boolean stopSoftAp(); boolean stopSoftAp();
int startLocalOnlyHotspot(in Messenger messenger, in IBinder binder); int startLocalOnlyHotspot(in Messenger messenger, in IBinder binder, in String packageName);
void stopLocalOnlyHotspot(); void stopLocalOnlyHotspot();

View File

@@ -1899,7 +1899,9 @@ public class WifiManager {
LocalOnlyHotspotCallbackProxy proxy = LocalOnlyHotspotCallbackProxy proxy =
new LocalOnlyHotspotCallbackProxy(this, looper, callback); new LocalOnlyHotspotCallbackProxy(this, looper, callback);
try { try {
int returnCode = mService.startLocalOnlyHotspot(proxy.getMessenger(), new Binder()); String packageName = mContext.getOpPackageName();
int returnCode = mService.startLocalOnlyHotspot(
proxy.getMessenger(), new Binder(), packageName);
if (returnCode != LocalOnlyHotspotCallback.REQUEST_REGISTERED) { if (returnCode != LocalOnlyHotspotCallback.REQUEST_REGISTERED) {
// Send message to the proxy to make sure we call back on the correct thread // Send message to the proxy to make sure we call back on the correct thread
proxy.notifyFailed(returnCode); proxy.notifyFailed(returnCode);

View File

@@ -58,6 +58,7 @@ public class WifiManagerTest {
private static final int ERROR_NOT_SET = -1; private static final int ERROR_NOT_SET = -1;
private static final int ERROR_TEST_REASON = 5; private static final int ERROR_TEST_REASON = 5;
private static final String TEST_PACKAGE_NAME = "TestPackage";
@Mock Context mContext; @Mock Context mContext;
@Mock IWifiManager mWifiService; @Mock IWifiManager mWifiService;
@@ -76,6 +77,7 @@ public class WifiManagerTest {
mLooper = new TestLooper(); mLooper = new TestLooper();
mHandler = spy(new Handler(mLooper.getLooper())); mHandler = spy(new Handler(mLooper.getLooper()));
when(mContext.getApplicationInfo()).thenReturn(mApplicationInfo); when(mContext.getApplicationInfo()).thenReturn(mApplicationInfo);
when(mContext.getOpPackageName()).thenReturn(TEST_PACKAGE_NAME);
mWifiServiceMessenger = new Messenger(mHandler); mWifiServiceMessenger = new Messenger(mHandler);
mWifiManager = new WifiManager(mContext, mWifiService, mLooper.getLooper()); mWifiManager = new WifiManager(mContext, mWifiService, mLooper.getLooper());
@@ -126,8 +128,8 @@ public class WifiManagerTest {
@Test @Test
public void testCreationAndCloseOfLocalOnlyHotspotReservation() throws Exception { public void testCreationAndCloseOfLocalOnlyHotspotReservation() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class),
.thenReturn(REQUEST_REGISTERED); anyString())).thenReturn(REQUEST_REGISTERED);
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
callback.onStarted(mWifiManager.new LocalOnlyHotspotReservation(mApConfig)); callback.onStarted(mWifiManager.new LocalOnlyHotspotReservation(mApConfig));
@@ -144,8 +146,8 @@ public class WifiManagerTest {
public void testLocalOnlyHotspotReservationCallsStopProperlyInTryWithResources() public void testLocalOnlyHotspotReservationCallsStopProperlyInTryWithResources()
throws Exception { throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class),
.thenReturn(REQUEST_REGISTERED); anyString())).thenReturn(REQUEST_REGISTERED);
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
callback.onStarted(mWifiManager.new LocalOnlyHotspotReservation(mApConfig)); callback.onStarted(mWifiManager.new LocalOnlyHotspotReservation(mApConfig));
@@ -304,7 +306,8 @@ public class WifiManagerTest {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
verify(mWifiService).startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)); verify(mWifiService)
.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class), anyString());
} }
/** /**
@@ -315,7 +318,7 @@ public class WifiManagerTest {
public void testStartLocalOnlyHotspotThrowsSecurityException() throws Exception { public void testStartLocalOnlyHotspotThrowsSecurityException() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
doThrow(new SecurityException()).when(mWifiService) doThrow(new SecurityException()).when(mWifiService)
.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)); .startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class), anyString());
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
} }
@@ -327,7 +330,7 @@ public class WifiManagerTest {
public void testStartLocalOnlyHotspotThrowsIllegalStateException() throws Exception { public void testStartLocalOnlyHotspotThrowsIllegalStateException() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
doThrow(new IllegalStateException()).when(mWifiService) doThrow(new IllegalStateException()).when(mWifiService)
.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)); .startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class), anyString());
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
} }
@@ -337,8 +340,8 @@ public class WifiManagerTest {
@Test @Test
public void testCorrectLooperIsUsedForHandler() throws Exception { public void testCorrectLooperIsUsedForHandler() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class),
.thenReturn(ERROR_INCOMPATIBLE_MODE); anyString())).thenReturn(ERROR_INCOMPATIBLE_MODE);
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
mLooper.dispatchAll(); mLooper.dispatchAll();
assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason); assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason);
@@ -355,8 +358,8 @@ public class WifiManagerTest {
TestLooper altLooper = new TestLooper(); TestLooper altLooper = new TestLooper();
when(mContext.getMainLooper()).thenReturn(altLooper.getLooper()); when(mContext.getMainLooper()).thenReturn(altLooper.getLooper());
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class),
.thenReturn(ERROR_INCOMPATIBLE_MODE); anyString())).thenReturn(ERROR_INCOMPATIBLE_MODE);
mWifiManager.startLocalOnlyHotspot(callback, null); mWifiManager.startLocalOnlyHotspot(callback, null);
altLooper.dispatchAll(); altLooper.dispatchAll();
assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason); assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason);
@@ -374,7 +377,7 @@ public class WifiManagerTest {
TestLooper callbackLooper = new TestLooper(); TestLooper callbackLooper = new TestLooper();
Handler callbackHandler = new Handler(callbackLooper.getLooper()); Handler callbackHandler = new Handler(callbackLooper.getLooper());
when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(), when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(),
any(IBinder.class))).thenReturn(REQUEST_REGISTERED); any(IBinder.class), anyString())).thenReturn(REQUEST_REGISTERED);
mWifiManager.startLocalOnlyHotspot(callback, callbackHandler); mWifiManager.startLocalOnlyHotspot(callback, callbackHandler);
callbackLooper.dispatchAll(); callbackLooper.dispatchAll();
mLooper.dispatchAll(); mLooper.dispatchAll();
@@ -401,7 +404,7 @@ public class WifiManagerTest {
TestLooper callbackLooper = new TestLooper(); TestLooper callbackLooper = new TestLooper();
Handler callbackHandler = new Handler(callbackLooper.getLooper()); Handler callbackHandler = new Handler(callbackLooper.getLooper());
when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(), when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(),
any(IBinder.class))).thenReturn(REQUEST_REGISTERED); any(IBinder.class), anyString())).thenReturn(REQUEST_REGISTERED);
mWifiManager.startLocalOnlyHotspot(callback, callbackHandler); mWifiManager.startLocalOnlyHotspot(callback, callbackHandler);
callbackLooper.dispatchAll(); callbackLooper.dispatchAll();
mLooper.dispatchAll(); mLooper.dispatchAll();
@@ -426,7 +429,7 @@ public class WifiManagerTest {
TestLooper callbackLooper = new TestLooper(); TestLooper callbackLooper = new TestLooper();
Handler callbackHandler = new Handler(callbackLooper.getLooper()); Handler callbackHandler = new Handler(callbackLooper.getLooper());
when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(), when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(),
any(IBinder.class))).thenReturn(REQUEST_REGISTERED); any(IBinder.class), anyString())).thenReturn(REQUEST_REGISTERED);
mWifiManager.startLocalOnlyHotspot(callback, callbackHandler); mWifiManager.startLocalOnlyHotspot(callback, callbackHandler);
callbackLooper.dispatchAll(); callbackLooper.dispatchAll();
mLooper.dispatchAll(); mLooper.dispatchAll();
@@ -449,7 +452,7 @@ public class WifiManagerTest {
TestLooper callbackLooper = new TestLooper(); TestLooper callbackLooper = new TestLooper();
Handler callbackHandler = new Handler(callbackLooper.getLooper()); Handler callbackHandler = new Handler(callbackLooper.getLooper());
when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(), when(mWifiService.startLocalOnlyHotspot(mMessengerCaptor.capture(),
any(IBinder.class))).thenReturn(REQUEST_REGISTERED); any(IBinder.class), anyString())).thenReturn(REQUEST_REGISTERED);
mWifiManager.startLocalOnlyHotspot(callback, callbackHandler); mWifiManager.startLocalOnlyHotspot(callback, callbackHandler);
callbackLooper.dispatchAll(); callbackLooper.dispatchAll();
mLooper.dispatchAll(); mLooper.dispatchAll();
@@ -470,8 +473,8 @@ public class WifiManagerTest {
@Test @Test
public void testLocalOnlyHotspotCallbackFullOnIncompatibleMode() throws Exception { public void testLocalOnlyHotspotCallbackFullOnIncompatibleMode() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class),
.thenReturn(ERROR_INCOMPATIBLE_MODE); anyString())).thenReturn(ERROR_INCOMPATIBLE_MODE);
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
mLooper.dispatchAll(); mLooper.dispatchAll();
assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason); assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason);
@@ -486,8 +489,8 @@ public class WifiManagerTest {
@Test @Test
public void testLocalOnlyHotspotCallbackFullOnTetheringDisallowed() throws Exception { public void testLocalOnlyHotspotCallbackFullOnTetheringDisallowed() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class),
.thenReturn(ERROR_TETHERING_DISALLOWED); anyString())).thenReturn(ERROR_TETHERING_DISALLOWED);
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
mLooper.dispatchAll(); mLooper.dispatchAll();
assertEquals(ERROR_TETHERING_DISALLOWED, callback.mFailureReason); assertEquals(ERROR_TETHERING_DISALLOWED, callback.mFailureReason);
@@ -504,7 +507,7 @@ public class WifiManagerTest {
public void testLocalOnlyHotspotCallbackFullOnSecurityException() throws Exception { public void testLocalOnlyHotspotCallbackFullOnSecurityException() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
doThrow(new SecurityException()).when(mWifiService) doThrow(new SecurityException()).when(mWifiService)
.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class)); .startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class), anyString());
try { try {
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
} catch (SecurityException e) { } catch (SecurityException e) {
@@ -524,8 +527,8 @@ public class WifiManagerTest {
@Test @Test
public void testLocalOnlyHotspotCallbackFullOnNoChannelError() throws Exception { public void testLocalOnlyHotspotCallbackFullOnNoChannelError() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class),
.thenReturn(REQUEST_REGISTERED); anyString())).thenReturn(REQUEST_REGISTERED);
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
mLooper.dispatchAll(); mLooper.dispatchAll();
//assertEquals(ERROR_NO_CHANNEL, callback.mFailureReason); //assertEquals(ERROR_NO_CHANNEL, callback.mFailureReason);
@@ -540,8 +543,8 @@ public class WifiManagerTest {
@Test @Test
public void testCancelLocalOnlyHotspotRequestCallsStopOnWifiService() throws Exception { public void testCancelLocalOnlyHotspotRequestCallsStopOnWifiService() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class),
.thenReturn(REQUEST_REGISTERED); anyString())).thenReturn(REQUEST_REGISTERED);
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
mWifiManager.cancelLocalOnlyHotspotRequest(); mWifiManager.cancelLocalOnlyHotspotRequest();
verify(mWifiService).stopLocalOnlyHotspot(); verify(mWifiService).stopLocalOnlyHotspot();
@@ -562,8 +565,8 @@ public class WifiManagerTest {
@Test @Test
public void testCallbackAfterLocalOnlyHotspotWasCancelled() throws Exception { public void testCallbackAfterLocalOnlyHotspotWasCancelled() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class),
.thenReturn(REQUEST_REGISTERED); anyString())).thenReturn(REQUEST_REGISTERED);
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
mWifiManager.cancelLocalOnlyHotspotRequest(); mWifiManager.cancelLocalOnlyHotspotRequest();
verify(mWifiService).stopLocalOnlyHotspot(); verify(mWifiService).stopLocalOnlyHotspot();
@@ -581,8 +584,8 @@ public class WifiManagerTest {
@Test @Test
public void testCancelAfterLocalOnlyHotspotCallbackTriggered() throws Exception { public void testCancelAfterLocalOnlyHotspotCallbackTriggered() throws Exception {
TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(); TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback();
when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class))) when(mWifiService.startLocalOnlyHotspot(any(Messenger.class), any(IBinder.class),
.thenReturn(ERROR_INCOMPATIBLE_MODE); anyString())).thenReturn(ERROR_INCOMPATIBLE_MODE);
mWifiManager.startLocalOnlyHotspot(callback, mHandler); mWifiManager.startLocalOnlyHotspot(callback, mHandler);
mLooper.dispatchAll(); mLooper.dispatchAll();
assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason); assertEquals(ERROR_INCOMPATIBLE_MODE, callback.mFailureReason);