Fix bug in provider removal

We shouldn't mark the provider as stopped until all actions required to
stop the provider are complete.

Bug: 170688034
Test: manual
Change-Id: If810dc166d3b78974370390c15dfc9c6ebdb1098
This commit is contained in:
Soonil Nagarkar
2020-10-29 11:27:50 -07:00
parent 65186049b1
commit 5d74f7a7ca
2 changed files with 15 additions and 9 deletions

View File

@@ -306,9 +306,8 @@ public class LocationManagerService extends ILocationManager.Stub {
private void removeLocationProviderManager(LocationProviderManager manager) {
synchronized (mProviderManagers) {
Preconditions.checkState(getLocationProviderManager(manager.getName()) == manager);
mProviderManagers.remove(manager);
boolean removed = mProviderManagers.remove(manager);
Preconditions.checkArgument(removed);
manager.setMockProvider(null);
manager.setRealProvider(null);
manager.stopManager();

View File

@@ -1197,19 +1197,19 @@ class LocationProviderManager extends
public void stopManager() {
synchronized (mLock) {
mUserHelper.removeListener(mUserChangedListener);
mSettingsHelper.removeOnLocationEnabledChangedListener(mLocationEnabledChangedListener);
mStarted = false;
final long identity = Binder.clearCallingIdentity();
try {
onEnabledChanged(UserHandle.USER_ALL);
removeRegistrationIf(key -> true);
mEnabledListeners.clear();
} finally {
Binder.restoreCallingIdentity(identity);
}
mUserHelper.removeListener(mUserChangedListener);
mSettingsHelper.removeOnLocationEnabledChangedListener(mLocationEnabledChangedListener);
Preconditions.checkState(mEnabledListeners.isEmpty());
mStarted = false;
}
}
@@ -1408,6 +1408,7 @@ class LocationProviderManager extends
Location location;
synchronized (mLock) {
Preconditions.checkState(mStarted);
LastLocation lastLocation = mLastLocations.get(userId);
if (lastLocation == null) {
location = null;
@@ -1429,6 +1430,7 @@ class LocationProviderManager extends
public void injectLastLocation(Location location, int userId) {
synchronized (mLock) {
Preconditions.checkState(mStarted);
if (getLastLocationUnsafe(userId, PERMISSION_FINE, false, Long.MAX_VALUE) == null) {
setLastLocation(location, userId);
}
@@ -1476,6 +1478,7 @@ class LocationProviderManager extends
permissionLevel);
synchronized (mLock) {
Preconditions.checkState(mStarted);
final long ident = Binder.clearCallingIdentity();
try {
putRegistration(callback.asBinder(), registration);
@@ -1517,6 +1520,7 @@ class LocationProviderManager extends
permissionLevel);
synchronized (mLock) {
Preconditions.checkState(mStarted);
final long ident = Binder.clearCallingIdentity();
try {
putRegistration(listener.asBinder(), registration);
@@ -1535,6 +1539,7 @@ class LocationProviderManager extends
permissionLevel);
synchronized (mLock) {
Preconditions.checkState(mStarted);
final long identity = Binder.clearCallingIdentity();
try {
putRegistration(pendingIntent, registration);
@@ -1546,6 +1551,7 @@ class LocationProviderManager extends
public void unregisterLocationRequest(ILocationListener listener) {
synchronized (mLock) {
Preconditions.checkState(mStarted);
final long identity = Binder.clearCallingIdentity();
try {
removeRegistration(listener.asBinder());
@@ -1557,6 +1563,7 @@ class LocationProviderManager extends
public void unregisterLocationRequest(PendingIntent pendingIntent) {
synchronized (mLock) {
Preconditions.checkState(mStarted);
final long identity = Binder.clearCallingIdentity();
try {
removeRegistration(pendingIntent);