The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | import java.util.Arrays; |
| 18 | import java.util.HashSet; |
| 19 | import java.util.Set; |
| 20 | |
| 21 | /** |
| 22 | * This is not instantiated - we just provide data for other classes to use |
| 23 | */ |
| 24 | public class Policy { |
| 25 | |
| 26 | /** |
| 27 | * This location (in the build system) of the preloaded-classes file. |
| 28 | */ |
| 29 | private static final String PRELOADED_CLASS_FILE = "frameworks/base/preloaded-classes"; |
| 30 | |
| 31 | /** |
| 32 | * The internal process name of the system process. Note, this also shows up as |
| 33 | * "system_process", e.g. in ddms. |
| 34 | */ |
| 35 | private static final String SYSTEM_SERVER_PROCESS_NAME = "system_server"; |
| 36 | |
| 37 | /** |
| 38 | * Names of non-application processes - these will not be checked for preloaded classes. |
| 39 | * |
| 40 | * TODO: Replace this hardcoded list with a walk up the parent chain looking for zygote. |
| 41 | */ |
| 42 | private static final Set<String> NOT_FROM_ZYGOTE = new HashSet<String>(Arrays.asList( |
| 43 | "zygote", |
| 44 | "dexopt", |
| 45 | "unknown", |
| 46 | SYSTEM_SERVER_PROCESS_NAME, |
| 47 | "com.android.development", |
| 48 | "app_process" // am & other shell commands |
| 49 | )); |
| 50 | |
| 51 | /** |
| 52 | * Long running services. These are restricted in their contribution to the preloader |
| 53 | * because their launch time is less critical. |
| 54 | */ |
| 55 | private static final Set<String> SERVICES = new HashSet<String>(Arrays.asList( |
| 56 | SYSTEM_SERVER_PROCESS_NAME, |
| 57 | "com.android.acore", |
| 58 | // Commented out to make sure DefaultTimeZones gets preloaded. |
| 59 | // "com.android.phone", |
| 60 | "com.google.process.content", |
| 61 | "android.process.media" |
| 62 | )); |
| 63 | |
| 64 | /** |
| 65 | * Classes which we shouldn't load from the Zygote. |
| 66 | */ |
| 67 | private static final Set<String> EXCLUDED_CLASSES = new HashSet<String>(Arrays.asList( |
| 68 | // Binders |
| 69 | "android.app.AlarmManager", |
| 70 | "android.app.SearchManager", |
| 71 | "android.os.FileObserver", |
| 72 | "com.android.server.PackageManagerService$AppDirObserver", |
| 73 | |
| 74 | // Threads |
| 75 | "android.os.AsyncTask", |
| 76 | "android.pim.ContactsAsyncHelper", |
| 77 | "java.lang.ProcessManager" |
| 78 | |
| 79 | )); |
| 80 | |
| 81 | /** |
| 82 | * No constructor - use static methods only |
| 83 | */ |
| 84 | private Policy() {} |
| 85 | |
| 86 | /** |
| 87 | * Returns the path/file name of the preloaded classes file that will be written |
| 88 | * by WritePreloadedClassFile. |
| 89 | */ |
| 90 | public static String getPreloadedClassFileName() { |
| 91 | return PRELOADED_CLASS_FILE; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Reports if a given process name was created from zygote |
| 96 | */ |
| 97 | public static boolean isFromZygote(String processName) { |
| 98 | return !NOT_FROM_ZYGOTE.contains(processName); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Reports if the given process name is a "long running" process or service |
| 103 | */ |
| 104 | public static boolean isService(String processName) { |
| 105 | return SERVICES.contains(processName); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Reports if the given class should never be preloaded |
| 110 | */ |
| 111 | public static boolean isPreloadableClass(String className) { |
| 112 | return !EXCLUDED_CLASSES.contains(className); |
| 113 | } |
| 114 | } |