|
42 | 42 | public class BinService extends Service implements StreamListener.Listener { |
43 | 43 | public static final int START = 0; |
44 | 44 | public static final int STOP = 1; |
| 45 | + public static final int STATUS = 2; |
45 | 46 | public static final int NOTIFICATION_ID = 1; |
46 | 47 | public static final String ACTION_START_SERVICE = "com.gianlu.aria2android.START_SERVICE"; |
47 | 48 | public static final String ACTION_STOP_SERVICE = "com.gianlu.aria2android.STOP_SERVICE"; |
@@ -69,6 +70,12 @@ public IBinder onBind(Intent intent) { |
69 | 70 | return messenger.getBinder(); |
70 | 71 | } |
71 | 72 |
|
| 73 | + private void dispatchStatus() { |
| 74 | + Intent intent = new Intent(Action.SERVER_STATUS.toString()); |
| 75 | + intent.putExtra("on", process != null); |
| 76 | + broadcastManager.sendBroadcast(intent); |
| 77 | + } |
| 78 | + |
72 | 79 | @TargetApi(Build.VERSION_CODES.O) |
73 | 80 | private void createChannel() { |
74 | 81 | NotificationChannel chan = new NotificationChannel(CHANNEL_ID, SERVICE_NAME, NotificationManager.IMPORTANCE_DEFAULT); |
@@ -118,7 +125,7 @@ private void startBin(@NonNull StartConfig config) { |
118 | 125 | dispatchBroadcast(Action.SERVER_START, null, null); |
119 | 126 | } |
120 | 127 |
|
121 | | - private void ex(Exception ex) { |
| 128 | + private void ex(@NonNull Exception ex) { |
122 | 129 | Logging.log(ex); |
123 | 130 | dispatchBroadcast(Action.SERVER_EX, null, ex); |
124 | 131 | } |
@@ -200,6 +207,7 @@ public void unknownLogLine(@NonNull String line) { |
200 | 207 | } |
201 | 208 |
|
202 | 209 | public enum Action { |
| 210 | + SERVER_STATUS, |
203 | 211 | SERVER_START, |
204 | 212 | SERVER_MSG, |
205 | 213 | SERVER_EX, |
@@ -236,6 +244,9 @@ public void handleMessage(Message msg) { |
236 | 244 | case STOP: |
237 | 245 | stopBin(); |
238 | 246 | break; |
| 247 | + case STATUS: |
| 248 | + dispatchStatus(); |
| 249 | + break; |
239 | 250 | default: |
240 | 251 | super.handleMessage(msg); |
241 | 252 | } |
|
0 commit comments