diff options
author | Oscar Shu <xshu@google.com> | 2020-05-08 00:39:59 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-05-08 00:39:59 +0000 |
commit | b980e07ab21af7d26a046729202606d1ff9fcab9 (patch) | |
tree | 4ebeef870f0d7bcdf1e4369fdf28953de06a430c | |
parent | edc6d783e824e1cf1c25d89a9e4b4389511a2977 (diff) | |
parent | cf601559d982f5270e48a888a8826b86b8afc2ee (diff) |
Merge "Fix WifiLockManager Death link does not exist" into rvc-dev
-rw-r--r-- | service/java/com/android/server/wifi/WifiLockManager.java | 9 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java | 16 |
2 files changed, 23 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/WifiLockManager.java b/service/java/com/android/server/wifi/WifiLockManager.java index 7bbd3aa2e..7cbeea0d3 100644 --- a/service/java/com/android/server/wifi/WifiLockManager.java +++ b/service/java/com/android/server/wifi/WifiLockManager.java @@ -36,6 +36,7 @@ import com.android.server.wifi.util.WorkSourceUtil; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; +import java.util.NoSuchElementException; /** * WifiLockManager maintains the list of wake locks held by different applications. @@ -189,7 +190,6 @@ public class WifiLockManager { // This is to make sure worksource value can not be changed by caller // after function returns. WorkSource newWorkSource = new WorkSource(ws); - return addLock(new WifiLock(lockMode, tag, binder, newWorkSource)); } @@ -804,6 +804,7 @@ public class WifiLockManager { try { mBinder.linkToDeath(this, 0); } catch (RemoteException e) { + Log.e(TAG, "mBinder.linkToDeath failed: " + e.getMessage()); binderDied(); } } @@ -829,7 +830,11 @@ public class WifiLockManager { } public void unlinkDeathRecipient() { - mBinder.unlinkToDeath(this, 0); + try { + mBinder.unlinkToDeath(this, 0); + } catch (NoSuchElementException e) { + Log.e(TAG, "mBinder.unlinkToDeath failed: " + e.getMessage()); + } } public String toString() { diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java index ed27d5041..40c47f4bf 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java @@ -41,6 +41,7 @@ import org.mockito.MockitoAnnotations; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.NoSuchElementException; /** Unit tests for {@link WifiLockManager}. */ @SmallTest @@ -1375,4 +1376,19 @@ public class WifiLockManagerTest extends WifiBaseTest { + " uid=" + Binder.getCallingUid() + " workSource=WorkSource{" + DEFAULT_TEST_UID_1 + "}")); } + + /** + * Verify that an Exception in unlinkDeathRecipient is caught. + */ + @Test + public void testUnlinkDeathRecipiientCatchesException() throws Exception { + acquireWifiLockSuccessful(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "", + mBinder, mWorkSource); + assertEquals(WifiManager.WIFI_MODE_FULL_HIGH_PERF, mWifiLockManager.getStrongestLockMode()); + + doThrow(new NoSuchElementException()).when(mBinder).unlinkToDeath(any(), anyInt()); + releaseLowLatencyWifiLockSuccessful(mBinder); + assertEquals(WifiManager.WIFI_MODE_NO_LOCKS_HELD, + mWifiLockManager.getStrongestLockMode()); + } } |