summaryrefslogtreecommitdiffstats
path: root/src/com/android/packageinstaller/permission/utils/Utils.java
diff options
context:
space:
mode:
authorLuca Stefani <luca.stefani.ge1@gmail.com>2019-09-04 17:52:04 +0200
committerMichael Bestas <mkbestas@lineageos.org>2019-09-04 21:13:25 +0300
commitd8d0d6065d513345990ba10ff01a62654b21df32 (patch)
tree51efdb050c856d548d51682db636c4cf05e07abc /src/com/android/packageinstaller/permission/utils/Utils.java
parent24705070d6210f5dc08bc5e73f8e181215221eb9 (diff)
downloadandroid_packages_apps_PackageInstaller-d8d0d6065d513345990ba10ff01a62654b21df32.tar.gz
android_packages_apps_PackageInstaller-d8d0d6065d513345990ba10ff01a62654b21df32.tar.bz2
android_packages_apps_PackageInstaller-d8d0d6065d513345990ba10ff01a62654b21df32.zip
Revert "Remove Permissions Hub."
This reverts commit 5747740517e37ebe05209fde129cc776af4c2127. Change-Id: Ic38e77e8b11baa2dded3593089720d6592d8ddb6
Diffstat (limited to 'src/com/android/packageinstaller/permission/utils/Utils.java')
-rw-r--r--src/com/android/packageinstaller/permission/utils/Utils.java72
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