Search in sources :

Example 36 with PackageManager

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

the class AccountManagerBackupHelper method restoreAccountAccessPermissions.

public void restoreAccountAccessPermissions(byte[] data, int userId) {
    try {
        ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(dataStream, StandardCharsets.UTF_8.name());
        PackageManager packageManager = mAccountManagerService.mContext.getPackageManager();
        final int permissionsOuterDepth = parser.getDepth();
        while (XmlUtils.nextElementWithin(parser, permissionsOuterDepth)) {
            if (!TAG_PERMISSIONS.equals(parser.getName())) {
                continue;
            }
            final int permissionOuterDepth = parser.getDepth();
            while (XmlUtils.nextElementWithin(parser, permissionOuterDepth)) {
                if (!TAG_PERMISSION.equals(parser.getName())) {
                    continue;
                }
                String accountDigest = parser.getAttributeValue(null, ATTR_ACCOUNT_SHA_256);
                if (TextUtils.isEmpty(accountDigest)) {
                    XmlUtils.skipCurrentTag(parser);
                }
                String packageName = parser.getAttributeValue(null, ATTR_PACKAGE);
                if (TextUtils.isEmpty(packageName)) {
                    XmlUtils.skipCurrentTag(parser);
                }
                String digest = parser.getAttributeValue(null, ATTR_DIGEST);
                if (TextUtils.isEmpty(digest)) {
                    XmlUtils.skipCurrentTag(parser);
                }
                PendingAppPermission pendingAppPermission = new PendingAppPermission(accountDigest, packageName, digest, userId);
                if (!pendingAppPermission.apply(packageManager)) {
                    synchronized (mLock) {
                        // Start watching before add pending to avoid a missed signal
                        if (mRestorePackageMonitor == null) {
                            mRestorePackageMonitor = new RestorePackageMonitor();
                            mRestorePackageMonitor.register(mAccountManagerService.mContext, mAccountManagerService.mMessageHandler.getLooper(), true);
                        }
                        if (mRestorePendingAppPermissions == null) {
                            mRestorePendingAppPermissions = new ArrayList<>();
                        }
                        mRestorePendingAppPermissions.add(pendingAppPermission);
                    }
                }
            }
        }
        // Make sure we eventually prune the in-memory pending restores
        synchronized (mLock) {
            mRestoreCancelCommand = new CancelRestoreCommand();
        }
        mAccountManagerService.mMessageHandler.postDelayed(mRestoreCancelCommand, PENDING_RESTORE_TIMEOUT_MILLIS);
    } catch (XmlPullParserException | IOException e) {
        Log.e(TAG, "Error restoring app permissions", e);
    }
}
Also used : PackageManager(android.content.pm.PackageManager) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 37 with PackageManager

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

the class TextServicesManagerService method buildSpellCheckerMapLocked.

private static void buildSpellCheckerMapLocked(Context context, ArrayList<SpellCheckerInfo> list, HashMap<String, SpellCheckerInfo> map, TextServicesSettings settings) {
    list.clear();
    map.clear();
    final PackageManager pm = context.getPackageManager();
    // Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default
    // behavior of PackageManager is exactly what we want.  It by default picks up appropriate
    // services depending on the unlock state for the specified user.
    final List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(SpellCheckerService.SERVICE_INTERFACE), PackageManager.GET_META_DATA, settings.getCurrentUserId());
    final int N = services.size();
    for (int i = 0; i < N; ++i) {
        final ResolveInfo ri = services.get(i);
        final ServiceInfo si = ri.serviceInfo;
        final ComponentName compName = new ComponentName(si.packageName, si.name);
        if (!android.Manifest.permission.BIND_TEXT_SERVICE.equals(si.permission)) {
            Slog.w(TAG, "Skipping text service " + compName + ": it does not require the permission " + android.Manifest.permission.BIND_TEXT_SERVICE);
            continue;
        }
        if (DBG)
            Slog.d(TAG, "Add: " + compName);
        try {
            final SpellCheckerInfo sci = new SpellCheckerInfo(context, ri);
            if (sci.getSubtypeCount() <= 0) {
                Slog.w(TAG, "Skipping text service " + compName + ": it does not contain subtypes.");
                continue;
            }
            list.add(sci);
            map.put(sci.getId(), sci);
        } catch (XmlPullParserException e) {
            Slog.w(TAG, "Unable to load the spell checker " + compName, e);
        } catch (IOException e) {
            Slog.w(TAG, "Unable to load the spell checker " + compName, e);
        }
    }
    if (DBG) {
        Slog.d(TAG, "buildSpellCheckerMapLocked: " + list.size() + "," + map.size());
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 38 with PackageManager

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

the class NetworkScorerAppManager method findRecommendationService.

private ResolveInfo findRecommendationService(String packageName) {
    final PackageManager pm = mContext.getPackageManager();
    final int resolveFlags = 0;
    final Intent serviceIntent = new Intent(NetworkScoreManager.ACTION_RECOMMEND_NETWORKS);
    serviceIntent.setPackage(packageName);
    final ResolveInfo resolveServiceInfo = pm.resolveService(serviceIntent, resolveFlags);
    if (VERBOSE) {
        Log.d(TAG, "Resolved " + serviceIntent + " to " + resolveServiceInfo);
    }
    if (resolveServiceInfo != null && resolveServiceInfo.serviceInfo != null) {
        return resolveServiceInfo;
    }
    if (VERBOSE) {
        Log.v(TAG, packageName + " does not have a service for " + serviceIntent);
    }
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent)

Example 39 with PackageManager

use of android.content.pm.PackageManager in project Conversations by siacs.

the class MessageAdapter method openDownloadable.

public void openDownloadable(Message message) {
    DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
    if (!file.exists()) {
        Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show();
        return;
    }
    Intent openIntent = new Intent(Intent.ACTION_VIEW);
    String mime = file.getMimeType();
    if (mime == null) {
        mime = "*/*";
    }
    Uri uri;
    try {
        uri = FileBackend.getUriForFile(activity, file);
    } catch (SecurityException e) {
        Toast.makeText(activity, activity.getString(R.string.no_permission_to_access_x, file.getAbsolutePath()), Toast.LENGTH_SHORT).show();
        return;
    }
    openIntent.setDataAndType(uri, mime);
    openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    PackageManager manager = activity.getPackageManager();
    List<ResolveInfo> info = manager.queryIntentActivities(openIntent, 0);
    if (info.size() == 0) {
        openIntent.setDataAndType(uri, "*/*");
    }
    try {
        getContext().startActivity(openIntent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(activity, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show();
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) SpannableString(android.text.SpannableString) DownloadableFile(eu.siacs.conversations.entities.DownloadableFile) Uri(android.net.Uri)

Example 40 with PackageManager

use of android.content.pm.PackageManager in project dynamic-load-apk by singwhatiwanna.

the class DLUtils method getAppIcon.

public static Drawable getAppIcon(Context context, String apkFilepath) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pkgInfo = getPackageInfo(context, apkFilepath);
    if (pkgInfo == null) {
        return null;
    }
    // Workaround for http://code.google.com/p/android/issues/detail?id=9151
    ApplicationInfo appInfo = pkgInfo.applicationInfo;
    if (Build.VERSION.SDK_INT >= 8) {
        appInfo.sourceDir = apkFilepath;
        appInfo.publicSourceDir = apkFilepath;
    }
    return pm.getApplicationIcon(appInfo);
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

PackageManager (android.content.pm.PackageManager)1475 Intent (android.content.Intent)499 ResolveInfo (android.content.pm.ResolveInfo)456 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)351 PackageInfo (android.content.pm.PackageInfo)268 ApplicationInfo (android.content.pm.ApplicationInfo)253 ComponentName (android.content.ComponentName)241 ArrayList (java.util.ArrayList)158 ActivityInfo (android.content.pm.ActivityInfo)140 IOException (java.io.IOException)126 RemoteException (android.os.RemoteException)105 Drawable (android.graphics.drawable.Drawable)94 IPackageManager (android.content.pm.IPackageManager)93 Resources (android.content.res.Resources)90 PendingIntent (android.app.PendingIntent)75 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)68 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)53 ServiceInfo (android.content.pm.ServiceInfo)48