From b4f88faa261307c389066427f9ec110cccebfd25 Mon Sep 17 00:00:00 2001 From: Danesh M Date: Thu, 24 Sep 2015 11:14:17 -0700 Subject: [PATCH] CMSdk : Add thermal monitor service impl Change-Id: I54c4473a5fdd026958bc6bf170b2e8953aaa64af --- .../platform/internal/CMHardwareService.java | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java index 93ee73f..738784b 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/CMHardwareService.java @@ -18,6 +18,8 @@ package org.cyanogenmod.platform.internal; import android.content.Context; import android.content.pm.PackageManager; import android.os.IBinder; +import android.os.RemoteCallbackList; +import android.os.RemoteException; import android.util.Log; import com.android.server.SystemService; @@ -26,6 +28,8 @@ import cyanogenmod.app.CMContextConstants; import cyanogenmod.hardware.ICMHardwareService; import cyanogenmod.hardware.CMHardwareManager; import cyanogenmod.hardware.DisplayMode; +import cyanogenmod.hardware.IThermalListenerCallback; +import cyanogenmod.hardware.ThermalListenerCallback; import java.io.File; @@ -42,16 +46,20 @@ import org.cyanogenmod.hardware.PersistentStorage; import org.cyanogenmod.hardware.SerialNumber; import org.cyanogenmod.hardware.SunlightEnhancement; import org.cyanogenmod.hardware.TapToWake; +import org.cyanogenmod.hardware.ThermalMonitor; +import org.cyanogenmod.hardware.ThermalUpdateCallback; import org.cyanogenmod.hardware.TouchscreenHovering; import org.cyanogenmod.hardware.VibratorHW; -public class CMHardwareService extends SystemService { +public class CMHardwareService extends SystemService implements ThermalUpdateCallback { private static final boolean DEBUG = true; private static final String TAG = CMHardwareService.class.getSimpleName(); private final Context mContext; private final CMHardwareInterface mCmHwImpl; + private int mCurrentThermalState; + private RemoteCallbackList mRemoteCallbackList; private interface CMHardwareInterface { public int getSupportedFeatures(); @@ -120,6 +128,8 @@ public class CMHardwareService extends SystemService { mSupportedFeatures |= CMHardwareManager.FEATURE_DISPLAY_MODES; if (PersistentStorage.isSupported()) mSupportedFeatures |= CMHardwareManager.FEATURE_PERSISTENT_STORAGE; + if (ThermalMonitor.isSupported()) + mSupportedFeatures |= CMHardwareManager.FEATURE_THERMAL_MONITOR; } public int getSupportedFeatures() { @@ -144,6 +154,8 @@ public class CMHardwareService extends SystemService { return TouchscreenHovering.isEnabled(); case CMHardwareManager.FEATURE_AUTO_CONTRAST: return AutoContrast.isEnabled(); + case CMHardwareManager.FEATURE_THERMAL_MONITOR: + return ThermalMonitor.isEnabled(); default: Log.e(TAG, "feature " + feature + " is not a boolean feature"); return false; @@ -322,6 +334,26 @@ public class CMHardwareService extends SystemService { @Override public void onStart() { + if (ThermalMonitor.isSupported()) { + ThermalMonitor.initialize(this); + mRemoteCallbackList = new RemoteCallbackList(); + } + } + + @Override + public void setThermalState(int state) { + mCurrentThermalState = state; + int i = mRemoteCallbackList.beginBroadcast(); + while (i > 0) { + i--; + try { + mRemoteCallbackList.getBroadcastItem(i).onThermalChanged(state); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing + // the dead object for us. + } + } + mRemoteCallbackList.finishBroadcast(); } private final IBinder mService = new ICMHardwareService.Stub() { @@ -560,5 +592,35 @@ public class CMHardwareService extends SystemService { } return mCmHwImpl.readPersistentBytes(key); } + + @Override + public int getThermalState() { + mContext.enforceCallingOrSelfPermission( + cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null); + if (isSupported(CMHardwareManager.FEATURE_THERMAL_MONITOR)) { + return mCurrentThermalState; + } + return ThermalListenerCallback.State.STATE_UNKNOWN; + } + + @Override + public boolean registerThermalListener(IThermalListenerCallback callback) { + mContext.enforceCallingOrSelfPermission( + cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null); + if (isSupported(CMHardwareManager.FEATURE_THERMAL_MONITOR)) { + return mRemoteCallbackList.register(callback); + } + return false; + } + + @Override + public boolean unRegisterThermalListener(IThermalListenerCallback callback) { + mContext.enforceCallingOrSelfPermission( + cyanogenmod.platform.Manifest.permission.HARDWARE_ABSTRACTION_ACCESS, null); + if (isSupported(CMHardwareManager.FEATURE_THERMAL_MONITOR)) { + return mRemoteCallbackList.unregister(callback); + } + return false; + } }; }