Search in sources :

Example 1 with IPackageMoveObserver

use of android.content.pm.IPackageMoveObserver in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerService method movePrimaryStorage.

@Override
public int movePrimaryStorage(String volumeUuid) throws RemoteException {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MOVE_PACKAGE, null);
    final int realMoveId = mNextMoveId.getAndIncrement();
    final Bundle extras = new Bundle();
    extras.putString(VolumeRecord.EXTRA_FS_UUID, volumeUuid);
    mMoveCallbacks.notifyCreated(realMoveId, extras);
    final IPackageMoveObserver callback = new IPackageMoveObserver.Stub() {

        @Override
        public void onCreated(int moveId, Bundle extras) {
        // Ignored
        }

        @Override
        public void onStatusChanged(int moveId, int status, long estMillis) {
            mMoveCallbacks.notifyStatusChanged(realMoveId, status, estMillis);
        }
    };
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    storage.setPrimaryStorageUuid(volumeUuid, callback);
    return realMoveId;
}
Also used : Bundle(android.os.Bundle) StorageManager(android.os.storage.StorageManager) IPackageMoveObserver(android.content.pm.IPackageMoveObserver)

Example 2 with IPackageMoveObserver

use of android.content.pm.IPackageMoveObserver in project platform_frameworks_base by android.

the class PackageManagerService method movePrimaryStorage.

@Override
public int movePrimaryStorage(String volumeUuid) throws RemoteException {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MOVE_PACKAGE, null);
    final int realMoveId = mNextMoveId.getAndIncrement();
    final Bundle extras = new Bundle();
    extras.putString(VolumeRecord.EXTRA_FS_UUID, volumeUuid);
    mMoveCallbacks.notifyCreated(realMoveId, extras);
    final IPackageMoveObserver callback = new IPackageMoveObserver.Stub() {

        @Override
        public void onCreated(int moveId, Bundle extras) {
        // Ignored
        }

        @Override
        public void onStatusChanged(int moveId, int status, long estMillis) {
            mMoveCallbacks.notifyStatusChanged(realMoveId, status, estMillis);
        }
    };
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    storage.setPrimaryStorageUuid(volumeUuid, callback);
    return realMoveId;
}
Also used : Bundle(android.os.Bundle) StorageManager(android.os.storage.StorageManager) IPackageMoveObserver(android.content.pm.IPackageMoveObserver)

Example 3 with IPackageMoveObserver

use of android.content.pm.IPackageMoveObserver in project android_frameworks_base by ParanoidAndroid.

the class PackageManagerService method processPendingMove.

private void processPendingMove(final MoveParams mp, final int currentStatus) {
    // Queue up an async operation since the package deletion may take a
    // little while.
    mHandler.post(new Runnable() {

        public void run() {
            // TODO fix this; this does nothing.
            mHandler.removeCallbacks(this);
            int returnCode = currentStatus;
            if (currentStatus == PackageManager.MOVE_SUCCEEDED) {
                int[] uidArr = null;
                ArrayList<String> pkgList = null;
                synchronized (mPackages) {
                    PackageParser.Package pkg = mPackages.get(mp.packageName);
                    if (pkg == null) {
                        Slog.w(TAG, " Package " + mp.packageName + " doesn't exist. Aborting move");
                        returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST;
                    } else if (!mp.srcArgs.getCodePath().equals(pkg.applicationInfo.sourceDir)) {
                        Slog.w(TAG, "Package " + mp.packageName + " code path changed from " + mp.srcArgs.getCodePath() + " to " + pkg.applicationInfo.sourceDir + " Aborting move and returning error");
                        returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR;
                    } else {
                        uidArr = new int[] { pkg.applicationInfo.uid };
                        pkgList = new ArrayList<String>();
                        pkgList.add(mp.packageName);
                    }
                }
                if (returnCode == PackageManager.MOVE_SUCCEEDED) {
                    // Send resources unavailable broadcast
                    sendResourcesChangedBroadcast(false, pkgList, uidArr, null);
                    // Update package code and resource paths
                    synchronized (mInstallLock) {
                        synchronized (mPackages) {
                            PackageParser.Package pkg = mPackages.get(mp.packageName);
                            // Recheck for package again.
                            if (pkg == null) {
                                Slog.w(TAG, " Package " + mp.packageName + " doesn't exist. Aborting move");
                                returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST;
                            } else if (!mp.srcArgs.getCodePath().equals(pkg.applicationInfo.sourceDir)) {
                                Slog.w(TAG, "Package " + mp.packageName + " code path changed from " + mp.srcArgs.getCodePath() + " to " + pkg.applicationInfo.sourceDir + " Aborting move and returning error");
                                returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR;
                            } else {
                                final String oldCodePath = pkg.mPath;
                                final String newCodePath = mp.targetArgs.getCodePath();
                                final String newResPath = mp.targetArgs.getResourcePath();
                                final String newNativePath = mp.targetArgs.getNativeLibraryPath();
                                final File newNativeDir = new File(newNativePath);
                                if (!isForwardLocked(pkg) && !isExternal(pkg)) {
                                    NativeLibraryHelper.copyNativeBinariesIfNeededLI(new File(newCodePath), newNativeDir);
                                }
                                final int[] users = sUserManager.getUserIds();
                                for (int user : users) {
                                    if (mInstaller.linkNativeLibraryDirectory(pkg.packageName, newNativePath, user) < 0) {
                                        returnCode = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE;
                                    }
                                }
                                if (returnCode == PackageManager.MOVE_SUCCEEDED) {
                                    pkg.mPath = newCodePath;
                                    // Move dex files around
                                    if (moveDexFilesLI(pkg) != PackageManager.INSTALL_SUCCEEDED) {
                                        // Moving of dex files failed. Set
                                        // error code and abort move.
                                        pkg.mPath = pkg.mScanPath;
                                        returnCode = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE;
                                    }
                                }
                                if (returnCode == PackageManager.MOVE_SUCCEEDED) {
                                    pkg.mScanPath = newCodePath;
                                    pkg.applicationInfo.sourceDir = newCodePath;
                                    pkg.applicationInfo.publicSourceDir = newResPath;
                                    pkg.applicationInfo.nativeLibraryDir = newNativePath;
                                    PackageSetting ps = (PackageSetting) pkg.mExtras;
                                    ps.codePath = new File(pkg.applicationInfo.sourceDir);
                                    ps.codePathString = ps.codePath.getPath();
                                    ps.resourcePath = new File(pkg.applicationInfo.publicSourceDir);
                                    ps.resourcePathString = ps.resourcePath.getPath();
                                    ps.nativeLibraryPathString = newNativePath;
                                    // correctly.
                                    if ((mp.flags & PackageManager.INSTALL_EXTERNAL) != 0) {
                                        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
                                    } else {
                                        pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_EXTERNAL_STORAGE;
                                    }
                                    ps.setFlags(pkg.applicationInfo.flags);
                                    mAppDirs.remove(oldCodePath);
                                    mAppDirs.put(newCodePath, pkg);
                                    // Persist settings
                                    mSettings.writeLPr();
                                }
                            }
                        }
                    }
                    // Send resources available broadcast
                    sendResourcesChangedBroadcast(true, pkgList, uidArr, null);
                }
            }
            if (returnCode != PackageManager.MOVE_SUCCEEDED) {
                // Clean up failed installation
                if (mp.targetArgs != null) {
                    mp.targetArgs.doPostInstall(PackageManager.INSTALL_FAILED_INTERNAL_ERROR, -1);
                }
            } else {
                // Force a gc to clear things up.
                Runtime.getRuntime().gc();
                // Delete older code
                synchronized (mInstallLock) {
                    mp.srcArgs.doPostDeleteLI(true);
                }
            }
            // an operation was already pending for this package.
            if (returnCode != PackageManager.MOVE_FAILED_OPERATION_PENDING) {
                synchronized (mPackages) {
                    PackageParser.Package pkg = mPackages.get(mp.packageName);
                    if (pkg != null) {
                        pkg.mOperationPending = false;
                    }
                }
            }
            IPackageMoveObserver observer = mp.observer;
            if (observer != null) {
                try {
                    observer.packageMoved(mp.packageName, returnCode);
                } catch (RemoteException e) {
                    Log.i(TAG, "Observer no longer exists.");
                }
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) IPackageMoveObserver(android.content.pm.IPackageMoveObserver) RemoteException(android.os.RemoteException) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Aggregations

IPackageMoveObserver (android.content.pm.IPackageMoveObserver)3 Bundle (android.os.Bundle)2 StorageManager (android.os.storage.StorageManager)2 RemoteException (android.os.RemoteException)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ZipFile (java.util.zip.ZipFile)1