[Q] File read/write modifications - Android Software Development

Hi,
I'm trying to create a program that reads an existing file and later overwrites it with new data. The file i'm trying to open is in /data/data/PACKAGE/files/FILE (but package is another application then mine)
This is the code so far:
Code:
try {
runtime.exec("su");
runtime.exec("chmod 777 /data/data/PACKAGE/files/FILE");
runtime.exec("cp /data/data/PACKAGE/files/FILE /sdcard/NEWFILE");
runtime.exec("chmod 777 /sdcard/NEWFILE");
}
.....
File file = new File("/sdcard/NEWFILE");
FileInputStream fis = new FileInputStream(file);
BufferedWriter fos = new BufferedWriter(new FileWriter(new File("/sdcard/NEWFILE_TEMP")),MODE_WORLD_READABLE);
The first part (cp to /sdcard/) seems to work, the file is present at /SDCARD, but it won't open. Superuser permissions have been granted.
Also
Code:
android:permission="android.permission.WRITE_EXTERNAL_STORAGE"
has been added to the manifest.xml file.
What am I missing here?

nobody has an idea?

You don't need to chmod the file.
With superuser shell you can access all files anyways and after you have copied it to the sdcard anyone can do anything with it.
jehan1 said:
but it won't open
Click to expand...
Click to collapse
How do you know that?
Maybe post the error message?

Related

[GUIDE] how to make a flashable package (update.zip)

thanks to this page for teaching me: http://www.robmcghee.com/android/creating-an-android-update-zip-package/
note: although i am copying this from the page, this isnt a straight ctrl+c, ctrl+p from it. ive rewritten it with slightly more english. ok alot more.
before we start, grab ppcgeeks auto signer here, or nothing will flash anyway. its the easiest method since its drag, drop, and click.
also i recommend 7-zip but its not necessarily needed.
first step, make the folder structure.
ive included prebuilt updates to make it a little faster for you. they contain no actual files, just the appropriate folder structure and update script. they must be resigned if you add files and expect to flash them.
if what your looking for isnt included, make a folder and name it "workdir". this will contain your work.
this is just to make it easier to organize all your stuff. if you feel so inclined you can name it whatever you want, it doesnt really matter.
next youll need to make folders inside the workdir according to where your flashing stuff, ie if your flashing wallpapers youd need to make a structure that looks like this: "workdir/system/customize/resource"
next to make the update-script. this tells the system what to do.
first make this folder structure: "workdir/META-INF/com/google/android"
make sure you capitalize "META-INF"
now put a text file into the "android" folder and call it "update-script"
the easiest way to code it would be to copy this into it:
Code:
show_progress 0.1 0
copy_dir PACKAGE:(x) (X):
set_perm_recursive 0 0 0755 0644 (X):(y)
show_progress 0.1 10
replace the (x) with the directory in the root your flashing to in lowercase, ie system or data or sdcard.
replace the (X)'s with the same thing as (x) except in UPPERCASE such as SYSTEM or DATA or SDCARD.
replace the with the next directory in lowercase like media or app or customize.
note: if your adding to the root of (X) folder then leave this blank, no spaces or anything.
if your flashing an app it should look something like this:
Code:
show_progress 0.1 0
copy_dir PACKAGE:system SYSTEM:
set_perm_recursive 0 0 0755 0644 SYSTEM:app
show_progress 0.1 10
after youve done that, save and close the file. now you need to take the extension off of the text file. simply delete the .txt at the end of the file.
if there is no extension showing, make sure you have "hide extensions for known file types" unchecked in tools> folder options> "view" tab.
second to last step! compress the workdir contents into a zip file, not the actual workdir though. it should look like this inside the zip: "update.zip/(folders)" not "update.zip/workdir/(folders)"
finally, sign the zip with the auto signer and put it into the root of the sd card.
boot into recovery and flash it up! with a bit of luck, it should work.
if you have any questions, problems, or concerns just post them. i have instant subscription to this thread and will be notified every 30 min when my evo fetches my mail.
Thanx for this thread!
Ok, my app should be installed in /system/app/
but is it possible to include in the same (app)update-script: delete /data/app/xxx.apk?
What directories do boot animations go into?
Awesome thread and thanks btw.
Foxwolfe said:
What directories do boot animations go into?
Click to expand...
Click to collapse
/data/local/
rori~ said:
Ok, my app should be installed in /system/app/
but is it possible to include in the same (app)update-script: delete /data/app/xxx.apk?
Click to expand...
Click to collapse
honestly, i couldnt tell you for sure but i dont see why you couldnt
Foxwolfe said:
Awesome thread and thanks btw.
Click to expand...
Click to collapse
thanks
I keep getting a syntax error. I am trying to flash silent.mp3 so i can select that in my notifications, because for some reason it does not have that option :/
can you let me know where I went wrong?
have tried both
set_perm_recursive 0 0 0755 0644 SYSTEM:media
set_perm_recursive 0 0 0755 0644 SYSTEM:notifications
but to no avail
what was the whole code in the update-script?
did you use the example i posted?
show_progress 0.1 0
copy_dir PACKAGE:system SYSTEM:
set_perm_recursive 0 0 0755 0644 SYSTEM:media
show_progress 0.1 10
daktah said:
what was the whole code in the update-script?
did you use the example i posted?
show_progress 0.1 0
copy_dir PACKAGE:system SYSTEM:
set_perm_recursive 0 0 0755 0644 SYSTEM:media
show_progress 0.1 10
Click to expand...
Click to collapse
yeah, sorry for not making it clear. Im kinda rote-learning this atm, I did a straight copy of your notifications script into my flashable-zip. when that didnt work I tried it with line3 modified as a stab in the dark.
what does the entire folder structure look like? if I am changing notifications is it /system/media/audio/notification where I put the files?
i believe it is
Code:
workdir.zip/
_system/
__media/
___audio/(files).mp3
_META-INF/
__com/
___google/
____android/update-script
if you still cant get it going i can assemble it for you
Just wanting to be sure here because Ive read the first post a few times and still can't tell. On the root of the update.zip I am supposed to create the folder structure that I want it to flash too. (ie. media/audio/ringtones) and then place the actual file that im flashing in that directory. (ie media/audio/ringtones/newring.mp3) At this point then the whole .zip dir would look like:
update.zip
__media/
_____audio/
_______ringtones/
__________newring.mp3
__META-INF/
_____com/
_______google/
___________android/
_______________update-script
_____CERT.RSA
_____CERT.SF
_____MANIFEST.MF
Then just sign the .zip and flash it... Is this correct?
You got it
Wow sounds real complex just to add an mp3 for a ringtone. I know if you create a file on sdcard
media/
audio
alarm
notifacation
And then put the file you want for what you want into the folder you want it for it will show in dropdown menu so you can select it.
Been trying to get googles auto app builder program to force download the sdk for devices so i can start there first. Want an app that forces mms to the sprint max of 5mb send limit and not stocks 2mb or handsents 1.2 limit. Will doing this according to thread give me an app that does this? What would i need to change? (guess you could make it faster than trying to teach me but still wonder)
jpwhre said:
Wow sounds real complex just to add an mp3 for a ringtone. I know if you create a file on sdcard
media/
audio
alarm
notifacation
And then put the file you want for what you want into the folder you want it for it will show in dropdown menu so you can select it.
Click to expand...
Click to collapse
thats true but installing saves space on the sd card and makes it load instantly instead of waiting for the sd card to be prepared
jpwhre said:
Been trying to get googles auto app builder program to force download the sdk for devices so i can start there first. Want an app that forces mms to the sprint max of 5mb send limit and not stocks 2mb or handsents 1.2 limit. Will doing this according to thread give me an app that does this? What would i need to change? (guess you could make it faster than trying to teach me but still wonder)
Click to expand...
Click to collapse
what? im lost lol
On wm arcsoft had a setting in the app that lets you change settings and change size limit to 500kb. You can also make these changes in regeditor. Android doesn't have a registory nor does there seam to be an app to install that will allow these changes. Wondering if your tutorial thread would allow the building of an app and what would i need to change to do this. Googles app builder program doesn't come preinstalled with any sdks and on a slow connection i can't get it to download.
if your saying building an app as in coding and assembling one then no as this is just a guide to make an installable zip to flash with ra or clockwork. youd need to use the sdk tools and such for that. but this guide should allow you to install pretty much anything into the nand from ringtones to apks and the like.
daktah said:
i believe it is
Code:
workdir.zip/
_system/
__media/
___audio/(files).mp3
_META-INF/
__com/
___google/
____android/update-script
if you still cant get it going i can assemble it for you
Click to expand...
Click to collapse
finally got adb to stop sh***ing itself. did it that way.
thanks for the help anyway.
so, i'm by no means an expert at this... but i was trying to make an update.zip for wallpapers. i've attached what i did, if you could take a peak at it and give me a pointer, that would be awesome!
path to my wallpapers...
using launcherpro
data/app/com.fede.launcher-1.apk/res/drawable-hdpi
data/app/com.fede.launcehr-1/apk/res/drawable-mdpi
granted, I'm trying to flash a theme, but it seems like the process and folder/file structure would be the same.
I've followed the steps one by one, but after flashing the .zip in recovery and rebooting, everything looks the exact same as it did before! I figured I would start with framewor-res, and see if I could get that to work before I started working on all the other images, but even after modifying all images, straightening out the .9.png's, and compiling everything correctly in Eclipse, I get nothing.
I have no effing clue what's going on, any ideas?
im on a mac, any suggestions for what i can use to sign the zip? i have apk manager and thempro and they can both sign apps but i dont know if its okay to use them to sign a flashable zip
Hi man!
I'm not do a Update.zip yet with your tutorial, but i have a question:
some Update.zip have a file named updated-binary together with update-script, how i do that file? because when i try to flash via OpenRecovery say's that coul'd not find that file: update-binary...
Sory for my english, i'm from Argentina, and i try not to use Google Translate...
Regards!!!
PS: Great work with this tutorial!!!

[Q] "Download Unsuccessful"

Ho there, Im sure this has been posted a thousand times before. The best post I could find was s0be's fix but the instructions are not in regular English. Basically, I am unable to download any new apps/any app updates for no apparent reason. I have tried every solution under the sun except this one. Usually you guys know what your talking about so I have confidence in it.
http://forum.xda-developers.com/showpost.php?p=11055157&postcount=4647
can anyone translate? would be much appreciated.
We can forgo any contemptuousness by simply acknowledging my n00byness now.
Thanks
dburg84 said:
1. adb shell
This starts an interactive shell with the device. Every command from now on will run on the device and not on the computer.
2. su
su = Super User = the highest level of clearance. Once this is called you are running as root and have access to every little thing in the OS. You are now the boss. You need "root" to get access to this command.
3. mkdir /cache/download
mkdir = Make Directory = Create a new folder/directory with the name "download" in the path "/cache/".
"/" being the master/root path for all paths.
4. chown system:cache /cache/download
chown = Change owner = Change the persons who are recognized by the OS as being the owners of that particular directory.
system:cache = the user is "system" and the group is "cache".
Every file and directory on the OS always has 3 person categories attached. User (the owner), Group(the group), All (everyone else). You can change permissions for every one of those 3 as seen below.
5. chmod ug+rwx /cache/download
chmod = Change Mode = change the permissions for a specific file.
ug = both the User and the Group.
+rwx = Add (the +) Read, Write and eXecute permissions.
ug+rwx /cache/download = Add Read, Write and eXecute permissions to the user and group for the directory "/cache/download".
6. chmod a+x /cache/download
As above, but here you giving everybody else eXecute permission only.
Click to expand...
Click to collapse
I have edited the post you referred to.
My comments are in bold.
Good luck
http://en.wikipedia.org/wiki/Chmod
http://en.wikipedia.org/wiki/Chown
http://en.wikipedia.org/wiki/Mkdir
Thanks!
Thanks for clarifying!
/sacrifice lamb to the XDA gods
I had the same problem some days ago and i tried almost everything i found on the web, but nothing worked.
At least i solved the problem replacing the market app (vendor.apk) with a most recent one.
To do this you need a working vendor.apk (i grabbed from a most recent rom) and a file explorer who can use root to copy file in /system/app (like ES File Explorer or Root Explorer).
Now simply replace vendor.apk.
This worked for me
Or you could just re-install it.
Use my APK installer tool and check the "re-install" box.
This will overwrite the apk file but not mess with the configuration...
Just like what you suggested :0)
yes sure, nice tool mate
Thanks for all your help!
Thanks for all the help! I did what you suggested and tried to replace the android market with a newer version. I couldn't do a direct install with a new APK, someone said you have to uninstall the old APK. I decided to try just flashing a new gapps; I got the files from this thread http://forum.xda-developers.com/showthread.php?t=909067
It worked. The new market was able to update my apps successfully.
You guys rock!!! Thanks again!
no problem mate, i got crazy for the same problem last weeke so i'm happy to share the solution
Would it work if i do the same for "download unsuccessful. please try again" problem ?
the "please try again" problem should be a connection problem I suggest to check your wi-fi or apn settings
I made it just a minute ago.
-- Unmount SD Card. (Settings - Sd& Phone Storage)
-- Install any app from Market. (It will install without any error.)
-- Mount SD card back. And ta-daaa! You can install any app from market now.
Thanks anyway
jamiescott23 said:
I made it just a minute ago.
-- Unmount SD Card. (Settings - Sd& Phone Storage)
-- Install any app from Market. (It will install without any error.)
-- Mount SD card back. And ta-daaa! You can install any app from market now.
Thanks anyway
Click to expand...
Click to collapse
i having this issue atm i have tried this and it didn't work...
you can also try to clear data from "download manager" in the app manager
ok got a fix to this with rom manger i DL and install new gapps Im useing CM6 so i used 20101020 mdpi-tiny i let it back up and wipe all data and it worked but i wish i would have tried it with out wipe 1st but it works now...

[TOOL][LINUX] Apktool binary replacement

This is a binary replacement for apktool
This replacement will make editing ICS apk's much easier without having to switch between tool versions ect...
To use simply place all the files within stools folder in /bin/ and set permissions 775 (Do not put folder in /bin/ only content)
Usage:
Decode apk:
1) Open terminal and enter "apktool -d apk"
2) It will then ask "Enter <apkfile/dir>:"
3) If you are already in the corrent folder just type the name of the apk e.g "framework-res.apk"
Done!
Encode apk:
1) Open terminal and enter "apktool -e apk"
2) It will then ask "Enter <apkfile/dir>:"
3) Type the name of the folder created when decoding the apk e.g "framework-res.apk" will be "framework-res" no .apk extension
Done!
Download
Hope this improves someone's work flow in one way or another
Hi Slethen,
This looks just what I need, but when I tried to download it, got the message:
404.
You Fail At Internet!
Click to expand...
Click to collapse
Meanwhile, I've downloaded AndroidSuite, but that looks like it's for Windoze.
Do you still have the linux version?
Thanks.
Thailandian said:
Hi Slethen,
This looks just what I need, but when I tried to download it, got the message:
Meanwhile, I've downloaded AndroidSuite, but that looks like it's for Windoze.
Do you still have the linux version?
Thanks.
Click to expand...
Click to collapse
Linux AndroidSuite - http://forum.xda-developers.com/showthread.php?t=1973066
Sorry about 404 my site took a lot of DDoS attacks and data loose was painful.
Site is back up as of 31 DEC 2012

Managing Sensitive Files? Thoughts?

Haven't received my device yet, but gearing up and getting things ready so I can hit the ground running when I receive it.
Coming from an LG G4 which had a 'lock' option in the gallery for hiding pictures. It effectively renames the image from .jpg to .jpg.dm so the gallery can't see it. LG G4 decided to get the bootloop bug so I'm switching.
I know there are many options out there but I've heard that some are hit or miss with newer phones (such as Vaulty).
What is the best way, specifically on the N6P, to keep certain files/pictures private? Any recommendations?
Alternatively, what I'm thinking of doing is something similar to the following:
1) Utilize a .nomedia file in the folders I want to keep private on the phone
2) Every other week or so, using Skipsoft Toolkit, download my phones pictures, etc. to my PC
3) Run a PowerShell script that will rename the extensions (see below)
OR
4) Build one PowerShell script that does everything (copy from phone to PC, rename if it finds certain extensions, etc.)
----------------------------
To copy files from Android via ADB by way of PowerShell (replace #2 above so you can do everything in one PowerShell script):
Code:
Place holder - need to actually get an Android device so I can test the script
To rename the file(s) by adding an extension to the file(s):
Code:
<# Renames all media files found in the working and sub-directories to have an extension of .hd #>
$Look4Ext = ".jpg|.jpeg|.png|.bmp|.gif|.3gp|.mp4|.webm|.mkv"
$files = Get-ChildItem $PSScriptRoot -Recurse | Where-Object {$_.Extension -match $Look4Ext}
ForEach ($file in $files) {
$filenew = $file.BaseName + ".hd"
Rename-Item -Path $file.fullname -NewName $filenew
}
To revert the name back by removing an extension from the file(s):
Code:
<# Renames all files in the working directory back to their original extension if they end in .hd #>
$Look4Ext = ".hd"
$files = Get-ChildItem $PSScriptRoot -Recurse | Where-Object {$_.Extension -eq $Look4Ext}
ForEach ($file in $files) {
$filenew = $file.basename
Rename-Item -Path $file.fullname -NewName $filenew
}
Full Script:
Code:
Placeholder

[TOOL] - Topway TS10 firmware workbench

Hi fellows
I'm a kind of newbie in the Android world, but I created a set of shell scripts to work with Topway TS10 Firmware:
---------------------------------------------------------------------------------------------------------------
TS10-Firmware-Workbench​Scripts intended to mount the Topway TS10 Firmware, make modifications and reassemble the firmware They can retrieve the firmware from specified location and after modification, they can put the firmware into another specified location
Files:
1-) config.ini = A file to setup parameters, paths for the original firmware and patched firmware, temp directory to work with firmware files and mount point to edit the firmware
2-) import_original.sh = Retrieves the files .0 .1 .2 and .3 from the location specified in config.ini
3-) import_patched.sh = Retrieves the same files that 'import_original.sh' but from the patched location specified in the config.ini (normally a firmware that you've already patched before)
4-) unpack.sh = Unpack the imported firmware and create the mount moint (as specified in the config.ini file) to work with the firmware
5-) repack.sh = Unmount the modified firmware from the mount point, delete the mount point, split the firmware in files .0 .1 .2 and .3 and move it to the patched directory as specified in config.ini
6-) inject_tweaks.sh = Modify locale, dataroaming and remove (if necessary) the values in ro.fota.device to avoid message "UI unauthorized, please contact the supplier"
7-) inject_mods.sh = This will copy all the contents of the '_mods' folder inside firmware. I.E. I put a 'gps_debug.cfg' inside 'system/etc/' and it will be injected into firmware overwritting the existent
inject_su.sh = This will inject su binary into firmware as a daemon, this is dangerous as the firmware is permanently rooted and the apps don't ask for permissions (they already have the root access) USE AT YOUR OWN RISK
9-) clean_local.sh = This script will unmount the firmware and delete it, it will also delete temporary files. as its name says, it cleans the dir !
External (included) tools:
tools/twt (Topwaytool) forked from https://github.com/mkotyk/topwaytool
_mods folder containing a sample file 'gps_debug.cfg'
N'joy it !
---------------------------------------------------------------------------------------------------------------
News
This will allow you to have root privileges in original firmware, but read VERY CAREFULLY as this method int NOT SAFE at all
At least for me it do the trick as I expected
I'll have my Topway TS10 THEME1 HU in a week and, if I am brave enough, I'll give it a go.
mariodantas said:
News here
https://github.com/mariodantas/TS10-Firmware-Workbench
This will allow you to have root privileges in original firmware, but read VERY CAREFULLY as this method int NOT SAFE at all
At least for me it do the trick as I expected
Click to expand...
Click to collapse
Is this way to root ownice k7 radio that i wish?? TT wow.....
This will ROOT, but everything inside will have ROOT privileges, UNSAFE, but as I said, for me, it did the trick and I'm happy with this !
mariodantas said:
This will ROOT, but everything inside will have ROOT privileges, UNSAFE, but as I said, for me, it did the trick and I'm happy with this !
Click to expand...
Click to collapse
Hello mariodantas.
I'm trying to utilize the project you made to mount firmware and inject su.
I'm a little new to some of this, so any guidance would be grateful.
Question:
How do i know what the mount point should be while using unpack.sh in config.ini?
! Creating _mountpoint folder...
Step 4 of 4 - Mounting ready raw firmware into '_mountpoint/' folder
mount: exec /Library/Filesystems/auto.fs/Contents/Resources/mount_auto for /Users/me/Desktop/TS10-Firmware-Workbench-main/_mountpoint: No such file or directory
mount: /Users/me/Desktop/TS10-Firmware-Workbench-main/_mountpoint failed with 72
READY !!!, you can go into '_mountpoint/' folder.
But _mountpoint folder is empty.
Andason74 said:
Hello mariodantas.
I'm trying to utilize the project you made to mount firmware and inject su.
I'm a little new to some of this, so any guidance would be grateful.
Question:
How do i know what the mount point should be while using unpack.sh in config.ini?
! Creating _mountpoint folder...
Step 4 of 4 - Mounting ready raw firmware into '_mountpoint/' folder
mount: exec /Library/Filesystems/auto.fs/Contents/Resources/mount_auto for /Users/me/Desktop/TS10-Firmware-Workbench-main/_mountpoint: No such file or directory
mount: /Users/me/Desktop/TS10-Firmware-Workbench-main/_mountpoint failed with 72
READY !!!, you can go into '_mountpoint/' folder.
But _mountpoint folder is empty.
Click to expand...
Click to collapse
What is your platform ? OSX ?
mariodantas said:
What is your platform ? OSX ?
Click to expand...
Click to collapse
Yes, OSX. I was checking more last night and maybe the issue is how mac handles the "auto" for file type.
Yes it sould be the mount command for OSX, but i can't help with OSX sorry, maybe you can clone the repo and after find the solution issue a pull request ?
after rooting the firmware doesn't seem to pass the checksum, everything is not working please help me ts10 1.2 ols10. ownice
Hello, have to check what's wrong with my code against 1.2 ols10 firmware, will check tonight and come back ASAP !
Cannot open file patch /init.rc.patch do not such how to fix please
Ok will check tonight !
@binharmani please add this to your config.ini
#Super User Folder
SUPERUSERFOLDER="_ superuser"
Click to expand...
Click to collapse
thank bro tool is ok . amazing good job
Thanks fellow
you can modify the "build.prop" manually after using "unpack.sh" by entering into "_mountpoint", modifying what you need and then repack the file and reflash in your headunit
How to set 775 file build.prop on linux
binharmani said:
How to set 775 file build.prop on linux
Click to expand...
Click to collapse
chmod 0775 build.prop
you should use a command line instead of the interface !
Mario good morning, if possible for you check the metode for change image car on display of ownice K7 ? Image in centrale display is very bad ifnpossible change png image with other car .......?
hello!
i've managed to use your tool, but there is a mention:
i've used it in a ubuntu vm (latest) and the mountpoint directory is empty if i don't run everything as root
repacked ok after this
my question is if i have to add the other files originally found in my original firmware folder with the newly repacked firmware files.
original firmware content (TS10.1.2_20210505.171701_TW1-V2):
a53f244a-9cbf-11ea-bb71-8bb1f7c98e0b.*
a71a8002-9cbf-11ea-b64e-578022b8a84a
ab2e7e2e-9cbf-11ea-bb71-fbb02866c44e
repacked firmware content:
a53f244a-9cbf-11ea-bb71-8bb1f7c98e0b.*

Categories

Resources