I am trying to run a shell script through an android app. The script has a command which just runs a jar on the device. When I run this command directly on the shell using adb, everything works fine. But when I run it through the script using the android app, I get a permission denied exception (open failed: EACCES (Permission denied)) for the files created in /data/local/tmp folder. Can anyone guide in how to resolve this issue?
This is what my manifest looks like
<manifest ….>
<uses-sdk …>
<uses-permission… .>
…
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
…
<application …>
…
</application>
</manifest>
Thanks.
You can try to use the android:preserveLegacyExternalStorage="true" tag in the manifest file in the application tag. This tag is used to access the storage in the android 11 devices.
The purpose of a permission is to protect the privacy of an Android user. Android apps must request permission to access sensitive user data (such as contacts and SMS), as well as certain system features (such as camera and internet).
Only on a rooted device you could either change the permissions, or be privileged enough to override them. PS: On Android, the sudo command is simply called su -- which explains your last error ( /system/bin/sh: sudo: not found) in case your device is already rooted.
When you declare install-time permissions in your app, the system automatically grants your app the permissions when the user installs your app. An app store presents an install-time permission notice to the user when they view an app's details page, as shown in Figure 2.
Other pages explain how to evaluate whether your app needs to request permissions, declare permissions, request runtime permissions, and restrict how other apps can interact with your app's components. To view a complete list of Android app permissions, visit the permissions API reference page.
If I understand the scenario correctly, you create the script on the fly, and use /data/local/tmp
as an easy location that is both publicly writable and executable. Once, this was possible. But on recent versions of Android, security has been tightened.
Your app can execute files under /data/data/${your.package}
. You can use getContext().getFilesDir() to reliably obtain the full path. Note that you still need to use chmod 500
to ensure that the file has executable permission.
If you have some fixed executables (binaries or scripts) that must be installed with your app, there is a clever trick to let the system package installer take care of all that for you: make sure the file has a name "libsomething.so" and put it in /libs/armeabi
directory under the Eclipse project root. After installation, the files will be present in getContext().getApplicationInfo().nativeLibraryDir directory with executable permissions set.
PS You don't need the WRITE_EXTERNAL_STORAGE permission for this to work (maybe you need it for other things your app does).
PPS You can run a shell script from anywhere, including /sdcard
, and you don't need executable permission for the script. Instead, use sh -c source full.path.to.script
.
You can use the adb interface to copy and/or push files to the /data/local/tmp
folder but if you want to use/see them in the terminal app you will need to (in adb interface) first
cd /data/local/tmp
then make a folder inside the folder. Example
mkdir folder
next change the permissions
chmod - R 777 folder
Now you have a folder you can read and write to.
A few things that I would like to know is how to make the system think that the su
binary is in the /system/bin
folder (without copying) because I can only get tmp... root access because even with root access, I can not remount the system directory as rw
because the zte-paragon has its system partition formatted as a read-only file-system
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With