Skip to content

Commit

Permalink
Remove attributes part 2 (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
dshokouhi committed Oct 13, 2020
1 parent 51072b9 commit 0a2edd0
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 81 deletions.
Expand Up @@ -102,13 +102,6 @@ class AudioSensorManager : SensorManager {
private fun updateAudioSensor(context: Context, audioManager: AudioManager) {
if (!isEnabled(context, audioSensor.id))
return
val audioMode = when (audioManager.mode) {
AudioManager.MODE_NORMAL -> "normal"
AudioManager.MODE_RINGTONE -> "ringing"
AudioManager.MODE_IN_CALL -> "in_call"
AudioManager.MODE_IN_COMMUNICATION -> "in_communication"
else -> "unknown"
}

val ringerMode = when (audioManager.ringerMode) {
AudioManager.RINGER_MODE_NORMAL -> "normal"
Expand All @@ -117,28 +110,6 @@ class AudioSensorManager : SensorManager {
else -> "unknown"
}

val isMicMuted = audioManager.isMicrophoneMute

val isMusicActive = audioManager.isMusicActive

val isSpeakerOn = audioManager.isSpeakerphoneOn
var isHeadphones = false
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val audioDevices = audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)
for (deviceInfo in audioDevices) {
if (deviceInfo.type == AudioDeviceInfo.TYPE_WIRED_HEADPHONES || deviceInfo.type == AudioDeviceInfo.TYPE_WIRED_HEADSET || deviceInfo.type == AudioDeviceInfo.TYPE_USB_HEADSET)
isHeadphones = true
}
} else {
// Use deprecated method as getDevices is API 23 and up only and we support API 21
isHeadphones = audioManager.isWiredHeadsetOn
}

val volumeLevelAlarm = audioManager.getStreamVolume(AudioManager.STREAM_ALARM)
val volumeLevelCall = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)
val volumeLevelMusic = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
val volumeLevelRing = audioManager.getStreamVolume(AudioManager.STREAM_RING)

val icon = when (audioManager.ringerMode) {
AudioManager.RINGER_MODE_NORMAL -> "mdi:volume-high"
AudioManager.RINGER_MODE_SILENT -> "mdi:volume-off"
Expand All @@ -150,17 +121,7 @@ class AudioSensorManager : SensorManager {
audioSensor,
ringerMode,
icon,
mapOf(
"audio_mode" to audioMode, // Remove after next release
"is_headphones" to isHeadphones, // Remove after next release
"is_mic_muted" to isMicMuted, // Remove after next release
"is_music_active" to isMusicActive, // Remove after next release
"is_speakerphone_on" to isSpeakerOn, // Remove after next release
"volume_level_alarm" to volumeLevelAlarm, // Remove after next release
"volume_level_call" to volumeLevelCall, // Remove after next release
"volume_level_music" to volumeLevelMusic, // Remove after next release
"volume_level_ring" to volumeLevelRing // Remove after next release
)
mapOf()
)
}

Expand Down
Expand Up @@ -128,10 +128,7 @@ class BatterySensorManager : SensorManager {
if (!isEnabled(context, batteryState.id))
return

val isCharging = getIsCharging(intent)
val chargerType = getChargerType(intent)
val chargingStatus = getChargingStatus(intent)
val batteryHealth = getBatteryHealth(intent)

val icon = when (chargingStatus) {
"charging" -> "mdi:battery-plus"
Expand All @@ -145,11 +142,7 @@ class BatterySensorManager : SensorManager {
batteryState,
chargingStatus,
icon,
mapOf(
"is_charging" to isCharging, // Remove after next release
"charger_type" to chargerType, // Remove after next release
"battery_health" to batteryHealth // Remove after next release
)
mapOf()
)
}

Expand Down
Expand Up @@ -98,7 +98,6 @@ class BluetoothSensorManager : SensorManager {
mapOf(
"connected_paired_devices" to connectedPairedDevices,
"connected_not_paired_devices" to connectedNotPairedDevices,
"is_bt_on" to isBtOn, // Remove after next release
"paired_devices" to bondedString
)
)
Expand Down
Expand Up @@ -127,39 +127,23 @@ class NetworkSensorManager : SensorManager {

var conInfo: WifiInfo? = null
var ssid = "Unknown"
var lastScanStrength = -1
var wifiEnabled = false

if (checkPermission(context, wifiConnection.id)) {
val wifiManager =
(context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager)
conInfo = wifiManager.connectionInfo

wifiEnabled = wifiManager.isWifiEnabled

ssid = if (conInfo.networkId == -1) {
"<not connected>"
} else {
conInfo.ssid.removePrefix("\"").removeSuffix("\"")
}

lastScanStrength = wifiManager.scanResults.firstOrNull {
it.BSSID == conInfo.bssid
}?.level ?: -1
}

val icon = if (ssid != "<not connected>") "mdi:wifi" else "mdi:wifi-off"

val attributes = conInfo?.let {
mapOf(
"bssid" to conInfo.bssid, // Remove after next release
"ip_address" to getIpAddress(conInfo.ipAddress), // Remove after next release
"link_speed" to conInfo.linkSpeed, // Remove after next release
"is_hidden" to conInfo.hiddenSSID,
"is_wifi_on" to wifiEnabled, // Remove after next release
"frequency" to conInfo.frequency, // Remove after next release
"signal_level" to lastScanStrength // Remove after next release
)
mapOf("is_hidden" to conInfo.hiddenSSID)
}.orEmpty()

onSensorUpdated(
Expand Down
Expand Up @@ -85,18 +85,6 @@ class StorageSensorManager : SensorManager {
val totalInternalStorage = getTotalInternalMemorySize()
val freeInternalStorage = getAvailableInternalMemorySize()
val percentageFreeInternalStorage = getPercentageInternal()
externalPath = externalMemoryAvailable(context)
var totalExternalStorage = "No SD Card"
var freeExternalStorage = "No SD Card"

if (externalPath != null) {
val statSD = StatFs(externalPath.toString())
blockSizeSD = statSD.blockSizeLong
availableBlocksSD = statSD.availableBlocksLong
totalBlocksSD = statSD.blockCountLong
totalExternalStorage = getTotalExternalMemorySize()
freeExternalStorage = getAvailableExternalMemorySize()
}

val icon = "mdi:harddisk"

Expand All @@ -106,9 +94,7 @@ class StorageSensorManager : SensorManager {
icon,
mapOf(
"Free internal storage" to freeInternalStorage,
"Total internal storage" to totalInternalStorage,
"Free external storage" to freeExternalStorage, // Remove after next release
"Total external storage" to totalExternalStorage // Remove after next release
"Total internal storage" to totalInternalStorage
)
)
}
Expand Down

0 comments on commit 0a2edd0

Please sign in to comment.