1 package org.robolectric.shadows; 2 3 import static android.os.Build.VERSION_CODES.LOLLIPOP; 4 import static android.os.Build.VERSION_CODES.M; 5 6 import android.os.BatteryManager; 7 import java.util.HashMap; 8 import java.util.Map; 9 import org.robolectric.annotation.Implementation; 10 import org.robolectric.annotation.Implements; 11 12 @Implements(BatteryManager.class) 13 public class ShadowBatteryManager { 14 private boolean isCharging = false; 15 private final Map<Integer, Long> longProperties = new HashMap<>(); 16 private final Map<Integer, Integer> intProperties = new HashMap<>(); 17 18 @Implementation(minSdk = M) isCharging()19 protected boolean isCharging() { 20 return isCharging; 21 } 22 setIsCharging(boolean charging)23 public void setIsCharging(boolean charging) { 24 isCharging = charging; 25 } 26 27 @Implementation(minSdk = LOLLIPOP) getIntProperty(int id)28 protected int getIntProperty(int id) { 29 return intProperties.containsKey(id) ? intProperties.get(id) : Integer.MIN_VALUE; 30 } 31 setIntProperty(int id, int value)32 public void setIntProperty(int id, int value) { 33 intProperties.put(id, value); 34 } 35 36 @Implementation(minSdk = LOLLIPOP) getLongProperty(int id)37 protected long getLongProperty(int id) { 38 return longProperties.containsKey(id) ? longProperties.get(id) : Long.MIN_VALUE; 39 } 40 setLongProperty(int id, long value)41 public void setLongProperty(int id, long value) { 42 longProperties.put(id, value); 43 } 44 } 45