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

Commit 7c0f3292 authored by Songchun Fan's avatar Songchun Fan
Browse files

copy first level apk dir on movePackage

The goal is to make sure the code path still has two levels after the
move, on the target storage.

Test: manual as follows:
$ adb install ~/Downloads/yelp.apk
$ adb shell
walleye:/ # su
walleye:/ # sm set-virtual-disk true
walleye:/ # sm list-disks
disk:7,224
walleye:/ # sm partition disk:7,224 private
walleye:/ # sm list-volumes
private mounted null
private:7,226 mounted ea386596-0d69-4cd7-87f8-2d77ced59f0c
emulated;0 mounted null
emulated:7,226;0 unmounted null
walleye:/ # pm move-package com.yelp.android ea386596-0d69-4cd7-87f8-2d77ced59f0c
Success

Example log:
PackageManager: Update package com.yelp.android code path from /data/app/~~LKNWa_moIm9tFw5KY5E7ZA==/com.yelp.android-VgweFDciQH9cPQLnkooiMA== to /mnt/expand/ea386596-0d69-4cd7-87f8-2d77ced59f0c/app/~~LKNWa_moIm9tFw5KY5E7ZA==/com.yelp.android-VgweFDciQH9cPQLnkooiMA==

BUG: b/148844589 b/148237378
Change-Id: I46109a7befa8971a05049b4f495ca0d73e244a0b
parent 75088d14
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -234,11 +234,11 @@ public class Installer extends SystemService {
    }

    public void moveCompleteApp(String fromUuid, String toUuid, String packageName,
            String dataAppName, int appId, String seInfo, int targetSdkVersion,
            int appId, String seInfo, int targetSdkVersion,
            String fromCodePath) throws InstallerException {
        if (!checkBeforeRemote()) return;
        try {
            mInstalld.moveCompleteApp(fromUuid, toUuid, packageName, dataAppName, appId, seInfo,
            mInstalld.moveCompleteApp(fromUuid, toUuid, packageName, appId, seInfo,
                    targetSdkVersion, fromCodePath);
        } catch (Exception e) {
            throw InstallerException.from(e);
+12 −9
Original line number Diff line number Diff line
@@ -14000,20 +14000,18 @@ public class PackageManagerService extends IPackageManager.Stub
        final String fromUuid;
        final String toUuid;
        final String packageName;
        final String dataAppName;
        final int appId;
        final String seinfo;
        final int targetSdkVersion;
        final String fromCodePath;
        public MoveInfo(int moveId, String fromUuid, String toUuid, String packageName,
                String dataAppName, int appId, String seinfo, int targetSdkVersion,
                int appId, String seinfo, int targetSdkVersion,
                String fromCodePath) {
            this.moveId = moveId;
            this.fromUuid = fromUuid;
            this.toUuid = toUuid;
            this.packageName = packageName;
            this.dataAppName = dataAppName;
            this.appId = appId;
            this.seinfo = seinfo;
            this.targetSdkVersion = targetSdkVersion;
@@ -15137,7 +15135,7 @@ public class PackageManagerService extends IPackageManager.Stub
            synchronized (mInstaller) {
                try {
                    mInstaller.moveCompleteApp(move.fromUuid, move.toUuid, move.packageName,
                            move.dataAppName, move.appId, move.seinfo, move.targetSdkVersion,
                            move.appId, move.seinfo, move.targetSdkVersion,
                            move.fromCodePath);
                } catch (InstallerException e) {
                    Slog.w(TAG, "Failed to move app", e);
@@ -15145,7 +15143,8 @@ public class PackageManagerService extends IPackageManager.Stub
                }
            }
            codeFile = new File(Environment.getDataAppDirectory(move.toUuid), move.dataAppName);
            final String toPathName = new File(move.fromCodePath).getName();
            codeFile = new File(Environment.getDataAppDirectory(move.toUuid), toPathName);
            resourceFile = codeFile;
            if (DEBUG_INSTALL) Slog.d(TAG, "codeFile after move is " + codeFile);
@@ -15197,8 +15196,9 @@ public class PackageManagerService extends IPackageManager.Stub
        }
        private boolean cleanUp(String volumeUuid) {
            final String toPathName = new File(move.fromCodePath).getName();
            final File codeFile = new File(Environment.getDataAppDirectory(volumeUuid),
                    move.dataAppName);
                    toPathName);
            Slog.d(TAG, "Cleaning up " + move.packageName + " on " + volumeUuid);
            final int[] userIds = mUserManager.getUserIds();
            synchronized (mInstallLock) {
@@ -22152,7 +22152,11 @@ public class PackageManagerService extends IPackageManager.Stub
            targetSdkVersion = pkg.getTargetSdkVersion();
            freezer = freezePackage(packageName, "movePackageInternal");
            installedUserIds = ps.queryInstalledUsers(mUserManager.getUserIds(), true);
            fromCodePath = pkg.getCodePath();
            if (codeFile.getParentFile().getName().startsWith(RANDOM_DIR_PREFIX)) {
                fromCodePath = codeFile.getParentFile().getAbsolutePath();
            } else {
                fromCodePath = codeFile.getAbsolutePath();
            }
        }
        final Bundle extras = new Bundle();
@@ -22279,9 +22283,8 @@ public class PackageManagerService extends IPackageManager.Stub
                }
            }).start();
            final String dataAppName = codeFile.getName();
            move = new MoveInfo(moveId, currentVolumeUuid, volumeUuid, packageName,
                    dataAppName, appId, seinfo, targetSdkVersion, fromCodePath);
                    appId, seinfo, targetSdkVersion, fromCodePath);
        } else {
            move = null;
        }