use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.
the class ManagedServices method registerServiceLocked.
private void registerServiceLocked(final ComponentName name, final int userid, final boolean isSystem) {
if (DEBUG)
Slog.v(TAG, "registerService: " + name + " u=" + userid);
final String servicesBindingTag = name.toString() + "/" + userid;
if (mServicesBinding.contains(servicesBindingTag)) {
// stop registering this thing already! we're working on it
return;
}
mServicesBinding.add(servicesBindingTag);
final int N = mServices.size();
for (int i = N - 1; i >= 0; i--) {
final ManagedServiceInfo info = mServices.get(i);
if (name.equals(info.component) && info.userid == userid) {
// cut old connections
if (DEBUG)
Slog.v(TAG, " disconnecting old " + getCaption() + ": " + info.service);
removeServiceLocked(i);
if (info.connection != null) {
mContext.unbindService(info.connection);
}
}
}
Intent intent = new Intent(mConfig.serviceInterface);
intent.setComponent(name);
intent.putExtra(Intent.EXTRA_CLIENT_LABEL, mConfig.clientLabel);
final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mConfig.settingsAction), 0);
intent.putExtra(Intent.EXTRA_CLIENT_INTENT, pendingIntent);
ApplicationInfo appInfo = null;
try {
appInfo = mContext.getPackageManager().getApplicationInfo(name.getPackageName(), 0);
} catch (NameNotFoundException e) {
// Ignore if the package doesn't exist we won't be able to bind to the service.
}
final int targetSdkVersion = appInfo != null ? appInfo.targetSdkVersion : Build.VERSION_CODES.BASE;
try {
if (DEBUG)
Slog.v(TAG, "binding: " + intent);
ServiceConnection serviceConnection = new ServiceConnection() {
IInterface mService;
@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
boolean added = false;
ManagedServiceInfo info = null;
synchronized (mMutex) {
mServicesBinding.remove(servicesBindingTag);
try {
mService = asInterface(binder);
info = newServiceInfo(mService, name, userid, isSystem, this, targetSdkVersion);
binder.linkToDeath(info, 0);
added = mServices.add(info);
} catch (RemoteException e) {
// already dead
}
}
if (added) {
onServiceAdded(info);
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
Slog.v(TAG, getCaption() + " connection lost: " + name);
}
};
if (!mContext.bindServiceAsUser(intent, serviceConnection, BIND_AUTO_CREATE | BIND_FOREGROUND_SERVICE | BIND_ALLOW_WHITELIST_MANAGEMENT, new UserHandle(userid))) {
mServicesBinding.remove(servicesBindingTag);
Slog.w(TAG, "Unable to bind " + getCaption() + " service: " + intent);
return;
}
} catch (SecurityException ex) {
Slog.e(TAG, "Unable to bind " + getCaption() + " service: " + intent, ex);
return;
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.
the class NotificationManagerService method generateLedColorForNotification.
private int generateLedColorForNotification(NotificationRecord ledNotification) {
if (!mAutoGenerateNotificationColor) {
return mDefaultNotificationColor;
}
if (!mMultiColorNotificationLed) {
return mDefaultNotificationColor;
}
final String packageName = ledNotification.sbn.getPackageName();
final String mapping = mapPackage(packageName);
int color = mDefaultNotificationColor;
if (mGeneratedPackageLedColors.containsKey(mapping)) {
return mGeneratedPackageLedColors.get(mapping);
}
PackageManager pm = getContext().getPackageManager();
Drawable icon;
try {
icon = pm.getApplicationIcon(mapping);
} catch (NameNotFoundException e) {
Slog.e(TAG, e.getMessage(), e);
return color;
}
color = ColorUtils.generateAlertColorFromDrawable(icon);
mGeneratedPackageLedColors.put(mapping, color);
return color;
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.
the class RankingHelper method readXml.
public void readXml(XmlPullParser parser, boolean forRestore) throws XmlPullParserException, IOException {
final PackageManager pm = mContext.getPackageManager();
int type = parser.getEventType();
if (type != XmlPullParser.START_TAG)
return;
String tag = parser.getName();
if (!TAG_RANKING.equals(tag))
return;
mRecords.clear();
mRestoredWithoutUids.clear();
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
tag = parser.getName();
if (type == XmlPullParser.END_TAG && TAG_RANKING.equals(tag)) {
return;
}
if (type == XmlPullParser.START_TAG) {
if (TAG_PACKAGE.equals(tag)) {
int uid = safeInt(parser, ATT_UID, Record.UNKNOWN_UID);
String name = parser.getAttributeValue(null, ATT_NAME);
if (!TextUtils.isEmpty(name)) {
if (forRestore) {
try {
//TODO: http://b/22388012
uid = pm.getPackageUidAsUser(name, UserHandle.USER_SYSTEM);
} catch (NameNotFoundException e) {
// noop
}
}
Record r = null;
if (uid == Record.UNKNOWN_UID) {
r = mRestoredWithoutUids.get(name);
if (r == null) {
r = new Record();
mRestoredWithoutUids.put(name, r);
}
} else {
r = getOrCreateRecord(name, uid);
}
r.importance = safeInt(parser, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
r.priority = safeInt(parser, ATT_PRIORITY, DEFAULT_PRIORITY);
r.visibility = safeInt(parser, ATT_VISIBILITY, DEFAULT_VISIBILITY);
r.soundTimeout = safeInt(parser, ATT_SOUND_TIMEOUT, 0);
}
}
}
}
throw new IllegalStateException("Failed to reach END_DOCUMENT");
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.
the class TvInputManagerService method getContentResolverForUser.
private ContentResolver getContentResolverForUser(int userId) {
UserHandle user = new UserHandle(userId);
Context context;
try {
context = mContext.createPackageContextAsUser("android", 0, user);
} catch (NameNotFoundException e) {
Slog.e(TAG, "failed to create package context as user " + user);
context = mContext;
}
return context.getContentResolver();
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.
the class UidDetailProvider method buildUidDetail.
/**
* Build {@link UidDetail} object, blocking until all {@link Drawable}
* lookup is finished.
*/
private UidDetail buildUidDetail(int uid) {
final Resources res = mContext.getResources();
final PackageManager pm = mContext.getPackageManager();
final UidDetail detail = new UidDetail();
detail.label = pm.getNameForUid(uid);
detail.icon = pm.getDefaultActivityIcon();
// handle special case labels
switch(uid) {
case android.os.Process.SYSTEM_UID:
detail.label = res.getString(R.string.process_kernel_label);
detail.icon = pm.getDefaultActivityIcon();
return detail;
case TrafficStats.UID_REMOVED:
detail.label = res.getString(UserManager.supportsMultipleUsers() ? R.string.data_usage_uninstalled_apps_users : R.string.data_usage_uninstalled_apps);
detail.icon = pm.getDefaultActivityIcon();
return detail;
case TrafficStats.UID_TETHERING:
final ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
detail.label = res.getString(Utils.getTetheringLabel(cm));
detail.icon = pm.getDefaultActivityIcon();
return detail;
}
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
// Handle keys that are actually user handles
if (isKeyForUser(uid)) {
final int userHandle = getUserIdForKey(uid);
final UserInfo info = um.getUserInfo(userHandle);
if (info != null) {
detail.label = Utils.getUserLabel(mContext, info);
detail.icon = Utils.getUserIcon(mContext, um, info);
return detail;
}
}
// otherwise fall back to using packagemanager labels
final String[] packageNames = pm.getPackagesForUid(uid);
final int length = packageNames != null ? packageNames.length : 0;
try {
final int userId = UserHandle.getUserId(uid);
UserHandle userHandle = new UserHandle(userId);
IPackageManager ipm = AppGlobals.getPackageManager();
if (length == 1) {
final ApplicationInfo info = ipm.getApplicationInfo(packageNames[0], 0, /* no flags */
userId);
if (info != null) {
detail.label = info.loadLabel(pm).toString();
detail.icon = um.getBadgedIconForUser(info.loadIcon(pm), new UserHandle(userId));
}
} else if (length > 1) {
detail.detailLabels = new CharSequence[length];
detail.detailContentDescriptions = new CharSequence[length];
for (int i = 0; i < length; i++) {
final String packageName = packageNames[i];
final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0);
final ApplicationInfo appInfo = ipm.getApplicationInfo(packageName, 0, /* no flags */
userId);
if (appInfo != null) {
detail.detailLabels[i] = appInfo.loadLabel(pm).toString();
detail.detailContentDescriptions[i] = um.getBadgedLabelForUser(detail.detailLabels[i], userHandle);
if (packageInfo.sharedUserLabel != 0) {
detail.label = pm.getText(packageName, packageInfo.sharedUserLabel, packageInfo.applicationInfo).toString();
detail.icon = um.getBadgedIconForUser(appInfo.loadIcon(pm), userHandle);
}
}
}
}
detail.contentDescription = um.getBadgedLabelForUser(detail.label, userHandle);
} catch (NameNotFoundException e) {
Log.w(TAG, "Error while building UI detail for uid " + uid, e);
} catch (RemoteException e) {
Log.w(TAG, "Error while building UI detail for uid " + uid, e);
}
if (TextUtils.isEmpty(detail.label)) {
detail.label = Integer.toString(uid);
}
return detail;
}
Aggregations