123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package com.jyc.threegames.service;
- import android.app.Service;
- 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;
- import com.jyc.threegames.activity.RingActivity;
- import com.jyc.threegames.bean.result.ResGameInfo;
- 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() {
- // @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 boolean handleMessage(@NonNull Message message) {
- if (App.CAN_PLAY_GAME && LoginController.getInstance().getCurrentLoginInfo() != null && !LoginController.getInstance().isCurrentUserAdmin())
- new SimpleRequest<ResGameInfo>().request(App.app, 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);
- }
- }
- });
- return true;
- }
- });
- PowerManager.WakeLock mWakeLock;
- WifiManager.WifiLock mWifiLock;
- private Timer mTimer;
- @Nullable
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
- @Override
- public void onCreate() {
- super.onCreate();
- // 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);
- if (mTimer != null)
- mTimer.cancel();
- if (mWakeLock != null)
- mWakeLock.release();
- if (mWifiLock != null)
- mWifiLock.release();
- super.onDestroy();
- }
- }
|