Showing
2 changed files
with
55 additions
and
11 deletions
| @@ -32,7 +32,7 @@ import static com.qnbar.smc.service.SocketService.USER_OPEN_DOOR; | @@ -32,7 +32,7 @@ import static com.qnbar.smc.service.SocketService.USER_OPEN_DOOR; | ||
| 32 | import static com.qnbar.smc.service.SocketService.USER_OPEN_DOOR_AND_GET_MOVIE; | 32 | import static com.qnbar.smc.service.SocketService.USER_OPEN_DOOR_AND_GET_MOVIE; |
| 33 | 33 | ||
| 34 | public class SocketService1 extends Service { | 34 | public class SocketService1 extends Service { |
| 35 | - private static final String TAG = "BackService"; | 35 | + private static final String TAG = "BackService1"; |
| 36 | private static final long HEART_BEAT_RATE = 2 * 1000; | 36 | private static final long HEART_BEAT_RATE = 2 * 1000; |
| 37 | 37 | ||
| 38 | // public static final int USER_OPEN_DOOR_AND_GET_MOVIE = 1703; | 38 | // public static final int USER_OPEN_DOOR_AND_GET_MOVIE = 1703; |
| @@ -61,7 +61,8 @@ public class SocketService1 extends Service { | @@ -61,7 +61,8 @@ public class SocketService1 extends Service { | ||
| 61 | private static final int CONNECTION_BEFORE_AUTHENTICATION = 10003;//还未注册连接就进行认证 | 61 | private static final int CONNECTION_BEFORE_AUTHENTICATION = 10003;//还未注册连接就进行认证 |
| 62 | private static final int NOT_SEND_ROOM_SN = 10004;//终端编号未传 | 62 | private static final int NOT_SEND_ROOM_SN = 10004;//终端编号未传 |
| 63 | private static final int HEART_BEAR_ERROR = 10005; //心跳异常,没有找到房间连接信息 | 63 | private static final int HEART_BEAR_ERROR = 10005; //心跳异常,没有找到房间连接信息 |
| 64 | - private static final int HEART_BEAR_ERROR_SYMBOL = 10006;//心跳异常,连接标识符不一致 | 64 | + private static final int HEART_BEAT_ERROR_SYMBOL = 10006;//心跳异常,连接标识符不一致 |
| 65 | + private static final int ROOM_SN_CONNECTED = 10010;//room_sn 已连接,不能再连接 | ||
| 65 | private static final int OPEN_DOOR = 50001;//开门命令 | 66 | private static final int OPEN_DOOR = 50001;//开门命令 |
| 66 | private static final int CLEAN_OVER = 50002;// | 67 | private static final int CLEAN_OVER = 50002;// |
| 67 | 68 | ||
| @@ -292,6 +293,23 @@ public class SocketService1 extends Service { | @@ -292,6 +293,23 @@ public class SocketService1 extends Service { | ||
| 292 | case HEART_BEAT_SUCCESS: | 293 | case HEART_BEAT_SUCCESS: |
| 293 | Log.d(TAG, "HEART_BEAT_SUCCESS"); | 294 | Log.d(TAG, "HEART_BEAT_SUCCESS"); |
| 294 | break; | 295 | break; |
| 296 | + case HEART_BEAT_ERROR_SYMBOL: | ||
| 297 | + case ROOM_SN_CONNECTED: | ||
| 298 | + String msg1 = socketResponse.getCode() == HEART_BEAT_ERROR_SYMBOL ? "HEART_BEAT_ERROR_SYMBOL" : "ROOM_SN_CONNECTED"; | ||
| 299 | + Log.d(TAG, msg1); | ||
| 300 | + mHandler.removeCallbacks(heartBeatRunnable); | ||
| 301 | + mReadThread.release(); | ||
| 302 | + sendRegister = false; | ||
| 303 | + releaseLastSocket(mSocket); | ||
| 304 | + Log.d(TAG, msg1 + " before:" + +System.currentTimeMillis()); | ||
| 305 | + try { | ||
| 306 | + Thread.sleep(10 * 1000); | ||
| 307 | + } catch (InterruptedException e) { | ||
| 308 | + e.printStackTrace(); | ||
| 309 | + } | ||
| 310 | + Log.d(TAG, msg1 + " after:" + System.currentTimeMillis()); | ||
| 311 | + new InitSocketThread().start(); | ||
| 312 | + break; | ||
| 295 | case RETURN_VERIFY_CODE: | 313 | case RETURN_VERIFY_CODE: |
| 296 | Log.d(TAG, "RETURN_VERIFY_CODE"); | 314 | Log.d(TAG, "RETURN_VERIFY_CODE"); |
| 297 | if (!TextUtils.isEmpty(socketResponse.getData().getVerify())) { | 315 | if (!TextUtils.isEmpty(socketResponse.getData().getVerify())) { |
| @@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
| 15 | 15 | ||
| 16 | package com.xgimi.gimicinema.activity; | 16 | package com.xgimi.gimicinema.activity; |
| 17 | 17 | ||
| 18 | +import android.app.ActivityManager; | ||
| 18 | import android.app.AlertDialog; | 19 | import android.app.AlertDialog; |
| 19 | import android.bluetooth.BluetoothAdapter; | 20 | import android.bluetooth.BluetoothAdapter; |
| 20 | import android.content.BroadcastReceiver; | 21 | import android.content.BroadcastReceiver; |
| @@ -45,7 +46,6 @@ import android.widget.ImageView; | @@ -45,7 +46,6 @@ import android.widget.ImageView; | ||
| 45 | import android.widget.RelativeLayout; | 46 | import android.widget.RelativeLayout; |
| 46 | import android.widget.ScrollView; | 47 | import android.widget.ScrollView; |
| 47 | import android.widget.Toast; | 48 | import android.widget.Toast; |
| 48 | - | ||
| 49 | import com.adroplat.fist_switch.jni.Device; | 49 | import com.adroplat.fist_switch.jni.Device; |
| 50 | import com.adroplat.fist_switch.jni.FistJni; | 50 | import com.adroplat.fist_switch.jni.FistJni; |
| 51 | import com.adroplat.fist_switch.jni.SubDevice; | 51 | import com.adroplat.fist_switch.jni.SubDevice; |
| @@ -73,6 +73,7 @@ import com.gimi.common.cinema.utils.OpenMMUtils; | @@ -73,6 +73,7 @@ import com.gimi.common.cinema.utils.OpenMMUtils; | ||
| 73 | import com.gimi.common.cinema.utils.ScreenUtils; | 73 | import com.gimi.common.cinema.utils.ScreenUtils; |
| 74 | import com.gimi.common.cinema.utils.SystemUtils; | 74 | import com.gimi.common.cinema.utils.SystemUtils; |
| 75 | import com.gimi.common.cinema.utils.Utils; | 75 | import com.gimi.common.cinema.utils.Utils; |
| 76 | +import com.gimi.common.cinema.utils.XgimiDevice; | ||
| 76 | import com.google.gson.Gson; | 77 | import com.google.gson.Gson; |
| 77 | import com.qnbar.smc.model.Light; | 78 | import com.qnbar.smc.model.Light; |
| 78 | import com.qnbar.smc.model.Lights; | 79 | import com.qnbar.smc.model.Lights; |
| @@ -109,7 +110,6 @@ import com.xgimi.gimicinema.view.MovieItem; | @@ -109,7 +110,6 @@ import com.xgimi.gimicinema.view.MovieItem; | ||
| 109 | import com.xgimi.gimicinema.view.OrderRecyclerView; | 110 | import com.xgimi.gimicinema.view.OrderRecyclerView; |
| 110 | import com.xgimi.smartscreen.SmartScreenBean; | 111 | import com.xgimi.smartscreen.SmartScreenBean; |
| 111 | import com.xgimi.smartscreen.service.ConfigService; | 112 | import com.xgimi.smartscreen.service.ConfigService; |
| 112 | - | ||
| 113 | import org.greenrobot.eventbus.EventBus; | 113 | import org.greenrobot.eventbus.EventBus; |
| 114 | import org.greenrobot.eventbus.Subscribe; | 114 | import org.greenrobot.eventbus.Subscribe; |
| 115 | import org.greenrobot.eventbus.ThreadMode; | 115 | import org.greenrobot.eventbus.ThreadMode; |
| @@ -240,13 +240,15 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen | @@ -240,13 +240,15 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen | ||
| 240 | 240 | ||
| 241 | presenter.load(this); | 241 | presenter.load(this); |
| 242 | 242 | ||
| 243 | -// if (!new SystemUtils().isServiceRunning(getApplicationContext(), "com.qnbar.smc.service.SocketService1")) { | ||
| 244 | - System.out.println("com.qnbar.smc.service.SocketService1 is not running then will start again"); | ||
| 245 | - Intent intent = new Intent(this, SocketService1.class); | ||
| 246 | - startService(intent); | ||
| 247 | -// } else { | ||
| 248 | -// System.out.println("com.qnbar.smc.service.SocketService1"); | ||
| 249 | -// } | 243 | +// if (!isServiceRunning(context, "com.qnbar.smc.service.SocketService1")) { |
| 244 | + //918清空内存后表现和928不同,获取不到此service是否运行,或者没有启动此service | ||
| 245 | + if (XgimiDevice.isZ4X() || XgimiDevice.isZ3S() || XgimiDevice.isZ4X() || !new SystemUtils().isServiceRunning(context, "com.qnbar.smc.service.SocketService1")) { | ||
| 246 | + Log.d("BackService", "SocketService1 is not running then will start again"); | ||
| 247 | + Intent intent = new Intent(this, SocketService1.class); | ||
| 248 | + startService(intent); | ||
| 249 | + } else { | ||
| 250 | + Log.d("BackService", "SocketService1 is running"); | ||
| 251 | + } | ||
| 250 | // initGetOrderInfo = true; | 252 | // initGetOrderInfo = true; |
| 251 | // presenter.getOrderInfo(); | 253 | // presenter.getOrderInfo(); |
| 252 | // new Handler().postDelayed(new Runnable() { | 254 | // new Handler().postDelayed(new Runnable() { |
| @@ -261,6 +263,30 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen | @@ -261,6 +263,30 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen | ||
| 261 | // PollingUtils.startPollingService(context, 60, CountService.class, CountService.STATUS_ACTION); | 263 | // PollingUtils.startPollingService(context, 60, CountService.class, CountService.STATUS_ACTION); |
| 262 | } | 264 | } |
| 263 | 265 | ||
| 266 | + /* | ||
| 267 | + * 判断服务是否启动,context上下文对象 ,className服务的name | ||
| 268 | + */ | ||
| 269 | + public static boolean isServiceRunning(Context mContext, String className) { | ||
| 270 | + | ||
| 271 | + boolean isRunning = false; | ||
| 272 | + ActivityManager activityManager = (ActivityManager) mContext | ||
| 273 | + .getSystemService(Context.ACTIVITY_SERVICE); | ||
| 274 | + List<ActivityManager.RunningServiceInfo> serviceList = activityManager | ||
| 275 | + .getRunningServices(Integer.MAX_VALUE); | ||
| 276 | + | ||
| 277 | + if (!(serviceList.size() > 0)) { | ||
| 278 | + return false; | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + for (int i = 0; i < serviceList.size(); i++) { | ||
| 282 | + if (serviceList.get(i).service.getClassName().equals(className)) { | ||
| 283 | + isRunning = true; | ||
| 284 | + break; | ||
| 285 | + } | ||
| 286 | + } | ||
| 287 | + return isRunning; | ||
| 288 | + } | ||
| 289 | + | ||
| 264 | private boolean initGetOrderInfo; | 290 | private boolean initGetOrderInfo; |
| 265 | 291 | ||
| 266 | public void getTimeByCalendar() { | 292 | public void getTimeByCalendar() { |
Please
register
or
login
to post a comment