Created
November 16, 2020 09:55
-
-
Save AshuTyagi16/99dc764d9bd6025173f0b2ab21d71ee1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocationManagerService extends ILocationManager.Stub { | |
private Receiver getReceiverLocked(ILocationListener listener, int pid, int uid, | |
String packageName) { | |
IBinder binder = listener.asBinder(); | |
Receiver receiver = mReceivers.get(binder); | |
if (receiver == null) { | |
receiver = new Receiver(listener, null, pid, uid, packageName); | |
mReceivers.put(binder, receiver); | |
try { | |
// Register to receive a notification when the process hosting | |
// the token goes away. | |
receiver.getListener().asBinder().linkToDeath(receiver, 0); | |
} catch (RemoteException e) { | |
Slog.e(TAG, "linkToDeath failed:", e); | |
return null; | |
} | |
} | |
return receiver; | |
} | |
private final class Receiver implements IBinder.DeathRecipient, PendingIntent.OnFinished { | |
@Override | |
public void binderDied() { | |
synchronized (mLock) { | |
removeUpdatesLocked(this); | |
} | |
} | |
private void removeUpdatesLocked(Receiver receiver) { | |
if (mReceivers.remove(receiver.mKey) != null && receiver.isListener()) { | |
// We no longer care about receiving death notifications. | |
receiver.getListener().asBinder().unlinkToDeath(receiver, 0); | |
synchronized (receiver) { | |
receiver.clearPendingBroadcastsLocked(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment