-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.kt
254 lines (230 loc) · 10.5 KB
/
App.kt
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
package com.devx.kdeviceinfo.sample
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.devx.kdeviceinfo.DeviceInfoXState
import com.devx.kdeviceinfo.OnPlatform
import com.devx.kdeviceinfo.model.android.AndroidInfo
import com.devx.kdeviceinfo.model.desktop.DesktopInfo
import com.devx.kdeviceinfo.model.ios.IosInfo
import com.devx.kdeviceinfo.model.web.WebInfo
import com.devx.kdeviceinfo.rememberDeviceInfoXState
import com.devx.kdeviceinfo.sample.theme.AppTheme
@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun App() = AppTheme {
val deviceInfoXState: DeviceInfoXState = rememberDeviceInfoXState()
Scaffold(topBar = {
TopAppBar(title = { Text(text = "KDeviceInfo Sample App") })
}) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues = it)
.padding(horizontal = 16.dp)
) {
OnPlatform(
deviceInfoXState = deviceInfoXState,
onAndroid = { androidInfo ->
ShowAndroidDeviceInfo(androidInfo = androidInfo)
},
onIos = { iosInfo ->
ShowIosDeviceInfo(iosInfo = iosInfo)
},
onDesktop = { desktopInfo ->
ShowDesktopDeviceInfo(desktopInfo = desktopInfo)
},
onWeb = { webInfo -> ShowWebDeviceInfo(webInfo = webInfo) }
)
}
}
}
@Composable
private fun ShowAndroidDeviceInfo(androidInfo: AndroidInfo) {
val verticalScrollState = rememberScrollState()
Column(modifier = Modifier.verticalScroll(state = verticalScrollState)) {
// App Info
Text(text = "App Info", style = TextStyle(fontSize = 20.sp))
Text(text = "App Name : ${androidInfo.appName}")
Text(text = "Version Code : ${androidInfo.versionCode}")
Text(text = "Version Name : ${androidInfo.versionName}")
Text(text = "Package Name : ${androidInfo.packageName}")
Text(text = "Debug App : ${androidInfo.isDebug}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
// Device Info
Text(text = "Device Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Device : ${androidInfo.device}")
Text(text = "Android ID : ${androidInfo.androidId}")
Text(text = "SdkInt : ${androidInfo.version.sdkInt}")
Text(text = "Release : ${androidInfo.version.release}")
Text(text = "CodeName : ${androidInfo.version.codeName}")
Text(text = "Board : ${androidInfo.board}")
Text(text = "IsPhysicalDevice : ${androidInfo.isPhysicalDevice}")
Text(text = "Manufacturer : ${androidInfo.manufacturer}")
Text(text = "Model : ${androidInfo.model}")
Text(text = "Device Orientation : ${androidInfo.deviceOrientation.getDeviceOrientation()}")
Text(text = "IsPortrait : ${androidInfo.deviceOrientation.isPortrait}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
// Locale
Text(text = "Locale Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Language Code : ${androidInfo.locale.languageCode}")
Text(text = "Region : ${androidInfo.locale.region}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
}
}
@Composable
private fun ShowIosDeviceInfo(iosInfo: IosInfo) {
val verticalScrollState = rememberScrollState()
Column(modifier = Modifier.verticalScroll(state = verticalScrollState)) {
// App Info
Text(text = "App Info", style = TextStyle(fontSize = 20.sp))
Text(text = "App Name : ${iosInfo.appName}")
Text(text = "App Version : ${iosInfo.appVersion}")
Text(text = "App Short Version : ${iosInfo.appShortVersion}")
Text(text = "Bundle Id : ${iosInfo.bundleId}")
Text(text = "Debug App : ${iosInfo.isDebug}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
// Device Info
Text(text = "Device Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Name : ${iosInfo.name}")
Text(text = "Model : ${iosInfo.model}")
Text(text = "SystemName : ${iosInfo.systemName}")
Text(text = "SystemVersion : ${iosInfo.systemVersion}")
Text(text = "LocalizedModel : ${iosInfo.localizedModel}")
Text(text = "IsPhysicalDevice : ${iosInfo.isPhysicalDevice}")
Text(text = "Device Orientation : ${iosInfo.deviceOrientation.getDeviceOrientation()}")
Text(text = "IsPortrait : ${iosInfo.deviceOrientation.isPortrait}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
// Locale Info
Text(text = "Locale Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Language Code : ${iosInfo.locale.languageCode}")
Text(text = "Region : ${iosInfo.locale.region}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
}
}
@Composable
private fun ShowDesktopDeviceInfo(desktopInfo: DesktopInfo) {
val verticalScrollState = rememberScrollState()
Row(
modifier = Modifier
.fillMaxSize()
.verticalScroll(state = verticalScrollState)
) {
Column (
modifier = Modifier
.weight(1f)
.fillMaxWidth()
) {
// Operating System Info (only easy to print info)
// NOT PRINTED BUT AVAILABLE
// - FileSystem
// - InternetProtocolStats
// - currentProcess: OSProcess
// - currentThread: OSThread
// - networkParams: NetworkParams
// - services: List<OSService>
// - sessions: List<OSSession>
val operatingSystem = desktopInfo.operatingSystem
Text(text = "Operating System Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Family : ${operatingSystem.family}")
Text(text = "Manufacturer : ${operatingSystem.manufacturer}")
val versionInfo = operatingSystem.versionInfo
Text(text = "Version : ${versionInfo.version}")
Text(text = "Codename : ${versionInfo.codeName}")
Text(text = "Build number : ${versionInfo.buildNumber}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
// General info
Text(text = "General Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Process id : ${operatingSystem.processId}")
Text(text = "Process count : ${operatingSystem.processCount}")
Text(text = "Thread id : ${operatingSystem.threadId}")
Text(text = "Thread count : ${operatingSystem.threadCount}")
Text(text = "Bitness : ${operatingSystem.bitness}")
Text(text = "System uptime : ${operatingSystem.systemUptime}")
Text(text = "System boot time : ${operatingSystem.systemBootTime}")
Text(text = "Is elevated : ${operatingSystem.isElevated}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
}
Column (
modifier = Modifier
.weight(1f)
.fillMaxWidth()
) {
// Hardware Info (few example)
// Info available
// - Computer system
// - Central processor
// - Global memory
// - Sensors
// - Power sources
// - Disk stores
// - Logical volume groups
// - Network IFs
// - Displays
// - Sensors
// - Sound cards
// - Graphics cards
val hardware = desktopInfo.hardware
Text(text = "Hardware Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Cpu temperature : ${hardware.sensors.cpuTemperature}")
Text(text = "Cpu max freq: ${hardware.centralProcessor.maxFreq} hz")
Text(text = "Graphics cards number: ${hardware.graphicsCards.size}")
hardware.graphicsCards.forEach { card ->
Text(text = "Graphics cards name: ${card.name}")
}
Text(text = "Ram size: ${hardware.globalMemory.total} bytes")
}
}
}
@Composable
private fun ShowWebDeviceInfo(
webInfo: WebInfo
) {
val verticalScrollState = rememberScrollState()
Column(modifier = Modifier.verticalScroll(state = verticalScrollState)) {
// Browser Info
val userAgent = webInfo.userAgent
Text(text = "User Agent Info", style = TextStyle(fontSize = 20.sp))
Text(text = "UA : $userAgent")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
// Browser Info
val browser = webInfo.browser
Text(text = "Browser Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Name : ${browser.name}")
Text(text = "Version : ${browser.version}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
// Device Info
val device = webInfo.device
Text(text = "Device Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Model : ${device.model}")
Text(text = "Type : ${device.type}")
Text(text = "Vendor : ${device.vendor}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
// Engine Info
val engine = webInfo.engine
Text(text = "Engine Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Name : ${engine.name}")
Text(text = "Version : ${engine.version}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
// Engine Info
val os = webInfo.os
Text(text = "Operating System Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Name : ${os.name}")
Text(text = "Version : ${os.version}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
// Engine Info
val cpu = webInfo.cpu
Text(text = "CPU Info", style = TextStyle(fontSize = 20.sp))
Text(text = "Architecture : ${cpu.architecture}")
Spacer(modifier = Modifier.fillMaxWidth().height(height = 20.dp))
}
}