Search in sources :

Example 11 with IPackageManager

use of android.content.pm.IPackageManager in project cornerstone by Onskreen.

the class ActivityManagerService method clearApplicationUserData.

public boolean clearApplicationUserData(final String packageName, final IPackageDataObserver observer) {
    int uid = Binder.getCallingUid();
    int pid = Binder.getCallingPid();
    long callingId = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        int pkgUid = -1;
        synchronized (this) {
            try {
                pkgUid = pm.getPackageUid(packageName);
            } catch (RemoteException e) {
            }
            if (pkgUid == -1) {
                Slog.w(TAG, "Invalid packageName:" + packageName);
                return false;
            }
            if (uid == pkgUid || checkComponentPermission(android.Manifest.permission.CLEAR_APP_USER_DATA, pid, uid, -1, true) == PackageManager.PERMISSION_GRANTED) {
                forceStopPackageLocked(packageName, pkgUid);
            } else {
                throw new SecurityException(pid + " does not have permission:" + android.Manifest.permission.CLEAR_APP_USER_DATA + " to clear data" + "for process:" + packageName);
            }
        }
        try {
            //clear application user data
            pm.clearApplicationUserData(packageName, observer);
            Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, Uri.fromParts("package", packageName, null));
            intent.putExtra(Intent.EXTRA_UID, pkgUid);
            broadcastIntentInPackage("android", Process.SYSTEM_UID, intent, null, null, 0, null, null, null, false, false);
        } catch (RemoteException e) {
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
    return true;
}
Also used : IPackageManager(android.content.pm.IPackageManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 12 with IPackageManager

use of android.content.pm.IPackageManager in project cornerstone by Onskreen.

the class ActivityManagerService method clearApplicationUserData.

public boolean clearApplicationUserData(final String packageName, final IPackageDataObserver observer, final int userId) {
    enforceNotIsolatedCaller("clearApplicationUserData");
    int uid = Binder.getCallingUid();
    int pid = Binder.getCallingPid();
    long callingId = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        int pkgUid = -1;
        synchronized (this) {
            try {
                pkgUid = pm.getPackageUid(packageName, userId);
            } catch (RemoteException e) {
            }
            if (pkgUid == -1) {
                Slog.w(TAG, "Invalid packageName:" + packageName);
                return false;
            }
            if (uid == pkgUid || checkComponentPermission(android.Manifest.permission.CLEAR_APP_USER_DATA, pid, uid, -1, true) == PackageManager.PERMISSION_GRANTED) {
                forceStopPackageLocked(packageName, pkgUid);
            } else {
                throw new SecurityException(pid + " does not have permission:" + android.Manifest.permission.CLEAR_APP_USER_DATA + " to clear data" + "for process:" + packageName);
            }
        }
        try {
            //clear application user data
            pm.clearApplicationUserData(packageName, observer, userId);
            Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, Uri.fromParts("package", packageName, null));
            intent.putExtra(Intent.EXTRA_UID, pkgUid);
            broadcastIntentInPackage("android", Process.SYSTEM_UID, intent, null, null, 0, null, null, null, false, false, userId);
        } catch (RemoteException e) {
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
    return true;
}
Also used : IPackageManager(android.content.pm.IPackageManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 13 with IPackageManager

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

the class AccessPoint method getSavedNetworkSummary.

public String getSavedNetworkSummary() {
    WifiConfiguration config = mConfig;
    if (config != null) {
        PackageManager pm = mContext.getPackageManager();
        String systemName = pm.getNameForUid(android.os.Process.SYSTEM_UID);
        int userId = UserHandle.getUserId(config.creatorUid);
        ApplicationInfo appInfo = null;
        if (config.creatorName != null && config.creatorName.equals(systemName)) {
            appInfo = mContext.getApplicationInfo();
        } else {
            try {
                IPackageManager ipm = AppGlobals.getPackageManager();
                appInfo = ipm.getApplicationInfo(config.creatorName, 0, /* flags */
                userId);
            } catch (RemoteException rex) {
            }
        }
        if (appInfo != null && !appInfo.packageName.equals(mContext.getString(R.string.settings_package)) && !appInfo.packageName.equals(mContext.getString(R.string.certinstaller_package))) {
            return mContext.getString(R.string.saved_network, appInfo.loadLabel(pm));
        }
    }
    return "";
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) SpannableString(android.text.SpannableString) RemoteException(android.os.RemoteException)

Example 14 with IPackageManager

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

the class ActivityManagerService method revokeUriPermissionLocked.

private void revokeUriPermissionLocked(int callingUid, GrantUri grantUri, final int modeFlags) {
    if (DEBUG_URI_PERMISSION)
        Slog.v(TAG_URI_PERMISSION, "Revoking all granted permissions to " + grantUri);
    final IPackageManager pm = AppGlobals.getPackageManager();
    final String authority = grantUri.uri.getAuthority();
    final ProviderInfo pi = getProviderInfoLocked(authority, grantUri.sourceUserId, MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE);
    if (pi == null) {
        Slog.w(TAG, "No content provider found for permission revoke: " + grantUri.toSafeString());
        return;
    }
    // Does the caller have this permission on the URI?
    if (!checkHoldingPermissionsLocked(pm, pi, grantUri, callingUid, modeFlags)) {
        // If they don't have direct access to the URI, then revoke any
        // ownerless URI permissions that have been granted to them.
        final ArrayMap<GrantUri, UriPermission> perms = mGrantedUriPermissions.get(callingUid);
        if (perms != null) {
            boolean persistChanged = false;
            for (Iterator<UriPermission> it = perms.values().iterator(); it.hasNext(); ) {
                final UriPermission perm = it.next();
                if (perm.uri.sourceUserId == grantUri.sourceUserId && perm.uri.uri.isPathPrefixMatch(grantUri.uri)) {
                    if (DEBUG_URI_PERMISSION)
                        Slog.v(TAG_URI_PERMISSION, "Revoking non-owned " + perm.targetUid + " permission to " + perm.uri);
                    persistChanged |= perm.revokeModes(modeFlags | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION, false);
                    if (perm.modeFlags == 0) {
                        it.remove();
                    }
                }
            }
            if (perms.isEmpty()) {
                mGrantedUriPermissions.remove(callingUid);
            }
            if (persistChanged) {
                schedulePersistUriGrants();
            }
        }
        return;
    }
    boolean persistChanged = false;
    // Go through all of the permissions and remove any that match.
    int N = mGrantedUriPermissions.size();
    for (int i = 0; i < N; i++) {
        final int targetUid = mGrantedUriPermissions.keyAt(i);
        final ArrayMap<GrantUri, UriPermission> perms = mGrantedUriPermissions.valueAt(i);
        for (Iterator<UriPermission> it = perms.values().iterator(); it.hasNext(); ) {
            final UriPermission perm = it.next();
            if (perm.uri.sourceUserId == grantUri.sourceUserId && perm.uri.uri.isPathPrefixMatch(grantUri.uri)) {
                if (DEBUG_URI_PERMISSION)
                    Slog.v(TAG_URI_PERMISSION, "Revoking " + perm.targetUid + " permission to " + perm.uri);
                persistChanged |= perm.revokeModes(modeFlags | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION, true);
                if (perm.modeFlags == 0) {
                    it.remove();
                }
            }
        }
        if (perms.isEmpty()) {
            mGrantedUriPermissions.remove(targetUid);
            N--;
            i--;
        }
    }
    if (persistChanged) {
        schedulePersistUriGrants();
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) ProviderInfo(android.content.pm.ProviderInfo) Point(android.graphics.Point)

Example 15 with IPackageManager

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

the class ActivityManagerService method bindBackupAgent.

// =========================================================
// BACKUP AND RESTORE
// =========================================================
// Cause the target app to be launched if necessary and its backup agent
// instantiated.  The backup agent will invoke backupAgentCreated() on the
// activity manager to announce its creation.
public boolean bindBackupAgent(String packageName, int backupMode, int userId) {
    if (DEBUG_BACKUP)
        Slog.v(TAG, "bindBackupAgent: app=" + packageName + " mode=" + backupMode);
    enforceCallingPermission("android.permission.CONFIRM_FULL_BACKUP", "bindBackupAgent");
    IPackageManager pm = AppGlobals.getPackageManager();
    ApplicationInfo app = null;
    try {
        app = pm.getApplicationInfo(packageName, 0, userId);
    } catch (RemoteException e) {
    // can't happen; package manager is process-local
    }
    if (app == null) {
        Slog.w(TAG, "Unable to bind backup agent for " + packageName);
        return false;
    }
    synchronized (this) {
        // !!! TODO: currently no check here that we're already bound
        BatteryStatsImpl.Uid.Pkg.Serv ss = null;
        BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
        synchronized (stats) {
            ss = stats.getServiceStatsLocked(app.uid, app.packageName, app.name);
        }
        // Backup agent is now in use, its package can't be stopped.
        try {
            AppGlobals.getPackageManager().setPackageStoppedState(app.packageName, false, UserHandle.getUserId(app.uid));
        } catch (RemoteException e) {
        } catch (IllegalArgumentException e) {
            Slog.w(TAG, "Failed trying to unstop package " + app.packageName + ": " + e);
        }
        BackupRecord r = new BackupRecord(ss, app, backupMode);
        ComponentName hostingName = (backupMode == IApplicationThread.BACKUP_MODE_INCREMENTAL) ? new ComponentName(app.packageName, app.backupAgentName) : new ComponentName("android", "FullBackupAgent");
        // startProcessLocked() returns existing proc's record if it's already running
        ProcessRecord proc = startProcessLocked(app.processName, app, false, 0, "backup", hostingName, false, false, false);
        if (proc == null) {
            Slog.e(TAG, "Unable to start backup agent process " + r);
            return false;
        }
        // process after the full backup is done and the ProcessRecord will vaporize anyway.
        if (UserHandle.isApp(app.uid) && backupMode == IApplicationThread.BACKUP_MODE_FULL) {
            proc.inFullBackup = true;
        }
        r.app = proc;
        mBackupTarget = r;
        mBackupAppName = app.packageName;
        // Try not to kill the process during backup
        updateOomAdjLocked(proc);
        // If it is not yet live, this will be done when it attaches to the framework.
        if (proc.thread != null) {
            if (DEBUG_BACKUP)
                Slog.v(TAG_BACKUP, "Agent proc already running: " + proc);
            try {
                proc.thread.scheduleCreateBackupAgent(app, compatibilityInfoForPackageLocked(app), backupMode);
            } catch (RemoteException e) {
            // Will time out on the backup manager side
            }
        } else {
            if (DEBUG_BACKUP)
                Slog.v(TAG_BACKUP, "Agent proc not running, waiting for attach");
        }
    // Invariants: at this point, the target app process exists and the application
    // is either already running or in the process of coming up.  mBackupTarget and
    // mBackupAppName describe the app, so that when it binds back to the AM we
    // know that it's scheduled for a backup-agent operation.
    }
    return true;
}
Also used : IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException) BatteryStatsImpl(com.android.internal.os.BatteryStatsImpl)

Aggregations

IPackageManager (android.content.pm.IPackageManager)192 RemoteException (android.os.RemoteException)182 ApplicationInfo (android.content.pm.ApplicationInfo)58 Point (android.graphics.Point)33 PackageInfo (android.content.pm.PackageInfo)32 ComponentName (android.content.ComponentName)29 Intent (android.content.Intent)26 ArrayList (java.util.ArrayList)20 PackageManager (android.content.pm.PackageManager)18 UserHandle (android.os.UserHandle)13 Context (android.content.Context)12 HashMap (java.util.HashMap)12 ProviderInfo (android.content.pm.ProviderInfo)10 PendingIntent (android.app.PendingIntent)9 HashSet (java.util.HashSet)9 UserManager (android.os.UserManager)8 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 ResolveInfo (android.content.pm.ResolveInfo)7 ActivityManager (android.app.ActivityManager)6 SpannableString (android.text.SpannableString)6