From d6cc033f0dc4878de63b7c63f87b0d1d5580d109 Mon Sep 17 00:00:00 2001 From: Byoungwook Park Date: Wed, 8 Nov 2023 20:30:41 +0900 Subject: [PATCH] wip: android channel geoLocation --- .../src/internal/channel/android-channel.ts | 4 ++ .../src/internal/externals/cli/adb/adb.ts | 62 ++++++++++--------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/packages/typescript-private/device-server/src/internal/channel/android-channel.ts b/packages/typescript-private/device-server/src/internal/channel/android-channel.ts index 8b33c7297..83cf3048f 100644 --- a/packages/typescript-private/device-server/src/internal/channel/android-channel.ts +++ b/packages/typescript-private/device-server/src/internal/channel/android-channel.ts @@ -438,8 +438,12 @@ export class AndroidChannel implements DeviceChannel { } async setGeoLocation(geoLocation: GeoLocation): Promise { + await this.adb.disableLocation('gps'); + await this.adb.disableLocation('network'); + await this.adb.enableLocation('gps'); const newAppiumAdb = this.appiumAdb.clone({ adbExecTimeout: 1000 * 60 * 3 }); await newAppiumAdb.setGeoLocation(geoLocation); + await this.adb.disableLocation('gps'); } async getAlert(): Promise { diff --git a/packages/typescript-private/device-server/src/internal/externals/cli/adb/adb.ts b/packages/typescript-private/device-server/src/internal/externals/cli/adb/adb.ts index c0bc0c3ae..745176d4b 100644 --- a/packages/typescript-private/device-server/src/internal/externals/cli/adb/adb.ts +++ b/packages/typescript-private/device-server/src/internal/externals/cli/adb/adb.ts @@ -269,9 +269,7 @@ export class AdbSerial { }); } - /** - * network - */ + //#region network async forward(hostPort: number, devicePort: number): Promise { const { serial, printable } = this; @@ -416,10 +414,9 @@ export class AdbSerial { }); }); } + //#endregion - /** - * app control - */ + //#region app control @Retry({ retryCount: 3, retryInterval: 1000 }) async uninstallApp(appName: string, keep = false): Promise { @@ -730,11 +727,9 @@ export class AdbSerial { return rv; }); } + //#endregion - /** - * device info - */ - + //#region device info async getForegroundPackage(): Promise { const { serial, printable } = this; return await usingAsnyc(new AdbSerialScope('getForegroundPackage', { serial }), async () => { @@ -892,11 +887,9 @@ export class AdbSerial { }); return result; } + //#endregion - /** - * display - */ - + //#region display async isScreenOn(): Promise { const { serial, printable } = this; return await usingAsnyc(new AdbSerialScope('isScreenOn', { serial }), async () => { @@ -1003,10 +996,9 @@ export class AdbSerial { await shellIgnoreError(serial, `settings put system screen_brightness ${value}`, { printable }); }); } + //#endregion - /** - * security - */ + //#region security async unlock(): Promise { const { serial, printable } = this; return await usingAsnyc(new AdbSerialScope('unlock', { serial }), async () => { @@ -1058,11 +1050,9 @@ export class AdbSerial { } }); } + //#endregion - /** - * FileSystem - */ - + //#region file system @Retry({ retryCount: 3, retryInterval: 300 }) async readDir(path: string): Promise { const { serial, printable } = this; @@ -1092,12 +1082,26 @@ export class AdbSerial { return rv; }); } + //#endregion - /** - * emulator - * - */ + //#region location + + async enableLocation(type: 'gps' | 'network'): Promise { + const { serial } = this; + return await usingAsnyc(new AdbSerialScope('enableLocation', { serial }), async () => { + await shell(serial, `settings put secure location_providers_allowed +${type}`); + }); + } + async disableLocation(type: 'gps' | 'network'): Promise { + const { serial } = this; + return await usingAsnyc(new AdbSerialScope('disableLocation', { serial }), async () => { + await shell(serial, `settings put secure location_providers_allowed -${type}`); + }); + } + //#endregion + + //#region emulator async getEmulatorName(): Promise { const { serial, printable } = this; return await usingAsnyc(new AdbSerialScope('getEmulatorName', { serial }), async () => { @@ -1110,12 +1114,9 @@ export class AdbSerial { return rv; }); } + //#endregion - /** - * reset - * - */ - + //#region reset ResetDangerousPackagePrefixes = ['com.sec.', 'com.samsung.', 'com.skt.', 'com.knox.', 'com.android.', 'com.google.']; NotDangerousPackagePrefixes = ['com.android.chrome', 'com.google.android.youtube', 'com.google.android.apps.maps', 'com.google.android.webview']; @@ -1218,6 +1219,7 @@ export class AdbSerial { await shell(serial, `ime reset`); }); } + //#endregion async getSystemBarVisibility(): Promise { const { serial, printable } = this;