1

I have an android project that demonstrates how to write android test cases which can be executed on an emulator or a device. As a result of those test cases, data is populated in the device and the resultant SQLite *.db file can be downloaded from Android Studio's DDMS screen.

NOTE: I have already tried as a root user in adb shell. Problem I am facing in accessing *.db file is consistent from adb and DDMS in emulator with API 26.

Code is accessible here.

I have created 2 emulators (API 23 and API 26) in AVD Manager.

AVD Manager enter image description here

When I run the androidTest on both the emulators, all the test cases pass successfully.

Using Android Studio's DDMS ...

  • On the emulator with API 23, I am able to view the SQLite *.db file under /data/data/<package-name>/databases/weather.db and download it to my desktop and view it through http://inloop.github.io/sqlite-viewer/

DDMS enter image description here

ADB Shell enter image description here

  • On the emulator with API 26, the /data folder is empty?? I do not see the same hierarchy for accessing the SQLite *.db file as on device with API 23.

The android app and androidTest both run successfully on emulator with API 26 which means data is saved somewhere in android emulator but what is the new location?

DDMS enter image description here

ADB Shell enter image description here

Is it new behavior after API 25/26 and do I need special permissions to access data in DDMS or adb shell?

If this is new behavior then where is the SQLite *.db file located after API 25/26?

I have googled about it on stack overflow and android documentation but didn't find anything concrete, let me know if I have missed anything.

JRG
  • 4,037
  • 3
  • 23
  • 34

2 Answers2

0

Make sure:

1) You are running adb as root user.

2) Your emulator should have root access.

Link: How to get root access on Android emulator?

Uddhav P. Gautam
  • 7,362
  • 3
  • 47
  • 64
  • I have tried accessing `/data` directory as a `root user` but it doesn't help. I can't find my package under `/data/data` directory and it throws `Permission denied` error on adb shell. This error happens only on emulator with `API 26` and not with `API 23` or lower versions. Just wondering, if it's root user issue, then shouldn't it be same on emulator with `API 23` not just with `API 26`? – JRG Jul 24 '17 at 19:16
  • There is permission denied. Why don't you install "adb –e install supersu.apk" and give root access to your emulator? Please try this. As you said, you are already using adb via root. Probably there change in root access when you go from API 23 to API 26. – Uddhav P. Gautam Jul 24 '17 at 19:20
  • @JRG, Is is purely security permission related issue. Doing above two should solve the problem. – Uddhav P. Gautam Jul 24 '17 at 19:21
0

@jrg I have been testing to see how to write to the SD CARD and how to find the path to the INTERNAL location of a sqlite db and how to view it with Api 26 or greater. I am not sure this will help and I am curious about rooting an Emulator once rooted can you remove the rooting by deleting the device from the AVD manager

here is some code that might help

    String state = Environment.getExternalStorageState();

    if (state.equals(Environment.MEDIA_MOUNTED) && (!state.equals(Environment.MEDIA_MOUNTED_READ_ONLY))) {

        File removable = ContextCompat.getExternalFilesDirs(this, null)[1];
        THE_PATH = String.valueOf(removable) + "/Documents/";

        //System.out.println("ALL TRUE ==> " + THE_PATH);

    } else {// if (state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
        THE_PATH = "";
        //System.out.println("ALL FALSE ==> "+ THE_PATH);
    }

When I eject the SD CARD on the emulator and a real device I use this code to create the path

        Context context = this;
    String removable = getFilesDir().getAbsolutePath();
    THE_PATH = String.valueOf(removable)+"/";
    System.out.println("INTERNAL PATH ======> "+THE_PATH);
    File file = new File(context.getFilesDir(), "NAME_OF_FILE");
    String PA = String.valueOf(file);
    System.out.println("Where AM  I ======> "+PA);

I do not think Android permits you to navigate to the internal storage without a File Manager application on your device. Have you considered installing a File Manager app on the emulator. Down side to this is I think your need AS 2.4 beta to be permitted to do this

Vector
  • 3,066
  • 5
  • 27
  • 54