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);
}
}
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());
}
}
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;
}
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();
}
}
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);
}
Aggregations