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

Commit e3ffa740 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5671249 from 1977a5af to qt-qpr1-release

Change-Id: Ibe07bdfe2d16469a4631d4a5f12479d22e337243
parents cf32c763 1977a5af
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.packageinstaller.permission.service;

import static com.android.packageinstaller.PermissionControllerStatsLog.RUNTIME_PERMISSIONS_UPGRADE_RESULT;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageInfo;
@@ -26,9 +28,12 @@ import android.util.Log;

import androidx.annotation.NonNull;

import com.android.packageinstaller.PermissionControllerStatsLog;
import com.android.packageinstaller.permission.model.AppPermissionGroup;
import com.android.packageinstaller.permission.model.Permission;
import com.android.packageinstaller.permission.utils.Utils;

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

/**
@@ -209,6 +214,9 @@ class RuntimePermissionsUpgradeController {
                                && !bgGroup.isSystemFixed()
                                && !bgGroup.isPolicyFixed()) {
                            bgGroup.grantRuntimePermissions(group.isUserFixed());

                            logRuntimePermissionUpgradeResult(bgGroup,
                                    app.applicationInfo.uid, app.packageName);
                        }

                        break;
@@ -226,4 +234,17 @@ class RuntimePermissionsUpgradeController {

        return currentVersion;
    }

    private static void logRuntimePermissionUpgradeResult(AppPermissionGroup permissionGroup,
            int uid, String packageName) {
        ArrayList<Permission> permissions = permissionGroup.getPermissions();
        int numPermissions = permissions.size();
        for (int i = 0; i < numPermissions; i++) {
            Permission permission = permissions.get(i);
            PermissionControllerStatsLog.write(RUNTIME_PERMISSIONS_UPGRADE_RESULT,
                    permission.getName(), uid, packageName);
            Log.v(LOG_TAG, "Runtime permission upgrade logged for permissionName="
                    + permission.getName() + " uid=" + uid + " packageName=" + packageName);
        }
    }
}
+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;
+5 −0
Original line number Diff line number Diff line
@@ -128,10 +128,15 @@ public class DefaultAppChildFragment<PF extends PreferenceFragmentCompat
            preferenceFragment.setPreferenceScreen(preferenceScreen);
        } else {
            oldDescriptionPreference = preferenceScreen.findPreference(PREFERENCE_KEY_DESCRIPTION);
            if (oldDescriptionPreference != null) {
                preferenceScreen.removePreference(oldDescriptionPreference);
                oldDescriptionPreference.setOrder(Preference.DEFAULT_ORDER);
            }
            for (int i = preferenceScreen.getPreferenceCount() - 1; i >= 0; --i) {
                Preference preference = preferenceScreen.getPreference(i);

                preferenceScreen.removePreference(preference);
                preference.setOrder(Preference.DEFAULT_ORDER);
                oldPreferences.put(preference.getKey(), preference);
            }
        }
+5 −2
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ public class DefaultAppListChildFragment<PF extends PreferenceFragmentCompat
            if (oldWorkPreferenceCategory != null) {
                clearPreferences(oldWorkPreferenceCategory, oldWorkPreferences);
                preferenceScreen.removePreference(oldWorkPreferenceCategory);
                oldWorkPreferenceCategory.setOrder(Preference.DEFAULT_ORDER);
            }
            clearPreferences(preferenceScreen, oldPreferences);
        }
@@ -143,9 +144,11 @@ public class DefaultAppListChildFragment<PF extends PreferenceFragmentCompat
    private static void clearPreferences(@NonNull PreferenceGroup preferenceGroup,
            @NonNull ArrayMap<String, Preference> oldPreferences) {
        for (int i = preferenceGroup.getPreferenceCount() - 1; i >= 0; --i) {
            Preference Preference = preferenceGroup.getPreference(i);
            Preference preference = preferenceGroup.getPreference(i);

            oldPreferences.put(Preference.getKey(), Preference);
            preferenceGroup.removePreference(preference);
            preference.setOrder(Preference.DEFAULT_ORDER);
            oldPreferences.put(preference.getKey(), preference);
        }
    }

+5 −0
Original line number Diff line number Diff line
@@ -116,10 +116,15 @@ public class SpecialAppAccessChildFragment<PF extends PreferenceFragmentCompat
            preferenceFragment.setPreferenceScreen(preferenceScreen);
        } else {
            oldDescriptionPreference = preferenceScreen.findPreference(PREFERENCE_KEY_DESCRIPTION);
            if (oldDescriptionPreference != null) {
                preferenceScreen.removePreference(oldDescriptionPreference);
                oldDescriptionPreference.setOrder(Preference.DEFAULT_ORDER);
            }
            for (int i = preferenceScreen.getPreferenceCount() - 1; i >= 0; --i) {
                Preference preference = preferenceScreen.getPreference(i);

                preferenceScreen.removePreference(preference);
                preference.setOrder(Preference.DEFAULT_ORDER);
                oldPreferences.put(preference.getKey(), preference);
            }
        }
Loading