@bryce3310687963/android-toolkit 1.0.51 → 1.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/index.cjs +37 -5
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +37 -5
- package/dist/index.js.map +3 -3
- package/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -883,9 +883,16 @@ async function adbExec(ctx, args, options = {}) {
|
|
|
883
883
|
const startedAt = Date.now();
|
|
884
884
|
try {
|
|
885
885
|
const { stdout } = await execAdbWithRetry(adbPath, args, options);
|
|
886
|
-
Logger.useTemplate().adbExec({ duration: Logger.duration(startedAt), args: compactArgs(args) });
|
|
886
|
+
Logger.useTemplate().adbExec({ duration: Logger.duration(startedAt), args: options.sensitive ? "[REDACTED]" : compactArgs(args) });
|
|
887
887
|
return stdout;
|
|
888
888
|
} catch (error) {
|
|
889
|
+
if (options.sensitive) {
|
|
890
|
+
throw new CrawlerError({
|
|
891
|
+
message: "ADB command failed (sensitive content omitted)",
|
|
892
|
+
code: isAdbUnavailableError(error) ? Code.AdbUnavailable : Code.AutomationFailed,
|
|
893
|
+
context: { adbPath }
|
|
894
|
+
});
|
|
895
|
+
}
|
|
889
896
|
if (isAdbUnavailableError(error)) {
|
|
890
897
|
throw new CrawlerError({
|
|
891
898
|
message: `adb_unavailable: ${error?.message || String(error)}`,
|
|
@@ -914,7 +921,8 @@ async function writeCacheFile(ctx, options = {}) {
|
|
|
914
921
|
].join(" && ");
|
|
915
922
|
await Device.adbShell(ctx, [`su -c ${shellQuoteForRemote(command)}`], {
|
|
916
923
|
timeoutMs: Number(options.timeoutMs || 1e4),
|
|
917
|
-
maxBuffer: Number(options.maxBuffer || 1024)
|
|
924
|
+
maxBuffer: Number(options.maxBuffer || 1024),
|
|
925
|
+
sensitive: true
|
|
918
926
|
});
|
|
919
927
|
return filePath;
|
|
920
928
|
}
|
|
@@ -1238,8 +1246,8 @@ async function execAdbWithRetry(adbPath, args, options = {}) {
|
|
|
1238
1246
|
label: options.label || "adb",
|
|
1239
1247
|
attempt,
|
|
1240
1248
|
attempts,
|
|
1241
|
-
args: compactArgs(args),
|
|
1242
|
-
message: error?.message || String(error)
|
|
1249
|
+
args: options.sensitive ? "[REDACTED]" : compactArgs(args),
|
|
1250
|
+
message: options.sensitive ? "sensitive ADB command failed" : error?.message || String(error)
|
|
1243
1251
|
});
|
|
1244
1252
|
await sleep(delayMs * attempt);
|
|
1245
1253
|
}
|
|
@@ -1936,8 +1944,32 @@ import { promisify as promisify2 } from "node:util";
|
|
|
1936
1944
|
var execFileAsync2 = promisify2(execFile2);
|
|
1937
1945
|
var DeviceSQLite = {
|
|
1938
1946
|
query,
|
|
1939
|
-
health
|
|
1947
|
+
health,
|
|
1948
|
+
reset
|
|
1940
1949
|
};
|
|
1950
|
+
async function reset(ctx, options = {}) {
|
|
1951
|
+
const packageName = requireNonEmpty2(ctx?.packageName, "packageName");
|
|
1952
|
+
const dbNamePrefix = requireNonEmpty2(options.dbNamePrefix, "dbNamePrefix");
|
|
1953
|
+
if (!/^[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)+$/.test(packageName) || !/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(dbNamePrefix)) {
|
|
1954
|
+
throw new CrawlerError({ message: "invalid_request: invalid database reset target", code: Code.InvalidRequest });
|
|
1955
|
+
}
|
|
1956
|
+
const command = [
|
|
1957
|
+
"set -e",
|
|
1958
|
+
`db_dir=${shellQuote(`/data/data/${packageName}/databases`)}`,
|
|
1959
|
+
'if [ -L "$db_dir" ]; then echo "refusing symlink database directory" >&2; exit 1; fi',
|
|
1960
|
+
'if [ ! -d "$db_dir" ]; then exit 0; fi',
|
|
1961
|
+
`for db_file in "$db_dir"/${shellQuote(dbNamePrefix)}*; do`,
|
|
1962
|
+
' [ -e "$db_file" ] || [ -L "$db_file" ] || continue',
|
|
1963
|
+
' if [ -L "$db_file" ] || [ ! -f "$db_file" ]; then echo "refusing unexpected database entry: $db_file" >&2; exit 1; fi',
|
|
1964
|
+
"done",
|
|
1965
|
+
// 主库和 WAL/SHM/journal 一起删除,避免旧日志在重建时恢复聊天记录。
|
|
1966
|
+
`rm -f -- "$db_dir"/${shellQuote(dbNamePrefix)}*`
|
|
1967
|
+
].join("\n");
|
|
1968
|
+
await adbSuShell(ctx, command, { timeoutMs: 3e4, maxBuffer: 4096 }).catch((error) => {
|
|
1969
|
+
throw CrawlerError.from(error, { code: Code.AutomationFailed, context: { packageName, dbNamePrefix } });
|
|
1970
|
+
});
|
|
1971
|
+
Logger.info("DeviceSQLite.reset", { packageName, dbNamePrefix });
|
|
1972
|
+
}
|
|
1941
1973
|
async function query(ctx, options = {}) {
|
|
1942
1974
|
if (!options.sql) {
|
|
1943
1975
|
throw new CrawlerError({
|