diff options
| author | 2018-05-07 14:43:05 -0700 | |
|---|---|---|
| committer | 2018-05-08 10:01:16 -0700 | |
| commit | 4589565b63a116cb8d72b2dfbc6c53bb07caa6ea (patch) | |
| tree | 944e115557c5d62985094ab5ca72111cabe23e4f | |
| parent | f450a7266bab285066d9f26445d4529a0f843d38 (diff) | |
Pre-cache more system servers
Bug: 78792330
Test: Boot system
Change-Id: Id65d9f7d9a697e3c85b410e5da4028a712e4347a
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 21 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 51 |
2 files changed, 60 insertions, 12 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index a183f735d74a..0ae4b7d3df66 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -857,6 +857,27 @@ public final class ActivityThread extends ClientTransactionHandler { String buildSerial, boolean autofillCompatibilityEnabled) { if (services != null) { + if (false) { + // Test code to make sure the app could see the passed-in services. + for (Object oname : services.keySet()) { + if (services.get(oname) == null) { + continue; // AM just passed in a null service. + } + String name = (String) oname; + + // See b/79378449 about the following exemption. + switch (name) { + case "package": + case Context.WINDOW_SERVICE: + continue; + } + + if (ServiceManager.getService(name) == null) { + Log.wtf(TAG, "Service " + name + " should be accessible by this app"); + } + } + } + // Setup the service cache in the ServiceManager ServiceManager.initServiceCache(services); } diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index a8e63f6695d4..52628c1edbc2 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -1448,8 +1448,8 @@ public class ActivityManagerService extends IActivityManager.Stub * List of initialization arguments to pass to all processes when binding applications to them. * For example, references to the commonly used services. */ - HashMap<String, IBinder> mAppBindArgs; - HashMap<String, IBinder> mIsolatedAppBindArgs; + ArrayMap<String, IBinder> mAppBindArgs; + ArrayMap<String, IBinder> mIsolatedAppBindArgs; /** * Temporary to avoid allocations. Protected by main lock. @@ -3432,29 +3432,56 @@ public class ActivityManagerService extends IActivityManager.Stub * process when the bindApplication() IPC is sent to the process. They're * lazily setup to make sure the services are running when they're asked for. */ - private HashMap<String, IBinder> getCommonServicesLocked(boolean isolated) { + private ArrayMap<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")); + mIsolatedAppBindArgs = new ArrayMap<>(1); + addServiceToMap(mIsolatedAppBindArgs, "package"); } return mIsolatedAppBindArgs; } if (mAppBindArgs == null) { - mAppBindArgs = new HashMap<>(); - - // 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)); + mAppBindArgs = new ArrayMap<>(); + + // Add common services. + // IMPORTANT: Before adding services here, make sure ephemeral apps can access them too. + // Enable the check in ApplicationThread.bindApplication() to make sure. + addServiceToMap(mAppBindArgs, "package"); + addServiceToMap(mAppBindArgs, Context.WINDOW_SERVICE); + addServiceToMap(mAppBindArgs, Context.ALARM_SERVICE); + addServiceToMap(mAppBindArgs, Context.DISPLAY_SERVICE); + addServiceToMap(mAppBindArgs, Context.NETWORKMANAGEMENT_SERVICE); + addServiceToMap(mAppBindArgs, Context.CONNECTIVITY_SERVICE); + addServiceToMap(mAppBindArgs, Context.ACCESSIBILITY_SERVICE); + addServiceToMap(mAppBindArgs, Context.INPUT_METHOD_SERVICE); + addServiceToMap(mAppBindArgs, Context.INPUT_SERVICE); + addServiceToMap(mAppBindArgs, "graphicsstats"); + addServiceToMap(mAppBindArgs, Context.APP_OPS_SERVICE); + addServiceToMap(mAppBindArgs, "content"); + addServiceToMap(mAppBindArgs, Context.JOB_SCHEDULER_SERVICE); + addServiceToMap(mAppBindArgs, Context.NOTIFICATION_SERVICE); + addServiceToMap(mAppBindArgs, Context.VIBRATOR_SERVICE); + addServiceToMap(mAppBindArgs, Context.ACCOUNT_SERVICE); + addServiceToMap(mAppBindArgs, Context.POWER_SERVICE); + addServiceToMap(mAppBindArgs, Context.USER_SERVICE); + addServiceToMap(mAppBindArgs, "mount"); } return mAppBindArgs; } + private static void addServiceToMap(ArrayMap<String, IBinder> map, String name) { + final IBinder service = ServiceManager.getService(name); + if (service != null) { + map.put(name, service); + if (false) { + Log.i(TAG, "Adding " + name + " to the pre-loaded service cache."); + } + } + } + /** * Update AMS states when an activity is resumed. This should only be called by * {@link ActivityStack#onActivityStateChanged(ActivityRecord, ActivityState, String)} when an |