From 222676eb44a01c131dd9dff0155caabe1954555e Mon Sep 17 00:00:00 2001 From: Benjamin Elo Date: Wed, 10 Jul 2019 09:04:26 -0700 Subject: [PATCH] Moved navigation inside of Android Device Summary: It makes more sense for the navigation ability to be inside the Device's class instead of scattered throughout the rest of the app. I have moved the Android navigation logic inside the AndroidDevice and added a function stub to BaseDevice. I also encoded the URI as an initial safeguard to injection attacks via adb, but will remove this altogether once I enable navigation through the socket connection. Reviewed By: jknoxville Differential Revision: D16182374 fbshipit-source-id: be3c6d1cfcbe293583edada1f77c023965dfd12c --- src/chrome/LocationsButton.js | 5 ++--- src/devices/AndroidDevice.js | 5 +++++ src/devices/BaseDevice.js | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/chrome/LocationsButton.js b/src/chrome/LocationsButton.js index dd88b6cc2..4834091df 100644 --- a/src/chrome/LocationsButton.js +++ b/src/chrome/LocationsButton.js @@ -28,9 +28,8 @@ const DropdownButton = styled(Button)({ class LocationsButton extends Component { goToLocation = (location: string) => { const {selectedDevice} = this.props; - if (selectedDevice instanceof AndroidDevice) { - const shellCommand = `am start ${location}`; - selectedDevice.adb.shell(selectedDevice.serial, shellCommand); + if (selectedDevice != null) { + selectedDevice.navigateToLocation(location); } }; diff --git a/src/devices/AndroidDevice.js b/src/devices/AndroidDevice.js index 974bdc6a1..9db48fedc 100644 --- a/src/devices/AndroidDevice.js +++ b/src/devices/AndroidDevice.js @@ -97,4 +97,9 @@ export default class AndroidDevice extends BaseDevice { [...this.logEntries], ); } + + navigateToLocation(location: string) { + const shellCommand = `am start ${encodeURI(location)}`; + this.adb.shell(this.serial, shellCommand); + } } diff --git a/src/devices/BaseDevice.js b/src/devices/BaseDevice.js index 62bdc000e..928270611 100644 --- a/src/devices/BaseDevice.js +++ b/src/devices/BaseDevice.js @@ -139,6 +139,10 @@ export default class BaseDevice { throw new Error('unimplemented'); } + navigateToLocation(location: string) { + throw new Error('unimplemented'); + } + archive(): ?ArchivedDevice { return null; }