[HOWTO] Use pattern lock and device encryption - Android General
Normally, a pattern/gesture lock is not available when device encryption is activated.
But the lockscreen can be reactivated by changing the corresponding settings in /data/data/com.android.providers.settings/databases/settings.db to the values used for the pattern lock before enabling device encryption, namely resetting lockscreen.password_type to PASSWORD_QUALITY_SOMETHING.
If you don't run Android 4.0.4, you may verify that android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_SOMETHING still corresponds to 0x10000.
Enter a root shell and execute:
Code:
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='65536' WHERE name = 'lockscreen.password_type'"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='1' WHERE name = 'lockscreen.patterneverchosen'"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='1' WHERE name = 'lock_pattern_autolock'"
Generate a new gesture.key with the attached perl script (call it without arguments for help) and transfer it to the device:
Code:
mv gen-gesture.key.pl.txt gen-gesture.key.pl && chmod +x gen-gesture.key.pl
./gen-gesture.key.pl 01258 > gesture.key
adb push gesture.key /mnt/sdcard/Download/
adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
^C
Reboot the device.
This was tested on my Samsung Galaxy S3 with Android 4.0.4.
Thanks to robberknight who initiated a thread about PIN locks and encryption.
Thanks for the post!
I tried this today with my Samsung Galaxy Note 2 but it didn't work (Android 4.1)
The only thing I couldn't do (regarding to your how-to) was using the sqlite3 command from the shell, because there is no sqlite3 on my device (installing it with "SQLite Installer for root" didn't work either, I'm getting a "CANNOT LINK EXECUTABLE" error). So I just pulled the settings.db to my computer, editied it with an sqlite-manager and pushed it back. But I guess this shouldn't make any difference ...
I simply can't get rid of the password unlock screen, no matter what I enter in the sqlite database.
And I would be happy if I could even use a PIN instead of an alphanumeric password (which is the only option for encryption now)
By the way, what did you mean with "If you don't run Android 4.0.4, you may verify that android.app.admin.DevicePolicyManager.PASSWORD_QUA LITY_SOMETHING still corresponds to 0x10000."?
On my phone this constant is 65536
Right now this would be my lock-settings from the settings.db:
"103","lock_after_timeout_rollback","60000"
"35","lock_motion_tilt_to_unlock","0"
"107","lock_pattern_autolock","1"
"108","lock_pattern_visible_pattern","0"
"104","lock_screen_lock_after_timeout","60000"
"94","lock_screen_owner_info","..."
"95","lock_screen_owner_info_enabled","1"
"59","lock_screen_quick_note","1"
"36","lock_signature_visible_pattern","1"
"29","lockscreen.disabled","0"
"109","lockscreen.lockexchange.enable","0"
"34","lockscreen.options","enable_facelock"
"105","lockscreen.password_type","65536"
"106","lockscreen.patterneverchosen","1"
Found the solution on my own: Just delete the /data/system/locksettings.db (this one was empty on my device anyway)
After a restart the lock-keys of settings.db now finally work. I guess there is some caching in place and removing the locksettings.db forces Android to update the settings of the lock-screen.
Hello!
This sounds very interesting.
How to define the unlock pattern:
Does the perl-script create a pattern/gesture that corresponds to the digits you entered. In your example:
gen-gesture.key.pl 01258 > gesture.key - This makes your pattern 01258? (Since there is no dot inte 3x3 pattern matrix to represent a "0" then this cannot be correct.)
How do I define the pattern I want to use then? Is this done separately by going in to the settings later when the phone is booted? I don't dare to do this in fear of "locking" the device with a pattern/gesture that I don't know.
I hope to get your help here...
Thank you!
Thank you very much mod23! My phone is finally usable again
Works as described on Galaxy R with leaked ICS.
-Android Freak- said:
This makes your pattern 01258? (Since there is no dot inte 3x3 pattern matrix to represent a "0" then this cannot be correct.)
Click to expand...
Click to collapse
Was confused at first as well, but running the perl script without arguments tells us:
0 1 2
3 4 5
6 7 8
Afterwards, you won't be able to change it in the settings. I think you have to newly generate the gesture.key
Warning
I do not want to give lessons to anybody, but just to highlight how the unlock pattern protection is low, thwarting almost certainly the extra layer of protection that is supposed to be brought by Android full-phone encryption. Just consider the following remarks:
1) Contrary to a PIN code, pattern lock equivalent digits will be linked to each other (except if you are really really cunning). For example, if you start at digit 0, the following digits are to be 1,4 or 3. Thus decreasing dramatically the entropy of the underlying number.
2) You can't use the same digit two times. As an example, try the greek PHI symbol. The equivalent PIN code can't be 03452147, because 4 can't be used two times. The equivalent code must be simpler: 034521 7. You will agree that this greatly reduces the number of possible equivalent PIN codes you can achieve with pattern lock.
3) The protection mechanism offered by Android is way too weak in my opinion for such lock mechanism. After 3 failed attempts, your phone just ask you to wait for 30 sec. It does not shutdown.
4) But the killing argument is: you have grease under your fingers. Except if you systematically think to wipe the screen of your phone after unlocking your phone, the gesture will let a fingerprint corresponding to the gesture you will repeat several times per day. Try by yourself, and see how easy it is to see the lock pattern used with an oblique light source.
So, if I was to steal your phone to have access to your personal data you think secured by encryption, I would
1) Steal your phone when it is on
2) Realize that it is "protected" by lock pattern
2) Use an oblique light with the almost certainty that I will see the fingerprint of the pattern lock (except if you wipe systematically your screen, or you wash your hands always before unlocking your phone).
3) Try to draw the pattern in one direction.
4) Try it in the other direction if it fails. Almost sure to unlock the phone at this point (except if the pattern is really really intricate).
5) Once your phone is unlocked, I could do whatever I would want to with it. So no need to be the king of crackers.
I hope, after reading this, you will reconsider using pattern lock in parallel to encryption. In my opinion, it is a total nonsense. But it is my only personal opinion. Just judge by yourself.
Edit:
------
For me, the only way, both secure and practical, to secure your phone is by using a PIN code of at least 4 numbers (6 is better). PIN codes let fingerprints much harder to "interpret" than unlock pattern. Then use a handy tool like EncPassChanger to have a true complex password for decryption at boot time. And, if you are clearly paranoid, follow this great tip: http://forum.xda-developers.com/showpost.php?p=26730989&postcount=2.
And, something that people may forget, always double check that USB debugging is disabled.
lolo250612 said:
For me, the only way, both secure and practical, to secure your phone is by using a PIN code of at least 4 numbers (6 is better). PIN codes let fingerprints much harder to "interpret" that unlock pattern. Then use a handy tool like EncPassChanger to have a true complex password for decryption only at boot time. And, if you are clearly paranoid, follow this great tip: http://forum.xda-developers.com/showpost.php?p=26730989&postcount=2.
Click to expand...
Click to collapse
There is one big problem with your solution: The SD card. The SD card is encrypted with your PIN Code as well, which is stored in the same file as your screen-unlock-PIN code. I have no idea why the Google developers choose to use the same file for everything, but they did. So your solution is a good idea as long as you don't care about the security of your SD card.
On my phone (Lenvo A789, with ICS 4.0.4), the sdcards (both internal and external) are not encrypted at all. Only /data and other "system" partitions. You can view them with Terminal Emulator, by typing the mount command. The encrypted partitions correspond to /dev/block/dm-x (x is a number). Just to be clear, I mean "sdcards", the partition /mnt/sdcard or /mnt/sdcard2 as reported by Android and mounted as such.
Anyway. I am certainly not an expert in security. I am just trying to document myself to have an overview of the security mechanisms I use. But, if I am right, your encrypted partitions are not encrypted directly with your password or your PIN code. They are encrypted by a random key generated by Android when you start the encryption process. This master key is then encrypted itself at first by your PIN code (if you choose this option) before being saved in a file. That's what allows the user to change his password without having to re-encrypt everything. And I agree with you, this is a major security flaw, as a password with only digits can be cracked in a few µsec by a casual PC, if somebody has access physically to the content of your phone memory and this key file.
This is where EncPassChanger acts. It reencrypts your master key (not the data itself) with a password that can be complex as you don't type it everytime you unlock your phone.
So you have your PIN code to unlock your phone when it is on ( and only when it is on); it does not decrypt anything, decryption only occurs at boot time; it just gives you access to the UI and allows you to interact with your phone. And you have a strong password for the encryption of the data that lay physically on the memory (even when the phone is off), that allows Android to decrypt your master encryption key at boot, and therefore your data. And the PIN code cannot be used to decrypt your encryption master key any longer.
"Online" protection (phone lock) and "offline" protection (encryption of data lying "physically" on the memory) are really two different things. They become completely disconnected from each other once you use EncPassChanger to make the encryption/decryption password different from the initial PIN code. The only thing you have to be careful about, is that if you change your PIN code for whatever reasons, Android reencrypts the master encryption key with this new PIN code, droping the job done previously by EncPassChanger. So you have to use it again.
And the fact that, for a reason I don't see clearly, your sdcard would be encrypted as well as /data, does not change anything to that.
But I may be wrong, don't I ?
For more extensive details, see: http://nelenkov.blogspot.fr/2012/08/changing-androids-disk-encryption.html and http://source.android.com/tech/encryption/android_crypto_implementation.html
And even more details (Android encryption is in fact more or less Linux LUKS): http://www.markus-gattol.name/ws/dm-crypt_luks.html
Confirmed working on Nexus 10 and Nexus 4 with 4.2.2
Check for records in settings.db first!
If they don't exist, use this method.
On newer devices, the fields above do not exist in the settings.db file once encryption has been activated. The proper way to do this for a device is to confirm the settings are there, and if not, go through the below process (note the INSERTs instead of UPDATEs).
Create gesture.key using the Perl script and copy to SDCARD
Ensure device is unlocked and keep screen active while running the below code. If the device locks, you can get stuck on a black screen after removing /data/system/locksettings.db.
Run the below code.
Code:
su -
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lockscreen.password_type', '65536')"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lockscreen.patterneverchosen', '1')"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lock_pattern_autolock', '1')"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lock_pattern_visible_pattern', '1')"
cat /mnt/sdcard/gesture.key > /data/system/gesture.key
rm /data/system/locksettings.*
Reboot
Lastly, combine with EncPassChanger to use a 20+ character encryption password at boot to ease your mind about brute force attempts.
Thanks,
Ben
Fmstrat said:
Confirmed working on Nexus 10 and Nexus 4 with 4.2.2
Check for records in settings.db first!
If they don't exist, use this method.
On newer devices, the fields above do not exist in the settings.db file once encryption has been activated. The proper way to do this for a device is to confirm the settings are there, and if not, go through the below process (note the INSERTs instead of UPDATEs).
Create gesture.key using the Perl script and copy to SDCARD
Ensure device is unlocked and keep screen active while running the below code. If the device locks, you can get stuck on a black screen after removing /data/system/locksettings.db.
Run the below code.
Code:
su -
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lockscreen.password_type', '65536')"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lockscreen.patterneverchosen', '1')"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lock_pattern_autolock', '1')"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lock_pattern_visible_pattern', '1')"
cat /mnt/sdcard/gesture.key > /data/system/gesture.key
rm /data/system/locksettings.*
Reboot
Lastly, combine with EncPassChanger to use a 20+ character encryption password at boot to ease your mind about brute force attempts.
Thanks,
Ben
Click to expand...
Click to collapse
Thanks for the update. I want to give this a try on my Razr Maxx HD running 4.1.1, any idea if this will work? Also, in your info here, your code says:
Code:
('lockscreen.password_type', '65536')"
But isn't it impossible to use the same number twice? Not sure I understand this correctly if that is a true pattern lock sequence.
gadsden said:
Thanks for the update. I want to give this a try on my Razr Maxx HD running 4.1.1, any idea if this will work? Also, in your info here, your code says:
Code:
('lockscreen.password_type', '65536')"
But isn't it impossible to use the same number twice? Not sure I understand this correctly if that is a true pattern lock sequence.
Click to expand...
Click to collapse
I don't see any reason why it wouldn't work, but of course, no guarantees. As for the password_type, 65536 is a code saying "use the pattern lock", it is not the same as the string of numbers used with the python file to create your gesture.key file.
Thanks,
Ben
Fmstrat said:
Confirmed working on Nexus 10 and Nexus 4 with 4.2.2
Check for records in settings.db first!
If they don't exist, use this method.
On newer devices, the fields above do not exist in the settings.db file once encryption has been activated. The proper way to do this for a device is to confirm the settings are there, and if not, go through the below process (note the INSERTs instead of UPDATEs).
Create gesture.key using the Perl script and copy to SDCARD
Ensure device is unlocked and keep screen active while running the below code. If the device locks, you can get stuck on a black screen after removing /data/system/locksettings.db.
Run the below code.
Code:
su -
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lockscreen.password_type', '65536')"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lockscreen.patterneverchosen', '1')"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lock_pattern_autolock', '1')"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) values ('lock_pattern_visible_pattern', '1')"
cat /mnt/sdcard/gesture.key > /data/system/gesture.key
rm /data/system/locksettings.*
Reboot
Lastly, combine with EncPassChanger to use a 20+ character encryption password at boot to ease your mind about brute force attempts.
Thanks,
Ben
Click to expand...
Click to collapse
Ok, I'm ready to do this, but I am afraid I have no idea what I'm doing! I couldn't find the settings.db like you said might happen. I tried running the perl script, but got permission denied when it tried to create /data/system/gesture.key. It did create the key and push it to the device, but then it stopped there.
After I verified it did push the gesture.key, I tried running the sqlite3 code in root shell. Some of the commands said adb does not recognize this command as an internal or external command. I have never ran commands like the ones shown here for sqlite3. My adb experience is pretty limited to following directions to root. I have done manual roots in adb, so I understand some basic commands, but this is out of my league! Can you help me a little bit to do this with some steps that are more beginner-ish? If you can help me out (PM is fine), I'll be glad to type out the instructions in an organized way for others to follow in the future. I really want to be able to set this up, any help would be greatly appreciated.
Ok, I think I need to stop messing with this now, been working on it all day! I ran all the sqlite3 commands you said, and got stuck at the cat command. It says no such file or directory. I think I did the perl script wrong and never got the gesture key done right. It pushed a file called gesture.key, but I don't know if it's right. I am not sure how to run the perl script, really. I have to get back to my job that I haven't done anything at today, yikes! Any help is appreciated.
Ok, I didn't quite understand the concept of how this worked yesterday, so I spent some more time on it today. I thought the perl script was to be ran from the PC. I didn't understand that I was supposed to be loosely following the steps in the other thread referenced here. Having no experience whatsoever with python, I didn't know what to do. Now, I understand the process, I am just having a little trouble. So far I have followed these instructions.
Fmstrat said:
Check for records in settings.db first!
If they don't exist, use this method.
Click to expand...
Click to collapse
I looked and could not find this, so I proceeded as described.
azoom1 said:
1) Load SLA4
2) Menu-View-Interpreters
3) Menu-Add
4) Select Python 2.6.2 - the SLA4 app will go get Python and intall it with the correct linking
5) Exit SLA4, then start Python and select Install, and when finished, exit Python
6) Put the pin_change.py file in the SLA4 "scripts" directory
7) Start SLA4
After that, when SLA4 is run you should see the script in the pick list. Upon selection SLA4 will pop-up an icon select-list. Pick the gear, which will run the script.
Click to expand...
Click to collapse
(I pasted this from the other thread, I did not use the script name here, I did use gen-gesture.key.py)
I installed SLA4 as described here and went to run the script with the gear icon. When I run it, all I get is a notification that gen-gesture.key.py was exited. Reading that I am supposed to generate the key, then copy it to the SD card, I thought maybe it did generate the gesture.key and I just have to find it, but I looked everywhere through files and couldn't find the file anywhere. I did locate a log file, gen-gesture.key.py.log, but it was blank, nothing to see.
Thinking there might have been a problem with the script, I tried to use the QR code here, but python said "Invalid QR code content". I double checked my script and I don't appear to have missed anything when I copied it, so I am lead to believe there is something else I am missing about how to use python. Only other thing I can think of that's wrong is the script extension, I used .py to run it in python, but wonder if it's supposed to be .pl since it's perl, or if I need .py to run it in python and the script runs as a perl script like that.
So, I am trying really hard to do this, I'm trying to learn on my own, but a little help would be really nice if anyone is able.
Bumped for help!
gadsden said:
Bumped for help!
Click to expand...
Click to collapse
You should not need to follow any directions in another thread. The Perl script is intended to be run on a PC, not on the phone, so there is no need for Perl to be installed. Running the script with out any arguments prints out the pattern of the android lock screen but instead of dots it has numbers. Run the script with the numbers after it as provided in the example in post number 1 to create the gesture.key file on your PC. Then copy that file over to the phone as described.
I'm also a little confused by your comment about not finding settings.db. I can think of no reason why the file would not exist, unless you mean that the records were not in the database file.
Thanks,
Ben
Fmstrat said:
You should not need to follow any directions in another thread. The Perl script is intended to be run on a PC, not on the phone, so there is no need for Perl to be installed. Running the script with out any arguments prints out the pattern of the android lock screen but instead of dots it has numbers. Run the script with the numbers after it as provided in the example in post number 1 to create the gesture.key file on your PC. Then copy that file over to the phone as described.
I'm also a little confused by your comment about not finding settings.db. I can think of no reason why the file would not exist, unless you mean that the records were not in the database file.
Thanks,
Ben
Click to expand...
Click to collapse
You said to check for records in settings.db first. When I search through my files, I can locate the directory data/data/com.android.providers.settings, but there is nothing inside of it. So, I did run the sqlite codes. I ran each line separately, and it said Error:too many options. So, I ran them all together and no errors came back. However, I still can't find anything in the directory.
Then to run the script, there is an attached file here called gen-gesture.key.pl.txt. Am I supposed to put that file into my platform tools folder and use the mv gen-gesture.key code to call the script? Or do I paste the text in the txt file into adb? I have tried running everything explained here in root shell in adb, I thought that was how I am supposed to do it, but I seem to be missing something. Sorry for the basic questions, but I'm still learning here.
Fmstrat said:
You should not need to follow any directions in another thread. The Perl script is intended to be run on a PC, not on the phone, so there is no need for Perl to be installed. Running the script with out any arguments prints out the pattern of the android lock screen but instead of dots it has numbers. Run the script with the numbers after it as provided in the example in post number 1 to create the gesture.key file on your PC. Then copy that file over to the phone as described.
I'm also a little confused by your comment about not finding settings.db. I can think of no reason why the file would not exist, unless you mean that the records were not in the database file.
Thanks,
Ben
Click to expand...
Click to collapse
Here's what I did so far.
1) Installed perl because it wasn't on my computer
2) changed permissions on /data/data/com.android.providers.settings/databases/settings.db to 777 so I could view the files in DDMS. Checked the settings.db and when I outputted it as a text file, all I got was a blank document
3) installed sqlite3 on my phone with sqlite installer
4) Entered root shell and entered
Code:
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='65536' WHERE name = 'lockscreen.password_type'"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='1' WHERE name = 'lockscreen.patterneverchosen'"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='1' WHERE name = 'lock_pattern_autolock'"
I didn't know if I was supposed to run each line individually, or all at once, so I did it both ways. neither one had an error
5) Saved the gen-gesture.key.pl.txt file to my platform tools folder. Ran
Code:
perl gen.gesture.key.pl.txt
It came back with this
Code:
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>perl C:\Android\ad
t-bundle-windows-x86-20130219\sdk\platform-tools\gen-gesture.key.pl.txt
Usage: gen-gesture.key.pl <sequence>
With sequence as number sequence drawn on this keypad:
0 1 2
3 4 5
6 7 8
The generated binary output has to be put into: /data/system/gesture.key
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>
6) then entered this all at once
Code:
mv gen-gesture.key.pl.txt gen-gesture.key.pl && chmod +x gen-gesture.key.pl
./gen-gesture.key.pl 01258 > gesture.key
adb push gesture.key /mnt/sdcard/Download/
adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
^C
it came back with a bunch of errors and left me at root shell. I figured maybe I was supposed to run it from root shell anyway, so I entered it again. The very first command came back as "mv" is not a recognized internal or external command. I tried it a couple more times, but I'm not following what's supposed to happen here. I did do a reboot of the phone and when I did so, the lock settings were disabled. So, something is happening, but not everything that needs to. I I've probably spent over 12 hours on this over the past week and I am sure I'm doing it wrong. The OP doesn't describe in detail how a beginner needs to do this. I've learned as much as I can, but seeing as how I even got stuck on not knowing I needed to install perl, I'm positive that I'm missing more. The post just isn't beginner friendly. I'm trying hard to understand this but I'm becoming really discouraged here. Can someone provide a little more info here.
Here's the whole session if it helps
Code:
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>perl C:\Android\ad
t-bundle-windows-x86-20130219\sdk\platform-tools\gen-gesture.key.pl.txt
Usage: gen-gesture.key.pl <sequence>
With sequence as number sequence drawn on this keypad:
0 1 2
3 4 5
6 7 8
The generated binary output has to be put into: /data/system/gesture.key
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>mv gen-gesture.key
.pl.txt gen-gesture.key.pl && chmod +x gen-gesture.key.pl
'mv' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>./gen-gesture.key.
pl 01258 > gesture.key
'.' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb push gesture.k
ey /mnt/sdcard/Download/
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
^Csu -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
[email protected]:/ $ su -
re.key > /data/system/gesture.key <
[email protected]:/ # mv gen-gesture.key.pl.txt gen-gesture.key.pl && chmod +x gen-g
esture.key.pl
./gen-gesture.key.pl 01258 > gesture.key
adb push gesture.key /mnt/sdcard/Download/
adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
n-gesture.key.pl && chmod +x gen-gesture.key.pl <
sh: ^Cmv: not found
adb push gesture.key /mnt/sdcard/Download/
adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
127|[email protected]:/ # ./gen-gesture.key.pl 01258 > gesture.key
sh: can't create gesture.key: Read-only file system
1|[email protected]:/ # adb push gesture.key /mnt/sdcard/Download/
* daemon not running. starting it now on port 5038 *
* daemon started successfully *
error: device not found
1|[email protected]:/ # adb shell
error: device not found
1|[email protected]:/ # su -
re.key > /data/system/gesture.key <
[email protected]:/ #
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>mv gen-gesture.key
.pl.txt gen-gesture.key.pl && chmod +x gen-gesture.key.pl
'mv' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>./gen-gesture.key.
pl 01258 > gesture.key
'.' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb push gesture.k
ey /mnt/sdcard/Download/
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
^Csu -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
[email protected]:/ $ su -
re.key > /data/system/gesture.key <
[email protected]:/ # exit
^Cexit
sh: ^Cexit: not found
127|[email protected]:/ # exit
exit
127|[email protected]:/ $ exit
exit
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>mv gen-gesture.key
.pl.txt gen-gesture.key.pl && chmod +x gen-gesture.key.pl
'mv' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>./gen-gesture.key.
pl 01258 > gesture.key
'.' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb push gesture.k
ey /mnt/sdcard/Download/
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
^Csu -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
[email protected]:/ $ su -
re.key > /data/system/gesture.key <
[email protected]:/ #
Been working on this for a whole week now, just wondering if I'm even on the right track here?
gadsden said:
Here's what I did so far.
1) Installed perl because it wasn't on my computer
2) changed permissions on /data/data/com.android.providers.settings/databases/settings.db to 777 so I could view the files in DDMS. Checked the settings.db and when I outputted it as a text file, all I got was a blank document
3) installed sqlite3 on my phone with sqlite installer
4) Entered root shell and entered
Code:
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='65536' WHERE name = 'lockscreen.password_type'"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='1' WHERE name = 'lockscreen.patterneverchosen'"
sqlite3 -batch /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='1' WHERE name = 'lock_pattern_autolock'"
I didn't know if I was supposed to run each line individually, or all at once, so I did it both ways. neither one had an error
5) Saved the gen-gesture.key.pl.txt file to my platform tools folder. Ran
Code:
perl gen.gesture.key.pl.txt
It came back with this
Code:
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>perl C:\Android\ad
t-bundle-windows-x86-20130219\sdk\platform-tools\gen-gesture.key.pl.txt
Usage: gen-gesture.key.pl <sequence>
With sequence as number sequence drawn on this keypad:
0 1 2
3 4 5
6 7 8
The generated binary output has to be put into: /data/system/gesture.key
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>
6) then entered this all at once
Code:
mv gen-gesture.key.pl.txt gen-gesture.key.pl && chmod +x gen-gesture.key.pl
./gen-gesture.key.pl 01258 > gesture.key
adb push gesture.key /mnt/sdcard/Download/
adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
^C
it came back with a bunch of errors and left me at root shell. I figured maybe I was supposed to run it from root shell anyway, so I entered it again. The very first command came back as "mv" is not a recognized internal or external command. I tried it a couple more times, but I'm not following what's supposed to happen here. I did do a reboot of the phone and when I did so, the lock settings were disabled. So, something is happening, but not everything that needs to. I I've probably spent over 12 hours on this over the past week and I am sure I'm doing it wrong. The OP doesn't describe in detail how a beginner needs to do this. I've learned as much as I can, but seeing as how I even got stuck on not knowing I needed to install perl, I'm positive that I'm missing more. The post just isn't beginner friendly. I'm trying hard to understand this but I'm becoming really discouraged here. Can someone provide a little more info here.
Here's the whole session if it helps
Code:
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>perl C:\Android\ad
t-bundle-windows-x86-20130219\sdk\platform-tools\gen-gesture.key.pl.txt
Usage: gen-gesture.key.pl <sequence>
With sequence as number sequence drawn on this keypad:
0 1 2
3 4 5
6 7 8
The generated binary output has to be put into: /data/system/gesture.key
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>mv gen-gesture.key
.pl.txt gen-gesture.key.pl && chmod +x gen-gesture.key.pl
'mv' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>./gen-gesture.key.
pl 01258 > gesture.key
'.' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb push gesture.k
ey /mnt/sdcard/Download/
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
^Csu -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
[email protected]:/ $ su -
re.key > /data/system/gesture.key <
[email protected]:/ # mv gen-gesture.key.pl.txt gen-gesture.key.pl && chmod +x gen-g
esture.key.pl
./gen-gesture.key.pl 01258 > gesture.key
adb push gesture.key /mnt/sdcard/Download/
adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
n-gesture.key.pl && chmod +x gen-gesture.key.pl <
sh: ^Cmv: not found
adb push gesture.key /mnt/sdcard/Download/
adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
127|[email protected]:/ # ./gen-gesture.key.pl 01258 > gesture.key
sh: can't create gesture.key: Read-only file system
1|[email protected]:/ # adb push gesture.key /mnt/sdcard/Download/
* daemon not running. starting it now on port 5038 *
* daemon started successfully *
error: device not found
1|[email protected]:/ # adb shell
error: device not found
1|[email protected]:/ # su -
re.key > /data/system/gesture.key <
[email protected]:/ #
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>mv gen-gesture.key
.pl.txt gen-gesture.key.pl && chmod +x gen-gesture.key.pl
'mv' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>./gen-gesture.key.
pl 01258 > gesture.key
'.' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb push gesture.k
ey /mnt/sdcard/Download/
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
^Csu -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
[email protected]:/ $ su -
re.key > /data/system/gesture.key <
[email protected]:/ # exit
^Cexit
sh: ^Cexit: not found
127|[email protected]:/ # exit
exit
127|[email protected]:/ $ exit
exit
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>mv gen-gesture.key
.pl.txt gen-gesture.key.pl && chmod +x gen-gesture.key.pl
'mv' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>./gen-gesture.key.
pl 01258 > gesture.key
'.' is not recognized as an internal or external command,
operable program or batch file.
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb push gesture.k
ey /mnt/sdcard/Download/
C:\Android\adt-bundle-windows-x86-20130219\sdk\platform-tools>adb shell
su -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
^Csu -
cat /mnt/sdcard/Download/gesture.key > /data/system/gesture.key
[email protected]:/ $ su -
re.key > /data/system/gesture.key <
[email protected]:/ #
Click to expand...
Click to collapse
thx
Related
[Q] adb shell in batch
Hi, I'm making a batch file (*.bat) for myself to try make some things easier file where I enter commands with adb.exe. The problem is, any code after 'adb shell' is not executed in the batch. So if I had a batch with the following: Code: adb shell su 'su' will not be executed and stays at '$'. It seems like it's too deep for a batch file to enter codes. I also tried pushing a sh with the same script and run it from adb but then all I get it permission denied. I have also tried 'adb shell su' without any luck. Anyone with a solution?
Anyone? Or how about a .rc file that gets su and runs commands... Sent from my HTC
To execute a script, you can always push your script and then execute it: Code: adb push script /sdcard/script adb shell sh /sdcard/script As for the commands you have shown, keep in mind that su doesn't simply change the running shell's permissions or the like but creates a new child environment within its own shell. You leave your script and after the new shell has finished, you're back in your old environment and the script continues.
mizch said: To execute a script, you can always push your script and then execute it: Code: adb push script /sdcard/script adb shell sh /sdcard/script As for the commands you have shown, keep in mind that su doesn't simply change the running shell's permissions or the like but creates a new child environment within its own shell. You leave your script and after the new shell has finished, you're back in your old environment and the script continues. Click to expand... Click to collapse yes, is there any way to automate the script inside the shell and use exit to finally go back to the batch script.
Can you provide me with an example of what you want to achieve?
To execute shell commands from a batch, it doesn't matter if I have to push a script and execute it. It's so that I get su and automate commands after that. Like flash_image, remount, chmod etc..
you will need to use the 'adb shell command' ad 'sh' files
I am trying to create a unix script file that copies files from /dbdata/databases to another folder as a backup. When I try running the script in adb shell as SU, I get cd: can't cd to /dbdata/databases This is on a rooted Captivate. Any help would be greatly appreciated!
Hi, su -c "command" should do the job for you. You will need to enclose the whole of the command in quotes however, otherwise su will be expecting the command to execute, doing nothing. Example: adb shell "su -c 'sqlite3 /data/data/my.db/databases/mydb.db < /sdcard/dump.sql'" (run from a Unix or Windows(?) shell). Notice the use of "" and ''. (in this case dump.sql contains .dump, for instance) Of course the sqlite3 command could be placed within another script on the android device. Hope that helps.
I looked around a bit and found the answer. The simple answer is, wrap the command Code: cp "source" "destination" in double quotes! Thank you grindingbob for the adb shell "su -c 'sh /mnt/sdcard/tmp/2.sh'" command.
No probs I was more referring to executing commands as a su without interacting with adb shell. As a side-note, cp might not be a good idea, unless you're sure no db accessing is taking place at the same time.
I am pretty sure well as sure as a novice can be! The files I am backing up are log files, call history and text message history. The results from running a unix script which contains Code: cp "/dbdata/databases/com.android.providers.contacts/contacts2.db" "/mnt/sdcard/tmp4/contacts2.db" cp "/dbdata/databases/com.android.providers.telephony/mmssms.db" "/mnt/sdcard/tmp4/mmssms.db" cp "/dbdata/databases/com.sec.android.provider.logsprovider/logs.db" "/mnt/sdcard/tmp4/logs.db" are only the logs.db file is copied, the other two are not. grindingbob said: No probs I was more referring to executing commands as a su without interacting with adb shell. As a side-note, cp might not be a good idea, unless you're sure no db accessing is taking place at the same time. Click to expand... Click to collapse
Permission issues for *.sh files from ADB Dear All, I have a 3.2 device with Root permissions & Busybox. I created a sample *.sh file, Pushed to SDcard, and gave '777' Permissions. When i Try to run it from ADB shell its not working Any help... CMD prompt Traces: Step -1: Created a sh file cat TAB.sh #!/bin/sh cd /data/data/com.android.gallery/shared_prefs Step -2 Pushed the file to SDcard # ls -l *.sh ls -l *.sh -rw-rw-r-- root sdcard_rw 56 2012-03-13 15:06 SP.sh -rw-rw-r-- root sdcard_rw 62 2012-03-13 15:05 TAB.sh Step -3 Gave 777 permission for *.sh files # chmod 777 *.sh chmod 777 *.sh # ls -l ls -l -rw-rw-r-- root sdcard_rw 56 2012-03-13 15:06 SP.sh -rw-rw-r-- root sdcard_rw 62 2012-03-13 15:05 TAB.sh Execute permission not applied Tried other operations, dint workout Step 4 other options: # chmod +X *.sh chmod +X *.sh Bad mode # chmod +x *.sh chmod +x *.sh Bad mode # chmod u+x *.sh chmod u+x *.sh Bad mode Any Help?
[GUIDE] Basic Unix/Linux command to use with ADB SHELL
I am sure that many of the new people in here are not exactly sure how to use ADB under linux. So Ive been reading the Evo 3D forum, and I found this really nice guide by vboyz103. You can find the thread HERE All props go to vboyz103 for creating it, im just sharing it with you guys. P.S. - I found it in the Android Development forum, so Im putting it in ours. If it does not belong here - MODs - please move it to General. vboyz103 said: So I have been reading quite a few threads here on XDA, and the one thing I noticed for noobs to linux/unix world is that they are struggling with some basic command once adb shell is gained. I decided to whip out this quick tutorial to help those noobs out to become more of an expert...like me...lol j/k Here we go: Prerequisites: You must know how to invoke a adb shell command already to drop into your phone. ALL commands in Unix/Linux are case sensitive For more details, go to this ADB tutorial (very good one): http://forum.xda-developers.com/showthread.php?t=517874 Let's get going: Once a shell is gained via adb, let's look at some of the basic commands you can do to navigate around the filesystem. Note: you must remove the double-quotes (") for the actual command. Code: "cd" = is change directory to change to any directory, you type: cd dir_name (where dir_name is a full path) Example: I want to go to /data/local/tmp in my phone, I would do cd /data/local/tmp <hit ENTER> You can also use the ".." to go UP one directory. Example: I'm in /data/local/tmp and I want to go up to /data folder, a command would be: cd ../.. alternatively, if I do cd .. then i'll drop into /data/local folder instead. Code: "ls" = list files/directories to list files/directories within a folder, the command should be: ls <hit enter> => this will list all NON-HIDDEN file/directories within your CURRENT directory. ls /data/local/tmp => this will list all NON-HIDDEN file/directories within /data/local/tmp directory. ls -l => this will list all NON-HIDDEN file/directories within your CURRENT directory, plus additional details. Consider this is like a "Details" view in Windows Explorer. ls -a => this will list all files/directories (including hidden files) within your CURRENT directory. ls -la => this will list all files/directories (including hidden files) within your CURRENT directory, plus details. Code: "chmod" = change mode Goes to wikipedia for more details: https://secure.wikimedia.org/wikipedia/en/wiki/Chmod Most commonly used modes on android phones are: "755" or "777". So if you have a root.sh shell script that you downloaded from XDA, and uploaded to your phone and try to execute it with ./root.sh and it said "Permission denied". That means your script does not have the execute permission. You need to do: chmod 755 root.sh <hit enter> [B]IMPORTANT: There is *NO* negative sign (-) in front of the mode bit. So it is NOT chmod -755 root.sh[/B] If you get a "File or directory not found" error, which means you are chmod-ing a file that doesn't exist in your current directory. To execute a chmod on root.sh in /data/local/tmp you do: chmod 755 /data/local/tmp/root.sh If you want to chmod an ENTIRE DIRECTORY and ALL files underneath it you do: chmod -R 755 /data/local/tmp => this will set /data/local/tmp and ALL files/folders underneath it to be 755. Code: "chown" = change ownership Go to wikipedia for details: https://secure.wikimedia.org/wikipedia/en/wiki/Chown Most common used chown for android is: "root:root" or "root:shell" Example: if you want to change ownership of root.sh to root:shell then you do: chown root:shell root.sh NOTE: the -R (recursive) option is also available for chown. chown -R root:shell /data/local/tmp Code: "pwd" = print working directory so when you are within a directory and you want to know which directory you are in, then you issue the command: pwd <hit enter> The system will reply back with the currently directory you are in. I'll try to add more if I think of anything else useful, or if you have suggestions, please feel free to add. Click to expand... Click to collapse
[FIX]Facebook contact icon fix for 3rd party apps
I make no claims to be any good at this but I was searching around for a fix to the contacts not displaying in 3rd party apps issue and came across a user named erishasnobattery on teambamf.net that had come up with a solution in addition to the zerg rush temp root script and incorporated the two for the HTC rezound. So I took a look at it and figured that it could be applied to my Sensation, didn't have a usb cable at work with me so I just did it manually but I've modified the batch file that he was using to push via adb from a PC and I've attached it. I saw when I posted this that there is an app that does it but I also saw that some people don't like installing 3rd party apps for small little issues like this so I figured I'd put it up anyways, mods can determine whether it should stay up or not. Like I said I'm no expert and I didn't use the batch file, I modified the permissions with root explorer and downloaded the files to the appropriate directories and ran the script, rebooted the phone and bam all contact pics in handcent so it works. I did notice when I went to move the sqlite3 file to /system/xbin it was already there so I just changed the permissions on the existing file instead of overwriting with the one included. Contents of the batch file are as follows: :cd %:h @echo off echo Waiting for Device.... adb wait-for-device > NUL 2>&1 echo Pushing Files... adb push sqlite3 /system/xbin/sqlite3 > NUL 2>&1 adb shell chmod 777 /system/xbin/sqlite3 > NUL 2>&1 adb push fix_contacts.sh /system/etc/fix_contacts.sh > NUL 2>&1 adb shell chmod 777 /system/etc/fix_contacts.sh > NUL 2>&1 adb shell /system/etc/fix_contacts.sh > NUL 2>&1 echo Fix Complete, Hit Enter to reboot. pause adb reboot > NUL 2>&1 contents of the fix_contacts.sh file are as follows: #!/system/bin/sh/system/xbin/sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db "UPDATE raw_contacts SET is_restricted=0 WHERE is_restricted!=0" You can determine for yourself if you want to use it, obviously not responsible for any problems it may cause and as always do a backup first. Thanks, Court
cotawa said: I make no claims to be any good at this but I was searching around for a fix to the contacts not displaying in 3rd party apps issue and came across a user named erishasnobattery on teambamf.net that had come up with a solution in addition to the zerg rush temp root script and incorporated the two for the HTC rezound. So I took a look at it and figured that it could be applied to my Sensation, didn't have a usb cable at work with me so I just did it manually but I've modified the batch file that he was using to push via adb from a PC and I've attached it. I saw when I posted this that there is an app that does it but I also saw that some people don't like installing 3rd party apps for small little issues like this so I figured I'd put it up anyways, mods can determine whether it should stay up or not. Like I said I'm no expert and I didn't use the batch file, I modified the permissions with root explorer and downloaded the files to the appropriate directories and ran the script, rebooted the phone and bam all contact pics in handcent so it works. I did notice when I went to move the sqlite3 file to /system/xbin it was already there so I just changed the permissions on the existing file instead of overwriting with the one included. Contents of the batch file are as follows: :cd %:h @echo off echo Waiting for Device.... adb wait-for-device > NUL 2>&1 echo Pushing Files... adb push sqlite3 /system/xbin/sqlite3 > NUL 2>&1 adb shell chmod 777 /system/xbin/sqlite3 > NUL 2>&1 adb push fix_contacts.sh /system/etc/fix_contacts.sh > NUL 2>&1 adb shell chmod 777 /system/etc/fix_contacts.sh > NUL 2>&1 adb shell /system/etc/fix_contacts.sh > NUL 2>&1 echo Fix Complete, Hit Enter to reboot. pause adb reboot > NUL 2>&1 contents of the fix_contacts.sh file are as follows: #!/system/bin/sh/system/xbin/sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db "UPDATE raw_contacts SET is_restricted=0 WHERE is_restricted!=0" You can determine for yourself if you want to use it, obviously not responsible for any problems it may cause and as always do a backup first. Thanks, Court Click to expand... Click to collapse Thanks for sharing the fix, it works. This just changes one of the attributes for the raw_contact entity, which I suppose is quite safe if you don't install untrustworthy apps. (Any application that has been granted permission to access your contacts during install will now have access to your facebook contacts & possibly other restricted contacts too.) If you are already running a custom ROM, then I recommend you follow these instructions: Download Terminal Emulator from Google Play Open Terminal Emulator Type Code: su and hit enter Type Code: cp /data/data/com.android.providers.contacts/databases/contacts2.db /sdcard/contacts2.db and hit enter Type Code: /data/data/com.android.providers.contacts/databases/contacts2.db "UPDATE raw_contacts SET is_restricted=0 WHERE is_restricted!=0" and hit enter. Type Code: exit and hit enter. Reboot the phone. Done. That's all you need. You may need to repeat this everytime a new contact is added.
[GUIDE] SManager - How to use Commands
Hi, I want to learn some of the commands for use in SManager (Script Manager) for ANDROID. https://sites.google.com/site/devwom/script-manager Does anyone know a suitable thread with guide or commands for SManager? I tried searching the web and XDA but did not find anything myself. Specifically I want to know the cmd line to start an app. EDIT 1: Spent a good few hours trying to google a solution but drawn a blank.......Maybe Shell Scripts for Linux are not same as for Android...? I would like to be able to run a script that does the following: Checks if a directory exists on the sdcard then executes a command (renaming of 2 directories) then starts a program EDIT 2: well a few emails with the author of SManager and I was able to write my first script to check if the app is running and then if not, to rename folders and start the other version of the app. (I have Navigon Europe as well as Navigon Australia and was looking for a solution to allow both to co exist on my One-X at the same time. As both apps share the same directory structure the issue was that starting one version would overwrite the critical files of the other). Now with my script installed as a widget I can toggle between each version without problem. Here is some useful information on shell language for others (credits to the author of SManager Devwom): http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html Here are some critical bits of info received during my emails with him: Thanks a lot for your interest in SManager. The requested commands is a mix between linux commands and android os commands. To get info about each command you can search in google and select the preferred page. But the commands available in each Android device depends on running rom. To get all available commands in your device, simply execute a ls (lower case LS) in system directories, that is: ls /system/bin ls /system/sbin ls /system/xbin ls /system/usr/bin ls /system/usr/sbin ls /system/usr/xbin These are the most common directories where binaries resides in android devices. May be you also can have commands at: ls /bin ls /sbin ls /usr/bin ls /usr/sbin usually android rooted roms have the well known busybox, to get a list all comands inside it simply execute busybox to get all installed packages (and running names) from your device you can execute: pm list packages to get info about running process ps or ps aux or ps -aux depending on ps version installed If conditions are based on test bash command this command is a bit confused, because usually it is named as [, and other times it is built-in inside shell read "test man page" to get a full list of test command flags. To check if an app is running: if [ -n "$(ps|grep os.tools.scriptmanager)" ] ; then echo SManager is running fi To check if app is NOT running: if [ -z "$(ps|grep os.tools.scriptmanager)" ] ; then echo SManager is NOT running fi To check if a file exist: if [ -e /sdcard/file ] ; then echo /sdcard/file exists fi To check if a file exist and it is a directory: if [ -d /sdcard/file ] ; then echo /sdcard/file exists and is directory fi To rename a directory simply use mv command: I hope you can build your script with this info. Start app it is very easy but getting correct info to start app is a bit confused. starting app uses "am command" To get correct info to start app you should execute: logcat |grep Starting in a terminal on device then go to launcher and launch desired app then go back to the terminal and you will see a line with info about how to fill am command. For example if you execute SManager in logcat|grep Starting output you will see I/ActivityManager(* 275): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=os.tools.scriptmanager/.launcherActivity } from pid 377 so to start scriptmanager you need the following command am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n os.tools.scriptmanager/.launcherActivity I do not know how to stop apps from command line, I usually use killall command: killall os.tools.scriptmanager if you do not have killall command you can use grep and awk or cut commands kill "$(ps|grep os.tools.scriptmanager|grep -v grep|awk '{print $2;}')" or kill "$(ps|grep os.tools.scriptmanager|grep -v grep|cut -f5 -d" ")" may you need adjust -f5 flag To execute script as shortcut install SMWidgets. Scripts usually ends with last line , ie, not special action is required, it will exit with the last executed command return code Also you can add exit 0 or preferred exit value, but 0 usually means OK To end script in the middle use exit value where value usually it is not 0 Also it is better use mv command instead rename command. rename command it is not linux standard, but mv command is in all linux shells. Android shell programing it is not equals to linux shell programming but this was one of my first scripting documents many years ago and it can be used as a guide. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html Best regards, Devwom
Thanks, this is valuable information! It's a shame this thread didn't get more replies I've been looking to change my wallpaper by script, but so far I haven't been succesful. With your guide, I guess I'm a step closer to my goals!
Hi. Perhaps developer of smanager or any expert is reading... I would like to write a script for 2 purposes. Both handle with samba share running on my ubuntu. 1st situation.: I would like to move my media, download and documents files from android to the desired folder on my Ubuntu, which is shared by samba in my LAN. The goal is to start this script with just touching a widget. 2nd situation: I would like to copy files from my samba shared folder in ubuntu to a specific folder on sdcard in android. All files in folder on sdcard should be deleted before copying. Again just by touching a widget. Shared folder on samba are with password and rw. Till now I am doing it manually with esexplorer... I would like to do it with script. Sent from my Incredible S using xda app-developers app
Terminal emulator size after upgrade Android 4.3
Hi, I'm having an issue with all terminal emulators (Android Terminal Emulator, ConnectBot, ...) after upgrading my Nexus 10 from Android 4.2.2 to 4.3. The terminal is not recognizing the actual size of the screen and it is fixed to 80 columns and 20 rows. I can temporarily fix it typing "stty cols 180 rows 35", but those values depend on the screen rotation, font size, etc. This is really weird, and I wasn't having this issue before the upgrade. Anyone else has this problem or know how to solve it? Thanks!
Ok, i've been doing some tests. It seems to be a 'su' bug, it is not receiving the SIGWINCH signal. If I type without su: trap 'echo sigwinch' SIGWINCH It is executed every time I rotate the tablet or popup the keyboard. But, under su, the same command is not working. It may be a permission issue. Any ideas?
I can confirm having the same issue with my Nexus 10 and android 4.3. As soon as I run su - from the terminal (Android Terminal Emulator) the lines start wrapping at 80 characters.
Hi, i've been working on this trying to find a solution. Here is what I saw: Every time I enter su or enter chroot (i have a chrooted debian), the tty number is changed to another one. That isn't the usual tty behavior! So, if the normal user is in /dev/pts/0 , root could be in /dev/pts/1 and chroot in /dev/pts/2. If I rotate the screen /dev/pts/0 cols and rows are changed even if I am as root, I can verify that by typing: stty -F /dev/pts/0 -a But, if I am at /dev/pts/1 i'm not receiving that SIGWINCH signal. In common linux distributions, that is not happening as pts number doesn't change. Here is my (not so perfect) solution for the chrooted debian: Write a fix_stty.sh script as root: #!/bin/bash sttypath=/bin tty0=$(ls --sort time /dev/pts/ | head -n 1 | awk '{print $1}') stty0=$($sttypath/stty -F /dev/pts/$tty0 -a | head -n1) rows=$(echo $stty0 | sed -e 's:.*rows\ \([0-9]\+\).*:\1:g') cols=$(echo $stty0 | sed -e 's:.*columns\ \([0-9]\+\).*:\1:g') $sttypath/stty rows $rows cols $cols Save it in /usr/local/bin Make it executable: chmod +rx /usr/local/bin/fix_stty.sh Add to ~/.bashrc this line: trap '/usr/local/bin/fix_stty.sh' DEBUG Or if you use non-root users: trap 'sudo /usr/local/bin/fix_stty.sh' DEBUG And add to sudoers file: %sudo ALL = (ALL) NOPASSWD: /usr/local/bin/fix_stty.sh Logout and login again, and it will fix the rows and columns before each command. ---- For su, outside the chrooted linux write a script fix_stty.sh: sttypath=/system/xbin tty0=$(/system/xbin/busybox ls -t /dev/pts | head -n1) stty0=$($sttypath/stty -F /dev/pts/$tty0 -a | head -n1) rows=$(echo $stty0 | sed -e 's:.*rows\ \([0-9]\+\).*:\1:g') cols=$(echo $stty0 | sed -e 's:.*columns\ \([0-9]\+\).*:\1:g') $sttypath/stty rows $rows cols $cols Save it to /system/xbin (You should remount /system as rw: mount --remount -orw /system) Then, make it exec: chmod 755 /system/xbin/fix_stty.sh And, finally you should type at each su login: trap '/system/xbin/fin_stty.sh' SIGINT (i don't know why DEBUG isn't here) So you have to press Ctrl+C to fix it. ---- Alternatively, you can write an infinite loop or a simple daemon to fix it, but i don't like daemons on my tablet. If anyone has a better solutions, please post it.
Hi all. I've been mulling over this problem as well. I believe the issue is because in 4.3, SuperSU now uses a "proxy", where commands are sent form the process which called su to daemonsu, which is launched at system startup. Chainfire explains a bit more in his G+ posts the reasons for doing this, but I think the key here is that root processes are now launched on a different tty, because they are launched by a different process (namely, daemonsu). Starting a root shell (whether system shell or ubuntu/debian chroot) now results in the creation of three pts devices, as opposed to the usual one. However, other shells not launched locally are fine. For example, starting the SSH server in my chroot and logging in via SSH is always fine. I'm still trying to figure out a permanent solution to this problem. I still don't have a full understanding of the problem as I'm still trying to wrap my head around how Linux handles terminals and TTYs. I do have a few ideas floating around my head, though: Change daemonsu and su to support full termios/line-discipline/whatever-we-need through the "pts bridge" that he is using Create TTY(pts) pairs on demand, and have a modified Terminal Emulator connect to those directly when we want a shell Have a background-ed process in the original terminal catch SIGWINCH and pass it to the root terminal Still quite a bit a figure out though. I may just go through Terminal Emulator's source code to see how it work to get a better picture too. But that's gonna take time. I've also created a little native utility which creates two pts pseudo-TTYs and shuffles data between them. I'm still experimenting. Will post more as I learn more.
Just to let you all know that I've got a system working for myself: http://blog.tan-ce.com/android-root-shell/ The way I'm doing it uses a daemon, much like the su daemons ChainFire and Koush are using. The benefit of doing it this way is that I'm not confined by the application container, which is good for security when used by applications, but is annoying when you are using the terminal itself. I remember having to do hacks with adb servers to get around those. But if you don't want a daemon, you can still set one up manually, just look at the last section of the README on how to use pts-wrap and pts-exec.
I gave this a try. First, I've noticed that pts-wrap and pts-exec symbolic links were missing. And I don't think the line '/system/etc/install-recovery-2.sh' in pts-daemon-start file is needed at all. I'm using ChainFire SuperSU and pts-shell is not working as expected or catching SIGWINCH signals. I just don't see any difference with the standard shell. Maybe I misunderstood how it works.
alf_tux said: I gave this a try. First, I've noticed that pts-wrap and pts-exec symbolic links were missing. And I don't think the line '/system/etc/install-recovery-2.sh' in pts-daemon-start file is needed at all. Click to expand... Click to collapse My mistake, I forgot to create the symlinks for those two. install-recovery-2.sh is an idea I took from CharinFire's SuperSU. Basically, it seems as if people are using install-recovery.sh to install startup scripts, and having the script try to call install-recovery-2.sh allows you to chain recovery scripts. For example, if you install this on a system with SuperSU, it will be installed as install-recovery-2.sh. If the system doesn't already have an install-recovery.sh, it'll install itself as install-recovery.sh. Anyway, I've fixed and uploaded a new zip. alf_tux said: I'm using ChainFire SuperSU and pts-shell is not working as expected or catching SIGWINCH signals. I just don't see any difference with the standard shell. Maybe I misunderstood how it works. Click to expand... Click to collapse Are you running pts-shell from a regular (non-root) shell, or from a root shell? It should be run from a non-root shell. (It will give you a root shell once it runs.) Only pts-passwd and pts-daemon is meant to be run as root.
tan-ce said: Are you running pts-shell from a regular (non-root) shell, or from a root shell? It should be run from a non-root shell. (It will give you a root shell once it runs.) Only pts-passwd and pts-daemon is meant to be run as root. Click to expand... Click to collapse Yes, here is my the terminal output: [email protected]:/ $ ps | grep pts root 136 1 760 180 ffffffff 00000000 S /system/xbin/pts-daemon [email protected]:/ $ pts-shell /system/bin/sh (pts-shell) /system/bin/sh Could not connect to socket: Permission denied 255|[email protected]:/ $ su pts-shell /system/bin/sh [email protected]:/ # As you see, I can only run pts-shell as root.
alf_tux said: Yes, here is my the terminal output: [email protected]:/ $ ps | grep pts root 136 1 760 180 ffffffff 00000000 S /system/xbin/pts-daemon [email protected]:/ $ pts-shell /system/bin/sh (pts-shell) /system/bin/sh Could not connect to socket: Permission denied 255|[email protected]:/ $ su pts-shell /system/bin/sh [email protected]:/ # As you see, I can only run pts-shell as root. Click to expand... Click to collapse Sorry, I realized that the correct command should be: [email protected]:/ $ su -c pts-shell /system/bin/sh (pts-shell) /system/bin/sh (pts-shell) Enter your password: [email protected]:/ # Anyway I can only run this as root.
Oh yeah, I found the bug. Sorry, my bad. I've fixed it and uploaded a new copy of the update ZIP, but you don't have to upgrade if you don't want to. Running Code: # chmod 0701 /data/pts should be sufficient to fix the problem. Then you should be able to run pts-shell from a regular (non-root) shell.
tan-ce said: Oh yeah, I found the bug. Sorry, my bad. I've fixed it and uploaded a new copy of the update ZIP, but you don't have to upgrade if you don't want to. Running Code: # chmod 0701 /data/pts should be sufficient to fix the problem. Then you should be able to run pts-shell from a regular (non-root) shell. Click to expand... Click to collapse I don't think that was the the bug: [email protected]:/ $ su [email protected]:/ # ls -l /data/pts -rw------- root root 61 2013-08-28 19:09 passwd srw-rw-rw- root root 2013-08-28 18:59 pts [email protected]:/ # chmod 0701 /data/pts [email protected]:/ # ls -l /data/pts -rw------- root root 61 2013-08-28 19:09 passwd srw-rw-rw- root root 2013-08-28 18:59 pts [email protected]:/ # ^D [email protected]:/ $ pts-shell /system/bin/sh (pts-shell) /system/bin/sh Could not connect to socket: Connection refused 255|[email protected]:/ $ I have also tried: chmod 0701 /data/pts/pts And chmod 0701 /data/pts/* I'm getting the same connection refused. Maybe you can send me a debug version, I can run it just to find what is going on.
alf_tux said: I'm getting the same connection refused. Maybe you can send me a debug version, I can run it just to find what is going on. Click to expand... Click to collapse That's strange. Could you show me the output of ls -la? (The "a" is needed to see the permissions for /data and /data/pts itself) After that, perhaps you could try "chmod 0711 /data/pts" There isn't a debug version. The error message comes from the part of the code which tries to open a unix socket located at /data/pts/pts. For this to work, /data and /data/pts must have the execute bit set, and /data/pts/pts needs to have the readable and writable bit set for you. Otherwise you'll get a "permission denied". Perhaps it might be easier for me to just move the socket to /dev like what koush does for Superuser... it's possible the permissions on my /data is non-standard. On a side note, I'm also currently trying to contribute to koush's Superuser project to fix terminal handling. With any luck, I (or someone else?) will succeed and we won't really need my pts-multi tools anymore.
tan-ce said: That's strange. Could you show me the output of ls -la? (The "a" is needed to see the permissions for /data and /data/pts itself) After that, perhaps you could try "chmod 0711 /data/pts" There isn't a debug version. The error message comes from the part of the code which tries to open a unix socket located at /data/pts/pts. For this to work, /data and /data/pts must have the execute bit set, and /data/pts/pts needs to have the readable and writable bit set for you. Otherwise you'll get a "permission denied". Perhaps it might be easier for me to just move the socket to /dev like what koush does for Superuser... it's possible the permissions on my /data is non-standard. On a side note, I'm also currently trying to contribute to koush's Superuser project to fix terminal handling. With any luck, I (or someone else?) will succeed and we won't really need my pts-multi tools anymore. Click to expand... Click to collapse Yes, I agree that fixing su would be better. I don't have my tablet right know, i don't remember well /data /data/pts and /data/pts/pts read and exec bits. I will see better whan I have my tablet with me.
Here is the output: /data: drwxrwx--x system system 2013-08-28 18:59 data /data/pts: drwxr-xr-x root root 2013-08-28 19:06 pts [email protected]:/ $ ls -la /data/pts -rwxrwxrwx root root 61 2013-08-28 19:09 passwd srwxrwxrwx root root 2013-08-28 18:59 pts [email protected]:/ $ pts-shell /system/bin/sh (pts-shell) /system/bin/sh Could not connect to socket: Connection refused 255|[email protected]:/ $ I suppose it isn't a permission problem.
alf_tux said: I suppose it isn't a permission problem. Click to expand... Click to collapse You're probably right, my Nexus 10 could be a bit different because of the semi-botched update I went through. Well, good news on two fronts: First, I updated pts-multi (latest update zip here) to use /dev/pts-daemon as the socket instead of /data... It works on mine, and I think it should work on yours, because Superuser puts its socket there too. Second, I finished some modifications to the su binary in Superuser (source code here), and I've submitted a pull request to Koush. He says he'll do a code review of my changes, and we'll see how it goes.
tan-ce said: You're probably right, my Nexus 10 could be a bit different because of the semi-botched update I went through. Well, good news on two fronts: First, I updated pts-multi (latest update zip here) to use /dev/pts-daemon as the socket instead of /data... It works on mine, and I think it should work on yours, because Superuser puts its socket there too. Second, I finished some modifications to the su binary in Superuser (source code here), and I've submitted a pull request to Koush. He says he'll do a code review of my changes, and we'll see how it goes. Click to expand... Click to collapse T/hanks! I tried your new update and I think it's working! Can you add a passwordless option? Or if password is blank just don't ask for it
alf_tux said: T/hanks! I tried your new update and I think it's working! Can you add a passwordless option? Or if password is blank just don't ask for it Click to expand... Click to collapse Ok, but I took the easiest way out... If you set the environment variable PTS_AUTH, pts-shell will read the password from there instead of prompting you for it. So, if you're writing a script to spawn a root shell, do: Code: #!/system/bin/sh export PTS_AUTH="your password here" pts-shell /system/bin/sh The latest update zip is here.
Thanks a lot tan-ce!! It's working just as I expected!
Glad to hear it.