Merge "Don't remove OnAlarmListener mappings in the client" into rvc-dev am: 007a73c551
Change-Id: I9eaad484821b38b8df8951fee1f3641a2d749503
This commit is contained in:
@@ -31,7 +31,6 @@ import android.os.Parcelable;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.WorkSource;
|
import android.os.WorkSource;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArrayMap;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.proto.ProtoOutputStream;
|
import android.util.proto.ProtoOutputStream;
|
||||||
|
|
||||||
@@ -40,6 +39,8 @@ import libcore.timezone.ZoneInfoDb;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to the system alarm services. These allow you
|
* This class provides access to the system alarm services. These allow you
|
||||||
@@ -222,26 +223,12 @@ public class AlarmManager {
|
|||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
throw ex.rethrowFromSystemServer();
|
throw ex.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (AlarmManager.class) {
|
|
||||||
if (sWrappers != null) {
|
|
||||||
sWrappers.remove(mListener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doAlarm(IAlarmCompleteListener alarmManager) {
|
public void doAlarm(IAlarmCompleteListener alarmManager) {
|
||||||
mCompletion = alarmManager;
|
mCompletion = alarmManager;
|
||||||
|
|
||||||
// Remove this listener from the wrapper cache first; the server side
|
|
||||||
// already considers it gone
|
|
||||||
synchronized (AlarmManager.class) {
|
|
||||||
if (sWrappers != null) {
|
|
||||||
sWrappers.remove(mListener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mHandler.post(this);
|
mHandler.post(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,9 +250,14 @@ public class AlarmManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tracking of the OnAlarmListener -> wrapper mapping, for cancel() support.
|
/**
|
||||||
// Access is synchronized on the AlarmManager class object.
|
* Tracking of the OnAlarmListener -> ListenerWrapper mapping, for cancel() support.
|
||||||
private static ArrayMap<OnAlarmListener, ListenerWrapper> sWrappers;
|
* An entry is guaranteed to stay in this map as long as its ListenerWrapper is held by the
|
||||||
|
* server.
|
||||||
|
*
|
||||||
|
* <p>Access is synchronized on the AlarmManager class object.
|
||||||
|
*/
|
||||||
|
private static WeakHashMap<OnAlarmListener, WeakReference<ListenerWrapper>> sWrappers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* package private on purpose
|
* package private on purpose
|
||||||
@@ -682,14 +674,17 @@ public class AlarmManager {
|
|||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
synchronized (AlarmManager.class) {
|
synchronized (AlarmManager.class) {
|
||||||
if (sWrappers == null) {
|
if (sWrappers == null) {
|
||||||
sWrappers = new ArrayMap<OnAlarmListener, ListenerWrapper>();
|
sWrappers = new WeakHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
recipientWrapper = sWrappers.get(listener);
|
final WeakReference<ListenerWrapper> weakRef = sWrappers.get(listener);
|
||||||
|
if (weakRef != null) {
|
||||||
|
recipientWrapper = weakRef.get();
|
||||||
|
}
|
||||||
// no existing wrapper => build a new one
|
// no existing wrapper => build a new one
|
||||||
if (recipientWrapper == null) {
|
if (recipientWrapper == null) {
|
||||||
recipientWrapper = new ListenerWrapper(listener);
|
recipientWrapper = new ListenerWrapper(listener);
|
||||||
sWrappers.put(listener, recipientWrapper);
|
sWrappers.put(listener, new WeakReference<>(recipientWrapper));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -948,7 +943,10 @@ public class AlarmManager {
|
|||||||
ListenerWrapper wrapper = null;
|
ListenerWrapper wrapper = null;
|
||||||
synchronized (AlarmManager.class) {
|
synchronized (AlarmManager.class) {
|
||||||
if (sWrappers != null) {
|
if (sWrappers != null) {
|
||||||
wrapper = sWrappers.get(listener);
|
final WeakReference<ListenerWrapper> weakRef = sWrappers.get(listener);
|
||||||
|
if (weakRef != null) {
|
||||||
|
wrapper = weakRef.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user