Search in sources :

Example 66 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.

the class DevicePolicyManagerService method notifyPendingSystemUpdate.

@Override
public void notifyPendingSystemUpdate(long updateReceivedTime) {
    mContext.enforceCallingOrSelfPermission(permission.NOTIFY_PENDING_SYSTEM_UPDATE, "Only the system update service can broadcast update information");
    if (UserHandle.getCallingUserId() != UserHandle.USER_SYSTEM) {
        Slog.w(LOG_TAG, "Only the system update service in the system user " + "can broadcast update information.");
        return;
    }
    Intent intent = new Intent(DeviceAdminReceiver.ACTION_NOTIFY_PENDING_SYSTEM_UPDATE);
    intent.putExtra(DeviceAdminReceiver.EXTRA_SYSTEM_UPDATE_RECEIVED_TIME, updateReceivedTime);
    synchronized (this) {
        final String deviceOwnerPackage = mOwners.hasDeviceOwner() ? mOwners.getDeviceOwnerComponent().getPackageName() : null;
        if (deviceOwnerPackage == null) {
            return;
        }
        final UserHandle deviceOwnerUser = new UserHandle(mOwners.getDeviceOwnerUserId());
        ActivityInfo[] receivers = null;
        try {
            receivers = mContext.getPackageManager().getPackageInfo(deviceOwnerPackage, PackageManager.GET_RECEIVERS).receivers;
        } catch (NameNotFoundException e) {
            Log.e(LOG_TAG, "Cannot find device owner package", e);
        }
        if (receivers != null) {
            long ident = mInjector.binderClearCallingIdentity();
            try {
                for (int i = 0; i < receivers.length; i++) {
                    if (permission.BIND_DEVICE_ADMIN.equals(receivers[i].permission)) {
                        intent.setComponent(new ComponentName(deviceOwnerPackage, receivers[i].name));
                        mContext.sendBroadcastAsUser(intent, deviceOwnerUser);
                    }
                }
            } finally {
                mInjector.binderRestoreCallingIdentity(ident);
            }
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ComponentName(android.content.ComponentName) ParcelableString(com.android.internal.util.ParcelableString)

Example 67 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.

the class RemoteViews method getApplicationInfo.

private static ApplicationInfo getApplicationInfo(String packageName, int userId) {
    if (packageName == null) {
        return null;
    }
    // Get the application for the passed in package and user.
    Application application = ActivityThread.currentApplication();
    if (application == null) {
        throw new IllegalStateException("Cannot create remote views out of an aplication.");
    }
    ApplicationInfo applicationInfo = application.getApplicationInfo();
    if (UserHandle.getUserId(applicationInfo.uid) != userId || !applicationInfo.packageName.equals(packageName)) {
        try {
            Context context = application.getBaseContext().createPackageContextAsUser(packageName, 0, new UserHandle(userId));
            applicationInfo = context.getApplicationInfo();
        } catch (NameNotFoundException nnfe) {
            throw new IllegalArgumentException("No such package " + packageName);
        }
    }
    return applicationInfo;
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) UserHandle(android.os.UserHandle) ApplicationInfo(android.content.pm.ApplicationInfo) Application(android.app.Application)

Example 68 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.

the class ResolverActivity method onCreate.

protected void onCreate(Bundle savedInstanceState, Intent intent, CharSequence title, int defaultTitleRes, Intent[] initialIntents, List<ResolveInfo> rList, boolean alwaysUseOption) {
    setTheme(R.style.Theme_DeviceDefault_Resolver);
    super.onCreate(savedInstanceState);
    // Determine whether we should show that intent is forwarded
    // from managed profile to owner or other way around.
    setProfileSwitchMessageId(intent.getContentUserHint());
    try {
        mLaunchedFromUid = ActivityManagerNative.getDefault().getLaunchedFromUid(getActivityToken());
    } catch (RemoteException e) {
        mLaunchedFromUid = -1;
    }
    if (mLaunchedFromUid < 0 || UserHandle.isIsolated(mLaunchedFromUid)) {
        // Gulp!
        finish();
        return;
    }
    mPm = getPackageManager();
    mPackageMonitor.register(this, getMainLooper(), false);
    mRegistered = true;
    final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    mIconDpi = am.getLauncherLargeIconDensity();
    // Add our initial intent as the first item, regardless of what else has already been added.
    mIntents.add(0, new Intent(intent));
    final String referrerPackage = getReferrerPackageName();
    mResolverComparator = new ResolverComparator(this, getTargetIntent(), referrerPackage);
    if (configureContentView(mIntents, initialIntents, rList, alwaysUseOption)) {
        return;
    }
    final ResolverDrawerLayout rdl = (ResolverDrawerLayout) findViewById(R.id.contentPanel);
    if (rdl != null) {
        rdl.setOnDismissedListener(new ResolverDrawerLayout.OnDismissedListener() {

            @Override
            public void onDismissed() {
                finish();
            }
        });
        if (isVoiceInteraction()) {
            rdl.setCollapsed(false);
        }
        mResolverDrawerLayout = rdl;
    }
    if (title == null) {
        title = getTitleForAction(intent.getAction(), defaultTitleRes);
    }
    if (!TextUtils.isEmpty(title)) {
        final TextView titleView = (TextView) findViewById(R.id.title);
        if (titleView != null) {
            titleView.setText(title);
        }
        setTitle(title);
        // Try to initialize the title icon if we have a view for it and a title to match
        final ImageView titleIcon = (ImageView) findViewById(R.id.title_icon);
        if (titleIcon != null) {
            ApplicationInfo ai = null;
            try {
                if (!TextUtils.isEmpty(referrerPackage)) {
                    ai = mPm.getApplicationInfo(referrerPackage, 0);
                }
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Could not find referrer package " + referrerPackage);
            }
            if (ai != null) {
                titleIcon.setImageDrawable(ai.loadIcon(mPm));
            }
        }
    }
    final ImageView iconView = (ImageView) findViewById(R.id.icon);
    final DisplayResolveInfo iconInfo = mAdapter.getFilteredItem();
    if (iconView != null && iconInfo != null) {
        new LoadIconIntoViewTask(iconInfo, iconView).execute();
    }
    if (alwaysUseOption || mAdapter.hasFilteredItem()) {
        final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar);
        if (buttonLayout != null) {
            buttonLayout.setVisibility(View.VISIBLE);
            mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always);
            mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once);
        } else {
            mAlwaysUseOption = false;
        }
    }
    if (mAdapter.hasFilteredItem()) {
        setAlwaysButtonEnabled(true, mAdapter.getFilteredPosition(), false);
        mOnceButton.setEnabled(true);
    }
    mProfileView = findViewById(R.id.profile_button);
    if (mProfileView != null) {
        mProfileView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final DisplayResolveInfo dri = mAdapter.getOtherProfile();
                if (dri == null) {
                    return;
                }
                // Do not show the profile switch message anymore.
                mProfileSwitchMessageId = -1;
                onTargetSelected(dri, false);
                finish();
            }
        });
        bindProfileView();
    }
    if (isVoiceInteraction()) {
        onSetupVoiceInteraction();
    }
    final Set<String> categories = intent.getCategories();
    MetricsLogger.action(this, mAdapter.hasFilteredItem() ? MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_APP_FEATURED : MetricsProto.MetricsEvent.ACTION_SHOW_APP_DISAMBIG_NONE_FEATURED, intent.getAction() + ":" + intent.getType() + ":" + (categories != null ? Arrays.toString(categories.toArray()) : ""));
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ViewGroup(android.view.ViewGroup) ApplicationInfo(android.content.pm.ApplicationInfo) LabeledIntent(android.content.pm.LabeledIntent) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager) ResolverDrawerLayout(com.android.internal.widget.ResolverDrawerLayout) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) RemoteException(android.os.RemoteException)

Example 69 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.

the class AndroidPackageInfoFetcher method getStatements.

/**
     * Returns all statements that the specified package makes in its AndroidManifest.xml.
     *
     * @throws NameNotFoundException if the app is not installed on the device.
     */
public List<String> getStatements(String packageName) throws NameNotFoundException {
    PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
    ApplicationInfo appInfo = packageInfo.applicationInfo;
    if (appInfo.metaData == null) {
        return Collections.<String>emptyList();
    }
    int tokenResourceId = appInfo.metaData.getInt(ASSOCIATED_ASSETS_KEY);
    if (tokenResourceId == 0) {
        return Collections.<String>emptyList();
    }
    try {
        return Arrays.asList(mContext.getPackageManager().getResourcesForApplication(packageName).getStringArray(tokenResourceId));
    } catch (NotFoundException e) {
        return Collections.<String>emptyList();
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 70 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by ResurrectionRemix.

the class LocationManagerService method ensureFallbackFusedProviderPresentLocked.

private void ensureFallbackFusedProviderPresentLocked(ArrayList<String> pkgs) {
    PackageManager pm = mContext.getPackageManager();
    String systemPackageName = mContext.getPackageName();
    ArrayList<HashSet<Signature>> sigSets = ServiceWatcher.getSignatureSets(mContext, pkgs);
    List<ResolveInfo> rInfos = pm.queryIntentServicesAsUser(new Intent(FUSED_LOCATION_SERVICE_ACTION), PackageManager.GET_META_DATA, mCurrentUserId);
    for (ResolveInfo rInfo : rInfos) {
        String packageName = rInfo.serviceInfo.packageName;
        // this list the standard provider binding logic won't bind to it.
        try {
            PackageInfo pInfo;
            pInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
            if (!ServiceWatcher.isSignatureMatch(pInfo.signatures, sigSets)) {
                Log.w(TAG, packageName + " resolves service " + FUSED_LOCATION_SERVICE_ACTION + ", but has wrong signature, ignoring");
                continue;
            }
        } catch (NameNotFoundException e) {
            Log.e(TAG, "missing package: " + packageName);
            continue;
        }
        // Get the version info
        if (rInfo.serviceInfo.metaData == null) {
            Log.w(TAG, "Found fused provider without metadata: " + packageName);
            continue;
        }
        int version = rInfo.serviceInfo.metaData.getInt(ServiceWatcher.EXTRA_SERVICE_VERSION, -1);
        if (version == 0) {
            // Make sure it's in the system partition.
            if ((rInfo.serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                if (D)
                    Log.d(TAG, "Fallback candidate not in /system: " + packageName);
                continue;
            }
            // as a proxy for coreApp="true"
            if (pm.checkSignatures(systemPackageName, packageName) != PackageManager.SIGNATURE_MATCH) {
                if (D)
                    Log.d(TAG, "Fallback candidate not signed the same as system: " + packageName);
                continue;
            }
            // Found a valid fallback.
            if (D)
                Log.d(TAG, "Found fallback provider: " + packageName);
            return;
        } else {
            if (D)
                Log.d(TAG, "Fallback candidate not version 0: " + packageName);
        }
    }
    throw new IllegalStateException("Unable to find a fused location provider that is in the " + "system partition with version 0 and signed with the platform certificate. " + "Such a package is needed to provide a default fused location provider in the " + "event that no other fused location provider has been installed or is currently " + "available. For example, coreOnly boot mode when decrypting the data " + "partition. The fallback must also be marked coreApp=\"true\" in the manifest");
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) HashSet(java.util.HashSet)

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)141 ComponentName (android.content.ComponentName)133 ActivityInfo (android.content.pm.ActivityInfo)125 Resources (android.content.res.Resources)112 Context (android.content.Context)103 Drawable (android.graphics.drawable.Drawable)93 Bundle (android.os.Bundle)93 IOException (java.io.IOException)90 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