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

feat:添加“自动授权应用权限”方法,指定包名后自动赋予被测应用运行时所需权限,不再出现运行时权限弹窗,避免对用例执行的干扰 #977

Merged
merged 4 commits into from
May 27, 2024

Conversation

caofengbin
Copy link
Contributor

Android端6.0之后的系统,部分敏感权限系统强制要求运行时动态授权,会对用例执行产生干扰,需要自己处理。

参考Appium的启动参数autoGrantPermissions的实现原理,补齐相关能力。

appium-adb中的实现方式

Copy link
Member

@codeskyblue codeskyblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just need little update

bool of operate
"""
output, _ = self.shell(['dumpsys', 'package', f'{package_name}'])
groupPattern = re.compile(r'^(\s*' + 'runtime' + r' permissions:[\s\S]+)', re.MULTILINE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use group_pattern instead of groupPattern. the following code need follow the same rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经修改

@@ -873,6 +873,42 @@ def app_info(self, package_name: str) -> Dict[str, Any]:
"versionCode": info.version_code,
}

def app_auto_grant_permissions(self, package_name: str) -> bool:
""" auto grant runtime permissions to target app,prevent dynamic permission pop-up window to pop up
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref https://github.com/appium/appium-adb/blob/master/lib/helpers.js#L585

if (apiLevel < 23) {
      log.debug(`Skipping permissions grant option, since ` +
                `the current API level ${apiLevel} does not support applications ` +
                `permissions customization`);

does here need to check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

尝试在增加授权之前获取了目标App的target API版本,做判断之后再进行授权操作。

else:
permissionName = permissionNameMatcher.group()
print(permissionName)
self.shell(['pm', 'grant', f'{package_name}', permissionName])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here just use package_name if ok, no need to use f'{package_name}'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 7.14286% with 26 lines in your changes are missing coverage. Please review.

Project coverage is 24.68%. Comparing base (64c6f2b) to head (c11fd22).
Report is 1 commits behind head on master.

Files Patch % Lines
uiautomator2/__init__.py 7.14% 26 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #977      +/-   ##
==========================================
+ Coverage   24.39%   24.68%   +0.28%     
==========================================
  Files          19       19              
  Lines        2820     2832      +12     
  Branches      430      435       +5     
==========================================
+ Hits          688      699      +11     
- Misses       2106     2108       +2     
+ Partials       26       25       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codeskyblue
Copy link
Member

还是需要调整一下。

这个sdk版本是根据系统的版本来的,而不是根据sdk里面写的版本。

具体可以参考 https://developer.android.com/tools/adb#pm
image

https://stackoverflow.com/questions/16410167/how-do-i-use-adb-grant-or-adb-revoke

@caofengbin
Copy link
Contributor Author

还是需要调整一下。

这个sdk版本是根据系统的版本来的,而不是根据sdk里面写的版本。

具体可以参考 https://developer.android.com/tools/adb#pm image

https://stackoverflow.com/questions/16410167/how-do-i-use-adb-grant-or-adb-revoke

已经修改为通过adb shell getprop ro.build.version.sdk的方式拿到系统版本号,再做判断

@codeskyblue codeskyblue merged commit 5d20e56 into openatx:master May 27, 2024
7 of 8 checks passed
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