Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve 'stat' command not available on some devices #163

Merged
merged 13 commits into from
Dec 26, 2018

Conversation

finfou
Copy link
Contributor

@finfou finfou commented Jul 11, 2018

As 'stat' command might be not available, I tried to use 'ls -l's output instead.

I used bellow script to test the new method:

  1. detect /data/local/tmp which is executable 2. detect /data/local/tmp which isn't executable 3. /data which is not executable, on some device it return "file or directory doesn't found" and on others returns empty from stdout.

from uiautomator2 import adbutils
import os

adb = adbutils.Adb('4840a1ba')
dirs = ['/data/local/tmp', '/data/data/com.android.shell', '/data', '/data/local']
for dirname in dirs:
testpath = "%s/%s" % (dirname, 'permtest')
adb.shell('touch', testpath, raise_error=False)
adb.shell('chmod', '+x', testpath, raise_error=False)
content = adb.shell('ls', '-l', testpath, raise_error=False)
print('ls output: "%s"' % content)
if -1 !=content.find('x'):
print(dirname, 'is executable')
else:
print(dirname, 'is not executable')

Result1 from Z2

ls output: "-rw-rw-rw- shell shell 0 2018-07-11 19:41 permtest

"

/data/local/tmp is not executable

ls output: "-rwxrwxrwx shell shell 0 2018-07-11 19:41 permtest

"

/data/data/com.android.shell is executable

ls output: "/data/permtest: No such file or directory

"

/data is not executable

ls output: "/data/local/permtest: No such file or directory

"

/data/local is not executable

Result2 from Samsung S7 edge

ls output: "-rwxrwxrwx 1 shell shell 0 2018-07-11 19:42 /data/local/tmp/permtest

"

/data/local/tmp is executable

ls output: "-rwxrwxrwx 1 shell shell 0 2018-07-11 19:42 /data/data/com.android.shell/permtest

"

/data/data/com.android.shell is executable

ls output: ""

/data is not executable

ls output: ""

/data/local is not executable

@finfou
Copy link
Contributor Author

finfou commented Jul 11, 2018

BTW, the default atx-agent version provided by atx-server is still 0.3.3, the one provided by uiautomator2 is now 0.3.5. So when connected to server, there will be a downgrade, not sure if it's intended, so can wait for 0.3.5 become stable before update atx-server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants