OLD | NEW |
1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. All Rights Reserved. |
2 | 2 |
3 package com.skia; | 3 package com.skia; |
4 | 4 |
5 import android.app.IntentService; | 5 import android.app.IntentService; |
6 import android.content.Intent; | 6 import android.content.Intent; |
7 import android.os.Bundle; | 7 import android.os.Bundle; |
8 import android.os.IBinder; | 8 import android.os.IBinder; |
9 import android.util.Log; | 9 import android.util.Log; |
10 | 10 |
11 /** | 11 /** |
12 * @author borenet@google.com (Eric Boren) | 12 * @author borenet@google.com (Eric Boren) |
13 * | 13 * |
14 */ | 14 */ |
15 public class SkiaIntentService extends IntentService { | 15 public class SkiaIntentService extends IntentService { |
16 public SkiaIntentService() { | 16 public SkiaIntentService() { |
17 super("SkiaIntentService"); | 17 super("SkiaIntentService"); |
18 } | 18 } |
19 | 19 |
20 @Override | 20 @Override |
21 public IBinder onBind(Intent arg0) { | 21 public IBinder onBind(Intent arg0) { |
22 return null; | 22 return null; |
23 } | 23 } |
24 @Override | 24 @Override |
25 public void onCreate() { | 25 public void onCreate() { |
26 super.onCreate(); | 26 super.onCreate(); |
27 } | 27 } |
28 | 28 |
29 @Override | 29 @Override |
30 public void onDestroy() { | 30 public void onDestroy() { |
31 super.onDestroy(); | 31 super.onDestroy(); |
32 } | 32 } |
33 | 33 |
34 @Override | 34 @Override |
35 public void onHandleIntent(Intent intent) { | 35 public void onHandleIntent(Intent intent) { |
36 | 36 |
37 // Extract command-line arguments | 37 // Extract command-line arguments |
38 Bundle bundle = intent.getExtras(); | 38 Bundle bundle = intent.getExtras(); |
39 | 39 |
40 // Number of times to repeat the SkiaReturnCode in the log. | 40 // Number of times to repeat the SkiaReturnCode in the log. |
41 int returnRepeats = bundle.getInt("returnRepeats", 1); | 41 int returnRepeats = bundle.getInt("returnRepeats", 1); |
42 | 42 |
43 // We require at least the program name to be specified. | 43 // We require at least the program name to be specified. |
44 if (!bundle.containsKey("args")) { | 44 if (!bundle.containsKey("args")) { |
45 Log.e("skia", | 45 Log.e("skia", |
46 "No command line arguments supplied. Unable to continue."); | 46 "No command line arguments supplied. Unable to continue."); |
47 SkiaReturn(-1, returnRepeats); | 47 SkiaReturn(-1, returnRepeats); |
48 return; | 48 return; |
49 } | 49 } |
50 | 50 |
51 String cmd = bundle.getString("args").trim(); | 51 String cmd = bundle.getString("args").trim(); |
52 String[] args = cmd.split("\\s+"); | 52 String[] args = cmd.split("\\s+"); |
53 Log.d("skia", "Executing Command: " + cmd); | 53 Log.d("skia", "Executing Command: " + cmd); |
54 | 54 |
55 // Load the requested library | 55 // Load the requested library |
56 String lib = args[0]; | 56 String lib = args[0]; |
57 try { | 57 try { |
| 58 System.loadLibrary("skia_android"); |
58 System.loadLibrary(lib); | 59 System.loadLibrary(lib); |
59 } catch (UnsatisfiedLinkError e) { | 60 } catch (UnsatisfiedLinkError e) { |
60 Log.e("skia", "Library " + lib + | 61 Log.e("skia", "Library " + lib + |
61 " could not be linked! Unable to continue."); | 62 " could not be linked! Unable to continue."); |
62 SkiaReturn(-1, returnRepeats); | 63 SkiaReturn(-1, returnRepeats); |
63 throw e; | 64 throw e; |
64 } | 65 } |
65 | 66 |
66 // JNI call to run the program | 67 // JNI call to run the program |
67 int retval = run(args); | 68 int retval = run(args); |
68 SkiaReturn(retval, returnRepeats); | 69 SkiaReturn(retval, returnRepeats); |
69 } | 70 } |
70 | 71 |
71 /** | 72 /** |
72 * Print out the exit code of the native program. Skia's buildbots watch the | 73 * Print out the exit code of the native program. Skia's buildbots watch the |
73 * logcat output for this line. The buildbots occasionally have to restart | 74 * logcat output for this line. The buildbots occasionally have to restart |
74 * a dead adb process, which causes them to miss some log output (Bug: | 75 * a dead adb process, which causes them to miss some log output (Bug: |
75 * https://code.google.com/p/skia/issues/detail?id=809). If this | 76 * https://code.google.com/p/skia/issues/detail?id=809). If this |
76 * "SKIA_RETURN_CODE" line is missed while adb is being restarted, then the | 77 * "SKIA_RETURN_CODE" line is missed while adb is being restarted, then the |
77 * test may never finish. Therefore, we print the line as many times as the | 78 * test may never finish. Therefore, we print the line as many times as the |
78 * caller specifies, waiting one second in between. | 79 * caller specifies, waiting one second in between. |
79 */ | 80 */ |
80 private void SkiaReturn(int code, int repeats) { | 81 private void SkiaReturn(int code, int repeats) { |
81 Log.d("skia", "SKIA_RETURN_CODE " + code); | 82 Log.d("skia", "SKIA_RETURN_CODE " + code); |
82 for (int i = 1; i < repeats; ++i) { | 83 for (int i = 1; i < repeats; ++i) { |
83 try { | 84 try { |
84 Thread.sleep(1000); | 85 Thread.sleep(1000); |
85 } catch (InterruptedException e) { | 86 } catch (InterruptedException e) { |
86 return; | 87 return; |
87 } | 88 } |
88 Log.d("skia", "SKIA_RETURN_CODE " + code); | 89 Log.d("skia", "SKIA_RETURN_CODE " + code); |
89 } | 90 } |
90 } | 91 } |
91 | 92 |
92 native int run(String[] args); | 93 native int run(String[] args); |
93 } | 94 } |
OLD | NEW |