Android frameworks 开发总结之十(lock screen message && Battery Last full charge)

1.設置lock screen message後不显示


XXXt設備設置lock screen message後,發現鎖頻界面不顯示內容,像時間日期都不顯示。只在右上角顯示一個鎖圖標,需要向下滑動一下才能顯示出來。布局文件位置: frameworks/base/packages/SystemUI/res-keyguard/layout/keyguard_status_view.xml 修改:frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java中的layoutOwnerInfo方法:

private void layoutOwnerInfo() {
        if (mOwnerInfo != null && mOwnerInfo.getVisibility() != GONE) {
            // Animate owner info during wake-up transition
            mOwnerInfo.setAlpha(1f - mDarkAmount);

            float ratio = mDarkAmount;
            // Calculate how much of it we should crop in order to have a smooth transition
            int collapsed = mOwnerInfo.getTop() - mOwnerInfo.getPaddingTop();
            int expanded = mOwnerInfo.getBottom() + mOwnerInfo.getPaddingBottom();
            int toRemove = (int) ((expanded - collapsed) * ratio);
            mOwnerInfo.setTop(mIconTopMarginWithHeader * 4);
            setBottom(getMeasuredHeight() - 50);
            if (mNotificationIcons != null) {
                // We're using scrolling in order not to overload the translation which is used
                // when appearing the icons
                mNotificationIcons.setScrollY(toRemove);
            }
        } else if (mNotificationIcons != null){
            mNotificationIcons.setScrollY(0);
        }
    }

在其它设备上(在横屏的情况下不显示lock screen message,原因是字体过大导致的,修改方式:

private void updateOwnerInfo() {
    if (mOwnerInfo == null) return;
    String info = mLockPatternUtils.getDeviceOwnerInfo();
    if (info == null) {
        // Use the current user owner information if enabled.
        final boolean ownerInfoEnabled = mLockPatternUtils.isOwnerInfoEnabled(
                KeyguardUpdateMonitor.getCurrentUser());
        if (ownerInfoEnabled) {
            info = mLockPatternUtils.getOwnerInfo(KeyguardUpdateMonitor.getCurrentUser());
        }
    }
    mOwnerInfo.setText(info);
    mOwnerInfo.setTextSize(24);
    updateDark();
}

2.锁屏界面上charging和emergency call位置不正确

Jaws设备上在横屏的情况下charging和emergency call位置不正确. 布局文件:frameworks/base/packages/SystemUI/res/layout/keyguard_bottom_area.xml . 修改布局文件中的android:layout_marginBottom属性

3.修改Battery Last full charge

XXX設備有外部電池,所以last full charge需要考慮當拔掉充電線時候,檢測外部電池電量。last full charge的更新在: frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java文件中.当手机充满电后,如果拔掉充电器,则会以setBatteryStateLocked() → setOnBatteryLocked() → resetAllStatsLocked() → initTimes()的调用顺序,将mStartClockTime设置为当前系统时间。从而在Settings中提示上次充满电为0分钟前。Patch如下:

diff --git a/core/java/com/android/internal/app/IBatteryStats.aidl b/core/java/com/android/internal/app/IBatteryStats.aidl
index 15b1d75..5bb031c 100644
--- a/core/java/com/android/internal/app/IBatteryStats.aidl
+++ b/core/java/com/android/internal/app/IBatteryStats.aidl
@@ -161,4 +161,5 @@ interface IBatteryStats {
 
     /** {@hide} */
     boolean setChargingStateUpdateDelayMillis(int delay);
+    void setAmarBatteryState(boolean isExist,int level);
 }
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 3113004..95df0ae 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -996,6 +996,8 @@ public class BatteryStatsImpl extends BatteryStats {
 
     private long[] mCpuFreqs;
 
+    private boolean isAmarBatteryExist = false;
+    private int amarBatteryLevle = 0;
     @VisibleForTesting
     protected PowerProfile mPowerProfile;
 
@@ -10401,12 +10403,14 @@ public class BatteryStatsImpl extends BatteryStats {
     }
 
     void initTimes(long uptime, long realtime) {
-        mStartClockTime = System.currentTimeMillis();
          //開機初始化或者外部電池不存在時候更新或者外部電池存在並且電量大於等於90的時候
+        if(mStartClockTime == 0 || (isAmarBatteryExist && amarBatteryLevle >= 90) || (!isAmarBatteryExist)){ 
+            mStartClockTime = System.currentTimeMillis();
+            mRealtimeStart = realtime;
+        }
         mOnBatteryTimeBase.init(uptime, realtime);
         mOnBatteryScreenOffTimeBase.init(uptime, realtime);
         mRealtime = 0;
         mUptime = 0;
-        mRealtimeStart = realtime;
         mUptimeStart = uptime;
     }
 
@@ -12419,6 +12423,11 @@ public class BatteryStatsImpl extends BatteryStats {
         mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh);
     }
 
+    public void setAmarBatteryState(boolean isExist,int level){
+        isAmarBatteryExist = isExist;
+        amarBatteryLevle = level;
+    }
+
     public static boolean isOnBattery(int plugType, int status) {
         return plugType == BATTERY_PLUGGED_NONE && status != BatteryManager.BATTERY_STATUS_UNKNOWN;
     }
diff --git a/services/core/java/com/android/server/BatteryService.java b/services/core/java/com/android/server/BatteryService.java
index acac12e..7362aa0 100644
--- a/services/core/java/com/android/server/BatteryService.java
+++ b/services/core/java/com/android/server/BatteryService.java
@@ -537,6 +537,30 @@ public final class BatteryService extends SystemService {
 
         // Let the battery stats keep track of the current level.
         try {
+            if (batread == null) {
+                batread = IBatread2.getService(true);
+            }
+        } catch (RemoteException e) {
+            Slog.w(TAG, "Got second battery error 1: ", e);
+        }
+
+        try {
+            if(checkAmarBatteryError()){
+                mBatteryStats.setAmarBatteryState(false, 0);
+            }else {
+                boolean isAmarBatteryExist = checkAmarBatteryExist();
+                int amarBatteryLevel = 0;
+                if (isAmarBatteryExist && batread != null) {
+                    try {
+                        if (batread != null) {
+                            amarBatteryLevel = batread.batteryread2("bms_ext/capacity");
+                        }
+                    } catch (Exception e) {
+                        Slog.w(TAG, "batteryread2 error: ", e);
+                    }
+                }
+                mBatteryStats.setAmarBatteryState(isAmarBatteryExist, amarBatteryLevel);
+            }
             mBatteryStats.setBatteryState(mHealthInfo.batteryStatus, mHealthInfo.batteryHealth,
                     mPlugType, mHealthInfo.batteryLevel, mHealthInfo.batteryTemperature,
                     mHealthInfo.batteryVoltage, mHealthInfo.batteryChargeCounter,
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
index a47ea4f..24eac58 100644
--- a/services/core/java/com/android/server/am/BatteryStatsService.java
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -1164,6 +1164,12 @@ public final class BatteryStatsService extends IBatteryStats.Stub
         });
     }
 
+    public void setAmarBatteryState(boolean isExist,int level){
+        if(mStats != null){
+            mStats.setAmarBatteryState(isExist,level);
+        }
+    }
+
     public long getAwakeTimeBattery() {
         mContext.enforceCallingOrSelfPermission(
                 android.Manifest.permission.BATTERY_STATS, null);

你可能感兴趣的:(android)