private getTargetAndroidDeviceId()

in src/extension/networkInspector/certificateProvider.ts [353:399]


    private getTargetAndroidDeviceId(
        appName: string,
        deviceCsrFilePath: string,
        csr: string,
    ): Promise<string> {
        return this.adbHelper.getOnlineTargets().then(devices => {
            if (devices.length === 0) {
                throw new Error("No Android devices found");
            }
            const deviceMatchList = devices.map(device =>
                this.androidDeviceHasMatchingCSR(deviceCsrFilePath, device.id, appName, csr)
                    .then(result => {
                        return { id: device.id, ...result, error: null };
                    })
                    .catch(e => {
                        this.logger.error(
                            `Unable to check for matching CSR in ${device.id}:${appName}`,
                        );
                        return { id: device.id, isMatch: false, foundCsr: null, error: e };
                    }),
            );
            return Promise.all(deviceMatchList).then(devices => {
                const matchingIds = devices.filter(m => m.isMatch).map(m => m.id);
                if (matchingIds.length == 0) {
                    const erroredDevice = devices.find(d => d.error);
                    if (erroredDevice) {
                        throw erroredDevice.error;
                    }
                    const foundCsrs = devices
                        .filter(d => d.foundCsr !== null)
                        .map(d => (d.foundCsr ? encodeURI(d.foundCsr) : "null"));
                    this.logger.error(`Looking for CSR (url encoded):

            ${encodeURI(this.santitizeString(csr))}

            Found these:

            ${foundCsrs.join("\n\n")}`);
                    throw new Error(`No matching device found for app: ${appName}`);
                }
                if (matchingIds.length > 1) {
                    this.logger.error(`More than one matching device found for CSR:\n${csr}`);
                }
                return matchingIds[0];
            });
        });
    }