I'm trying to capture sound from microphone via Java Sound API.
I'm using sample code from github and it works perfect on Windows system, but when it runs on MacOS - audio-line buffer returns zero-bytes.
Also if I compile project to jar and run it via administrator permission - appears a message to give access to microphone and after I grant it - all works.
So the question is how to make permission request from code and run app without sudo?
Thanks!
BTW, you have to use the default terminal that comes with mac to execute jar file. That will worked.
The third party terminal, such as iTerm, it's not ok.
I am trying to write to a file using a FileOutputStream in java. I am running ubuntu and I think the problem is with the permissions. Even though the error I receive says '(No such file or directory)' I am sure the path I am giving is right, since I can read from the same file with no issues. I am not very familiar with ubuntu write permissions but I think I need to set the mode with chmod -r on the root directory. However I am not sure of the exact command and the option of permission I should set.
I would like to use an external executable within my android app.
It is distributed for different platforms and under windows it's a console program that can be used in this way
For Android the executable is called senpai-arm. I moved it to an Android folder and tried to start it in a similar way to the link above but it won't start.
String storage = context.getFilesDir().getAbsolutePath();
// Create the proccess in JAVA
Process proc = Runtime.getRuntime().exec(storage+ "/senpai-arm");
error message below:
java.io.IOException: Error running exec().
Command: [/data/user/0/com.example.jp.fanfar/files/senpai-arm] Working Directory: null Environment: nul
cause: Permission denied
Sorry that I didn't observe the cause Permission denied in my original question.
I rephrase my question a bit.
Is it possible to start a program like this?
What permissions do I need? I have read/write external storage permission.
(I have the source code in C++ and read about NDK but I was hoping to take a shortcut by using the distributed executable instead.)
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.
Update 8 years later
On modern versions of Android, there is no way to run downloaded or generated code (a.k.a. W^X violation). We can only embed prebuilt binaries in the APK (or bundle) (using jniLibs and other settings in gradle.build) and make sure it is extracted to the native file system (explicitly set android:extractNativeLibs = "true"). Then you can run the binary from getContext().getApplicationInfo().nativeLibraryDir.
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
I think the reason is that your Andorid is not been rooted.
the "/data" have the root Permission.
So root your phone first, and give your app the permission.
you can try command:"su" int the shell change to root.
Make sure the /data/local/tmp location is world-executable on your device:
adb shell ls -ld /data/ /data/local/ /data/local/tmp/
drwxrwx--x system system XXXX-XX-XX XX:XX
drwxr-x--x root root XXXX-XX-XX XX:XX
drwxrwx--x shell shell XXXX-XX-XX XX:XX
# ^ all x here == OK!
If it's not, there's nothing you can do, and you need to use the standard storage (internal /data/data/{package} or external /sdcard/).
Make sure you made the file world-readable.
adb shell chmod o+r /data/local/tmp/myfile.txt
You don't need any permissions.
I am running a webservice using glassfish server on Ubuntu. The problem is - it is required to access a directory outside of its shared resource. Presently it is giving an error saying "Permission Denied". I set a permission into server.policy too.
grant codeBase "/home/glassfish/glassfish/test/-" {
permission java.security.AllPermission;
};
But it seems not working.
I tried <property name="alternatedocroot_1" value="from=*.* dir=/home/glassfish/glassfish/test"/> , but it seems it is giving only reading permission. I need write permission also. So my question is how can I set the write permission ?
Thanks.
This is not a JavaSecurity problem so you shouldn't need to tweak anything in that regard.
FWIW our web-apps deployed to GF on various flavors of Windows write to directories which are outside of the 'Application' directory using File APIs. alternatedocroot pertains to GF serving static content using the DefaultServlet not to writing outside of the Application deployment directory.
On windows when you run as Service you have to be careful that the 'Run As' user has proper permissions to write to the target directory, on Unix you need to make sure the user set by your rc (init.d) scripts that runs asadmin.sh has permissions to read/write to the target directory.
I would double check the the user that the java process GF is running under has rwx permissions on the directory your are trying to write to. Make sure that user can write to the target folder. To test this you can su to the user and use the 'touch' command like so: touch /tmp/test and verify write permissions that way. Verify read permissions similarly by running 'ls -l /tmp/test' to make sure you can read it.
See what 'ps -ef | grep java' shows to verify the user running the GF java process. Additionally in your code try specifying a full path to the test file, eg. File test = new File("/tmp/test");
Are you running GF from an rc script or are you starting it using asadmin.sh from a shell prompt? If you are running an rc script check that your rc script is really running it as the user you expect it to be.