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

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

Merge "New strings for granting foreground to background perms"

parents 983fed3e 734241eb
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -36,6 +36,12 @@
    <!-- Title for the dialog button to always deny a permission grant from now on. [CHAR LIMIT=60] -->
    <string name="grant_dialog_button_deny_and_dont_ask_again">Deny \u0026 don\u2019t ask again</string>

    <!-- Title for the dialog button to deny a change from foreground to background permission grant. [CHAR LIMIT=60] -->
    <string name="grant_dialog_button_deny_background">Keep while-in-use access</string>

    <!-- Title for the dialog button to always deny a change from foreground to background permission grant from now on. [CHAR LIMIT=60] -->
    <string name="grant_dialog_button_deny_background_and_dont_ask_again">Keep and don\u2019t ask again</string>

    <!-- Title for the dialog button to get more info about a permission. [CHAR LIMIT=15] -->
    <string name="grant_dialog_button_more_info">More info</string>

@@ -93,6 +99,9 @@
    <!-- Title for the dialog button to allow a permission grant only when the app is in the foreground. [CHAR LIMIT=60] -->
    <string name="grant_dialog_button_allow_foreground">Allow only while the app is in use</string>

    <!-- Title for the dialog button to allow a change from foreground to background permission grant. [CHAR LIMIT=60]  -->
    <string name="grant_dialog_button_allow_background">Allow all the time</string>

    <!-- Breadcrumb for page of managing application permissions [CHAR LIMIT=50] -->
    <string name="app_permissions_breadcrumb">Apps</string>

+33 −4
Original line number Diff line number Diff line
@@ -86,6 +86,13 @@ public class GrantPermissionsActivity extends Activity
    private static final String KEY_REQUEST_ID = GrantPermissionsActivity.class.getName()
            + "_REQUEST_ID";

    public static int NUM_BUTTONS = 5;
    public static int LABEL_ALLOW_BUTTON = 0;
    public static int LABEL_ALLOW_ALWAYS_BUTTON = 1;
    public static int LABEL_ALLOW_FOREGROUND_BUTTON = 2;
    public static int LABEL_DENY_BUTTON = 3;
    public static int LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON = 4;

    /** Unique Id of a request */
    private long mRequestId;

@@ -628,14 +635,30 @@ public class GrantPermissionsActivity extends Activity
                    }
                }

                boolean showForegroundChooser = false;
                // The button doesn't show when its label is null
                CharSequence[] buttonLabels = new CharSequence[NUM_BUTTONS];
                buttonLabels[LABEL_ALLOW_BUTTON] = getString(R.string.grant_dialog_button_allow);
                buttonLabels[LABEL_ALLOW_ALWAYS_BUTTON] = null;
                buttonLabels[LABEL_ALLOW_FOREGROUND_BUTTON] = null;
                buttonLabels[LABEL_DENY_BUTTON] = getString(R.string.grant_dialog_button_deny);
                if (isForegroundPermissionUserSet || isBackgroundPermissionUserSet) {
                    buttonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] =
                            getString(R.string.grant_dialog_button_deny_and_dont_ask_again);
                } else {
                    buttonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] = null;
                }

                int messageId;
                int detailMessageId = 0;
                if (needForegroundPermission) {
                    messageId = groupState.mGroup.getRequest();

                    if (needBackgroundPermission) {
                        showForegroundChooser = true;
                        buttonLabels[LABEL_ALLOW_BUTTON] = null;
                        buttonLabels[LABEL_ALLOW_ALWAYS_BUTTON] =
                                getString(R.string.grant_dialog_button_allow_always);
                        buttonLabels[LABEL_ALLOW_FOREGROUND_BUTTON] =
                                getString(R.string.grant_dialog_button_allow_foreground);
                    } else {
                        if (foregroundGroupState.mGroup.hasPermissionWithBackgroundMode()) {
                            detailMessageId = groupState.mGroup.getRequestDetail();
@@ -645,6 +668,13 @@ public class GrantPermissionsActivity extends Activity
                    if (needBackgroundPermission) {
                        messageId = groupState.mGroup.getBackgroundRequest();
                        detailMessageId = groupState.mGroup.getBackgroundRequestDetail();
                        buttonLabels[LABEL_ALLOW_BUTTON] =
                                getString(R.string.grant_dialog_button_allow_always);
                        buttonLabels[LABEL_DENY_BUTTON] =
                                getString(R.string.grant_dialog_button_deny_background);
                        buttonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] =
                                getString(R.string
                                        .grant_dialog_button_deny_background_and_dont_ask_again);
                    } else {
                        // Not reached as the permissions should be auto-granted
                        return false;
@@ -669,8 +699,7 @@ public class GrantPermissionsActivity extends Activity
                setTitle(message);

                mViewHandler.updateUi(groupState.mGroup.getName(), numGrantRequests, currentIndex,
                        icon, message, detailMessage, showForegroundChooser,
                        isForegroundPermissionUserSet || isBackgroundPermissionUserSet);
                        icon, message, detailMessage, buttonLabels);

                return true;
            }
+2 −4
Original line number Diff line number Diff line
@@ -74,12 +74,10 @@ public interface GrantPermissionsViewHandler {
     * @param message the message to display the user
     * @param detailMessage another message to display to the user. This clarifies "message" in more
     *                      detail
     * @param showForegroundChooser whether to show the "only in foreground / always" option
     * @param showDoNotAsk whether to show the "do not ask again" option
     * @param buttonLabels labels for each button. Use null to make the button gone
     */
    void updateUi(String groupName, int groupCount, int groupIndex, Icon icon,
            CharSequence message, CharSequence detailMessage, boolean showForegroundChooser,
            boolean showDoNotAsk);
            CharSequence message, CharSequence detailMessage, CharSequence[] buttonLabels);

    /**
     * Sets the result listener that will be notified when the user responds
+6 −3
Original line number Diff line number Diff line
package com.android.packageinstaller.permission.ui;

import static com.android.packageinstaller.permission.ui.GrantPermissionsActivity.LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
@@ -77,10 +79,11 @@ final class GrantPermissionsWatchViewHandler implements GrantPermissionsViewHand

    @Override
    public void updateUi(String groupName, int groupCount, int groupIndex, Icon icon,
            CharSequence message, CharSequence detailMessage, boolean showForegroundChooser,
            boolean showDoNotAsk) {
            CharSequence message, CharSequence detailMessage,
            CharSequence[] buttonLabels) {
        // TODO: Handle detailMessage
        // TODO: Handle showForegroundChooser

        boolean showDoNotAsk = buttonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] != null;

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "updateUi() - groupName: " + groupName
+39 −24
Original line number Diff line number Diff line
@@ -16,6 +16,12 @@

package com.android.packageinstaller.permission.ui.handheld;

import static com.android.packageinstaller.permission.ui.GrantPermissionsActivity.LABEL_ALLOW_ALWAYS_BUTTON;
import static com.android.packageinstaller.permission.ui.GrantPermissionsActivity.LABEL_ALLOW_BUTTON;
import static com.android.packageinstaller.permission.ui.GrantPermissionsActivity.LABEL_ALLOW_FOREGROUND_BUTTON;
import static com.android.packageinstaller.permission.ui.GrantPermissionsActivity.LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON;
import static com.android.packageinstaller.permission.ui.GrantPermissionsActivity.LABEL_DENY_BUTTON;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Icon;
@@ -43,10 +49,7 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand
    public static final String ARG_GROUP_ICON = "ARG_GROUP_ICON";
    public static final String ARG_GROUP_MESSAGE = "ARG_GROUP_MESSAGE";
    private static final String ARG_GROUP_DETAIL_MESSAGE = "ARG_GROUP_DETAIL_MESSAGE";

    public static final String ARG_GROUP_SHOW_DO_NOT_ASK = "ARG_GROUP_SHOW_DO_NOT_ASK";
    private static final String ARG_GROUP_SHOW_FOREGOUND_CHOOSER =
            "ARG_GROUP_SHOW_FOREGOUND_CHOOSER";
    private static final String ARG_DIALOG_BUTTON_LABELS = "ARG_DIALOG_BUTTON_LABELS";

    // Animation parameters.
    private static final long SWITCH_TIME_MILLIS = 75;
@@ -64,9 +67,7 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand
    private Icon mGroupIcon;
    private CharSequence mGroupMessage;
    private CharSequence mDetailMessage;

    private boolean mShowDonNotAsk;
    private boolean mShowForegroundChooser;
    private CharSequence[] mButtonLabels;

    // Views
    private ImageView mIconView;
@@ -98,9 +99,7 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand
        arguments.putParcelable(ARG_GROUP_ICON, mGroupIcon);
        arguments.putCharSequence(ARG_GROUP_MESSAGE, mGroupMessage);
        arguments.putCharSequence(ARG_GROUP_DETAIL_MESSAGE, mDetailMessage);

        arguments.putBoolean(ARG_GROUP_SHOW_DO_NOT_ASK, mShowDonNotAsk);
        arguments.putBoolean(ARG_GROUP_SHOW_FOREGOUND_CHOOSER, mShowForegroundChooser);
        arguments.putCharSequenceArray(ARG_DIALOG_BUTTON_LABELS, mButtonLabels);

    }

@@ -112,17 +111,14 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand
        mGroupCount = savedInstanceState.getInt(ARG_GROUP_COUNT);
        mGroupIndex = savedInstanceState.getInt(ARG_GROUP_INDEX);
        mDetailMessage = savedInstanceState.getCharSequence(ARG_GROUP_DETAIL_MESSAGE);

        mShowDonNotAsk = savedInstanceState.getBoolean(ARG_GROUP_SHOW_DO_NOT_ASK);
        mShowForegroundChooser = savedInstanceState.getBoolean(ARG_GROUP_SHOW_FOREGOUND_CHOOSER);
        mButtonLabels = savedInstanceState.getCharSequenceArray(ARG_DIALOG_BUTTON_LABELS);

        updateAll();
    }

    @Override
    public void updateUi(String groupName, int groupCount, int groupIndex, Icon icon,
            CharSequence message, CharSequence detailMessage, boolean showForegroundChooser,
            boolean showDonNotAsk) {
            CharSequence message, CharSequence detailMessage, CharSequence[] buttonLabels) {
        boolean isNewGroup = mGroupIndex != groupIndex;

        mGroupName = groupName;
@@ -130,9 +126,8 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand
        mGroupIndex = groupIndex;
        mGroupIcon = icon;
        mGroupMessage = message;
        mShowDonNotAsk = showDonNotAsk;
        mDetailMessage = detailMessage;
        mShowForegroundChooser = showForegroundChooser;
        mButtonLabels = buttonLabels;

        // If this is a second (or later) permission and the views exist, then animate.
        if (mIconView != null) {
@@ -143,7 +138,7 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand
    private void updateAll() {
        updateDescription();
        updateDetailDescription();
        updateDoNotAskAndForegroundOption();
        updateButtons();
    }

    @Override
@@ -197,20 +192,40 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand
        }
    }

    private void updateDoNotAskAndForegroundOption() {
        if (mShowForegroundChooser) {
    private void updateButtons() {
        if (mButtonLabels[LABEL_ALLOW_BUTTON] == null) {
            mAllowButton.setVisibility(View.GONE);
            mAllowAlwaysButton.setVisibility(View.VISIBLE);
            mAllowForegroundButton.setVisibility(View.VISIBLE);
        } else {
            mAllowButton.setVisibility(View.VISIBLE);
            mAllowButton.setText(mButtonLabels[LABEL_ALLOW_BUTTON]);
        }

        if (mButtonLabels[LABEL_ALLOW_ALWAYS_BUTTON] == null) {
            mAllowAlwaysButton.setVisibility(View.GONE);
        } else {
            mAllowAlwaysButton.setVisibility(View.VISIBLE);
            mAllowAlwaysButton.setText(mButtonLabels[LABEL_ALLOW_ALWAYS_BUTTON]);
        }

        if (mButtonLabels[LABEL_ALLOW_FOREGROUND_BUTTON] == null) {
            mAllowForegroundButton.setVisibility(View.GONE);
        } else {
            mAllowForegroundButton.setVisibility(View.VISIBLE);
            mAllowForegroundButton.setText(mButtonLabels[LABEL_ALLOW_FOREGROUND_BUTTON]);
        }
        if (mShowDonNotAsk) {
            mDenyAndDontAskAgainButton.setVisibility(View.VISIBLE);

        if (mButtonLabels[LABEL_DENY_BUTTON] == null) {
            mDenyButton.setVisibility(View.GONE);
        } else {
            mDenyButton.setVisibility(View.VISIBLE);
            mDenyButton.setText(mButtonLabels[LABEL_DENY_BUTTON]);
        }

        if (mButtonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] == null) {
            mDenyAndDontAskAgainButton.setVisibility(View.GONE);
        } else {
            mDenyAndDontAskAgainButton.setVisibility(View.VISIBLE);
            mDenyAndDontAskAgainButton.setText(mButtonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON]);
        }

    }
Loading