Policy.java revision 0a2fb2174ed8d3e34ae435410ea3998a1fb2d97f
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
17import java.util.Arrays;
18import java.util.HashSet;
19import java.util.Set;
20
21/**
22 * Policy that governs which classes are preloaded.
23 */
24public class Policy {
25
26    /**
27     * No constructor - use static methods only
28     */
29    private Policy() {}
30
31    /**
32     * This location (in the build system) of the preloaded-classes file.
33     */
34    static final String PRELOADED_CLASS_FILE
35            = "frameworks/base/preloaded-classes";
36
37    /**
38     * Long running services. These are restricted in their contribution to the
39     * preloader because their launch time is less critical.
40     */
41    // TODO: Generate this automatically from package manager.
42    private static final Set<String> SERVICES = new HashSet<String>(Arrays.asList(
43        "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.process.gapps",
50        "android.tts"
51    ));
52
53    /**
54     * Classes which we shouldn't load from the Zygote.
55     */
56    private static final Set<String> EXCLUDED_CLASSES
57            = new HashSet<String>(Arrays.asList(
58        // Binders
59        "android.app.AlarmManager",
60        "android.app.SearchManager",
61        "android.os.FileObserver",
62        "com.android.server.PackageManagerService$AppDirObserver",
63
64        // Threads
65        "android.os.AsyncTask",
66        "android.pim.ContactsAsyncHelper",
67        "java.lang.ProcessManager"
68    ));
69
70    /**
71     * Returns true if the given process name is a "long running" process or
72     * service.
73     */
74    public static boolean isService(String processName) {
75        return SERVICES.contains(processName);
76    }
77
78    /**Reports if the given class should be preloaded. */
79    public static boolean isPreloadable(LoadedClass clazz) {
80        return clazz.systemClass && !EXCLUDED_CLASSES.contains(clazz.name);
81    }
82}
83