1/* 2 * Copyright 2014 Intel Corporation All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.intel.thermal; 18 19import android.util.Log; 20 21import java.util.ArrayList; 22import java.util.Arrays; 23 24/** 25 * The RawThermalZone class extends the ThermalZone class, with a default 26 * implementation of the isZoneStateChanged() method. This computes the 27 * zone state by first computing max of all sensor temperature (in polling mode) 28 * and comparing this temperature against zone thresholds. For uevent based 29 * monitoring only the temperature of first sensor is used to compute zone state. 30 * 31 * @hide 32 */ 33public class RawThermalZone extends ThermalZone { 34 35 private static final String TAG = "RawThermalZone"; 36 private ThermalZoneMonitor mTzm = null; 37 38 public RawThermalZone() { 39 super(); 40 // for raw zone emul temp flag is always false 41 mSupportsEmulTemp = false; 42 } 43 44 // irrespective of what flag is set in XML, emul temp flag is false for raw thermal zone 45 // over ride function. so that even if flag is 1 in XML, 0 will be written 46 public void setEmulTempFlag(int flag) { 47 mSupportsEmulTemp = false; 48 if (flag != 0) { 49 Log.i(TAG, "zone:" + getZoneName() 50 + " is a raw zone, doesnt support emulated temperature"); 51 } 52 } 53 54 public void startMonitoring() { 55 mTzm = new ThermalZoneMonitor(this); 56 } 57 58 public void stopMonitoring() { 59 if (mTzm != null) { 60 mTzm.stopMonitor(); 61 } 62 } 63 64 // override updateZoneTemp 65 public boolean updateZoneTemp() { 66 int curTemp = ThermalManager.INVALID_TEMP, maxCurTemp = ThermalManager.INVALID_TEMP; 67 if (isUEventSupported()) { 68 ArrayList<ThermalSensor> list = getThermalSensorList(); 69 if (list != null) { 70 // for uevent based monitoring only first sensor used 71 ThermalSensor s = list.get(0); 72 if (s != null) { 73 maxCurTemp = s.getCurrTemp(); 74 } 75 } 76 } else { 77 //zone temp is max of all sensor temp 78 for (ThermalSensor ts : getThermalSensorList()) { 79 if (ts != null && ts.getSensorActiveStatus()) { 80 curTemp = ts.getCurrTemp(); 81 if (curTemp > maxCurTemp) { 82 maxCurTemp = curTemp; 83 } 84 } 85 } 86 } 87 88 if (maxCurTemp != ThermalManager.INVALID_TEMP) { 89 setZoneTemp(maxCurTemp); 90 // it is assumed only one sensor will be provided for moving average 91 if (getMovingAverageFlag() && !isUEventSupported()) { 92 // only for polling mode apply moving average on predicted zone temp 93 setZoneTemp(movingAverageTemp()); 94 } 95 return true; 96 } 97 98 return false; 99 } 100} 101