Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 198a32c7 authored by /e/ robot's avatar /e/ robot
Browse files

Merge remote-tracking branch 'origin/lineage-22.2' into a15

parents bdd0a45c 787a24e2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ java_defaults {

    static_libs: [
        "vendor.lineage.health-V2-java",
        "vendor.lineage.livedisplay-V1-java",
        "vendor.lineage.livedisplay-V2.0-java",
        "vendor.lineage.livedisplay-V2.1-java",
        "vendor.lineage.touch-V1-java",
+132 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2025 The LineageOS Project
 * SPDX-License-Identifier: Apache-2.0
 */

package org.lineageos.platform.internal.health;

import android.content.res.Resources;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;

import com.android.internal.util.ArrayUtils;

import lineageos.providers.LineageSettings;

import org.lineageos.platform.internal.health.LineageHealthFeature;
import org.lineageos.platform.internal.R;

import vendor.lineage.health.FastChargeMode;
import vendor.lineage.health.IFastCharge;

import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.ArrayList;
import java.util.List;

public class FastChargeController extends LineageHealthFeature {
    private final int[] mChargingSpeedValues;
    private final ContentResolver mContentResolver;
    private final IFastCharge mFastCharge;

    // Settings uris
    private final Uri MODE_URI = LineageSettings.System.getUriFor(
            LineageSettings.System.FAST_CHARGE_MODE);

    public FastChargeController(Context context, Handler handler) {
        super(context, handler);

        mContentResolver = mContext.getContentResolver();
        mFastCharge = IFastCharge.Stub.asInterface(
                ServiceManager.waitForDeclaredService(
                        IFastCharge.DESCRIPTOR + "/default"));

        Resources res = mContext.getResources();
        mChargingSpeedValues = Stream.of(res.getStringArray(R.array.charging_speed_values))
                .mapToInt(Integer::parseInt)
                .toArray();

        if (mFastCharge == null) {
            Log.i(TAG, "Lineage Health HAL not found");
            return;
        }
    }

    @Override
    public boolean isSupported() {
        try {
            return mFastCharge != null && mFastCharge.getSupportedFastChargeModes() > 0;
        } catch (RemoteException e) {
            return false;
        }
    }

    public int[] getSupportedFastChargeModes() {
        try {
            long supportedFastChargeModes = mFastCharge.getSupportedFastChargeModes();

            return IntStream.of(mChargingSpeedValues)
                    .filter(mode -> (supportedFastChargeModes & mode) != 0)
                    .toArray();
        } catch (RemoteException e) {
            return new int[0];
        }
    }

    public int getFastChargeMode() {
        int[] supportedFastChargeModes = getSupportedFastChargeModes();
        int defaultMode = supportedFastChargeModes[supportedFastChargeModes.length - 1];

        int mode = LineageSettings.System.getInt(mContentResolver,
                LineageSettings.System.FAST_CHARGE_MODE,
                defaultMode);
        if (mode != defaultMode && !ArrayUtils.contains(supportedFastChargeModes, mode)) {
            return defaultMode;
        }

        return mode;
    }

    public boolean setFastChargeMode(int mode) {
        putInt(LineageSettings.System.FAST_CHARGE_MODE, mode);
        return true;
    }

    @Override
    public void onStart() {
        if (mFastCharge == null) {
            return;
        }

        // Register setting observer
        registerSettings(MODE_URI);

        handleSettingChange();
    }

    private void handleSettingChange() {
        try {
            mFastCharge.setFastChargeMode(getFastChargeMode());
        } catch (RemoteException e) {
        }
    }

    @Override
    protected void onSettingsChanged(Uri uri) {
        handleSettingChange();
    }

    @Override
    public void dump(PrintWriter pw) {
        pw.println();
        pw.println("FastChargeController Configuration:");
        pw.println("  Mode: " + getFastChargeMode());
        pw.println();
    }
}
+26 −1
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2023-2024 The LineageOS Project
 * SPDX-FileCopyrightText: 2023-2025 The LineageOS Project
 * SPDX-License-Identifier: Apache-2.0
 */

@@ -37,6 +37,7 @@ public class HealthInterfaceService extends LineageSystemService {

    // Health features
    private ChargingControlController mCCC;
    private FastChargeController mFCC;

    public HealthInterfaceService(Context context) {
        super(context);
@@ -69,6 +70,10 @@ public class HealthInterfaceService extends LineageSystemService {
        if (mCCC.isSupported()) {
            mFeatures.add(mCCC);
        }
        mFCC = new FastChargeController(mContext, mHandler);
        if (mFCC.isSupported()) {
            mFeatures.add(mFCC);
        }

        if (!mFeatures.isEmpty()) {
            publishBinderService(LineageContextConstants.LINEAGE_HEALTH_INTERFACE, mService);
@@ -156,6 +161,26 @@ public class HealthInterfaceService extends LineageSystemService {
                    || mCCC.isChargingModeSupported(ChargingControlSupportedMode.LIMIT);
        }

        @Override
        public boolean isFastChargeSupported() {
            return mFCC.isSupported();
        }

        @Override
        public int[] getSupportedFastChargeModes() {
            return mFCC.getSupportedFastChargeModes();
        }

        @Override
        public int getFastChargeMode() {
            return mFCC.getFastChargeMode();
        }

        @Override
        public boolean setFastChargeMode(int mode) {
            return mFCC.setFastChargeMode(mode);
        }

        @Override
        public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
            mContext.enforceCallingOrSelfPermission(Manifest.permission.DUMP, TAG);
+14 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     SPDX-FileCopyrightText: 2015 The CyanogenMod Project
     SPDX-FileCopyrightText: 2022 The LineageOS Project
     SPDX-FileCopyrightText: 2022-2025 The LineageOS Project
     SPDX-License-Identifier: Apache-2.0
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- Fast charge -->
    <string-array name="charging_speed_entries" translatable="false">
        <item>@string/charging_speed_slow</item>
        <item>@string/charging_speed_fast</item>
        <item>@string/charging_speed_super_fast</item>
    </string-array>

    <string-array name="charging_speed_values" translatable="false">
        <item>1</item> <!-- FastChargeMode.NONE -->
        <item>2</item> <!-- FastChargeMode.FAST_CHARGE -->
        <item>4</item> <!-- FastChargeMode.SUPER_FAST_CHARGE -->
    </string-array>

    <!-- LiveDisplay -->
    <string-array name="live_display_entries" translatable="false">
        <item>@string/live_display_auto</item>
+7 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     SPDX-FileCopyrightText: 2015 The CyanogenMod Project
     SPDX-FileCopyrightText: 2017-2023 The LineageOS Project
     SPDX-FileCopyrightText: 2017-2025 The LineageOS Project
     SPDX-License-Identifier: Apache-2.0
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
@@ -43,6 +43,12 @@
    <!-- Name of wildcard profile. -->
    <string name="wildcardProfile">Other</string>

    <!-- Charging speed strings -->
    <string name="charging_speed">Charging speed</string>
    <string name="charging_speed_slow">Slow</string>
    <string name="charging_speed_fast">Fast</string>
    <string name="charging_speed_super_fast">Super fast</string>

    <!-- LiveDisplay strings -->
    <string name="live_display_title" translatable="false">LiveDisplay</string>
    <string name="live_display_auto">Automatic</string>
Loading