Home | History | Annotate | Download | only in thermal
      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 
     17 package com.intel.thermal;
     18 
     19 import android.util.Log;
     20 
     21 import java.util.ArrayList;
     22 import 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  */
     33 public 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 (int i = 0; i < mThermalSensors.size(); i++) {
     79                 if (mThermalSensors.get(i) != null &&
     80                         mThermalSensors.get(i).getSensorActiveStatus()) {
     81                     curTemp = mThermalSensors.get(i).getCurrTemp();
     82                     if (curTemp > maxCurTemp) {
     83                         maxCurTemp = curTemp;
     84                     }
     85                 }
     86             }
     87         }
     88 
     89         if (maxCurTemp != ThermalManager.INVALID_TEMP) {
     90             setZoneTemp(maxCurTemp);
     91             // it is assumed only one sensor will be provided for moving average
     92             if (getMovingAverageFlag() && !isUEventSupported()) {
     93                 // only for polling mode apply moving average on predicted zone temp
     94                 setZoneTemp(movingAverageTemp());
     95             }
     96             return true;
     97         }
     98 
     99         return false;
    100     }
    101 }
    102