@@ -190,7 +190,7 @@ private void updateCPUInfoView() {
190190 short [] clockSpeeds = CPUStatus .getCurrentClockSpeeds ();
191191 int totalClockSpeed = 0 ;
192192 short maxClockSpeed = 0 ;
193-
193+
194194 for (int i = 0 ; i < clockSpeeds .length ; i ++) {
195195 TextView textView = new TextView (activity );
196196 textView .setTextSize (TypedValue .COMPLEX_UNIT_DIP , 14 );
@@ -200,48 +200,36 @@ private void updateCPUInfoView() {
200200 totalClockSpeed += clockSpeeds [i ];
201201 maxClockSpeed = (short ) Math .max (maxClockSpeed , clockSpeed );
202202 }
203-
203+
204204 int avgClockSpeed = totalClockSpeed / clockSpeeds .length ;
205205 TextView tvCPUTitle = findViewById (R .id .TVCPUTitle );
206206 byte cpuUsagePercent = (byte ) (((float ) avgClockSpeed / maxClockSpeed ) * 100.0f );
207-
208- // 仅使用Android API获取温度
207+
208+ // 直接尝试获取温度,失败就返回-1
209209 float cpuTemperature = getCPUTemperatureViaAndroidAPI ();
210210 String temperatureText = (cpuTemperature >= 0 ) ?
211211 String .format (" | %.1f°C" , cpuTemperature ) : "" ;
212212
213213 tvCPUTitle .setText ("CPU (" + cpuUsagePercent + "%)" + temperatureText );
214214 }
215-
215+
216216 /**
217- * 使用Android官方API获取CPU温度(需要API 24+)
217+ * 尝试获取CPU温度,失败返回-1
218218 */
219- @ RequiresApi (api = Build .VERSION_CODES .N )
220219 private float getCPUTemperatureViaAndroidAPI () {
221220 try {
222221 HardwarePropertiesManager hwManager =
223222 (HardwarePropertiesManager ) activity .getSystemService (Context .HARDWARE_PROPERTIES_SERVICE );
224- if (hwManager == null ) {
225- Log .w ("TaskManager" , "HardwarePropertiesManager not available" );
226- return -1 ;
227- }
228-
229- // 使用正确的常量名称(Android 7.0+)
230223 float [] temps = hwManager .getDeviceTemperatures (
231224 HardwarePropertiesManager .DEVICE_TEMPERATURE_CPU ,
232225 HardwarePropertiesManager .TEMPERATURE_CURRENT
233226 );
234-
235- if (temps != null && temps .length > 0 ) {
236- return temps [0 ];
237- }
227+ return (temps != null && temps .length > 0 ) ? temps [0 ] : -1 ;
238228 } catch (Exception e ) {
239- Log . e ( "TaskManager" , "Failed to get CPU temperature" , e );
229+ return - 1 ; // 静默失败,不显示温度
240230 }
241- return -1 ;
242231 }
243232
244-
245233 private void updateMemoryInfoView () {
246234 ActivityManager activityManager = (ActivityManager ) activity .getSystemService (Context .ACTIVITY_SERVICE );
247235 ActivityManager .MemoryInfo memoryInfo = new ActivityManager .MemoryInfo ();
0 commit comments