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