Skip to content

Commit 3be8875

Browse files
committed
set additional avd parameters
1 parent a6c1f9c commit 3be8875

File tree

1 file changed

+134
-99
lines changed

1 file changed

+134
-99
lines changed

src/processing/mode/android/AVD.java

Lines changed: 134 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import java.awt.Frame;
2929
import java.io.*;
3030
import java.util.ArrayList;
31-
import java.util.HashMap;
32-
import java.util.List;
3331
import java.util.Map;
3432

3533

@@ -45,15 +43,15 @@ public class AVD {
4543
"and your sketch may be launching shortly.)";
4644

4745
private static final String COMMAND_LINE_TUT_URL =
48-
"http://android.processing.org/tutorials/command_line/index.html";
46+
"https://developer.android.com/studio/command-line/avdmanager.html";
4947

5048
static private final String AVD_LOAD_TITLE =
5149
"Could not load the AVD.";
5250
static private final String AVD_LOAD_MESSAGE =
5351
"This could mean that the Android tools need to be updated,<br>" +
5452
"or that the Processing AVD should be deleted (it will<br>" +
5553
"automatically re-created the next time you run Processing).<br><br>" +
56-
"You can use the SDK command-line tools to update the SDK or list<br>" +
54+
"You can use the avdmanager command line tool to create AVDs manually and list<br>" +
5755
"the current AVDs, check <a href=\"" + COMMAND_LINE_TUT_URL + "\">this online tutorial</a> for more info.";
5856

5957
private static final String GETTING_START_TUT_URL =
@@ -66,54 +64,52 @@ public class AVD {
6664
"found in <a href=\"" + GETTING_START_TUT_URL + "\">this online tutorial</a>.";
6765

6866
static final String DEFAULT_SDCARD_SIZE = "64M";
67+
static final String DEVICE_DEFINITION = "Nexus 5";
68+
static final String DEVICE_SKIN = "1080x1920";
69+
70+
static final String DEVICE_WEAR_DEFINITION = "wear_square_280_280dpi";
71+
static final String DEVICE_WEAR_SKIN = "280x280";
6972

7073
/** Name of this avd. */
7174
protected String name;
7275

73-
/** "android-7" or "Google Inc.:Google APIs:7" */
76+
/** "system-images;android-25;google_apis;x86" */
7477
protected String sdkId;
78+
79+
protected String device;
80+
protected String skin;
7581

7682
static boolean invalidPackage;
7783
static ArrayList<String> avdList;
7884
static ArrayList<String> badList;
7985
// static ArrayList<String> skinList;
8086

81-
private Map<String, String> preferredAbi = new HashMap<>(30);
82-
private List<String> abiList = new ArrayList<>();
8387
private static Process process;
8488

8589
/** Default virtual device used by Processing. */
8690
static public final AVD mobileAVD =
87-
new AVD("Processing-0" + Base.getRevision(),
91+
new AVD("processing-phone",
8892
"system-images;" + AndroidBuild.TARGET_PLATFORM + ";" +
89-
SysImageDownloader.SYSTEM_IMAGE_TAG + ";x86", SysImageDownloader.SYSTEM_IMAGE_TAG);
90-
// "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion);
93+
SysImageDownloader.SYSTEM_IMAGE_TAG + ";x86",
94+
DEVICE_DEFINITION, DEVICE_SKIN);
9195

9296
/** Default virtual wear device used by Processing. */
9397
static public final AVD wearAVD =
94-
new AVD("Processing-Wear-0" + Base.getRevision(),
98+
new AVD("processing-watch",
9599
"system-images;" + AndroidBuild.TARGET_PLATFORM + ";" +
96-
SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG + ";x86", SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG);
100+
SysImageDownloader.SYSTEM_IMAGE_WEAR_TAG + ";x86",
101+
DEVICE_WEAR_DEFINITION, DEVICE_WEAR_SKIN);
102+
97103

98104
public AVD(final String name, final String sdkId,
99-
final String tag) {
105+
final String device, final String skin) {
100106
this.name = name;
101107
this.sdkId = sdkId;
108+
this.device = device;
109+
this.skin = skin;
102110
//initializeAbiList(tag);
103111
}
104112

105-
private void initializeAbiList(String tag) {
106-
if (abiList.size() == 0) {
107-
// The order in this list determines the preference of one abi over the other
108-
abiList.add(tag + "/x86");
109-
abiList.add(tag + "/x86_64");
110-
abiList.add(tag + "/armeabi-v7a");
111-
// abiList.add("google_apis/x86");
112-
// abiList.add("google_apis/x86_64");
113-
// abiList.add("google_apis/armeabi-v7a");
114-
}
115-
}
116-
117113

118114
static protected void list(final AndroidSDK sdk) throws IOException {
119115
try {
@@ -199,85 +195,23 @@ protected boolean badness() {
199195
return false;
200196
}
201197

202-
203-
protected void initTargets(final AndroidSDK sdk) throws IOException {
204-
preferredAbi.clear();
205-
ProcessBuilder pb = new ProcessBuilder(sdk.getAvdManagerPath(), "list", "target");
206-
207-
Map<String, String> env = pb.environment();
208-
env.clear();
209-
env.put("JAVA_HOME", Platform.getJavaHome().getCanonicalPath());
210-
pb.redirectErrorStream(true);
211-
212-
process = pb.start();
213-
InputStream stdout = process.getInputStream();
214-
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
215-
216-
try {
217-
process.waitFor();
218-
219-
String api = null;
220-
String[] abis = null;
221-
String line;
222-
while ((line = reader.readLine()) != null) {
223-
line = line.trim();
224-
if (line.equals("")) continue;
225-
226-
if (line.indexOf("API level") == 0) {
227-
String[] m = line.split(":");
228-
if (1 < m.length) {
229-
api = m[1];
230-
api = api.trim();
231-
}
232-
}
233-
234-
if (line.indexOf("Tag/ABIs") == 0) {
235-
String[] m = line.split(":");
236-
if (1 < m.length) {
237-
String str = m[1];
238-
abis = str.split(",");
239-
for (int i = 0; i < abis.length; i++) {
240-
abis[i] = abis[i].trim();
241-
}
242-
}
243-
}
244-
245-
if (api != null && abis != null) {
246-
for (String abi: abis) {
247-
if (abiList.indexOf(abi) == -1) continue;
248-
if (preferredAbi.get(api) == null) {
249-
preferredAbi.put(api, abi);
250-
} else if (abiList.indexOf(preferredAbi.get(api)) < abiList.indexOf(abi)) {
251-
preferredAbi.put(api, abi);
252-
}
253-
}
254-
api = null;
255-
abis = null;
256-
}
257-
}
258-
} catch (InterruptedException e) {
259-
} finally {
260-
process.destroy();
261-
}
262-
}
263-
264-
265-
protected boolean noTargets(final AndroidSDK sdk) throws IOException {
266-
initTargets(sdk);
267-
// return preferredAbi.size() == 0;
268-
return preferredAbi.get(AndroidBuild.TARGET_SDK) == null;
269-
}
270-
271198

272199
protected boolean create(final AndroidSDK sdk) throws IOException {
273200
//initTargets(sdk);
274-
201+
File sketchbookFolder = processing.app.Base.getSketchbookFolder();
202+
File androidFolder = new File(sketchbookFolder, "android");
203+
if (!androidFolder.exists()) androidFolder.mkdir();
204+
File avdPath = new File(androidFolder, "avd/" + name);
205+
275206
ProcessBuilder pb = new ProcessBuilder(
276207
sdk.getAvdManagerPath(),
277208
"create", "avd",
278-
"-n", name,
209+
"-n", name,
279210
"-k", sdkId,
280-
"-c", DEFAULT_SDCARD_SIZE
211+
"-c", DEFAULT_SDCARD_SIZE,
212+
"-d", device,
213+
"-p", avdPath.getAbsolutePath(),
214+
"-f"
281215
);
282216

283217
// avdmanager create avd -n "Wear-Processing-0254" -k "system-images;android-25;google_apis;x86" -c 64M
@@ -308,17 +242,26 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
308242
process.waitFor();
309243

310244
if (process.exitValue() == 0) {
245+
// Add skin to AVD's config file
246+
File configFile = new File(avdPath, "config.ini");
247+
if (configFile.exists()) {
248+
try (PrintWriter output = new PrintWriter(new FileWriter(configFile.getAbsolutePath(), true)))
249+
{
250+
output.printf("%s\r\n", "skin.name=" + skin);
251+
}
252+
catch (Exception e) {}
253+
}
311254
return true;
312255
}
313256

314257
String line;
315258
StringBuilder output = new StringBuilder();
316-
while((line = reader.readLine()) != null) {
259+
while ((line = reader.readLine()) != null) {
317260
output.append(line);
318261
}
319262
if (output.toString().contains("Package path is not valid")) {
320263
// They didn't install the Google APIs
321-
//AndroidUtil.showMessage(AVD_TARGET_TITLE, AVD_TARGET_MESSAGE);
264+
AndroidUtil.showMessage(AVD_TARGET_TITLE, AVD_TARGET_MESSAGE);
322265
invalidPackage = true;
323266
} else {
324267
// Just generally not working
@@ -336,13 +279,15 @@ protected boolean create(final AndroidSDK sdk) throws IOException {
336279
return false;
337280
}
338281

282+
339283
static public String getPort(boolean wear) {
340284
if (wear) {
341285
return EmulatorController.WEAR_PORT;
342286
} else {
343287
return EmulatorController.DEFAULT_PORT;
344288
}
345289
}
290+
346291

347292
static public boolean ensureProperAVD(final Frame window, final AndroidMode mode,
348293
final AndroidSDK sdk, boolean wear) {
@@ -399,4 +344,94 @@ static public boolean ensureProperAVD(final Frame window, final AndroidMode mode
399344
}
400345
return false;
401346
}
347+
348+
349+
//////////////////////////////////////////////////////////////////////////////
350+
// To remove:
351+
352+
/*
353+
354+
private Map<String, String> preferredAbi = new HashMap<>(30);
355+
private List<String> abiList = new ArrayList<>();
356+
357+
protected boolean noTargets(final AndroidSDK sdk) throws IOException {
358+
initTargets(sdk);
359+
// return preferredAbi.size() == 0;
360+
return preferredAbi.get(AndroidBuild.TARGET_SDK) == null;
361+
}
362+
363+
364+
private void initializeAbiList(String tag) {
365+
if (abiList.size() == 0) {
366+
// The order in this list determines the preference of one abi over the other
367+
abiList.add(tag + "/x86");
368+
abiList.add(tag + "/x86_64");
369+
abiList.add(tag + "/armeabi-v7a");
370+
// abiList.add("google_apis/x86");
371+
// abiList.add("google_apis/x86_64");
372+
// abiList.add("google_apis/armeabi-v7a");
373+
}
374+
}
375+
376+
protected void initTargets(final AndroidSDK sdk) throws IOException {
377+
preferredAbi.clear();
378+
ProcessBuilder pb = new ProcessBuilder(sdk.getAvdManagerPath(), "list", "target");
379+
380+
Map<String, String> env = pb.environment();
381+
env.clear();
382+
env.put("JAVA_HOME", Platform.getJavaHome().getCanonicalPath());
383+
pb.redirectErrorStream(true);
384+
385+
process = pb.start();
386+
InputStream stdout = process.getInputStream();
387+
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
388+
389+
try {
390+
process.waitFor();
391+
392+
String api = null;
393+
String[] abis = null;
394+
String line;
395+
while ((line = reader.readLine()) != null) {
396+
line = line.trim();
397+
if (line.equals("")) continue;
398+
399+
if (line.indexOf("API level") == 0) {
400+
String[] m = line.split(":");
401+
if (1 < m.length) {
402+
api = m[1];
403+
api = api.trim();
404+
}
405+
}
406+
407+
if (line.indexOf("Tag/ABIs") == 0) {
408+
String[] m = line.split(":");
409+
if (1 < m.length) {
410+
String str = m[1];
411+
abis = str.split(",");
412+
for (int i = 0; i < abis.length; i++) {
413+
abis[i] = abis[i].trim();
414+
}
415+
}
416+
}
417+
418+
if (api != null && abis != null) {
419+
for (String abi: abis) {
420+
if (abiList.indexOf(abi) == -1) continue;
421+
if (preferredAbi.get(api) == null) {
422+
preferredAbi.put(api, abi);
423+
} else if (abiList.indexOf(preferredAbi.get(api)) < abiList.indexOf(abi)) {
424+
preferredAbi.put(api, abi);
425+
}
426+
}
427+
api = null;
428+
abis = null;
429+
}
430+
}
431+
} catch (InterruptedException e) {
432+
} finally {
433+
process.destroy();
434+
}
435+
}
436+
*/
402437
}

0 commit comments

Comments
 (0)