|
|
@@ -8,9 +8,11 @@ import android.text.TextUtils;
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
|
|
|
|
import com.sheep.gamegroup.model.entity.AppRecord;
|
|
|
+import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
|
import com.sheep.gamegroup.util.MyDbManager;
|
|
|
+import com.sheep.jiuyan.samllsheep.BuildConfig;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
|
|
|
import java.util.List;
|
|
|
@@ -22,6 +24,10 @@ import java.util.List;
|
|
|
public class MonitorAppService extends AccessibilityService {
|
|
|
@Override
|
|
|
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
|
|
|
+ TaskEty taskEty = SheepApp.getInstance().getTaskEty();
|
|
|
+ if(taskEty == null) {//当前没有时长任务时不操作数据库
|
|
|
+ return;
|
|
|
+ }
|
|
|
// 此方法是在主线程中回调过来的,所以消息是阻塞执行的
|
|
|
// 获取包名
|
|
|
CharSequence packageName = accessibilityEvent.getPackageName();
|
|
|
@@ -30,7 +36,8 @@ public class MonitorAppService extends AccessibilityService {
|
|
|
List<CharSequence> textList = accessibilityEvent.getText();
|
|
|
switch (eventType) {
|
|
|
case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
|
|
|
- System.out.println("MonitorAppService TYPE_WINDOW_STATE_CHANGED: " + " pkgName: " + packageName + " className: " + className + " source: " + ListUtil.getIndex(textList, 0));
|
|
|
+ if(BuildConfig.DEBUG)
|
|
|
+ System.out.println("MonitorAppService TYPE_WINDOW_STATE_CHANGED: " + " pkgName: " + packageName + " className: " + className + " source: " + ListUtil.getIndex(textList, 0));
|
|
|
|
|
|
long curTime = System.currentTimeMillis();
|
|
|
AppRecord appRecord = new AppRecord();
|
|
|
@@ -44,7 +51,7 @@ public class MonitorAppService extends AccessibilityService {
|
|
|
long lastTime = SheepApp.getInstance().getLastTime();
|
|
|
if(lastAppRecord != null && lastTime != 0)
|
|
|
lastAppRecord.setTime(lastAppRecord.getTime() + curTime - lastTime);
|
|
|
- if(lastAppRecord != null)
|
|
|
+ if(lastAppRecord != null && TextUtils.equals(taskEty.getPackage_names(), packageName.toString()))
|
|
|
MyDbManager.getInstance().saveOrUpdate(lastAppRecord);
|
|
|
|
|
|
SheepApp.getInstance().setLastTime(curTime);
|