sm8350-common: parts: Fix thermal profile screen state handling
This commit is contained in:
parent
9ac68341c5
commit
f1b552a3e8
1 changed files with 29 additions and 12 deletions
|
|
@ -37,7 +37,8 @@ public class ThermalService extends Service {
|
|||
private static final String TAG = "ThermalService";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private String mPreviousApp;
|
||||
private boolean mScreenOn = true;
|
||||
private String mCurrentApp = "";
|
||||
private ThermalUtils mThermalUtils;
|
||||
|
||||
private IActivityTaskManager mActivityTaskManager;
|
||||
|
|
@ -45,8 +46,16 @@ public class ThermalService extends Service {
|
|||
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mPreviousApp = "";
|
||||
mThermalUtils.setDefaultThermalProfile();
|
||||
switch (intent.getAction()) {
|
||||
case Intent.ACTION_SCREEN_OFF:
|
||||
mScreenOn = false;
|
||||
setThermalProfile();
|
||||
break;
|
||||
case Intent.ACTION_SCREEN_ON:
|
||||
mScreenOn = true;
|
||||
setThermalProfile();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -82,19 +91,27 @@ public class ThermalService extends Service {
|
|||
this.registerReceiver(mIntentReceiver, filter);
|
||||
}
|
||||
|
||||
private void setThermalProfile() {
|
||||
if (mScreenOn) {
|
||||
mThermalUtils.setThermalProfile(mCurrentApp);
|
||||
} else {
|
||||
mThermalUtils.setDefaultThermalProfile();
|
||||
}
|
||||
}
|
||||
|
||||
private final TaskStackListener mTaskListener = new TaskStackListener() {
|
||||
@Override
|
||||
public void onTaskStackChanged() {
|
||||
try {
|
||||
final RootTaskInfo info = mActivityTaskManager.getFocusedRootTaskInfo();
|
||||
if (info == null || info.topActivity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String foregroundApp = info.topActivity.getPackageName();
|
||||
if (!foregroundApp.equals(mPreviousApp)) {
|
||||
mThermalUtils.setThermalProfile(foregroundApp);
|
||||
mPreviousApp = foregroundApp;
|
||||
final ActivityTaskManager.RootTaskInfo focusedTask =
|
||||
ActivityTaskManager.getService().getFocusedRootTaskInfo();
|
||||
if (focusedTask != null && focusedTask.topActivity != null) {
|
||||
ComponentName taskComponentName = focusedTask.topActivity;
|
||||
String foregroundApp = taskComponentName.getPackageName();
|
||||
if (!foregroundApp.equals(mCurrentApp)) {
|
||||
mCurrentApp = foregroundApp;
|
||||
setThermalProfile();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue