packageName.js
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { RELEASE_PACKAGE_NAME } from './constants.js'
/**
* 当前安装包名(自定义基座多为 io.dcloud.HBuilder,正式包为 uni.gltap)
*/
export function getRuntimePackageName() {
try {
if (typeof plus !== 'undefined') {
const osName = plus.os?.name
if (osName === 'Android' || osName === 'android') {
const main = plus.android.runtimeMainActivity()
const pkg = main?.getPackageName?.()
if (pkg) return String(pkg)
}
}
} catch (_) {
/* ignore */
}
return RELEASE_PACKAGE_NAME
}
/** 参与路径合并扫描的包名:当前运行包 + 正式发包名(遗留数据) */
export function getPackageNamesForMerge() {
const names = new Set()
const runtime = getRuntimePackageName()
if (runtime) names.add(runtime)
if (RELEASE_PACKAGE_NAME) names.add(RELEASE_PACKAGE_NAME)
return [...names]
}
export function getDefaultPackageRoots() {
const roots = []
const seen = new Set()
for (const pkg of getPackageNamesForMerge()) {
for (const path of [
`/data/data/${pkg}`,
`/data/user/0/${pkg}`,
`/storage/emulated/0/Android/data/${pkg}`
]) {
if (!seen.has(path)) {
seen.add(path)
roots.push(path)
}
}
}
return roots
}