Skip to content

Commit

Permalink
[AppInfo] Hide “Data usage” for apps without the internet permission
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <muntashirakon@riseup.net>
  • Loading branch information
MuntashirAkon committed Jul 8, 2024
1 parent 416ee4c commit 0903261
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ private List<ActionItem> getHorizontalActions() {
Intent fdroid_intent = new Intent(Intent.ACTION_VIEW);
fdroid_intent.setData(Uri.parse("https://f-droid.org/packages/" + mPackageName));
List<ResolveInfo> resolvedActivities = mPackageManager.queryIntentActivities(fdroid_intent, 0);
if (resolvedActivities.size() > 0) {
if (!resolvedActivities.isEmpty()) {
ActionItem fdroidItem = new ActionItem(R.string.fdroid, R.drawable.ic_frost_fdroid);
actionItems.add(fdroidItem);
fdroidItem.setOnClickListener(v -> {
Expand Down Expand Up @@ -1751,7 +1751,10 @@ private String getHiddenApiEnforcementPolicy(int policy) {

private void setDataUsage(@NonNull AppInfoViewModel.AppInfo appInfo) {
AppUsageStatsManager.DataUsage dataUsage = appInfo.dataUsage;
if (dataUsage == null) return;
if (dataUsage == null) {
// No permission
return;
}
// Hide data usage if:
// 1. OS is Android 6.0 onwards, AND
// 2. The user is not the current user, AND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package io.github.muntashirakon.AppManager.details.info;

import android.Manifest;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.Application;
Expand Down Expand Up @@ -69,6 +70,7 @@
import io.github.muntashirakon.AppManager.uri.UriManager;
import io.github.muntashirakon.AppManager.usage.AppUsageStatsManager;
import io.github.muntashirakon.AppManager.usage.UsageUtils;
import io.github.muntashirakon.AppManager.utils.ArrayUtils;
import io.github.muntashirakon.AppManager.utils.ExUtils;
import io.github.muntashirakon.AppManager.utils.KeyStoreUtils;
import io.github.muntashirakon.AppManager.utils.PackageUtils;
Expand Down Expand Up @@ -354,8 +356,10 @@ private void loadAppInfoInternal(@NonNull PackageInfo packageInfo, boolean isExt
boolean hasUsageAccess = FeatureController.isUsageAccessEnabled() && SelfPermissions.checkUsageStatsPermission();
if (hasUsageAccess) {
// Net statistics
appInfo.dataUsage = AppUsageStatsManager.getDataUsageForPackage(getApplication(),
applicationInfo.uid, UsageUtils.USAGE_LAST_BOOT);
if (ArrayUtils.contains(packageInfo.requestedPermissions, Manifest.permission.INTERNET)) {
appInfo.dataUsage = AppUsageStatsManager.getDataUsageForPackage(getApplication(),
applicationInfo.uid, UsageUtils.USAGE_LAST_BOOT);
} else appInfo.dataUsage = null;
// Set sizes
appInfo.sizeInfo = PackageUtils.getPackageSizeInfo(getApplication(), packageName, userId,
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? applicationInfo.storageUuid : null);
Expand All @@ -367,7 +371,6 @@ private void loadAppInfoInternal(@NonNull PackageInfo packageInfo, boolean isExt
try {
applicationLabel = pm.getApplicationInfo(installerPackageName, 0).loadLabel(pm).toString();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
applicationLabel = installerPackageName;
}
appInfo.installerApp = applicationLabel;
Expand Down

0 comments on commit 0903261

Please sign in to comment.