|
@@ -7,8 +7,10 @@ import android.provider.Settings;
|
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
|
|
|
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.AppRecord;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
import com.sheep.gamegroup.util.ListUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.MyDbManager;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
@@ -17,6 +19,8 @@ import java.util.List;
|
|
|
* realicing@sina.com
|
|
* realicing@sina.com
|
|
|
*/
|
|
*/
|
|
|
public class MonitorAppService extends AccessibilityService {
|
|
public class MonitorAppService extends AccessibilityService {
|
|
|
|
|
+ private AppRecord lastAppRecord;
|
|
|
|
|
+ private long lastTime;
|
|
|
@Override
|
|
@Override
|
|
|
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
|
|
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
|
|
|
// 此方法是在主线程中回调过来的,所以消息是阻塞执行的
|
|
// 此方法是在主线程中回调过来的,所以消息是阻塞执行的
|
|
@@ -28,13 +32,28 @@ public class MonitorAppService extends AccessibilityService {
|
|
|
switch (eventType) {
|
|
switch (eventType) {
|
|
|
case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
|
|
case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
|
|
|
System.out.println("MonitorAppService TYPE_WINDOW_STATE_CHANGED: " + " pkgName: " + packageName + " className: " + className + " source: " + ListUtil.getIndex(textList, 0));
|
|
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();
|
|
|
|
|
+ appRecord.setType_id(eventType);
|
|
|
|
|
+ appRecord.setClassName(className.toString());
|
|
|
|
|
+ appRecord.setPackageName(packageName.toString());
|
|
|
|
|
+ if(!textList.isEmpty())
|
|
|
|
|
+ appRecord.setTag(textList.get(0).toString());
|
|
|
|
|
+ if(lastAppRecord != null && lastTime != 0)
|
|
|
|
|
+ lastAppRecord.setTime(lastAppRecord.getTime() + curTime - lastTime);
|
|
|
|
|
+ if(lastAppRecord != null)
|
|
|
|
|
+ MyDbManager.getInstance().saveOrUpdate(lastAppRecord);
|
|
|
|
|
+
|
|
|
|
|
+ lastTime = curTime;
|
|
|
|
|
+ lastAppRecord = appRecord;
|
|
|
break;
|
|
break;
|
|
|
// case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
|
|
// case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
|
|
|
// System.out.println("MonitorAppService TYPE_WINDOW_CONTENT_CHANGED: " + " packageName: " + packageName + " source: " + ListUtil.getIndex(textList, 0));
|
|
// System.out.println("MonitorAppService TYPE_WINDOW_CONTENT_CHANGED: " + " packageName: " + packageName + " source: " + ListUtil.getIndex(textList, 0));
|
|
|
// break;
|
|
// break;
|
|
|
- case AccessibilityEvent.TYPE_VIEW_CLICKED:
|
|
|
|
|
- System.out.println("MonitorAppService TYPE_VIEW_CLICKED: " + " pkgName: " + packageName + " className: " + className + " source: " + ListUtil.getIndex(textList, 0));
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+// case AccessibilityEvent.TYPE_VIEW_CLICKED:
|
|
|
|
|
+// System.out.println("MonitorAppService TYPE_VIEW_CLICKED: " + " pkgName: " + packageName + " className: " + className + " source: " + ListUtil.getIndex(textList, 0));
|
|
|
|
|
+// break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|