Friday, November 23, 2018

ADB with Chrome in Mac

So, adb is basically a tool, a command line tool to be specific which is useful to connect to your device and interact with while debugging the apps and many more things.

Nowadays many apps need root access to do certain things but many people like me don't want to root the system as it voids the warranty and also the chances of messing things up increases.

But since the functionality of the app needs certain privileges to do the task, we have to provide them the permissions they are asking for. The other way to do the same is going in the debugging mode and granting the permission via adb command.

But here comes the catch, installing adb is not that straightforward since it needs the drivers as well as the android toolkit in order to talk to those drivers. So keeping that in mind someone (I don't know the name exactly) created a plugin to talk to the phone in Debugging mode and running the commands accordingly.

Pre-requisites:

  1. Chrome (latest version if possible otherwise its ok)
  2. A basic knowledge of what is adb and a command pm
  3. Android Phone (:D)
  4. USB connector (:D)
Here are the steps with snapshots in Mac:
  1. Install Chrome and update if available
  2. Here is the link for ADB for Chrome, link
  3. Install this plugin, it will create a shortcut in the apps shortcut, like this:
  4. Open the app, it will show something like this:
  5. This app internally is dependent on the adb command to detect the devices and run the commands internally.
  6. So let's install adb, for that just one command and that's it
    1. brew cask install android-platform-tools
      1. In case brew is not installed in your mac, I strongly recommend you to install that before going forward, please follow here.
      2. In simple words run:
        /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  7. Now connect your phone and Enable the Developer options & Enable USB Debugging.
    1. Enable Developer options & USB Debugging
      1. For this go to Settings > About Phone > Build Number (tap 7 times)
      2. Go back to Settings, and under system section, you will find one new menu named Developer Options
      3. Go inside that enable Developer Options and USB Debugging
      4. In any step, if you have difficulty please follow here.
  8. Now connect your phone with Laptop and issue a command: adb devices
  9. If steps 6.1 and 7.1 was successful then, you will get a popup in your mobile asking for the confirmation to allow USB debugging with the laptop with some Random id, something like this(this is just an example, found in google :D ):
  10. After you approve this request, it will show your connected phone.
  11. Restart the App (Step 4) and you will find your mobile being showed there like this:
  12. Click the terminal icon and you will get a shell where you can pass you grant permission command easily, like this:
  13. I have taken an example of some Fluid app to show how to grant permission, but we can issue other grant permissions as well.
NOTE:
  1.  In most of the cases, you will find the grant permission command starts with adb shell ..... but just issue the command from the pm word. The reason is that, adb shell .... command is required, in case you are running the command from outside the mobile context. In our case, i.e., once you open the terminal, you are actually inside the mobile, and you don't need the adb command and in fact, you don't have adb inside the mobile, you have in your machine, so for our case, it would be something like:

    pm <sub_command> <package_name_with_settings_name>
  2. Also, this way of granting the permission and all is very dangerous, so be very careful what are you doing and what the app is trying to achieve via that permission. 
  3. I am not at all responsible in case it makes your mobile to malfunction in any way since this post is purely for educational purposes.

Cheers, 
Happy Coding,




No comments:

Post a Comment