[QCM6125][Android13] 动态显示或隐藏电池选项

文章目录

    • 开发平台基本信息
    • 问题描述
    • 解决方法

开发平台基本信息

芯片: QCM6125
版本: Android 13
kernel: msm-4.14

问题描述

Android原生代码是默认支持电池功能的,所以原生设置与SystemUI也都是显示电池选项与图标的,而且并没有提供统一的属性或者接口去动态控制电池选项的显示与隐藏。这时候,就需要增加一个属性,通过属性判断当前产品是否需要显示电池选项。

解决方法

这里通过属性persist.support.ui.battery=off来控制电池的显示与隐藏。

--- a/QSSI.13/frameworks/base/packages/SystemUI/src/com/android/systemui/battery/BatteryMeterView.java
+++ b/QSSI.13/frameworks/base/packages/SystemUI/src/com/android/systemui/battery/BatteryMeterView.java
@@ -21,6 +21,7 @@ import static com.android.systemui.DejankUtils.whitelistIpcs;
 
 import static java.lang.annotation.RetentionPolicy.SOURCE;
 
+import android.os.SystemProperties;
 import android.animation.LayoutTransition;
 import android.animation.ObjectAnimator;
 import android.annotation.IntDef;
@@ -90,6 +91,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
     private int mNonAdaptedBackgroundColor;
 
     private BatteryEstimateFetcher mBatteryEstimateFetcher;
+    private boolean mShowFlag = true;
 
     public BatteryMeterView(Context context, AttributeSet attrs) {
         this(context, attrs, 0);
@@ -121,7 +123,11 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
                 getResources().getDimensionPixelSize(R.dimen.status_bar_battery_icon_height));
         mlp.setMargins(0, 0, 0,
                 getResources().getDimensionPixelOffset(R.dimen.battery_margin_bottom));
-        addView(mBatteryIconView, mlp);
+        // add by telpo
+        mShowFlag = "on".equals(SystemProperties.get("persist.support.ui.battery", "on"));
+        if(mShowFlag) {
+            addView(mBatteryIconView, mlp);
+        }
 
         updateShowPercent();
         mDualToneHandler = new DualToneHandler(context);
@@ -293,7 +299,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
                 || mShowPercentMode == MODE_ESTIMATE;
         shouldShow = shouldShow && !mBatteryStateUnknown;
 
-        if (shouldShow) {
+        if (mShowFlag && shouldShow) {
             if (!showing) {
                 mBatteryPercentView = loadPercentView();
                 if (mPercentageStyleId != 0) { // Only set if specified as attribute

--- a/QSSI.13/packages/apps/Settings/src/com/android/settings/Utils.java
+++ b/QSSI.13/packages/apps/Settings/src/com/android/settings/Utils.java
@@ -299,8 +299,14 @@ public final class Utils extends com.android.settingslib.Utils {
         }
     }
 
+    // modify by telpo
+    public static boolean isBatteryAvailable() {
+        return "on".equals(SystemProperties.get("persist.support.ui.battery", "on"));
+    }
+
+
     public static boolean isBatteryPresent(Intent batteryChangedIntent) {
-        return batteryChangedIntent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, true);
+        return isBatteryAvailable();
     }


--- a/QSSI.13/packages/apps/Settings/src/com/android/settings/applications/appinfo/AppBatteryPreferenceController.java
+++ b/QSSI.13/packages/apps/Settings/src/com/android/settings/applications/appinfo/AppBatteryPreferenceController.java
@@ -27,6 +27,7 @@ import android.os.UserHandle;
 import android.os.UserManager;
 import android.util.Log;
 
+import com.android.settings.Utils;
 import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
 import androidx.loader.app.LoaderManager;
@@ -99,7 +100,7 @@ public class AppBatteryPreferenceController extends BasePreferenceController
 
     @Override
     public int getAvailabilityStatus() {
-        return mContext.getResources().getBoolean(R.bool.config_show_app_info_settings_battery)
+        return Utils.isBatteryAvailable()
                 ? AVAILABLE
                 : CONDITIONALLY_UNAVAILABLE;
     }

--- a/QSSI.13/packages/apps/Settings/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java
+++ b/QSSI.13/packages/apps/Settings/src/com/android/settings/fuelgauge/TopLevelBatteryPreferenceController.java
@@ -30,6 +30,7 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
 import com.android.settingslib.core.lifecycle.events.OnStart;
 import com.android.settingslib.core.lifecycle.events.OnStop;
 import com.android.settingslib.utils.ThreadUtils;
+import com.android.settings.Utils;
 
 public class TopLevelBatteryPreferenceController extends BasePreferenceController implements
         LifecycleObserver, OnStart, OnStop, BatteryPreferenceController {
@@ -62,7 +63,7 @@ public class TopLevelBatteryPreferenceController extends BasePreferenceControlle
 
     @Override
     public int getAvailabilityStatus() {
-        return mContext.getResources().getBoolean(R.bool.config_show_top_level_battery)
+        return Utils.isBatteryAvailable()
                 ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
     }
 

你可能感兴趣的:(Android13,Android13,framework,电池选项)