diff options
Diffstat (limited to 'src/com/android/packageinstaller/permission/utils/Utils.java')
-rw-r--r-- | src/com/android/packageinstaller/permission/utils/Utils.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/com/android/packageinstaller/permission/utils/Utils.java b/src/com/android/packageinstaller/permission/utils/Utils.java index 707b9f7b..867d603c 100644 --- a/src/com/android/packageinstaller/permission/utils/Utils.java +++ b/src/com/android/packageinstaller/permission/utils/Utils.java @@ -84,6 +84,7 @@ import com.android.launcher3.icons.IconFactory; import com.android.packageinstaller.Constants; import com.android.packageinstaller.permission.data.PerUserUidToSensitivityLiveData; import com.android.packageinstaller.permission.model.AppPermissionGroup; +import com.android.packageinstaller.permission.model.AppPermissionUsage; import com.android.permissioncontroller.R; import java.util.ArrayList; @@ -101,6 +102,9 @@ public final class Utils { public static final float DEFAULT_MAX_LABEL_SIZE_PX = 500f; + /** Whether to show the Permissions Hub. */ + private static final String PROPERTY_PERMISSIONS_HUB_ENABLED = "permissions_hub_enabled"; + /** Whether to show location access check notifications. */ private static final String PROPERTY_LOCATION_ACCESS_CHECK_ENABLED = "location_access_check_enabled"; @@ -566,6 +570,39 @@ public final class Utils { } /** + * Build a string representing the amount of time passed since the most recent permission usage. + * + * @return a string representing the amount of time since this app's most recent permission + * usage or null if there are no usages. + */ + public static @Nullable String getRelativeLastUsageString(@NonNull Context context, + @Nullable AppPermissionUsage.GroupUsage groupUsage) { + if (groupUsage == null || groupUsage.getLastAccessTime() == 0) { + return null; + } + return getTimeDiffStr(context, System.currentTimeMillis() + - groupUsage.getLastAccessTime()); + } + + /** + * Build a string representing the time of the most recent permission usage if it happened on + * the current day and the date otherwise. + * + * @param context the context. + * @param groupUsage the permission usage. + * + * @return a string representing the time or date of the most recent usage or null if there are + * no usages. + */ + public static @Nullable String getAbsoluteLastUsageString(@NonNull Context context, + @Nullable AppPermissionUsage.GroupUsage groupUsage) { + if (groupUsage == null) { + return null; + } + return getAbsoluteTimeString(context, groupUsage.getLastAccessTime()); + } + + /** * Build a string representing the given time if it happened on the current day and the date * otherwise. * @@ -587,6 +624,20 @@ public final class Utils { } /** + * Build a string representing the duration of a permission usage. + * + * @return a string representing the duration of this app's usage or null if there are no + * usages. + */ + public static @Nullable String getUsageDurationString(@NonNull Context context, + @Nullable AppPermissionUsage.GroupUsage groupUsage) { + if (groupUsage == null) { + return null; + } + return getTimeDiffStr(context, groupUsage.getAccessDuration()); + } + + /** * Build a string representing the number of milliseconds passed in. It rounds to the nearest * unit. For example, given a duration of 3500 and an English locale, this can return * "3 seconds". @@ -727,6 +778,27 @@ public final class Utils { } /** + * Whether the Permissions Hub is enabled. + * + * @return whether the Permissions Hub is enabled. + */ + public static boolean isPermissionsHubEnabled() { + return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, + PROPERTY_PERMISSIONS_HUB_ENABLED, false); + } + + /** + * 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 !permissionGroup.equals(STORAGE); + } + + /** * Get a device protected storage based shared preferences. Avoid storing sensitive data in it. * * @param context the context to get the shared preferences |