sm8350-common: parts: Checkout thermal profiles to xiaomi-sm8250 implementation

This commit is contained in:
EmanuelCN 2023-11-17 19:35:36 +02:00 committed by zaidkhan0997
parent 8d1447e38e
commit f407164d2e
Signed by: zaidkhan0997
GPG Key ID: 6C50557AD547C980
3 changed files with 44 additions and 22 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020-2022 The LineageOS Project * Copyright (C) 2020 The LineageOS Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,17 +17,29 @@
package org.lineageos.settings.thermal; package org.lineageos.settings.thermal;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem;
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity; import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
public class ThermalActivity extends CollapsingToolbarBaseActivity { public class ThermalActivity extends CollapsingToolbarBaseActivity {
private static final String TAG_THERMAL = "thermal"; private static final String TAG_THERMAL = "thermal";
private static final String THERMAL_SCONFIG = "/sys/class/thermal/thermal_message/sconfig";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(com.android.settingslib.collapsingtoolbar.R.id.content_frame, getFragmentManager().beginTransaction().replace(com.android.settingslib.collapsingtoolbar.R.id.content_frame,
new ThermalSettingsFragment(), TAG_THERMAL).commit(); new ThermalSettingsFragment(), TAG_THERMAL).commit();
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return false;
}
} }

View File

@ -18,8 +18,11 @@ package org.lineageos.settings.thermal;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityTaskManager; import android.app.ActivityTaskManager;
import android.app.ActivityTaskManager.RootTaskInfo;
import android.app.IActivityTaskManager;
import android.app.TaskStackListener; import android.app.TaskStackListener;
import android.app.Service; import android.app.Service;
import android.app.TaskStackListener;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
@ -37,6 +40,8 @@ public class ThermalService extends Service {
private String mPreviousApp; private String mPreviousApp;
private ThermalUtils mThermalUtils; private ThermalUtils mThermalUtils;
private IActivityTaskManager mActivityTaskManager;
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -49,7 +54,8 @@ public class ThermalService extends Service {
public void onCreate() { public void onCreate() {
if (DEBUG) Log.d(TAG, "Creating service"); if (DEBUG) Log.d(TAG, "Creating service");
try { try {
ActivityTaskManager.getService().registerTaskStackListener(mTaskListener); mActivityTaskManager = ActivityTaskManager.getService();
mActivityTaskManager.registerTaskStackListener(mTaskListener);
} catch (RemoteException e) { } catch (RemoteException e) {
// Do nothing // Do nothing
} }
@ -80,15 +86,15 @@ public class ThermalService extends Service {
@Override @Override
public void onTaskStackChanged() { public void onTaskStackChanged() {
try { try {
final ActivityTaskManager.RootTaskInfo focusedTask = final RootTaskInfo info = mActivityTaskManager.getFocusedRootTaskInfo();
ActivityTaskManager.getService().getFocusedRootTaskInfo(); if (info == null || info.topActivity == null) {
if (focusedTask != null && focusedTask.topActivity != null) { return;
ComponentName taskComponentName = focusedTask.topActivity; }
String foregroundApp = taskComponentName.getPackageName();
if (!foregroundApp.equals(mPreviousApp)) { String foregroundApp = info.topActivity.getPackageName();
mThermalUtils.setThermalProfile(foregroundApp); if (!foregroundApp.equals(mPreviousApp)) {
mPreviousApp = foregroundApp; mThermalUtils.setThermalProfile(foregroundApp);
} mPreviousApp = foregroundApp;
} }
} catch (Exception e) {} } catch (Exception e) {}
} }

View File

@ -1,12 +1,12 @@
/** /**
* Copyright (C) 2020 The LineageOS Project * Copyright (C) 2020 The LineageOS Project
* * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -83,7 +83,7 @@ public class ThermalSettingsFragment extends PreferenceFragment
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
return inflater.inflate(R.layout.thermal_layout, container, false); return inflater.inflate(R.layout.thermal_layout, container, false);
} }
@ -100,6 +100,7 @@ public class ThermalSettingsFragment extends PreferenceFragment
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
getActivity().setTitle(getResources().getString(R.string.thermal_title));
rebuild(); rebuild();
} }
@ -274,6 +275,7 @@ public class ThermalSettingsFragment extends PreferenceFragment
view.setText(items[position]); view.setText(items[position]);
view.setTextSize(14f); view.setTextSize(14f);
return view; return view;
} }
} }
@ -302,20 +304,22 @@ public class ThermalSettingsFragment extends PreferenceFragment
@NonNull @NonNull
@Override @Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()) ViewHolder holder = new ViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.thermal_list_item, parent, false)); .inflate(R.layout.thermal_list_item, parent, false));
Context context = holder.itemView.getContext();
holder.mode.setAdapter(new ModeAdapter(context));
holder.mode.setOnItemSelectedListener(this);
return holder;
} }
@Override @Override
public void onBindViewHolder(ViewHolder holder, int position) { public void onBindViewHolder(ViewHolder holder, int position) {
Context context = holder.itemView.getContext();
ApplicationsState.AppEntry entry = mEntries.get(position); ApplicationsState.AppEntry entry = mEntries.get(position);
if (entry == null) { if (entry == null) {
return; return;
} }
holder.mode.setAdapter(new ModeAdapter(context));
holder.mode.setOnItemSelectedListener(this);
holder.title.setText(entry.label); holder.title.setText(entry.label);
holder.title.setOnClickListener(v -> holder.mode.performClick()); holder.title.setOnClickListener(v -> holder.mode.performClick());
mApplicationsState.ensureIcon(entry); mApplicationsState.ensureIcon(entry);
@ -327,7 +331,7 @@ public class ThermalSettingsFragment extends PreferenceFragment
} }
private void setEntries(List<ApplicationsState.AppEntry> entries, private void setEntries(List<ApplicationsState.AppEntry> entries,
List<String> sections, List<Integer> positions) { List<String> sections, List<Integer> positions) {
mEntries = entries; mEntries = entries;
mSections = sections.toArray(new String[sections.size()]); mSections = sections.toArray(new String[sections.size()]);
mPositions = new int[positions.size()]; mPositions = new int[positions.size()];