@aiscene/android 1.6.7 → 1.6.8

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.
@@ -9,14 +9,11 @@ import { AndroidDeviceOpt } from '@midscene/core/device';
9
9
  import { BaseMCPServer } from '@midscene/shared/mcp';
10
10
  import { BaseMidsceneTools } from '@midscene/shared/mcp';
11
11
  import { DeviceAction } from '@midscene/core';
12
- import { ElementCacheFeature } from '@midscene/core';
13
12
  import type { ElementInfo } from '@midscene/shared/extractor';
14
- import { IModelConfig } from '@midscene/shared/env';
15
13
  import { InterfaceType } from '@midscene/core';
16
14
  import { LaunchMCPServerOptions } from '@midscene/shared/mcp';
17
15
  import { LaunchMCPServerResult } from '@midscene/shared/mcp';
18
16
  import { Point } from '@midscene/core';
19
- import { Rect } from '@midscene/core';
20
17
  import { Size } from '@midscene/core';
21
18
  import { Tool } from '@midscene/shared/mcp';
22
19
  import { ToolDefinition } from '@midscene/shared/mcp';
@@ -67,7 +64,6 @@ declare class AndroidDevice implements AbstractInterface {
67
64
  private yadbPushed;
68
65
  private devicePixelRatio;
69
66
  private devicePixelRatioInitialized;
70
- private scalingRatio;
71
67
  private adb;
72
68
  private connectingAdb;
73
69
  private destroyed;
@@ -78,6 +74,9 @@ declare class AndroidDevice implements AbstractInterface {
78
74
  private cachedPhysicalDisplayId;
79
75
  private scrcpyAdapter;
80
76
  private appNameMapping;
77
+ private scalingRatio;
78
+ private takeScreenshotFailCount;
79
+ private static readonly TAKE_SCREENSHOT_FAIL_THRESHOLD;
81
80
  interfaceType: InterfaceType;
82
81
  uri: string | undefined;
83
82
  options?: AndroidDeviceOpt;
@@ -108,16 +107,6 @@ declare class AndroidDevice implements AbstractInterface {
108
107
  private resolvePackageName;
109
108
  launch(uri: string): Promise<AndroidDevice>;
110
109
  execYadb(keyboardContent: string): Promise<void>;
111
- /**
112
- * 通过剪贴板输入文本(备用方案,当YADB不可用时)
113
- * 支持中文等非ASCII字符
114
- */
115
- private inputViaClipboard;
116
- /**
117
- * 逐字符输入文本(最后备用方案)
118
- * 通过模拟按键输入,支持中文(如果有对应输入法)
119
- */
120
- private inputCharByChar;
121
110
  getElementsInfo(): Promise<ElementInfo[]>;
122
111
  getElementsNodeTree(): Promise<any>;
123
112
  getScreenSize(): Promise<{
@@ -129,22 +118,38 @@ declare class AndroidDevice implements AbstractInterface {
129
118
  private initializeDevicePixelRatio;
130
119
  getDisplayDensity(): Promise<number>;
131
120
  getDisplayOrientation(): Promise<number>;
132
- size(): Promise<Size>;
133
121
  /**
134
- * Generate cache feature for an element at given center point
135
- * Cache is based on test case ID + device ID, so screen size is guaranteed to be consistent
136
- * for same test case on same device. We store exact coordinates for maximum accuracy.
122
+ * Get physical screen dimensions adjusted for current orientation.
123
+ * Swaps width/height when the device is in landscape and the reported
124
+ * dimensions do not already reflect the current orientation.
137
125
  */
138
- cacheFeatureForPoint(center: [number, number], options?: {
139
- targetDescription?: string;
140
- modelConfig?: IModelConfig;
141
- }): Promise<ElementCacheFeature>;
126
+ private getOrientedPhysicalSize;
127
+ size(): Promise<Size>;
128
+ cacheFeatureForPoint(center: [number, number]): Promise<{
129
+ centerX: number;
130
+ centerY: number;
131
+ screenSize: {
132
+ width: number;
133
+ height: number;
134
+ };
135
+ }>;
136
+ rectMatchesCacheFeature(feature: {
137
+ centerX: number;
138
+ centerY: number;
139
+ screenSize: {
140
+ width: number;
141
+ height: number;
142
+ };
143
+ }): Promise<{
144
+ left: number;
145
+ top: number;
146
+ width: number;
147
+ height: number;
148
+ }>;
142
149
  /**
143
- * Find element rect from cache feature
144
- * Since cache is keyed by test case ID + device ID, screen size will be identical
145
- * We return the exact cached coordinates for maximum accuracy.
150
+ * Convert logical coordinates (from AI) back to physical coordinates (for ADB).
151
+ * The ratio is derived from size(), so overriding size() alone is sufficient.
146
152
  */
147
- rectMatchesCacheFeature(feature: ElementCacheFeature): Promise<Rect>;
148
153
  private adjustCoordinates;
149
154
  /**
150
155
  * Calculate the end point for scroll operations based on start point, scroll delta, and screen boundaries.
@@ -173,11 +178,15 @@ declare class AndroidDevice implements AbstractInterface {
173
178
  scrollRight(distance?: number, startPoint?: Point): Promise<void>;
174
179
  ensureYadb(): Promise<void>;
175
180
  /**
176
- * Check if text contains characters that may cause issues with ADB inputText
177
- * This includes:
178
- * - Non-ASCII characters (Unicode characters like ö, é, ñ, Chinese, Japanese, etc.)
179
- * - Format specifiers that may be interpreted by shell (%, $)
180
- * - Special shell characters that need escaping
181
+ * Check if text contains characters that may cause issues with ADB inputText.
182
+ * appium-adb's inputText has known bugs with certain characters:
183
+ * - Backslash causes broken shell quoting
184
+ * - Backtick is not escaped at all
185
+ * - Text containing both " and ' throws an error
186
+ * - Dollar sign can cause variable expansion issues
187
+ *
188
+ * For these characters, we route through yadb which handles them correctly
189
+ * via escapeForShell + double-quoted shell context.
181
190
  */
182
191
  private shouldUseYadbForText;
183
192
  keyboardType(text: string, options?: AndroidDeviceInputOpt): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiscene/android",
3
- "version": "1.6.7",
3
+ "version": "1.6.8",
4
4
  "description": "Android automation library for Midscene",
5
5
  "keywords": [
6
6
  "Android UI automation",
@@ -15,7 +15,11 @@
15
15
  "bin": {
16
16
  "midscene-android": "./bin/midscene-android"
17
17
  },
18
- "files": ["bin", "dist", "README.md"],
18
+ "files": [
19
+ "bin",
20
+ "dist",
21
+ "README.md"
22
+ ],
19
23
  "exports": {
20
24
  ".": {
21
25
  "types": "./dist/types/index.d.ts",
@@ -29,34 +33,21 @@
29
33
  },
30
34
  "./package.json": "./package.json"
31
35
  },
32
- "scripts": {
33
- "dev": "npm run build:watch",
34
- "prebuild": "node scripts/download-scrcpy-server.mjs && node scripts/download-yadb.mjs",
35
- "build": "rslib build",
36
- "build:watch": "rslib build --watch --no-clean",
37
- "prepack": "node scripts/download-scrcpy-server.mjs && node scripts/download-yadb.mjs",
38
- "playground": "DEBUG=midscene:* tsx demo/playground.ts",
39
- "test": "vitest --run",
40
- "test:u": "vitest --run -u",
41
- "test:ai": "AI_TEST_TYPE=android npm run test",
42
- "test:ai:cache": "MIDSCENE_CACHE=true AI_TEST_TYPE=android npm run test"
43
- },
44
36
  "dependencies": {
45
- "@midscene/core": "workspace:*",
46
- "@midscene/shared": "workspace:*",
47
37
  "@yume-chan/adb": "2.5.1",
48
38
  "@yume-chan/adb-scrcpy": "2.3.2",
49
39
  "@yume-chan/adb-server-node-tcp": "2.5.2",
50
40
  "@yume-chan/scrcpy": "2.3.0",
51
41
  "@yume-chan/stream-extra": "2.1.0",
52
42
  "appium-adb": "12.12.1",
53
- "sharp": "^0.34.3"
43
+ "sharp": "^0.34.3",
44
+ "@midscene/core": "1.6.0",
45
+ "@midscene/shared": "1.6.0"
54
46
  },
55
47
  "optionalDependencies": {
56
48
  "@ffmpeg-installer/ffmpeg": "^1.1.0"
57
49
  },
58
50
  "devDependencies": {
59
- "@midscene/playground": "workspace:*",
60
51
  "@rslib/core": "^0.18.3",
61
52
  "@types/node": "^18.0.0",
62
53
  "dotenv": "^16.4.5",
@@ -64,7 +55,19 @@
64
55
  "typescript": "^5.8.3",
65
56
  "tsx": "^4.19.2",
66
57
  "vitest": "3.0.5",
67
- "zod": "3.24.3"
58
+ "zod": "3.24.3",
59
+ "@midscene/playground": "1.6.0"
68
60
  },
69
- "license": "MIT"
70
- }
61
+ "license": "MIT",
62
+ "scripts": {
63
+ "dev": "npm run build:watch",
64
+ "prebuild": "node scripts/download-scrcpy-server.mjs && node scripts/download-yadb.mjs",
65
+ "build": "rslib build",
66
+ "build:watch": "rslib build --watch --no-clean",
67
+ "playground": "DEBUG=midscene:* tsx demo/playground.ts",
68
+ "test": "vitest --run",
69
+ "test:u": "vitest --run -u",
70
+ "test:ai": "AI_TEST_TYPE=android npm run test",
71
+ "test:ai:cache": "MIDSCENE_CACHE=true AI_TEST_TYPE=android npm run test"
72
+ }
73
+ }