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

Commit 0fb4b8f1 authored by Stanislav Zholnin's avatar Stanislav Zholnin Committed by android-build-merger
Browse files

Adding logging for GrantPermissionsActivity buttons presented and pressed.

am: 0f0587d8

Change-Id: I80638da6e16cc62d7e6db121a0bc6ac5e64d9720
parents c1b0d23f 0f0587d8
Loading
Loading
Loading
Loading
+64 −15
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.packageinstaller.permission.ui;
import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;

import static com.android.packageinstaller.PermissionControllerStatsLog.GRANT_PERMISSIONS_ACTIVITY_BUTTON_ACTIONS;
import static com.android.packageinstaller.PermissionControllerStatsLog.PERMISSION_GRANT_REQUEST_RESULT_REPORTED__RESULT__AUTO_DENIED;
import static com.android.packageinstaller.PermissionControllerStatsLog.PERMISSION_GRANT_REQUEST_RESULT_REPORTED__RESULT__AUTO_GRANTED;
import static com.android.packageinstaller.PermissionControllerStatsLog.PERMISSION_GRANT_REQUEST_RESULT_REPORTED__RESULT__IGNORED;
@@ -95,6 +96,7 @@ public class GrantPermissionsActivity extends Activity
    private long mRequestId;

    private String[] mRequestedPermissions;
    private CharSequence[] mButtonLabels;

    private ArrayMap<Pair<String, Boolean>, GroupState> mRequestGrantPermissionGroups =
            new ArrayMap<>();
@@ -641,16 +643,16 @@ public class GrantPermissionsActivity extends Activity
                }

                // 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);
                mButtonLabels = new CharSequence[NUM_BUTTONS];
                mButtonLabels[LABEL_ALLOW_BUTTON] = getString(R.string.grant_dialog_button_allow);
                mButtonLabels[LABEL_ALLOW_ALWAYS_BUTTON] = null;
                mButtonLabels[LABEL_ALLOW_FOREGROUND_BUTTON] = null;
                mButtonLabels[LABEL_DENY_BUTTON] = getString(R.string.grant_dialog_button_deny);
                if (isForegroundPermissionUserSet || isBackgroundPermissionUserSet) {
                    buttonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] =
                    mButtonLabels[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;
                    mButtonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] = null;
                }

                int messageId;
@@ -659,14 +661,14 @@ public class GrantPermissionsActivity extends Activity
                    messageId = groupState.mGroup.getRequest();

                    if (groupState.mGroup.hasPermissionWithBackgroundMode()) {
                        buttonLabels[LABEL_ALLOW_BUTTON] = null;
                        buttonLabels[LABEL_ALLOW_FOREGROUND_BUTTON] =
                        mButtonLabels[LABEL_ALLOW_BUTTON] = null;
                        mButtonLabels[LABEL_ALLOW_FOREGROUND_BUTTON] =
                                getString(R.string.grant_dialog_button_allow_foreground);
                        if (needBackgroundPermission) {
                            buttonLabels[LABEL_ALLOW_ALWAYS_BUTTON] =
                            mButtonLabels[LABEL_ALLOW_ALWAYS_BUTTON] =
                                    getString(R.string.grant_dialog_button_allow_always);
                            if (isForegroundPermissionUserSet || isBackgroundPermissionUserSet) {
                                buttonLabels[LABEL_DENY_BUTTON] = null;
                                mButtonLabels[LABEL_DENY_BUTTON] = null;
                            }
                        }
                    } else {
@@ -676,11 +678,11 @@ public class GrantPermissionsActivity extends Activity
                    if (needBackgroundPermission) {
                        messageId = groupState.mGroup.getBackgroundRequest();
                        detailMessageId = groupState.mGroup.getBackgroundRequestDetail();
                        buttonLabels[LABEL_ALLOW_BUTTON] =
                        mButtonLabels[LABEL_ALLOW_BUTTON] =
                                getString(R.string.grant_dialog_button_allow_background);
                        buttonLabels[LABEL_DENY_BUTTON] =
                        mButtonLabels[LABEL_DENY_BUTTON] =
                                getString(R.string.grant_dialog_button_deny_background);
                        buttonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] =
                        mButtonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] =
                                getString(R.string
                                        .grant_dialog_button_deny_background_and_dont_ask_again);
                    } else {
@@ -707,7 +709,7 @@ public class GrantPermissionsActivity extends Activity
                setTitle(message);

                mViewHandler.updateUi(groupState.mGroup.getName(), numGrantRequests, currentIndex,
                        icon, message, detailMessage, buttonLabels);
                        icon, message, detailMessage, mButtonLabels);

                return true;
            }
@@ -723,6 +725,7 @@ public class GrantPermissionsActivity extends Activity
    @Override
    public void onPermissionGrantResult(String name,
            @GrantPermissionsViewHandler.Result int result) {
        logGrantPermissionActivityButtons(name, result);
        GroupState foregroundGroupState = getForegroundGroupState(name);
        GroupState backgroundGroupState = getBackgroundGroupState(name);

@@ -953,6 +956,52 @@ public class GrantPermissionsActivity extends Activity
        }
    }

    private void logGrantPermissionActivityButtons(String permissionGroupName, int grantResult) {
        int clickedButton = 0;
        int presentedButtons = getButtonState();
        switch (grantResult) {
            case GRANTED_ALWAYS:
                if ((presentedButtons & (1 << LABEL_ALLOW_BUTTON)) != 0) {
                    clickedButton = 1 << LABEL_ALLOW_BUTTON;
                } else {
                    clickedButton = 1 << LABEL_ALLOW_ALWAYS_BUTTON;
                }
                break;
            case GRANTED_FOREGROUND_ONLY:
                clickedButton = 1 << LABEL_ALLOW_FOREGROUND_BUTTON;
                break;
            case DENIED:
                clickedButton = 1 << LABEL_DENY_BUTTON;
                break;
            case DENIED_DO_NOT_ASK_AGAIN:
                clickedButton = 1 << LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON;
                break;
            default:
                break;
        }

        PermissionControllerStatsLog.write(GRANT_PERMISSIONS_ACTIVITY_BUTTON_ACTIONS,
                permissionGroupName, mCallingUid, mCallingPackage, presentedButtons,
                clickedButton);
        Log.v(LOG_TAG, "Logged buttons presented and clicked permissionGroupName="
                + permissionGroupName + " uid=" + mCallingUid + " package=" + mCallingPackage
                + " presentedButtons=" + presentedButtons + " clickedButton=" + clickedButton);
    }

    private int getButtonState() {
        if (mButtonLabels == null) {
            return 0;
        }
        int buttonState = 0;
        for (int i = NUM_BUTTONS - 1; i >= 0; i--) {
            buttonState *= 2;
            if (mButtonLabels[i] != null) {
                buttonState++;
            }
        }
        return buttonState;
    }

    private static final class GroupState {
        static final int STATE_UNKNOWN = 0;
        static final int STATE_ALLOWED = 1;