Shell access via ADB#

Vous pouvez mettre votre appareil UBports en mode développeur, vous permettant alors d’accéder à un shell Bash sur cet appareil depuis votre ordinateur. C’est pratique pour déboguer ou aussi pour un usage plus avancé du shell.

Installer ADB (Android Debug Bridge)#

Tout d’abord, il est nécessaire d’installer ADB sur votre ordinateur.

Sur Ubuntu:

sudo apt install android-tools-adb

Sur Fedora:

sudo dnf install android-tools

And on macOS with Homebrew:

brew install android-platform-tools

Pour Windows, récupérez seulement le paquet correspondant aux outils en lignes de commande depuis cet endroit.

Activer le mode développeur#

Ensuite, vous devrez activer le mode développeur.

  1. Activez le mode développeur (Paramètres système - À propos de - Mode développeur - cochez la case pour l’activer)

  2. Redémarrez votre appareil

  3. Plug the device into a computer with ADB installed

  4. Ouvrez un terminal et lancez adb devices.

Note

Une fois que vous avez fini d’utiliser le shell, c’est une bonne pratique de désactiver le mode développeur.

If there’s a device in the list here (The command doesn’t print « List of devices attached » and a blank line), you are able to use ADB. If not, continue to the next section.

Authorize access to the device#

When using adb for the first time on a computer, the following dialog will appear when you unlock the screen.

../../_images/adb_authorization_prompt.png

This ensures that ADB commands will not work on a new computer unless user unlock the phone and acknowledge the dialog. Selecting « Allow » will make the ADB commands work for this session, and will also remember this computer so that it won’t prompt you again in the future.

Note

If you’re bringing up a port and you require ADB access before the UI is available, you can disable this protection by editing /etc/default/adbd and change ADBD_SECURE=1 to ADBD_SECURE=0.

Frequently used ADB commands#

ADB shell commands:

adb shell — Gives you access to the Linux command-line shell on your device.
adb shell [command] — Runs the specified shell command on your device.

Commandes supplémentaires adb

adb push [source] [destination] — Pushes a file from your computer to your device.
adb pull [destination] [source] — Pulls a file from your device to your computer.

For more ADB commands, refer to the official documentation.

Ajouter des identifiants de matériels#

ADB n’arrive pas toujours à déterminer à quels appareils sur votre PC il doit parler ou pas. Vous pouvez ajouter manuellement l’appareil auquel il ne sait pas comment parler.

Lancez la commande seulement pour l’appareil sélectionné s’il est dessous. Ensuite, lancez adb kill-server suivi par la commande que vous aviez initialement essayé de lancer.

Fairphone 2:

printf "0x2ae5 \n" >> ~/.android/adb_usb.ini

OnePlus One:

printf "0x9d17 \n" >> ~/.android/adb_usb.ini