Search in sources :

Example 16 with IPackageManager

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

the class AccountManagerService method checkUidPermission.

private boolean checkUidPermission(String permission, int uid, String opPackageName) {
    final long identity = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = ActivityThread.getPackageManager();
        if (pm.checkUidPermission(permission, uid) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
        final int opCode = AppOpsManager.permissionToOpCode(permission);
        return (opCode == AppOpsManager.OP_NONE || mAppOpsManager.noteOpNoThrow(opCode, uid, opPackageName) == AppOpsManager.MODE_ALLOWED);
    } catch (RemoteException e) {
    /* ignore - local call */
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
    return false;
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException)

Example 17 with IPackageManager

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

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 18 with IPackageManager

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

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)) {
                    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 19 with IPackageManager

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

the class CardEmulation method getInstance.

/**
     * Helper to get an instance of this class.
     *
     * @param adapter A reference to an NfcAdapter object.
     * @return
     */
public static synchronized CardEmulation 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, 0)) {
                Log.e(TAG, "This device does not support card emulation");
                throw new UnsupportedOperationException();
            }
        } catch (RemoteException e) {
            Log.e(TAG, "PackageManager query failed.");
            throw new UnsupportedOperationException();
        }
        sIsInitialized = true;
    }
    CardEmulation manager = sCardEmus.get(context);
    if (manager == null) {
        // Get card emu service
        INfcCardEmulation service = adapter.getCardEmulationService();
        if (service == null) {
            Log.e(TAG, "This device does not implement the INfcCardEmulation interface.");
            throw new UnsupportedOperationException();
        }
        manager = new CardEmulation(context, service);
        sCardEmus.put(context, manager);
    }
    return manager;
}
Also used : Context(android.content.Context) INfcCardEmulation(android.nfc.INfcCardEmulation) IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException) INfcCardEmulation(android.nfc.INfcCardEmulation)

Example 20 with IPackageManager

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

the class AppRestrictionsHelper method fetchAndMergeApps.

public void fetchAndMergeApps() {
    mVisibleApps = new ArrayList<>();
    final PackageManager pm = mPackageManager;
    final IPackageManager ipm = mIPm;
    final HashSet<String> excludePackages = new HashSet<>();
    addSystemImes(excludePackages);
    // Add launchers
    Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
    if (mLeanback) {
        launcherIntent.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
    } else {
        launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    }
    addSystemApps(mVisibleApps, launcherIntent, excludePackages);
    // Add widgets
    Intent widgetIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    addSystemApps(mVisibleApps, widgetIntent, excludePackages);
    List<ApplicationInfo> installedApps = pm.getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES);
    for (ApplicationInfo app : installedApps) {
        // If it's not installed, skip
        if ((app.flags & ApplicationInfo.FLAG_INSTALLED) == 0)
            continue;
        if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && (app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0) {
            // Downloaded app
            SelectableAppInfo info = new SelectableAppInfo();
            info.packageName = app.packageName;
            info.appName = app.loadLabel(pm);
            info.activityName = info.appName;
            info.icon = app.loadIcon(pm);
            mVisibleApps.add(info);
        } else {
            try {
                PackageInfo pi = pm.getPackageInfo(app.packageName, 0);
                // but will still be marked as false and immutable.
                if (mRestrictedProfile && pi.requiredAccountType != null && pi.restrictedAccountType == null) {
                    mSelectedPackages.put(app.packageName, false);
                }
            } catch (PackageManager.NameNotFoundException re) {
            // Skip
            }
        }
    }
    // Get the list of apps already installed for the user
    List<ApplicationInfo> userApps = null;
    try {
        ParceledListSlice<ApplicationInfo> listSlice = ipm.getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES, mUser.getIdentifier());
        if (listSlice != null) {
            userApps = listSlice.getList();
        }
    } catch (RemoteException re) {
    // Ignore
    }
    if (userApps != null) {
        for (ApplicationInfo app : userApps) {
            if ((app.flags & ApplicationInfo.FLAG_INSTALLED) == 0)
                continue;
            if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && (app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0) {
                // Downloaded app
                SelectableAppInfo info = new SelectableAppInfo();
                info.packageName = app.packageName;
                info.appName = app.loadLabel(pm);
                info.activityName = info.appName;
                info.icon = app.loadIcon(pm);
                mVisibleApps.add(info);
            }
        }
    }
    // Sort the list of visible apps
    Collections.sort(mVisibleApps, new AppLabelComparator());
    // Remove dupes
    Set<String> dedupPackageSet = new HashSet<String>();
    for (int i = mVisibleApps.size() - 1; i >= 0; i--) {
        SelectableAppInfo info = mVisibleApps.get(i);
        if (DEBUG)
            Log.i(TAG, info.toString());
        String both = info.packageName + "+" + info.activityName;
        if (!TextUtils.isEmpty(info.packageName) && !TextUtils.isEmpty(info.activityName) && dedupPackageSet.contains(both)) {
            mVisibleApps.remove(i);
        } else {
            dedupPackageSet.add(both);
        }
    }
    // Establish master/slave relationship for entries that share a package name
    HashMap<String, SelectableAppInfo> packageMap = new HashMap<String, SelectableAppInfo>();
    for (SelectableAppInfo info : mVisibleApps) {
        if (packageMap.containsKey(info.packageName)) {
            info.masterEntry = packageMap.get(info.packageName);
        } else {
            packageMap.put(info.packageName, info);
        }
    }
}
Also used : HashMap(java.util.HashMap) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException) HashSet(java.util.HashSet)

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