From 1d474a1779067de79dccd77a3ba671769bfe2b3c Mon Sep 17 00:00:00 2001 From: Kristian Martinoski Date: Tue, 19 Nov 2024 15:15:04 +0100 Subject: [PATCH] add initial implementation for thermal info for android --- .../android/app/src/main/AndroidManifest.xml | 1 + .../rnvideosample/MainApplication.kt | 1 + .../getstream/rnvideosample/ThermalModule.kt | 38 ++++++++++ .../getstream/rnvideosample/ThermalPackage.kt | 13 ++++ .../src/components/LobbyViewComponent.tsx | 2 + .../dogfood/src/components/ThermalInfo.tsx | 73 +++++++++++++++++++ 6 files changed, 128 insertions(+) create mode 100644 sample-apps/react-native/dogfood/android/app/src/main/java/io/getstream/rnvideosample/ThermalModule.kt create mode 100644 sample-apps/react-native/dogfood/android/app/src/main/java/io/getstream/rnvideosample/ThermalPackage.kt create mode 100644 sample-apps/react-native/dogfood/src/components/ThermalInfo.tsx diff --git a/sample-apps/react-native/dogfood/android/app/src/main/AndroidManifest.xml b/sample-apps/react-native/dogfood/android/app/src/main/AndroidManifest.xml index 8b7d30e266..5b0da21916 100644 --- a/sample-apps/react-native/dogfood/android/app/src/main/AndroidManifest.xml +++ b/sample-apps/react-native/dogfood/android/app/src/main/AndroidManifest.xml @@ -11,6 +11,7 @@ + = 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) + } + } +} \ No newline at end of file diff --git a/sample-apps/react-native/dogfood/android/app/src/main/java/io/getstream/rnvideosample/ThermalPackage.kt b/sample-apps/react-native/dogfood/android/app/src/main/java/io/getstream/rnvideosample/ThermalPackage.kt new file mode 100644 index 0000000000..a797d16d4a --- /dev/null +++ b/sample-apps/react-native/dogfood/android/app/src/main/java/io/getstream/rnvideosample/ThermalPackage.kt @@ -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>() + + override fun createNativeModules(reactContext: ReactApplicationContext): List = + listOf(ThermalModule(reactContext)) +} \ No newline at end of file diff --git a/sample-apps/react-native/dogfood/src/components/LobbyViewComponent.tsx b/sample-apps/react-native/dogfood/src/components/LobbyViewComponent.tsx index e8370c6206..1d269bcce5 100644 --- a/sample-apps/react-native/dogfood/src/components/LobbyViewComponent.tsx +++ b/sample-apps/react-native/dogfood/src/components/LobbyViewComponent.tsx @@ -9,6 +9,7 @@ import { Pressable, StyleSheet, View, Text } from 'react-native'; import { MeetingStackParamList } from '../../types'; import { appTheme } from '../theme'; import { useOrientation } from '../hooks/useOrientation'; +import { ThermalInfo } from './ThermalInfo'; type LobbyViewComponentType = NativeStackScreenProps< MeetingStackParamList, @@ -30,6 +31,7 @@ export const LobbyViewComponent = ({ const JoinCallButtonComponent = useCallback(() => { return ( <> + {route.name === 'MeetingScreen' ? ( { + const [thermalStatus, setThermalStatus] = useState('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 ( + + Thermal Status + + {thermalStatus} + + + ); +}; + +const styles = StyleSheet.create({ + container: { + padding: 8, + borderRadius: 8, + marginVertical: 4, + }, + label: { + fontSize: 14, + fontWeight: '600', + marginBottom: 4, + }, + status: { + fontSize: 16, + fontWeight: 'bold', + }, +});