1 /*
2 **
3 ** Copyright 2017, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 package android.content.pm;
19 
20 import android.content.pm.IStagedApexObserver;
21 import android.content.pm.StagedApexInfo;
22 
23 /**
24  * Parallel implementation of certain {@link PackageManager} APIs that need to
25  * be exposed to native code.
26  * <p>These APIs are a parallel definition to the APIs in PackageManager, so,
27  * they can technically diverge. However, it's good practice to keep these
28  * APIs in sync with each other.
29  * <p>Because these APIs are exposed to native code, it's possible they will
30  * be exposed to privileged components [such as UID 0]. Care should be taken
31  * to avoid exposing potential security holes for methods where permission
32  * checks are bypassed based upon UID alone.
33  *
34  * @hide
35  */
36 interface IPackageManagerNative {
37     /**
38      * Returns a set of names for the given UIDs.
39      * IMPORTANT: Unlike the Java version of this API, unknown UIDs are
40      * not represented by 'null's. Instead, they are represented by empty
41      * strings.
42      */
getNamesForUids(in int[] uids)43     @utf8InCpp String[] getNamesForUids(in int[] uids);
44 
45     /**
46      * Return the UID associated with the given package name.
47      * Note that the same package will have different UIDs under different UserHandle on
48      * the same device.
49      * @param packageName The full name (i.e. com.google.apps.contacts) of the desired package.
50      * @param flags Additional option flags to modify the data returned.
51      * @param userId The user handle identifier to look up the package under.
52      * @return Returns an integer UID who owns the given package name, or -1 if no such package is
53      *            available to the caller.
54      */
getPackageUid(in @tf8InCpp String packageName, in long flags, in int userId)55      int getPackageUid(in @utf8InCpp String packageName, in long flags, in int userId);
56 
57     /**
58      * Returns the name of the installer (a package) which installed the named
59      * package. Preloaded packages return the string "preload". Sideloaded packages
60      * return an empty string. Unknown or unknowable are returned as empty strings.
61      */
62 
getInstallerForPackage(in String packageName)63     @utf8InCpp String getInstallerForPackage(in String packageName);
64 
65     /**
66      * Returns the version code of the named package.
67      * Unknown or unknowable versions are returned as 0.
68      */
69 
getVersionCodeForPackage(in String packageName)70     long getVersionCodeForPackage(in String packageName);
71 
72     /**
73      * Return if each app, identified by its package name allows its audio to be recorded.
74      * Unknown packages are mapped to false.
75      */
isAudioPlaybackCaptureAllowed(in @tf8InCpp String[] packageNames)76     boolean[] isAudioPlaybackCaptureAllowed(in @utf8InCpp String[] packageNames);
77 
78     /*  ApplicationInfo.isSystemApp() == true */
79     const int LOCATION_SYSTEM = 0x1;
80     /*  ApplicationInfo.isVendor() == true */
81     const int LOCATION_VENDOR = 0x2;
82     /*  ApplicationInfo.isProduct() == true */
83     const int LOCATION_PRODUCT = 0x4;
84 
85     /**
86      * Returns a set of bitflags about package location.
87      * LOCATION_SYSTEM: getApplicationInfo(packageName).isSystemApp()
88      * LOCATION_VENDOR: getApplicationInfo(packageName).isVendor()
89      * LOCATION_PRODUCT: getApplicationInfo(packageName).isProduct()
90      */
getLocationFlags(in @tf8InCpp String packageName)91     int getLocationFlags(in @utf8InCpp String packageName);
92 
93     /**
94      * Returns the target SDK version for the given package.
95      * Unknown packages will cause the call to fail. The caller must check the
96      * returned Status before using the result of this function.
97      */
getTargetSdkVersionForPackage(in String packageName)98     int getTargetSdkVersionForPackage(in String packageName);
99 
100     /**
101      * Returns the name of module metadata package, or empty string if device doesn't have such
102      * package.
103      */
getModuleMetadataPackageName()104     @utf8InCpp String getModuleMetadataPackageName();
105 
106     /**
107      * Returns true if the package has the SHA 256 version of the signing certificate.
108      * @see PackageManager#hasSigningCertificate(String, byte[], int), where type
109      * has been set to {@link PackageManager#CERT_INPUT_SHA256}.
110      */
hasSha256SigningCertificate(in @tf8InCpp String packageName, in byte[] certificate)111     boolean hasSha256SigningCertificate(in @utf8InCpp String packageName, in byte[] certificate);
112 
113     /**
114      * Returns the debug flag for the given package.
115      * Unknown packages will cause the call to fail.
116      */
isPackageDebuggable(in String packageName)117     boolean isPackageDebuggable(in String packageName);
118 
119     /**
120      * Check whether the given feature name and version is one of the available
121      * features as returned by {@link PackageManager#getSystemAvailableFeatures()}. Since
122      * features are defined to always be backwards compatible, this returns true
123      * if the available feature version is greater than or equal to the
124      * requested version.
125      */
hasSystemFeature(in String featureName, in int version)126     boolean hasSystemFeature(in String featureName, in int version);
127 
128     /** Register a observer for change in set of staged APEX ready for installation */
registerStagedApexObserver(in IStagedApexObserver observer)129     void registerStagedApexObserver(in IStagedApexObserver observer);
130 
131     /**
132      * Unregister an existing staged apex observer.
133      * This does nothing if this observer was not already registered.
134      */
unregisterStagedApexObserver(in IStagedApexObserver observer)135     void unregisterStagedApexObserver(in IStagedApexObserver observer);
136 
137     /**
138      * Get APEX module names of all APEX that are staged ready for installation
139      */
getStagedApexModuleNames()140     @utf8InCpp String[] getStagedApexModuleNames();
141 
142     /**
143      * Get information of APEX which is staged ready for installation.
144      * Returns null if no such APEX is found.
145      */
getStagedApexInfo(in @tf8InCpp String moduleName)146     @nullable StagedApexInfo getStagedApexInfo(in @utf8InCpp String moduleName);
147 }
148