Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8db272ff authored by Todd Kennedy's avatar Todd Kennedy Committed by Android (Google) Code Review
Browse files

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

parents 3433906a 8fd52796
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -3228,6 +3228,12 @@ public class ApplicationPackageManager extends PackageManager {
    @Override
    public void registerDexModule(@NonNull String dexModule,
            @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.
        boolean isSharedModule = false;
        try {
@@ -3236,16 +3242,11 @@ public class ApplicationPackageManager extends PackageManager {
                isSharedModule = true;
            }
        } catch (ErrnoException e) {
            if (callbackDelegate != null) {
                callback.onDexModuleRegistered(dexModule, false,
                        "Could not get stat the module file: " + e.getMessage());
            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);
            return;
        }

        // Invoke the package manager service.
+8 −1
Original line number Diff line number Diff line
@@ -2978,6 +2978,13 @@ public class PackageManagerTests extends AndroidTestCase {
        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.
    private static String[] getAppDexInstructionSets(ApplicationInfo info) {
        if (info.primaryCpuAbi != null) {