OSDN Git Service

DO NOT MERGE Isolated processes don't get precached system service binders am: f4d23f...
authorChristopher Tate <ctate@google.com>
Sat, 15 Oct 2016 00:44:43 +0000 (00:44 +0000)
committerandroid-build-merger <android-build-merger@google.com>
Sat, 15 Oct 2016 00:44:43 +0000 (00:44 +0000)
am: 7044826aa8

Change-Id: Ia3129e0748d14e8250ac39d0f0e383318c9999bf

1  2 
services/core/java/com/android/server/am/ActivityManagerService.java

@@@ -321,11 -321,6 +321,11 @@@ public final class ActivityManagerServi
      // before we decide it must be hung.
      static final int CONTENT_PROVIDER_PUBLISH_TIMEOUT = 10*1000;
  
 +    // How long we will retain processes hosting content providers in the "last activity"
 +    // state before allowing them to drop down to the regular cached LRU list.  This is
 +    // to avoid thrashing of provider processes under low memory situations.
 +    static final int CONTENT_PROVIDER_RETAIN_TIME = 20*1000;
 +
      // How long we wait for a launched process to attach to the activity manager
      // before we decide it's never going to come up for real, when the process was
      // started with a wrapper for instrumentation (such as Valgrind) because it
       * For example, references to the commonly used services.
       */
      HashMap<String, IBinder> mAppBindArgs;
+     HashMap<String, IBinder> mIsolatedAppBindArgs;
  
      /**
       * Temporary to avoid allocations.  Protected by main lock.
       * lazily setup to make sure the services are running when they're asked for.
       */
      private HashMap<String, IBinder> getCommonServicesLocked(boolean isolated) {
+         // Isolated processes won't get this optimization, so that we don't
+         // violate the rules about which services they have access to.
+         if (isolated) {
+             if (mIsolatedAppBindArgs == null) {
+                 mIsolatedAppBindArgs = new HashMap<>();
+                 mIsolatedAppBindArgs.put("package", ServiceManager.getService("package"));
+             }
+             return mIsolatedAppBindArgs;
+         }
          if (mAppBindArgs == null) {
              mAppBindArgs = new HashMap<>();
  
-             // Isolated processes won't get this optimization, so that we don't
-             // violate the rules about which services they have access to.
-             if (!isolated) {
-                 // Setup the application init args
-                 mAppBindArgs.put("package", ServiceManager.getService("package"));
-                 mAppBindArgs.put("window", ServiceManager.getService("window"));
-                 mAppBindArgs.put(Context.ALARM_SERVICE,
-                         ServiceManager.getService(Context.ALARM_SERVICE));
-             }
+             // Setup the application init args
+             mAppBindArgs.put("package", ServiceManager.getService("package"));
+             mAppBindArgs.put("window", ServiceManager.getService("window"));
+             mAppBindArgs.put(Context.ALARM_SERVICE,
+                     ServiceManager.getService(Context.ALARM_SERVICE));
          }
          return mAppBindArgs;
      }
              if (conn.stableCount == 0 && conn.unstableCount == 0) {
                  cpr.connections.remove(conn);
                  conn.client.conProviders.remove(conn);
 +                if (conn.client.setProcState < ActivityManager.PROCESS_STATE_LAST_ACTIVITY) {
 +                    // The client is more important than last activity -- note the time this
 +                    // is happening, so we keep the old provider process around a bit as last
 +                    // activity to avoid thrashing it.
 +                    if (cpr.proc != null) {
 +                        cpr.proc.lastProviderTime = SystemClock.uptimeMillis();
 +                    }
 +                }
                  stopAssociationLocked(conn.client.uid, conn.client.processName, cpr.uid, cpr.name);
                  return true;
              }
                  pw.print(" Lost RAM: "); pw.print(memInfo.getTotalSizeKb()
                          - totalPss - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
                          - memInfo.getKernelUsedSizeKb()); pw.println(" kB");
 +            } else {
 +                pw.print("lostram,"); pw.println(memInfo.getTotalSizeKb()
 +                        - totalPss - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
 +                        - memInfo.getKernelUsedSizeKb());
              }
              if (!brief) {
                  if (memInfo.getZramTotalSizeKb() != 0) {
              }
          }
  
 +        if (app.lastProviderTime > 0 && (app.lastProviderTime+CONTENT_PROVIDER_RETAIN_TIME) > now) {
 +            if (adj > ProcessList.PREVIOUS_APP_ADJ) {
 +                adj = ProcessList.PREVIOUS_APP_ADJ;
 +                schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
 +                app.cached = false;
 +                app.adjType = "provider";
 +            }
 +            if (procState > ActivityManager.PROCESS_STATE_LAST_ACTIVITY) {
 +                procState = ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
 +            }
 +        }
 +
          if (mayBeTop && procState > ActivityManager.PROCESS_STATE_TOP) {
              // A client of one of our services or providers is in the top state.  We
              // *may* want to be in the top state, but not if we are already running in