On LineageOS how to set *Restrict USB* with `adb`?
Feb 15, 5:54pm

On LineageOS (and most Android-based systems), you can use ADB (Android Debug Bridge) to enable or disable the "Restrict USB" setting, which is part of Android's USB Guard or USB restrictions feature. This setting is often used to prevent data transfer or unauthorized access via USB when the device is locked.


Steps to Set "Restrict USB" via ADB

1. Enable USB Debugging

  • Go to Settings > About phone and tap Build number 7 times to enable Developer options.
  • Go to Settings > System > Developer options and enable USB debugging.

2. Connect to ADB

  • Connect your device to a computer via USB.
  • Open a terminal/command prompt and run:
    bash
    adb devices
    (Ensure your device is listed and authorized.)

3. Set "Restrict USB" Mode

Use the following ADB command to enable or disable USB restrictions:

bash
adb shell settings put global usb_restricted_mode [0|1]
  • 0 = Disable USB restrictions (allow data transfer when locked).
  • 1 = Enable USB restrictions (block data transfer when locked).

4. Verify the Setting

To check the current status:

bash
adb shell settings get global usb_restricted_mode
  • Returns 1 if enabled, 0 if disabled.

Notes

  • This setting is enforced when the device is locked (screen off or locked).
  • Some custom ROMs (including LineageOS) may have additional USB-related settings in Settings > System > Developer options or Settings > Security.
  • If the command doesn't work, your ROM may use a different key. Try searching for USB-related settings with:
    bash
    adb shell settings list global | grep usb
Feb 15, 5:54pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.