summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-03-29 13:14:15 -0700
committerRebecca Silberstein <silberst@google.com>2017-04-28 22:24:05 -0700
commit768b7a7cb87525e92eb1a59a7a3e0c98b9f6f238 (patch)
tree3a227d9e79fb60ebf17ee37942449ee58fb76a12 /tests
parent003b695597a1f010724662fbf4ac76953a71e3b8 (diff)
LocalOnlyHotspotRequestInfo: track LOHS requests
Add a new class to keep track of apps Binder instances that request LocalOnlyHotspot. When the app dies, it will trigger a callback to remove the request. We will also unlinkToDeath when the app calls to stop using LocalOnlyHotspot. This object also contains a Messenger that will allow WifiServiceImpl to communicate updates to WifiManager for the requesting app. Bug: 36732530 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: Ia366a3cc7339cdea94a137d62905b15b72cf05c0
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java151
1 files changed, 151 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java b/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java
new file mode 100644
index 000000000..0e8ead2e6
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.verify;
+
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.test.TestLooper;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/*
+ * Unit tests for {@link com.android.server.wifi.LocalOnlyHotspotRequestInfo}.
+ */
+@SmallTest
+public class LocalOnlyHotspotRequestInfoTest {
+
+ private static final String TAG = "LocalOnlyHotspotRequestInfoTest";
+ @Mock IBinder mAppBinder;
+ @Mock LocalOnlyHotspotRequestInfo.RequestingApplicationDeathCallback mCallback;
+ private Handler mHandler;
+ private Messenger mMessenger;
+ private TestLooper mTestLooper;
+ RemoteException mRemoteException;
+ private LocalOnlyHotspotRequestInfo mLOHSRequestInfo;
+
+ /**
+ * Setup test.
+ */
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mTestLooper = new TestLooper();
+ mHandler = new Handler(mTestLooper.getLooper());
+ mMessenger = new Messenger(mHandler);
+ mRemoteException = new RemoteException("Test Remote Exception");
+ }
+
+ /**
+ * Make sure we link the call to request LocalOnlyHotspot by an app is linked to their Binder
+ * call. This allows us to clean up if the app dies.
+ */
+ @Test
+ public void verifyBinderLinkToDeathIsCalled() throws Exception {
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mAppBinder, mMessenger, mCallback);
+ verify(mAppBinder).linkToDeath(eq(mLOHSRequestInfo), eq(0));
+ }
+
+ /**
+ * Calls to create the requestor to binder death should not pass null callback.
+ */
+ @Test(expected = NullPointerException.class)
+ public void verifyNullCallbackChecked() throws Exception {
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mAppBinder, mMessenger, null);
+ }
+
+ /**
+ * Calls to create the request info object should not pass a null messenger.
+ */
+ @Test(expected = NullPointerException.class)
+ public void verifyNullMessengerChecked() throws Exception {
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mAppBinder, null, mCallback);
+ }
+
+ /**
+ * Calls to link the requestor to binder death should not pass null binder
+ */
+ @Test(expected = NullPointerException.class)
+ public void verifyNullBinderChecked() throws Exception {
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(null, mMessenger, mCallback);
+ }
+
+ /**
+ * Calls to unlink the DeathRecipient should call to unlink from Binder.
+ */
+ @Test
+ public void verifyUnlinkDeathRecipientUnlinksFromBinder() throws Exception {
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mAppBinder, mMessenger, mCallback);
+ mLOHSRequestInfo.unlinkDeathRecipient();
+ verify(mAppBinder).unlinkToDeath(eq(mLOHSRequestInfo), eq(0));
+ }
+
+ /**
+ * Binder death notification should trigger a callback on the requestor.
+ */
+ @Test
+ public void verifyBinderDeathTriggersCallback() {
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mAppBinder, mMessenger, mCallback);
+ mLOHSRequestInfo.binderDied();
+ verify(mCallback).onLocalOnlyHotspotRequestorDeath(eq(mLOHSRequestInfo));
+ }
+
+ /**
+ * Verify a RemoteException when calling linkToDeath triggers the callback.
+ */
+ @Test
+ public void verifyRemoteExceptionTriggersCallback() throws Exception {
+ doThrow(mRemoteException).when(mAppBinder)
+ .linkToDeath(any(IBinder.DeathRecipient.class), eq(0));
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mAppBinder, mMessenger, mCallback);
+ verify(mCallback).onLocalOnlyHotspotRequestorDeath(eq(mLOHSRequestInfo));
+ }
+
+ /**
+ * Verify the uid is properly set.
+ */
+ @Test
+ public void verifyUid() {
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mAppBinder, mMessenger, mCallback);
+ assertEquals(Process.myUid(), mLOHSRequestInfo.getUid());
+ }
+
+ /**
+ * Verify that sendMessage does send a Message properly
+ */
+ @Test
+ public void verifySendMessenger() throws Exception {
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mAppBinder, mMessenger, mCallback);
+ mLOHSRequestInfo.sendMessage(1, 1);
+ Message message = mTestLooper.nextMessage();
+ assertEquals(1, message.what);
+ assertEquals(1, message.arg1);
+ }
+}