Search in sources :

Example 26 with NameNotFoundException

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);
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Bundle(android.os.Bundle)

Example 27 with NameNotFoundException

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;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 28 with NameNotFoundException

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());
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable)

Example 29 with NameNotFoundException

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;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Signature(android.content.pm.Signature)

Example 30 with NameNotFoundException

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();
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) UserInfo(android.content.pm.UserInfo) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Cursor(android.database.Cursor) Bitmap(android.graphics.Bitmap) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException) Pair(android.util.Pair)

Aggregations

NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1012 PackageManager (android.content.pm.PackageManager)358 PackageInfo (android.content.pm.PackageInfo)291 ApplicationInfo (android.content.pm.ApplicationInfo)235 Intent (android.content.Intent)143 ComponentName (android.content.ComponentName)134 ActivityInfo (android.content.pm.ActivityInfo)125 Resources (android.content.res.Resources)112 Context (android.content.Context)105 Drawable (android.graphics.drawable.Drawable)93 Bundle (android.os.Bundle)93 IOException (java.io.IOException)91 UserHandle (android.os.UserHandle)79 ResolveInfo (android.content.pm.ResolveInfo)72 ArrayList (java.util.ArrayList)68 RemoteException (android.os.RemoteException)63 File (java.io.File)57 TextView (android.widget.TextView)52 View (android.view.View)47 FileNotFoundException (java.io.FileNotFoundException)44