Skip to content

Commit 0d7c1c8

Browse files
committed
testing image install
1 parent c1a30af commit 0d7c1c8

File tree

6 files changed

+142
-64
lines changed

6 files changed

+142
-64
lines changed

src/processing/mode/android/AVD.java

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class AVD {
5454
"This could mean that the Android tools need to be updated,<br>" +
5555
"or that the Processing AVD should be deleted (it will<br>" +
5656
"automatically re-created the next time you run Processing).<br><br>" +
57-
"You can use the avdmanager command line tool to create AVDs manually and list<br>" +
57+
"You can use the avdmanager command line tool to create AVDs manually and list " +
5858
"the current AVDs, check <a href=\"" + COMMAND_LINE_TUT_URL + "\">this online tutorial</a> for more info.";
5959

6060
private static final String GETTING_START_TUT_URL =
@@ -67,26 +67,27 @@ public class AVD {
6767
"found in <a href=\"" + GETTING_START_TUT_URL + "\">this online tutorial</a>.";
6868

6969
static final String DEFAULT_SDCARD_SIZE = "64M";
70-
static final String DEVICE_DEFINITION = "Nexus 5";
71-
static final String DEVICE_SKIN = "1080x1920";
70+
71+
static final String DEVICE_DEFINITION = "Nexus One";
72+
static final String DEVICE_SKIN = "480x800";
7273

7374
static final String DEVICE_WEAR_DEFINITION = "wear_square_280_280dpi";
7475
static final String DEVICE_WEAR_SKIN = "280x280";
7576

7677
/** Name of this avd. */
7778
protected String name;
7879

79-
/** "system-images;android-25;google_apis;x86" */
80-
protected ArrayList<String> watchImages;
81-
protected ArrayList<String> phoneImages;
82-
8380
protected String device;
8481
protected String skin;
8582

8683
static ArrayList<String> avdList;
8784
static ArrayList<String> badList;
8885
// static ArrayList<String> skinList;
89-
86+
87+
/** "system-images;android-25;google_apis;x86" */
88+
static ArrayList<String> wearImages;
89+
static ArrayList<String> phoneImages;
90+
9091
private static Process process;
9192

9293
/** Default virtual device used by Processing. */
@@ -104,11 +105,6 @@ public AVD(final String name, final String device, final String skin) {
104105
this.name = name;
105106
this.device = device;
106107
this.skin = skin;
107-
108-
if (name.contains("phone"))
109-
phoneImages = new ArrayList<>();
110-
else
111-
watchImages = new ArrayList<>();
112108
}
113109

114110

@@ -196,7 +192,39 @@ protected boolean badness() {
196192
return false;
197193
}
198194

199-
protected void getImages(AndroidSDK sdk) throws IOException {
195+
196+
protected boolean hasImages(final AndroidSDK sdk) throws IOException {
197+
if (phoneImages == null) {
198+
phoneImages = new ArrayList<String>();
199+
getImages(phoneImages, sdk, SysImageDownloader.SYSTEM_IMAGE_TAG);
200+
}
201+
return !phoneImages.isEmpty();
202+
}
203+
204+
205+
protected void refreshImages(final AndroidSDK sdk) throws IOException {
206+
phoneImages = new ArrayList<String>();
207+
getImages(phoneImages, sdk, SysImageDownloader.SYSTEM_IMAGE_TAG);
208+
}
209+
210+
211+
protected boolean hasWearImages(final AndroidSDK sdk) throws IOException {
212+
if (wearImages == null) {
213+
wearImages = new ArrayList<String>();
214+
getImages(wearImages, sdk, SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG);
215+
}
216+
return !wearImages.isEmpty();
217+
}
218+
219+
220+
protected void refreshWearImages(final AndroidSDK sdk) throws IOException {
221+
wearImages = new ArrayList<String>();
222+
getImages(wearImages, sdk, SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG);
223+
}
224+
225+
226+
protected void getImages(final ArrayList<String> images, final AndroidSDK sdk,
227+
final String imageTag) throws IOException {
200228
// Dummy avdmanager creation command to get the list of installed images
201229
// TODO : Find a better way to get the list of installed images
202230
ProcessBuilder pb = new ProcessBuilder(
@@ -218,12 +246,10 @@ protected void getImages(AndroidSDK sdk) throws IOException {
218246
output.addTarget(new LineProcessor() {
219247
@Override
220248
public void processLine(String line) {
221-
if (phoneImages != null && line.contains(AndroidBuild.TARGET_PLATFORM) &&
222-
line.contains(SysImageDownloader.SYSTEM_IMAGE_TAG))
223-
phoneImages.add(line);
224-
else if (watchImages != null && line.contains(AndroidBuild.TARGET_PLATFORM) &&
225-
line.contains(SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG))
226-
watchImages.add(line);
249+
if (images != null && line.contains(AndroidBuild.TARGET_PLATFORM) &&
250+
line.contains(imageTag))
251+
System.out.println("IMAGE ---> " + line);
252+
images.add(line);
227253
}
228254
}).start();
229255

@@ -235,6 +261,7 @@ else if (watchImages != null && line.contains(AndroidBuild.TARGET_PLATFORM) &&
235261
}
236262
}
237263

264+
238265
protected String getSdkId() throws IOException {
239266
if (Preferences.get("android.system.image.type") == null)
240267
Preferences.set("android.system.image.type", "x86"); // Prefer x86
@@ -245,7 +272,7 @@ protected String getSdkId() throws IOException {
245272
return image;
246273
}
247274
} else {
248-
for (String image : watchImages) {
275+
for (String image : wearImages) {
249276
if (image.contains(Preferences.get("android.system.image.type")))
250277
return image;
251278
}
@@ -353,14 +380,12 @@ static public boolean ensureProperAVD(final Frame window, final AndroidMode mode
353380
AndroidUtil.showMessage(AVD_LOAD_TITLE, AVD_LOAD_MESSAGE);
354381
return false;
355382
}
356-
wearAVD.getImages(sdk);
357-
if (wearAVD.watchImages.isEmpty()) {
383+
if (wearAVD.hasWearImages(sdk)) {
358384
boolean res = AndroidSDK.locateSysImage(window, mode, true);
359385
if (!res) {
360386
return false;
361387
} else {
362-
// Refresh images list
363-
wearAVD.getImages(sdk);
388+
wearAVD.refreshWearImages(sdk);
364389
}
365390
}
366391
if (wearAVD.create(sdk)) {
@@ -374,14 +399,12 @@ static public boolean ensureProperAVD(final Frame window, final AndroidMode mode
374399
AndroidUtil.showMessage(AVD_LOAD_TITLE, AVD_LOAD_MESSAGE);
375400
return false;
376401
}
377-
mobileAVD.getImages(sdk);
378-
if (mobileAVD.phoneImages.isEmpty()) {
402+
if (mobileAVD.hasImages(sdk)) {
379403
boolean res = AndroidSDK.locateSysImage(window, mode, false);
380404
if (!res) {
381405
return false;
382406
} else {
383-
// Refresh images list
384-
mobileAVD.getImages(sdk);
407+
mobileAVD.refreshImages(sdk);
385408
}
386409
}
387410
if (mobileAVD.create(sdk)) {

src/processing/mode/android/AndroidSDK.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class AndroidSDK {
6565
private final File avdManager;
6666
private final File wearablePath;
6767
private final File supportLibPath;
68-
68+
6969
private static final String SDK_DOWNLOAD_URL =
7070
"https://developer.android.com/studio/index.html#downloads";
7171

@@ -119,6 +119,20 @@ class AndroidSDK {
119119

120120
private static final String SELECT_ANDROID_SDK_FOLDER =
121121
"Choose the location of the Android SDK";
122+
123+
/*
124+
private static final String GOOGLE_INSTALL_TITLE = "Google USB Drivers";
125+
126+
private static final String DRIVER_INSTALL_URL =
127+
"https://developer.android.com/studio/run/oem-usb.html#InstallingDriver";
128+
129+
private static final String GOOGLE_INSTALL_MESSAGE =
130+
"If you are planning to use Google Nexus devices, then need the " +
131+
"Google USB Driver to connect them to Processing. You would have to " +
132+
"install the driver manually following <a href=\"" + DRIVER_INSTALL_URL +
133+
"\">these instructions</a>.<br><br>" +
134+
"The installation files are available in this folder</br>";
135+
*/
122136

123137
private static final int NO_ERROR = 0;
124138
private static final int MISSING_SDK = 1;
@@ -130,7 +144,7 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
130144
if (!folder.exists()) {
131145
throw new BadSDKException(folder + " does not exist");
132146
}
133-
147+
134148
tools = new File(folder, "tools");
135149
if (!tools.exists()) {
136150
throw new BadSDKException("There is no tools folder in " + folder);
@@ -172,7 +186,7 @@ public AndroidSDK(File folder) throws BadSDKException, IOException {
172186
if (!supportLibPath.exists()) {
173187
throw new BadSDKException("There is no support library folder in " + folder);
174188
}
175-
189+
176190
avdManager = findAvdManager(new File(tools, "bin"));
177191

178192
String path = Platform.getenv("PATH");
@@ -290,6 +304,20 @@ public File getSupportLibrary() {
290304
return supportLibPath;
291305
}
292306

307+
308+
static public File getHAXMInstallerFolder() {
309+
String sdkPrefsPath = Preferences.get("android.sdk.path");
310+
File sdkPath = new File(sdkPrefsPath);
311+
return new File(sdkPath, "extras/intel/HAXM");
312+
}
313+
314+
315+
static public File getGoogleDriverFolder() {
316+
String sdkPrefsPath = Preferences.get("android.sdk.path");
317+
File sdkPath = new File(sdkPrefsPath);
318+
return new File(sdkPath, "extras/google_usb");
319+
}
320+
293321

294322
/**
295323
* Checks a path to see if there's a tools/android file inside, a rough check
@@ -404,6 +432,11 @@ static public AndroidSDK download(final Frame editor, final AndroidMode androidM
404432
if (sdk == null) {
405433
throw new BadSDKException("SDK could not be downloaded");
406434
}
435+
// File googDriv = AndroidSDK.getGoogleDriverFolder();
436+
// if (googDriv.exists()) {
437+
// AndroidUtil.showMessage(GOOGLE_INSTALL_TITLE,
438+
// GOOGLE_INSTALL_MESSAGE + googDriv.getAbsolutePath());
439+
// }
407440
return sdk;
408441
}
409442

src/processing/mode/android/EmulatorController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ synchronized public void launch(File sdkToolsPath, boolean wear, boolean gpu) th
107107

108108

109109
//System.err.println("EmulatorController: Launching emulator");
110-
if (Base.DEBUG) {
110+
//if (Base.DEBUG) {
111111
System.out.println(processing.core.PApplet.join(cmd, " "));
112-
}
112+
// }
113113
//ProcessResult adbResult = new ProcessHelper(adbCmd).execute();
114114
final Process p = Runtime.getRuntime().exec(cmd);
115115
ProcessRegistry.watch(p);

src/processing/mode/android/Manifest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
public class Manifest {
4545
static final String MANIFEST_XML = "AndroidManifest.xml";
4646

47-
static final String WORLD_OF_HURT_COMING =
47+
static final String MANIFEST_ERROR =
4848
"Errors occurred while reading or writing " + MANIFEST_XML + ",\n" +
4949
"which means lots of things are likely to stop working properly.\n" +
5050
"To prevent losing any data, it's recommended that you use “Save As”\n" +
@@ -311,7 +311,7 @@ protected void load(boolean forceNew) {
311311
}
312312
}
313313
if (xml == null) {
314-
Messages.showWarning("Error handling " + MANIFEST_XML, WORLD_OF_HURT_COMING);
314+
Messages.showWarning("Error handling " + MANIFEST_XML, MANIFEST_ERROR);
315315
}
316316
}
317317

src/processing/mode/android/SDKDownloader.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ protected Object doInBackground() throws Exception {
114114
if (!extrasFolder.exists()) extrasFolder.mkdir();
115115
File googleRepoFolder = new File(extrasFolder, "google");
116116
if (!googleRepoFolder.exists()) googleRepoFolder.mkdir();
117+
File googleDriverFolder = new File(googleRepoFolder, "usb_driver");
118+
if (!googleDriverFolder.exists()) googleDriverFolder.mkdir();
119+
File haxmFolder = new File(extrasFolder, "intel/HAXM");
120+
if (!haxmFolder.exists()) haxmFolder.mkdirs();
117121
File androidRepoFolder = new File(extrasFolder, "android");
118122
if (!androidRepoFolder.exists()) androidRepoFolder.mkdir();
119123

@@ -147,9 +151,9 @@ protected Object doInBackground() throws Exception {
147151
File downloadedPlatform = new File(tempFolder, downloadUrls.platformFilename);
148152
downloadAndUnpack(downloadUrls.platformUrl, downloadedPlatform, platformsFolder, false);
149153

150-
// emulator
154+
// emulator, unpacks directly to sdk folder
151155
File downloadedEmulator = new File(tempFolder, downloadUrls.emulatorFilename);
152-
downloadAndUnpack(downloadUrls.emulatorUrl, downloadedEmulator, emulatorFolder, true);
156+
downloadAndUnpack(downloadUrls.emulatorUrl, downloadedEmulator, sdkFolder, true);
153157

154158
// google repository
155159
File downloadedGoogleRepo = new File(tempFolder, downloadUrls.googleRepoFilename);
@@ -162,23 +166,13 @@ protected Object doInBackground() throws Exception {
162166
// usb driver
163167
if (Platform.isWindows()) {
164168
File downloadedFolder = new File(tempFolder, downloadUrls.usbDriverFilename);
165-
downloadAndUnpack(downloadUrls.usbDriverUrl, downloadedFolder, googleRepoFolder, false);
169+
downloadAndUnpack(downloadUrls.usbDriverUrl, downloadedFolder, googleDriverFolder, false);
166170
}
167171

168172
// HAXM
169173
if (!Platform.isLinux()) {
170174
File downloadedFolder = new File(tempFolder, downloadUrls.haxmFilename);
171-
File haxmFolder = new File(tempFolder, "HAXM");
172175
downloadAndUnpack(downloadUrls.haxmUrl, downloadedFolder, haxmFolder, true);
173-
174-
ProcessBuilder pb;
175-
if (Platform.isWindows())
176-
pb = new ProcessBuilder("cmd.exe", "/c", "start", "silent_install.bat");
177-
else
178-
pb = new ProcessBuilder("silent_install.sh");
179-
180-
pb.directory(haxmFolder);
181-
pb.start().waitFor();
182176
}
183177

184178
if (Platform.isLinux() || Platform.isMacOS()) {

0 commit comments

Comments
 (0)