Skip to content

Commit 71bfc7d

Browse files
committed
Upload file
1 parent dd21e9d commit 71bfc7d

1 file changed

Lines changed: 38 additions & 17 deletions

File tree

krscript/src/main/java/com/omarea/krscript/model/ShellHandlerBase.java

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@
66
import android.text.Spannable;
77
import android.text.SpannableString;
88
import android.text.style.ForegroundColorSpan;
9-
9+
import android.content.Context;
10+
import android.content.Intent;
11+
import android.content.ComponentName;
12+
import android.net.Uri;
13+
import android.os.Build;
1014
import java.util.regex.Pattern;
1115

1216
/**
1317
* Created by Hello on 2018/04/01.
1418
*/
1519

1620
public abstract class ShellHandlerBase extends Handler {
21+
22+
protected final Context context;
23+
24+
protected ShellHandlerBase(Context context) {
25+
this.context = context.getApplicationContext();
26+
}
27+
1728
/**
1829
* 处理启动信息
1930
*/
@@ -38,8 +49,6 @@ public abstract class ShellHandlerBase extends Handler {
3849
* 处理Exitvalue
3950
*/
4051
public static final int EVENT_EXIT = -2;
41-
42-
protected abstract void onAm(String type, String args);
4352

4453
protected abstract void onToast(String text);
4554

@@ -142,7 +151,6 @@ protected void onError(Object msg) {
142151
updateLog(msg, "#ff0000");
143152
}
144153

145-
@Override
146154
protected void onAm(String type, String args) {
147155
try {
148156
Intent intent = parseIntentArgs(args);
@@ -177,42 +185,55 @@ private Intent parseIntentArgs(String args) {
177185
for (int i = 0; i < tokens.length; i++) {
178186
switch (tokens[i]) {
179187

180-
case "-a":
188+
case "-a": // action
189+
if (i + 1 >= tokens.length) break;
181190
intent.setAction(tokens[++i]);
182191
break;
183192

184-
case "-d":
193+
case "-d": // data
194+
if (i + 1 >= tokens.length) break;
185195
intent.setData(Uri.parse(tokens[++i]));
186196
break;
187197

188-
case "-n": {
189-
String[] cn = tokens[++i].split("/");
190-
intent.setComponent(new ComponentName(cn[0], cn[1]));
198+
case "-n": { // component
199+
if (i + 1 >= tokens.length) break;
200+
String[] cn = tokens[++i].split("/", 2);
201+
if (cn.length == 2) {
202+
intent.setComponent(new ComponentName(cn[0], cn[1]));
203+
}
191204
break;
192205
}
193206

194-
case "--es": {
207+
case "--es": { // string extra
208+
if (i + 2 >= tokens.length) break;
195209
String key = tokens[++i];
196210
String val = tokens[++i];
197211
intent.putExtra(key, val);
198212
break;
199213
}
200214

201-
case "--ei": {
215+
case "--ei": { // int extra
216+
if (i + 2 >= tokens.length) break;
202217
String key = tokens[++i];
203-
int val = Integer.parseInt(tokens[++i]);
204-
intent.putExtra(key, val);
218+
try {
219+
int val = Integer.parseInt(tokens[++i]);
220+
intent.putExtra(key, val);
221+
} catch (NumberFormatException ignored) {}
205222
break;
206223
}
207224

208-
case "--el": {
225+
case "--el": { // long extra
226+
if (i + 2 >= tokens.length) break;
209227
String key = tokens[++i];
210-
long val = Long.parseLong(tokens[++i]);
211-
intent.putExtra(key, val);
228+
try {
229+
long val = Long.parseLong(tokens[++i]);
230+
intent.putExtra(key, val);
231+
} catch (NumberFormatException ignored) {}
212232
break;
213233
}
214234

215-
case "--ez": {
235+
case "--ez": { // boolean extra
236+
if (i + 2 >= tokens.length) break;
216237
String key = tokens[++i];
217238
boolean val = Boolean.parseBoolean(tokens[++i]);
218239
intent.putExtra(key, val);

0 commit comments

Comments
 (0)