Shell scripts for Android | We discuss residents and other useful commands in everyday life.



Rep: (980)
Shell scripts for Android

The topic is devoted to the creation, debugging of scripts on the shell, as well as the development and study of various utilities command line Android.
For the full implementation of the desired under Android, as a rule, you will need root-rights and busybox.
This topic has grown from the topic.Tasker(parent theme), so don’t be surprised if you are suddenly sent there. (Tasker is a shell in Android.) From this topic has grown subsidiaryLinux kernel from the insideAll questions on the kernel should be asked in it.
Recipes, ideas, semi-ready examples.
Interception of hardware buttons, this script began with this script. It is recommended that you read the discussion.original postin the subjectTasker. Over the years, the script has found many different uses, seeMAX 3Tasker in the same topic, recipe "We catch events in logcat" here.
Modern lookto the button interception script: work on errors, performance evaluations, optimization.
Recipes withbusybox inotifyd
- Monitoring block devices(connect / disconnect flash drives and not only)
- Automate downloading files via torrent
- Spy on screenshots
Processing the status bar notificationaka Search in a file by a dynamically formed template from a pipe (pipe), recipes - in the discussion.
Recipes withservice call
- Read / write clipboardvia clipboard service [interfaceIClipboard]
- Mounting / Unmounting Disksvia mount service [interfaceIMountService]
- Enable USB MTPvia usb service [interfaceIusbmanager]
Search for service method numbers forservice call: with Taskertime, two; withusingJaDX (themeon the forum)
Reading contactsthrough contacts provider and utilitycontent
Showdowns with selinux
- More discussion selinux, which are key to understanding the work selinux in Android:
1 + discussion.Start, answerand away we go:note, comment, explanation, clarification, question, answer, end
2 + discussion.question, answer 1, answer 2, one more question, update 1, update 2, report, note, comment, end
- change selinux to support policiesnit.d: recipe itself, toolsandcomment.
We understand with the network routing in Android:Start...end.
We're setting up the network settings throughndc:
- general information onndc: Shell scripts for Android (Post Visitor7 # 58763900), Shell scripts for Android (Post username11 # 58769171)andScripts on the shell under Android (Post Visitor7 # 58784069)
- wifi access point control (tethering)Scripts on the shell under Android (Post kaztost # 58025052)
- installation of the dns server for the interfaceShell scripts for Android (Post Angel_Hranitel # 80575498)
RAM-Drive on Android (with continuation)
How to change init.rc (bottom message)
Tracking changes in a specific directory
Airplane mode (see and below)
Create a swap
We work with API VKontaktethroughcurl
Connect to a given Wi-Fi network
RTFM: materiel, regulatory documentation, literature
Bibliographyon Unix device, list item 1 is mandatory for reading
Shell programming (Unix)textbook A. Soloviev (seed - n. 1 of the above list - certainly preferable to paraphrase)
Help onbusybox
Android regulatory documents:
- Android Architectureaka Android Interfaces and Architecture - internal system device
- Android Core Technologies(Modern name - Configure an Android Device) - that can hack into the system and how to do it right
Hardware: "freezing" applications and components
- explanationon fingers
- discussion of the nuances:question, answer
- from obuzhdeniya above a couple of years there was a storyApplication freeze3 or many bukf
Hardware:character escaping
Shell scripting in the Android environmentXakep article in the magazine for those who are not able to master more or less serious text for sane people - a waste of time
Shell Developer Tools
teamset -x- the debugging tool built into the shell, displays each script command instderr, the details.
wShell- terminal emulator with web interface based on Shell In A Box. If the Android device and the computer are on the same local network, you can access the command line of the device from a computer via a web browser.
Shellcheck- static analyzer (lint) for shell scripts (few details)
Safety Rules. Read a must.
Most commands and scripts hosted in this thread are executed as root. This means that a command (or script), if used improperly, can create new problems and not help solve old ones. And the problems are already big, before which the old ones will seem to be a mere trifle.
Therefore, before you rush to download, drive commands and execute them
1. Make a full backup of the firmware (nandroid backup).
If you do not know what it is, you are in this topic too soon. Read the help sections for newbies on the forum, the theme of the firmware of your device.
"Toy" backups, such as Titanium Backup will not help, if something terrible happens. The backup manager bu built into Android ICS and higher (used by programs like Helium) will also not always help. Do not indulge and do not be lazy, make a normal backup from under the recovery.
2. Made in paragraph 1 backup put in a safe place.
Do not delete it immediately after your experiments have ended, in your opinion, successfully. Android can have a completely different view on their success. Watch the system, live some time in it. If you see strange things, roll back to the saved state. Watch again.
By the way, backup will help and analyze what happened, if something suddenly happens. We may need files from it during the trial.
3. If you don’t understand at all what a particular script does, laid out in the subject, still try to figure it out before you use it.
For some scripts it is necessary to comply with the conditions of their execution, otherwise they will not only not work, but also do something with the system. Easily.
Surely the script as it is laid out will not suit you. You will need to "finish" it to fit your needs.
Finally, the worst (and the most unlikely, but still). You may slip the script that will do something bad. And okay, if simply the files in the system wonders, you performed item 1 of the rules. (True? Exactly sure? Ok, let's believe.) Worse, if the script sends something to a short number in Zimbabwe. Well, there is a credit card, for example. What, no credit cards? Nothing, SMS for a short number in Zimbabwe is not free, you know. And do not think that something will protect you, the script from the root does not catch any antivirus or various security managers. Of course, we will quickly intervene, and the further spread of malware will stop. (But specifically your SMS will leave. In Zimbabwe.)
4. Your device (phone, tablet) is not the only testing ground for your experiences.
Most of the scripts can be checked and debugged on the BB under Linux. Virtual machine and Live distribution is enough. Any Linux distribution. It will take busybox to bring such a polygon closer to the real machine, but in any Linux distribution box, busybox is present.
You can also use the Android emulator. Yes, there is a Google on the farm and such. Lies next to the SDK for Android, an image with Android can be found on the Internet. This is anyway better than killing a real device. I remind you that it cost you a certain amount. (Of course, working in the emulator you are already tired of step 1 of the Rules. You do not need to follow these rules.)
5. For debugging scripts it is better to use not a terminal emulator application, but adb (Android Debug Bridge) or ssh session From BB to the device.
Fingers will break typing characters on the virtual keyboard. Again, make a mistake, make mischief. The client part of adb (for BB) can be found on the Internet, the server part in Android already exists (do not forget to enable debugging in “Settings”). Applications with ssh server can be found on Google Play.

There is no curator in the subject. If there is a user in the subject who wants to become a Curator and the correspondingRequirements for candidates, he can apply in the topicI want to be curator(after having studied the topic header and all materials for curators).
Prior to the appointment of the curator, on filling caps, please contactmoderatorssection through a buttonPictureunder the messages to which you want to add links.


Post has been editedderak1129 - 22.06.20, 23:05
Reason for editing: Notification.



Rep: (758)
ivan1999, / Dev / block / mmcblk1p1 means
blk1 external card (1), blk0 ext. (0)
p1 - ​​the 1st section, etc., if / dev / block / mmcblk1 the entire map of the entire
But I do not advise you to do what you do.
I tried once. The result of this. Applications run under different users, and if the card is in ext2
This leads to the fact that some applications can not read files created by others.
For instance make a photo and gallery can not be considered the file



Rep: (2512)
ivan1999 1. System and its mount, because the sd card can only be fat. 2. A special device for the sd card has a name that depends on the device. However, for each specific device name fixed. Insert the card with the fat, see the device name. There are other ways, it's easier, but they depend on the version of Android.
svs-57 Usually used for such things data2sd.



Rep: (758)
username11, I use a custom kernel with init.d scripts. And added to the mount.
Android starts later and all picks. But with permishenami problems remain. Of course it is possible
search any mount option to overcome it.
And what does not work on data2sd extFat? I have verified that "mount --bind" works. All such team it's used.



Rep: (2512)
svs-57 You with app2sd accidentally confused? If not, then it is clearly not "all." Classic data2sd implemented through symbolic links. You can, of course, through the bind mount. But, I would like to use extFat poosteregsya. Somehow with ext calmer and common attributes, and advanced, and contexts selinux. Yes, and for holes, too. In general, a lot of what is quieter.
Unfortunately, you can not mount the ext to the rights of the user in terms of uid / gid options that are used to implement shared access to sd in Android. Somehow, no one comes to mind, although there is a need. Probably, if you search, you can find the fuse module.



Rep: (8)
Looking for a way to download iptv stream on android
For example, a link to the stream viewhttp: //XXX.YYY.ZZ
The task is to save the file with the name IPTVstream_06.04.2014-23.21.49.ts (example) for this link,
where is 04.04.2014-23.21.49 - this is a temporary variable (for convenience of saving, so that the files do not overwrite each other and the identification)
Windows example
cmd / K "for / f" tokens = 1,2 delims =: "% a in ('time / t') do wget.exehttp: //XXX.YYY.ZZ-O IPTVSTREAM_% date% -% a.% B.% Time: ~ 6.2% .ts "
Advise how you can do it, can it be done with scripting programs like SL4A Script Launcher or can Tasker and wget from busybox?

Post has been editedusername11 - 18.05.19, 11:32
Reason for editing: posts merged



Rep: (758)
cojoc shell + wget. wget and save the name and make of date. The date format can be set.
date +% d.% m.% Y-% H.% M.% S
07.04.2014-01.27.16

wget http:. //XXX.YYY.ZZ -O IPTVSTREAM_`date +% d% m% Y-% H.% M.% S`.


Post has been editedusername11 - 18.05.19, 11:33
Reason for editing: posts merged



Rep: (5)
Advice on how to send the manifest intent to activate the FM transmitter.
doing
root @ android: / # am broadcast -a android.intent.action.MAIN -c android.intent.ca
tegory.DEFAULT -n com.spreadwin.app.fmt / .FMReceiver.MYACTION_CHANGE_STATE -d 1
DEFAULT -n com.spreadwin.app.fmt / .FMReceiver.MYACTION_CHANGE_STATE -d 1
Something does not work. Something I will not understand in the manifest.
The application window is only the scale and frequency checkbox. I only need to include.
I read about Intents and can not figure out where they go and how to pass them. unpacked smali, too rubbish. like as described in xml that much but I can not figure out how to design a query.
<? xml version = "1.0" encoding = "UTF-8"?>
- <manifest android: sharedUserId = "android.uid.system" android: versionCode = "104" android: versionName = "android4.0-2012.02.21-1.0.4" package = "com.spreadwin.app.fmt" xmlns: android = "http://schemas.android.com/apk/res/android">
- <application android: label = "@ string / app_name" android: icon = "@ drawable / icon" android: debuggable = "true" android: screenOrientation = "landscape">
- <activity android: label = "FMT" android: name = android "FM.": launchMode = "singleTask" android: screenOrientation = "landscape">
- <intent-filter>
<action android: name = "android.intent.action.MAIN" />
<category android: name = "android.intent.category.LAUNCHER" />
</ intent-filter>
</ activity>
- <activity android: label = "notification" android: name = "MyNotification.">
- <intent-filter>
<action android: name = "android.intent.action.MAIN" />
<category android: name = "android.intent.category.DEFAULT" />
</ intent-filter>
</ activity>
- <receiver android: name = "FMReceiver.">
- <intent-filter>
<action android: name = "MYACTION_CHANGE_STATE" />
</ intent-filter>
</ receiver>
</ application>
<uses-sdk android: minSdkVersion = "7" />
</ manifest>


Attached files

Attached fileAndroidManifest.zip(634 bytes)


Post has been editedusername11 - 18.05.19, 11:44
Reason for editing: posts merged



Rep: (2512)
sterr1 , Your receiver - com.spreadwin.app.fmt / .FMReceiver, action - MYACTION_CHANGE_STATE. Why are you asking data uri, I do not understand. The problem is that intent MYACTION_CHANGE_STATE may require also additional. settings, extra. That is you, in any, even smali watch to see if and what parameters are passed. No, you can, of course, through dumpsys service activity to try their spy.

Post has been editedusername11 - 18.05.19, 11:45



Rep: (758)
Then I was asked to do the theme SGS4 USB Mass Storage (colloquially mode "stick") to external SD
Spread 2 script.
Attached fileums.zip(597 bytes)

Run as root
ums-enable - incl. UMS
#! / system / bin / sh
umount / mnt / media_rw / extSdCard
echo 0>/ sys / class / android_usb / android0 / enable
echo / dev / block / vold / 179: 33>/ Sys / class / android_usb / android0 / f_mass_storage / lun0 / file
echo mass_storage>/ sys / class / android_usb / android0 / functions
echo 1>/ sys / class / android_usb / android0 / enable
ums-disable - off. UMS
#! / system / bin / sh
echo 0>/ sys / class / android_usb / android0 / enable
echo mtp, acm, adb / sys / class / android_usb / android0 / functions
echo 1>/ sys / class / android_usb / android0 / enable
/ System / bin / sdcard / dev / block / vold / 179: 33 / mnt / media_rw / extSdCard


Post has been editedusername11 - 18.05.19, 11:42
Reason for editing: added script code



Rep: (909)
Tell me, why can incorrectly work getprop ..?
The essence of the problem. If the specified line reading, which contains the text information (getprop ro.manufacturer), then returns to ask if unknown .. line reading, which contains the digits (getprop ro.build.version.sdk), the result is returned normal .. As a result returns a normal , if you read the entire Old (getorop) .. This byaka that the terminal, which through the adb .. .. what's the catch?
Well, as it's
u0_a490 @ unknown: / $ getprop ro.product.manufacturer
unknown
u0_a490 @ unknown: / $ getprop | grep manufacturer
[Ro.product.manufacturer]: [HTC]
u0_a490 @ unknown: / $


Attached images
Attached Image


Post has been editedusername11 - 18.05.19, 11:53
Reason for editing: posts merged



Rep: (165)
sterr1,
echo cmd_on>/ Sys / bus / i2c / devices / 0-002c / on
Where cmd_on value look the same name to FM class.
setprop hw.fmt.audio.speaker 1



Rep: (5)
so that in the garbage, the messages can not be edited.

echo on>/ Sys / bus / i2c / devices / 1-002c / on
It does include a tuner, but usililitel in the correct mode can not be translated.
setprop hw.fmt.audio.speaker 1 does not work, dirty obtained from this sound. When switching through the program's okay. can still somehow Broadcast can be done?



Rep: (165)
sterr1,
am start -a MYACTION_CHANGE_STATE -n com.spreadwin.app.fmt / .FMReceiver



Rep: (2512)
Axell See, getprop - is an applet toolbox. He almost did not do anything, it refers to bionic of two functions, one lists the vsek properties, drgaya - specific. Look in the toolbox sources, you will understand that there is nothing special break. Therefore, the assumption in the order of increasing the fantastic:
1. Is there any type shnyaga xposed or lbe intercepts property_get ().
2. Something is broken in the toolbox
3. Something is broken in bionic.
Given how deeply htc likes to climb unwashed hands in iskhodnoki Android, options 2 and 3 are not so fantastic. Option 1 you think will be able to check for yourself. To check the 2 and 3, I would take a toolbox of deliberately running and close to the problematic firmware. In principle, it is possible and not so close, the applet getprop either earn or toolbox sdampit crust at the start. Naturally, it is impossible to replace the original toolbox, Coverings such as blankets apparatus.
To test 3 have to collect toolbox (or just the applet getprop) from source, statically linked with bionic, not to use the version installed on the machine.
While check these considerations. Option with a broken ashmem and other fiction will work out later. If you do not dig, I will need from you Android version.
Nfc666 In fact, broadcast. He's out there seem to be a real receiver, not the activity.

Post has been editedusername11 - 18.05.19, 11:54



Rep: (5)
Nfc66 you make a mistake.
am broadcast -a MYACTION_CHANGE_STATE -n com.spreadwin.app.fmt / .FMReceiver
But thanks anyway! Everything works as it should.
It acts as a trigger. The first application comprises a second off.
Operation indicator is in /sys/devices/platform/sun5i-i2c.1/i2c-1/1-002c/on in the file contains either "on" or "off"


Post has been editedsterr1 - 19.04.14, 13:59



Rep: (909)
username11, of Caps
umout mht / usb
Do not unmount .. :) Android sees the connection stick. Way mht / usb, storage / usb .. flush mounted machine gun, so I do not know that Spanish-Xia in the mount .. You can catch logkatom, if possible ..
========================
>umount / mht / usb
=======================

failed: No such file or directory
>umount / storage / usb
=======================

failed: Invalid argument
There is no quick unmounting NTS .. We need to go into Settings, Memory ..
And about the prog - there are only those that monitor mount (Total, wire, etc ..), but they use flash or not - I do not know ..
PS .. Hiking is not used, if not go to them ..
Here is the logAttached fileLog.txt(31.4 KB)
Vold involved ..

Post has been editedusername11 - 18.05.19, 16:19
Reason for editing: posts merged



Rep: (863)
Axell @ 30.04.2014, 15:55*
Do not unmount ..

Of Mana:
Useful options when mounting flash drives are Sync and Flush. The first leads to a constant reset to the record buffer disk, so that the data is not lost when the flash disk is disconnected without unmounting. The side effect of such mounting is a significant reduction in recording speed. The second option (available only in new Linux kernels) leads to a discharge of the buffer on the disk after recording the last file. It also contributes to data saving if the disk is removed without unmounting, but does not lead to a drop of recording speed.



Rep: (2512)
In a hat

Axell A) If you edited the vold, then he'll have to explain that it is necessary to dismount, ie vold himself and must then perform the operation unmounting. b) mounting / mht / usb point does not exist or / storage / usb - not a mount point or incorrect arguments at umount, for example, is not specified device. c) It is necessary to call unmountVolume method (String mountPoint, ...). This is done through a utility service, call the team.
1. Study the command service call, if you do not know. I propose to immediately look for in Tasker topic can be here Poshukayte and Google.
Continue until you are reading. We learned how to run a service methods?
2. It is necessary to determine the transaction number and a method arguments.
Take the source code of his version of Android, you learn unmountVolume method in the frameworks / base / core / java / android / os / storage / IMountService.java, see ibid TRANSACTION_unmountVolume transaction number.
3. Find through the same service command server for MountService.
4. service call server transaction path s16
PROFIT!
Fun entertainment I came up with you for the holidays, given that demand will almost anyone to their end? : D
d) Only I advise you to make a backup nandroid. By experience, when people get to the service, the team, they are in some umount not stop. There is vast pool of opportunities. Except that if a transaction number does not guess, is sooo painful.
GrAnd1 @ 30.04.2014, 16:04*
It is available only on Linux newer kernels
Nicho so new, since 2.6.19.
GrAnd1 @ 30.04.2014, 16:04*
leads to the discharge of the buffer to disk after writing the last file
Not. When a disk enters into a state of idle, ie to him will not be appeals.
In general, Russian pedivikiya such pedivikiya.

Post has been editedusername11 - 23.02.20, 15:53
Reason for editing: post is placed in the header



Rep: (909)
username11 @ 30.04.14, 17:04*
.. Only here with the transaction number if not guess, is sooo painful.
Transactions are found number ..
static final int TRANSACTION_unmountVolume = IBinder.FIRST_CALL_TRANSACTION + 6
In two of my OS releases it the same ..
But problems with the server .. How it correctly to find ..?
ZY..Etot or something ..?
19 usb: [android.hardware.usb.IUsbManager]
It turned easily, even neponadobilsya service list .. :)
And how to prescribe the number "6" and "6" ..?
Here he IMountSetviceAttached fileIMountService.java.txt(55.96 Kb)


Post has been editedusername11 - 18.05.19, 16:26
Reason for editing: changed link to post



Rep: (909)
username11, all figured out ..
Just something strange happened ..
The docksTRANSACTION_unmountVolume Under the number 6 And I have a 7 .. 6-ka my mounts ..
How is it ..?

And yes, the script for some reason only for SU works, although to unmount spets.razresheniya not required ..

Still used to learn how to scriptToast to bring you the price would not be .. Mot push in the right direction .. :)

Post has been editedAxell - 30.04.14, 23:35


Full version    

Help     rules

Now: 04.02.21, 14:23