|
@@ -5,9 +5,14 @@ import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
+import android.net.wifi.WifiManager;
|
|
|
+import android.os.Handler;
|
|
|
import android.os.IBinder;
|
|
|
+import android.os.Message;
|
|
|
+import android.os.PowerManager;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
+import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
import com.jyc.threegames.App;
|
|
@@ -17,24 +22,47 @@ import com.jyc.threegames.controller.GameController;
|
|
|
import com.jyc.threegames.controller.LoginController;
|
|
|
import com.jyc.threegames.net.SimpleRequest;
|
|
|
|
|
|
+import java.util.Timer;
|
|
|
+import java.util.TimerTask;
|
|
|
+
|
|
|
public class GameService extends Service {
|
|
|
|
|
|
- private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
+// private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
+// @Override
|
|
|
+// public void onReceive(Context context, Intent intent) {
|
|
|
+// if (App.CAN_PLAY_GAME && LoginController.getInstance().getCurrentLoginInfo() != null && !LoginController.getInstance().isCurrentUserAdmin())
|
|
|
+// new SimpleRequest<ResGameInfo>().request(context, GameController.getInstance().needPlayGame(), new SimpleRequest.Executor<ResGameInfo>() {
|
|
|
+// @Override
|
|
|
+// public void execute(ResGameInfo obj) {
|
|
|
+// if (App.CAN_PLAY_GAME && obj != null && obj.needDoGame){
|
|
|
+// RingActivity.LAUNCH(App.app, obj);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
+// };
|
|
|
+
|
|
|
+ private Handler mHandler = new Handler(new Handler.Callback() {
|
|
|
@Override
|
|
|
- public void onReceive(Context context, Intent intent) {
|
|
|
- Toast.makeText(context, "接收到通知", Toast.LENGTH_LONG).show();
|
|
|
+ public boolean handleMessage(@NonNull Message message) {
|
|
|
if (App.CAN_PLAY_GAME && LoginController.getInstance().getCurrentLoginInfo() != null && !LoginController.getInstance().isCurrentUserAdmin())
|
|
|
- new SimpleRequest<ResGameInfo>().request(context, GameController.getInstance().needPlayGame(), new SimpleRequest.Executor<ResGameInfo>() {
|
|
|
+ new SimpleRequest<ResGameInfo>().request(App.app, GameController.getInstance().needPlayGame(), new SimpleRequest.Executor<ResGameInfo>() {
|
|
|
@Override
|
|
|
public void execute(ResGameInfo obj) {
|
|
|
- Toast.makeText(context, "已發送推送", Toast.LENGTH_LONG).show();
|
|
|
- if (App.CAN_PLAY_GAME && obj != null && obj.needDoGame){
|
|
|
+ if (App.CAN_PLAY_GAME && obj != null && obj.needDoGame) {
|
|
|
RingActivity.LAUNCH(App.app, obj);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
- };
|
|
|
+ });
|
|
|
+
|
|
|
+ PowerManager.WakeLock mWakeLock;
|
|
|
+ WifiManager.WifiLock mWifiLock;
|
|
|
+
|
|
|
+ private Timer mTimer;
|
|
|
|
|
|
@Nullable
|
|
|
@Override
|
|
@@ -45,14 +73,40 @@ public class GameService extends Service {
|
|
|
@Override
|
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
|
- IntentFilter intentFilter = new IntentFilter();
|
|
|
- intentFilter.addAction(Intent.ACTION_TIME_TICK);
|
|
|
- registerReceiver(mReceiver, intentFilter);
|
|
|
+// IntentFilter intentFilter = new IntentFilter();
|
|
|
+// intentFilter.addAction(Intent.ACTION_TIME_TICK);
|
|
|
+// registerReceiver(mReceiver, intentFilter);
|
|
|
+ PowerManager pm = (PowerManager) this.getSystemService(
|
|
|
+ Context.POWER_SERVICE);
|
|
|
+ mWakeLock = pm.newWakeLock(
|
|
|
+ PowerManager.PARTIAL_WAKE_LOCK
|
|
|
+ | PowerManager.ON_AFTER_RELEASE,
|
|
|
+ "three_game:weak_lock");
|
|
|
+ mWakeLock.acquire();
|
|
|
+
|
|
|
+ WifiManager wMgr = (WifiManager) this.getSystemService(WIFI_SERVICE);
|
|
|
+ mWifiLock = wMgr.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "three_game:wifi_lock");
|
|
|
+ mWifiLock.acquire();
|
|
|
+
|
|
|
+ mTimer = new Timer();
|
|
|
+ mTimer.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mHandler.sendEmptyMessage(0);
|
|
|
+ }
|
|
|
+ }, 0, 10 * 1000);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onDestroy() {
|
|
|
- unregisterReceiver(mReceiver);
|
|
|
+// unregisterReceiver(mReceiver);
|
|
|
+ if (mTimer != null)
|
|
|
+ mTimer.cancel();
|
|
|
+ if (mWakeLock != null)
|
|
|
+ mWakeLock.release();
|
|
|
+
|
|
|
+ if (mWifiLock != null)
|
|
|
+ mWifiLock.release();
|
|
|
super.onDestroy();
|
|
|
}
|
|
|
}
|