Merge "Null check before invoking callback" into sc-dev

This commit is contained in:
Todd Kennedy
2021-03-10 21:00:40 +00:00
committed by Android (Google) Code Review
2 changed files with 18 additions and 10 deletions

View File

@@ -3228,6 +3228,12 @@ public class ApplicationPackageManager extends PackageManager {
@Override @Override
public void registerDexModule(@NonNull String dexModule, public void registerDexModule(@NonNull String dexModule,
@Nullable DexModuleRegisterCallback callback) { @Nullable DexModuleRegisterCallback callback) {
// Create the callback delegate to be passed to package manager service.
DexModuleRegisterCallbackDelegate callbackDelegate = null;
if (callback != null) {
callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
}
// Check if this is a shared module by looking if the others can read it. // Check if this is a shared module by looking if the others can read it.
boolean isSharedModule = false; boolean isSharedModule = false;
try { try {
@@ -3236,16 +3242,11 @@ public class ApplicationPackageManager extends PackageManager {
isSharedModule = true; isSharedModule = true;
} }
} catch (ErrnoException e) { } catch (ErrnoException e) {
if (callbackDelegate != null) {
callback.onDexModuleRegistered(dexModule, false, callback.onDexModuleRegistered(dexModule, false,
"Could not get stat the module file: " + e.getMessage()); "Could not get stat the module file: " + e.getMessage());
return;
} }
return;
// Module path is ok.
// Create the callback delegate to be passed to package manager service.
DexModuleRegisterCallbackDelegate callbackDelegate = null;
if (callback != null) {
callbackDelegate = new DexModuleRegisterCallbackDelegate(callback);
} }
// Invoke the package manager service. // Invoke the package manager service.

View File

@@ -2923,7 +2923,7 @@ public class PackageManagerTests extends AndroidTestCase {
assertFalse("BaseCodePath should not be registered", callback.mSuccess); assertFalse("BaseCodePath should not be registered", callback.mSuccess);
} }
// Verify thatmodules which are not own by the calling package are not registered. // Verify that modules which are not own by the calling package are not registered.
public void testRegisterDexModuleNotOwningModule() throws Exception { public void testRegisterDexModuleNotOwningModule() throws Exception {
TestDexModuleRegisterCallback callback = new TestDexModuleRegisterCallback(); TestDexModuleRegisterCallback callback = new TestDexModuleRegisterCallback();
String moduleBelongingToOtherPackage = "/data/user/0/com.google.android.gms/module.apk"; String moduleBelongingToOtherPackage = "/data/user/0/com.google.android.gms/module.apk";
@@ -2978,6 +2978,13 @@ public class PackageManagerTests extends AndroidTestCase {
assertFalse("DexModule registration should fail", callback.mSuccess); assertFalse("DexModule registration should fail", callback.mSuccess);
} }
// If the module does not exist on disk we should get a failure.
public void testRegisterDexModuleNotExistsNoCallback() throws Exception {
ApplicationInfo info = getContext().getApplicationInfo();
String nonExistentApk = Paths.get(info.dataDir, "non-existent.apk").toString();
getPm().registerDexModule(nonExistentApk, null);
}
// Copied from com.android.server.pm.InstructionSets because we don't have access to it here. // Copied from com.android.server.pm.InstructionSets because we don't have access to it here.
private static String[] getAppDexInstructionSets(ApplicationInfo info) { private static String[] getAppDexInstructionSets(ApplicationInfo info) {
if (info.primaryCpuAbi != null) { if (info.primaryCpuAbi != null) {