Skip to content

Commit ca4e0ab

Browse files
committed
feat: overview kernel version and font scale
1 parent 463869f commit ca4e0ab

File tree

10 files changed

+110
-59
lines changed

10 files changed

+110
-59
lines changed

src/common/langs/en-US.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,8 @@
106106
"no": "No",
107107
"minSdkVersion": "Min SDK Version",
108108
"targetSdkVersion": "Target SDK Version",
109-
"onlyPackage": "Only Packages"
109+
"onlyPackage": "Only Packages",
110+
"kernelVersion": "Kernel Version",
111+
"physicalResolution": "Physical Resolution",
112+
"fontScale": "Font Scale"
110113
}

src/common/langs/zh-CN.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,8 @@
106106
"no": "",
107107
"minSdkVersion": "最小 SDK 版本",
108108
"targetSdkVersion": "目标 SDK 版本",
109-
"onlyPackage": "仅显示应用"
109+
"onlyPackage": "仅显示应用",
110+
"kernelVersion": "内核版本",
111+
"physicalResolution": "物理分辨率",
112+
"fontScale": "字体缩放"
110113
}

src/main/lib/adb.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ async function getOverview(deviceId: string) {
5757
const device = await client.getDevice(deviceId)
5858
const properties = await device.getProperties()
5959
const cpus = await getCpus(deviceId)
60+
const [kernelVersion, fontScale] = await shell(deviceId, [
61+
'uname -r',
62+
'settings get system font_scale',
63+
])
6064

6165
return {
6266
name: getMarketName(properties) || properties['ro.product.name'],
@@ -68,6 +72,8 @@ async function getOverview(deviceId: string) {
6872
sdkVersion: properties['ro.build.version.sdk'],
6973
serialNum: properties['ro.serialno'] || '',
7074
cpuNum: cpus.length,
75+
kernelVersion,
76+
fontScale: toNum(fontScale),
7177
...(await getStorage(deviceId)),
7278
...(await getMemory(deviceId)),
7379
...(await getScreen(deviceId)),
@@ -141,23 +147,25 @@ async function screencap(deviceId: string) {
141147
}
142148

143149
async function getScreen(deviceId: string) {
144-
const wmSize = await shell(deviceId, 'wm size')
145-
const wmDensity = await shell(deviceId, 'wm density')
146-
147-
const useOverrideResolution = contain(wmSize, 'Override')
148-
const useOverrideDensity = contain(wmDensity, 'Override')
149-
const resolution = getPropValue(
150-
useOverrideResolution ? 'Override size' : 'Physical size',
151-
wmSize
152-
)
153-
const density = getPropValue(
154-
useOverrideDensity ? 'Override density' : 'Physical density',
155-
wmDensity
156-
)
150+
const [wmSize, wmDensity] = await shell(deviceId, ['wm size', 'wm density'])
151+
152+
const physicalResolution = getPropValue('Physical size', wmSize)
153+
const physicalDensity = getPropValue('Physical density', wmDensity)
154+
155+
const hasOverrideResolution = contain(wmSize, 'Override')
156+
const hasOverrideDensity = contain(wmDensity, 'Override')
157+
const resolution = hasOverrideResolution
158+
? getPropValue('Override size', wmSize)
159+
: physicalResolution
160+
const density = hasOverrideDensity
161+
? getPropValue('Override density', wmDensity)
162+
: physicalDensity
157163

158164
return {
159165
resolution,
166+
physicalResolution,
160167
density,
168+
physicalDensity,
161169
}
162170
}
163171

src/main/lib/adb/base.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Adb, { Client } from '@devicefarmer/adbkit'
88
import getPort from 'licia/getPort'
99
import toNum from 'licia/toNum'
1010
import types from 'licia/types'
11+
import isStr from 'licia/isStr'
1112

1213
let client: Client
1314

@@ -91,11 +92,23 @@ export async function init(c: Client) {
9192
client = c
9293
}
9394

94-
export async function shell(deviceId: string, cmd: string): Promise<string> {
95+
export async function shell(deviceId: string, cmd: string): Promise<string>
96+
export async function shell(deviceId: string, cmd: string[]): Promise<string[]>
97+
export async function shell(
98+
deviceId: string,
99+
cmd: string | string[]
100+
): Promise<string | string[]> {
95101
const device = await client.getDevice(deviceId)
96-
const socket = await device.shell(cmd)
97-
const output = await Adb.util.readAll(socket)
98-
return output.toString()
102+
const cmds: string[] = isStr(cmd) ? [cmd] : cmd
103+
104+
const socket = await device.shell(cmds.join('\necho "aya_separator"\n'))
105+
const output = (await Adb.util.readAll(socket)).toString()
106+
107+
if (cmds.length === 1) {
108+
return output
109+
}
110+
111+
return map(output.split('aya_separator'), trim)
99112
}
100113

101114
export async function forwardTcp(deviceId: string, remote: string) {

src/main/lib/adb/cpu.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ export async function getCpus(deviceId: string, speed = true) {
8383
})
8484

8585
if (speed) {
86-
const freqCmd = map(cpus, (cpu, idx) => {
87-
return `cat /sys/devices/system/cpu/cpu${idx}/cpufreq/scaling_cur_freq`
88-
}).join('\n')
89-
const freq: string = await shell(deviceId, freqCmd)
86+
const freqs = await shell(
87+
deviceId,
88+
map(cpus, (cpu, idx) => {
89+
return `cat /sys/devices/system/cpu/cpu${idx}/cpufreq/scaling_cur_freq`
90+
})
91+
)
9092
const speeds: number[] = []
91-
each(freq.split('\n'), (line) => {
93+
each(freqs, (line) => {
9294
line = trim(line)
9395
if (!line) {
9496
return

src/main/lib/adb/fps.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ async function getFpsByLatency(deviceId: string, pkg: string) {
5151
return fps
5252
}
5353

54-
const latencyCmd = map(layers, (layer) => {
55-
return `dumpsys SurfaceFlinger --latency "${layer}"`
56-
}).join('\n echo "aya_separator";\n')
57-
58-
const latency = await shell(deviceId, latencyCmd)
59-
const latencies = latency.split('aya_separator')
54+
const latencies = await shell(
55+
deviceId,
56+
map(layers, (layer) => {
57+
return `dumpsys SurfaceFlinger --latency "${layer}"`
58+
})
59+
)
6060
const allFps = map(latencies, (latency) => {
6161
latency = trim(latency)
6262
let fps = 0

0 commit comments

Comments
 (0)