-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add initial implementation for thermal info for android
- Loading branch information
1 parent
9da68db
commit 1d474a1
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...eact-native/dogfood/android/app/src/main/java/io/getstream/rnvideosample/ThermalModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.getstream.rnvideosample | ||
|
||
import android.os.Build | ||
import android.os.PowerManager | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule | ||
import com.facebook.react.bridge.ReactMethod | ||
import com.facebook.react.bridge.Promise | ||
|
||
class ThermalModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { | ||
|
||
override fun getName(): String = "ThermalModule" | ||
|
||
@ReactMethod | ||
fun getCurrentThermalStatus(promise: Promise) { | ||
try { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | ||
val powerManager = reactContext.getSystemService(ReactApplicationContext.POWER_SERVICE) as PowerManager | ||
val status = powerManager.currentThermalStatus | ||
val thermalStatus = when (status) { | ||
PowerManager.THERMAL_STATUS_NONE -> "NONE" | ||
PowerManager.THERMAL_STATUS_LIGHT -> "LIGHT" | ||
PowerManager.THERMAL_STATUS_MODERATE -> "MODERATE" | ||
PowerManager.THERMAL_STATUS_SEVERE -> "SEVERE" | ||
PowerManager.THERMAL_STATUS_CRITICAL -> "CRITICAL" | ||
PowerManager.THERMAL_STATUS_EMERGENCY -> "EMERGENCY" | ||
PowerManager.THERMAL_STATUS_SHUTDOWN -> "SHUTDOWN" | ||
else -> "UNKNOWN" | ||
} | ||
promise.resolve(thermalStatus) | ||
} else { | ||
promise.resolve("NOT_SUPPORTED") | ||
} | ||
} catch (e: Exception) { | ||
promise.reject("THERMAL_ERROR", e.message) | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...act-native/dogfood/android/app/src/main/java/io/getstream/rnvideosample/ThermalPackage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.getstream.rnvideosample | ||
|
||
import com.facebook.react.ReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.uimanager.ViewManager | ||
|
||
class ThermalPackage : ReactPackage { | ||
override fun createViewManagers(reactContext: ReactApplicationContext) = emptyList<ViewManager<*, *>>() | ||
|
||
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> = | ||
listOf(ThermalModule(reactContext)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
sample-apps/react-native/dogfood/src/components/ThermalInfo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { View, Text, StyleSheet, Platform, NativeModules } from 'react-native'; | ||
import { useTheme } from '@stream-io/video-react-native-sdk'; | ||
|
||
const { ThermalModule } = NativeModules; | ||
|
||
export const ThermalInfo = () => { | ||
const [thermalStatus, setThermalStatus] = useState<string>('Unknown'); | ||
const { theme } = useTheme(); | ||
|
||
useEffect(() => { | ||
const checkThermalStatus = async () => { | ||
if (Platform.OS === 'android') { | ||
try { | ||
const status = await ThermalModule.getCurrentThermalStatus(); | ||
setThermalStatus(status); | ||
} catch (error) { | ||
console.error('Failed to get thermal status:', error); | ||
setThermalStatus('Error'); | ||
} | ||
} | ||
}; | ||
|
||
checkThermalStatus(); | ||
const interval = setInterval(checkThermalStatus, 5000); | ||
|
||
return () => clearInterval(interval); | ||
}, []); | ||
|
||
const getStatusColor = () => { | ||
switch (thermalStatus) { | ||
case 'NONE': | ||
case 'LIGHT': | ||
return '#4CAF50'; | ||
case 'MODERATE': | ||
return '#FFC107'; | ||
case 'SEVERE': | ||
case 'CRITICAL': | ||
return '#F44336'; | ||
case 'EMERGENCY': | ||
case 'SHUTDOWN': | ||
return '#D32F2F'; | ||
default: | ||
return theme.colors.textLowEmphasis; | ||
} | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text style={[styles.label, { color: 'white' }]}>Thermal Status</Text> | ||
<Text style={[styles.status, { color: getStatusColor() }]}> | ||
{thermalStatus} | ||
</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
padding: 8, | ||
borderRadius: 8, | ||
marginVertical: 4, | ||
}, | ||
label: { | ||
fontSize: 14, | ||
fontWeight: '600', | ||
marginBottom: 4, | ||
}, | ||
status: { | ||
fontSize: 16, | ||
fontWeight: 'bold', | ||
}, | ||
}); |