public void replaceDrawable( ImageView v, ComponentName component, String name, boolean isService) { if (component != null) { try { PackageManager packageManager = mContext.getPackageManager(); // Look for the search icon specified in the activity meta-data Bundle metaData = isService ? packageManager.getServiceInfo(component, PackageManager.GET_META_DATA).metaData : packageManager.getActivityInfo(component, PackageManager.GET_META_DATA).metaData; if (metaData != null) { int iconResId = metaData.getInt(name); if (iconResId != 0) { Resources res = packageManager.getResourcesForApplication(component.getPackageName()); v.setImageDrawable(res.getDrawable(iconResId)); return; } } } catch (PackageManager.NameNotFoundException e) { Log.w( TAG, "Failed to swap drawable; " + component.flattenToShortString() + " not found", e); } catch (Resources.NotFoundException nfe) { Log.w(TAG, "Failed to swap drawable from " + component.flattenToShortString(), nfe); } } v.setImageDrawable(null); }
boolean updateService(Context context, ActivityManager.RunningServiceInfo service) { final PackageManager pm = context.getPackageManager(); boolean changed = false; ServiceItem si = mServices.get(service.service); if (si == null) { changed = true; si = new ServiceItem(); si.mRunningService = service; try { si.mServiceInfo = pm.getServiceInfo(service.service, 0); } catch (PackageManager.NameNotFoundException e) { } si.mDisplayLabel = makeLabel(pm, si.mRunningService.service.getClassName(), si.mServiceInfo); mLabel = mDisplayLabel != null ? mDisplayLabel.toString() : null; si.mPackageInfo = si.mServiceInfo.applicationInfo; mServices.put(service.service, si); } si.mCurSeq = mCurSeq; si.mRunningService = service; long activeSince = service.restarting == 0 ? service.activeSince : -1; if (si.mActiveSince != activeSince) { si.mActiveSince = activeSince; changed = true; } if (service.clientPackage != null && service.clientLabel != 0) { if (si.mShownAsStarted) { si.mShownAsStarted = false; changed = true; } try { Resources clientr = pm.getResourcesForApplication(service.clientPackage); String label = clientr.getString(service.clientLabel); si.mDescription = context.getResources().getString(R.string.service_client_name, label); } catch (PackageManager.NameNotFoundException e) { si.mDescription = null; } } else { if (!si.mShownAsStarted) { si.mShownAsStarted = true; changed = true; } si.mDescription = context.getResources().getString(R.string.service_started_by_app); } return changed; }