Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d6bcbec authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

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
parent c231992a
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -732,7 +732,7 @@ public class LocationManager {
                    mContext.getAttributionTag(), transport.getListenerId());
            if (cancelRemote != null) {
                transport.register(mContext.getSystemService(AlarmManager.class),
                        cancellationSignal);
                        cancellationSignal, cancelRemote);
                if (cancellationSignal != null) {
                    cancellationSignal.setRemote(cancelRemote);
                }
@@ -2571,7 +2571,8 @@ public class LocationManager {
        }

        public synchronized void register(AlarmManager alarmManager,
                CancellationSignal cancellationSignal) {
                CancellationSignal cancellationSignal,
                ICancellationSignal remoteCancellationSignal) {
            if (mConsumer == null) {
                return;
            }
@@ -2587,15 +2588,21 @@ public class LocationManager {
            if (cancellationSignal != null) {
                cancellationSignal.setOnCancelListener(this);
            }

            mRemoteCancellationSignal = remoteCancellationSignal;
        }

        @Override
        public void onCancel() {
            synchronized (this) {
                mRemoteCancellationSignal = null;
            }
            remove();
        }

        private Consumer<Location> remove() {
            Consumer<Location> consumer;
            ICancellationSignal cancellationSignal;
            synchronized (this) {
                mExecutor = null;
                consumer = mConsumer;
@@ -2605,6 +2612,18 @@ public class LocationManager {
                    mAlarmManager.cancel(this);
                    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;