From 51e39f947569b867f8cd05765368ecb83f1786fa Mon Sep 17 00:00:00 2001 From: LibXZR Date: Mon, 4 Jul 2022 21:34:43 +0200 Subject: [PATCH] Cherish: Add force background freezer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic0c119282c295db9b7d4dc03c037828b02c5a9e4 Signed-off-by: Hưng Phan --- res/values/cherish_strings.xml | 4 ++ res/xml/cherish_settings_misc.xml | 7 +++ ...eBackgroundFreezePreferenceController.java | 48 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/com/cherish/settings/preferences/ForceBackgroundFreezePreferenceController.java diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml index e1a3e74..767dc1f 100644 --- a/res/values/cherish_strings.xml +++ b/res/values/cherish_strings.xml @@ -864,4 +864,8 @@ Strict standby policy When dismissing from recents, this will force stop apps with restricted battery usage and impose stronger restrictions to them. Also, all app standby restrictions will be imposed even when device is charging. + + + Background tasks freezer + Freeze tasks with restricted battery usage when moving them to background and unfreeze them when moving to foreground. This could save battery slightly but may lead to crashes and background ANR. diff --git a/res/xml/cherish_settings_misc.xml b/res/xml/cherish_settings_misc.xml index 1e24f3f..18afa07 100644 --- a/res/xml/cherish_settings_misc.xml +++ b/res/xml/cherish_settings_misc.xml @@ -40,6 +40,13 @@ android:key="strict_standby_policy" android:title="@string/strict_standby_policy_title" android:summary="@string/strict_standby_policy_summary" + android:defaultValue="false"/> + + diff --git a/src/com/cherish/settings/preferences/ForceBackgroundFreezePreferenceController.java b/src/com/cherish/settings/preferences/ForceBackgroundFreezePreferenceController.java new file mode 100644 index 0000000..89baff0 --- /dev/null +++ b/src/com/cherish/settings/preferences/ForceBackgroundFreezePreferenceController.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022 Project Kaleidoscope + * + * 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 com.cherish.settings.preferences; + +import android.app.ActivityManager; +import android.content.Context; +import android.os.RemoteException; +import android.util.Log; + +import com.android.settings.core.BasePreferenceController; +import com.android.settings.R; + +public class ForceBackgroundFreezePreferenceController extends BasePreferenceController { + private static final String TAG = "ForceBackgroundFreezePreferenceController"; + + public ForceBackgroundFreezePreferenceController(Context context, String key) { + super(context, key); + } + + @Override + @AvailabilityStatus + public int getAvailabilityStatus() { + int ret = UNSUPPORTED_ON_DEVICE; + + try { + if (ActivityManager.getService().isAppFreezerEnabled()) + ret = AVAILABLE; + } catch (RemoteException e) { + Log.w(TAG, "Unable to obtain freezer enabling status from ActivityManager"); + } + + return ret; + } +}