Skip to content

Commit

Permalink
no need for the if as 21 is min already
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Feb 19, 2024
1 parent e8b4e5f commit 08c995b
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public class PlatformModule extends KrollModule
private int versionMinor;
private int versionPatch;
protected int batteryState;
protected double batteryLevel;
protected boolean batteryStateReady;

protected BroadcastReceiver batteryStateReceiver;
Expand All @@ -87,7 +86,6 @@ public PlatformModule()
super();

batteryState = BATTERY_STATE_UNKNOWN;
batteryLevel = -1;

// Extract "<major>.<minor>" integers from OS version string.
String[] versionComponents = Build.VERSION.RELEASE.split("\\.");
Expand Down Expand Up @@ -414,14 +412,10 @@ public int getBatteryState()
@Kroll.getProperty
public double getBatteryLevel()
{
if (Build.VERSION.SDK_INT >= 21) {
Context context = TiApplication.getInstance().getApplicationContext();
BatteryManager bm = (BatteryManager) context.getSystemService(BATTERY_SERVICE);
int batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
return batLevel;
} else {
return batteryLevel;
}
Context context = TiApplication.getInstance().getApplicationContext();
BatteryManager bm = (BatteryManager) context.getSystemService(BATTERY_SERVICE);
int batLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
return batLevel;
}

@Kroll.getProperty
Expand Down Expand Up @@ -511,7 +505,7 @@ protected void registerBatteryStateReceiver()
public void onReceive(Context context, Intent intent)
{
int scale = intent.getIntExtra(TiC.PROPERTY_SCALE, -1);
batteryLevel = convertBatteryLevel(intent.getIntExtra(TiC.PROPERTY_LEVEL, -1), scale);
double batteryLevel = convertBatteryLevel(intent.getIntExtra(TiC.PROPERTY_LEVEL, -1), scale);
batteryState = convertBatteryStatus(intent.getIntExtra(TiC.PROPERTY_STATUS, -1));

KrollDict event = new KrollDict();
Expand Down

0 comments on commit 08c995b

Please sign in to comment.