PackageManagerNative: Implement getModuleMetadataPackageName
* If configuration has config_defaultModuleMetadataProvider, it's value is returned. * Otherwise, currently IllegalStateException is thrown. It will be changed to return empty string in a follow-up CL. Test: builds Bug: 131774400 Change-Id: I33df0fe25eca3370c4a4ddf77b29d3f228ffdf22
This commit is contained in:
@@ -64,6 +64,7 @@ public class ModuleInfoProvider {
|
||||
|
||||
// TODO: Move this to an earlier boot phase if anybody requires it then.
|
||||
private volatile boolean mMetadataLoaded;
|
||||
private volatile String mPackageName;
|
||||
|
||||
ModuleInfoProvider(Context context, IPackageManager packageManager) {
|
||||
mContext = context;
|
||||
@@ -81,9 +82,9 @@ public class ModuleInfoProvider {
|
||||
|
||||
/** Called by the {@code PackageManager} when it has completed its boot sequence */
|
||||
public void systemReady() {
|
||||
final String packageName = mContext.getResources().getString(
|
||||
mPackageName = mContext.getResources().getString(
|
||||
R.string.config_defaultModuleMetadataProvider);
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
if (TextUtils.isEmpty(mPackageName)) {
|
||||
Slog.w(TAG, "No configured module metadata provider.");
|
||||
return;
|
||||
}
|
||||
@@ -91,13 +92,13 @@ public class ModuleInfoProvider {
|
||||
final Resources packageResources;
|
||||
final PackageInfo pi;
|
||||
try {
|
||||
pi = mPackageManager.getPackageInfo(packageName,
|
||||
pi = mPackageManager.getPackageInfo(mPackageName,
|
||||
PackageManager.GET_META_DATA, UserHandle.USER_SYSTEM);
|
||||
|
||||
Context packageContext = mContext.createPackageContext(packageName, 0);
|
||||
Context packageContext = mContext.createPackageContext(mPackageName, 0);
|
||||
packageResources = packageContext.getResources();
|
||||
} catch (RemoteException | NameNotFoundException e) {
|
||||
Slog.w(TAG, "Unable to discover metadata package: " + packageName, e);
|
||||
Slog.w(TAG, "Unable to discover metadata package: " + mPackageName, e);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -201,4 +202,11 @@ public class ModuleInfoProvider {
|
||||
|
||||
return mModuleInfo.get(packageName);
|
||||
}
|
||||
|
||||
String getPackageName() {
|
||||
if (!mMetadataLoaded) {
|
||||
throw new IllegalStateException("Call to getVersion before metadata loaded");
|
||||
}
|
||||
return mPackageName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24068,6 +24068,11 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
| (appInfo.isVendor() ? IPackageManagerNative.LOCATION_VENDOR : 0)
|
||||
| (appInfo.isProduct() ? IPackageManagerNative.LOCATION_PRODUCT : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModuleMetadataPackageName() throws RemoteException {
|
||||
return PackageManagerService.this.mModuleInfoProvider.getPackageName();
|
||||
}
|
||||
}
|
||||
|
||||
private class PackageManagerInternalImpl extends PackageManagerInternal {
|
||||
|
||||
Reference in New Issue
Block a user