blob: 7a190ac273d455ec4c30a34304ac4976804c320b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17import java.util.Arrays;
18import java.util.HashSet;
19import java.util.Set;
20
21/**
Jean-Baptiste Queru72b1f372009-08-31 09:17:57 -070022 * Policy that governs which classes are preloaded.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023 */
24public class Policy {
Jean-Baptiste Queru72b1f372009-08-31 09:17:57 -070025
26 /**
27 * No constructor - use static methods only
28 */
29 private Policy() {}
30
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031 /**
32 * This location (in the build system) of the preloaded-classes file.
33 */
Jean-Baptiste Queru72b1f372009-08-31 09:17:57 -070034 static final String PRELOADED_CLASS_FILE
35 = "frameworks/base/preloaded-classes";
36
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 /**
Jean-Baptiste Queru72b1f372009-08-31 09:17:57 -070038 * Long running services. These are restricted in their contribution to the
39 * preloader because their launch time is less critical.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 */
Jean-Baptiste Queru72b1f372009-08-31 09:17:57 -070041 // TODO: Generate this automatically from package manager.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 private static final Set<String> SERVICES = new HashSet<String>(Arrays.asList(
Jean-Baptiste Queru72b1f372009-08-31 09:17:57 -070043 "system_server",
44 "com.google.process.content",
45 "android.process.media",
46 "com.android.phone",
47 "com.google.android.apps.maps.FriendService",
48 "com.google.android.apps.maps.LocationFriendService",
49 "com.google.android.googleapps",
50 "com.google.process.gapps",
51 "android.tts"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 ));
53
54 /**
55 * Classes which we shouldn't load from the Zygote.
56 */
Jean-Baptiste Queru72b1f372009-08-31 09:17:57 -070057 private static final Set<String> EXCLUDED_CLASSES
58 = new HashSet<String>(Arrays.asList(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 // Binders
60 "android.app.AlarmManager",
61 "android.app.SearchManager",
62 "android.os.FileObserver",
63 "com.android.server.PackageManagerService$AppDirObserver",
64
65 // Threads
66 "android.os.AsyncTask",
67 "android.pim.ContactsAsyncHelper",
68 "java.lang.ProcessManager"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 ));
70
71 /**
Jean-Baptiste Queru72b1f372009-08-31 09:17:57 -070072 * Returns true if the given process name is a "long running" process or
73 * service.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 */
75 public static boolean isService(String processName) {
76 return SERVICES.contains(processName);
77 }
Jean-Baptiste Queru72b1f372009-08-31 09:17:57 -070078
79 /**Reports if the given class should be preloaded. */
80 public static boolean isPreloadable(LoadedClass clazz) {
81 return clazz.systemClass && !EXCLUDED_CLASSES.contains(clazz.name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 }
83}