Loading core/java/android/app/SystemServiceRegistry.java +3 −3 Original line number Diff line number Diff line Loading @@ -304,14 +304,14 @@ final class SystemServiceRegistry { }}); registerService(Context.BATTERY_SERVICE, BatteryManager.class, new StaticServiceFetcher<BatteryManager>() { new CachedServiceFetcher<BatteryManager>() { @Override public BatteryManager createService() throws ServiceNotFoundException { public BatteryManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBatteryStats stats = IBatteryStats.Stub.asInterface( ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME)); IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub .asInterface(ServiceManager.getServiceOrThrow("batteryproperties")); return new BatteryManager(stats, registrar); return new BatteryManager(ctx, stats, registrar); }}); registerService(Context.NFC_SERVICE, NfcManager.class, Loading core/java/android/os/BatteryManager.java +27 −15 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.os; import android.annotation.SystemService; import android.content.Context; import android.hardware.health.V1_0.Constants; import com.android.internal.app.IBatteryStats; /** Loading Loading @@ -216,6 +217,7 @@ public class BatteryManager { */ public static final int BATTERY_PROPERTY_STATUS = 6; private final Context mContext; private final IBatteryStats mBatteryStats; private final IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar; Loading @@ -223,6 +225,7 @@ public class BatteryManager { * @removed Was previously made visible by accident. */ public BatteryManager() { mContext = null; mBatteryStats = IBatteryStats.Stub.asInterface( ServiceManager.getService(BatteryStats.SERVICE_NAME)); mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar.Stub.asInterface( Loading @@ -230,8 +233,10 @@ public class BatteryManager { } /** {@hide} */ public BatteryManager(IBatteryStats batteryStats, public BatteryManager(Context context, IBatteryStats batteryStats, IBatteryPropertiesRegistrar batteryPropertiesRegistrar) { mContext = context; mBatteryStats = batteryStats; mBatteryPropertiesRegistrar = batteryPropertiesRegistrar; } Loading Loading @@ -278,16 +283,23 @@ public class BatteryManager { } /** * Return the value of a battery property of integer type. If the * platform does not provide the property queried, this value will * be Integer.MIN_VALUE. * Return the value of a battery property of integer type. * * @param id identifier of the requested property * * @return the property value, or Integer.MIN_VALUE if not supported. * @return the property value. If the property is not supported or there is any other error, * return (a) 0 if {@code targetSdkVersion < VERSION_CODES.P} or (b) Integer.MIN_VALUE * if {@code targetSdkVersion >= VERSION_CODES.P}. */ public int getIntProperty(int id) { return (int)queryProperty(id); long value = queryProperty(id); if (value == Long.MIN_VALUE && mContext != null && mContext.getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.P) { return Integer.MIN_VALUE; } return (int) value; } /** Loading Loading
core/java/android/app/SystemServiceRegistry.java +3 −3 Original line number Diff line number Diff line Loading @@ -304,14 +304,14 @@ final class SystemServiceRegistry { }}); registerService(Context.BATTERY_SERVICE, BatteryManager.class, new StaticServiceFetcher<BatteryManager>() { new CachedServiceFetcher<BatteryManager>() { @Override public BatteryManager createService() throws ServiceNotFoundException { public BatteryManager createService(ContextImpl ctx) throws ServiceNotFoundException { IBatteryStats stats = IBatteryStats.Stub.asInterface( ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME)); IBatteryPropertiesRegistrar registrar = IBatteryPropertiesRegistrar.Stub .asInterface(ServiceManager.getServiceOrThrow("batteryproperties")); return new BatteryManager(stats, registrar); return new BatteryManager(ctx, stats, registrar); }}); registerService(Context.NFC_SERVICE, NfcManager.class, Loading
core/java/android/os/BatteryManager.java +27 −15 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.os; import android.annotation.SystemService; import android.content.Context; import android.hardware.health.V1_0.Constants; import com.android.internal.app.IBatteryStats; /** Loading Loading @@ -216,6 +217,7 @@ public class BatteryManager { */ public static final int BATTERY_PROPERTY_STATUS = 6; private final Context mContext; private final IBatteryStats mBatteryStats; private final IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar; Loading @@ -223,6 +225,7 @@ public class BatteryManager { * @removed Was previously made visible by accident. */ public BatteryManager() { mContext = null; mBatteryStats = IBatteryStats.Stub.asInterface( ServiceManager.getService(BatteryStats.SERVICE_NAME)); mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar.Stub.asInterface( Loading @@ -230,8 +233,10 @@ public class BatteryManager { } /** {@hide} */ public BatteryManager(IBatteryStats batteryStats, public BatteryManager(Context context, IBatteryStats batteryStats, IBatteryPropertiesRegistrar batteryPropertiesRegistrar) { mContext = context; mBatteryStats = batteryStats; mBatteryPropertiesRegistrar = batteryPropertiesRegistrar; } Loading Loading @@ -278,16 +283,23 @@ public class BatteryManager { } /** * Return the value of a battery property of integer type. If the * platform does not provide the property queried, this value will * be Integer.MIN_VALUE. * Return the value of a battery property of integer type. * * @param id identifier of the requested property * * @return the property value, or Integer.MIN_VALUE if not supported. * @return the property value. If the property is not supported or there is any other error, * return (a) 0 if {@code targetSdkVersion < VERSION_CODES.P} or (b) Integer.MIN_VALUE * if {@code targetSdkVersion >= VERSION_CODES.P}. */ public int getIntProperty(int id) { return (int)queryProperty(id); long value = queryProperty(id); if (value == Long.MIN_VALUE && mContext != null && mContext.getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.P) { return Integer.MIN_VALUE; } return (int) value; } /** Loading