Skip to content

Commit 52ae725

Browse files
authored
feat(andsvc-protocol): Update Android Service communication to use new protocol (#4617)
#### Details This PR updates the AI-Android client to interact with the Android Service using [its new protocol](microsoft/accessibility-insights-for-android-service#126). To do this, all interaction with the service now occurs via ADB rather than a mix of HTTP requests and ADB. Minor changes were made to the setup workflow as port forwarding is no longer applicable, but the overall user impact is minimal. Some of the work to achieve this includes: - add adb commands to communicate with the new content provider (readContent and callContent) - create new DeviceCommunicator class that sends commands to the device after setup (implementation details like the specific focus commands and content types (config/result) live here instead of in the adb wrapper) - adapt the ServiceConfigurator into a DeviceConfigurator for commands sent to the device during setup (includes some refactoring of grantOverlayPermissions to move logic out of the adb wrapper) - replace classes that call http endpoints with calls to the DeviceCommunicator - remove port forwarding calls but leave obsolete code for now - update unit tests and snapshots - update e2e tests and snapshots ##### Motivation Maintain compatibility with the new Android Service version. ##### Context Credit to @madalynrose for the implementation #### Pull request checklist <!-- If a checklist item is not applicable to this change, write "n/a" in the checkbox --> - [n/a] Addresses an existing issue: #0000 - [x] Ran `yarn fastpass` - [x] Added/updated relevant unit test(s) (and ran `yarn test`) - [x] Verified code coverage for the changes made. Check coverage report at: `<rootDir>/test-results/unit/coverage` - [x] PR title *AND* final merge commit title both start with a semantic tag (`fix:`, `chore:`, `feat(feature-name):`, `refactor:`). See `CONTRIBUTING.md`. - [n/a] (UI changes only) Added screenshots/GIFs to description above - [n/a] (UI changes only) Verified usability with NVDA/JAWS
1 parent ce233ea commit 52ae725

File tree

83 files changed

+201838
-2286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+201838
-2286
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
"webpack-node-externals": "^3.0.0"
169169
},
170170
"dependencies": {
171-
"accessibility-insights-for-android-service-bin": "1.4.0",
171+
"accessibility-insights-for-android-service-bin": "2.0.0",
172172
"ajv": "^8.6.2",
173173
"android-device-list": "^1.2.7",
174174
"appium-adb": "^8.13.2",
@@ -183,7 +183,6 @@
183183
"lodash": "^4.17.21",
184184
"luxon": "^2.0.2",
185185
"office-ui-fabric-react": "7.98.0",
186-
"portfinder": "^1.0.28",
187186
"react": "^16.14.0",
188187
"react-copy-to-clipboard": "^5.0.4",
189188
"react-dom": "^16.14.0",

src/common/extension-telemetry-events.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,10 @@ export type NeedsReviewAnalyzerScanTelemetryData = {
194194
incompleteRuleResults: string;
195195
} & RuleAnalyzerScanTelemetryData;
196196

197-
export type PortTelemetryData = {
198-
port: number;
197+
export type AndroidScanStartedTelemetryData = {
198+
source: TelemetryEventSource;
199199
};
200-
201200
export type AndroidScanCompletedTelemetryData = {
202-
port: number;
203201
scanDuration: number;
204202
} & InstanceCount;
205203

@@ -231,7 +229,7 @@ export type AtfaInstanceCount = {
231229
};
232230

233231
export type AndroidScanFailedTelemetryData = {
234-
port: number;
232+
port?: number;
235233
scanDuration: number;
236234
};
237235

@@ -267,7 +265,7 @@ export type TelemetryData =
267265
| IssuesAnalyzerScanTelemetryData
268266
| AssessmentRequirementScanTelemetryData
269267
| RequirementStatusTelemetryData
270-
| PortTelemetryData
268+
| AndroidScanStartedTelemetryData
271269
| AndroidScanCompletedTelemetryData
272270
| AndroidScanFailedTelemetryData
273271
| DeviceFocusKeyEventTelemetryData

src/electron/flux/action-creator/scan-action-creator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export class ScanActionCreator {
99
private readonly deviceConnectionActions: DeviceConnectionActions,
1010
) {}
1111

12-
public scan(port: number): void {
12+
public scan(): void {
1313
this.deviceConnectionActions.statusUnknown.invoke();
14-
this.scanActions.scanStarted.invoke({ port });
14+
this.scanActions.scanStarted.invoke();
1515
}
1616
}

src/electron/flux/action/device-action-payloads.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3-
export interface PortPayload {
4-
port: number;
5-
}
63

74
export interface ConnectedDevicePayload {
85
connectedDevice: string;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33
import { Action } from 'common/flux/action';
4-
import { PortPayload } from 'electron/flux/action/device-action-payloads';
54

65
export class ScanActions {
7-
public readonly scanStarted = new Action<PortPayload>();
6+
public readonly scanStarted = new Action<void>();
87
public readonly scanCompleted = new Action<void>();
98
public readonly scanFailed = new Action<void>();
109
}

src/electron/flux/store/android-setup-store.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ export class AndroidSetupStore extends BaseStoreImpl<AndroidSetupStoreData> {
2626
this.stateMachine = this.createAndroidSetupStateMachine(this.stepTransition, {
2727
setSelectedDevice: this.setSelectedDevice,
2828
setAvailableDevices: this.setAvailableDevices,
29-
getScanPort: () => this.state.scanPort,
30-
setScanPort: this.setScanPort,
3129
setApplicationName: this.setApplicationName,
3230
});
3331
}
@@ -69,11 +67,6 @@ export class AndroidSetupStore extends BaseStoreImpl<AndroidSetupStoreData> {
6967
this.state.availableDevices = devices;
7068
};
7169

72-
private setScanPort = (scanPort?: number): void => {
73-
// emitChange will be called from step transition when the step changes
74-
this.state.scanPort = scanPort;
75-
};
76-
7770
private setApplicationName = (appName?: string): void => {
7871
// emitChange will be called from step transition when the step changes
7972
this.state.applicationName = appName;

src/electron/flux/types/android-setup-state-machine-types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ export type AndroidSetupStepTransitionCallback = (nextStep: AndroidSetupStepId)
1313
export type AndroidSetupStoreCallbacks = {
1414
setSelectedDevice: (device: DeviceInfo) => void;
1515
setAvailableDevices: (devices: DeviceInfo[]) => void;
16-
getScanPort: () => number | undefined;
17-
setScanPort: (scanPort?: number) => void;
1816
setApplicationName: (appName?: string) => void;
1917
};
2018

src/electron/flux/types/android-setup-store-data.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ export type AndroidSetupStoreData = {
1010
selectedDevice?: DeviceInfo;
1111
availableDevices?: DeviceInfo[];
1212

13-
scanPort?: number;
1413
applicationName?: string;
1514
};

src/electron/platform/android/adb-wrapper.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ export interface AdbWrapper {
2727
getDumpsysOutput(deviceId: string, serviceToQuery: string): Promise<string>;
2828
installService(deviceId: string, apkLocation: string): Promise<void>;
2929
uninstallService(deviceId: string, packageName: string): Promise<void>;
30-
setTcpForwarding(deviceId: string, localPort: number, devicePort: number): Promise<number>;
31-
removeTcpForwarding(deviceId: string, devicePort: number): Promise<void>;
3230
sendKeyEvent(deviceId: string, keyEventCode: KeyEventCode): Promise<void>;
33-
grantOverlayPermission: (deviceId: string, packageName: string) => Promise<void>;
31+
grantPermission(deviceId: string, packageName: string, permission: string): Promise<void>;
32+
hasPermission(deviceId: string, permissionName: string, matchString: string): Promise<boolean>;
33+
readContent: (deviceId: string, contentUri: string) => Promise<string>;
34+
callContent: (deviceId: string, contentUri: string, method: string) => Promise<void>;
3435
}
3536

3637
export interface AdbWrapperFactory {

src/electron/platform/android/android-service-apk-locator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as path from 'path';
44
import { apkVersionName } from 'accessibility-insights-for-android-service-bin';
55

6+
export const AndroidServicePackageName = 'com.microsoft.accessibilityinsightsforandroidservice';
67
export type AndroidServiceApkInfo = {
78
path: string;
89
versionName: string;

0 commit comments

Comments
 (0)