Permission denied message on Android method tracing - android

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

Related

Android app permission problem running under VirtualBox

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

Android -- Is there anywhere I can write a log file so that I can look at it without having root?

I have a very intermittent bug and need to do some logging to figure it out.
I am trying to create an error log file that I can look at on my device. I can't seem to create a file anywhere other than data/data/com.myapp/files or data/data/com.myapp/databases. I understand that I can't root my device using towelroot and I don't want to use something more risky (device is Motorola XT907, Droid Razr M, System Version 182.46.15, OS 4.4.2). Any ideas would be appreciated.
You could output to logcat and filter your process via ADB.
adb logcat
Or use DDMS, I use DDMS from within Eclipse with it's ADT plugin.
Also you could write and read from external storage, you'll need to add the permissions to your manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Then follow the guide here to write and read to external storage
http://developer.android.com/training/basics/data-storage/files.html

Emulator : Dev tools has stopped on running media provider

I added few songs using DDMS and in the emulator opened Dev tools->Media Provider and ran scan SD card but got the error msg : Dev tools has stopped. Any idea how to resolve this ? I tried creating new AVD also both in Eclipse and Android Studio , Genymotion . But same results. Can anyone help on how to resolve this?
On API 23 Emulator you can go to Setting => App => Dev Tools => Permissions , and check the permissions
Answering just in case it helps someone.
Giving permissions to Dev tools solves the issues sometimes but if it does not, one option is to download the files (songs or images) using browser on your emulator, if number of files is not much.
Worked well for me.
It seems that in the Nexus 5 image that comes with the latest version of Android Studio, the "Dev Tool" app does not declare the required <uses-premission> element in its manifest. If you filter the logcat by com.android.developer you will see this exception:
Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=2331, uid=10023
Unfortunately there's not a lot you can do if you're not willing (or don't know how, as I admit I don't) to pull out the apk, unpack it, edit the AndroidManifest.xml, and pack it all back in. Use another image, or refresh the MediaStore using adb shell:
Refresh Android mediastore using adb

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