Skip to content

Commit

Permalink
latest release with refactoring on android side, need more changes fo…
Browse files Browse the repository at this point in the history
…r android and ios
  • Loading branch information
rvenky125 committed Apr 26, 2024
1 parent fd7357a commit f043d4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
2 changes: 1 addition & 1 deletion device-info/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.GradleKpmIosX64Variant

val libVersion = "0.0.14-alpha"
val libVersion = "0.0.15-alpha"
val artifactId = "kmp-device-info"
val groupId = "io.github.rvenky125"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,10 @@ actual class DeviceInfo {
return ipAddressSync
}


@get:Suppress("deprecation")
private val isCameraPresentSync: Boolean?
get() = try {
try {
cameraManager.cameraIdList.size > 0
cameraManager.cameraIdList.isNotEmpty()
} catch (e: Exception) {
false
}
Expand All @@ -235,11 +233,10 @@ actual class DeviceInfo {
null
}


actual fun isCameraPresent() = isCameraPresentSync

@get:SuppressLint("HardwareIds")
val macAddressSync: String
private val macAddressSync: String
@SuppressLint("HardwareIds")
get() {
val wifiInfo = wifiInfo
var macAddress = ""
Expand Down Expand Up @@ -352,18 +349,11 @@ actual class DeviceInfo {
actual fun getTotalDiskCapacityOld() = totalDiskCapacityOldSync


val freeDiskStorageOldSync: Double
private val freeDiskStorageOldSync: Double
get() = try {
val external = StatFs(Environment.getExternalStorageDirectory().absolutePath)
val availableBlocks: Long
val blockSize: Long
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
availableBlocks = external.availableBlocks.toLong()
blockSize = external.blockSize.toLong()
} else {
availableBlocks = external.availableBlocksLong
blockSize = external.blockSizeLong
}
val availableBlocks: Long = external.availableBlocksLong
val blockSize: Long = external.blockSizeLong
BigInteger.valueOf(availableBlocks).multiply(BigInteger.valueOf(blockSize))
.toDouble()
} catch (e: Exception) {
Expand Down Expand Up @@ -392,7 +382,7 @@ actual class DeviceInfo {
return isBatteryChargingSync
}

val usedMemorySync: Double
private val usedMemorySync: Double
get() {
return try {
val pid = Process.myPid()
Expand Down Expand Up @@ -498,7 +488,7 @@ actual class DeviceInfo {
return hasSystemFeatureSync(feature)
}

val systemAvailableFeaturesSync: List<String>
private val systemAvailableFeaturesSync: List<String>
get() {
val featureList: Array<FeatureInfo> =
context.packageManager.systemAvailableFeatures
Expand Down Expand Up @@ -652,16 +642,11 @@ actual class DeviceInfo {
get() {
try {
return if (Build.VERSION.SDK_INT >= 26) {
// There are a lot of conditions to access to getSerial api
// For details, see https://developer.android.com/reference/android/os/Build#getSerial()
// Rather than check each one, just try and rely on the catch below, for discussion on this approach, refer to
// https://github.com/react-native-device-info/react-native-device-info/issues/1320
Build.getSerial()
} else {
Build.SERIAL
}
} catch (e: Exception) {
// This is almost always a PermissionException. We will log it but return unknown
System.err.println("getSerialNumber failed, it probably should not be used: " + e.message)
}
return "unknown"
Expand All @@ -685,7 +670,7 @@ actual class DeviceInfo {
return buildIdSync
}

val apiLevelSync: Int
private val apiLevelSync: Int
get() = Build.VERSION.SDK_INT

actual fun getApiLevel(): Int {
Expand Down Expand Up @@ -854,12 +839,9 @@ actual class DeviceInfo {
@get:SuppressLint("HardwareIds", "MissingPermission")
val phoneNumberSync: String
get() {
if (context != null &&
(context.checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) === PackageManager.PERMISSION_GRANTED || Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkCallingOrSelfPermission(
if (context.checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED || Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkCallingOrSelfPermission(
Manifest.permission.READ_SMS
) === PackageManager.PERMISSION_GRANTED || Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && context.checkCallingOrSelfPermission(
Manifest.permission.READ_PHONE_NUMBERS
) === PackageManager.PERMISSION_GRANTED)
) == PackageManager.PERMISSION_GRANTED
) {
try {
return telephonyManager.line1Number
Expand Down Expand Up @@ -900,7 +882,7 @@ actual class DeviceInfo {
return supported32BitAbisSync
}

val supported64BitAbisSync: List<String>
private val supported64BitAbisSync: List<String>
get() {
val array = listOf<String>()
for (abi in Build.SUPPORTED_64_BIT_ABIS) {
Expand Down

0 comments on commit f043d4f

Please sign in to comment.