Search in sources :

Example 21 with NameNotFoundException

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

the class NotificationManagerService method importOldBlockDb.

/**
     * Read the old XML-based app block database and import those blockages into the AppOps system.
     */
private void importOldBlockDb() {
    loadBlockDb();
    PackageManager pm = mContext.getPackageManager();
    for (String pkg : mBlockedPackages) {
        PackageInfo info = null;
        try {
            info = pm.getPackageInfo(pkg, 0);
            setNotificationsEnabledForPackage(pkg, info.applicationInfo.uid, false);
        } catch (NameNotFoundException e) {
        // forget you
        }
    }
    mBlockedPackages.clear();
    if (mPolicyFile != null) {
        mPolicyFile.delete();
    }
    ThemeUtils.registerThemeChangeReceiver(mContext, mThemeChangeReceiver);
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo)

Example 22 with NameNotFoundException

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

the class PackageManagerBackupAgent method onBackup.

// The backed up data is the signature block for each app, keyed by
// the package name.
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) {
    if (DEBUG)
        Slog.v(TAG, "onBackup()");
    // we'll reuse these
    ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream();
    DataOutputStream outputBufferStream = new DataOutputStream(outputBuffer);
    parseStateFile(oldState);
    // "already backed up" map built by parseStateFile().
    if (mStoredIncrementalVersion == null || !mStoredIncrementalVersion.equals(Build.VERSION.INCREMENTAL)) {
        Slog.i(TAG, "Previous metadata " + mStoredIncrementalVersion + " mismatch vs " + Build.VERSION.INCREMENTAL + " - rewriting");
        mExisting.clear();
    }
    try {
        /*
             * Global metadata:
             *
             * int SDKversion -- the SDK version of the OS itself on the device
             *                   that produced this backup set.  Used to reject
             *                   backups from later OSes onto earlier ones.
             * String incremental -- the incremental release name of the OS stored in
             *                       the backup set.
             */
        if (!mExisting.contains(GLOBAL_METADATA_KEY)) {
            if (DEBUG)
                Slog.v(TAG, "Storing global metadata key");
            outputBufferStream.writeInt(Build.VERSION.SDK_INT);
            outputBufferStream.writeUTF(Build.VERSION.INCREMENTAL);
            writeEntity(data, GLOBAL_METADATA_KEY, outputBuffer.toByteArray());
        } else {
            if (DEBUG)
                Slog.v(TAG, "Global metadata key already stored");
            // don't consider it to have been skipped/deleted
            mExisting.remove(GLOBAL_METADATA_KEY);
        }
        // write its signature block to the output, keyed on the package name.
        for (PackageInfo pkg : mAllPackages) {
            String packName = pkg.packageName;
            if (packName.equals(GLOBAL_METADATA_KEY)) {
                // We've already handled the metadata key; skip it here
                continue;
            } else {
                PackageInfo info = null;
                try {
                    info = mPackageManager.getPackageInfo(packName, PackageManager.GET_SIGNATURES);
                } catch (NameNotFoundException e) {
                    // Weird; we just found it, and now are told it doesn't exist.
                    // Treat it as having been removed from the device.
                    mExisting.add(packName);
                    continue;
                }
                if (mExisting.contains(packName)) {
                    // We have backed up this app before.  Check whether the version
                    // of the backup matches the version of the current app; if they
                    // don't match, the app has been updated and we need to store its
                    // metadata again.  In either case, take it out of mExisting so that
                    // we don't consider it deleted later.
                    mExisting.remove(packName);
                    if (info.versionCode == mStateVersions.get(packName).versionCode) {
                        continue;
                    }
                }
                if (info.signatures == null || info.signatures.length == 0) {
                    Slog.w(TAG, "Not backing up package " + packName + " since it appears to have no signatures.");
                    continue;
                }
                // We need to store this app's metadata
                /*
                     * Metadata for each package:
                     *
                     * int version       -- [4] the package's versionCode
                     * byte[] signatures -- [len] flattened Signature[] of the package
                     */
                // marshal the version code in a canonical form
                outputBuffer.reset();
                outputBufferStream.writeInt(info.versionCode);
                writeSignatureArray(outputBufferStream, info.signatures);
                if (DEBUG) {
                    Slog.v(TAG, "+ writing metadata for " + packName + " version=" + info.versionCode + " entityLen=" + outputBuffer.size());
                }
                // Now we can write the backup entity for this package
                writeEntity(data, packName, outputBuffer.toByteArray());
            }
        }
        // on the device.  Write a deletion entity for them.
        for (String app : mExisting) {
            if (DEBUG)
                Slog.v(TAG, "- removing metadata for deleted pkg " + app);
            try {
                data.writeEntityHeader(app, -1);
            } catch (IOException e) {
                Slog.e(TAG, "Unable to write package deletions!");
                return;
            }
        }
    } catch (IOException e) {
        // Real error writing data
        Slog.e(TAG, "Unable to write package backup data file!");
        return;
    }
    // Finally, write the new state blob -- just the list of all apps we handled
    writeStateFile(mAllPackages, newState);
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) DataOutputStream(java.io.DataOutputStream) PackageInfo(android.content.pm.PackageInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 23 with NameNotFoundException

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

the class ServiceWatcher method bindBestPackageLocked.

/**
     * Searches and binds to the best package, or do nothing
     * if the best package is already bound.
     * Only checks the named package, or checks all packages if it
     * is null.
     * Return true if a new package was found to bind to.
     */
private boolean bindBestPackageLocked(String justCheckThisPackage) {
    Intent intent = new Intent(mAction);
    if (justCheckThisPackage != null) {
        intent.setPackage(justCheckThisPackage);
    }
    List<ResolveInfo> rInfos = mPm.queryIntentServicesAsUser(intent, PackageManager.GET_META_DATA, UserHandle.USER_OWNER);
    int bestVersion = Integer.MIN_VALUE;
    String bestPackage = null;
    boolean bestIsMultiuser = false;
    if (rInfos != null) {
        for (ResolveInfo rInfo : rInfos) {
            String packageName = rInfo.serviceInfo.packageName;
            // check signature
            try {
                PackageInfo pInfo;
                pInfo = mPm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
                if (!isSignatureMatch(pInfo.signatures)) {
                    Log.w(mTag, packageName + " resolves service " + mAction + ", but has wrong signature, ignoring");
                    continue;
                }
            } catch (NameNotFoundException e) {
                Log.wtf(mTag, e);
                continue;
            }
            // check metadata
            int version = Integer.MIN_VALUE;
            boolean isMultiuser = false;
            if (rInfo.serviceInfo.metaData != null) {
                version = rInfo.serviceInfo.metaData.getInt(EXTRA_SERVICE_VERSION, Integer.MIN_VALUE);
                isMultiuser = rInfo.serviceInfo.metaData.getBoolean(EXTRA_SERVICE_IS_MULTIUSER);
            }
            if (version > mVersion) {
                bestVersion = version;
                bestPackage = packageName;
                bestIsMultiuser = isMultiuser;
            }
        }
        if (D) {
            Log.d(mTag, String.format("bindBestPackage for %s : %s found %d, %s", mAction, (justCheckThisPackage == null ? "" : "(" + justCheckThisPackage + ") "), rInfos.size(), (bestPackage == null ? "no new best package" : "new best package: " + bestPackage)));
        }
    } else {
        if (D)
            Log.d(mTag, "Unable to query intent services for action: " + mAction);
    }
    if (bestPackage != null) {
        bindToPackageLocked(bestPackage, bestVersion, bestIsMultiuser);
        return true;
    }
    return false;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent)

Example 24 with NameNotFoundException

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

the class InputManagerService method visitKeyboardLayout.

private void visitKeyboardLayout(String keyboardLayoutDescriptor, KeyboardLayoutVisitor visitor) {
    KeyboardLayoutDescriptor d = KeyboardLayoutDescriptor.parse(keyboardLayoutDescriptor);
    if (d != null) {
        final PackageManager pm = mContext.getPackageManager();
        try {
            ActivityInfo receiver = pm.getReceiverInfo(new ComponentName(d.packageName, d.receiverName), PackageManager.GET_META_DATA);
            visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, visitor);
        } catch (NameNotFoundException ex) {
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ComponentName(android.content.ComponentName)

Example 25 with NameNotFoundException

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

the class UsbSettingsManager method handlePackageUpdate.

// Check to see if the package supports any USB devices or accessories.
// If so, clear any non-matching preferences for matching devices/accessories.
private void handlePackageUpdate(String packageName) {
    synchronized (mLock) {
        PackageInfo info;
        boolean changed = false;
        try {
            info = mPackageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);
        } catch (NameNotFoundException e) {
            Slog.e(TAG, "handlePackageUpdate could not find package " + packageName, e);
            return;
        }
        ActivityInfo[] activities = info.activities;
        if (activities == null)
            return;
        for (int i = 0; i < activities.length; i++) {
            // check for meta-data, both for devices and accessories
            if (handlePackageUpdateLocked(packageName, activities[i], UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
                changed = true;
            }
            if (handlePackageUpdateLocked(packageName, activities[i], UsbManager.ACTION_USB_ACCESSORY_ATTACHED)) {
                changed = true;
            }
        }
        if (changed) {
            writeSettingsLocked();
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo)

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