Search in sources :

Example 16 with NameNotFoundException

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

the class BackupManagerService method clearApplicationDataSynchronous.

// clear an application's data, blocking until the operation completes or times out
void clearApplicationDataSynchronous(String packageName) {
    // Don't wipe packages marked allowClearUserData=false
    try {
        PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
        if ((info.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) == 0) {
            if (MORE_DEBUG)
                Slog.i(TAG, "allowClearUserData=false so not wiping " + packageName);
            return;
        }
    } catch (NameNotFoundException e) {
        Slog.w(TAG, "Tried to clear data for " + packageName + " but not found");
        return;
    }
    ClearDataObserver observer = new ClearDataObserver();
    synchronized (mClearDataLock) {
        mClearingData = true;
        try {
            mActivityManager.clearApplicationUserData(packageName, observer, 0);
        } catch (RemoteException e) {
        // can't happen because the activity manager is in this process
        }
        // only wait 10 seconds for the clear data to happen
        long timeoutMark = System.currentTimeMillis() + TIMEOUT_INTERVAL;
        while (mClearingData && (System.currentTimeMillis() < timeoutMark)) {
            try {
                mClearDataLock.wait(5000);
            } catch (InterruptedException e) {
                // won't happen, but still.
                mClearingData = false;
            }
        }
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException)

Example 17 with NameNotFoundException

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

the class BackupManagerService method initPackageTracking.

private void initPackageTracking() {
    if (DEBUG)
        Slog.v(TAG, "Initializing package tracking");
    // Remember our ancestral dataset
    mTokenFile = new File(mBaseStateDir, "ancestral");
    try {
        RandomAccessFile tf = new RandomAccessFile(mTokenFile, "r");
        int version = tf.readInt();
        if (version == CURRENT_ANCESTRAL_RECORD_VERSION) {
            mAncestralToken = tf.readLong();
            mCurrentToken = tf.readLong();
            int numPackages = tf.readInt();
            if (numPackages >= 0) {
                mAncestralPackages = new HashSet<String>();
                for (int i = 0; i < numPackages; i++) {
                    String pkgName = tf.readUTF();
                    mAncestralPackages.add(pkgName);
                }
            }
        }
        tf.close();
    } catch (FileNotFoundException fnf) {
        // Probably innocuous
        Slog.v(TAG, "No ancestral data");
    } catch (IOException e) {
        Slog.w(TAG, "Unable to read token file", e);
    }
    // Keep a log of what apps we've ever backed up.  Because we might have
    // rebooted in the middle of an operation that was removing something from
    // this log, we sanity-check its contents here and reconstruct it.
    mEverStored = new File(mBaseStateDir, "processed");
    File tempProcessedFile = new File(mBaseStateDir, "processed.new");
    // Ignore it -- we'll validate "processed" against the current package set.
    if (tempProcessedFile.exists()) {
        tempProcessedFile.delete();
    }
    // file to continue the recordkeeping.
    if (mEverStored.exists()) {
        RandomAccessFile temp = null;
        RandomAccessFile in = null;
        try {
            temp = new RandomAccessFile(tempProcessedFile, "rws");
            in = new RandomAccessFile(mEverStored, "r");
            while (true) {
                PackageInfo info;
                String pkg = in.readUTF();
                try {
                    info = mPackageManager.getPackageInfo(pkg, 0);
                    mEverStoredApps.add(pkg);
                    temp.writeUTF(pkg);
                    if (MORE_DEBUG)
                        Slog.v(TAG, "   + " + pkg);
                } catch (NameNotFoundException e) {
                    // nope, this package was uninstalled; don't include it
                    if (MORE_DEBUG)
                        Slog.v(TAG, "   - " + pkg);
                }
            }
        } catch (EOFException e) {
            // old one with the new one then reopen the file for continuing use.
            if (!tempProcessedFile.renameTo(mEverStored)) {
                Slog.e(TAG, "Error renaming " + tempProcessedFile + " to " + mEverStored);
            }
        } catch (IOException e) {
            Slog.e(TAG, "Error in processed file", e);
        } finally {
            try {
                if (temp != null)
                    temp.close();
            } catch (IOException e) {
            }
            try {
                if (in != null)
                    in.close();
            } catch (IOException e) {
            }
        }
    }
    // Register for broadcasts about package install, etc., so we can
    // update the provider list.
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addDataScheme("package");
    mContext.registerReceiver(mBroadcastReceiver, filter);
    // Register for events related to sdcard installation.
    IntentFilter sdFilter = new IntentFilter();
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
    sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
    mContext.registerReceiver(mBroadcastReceiver, sdFilter);
}
Also used : IntentFilter(android.content.IntentFilter) RandomAccessFile(java.io.RandomAccessFile) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) FileNotFoundException(java.io.FileNotFoundException) EOFException(java.io.EOFException) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 18 with NameNotFoundException

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

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)

Example 19 with NameNotFoundException

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

the class BackupManagerService method clearBackupData.

// Clear the given package's backup data from the current transport
public void clearBackupData(String packageName) {
    if (DEBUG)
        Slog.v(TAG, "clearBackupData() of " + packageName);
    PackageInfo info;
    try {
        info = mPackageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
    } catch (NameNotFoundException e) {
        Slog.d(TAG, "No such package '" + packageName + "' - not clearing backup data");
        return;
    }
    // If the caller does not hold the BACKUP permission, it can only request a
    // wipe of its own backed-up data.
    HashSet<String> apps;
    if ((mContext.checkPermission(android.Manifest.permission.BACKUP, Binder.getCallingPid(), Binder.getCallingUid())) == PackageManager.PERMISSION_DENIED) {
        apps = mBackupParticipants.get(Binder.getCallingUid());
    } else {
        // !!! TODO: allow data-clear of ANY app?
        if (DEBUG)
            Slog.v(TAG, "Privileged caller, allowing clear of other apps");
        apps = new HashSet<String>();
        int N = mBackupParticipants.size();
        for (int i = 0; i < N; i++) {
            HashSet<String> s = mBackupParticipants.valueAt(i);
            if (s != null) {
                apps.addAll(s);
            }
        }
    }
    // Is the given app an available participant?
    if (apps.contains(packageName)) {
        if (DEBUG)
            Slog.v(TAG, "Found the app - running clear process");
        // found it; fire off the clear request
        synchronized (mQueueLock) {
            long oldId = Binder.clearCallingIdentity();
            mWakelock.acquire();
            Message msg = mBackupHandler.obtainMessage(MSG_RUN_CLEAR, new ClearParams(getTransport(mCurrentTransport), info));
            mBackupHandler.sendMessage(msg);
            Binder.restoreCallingIdentity(oldId);
        }
    }
}
Also used : Message(android.os.Message) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo)

Example 20 with NameNotFoundException

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

the class NotificationManagerService method idDebugString.

private static String idDebugString(Context baseContext, String packageName, int id) {
    Context c = null;
    if (packageName != null) {
        try {
            c = baseContext.createPackageContext(packageName, 0);
        } catch (NameNotFoundException e) {
            c = baseContext;
        }
    } else {
        c = baseContext;
    }
    String pkg;
    String type;
    String name;
    Resources r = c.getResources();
    try {
        return r.getResourceName(id);
    } catch (Resources.NotFoundException e) {
        return "<name unknown>";
    }
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Resources(android.content.res.Resources)

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