Requre a minimum remaining battery capacity to install updates
The recovery doesn't install the update if the remaining battery capacity isn't at least 20% (or 15% if charging). Require at least 40%, just to be safe. Change-Id: I5cd7c40f029141cde2b0922b25fece2b55989710
This commit is contained in:
@@ -17,11 +17,14 @@ package org.lineageos.updater.controller;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.SystemClock;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.lineageos.updater.R;
|
||||
import org.lineageos.updater.misc.Constants;
|
||||
import org.lineageos.updater.misc.FileUtils;
|
||||
import org.lineageos.updater.misc.Utils;
|
||||
@@ -65,12 +68,27 @@ class UpdateInstaller {
|
||||
return sInstallingUpdate != null && sInstallingUpdate.equals(downloadId);
|
||||
}
|
||||
|
||||
private static boolean isBatteryLevelOk(Context context) {
|
||||
BatteryManager bm = context.getSystemService(BatteryManager.class);
|
||||
int percent = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
||||
return percent >= context.getResources().getInteger(R.integer.battery_ok_percentage);
|
||||
}
|
||||
|
||||
void install(String downloadId) {
|
||||
if (isInstalling()) {
|
||||
Log.e(TAG, "Already installing an update");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isBatteryLevelOk(mContext)) {
|
||||
new AlertDialog.Builder(mContext)
|
||||
.setTitle(R.string.dialog_battery_low_title)
|
||||
.setMessage(R.string.dialog_battery_low_message)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateInfo update = mUpdaterController.getUpdate(downloadId);
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
long buildTimestamp = SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0);
|
||||
|
Reference in New Issue
Block a user