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

Commit abf2ad0a authored by Priaynk Singh's avatar Priaynk Singh Committed by Priyank Singh
Browse files

Adding the functionality to toggle the switch when clicked on the row.

This is to toggle the apps permission.

Test: Manual
Bug: 111965198
Change-Id: Ia7652f6596b1e3518ddc8f0a006b2e6222ef11b8
(cherry picked from commit eaad4fed8c8ced5748fdfecee27a94d3dd9a0127)
parent c19031a7
Loading
Loading
Loading
Loading
+36 −22
Original line number Diff line number Diff line
/**
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +13,6 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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


@@ -63,6 +62,7 @@ public final class AppPermissionsFragment extends Fragment{

    /**
     * Creates a new instance.
     *
     * @param packageName the packageName of the application that we are listing the
     *                    permissions here.
     */
@@ -172,6 +172,8 @@ public final class AppPermissionsFragment extends Fragment{

    private class PermissionLineItem extends TextListItem {

        private boolean mSwitchState;

        PermissionLineItem(AppPermissionGroup permissionGroup, Context context) {
            super(context);
            setTitle(permissionGroup.getLabel().toString());
@@ -182,7 +184,20 @@ public final class AppPermissionsFragment extends Fragment{
                    permissionGroup.areRuntimePermissionsGranted(),
                    /* showDivider= */ false,
                    (button, isChecked) -> {
                        if (isChecked) {
                        mSwitchState = isChecked;
                        updatePermission(permissionGroup, context, mSwitchState);
                    });
            setOnClickListener(v -> {
                mSwitchState = !mSwitchState;
                setSwitchState(mSwitchState);
                updatePermission(permissionGroup, context, mSwitchState);
                notifyDataSetChanged();
            });
        }

        private void updatePermission(AppPermissionGroup permissionGroup, Context context,
                boolean isGranted) {
            if (isGranted) {
                permissionGroup.grantRuntimePermissions(/* fixedByTheUser= */ false);
                return;
            }
@@ -201,7 +216,6 @@ public final class AppPermissionsFragment extends Fragment{
                                    permissionGroup.revokeRuntimePermissions(
                                            /* fixedByTheUser= */ false))
                    .show();
                    });
        }
    }
}