@@ -202,70 +202,7 @@ private void updateCPUInfoView() {
202202 int avgClockSpeed = totalClockSpeed / clockSpeeds .length ;
203203 TextView tvCPUTitle = findViewById (R .id .TVCPUTitle );
204204 byte cpuUsagePercent = (byte ) (((float ) avgClockSpeed / maxClockSpeed ) * 100.0f );
205-
206- // 添加CPU温度显示(使用Java标准IO,不需要额外导入)
207- String cpuTemp = getCPUTemperature ();
208- tvCPUTitle .setText ("CPU (" + cpuUsagePercent + "%)" +
209- (cpuTemp != null ? ", " + cpuTemp : "" ));
210- }
211-
212- private String getCPUTemperature () {
213- java .io .File thermalDir = new java .io .File ("/sys/class/thermal/" );
214- java .io .File [] thermalZones = thermalDir .listFiles (
215- new java .io .FilenameFilter () {
216- @ Override
217- public boolean accept (java .io .File dir , String name ) {
218- return name .startsWith ("thermal_zone" );
219- }
220- }
221- );
222-
223- if (thermalZones != null ) {
224- for (java .io .File zone : thermalZones ) {
225- java .io .File tempFile = new java .io .File (zone , "temp" );
226- java .io .File typeFile = new java .io .File (zone , "type" );
227-
228- if (tempFile .canRead () && typeFile .canRead ()) {
229- try {
230- // 使用完全限定的java.io类名
231- String type = readFile (typeFile );
232- String tempStr = readFile (tempFile );
233-
234- if (type != null && tempStr != null ) {
235- tempStr = tempStr .trim ();
236- try {
237- int temp = Integer .parseInt (tempStr );
238- if (temp > 0 && (type .toLowerCase ().contains ("cpu" ) ||
239- type .toLowerCase ().contains ("thermal" ))) {
240- return (temp / 1000 ) + "°C" ;
241- }
242- } catch (NumberFormatException e ) {
243- continue ;
244- }
245- }
246- } catch (java .io .IOException e ) {
247- continue ;
248- }
249- }
250- }
251- }
252- return null ;
253- }
254-
255- private String readFile (java .io .File file ) throws java .io .IOException {
256- java .io .BufferedReader reader = null ;
257- try {
258- reader = new java .io .BufferedReader (new java .io .FileReader (file ));
259- return reader .readLine ();
260- } finally {
261- if (reader != null ) {
262- try {
263- reader .close ();
264- } catch (java .io .IOException e ) {
265- // 忽略关闭错误
266- }
267- }
268- }
205+ tvCPUTitle .setText ("CPU (" + cpuUsagePercent + "%)" );
269206 }
270207
271208 private void updateMemoryInfoView () {
0 commit comments