Search in sources :

Example 1 with VersionInfo

use of com.android.server.pm.Settings.VersionInfo in project platform_frameworks_base by android.

the class PackageManagerService method loadPrivatePackagesInner.

private void loadPrivatePackagesInner(VolumeInfo vol) {
    final String volumeUuid = vol.fsUuid;
    if (TextUtils.isEmpty(volumeUuid)) {
        Slog.e(TAG, "Loading internal storage is probably a mistake; ignoring");
        return;
    }
    final ArrayList<PackageFreezer> freezers = new ArrayList<>();
    final ArrayList<ApplicationInfo> loaded = new ArrayList<>();
    final int parseFlags = mDefParseFlags | PackageParser.PARSE_EXTERNAL_STORAGE;
    final VersionInfo ver;
    final List<PackageSetting> packages;
    synchronized (mPackages) {
        ver = mSettings.findOrCreateVersion(volumeUuid);
        packages = mSettings.getVolumePackagesLPr(volumeUuid);
    }
    for (PackageSetting ps : packages) {
        freezers.add(freezePackage(ps.name, "loadPrivatePackagesInner"));
        synchronized (mInstallLock) {
            final PackageParser.Package pkg;
            try {
                pkg = scanPackageTracedLI(ps.codePath, parseFlags, SCAN_INITIAL, 0, null);
                loaded.add(pkg.applicationInfo);
            } catch (PackageManagerException e) {
                Slog.w(TAG, "Failed to scan " + ps.codePath + ": " + e.getMessage());
            }
            if (!Build.FINGERPRINT.equals(ver.fingerprint)) {
                clearAppDataLIF(ps.pkg, UserHandle.USER_ALL, StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE | Installer.FLAG_CLEAR_CODE_CACHE_ONLY);
            }
        }
    }
    // Reconcile app data for all started/unlocked users
    final StorageManager sm = mContext.getSystemService(StorageManager.class);
    final UserManager um = mContext.getSystemService(UserManager.class);
    UserManagerInternal umInternal = getUserManagerInternal();
    for (UserInfo user : um.getUsers()) {
        final int flags;
        if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
            flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
        } else if (umInternal.isUserRunning(user.id)) {
            flags = StorageManager.FLAG_STORAGE_DE;
        } else {
            continue;
        }
        try {
            sm.prepareUserStorage(volumeUuid, user.id, user.serialNumber, flags);
            synchronized (mInstallLock) {
                reconcileAppsDataLI(volumeUuid, user.id, flags);
            }
        } catch (IllegalStateException e) {
            // Device was probably ejected, and we'll process that event momentarily
            Slog.w(TAG, "Failed to prepare storage: " + e);
        }
    }
    synchronized (mPackages) {
        int updateFlags = UPDATE_PERMISSIONS_ALL;
        if (ver.sdkVersion != mSdkVersion) {
            logCriticalInfo(Log.INFO, "Platform changed from " + ver.sdkVersion + " to " + mSdkVersion + "; regranting permissions for " + volumeUuid);
            updateFlags |= UPDATE_PERMISSIONS_REPLACE_PKG | UPDATE_PERMISSIONS_REPLACE_ALL;
        }
        updatePermissionsLPw(null, null, volumeUuid, updateFlags);
        // Yay, everything is now upgraded
        ver.forceCurrent();
        mSettings.writeLPr();
    }
    for (PackageFreezer freezer : freezers) {
        freezer.close();
    }
    if (DEBUG_INSTALL)
        Slog.d(TAG, "Loaded packages " + loaded);
    sendResourcesChangedBroadcast(true, false, loaded, null);
}
Also used : ArrayList(java.util.ArrayList) EphemeralApplicationInfo(android.content.pm.EphemeralApplicationInfo) ApplicationInfo(android.content.pm.ApplicationInfo) StorageManager(android.os.storage.StorageManager) UserInfo(android.content.pm.UserInfo) VersionInfo(com.android.server.pm.Settings.VersionInfo) PackageParser(android.content.pm.PackageParser) UserManagerInternal(android.os.UserManagerInternal) UserManager(android.os.UserManager)

Example 2 with VersionInfo

use of com.android.server.pm.Settings.VersionInfo in project platform_frameworks_base by android.

the class PackageManagerService method loadMediaPackages.

/*
     * Look at potentially valid container ids from processCids If package
     * information doesn't match the one on record or package scanning fails,
     * the cid is added to list of removeCids. We currently don't delete stale
     * containers.
     */
private void loadMediaPackages(ArrayMap<AsecInstallArgs, String> processCids, int[] uidArr, boolean externalStorage) {
    ArrayList<String> pkgList = new ArrayList<String>();
    Set<AsecInstallArgs> keys = processCids.keySet();
    for (AsecInstallArgs args : keys) {
        String codePath = processCids.get(args);
        if (DEBUG_SD_INSTALL)
            Log.i(TAG, "Loading container : " + args.cid);
        int retCode = PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
        try {
            // Make sure there are no container errors first.
            if (args.doPreInstall(PackageManager.INSTALL_SUCCEEDED) != PackageManager.INSTALL_SUCCEEDED) {
                Slog.e(TAG, "Failed to mount cid : " + args.cid + " when installing from sdcard");
                continue;
            }
            // Check code path here.
            if (codePath == null || !codePath.startsWith(args.getCodePath())) {
                Slog.e(TAG, "Container " + args.cid + " cachepath " + args.getCodePath() + " does not match one in settings " + codePath);
                continue;
            }
            // Parse package
            int parseFlags = mDefParseFlags;
            if (args.isExternalAsec()) {
                parseFlags |= PackageParser.PARSE_EXTERNAL_STORAGE;
            }
            if (args.isFwdLocked()) {
                parseFlags |= PackageParser.PARSE_FORWARD_LOCK;
            }
            synchronized (mInstallLock) {
                PackageParser.Package pkg = null;
                try {
                    // Sadly we don't know the package name yet to freeze it
                    pkg = scanPackageTracedLI(new File(codePath), parseFlags, SCAN_IGNORE_FROZEN, 0, null);
                } catch (PackageManagerException e) {
                    Slog.w(TAG, "Failed to scan " + codePath + ": " + e.getMessage());
                }
                // Scan the package
                if (pkg != null) {
                    // writer
                    synchronized (mPackages) {
                        retCode = PackageManager.INSTALL_SUCCEEDED;
                        pkgList.add(pkg.packageName);
                        // Post process args
                        args.doPostInstall(PackageManager.INSTALL_SUCCEEDED, pkg.applicationInfo.uid);
                    }
                } else {
                    Slog.i(TAG, "Failed to install pkg from  " + codePath + " from sdcard");
                }
            }
        } finally {
            if (retCode != PackageManager.INSTALL_SUCCEEDED) {
                Log.w(TAG, "Container " + args.cid + " is stale, retCode=" + retCode);
            }
        }
    }
    // writer
    synchronized (mPackages) {
        // If the platform SDK has changed since the last time we booted,
        // we need to re-grant app permission to catch any new ones that
        // appear. This is really a hack, and means that apps can in some
        // cases get permissions that the user didn't initially explicitly
        // allow... it would be nice to have some better way to handle
        // this situation.
        final VersionInfo ver = externalStorage ? mSettings.getExternalVersion() : mSettings.getInternalVersion();
        final String volumeUuid = externalStorage ? StorageManager.UUID_PRIMARY_PHYSICAL : StorageManager.UUID_PRIVATE_INTERNAL;
        int updateFlags = UPDATE_PERMISSIONS_ALL;
        if (ver.sdkVersion != mSdkVersion) {
            logCriticalInfo(Log.INFO, "Platform changed from " + ver.sdkVersion + " to " + mSdkVersion + "; regranting permissions for external");
            updateFlags |= UPDATE_PERMISSIONS_REPLACE_PKG | UPDATE_PERMISSIONS_REPLACE_ALL;
        }
        updatePermissionsLPw(null, null, volumeUuid, updateFlags);
        // Yay, everything is now upgraded
        ver.forceCurrent();
        // can downgrade to reader
        // Persist settings
        mSettings.writeLPr();
    }
    // Send a broadcast to let everyone know we are done processing
    if (pkgList.size() > 0) {
        sendResourcesChangedBroadcast(true, false, pkgList, uidArr, null);
    }
}
Also used : VersionInfo(com.android.server.pm.Settings.VersionInfo) PackageParser(android.content.pm.PackageParser) ArrayList(java.util.ArrayList) PackageParser.isApkFile(android.content.pm.PackageParser.isApkFile) File(java.io.File) DexFile(dalvik.system.DexFile) StrictJarFile(android.util.jar.StrictJarFile)

Example 3 with VersionInfo

use of com.android.server.pm.Settings.VersionInfo in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerService method loadPrivatePackagesInner.

private void loadPrivatePackagesInner(VolumeInfo vol) {
    final String volumeUuid = vol.fsUuid;
    if (TextUtils.isEmpty(volumeUuid)) {
        Slog.e(TAG, "Loading internal storage is probably a mistake; ignoring");
        return;
    }
    final ArrayList<PackageFreezer> freezers = new ArrayList<>();
    final ArrayList<ApplicationInfo> loaded = new ArrayList<>();
    final int parseFlags = mDefParseFlags | PackageParser.PARSE_EXTERNAL_STORAGE;
    final VersionInfo ver;
    final List<PackageSetting> packages;
    synchronized (mPackages) {
        ver = mSettings.findOrCreateVersion(volumeUuid);
        packages = mSettings.getVolumePackagesLPr(volumeUuid);
    }
    for (PackageSetting ps : packages) {
        freezers.add(freezePackage(ps.name, "loadPrivatePackagesInner"));
        synchronized (mInstallLock) {
            final PackageParser.Package pkg;
            try {
                pkg = scanPackageTracedLI(ps.codePath, parseFlags, SCAN_INITIAL, 0, null);
                loaded.add(pkg.applicationInfo);
            } catch (PackageManagerException e) {
                Slog.w(TAG, "Failed to scan " + ps.codePath + ": " + e.getMessage());
            }
            if (!Build.FINGERPRINT.equals(ver.fingerprint)) {
                clearAppDataLIF(ps.pkg, UserHandle.USER_ALL, StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE | Installer.FLAG_CLEAR_CODE_CACHE_ONLY);
            }
        }
    }
    // Reconcile app data for all started/unlocked users
    final StorageManager sm = mContext.getSystemService(StorageManager.class);
    final UserManager um = mContext.getSystemService(UserManager.class);
    UserManagerInternal umInternal = getUserManagerInternal();
    for (UserInfo user : um.getUsers()) {
        final int flags;
        if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
            flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
        } else if (umInternal.isUserRunning(user.id)) {
            flags = StorageManager.FLAG_STORAGE_DE;
        } else {
            continue;
        }
        try {
            sm.prepareUserStorage(volumeUuid, user.id, user.serialNumber, flags);
            synchronized (mInstallLock) {
                reconcileAppsDataLI(volumeUuid, user.id, flags);
            }
        } catch (IllegalStateException e) {
            // Device was probably ejected, and we'll process that event momentarily
            Slog.w(TAG, "Failed to prepare storage: " + e);
        }
    }
    synchronized (mPackages) {
        int updateFlags = UPDATE_PERMISSIONS_ALL;
        if (ver.sdkVersion != mSdkVersion) {
            logCriticalInfo(Log.INFO, "Platform changed from " + ver.sdkVersion + " to " + mSdkVersion + "; regranting permissions for " + volumeUuid);
            updateFlags |= UPDATE_PERMISSIONS_REPLACE_PKG | UPDATE_PERMISSIONS_REPLACE_ALL;
        }
        updatePermissionsLPw(null, null, volumeUuid, updateFlags);
        // Yay, everything is now upgraded
        ver.forceCurrent();
        mSettings.writeLPr();
    }
    for (PackageFreezer freezer : freezers) {
        freezer.close();
    }
    if (DEBUG_INSTALL)
        Slog.d(TAG, "Loaded packages " + loaded);
    sendResourcesChangedBroadcast(true, false, loaded, null);
}
Also used : ArrayList(java.util.ArrayList) EphemeralApplicationInfo(android.content.pm.EphemeralApplicationInfo) ApplicationInfo(android.content.pm.ApplicationInfo) StorageManager(android.os.storage.StorageManager) UserInfo(android.content.pm.UserInfo) VersionInfo(com.android.server.pm.Settings.VersionInfo) PackageParser(android.content.pm.PackageParser) UserManagerInternal(android.os.UserManagerInternal) UserManager(android.os.UserManager)

Example 4 with VersionInfo

use of com.android.server.pm.Settings.VersionInfo in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerService method loadMediaPackages.

/*
     * Look at potentially valid container ids from processCids If package
     * information doesn't match the one on record or package scanning fails,
     * the cid is added to list of removeCids. We currently don't delete stale
     * containers.
     */
private void loadMediaPackages(ArrayMap<AsecInstallArgs, String> processCids, int[] uidArr, boolean externalStorage) {
    ArrayList<String> pkgList = new ArrayList<String>();
    Set<AsecInstallArgs> keys = processCids.keySet();
    for (AsecInstallArgs args : keys) {
        String codePath = processCids.get(args);
        if (DEBUG_SD_INSTALL)
            Log.i(TAG, "Loading container : " + args.cid);
        int retCode = PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
        try {
            // Make sure there are no container errors first.
            if (args.doPreInstall(PackageManager.INSTALL_SUCCEEDED) != PackageManager.INSTALL_SUCCEEDED) {
                Slog.e(TAG, "Failed to mount cid : " + args.cid + " when installing from sdcard");
                continue;
            }
            // Check code path here.
            if (codePath == null || !codePath.startsWith(args.getCodePath())) {
                Slog.e(TAG, "Container " + args.cid + " cachepath " + args.getCodePath() + " does not match one in settings " + codePath);
                continue;
            }
            // Parse package
            int parseFlags = mDefParseFlags;
            if (args.isExternalAsec()) {
                parseFlags |= PackageParser.PARSE_EXTERNAL_STORAGE;
            }
            if (args.isFwdLocked()) {
                parseFlags |= PackageParser.PARSE_FORWARD_LOCK;
            }
            synchronized (mInstallLock) {
                PackageParser.Package pkg = null;
                try {
                    // Sadly we don't know the package name yet to freeze it
                    pkg = scanPackageTracedLI(new File(codePath), parseFlags, SCAN_IGNORE_FROZEN, 0, null);
                } catch (PackageManagerException e) {
                    Slog.w(TAG, "Failed to scan " + codePath + ": " + e.getMessage());
                }
                // Scan the package
                if (pkg != null) {
                    // writer
                    synchronized (mPackages) {
                        retCode = PackageManager.INSTALL_SUCCEEDED;
                        pkgList.add(pkg.packageName);
                        // Post process args
                        args.doPostInstall(PackageManager.INSTALL_SUCCEEDED, pkg.applicationInfo.uid);
                    }
                } else {
                    Slog.i(TAG, "Failed to install pkg from  " + codePath + " from sdcard");
                }
            }
        } finally {
            if (retCode != PackageManager.INSTALL_SUCCEEDED) {
                Log.w(TAG, "Container " + args.cid + " is stale, retCode=" + retCode);
            }
        }
    }
    // writer
    synchronized (mPackages) {
        // If the platform SDK has changed since the last time we booted,
        // we need to re-grant app permission to catch any new ones that
        // appear. This is really a hack, and means that apps can in some
        // cases get permissions that the user didn't initially explicitly
        // allow... it would be nice to have some better way to handle
        // this situation.
        final VersionInfo ver = externalStorage ? mSettings.getExternalVersion() : mSettings.getInternalVersion();
        final String volumeUuid = externalStorage ? StorageManager.UUID_PRIMARY_PHYSICAL : StorageManager.UUID_PRIVATE_INTERNAL;
        int updateFlags = UPDATE_PERMISSIONS_ALL;
        if (ver.sdkVersion != mSdkVersion) {
            logCriticalInfo(Log.INFO, "Platform changed from " + ver.sdkVersion + " to " + mSdkVersion + "; regranting permissions for external");
            updateFlags |= UPDATE_PERMISSIONS_REPLACE_PKG | UPDATE_PERMISSIONS_REPLACE_ALL;
        }
        updatePermissionsLPw(null, null, volumeUuid, updateFlags);
        // Yay, everything is now upgraded
        ver.forceCurrent();
        // can downgrade to reader
        // Persist settings
        mSettings.writeLPr();
    }
    // Send a broadcast to let everyone know we are done processing
    if (pkgList.size() > 0) {
        sendResourcesChangedBroadcast(true, false, pkgList, uidArr, null);
    }
}
Also used : VersionInfo(com.android.server.pm.Settings.VersionInfo) PackageParser(android.content.pm.PackageParser) ArrayList(java.util.ArrayList) PackageParser.isApkFile(android.content.pm.PackageParser.isApkFile) File(java.io.File) DexFile(dalvik.system.DexFile) StrictJarFile(android.util.jar.StrictJarFile)

Aggregations

PackageParser (android.content.pm.PackageParser)4 VersionInfo (com.android.server.pm.Settings.VersionInfo)4 ArrayList (java.util.ArrayList)4 ApplicationInfo (android.content.pm.ApplicationInfo)2 EphemeralApplicationInfo (android.content.pm.EphemeralApplicationInfo)2 PackageParser.isApkFile (android.content.pm.PackageParser.isApkFile)2 UserInfo (android.content.pm.UserInfo)2 UserManager (android.os.UserManager)2 UserManagerInternal (android.os.UserManagerInternal)2 StorageManager (android.os.storage.StorageManager)2 StrictJarFile (android.util.jar.StrictJarFile)2 DexFile (dalvik.system.DexFile)2 File (java.io.File)2