Skip to content

Commit

Permalink
feat(android): gracefully handle when device is offline
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd committed Sep 26, 2020
1 parent 9da9f59 commit aa6688d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/android/utils/adb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as through2 from 'through2';

import {
ADBException,
ERR_DEVICE_OFFLINE,
ERR_INCOMPATIBLE_UPDATE,
ERR_MIN_SDK_VERSION,
ERR_NOT_ENOUGH_SPACE,
Expand Down Expand Up @@ -252,6 +253,13 @@ export async function installApk(
ERR_NOT_ENOUGH_SPACE,
),
);
} else if (event === ADBEvent.DeviceOffline) {
reject(
new ADBException(
`Encountered adb error: ${ADBEvent[event]}.`,
ERR_DEVICE_OFFLINE,
),
);
}

cb();
Expand Down Expand Up @@ -290,6 +298,7 @@ export enum ADBEvent {
NewerSdkRequiredOnDeviceFailure, // device does not meet minSdkVersion requirement
NoCertificates, // no certificates in APK, likely due to improper signing config
NotEnoughSpace, // device is out of hard drive space
DeviceOffline, // device is off or needs to be woken up
}

export function parseAdbInstallOutput(line: string): ADBEvent | undefined {
Expand All @@ -306,6 +315,8 @@ export function parseAdbInstallOutput(line: string): ADBEvent | undefined {
event = ADBEvent.NoCertificates;
} else if (line.includes('not enough space')) {
event = ADBEvent.NotEnoughSpace;
} else if (line.includes('device offline')) {
event = ADBEvent.DeviceOffline;
}

if (typeof event !== 'undefined') {
Expand Down
2 changes: 2 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const ERR_VERSION_DOWNGRADE = 'ERR_VERSION_DOWNGRADE';
export const ERR_MIN_SDK_VERSION = 'ERR_MIN_SDK_VERSION';
export const ERR_NO_CERTIFICATES = 'ERR_NO_CERTIFICATES';
export const ERR_NOT_ENOUGH_SPACE = 'ERR_NOT_ENOUGH_SPACE';
export const ERR_DEVICE_OFFLINE = 'ERR_DEVICE_OFFLINE';
export const ERR_INVALID_SDK_PACKAGE = 'ERR_INVALID_SDK_PACKAGE';
export const ERR_INVALID_SERIAL = 'ERR_INVALID_SERIAL';
export const ERR_INVALID_SKIN = 'ERR_INVALID_SKIN';
Expand Down Expand Up @@ -79,6 +80,7 @@ export type ADBExceptionCode =
| typeof ERR_MIN_SDK_VERSION
| typeof ERR_NO_CERTIFICATES
| typeof ERR_NOT_ENOUGH_SPACE
| typeof ERR_DEVICE_OFFLINE
| typeof ERR_NON_ZERO_EXIT;

export class ADBException extends AndroidException<ADBExceptionCode> {}
Expand Down

0 comments on commit aa6688d

Please sign in to comment.