Skip to content

Commit

Permalink
base: dock battery
Browse files Browse the repository at this point in the history
Change-Id: I8cc3fc465daa49c9010bdbbf876dae18461d7024
Require: topic:dock_battery
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>

Improve dock battery strings

Change-Id: Iccfa2df4ec608ae02c0bfcef99648788dab95933

systemui: fix battery text level visibility

Use present flag instead of plug-in flag to determine the battery present (only hide the
text level view if the battery is not present)

Change-Id: I8e20e107bbeeecdc846833dc80c1a2754d82a039
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>

systemui: restore space between clock & battery

Initialize dock battery to GONE visibility because isn't update on device not supporting
dock battery.

Change-Id: I23aeafc27db0fc499050a7306e8549293accb507
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>

SystemUI: fix battery icon jump on qs expand

The layouts are slightly different for the header and icon layouts.

Change-Id: I85d3fc007eb9b2c3e2ba09bb761a91b521b89700
Signed-off-by: Roman Birg <roman@cyngn.com>

systemui: move dock battery level views outside systemicons layout

At not the ideal, this at least will match normal battery level view, puttings battery levels
in the correct order. In addition fix two small dock battery bugs:
 -  BatteryLevelTextView not displayed if mode is TEXT
 -  Properly hide DockBatteryMetterView for modes NONE and TEXT
 -  Underline the dock BatteryLevelTextView to differentiate normal from dock text view

Screenshot: https://cloud.ruesga.com/f/74fe240c66/

Change-Id: Idfd3a4bb2f19bd29f9f4dd2b0ea7f645bb531986
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
  • Loading branch information
jruesga authored and temasek committed Mar 11, 2016
1 parent de442a2 commit 81b0777
Show file tree
Hide file tree
Showing 31 changed files with 1,460 additions and 90 deletions.
1 change: 1 addition & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ LOCAL_SRC_FILES += \
core/java/android/app/IAppTask.aidl \
core/java/android/app/ITaskStackListener.aidl \
core/java/android/app/IBackupAgent.aidl \
core/java/android/app/IBatteryService.aidl \
core/java/android/app/IInstrumentationWatcher.aidl \
core/java/android/app/INotificationManager.aidl \
core/java/android/app/IProcessObserver.aidl \
Expand Down
26 changes: 26 additions & 0 deletions core/java/android/app/IBatteryService.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2016, The CyanogenMod 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 android.app;

/**
* System private API for talking with the battery service.
*
* {@hide}
*/
interface IBatteryService {
boolean isDockBatterySupported();
}
4 changes: 3 additions & 1 deletion core/java/android/app/SystemServiceRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ public DownloadManager createService(ContextImpl ctx) {
new StaticServiceFetcher<BatteryManager>() {
@Override
public BatteryManager createService() {
return new BatteryManager();
IBinder b = ServiceManager.getService(Context.BATTERY_SERVICE);
IBatteryService service = IBatteryService.Stub.asInterface(b);
return new BatteryManager(service);
}});

registerService(Context.NFC_SERVICE, NfcManager.class,
Expand Down
160 changes: 156 additions & 4 deletions core/java/android/os/BatteryManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2008 The Android Open Source Project
* Copyright (C) 2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +17,7 @@

package android.os;

import android.app.IBatteryService;
import android.content.Context;
import android.os.BatteryProperty;
import android.os.IBatteryPropertiesRegistrar;
Expand Down Expand Up @@ -93,6 +95,79 @@ public class BatteryManager {
*/
public static final String EXTRA_TECHNOLOGY = "technology";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* integer containing the current dock status constant.
* @hide
*/
public static final String EXTRA_DOCK_STATUS = "dock_status";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* integer containing the current dock health constant.
* @hide
*/
public static final String EXTRA_DOCK_HEALTH = "dock_health";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* boolean indicating whether a dock battery is present.
* @hide
*/
public static final String EXTRA_DOCK_PRESENT = "dock_present";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* integer field containing the current dock battery level, from 0 to
* {@link #EXTRA_SCALE}.
* @hide
*/
public static final String EXTRA_DOCK_LEVEL = "dock_level";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* integer containing the maximum dock battery level.
* @hide
*/
public static final String EXTRA_DOCK_SCALE = "dock_scale";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* integer containing the resource ID of a small status bar icon
* indicating the current dock battery state.
* @hide
*/
public static final String EXTRA_DOCK_ICON_SMALL = "dock_icon-small";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* integer indicating whether the device is plugged in to a dock power
* source.
* @hide
*/
public static final String EXTRA_DOCK_PLUGGED = "dock_plugged";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* integer containing the current dock battery voltage level.
* @hide
*/
public static final String EXTRA_DOCK_VOLTAGE = "dock_voltage";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* integer containing the current dock battery temperature.
* @hide
*/
public static final String EXTRA_DOCK_TEMPERATURE = "dock_temperature";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* String describing the technology of the current dock battery.
* @hide
*/
public static final String EXTRA_DOCK_TECHNOLOGY = "dock_technology";

/**
* Extra for {@link android.content.Intent#ACTION_BATTERY_CHANGED}:
* Int value set to nonzero if an unsupported charger is attached
Expand Down Expand Up @@ -133,10 +208,23 @@ public class BatteryManager {
/** Power source is wireless. */
public static final int BATTERY_PLUGGED_WIRELESS = 4;

// values of the "dock_plugged" field in the ACTION_BATTERY_CHANGED intent.
// These must be powers of 2.
/** Power source is an DockAC charger.
* @hide*/
public static final int BATTERY_DOCK_PLUGGED_AC = 1;
/** Power source is an DockUSB charger.
* @hide*/
public static final int BATTERY_DOCK_PLUGGED_USB = 2;

/** @hide */
public static final int BATTERY_PLUGGED_ANY =
BATTERY_PLUGGED_AC | BATTERY_PLUGGED_USB | BATTERY_PLUGGED_WIRELESS;

/** @hide */
public static final int BATTERY_DOCK_PLUGGED_ANY =
BATTERY_DOCK_PLUGGED_AC | BATTERY_DOCK_PLUGGED_USB;

/**
* Sent when the device's battery has started charging (or has reached full charge
* and the device is on power). This is a good time to do work that you would like to
Expand Down Expand Up @@ -191,6 +279,7 @@ public class BatteryManager {
*/
public static final int BATTERY_PROPERTY_ENERGY_COUNTER = 5;

private final IBatteryService mBatteryService;
private final IBatteryStats mBatteryStats;
private final IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar;

Expand All @@ -202,6 +291,27 @@ public BatteryManager() {
ServiceManager.getService(BatteryStats.SERVICE_NAME));
mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar.Stub.asInterface(
ServiceManager.getService("batteryproperties"));
mBatteryService = null;
}

/** @hide */
public BatteryManager(IBatteryService service) {
super();
mBatteryStats = IBatteryStats.Stub.asInterface(
ServiceManager.getService(BatteryStats.SERVICE_NAME));
mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar.Stub.asInterface(
ServiceManager.getService("batteryproperties"));
mBatteryService = service;
}

/** @hide */
public boolean isDockBatterySupported() {
try {
return mBatteryService != null && mBatteryService.isDockBatterySupported();
} catch (RemoteException ex) {
// Ignore
}
return false;
}

/**
Expand All @@ -223,8 +333,10 @@ public boolean isCharging() {
*
* Returns the requested value, or Long.MIN_VALUE if property not
* supported on this system or on other error.
* fromDock determines if the property is query from the normal battery
* or the dock battery.
*/
private long queryProperty(int id) {
private long queryProperty(int id, boolean fromDock) {
long ret;

if (mBatteryPropertiesRegistrar == null) {
Expand All @@ -234,7 +346,13 @@ private long queryProperty(int id) {
try {
BatteryProperty prop = new BatteryProperty();

if (mBatteryPropertiesRegistrar.getProperty(id, prop) == 0)
final int callResult;
if (!fromDock) {
callResult = mBatteryPropertiesRegistrar.getProperty(id, prop);
} else {
callResult = mBatteryPropertiesRegistrar.getDockProperty(id, prop);
}
if (callResult == 0)
ret = prop.getLong();
else
ret = Long.MIN_VALUE;
Expand All @@ -255,7 +373,7 @@ private long queryProperty(int id) {
* @return the property value, or Integer.MIN_VALUE if not supported.
*/
public int getIntProperty(int id) {
return (int)queryProperty(id);
return (int)queryProperty(id, false);
}

/**
Expand All @@ -268,6 +386,40 @@ public int getIntProperty(int id) {
* @return the property value, or Long.MIN_VALUE if not supported.
*/
public long getLongProperty(int id) {
return queryProperty(id);
return queryProperty(id, false);
}

/**
* Return the value of a dock battery property of integer type. If the
* platform does not provide the property queried, this value will
* be Integer.MIN_VALUE.
*
* @param id identifier of the requested property
*
* @return the property value, or Integer.MIN_VALUE if not supported.
* @hide
*/
public int getIntDockProperty(int id) {
if (!isDockBatterySupported()) {
return Integer.MIN_VALUE;
}
return (int)queryProperty(id, true);
}

/**
* Return the value of a dock battery property of long type If the
* platform does not provide the property queried, this value will
* be Long.MIN_VALUE.
*
* @param id identifier of the requested property
*
* @return the property value, or Long.MIN_VALUE if not supported.
* @hide
*/
public long getLongDockProperty(int id) {
if (!isDockBatterySupported()) {
return Long.MIN_VALUE;
}
return queryProperty(id, true);
}
}
21 changes: 21 additions & 0 deletions core/java/android/os/BatteryManagerInternal.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 The Android Open Source Project
* Copyright (C) 2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +43,26 @@ public abstract class BatteryManagerInternal {
*/
public abstract boolean getBatteryLevelLow();

/**
* Returns whether dock batteries is supported
*/
public abstract boolean isDockBatterySupported();

/**
* Returns the current dock plug type.
*/
public abstract int getDockPlugType();

/**
* Returns dock battery level as a percentage.
*/
public abstract int getDockBatteryLevel();

/**
* Returns whether we currently consider the dock battery level to be low.
*/
public abstract boolean getDockBatteryLevelLow();

/**
* Returns a non-zero value if an unsupported charger is attached.
*/
Expand Down
54 changes: 54 additions & 0 deletions core/java/android/os/BatteryProperties.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright 2013, The Android Open Source Project
* Copyright 2016, The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +32,16 @@ public class BatteryProperties implements Parcelable {
public int batteryTemperature;
public String batteryTechnology;

public boolean dockBatterySupported;
public boolean chargerDockAcOnline;
public int dockBatteryStatus;
public int dockBatteryHealth;
public boolean dockBatteryPresent;
public int dockBatteryLevel;
public int dockBatteryVoltage;
public int dockBatteryTemperature;
public String dockBatteryTechnology;

public BatteryProperties() {
}

Expand All @@ -46,6 +57,16 @@ public void set(BatteryProperties other) {
batteryVoltage = other.batteryVoltage;
batteryTemperature = other.batteryTemperature;
batteryTechnology = other.batteryTechnology;

dockBatterySupported = other.dockBatterySupported;
chargerDockAcOnline = other.chargerDockAcOnline;
dockBatteryStatus = other.dockBatteryStatus;
dockBatteryHealth = other.dockBatteryHealth;
dockBatteryPresent = other.dockBatteryPresent;
dockBatteryLevel = other.dockBatteryLevel;
dockBatteryVoltage = other.dockBatteryVoltage;
dockBatteryTemperature = other.dockBatteryTemperature;
dockBatteryTechnology = other.dockBatteryTechnology;
}

/*
Expand All @@ -65,6 +86,27 @@ private BatteryProperties(Parcel p) {
batteryVoltage = p.readInt();
batteryTemperature = p.readInt();
batteryTechnology = p.readString();

dockBatterySupported = p.readInt() == 1 ? true : false;
if (dockBatterySupported) {
chargerDockAcOnline = p.readInt() == 1 ? true : false;
dockBatteryStatus = p.readInt();
dockBatteryHealth = p.readInt();
dockBatteryPresent = p.readInt() == 1 ? true : false;
dockBatteryLevel = p.readInt();
dockBatteryVoltage = p.readInt();
dockBatteryTemperature = p.readInt();
dockBatteryTechnology = p.readString();
} else {
chargerDockAcOnline = false;
dockBatteryStatus = BatteryManager.BATTERY_STATUS_UNKNOWN;
dockBatteryHealth = BatteryManager.BATTERY_HEALTH_UNKNOWN;
dockBatteryPresent = false;
dockBatteryLevel = 0;
dockBatteryVoltage = 0;
dockBatteryTemperature = 0;
dockBatteryTechnology = "";
}
}

public void writeToParcel(Parcel p, int flags) {
Expand All @@ -79,6 +121,18 @@ public void writeToParcel(Parcel p, int flags) {
p.writeInt(batteryVoltage);
p.writeInt(batteryTemperature);
p.writeString(batteryTechnology);

p.writeInt(dockBatterySupported ? 1 : 0);
if (dockBatterySupported) {
p.writeInt(chargerDockAcOnline ? 1 : 0);
p.writeInt(dockBatteryStatus);
p.writeInt(dockBatteryHealth);
p.writeInt(dockBatteryPresent ? 1 : 0);
p.writeInt(dockBatteryLevel);
p.writeInt(dockBatteryVoltage);
p.writeInt(dockBatteryTemperature);
p.writeString(dockBatteryTechnology);
}
}

public static final Parcelable.Creator<BatteryProperties> CREATOR
Expand Down
Loading

0 comments on commit 81b0777

Please sign in to comment.