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

Commit 035cf6bd authored by Joel Galenson's avatar Joel Galenson
Browse files

Update Permissions Hub to the newest design.

- Remove the bar chart.
- Add a menu option to control whether we sort by most recently used
  apps or by time.
- Change the default sort option to be by most recently used apps.
- Show permission names instead of icons in the parent summaries and
  ellipsize them on overflow.
- Change sort by app to sort by apps with recent usages instead of
  apps with the most permissions accessed.
- Modify the access string to show whether the access was in the
  foreground or the background.
- Show a gear icon on the right of the access preferences.
- Fix a bug where usage entries were not vertically centered.

Bug: 128521173
Test: View screen.
Change-Id: I3e9423884d56bb35cfbb040c7aa208afb998da73
parent c4b7e139
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ LOCAL_STATIC_ANDROID_LIBRARIES += \
    SettingsLibSearchWidget \
    SettingsLibSettingsSpinner \
    SettingsLibLayoutPreference \
    SettingsLibBarChartPreference \
    SettingsLibActionBarShadow \
    SettingsLibProgressBar

+9 −9
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="14dp"
    android:paddingBottom="14dp"
    android:paddingTop="12dp"
    android:paddingBottom="12dp"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:gravity="center_vertical"
    android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
@@ -57,8 +57,7 @@
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceListItem"
        android:ellipsize="marquee"
        app:layout_constraintStart_toEndOf="@+id/title_widget_frame"
        app:layout_constraintTop_toTopOf="@+id/image_frame_include"/>
        app:layout_constraintStart_toEndOf="@+id/title_widget_frame"/>

    <LinearLayout
        android:id="@+id/summary_widget_frame"
@@ -71,24 +70,25 @@

    <TextView
        android:id="@android:id/summary"
        android:layout_width="wrap_content"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="?android:attr/textColorSecondary"
        android:maxLines="10"
        app:layout_constraintStart_toEndOf="@+id/summary_widget_frame"
        app:layout_constraintTop_toBottomOf="@android:id/title"/>
        app:layout_constraintTop_toBottomOf="@android:id/title"
        app:layout_constraintEnd_toStartOf="@android:id/widget_frame"/>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout
        android:id="@android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_height="wrap_content"
        android:gravity="end|center_vertical"
        android:paddingStart="16dp"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/image_frame_include"
        app:layout_constraintBottom_toBottomOf="@+id/image_frame_include"/>
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
+20 −26
Original line number Diff line number Diff line
@@ -262,8 +262,11 @@
    <!-- Title for permission usage [CHAR LIMIT=30] -->
    <string name="permission_usage_title">Dashboard</string>

    <!-- Summary for showing a single permission access and the time of the last access [CHAR LIMIT=80] -->
    <string name="permission_usage_summary">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g></string>
    <!-- Summary for showing a single permission access and the time of the last access when it was in the foreground [CHAR LIMIT=80] -->
    <string name="permission_usage_summary_foreground">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g> &lt;font color="#0f9d58"&gt;(while the app was in use)&lt;/font&gt;</string>

    <!-- Summary for showing a single permission access and the time of the last access when it was in the background [CHAR LIMIT=80] -->
    <string name="permission_usage_summary_background">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g> (in the background)</string>

    <!-- Description for showing permission accesses with any permission [CHAR LIMIT=30] -->
    <string name="permission_usage_any_permission">Any permission</string>
@@ -290,40 +293,22 @@
    <string name="no_permission_usages">No permission usages</string>

    <!-- Label for the title of the list of permission usages that shows which apps used which permissions[CHAR LIMIT=50] -->
    <string name="permission_usage_list_title_any_time">Access at any time</string>
    <string name="permission_usage_list_title_any_time">Most recent access at any time</string>

    <!-- Label for the title of the list of permission usages that shows which apps used which permissions[CHAR LIMIT=50] -->
    <string name="permission_usage_list_title_last_7_days">Access in last 7 days</string>
    <string name="permission_usage_list_title_last_7_days">Most recent access in last 7 days</string>

    <!-- Label for the title of the list of permission usages that shows which apps used which permissions[CHAR LIMIT=50] -->
    <string name="permission_usage_list_title_last_day">Access in last 24 hours</string>
    <string name="permission_usage_list_title_last_day">Most recent access in last 24 hours</string>

    <!-- Label for the title of the list of permission usages that shows which apps used which permissions[CHAR LIMIT=50] -->
    <string name="permission_usage_list_title_last_hour">Access in the last hour</string>
    <string name="permission_usage_list_title_last_hour">Most recent access in the last hour</string>

    <!-- Label for the title of the list of permission usages that shows which apps used which permissions[CHAR LIMIT=50] -->
    <string name="permission_usage_list_title_last_15_minutes">Access in last 15 minutes</string>
    <string name="permission_usage_list_title_last_15_minutes">A=Most recent access in last 15 minutes</string>

    <!-- Label for the title of the list of permission usages that shows which apps used which permissions[CHAR LIMIT=50] -->
    <string name="permission_usage_list_title_last_minute">Access in last 1 minute</string>

    <!-- Label for the title of the permission bar chart showing how often the most common permissions are used [CHAR LIMIT=50] -->
    <string name="permission_usage_bar_chart_title_any_time">Top permission usage at any time</string>

    <!-- Label for the title of the permission bar chart showing how often the most common permissions are used [CHAR LIMIT=50] -->
    <string name="permission_usage_bar_chart_title_last_7_days">Top permission usage in last 7 days</string>

    <!-- Label for the title of the permission bar chart showing how often the most common permissions are used [CHAR LIMIT=50] -->
    <string name="permission_usage_bar_chart_title_last_day">Top permission usage in last 24 hours</string>

    <!-- Label for the title of the permission bar chart showing how often the most common permissions are used [CHAR LIMIT=50] -->
    <string name="permission_usage_bar_chart_title_last_hour">Top permission usage in last 1 hour</string>

    <!-- Label for the title of the permission bar chart showing how often the most common permissions are used [CHAR LIMIT=50] -->
    <string name="permission_usage_bar_chart_title_last_15_minutes">Top permission usage in last 15 minutes</string>

    <!-- Label for the title of the permission bar chart showing how often the most common permissions are used [CHAR LIMIT=50] -->
    <string name="permission_usage_bar_chart_title_last_minute">Top permission usage in last 1 minute</string>
    <string name="permission_usage_list_title_last_minute">Most recent access in last 1 minute</string>

    <!-- Label for the bars on the chart that shows how many apps have used various permissions [CHAR LIMIT=10] -->
    <string name="app_permission_usage_bar_label">Apps</string>
@@ -349,6 +334,15 @@
    <!-- Label for sorting usages by the most recent accesses [CHAR LIMIT=30] -->
    <string name="sort_spinner_recent">Recent</string>

    <!-- Label for sorting usages by which app used a permission most recently [CHAR LIMIT=30] -->
    <string name="sort_by_app">Sort by app usage</string>

    <!-- Label for sorting usages by access time [CHAR LIMIT=30] -->
    <string name="sort_by_time">Sort by time</string>

    <!-- Separator for a list of items. Include spaces before and after if needed [CHAR LIMIT=10] -->
    <string name="item_separator">,\u0020</string>

    <!-- Label for refreshing the list of permission usages. [CHAR LIMIT=30] -->
    <string name="permission_usage_refresh">Refresh</string>

+36 −18
Original line number Diff line number Diff line
@@ -20,13 +20,12 @@ import android.app.AppOpsManager;
import android.app.AppOpsManager.HistoricalOp;
import android.app.AppOpsManager.HistoricalPackageOps;
import android.app.AppOpsManager.OpEntry;

import android.app.AppOpsManager.PackageOps;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.packageinstaller.permission.model.PermissionApps.PermissionApp;
import com.android.packageinstaller.permission.utils.Utils;

import java.util.ArrayList;
import java.util.List;
@@ -107,25 +106,25 @@ public final class AppPermissionUsage {
            if (mLastUsage == null) {
                return 0;
            }
            long lastAccessTime = 0;
            final ArrayList<Permission> permissions = mGroup.getPermissions();
            final int permissionCount = permissions.size();
            for (int i = 0; i < permissionCount; i++) {
                final Permission permission = permissions.get(i);
                final String opName = permission.getAppOp();
                final List<OpEntry> ops = mLastUsage.getOps();
                final int opCount = ops.size();
                for (int j = 0; j < opCount; j++) {
                    final OpEntry op = ops.get(j);
                    if (op.getOpStr().equals(opName)) {
                        lastAccessTime = Math.max(lastAccessTime,
                                op.getLastAccessTime(AppOpsManager.OP_FLAGS_ALL_TRUSTED));
                    }
            return lastAccessAggregate(
                    (op) -> op.getLastAccessTime(AppOpsManager.OP_FLAGS_ALL_TRUSTED));
        }

        public long getLastAccessForegroundTime() {
            if (mLastUsage == null) {
                return 0;
            }
            return lastAccessTime;
            return lastAccessAggregate(
                    (op) -> op.getLastAccessForegroundTime(AppOpsManager.OP_FLAGS_ALL_TRUSTED));
        }

        public long getLastAccessBackgroundTime() {
            if (mLastUsage == null) {
                return 0;
            }
            return lastAccessAggregate(
                    (op) -> op.getLastAccessBackgroundTime(AppOpsManager.OP_FLAGS_ALL_TRUSTED));
        }

        public long getForegroundAccessCount() {
            if (mHistoricalUsage == null) {
@@ -178,6 +177,25 @@ public final class AppPermissionUsage {
            return aggregate;
        }

        private long lastAccessAggregate(@NonNull Function<OpEntry, Long> extractor) {
            long aggregate = 0;
            final ArrayList<Permission> permissions = mGroup.getPermissions();
            final int permissionCount = permissions.size();
            for (int permissionNum = 0; permissionNum < permissionCount; permissionNum++) {
                final Permission permission = permissions.get(permissionNum);
                final String opName = permission.getAppOp();
                final List<OpEntry> ops = mLastUsage.getOps();
                final int opCount = ops.size();
                for (int opNum = 0; opNum < opCount; opNum++) {
                    final OpEntry op = ops.get(opNum);
                    if (op.getOpStr().equals(opName)) {
                        aggregate = Math.max(aggregate, extractor.apply(op));
                    }
                }
            }
            return aggregate;
        }

        public @NonNull AppPermissionGroup getGroup() {
            return mGroup;
        }
+6 −0
Original line number Diff line number Diff line
@@ -17,11 +17,13 @@
package com.android.packageinstaller.permission.ui.handheld;

import android.content.Context;
import android.text.TextUtils;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
@@ -78,6 +80,10 @@ public class ExpandablePreferenceGroup extends PreferenceGroup {

        super.onBindViewHolder(holder);

        TextView summary = (TextView) holder.findViewById(android.R.id.summary);
        summary.setMaxLines(1);
        summary.setEllipsize(TextUtils.TruncateAt.END);

        ImageView rightImageView = holder.findViewById(
                android.R.id.widget_frame).findViewById(R.id.icon);
        if (mExpanded) {
Loading