sm8350-common: parts: Checkout thermal profiles to xiaomi-sm8250 implementation
This commit is contained in:
parent
8d1447e38e
commit
f407164d2e
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -17,11 +17,14 @@
|
||||
package org.lineageos.settings.thermal;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
|
||||
|
||||
public class ThermalActivity extends CollapsingToolbarBaseActivity {
|
||||
|
||||
private static final String TAG_THERMAL = "thermal";
|
||||
private static final String THERMAL_SCONFIG = "/sys/class/thermal/thermal_message/sconfig";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -30,4 +33,13 @@ public class ThermalActivity extends CollapsingToolbarBaseActivity {
|
||||
getFragmentManager().beginTransaction().replace(com.android.settingslib.collapsingtoolbar.R.id.content_frame,
|
||||
new ThermalSettingsFragment(), TAG_THERMAL).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,11 @@ package org.lineageos.settings.thermal;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityTaskManager;
|
||||
import android.app.ActivityTaskManager.RootTaskInfo;
|
||||
import android.app.IActivityTaskManager;
|
||||
import android.app.TaskStackListener;
|
||||
import android.app.Service;
|
||||
import android.app.TaskStackListener;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@ -37,6 +40,8 @@ public class ThermalService extends Service {
|
||||
private String mPreviousApp;
|
||||
private ThermalUtils mThermalUtils;
|
||||
|
||||
private IActivityTaskManager mActivityTaskManager;
|
||||
|
||||
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@ -49,7 +54,8 @@ public class ThermalService extends Service {
|
||||
public void onCreate() {
|
||||
if (DEBUG) Log.d(TAG, "Creating service");
|
||||
try {
|
||||
ActivityTaskManager.getService().registerTaskStackListener(mTaskListener);
|
||||
mActivityTaskManager = ActivityTaskManager.getService();
|
||||
mActivityTaskManager.registerTaskStackListener(mTaskListener);
|
||||
} catch (RemoteException e) {
|
||||
// Do nothing
|
||||
}
|
||||
@ -80,16 +86,16 @@ public class ThermalService extends Service {
|
||||
@Override
|
||||
public void onTaskStackChanged() {
|
||||
try {
|
||||
final ActivityTaskManager.RootTaskInfo focusedTask =
|
||||
ActivityTaskManager.getService().getFocusedRootTaskInfo();
|
||||
if (focusedTask != null && focusedTask.topActivity != null) {
|
||||
ComponentName taskComponentName = focusedTask.topActivity;
|
||||
String foregroundApp = taskComponentName.getPackageName();
|
||||
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;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
};
|
||||
|
@ -1,12 +1,12 @@
|
||||
/**
|
||||
* Copyright (C) 2020 The LineageOS Project
|
||||
*
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -100,6 +100,7 @@ public class ThermalSettingsFragment extends PreferenceFragment
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getActivity().setTitle(getResources().getString(R.string.thermal_title));
|
||||
rebuild();
|
||||
}
|
||||
|
||||
@ -274,6 +275,7 @@ public class ThermalSettingsFragment extends PreferenceFragment
|
||||
|
||||
view.setText(items[position]);
|
||||
view.setTextSize(14f);
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@ -302,20 +304,22 @@ public class ThermalSettingsFragment extends PreferenceFragment
|
||||
@NonNull
|
||||
@Override
|
||||
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));
|
||||
Context context = holder.itemView.getContext();
|
||||
holder.mode.setAdapter(new ModeAdapter(context));
|
||||
holder.mode.setOnItemSelectedListener(this);
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
Context context = holder.itemView.getContext();
|
||||
ApplicationsState.AppEntry entry = mEntries.get(position);
|
||||
|
||||
if (entry == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
holder.mode.setAdapter(new ModeAdapter(context));
|
||||
holder.mode.setOnItemSelectedListener(this);
|
||||
holder.title.setText(entry.label);
|
||||
holder.title.setOnClickListener(v -> holder.mode.performClick());
|
||||
mApplicationsState.ensureIcon(entry);
|
||||
|
Loading…
Reference in New Issue
Block a user