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

Commit 910397f2 authored by Jorge Ruesga's avatar Jorge Ruesga Committed by Gerrit Code Review
Browse files

base: dock battery



Change-Id: I8cc3fc465daa49c9010bdbbf876dae18461d7024
Require: topic:dock_battery
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent c2614beb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,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 \
+3 −1
Original line number Diff line number Diff line
@@ -436,7 +436,9 @@ class ContextImpl extends Context {

        registerService(BATTERY_SERVICE, new ServiceFetcher() {
                public Object createService(ContextImpl ctx) {
                    return new BatteryManager();
                    IBinder b = ServiceManager.getService(BATTERY_SERVICE);
                    IBatteryService service = IBatteryService.Stub.asInterface(b);
                    return new BatteryManager(service);
                }});

        registerService(NFC_SERVICE, new ServiceFetcher() {
+26 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2015, 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();
}
+156 −4
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 The Android Open Source Project
 * Copyright (C) 2015 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.
@@ -16,6 +17,8 @@

package android.os;

import android.app.IBatteryService;
import android.content.Context;
import android.os.BatteryProperty;
import android.os.IBatteryPropertiesRegistrar;
import android.os.RemoteException;
@@ -91,6 +94,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
@@ -124,10 +200,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;

    /*
     * Battery property identifiers.  These must match the values in
     * frameworks/native/include/batteryservice/BatteryService.h
@@ -162,15 +251,38 @@ public class BatteryManager {
     */
    public static final int BATTERY_PROPERTY_ENERGY_COUNTER = 5;

    private final IBatteryService mBatteryService;
    private IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar;

    public BatteryManager() {
        this(null);
    }

    /** @hide */
    public BatteryManager(IBatteryService service) {
        super();
        mBatteryService = service;
    }

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

    /**
     * Query a battery property from the batteryproperties service.
     *
     * 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) {
@@ -185,7 +297,13 @@ public class BatteryManager {
        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;
@@ -206,7 +324,7 @@ public class BatteryManager {
     * @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);
    }

    /**
@@ -219,6 +337,40 @@ public class BatteryManager {
     * @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 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 * Copyright (C) 2015 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.
@@ -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.
     */
Loading