Defer initialization of Android and iOS device managers
Summary: Remove hidden async initialization of adb and idb. Make it explicit. Remove nullable fields in Android and iOS device managers. Reviewed By: lawrencelomax Differential Revision: D33915177 fbshipit-source-id: 882f79310410e0dfde6169abf343ab808644e4a2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fd13399cb9
commit
51ef1810b2
@@ -10,28 +10,20 @@
|
||||
import AndroidDevice from './AndroidDevice';
|
||||
import KaiOSDevice from './KaiOSDevice';
|
||||
import child_process from 'child_process';
|
||||
import {setAdbClient} from './adbClient';
|
||||
import {Client as ADBClient, Device} from 'adbkit';
|
||||
import {join} from 'path';
|
||||
import {FlipperServerImpl} from '../../FlipperServerImpl';
|
||||
import {notNull} from '../../utils/typeUtils';
|
||||
import {
|
||||
getServerPortsConfig,
|
||||
getFlipperServerConfig,
|
||||
} from '../../FlipperServerConfig';
|
||||
import {getServerPortsConfig} from '../../FlipperServerConfig';
|
||||
import AndroidCertificateProvider from './AndroidCertificateProvider';
|
||||
import {assertNotNull} from '../../comms/Utilities';
|
||||
|
||||
export class AndroidDeviceManager {
|
||||
private adbClient?: ADBClient;
|
||||
constructor(public flipperServer: FlipperServerImpl) {}
|
||||
|
||||
public get certificateProvider() {
|
||||
assertNotNull(
|
||||
this.adbClient,
|
||||
'AndroidDeviceManager.certificateProvider -> missing adbClient',
|
||||
);
|
||||
return new AndroidCertificateProvider(this.adbClient);
|
||||
readonly certificateProvider: AndroidCertificateProvider;
|
||||
constructor(
|
||||
private readonly flipperServer: FlipperServerImpl,
|
||||
private readonly adbClient: ADBClient,
|
||||
) {
|
||||
this.certificateProvider = new AndroidCertificateProvider(this.adbClient);
|
||||
}
|
||||
|
||||
private createDevice(
|
||||
@@ -181,16 +173,7 @@ export class AndroidDeviceManager {
|
||||
|
||||
async watchAndroidDevices() {
|
||||
try {
|
||||
const client = await setAdbClient(getFlipperServerConfig().settings);
|
||||
if (!client) {
|
||||
throw new Error(
|
||||
'AndroidDeviceManager.watchAndroidDevices -> adb not initialized',
|
||||
);
|
||||
}
|
||||
|
||||
this.adbClient = client;
|
||||
|
||||
client
|
||||
this.adbClient
|
||||
.trackDevices()
|
||||
.then((tracker) => {
|
||||
tracker.on('error', (err) => {
|
||||
@@ -212,7 +195,7 @@ export class AndroidDeviceManager {
|
||||
|
||||
tracker.on('add', async (device) => {
|
||||
if (device.type !== 'offline') {
|
||||
this.registerDevice(client, device);
|
||||
this.registerDevice(this.adbClient, device);
|
||||
} else {
|
||||
console.warn(
|
||||
`[conn] Found device ${device.id}, but it has status offline. If this concerns an emulator and the problem persists, try these solutins: https://stackoverflow.com/a/21330228/1983583, https://stackoverflow.com/a/56053223/1983583`,
|
||||
@@ -224,7 +207,7 @@ export class AndroidDeviceManager {
|
||||
if (device.type === 'offline') {
|
||||
this.flipperServer.unregisterDevice(device.id);
|
||||
} else {
|
||||
this.registerDevice(client, device);
|
||||
this.registerDevice(this.adbClient, device);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -88,8 +88,10 @@ test('test checkXcodeVersionMismatch with an incorrect Simulator.app', () => {
|
||||
});
|
||||
|
||||
test('test queryDevices when simctl used', async () => {
|
||||
const ios = new IOSDeviceManager(fakeFlipperServer);
|
||||
(ios as any).idbConfig = getFlipperServerConfig().settings;
|
||||
const ios = new IOSDeviceManager(
|
||||
fakeFlipperServer,
|
||||
getFlipperServerConfig().settings,
|
||||
);
|
||||
ios.simctlBridge = fakeSimctlBridge;
|
||||
|
||||
await ios.queryDevices(fakeSimctlBridge);
|
||||
@@ -109,8 +111,10 @@ test('test queryDevices when simctl used', async () => {
|
||||
});
|
||||
|
||||
test('test queryDevices when idb used', async () => {
|
||||
const ios = new IOSDeviceManager(fakeFlipperServer);
|
||||
(ios as any).idbConfig = getFlipperServerConfig().settings;
|
||||
const ios = new IOSDeviceManager(
|
||||
fakeFlipperServer,
|
||||
getFlipperServerConfig().settings,
|
||||
);
|
||||
ios.simctlBridge = fakeSimctlBridge;
|
||||
|
||||
await ios.queryDevices(fakeIDBBridge);
|
||||
|
||||
@@ -22,14 +22,11 @@ import {
|
||||
} from './IOSBridge';
|
||||
import {FlipperServerImpl} from '../../FlipperServerImpl';
|
||||
import {getFlipperServerConfig} from '../../FlipperServerConfig';
|
||||
import {IdbConfig, setIdbConfig} from './idbConfig';
|
||||
import {assertNotNull} from '../../comms/Utilities';
|
||||
import {IdbConfig} from './idbConfig';
|
||||
import iOSCertificateProvider from './iOSCertificateProvider';
|
||||
|
||||
export class IOSDeviceManager {
|
||||
private portForwarders: Array<ChildProcess> = [];
|
||||
private idbConfig?: IdbConfig;
|
||||
|
||||
private portforwardingClient = path.join(
|
||||
getFlipperServerConfig().paths.staticPath,
|
||||
'PortForwardingMacApp.app',
|
||||
@@ -39,14 +36,13 @@ export class IOSDeviceManager {
|
||||
);
|
||||
simctlBridge: SimctlBridge = new SimctlBridge();
|
||||
|
||||
constructor(private flipperServer: FlipperServerImpl) {}
|
||||
readonly certificateProvider: iOSCertificateProvider;
|
||||
|
||||
public get certificateProvider() {
|
||||
assertNotNull(
|
||||
this.idbConfig,
|
||||
'IOSDeviceManager.certificateProvider -> missing idbConfig',
|
||||
);
|
||||
return new iOSCertificateProvider(this.idbConfig);
|
||||
constructor(
|
||||
private readonly flipperServer: FlipperServerImpl,
|
||||
private readonly idbConfig: IdbConfig,
|
||||
) {
|
||||
this.certificateProvider = new iOSCertificateProvider(this.idbConfig);
|
||||
}
|
||||
|
||||
private forwardPort(port: number, multiplexChannelPort: number) {
|
||||
@@ -137,11 +133,9 @@ export class IOSDeviceManager {
|
||||
}
|
||||
|
||||
public async watchIOSDevices() {
|
||||
const settings = getFlipperServerConfig().settings;
|
||||
this.idbConfig = setIdbConfig(settings);
|
||||
try {
|
||||
const isDetected = await iosUtil.isXcodeDetected();
|
||||
if (settings.enablePhysicalIOS) {
|
||||
if (this.idbConfig.enablePhysicalIOS) {
|
||||
this.startDevicePortForwarders();
|
||||
}
|
||||
try {
|
||||
@@ -149,9 +143,9 @@ export class IOSDeviceManager {
|
||||
await this.checkXcodeVersionMismatch();
|
||||
// Awaiting the promise here to trigger immediate error handling.
|
||||
const bridge = await makeIOSBridge(
|
||||
settings.idbPath,
|
||||
this.idbConfig.idbPath,
|
||||
isDetected,
|
||||
settings.enablePhysicalIOS,
|
||||
this.idbConfig.enablePhysicalIOS,
|
||||
);
|
||||
this.queryDevicesForever(bridge);
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user