blob: ade889e3e44b6c9b0867270ccd198fe72980e91b [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/**
22 * This is not instantiated - we just provide data for other classes to use
23 */
24public class Policy {
25
26 /**
Bob Lee2e93f652009-08-11 01:16:03 -070027 * No constructor - use static methods only
28 */
29 private Policy() {}
30
31 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032 * This location (in the build system) of the preloaded-classes file.
33 */
Bob Lee2e93f652009-08-11 01:16:03 -070034 private static final String PRELOADED_CLASS_FILE
35 = "frameworks/base/preloaded-classes";
36
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 /**
Bob Lee2e93f652009-08-11 01:16:03 -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 */
41 private static final Set<String> SERVICES = new HashSet<String>(Arrays.asList(
Bob Lee2e93f652009-08-11 01:16:03 -070042 "system_server",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 "com.google.process.content",
Bob Lee2e93f652009-08-11 01:16:03 -070044 "android.process.media",
45 "com.google.process.gapps"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 ));
47
48 /**
49 * Classes which we shouldn't load from the Zygote.
50 */
Bob Lee2e93f652009-08-11 01:16:03 -070051 private static final Set<String> EXCLUDED_CLASSES
52 = new HashSet<String>(Arrays.asList(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 // Binders
54 "android.app.AlarmManager",
55 "android.app.SearchManager",
56 "android.os.FileObserver",
57 "com.android.server.PackageManagerService$AppDirObserver",
58
59 // Threads
60 "android.os.AsyncTask",
61 "android.pim.ContactsAsyncHelper",
62 "java.lang.ProcessManager"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 ));
64
65 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 * Returns the path/file name of the preloaded classes file that will be written
67 * by WritePreloadedClassFile.
68 */
69 public static String getPreloadedClassFileName() {
70 return PRELOADED_CLASS_FILE;
71 }
72
73 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 * Reports if the given process name is a "long running" process or service
75 */
76 public static boolean isService(String processName) {
77 return SERVICES.contains(processName);
78 }
79
80 /**
81 * Reports if the given class should never be preloaded
82 */
83 public static boolean isPreloadableClass(String className) {
84 return !EXCLUDED_CLASSES.contains(className);
85 }
86}