DO NOT MERGE Local timeout should cancel remote work

Ensure that when getCurrentLocation() times out locally, remote work in
system server is also canceled.

Bug: 168666216
Test: manual
Change-Id: Idde2156323c3fca0ed94ff886a4277122c598753
This commit is contained in:
Soonil Nagarkar
2020-09-24 09:35:49 -07:00
parent c231992ac3
commit 2d6bcbecd3

View File

@@ -732,7 +732,7 @@ public class LocationManager {
mContext.getAttributionTag(), transport.getListenerId()); mContext.getAttributionTag(), transport.getListenerId());
if (cancelRemote != null) { if (cancelRemote != null) {
transport.register(mContext.getSystemService(AlarmManager.class), transport.register(mContext.getSystemService(AlarmManager.class),
cancellationSignal); cancellationSignal, cancelRemote);
if (cancellationSignal != null) { if (cancellationSignal != null) {
cancellationSignal.setRemote(cancelRemote); cancellationSignal.setRemote(cancelRemote);
} }
@@ -2571,7 +2571,8 @@ public class LocationManager {
} }
public synchronized void register(AlarmManager alarmManager, public synchronized void register(AlarmManager alarmManager,
CancellationSignal cancellationSignal) { CancellationSignal cancellationSignal,
ICancellationSignal remoteCancellationSignal) {
if (mConsumer == null) { if (mConsumer == null) {
return; return;
} }
@@ -2587,15 +2588,21 @@ public class LocationManager {
if (cancellationSignal != null) { if (cancellationSignal != null) {
cancellationSignal.setOnCancelListener(this); cancellationSignal.setOnCancelListener(this);
} }
mRemoteCancellationSignal = remoteCancellationSignal;
} }
@Override @Override
public void onCancel() { public void onCancel() {
synchronized (this) {
mRemoteCancellationSignal = null;
}
remove(); remove();
} }
private Consumer<Location> remove() { private Consumer<Location> remove() {
Consumer<Location> consumer; Consumer<Location> consumer;
ICancellationSignal cancellationSignal;
synchronized (this) { synchronized (this) {
mExecutor = null; mExecutor = null;
consumer = mConsumer; consumer = mConsumer;
@@ -2605,6 +2612,18 @@ public class LocationManager {
mAlarmManager.cancel(this); mAlarmManager.cancel(this);
mAlarmManager = null; mAlarmManager = null;
} }
// ensure only one cancel event will go through
cancellationSignal = mRemoteCancellationSignal;
mRemoteCancellationSignal = null;
}
if (cancellationSignal != null) {
try {
cancellationSignal.cancel();
} catch (RemoteException e) {
// ignore
}
} }
return consumer; return consumer;