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

Commit c1552397 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Allow multiple original-package tags.

Also fix some issues with moving files from update commands.
parent 6be0fc10
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -674,14 +674,19 @@ int create_move_path(char path[PKG_PATH_MAX],
    return 0;
}

void mkinnerdirs(char* path, int basepos, mode_t mode, int uid, int gid)
void mkinnerdirs(char* path, int basepos, mode_t mode, int uid, int gid,
        struct stat* statbuf)
{
    while (path[basepos] != 0) {
        if (path[basepos] == '/') {
            path[basepos] = 0;
            if (lstat(path, statbuf) < 0) {
                LOGI("Making directory: %s\n", path);
                if (mkdir(path, mode) == 0) {
                    chown(path, uid, gid);
                } else {
                    LOGW("Unable to make directory %s: %s\n", path, strerror(errno));
                }
            }
            path[basepos] = '/';
            basepos++;
@@ -690,8 +695,8 @@ void mkinnerdirs(char* path, int basepos, mode_t mode, int uid, int gid)
    }
}

int movefileordir(char* srcpath, char* dstpath, int dstuid, int dstgid,
        struct stat* statbuf)
int movefileordir(char* srcpath, char* dstpath, int dstbasepos,
        int dstuid, int dstgid, struct stat* statbuf)
{
    DIR *d;
    struct dirent *de;
@@ -706,8 +711,9 @@ int movefileordir(char* srcpath, char* dstpath, int dstuid, int dstgid,
    }
    
    if ((statbuf->st_mode&S_IFDIR) == 0) {
        mkinnerdirs(dstpath, dstbasepos, S_IRWXU|S_IRWXG|S_IXOTH,
                dstuid, dstgid, statbuf);
        LOGI("Renaming %s to %s (uid %d)\n", srcpath, dstpath, dstuid);
        mkinnerdirs(dstpath, dstend-1, S_IRWXU|S_IRWXG|S_IXOTH, dstuid, dstgid);
        if (rename(srcpath, dstpath) >= 0) {
            if (chown(dstpath, dstuid, dstgid) < 0) {
                LOGE("cannot chown %s: %s\n", dstpath, strerror(errno));
@@ -752,7 +758,7 @@ int movefileordir(char* srcpath, char* dstpath, int dstuid, int dstgid,
        strcpy(srcpath+srcend+1, name);
        strcpy(dstpath+dstend+1, name);
        
        if (movefileordir(srcpath, dstpath, dstuid, dstgid, statbuf) != 0) {
        if (movefileordir(srcpath, dstpath, dstbasepos, dstuid, dstgid, statbuf) != 0) {
            res = 1;
        }
        
@@ -834,7 +840,9 @@ int movefiles()
                            LOGV("Move file: %s (from %s to %s)\n", buf+bufp, srcpkg, dstpkg);
                            if (!create_move_path(srcpath, PKG_DIR_PREFIX, srcpkg, buf+bufp) &&
                                    !create_move_path(dstpath, PKG_DIR_PREFIX, dstpkg, buf+bufp)) {
                                movefileordir(srcpath, dstpath, dstuid, dstgid, &s);
                                movefileordir(srcpath, dstpath,
                                        strlen(dstpath)-strlen(buf+bufp),
                                        dstuid, dstgid, &s);
                            }
                        }
                    } else {
+6 −3
Original line number Diff line number Diff line
@@ -967,9 +967,12 @@ public class PackageParser {
                String orig =sa.getNonResourceString(
                        com.android.internal.R.styleable.AndroidManifestOriginalPackage_name);
                if (!pkg.packageName.equals(orig)) {
                    pkg.mOriginalPackage = orig;
                    if (pkg.mOriginalPackages == null) {
                        pkg.mOriginalPackages = new ArrayList<String>();
                        pkg.mRealPackage = pkg.packageName;
                    }
                    pkg.mOriginalPackages.add(orig);
                }

                sa.recycle();

@@ -2579,7 +2582,7 @@ public class PackageParser {
        public ArrayList<String> usesOptionalLibraries = null;
        public String[] usesLibraryFiles = null;

        public String mOriginalPackage = null;
        public ArrayList<String> mOriginalPackages = null;
        public String mRealPackage = null;
        public ArrayList<String> mAdoptPermissions = null;
        
+36 −28
Original line number Diff line number Diff line
@@ -2372,10 +2372,10 @@ class PackageManagerService extends IPackageManager.Stub {
        synchronized (mPackages) {
            // Look to see if we already know about this package.
            String oldName = mSettings.mRenamedPackages.get(pkg.packageName);
            if (oldName != null && oldName.equals(pkg.mOriginalPackage)) {
            if (pkg.mOriginalPackages != null && pkg.mOriginalPackages.contains(oldName)) {
                // This package has been renamed to its original name.  Let's
                // use that.
                ps = mSettings.peekPackageLP(pkg.mOriginalPackage);
                ps = mSettings.peekPackageLP(oldName);
            }
            // If there was no original package, see one for the real package name.
            if (ps == null) {
@@ -2645,7 +2645,7 @@ class PackageManagerService extends IPackageManager.Stub {

        if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
            // Only system apps can use these features.
            pkg.mOriginalPackage = null;
            pkg.mOriginalPackages = null;
            pkg.mRealPackage = null;
            pkg.mAdoptPermissions = null;
        }
@@ -2727,22 +2727,22 @@ class PackageManagerService extends IPackageManager.Stub {
            }

            if (false) {
                if (pkg.mOriginalPackage != null) {
                if (pkg.mOriginalPackages != null) {
                    Log.w(TAG, "WAITING FOR DEBUGGER");
                    Debug.waitForDebugger();
                    Log.i(TAG, "Package " + pkg.packageName + " from original package"
                            + pkg.mOriginalPackage);
                    Log.i(TAG, "Package " + pkg.packageName + " from original packages"
                            + pkg.mOriginalPackages);
                }
            }
            
            // Check if we are renaming from an original package name.
            PackageSetting origPackage = null;
            String realName = null;
            if (pkg.mOriginalPackage != null) {
            if (pkg.mOriginalPackages != null) {
                // This package may need to be renamed to a previously
                // installed name.  Let's check on that...
                String renamed = mSettings.mRenamedPackages.get(pkg.mRealPackage);
                if (pkg.mOriginalPackage.equals(renamed)) {
                if (pkg.mOriginalPackages.contains(renamed)) {
                    // This package had originally been installed as the
                    // original name, and we have already taken care of
                    // transitioning to the new one.  Just update the new
@@ -2755,13 +2755,16 @@ class PackageManagerService extends IPackageManager.Stub {
                        pkg.setPackageName(renamed);
                    }
                    
                } else if ((origPackage
                        = mSettings.peekPackageLP(pkg.mOriginalPackage)) != null) {
                } else {
                    for (int i=pkg.mOriginalPackages.size()-1; i>=0; i--) {
                        if ((origPackage=mSettings.peekPackageLP(
                                pkg.mOriginalPackages.get(i))) != null) {
                            // We do have the package already installed under its
                            // original name...  should we use it?
                            if (!verifyPackageUpdate(origPackage, pkg)) {
                                // New package is not compatible with original.
                                origPackage = null;
                                continue;
                            } else if (origPackage.sharedUser != null) {
                                // Make sure uid is compatible between packages.
                                if (!origPackage.sharedUser.name.equals(pkg.mSharedUserId)) {
@@ -2770,11 +2773,15 @@ class PackageManagerService extends IPackageManager.Stub {
                                            + origPackage.sharedUser.name
                                            + " differs from " + pkg.mSharedUserId);
                                    origPackage = null;
                                    continue;
                                }
                            } else {
                                if (DEBUG_UPGRADE) Log.v(TAG, "Renaming new package "
                                        + pkg.packageName + " to old name " + origPackage.name);
                            }
                            break;
                        }
                    }
                }
            }
            
@@ -5479,13 +5486,14 @@ class PackageManagerService extends IPackageManager.Stub {
            // Check if installing already existing package
            if ((pFlags&PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
                String oldName = mSettings.mRenamedPackages.get(pkgName);
                if (oldName != null && oldName.equals(pkg.mOriginalPackage)
                if (pkg.mOriginalPackages != null
                        && pkg.mOriginalPackages.contains(oldName)
                        && mPackages.containsKey(oldName)) {
                    // This package is derived from an original package,
                    // and this device has been updating from that original
                    // name.  We must continue using the original name, so
                    // rename the new package here.
                    pkg.setPackageName(pkg.mOriginalPackage);
                    pkg.setPackageName(oldName);
                    pkgName = pkg.packageName;
                    replace = true;
                } else if (mPackages.containsKey(pkgName)) {