Search in sources :

Example 31 with IPackageManager

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

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)

Example 32 with IPackageManager

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

the class CompatModePackages method saveCompatModes.

void saveCompatModes() {
    HashMap<String, Integer> pkgs;
    synchronized (mService) {
        pkgs = new HashMap<String, Integer>(mPackages);
    }
    FileOutputStream fos = null;
    try {
        fos = mFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        out.startTag(null, "compat-packages");
        final IPackageManager pm = AppGlobals.getPackageManager();
        final int screenLayout = mService.mConfiguration.screenLayout;
        final int smallestScreenWidthDp = mService.mConfiguration.smallestScreenWidthDp;
        final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Integer> entry = it.next();
            String pkg = entry.getKey();
            int mode = entry.getValue();
            if (mode == 0) {
                continue;
            }
            ApplicationInfo ai = null;
            try {
                ai = pm.getApplicationInfo(pkg, 0, 0);
            } catch (RemoteException e) {
            }
            if (ai == null) {
                continue;
            }
            CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout, smallestScreenWidthDp, false);
            if (info.alwaysSupportsScreen()) {
                continue;
            }
            if (info.neverSupportsScreen()) {
                continue;
            }
            out.startTag(null, "pkg");
            out.attribute(null, "name", pkg);
            out.attribute(null, "mode", Integer.toString(mode));
            out.endTag(null, "pkg");
        }
        out.endTag(null, "compat-packages");
        out.endDocument();
        mFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Slog.w(TAG, "Error writing compat packages", e1);
        if (fos != null) {
            mFile.failWrite(fos);
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IPackageManager(android.content.pm.IPackageManager) FileOutputStream(java.io.FileOutputStream) RemoteException(android.os.RemoteException) HashMap(java.util.HashMap) Map(java.util.Map) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 33 with IPackageManager

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

the class NfcCommand method run.

@Override
public void run(String[] args) {
    boolean validCommand = false;
    if (args.length >= 2) {
        boolean flag = false;
        if ("enable".equals(args[1])) {
            flag = true;
            validCommand = true;
        } else if ("disable".equals(args[1])) {
            flag = false;
            validCommand = true;
        }
        if (validCommand) {
            IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
            try {
                if (pm.hasSystemFeature(PackageManager.FEATURE_NFC, 0) || pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION, 0)) {
                    INfcAdapter nfc = INfcAdapter.Stub.asInterface(ServiceManager.getService(Context.NFC_SERVICE));
                    try {
                        if (flag) {
                            nfc.enable();
                        } else
                            nfc.disable(true);
                    } catch (RemoteException e) {
                        System.err.println("NFC operation failed: " + e);
                    }
                } else {
                    System.err.println("NFC feature not supported.");
                }
            } catch (RemoteException e) {
                System.err.println("RemoteException while calling PackageManager, is the " + "system running?");
            }
            return;
        }
    }
    System.err.println(longHelp());
}
Also used : IPackageManager(android.content.pm.IPackageManager) INfcAdapter(android.nfc.INfcAdapter) RemoteException(android.os.RemoteException)

Example 34 with IPackageManager

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

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")) {
            int code = Integer.parseInt(parser.getAttributeValue(null, "n"));
            // use op name string if it exists
            String codeNameStr = parser.getAttributeValue(null, "ns");
            if (codeNameStr != null) {
                // returns OP_NONE if it could not be mapped
                code = AppOpsManager.nameToOp(codeNameStr);
            }
            // skip op codes that are out of bounds
            if (code == AppOpsManager.OP_NONE || code >= AppOpsManager._NUM_OP) {
                continue;
            }
            Op op = new Op(uid, pkgName, code, AppOpsManager.MODE_ERRORED);
            String mode = parser.getAttributeValue(null, "m");
            if (mode != null) {
                op.mode = Integer.parseInt(mode);
            } else {
                String sDefualtMode = parser.getAttributeValue(null, "dm");
                int defaultMode;
                if (sDefualtMode != null) {
                    defaultMode = Integer.parseInt(sDefualtMode);
                } else {
                    defaultMode = getDefaultMode(code, uid, pkgName);
                }
                op.mode = defaultMode;
            }
            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;
            }
            String allowed = parser.getAttributeValue(null, "ac");
            if (allowed != null) {
                op.allowedCount = Integer.parseInt(allowed);
            }
            String ignored = parser.getAttributeValue(null, "ic");
            if (ignored != null) {
                op.ignoredCount = Integer.parseInt(ignored);
            }
            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 35 with IPackageManager

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

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)

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