LocalService.java
2.63 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
package com.lotus.town.ali.service;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
import com.lotus.town.config.SupportAction;
import com.sdk.Sdk;
import com.secure.clean.ali.service.IMyAidlInterface;
public class LocalService extends Service {
private MyBinder mBinder;
private ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
}
@Override
public void onServiceDisconnected(ComponentName name) {
startService(new Intent(LocalService.this,RemoteService.class));
bindService(new Intent(LocalService.this,RemoteService.class),connection, Context.BIND_IMPORTANT);
}
};
public LocalService() {
}
@Override
public void onCreate() {
super.onCreate();
}
private boolean stop = false;
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if(stop) {
monitorScreenOn();
handler.sendEmptyMessageDelayed(0, 1000);
}
}
};
private void monitorScreenOn(){
if (((PowerManager) this.getSystemService(Context.POWER_SERVICE)).isScreenOn()) {
} else {
if(!Sdk.isInSplash) {
Intent i = new Intent();
i.setPackage(this.getPackageName());
i.setAction(SupportAction.SCREEN_OFF_MY);
this.sendBroadcast(i);
stop = true;
}
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
stop = false;
if(handler.hasMessages(0)) {
handler.removeMessages(0);
handler.sendEmptyMessageDelayed(0, 3000);
} else {
handler.sendEmptyMessageDelayed(0, 3000);
}
startService(new Intent(LocalService.this,RemoteService.class));
bindService(new Intent(this,RemoteService.class),connection, Context.BIND_IMPORTANT);
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
mBinder = new MyBinder();
return mBinder;
}
private class MyBinder extends IMyAidlInterface.Stub{
@Override
public String getServiceName() throws RemoteException {
return LocalService.class.getName();
}
}
}