-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddonService.java
More file actions
105 lines (78 loc) · 2.44 KB
/
AddonService.java
File metadata and controls
105 lines (78 loc) · 2.44 KB
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
/**
* Copyright (C) 2020, ControlThings Oy Ab
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* @license Apache-2.0
*/
package addon;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.ResultReceiver;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
public abstract class AddonService extends Service {
private final String TAG = "AddonService";
static final int BRIDGE_CONNECTED = 32;
static final int BRIDGE_DISCONNECTED = 33;
WishBridgeJni wishBridgeJni;
List<ResultReceiver> addonReceiverList = new ArrayList<>();
boolean connectedStatus;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "in onStartCommand");
if (intent.hasExtra("receiver") && intent.getParcelableExtra("receiver") instanceof ResultReceiver) {
ResultReceiver addonReceiver = intent.getParcelableExtra("receiver");
addonReceiverList.add(addonReceiver);
if (connectedStatus) {
addonReceiver.send(BRIDGE_CONNECTED, null);
}
}
return Service.START_NOT_STICKY;
}
public abstract void startAddon();
public void connected(boolean status) {
for (ResultReceiver addonReceiver : addonReceiverList) {
if (addonReceiver != null) {
if (status) {
addonReceiver.send(BRIDGE_CONNECTED, null);
} else {
addonReceiver.send(BRIDGE_DISCONNECTED, null);
}
}
}
connectedStatus = status;
}
@Override
public void onCreate() {
super.onCreate();
startAddon();
wishBridgeJni = new WishBridgeJni(getBaseContext(), this);
}
@Override
public IBinder onBind(Intent intent) {
Log.d(TAG, "onBind");
return null;
}
@Override
public void onRebind(Intent intent) {
Log.d(TAG, "onRebind");
super.onRebind(intent);
}
@Override
public boolean onUnbind(Intent intent) {
Log.d(TAG, "onUnbind");
return true;
}
@Override
public void onDestroy() {
super.onDestroy();
wishBridgeJni.setConnected(false);
}
}