Revert "Use BinderDeathDispatcher for alarm listeners"

This reverts commit 715ecc2bac.

Reason for revert: Causes IAlarmListener objects to leak: b/189091551

Change-Id: I9008db537affb4041be36905c317bdcb5368edc9
Merged-In: I390d9bba37a4040b7e789e0ae04f9980fbed5c12
This commit is contained in:
Suprabh Shukla
2021-05-26 20:55:59 +00:00
parent 715ecc2bac
commit 616e234464
4 changed files with 23 additions and 67 deletions

View File

@@ -63,10 +63,6 @@ public class BinderDeathDispatcher<T extends IInterface> {
@Override
public void binderDied() {
}
@Override
public void binderDied(IBinder who) {
final ArraySet<DeathRecipient> copy;
synchronized (mLock) {
copy = mRecipients;
@@ -81,7 +77,7 @@ public class BinderDeathDispatcher<T extends IInterface> {
// Let's call it without holding the lock.
final int size = copy.size();
for (int i = 0; i < size; i++) {
copy.valueAt(i).binderDied(who);
copy.valueAt(i).binderDied();
}
}
}

View File

@@ -1,15 +1,5 @@
{
"presubmit": [
{
"file_patterns": [
"BinderDeathDispatcher\\.java"
],
"name": "FrameworksCoreTests",
"options": [
{ "include-filter": "com.android.internal.os.BinderDeathDispatcherTest" },
{ "exclude-annotation": "com.android.internal.os.SkipPresubmit" }
]
},
{
"name": "FrameworksCoreTests",
"options": [

View File

@@ -17,7 +17,6 @@ package com.android.internal.os;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
@@ -32,14 +31,14 @@ import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ShellCallback;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.FileDescriptor;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class BinderDeathDispatcherTest {
@@ -121,7 +120,7 @@ public class BinderDeathDispatcherTest {
public void die() {
isAlive = false;
if (mRecipient != null) {
mRecipient.binderDied(this);
mRecipient.binderDied();
}
mRecipient = null;
}
@@ -228,33 +227,33 @@ public class BinderDeathDispatcherTest {
// Kill the targets.
t1.die();
verify(r1, times(1)).binderDied(t1);
verify(r2, times(1)).binderDied(t1);
verify(r3, times(1)).binderDied(t1);
verify(r4, times(0)).binderDied(any());
verify(r5, times(0)).binderDied(any());
verify(r1, times(1)).binderDied();
verify(r2, times(1)).binderDied();
verify(r3, times(1)).binderDied();
verify(r4, times(0)).binderDied();
verify(r5, times(0)).binderDied();
assertThat(d.getTargetsForTest().size()).isEqualTo(2);
reset(r1, r2, r3, r4, r5);
t2.die();
verify(r1, times(1)).binderDied(t2);
verify(r2, times(0)).binderDied(any());
verify(r3, times(0)).binderDied(any());
verify(r4, times(0)).binderDied(any());
verify(r5, times(0)).binderDied(any());
verify(r1, times(1)).binderDied();
verify(r2, times(0)).binderDied();
verify(r3, times(0)).binderDied();
verify(r4, times(0)).binderDied();
verify(r5, times(0)).binderDied();
assertThat(d.getTargetsForTest().size()).isEqualTo(1);
reset(r1, r2, r3, r4, r5);
t3.die();
verify(r1, times(0)).binderDied(any());
verify(r2, times(0)).binderDied(any());
verify(r3, times(1)).binderDied(t3);
verify(r4, times(0)).binderDied(any());
verify(r5, times(1)).binderDied(t3);
verify(r1, times(0)).binderDied();
verify(r2, times(0)).binderDied();
verify(r3, times(1)).binderDied();
verify(r4, times(0)).binderDied();
verify(r5, times(1)).binderDied();
assertThat(d.getTargetsForTest().size()).isEqualTo(0);
@@ -263,27 +262,4 @@ public class BinderDeathDispatcherTest {
assertThat(d.getTargetsForTest().size()).isEqualTo(0);
}
@Test
public void duplicateRegistrations() {
BinderDeathDispatcher<MyTarget> d = new BinderDeathDispatcher<>();
MyTarget t1 = new MyTarget();
DeathRecipient r1 = mock(DeathRecipient.class);
DeathRecipient r2 = mock(DeathRecipient.class);
for (int i = 0; i < 5; i++) {
assertThat(d.linkToDeath(t1, r1)).isEqualTo(1);
}
assertThat(d.linkToDeath(t1, r2)).isEqualTo(2);
t1.die();
verify(r1, times(1)).binderDied(t1);
verify(r2, times(1)).binderDied(t1);
d.unlinkToDeath(t1, r1);
d.unlinkToDeath(t1, r2);
assertThat(d.getTargetsForTest()).isEmpty();
}
}

View File

@@ -91,7 +91,6 @@ import android.util.proto.ProtoOutputStream;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.BinderDeathDispatcher;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.FrameworkStatsLog;
@@ -177,8 +176,6 @@ class AlarmManagerService extends SystemService {
.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
| Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
private static final BinderDeathDispatcher<IAlarmListener> sListenerDeathDispatcher =
new BinderDeathDispatcher<>();
final LocalLog mLog = new LocalLog(TAG);
AppOpsManager mAppOps;
@@ -1704,8 +1701,9 @@ class AlarmManagerService extends SystemService {
}
if (directReceiver != null) {
if (sListenerDeathDispatcher.linkToDeath(directReceiver, mListenerDeathRecipient)
<= 0) {
try {
directReceiver.asBinder().linkToDeath(mListenerDeathRecipient, 0);
} catch (RemoteException e) {
Slog.w(TAG, "Dropping unreachable alarm listener " + listenerTag);
return;
}
@@ -2466,10 +2464,6 @@ class AlarmManagerService extends SystemService {
pw.println("]");
pw.println();
pw.println("Listener death dispatcher state:");
sListenerDeathDispatcher.dump(pw, " ");
pw.println();
if (mLog.dump(pw, " Recent problems", " ")) {
pw.println();
}