Settings: Add FastCharge preference into Battery settings

* Several OEMs let the user decide whether to enable or disable quick
   charging technology when using a quickcharge charger.
   Samsung, for example, exposes a sysfs node to disable it at
   will, depending on what the user sets in battery settings UI.

 * Disabling fast charge may be useful for reducing the heat produced by
   the device while charging, or for extending the lifespan of the battery.

 * This commit introduces a switch preference for disabling fastcharge
   on devices that support said feature.

Change-Id: I7dd09d357e9bd555a8efeaf9ee191e52b9f2d151
This commit is contained in:
Bruno Martins 2021-01-18 23:47:54 +00:00 committed by Michael Bestas
parent 809f6c074d
commit 70357db5c6
No known key found for this signature in database
4 changed files with 95 additions and 0 deletions

View file

@ -116,6 +116,7 @@ android_library {
// Lineage dependencies
"org.lineageos.platform.internal",
"LineagePreferenceLib",
"vendor.lineage.fastcharge-V1.0-java",
],
plugins: [

View file

@ -93,4 +93,8 @@
<!-- Wake on plug -->
<string name="wake_when_plugged_or_unplugged_title">Wake on plug</string>
<string name="wake_when_plugged_or_unplugged_summary">Turn the screen on when connecting or disconnecting a power source</string>
<!-- FastCharge feature -->
<string name="fast_charging_title">Fast charging</string>
<string name="fast_charging_summary">Disable to reduce the heat produced by the device while charging or to extend the lifespan of the battery</string>
</resources>

View file

@ -70,6 +70,12 @@
android:summary="@string/battery_percentage_description"
settings:controller="com.android.settings.display.BatteryPercentagePreferenceController" />
<SwitchPreferenceCompat
android:key="fast_charging"
android:title="@string/fast_charging_title"
android:summary="@string/fast_charging_summary"
settings:controller="com.android.settings.fuelgauge.FastChargingPreferenceController"/>
<com.android.settingslib.widget.FooterPreference
android:key="power_usage_footer"
android:title="@string/battery_footer_summary"

View file

@ -0,0 +1,84 @@
/*
* Copyright (C) 2021 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 com.android.settings.fuelgauge;
import android.content.Context;
import android.os.RemoteException;
import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.SwitchPreferenceCompat;
import com.android.settings.core.BasePreferenceController;
import vendor.lineage.fastcharge.V1_0.IFastCharge;
import java.util.NoSuchElementException;
/**
* Controller to change and update the fast charging toggle
*/
public class FastChargingPreferenceController extends BasePreferenceController
implements Preference.OnPreferenceChangeListener {
private static final String KEY_FAST_CHARGING = "fast_charging";
private static final String TAG = "FastChargingPreferenceController";
private IFastCharge mFastCharge = null;
public FastChargingPreferenceController(Context context) {
super(context, KEY_FAST_CHARGING);
try {
mFastCharge = IFastCharge.getService();
} catch (NoSuchElementException | RemoteException e) {
Log.e(TAG, "Failed to get IFastCharge interface", e);
}
}
@Override
public int getAvailabilityStatus() {
return mFastCharge != null ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
boolean fastChargingEnabled = false;
try {
fastChargingEnabled = mFastCharge.isEnabled();
} catch (RemoteException e) {
Log.e(TAG, "isEnabled failed", e);
}
((SwitchPreferenceCompat) preference).setChecked(fastChargingEnabled);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean shouldEnableFastCharging = (Boolean) newValue;
try {
mFastCharge.setEnabled(shouldEnableFastCharging);
updateState(preference);
} catch (RemoteException e) {
Log.e(TAG, "setEnabled failed", e);
}
return false;
}
}