Android app permission problem running under VirtualBox - android

I'm trying to run connected tests for my App using and Android ISO installed on VirtualBox. I got Android 7.1 ISO from http://www.android-x86.org/ . It is installed under VirtualBox and seems to be working correctly.
Our app uses PocketSphinx which creates some directories and stores some files in them. The app is working correctly on some Android 7.0 tablets and under the emulator that comes with Android Studio. Some of the time, it works correctly under VirtualBox, but it gets in some strange state where it cannot read or write to the directories it needs.
The AndroidManifest contains this permission (along with others):
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The permissions show up as enabled in the Settings=>Apps=>[Our App]=>Permissions.
Here is the actual error message:
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.hcs.android.orconnect/files/sync/cmudict-en-us.dict (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at java.io.FileOutputStream.<init>(FileOutputStream.java:169)
at edu.cmu.pocketsphinx.Assets.copy(Assets.java:224)
at edu.cmu.pocketsphinx.Assets.syncAssets(Assets.java:269)
If I set a breakpoint before this call, I can see that all of these return false:
new File("/storage/emulated/0/Android/data/").canRead()
new File("/storage/emulated/0/Android/data/").canWrite()
new File("/storage/emulated/0/Android/data/com.hcs.android.orconnect").canRead()
new File("/storage/emulated/0/Android/data/com.hcs.android.orconnect").canWrite()
However, something created the /storage/emulated/0/Android/data/com.hcs.android.orconnect/files folder. If I manually delete this folder from an adb shell prompt, it will be recreated on the next run of my App test, but the app still has the same problems.
I'm really at a loss as to why I'm having these permission problems. Any ideas on what is going on and how to fix the permissions?
(Note: I don't want to use the Android emulator, because we are running VirtualBox for other reasons and the two won't play with each other.)
(Note: Unsurprisingly, running the app from the debugger shows the same problems I'm seeing when I run the connected test.)
Steps to reproduce:
Set up and start VirtualBox image running the Android 7.1 ISO.
Run adb connect <ip address>
Run ./gradlew connectAndroidTest
Test will pass
Run ./gradlew connectAndroidTest
Test will fail and will fail for all future runs as well.
Work around:
Install the app (if not currently installed)
Twiddle the "Storage" permission in Settings => Apps => [My App]

Tracked the problem down to an inconsistency in Android's handling of permissions.
Our App's Manifest contained:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
This results in /data/system/users/0/runtime-permissions.xml containing:
<item name="android.permission.READ_EXTERNAL_STORAGE" granted="true" flags="0" />^M
<item name="android.permission.WRITE_EXTERNAL_STORAGE" granted="true" flags="0" />^M
Read is granted implicitly. However, when writing a connected test, I used the grant permission rules:
#Rule public GrantPermissionRule permissionRule2 = GrantPermissionRule.grant(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
This, however, does not implicitly grant read permission. So, when the app was run for the first time on the VM, it was granted WRITE explicitly and READ implicitly. However, after gradlew ran the test for the first time, it would uninstall the app. Then the next test run would reinstall the app, but only grant it WRITE permission per the rules. Then the test fails as described above.
So, the solution is to ask for both read and write permission in the test:
#Rule public GrantPermissionRule permissionRule2 = GrantPermissionRule.grant(android.Manifest.permission.READ_EXTERNAL_STORAGE);
#Rule public GrantPermissionRule permissionRule25 = GrantPermissionRule.grant(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
Never mind that this doesn't match my AndroidManifest.xml file. Google's left and right hand never met, so the behavior is different.
Thanks, Google! /s

Related

Uid issues between two applications for the 'strace' command

I'm going to use the strace -p <myPid> command between two applications.
However, strace command does not work with other applications (it works well for itself).
This is the error message:
attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted
Could not attach to process. If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf
If the command error occurs because of the difference of uid, can I fix modifies the uid?
Or is there any other solutions?
I did not exactly resolve on this issue, there are some problems figured out.
This issue is associated with setUid permission and android SE.
First of all, then build a android version 4.0.3, so I flashed an image file to a reference Phone.
And after giving the permission of setUid STRACE, it works well.(android SE was released above 4.3)
However, version 4.4.2 android SE were blocking the access process.
(Galaxy series can not be released because the android SE and KNOX interact with each other.)
Unfortunately, now I don't have an extra reference phone, turn off the android SE, I can't try running the command STRACE.(I'll update as soon as possible.)

Can't install app com.android.mms on android (INSTALL_FAILED_DUPLICATE_PERMISSION)

This is in the border of programming, so please delete the question if it's not correct posting it.
Question is regarding the Android 5.0 Lollipop.
Basically I've installed the "Messaging" app (com.android.mms) from inside another program (hide it pro). It's an older version of the android messaging. Then my Samsung s5 broke and I had to restore all apps into another similar Samsung. When trying to install the messaging app again (from inside or outside hide it pro) it fails with the error -505. Searching on the net I ended up by installing the android sdk and use adb to see if I could solve the issue. No luck: if I try to uninstall the app (which doesn't exist on the new phone) I get the error DELETE_FAILED_INTERNAL_ERROR.
$ adb uninstall /c/mfg/sms.apk
* daemon not running. starting it now o
* daemon started successfully *
Failure [DELETE_FAILED_INTERNAL_ERROR]
If I try to install the app via adb I get the following result:
$ adb install /c/mfg/sms.apk
3439 KB/s (2078237 bytes in 0.590s)
pkg: /data/local/tmp/sms.apk
Failure [INSTALL_FAILED_DUPLICATE_PERMISSION
perm=android.permission.MMS_SEND_OUTBOX_MSG pkg=com.android.mms]
I don't have the application on the phone, I can't put it to work and I can't get rid of the permissions. There's no way to uninstall on the phone since the app is not there and it won't let itself be installed. It doesn't appear on the Application Manager under "downloaded" or anywhere else.
My question is: is there no way to wipe out the permissions WITHOUT having the application? What I wanted was an app that allowed me to delete the permissions, regardless of having the app or not. The phone is not rooted at the moment but if needed I can root it to solve the issue if it helps. Please advise.
So I've finally found the issue. Thanks Manish and iagocanalejas for the suggestions.
It seems that something changed on the permissions system on android 5.0 (as part of one of the updates). It didn't happen before, but now if two packages from different applications ask for the same permission (in this case android.permission.MMS_SEND_OUTBOX_MSG pkg=com.android.mms), it won't let the second application install.
This behavior is new and didn't happen on previous versions of Lollipop. Flashing a newer version of the OS on my phone clearly didn't solve the issue (original was G900FXXU1BNL9 and I've finished with G900FXXU1BOD3). If anything, only made it worse since this behavior seems to have come to stay.
The solution was to root the phone, install Titanium Backup, and (after backing up everything) REMOVING with help of Titanium Backup the "Messages" application which on the Samsung replaces the standard "Messaging" android app.
Titanium backup was needed because "Messages" is considered as a system application and therefore couldn't be removed normally. No SMS messages were lost by removing "Messages". It was necessary to reboot the phone after removing "Messages" so that "Messaging" could be installed, but finally, after 2 weeks of effort, it could be done.
Have you tried to uninstall using application package? This should delete any data/cache associated with application.
$ adb uninstall com.android.mms
Install the application after this as usual:
$ adb install /c/mfg/sms.apk
Take a look on your manifest and see if u have duplicated rows

Permission denied message on Android method tracing

I'm trying to follow these steps to help figure out where my first Android app (using Android Studio, targeting a Nexus 9) is crashing:
http://developer.android.com/tools/debugging/debugging-tracing.html
I added Debug.startMethodTracing and Debug.stopMethodTracing to my main activity code in the recommended places. When I actually debug my code I get the following message in my "logcat" window.
02-17 11:40:34.418 15711-15711/com.mpr.myfirstapp E/artīš• Unable to open trace file '/storage/emulated/legacy/seemore.trace': Permission denied
I'm not sure why this is, and I'm also not sure how in Android Studio to view the trace logs. Can anyone help?
NOTE:
It seems worth noting that (from the link)
Android 2.2 and later devices do not need an SD card. The trace log
files are streamed directly to your development machine.
So I'm not sure if the permission issue is on my dev machine or on the device.
Thanks for any help.
You can use the Android Device Monitor to trace from your dev machine.
Try adding these to your AndroidManifest.xml and let me know if the error is still there.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Then in terminal you want to run (if you're on PC the command would be different but similar)
adb pull /sdcard/seemore.trace ~/tmp
Then open up Android Device Monitor and open up the file, now located in
~/tmp/seemore.trace
you can start the Android Device Monitor using the command
./monitor

Unable to get introspy.db file

I am running Introspy android application for penetration testing of android app but i am unable to get introspy.db file from application's internal files.
I took reference from https://github.com/iSECPartners/Introspy-Android
I know this was asked a long time ago but in case anyone else who searches needs an answer:
I also had this problem when running Introspy on a Galaxy S4 running KitKat (4.4.2). I have ran Introspy with zero problems on a Nexus S running JellyBean (4.2.1). Because of this I believe it is an Android SDK problem with newer versions.
If you look at the AndroidManifest file for Introspy-Android Core, the targetSdkVersion is 18, which denotes Jellybean. I looked at logcat files and found that I was getting the error:
Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
I simply added this permission to the Android Core AndroidManifest.xml file as well as the Android Config AndroidManifest.xml with the command:
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>
I then just recompiled both binaries and it worked! Hope this helps.
Is Cydia Substrate for Android installed? (https://play.google.com/store/apps/details?id=com.saurik.substrate&hl=en). The SuperSU.apk (https://play.google.com/store/apps/details?id=eu.chainfire.supersu&hl=en) may also be needed to give root permissions to Cydia substrate. Upon installing Cydia Substrate and SuperSU, you can give root permissions to the Substrate application and click on "Link Substrate" button in the Cydia Substrate application. Then try to start Introspy Config and setup the appropriate methods to hook into. Hopefully, this should do it. Also, all of this assumes you have a rooted phone or emulator.

Change Android firmware programmatically

I am trying to develop an application, which will check for firmware updates and will install updated firmware manually. Is it possible to get which modules of the firmware are added to update and the progress for updation?
It should be possible. I am trying to do the same thing. I posted a question about this as another user. It almost works for me, but my device can't apply the new image on boot time.
Basically you use the RecoverySystem.installPackage(context, packageFile) method to do this. You will also need the following permissions:
<uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" />
<uses-permission android:name="android.permission.DELETE_CACHE_FILES" />
Also, your app must run as a system app. I don't know if you're using the whole Android SDK with Eclipse and the SDK tools, but what I did for that was basically connect my device to my machine and used it for debuggin, then ran the app through the IDE so it gets uploaded and run on the device. And finally use the adb shell command to open up a shell on my device and moved the apk package file from /data/app to /system/app and rebooted.
Check out my post here. It might help you out.
Android development RecoverySystem.installPackage() cannot write to /cache/recovery/command permission denied

Categories

Resources