Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41fb0971 authored by Joel Galenson's avatar Joel Galenson
Browse files

Add function to control for which permissions to show usages.

Add a function to control whether or not to show permission usages for
each permission group.  If we do not want to show them, we do not
return the usages or show them in the UI.  We also show a special
string explaining it in AppPermissionFragment and
PermissionAppsFragment.

Note that we currently show usages for all groups, so this is
currently a no-op.

Fixes: 129536503
Test: Temporarily disable a permission's usages and inspect screens.
Change-Id: Ic3482c1cee5d6aac5802be7d761974326f121624
parent fdb6633a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -217,6 +217,9 @@ public final class PermissionUsages implements LoaderCallbacks<List<AppPermissio
                if (!group.getDeclaringPackage().equals(Utils.OS_PKG)) {
                    continue;
                }
                if (!Utils.shouldShowPermissionUsage(group.getName())) {
                    continue;
                }

                groups.add(group);

+18 −13
Original line number Diff line number Diff line
@@ -185,6 +185,10 @@ public class AppPermissionFragment extends SettingsWithLargeHeader {
                context.getString(R.string.app_permission_header, mGroup.getLabel()));

        if (Utils.isModernPermissionGroup(mGroup.getName())) {
            if (!Utils.shouldShowPermissionUsage(mGroup.getName())) {
                ((TextView) root.requireViewById(R.id.usage_summary)).setText(
                        context.getString(R.string.app_permission_footer_not_available));
            } else {
                String timeDiffStr = Utils.getRelativeLastUsageString(context,
                        PermissionUsages.loadLastGroupUsage(context, mGroup));
                if (timeDiffStr == null) {
@@ -201,6 +205,7 @@ public class AppPermissionFragment extends SettingsWithLargeHeader {
                                    mGroup.getLabel().toString().toLowerCase(),
                                    timeDiffStr));
                }
            }
        } else {
            root.requireViewById(R.id.usage_summary).setVisibility(View.GONE);
        }
+2 −1
Original line number Diff line number Diff line
@@ -230,7 +230,8 @@ public final class AppPermissionsFragment extends SettingsWithLargeHeader {
            preference.setIcon(Utils.applyTint(context, icon,
                    android.R.attr.colorControlNormal));
            preference.setTitle(group.getFullLabel());
            if (Utils.isModernPermissionGroup(group.getName())) {
            if (Utils.isModernPermissionGroup(group.getName()) && Utils.shouldShowPermissionUsage(
                    group.getName())) {
                String lastAccessStr = Utils.getAbsoluteLastUsageString(context,
                        PermissionUsages.loadLastGroupUsage(context, group));
                if (lastAccessStr != null) {
+12 −0
Original line number Diff line number Diff line
@@ -366,6 +366,15 @@ public final class PermissionAppsFragment extends SettingsWithLargeHeader implem
            denied.addPreference(empty);
        }

        if (!Utils.shouldShowPermissionUsage(mPermissionApps.getGroupName())) {
            PreferenceCategory footer = new PreferenceCategory(context);
            getPreferenceScreen().addPreference(footer);
            Preference footerText = new Preference(context);
            footerText.setSummary(context.getString(R.string.app_permission_footer_not_available));
            footerText.setIcon(R.drawable.ic_info_outline);
            footer.addPreference(footerText);
        }

        setLoading(false /* loading */, true /* animate */);

        if (mOnPermissionsLoadedListener != null) {
@@ -378,6 +387,9 @@ public final class PermissionAppsFragment extends SettingsWithLargeHeader implem
        if (!Utils.isModernPermissionGroup(group.getName())) {
            return;
        }
        if (!Utils.shouldShowPermissionUsage(group.getName())) {
            return;
        }
        String lastAccessStr = Utils.getAbsoluteLastUsageString(context,
                PermissionUsages.loadLastGroupUsage(context, group));
        if (lastAccessStr != null) {
+11 −0
Original line number Diff line number Diff line
@@ -755,6 +755,17 @@ public final class Utils {
                DeviceConfig.Privacy.PROPERTY_PERMISSIONS_HUB_ENABLED));
    }

    /**
     * Whether we should show permission usages for the specified permission group.
     *
     * @param permissionGroup The name of the permission group.
     *
     * @return whether or not to show permission usages for the given permission group.
     */
    public static boolean shouldShowPermissionUsage(@NonNull String permissionGroup) {
        return true;
    }

    /**
     * Get a device protected storage based shared preferences. Avoid storing sensitive data in it.
     *