Search in sources :

Example 1 with IPackageDataObserver

use of android.content.pm.IPackageDataObserver in project VirtualApp by asLody.

the class FreeStorageAndNotify method call.

@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    if (args[args.length - 1] instanceof IPackageDataObserver) {
        IPackageDataObserver observer = (IPackageDataObserver) args[args.length - 1];
        observer.onRemoveCompleted(null, true);
    }
    return 0;
}
Also used : IPackageDataObserver(android.content.pm.IPackageDataObserver)

Example 2 with IPackageDataObserver

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

the class ActivityManagerService method clearApplicationUserData.

@Override
public boolean clearApplicationUserData(final String packageName, final IPackageDataObserver observer, int userId) {
    enforceNotIsolatedCaller("clearApplicationUserData");
    int uid = Binder.getCallingUid();
    int pid = Binder.getCallingPid();
    userId = mUserController.handleIncomingUser(pid, uid, userId, false, ALLOW_FULL_ONLY, "clearApplicationUserData", null);
    long callingId = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        int pkgUid = -1;
        synchronized (this) {
            if (getPackageManagerInternalLocked().isPackageDataProtected(userId, packageName)) {
                throw new SecurityException("Cannot clear data for a protected package: " + packageName);
            }
            try {
                pkgUid = pm.getPackageUid(packageName, MATCH_UNINSTALLED_PACKAGES, userId);
            } catch (RemoteException e) {
            }
            if (pkgUid == -1) {
                Slog.w(TAG, "Invalid packageName: " + packageName);
                if (observer != null) {
                    try {
                        observer.onRemoveCompleted(packageName, false);
                    } catch (RemoteException e) {
                        Slog.i(TAG, "Observer no longer exists.");
                    }
                }
                return false;
            }
            if (uid == pkgUid || checkComponentPermission(android.Manifest.permission.CLEAR_APP_USER_DATA, pid, uid, -1, true) == PackageManager.PERMISSION_GRANTED) {
                forceStopPackageLocked(packageName, pkgUid, "clear data");
            } else {
                throw new SecurityException("PID " + pid + " does not have permission " + android.Manifest.permission.CLEAR_APP_USER_DATA + " to clear data" + " of package " + packageName);
            }
            // Remove all tasks match the cleared application package and user
            for (int i = mRecentTasks.size() - 1; i >= 0; i--) {
                final TaskRecord tr = mRecentTasks.get(i);
                final String taskPackageName = tr.getBaseIntent().getComponent().getPackageName();
                if (tr.userId != userId)
                    continue;
                if (!taskPackageName.equals(packageName))
                    continue;
                removeTaskByIdLocked(tr.taskId, false, REMOVE_FROM_RECENTS);
            }
        }
        final int pkgUidF = pkgUid;
        final int userIdF = userId;
        final IPackageDataObserver localObserver = new IPackageDataObserver.Stub() {

            @Override
            public void onRemoveCompleted(String packageName, boolean succeeded) throws RemoteException {
                synchronized (ActivityManagerService.this) {
                    finishForceStopPackageLocked(packageName, pkgUidF);
                }
                final Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, Uri.fromParts("package", packageName, null));
                intent.putExtra(Intent.EXTRA_UID, pkgUidF);
                intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(pkgUidF));
                broadcastIntentInPackage("android", Process.SYSTEM_UID, intent, null, null, 0, null, null, null, null, false, false, userIdF);
                if (observer != null) {
                    observer.onRemoveCompleted(packageName, succeeded);
                }
            }
        };
        try {
            // Clear application user data
            pm.clearApplicationUserData(packageName, localObserver, userId);
            synchronized (this) {
                // Remove all permissions granted from/to this package
                removeUriPermissionsForPackageLocked(packageName, userId, true);
            }
            // Remove all zen rules created by this package; revoke it's zen access.
            INotificationManager inm = NotificationManager.getService();
            inm.removeAutomaticZenRules(packageName);
            inm.setNotificationPolicyAccessGranted(packageName, false);
        } catch (RemoteException e) {
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
    return true;
}
Also used : IPackageManager(android.content.pm.IPackageManager) INotificationManager(android.app.INotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException) Point(android.graphics.Point) IPackageDataObserver(android.content.pm.IPackageDataObserver)

Example 3 with IPackageDataObserver

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

the class ActivityManagerService method clearApplicationUserData.

@Override
public boolean clearApplicationUserData(final String packageName, final IPackageDataObserver observer, int userId) {
    enforceNotIsolatedCaller("clearApplicationUserData");
    int uid = Binder.getCallingUid();
    int pid = Binder.getCallingPid();
    userId = mUserController.handleIncomingUser(pid, uid, userId, false, ALLOW_FULL_ONLY, "clearApplicationUserData", null);
    long callingId = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        int pkgUid = -1;
        synchronized (this) {
            if (getPackageManagerInternalLocked().isPackageDataProtected(userId, packageName)) {
                throw new SecurityException("Cannot clear data for a protected package: " + packageName);
            }
            try {
                pkgUid = pm.getPackageUid(packageName, MATCH_UNINSTALLED_PACKAGES, userId);
            } catch (RemoteException e) {
            }
            if (pkgUid == -1) {
                Slog.w(TAG, "Invalid packageName: " + packageName);
                if (observer != null) {
                    try {
                        observer.onRemoveCompleted(packageName, false);
                    } catch (RemoteException e) {
                        Slog.i(TAG, "Observer no longer exists.");
                    }
                }
                return false;
            }
            if (uid == pkgUid || checkComponentPermission(android.Manifest.permission.CLEAR_APP_USER_DATA, pid, uid, -1, true) == PackageManager.PERMISSION_GRANTED) {
                forceStopPackageLocked(packageName, pkgUid, "clear data");
            } else {
                throw new SecurityException("PID " + pid + " does not have permission " + android.Manifest.permission.CLEAR_APP_USER_DATA + " to clear data" + " of package " + packageName);
            }
            // Remove all tasks match the cleared application package and user
            for (int i = mRecentTasks.size() - 1; i >= 0; i--) {
                final TaskRecord tr = mRecentTasks.get(i);
                final String taskPackageName = tr.getBaseIntent().getComponent().getPackageName();
                if (tr.userId != userId)
                    continue;
                if (!taskPackageName.equals(packageName))
                    continue;
                removeTaskByIdLocked(tr.taskId, false, REMOVE_FROM_RECENTS);
            }
        }
        final int pkgUidF = pkgUid;
        final int userIdF = userId;
        final IPackageDataObserver localObserver = new IPackageDataObserver.Stub() {

            @Override
            public void onRemoveCompleted(String packageName, boolean succeeded) throws RemoteException {
                synchronized (ActivityManagerService.this) {
                    finishForceStopPackageLocked(packageName, pkgUidF);
                }
                final Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, Uri.fromParts("package", packageName, null));
                intent.putExtra(Intent.EXTRA_UID, pkgUidF);
                intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(pkgUidF));
                broadcastIntentInPackage("android", Process.SYSTEM_UID, intent, null, null, 0, null, null, null, null, false, false, userIdF);
                if (observer != null) {
                    observer.onRemoveCompleted(packageName, succeeded);
                }
            }
        };
        try {
            // Clear application user data
            pm.clearApplicationUserData(packageName, localObserver, userId);
            synchronized (this) {
                // Remove all permissions granted from/to this package
                removeUriPermissionsForPackageLocked(packageName, userId, true);
            }
            // Remove all zen rules created by this package; revoke it's zen access.
            INotificationManager inm = NotificationManager.getService();
            inm.removeAutomaticZenRules(packageName);
            inm.setNotificationPolicyAccessGranted(packageName, false);
        } catch (RemoteException e) {
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
    return true;
}
Also used : IPackageManager(android.content.pm.IPackageManager) INotificationManager(android.app.INotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException) Point(android.graphics.Point) IPackageDataObserver(android.content.pm.IPackageDataObserver)

Aggregations

IPackageDataObserver (android.content.pm.IPackageDataObserver)3 INotificationManager (android.app.INotificationManager)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 IPackageManager (android.content.pm.IPackageManager)2 Point (android.graphics.Point)2 RemoteException (android.os.RemoteException)2