1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
| class DiagnosisFetchListener { private var mSystemVersion : String? = null
private fun getSystemVersion():String { if (mSystemVersion.isNullOrEmpty()) { mSystemVersion = SystemPropertiesUtils.get(BuildConfig.SYSTEM_VERSION_PROP, "xxxOS") } return mSystemVersion as String } fun sendDiagnosisFetchMinder(taskUid: String) { GetEthernetInfoRequestJson().getEthernetRequest(object : GetEthernetInfoRequestJson.AnalysisEthernetJson { @RequiresApi(Build.VERSION_CODES.O) override fun analysisEthernetFromJson(json: String) { if (json.isEmpty()){ Log.e( DeviceReport.TAG, ">>> analysisEthernetFromJson(): origin json string is empty, return") return } val ip: String = RemoteDetectSystemInfoUtil.getEthernetIPFromJson(json) val netOperator: String = RemoteDetectSystemInfoUtil.getEthernetOperatorFromJson(json)
if (ip.isEmpty() || netOperator.isEmpty()) { Log.d(DeviceReport.TAG, ">>> CIot-ext-Handler sendDiagnosisFetchMinder!! ip or netOperator is null!") } val version: String = getSystemVersion() val systemTime: Long = SystemTimeUtils.getCurrentSystemTimestamp() val lastStartTime: Long = SystemTimeUtils.getLastStartTimestamp() val runningTime: Long = SystemTimeUtils.getElapsedTimeMillis()
val lightSensorUtil = SensorUtil("lightSensor") var lightSensorData: String = "" if(! lightSensorUtil.startRegisterListener( ContextHelper.getApplicationContext(), Sensor.TYPE_LIGHT, object: SensorUtil.SensorResultCallback { override fun onDataCallBack(result: List<Float>) { lightSensorData = result[0].toString() + "lux" } override fun onGetDataTimeout() { lightSensorData = "超时异常" }
})) { lightSensorData = "获取传感器失败,可能是硬件异常" } val colorTemperatureSensorUtil = SensorUtil("colorTemperatureSensor") var colorTemperatureSensorData: String = "" if(! colorTemperatureSensorUtil.startRegisterListener( ContextHelper.getApplicationContext(), 36, object: SensorUtil.SensorResultCallback { override fun onDataCallBack(result: List<Float>) { colorTemperatureSensorData = result[0].toString() + "k" } override fun onGetDataTimeout() { colorTemperatureSensorData = "超时异常" }
})) { colorTemperatureSensorData = "获取传感器失败,可能是硬件异常" } val gravitySensorUtil = SensorUtil("gravitySensor") var gravitySensorData: String = "" if(! gravitySensorUtil.startRegisterListener( ContextHelper.getApplicationContext(), Sensor.TYPE_ACCELEROMETER, object : SensorUtil.SensorResultCallback { override fun onDataCallBack(result: List<Float>) { gravitySensorData = "x:" + result[0].toString() + " y:" + result[1].toString() + " z:" + result[2].toString() } override fun onGetDataTimeout() { gravitySensorData = "超时异常" } })) { gravitySensorData = "获取传感器失败,可能是硬件异常" } val microphoneState: String = DetectMicUtils().getMicState() val cpuInfo: Float = RemoteDetectSystemInfoUtil.getCpuTotalUsageFloat() val totalMemory: Float = SystemMemoryUtils(ContextHelper.getApplicationContext()).getSystemMemoryTotalFloat() val usageMemory: Float = SystemMemoryUtils(ContextHelper.getApplicationContext()).getCurrentSystemMemoryUsageFloat() val totalStorage: Float = SystemStorageUtils(ContextHelper.getApplicationContext()).getSystemTotalStorageFloat() val usageStorage: Float = SystemStorageUtils(ContextHelper.getApplicationContext()).getCurrentSystemStorageUsageFloat()
val wlan0ip: String = RemoteDetectSystemInfoUtil.getDeviceSpecifiedIPAddress("wlan0") val wlan0subnetmask: String = RemoteDetectSystemInfoUtil. getDeviceSpecifiedSubNetMaskFromConnectionManager(ContextHelper.getApplicationContext(),"wlan0") val wlan0mac: String = RemoteDetectSystemInfoUtil.getDeviceSpecifiedMacAddress("wlan0") val wlan0dns: List<String> = RemoteDetectSystemInfoUtil. getDeviceSpecifiedDnsFromConnectionManager(getApplicationContext(), ConnectivityManager.TYPE_WIFI)
val eth0ip: String = RemoteDetectSystemInfoUtil.getDeviceSpecifiedIPAddress("eth0") val eth0subnetmask: String = RemoteDetectSystemInfoUtil. getDeviceSpecifiedSubNetMaskFromConnectionManager(ContextHelper.getApplicationContext(), "eth0") val eth0mac: String = RemoteDetectSystemInfoUtil.getDeviceSpecifiedMacAddress("eth0") val eth0dns: List<String> = RemoteDetectSystemInfoUtil. getDeviceSpecifiedDnsFromConnectionManager(getApplicationContext(), ConnectivityManager.TYPE_ETHERNET)
var outerNetInfo: OuterNetInfo = OuterNetInfo(ip, netOperator)
var innerNetInfoWifi: InnerNetInfo = InnerNetInfo(wlan0ip,wlan0subnetmask, wlan0mac, wlan0dns)
var innerNetInfoEth: InnerNetInfo = InnerNetInfo(eth0ip,eth0subnetmask, eth0mac, eth0dns)
val diagnosisFetchInfo = DiagnosisFetchInfo( version, systemTime, lastStartTime, runningTime, lightSensorData, colorTemperatureSensorData, gravitySensorData, microphoneState, cpuInfo, totalMemory, usageMemory, totalStorage, usageStorage, outerNetInfo, innerNetInfoWifi, innerNetInfoEth ) val diagnosisReportInfo = DiagnosisReportInfo(taskUid, diagnosisFetchInfo, 2)
HttpHelper.getInstance().doPut(HttpConstants.updateDiagnosisPutUrl(), diagnosisReportInfo, object: Callback { override fun onFailure(call: Call, e: IOException) { Log.e(DeviceReport.TAG, "updateDiagnosisPutUrl:response onFailure") }
override fun onResponse(call: Call, response: Response) { val body = response.body!!.string() try { if (response.isSuccessful && isJsonAndGetCode(body) == 0) { Log.d(DeviceReport.TAG, "updateDiagnosisPutUrl:response $body") } else { Log.e(DeviceReport.TAG, "updateDiagnosisPutUrl failed ${response.code}") } } catch (e: Exception) { Log.e(DeviceReport.TAG, e.printStackTrace().toString()) } } }) } }) } private fun isJsonAndGetCode(str: String): Int { try { val jsonStr = JSONObject(str) if (jsonStr.has("code")) { Log.d(DeviceReport.TAG, "code = " + jsonStr.getInt("code")) return jsonStr.getInt("code") } } catch (e: Exception) { e.printStackTrace() } return -1 } }
|