Bug 1498469 - Part 1: Wait until adb process is ready to show the 'Usb enabled' message r=jdescottes,daisuke

Differential Revision: https://phabricator.services.mozilla.com/D27296

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Belén Albeza 2019-04-23 11:44:44 +00:00
Родитель 32599911f8
Коммит ec2a8fd626
7 изменённых файлов: 40 добавлений и 8 удалений

Просмотреть файл

@ -36,6 +36,7 @@ const {
} = require("./src/modules/usb-runtimes");
loader.lazyRequireGetter(this, "adbAddon", "devtools/shared/adb/adb-addon", true);
loader.lazyRequireGetter(this, "adbProcess", "devtools/shared/adb/adb-process", true);
const Router = createFactory(require("devtools/client/shared/vendor/react-router-dom").HashRouter);
const App = createFactory(require("./src/components/App"));
@ -49,6 +50,7 @@ const AboutDebugging = {
}
this.onAdbAddonUpdated = this.onAdbAddonUpdated.bind(this);
this.onAdbProcessReady = this.onAdbProcessReady.bind(this);
this.onNetworkLocationsUpdated = this.onNetworkLocationsUpdated.bind(this);
this.onUSBRuntimesUpdated = this.onUSBRuntimesUpdated.bind(this);
@ -89,6 +91,9 @@ const AboutDebugging = {
adbAddon.on("update", this.onAdbAddonUpdated);
this.onAdbAddonUpdated();
adbProcess.on("adb-ready", this.onAdbProcessReady);
// get the initial status of adb process, in case it's already started
this.onAdbProcessReady();
// Remove deprecated remote debugging extensions.
await adbAddon.uninstallUnsupportedExtensions();
@ -98,6 +103,10 @@ const AboutDebugging = {
this.actions.updateAdbAddonStatus(adbAddon.status);
},
onAdbProcessReady() {
this.actions.updateAdbReady(adbProcess.ready);
},
onNetworkLocationsUpdated() {
this.actions.updateNetworkLocations(getNetworkLocations());
},
@ -123,6 +132,7 @@ const AboutDebugging = {
removeNetworkLocationsObserver(this.onNetworkLocationsUpdated);
removeUSBRuntimesObserver(this.onUSBRuntimesUpdated);
adbAddon.off("update", this.onAdbAddonUpdated);
adbProcess.off("adb-ready", this.onAdbProcessReady);
setDebugTargetCollapsibilities(state.ui.debugTargetCollapsibilities);
unmountComponentAtNode(this.mount);
},

Просмотреть файл

@ -12,6 +12,7 @@ const {
ADB_ADDON_UNINSTALL_SUCCESS,
ADB_ADDON_UNINSTALL_FAILURE,
ADB_ADDON_STATUS_UPDATED,
ADB_READY_UPDATED,
DEBUG_TARGET_COLLAPSIBILITY_UPDATED,
HIDE_PROFILER_DIALOG,
NETWORK_LOCATIONS_UPDATED,
@ -112,6 +113,10 @@ function updateAdbAddonStatus(adbAddonStatus) {
return { type: ADB_ADDON_STATUS_UPDATED, adbAddonStatus };
}
function updateAdbReady(isAdbReady) {
return { type: ADB_READY_UPDATED, isAdbReady };
}
function updateNetworkLocations(locations) {
return (dispatch, getState) => {
dispatch(Actions.updateNetworkRuntimes(locations));
@ -170,6 +175,7 @@ module.exports = {
showProfilerDialog,
uninstallAdbAddon,
updateAdbAddonStatus,
updateAdbReady,
updateDebugTargetCollapsibility,
updateNetworkLocations,
};

Просмотреть файл

@ -33,6 +33,7 @@ class App extends PureComponent {
dispatch: PropTypes.func.isRequired,
// getString prop is injected by the withLocalization wrapper
getString: PropTypes.func.isRequired,
isAdbReady: PropTypes.bool.isRequired,
isScanningUsb: PropTypes.bool.isRequired,
networkLocations: PropTypes.arrayOf(Types.location).isRequired,
networkRuntimes: PropTypes.arrayOf(Types.runtime).isRequired,
@ -149,6 +150,7 @@ class App extends PureComponent {
const {
adbAddonStatus,
dispatch,
isAdbReady,
isScanningUsb,
networkRuntimes,
selectedPage,
@ -164,6 +166,7 @@ class App extends PureComponent {
adbAddonStatus,
className: "app__sidebar",
dispatch,
isAdbReady,
isScanningUsb,
networkRuntimes,
selectedPage,
@ -179,6 +182,7 @@ class App extends PureComponent {
const mapStateToProps = state => {
return {
adbAddonStatus: state.ui.adbAddonStatus,
isAdbReady: state.ui.isAdbReady,
isScanningUsb: state.ui.isScanningUsb,
networkLocations: state.ui.networkLocations,
networkRuntimes: state.runtimes.networkRuntimes,

Просмотреть файл

@ -31,6 +31,7 @@ class Sidebar extends PureComponent {
adbAddonStatus: Types.adbAddonStatus,
className: PropTypes.string,
dispatch: PropTypes.func.isRequired,
isAdbReady: PropTypes.bool.isRequired,
isScanningUsb: PropTypes.bool.isRequired,
networkRuntimes: PropTypes.arrayOf(Types.runtime).isRequired,
selectedPage: Types.page,
@ -39,9 +40,10 @@ class Sidebar extends PureComponent {
};
}
renderAdbAddonStatus() {
const isAddonInstalled = this.props.adbAddonStatus === ADB_ADDON_STATES.INSTALLED;
const localizationId = isAddonInstalled ? "about-debugging-sidebar-usb-enabled" :
renderAdbStatus() {
const isUsbEnabled = this.props.isAdbReady &&
this.props.adbAddonStatus === ADB_ADDON_STATES.INSTALLED;
const localizationId = isUsbEnabled ? "about-debugging-sidebar-usb-enabled" :
"about-debugging-sidebar-usb-disabled";
return Message(
{
@ -208,7 +210,7 @@ class Sidebar extends PureComponent {
className: "sidebar-item--overflow sidebar-item--full-width",
},
dom.hr({ className: "separator separator--breathe" }),
this.renderAdbAddonStatus(),
this.renderAdbStatus(),
),
this.renderDevices(),
SidebarItem(

Просмотреть файл

@ -15,6 +15,7 @@ const actionTypes = {
ADB_ADDON_UNINSTALL_SUCCESS: "ADB_ADDON_UNINSTALL_SUCCESS",
ADB_ADDON_UNINSTALL_FAILURE: "ADB_ADDON_UNINSTALL_FAILURE",
ADB_ADDON_STATUS_UPDATED: "ADB_ADDON_STATUS_UPDATED",
ADB_READY_UPDATED: "ADB_READY_UPDATED",
CONNECT_RUNTIME_CANCEL: "CONNECT_RUNTIME_CANCEL",
CONNECT_RUNTIME_FAILURE: "CONNECT_RUNTIME_FAILURE",
CONNECT_RUNTIME_NOT_RESPONDING: "CONNECT_RUNTIME_NOT_RESPONDING",

Просмотреть файл

@ -6,6 +6,7 @@
const {
ADB_ADDON_STATUS_UPDATED,
ADB_READY_UPDATED,
DEBUG_TARGET_COLLAPSIBILITY_UPDATED,
HIDE_PROFILER_DIALOG,
NETWORK_LOCATIONS_UPDATED,
@ -22,6 +23,7 @@ function UiState(locations = [], debugTargetCollapsibilities = {},
return {
adbAddonStatus: null,
debugTargetCollapsibilities,
isAdbReady: false,
isScanningUsb: false,
networkLocations: locations,
selectedPage: null,
@ -38,6 +40,11 @@ function uiReducer(state = UiState(), action) {
return Object.assign({}, state, { adbAddonStatus });
}
case ADB_READY_UPDATED: {
const { isAdbReady } = action;
return Object.assign({}, state, { isAdbReady });
}
case DEBUG_TARGET_COLLAPSIBILITY_UPDATED: {
const { isCollapsed, key } = action;
const debugTargetCollapsibilities = new Map(state.debugTargetCollapsibilities);

Просмотреть файл

@ -6,9 +6,9 @@
const { Cc, Ci } = require("chrome");
const { dumpn } = require("devtools/shared/DevToolsUtils");
const EventEmitter = require("devtools/shared/event-emitter");
const { getFileForBinary } = require("./adb-binary");
const { setTimeout } = require("resource://gre/modules/Timer.jsm");
const { Services } = require("resource://gre/modules/Services.jsm");
loader.lazyRequireGetter(this, "runCommand", "devtools/shared/adb/commands/index", true);
loader.lazyRequireGetter(this, "check", "devtools/shared/adb/adb-running-checker", true);
@ -29,8 +29,10 @@ async function waitUntil(predicate, retry = 20) {
}
// Class representing the ADB process.
class AdbProcess {
class AdbProcess extends EventEmitter {
constructor() {
super();
this._ready = false;
this._didRunInitially = false;
}
@ -69,8 +71,8 @@ class AdbProcess {
async start() {
return new Promise(async (resolve, reject) => {
const onSuccessfulStart = () => {
Services.obs.notifyObservers(null, "adb-ready");
this._ready = true;
this.emit("adb-ready");
resolve();
};