Skip to content

app info add VersionName and VersionCode #38

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

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

poetry.lock
window_dump.xml
Expand Down
39 changes: 37 additions & 2 deletions uiautodev/driver/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,48 @@ def volume_down(self):

def volume_mute(self):
self.adb_device.keyevent("VOLUME_MUTE")


def get_app_version(self, package_name: str) -> Optional[dict]:
"""
Get the version information of an app, including mainVersion and subVersion.

Args:
package_name (str): The package name of the app.

Returns:
dict: A dictionary containing mainVersion and subVersion.
"""
output = self.adb_device.shell(["dumpsys", "package", package_name])

# versionName
m = re.search(r"versionName=(?P<name>[^\s]+)", output)
version_name = m.group("name") if m else ""
if version_name == "null": # Java dumps "null" for null values
version_name = None

# versionCode
m = re.search(r"versionCode=(?P<code>\d+)", output)
version_code = m.group("code") if m else ""
version_code = int(version_code) if version_code.isdigit() else None

return {
"versionName": version_name,
"versionCode": version_code
}

def app_list(self) -> List[AppInfo]:
results = []
output = self.adb_device.shell(["pm", "list", "packages", '-3'])
for m in re.finditer(r"^package:([^\s]+)\r?$", output, re.M):
packageName = m.group(1)
results.append(AppInfo(packageName=packageName))
# get version
version_info = self.get_app_version(packageName)
app_info = AppInfo(
packageName=packageName,
versionName=version_info.get("versionName"),
versionCode=version_info.get("versionCode")
)
results.append(app_info)
return results

def open_app_file(self, package: str) -> Iterator[bytes]:
Expand Down
6 changes: 4 additions & 2 deletions uiautodev/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Rect(BaseModel):

class Node(BaseModel):
key: str
name: str # can be seen as description
name: str # can be seen as description
bounds: Optional[Tuple[float, float, float, float]] = None
rect: Optional[Rect] = None
properties: Dict[str, Union[str, bool]] = {}
Expand All @@ -50,4 +50,6 @@ class WindowSize(typing.NamedTuple):


class AppInfo(BaseModel):
packageName: str
packageName: str
versionName: Optional[str] = None # Allow None values
versionCode: Optional[int] = None
Loading