Search in sources :

Example 66 with IPackageManager

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

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)

Example 67 with IPackageManager

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

the class ActivityManagerService method killPackageDependents.

/**
     * Kill processes for the user with id userId and that depend on the package named packageName
     */
@Override
public void killPackageDependents(String packageName, int userId) {
    enforceCallingPermission(android.Manifest.permission.KILL_UID, "killPackageDependents()");
    if (packageName == null) {
        throw new NullPointerException("Cannot kill the dependents of a package without its name.");
    }
    long callingId = Binder.clearCallingIdentity();
    IPackageManager pm = AppGlobals.getPackageManager();
    int pkgUid = -1;
    try {
        pkgUid = pm.getPackageUid(packageName, MATCH_DEBUG_TRIAGED_MISSING, userId);
    } catch (RemoteException e) {
    }
    if (userId != UserHandle.USER_ALL && pkgUid == -1) {
        throw new IllegalArgumentException("Cannot kill dependents of non-existing package " + packageName);
    }
    try {
        synchronized (this) {
            killPackageProcessesLocked(packageName, UserHandle.getAppId(pkgUid), userId, ProcessList.FOREGROUND_APP_ADJ, false, true, true, false, "dep: " + packageName);
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 68 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by AOSPA.

the class TaskRecord method restoreFromXml.

static TaskRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
    Intent intent = null;
    Intent affinityIntent = null;
    ArrayList<ActivityRecord> activities = new ArrayList<>();
    ComponentName realActivity = null;
    boolean realActivitySuspended = false;
    ComponentName origActivity = null;
    String affinity = null;
    String rootAffinity = null;
    boolean hasRootAffinity = false;
    boolean rootHasReset = false;
    boolean autoRemoveRecents = false;
    boolean askedCompatMode = false;
    int taskType = ActivityRecord.APPLICATION_ACTIVITY_TYPE;
    int userId = 0;
    boolean userSetupComplete = true;
    int effectiveUid = -1;
    String lastDescription = null;
    long firstActiveTime = -1;
    long lastActiveTime = -1;
    long lastTimeOnTop = 0;
    boolean neverRelinquishIdentity = true;
    int taskId = INVALID_TASK_ID;
    final int outerDepth = in.getDepth();
    TaskDescription taskDescription = new TaskDescription();
    TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
    int taskAffiliation = INVALID_TASK_ID;
    int taskAffiliationColor = 0;
    int prevTaskId = INVALID_TASK_ID;
    int nextTaskId = INVALID_TASK_ID;
    int callingUid = -1;
    String callingPackage = "";
    int resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
    boolean privileged = false;
    Rect bounds = null;
    int minWidth = INVALID_MIN_SIZE;
    int minHeight = INVALID_MIN_SIZE;
    for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
        final String attrName = in.getAttributeName(attrNdx);
        final String attrValue = in.getAttributeValue(attrNdx);
        if (TaskPersister.DEBUG)
            Slog.d(TaskPersister.TAG, "TaskRecord: attribute name=" + attrName + " value=" + attrValue);
        if (ATTR_TASKID.equals(attrName)) {
            if (taskId == INVALID_TASK_ID)
                taskId = Integer.parseInt(attrValue);
        } else if (ATTR_REALACTIVITY.equals(attrName)) {
            realActivity = ComponentName.unflattenFromString(attrValue);
        } else if (ATTR_REALACTIVITY_SUSPENDED.equals(attrName)) {
            realActivitySuspended = Boolean.valueOf(attrValue);
        } else if (ATTR_ORIGACTIVITY.equals(attrName)) {
            origActivity = ComponentName.unflattenFromString(attrValue);
        } else if (ATTR_AFFINITY.equals(attrName)) {
            affinity = attrValue;
        } else if (ATTR_ROOT_AFFINITY.equals(attrName)) {
            rootAffinity = attrValue;
            hasRootAffinity = true;
        } else if (ATTR_ROOTHASRESET.equals(attrName)) {
            rootHasReset = Boolean.valueOf(attrValue);
        } else if (ATTR_AUTOREMOVERECENTS.equals(attrName)) {
            autoRemoveRecents = Boolean.valueOf(attrValue);
        } else if (ATTR_ASKEDCOMPATMODE.equals(attrName)) {
            askedCompatMode = Boolean.valueOf(attrValue);
        } else if (ATTR_USERID.equals(attrName)) {
            userId = Integer.parseInt(attrValue);
        } else if (ATTR_USER_SETUP_COMPLETE.equals(attrName)) {
            userSetupComplete = Boolean.valueOf(attrValue);
        } else if (ATTR_EFFECTIVE_UID.equals(attrName)) {
            effectiveUid = Integer.parseInt(attrValue);
        } else if (ATTR_TASKTYPE.equals(attrName)) {
            taskType = Integer.parseInt(attrValue);
        } else if (ATTR_FIRSTACTIVETIME.equals(attrName)) {
            firstActiveTime = Long.valueOf(attrValue);
        } else if (ATTR_LASTACTIVETIME.equals(attrName)) {
            lastActiveTime = Long.valueOf(attrValue);
        } else if (ATTR_LASTDESCRIPTION.equals(attrName)) {
            lastDescription = attrValue;
        } else if (ATTR_LASTTIMEMOVED.equals(attrName)) {
            lastTimeOnTop = Long.valueOf(attrValue);
        } else if (ATTR_NEVERRELINQUISH.equals(attrName)) {
            neverRelinquishIdentity = Boolean.valueOf(attrValue);
        } else if (attrName.startsWith(TaskThumbnailInfo.ATTR_TASK_THUMBNAILINFO_PREFIX)) {
            thumbnailInfo.restoreFromXml(attrName, attrValue);
        } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
            taskDescription.restoreFromXml(attrName, attrValue);
        } else if (ATTR_TASK_AFFILIATION.equals(attrName)) {
            taskAffiliation = Integer.parseInt(attrValue);
        } else if (ATTR_PREV_AFFILIATION.equals(attrName)) {
            prevTaskId = Integer.parseInt(attrValue);
        } else if (ATTR_NEXT_AFFILIATION.equals(attrName)) {
            nextTaskId = Integer.parseInt(attrValue);
        } else if (ATTR_TASK_AFFILIATION_COLOR.equals(attrName)) {
            taskAffiliationColor = Integer.parseInt(attrValue);
        } else if (ATTR_CALLING_UID.equals(attrName)) {
            callingUid = Integer.parseInt(attrValue);
        } else if (ATTR_CALLING_PACKAGE.equals(attrName)) {
            callingPackage = attrValue;
        } else if (ATTR_RESIZE_MODE.equals(attrName)) {
            resizeMode = Integer.parseInt(attrValue);
            resizeMode = (resizeMode == RESIZE_MODE_CROP_WINDOWS) ? RESIZE_MODE_FORCE_RESIZEABLE : resizeMode;
        } else if (ATTR_PRIVILEGED.equals(attrName)) {
            privileged = Boolean.valueOf(attrValue);
        } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
            bounds = Rect.unflattenFromString(attrValue);
        } else if (ATTR_MIN_WIDTH.equals(attrName)) {
            minWidth = Integer.parseInt(attrValue);
        } else if (ATTR_MIN_HEIGHT.equals(attrName)) {
            minHeight = Integer.parseInt(attrValue);
        } else {
            Slog.w(TAG, "TaskRecord: Unknown attribute=" + attrName);
        }
    }
    int event;
    while (((event = in.next()) != XmlPullParser.END_DOCUMENT) && (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
        if (event == XmlPullParser.START_TAG) {
            final String name = in.getName();
            if (TaskPersister.DEBUG)
                Slog.d(TaskPersister.TAG, "TaskRecord: START_TAG name=" + name);
            if (TAG_AFFINITYINTENT.equals(name)) {
                affinityIntent = Intent.restoreFromXml(in);
            } else if (TAG_INTENT.equals(name)) {
                intent = Intent.restoreFromXml(in);
            } else if (TAG_ACTIVITY.equals(name)) {
                ActivityRecord activity = ActivityRecord.restoreFromXml(in, stackSupervisor);
                if (TaskPersister.DEBUG)
                    Slog.d(TaskPersister.TAG, "TaskRecord: activity=" + activity);
                if (activity != null) {
                    activities.add(activity);
                }
            } else {
                Slog.e(TAG, "restoreTask: Unexpected name=" + name);
                XmlUtils.skipCurrentTag(in);
            }
        }
    }
    if (!hasRootAffinity) {
        rootAffinity = affinity;
    } else if ("@".equals(rootAffinity)) {
        rootAffinity = null;
    }
    if (effectiveUid <= 0) {
        Intent checkIntent = intent != null ? intent : affinityIntent;
        effectiveUid = 0;
        if (checkIntent != null) {
            IPackageManager pm = AppGlobals.getPackageManager();
            try {
                ApplicationInfo ai = pm.getApplicationInfo(checkIntent.getComponent().getPackageName(), PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS, userId);
                if (ai != null) {
                    effectiveUid = ai.uid;
                }
            } catch (RemoteException e) {
            }
        }
        Slog.w(TAG, "Updating task #" + taskId + " for " + checkIntent + ": effectiveUid=" + effectiveUid);
    }
    final TaskRecord task = new TaskRecord(stackSupervisor.mService, taskId, intent, affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset, autoRemoveRecents, askedCompatMode, taskType, userId, effectiveUid, lastDescription, activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity, taskDescription, thumbnailInfo, taskAffiliation, prevTaskId, nextTaskId, taskAffiliationColor, callingUid, callingPackage, resizeMode, privileged, realActivitySuspended, userSetupComplete, minWidth, minHeight);
    task.updateOverrideConfiguration(bounds);
    for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
        activities.get(activityNdx).task = task;
    }
    if (DEBUG_RECENTS)
        Slog.d(TAG_RECENTS, "Restored task=" + task);
    return task;
}
Also used : Rect(android.graphics.Rect) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) Point(android.graphics.Point) TaskDescription(android.app.ActivityManager.TaskDescription) IPackageManager(android.content.pm.IPackageManager) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException) TaskThumbnailInfo(android.app.ActivityManager.TaskThumbnailInfo)

Example 69 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by AOSPA.

the class AppOpsService method readUid.

void readUid(XmlPullParser parser, String pkgName) throws NumberFormatException, XmlPullParserException, IOException {
    int uid = Integer.parseInt(parser.getAttributeValue(null, "n"));
    String isPrivilegedString = parser.getAttributeValue(null, "p");
    boolean isPrivileged = false;
    if (isPrivilegedString == null) {
        try {
            IPackageManager packageManager = ActivityThread.getPackageManager();
            if (packageManager != null) {
                ApplicationInfo appInfo = ActivityThread.getPackageManager().getApplicationInfo(pkgName, 0, UserHandle.getUserId(uid));
                if (appInfo != null) {
                    isPrivileged = (appInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
                }
            } else {
                // Could not load data, don't add to cache so it will be loaded later.
                return;
            }
        } catch (RemoteException e) {
            Slog.w(TAG, "Could not contact PackageManager", e);
        }
    } else {
        isPrivileged = Boolean.parseBoolean(isPrivilegedString);
    }
    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }
        String tagName = parser.getName();
        if (tagName.equals("op")) {
            Op op = new Op(uid, pkgName, Integer.parseInt(parser.getAttributeValue(null, "n")));
            String mode = parser.getAttributeValue(null, "m");
            if (mode != null) {
                op.mode = Integer.parseInt(mode);
            }
            String time = parser.getAttributeValue(null, "t");
            if (time != null) {
                op.time = Long.parseLong(time);
            }
            time = parser.getAttributeValue(null, "r");
            if (time != null) {
                op.rejectTime = Long.parseLong(time);
            }
            String dur = parser.getAttributeValue(null, "d");
            if (dur != null) {
                op.duration = Integer.parseInt(dur);
            }
            String proxyUid = parser.getAttributeValue(null, "pu");
            if (proxyUid != null) {
                op.proxyUid = Integer.parseInt(proxyUid);
            }
            String proxyPackageName = parser.getAttributeValue(null, "pp");
            if (proxyPackageName != null) {
                op.proxyPackageName = proxyPackageName;
            }
            UidState uidState = getUidStateLocked(uid, true);
            if (uidState.pkgOps == null) {
                uidState.pkgOps = new ArrayMap<>();
            }
            Ops ops = uidState.pkgOps.get(pkgName);
            if (ops == null) {
                ops = new Ops(pkgName, uidState, isPrivileged);
                uidState.pkgOps.put(pkgName, ops);
            }
            ops.put(op.op, op);
        } else {
            Slog.w(TAG, "Unknown element under <pkg>: " + parser.getName());
            XmlUtils.skipCurrentTag(parser);
        }
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 70 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by AOSPA.

the class NfcFCardEmulation method getInstance.

/**
     * Helper to get an instance of this class.
     *
     * @param adapter A reference to an NfcAdapter object.
     * @return
     */
public static synchronized NfcFCardEmulation getInstance(NfcAdapter adapter) {
    if (adapter == null)
        throw new NullPointerException("NfcAdapter is null");
    Context context = adapter.getContext();
    if (context == null) {
        Log.e(TAG, "NfcAdapter context is null.");
        throw new UnsupportedOperationException();
    }
    if (!sIsInitialized) {
        IPackageManager pm = ActivityThread.getPackageManager();
        if (pm == null) {
            Log.e(TAG, "Cannot get PackageManager");
            throw new UnsupportedOperationException();
        }
        try {
            if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION_NFCF, 0)) {
                Log.e(TAG, "This device does not support NFC-F card emulation");
                throw new UnsupportedOperationException();
            }
        } catch (RemoteException e) {
            Log.e(TAG, "PackageManager query failed.");
            throw new UnsupportedOperationException();
        }
        sIsInitialized = true;
    }
    NfcFCardEmulation manager = sCardEmus.get(context);
    if (manager == null) {
        // Get card emu service
        INfcFCardEmulation service = adapter.getNfcFCardEmulationService();
        if (service == null) {
            Log.e(TAG, "This device does not implement the INfcFCardEmulation interface.");
            throw new UnsupportedOperationException();
        }
        manager = new NfcFCardEmulation(context, service);
        sCardEmus.put(context, manager);
    }
    return manager;
}
Also used : Context(android.content.Context) IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException) INfcFCardEmulation(android.nfc.INfcFCardEmulation) INfcFCardEmulation(android.nfc.INfcFCardEmulation)

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