Archive for February, 2016
Automated hotspot control on the Nexus 5x
by balleman on Feb.07, 2016, under Android
There are few things more frustrating than when an upgrade causes the loss of features you depend upon. In the case of my upgrade from the Nexus 4 to the Nexus 5x (and therefore from Android 5 to 6, ahem, Lollipop to Marshmallow) I lost my automation that would enable the WiFi hotspot while in my vehicle. Tethering works fine by enabling it through Settings, but it generates an error when enabling it with Macrodroid.
Enabling the hotspot is not something that is accessible from a public API, so the ordinary method seems to be to use reflection to make the change using the private API.
From setWifiApEnabled()
, eventually enforceTetherChangePermission()
is called in ConnectivityManager.java. This method checks if config_mobile_hotspot_provision_app
is set, and if so, requires the CONNECTIVITY_INTERNAL
permission which is only granted to system applications.
The cause of my problem, therefore, seems to be that “Entitlement APP provisioning for Tethering” (config_mobile_hotspot_provision_app
) is enabled in the Nexus 5x-specific configuration for at least my mcc/mnc, and was not present on the Nexus 4.
After not finding any other applications or configuration to solve this problem, the path I went down was to create my own system application with the CONNECTIVITY_INTERNAL
permission, to see if it could enable the hotspot. I was successful, so I implemented the application as a Locale plugin (i.e., quickly hacked it together with the example plugin) so that it could be called directly by Macrodroid. This seems to be working fine. You can (at your own risk) download it here and then you will need to move it into /system/priv-app for it to get the privileges of a system application, probably using your recovery image (TWRP, for instance).
It may also be possible (and perhaps better) to resolve this by removing the config_mobile_hotspot_provision_app
configuration, after which it should be possible to use the native Macrodroid hotspot actions, as described here, but I’ve not tried it yet for myself.
Update 2016-09-10: For Android 7 / Nougat, the permission required is now TETHER_PRIVILEGED
, but otherwise the above method still works. An updated APK is here.