Give serial to the device during cert exchange so it can provide it whenever it connects
Summary: Android devices don't always know their own serial. But we do a certificate exchange using adb from the desktop, so we can provide it in the response. After this the client will provide it every time it connects, so we can do things like filter plugins by device id. For apps that have already done cert exchange, they'll continue to use 'unknown' as their id until they do it again with an up to date version of sonar. We can think about forcefully stopping that, but I haven't done it. Reviewed By: danielbuechele Differential Revision: D9481460 fbshipit-source-id: f8932699711ebbec4260fabe32f87e6cdff920f2
This commit is contained in:
committed by
Facebook Github Bot
parent
94e22508ae
commit
edff177c3f
@@ -80,7 +80,7 @@ export default class CertificateProvider {
|
||||
csr: string,
|
||||
os: string,
|
||||
appDirectory: string,
|
||||
): Promise<void> {
|
||||
): Promise<{|deviceId: string|}> {
|
||||
this.ensureOpenSSLIsAvailable();
|
||||
return this.certificateSetup
|
||||
.then(_ => this.getCACertificate())
|
||||
@@ -102,7 +102,36 @@ export default class CertificateProvider {
|
||||
csr,
|
||||
os,
|
||||
),
|
||||
);
|
||||
)
|
||||
.then(_ => this.extractAppNameFromCSR(csr))
|
||||
.then(appName => this.getTargetDeviceId(os, appName, appDirectory, csr))
|
||||
.then(deviceId => {
|
||||
return {
|
||||
deviceId,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
getTargetDeviceId(
|
||||
os: string,
|
||||
appName: string,
|
||||
appDirectory: string,
|
||||
csr: string,
|
||||
): Promise<string> {
|
||||
if (os === 'Android') {
|
||||
return this.getTargetAndroidDeviceId(appName, appDirectory, csr);
|
||||
} else if (os === 'iOS') {
|
||||
const matches = /\/Devices\/([^/]+)\//.exec(appDirectory);
|
||||
if (matches === null || matches.length < 2) {
|
||||
return Promise.reject(
|
||||
new Error(
|
||||
`iOS simulator directory doesn't match expected format: ${appDirectory}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
return Promise.resolve(matches[1]);
|
||||
}
|
||||
return Promise.resolve('unknown');
|
||||
}
|
||||
|
||||
ensureOpenSSLIsAvailable(): void {
|
||||
@@ -150,7 +179,7 @@ export default class CertificateProvider {
|
||||
if (os === 'Android') {
|
||||
const appNamePromise = this.extractAppNameFromCSR(csr);
|
||||
const deviceIdPromise = appNamePromise.then(app =>
|
||||
this.getTargetDeviceId(app, destination, csr),
|
||||
this.getTargetAndroidDeviceId(app, destination, csr),
|
||||
);
|
||||
return Promise.all([deviceIdPromise, appNamePromise]).then(
|
||||
([deviceId, appName]) =>
|
||||
@@ -179,7 +208,7 @@ export default class CertificateProvider {
|
||||
return Promise.reject(new RecurringError(`Unsupported device os: ${os}`));
|
||||
}
|
||||
|
||||
getTargetDeviceId(
|
||||
getTargetAndroidDeviceId(
|
||||
appName: string,
|
||||
deviceCsrFilePath: string,
|
||||
csr: string,
|
||||
|
||||
Reference in New Issue
Block a user