Search in sources :

Example 51 with VisibleForTesting

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);
        }
    }
}
Also used : SliceManager(android.app.slice.SliceManager) Uri(android.net.Uri) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 52 with VisibleForTesting

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;
}
Also used : Bitmap(android.graphics.Bitmap) UserManager(android.os.UserManager) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 53 with VisibleForTesting

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);
}
Also used : AppOpsManager(android.app.AppOpsManager) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 54 with VisibleForTesting

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;
        }
    }
}
Also used : ApplicationsState(com.android.settingslib.applications.ApplicationsState) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) UsageStats(android.app.usage.UsageStats) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 55 with VisibleForTesting

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);
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

VisibleForTesting (androidx.annotation.VisibleForTesting)385 Intent (android.content.Intent)36 ArrayList (java.util.ArrayList)36 Context (android.content.Context)34 Bundle (android.os.Bundle)30 Uri (android.net.Uri)18 View (android.view.View)18 Preference (androidx.preference.Preference)18 TextView (android.widget.TextView)16 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)16 MetricsFeatureProvider (com.android.settingslib.core.instrumentation.MetricsFeatureProvider)16 SuppressLint (android.annotation.SuppressLint)15 Activity (android.app.Activity)14 RemoteException (android.os.RemoteException)14 SubscriptionInfo (android.telephony.SubscriptionInfo)12 ImageView (android.widget.ImageView)12 BluetoothDevice (android.bluetooth.BluetoothDevice)11 ComponentName (android.content.ComponentName)11 Drawable (android.graphics.drawable.Drawable)11 SharedPreferences (android.content.SharedPreferences)10