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;
}
}
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;
}
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) {
}
}
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");
}
}
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();
}
}
Aggregations