use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ParanoidAndroid.
the class MemoryUsageTest method testMemory.
public void testMemory() {
MemoryUsageInstrumentation instrumentation = (MemoryUsageInstrumentation) getInstrumentation();
Bundle args = instrumentation.getBundle();
mAm = ActivityManagerNative.getDefault();
createMappings();
parseArgs(args);
Bundle results = new Bundle();
for (String app : mNameToResultKey.keySet()) {
String processName;
try {
processName = startApp(app);
measureMemory(app, processName, results);
closeApp();
} catch (NameNotFoundException e) {
Log.i(TAG, "Application " + app + " not found");
}
}
instrumentation.sendStatus(0, results);
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ParanoidAndroid.
the class TaskStackBuilder method addParentStack.
/**
* Add the activity parent chain as specified by the
* {@link android.R.attr#parentActivityName parentActivityName} attribute of the activity
* (or activity-alias) element in the application's manifest to the task stack builder.
*
* @param sourceActivityName Must specify an Activity component. All parents of
* this activity will be added
* @return This TaskStackBuilder for method chaining
*/
public TaskStackBuilder addParentStack(ComponentName sourceActivityName) {
final int insertAt = mIntents.size();
PackageManager pm = mSourceContext.getPackageManager();
try {
ActivityInfo info = pm.getActivityInfo(sourceActivityName, 0);
String parentActivity = info.parentActivityName;
while (parentActivity != null) {
final ComponentName target = new ComponentName(info.packageName, parentActivity);
info = pm.getActivityInfo(target, 0);
parentActivity = info.parentActivityName;
final Intent parent = parentActivity == null && insertAt == 0 ? Intent.makeMainActivity(target) : new Intent().setComponent(target);
mIntents.add(insertAt, parent);
}
} catch (NameNotFoundException e) {
Log.e(TAG, "Bad ComponentName while traversing activity parent metadata");
throw new IllegalArgumentException(e);
}
return this;
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ParanoidAndroid.
the class SearchDialog method updateSearchAppIcon.
private void updateSearchAppIcon() {
PackageManager pm = getContext().getPackageManager();
Drawable icon;
try {
ActivityInfo info = pm.getActivityInfo(mLaunchComponent, 0);
icon = pm.getApplicationIcon(info.applicationInfo);
if (DBG)
Log.d(LOG_TAG, "Using app-specific icon");
} catch (NameNotFoundException e) {
icon = pm.getDefaultActivityIcon();
Log.w(LOG_TAG, mLaunchComponent + " not found, using generic app icon");
}
mAppIcon.setImageDrawable(icon);
mAppIcon.setVisibility(View.VISIBLE);
mSearchPlate.setPadding(SEARCH_PLATE_LEFT_PADDING_NON_GLOBAL, mSearchPlate.getPaddingTop(), mSearchPlate.getPaddingRight(), mSearchPlate.getPaddingBottom());
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ParanoidAndroid.
the class NetworkPolicyManager method isUidValidForPolicy.
/**
* Check if given UID can have a {@link #setUidPolicy(int, int)} defined,
* usually to protect critical system services.
*/
@Deprecated
public static boolean isUidValidForPolicy(Context context, int uid) {
// first, quick-reject non-applications
if (!UserHandle.isApp(uid)) {
return false;
}
if (!ALLOW_PLATFORM_APP_POLICY) {
final PackageManager pm = context.getPackageManager();
final HashSet<Signature> systemSignature;
try {
systemSignature = Sets.newHashSet(pm.getPackageInfo("android", GET_SIGNATURES).signatures);
} catch (NameNotFoundException e) {
throw new RuntimeException("problem finding system signature", e);
}
try {
// reject apps signed with platform cert
for (String packageName : pm.getPackagesForUid(uid)) {
final HashSet<Signature> packageSignature = Sets.newHashSet(pm.getPackageInfo(packageName, GET_SIGNATURES).signatures);
if (packageSignature.containsAll(systemSignature)) {
return false;
}
}
} catch (NameNotFoundException e) {
}
}
// nothing found above; we can apply policy to UID
return true;
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ParanoidAndroid.
the class UserTile method queryForUserInformation.
private void queryForUserInformation() {
Context currentUserContext = null;
UserInfo userInfo = null;
try {
userInfo = ActivityManagerNative.getDefault().getCurrentUser();
currentUserContext = mContext.createPackageContextAsUser("android", 0, new UserHandle(userInfo.id));
} catch (NameNotFoundException e) {
Log.e(TAG, "Couldn't create user context", e);
throw new RuntimeException(e);
} catch (RemoteException e) {
Log.e(TAG, "Couldn't get user info", e);
}
final int userId = userInfo.id;
final String userName = userInfo.name;
final Context context = currentUserContext;
mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {
@Override
protected Pair<String, Drawable> doInBackground(Void... params) {
try {
// The system needs some time to change the picture, if we try to load it when we receive the broadcast, we will load the old one
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
// Fall back to the UserManager nickname if we can't read the name from the local
// profile below.
String name = userName;
Drawable avatar = null;
Bitmap rawAvatar = um.getUserIcon(userId);
if (rawAvatar != null) {
avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
} else {
avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
}
// usually valid
if (um.getUsers().size() <= 1) {
// Try and read the display name from the local profile
final Cursor cursor = context.getContentResolver().query(Profile.CONTENT_URI, new String[] { Phone._ID, Phone.DISPLAY_NAME }, null, null, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
}
} finally {
cursor.close();
}
}
}
return new Pair<String, Drawable>(name, avatar);
}
@Override
protected void onPostExecute(Pair<String, Drawable> result) {
super.onPostExecute(result);
setUserTileInfo(result.first, result.second);
mUserInfoTask = null;
}
};
mUserInfoTask.execute();
}
Aggregations