Enabling tethering programmatically in Android 11 Question - Android Q&A, Help & Troubleshooting

Hi, all.
I normally write my own enable/disable usb tether scripts for each Android version I'm on, but 11 got me stumped. It looks like they've moved the tethering modules to a different location and it doesn't appear tethering can be called from "connectivity" (IConnectivityManager.aidl) any longer.
Android 10:
platform_frameworks_base/IConnectivityManager.aidl at android10-release · aosp-mirror/platform_frameworks_base
Contribute to aosp-mirror/platform_frameworks_base development by creating an account on GitHub.
github.com
line 113: int setUsbTethering(boolean enable, String callerPkg);
changes in 11:
Tethering | Android Open Source Project
source.android.com
"service list" brings up tethering on line 191 with reference to "android.net.ITetheringConnector" which I found below.
Tether-related references in 11:
platform_frameworks_base/packages/Tethering/common/TetheringLib/src/android/net at android11-release · aosp-mirror/platform_frameworks_base
Contribute to aosp-mirror/platform_frameworks_base development by creating an account on GitHub.
github.com
Line 29 Void setUsbTethering(boolean enable, String callerPkg, IIntResultListener receiver); in the above appears to be the command, but I have no idea what needs to happen in the "IIntResultListener receiver" field. I assume something has to happen in this package first:
platform_frameworks_base/IIntResultListener.aidl at android11-release · aosp-mirror/platform_frameworks_base
Contribute to aosp-mirror/platform_frameworks_base development by creating an account on GitHub.
github.com
oneway interface IIntResultListener {
void onResult(int resultCode);
}
Too much of a newb to figure this one out. Any help is appreciated. Apologies if posted in the wrong forum.

bump

Another bump

Was it possible on Android 10? using ADB command..? I found a few mentions on xda / other forums but they are for the old android version. I couldn't find any mentioned for the android 9 / 10 command.

Nope, haven't found anything since and just quit looking.

adb shell service call tethering 3 i32 1
adb shell service call tethering 3 i32 0
allows me to activate and deactivate USB tethering on Android 11. Note that the command returns a sort of error, but tethering actually gets enabled or disabled.

gillux said:
adb shell service call tethering 3 i32 1
adb shell service call tethering 3 i32 0
allows me to activate and deactivate USB tethering on Android 11. Note that the command returns a sort of error, but tethering actually gets enabled or disabled.
Click to expand...
Click to collapse
Thanks! That did the trick, tho it force-restarted the phone every time I tried it. Looks like they've added usb tethering as one of the options to select as soon as you plug the phone in, so makes life a bit easier also.

Related

[Q] hacking the netd daemon to disable "IPv6 privacy extensions"

Android's netd daemon, by default, enables something known as "IPv6 privacy extensions" (this means that the IPv6 address, instead of being generated from the device's MAC address, will be randomized — but this is irrelevant for my question).
In a nutshell, my problem is this: how can I hack, or communicate with, the netd daemon to force it to disable this feature?
(Android offers no configuration for this. I bug-reported the issue to Google ad android bug #31102 aka http : / / code.google.com/p/android/issues/detail?id=31102 (sorry I'm not allowed to post links) but they, of course, ignored it. Please note that there are lots of pages dealing with the question of how to enable IPv6 privacy extensions, because old versions of Android did not enable them: my question is how to disable them, permanently.)
What the netd daemon actually does is that when a network interface $IFACE is brought up, it opens the file /proc/sys/net/ipv6/conf/$IFACE/use_tempaddr and writes "2" there (this asks the Linux kernel to enable the feature). Up to Android 4.2, what I did was binary patch netd to replace the string "/proc/sys/net/ipv6/conf/%s/use_tempaddr" by "/dev/null\000" so the daemon would simply write that "2" to /dev/null and nothing would happen. But in Android 4.3 that part of the code has been slightly refactored, see InterfaceController.cpp from the netd source code, around line 134 (https : / / android.googlesource.com/platform/system/netd/+/android-4.3.1_r1/InterfaceController.cpp — again I'm not allowed to put links, what a pain), so a binary patch is not so trivial. (I could probably replace "use_tempaddr" by "hfr_grzcnqqe", but it would cause an error message in the logs and I'd like to avoid that.)
(Changing netd's source would be absolutely trivial. But I want to avoid recompiling it, because I'd probably spend many sleepless nights getting the correct native toolchain and convincing the Android makefiles to recompile just this bit: I don't have the resources to do a full Android build. Maybe I'm being pessimistic.)
In principle, it seems that netd reacts to commands that are sent to it (see https : / / android.googlesource.com/platform/system/netd/+/android-4.3.1_r1/CommandListener.cpp starting from around line 434). What I don't know is how to communicate with it to send it such commands, let alone do it precisely when a new interface is brought up. I know that at the other end of the line there is, for example, android.net.wifi.WifiStateMachine (see https : / / android.googlesource.com/platform/frameworks/base/+/android-4.3.1_r1/wifi/java/android/net/wifi/WifiStateMachine.java around line 2104). I'm a Linux dev, not so familiar with the Android IPC mechanisms or daemons, so I was hoping someone more knowledgeable could think of a way to pass a command at the right time.
PS: I'm aware that there's an app called to.doc.android.ipv6config which claims to solve the problem I'm talking about. But, looking at the code (https : / / gitorious.org/android-ipv6config/android-ipv6config/source/58e2060162485b54d4f8c147a558aeed708fa4b4:src/to/doc/android/ipv6config/LinuxIPCommandHelper.java around line 103), it's obvious that it does so in a completely wrong way, namely by talking to the kernel, bypassing netd's role as the network gatekeeper altogether.
PPS: I'm using CyanogenMod (currently 10.1.3, and this issue is preventing me from upgrading to 10.2), but I don't think this is relevant at all (I must admit I didn't check to see if CyanogenMod patched netd and/or android.net.wifi.WifiStateMachine in any way).
Meta-question: Is this the right place to ask? Apparently I have to ask 10 stupid questions before I'm allowed to post anywhere else.
Did you ever find a permanent solution? I've been tackling the issue on my new Galaxy S6 using the steps as outlined in this link:
https://www.reddit.com/r/Android/comments/2z1gyo/fix_lollipop_wifi_issues_and_coincidentally_the/
On the chance that someone has this issue and finds this thread ..
As far as I have seen (< 5.0), communication with the network daemon, netd, is done through unix-domain socket IPC on /dev/socket/netd. The commands are of the form:
Code:
interface setcfg [iface name] [options]
Where 'options' includes 'up' and 'down', among others. I have not verified this, but you may be able to do this from the console -- see 'netcfg'. As far as the specific command to do what you are requesting, I would either pull the netcfg executable into IDA or start by looking at the WifiStateMachine. The state machine set sets this option at line 2092 in the source:
Code:
mNwService.setInterfaceIpv6PrivacyExtensions(mInterfaceName, true);
Additionally, you could just pull in the apk for the WifiStateMachine and modify the smali to send false, rather than true, at the line above and you'll have your permanent disable. For this, see /system/framework/*.apk, or equivalent. The WSM implementation should be there somewhere.
-----------
From the source you posted, I found this too ..
Code:
"Usage: interface ipv6privacyextensions <interface> <enable|disable>"

Need help with raw HID access of Bluetooth device from Android 5.0+

Hi all,
The Scenario
We have a bluetooth hardware device that needs to be accessed from a box (owned by client) running Android 5.1.
Box will run a customized version of Android 5.1.
The device works with vendor specific HID reports.
Changes to ROM to allow device to work are allowable.
Attempt 1:
BluetoothInputDevice + HidService
This is a hidden interface in AOSP that can provide raw hid access to bluetooth hid devices. HidService should throw intents containing received reports, and accepts reports through a "Send report" method.
Unfortunately, it didn't work for me at all. I was unable to receive any HID reports.
Attempt 2:
/dev/hidraw0 + /system/bin/hidrawservice + /system/lib/libhidrawservice.so + external/HidRawAccess/HidRawAccess.java
Here, I thought to create a native executable service hidrawservice called from init.rc with elevated privilege to access /dev/hidraw0
hidrawservice exposes its own interface for /dev/hidraw0 (maybe through a unix socket)
A java + native android service comprising libhidrawservice.so and HidRawAccess.java that exposes direct methods for hidrawservice to android java apps.
The Problems:
for 1, I could never receive any HID reports at all in my app. More details: [I cannot post links here, Sorry. Please search stackoverflow with bluetooth hid host. ]
Specifically, I observe Bluedroid doesn't call any callbacks in jni code of HidService when reports are received.
for 2, I am stuck with SELinux. I can verify that through /dev/hidraw0 the HID reports are accessible. hidrawservice when run from adb shell captures reports. But when I start it from init.rc, Its not able to access /dev/hidraw0
I don't have any prior experience on SELinux policies so if anyone could guide me, would be extremely helpful.
I am seeking community help for either of those. I am also open to any suggestions towards this. I am not seeking to disable SELinux.
If it helps, for now, I am developing with a Nexus 7 2013 tablet, And AOSP is 5.1.1_r14, LMY48G.

[GUIDE] How to connect adb over wifi

Heres how to connect to android wear using adb over wifi, theres still some issues, so ill put it here and if someone has some information please share with us:
On wear:
Go to config -> about -> tap the version umber 7 times (it will enable dev options)
Now go back to config menu
Go to developer options
Enable adb (it will also enable the option adb over bluetooth)
On phone:
Open android wear app
Tap the cog icon
Enable Debug over wifi -> Check that the host will be connected (its the android wear)
Now open cmd (you will need to have adb on your path variable):
adb forward tcp:4444 localabstract:/adb-hub
adb connect localhost:4444 // if this gives an error try replacing localhost with 127.0.0.1
adb -s localhost:4444 tcpip 5555 // if this gives an error try replacing localhost with 127.0.0.1
On phone:
Disable adb over bluetooth
Disable bluetooth
On wear:
Go to config -> developer options -> disable the option auto change wifi state
Go to wifi, connect to your wifi
still on wifi, theres an advanced options, there you can get your ip address
on cmd:
adb connect 192.168.1.3:5555 // replace 192.168.1.3 with your android wear ip
THE PROBLEM:
Android wear keeps desconnecting the wifi for a lot of reasons, some that i know:
It detect bluetooth connection (its an automatic power save feature)
But even if you disconnect from bluetooth, sometimes it keep disconnecting.
THE SOLUTION:
I have found a feature under developer options named: Enable wifi state change. This is enabled by default, so disabling it should prevent the wear from disconnecting from wifi, and it does. But sometimes android wear auto enable this feature, even if you turn it off manually. If someone know something about it, or another way to prevent wifi disconnection, please share with us.
On phone:
Open android wear app
Tap the cog icon
Enable Debug over wifi -> Check that the host will be connected (its the android wear)
==============================
Unfortunately doesn't work on my phone, cannot find the "Debug over wifi" option, only Debug over bluetooth available.
The same here!! How did you proceed?
Do you know if there is any way to figure out the port being used?
sagits2016 said:
adb connect localhost:4444 // if this gives an error try replacing localhost with 127.0.0.1
Click to expand...
Click to collapse
Thank you SO MUCH!! I have been trying to connect my watch for days!

[GUIDE] [ROOT] Switch off individual SIMs with Tasker.

X-Posted from the Mi6 forum and Stack Overflow. I wanted to do this the whole time I had my Mi5 (RIP) but couldn't figure out how.
Could anybody test on their Mi5 and let me know if it works?
kylemd said:
I know that looking for this answer has bugged me for the past few years, so figured I'd x-post from Stack Overflow. I have found the solution to switching either SIM off in the Mi6 automatically. Will likely work with other phones.
The whole question and answer you can find on Stack Overflow here.
To get the required index out of your device, you'll need to run the following commands from command prompt:
Download jadx from here
ADB pull the devices framework.jar (adb pull /system/framework/framework.jar)
Open the .jar file with 7-Zip and extract the *.dex files.
Open each .dex file with jadx-gui until you find the one with the following tree: com.android.internal.telephony.ITelephony
Search for the item TRANSACTION_setSimPowerStateForSlot. Note the = x after it; this is the index number.
Now you have the index number you can test the following command in adb shell (or Tasker, with the "run shell" function). You will need to "su" in shell, or set Tasker to "Use Root".
service call phone x i32 y i32 z
Where:
x = index number you fetched previously,
y = your subscription ID (generally, SIM1 = 0, SIM2 = 1)
z = whether on (1) or off (0)
Click to expand...
Click to collapse
Of course, now that you can execute it in Tasker you can now switch either SIM off at specific times.
I've verified that it does indeed switch the SIM off (calls go straight to voicemail right after this command is executed) but I'm unsure of any further effects this switch has.
Enjoy!
Click to expand...
Click to collapse
Click to expand...
Click to collapse

RustDesk service/screen share not auto starting after reboot on Android

I got the following phone:
Moto G Pure | 2021 | 2-Day battery | Unlocked | Made for US by Motorola | 3/32GB | 13MP Camera | Deep Indigo
[https://www.amazon.com/gp/product/B09BTB5MKT/](https://www.amazon.com/gp/product/B09BTB5MKT/)
It has an Android 11 installed.
After installing RuskDesk Version: 1.1.10-1
and granting it the following 4 permissions:
Screen Capture, Input Control, Transfer File and Audio Capture
I was able to connect using the generated id and password and everything was working fine.
After rebooting my phone, I was not able to reconnect anymore. When I opened the app and went to the screen share tab, this what I saw there:
“A Service is not running Tap [Start Service] or OPEN [Screen Capture] permission to start the screen sharing service.”
All the other 3 permissions were already OPEN, it’s just the screen capture that wasn’t.
Is there a setting, adb permissions command or another way to make it automatically start the service/screen capture just like how TeamViewer Host does it?
I found this discussion on github page:
Android - Start on boot not working · rustdesk/rustdesk · Discussion #1516
On android the service doesn't start on boot. It appear that the permission to receive boot completion is commented on AndroidManifest.xml on line 14. <!--<uses-permission android:name="android.per...
github.com
I found in the end of that post they implemented this as a feature here:
Android start on boot (auto start after reboot) by Heap-Hop · Pull Request #3425 · rustdesk/rustdesk
#1516 Enable BootReceiver. Adapt to Android 12 (ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS, SYSTEM_ALERT_WINDOW). add Start on Boot setting option. Permissions detection before Start o...
github.com
But I don’t see an option anywhere in the RustDesk app where to enable start on boot setting assuming this feature already exists in the current version that I’m using? Do you have this option on your app?
I also try to give it the following adb permission:
adb shell cmd appops set com.carriez.flutter_hbb PROJECT_MEDIA allow
But I don’t see evidence it’s being granted when running:
adb shell dumpsys package com.carriez.flutter_hbb
Thank you.

Categories

Resources