|
|
@@ -6,25 +6,33 @@ import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.graphics.PixelFormat;
|
|
|
-import android.graphics.Point;
|
|
|
import android.os.Build;
|
|
|
import android.os.IBinder;
|
|
|
import android.provider.Settings;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
|
-import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
import android.view.WindowManager;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
+import com.sheep.gamegroup.util.LocationUtils;
|
|
|
+import com.sheep.gamegroup.util.MyDbManager;
|
|
|
+import com.sheep.jiuyan.samllsheep.BuildConfig;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.DeviceInfo;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.OpenService;
|
|
|
|
|
|
-
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import rx.Observable;
|
|
|
@@ -72,6 +80,7 @@ public class FloatService extends Service implements View.OnClickListener {
|
|
|
}
|
|
|
|
|
|
private Subscription subscription;
|
|
|
+ private int count = 0;
|
|
|
private void startTimer() {
|
|
|
if(subscription == null)
|
|
|
subscription = Observable.interval(1000, TimeUnit.MILLISECONDS)
|
|
|
@@ -80,8 +89,11 @@ public class FloatService extends Service implements View.OnClickListener {
|
|
|
.subscribe(new Action1<Long>() {
|
|
|
@Override
|
|
|
public void call(Long aLong) {
|
|
|
-
|
|
|
- Jump2View.getInstance().startAccessibility(getApplication());
|
|
|
+ try {
|
|
|
+ checkTask();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}, new Action1<Throwable>() {
|
|
|
@@ -92,6 +104,52 @@ public class FloatService extends Service implements View.OnClickListener {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void checkTask() {
|
|
|
+ TaskEty taskEty = SheepApp.getInstance().getTaskEty();
|
|
|
+ if(taskEty != null) {
|
|
|
+ if(Jump2View.getInstance().startAccessibility(getApplication())){
|
|
|
+ if(count > (BuildConfig.DEBUG ? 6 : 60)){//每过一分钟提交一次任务
|
|
|
+ count = 0;
|
|
|
+ if(TextUtils.isEmpty(taskEty.getPackage_names())){
|
|
|
+ if(BuildConfig.DEBUG)
|
|
|
+ G.showToast("没有包名,不能提交任务");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String gps = LocationUtils.getInstance().getLongitudeLatitude(getApplicationContext());
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("gps", gps);
|
|
|
+ long runTime = MyDbManager.getInstance().getAppRunTime(taskEty.getPackage_names());
|
|
|
+ MyDbManager.getInstance().removeAppRecord();
|
|
|
+ System.out.println("MonitorAppService runTime = "+runTime);
|
|
|
+ object.put("task_time", runTime/1000);
|
|
|
+ object.put("release_task_id", taskEty.getRelease_task_id());
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService().commitAutoTask(object)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(getApplicationContext()) {
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ if(BuildConfig.DEBUG)
|
|
|
+ System.out.println("MonitorAppService baseMessage onNext "+ JSON.toJSONString(baseMessage));
|
|
|
+ SheepApp.getInstance().setTaskEty(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ if(BuildConfig.DEBUG)
|
|
|
+ System.out.println("MonitorAppService baseMessage onError "+JSON.toJSONString(baseMessage));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ System.out.println("MonitorAppService count = "+count);
|
|
|
+ count++;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ count = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
private void createToucher() {
|
|
|
//赋值WindowManager&LayoutParam.
|