Search in sources :

Example 21 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class StorageMeasurement method measureExactStorage.

private void measureExactStorage(IMediaContainerService imcs) {
    final UserManager userManager = mContext.getSystemService(UserManager.class);
    final PackageManager packageManager = mContext.getPackageManager();
    final List<UserInfo> users = userManager.getUsers();
    final List<UserInfo> currentProfiles = userManager.getEnabledProfiles(ActivityManager.getCurrentUser());
    final MeasurementDetails details = new MeasurementDetails();
    final Message finished = mMeasurementHandler.obtainMessage(MeasurementHandler.MSG_COMPLETED, details);
    if (mVolume == null || !mVolume.isMountedReadable()) {
        finished.sendToTarget();
        return;
    }
    if (mSharedVolume != null && mSharedVolume.isMountedReadable()) {
        for (UserInfo currentUserInfo : currentProfiles) {
            final int userId = currentUserInfo.id;
            final File basePath = mSharedVolume.getPathForUser(userId);
            HashMap<String, Long> mediaMap = new HashMap<>(sMeasureMediaTypes.size());
            details.mediaSize.put(userId, mediaMap);
            // external volume
            for (String type : sMeasureMediaTypes) {
                final File path = new File(basePath, type);
                final long size = getDirectorySize(imcs, path);
                mediaMap.put(type, size);
            }
            // Measure misc files not counted under media
            addValue(details.miscSize, userId, measureMisc(imcs, basePath));
        }
        if (mSharedVolume.getType() == VolumeInfo.TYPE_EMULATED) {
            // will be spliced in later
            for (UserInfo user : users) {
                final File userPath = mSharedVolume.getPathForUser(user.id);
                final long size = getDirectorySize(imcs, userPath);
                addValue(details.usersSize, user.id, size);
            }
        }
    }
    final File file = mVolume.getPath();
    if (file != null) {
        details.totalSize = file.getTotalSpace();
        details.availSize = file.getFreeSpace();
    }
    // Measure all apps hosted on this volume for all users
    if (mVolume.getType() == VolumeInfo.TYPE_PRIVATE) {
        final List<ApplicationInfo> apps = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
        final List<ApplicationInfo> volumeApps = new ArrayList<>();
        for (ApplicationInfo app : apps) {
            if (Objects.equals(app.volumeUuid, mVolume.getFsUuid())) {
                volumeApps.add(app);
            }
        }
        final int count = users.size() * volumeApps.size();
        if (count == 0) {
            finished.sendToTarget();
            return;
        }
        final StatsObserver observer = new StatsObserver(true, details, ActivityManager.getCurrentUser(), currentProfiles, finished, count);
        for (UserInfo user : users) {
            for (ApplicationInfo app : volumeApps) {
                packageManager.getPackageSizeInfoAsUser(app.packageName, user.id, observer);
            }
        }
    } else {
        finished.sendToTarget();
        return;
    }
}
Also used : Message(android.os.Message) HashMap(java.util.HashMap) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) PackageManager(android.content.pm.PackageManager) UserManager(android.os.UserManager) File(java.io.File) IPackageStatsObserver(android.content.pm.IPackageStatsObserver)

Example 22 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class DeviceInfoUtils method getFeedbackReporterPackage.

public static String getFeedbackReporterPackage(Context context) {
    final String feedbackReporter = context.getResources().getString(R.string.oem_preferred_feedback_reporter);
    if (TextUtils.isEmpty(feedbackReporter)) {
        // Reporter not configured. Return.
        return feedbackReporter;
    }
    // Additional checks to ensure the reporter is on system image, and reporter is
    // configured to listen to the intent. Otherwise, dont show the "send feedback" option.
    final Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resolvedPackages = pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
    for (ResolveInfo info : resolvedPackages) {
        if (info.activityInfo != null) {
            if (!TextUtils.isEmpty(info.activityInfo.packageName)) {
                try {
                    ApplicationInfo ai = pm.getApplicationInfo(info.activityInfo.packageName, 0);
                    if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                        // Package is on the system image
                        if (TextUtils.equals(info.activityInfo.packageName, feedbackReporter)) {
                            return feedbackReporter;
                        }
                    }
                } catch (PackageManager.NameNotFoundException e) {
                // No need to do anything here.
                }
            }
        }
    }
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent)

Example 23 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class ApplicationsState method addPackage.

void addPackage(String pkgName, int userId) {
    try {
        synchronized (mEntriesMap) {
            if (DEBUG_LOCKING)
                Log.v(TAG, "addPackage acquired lock");
            if (DEBUG)
                Log.i(TAG, "Adding package " + pkgName);
            if (!mResumed) {
                // here.
                if (DEBUG_LOCKING)
                    Log.v(TAG, "addPackage release lock: not resumed");
                return;
            }
            if (indexOfApplicationInfoLocked(pkgName, userId) >= 0) {
                if (DEBUG)
                    Log.i(TAG, "Package already exists!");
                if (DEBUG_LOCKING)
                    Log.v(TAG, "addPackage release lock: already exists");
                return;
            }
            ApplicationInfo info = mIpm.getApplicationInfo(pkgName, mUm.isUserAdmin(userId) ? mAdminRetrieveFlags : mRetrieveFlags, userId);
            if (info == null) {
                return;
            }
            if (!info.enabled) {
                if (info.enabledSetting != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
                    return;
                }
                mHaveDisabledApps = true;
            }
            mApplications.add(info);
            if (!mBackgroundHandler.hasMessages(BackgroundHandler.MSG_LOAD_ENTRIES)) {
                mBackgroundHandler.sendEmptyMessage(BackgroundHandler.MSG_LOAD_ENTRIES);
            }
            if (!mMainHandler.hasMessages(MainHandler.MSG_PACKAGE_LIST_CHANGED)) {
                mMainHandler.sendEmptyMessage(MainHandler.MSG_PACKAGE_LIST_CHANGED);
            }
            if (DEBUG_LOCKING)
                Log.v(TAG, "addPackage releasing lock");
        }
    } catch (RemoteException e) {
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 24 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

the class ApplicationsState method removePackage.

public void removePackage(String pkgName, int userId) {
    synchronized (mEntriesMap) {
        if (DEBUG_LOCKING)
            Log.v(TAG, "removePackage acquired lock");
        int idx = indexOfApplicationInfoLocked(pkgName, userId);
        if (DEBUG)
            Log.i(TAG, "removePackage: " + pkgName + " @ " + idx);
        if (idx >= 0) {
            AppEntry entry = mEntriesMap.get(userId).get(pkgName);
            if (DEBUG)
                Log.i(TAG, "removePackage: " + entry);
            if (entry != null) {
                mEntriesMap.get(userId).remove(pkgName);
                mAppEntries.remove(entry);
            }
            ApplicationInfo info = mApplications.get(idx);
            mApplications.remove(idx);
            if (!info.enabled) {
                mHaveDisabledApps = false;
                for (int i = 0; i < mApplications.size(); i++) {
                    if (!mApplications.get(i).enabled) {
                        mHaveDisabledApps = true;
                        break;
                    }
                }
            }
            if (!mMainHandler.hasMessages(MainHandler.MSG_PACKAGE_LIST_CHANGED)) {
                mMainHandler.sendEmptyMessage(MainHandler.MSG_PACKAGE_LIST_CHANGED);
            }
        }
        if (DEBUG_LOCKING)
            Log.v(TAG, "removePackage releasing lock");
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo)

Example 25 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project platform_frameworks_base by android.

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)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)921 PackageManager (android.content.pm.PackageManager)345 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)274 RemoteException (android.os.RemoteException)204 Intent (android.content.Intent)103 ArrayList (java.util.ArrayList)98 IPackageManager (android.content.pm.IPackageManager)96 IOException (java.io.IOException)80 PackageInfo (android.content.pm.PackageInfo)79 ResolveInfo (android.content.pm.ResolveInfo)72 File (java.io.File)64 ComponentName (android.content.ComponentName)52 Context (android.content.Context)51 Bundle (android.os.Bundle)50 PendingIntent (android.app.PendingIntent)45 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)33