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 /** 22 * The ThermalZoneMonitor class runs a thread for each zone 23 * with which it is instantiated. 24 * 25 * @hide 26 */ 27 public class ThermalZoneMonitor implements Runnable { 28 private static final String TAG = "ThermalZoneMonitor"; 29 private Thread t; 30 private ThermalZone zone; 31 private String mThreadName; 32 private boolean stop = false; 33 ThermalZoneMonitor(ThermalZone tz)34 public ThermalZoneMonitor(ThermalZone tz) { 35 zone = tz; 36 mThreadName = "ThermalZone" + zone.getZoneId(); 37 t = new Thread(this, mThreadName); 38 t.start(); 39 } 40 stopMonitor()41 public void stopMonitor() { 42 stop = true; 43 t.interrupt(); 44 } 45 run()46 public void run() { 47 try { 48 while (!stop && !t.isInterrupted()) { 49 if (zone.isZoneStateChanged()) { 50 zone.sendThermalEvent(); 51 } 52 // stop value can be changed before going to sleep 53 if (!stop) { 54 Thread.sleep(zone.getPollDelay(zone.getZoneState())); 55 } 56 } 57 } catch (InterruptedException iex) { 58 Log.i(TAG, "Stopping thread " + mThreadName + " [InterruptedException]"); 59 } 60 } 61 } 62