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

Commit c4b7e139 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add a header showing the permission name, icon, and description to PermissionAppsFragment."

parents 1d876fd6 1a1f3612
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -400,6 +400,45 @@
    <!-- Text for linking to the page that shows the apps with a given permission [CHAR LIMIT=none] -->
    <string name="app_permission_footer_permission_apps_link">See all apps with the <xliff:g id="perm" example="Location">%1$s</xliff:g> permission</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have that permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_generic">Apps with this permission can <xliff:g id="description" example="record audio">%1$s</xliff:g></string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the activity recognition permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_activity_recognition">Apps with this permission can recognize activity</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the calendar permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_calendar">Apps with this permission can access your calendar</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the call log permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_call_log">Apps with this permission can read and write phone call log</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the camera permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_camera">Apps with this permission can take pictures and record video</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the contacts permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_contacts">Apps with this permission can access your contacts</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the location permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_location">Apps with this permission can access this device\'s location</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the media_aural permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_media_aural">Apps with this permission can access your music</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the media_visual permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_media_visual">Apps with this permission can access your photos &amp; videos</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the microphone permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_microphone">Apps with this permission can record audio</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the phone permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_phone">Apps with this permission can make and manage phone calls</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the sensors permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_sensors">Apps with this permission can access sensor data about your vital signs</string>

    <!-- Label for showing a permission group's description in the header of the list of apps that have the SMS permission [CHAR LIMIT=none] -->
    <string name="permission_description_summary_sms">Apps with this permission can send and view SMS messages</string>

    <!-- Summary for showing the time and/or date of the most recent access of a permission by an app [CHAR LIMIT=60] -->
    <string name="app_permission_most_recent_summary">Last access: <xliff:g id="time_date" example="12:42 PM">%1$s</xliff:g></string>

+2 −0
Original line number Diff line number Diff line
@@ -196,6 +196,8 @@
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginBottom">16dp</item>
        <item name="android:textColor">?android:attr/colorAccent</item>
        <item name="android:paddingStart">?android:attr/listPreferredItemPaddingStart</item>
        <item name="android:paddingEnd">?android:attr/listPreferredItemPaddingEnd</item>
    </style>

    <style name="LargeHeaderDivider">
+11 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
@@ -55,6 +56,7 @@ public class PermissionApps {

    private CharSequence mLabel;
    private Drawable mIcon;
    private @Nullable CharSequence mDescription;
    private List<PermissionApp> mPermApps;
    // Map (pkg|uid) -> AppPermission
    private ArrayMap<String, PermissionApp> mAppLookup;
@@ -161,6 +163,10 @@ public class PermissionApps {
        return mIcon;
    }

    public CharSequence getDescription() {
        return mDescription;
    }

    private @NonNull List<PackageInfo> getPackageInfos(@NonNull UserHandle user) {
        List<PackageInfo> apps = (mPmCache != null) ? mPmCache.getPackages(
                user.getIdentifier()) : null;
@@ -321,6 +327,11 @@ public class PermissionApps {
            mIcon = mContext.getDrawable(R.drawable.ic_perm_device_info);
        }
        mIcon = Utils.applyTint(mContext, mIcon, android.R.attr.colorControlNormal);
        if (info instanceof PermissionGroupInfo) {
            mDescription = ((PermissionGroupInfo) info).loadDescription(mPm);
        } else if (info instanceof PermissionInfo) {
            mDescription = ((PermissionInfo) info).loadDescription(mPm);
        }
    }

    public static class PermissionApp implements Comparable<PermissionApp> {
+14 −5
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
@@ -51,7 +52,7 @@ import java.util.Map;
 *
 * <p>Shows a list of apps which request at least on permission of this group.
 */
public final class PermissionAppsFragment extends PermissionsFrameFragment implements Callback {
public final class PermissionAppsFragment extends SettingsWithLargeHeader implements Callback {

    private static final String KEY_SHOW_SYSTEM_PREFS = "_showSystem";

@@ -162,12 +163,19 @@ public final class PermissionAppsFragment extends PermissionsFrameFragment imple
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        bindUi(this, mPermissionApps);
        bindUi(this, mPermissionApps,
                getArguments().getString(Intent.EXTRA_PERMISSION_NAME));
    }

    private static void bindUi(Fragment fragment, PermissionApps permissionApps) {
    private static void bindUi(SettingsWithLargeHeader fragment, PermissionApps permissionApps,
            @NonNull String groupName) {
        final Drawable icon = permissionApps.getIcon();
        final CharSequence label = permissionApps.getLabel();

        fragment.setHeader(icon, label, null);
        fragment.setSummary(Utils.getPermissionGroupDescriptionString(fragment.getActivity(),
                groupName, permissionApps.getDescription()), null);

        final ActionBar ab = fragment.getActivity().getActionBar();
        if (ab != null) {
            ab.setTitle(label);
@@ -373,7 +381,7 @@ public final class PermissionAppsFragment extends PermissionsFrameFragment imple
        }
    }

    public static class SystemAppsFragment extends PermissionsFrameFragment implements Callback {
    public static class SystemAppsFragment extends SettingsWithLargeHeader implements Callback {
        PermissionAppsFragment mOuterFragment;

        @Override
@@ -381,6 +389,7 @@ public final class PermissionAppsFragment extends PermissionsFrameFragment imple
            mOuterFragment = (PermissionAppsFragment) getTargetFragment();
            setLoading(true /* loading */, false /* animate */);
            super.onCreate(savedInstanceState);
            setHeader(mOuterFragment.mIcon, mOuterFragment.mLabel, null);
            if (mOuterFragment.mExtraScreen != null) {
                setPreferenceScreen();
            } else {
@@ -394,7 +403,7 @@ public final class PermissionAppsFragment extends PermissionsFrameFragment imple
            String groupName = getArguments().getString(Intent.EXTRA_PERMISSION_NAME);
            PermissionApps permissionApps = new PermissionApps(getActivity(),
                    groupName, (Callback) null);
            bindUi(this, permissionApps);
            bindUi(this, permissionApps, groupName);
        }

        @Override
+8 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.packageinstaller.permission.ui.handheld;

import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -103,12 +104,18 @@ public abstract class SettingsWithLargeHeader extends PermissionsFrameFragment
     * @param summary the text to display
     * @param listener the click listener if the summary should be clickable
     */
    public void setSummary(@NonNull String summary, @Nullable View.OnClickListener listener) {
    public void setSummary(@NonNull CharSequence summary, @Nullable View.OnClickListener listener) {
        TextView summaryView = mHeader.requireViewById(R.id.header_link);
        summaryView.setVisibility(View.VISIBLE);
        summaryView.setText(summary);
        if (listener != null) {
            summaryView.setOnClickListener(listener);
        } else {
            TypedArray a = getContext().obtainStyledAttributes(
                    new int[] { android.R.attr.textColorSecondary });
            int color = a.getColor(0, 0);
            a.recycle();
            summaryView.setTextColor(color);
        }
    }
}
Loading