In an instrument test, there is the need to read a file from folder /data/data/com.somePkg.xxx/files/My Baselines/20180111.ptm
.
The usual way File file = new File(String path)
won't work, since the target file is in a private package folder, it is not accessible, so have to use cat
.
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
String res = mDevice.executeShellCommand("cat /data/data/com.somePkg.xxx/files/My Baselines/20180111.ptm")
But there is a terrible issue with the space in the dict name "My Baselines", using "\ " won't work.
In the end, have to use find
command to get the file path and cat it directly:
String pkgFolder = "/data/data/com.somePkg.xxx/"
String cmd = "su 0 find " + pkgFolder + " -name *ptm -exec cat {} + ";
String res = mDevice.executeShellCommand(cmd);
And it works!
网友评论