| | |
| | | |
| | | import android.app.Activity; |
| | | import android.app.ActivityManager; |
| | | import android.app.AlarmManager; |
| | | import android.app.Application; |
| | | import android.app.PendingIntent; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.res.Configuration; |
| | | import android.os.Build; |
| | | import android.os.Handler; |
| | | import android.os.LocaleList; |
| | | import android.os.Process; |
| | | import android.os.SystemClock; |
| | |
| | | import com.google.gson.Gson; |
| | | import com.hdl.hdlhttp.HxHttpConfig; |
| | | import com.hdl.linkpm.sdk.HDLLinkPMSdk; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.user.HDLLinkPMUser; |
| | | import com.hdl.linkpm.sdk.user.callback.IOnReloginListener; |
| | | import com.hdl.linkpm.sdk.utils.HDLSDKSPUtils; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.enums.LogoutType; |
| | | import com.hdl.photovoltaic.enums.LowerTagType; |
| | | import com.hdl.photovoltaic.enums.NetworkType; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlAccountLogic; |
| | | import com.hdl.photovoltaic.other.HdlDeviceLogic; |
| | | import com.hdl.photovoltaic.other.HdlFileLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | |
| | | @Override |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | | Log.d("=======", "11111111"); |
| | | |
| | | // // 获取当前进程的PID |
| | | // String processMessage= "进程ID:"+Process.myPid()+" 进程名:"+RuningAcitvityUtil.getAppName(getBaseContext()); |
| | | // String processMessage = "进程Uid:" + Process.myUid() + "进程ID:" + Process.myPid() + " 进程名:" + RuningAcitvityUtil.getAppName(getBaseContext()); |
| | | // Log.d("=======", processMessage); |
| | | // Log.d(TAG, processMessage); |
| | | // if (RuningAcitvityUtil.getAppName(getBaseContext()).contains(":")) { |
| | | // //非原生进程,用初始化后面的 |
| | |
| | | HDLLinkPMUser.getInstance().setOnReloginListener(new IOnReloginListener() { |
| | | @Override |
| | | public void onReLogin(int type) { |
| | | if (5 == type) { |
| | | //切换服务器地址用的 |
| | | UserConfigManage.getInstance().setOnlineServer(!UserConfigManage.getInstance().isOnlineServer()); |
| | | if (type == LogoutType.ServerSwitchingLogout.getValue()) { |
| | | new Handler().postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //切换服务器地址用的 |
| | | UserConfigManage.getInstance().setOnlineServer(!UserConfigManage.getInstance().isOnlineServer()); |
| | | UserConfigManage.getInstance().Save(); |
| | | restartApp(mHDLApp); |
| | | } |
| | | }, 500); |
| | | } else if (type == LogoutType.AbnormalLogout.getValue()) { |
| | | //异常情况-强制重启应用 |
| | | new Handler().postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | restartApp(mHDLApp); |
| | | } |
| | | }, 500); |
| | | } else { |
| | | HdlLogLogic.print("监听到登录退出---" + type, true); |
| | | //删除推送Token |
| | | // HdlResidenceLogic.getInstance().pushDel(null); |
| | | //type: 0:正常退出 1:极光推送强制退出 |
| | | //收到登录处理通知,关闭所有页面并打开登录页面 |
| | | AppManagerUtils.getAppManager().finishAllActivity(); |
| | | // HDLSDKSPUtils.clear();//底层自己清空 |
| | | |
| | | //清空住宅id |
| | | UserConfigManage.getInstance().setHomeId(""); |
| | | //重新登陆,默认同意隐私政策 |
| | | UserConfigManage.getInstance().setAcceiptPolicy(false); |
| | | //重新设定一个时间 |
| | | UserConfigManage.getInstance().setLoginDateTime(0); |
| | | UserConfigManage.getInstance().Save(); |
| | | restartApp(mHDLApp); |
| | | return; |
| | | } |
| | | |
| | | HdlLogLogic.print("监听到登录退出---" + type, true); |
| | | //type: 0:正常退出 1:极光推送强制退出 |
| | | //收到登录处理通知,关闭所有页面并打开登录页面 |
| | | AppManagerUtils.getAppManager().finishAllActivity(); |
| | | // HDLSDKSPUtils.clear();//底层自己清空 |
| | | |
| | | //清空住宅id |
| | | UserConfigManage.getInstance().setHomeId(""); |
| | | //重新登陆,默认同意隐私政策 |
| | | UserConfigManage.getInstance().setAcceiptPolicy(false); |
| | | //重新设定一个时间 |
| | | UserConfigManage.getInstance().setLoginDateTime(0); |
| | | UserConfigManage.getInstance().Save(); |
| | | |
| | | //清空消息缓存数据 |
| | | HdlMessageLogic.getInstance().clearListMessage(); |
| | | //清空电站缓存数据 |
| | | HdlResidenceLogic.getInstance().clearHouseList(); |
| | | //清空设备缓存数据 |
| | | HdlDeviceLogic.getInstance().clearDeviceList(); |
| | | //清空缓存数据 |
| | | if (mInfoMap != null) { |
| | | mInfoMap.clear(); |
| | | } |
| | | //断开mqtt连接 |
| | | if (MqttRecvClient.getInstance() != null) { |
| | | MqttRecvClient.getInstance().disConnect(); |
| | | } |
| | | //断开所有tcp连接且清空连接缓存 |
| | | // TODO: 10/10/23 |
| | | //清空消息缓存数据 |
| | | HdlMessageLogic.getInstance().clearListMessage(); |
| | | //清空电站缓存数据 |
| | | HdlResidenceLogic.getInstance().clearHouseList(); |
| | | //清空设备缓存数据 |
| | | HdlDeviceLogic.getInstance().clearDeviceList(); |
| | | //清空缓存数据 |
| | | if (mInfoMap != null) { |
| | | mInfoMap.clear(); |
| | | } |
| | | //断开mqtt连接 |
| | | if (MqttRecvClient.getInstance() != null) { |
| | | MqttRecvClient.getInstance().disConnect(); |
| | | } |
| | | //断开所有tcp连接且清空连接缓存 |
| | | // TODO: 10/10/23 |
| | | // TcpSocketBoot.stopAllConnectLinkGateway(); |
| | | if (null != HDLUniMPSDKManager.getInstance().getUniMP()) { |
| | | HDLUniMPSDKManager.getInstance().getUniMP().closeUniMP(); |
| | | if (null != HDLUniMPSDKManager.getInstance().getUniMP()) { |
| | | HDLUniMPSDKManager.getInstance().getUniMP().closeUniMP(); |
| | | } |
| | | SystemClock.sleep(200); |
| | | initDCUniMPSDK(); |
| | | Intent intent = new Intent(getInstance(), LoginActivity.class); |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| | | if (type == 1) { |
| | | intent.putExtra("isJpush", true); |
| | | } |
| | | startActivity(intent); |
| | | } |
| | | SystemClock.sleep(200); |
| | | initDCUniMPSDK(); |
| | | Intent intent = new Intent(getInstance(), LoginActivity.class); |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| | | if (type == 1) { |
| | | intent.putExtra("isJpush", true); |
| | | } |
| | | startActivity(intent); |
| | | |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | public void test(Context context) { |
| | | // new Handler().postDelayed(() -> { |
| | | // // 1. 设置延迟重启 |
| | | // Intent restartIntent = new Intent(context, StartActivity.class); |
| | | // restartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| | | // |
| | | // PendingIntent pendingIntent = PendingIntent.getActivity( |
| | | // context, 0, restartIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT |
| | | // ); |
| | | // |
| | | // AlarmManager am1 = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); |
| | | // am1.set(AlarmManager.RTC, System.currentTimeMillis() + 300, pendingIntent); |
| | | // |
| | | // int myUid = android.os.Process.myUid(); |
| | | // ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
| | | // String packageName = context.getPackageName(); |
| | | // |
| | | // for (ActivityManager.RunningAppProcessInfo proc : am.getRunningAppProcesses()) { |
| | | // if (proc.uid == myUid && proc.processName.startsWith(packageName)) { |
| | | // if (proc.pid != android.os.Process.myPid()) { |
| | | // try { |
| | | // android.os.Process.killProcess(proc.pid); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // // 3. 退出当前进程 |
| | | // android.os.Process.killProcess(android.os.Process.myPid()); |
| | | // }, 500); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 初始化UniMPSDK 小程序SDK |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 重启app |
| | | */ |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 关掉app所有进程 |
| | | * |
| | | * @param context 上下文 |
| | | */ |
| | | private void killAppProcess(Context context) { |
| | | // AppManagerUtils.getAppManager().finishAllActivity(); |
| | | try { |
| | |
| | | List<android.app.ActivityManager.RunningAppProcessInfo> processInfos = manager.getRunningAppProcesses(); |
| | | // 先杀掉相关进程,最后再杀掉主进程 |
| | | for (android.app.ActivityManager.RunningAppProcessInfo runningAppProcessInfo : processInfos) { |
| | | if (runningAppProcessInfo.pid != android.os.Process.myPid()) { |
| | | if ((runningAppProcessInfo.uid == android.os.Process.myUid()) && (runningAppProcessInfo.pid != android.os.Process.myPid())) { |
| | | try { |
| | | android.os.Process.killProcess(runningAppProcessInfo.pid); |
| | | } catch (Exception e) { |