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 | /** |
Bob Lee | 9d2d6e1 | 2009-08-13 14:41:54 -0700 | [diff] [blame] | 22 | * Policy that governs which classes are preloaded. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | */ |
| 24 | public class Policy { |
Bob Lee | 9d2d6e1 | 2009-08-13 14:41:54 -0700 | [diff] [blame] | 25 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | /** |
Bob Lee | 2e93f65 | 2009-08-11 01:16:03 -0700 | [diff] [blame] | 27 | * No constructor - use static methods only |
| 28 | */ |
| 29 | private Policy() {} |
| 30 | |
| 31 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | * This location (in the build system) of the preloaded-classes file. |
| 33 | */ |
Bob Lee | 9d2d6e1 | 2009-08-13 14:41:54 -0700 | [diff] [blame] | 34 | static final String PRELOADED_CLASS_FILE |
Bob Lee | 2e93f65 | 2009-08-11 01:16:03 -0700 | [diff] [blame] | 35 | = "frameworks/base/preloaded-classes"; |
| 36 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | /** |
Bob Lee | 2e93f65 | 2009-08-11 01:16:03 -0700 | [diff] [blame] | 38 | * Long running services. These are restricted in their contribution to the |
| 39 | * preloader because their launch time is less critical. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | */ |
Bob Lee | 9d2d6e1 | 2009-08-13 14:41:54 -0700 | [diff] [blame] | 41 | // TODO: Generate this automatically from package manager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | private static final Set<String> SERVICES = new HashSet<String>(Arrays.asList( |
Bob Lee | 9d2d6e1 | 2009-08-13 14:41:54 -0700 | [diff] [blame] | 43 | "system_server", |
| 44 | "com.google.process.content", |
| 45 | "android.process.media", |
Jesse Wilson | e9fcaa0 | 2010-02-23 17:06:58 -0800 | [diff] [blame] | 46 | "com.android.bluetooth", |
| 47 | "com.android.calendar", |
| 48 | "com.android.inputmethod.latin", |
Bob Lee | 9d2d6e1 | 2009-08-13 14:41:54 -0700 | [diff] [blame] | 49 | "com.android.phone", |
Jesse Wilson | e9fcaa0 | 2010-02-23 17:06:58 -0800 | [diff] [blame] | 50 | "com.google.android.apps.maps.FriendService", // pre froyo |
| 51 | "com.google.android.apps.maps:FriendService", // froyo |
Bob Lee | 9d2d6e1 | 2009-08-13 14:41:54 -0700 | [diff] [blame] | 52 | "com.google.android.apps.maps.LocationFriendService", |
Jesse Wilson | e9fcaa0 | 2010-02-23 17:06:58 -0800 | [diff] [blame] | 53 | "com.google.android.deskclock", |
Bob Lee | 9d2d6e1 | 2009-08-13 14:41:54 -0700 | [diff] [blame] | 54 | "com.google.process.gapps", |
| 55 | "android.tts" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | )); |
| 57 | |
| 58 | /** |
| 59 | * Classes which we shouldn't load from the Zygote. |
| 60 | */ |
Bob Lee | 2e93f65 | 2009-08-11 01:16:03 -0700 | [diff] [blame] | 61 | private static final Set<String> EXCLUDED_CLASSES |
| 62 | = new HashSet<String>(Arrays.asList( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | // Binders |
| 64 | "android.app.AlarmManager", |
| 65 | "android.app.SearchManager", |
| 66 | "android.os.FileObserver", |
| 67 | "com.android.server.PackageManagerService$AppDirObserver", |
| 68 | |
| 69 | // Threads |
| 70 | "android.os.AsyncTask", |
| 71 | "android.pim.ContactsAsyncHelper", |
| 72 | "java.lang.ProcessManager" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | )); |
| 74 | |
| 75 | /** |
Bob Lee | 9d2d6e1 | 2009-08-13 14:41:54 -0700 | [diff] [blame] | 76 | * Returns true if the given process name is a "long running" process or |
| 77 | * service. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | */ |
| 79 | public static boolean isService(String processName) { |
| 80 | return SERVICES.contains(processName); |
| 81 | } |
Bob Lee | 9d2d6e1 | 2009-08-13 14:41:54 -0700 | [diff] [blame] | 82 | |
| 83 | /**Reports if the given class should be preloaded. */ |
| 84 | public static boolean isPreloadable(LoadedClass clazz) { |
| 85 | return clazz.systemClass && !EXCLUDED_CLASSES.contains(clazz.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | } |
| 87 | } |