Search in sources :

Example 6 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ParanoidAndroid.

the class Pm method getResources.

private Resources getResources(PackageItemInfo pii) {
    Resources res = mResourceCache.get(pii.packageName);
    if (res != null)
        return res;
    try {
        ApplicationInfo ai = mPm.getApplicationInfo(pii.packageName, 0, 0);
        AssetManager am = new AssetManager();
        am.addAssetPath(ai.publicSourceDir);
        res = new Resources(am, null, null);
        mResourceCache.put(pii.packageName, res);
        return res;
    } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
        return null;
    }
}
Also used : AssetManager(android.content.res.AssetManager) ApplicationInfo(android.content.pm.ApplicationInfo) Resources(android.content.res.Resources) RemoteException(android.os.RemoteException)

Example 7 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ParanoidAndroid.

the class DeviceAdminInfo method loadDescription.

/**
     * Load user-visible description associated with this device admin.
     *
     * @param pm Supply a PackageManager used to load the device admin's
     * resources.
     */
public CharSequence loadDescription(PackageManager pm) throws NotFoundException {
    if (mReceiver.activityInfo.descriptionRes != 0) {
        String packageName = mReceiver.resolvePackageName;
        ApplicationInfo applicationInfo = null;
        if (packageName == null) {
            packageName = mReceiver.activityInfo.packageName;
            applicationInfo = mReceiver.activityInfo.applicationInfo;
        }
        return pm.getText(packageName, mReceiver.activityInfo.descriptionRes, applicationInfo);
    }
    throw new NotFoundException();
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 8 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ParanoidAndroid.

the class BackupAgent method fullBackupFile.

/**
     * Write an entire file as part of a full-backup operation.  The file's contents
     * will be delivered to the backup destination along with the metadata necessary
     * to place it with the proper location and permissions on the device where the
     * data is restored.
     *
     * @param file The file to be backed up.  The file must exist and be readable by
     *     the caller.
     * @param output The destination to which the backed-up file data will be sent.
     */
public final void fullBackupFile(File file, FullBackupDataOutput output) {
    // Look up where all of our various well-defined dir trees live on this device
    String mainDir;
    String filesDir;
    String dbDir;
    String spDir;
    String cacheDir;
    String libDir;
    String efDir = null;
    String filePath;
    ApplicationInfo appInfo = getApplicationInfo();
    try {
        mainDir = new File(appInfo.dataDir).getCanonicalPath();
        filesDir = getFilesDir().getCanonicalPath();
        dbDir = getDatabasePath("foo").getParentFile().getCanonicalPath();
        spDir = getSharedPrefsFile("foo").getParentFile().getCanonicalPath();
        cacheDir = getCacheDir().getCanonicalPath();
        libDir = (appInfo.nativeLibraryDir == null) ? null : new File(appInfo.nativeLibraryDir).getCanonicalPath();
        // may or may not have external files access to attempt backup/restore there
        if (Process.myUid() != Process.SYSTEM_UID) {
            File efLocation = getExternalFilesDir(null);
            if (efLocation != null) {
                efDir = efLocation.getCanonicalPath();
            }
        }
        // Now figure out which well-defined tree the file is placed in, working from
        // most to least specific.  We also specifically exclude the lib and cache dirs.
        filePath = file.getCanonicalPath();
    } catch (IOException e) {
        Log.w(TAG, "Unable to obtain canonical paths");
        return;
    }
    if (filePath.startsWith(cacheDir) || filePath.startsWith(libDir)) {
        Log.w(TAG, "lib and cache files are not backed up");
        return;
    }
    final String domain;
    String rootpath = null;
    if (filePath.startsWith(dbDir)) {
        domain = FullBackup.DATABASE_TREE_TOKEN;
        rootpath = dbDir;
    } else if (filePath.startsWith(spDir)) {
        domain = FullBackup.SHAREDPREFS_TREE_TOKEN;
        rootpath = spDir;
    } else if (filePath.startsWith(filesDir)) {
        domain = FullBackup.DATA_TREE_TOKEN;
        rootpath = filesDir;
    } else if (filePath.startsWith(mainDir)) {
        domain = FullBackup.ROOT_TREE_TOKEN;
        rootpath = mainDir;
    } else if ((efDir != null) && filePath.startsWith(efDir)) {
        domain = FullBackup.MANAGED_EXTERNAL_TREE_TOKEN;
        rootpath = efDir;
    } else {
        Log.w(TAG, "File " + filePath + " is in an unsupported location; skipping");
        return;
    }
    // And now that we know where it lives, semantically, back it up appropriately
    Log.i(TAG, "backupFile() of " + filePath + " => domain=" + domain + " rootpath=" + rootpath);
    FullBackup.backupToTar(getPackageName(), domain, null, rootpath, filePath, output.getData());
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) IOException(java.io.IOException) File(java.io.File)

Example 9 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ParanoidAndroid.

the class WallpaperInfo method loadAuthor.

/**
     * Return a string indicating the author(s) of this wallpaper.
     */
public CharSequence loadAuthor(PackageManager pm) throws NotFoundException {
    if (mAuthorResource <= 0)
        throw new NotFoundException();
    String packageName = mService.resolvePackageName;
    ApplicationInfo applicationInfo = null;
    if (packageName == null) {
        packageName = mService.serviceInfo.packageName;
        applicationInfo = mService.serviceInfo.applicationInfo;
    }
    return pm.getText(packageName, mAuthorResource, applicationInfo);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 10 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ParanoidAndroid.

the class BatteryStats method dumpCheckinLocked.

@SuppressWarnings("unused")
public void dumpCheckinLocked(PrintWriter pw, String[] args, List<ApplicationInfo> apps) {
    prepareForDumpLocked();
    boolean isUnpluggedOnly = false;
    for (String arg : args) {
        if ("-u".equals(arg)) {
            if (LOCAL_LOGV)
                Log.v("BatteryStats", "Dumping unplugged data");
            isUnpluggedOnly = true;
        }
    }
    if (apps != null) {
        SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
        for (int i = 0; i < apps.size(); i++) {
            ApplicationInfo ai = apps.get(i);
            ArrayList<String> pkgs = uids.get(ai.uid);
            if (pkgs == null) {
                pkgs = new ArrayList<String>();
                uids.put(ai.uid, pkgs);
            }
            pkgs.add(ai.packageName);
        }
        SparseArray<? extends Uid> uidStats = getUidStats();
        final int NU = uidStats.size();
        String[] lineArgs = new String[2];
        for (int i = 0; i < NU; i++) {
            int uid = uidStats.keyAt(i);
            ArrayList<String> pkgs = uids.get(uid);
            if (pkgs != null) {
                for (int j = 0; j < pkgs.size(); j++) {
                    lineArgs[0] = Integer.toString(uid);
                    lineArgs[1] = pkgs.get(j);
                    dumpLine(pw, 0, /* uid */
                    "i", /* category */
                    UID_DATA, (Object[]) lineArgs);
                }
            }
        }
    }
    if (isUnpluggedOnly) {
        dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
    } else {
        dumpCheckinLocked(pw, STATS_SINCE_CHARGED, -1);
        dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
    }
}
Also used : SparseArray(android.util.SparseArray) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)908 PackageManager (android.content.pm.PackageManager)339 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)272 RemoteException (android.os.RemoteException)204 Intent (android.content.Intent)100 ArrayList (java.util.ArrayList)98 IPackageManager (android.content.pm.IPackageManager)96 IOException (java.io.IOException)80 PackageInfo (android.content.pm.PackageInfo)78 ResolveInfo (android.content.pm.ResolveInfo)72 File (java.io.File)64 ComponentName (android.content.ComponentName)52 Bundle (android.os.Bundle)48 Context (android.content.Context)47 PendingIntent (android.app.PendingIntent)43 Drawable (android.graphics.drawable.Drawable)43 UserInfo (android.content.pm.UserInfo)40 ActivityInfo (android.content.pm.ActivityInfo)35 ServiceInfo (android.content.pm.ServiceInfo)35 Resources (android.content.res.Resources)32