Can i enable USB tethering with SL4A? - android

I have had searched in API reference for a class/method to enable USB tethering, but found none. I wonder if it's still possible.
For information, I use a rooted HTC Wildfire with Cyanogenmod 7 and Android 2.3.7.
If it's not possible, I'm interested for a Java sample code to do it.

Not using the built in APIs (as you've checked), which simply means no, not if you're not willing to do a bit of work.
If, however, you are using Beanshell, JRuby or Rhino, then as per the SL4A FAQ ("API bridge?" question), "you can invoke Java calls directly" suggesting to "See the documentation for those interpreters" for how to do so (though I couldn't find it). However on the Unofficial Releases page, it states that:
"Beanshell and Rhino can both directly access the android api.
However, many Android api calls required a context, which, due to the
way they are run, these interpreters don't have. A solution is being
sought... suggestions appreciated."
And as per this answer, I believe a Context is required, though I may be wrong.
Finally, your last option would be to clone the source code for whatever interpreter you're using and add the call(s) your require. Quoting the FAQ again; "The RPC layer is easy to extend." and there's even a little walkthrough for it.
Good luck!

If you have root enabled, you by just try to do it whithoug SL4A or Android. I use this script:
#!/system/bin/sh
iptables -D droidwall-3g -m owner --uid-owner 0 -j RETURN
iptables -I droidwall-3g -m owner --uid-owner 0 -j RETURN
iptables -t nat -D POSTROUTING -o rmnet0 -j MASQUERADE
iptables -t nat -I POSTROUTING -o rmnet0 -j MASQUERADE
echo 1 > /sys/class/usb_composite/rndis/enable
ifconfig usb0 192.168.42.129 up
echo 1 > /proc/sys/net/ipv4/conf/usb0/forwarding
echo 1 > /proc/sys/net/ipv4/conf/rmnet0/forwarding
Maybe for other devices (mine is SE Xperia X10) you need to adjust things like /sys/class/usb_composite/rndis/enable.

Related

How to set SELinux to 0 or permissive mode in android 4.4.4 and above?

I want to set the SELinux (Security Enhanced Linux) mode to Permissive or (0) on android 4.4.4 (and above if possible). I use the following command: setenforce 0, setenforce permissive and setenforce Permissive under root (my device is rooted). But the output of getenforce is always Enforcing. Now I am exhausted with this problem.
Can any one give me a solution? Thanks in advance.
Depending on how your device was rooted and what Android ROM your running will determine how you can disable it. The first thing to try is:
adb shell su 0 setenforce 0
This is NOT the same as:
adb shell setenforce 0
The execute on su causes a domain transition from shell (which cannot setenforce) into the su domain (which can call setenforce). For instance, run:
$ adb shell id -Z
context=u:r:shell:s0
compared to:
$ adb shell su 0 id -Z
context=u:r:su:s0
This may fail for three reasons:
You do not have the su executable
The su executable has the wrong label
The su domain rules were not compiled into the bootimage
To correct issue 2, you can (assuming adb is root):
adb remount
adb shell chcon /system/xbin/su u:object_r:su_exec:s0
This might fail, which will likely indicate issue 3. To fix issue 3, you need to recompile a boot.img that contains the su policy files. If you're compiling AOSP, just lunch a userdebug or eng variant of your device.
Another approach, would be to remove the functionality from init.c, and like issue 3, requires a recompile of the boot.img. Go into system/core/init/init.c (or .cpp) and remove all calls to security_setenforce().
Additionally, XDA has an application that may help automate this process and make it easier, however, I cannot speak to the quality of the application:
http://www.xda-developers.com/easily-change-your-android-selinux-mode/
Apparently Google has removed the CONFIG_SECURITY_SELINUX_DEVELOP kernel flag from many of their Stock kernels. Thus the standard trick mentioned by William (below) probably doesn't work. An example of these devices is the Samsung Note 4 (SM-N910F) running AOS 4.4.4.
The link above states:
CONFIG_SECURITY_SELINUX_DEVELOP aka global permissive mode, is useful for
when you are first developing device-specific policy for a board (add
'androidboot.selinux=permissive' to BOARD_KERNEL_CMDLINE). It also
permits transient setenforce 0 in -userdebug or -eng builds, which can
be helpful for developers.
If the bootloader is locked, then you can't modify the kernel cmdline
"Also, the code in the init program for processing the
androidboot.selinux= option is only compiled in -userdebug and -eng builds, so even aside from bootloader locking, you cannot use
androidboot.selinux=permissive on a -user build."
The way to check what build type you have is:
$ getprop ro.build.type
user
MUST BE ROOTED! Not sure if this works on KitKat (it should) but I use this on my Nexus 6. Run following in terminal or ADB Shell:
su
mount -o remount,rw /system
mkdir /system/su.d
echo "#!/system/bin/sh" > /system/su.d/permissive.sh
echo "echo 0 > /sys/fs/selinux/enforce" >> /system/su.d/permissive.sh
chmod 755 /system/su.d/permissive.sh
And check it after reboot by this:
su
/system/bin/getenforce

How do I start the wpa_cli on android device?

I've rooted my android device because I'm trying to make it detect ad-hoc wifi.
I installed BusyBox pro and then I typed in the adb shell:
su -c "/system/bin/wpa_cli -p /data/misc/wifi/"
in order to start the wpa_cli shell it returned
/system/bin/sh: wpa_cli: not found
and I'm really confused. I wonder on what I missed. Can anybody help?
The wpa_cli shell is only needed to operate and monitor wpa_supplicant. If the WPA system is already configured, wpa_cli is not needed at runtime. Many manufacturers remove the wpa_cli executable from their systems to prevent users from changing how wifi is working. The Google Nexus devices include wpa_cli in their eng and userdebug builds, and may even include it in the user builds.
I would find the exact OS version on your device, check out an AOSP sandbox branched to that same version, and then build wpa_cli. This can be done by using lunch to select your device, and then do an "mma" in external/wpa_supplicant_8. You can then push wpa_cli from $OUT/system/bin onto your device at /system/bin, and it should run.
You should use wpa_supplicant instead of wpa_cli.
Make sure you have wpa_supplicant first by ls /system/bin | grep wpa

Android shell script grep

I'm attempting to write a script using the Android shell (with Busybox) to scan through some .xml files to extract information, however, I'm getting stuck on some optimization.
Shouldn't, for example,
(ax)b
match to
axbxc
It doesn't; when I try to execute this on Android (4.2.2, with Busybox 1.20.2, if it matters?).
echo axbxc > \sdcard\test.txt
grep "(ax)b" \sdcard\test.txt
returns nothing, while
grep "axb" \sdcard\test.txt
returns, as expected,
axbxc
Similarly, shouldn't
(?>ax)b
return axbxc as well? (This is the actual optimization I want to apply.)
What could be causing this problem? Additionally, does anyone know what regex engine Busybox uses, so that I can go and read up on it specifically?
To enable extended regular expressions in grep (and in busybox grep), you need to either use grep -E or use egrep (egrep is shortcut for grep -E).
I have tested this with busybox grep, and both methods work as expected and match your regex.
As for (?>ax)b - this would work only if you can use grep -P (support for Perl compatible regexes). However, busybox grep does not support this switch, so look-ahead and look-behind matches won't work.

Android Iptables: Can´t drop port

I try to iptables -A OUTPUT -p tcp --sport 5228 -j DROP but it comes to failure messages:
FIX ME! implement getprotobyname() bionic/libc/bionic/stubs.c:378
I have an rooted device and busybox on it. Strange is that if I see the rules list of iptables this port is in it. I´m not sure does it work? What is my problem?
Seems like a known bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=558415
It lists workarounds if you're interested.
Use protocol numbers (-p 6) instead of names (-p tcp):
iptables -A OUTPUT -p 6 --sport 5228 -j DROP
See this answer for more info:
getprotobyname error iptables

Looking for iptables binary for Android 2.3 ARM platform?

I am trying to setup a proxy on an Android device using iptables. We are using Androd 2.3. I don't see iptables in emulator or in our platform build.
Where can I download a prebuilt iptables binary (and all supporting libs it needs) for setting up a NAT like rule?
I like to run it like this eventually:
iptables -t nat -A PREROUTING -p tcp --dport 24 -j REDIRECT --to-port 7060
Thanks
I'm not aware of any pre-built iptables binary that android is supposed to have. That said, you could probably build iptabels for you device using the source code found here.

Categories

Resources