• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 package android.app;
18 
19 import android.content.pm.IPackageManager;
20 
21 /**
22  * Special private access for certain globals related to a process.
23  * @hide
24  */
25 public class AppGlobals {
26     /**
27      * Return the first Application object made in the process.
28      * NOTE: Only works on the main thread.
29      */
getInitialApplication()30     public static Application getInitialApplication() {
31         return ActivityThread.currentApplication();
32     }
33 
34     /**
35      * Return the package name of the first .apk loaded into the process.
36      * NOTE: Only works on the main thread.
37      */
getInitialPackage()38     public static String getInitialPackage() {
39         return ActivityThread.currentPackageName();
40     }
41 
42     /**
43      * Return the raw interface to the package manager.
44      * @return The package manager.
45      */
getPackageManager()46     public static IPackageManager getPackageManager() {
47         return ActivityThread.getPackageManager();
48     }
49 
50     /**
51      * Gets the value of an integer core setting.
52      *
53      * @param key The setting key.
54      * @param defaultValue The setting default value.
55      * @return The core settings.
56      */
getIntCoreSetting(String key, int defaultValue)57     public static int getIntCoreSetting(String key, int defaultValue) {
58         ActivityThread currentActivityThread = ActivityThread.currentActivityThread();
59         if (currentActivityThread != null) {
60             return currentActivityThread.getIntCoreSetting(key, defaultValue);
61         } else {
62             return defaultValue;
63         }
64     }
65 }
66