blob: 552d6e9334e2360afaf101045d0926ec574a3a08 [file] [log] [blame]
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -07001/*
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
17package android.app;
18
Artur Satayevd9b11b02019-12-10 17:47:51 +000019import android.compat.annotation.UnsupportedAppUsage;
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070020import android.content.pm.IPackageManager;
21
22/**
23 * Special private access for certain globals related to a process.
24 * @hide
25 */
26public class AppGlobals {
27 /**
28 * Return the first Application object made in the process.
29 * NOTE: Only works on the main thread.
30 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +010031 @UnsupportedAppUsage
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070032 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 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +010040 @UnsupportedAppUsage
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070041 public static String getInitialPackage() {
42 return ActivityThread.currentPackageName();
43 }
Svetoslav Ganov54d068e2011-03-02 12:58:40 -080044
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070045 /**
46 * Return the raw interface to the package manager.
Svetoslav Ganov54d068e2011-03-02 12:58:40 -080047 * @return The package manager.
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070048 */
Mathew Inwood4fb17d12018-08-14 14:25:44 +010049 @UnsupportedAppUsage
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070050 public static IPackageManager getPackageManager() {
51 return ActivityThread.getPackageManager();
52 }
Svetoslav Ganov54d068e2011-03-02 12:58:40 -080053
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 */
61 public static int getIntCoreSetting(String key, int defaultValue) {
Svetoslav Ganov11e515c2011-03-03 12:55:52 -080062 ActivityThread currentActivityThread = ActivityThread.currentActivityThread();
63 if (currentActivityThread != null) {
64 return currentActivityThread.getIntCoreSetting(key, defaultValue);
65 } else {
66 return defaultValue;
67 }
Svetoslav Ganov54d068e2011-03-02 12:58:40 -080068 }
Dianne Hackborn01e4cfc2010-06-24 15:07:24 -070069}