private async deployOrStageFileForMobileApp()

in src/extension/networkInspector/certificateProvider.ts [262:336]


    private async deployOrStageFileForMobileApp(
        destination: string,
        filename: string,
        contents: string,
        csr: string,
        os: ClientOS,
        medium: CertificateExchangeMedium,
        certFolder: string,
    ): Promise<void> {
        const appNamePromise = this.extractAppNameFromCSR(csr);

        if (medium === "WWW") {
            return fsUtils.writeFileToFolder(certFolder, filename, contents).catch(e => {
                throw new Error(`Failed to write ${filename} to temporary folder. Error: ${e}`);
            });
        }

        if (os === ClientOS.Android) {
            const deviceIdPromise = appNamePromise.then(app =>
                this.getTargetAndroidDeviceId(app, destination, csr),
            );
            return Promise.all([deviceIdPromise, appNamePromise]).then(([deviceId, appName]) => {
                if (process.platform === "win32") {
                    return fsUtils
                        .writeFileToFolder(certFolder, filename, contents)
                        .then(() =>
                            androidUtil.pushFile(
                                this.adbHelper,
                                deviceId,
                                appName,
                                destination + filename,
                                path.join(certFolder, filename),
                                this.logger,
                            ),
                        );
                }
                return androidUtil.push(
                    this.adbHelper,
                    deviceId,
                    appName,
                    destination + filename,
                    contents,
                    this.logger,
                );
            });
        }
        if (os === ClientOS.iOS || os === ClientOS.Windows || os === ClientOS.MacOS) {
            return fs.promises.writeFile(destination + filename, contents).catch(err => {
                if (os === ClientOS.iOS) {
                    // Writing directly to FS failed. It's probably a physical device.
                    const relativePathInsideApp = this.getRelativePathInAppContainer(destination);
                    return appNamePromise
                        .then(appName => {
                            return this.getTargetiOSDeviceId(appName, destination, csr);
                        })
                        .then(udid => {
                            return appNamePromise.then(appName =>
                                this.pushFileToiOSDevice(
                                    udid,
                                    appName,
                                    relativePathInsideApp,
                                    filename,
                                    contents,
                                ),
                            );
                        });
                }
                throw new Error(
                    `Invalid appDirectory recieved from ${os} device: ${destination}: ` +
                        err.toString(),
                );
            });
        }
        return Promise.reject(new Error(`Unsupported device os: ${os}`));
    }