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

Commit a48389aa authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Re-enable PermissionUsage

Bug: 161007415
Test: Looked at the PermissionUsage screen
Change-Id: Ib5da3b0fc62b28a128107b171534d2a94592d2f9
parent 1df15af9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/ImageView">

        <com.android.permissioncontroller.permission.ui.PreferenceImageView
        <com.android.permissioncontroller.permission.debug.PreferenceImageView
            android:id="@+id/icon"
            style="@style/ImageViewIcon" />

+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

        <com.android.permissioncontroller.permission.ui.PreferenceImageView
        <com.android.permissioncontroller.permission.debug.PreferenceImageView
            android:id="@+id/icon"
            style="@style/TitleSummaryImageViewIcon" />

+141 −0
Original line number Diff line number Diff line
@@ -287,9 +287,114 @@
    <!-- Help URL, application permissions [DO NOT TRANSLATE] -->
    <string name="help_app_permissions" translatable="false"></string>

    <!-- Title for permission usage [CHAR LIMIT=30] -->
    <string name="permission_usage_title">Dashboard</string>

    <!-- Summary for showing a single permission access and the number of accesses [CHAR LIMIT=80] -->
    <plurals name="permission_usage_summary">
        <item quantity="one">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g>\n<xliff:g id="num" example="42">%2$s</xliff:g> access</item>
        <item quantity="other">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g>\n<xliff:g id="num" example="42">%2$s</xliff:g> accesses</item>
    </plurals>

    <!-- Summary for showing a single permission access and the number of accesses, including those in the background [CHAR LIMIT=80] -->
    <plurals name="permission_usage_summary_background">
        <item quantity="one">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g>\n<xliff:g id="num" example="42">%2$s</xliff:g> access (<xliff:g id="num" example="7">%3$s</xliff:g> in background)</item>
        <item quantity="other">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g>\n<xliff:g id="num" example="42">%2$s</xliff:g> accesses (<xliff:g id="num" example="7">%3$s</xliff:g> in background)</item>
    </plurals>

    <!-- Summary for showing a single permission access and the number of accesses [CHAR LIMIT=120] -->
    <plurals name="permission_usage_summary_duration">
        <item quantity="one">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g>\n<xliff:g id="num" example="42">%2$s</xliff:g> access\nDuration: <xliff:g id="time" example="2 hours">%3$s</xliff:g></item>
        <item quantity="other">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g>\n<xliff:g id="num" example="42">%2$s</xliff:g> accesses\nDuration: <xliff:g id="time" example="2 hours">%3$s</xliff:g></item>
    </plurals>

    <!-- Summary for showing a single permission access and the number of accesses, including those in the background [CHAR LIMIT=120] -->
    <plurals name="permission_usage_summary_background_duration">
        <item quantity="one">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g>\n<xliff:g id="num" example="42">%2$s</xliff:g> access (<xliff:g id="num" example="7">%3$s</xliff:g> in background)\nDuration: <xliff:g id="time" example="2 hours">%3$s</xliff:g></item>
        <item quantity="other">Last access: <xliff:g id="time" example="12:10 PM">%1$s</xliff:g>\n<xliff:g id="num" example="42">%2$s</xliff:g> accesses (<xliff:g id="num" example="7">%3$s</xliff:g> in background)\nDuration: <xliff:g id="time" example="2 hours">%3$s</xliff:g></item>
    </plurals>

    <!-- 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>\nLast accessed in the background</string>

    <!-- Description for showing permission accesses with any permission [CHAR LIMIT=30] -->
    <string name="permission_usage_any_permission">Any permission</string>

    <!-- Description for showing permission accesses accessed any time [CHAR LIMIT=30] -->
    <string name="permission_usage_any_time">Any time</string>

    <!-- Description for showing permissions accessed in the last 7 days [CHAR LIMIT=30] -->
    <string name="permission_usage_last_7_days">Last 7 days</string>

    <!-- Description for showing permissions accessed in the last day [CHAR LIMIT=30] -->
    <string name="permission_usage_last_day">Last 24 hours</string>

    <!-- Description for showing permissions accessed in the last hour [CHAR LIMIT=30] -->
    <string name="permission_usage_last_hour">Last 1 hour</string>

    <!-- Description for showing permissions accessed in the last 15 minutes [CHAR LIMIT=30] -->
    <string name="permission_usage_last_15_minutes">Last 15 minutes</string>

    <!-- Description for showing permissions accessed in the last minute [CHAR LIMIT=30] -->
    <string name="permission_usage_last_minute">Last 1 minute</string>

    <!-- Label when no apps have used the requested permissions [CHAR LIMIT=30] -->
    <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">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">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">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">Most recent access in last 1 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">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">Most recent 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">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">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">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">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">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">Permission usage in last 1 minute</string>

    <!-- Label for the bars on the chart that shows how many apps have used various permissions [CHAR LIMIT=10] -->
    <plurals name="permission_usage_bar_label">
        <item quantity="one">1 app</item>
        <item quantity="other"><xliff:g id="number" example="7">%s</xliff:g> apps</item>
    </plurals>

    <!-- Label for the button to bring the user to view the details of recent permission accesses [CHAR LIMIT=42] -->
    <string name="permission_usage_view_details">See all in Dashboard</string>

    <!-- DO NOT TRANSLATE Summary placeholder -->
    <string name="summary_placeholder" translatable="false">&#160;</string>

    <!-- Label for filtered view that shows permission usages of a single permission [CHAR LIMIT=40] -->
    <string name="app_permission_usage_filter_label">Filtered by: <xliff:g id="perm" example="Location">%1$s</xliff:g> </string>

    <!-- Label for the text that removes the filter by permission to view all usages [CHAR LIMIT=none] -->
    <string name="app_permission_usage_remove_filter">Remove filter</string>

    <!-- Label for the title of the dialog allowing filtering by permissions [CHAR LIMIT=none] -->
    <string name="filter_by_title">Filter by</string>

@@ -299,9 +404,45 @@
    <!-- Label for the menu item allowing filtering by time [CHAR LIMIT=none] -->
    <string name="filter_by_time">Filter by time</string>

    <!-- Label for sorting usages by the number of permissions used [CHAR LIMIT=30] -->
    <string name="sort_spinner_most_permissions">Most permissions</string>

    <!-- Label for sorting usages by the number of accesses [CHAR LIMIT=30] -->
    <string name="sort_spinner_most_accesses">Most accesses</string>

    <!-- 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>

    <!-- Subtitle for showing how many apps have accessed a given permission [CHAR LIMIT=20] -->
    <plurals name="permission_usage_permission_filter_subtitle">
        <item quantity="one">1 app</item>
        <item quantity="other"><xliff:g id="number" example="7">%s</xliff:g> apps</item>
    </plurals>

    <!-- Help URL, permission usage [DO NOT TRANSLATE] -->
    <string name="help_permission_usage" translatable="false"></string>

    <!-- Title for permission usage [CHAR LIMIT=30] -->
    <string name="app_permission_usage_title">App permissions usage</string>

    <!-- Summary for an app's use of a permission [CHAR LIMIT=none] -->
    <string name="app_permission_usage_summary">Access: <xliff:g id="num" example="2">%1$s</xliff:g> times. Total duration: <xliff:g id="duration" example="2 hours">%2$s</xliff:g>. Last used <xliff:g id="time" example="2 hours">%3$s</xliff:g> ago.</string>

    <!-- Summary for an app's use of a permission without duration [CHAR LIMIT=none] -->
    <string name="app_permission_usage_summary_no_duration">Access: <xliff:g id="num" example="2">%1$s</xliff:g> times. Last used <xliff:g id="time" example="2 hours">%2$s</xliff:g> ago.</string>

    <!-- Title for the dialog button to allow a permission grant when you cannot only allow in the foreground. [CHAR LIMIT=60] -->
    <string name="app_permission_button_allow">Allow</string>

+135 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.permissioncontroller.permission.debug;

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;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceViewHolder;

import com.android.permissioncontroller.R;

import java.util.ArrayList;
import java.util.List;

/**
 * A preference group that expands/collapses its children when clicked.
 */
public class ExpandablePreferenceGroup extends PreferenceGroup {
    private @NonNull Context mContext;
    private @NonNull List<Preference> mPreferences;
    private @NonNull List<Pair<Integer, CharSequence>> mSummaryIcons;
    private boolean mExpanded;

    public ExpandablePreferenceGroup(@NonNull Context context) {
        super(context, null);

        mContext = context;
        mPreferences = new ArrayList<>();
        mSummaryIcons = new ArrayList<>();
        mExpanded = false;

        setLayoutResource(R.layout.preference_usage);
        setWidgetLayoutResource(R.layout.image_view);
        setOnPreferenceClickListener(preference -> {
            if (!mExpanded) {
                int numPreferences = mPreferences.size();
                for (int i = 0; i < numPreferences; i++) {
                    super.addPreference(mPreferences.get(i));
                }
            } else {
                removeAll();
            }
            mExpanded = !mExpanded;
            return true;
        });
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        ImageView icon = (ImageView) holder.findViewById(android.R.id.icon);
        int rightIconSize = mContext.getResources().getDimensionPixelSize(
                R.dimen.secondary_app_icon_size);
        icon.setMaxWidth(rightIconSize);
        icon.setMaxHeight(rightIconSize);

        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) {
            rightImageView.setImageResource(R.drawable.ic_arrow_up);
        } else {
            rightImageView.setImageResource(R.drawable.ic_arrow_down);
        }

        holder.setDividerAllowedAbove(false);
        holder.setDividerAllowedBelow(false);

        holder.findViewById(R.id.title_widget_frame).setVisibility(View.GONE);

        ViewGroup summaryFrame = (ViewGroup) holder.findViewById(R.id.summary_widget_frame);
        if (mSummaryIcons.isEmpty()) {
            summaryFrame.setVisibility(View.GONE);
        } else {
            summaryFrame.removeAllViews();
            int numIcons = mSummaryIcons.size();
            for (int i = 0; i < numIcons; i++) {
                LayoutInflater inflater = mContext.getSystemService(LayoutInflater.class);
                ViewGroup group = (ViewGroup) inflater.inflate(R.layout.title_summary_image_view,
                        null);
                ImageView imageView = group.requireViewById(R.id.icon);
                Pair<Integer, CharSequence> summaryIcons = mSummaryIcons.get(i);
                imageView.setImageResource(summaryIcons.first);
                if (summaryIcons.second != null) {
                    imageView.setContentDescription(summaryIcons.second);
                }
                summaryFrame.addView(group);
            }
        }
    }

    @Override
    public boolean addPreference(Preference preference) {
        mPreferences.add(preference);
        return true;
    }

    /**
     * Show the given icon next to this preference's summary.
     *
     * @param resId the resourceId of the drawable to use as the icon.
     */
    public void addSummaryIcon(@DrawableRes int resId, @Nullable CharSequence contentDescription) {
        mSummaryIcons.add(Pair.create(resId, contentDescription));
    }
}
+1052 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading