diff --git a/parts/AndroidManifest.xml b/parts/AndroidManifest.xml
index af3d7e9..1a075fa 100644
--- a/parts/AndroidManifest.xml
+++ b/parts/AndroidManifest.xml
@@ -85,43 +85,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/parts/res/drawable/ic_refresh_120.xml b/parts/res/drawable/ic_refresh_120.xml
deleted file mode 100644
index 623c150..0000000
--- a/parts/res/drawable/ic_refresh_120.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
diff --git a/parts/res/drawable/ic_refresh_60.xml b/parts/res/drawable/ic_refresh_60.xml
deleted file mode 100644
index 79afbc9..0000000
--- a/parts/res/drawable/ic_refresh_60.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
diff --git a/parts/res/drawable/ic_refresh_default.xml b/parts/res/drawable/ic_refresh_default.xml
deleted file mode 100644
index a05a37c..0000000
--- a/parts/res/drawable/ic_refresh_default.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
diff --git a/parts/res/layout/refresh_layout.xml b/parts/res/layout/refresh_layout.xml
deleted file mode 100644
index 6b2ebd7..0000000
--- a/parts/res/layout/refresh_layout.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
diff --git a/parts/res/layout/refresh_list_item.xml b/parts/res/layout/refresh_list_item.xml
deleted file mode 100644
index e2ce15f..0000000
--- a/parts/res/layout/refresh_list_item.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/parts/res/values/strings.xml b/parts/res/values/strings.xml
index 72ce713..e5fd574 100644
--- a/parts/res/values/strings.xml
+++ b/parts/res/values/strings.xml
@@ -25,14 +25,6 @@
On
Off
-
- Per-app refresh rate
- Refresh rate
- Set the maximum refresh rate for a specific application
- Default
- 60Hz
- 120Hz
-
GameBar
Enable the system overlay (FPS, Temp, etc.)
diff --git a/parts/src/org/lineageos/settings/BootCompletedReceiver.java b/parts/src/org/lineageos/settings/BootCompletedReceiver.java
index fa0f828..1bf14d6 100644
--- a/parts/src/org/lineageos/settings/BootCompletedReceiver.java
+++ b/parts/src/org/lineageos/settings/BootCompletedReceiver.java
@@ -31,7 +31,6 @@ import android.provider.Settings;
import android.util.Log;
import android.view.Display;
-import org.lineageos.settings.refreshrate.RefreshUtils;
import org.lineageos.settings.thermal.ThermalTileService;
public class BootCompletedReceiver extends BroadcastReceiver {
@@ -69,8 +68,5 @@ public class BootCompletedReceiver extends BroadcastReceiver {
private void startServices(Context context) {
if (DEBUG) Log.i(TAG, "Starting services...");
-
- // Start Refresh Rate Service
- RefreshUtils.startService(context);
}
}
diff --git a/parts/src/org/lineageos/settings/TileHandlerActivity.java b/parts/src/org/lineageos/settings/TileHandlerActivity.java
index e2dc0e4..d8aacbd 100644
--- a/parts/src/org/lineageos/settings/TileHandlerActivity.java
+++ b/parts/src/org/lineageos/settings/TileHandlerActivity.java
@@ -28,8 +28,6 @@ import android.util.Log;
import java.util.HashMap;
import java.util.Map;
-import org.lineageos.settings.refreshrate.RefreshActivity;
-import org.lineageos.settings.refreshrate.RefreshTileService;
import org.lineageos.settings.gamebar.GameBarSettingsActivity;
import org.lineageos.settings.gamebar.GameBarTileService;
import org.lineageos.settings.charge.ChargeActivity;
@@ -43,7 +41,6 @@ public final class TileHandlerActivity extends Activity {
private static final Map> TILE_ACTIVITY_MAP = new HashMap<>();
static {
- TILE_ACTIVITY_MAP.put(RefreshTileService.class.getName(), RefreshActivity.class);
TILE_ACTIVITY_MAP.put(GameBarTileService.class.getName(), GameBarSettingsActivity.class);
TILE_ACTIVITY_MAP.put(ChargeQSTile.class.getName(), ChargeActivity.class);
TILE_ACTIVITY_MAP.put(ChargingInfoTileService.class.getName(), ChargeActivity.class);
diff --git a/parts/src/org/lineageos/settings/refreshrate/RefreshActivity.java b/parts/src/org/lineageos/settings/refreshrate/RefreshActivity.java
deleted file mode 100644
index 02a10c2..0000000
--- a/parts/src/org/lineageos/settings/refreshrate/RefreshActivity.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2020-2022 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lineageos.settings.refreshrate;
-
-import android.os.Bundle;
-
-import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
-
-public class RefreshActivity extends CollapsingToolbarBaseActivity {
- private static final String TAG_REFRESH = "refresh";
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- getFragmentManager().beginTransaction().replace(com.android.settingslib.collapsingtoolbar.R.id.content_frame,
- new RefreshSettingsFragment(), TAG_REFRESH).commit();
- }
-}
diff --git a/parts/src/org/lineageos/settings/refreshrate/RefreshService.java b/parts/src/org/lineageos/settings/refreshrate/RefreshService.java
deleted file mode 100644
index ea46cd4..0000000
--- a/parts/src/org/lineageos/settings/refreshrate/RefreshService.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lineageos.settings.refreshrate;
-
-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.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Handler;
-import android.os.IBinder;
-import android.util.Log;
-import android.os.RemoteException;
-
-public class RefreshService extends Service {
-
- private static final String TAG = "RefreshService";
- private static final boolean DEBUG = true;
-
- private String mPreviousApp;
- private RefreshUtils mRefreshUtils;
- private IActivityTaskManager mActivityTaskManager;
-
- private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- mPreviousApp = "";
- }
- };
-
- @Override
- public void onCreate() {
- if (DEBUG) Log.d(TAG, "Creating service");
- try {
- mActivityTaskManager = ActivityTaskManager.getService();
- mActivityTaskManager.registerTaskStackListener(mTaskListener);
- } catch (RemoteException e) {
- // Do nothing
- }
- mRefreshUtils = new RefreshUtils(this);
- registerReceiver();
- super.onCreate();
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- if (DEBUG) Log.d(TAG, "Starting service");
- return START_STICKY;
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
-
- private void registerReceiver() {
- IntentFilter filter = new IntentFilter();
- filter.addAction(Intent.ACTION_SCREEN_OFF);
- filter.addAction(Intent.ACTION_SCREEN_ON);
- this.registerReceiver(mIntentReceiver, filter);
- }
-
- 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 (!mRefreshUtils.isAppInList) {
- mRefreshUtils.getOldRate();
- }
- if (!foregroundApp.equals(mPreviousApp)) {
- mRefreshUtils.setRefreshRate(foregroundApp);
- mPreviousApp = foregroundApp;
- }
- } catch (Exception e) {}
- }
- };
- }
diff --git a/parts/src/org/lineageos/settings/refreshrate/RefreshSettingsFragment.java b/parts/src/org/lineageos/settings/refreshrate/RefreshSettingsFragment.java
deleted file mode 100644
index 04a4063..0000000
--- a/parts/src/org/lineageos/settings/refreshrate/RefreshSettingsFragment.java
+++ /dev/null
@@ -1,419 +0,0 @@
-/**
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.lineageos.settings.refreshrate;
-
-import android.annotation.Nullable;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.os.Bundle;
-import android.text.TextUtils;
-import android.util.TypedValue;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.BaseAdapter;
-import android.widget.ImageView;
-import android.widget.ListView;
-import android.widget.SectionIndexer;
-import android.widget.Spinner;
-import android.widget.TextView;
-
-import androidx.annotation.NonNull;
-import androidx.preference.PreferenceFragment;
-import androidx.recyclerview.widget.RecyclerView;
-import androidx.recyclerview.widget.LinearLayoutManager;
-
-import com.android.settingslib.applications.ApplicationsState;
-
-import org.lineageos.settings.R;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class RefreshSettingsFragment extends PreferenceFragment
- implements ApplicationsState.Callbacks {
-
- private AllPackagesAdapter mAllPackagesAdapter;
- private ApplicationsState mApplicationsState;
- private ApplicationsState.Session mSession;
- private ActivityFilter mActivityFilter;
- private Map mEntryMap =
- new HashMap();
-
- private RefreshUtils mRefreshUtils;
- private RecyclerView mAppsRecyclerView;
-
- @Override
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- mApplicationsState = ApplicationsState.getInstance(getActivity().getApplication());
- mSession = mApplicationsState.newSession(this);
- mSession.onResume();
- mActivityFilter = new ActivityFilter(getActivity().getPackageManager());
-
- mAllPackagesAdapter = new AllPackagesAdapter(getActivity());
-
- mRefreshUtils = new RefreshUtils(getActivity());
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- return inflater.inflate(R.layout.refresh_layout, container, false);
- }
-
- @Override
- public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
-
- mAppsRecyclerView = view.findViewById(R.id.refresh_rv_view);
- mAppsRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
- mAppsRecyclerView.setAdapter(mAllPackagesAdapter);
- }
-
-
- @Override
- public void onResume() {
- super.onResume();
- getActivity().setTitle(getResources().getString(R.string.refresh_title));
- rebuild();
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
-
- mSession.onPause();
- mSession.onDestroy();
- }
-
- @Override
- public void onPackageListChanged() {
- mActivityFilter.updateLauncherInfoList();
- rebuild();
- }
-
- @Override
- public void onRebuildComplete(ArrayList entries) {
- if (entries != null) {
- handleAppEntries(entries);
- mAllPackagesAdapter.notifyDataSetChanged();
- }
- }
-
- @Override
- public void onLoadEntriesCompleted() {
- rebuild();
- }
-
- @Override
- public void onAllSizesComputed() {
- }
-
- @Override
- public void onLauncherInfoChanged() {
- }
-
- @Override
- public void onPackageIconChanged() {
- }
-
- @Override
- public void onPackageSizeChanged(String packageName) {
- }
-
- @Override
- public void onRunningStateChanged(boolean running) {
- }
-
- private void handleAppEntries(List entries) {
- final ArrayList sections = new ArrayList();
- final ArrayList positions = new ArrayList();
- final PackageManager pm = getActivity().getPackageManager();
- String lastSectionIndex = null;
- int offset = 0;
-
- for (int i = 0; i < entries.size(); i++) {
- final ApplicationInfo info = entries.get(i).info;
- final String label = (String) info.loadLabel(pm);
- final String sectionIndex;
-
- if (!info.enabled) {
- sectionIndex = "--"; // XXX
- } else if (TextUtils.isEmpty(label)) {
- sectionIndex = "";
- } else {
- sectionIndex = label.substring(0, 1).toUpperCase();
- }
-
- if (lastSectionIndex == null ||
- !TextUtils.equals(sectionIndex, lastSectionIndex)) {
- sections.add(sectionIndex);
- positions.add(offset);
- lastSectionIndex = sectionIndex;
- }
-
- offset++;
- }
-
- mAllPackagesAdapter.setEntries(entries, sections, positions);
- mEntryMap.clear();
- for (ApplicationsState.AppEntry e : entries) {
- mEntryMap.put(e.info.packageName, e);
- }
- }
-
- private void rebuild() {
- mSession.rebuild(mActivityFilter, ApplicationsState.ALPHA_COMPARATOR);
- }
-
- private int getStateDrawable(int state) {
- switch (state) {
- case RefreshUtils.STATE_STANDARD:
- return R.drawable.ic_refresh_60;
- case RefreshUtils.STATE_EXTREME:
- return R.drawable.ic_refresh_120;
- case RefreshUtils.STATE_DEFAULT:
- default:
- return R.drawable.ic_refresh_default;
- }
- }
-
- private class ViewHolder extends RecyclerView.ViewHolder {
- private TextView title;
- private Spinner mode;
- private ImageView icon;
- private View rootView;
- private ImageView stateIcon;
-
- private ViewHolder(View view) {
- super(view);
- this.title = view.findViewById(R.id.app_name);
- this.mode = view.findViewById(R.id.app_mode);
- this.icon = view.findViewById(R.id.app_icon);
- this.stateIcon = view.findViewById(R.id.state);
- this.rootView = view;
-
- view.setTag(this);
- }
- }
-
- private class ModeAdapter extends BaseAdapter {
-
- private final LayoutInflater inflater;
- private final int[] items = {
- R.string.refresh_default,
- R.string.refresh_standard,
- R.string.refresh_extreme
- };
-
- private ModeAdapter(Context context) {
- inflater = LayoutInflater.from(context);
- }
-
- @Override
- public int getCount() {
- return items.length;
- }
-
- @Override
- public Object getItem(int position) {
- return items[position];
- }
-
- @Override
- public long getItemId(int position) {
- return 0;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- TextView view;
- if (convertView != null) {
- view = (TextView) convertView;
- } else {
- view = (TextView) inflater.inflate(android.R.layout.simple_spinner_dropdown_item,
- parent, false);
- }
-
- view.setText(items[position]);
- view.setTextSize(14f);
-
- return view;
- }
- }
-
- private class AllPackagesAdapter extends RecyclerView.Adapter
- implements AdapterView.OnItemSelectedListener, SectionIndexer {
-
- private List mEntries = new ArrayList<>();
- private String[] mSections;
- private int[] mPositions;
-
- public AllPackagesAdapter(Context context) {
- mActivityFilter = new ActivityFilter(context.getPackageManager());
- }
-
- @Override
- public int getItemCount() {
- return mEntries.size();
- }
-
- @Override
- public long getItemId(int position) {
- return mEntries.get(position).id;
- }
-@NonNull
- @Override
- public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- return new ViewHolder(LayoutInflater.from(parent.getContext())
- .inflate(R.layout.refresh_list_item, parent, false));
- }
-
- @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);
- holder.icon.setImageDrawable(entry.icon);
- int packageState = mRefreshUtils.getStateForPackage(entry.info.packageName);
- holder.mode.setSelection(packageState, false);
- holder.mode.setTag(entry);
- holder.stateIcon.setImageResource(getStateDrawable(packageState));
- }
-
- private void setEntries(List entries,
- List sections, List positions) {
- mEntries = entries;
- mSections = sections.toArray(new String[sections.size()]);
- mPositions = new int[positions.size()];
- for (int i = 0; i < positions.size(); i++) {
- mPositions[i] = positions.get(i);
- }
- notifyDataSetChanged();
- }
-
-
- @Override
- public void onItemSelected(AdapterView> parent, View view, int position, long id) {
- final ApplicationsState.AppEntry entry = (ApplicationsState.AppEntry) parent.getTag();
-
- int currentState = mRefreshUtils.getStateForPackage(entry.info.packageName);
- if (currentState != position) {
- mRefreshUtils.writePackage(entry.info.packageName, position);
- notifyDataSetChanged();
- }
- }
-
- @Override
- public void onNothingSelected(AdapterView> parent) {
- }
-
- @Override
- public int getPositionForSection(int section) {
- if (section < 0 || section >= mSections.length) {
- return -1;
- }
-
- return mPositions[section];
- }
-
- @Override
- public int getSectionForPosition(int position) {
- if (position < 0 || position >= getItemCount()) {
- return -1;
- }
-
- final int index = Arrays.binarySearch(mPositions, position);
-
- /*
- * Consider this example: section positions are 0, 3, 5; the supplied
- * position is 4. The section corresponding to position 4 starts at
- * position 3, so the expected return value is 1. Binary search will not
- * find 4 in the array and thus will return -insertPosition-1, i.e. -3.
- * To get from that number to the expected value of 1 we need to negate
- * and subtract 2.
- */
- return index >= 0 ? index : -index - 2;
- }
-
- @Override
- public Object[] getSections() {
- return mSections;
- }
- }
-
- private class ActivityFilter implements ApplicationsState.AppFilter {
-
- private final PackageManager mPackageManager;
- private final List mLauncherResolveInfoList = new ArrayList();
-
- private ActivityFilter(PackageManager packageManager) {
- this.mPackageManager = packageManager;
-
- updateLauncherInfoList();
- }
-
- public void updateLauncherInfoList() {
- Intent i = new Intent(Intent.ACTION_MAIN);
- i.addCategory(Intent.CATEGORY_LAUNCHER);
- List resolveInfoList = mPackageManager.queryIntentActivities(i, 0);
-
- synchronized (mLauncherResolveInfoList) {
- mLauncherResolveInfoList.clear();
- for (ResolveInfo ri : resolveInfoList) {
- mLauncherResolveInfoList.add(ri.activityInfo.packageName);
- }
- }
- }
-
- @Override
- public void init() {
- }
-
- @Override
- public boolean filterApp(ApplicationsState.AppEntry entry) {
- boolean show = !mAllPackagesAdapter.mEntries.contains(entry.info.packageName);
- if (show) {
- synchronized (mLauncherResolveInfoList) {
- show = mLauncherResolveInfoList.contains(entry.info.packageName);
- }
- }
- return show;
- }
- }
-}
diff --git a/parts/src/org/lineageos/settings/refreshrate/RefreshTileService.java b/parts/src/org/lineageos/settings/refreshrate/RefreshTileService.java
deleted file mode 100644
index 976a129..0000000
--- a/parts/src/org/lineageos/settings/refreshrate/RefreshTileService.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (C) 2021 crDroid Android Project
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lineageos.settings.refreshrate;
-
-import android.content.Context;
-import android.provider.Settings;
-import android.service.quicksettings.Tile;
-import android.service.quicksettings.TileService;
-import android.view.Display;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Collections;
-
-public class RefreshTileService extends TileService {
- private static final String KEY_MIN_REFRESH_RATE = "min_refresh_rate";
- private static final String KEY_PREFERRED_REFRESH_RATE = "preferred_refresh_rate";
- private static final String KEY_PEAK_REFRESH_RATE = "peak_refresh_rate";
-
- private Context context;
- private Tile tile;
-
- private final List availableRates = new ArrayList<>();
- private int activeRateMin;
- private int activeRateMax;
-
- @Override
- public void onCreate() {
- super.onCreate();
- context = getApplicationContext();
- Display.Mode mode = context.getDisplay().getMode();
- Display.Mode[] modes = context.getDisplay().getSupportedModes();
- for (Display.Mode m : modes) {
- float rate = Float.valueOf(String.format(Locale.US, "%.02f", m.getRefreshRate()));
- if (m.getPhysicalWidth() == mode.getPhysicalWidth() &&
- m.getPhysicalHeight() == mode.getPhysicalHeight()) {
- if (!availableRates.contains(rate)) {
- availableRates.add(rate);
- }
- }
- }
-
- Collections.sort(availableRates);
-
- syncFromSettings();
- }
-
- private int getSettingOf(String key) {
- float rate = Settings.System.getFloat(context.getContentResolver(), key, 60);
- Float formattedRate = Float.valueOf(String.format(Locale.US, "%.02f", rate));
- int index = availableRates.indexOf(formattedRate);
-
- if (index == -1) {
- android.util.Log.w("RefreshTileService", "Unknown refresh rate in settings: " + formattedRate);
- return 0; // Fallback to the first available rate
- }
-
- return index;
- }
-
- private void syncFromSettings() {
- activeRateMin = getSettingOf(KEY_MIN_REFRESH_RATE);
- activeRateMax = getSettingOf(KEY_PEAK_REFRESH_RATE);
- }
-
- private void cycleRefreshRate() {
- if (activeRateMin < availableRates.size() - 1) {
- activeRateMin++;
- } else {
- activeRateMin = 0;
- }
-
- float rate = availableRates.get(activeRateMin);
- Settings.System.putFloat(context.getContentResolver(), KEY_MIN_REFRESH_RATE, rate);
- Settings.System.putFloat(context.getContentResolver(), KEY_PREFERRED_REFRESH_RATE, rate);
- Settings.System.putFloat(context.getContentResolver(), KEY_PEAK_REFRESH_RATE, rate);
- }
-
- private String getFormatRate(float rate) {
- return String.format("%.02f Hz", rate)
- .replaceAll("[\\.,]00", "");
- }
-
- private void updateTileView() {
- if (availableRates.isEmpty()) {
- android.util.Log.w("RefreshTileService", "No available refresh rates found.");
- return;
- }
-
- // Ensure indices are valid
- if (activeRateMin < 0 || activeRateMin >= availableRates.size()) activeRateMin = 0;
- if (activeRateMax < 0 || activeRateMax >= availableRates.size()) activeRateMax = 0;
-
- float min = availableRates.get(activeRateMin);
- float max = availableRates.get(activeRateMax);
-
- String displayText = String.format(Locale.US, min == max ? "%s" : "%s - %s",
- getFormatRate(min), getFormatRate(max));
-
- tile.setContentDescription(displayText);
- tile.setSubtitle(displayText);
- tile.setState(min == max ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
- tile.updateTile();
- }
-
- @Override
- public void onStartListening() {
- super.onStartListening();
- tile = getQsTile();
- syncFromSettings();
- updateTileView();
- }
-
- @Override
- public void onClick() {
- super.onClick();
- cycleRefreshRate();
- syncFromSettings();
- updateTileView();
- }
-}
diff --git a/parts/src/org/lineageos/settings/refreshrate/RefreshUtils.java b/parts/src/org/lineageos/settings/refreshrate/RefreshUtils.java
deleted file mode 100644
index d5b7acf..0000000
--- a/parts/src/org/lineageos/settings/refreshrate/RefreshUtils.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.lineageos.settings.refreshrate;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.os.UserHandle;
-import android.view.Display;
-
-import android.provider.Settings;
-import androidx.preference.PreferenceManager;
-
-public final class RefreshUtils {
-
- private static final String REFRESH_CONTROL = "refresh_control";
-
- private static float defaultMaxRate;
- private static float defaultMinRate;
- private static final String KEY_PEAK_REFRESH_RATE = "peak_refresh_rate";
- private static final String KEY_MIN_REFRESH_RATE = "min_refresh_rate";
- private Context mContext;
- protected static boolean isAppInList = false;
-
- protected static final int STATE_DEFAULT = 0;
- protected static final int STATE_STANDARD = 1;
- protected static final int STATE_EXTREME = 2;
-
- private static final float REFRESH_STATE_DEFAULT = 120f;
- private static final float REFRESH_STATE_STANDARD = 60f;
- private static final float REFRESH_STATE_EXTREME = 120f;
-
- private static final String REFRESH_STANDARD = "refresh.standard=";
- private static final String REFRESH_EXTREME = "refresh.extreme=";
-
- private SharedPreferences mSharedPrefs;
-
- protected RefreshUtils(Context context) {
- mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
- mContext = context;
- }
-
- public static void startService(Context context) {
- context.startServiceAsUser(new Intent(context, RefreshService.class),
- UserHandle.CURRENT);
- }
-
- private void writeValue(String profiles) {
- mSharedPrefs.edit().putString(REFRESH_CONTROL, profiles).apply();
- }
-
- protected void getOldRate(){
- defaultMaxRate = Settings.System.getFloat(mContext.getContentResolver(), KEY_PEAK_REFRESH_RATE, REFRESH_STATE_DEFAULT);
- defaultMinRate = Settings.System.getFloat(mContext.getContentResolver(), KEY_MIN_REFRESH_RATE, REFRESH_STATE_DEFAULT);
- }
-
-
- private String getValue() {
- String value = mSharedPrefs.getString(REFRESH_CONTROL, null);
-
- if (value == null || value.isEmpty()) {
- value = REFRESH_STANDARD + ":" + REFRESH_EXTREME;
- writeValue(value);
- }
- return value;
- }
-
- protected void writePackage(String packageName, int mode) {
- String value = getValue();
- value = value.replace(packageName + ",", "");
- String[] modes = value.split(":");
- String finalString;
-
- switch (mode) {
- case STATE_STANDARD:
- modes[0] = modes[0] + packageName + ",";
- break;
- case STATE_EXTREME:
- modes[1] = modes[1] + packageName + ",";
- break;
- }
-
- finalString = modes[0] + ":" + modes[1];
-
- writeValue(finalString);
- }
-
- protected int getStateForPackage(String packageName) {
- String value = getValue();
- String[] modes = value.split(":");
- int state = STATE_DEFAULT;
- if (modes[0].contains(packageName + ",")) {
- state = STATE_STANDARD;
- } else if (modes[1].contains(packageName + ",")) {
- state = STATE_EXTREME;
- }
- return state;
- }
-
- protected void setRefreshRate(String packageName) {
- String value = getValue();
- String modes[];
- float maxrate = defaultMaxRate;
- float minrate = defaultMinRate;
- isAppInList = false;
-
- if (value != null) {
- modes = value.split(":");
-
- if (modes[0].contains(packageName + ",")) {
- maxrate = REFRESH_STATE_STANDARD;
- if ( minrate > maxrate){
- minrate = maxrate;
- }
- isAppInList = true;
- } else if (modes[1].contains(packageName + ",")) {
- maxrate = REFRESH_STATE_EXTREME;
- if ( minrate > maxrate){
- minrate = maxrate;
- }
- isAppInList = true;
- }
- }
- Settings.System.putFloat(mContext.getContentResolver(), KEY_MIN_REFRESH_RATE, minrate);
- Settings.System.putFloat(mContext.getContentResolver(), KEY_PEAK_REFRESH_RATE, maxrate);
- }
-}