FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing-android/src/processing/mode/android/AVD.java at master · Dvik/processing-android · GitHub
Dvik
/
processing-android
Public
forked from
processing/processing-android
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing-android
/
src
/
processing
/
mode
/
android
/
AVD.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
248 lines (213 loc) · 7.67 KB
Breadcrumbs
processing-android
/
src
/
processing
/
mode
/
android
/
AVD.java
Copy path
File metadata and controls
248 lines (213 loc) · 7.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
package
processing
.
mode
.
android
;
import
processing
.
app
.
Base
;
import
processing
.
app
.
exec
.
ProcessHelper
;
import
processing
.
app
.
exec
.
ProcessResult
;
import
processing
.
core
.
PApplet
;
import
java
.
io
.
IOException
;
import
java
.
util
.
ArrayList
;
public
class
AVD
{
static
private
final
String
AVD_CREATE_PRIMARY
=
"An error occurred while running “android create avd”"
;
static
private
final
String
AVD_CREATE_SECONDARY
=
"The default Android emulator could not be set up. Make sure<br>"
+
"that the Android SDK is installed properly, and that the<br>"
+
"system images are installed for level %s.<br>"
+
"(Between you and me, occasionally, this error is a red herring,<br>"
+
"and your sketch may be launching shortly.)"
;
static
private
final
String
AVD_LOAD_PRIMARY
=
"There is an error with the Processing AVD."
;
static
private
final
String
AVD_LOAD_SECONDARY
=
"This could mean that the Android tools need to be updated,<br>"
+
"or that the Processing AVD should be deleted (it will<br>"
+
"automatically re-created the next time you run Processing).<br>"
+
"Open the Android SDK Manager (underneath the Android menu)<br>"
+
"to check for any errors."
;
static
private
final
String
AVD_TARGET_PRIMARY
=
"The Google APIs are not installed properly"
;
static
private
final
String
AVD_TARGET_SECONDARY
=
"Please re-read the installation instructions for Processing<br>"
+
"found at http://android.processing.org and try again."
;
static
final
String
DEFAULT_SKIN
=
"WVGA800"
;
static
final
String
DEFAULT_SDCARD_SIZE
=
"64M"
;
/** Name of this avd. */
protected
String
name
;
/** "android-7" or "Google Inc.:Google APIs:7" */
protected
String
target
;
static
ArrayList
<
String
>
avdList
;
static
ArrayList
<
String
>
badList
;
// static ArrayList<String> skinList;
private
String
[]
preferredAbi
=
new
String
[
50
];
private
static
ArrayList
<
String
>
abiList
=
new
ArrayList
<>();
/** Default virtual device used by Processing. */
static
public
final
AVD
defaultAVD
=
new
AVD
(
"Processing-0"
+
Base
.
getRevision
(),
"android-"
+
AndroidBuild
.
sdkVersion
);
// "Google Inc.:Google APIs:" + AndroidBuild.sdkVersion);
public
AVD
(
final
String
name
,
final
String
target
) {
this
.
name
=
name
;
this
.
target
=
target
;
initializeAbiList
();
}
private
void
initializeAbiList
() {
if
(
abiList
.
size
() ==
0
) {
abiList
.
add
(
"armeabi"
);
abiList
.
add
(
"x86"
);
abiList
.
add
(
"x86_64"
);
}
}
static
protected
void
list
(
final
AndroidSDK
sdk
)
throws
IOException
{
try
{
avdList
=
new
ArrayList
<
String
>();
badList
=
new
ArrayList
<
String
>();
ProcessResult
listResult
=
new
ProcessHelper
(
sdk
.
getAndroidToolPath
(),
"list"
,
"avds"
).
execute
();
if
(
listResult
.
succeeded
()) {
boolean
badness
=
false
;
for
(
String
line
:
listResult
) {
String
[]
m
=
PApplet
.
match
(
line
,
"
\\
s+Name
\\
:
\\
s+(
\\
S+)"
);
if
(
m
!=
null
) {
if
(!
badness
) {
// System.out.println("good: " + m[1]);
avdList
.
add
(
m
[
1
]);
}
else
{
// System.out.println("bad: " + m[1]);
badList
.
add
(
m
[
1
]);
}
// } else {
// System.out.println("nope: " + line);
}
// "The following Android Virtual Devices could not be loaded:"
if
(
line
.
contains
(
"could not be loaded:"
)) {
// System.out.println("starting the bad list");
// System.err.println("Could not list AVDs:");
// System.err.println(listResult);
badness
=
true
;
// break;
}
}
}
else
{
System
.
err
.
println
(
"Unhappy inside exists()"
);
System
.
err
.
println
(
listResult
);
}
}
catch
(
final
InterruptedException
ie
) { }
}
protected
boolean
exists
(
final
AndroidSDK
sdk
)
throws
IOException
{
if
(
avdList
==
null
) {
list
(
sdk
);
}
for
(
String
avd
:
avdList
) {
if
(
Base
.
DEBUG
) {
System
.
out
.
println
(
"AVD.exists() checking for "
+
name
+
" against "
+
avd
);
}
if
(
avd
.
equals
(
name
)) {
return
true
;
}
}
return
false
;
}
/**
* Return true if a member of the renowned and prestigious
* "The following Android Virtual Devices could not be loaded:" club.
* (Prestigious may also not be the right word.)
*/
protected
boolean
badness
() {
for
(
String
avd
:
badList
) {
if
(
avd
.
equals
(
name
)) {
return
true
;
}
}
return
false
;
}
protected
boolean
create
(
final
AndroidSDK
sdk
)
throws
IOException
{
final
String
[]
list_abi
= {
sdk
.
getAndroidToolPath
(),
"list"
,
"targets"
};
ProcessHelper
p
=
new
ProcessHelper
(
list_abi
);
try
{
final
ProcessResult
abiListResult
=
p
.
execute
();
String
api
=
null
;
String
abi
=
null
;
for
(
String
line
:
abiListResult
) {
String
[]
m
=
PApplet
.
match
(
line
,
"API
\\
slevel:
\\
s(
\\
S+)"
);
if
(
m
!=
null
) {
api
=
m
[
1
];
}
m
=
PApplet
.
match
(
line
,
"Tag
\\
/ABIs
\\
s:
\\
sdefault
\\
/(
\\
S+)"
);
if
(
m
!=
null
) {
abi
=
m
[
1
];
if
(
api
!=
null
&&
abi
!=
null
) {
int
index
=
Integer
.
parseInt
(
api
);
if
(
preferredAbi
[
index
] ==
null
) {
preferredAbi
[
index
] =
abi
;
}
else
if
(
abiList
.
indexOf
(
preferredAbi
[
index
]) <
abiList
.
indexOf
(
abi
)) {
preferredAbi
[
index
] =
abi
;
}
api
=
null
;
abi
=
null
;
}
}
}
}
catch
(
InterruptedException
e
) {}
if
(
preferredAbi
[
Integer
.
parseInt
(
AndroidBuild
.
sdkVersion
)] ==
null
) {
return
false
;
}
final
String
[]
params
= {
sdk
.
getAndroidToolPath
(),
"create"
,
"avd"
,
"-n"
,
name
,
"-t"
,
target
,
"-c"
,
DEFAULT_SDCARD_SIZE
,
"-s"
,
DEFAULT_SKIN
,
"--abi"
,
preferredAbi
[
Integer
.
parseInt
(
AndroidBuild
.
sdkVersion
)]
};
// Set the list to null so that exists() will check again
avdList
=
null
;
p
=
new
ProcessHelper
(
params
);
try
{
// Passes 'no' to "Do you wish to create a custom hardware profile [no]"
// System.out.println("CREATE AVD STARTING");
final
ProcessResult
createAvdResult
=
p
.
execute
(
"no"
);
// System.out.println("CREATE AVD HAS COMPLETED");
if
(
createAvdResult
.
succeeded
()) {
return
true
;
}
if
(
createAvdResult
.
toString
().
contains
(
"Target id is not valid"
)) {
// They didn't install the Google APIs
Base
.
showWarningTiered
(
"Android Error"
,
AVD_TARGET_PRIMARY
,
AVD_TARGET_SECONDARY
,
null
);
// throw new IOException("Missing required SDK components");
}
else
{
// Just generally not working
// Base.showWarning("Android Error", AVD_CREATE_ERROR, null);
Base
.
showWarningTiered
(
"Android Error"
,
AVD_CREATE_PRIMARY
,
AVD_CREATE_SECONDARY
,
null
);
System
.
out
.
println
(
createAvdResult
);
// throw new IOException("Error creating the AVD");
}
//System.err.println(createAvdResult);
}
catch
(
final
InterruptedException
ie
) { }
return
false
;
}
static
public
boolean
ensureProperAVD
(
final
AndroidSDK
sdk
) {
try
{
if
(
defaultAVD
.
exists
(
sdk
)) {
// System.out.println("the avd exists");
return
true
;
}
// if (badList.contains(defaultAVD)) {
if
(
defaultAVD
.
badness
()) {
// Base.showWarning("Android Error", AVD_CANNOT_LOAD, null);
Base
.
showWarningTiered
(
"Android Error"
,
AVD_LOAD_PRIMARY
,
AVD_LOAD_SECONDARY
,
null
);
return
false
;
}
if
(
defaultAVD
.
create
(
sdk
)) {
// System.out.println("the avd was created");
return
true
;
}
}
catch
(
final
Exception
e
) {
// Base.showWarning("Android Error", AVD_CREATE_ERROR, e);
Base
.
showWarningTiered
(
"Android Error"
,
AVD_CREATE_PRIMARY
,
String
.
format
(
AVD_CREATE_SECONDARY
,
AndroidBuild
.
sdkVersion
),
null
);
}
return
false
;
}
}
Back
|
FazBrowse Home
|
New Git URL