Add native bindings for getNamesForUids
A new API [getNamesForUids] was recently added to the PackageManager and this API needs to be accessible to native code. However, there were two constraints: 1) Instead of hand-rolling the binder, we wanted to auto generate the bindings directly from the AIDL compiler. 2) We didn't want to expose/annotate all 180+ PackageManager APIs when only a single API is needed. So, we chose to create a parallel API that can be used explicitly for native bindings without exposing the entirety of the PackageManager. Bug: 62805090 Test: Manual Test: Create a native application that calls into the new service Test: See the call works and data and returned Change-Id: Ia571ab1607c6c88fef44eb0de6a313a28906c732
This commit is contained in:
@@ -172,6 +172,7 @@ LOCAL_SRC_FILES += \
|
||||
core/java/android/content/pm/IPackageInstallerCallback.aidl \
|
||||
core/java/android/content/pm/IPackageInstallerSession.aidl \
|
||||
core/java/android/content/pm/IPackageManager.aidl \
|
||||
../native/libs/binder/aidl/android/content/pm/IPackageManagerNative.aidl \
|
||||
core/java/android/content/pm/IPackageMoveObserver.aidl \
|
||||
core/java/android/content/pm/IPackageStatsObserver.aidl \
|
||||
core/java/android/content/pm/IPinItemRequest.aidl \
|
||||
|
||||
@@ -61,12 +61,6 @@ import android.content.IntentSender;
|
||||
* {@hide}
|
||||
*/
|
||||
interface IPackageManager {
|
||||
// Since these transactions are also called from native code, these must be kept in sync with
|
||||
// the ones in frameworks/native/include/binder/IPackageManager.h
|
||||
// =============== Beginning of transactions used on native side as well ======================
|
||||
String[] getNamesForUids(in int[] uids);
|
||||
// =============== End of transactions used on native side as well ============================
|
||||
|
||||
void checkPackageStartable(String packageName, int userId);
|
||||
boolean isPackageAvailable(String packageName, int userId);
|
||||
PackageInfo getPackageInfo(String packageName, int flags, int userId);
|
||||
@@ -134,6 +128,7 @@ interface IPackageManager {
|
||||
String[] getPackagesForUid(int uid);
|
||||
|
||||
String getNameForUid(int uid);
|
||||
String[] getNamesForUids(in int[] uids);
|
||||
|
||||
int getUidForSharedUser(String sharedUserName);
|
||||
|
||||
|
||||
@@ -143,6 +143,7 @@ import android.content.pm.IPackageDeleteObserver2;
|
||||
import android.content.pm.IPackageInstallObserver2;
|
||||
import android.content.pm.IPackageInstaller;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.IPackageManagerNative;
|
||||
import android.content.pm.IPackageMoveObserver;
|
||||
import android.content.pm.IPackageStatsObserver;
|
||||
import android.content.pm.InstantAppInfo;
|
||||
@@ -2304,6 +2305,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
factoryTest, onlyCore);
|
||||
m.enableSystemUserPackages();
|
||||
ServiceManager.addService("package", m);
|
||||
final PackageManagerNative pmn = m.new PackageManagerNative();
|
||||
ServiceManager.addService("package_native", pmn);
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -6402,7 +6405,18 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
return null;
|
||||
}
|
||||
synchronized (mPackages) {
|
||||
return getNameForUidLocked(callingUid, uid);
|
||||
Object obj = mSettings.getUserIdLPr(UserHandle.getAppId(uid));
|
||||
if (obj instanceof SharedUserSetting) {
|
||||
final SharedUserSetting sus = (SharedUserSetting) obj;
|
||||
return sus.name + ":" + sus.userId;
|
||||
} else if (obj instanceof PackageSetting) {
|
||||
final PackageSetting ps = (PackageSetting) obj;
|
||||
if (filterAppAccessLPr(ps, callingUid, UserHandle.getUserId(callingUid))) {
|
||||
return null;
|
||||
}
|
||||
return ps.name;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6419,27 +6433,25 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
synchronized (mPackages) {
|
||||
for (int i = uids.length - 1; i >= 0; i--) {
|
||||
final int uid = uids[i];
|
||||
names[i] = getNameForUidLocked(callingUid, uid);
|
||||
Object obj = mSettings.getUserIdLPr(UserHandle.getAppId(uid));
|
||||
if (obj instanceof SharedUserSetting) {
|
||||
final SharedUserSetting sus = (SharedUserSetting) obj;
|
||||
names[i] = "shared:" + sus.name;
|
||||
} else if (obj instanceof PackageSetting) {
|
||||
final PackageSetting ps = (PackageSetting) obj;
|
||||
if (filterAppAccessLPr(ps, callingUid, UserHandle.getUserId(callingUid))) {
|
||||
names[i] = null;
|
||||
} else {
|
||||
names[i] = ps.name;
|
||||
}
|
||||
} else {
|
||||
names[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
private String getNameForUidLocked(int callingUid, int uid) {
|
||||
Object obj = mSettings.getUserIdLPr(UserHandle.getAppId(uid));
|
||||
if (obj instanceof SharedUserSetting) {
|
||||
final SharedUserSetting sus = (SharedUserSetting) obj;
|
||||
return sus.name + ":" + sus.userId;
|
||||
} else if (obj instanceof PackageSetting) {
|
||||
final PackageSetting ps = (PackageSetting) obj;
|
||||
if (filterAppAccessLPr(ps, callingUid, UserHandle.getUserId(callingUid))) {
|
||||
return null;
|
||||
}
|
||||
return ps.name;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUidForSharedUser(String sharedUserName) {
|
||||
if (getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
@@ -24781,6 +24793,20 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private class PackageManagerNative extends IPackageManagerNative.Stub {
|
||||
@Override
|
||||
public String[] getNamesForUids(int[] uids) throws RemoteException {
|
||||
final String[] results = PackageManagerService.this.getNamesForUids(uids);
|
||||
// massage results so they can be parsed by the native binder
|
||||
for (int i = results.length - 1; i >= 0; --i) {
|
||||
if (results[i] == null) {
|
||||
results[i] = "";
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
private class PackageManagerInternalImpl extends PackageManagerInternal {
|
||||
@Override
|
||||
public void setLocationPackagesProvider(PackagesProvider provider) {
|
||||
|
||||
Reference in New Issue
Block a user