HuaWeiSDK.java
8.6 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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
package com.sunvote.sdk;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.IBinder;
import android.os.RemoteException;
import com.sunvote.basebridge.IPadSystem;
import java.util.List;
public class HuaWeiSDK {
private Activity activity;
private IPadSystem iPadSystem;
private ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
iPadSystem = IPadSystem.Stub.asInterface(service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
iPadSystem = null;
}
};
private HuaWeiSDK(Activity activity) {
this.activity = activity;
}
private static HuaWeiSDK instance = null ;
public static HuaWeiSDK getInstance(Activity activity){
if(instance == null){
synchronized(HuaWeiSDK.class){
if(instance == null){
instance = new HuaWeiSDK(activity);
}
}
}
instance.activity = activity;
return instance;
}
/**
* 必须在同一个activity里面开启和关闭,如果在一个里面没有关闭,而在另外一个开启,会报错。
* 建议:在activity onCreate 里面调用open,在ondestroy 里面调用close
* 调用功能前 必须先open,不调用了 需要close
*/
public void open() {
bindService();
}
/**
* 必须在同一个activity里面开启和关闭,如果在一个里面没有关闭,而在另外一个开启,会报错。
* 建议:在activity onCreate 里面调用open,在ondestroy 里面调用close
* 调用功能前 必须先open,不调用了 需要close
*/
public void close(){
activity.unbindService(serviceConnection);
}
private void bindService() {
Intent intent = new Intent();
intent.setPackage("com.sunvote.basebridge");
intent.setAction("com.sunvote.basebridge.service.PadSystemService");
Intent tintent = getExplicitIntent(activity, intent);
if(tintent != null){
activity.bindService(getExplicitIntent(activity, intent), serviceConnection, Context.BIND_AUTO_CREATE);
}
}
public Intent getExplicitIntent(Context context, Intent implicitIntent) {
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfos = pm.queryIntentServices(implicitIntent, 0);
if (resolveInfos == null || resolveInfos.size() != 1) {
return null;
}
Intent explicitIntent = null;
ResolveInfo info = resolveInfos.get(0);
String packageName = info.serviceInfo.packageName;
String className = info.serviceInfo.name;
ComponentName component = new ComponentName(packageName, className);
explicitIntent = new Intent(implicitIntent);
explicitIntent.setComponent(component);
return explicitIntent;
}
/**
* 控制系统关机
*/
public boolean powerOffXPad() {
if (iPadSystem != null) {
try {
return iPadSystem.powerOffXPad();
} catch (RemoteException e) {
return false;
}
}
return false;
}
/**
* 控制系统重启
*
* @return true 成功
* false 失败
*/
public boolean rebootXPad() {
if (iPadSystem != null) {
try {
return iPadSystem.rebootXPad();
} catch (RemoteException e) {
return false;
}
}
return false;
}
/**
* 控制系统禁/启用通知栏
*
* @return true 成功
* false 失败
*/
public boolean setNavgation(boolean visible) {
if (iPadSystem != null) {
try {
return iPadSystem.setNavgation(visible);
} catch (RemoteException e) {
return false;
}
}
return false;
}
/**
* 是否激活
*
* @return true 成功
* false 失败
*/
public boolean isActiveMe() {
if (iPadSystem != null) {
try {
return iPadSystem.isActiveMe();
} catch (RemoteException e) {
return false;
}
}
return false;
}
public boolean setStatusBarExpandPanelDisabled(boolean disable) {
if (iPadSystem != null) {
try {
return iPadSystem.setStatusBarExpandPanelDisabled(disable);
} catch (RemoteException e) {
return false;
}
}
return false;
}
public boolean setNavigationBarDisabled(boolean disable) {
if (iPadSystem != null) {
try {
return iPadSystem.setNavigationBarDisabled(disable);
} catch (RemoteException e) {
return false;
}
}
return false;
}
/**
* 控制系统禁/启用Home键
*
* @return true 成功
* false 失败
*/
public boolean setHomeButtonDisabled(boolean disable) {
if (iPadSystem != null) {
try {
return iPadSystem.setHomeButtonDisabled(disable);
} catch (RemoteException e) {
return false;
}
}
return false;
}
/**
* 控制系统禁/启用BACK键
*
* @return true 成功
* false 失败
*/
public boolean setBackButtonDisabled(boolean disable) {
if (iPadSystem != null) {
try {
return iPadSystem.setBackButtonDisabled(disable);
} catch (RemoteException e) {
return false;
}
}
return false;
}
/**
* 控制系统禁/启用power off键
*
* @return true 成功
* false 失败
*/
public boolean setPowerDisabled(boolean disable) {
if (iPadSystem != null) {
try {
return iPadSystem.setPowerDisabled(disable);
} catch (RemoteException e) {
return false;
}
}
return false;
}
/**
* 控制系统禁/启用最近使用栏
*
* @return true 成功
* false 失败
*/
public boolean setTaskButtonDisabled(boolean disable) {
if (iPadSystem != null) {
try {
return iPadSystem.setTaskButtonDisabled(disable);
} catch (RemoteException e) {
return false;
}
}
return false;
}
public boolean installPackage(String packagePath) {
if (iPadSystem != null) {
try {
return iPadSystem.installPackage(packagePath);
} catch (RemoteException e) {
return false;
}
}
return false;
}
public boolean uninstallPackage(String packageName, boolean keepData) {
if (iPadSystem != null) {
try {
return iPadSystem.uninstallPackage(packageName, keepData);
} catch (RemoteException e) {
return false;
}
}
return false;
}
public boolean clearPackageData(String packageName) {
if (iPadSystem != null) {
try {
return iPadSystem.clearPackageData(packageName);
} catch (RemoteException e) {
return false;
}
}
return false;
}
/**
* 注册开机启动程序
* packageName 启动名称
* activi 是否激活
*
* @return 0 表示应用成功
* 1 下次生效
* 2 表示已成功
* -1 失败
*/
public int registerBootStarted(String packageName, String activity, boolean activi) {
if (iPadSystem != null) {
try {
return iPadSystem.registerBootStarted(packageName, activity, activi);
} catch (RemoteException e) {
return -1;
}
}
return -1;
}
/**
* 移除其他所有开机启动程序
*
* @return 0 成功
* <0 失败
* >=0 成功
*/
public int removeAllBootStarted() {
if (iPadSystem != null) {
try {
return iPadSystem.removeAllBootStarted();
} catch (RemoteException e) {
return -1;
}
}
return -1;
}
}