Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 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 | |
Artur Satayev | d9b11b0 | 2019-12-10 17:47:51 +0000 | [diff] [blame] | 19 | import android.compat.annotation.UnsupportedAppUsage; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 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 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 31 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 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 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 40 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 41 | public static String getInitialPackage() { |
| 42 | return ActivityThread.currentPackageName(); |
| 43 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 44 | |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 45 | /** |
| 46 | * Return the raw interface to the package manager. |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 47 | * @return The package manager. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 48 | */ |
Mathew Inwood | 4fb17d1 | 2018-08-14 14:25:44 +0100 | [diff] [blame] | 49 | @UnsupportedAppUsage |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 50 | public static IPackageManager getPackageManager() { |
| 51 | return ActivityThread.getPackageManager(); |
| 52 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 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 | */ |
| 61 | public static int getIntCoreSetting(String key, int defaultValue) { |
Svetoslav Ganov | 11e515c | 2011-03-03 12:55:52 -0800 | [diff] [blame] | 62 | ActivityThread currentActivityThread = ActivityThread.currentActivityThread(); |
| 63 | if (currentActivityThread != null) { |
| 64 | return currentActivityThread.getIntCoreSetting(key, defaultValue); |
| 65 | } else { |
| 66 | return defaultValue; |
| 67 | } |
Svetoslav Ganov | 54d068e | 2011-03-02 12:58:40 -0800 | [diff] [blame] | 68 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 69 | } |