From 24c98e8cf88f6edc3d5bdf2ce40a51f158f36884 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Sun, 14 Sep 2014 17:23:54 -0700 Subject: [PATCH] A little more work on issue ##16907799. I got distracted in the middle of it, and forget to finish up with the test to not kill processes if they aren't using an auto create binding. Change-Id: Ieecfe97fa3208e50cb91ba94be2a8659d128b0de --- .../com/android/server/am/ActiveServices.java | 21 ++++++++++++++++++- .../com/android/server/am/AppBindRecord.java | 13 ++++++------ .../android/server/am/IntentBindRecord.java | 9 ++++---- 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 dc9c45fe38a81..d38074fb74966 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 06265fd6856d7..65273c9fceb32 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 connections = new HashSet(); + final ArraySet 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 it = connections.iterator(); - while (it.hasNext()) { - ConnectionRecord c = it.next(); + for (int i=0; i=0; i--) { - AppBindRecord app = apps.valueAt(i); - if (app.connections.size() > 0) { - for (ConnectionRecord conn : app.connections) { - flags |= conn.flags; - } + final ArraySet connections = apps.valueAt(i).connections; + for (int j=connections.size()-1; j>=0; j--) { + flags |= connections.valueAt(j).flags; } } return flags;