Skip to content

Commit

Permalink
wip: android channel geoLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
yowpark committed Nov 8, 2023
1 parent 4b977c0 commit d6cc033
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,12 @@ export class AndroidChannel implements DeviceChannel {
}

async setGeoLocation(geoLocation: GeoLocation): Promise<void> {
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<DeviceAlert | undefined> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,7 @@ export class AdbSerial {
});
}

/**
* network
*/
//#region network

async forward(hostPort: number, devicePort: number): Promise<void> {
const { serial, printable } = this;
Expand Down Expand Up @@ -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<void> {
Expand Down Expand Up @@ -730,11 +727,9 @@ export class AdbSerial {
return rv;
});
}
//#endregion

/**
* device info
*/

//#region device info
async getForegroundPackage(): Promise<FocusedAppInfo[]> {
const { serial, printable } = this;
return await usingAsnyc(new AdbSerialScope('getForegroundPackage', { serial }), async () => {
Expand Down Expand Up @@ -892,11 +887,9 @@ export class AdbSerial {
});
return result;
}
//#endregion

/**
* display
*/

//#region display
async isScreenOn(): Promise<boolean> {
const { serial, printable } = this;
return await usingAsnyc(new AdbSerialScope('isScreenOn', { serial }), async () => {
Expand Down Expand Up @@ -1003,10 +996,9 @@ export class AdbSerial {
await shellIgnoreError(serial, `settings put system screen_brightness ${value}`, { printable });
});
}
//#endregion

/**
* security
*/
//#region security
async unlock(): Promise<void> {
const { serial, printable } = this;
return await usingAsnyc(new AdbSerialScope('unlock', { serial }), async () => {
Expand Down Expand Up @@ -1058,11 +1050,9 @@ export class AdbSerial {
}
});
}
//#endregion

/**
* FileSystem
*/

//#region file system
@Retry({ retryCount: 3, retryInterval: 300 })
async readDir(path: string): Promise<AndroidFileEntry[]> {
const { serial, printable } = this;
Expand Down Expand Up @@ -1092,12 +1082,26 @@ export class AdbSerial {
return rv;
});
}
//#endregion

/**
* emulator
*
*/
//#region location

async enableLocation(type: 'gps' | 'network'): Promise<void> {
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<void> {
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<string> {
const { serial, printable } = this;
return await usingAsnyc(new AdbSerialScope('getEmulatorName', { serial }), async () => {
Expand All @@ -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'];

Expand Down Expand Up @@ -1218,6 +1219,7 @@ export class AdbSerial {
await shell(serial, `ime reset`);
});
}
//#endregion

async getSystemBarVisibility(): Promise<AndroidSystemBarVisibility> {
const { serial, printable } = this;
Expand Down

0 comments on commit d6cc033

Please sign in to comment.