The Treehouse Blog

Archive for September 14th, 2017

Automated hotspot control on the Nexus 5x, continued: Android 8

by on Sep.14, 2017, under Android, Happenings

I like Oreos, but every time Google hijacks a new dessert, I need to revist the HSC app to accommodate its new flavor. Sigh.

Firstly, startTethering() now checks for and fails if it is passed a null callback (see here), which I had been doing. You wouldn’t think this would be a big thing to handle. The callback class is ConnectivityManager.OnStartTetheringCallback, an abstract class that is not present in the Android SDK. I’ve still been using reflection to access parts of the System API, as it has seemed to be the easiest approach for this type of thing. However, you can’t create a subclass using reflection. With Dynamic Proxy you could do this if it were an interface, but it’s not.

So I needed to find a better way of compiling against the non-public pieces of the Android API. The way that ended up working for me was to build the SDK from the AOSP sources. Following the documentation, I had a number of build errors having to do with things being defined in multiple places, which I would comment out as I encountered them. Eventually the build was almost successful (seemed to fail on the last step or so), but it got far enough to produce the .../framework_intermediates/classes.jar, which is to have what is needed. After stumbling through various things (I’ve found no great documentation for this), I ended up going with these gradle modifications to let me get at the class in question. I copied the above classes.jar as system_libraries/framework_all-26.jar.

top-level build.gradle, added to “allprojects” block:
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs.add('-Xbootclasspath/p:hsc/system_libraries/framework_all-26.jar:android/net/ConnectivityManager.class')
}
}

app-level build.gradle, added to the “dependencies” block:
provided files('system_libraries/framework_all-26.jar')

With these changes, AndroidStudio still can’t see changes (the IDE is unable to resolve the symbols), but the build process is nevertheless successful. There’s probably a better way, maybe even something trivial, or perhaps using a different IDE that is more flexible, for one.

Secondly, this: Privileged Permission Whitelist Requirement. Enforcement of this started in Android 8.0, and it means that even putting HSC into the /system/priv-app directory is not enough to give it the necessary privileges. Fortunately, adding the necessary permissions to /system/etc/permissions/privapp-permissions-platform.xml is apparently sufficient:

<privapp-permissions package="me.alleman.brady.hsc">
<permission name="android.permission.CHANGE_NETWORK_STATE" />
<permission name="android.permission.CHANGE_WIFI_STATE" />
<permission name="android.permission.ACCESS_WIFI_STATE" />
<permission name="android.permission.CONNECTIVITY_INTERNAL" />
<permission name="android.permission.TETHER_PRIVILEGED" />
<permission name="android.permission.ACCESS_NETWORK_STATE" />
<permission name="android.permission.MANAGE_USERS" />
<permission name="android.permission.WRITE_SETTINGS" />
</privapp-permissions>

The updated package, in case you find it useful: hsc8.apk

Comments Off on Automated hotspot control on the Nexus 5x, continued: Android 8 more...

September 2017
S M T W T F S
 12
3456789
10111213141516
17181920212223
24252627282930

Archives

Content Copyright © 2004 - 2019 Brady Alleman. All Rights Reserved.

As an Amazon Associate I earn from qualifying purchases.