Loading aconfig/settings_connecteddevice_flag_declarations.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -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" } src/com/android/settings/connecteddevice/usb/UsbDetailsController.java +14 −0 Original line number Diff line number Diff line Loading @@ -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; /** Loading Loading @@ -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(); } } } src/com/android/settings/connecteddevice/usb/UsbDetailsDataRoleController.java +13 −11 Original line number Diff line number Diff line Loading @@ -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()) { Loading @@ -109,6 +110,7 @@ public class UsbDetailsDataRoleController extends UsbDetailsController mUsbBackend.areAllRolesSupported() ? UsbBackend.PD_ROLE_SWAP_TIMEOUT_MS : UsbBackend.NONPD_ROLE_SWAP_TIMEOUT_MS); } }); } @Override Loading src/com/android/settings/connecteddevice/usb/UsbDetailsFragment.java +15 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ public class UsbDetailsFragment extends DashboardFragment { private List<UsbDetailsController> mControllers; private UsbBackend mUsbBackend; private boolean mUserAuthenticated = false; @VisibleForTesting UsbConnectionBroadcastReceiver mUsbReceiver; Loading @@ -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); Loading src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java +30 −28 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -161,6 +162,7 @@ public class UsbDetailsFunctionsController extends UsbDetailsController mUsbBackend.setCurrentFunctions(function); } } }); } private boolean isClickEventIgnored(long function, long previousFunction) { Loading Loading
aconfig/settings_connecteddevice_flag_declarations.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -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" }
src/com/android/settings/connecteddevice/usb/UsbDetailsController.java +14 −0 Original line number Diff line number Diff line Loading @@ -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; /** Loading Loading @@ -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(); } } }
src/com/android/settings/connecteddevice/usb/UsbDetailsDataRoleController.java +13 −11 Original line number Diff line number Diff line Loading @@ -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()) { Loading @@ -109,6 +110,7 @@ public class UsbDetailsDataRoleController extends UsbDetailsController mUsbBackend.areAllRolesSupported() ? UsbBackend.PD_ROLE_SWAP_TIMEOUT_MS : UsbBackend.NONPD_ROLE_SWAP_TIMEOUT_MS); } }); } @Override Loading
src/com/android/settings/connecteddevice/usb/UsbDetailsFragment.java +15 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ public class UsbDetailsFragment extends DashboardFragment { private List<UsbDetailsController> mControllers; private UsbBackend mUsbBackend; private boolean mUserAuthenticated = false; @VisibleForTesting UsbConnectionBroadcastReceiver mUsbReceiver; Loading @@ -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); Loading
src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java +30 −28 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -161,6 +162,7 @@ public class UsbDetailsFunctionsController extends UsbDetailsController mUsbBackend.setCurrentFunctions(function); } } }); } private boolean isClickEventIgnored(long function, long previousFunction) { Loading