3

My screen got broken and I've been using my phone with a VNC Server installed on it, but this morning i'd the stupid idea of enable hotspot just to see if I can use my mobile data plan on my laptop, but when I did this, the wi-fi got disconnected from my router and now i only have access to my phone using adb shell.

I need to disable hotspot from ADB, already searched on google but didn't find anything, i also tried disable and enabling wi-fi, doesn't works.

1

A cleaner way to do it is by calling "service call" command.

For example on my phone I could call

# Start Wifi tethering
adb shell service call connectivity 24 i32 0 
# Stop Wifi tethering
adb shell service call connectivity 25 i32 0 

Service call will call the function number 24 in connectivity service (which happened to be the function that turn on tethering) and pass it 0 as argument (0 would be wi-fi tethering, 1 would be usb tethering and 2 would be bluetooth).

Sadly service functions code change from one android version to another. This stackoverflow reply explain how to get the right function code for your current android version. https://stackoverflow.com/questions/20227326/where-to-find-info-on-androids-service-call-shell-command

Also this is the functions list for connectivity service for the android version I am using (Nougat) https://android.googlesource.com/platform/frameworks/base/+/android-7.1.2_r1/core/java/android/net/IConnectivityManager.aidl

  • Looks like I'm missing some permissions, can see that in the parcel-log i get when executing the command – Sigma Nov 3 at 21:32
  • 1
    Yes, I forgot to say that you need to be rooted to be able to do this so you need to execute the "su" command before running any of these. – Ramast Nov 4 at 21:15
5
  adb shell input keyevent 3 # home   

  adb shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings

  adb shell input keyevent 20 # down                                                   

  adb shell input keyevent 20 # down

  adb shell input keyevent 20 # down

  adb shell input keyevent 66 # enter

  adb shell input keyevent 20 # down

  adb shell input keyevent 20 # down

  adb shell input keyevent 66 # enter                                                 

  adb shell input keyevent 20 # down

  adb shell input keyevent 66 # enter
  • +1. This is helpful though in my CM12 I had to add some more keyevent 20 and 66 but it works well. Good! – Firelord Jun 2 '15 at 17:25
  • 2
    By using this question, the solution can be decreased to just three steps :- adb shell am start -n com.android.settings/.TetherSettings -> adb shell input keyevent 20 -> adb shell input keyevent 66 . Done! – Firelord Jun 2 '15 at 18:37
  • This worked for my Nexus 6 on Android 5.0 to enable WifiTether but I had to add one more keyevent 20. Seems 5.0+ has borked the ability to enable WifiTether from a Tasker plugin or from Tasker itself. There's really no am start command that will start hotspot directly? – Kristopher Dec 28 '15 at 16:00
  • hahaahh awesome – deFreitas Sep 11 '16 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.