add adbkit configurations settings
Summary: Adbkit configurations settings may be neccesary when we want to run flipper-server in an IPv6 stack machine as localhost would bind to [::1] rather than 127.0.0.1 which is where the adb server usually runs Reviewed By: mweststrate Differential Revision: D34964851 fbshipit-source-id: 9cf70f9bdc0c40e92382b1537013439f85983f65
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7f68a4d673
commit
83133618d6
@@ -45,6 +45,19 @@ export type Settings = {
|
|||||||
enablePluginMarketplace: boolean;
|
enablePluginMarketplace: boolean;
|
||||||
marketplaceURL: string;
|
marketplaceURL: string;
|
||||||
enablePluginMarketplaceAutoUpdate: boolean;
|
enablePluginMarketplaceAutoUpdate: boolean;
|
||||||
|
/**
|
||||||
|
* Adbkit settings are needed because localhost can resolve to
|
||||||
|
* 127.0.0.1 or [::1] depending on the machine (IPV4 or IPV6)
|
||||||
|
* this unknown behaviour of which address will be used by the
|
||||||
|
* adbkit may cause it not to connect to the correct address where the
|
||||||
|
* adb server is running. Notice that using the env variable ADB_SERVER_SOCKET
|
||||||
|
* set to tcp:127.0.0.1:5037 would make the adb start-server fail and so
|
||||||
|
* cannot be used as a solution.
|
||||||
|
*/
|
||||||
|
adbKitSettings?: {
|
||||||
|
host?: string;
|
||||||
|
port?: number;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum ReleaseChannel {
|
export enum ReleaseChannel {
|
||||||
|
|||||||
@@ -45,3 +45,43 @@ test('have defaults', () => {
|
|||||||
expect(port).toBe(5037);
|
expect(port).toBe(5037);
|
||||||
expect(host).toBe('localhost');
|
expect(host).toBe('localhost');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('prefer settings parameters over ANDROID_ADB_SERVER_PORT', () => {
|
||||||
|
process.env.ANDROID_ADB_SERVER_PORT = '1337';
|
||||||
|
process.env.ADB_SERVER_SOCKET = undefined;
|
||||||
|
const {port, host} = adbConfig({host: '::1', port: 1338});
|
||||||
|
expect(port).toBe(1338);
|
||||||
|
expect(host).toBe('::1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prefer settings parameters over ADB_SERVER_SOCKET', () => {
|
||||||
|
process.env.ANDROID_ADB_SERVER_PORT = undefined;
|
||||||
|
process.env.ADB_SERVER_SOCKET = 'tcp:127.0.0.1:5037';
|
||||||
|
const {port, host} = adbConfig({host: '::1', port: 1338});
|
||||||
|
expect(port).toBe(1338);
|
||||||
|
expect(host).toBe('::1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prefer host settings parameters over ADB_SERVER_SOCKET', () => {
|
||||||
|
process.env.ANDROID_ADB_SERVER_PORT = undefined;
|
||||||
|
process.env.ADB_SERVER_SOCKET = 'tcp:127.0.0.1:5037';
|
||||||
|
const {port, host} = adbConfig({host: '::1'});
|
||||||
|
expect(port).toBe(5037);
|
||||||
|
expect(host).toBe('::1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prefer port settings parameters over ADB_SERVER_SOCKET', () => {
|
||||||
|
process.env.ANDROID_ADB_SERVER_PORT = undefined;
|
||||||
|
process.env.ADB_SERVER_SOCKET = 'tcp:127.0.0.1:5037';
|
||||||
|
const {port, host} = adbConfig({port: 1338});
|
||||||
|
expect(port).toBe(1338);
|
||||||
|
expect(host).toBe('127.0.0.1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prefer port settings parameters over ANDROID_ADB_SERVER_PORT', () => {
|
||||||
|
process.env.ANDROID_ADB_SERVER_PORT = '1337';
|
||||||
|
process.env.ADB_SERVER_SOCKET = undefined;
|
||||||
|
const {port, host} = adbConfig({port: 1338});
|
||||||
|
expect(port).toBe(1338);
|
||||||
|
expect(host).toBe('localhost');
|
||||||
|
});
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ import path from 'path';
|
|||||||
|
|
||||||
type Config = {
|
type Config = {
|
||||||
androidHome: string;
|
androidHome: string;
|
||||||
|
adbKitSettings?: {
|
||||||
|
host?: string;
|
||||||
|
port?: number;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function initializeAdbClient(
|
export async function initializeAdbClient(
|
||||||
@@ -38,7 +42,7 @@ export async function initializeAdbClient(
|
|||||||
async function createClient(config: Config): Promise<Client> {
|
async function createClient(config: Config): Promise<Client> {
|
||||||
return reportPlatformFailures<Client>(
|
return reportPlatformFailures<Client>(
|
||||||
startAdbServer(config.androidHome).then(() =>
|
startAdbServer(config.androidHome).then(() =>
|
||||||
adbkit.createClient(adbConfig()),
|
adbkit.createClient(adbConfig(config.adbKitSettings)),
|
||||||
),
|
),
|
||||||
'createADBClient.shell',
|
'createADBClient.shell',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
import {parseEnvironmentVariableAsNumber} from '../../utils/environmentVariables';
|
import {parseEnvironmentVariableAsNumber} from '../../utils/environmentVariables';
|
||||||
|
|
||||||
export default () => {
|
export default (settings?: {host?: string; port?: number}) => {
|
||||||
let port = parseEnvironmentVariableAsNumber(
|
let port = parseEnvironmentVariableAsNumber(
|
||||||
'ANDROID_ADB_SERVER_PORT',
|
'ANDROID_ADB_SERVER_PORT',
|
||||||
5037,
|
5037,
|
||||||
@@ -26,6 +26,9 @@ export default () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host = settings?.host ?? host;
|
||||||
|
port = settings?.port ?? port;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
port,
|
port,
|
||||||
host,
|
host,
|
||||||
|
|||||||
Reference in New Issue
Block a user