use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingsSliceProvider method grantWhitelistedPackagePermissions.
@VisibleForTesting
static void grantWhitelistedPackagePermissions(Context context, List<Uri> descendants) {
if (descendants == null) {
Log.d(TAG, "No descendants to grant permission with, skipping.");
}
final String[] whitelistPackages = context.getResources().getStringArray(R.array.slice_whitelist_package_names);
if (whitelistPackages == null || whitelistPackages.length == 0) {
Log.d(TAG, "No packages to whitelist, skipping.");
return;
} else {
Log.d(TAG, String.format("Whitelisting %d uris to %d pkgs.", descendants.size(), whitelistPackages.length));
}
final SliceManager sliceManager = context.getSystemService(SliceManager.class);
for (Uri descendant : descendants) {
for (String toPackage : whitelistPackages) {
sliceManager.grantSlicePermission(toPackage, descendant);
}
}
}
use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class UserSettings method assignDefaultPhoto.
/**
* Assign the default photo to user with {@paramref userId}
*
* @param context used to get the {@link UserManager}
* @param userId used to get the icon bitmap
* @return true if assign photo successfully, false if failed
*/
@VisibleForTesting
static boolean assignDefaultPhoto(Context context, int userId) {
if (context == null) {
return false;
}
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
Bitmap bitmap = getDefaultUserIconAsBitmap(context.getResources(), userId);
um.setUserIcon(userId, bitmap);
return true;
}
use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppManagementFragment method appHasVpnPermission.
@VisibleForTesting
static boolean appHasVpnPermission(Context context, @NonNull ApplicationInfo application) {
final AppOpsManager service = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
final List<AppOpsManager.PackageOps> ops = service.getOpsForPackage(application.uid, application.packageName, new int[] { OP_ACTIVATE_VPN });
return !ArrayUtils.isEmpty(ops);
}
use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentAppStatsMixin method loadDisplayableRecentApps.
@VisibleForTesting
void loadDisplayableRecentApps(int number) {
mRecentApps.clear();
mCalendar = Calendar.getInstance();
mCalendar.add(Calendar.DAY_OF_YEAR, -1);
final List<UsageStats> mStats = mPowerManager.isPowerSaveMode() ? new ArrayList<>() : mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, mCalendar.getTimeInMillis(), System.currentTimeMillis());
final Map<String, UsageStats> map = new ArrayMap<>();
final int statCount = mStats.size();
for (int i = 0; i < statCount; i++) {
final UsageStats pkgStats = mStats.get(i);
if (!shouldIncludePkgInRecents(pkgStats)) {
continue;
}
final String pkgName = pkgStats.getPackageName();
final UsageStats existingStats = map.get(pkgName);
if (existingStats == null) {
map.put(pkgName, pkgStats);
} else {
existingStats.add(pkgStats);
}
}
final List<UsageStats> packageStats = new ArrayList<>();
packageStats.addAll(map.values());
Collections.sort(packageStats, this);
int count = 0;
for (UsageStats stat : packageStats) {
final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(stat.getPackageName(), mUserId);
if (appEntry == null) {
continue;
}
mRecentApps.add(stat);
count++;
if (count >= number) {
break;
}
}
}
use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppPermissionsPreferenceController method queryPermissionSummary.
@VisibleForTesting
void queryPermissionSummary() {
final List<PackageInfo> installedPackages = mPackageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
// Here we only get the first three apps and check their permissions.
final List<PackageInfo> packagesWithPermission = installedPackages.stream().filter(pInfo -> pInfo.permissions != null).limit(NUM_PACKAGE_TO_CHECK).collect(Collectors.toList());
for (PackageInfo installedPackage : packagesWithPermission) {
PermissionsSummaryHelper.getPermissionSummary(mContext, installedPackage.packageName, mPermissionsCallback);
}
}
Aggregations