Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: dart/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/mobile/AndroidDebugBridge.java

Issue 321583008: Merge to trunk cl - fixes/features for mobile support in the editor (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | dart/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/mobile/AndroidDevice.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014, the Dart project authors. 2 * Copyright (c) 2014, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
(...skipping 17 matching lines...) Expand all
28 * Instance of class {@code AndroidDevBridge} represents the AndroidDevBridge (a db) in the Android 28 * Instance of class {@code AndroidDevBridge} represents the AndroidDevBridge (a db) in the Android
29 * SDK 29 * SDK
30 */ 30 */
31 public class AndroidDebugBridge { 31 public class AndroidDebugBridge {
32 32
33 private File adb; 33 private File adb;
34 34
35 private static String[] INSTALL_CMD = new String[] {"install"}; 35 private static String[] INSTALL_CMD = new String[] {"install"};
36 private static String[] DEVICES_CMD = new String[] {"devices"}; 36 private static String[] DEVICES_CMD = new String[] {"devices"};
37 37
38 private static final String DEVICE_CONNECTED_SUFFIX = "\tdevice";
39 private static final String UNAUTHORIZED_SUFFIX = "\tunauthorized";
40
38 private static String[] LAUNCH_URL_IN_CC_CMD = new String[] { 41 private static String[] LAUNCH_URL_IN_CC_CMD = new String[] {
39 "shell", "am", "start", "-n", "org.chromium.content_shell_apk/.ContentShel lActivity", "-d"}; 42 "shell", "am", "start", "-n", "org.chromium.content_shell_apk/.ContentShel lActivity", "-d"};
40 43
41 private static String[] LAUNCH_URL_IN_BROWSER_CMD = new String[] { 44 private static String[] LAUNCH_URL_IN_BROWSER_CMD = new String[] {
42 "shell", "am", "start", "-n", "com.android.chrome/com.google.android.apps. chrome.Main", "-d"}; 45 "shell", "am", "start", "-n", "com.android.chrome/com.google.android.apps. chrome.Main", "-d"};
43 46
44 private static String[] STOP_APP_CMD = new String[] { 47 private static String[] STOP_APP_CMD = new String[] {
45 "shell", "am", "force-stop", "org.chromium.content_shell_apk"}; 48 "shell", "am", "force-stop", "org.chromium.content_shell_apk"};
46 49
47 private static final String CONTENT_SHELL_DEBUG_PORT = "localabstract:content_ shell_devtools_remote"; 50 private static final String CONTENT_SHELL_DEBUG_PORT = "localabstract:content_ shell_devtools_remote";
(...skipping 20 matching lines...) Expand all
68 return androidDebugBridge; 71 return androidDebugBridge;
69 } 72 }
70 73
71 AndroidDebugBridge(File adbExecutable) { 74 AndroidDebugBridge(File adbExecutable) {
72 this.adb = adbExecutable; 75 this.adb = adbExecutable;
73 } 76 }
74 77
75 /** 78 /**
76 * Gets the first device connected and detected by adb 79 * Gets the first device connected and detected by adb
77 * 80 *
78 * @return the device id or {@code null} if no device detected 81 * @return the device or {@code null} if no device detected
79 */ 82 */
80 public String getConnectedDevice() { 83 public AndroidDevice getConnectedDevice() {
81 List<String> args = buildAdbCommand(DEVICES_CMD); 84 List<String> args = buildAdbCommand(DEVICES_CMD);
82 if (runAdb(args)) { 85 if (runAdb(args)) {
83 //List of devices attached 86 //List of devices attached
84 //04f5385f95d80610 device 87 //04f5385f95d80610 device
88 //T062873654 unauthorized
89 String unauthorized = null;
85 LineNumberReader reader = new LineNumberReader(new StringReader(runner.get StdOut())); 90 LineNumberReader reader = new LineNumberReader(new StringReader(runner.get StdOut()));
86 try { 91 try {
87 while (true) { 92 while (true) {
88 String line = reader.readLine(); 93 String line = reader.readLine();
89 if (line == null) { 94 if (line == null) {
90 break; 95 break;
91 } 96 }
92 line = line.trim(); 97 line = line.trim();
93 if (line.endsWith("\tdevice")) { 98 if (line.endsWith(DEVICE_CONNECTED_SUFFIX)) {
94 return line.substring(0, line.length() - 7).trim(); 99 String id = line.substring(0, line.length() - DEVICE_CONNECTED_SUFFI X.length()).trim();
100 return new AndroidDevice(id, true);
101 }
102 if (line.endsWith(UNAUTHORIZED_SUFFIX)) {
103 unauthorized = line.substring(0, line.length() - UNAUTHORIZED_SUFFIX .length()).trim();
95 } 104 }
96 } 105 }
97 } catch (IOException e) { 106 } catch (IOException e) {
98 //$FALL-THROUGH$ 107 //$FALL-THROUGH$
99 } 108 }
109 if (unauthorized != null) {
110 return new AndroidDevice(unauthorized, false);
111 }
100 } 112 }
101 return null; 113 return null;
102 } 114 }
103 115
104 /** 116 /**
105 * Install the apk for the content shell onto the connected phone 117 * Install the apk for the content shell onto the connected phone
106 * <p> 118 * <p>
107 * adb install path/to/apk 119 * adb install path/to/apk
108 * </p> 120 * </p>
109 * 121 *
(...skipping 18 matching lines...) Expand all
128 // TODO(keertip): check version and reinstall 140 // TODO(keertip): check version and reinstall
129 // DartCore.getConsole().println(message); 141 // DartCore.getConsole().println(message);
130 } 142 }
131 contentShellInstallSet.add(deviceId); 143 contentShellInstallSet.add(deviceId);
132 return true; 144 return true;
133 } 145 }
134 return false; 146 return false;
135 } 147 }
136 148
137 /** 149 /**
150 * Determine if a mobile device is connected and authorized.
151 */
152 public boolean isDeviceConnectedAndAuthorized() {
153 AndroidDevice device = getConnectedDevice();
154 return device != null && device.isAuthorized();
155 }
156
157 /**
138 * Open the url in the chrome browser on the device 158 * Open the url in the chrome browser on the device
139 * <p> 159 * <p>
140 * adb shell am start com.android.chrome/com.google.android.apps.chrome.Main - d url 160 * adb shell am start com.android.chrome/com.google.android.apps.chrome.Main - d url
141 * </p> 161 * </p>
142 */ 162 */
143 public boolean launchChromeBrowser(String url) { 163 public boolean launchChromeBrowser(String url) {
144 List<String> args = buildAdbCommand(LAUNCH_URL_IN_BROWSER_CMD); 164 List<String> args = buildAdbCommand(LAUNCH_URL_IN_BROWSER_CMD);
145 args.add(url); 165 args.add(url);
146 return runAdb(args, "ADB: launch browser"); 166 return runAdb(args, "ADB: launch browser");
147 } 167 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 exitCode = runner.runSync(null); 259 exitCode = runner.runSync(null);
240 if (exitCode != 0) { 260 if (exitCode != 0) {
241 DartCore.getConsole().println(runner.getStdErr()); 261 DartCore.getConsole().println(runner.getStdErr());
242 } 262 }
243 263
244 } catch (IOException e) { 264 } catch (IOException e) {
245 DartCore.logError(e); 265 DartCore.logError(e);
246 } 266 }
247 return exitCode == 0 ? true : false; 267 return exitCode == 0 ? true : false;
248 } 268 }
249
250 } 269 }
OLDNEW
« no previous file with comments | « no previous file | dart/editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/mobile/AndroidDevice.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698