diff options
3 files changed, 31 insertions, 12 deletions
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index dc9c45fe38a8..d38074fb7496 100755 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -2104,7 +2104,26 @@ public final class ActiveServices { // don't want to be thrashing around restarting processes that are only // there to be cached. for (int appi=b.apps.size()-1; appi>=0; appi--) { - ProcessRecord proc = b.apps.keyAt(appi); + final ProcessRecord proc = b.apps.keyAt(appi); + // If the process is already gone, skip it. + if (proc.killedByAm || proc.thread == null) { + continue; + } + // Only do this for processes that have an auto-create binding; + // otherwise the binding can be left, because it won't cause the + // service to restart. + final AppBindRecord abind = b.apps.valueAt(appi); + boolean hasCreate = false; + for (int conni=abind.connections.size()-1; conni>=0; conni--) { + ConnectionRecord conn = abind.connections.valueAt(conni); + if ((conn.flags&Context.BIND_AUTO_CREATE) != 0) { + hasCreate = true; + break; + } + } + if (!hasCreate) { + continue; + } if (proc != null && !proc.persistent && proc.thread != null && proc.pid != 0 && proc.pid != ActivityManagerService.MY_PID && proc.setProcState >= ActivityManager.PROCESS_STATE_LAST_ACTIVITY) { diff --git a/services/core/java/com/android/server/am/AppBindRecord.java b/services/core/java/com/android/server/am/AppBindRecord.java index 06265fd6856d..65273c9fceb3 100644 --- a/services/core/java/com/android/server/am/AppBindRecord.java +++ b/services/core/java/com/android/server/am/AppBindRecord.java @@ -16,8 +16,9 @@ package com.android.server.am; +import android.util.ArraySet; + import java.io.PrintWriter; -import java.util.HashSet; import java.util.Iterator; /** @@ -28,7 +29,7 @@ final class AppBindRecord { final IntentBindRecord intent; // The intent we are bound to. final ProcessRecord client; // Who has started/bound the service. - final HashSet<ConnectionRecord> connections = new HashSet<ConnectionRecord>(); + final ArraySet<ConnectionRecord> connections = new ArraySet<>(); // All ConnectionRecord for this client. void dump(PrintWriter pw, String prefix) { @@ -38,11 +39,11 @@ final class AppBindRecord { } void dumpInIntentBind(PrintWriter pw, String prefix) { - if (connections.size() > 0) { + final int N = connections.size(); + if (N > 0) { pw.println(prefix + "Per-process Connections:"); - Iterator<ConnectionRecord> it = connections.iterator(); - while (it.hasNext()) { - ConnectionRecord c = it.next(); + for (int i=0; i<N; i++) { + ConnectionRecord c = connections.valueAt(i); pw.println(prefix + " " + c); } } diff --git a/services/core/java/com/android/server/am/IntentBindRecord.java b/services/core/java/com/android/server/am/IntentBindRecord.java index ba6010af4bf1..be290e953960 100644 --- a/services/core/java/com/android/server/am/IntentBindRecord.java +++ b/services/core/java/com/android/server/am/IntentBindRecord.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.Intent; import android.os.IBinder; import android.util.ArrayMap; +import android.util.ArraySet; import java.io.PrintWriter; @@ -78,11 +79,9 @@ final class IntentBindRecord { int collectFlags() { int flags = 0; for (int i=apps.size()-1; i>=0; i--) { - AppBindRecord app = apps.valueAt(i); - if (app.connections.size() > 0) { - for (ConnectionRecord conn : app.connections) { - flags |= conn.flags; - } + final ArraySet<ConnectionRecord> connections = apps.valueAt(i).connections; + for (int j=connections.size()-1; j>=0; j--) { + flags |= connections.valueAt(j).flags; } } return flags; |