1 /*
2  * Copyright (C) 2021 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 com.android.server.pm.pkg;
18 
19 import android.annotation.CurrentTimeMillisLong;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.SystemApi;
23 import android.content.pm.PackageManager;
24 import android.content.pm.overlay.OverlayPaths;
25 import android.os.UserHandle;
26 import android.processor.immutability.Immutable;
27 import android.util.ArraySet;
28 
29 import java.util.Map;
30 
31 
32 /**
33  * State for an app for a specific user, such as installed/enabled.
34  *
35  * Querying for a non-existent user does not throw an exception, so it is the responsibility of
36  * the caller to check for valid users if necessary. A default value assuming the app is installed
37  * for the non-existent user will be returned.
38  *
39  * The parent of this class is {@link PackageState}, which handles non-user state and holds one or
40  * many different {@link PackageUserState PackageUserStates}. This class is
41  * accessed through {@link PackageState#getStateForUser(UserHandle)}.
42  *
43  * @hide
44  */
45 @SystemApi(client = SystemApi.Client.SYSTEM_SERVER)
46 @Immutable
47 public interface PackageUserState {
48 
49     /**
50      * @return whether the package is marked as installed
51      */
isInstalled()52     boolean isInstalled();
53 
54     /**
55      * In epoch milliseconds. The timestamp of the first install of the app of the particular user
56      * on the device, surviving past app updates. Different users might have a different first
57      * install time.
58      * <p/>
59      * This does not survive full removal of the app (i.e., uninstalls for all users).
60      */
61     @CurrentTimeMillisLong
getFirstInstallTimeMillis()62     long getFirstInstallTimeMillis();
63 
64     // Methods below this comment are not yet exposed as API
65 
66     /**
67      * @hide
68      */
69     @NonNull
70     PackageUserState DEFAULT = PackageUserStateInternal.DEFAULT;
71 
72     /**
73      * Combination of {@link #getOverlayPaths()} and {@link #getSharedLibraryOverlayPaths()}
74      *
75      * @hide
76      */
77     @Immutable.Ignore
78     @Nullable
getAllOverlayPaths()79     OverlayPaths getAllOverlayPaths();
80 
81     /**
82      * Credential encrypted /data partition inode.
83      *
84      * @hide
85      */
getCeDataInode()86     long getCeDataInode();
87 
88     /**
89      * Fully qualified class names of components explicitly disabled.
90      *
91      * @hide
92      */
93     @NonNull
getDisabledComponents()94     ArraySet<String> getDisabledComponents();
95 
96     /**
97      * @hide
98      */
99     @PackageManager.DistractionRestriction
getDistractionFlags()100     int getDistractionFlags();
101 
102     /**
103      * Fully qualified class names of components explicitly enabled.
104      *
105      * @hide
106      */
107     @NonNull
getEnabledComponents()108     ArraySet<String> getEnabledComponents();
109 
110     /**
111      * Retrieve the effective enabled state of the package itself.
112      *
113      * @hide
114      */
115     @PackageManager.EnabledState
getEnabledState()116     int getEnabledState();
117 
118     /**
119      * @hide
120      * @see PackageManager#setHarmfulAppWarning(String, CharSequence)
121      */
122     @Nullable
getHarmfulAppWarning()123     String getHarmfulAppWarning();
124 
125     /**
126      * @hide
127      */
128     @PackageManager.InstallReason
getInstallReason()129     int getInstallReason();
130 
131     /**
132      * Tracks the last calling package to set a specific enabled state for the package.
133      *
134      * @hide
135      */
136     @Nullable
getLastDisableAppCaller()137     String getLastDisableAppCaller();
138 
139     /**
140      * @hide
141      */
142     @Immutable.Ignore
143     @Nullable
getOverlayPaths()144     OverlayPaths getOverlayPaths();
145 
146     /**
147      * @hide
148      */
149     @Immutable.Ignore
150     @NonNull
getSharedLibraryOverlayPaths()151     Map<String, OverlayPaths> getSharedLibraryOverlayPaths();
152 
153     /**
154      * @hide
155      */
156     @PackageManager.UninstallReason
getUninstallReason()157     int getUninstallReason();
158 
159     /**
160      * @return whether the given fully qualified class name is explicitly enabled
161      * @hide
162      */
isComponentEnabled(@onNull String componentName)163     boolean isComponentEnabled(@NonNull String componentName);
164 
165     /**
166      * @return {@link #isComponentEnabled(String)} but for explicitly disabled
167      * @hide
168      */
isComponentDisabled(@onNull String componentName)169     boolean isComponentDisabled(@NonNull String componentName);
170 
171     /**
172      * @hide
173      * @see PackageManager#setApplicationHiddenSettingAsUser(String, boolean, UserHandle)
174      */
isHidden()175     boolean isHidden();
176 
177     /**
178      * @return whether the package is marked as an ephemeral app, which restricts permissions,
179      * features, visibility
180      * @hide
181      */
isInstantApp()182     boolean isInstantApp();
183 
184     /**
185      * @return whether the package has not been launched since being explicitly stopped
186      * @hide
187      */
isNotLaunched()188     boolean isNotLaunched();
189 
190     /**
191      * @return whether the package has been stopped, which can occur if it's force-stopped, data
192      * cleared, or just been installed
193      * @hide
194      */
isStopped()195     boolean isStopped();
196 
197     /**
198      * @return whether the package has been suspended, maybe by the device admin, disallowing its
199      * launch
200      * @hide
201      */
isSuspended()202     boolean isSuspended();
203 
204     /**
205      * @return whether the package was installed as a virtual preload, which may be done as part
206      * of device infrastructure auto installation outside of the initial device image
207      * @hide
208      */
isVirtualPreload()209     boolean isVirtualPreload();
210 
211     /**
212      * The "package:type/entry" form of the theme resource ID previously set as the splash screen.
213      *
214      * @hide
215      * @see android.window.SplashScreen#setSplashScreenTheme(int)
216      * @see android.content.res.Resources#getResourceName(int)
217      */
218     @Nullable
getSplashScreenTheme()219     String getSplashScreenTheme();
220 
221     /**
222      * @return the min aspect ratio setting of the package which by default is unset
223      * unless it has been set by the user
224      * @hide
225      */
226     @PackageManager.UserMinAspectRatio
getMinAspectRatio()227     int getMinAspectRatio();
228 }
229