diff options
author | Svetoslav <svetoslavganov@google.com> | 2013-12-18 17:29:49 -0800 |
---|---|---|
committer | Svetoslav <svetoslavganov@google.com> | 2013-12-18 17:35:43 -0800 |
commit | dbcc95d4d889c4de2490870cfeb97cc8f6deb30e (patch) | |
tree | 163e66f7380ff26e481d42321a6499f5398a3661 /services/java/com/android | |
parent | 1732f2639b036522410037d5264a978235f7139a (diff) | |
download | frameworks_base-dbcc95d4d889c4de2490870cfeb97cc8f6deb30e.zip frameworks_base-dbcc95d4d889c4de2490870cfeb97cc8f6deb30e.tar.gz frameworks_base-dbcc95d4d889c4de2490870cfeb97cc8f6deb30e.tar.bz2 |
Removed print services not fully cleaned up.
1. When a print services is removed it is removed from the
installed and enabled services but not from the active
ones while it should.
2. If a package has more than one print service (very rare
but possible) we are executing the "make everything right"
code for each of them which is not very optimal.
Change-Id: I7f6fc4eef10b6757d3b2ede33eb298c3399c3ff7
Diffstat (limited to 'services/java/com/android')
-rw-r--r-- | services/java/com/android/server/print/PrintManagerService.java | 19 | ||||
-rw-r--r-- | services/java/com/android/server/print/UserState.java | 20 |
2 files changed, 33 insertions, 6 deletions
diff --git a/services/java/com/android/server/print/PrintManagerService.java b/services/java/com/android/server/print/PrintManagerService.java index a475639..e24fdb5 100644 --- a/services/java/com/android/server/print/PrintManagerService.java +++ b/services/java/com/android/server/print/PrintManagerService.java @@ -401,33 +401,40 @@ public final class PrintManagerService extends IPrintManager.Stub { @Override public void onPackageModified(String packageName) { synchronized (mLock) { + boolean servicesChanged = false; UserState userState = getOrCreateUserStateLocked(getChangingUserId()); Iterator<ComponentName> iterator = userState.getEnabledServices().iterator(); while (iterator.hasNext()) { ComponentName componentName = iterator.next(); if (packageName.equals(componentName.getPackageName())) { - userState.updateIfNeededLocked(); + servicesChanged = true; } } + if (servicesChanged) { + userState.updateIfNeededLocked(); + } } } @Override public void onPackageRemoved(String packageName, int uid) { synchronized (mLock) { + boolean servicesRemoved = false; UserState userState = getOrCreateUserStateLocked(getChangingUserId()); Iterator<ComponentName> iterator = userState.getEnabledServices().iterator(); while (iterator.hasNext()) { ComponentName componentName = iterator.next(); if (packageName.equals(componentName.getPackageName())) { iterator.remove(); - persistComponentNamesToSettingLocked( - Settings.Secure.ENABLED_PRINT_SERVICES, - userState.getEnabledServices(), getChangingUserId()); - userState.updateIfNeededLocked(); - return; + servicesRemoved = true; } } + if (servicesRemoved) { + persistComponentNamesToSettingLocked( + Settings.Secure.ENABLED_PRINT_SERVICES, + userState.getEnabledServices(), getChangingUserId()); + userState.updateIfNeededLocked(); + } } } diff --git a/services/java/com/android/server/print/UserState.java b/services/java/com/android/server/print/UserState.java index 43757f9..f647814 100644 --- a/services/java/com/android/server/print/UserState.java +++ b/services/java/com/android/server/print/UserState.java @@ -71,6 +71,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -594,6 +595,8 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks { .append(installedService.getSettingsActivityName()).println(); pw.append(installedServicePrefix).append(tab).append("addPrintersActivity=") .append(installedService.getAddPrintersActivityName()).println(); + pw.append(installedServicePrefix).append(tab).append("avancedOptionsActivity=") + .append(installedService.getAdvancedOptionsActivityName()).println(); } pw.append(prefix).append(tab).append("enabled services:").println(); @@ -787,11 +790,16 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks { } private void onConfigurationChangedLocked() { + Set<ComponentName> installedComponents = new ArraySet<ComponentName>(); + final int installedCount = mInstalledServices.size(); for (int i = 0; i < installedCount; i++) { ResolveInfo resolveInfo = mInstalledServices.get(i).getResolveInfo(); ComponentName serviceName = new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name); + + installedComponents.add(serviceName); + if (mEnabledServices.contains(serviceName)) { if (!mActiveServices.containsKey(serviceName)) { RemotePrintService service = new RemotePrintService( @@ -805,6 +813,18 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks { } } } + + Iterator<Map.Entry<ComponentName, RemotePrintService>> iterator = + mActiveServices.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry<ComponentName, RemotePrintService> entry = iterator.next(); + ComponentName serviceName = entry.getKey(); + RemotePrintService service = entry.getValue(); + if (!installedComponents.contains(serviceName)) { + removeServiceLocked(service); + iterator.remove(); + } + } } private void addServiceLocked(RemotePrintService service) { |