Skip to content

Commit 3d430e1

Browse files
committed
修复 adb shell dumpsys package 命令无法在高版本的 Android 获取 uid 的问题
1 parent 36ea4f4 commit 3d430e1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

shell/device-tools/DisplayLogcat.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ displayLogcatSingleDevice() {
4747
fi
4848

4949
if [[ -z "${uid}" || ! "${uid}" =~ ^[0-9]+$ ]]; then
50-
uid=$(adb -s "${deviceId}" shell dumpsys package "${packageName}" < /dev/null 2>/dev/null | awk -F'=' '/userId/{print $2; exit}' | awk '{print $1}' | tr -d '\r')
50+
local uidKey
51+
if (( androidVersionCode >= 34 )); then
52+
uidKey="appId"
53+
else
54+
uidKey="userId"
55+
fi
56+
uid=$(adb -s "${deviceId}" shell dumpsys package "${packageName}" < /dev/null 2>/dev/null | awk -F'=' -v key="${uidKey}" '$0 ~ key {print $2; exit}' | awk '{print $1}' | tr -d '\r')
5157
fi
5258

5359
if [[ -z "${uid}" || ! "${uid}" =~ ^[0-9]+$ ]]; then

0 commit comments

Comments
 (0)