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

Commit be50a8f6 authored by Jan Tomljanovic's avatar Jan Tomljanovic Committed by Android (Google) Code Review
Browse files

Merge "Require authentication for changing USB preferences." into main

parents e6c3d186 db40deb2
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -20,3 +20,10 @@ flag {
  description: "Gates whether to enable LE audio private broadcast sharing via QR code"
  bug: "308368124"
}

flag {
  name: "enable_auth_challenge_for_usb_preferences"
  namespace: "safety_center"
  description: "Gates whether to require an auth challenge for changing USB preferences"
  bug: "317367746"
}
+14 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import androidx.annotation.UiThread;
import androidx.annotation.VisibleForTesting;

import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.flags.Flags;
import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.core.AbstractPreferenceController;

/**
@@ -61,4 +63,16 @@ public abstract class UsbDetailsController extends AbstractPreferenceController
     */
    @UiThread
    protected abstract void refresh(boolean connected, long functions, int powerRole, int dataRole);

    /** Protects given action with an auth challenge. */
    protected final void requireAuthAndExecute(Runnable action) {
        if (Flags.enableAuthChallengeForUsbPreferences() && !mFragment.isUserAuthenticated()) {
            WifiDppUtils.showLockScreen(mContext, () -> {
                mFragment.setUserAuthenticated(true);
                action.run();
            });
        } else {
            action.run();
        }
    }
}
+13 −11
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ public class UsbDetailsDataRoleController extends UsbDetailsController

    @Override
    public void onRadioButtonClicked(SelectorWithWidgetPreference preference) {
        requireAuthAndExecute(() -> {
            int role = UsbBackend.dataRoleFromString(preference.getKey());
            if (role != mUsbBackend.getDataRole() && mNextRolePref == null
                    && !Utils.isMonkeyRunning()) {
@@ -109,6 +110,7 @@ public class UsbDetailsDataRoleController extends UsbDetailsController
                        mUsbBackend.areAllRolesSupported() ? UsbBackend.PD_ROLE_SWAP_TIMEOUT_MS
                                : UsbBackend.NONPD_ROLE_SWAP_TIMEOUT_MS);
            }
        });
    }

    @Override
+15 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ public class UsbDetailsFragment extends DashboardFragment {

    private List<UsbDetailsController> mControllers;
    private UsbBackend mUsbBackend;
    private boolean mUserAuthenticated = false;

    @VisibleForTesting
    UsbConnectionBroadcastReceiver mUsbReceiver;
@@ -56,6 +57,20 @@ public class UsbDetailsFragment extends DashboardFragment {
                }
            };

    boolean isUserAuthenticated() {
        return mUserAuthenticated;
    }

    void setUserAuthenticated(boolean userAuthenticated) {
        mUserAuthenticated = userAuthenticated;
    }

    @Override
    public void onStart() {
        super.onStart();
        mUserAuthenticated = false;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
+30 −28
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ public class UsbDetailsFunctionsController extends UsbDetailsController

    @Override
    public void onRadioButtonClicked(SelectorWithWidgetPreference preference) {
        requireAuthAndExecute(() -> {
            final long function = UsbBackend.usbFunctionsFromString(preference.getKey());
            final long previousFunction = mUsbBackend.getCurrentFunctions();
            if (DEBUG) {
@@ -161,6 +162,7 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
                    mUsbBackend.setCurrentFunctions(function);
                }
            }
        });
    }

    private boolean isClickEventIgnored(long function, long previousFunction) {
Loading