Updater: Move battery level check to UpdatesListAdapter
* We cannot create dialog from service level without hardcoding theme resource and granting SYSTEM_ALERT_WINDOW permission therefore we got to move it here. Change-Id: I70ee5d6c8ef4af4f5c6f29e593b1c20797781017
This commit is contained in:
@@ -17,6 +17,7 @@ package org.lineageos.updater;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.BatteryManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
@@ -422,6 +423,12 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
}
|
||||
|
||||
private AlertDialog.Builder getInstallDialog(final String downloadId) {
|
||||
if (!isBatteryLevelOk()) {
|
||||
return new AlertDialog.Builder(mActivity)
|
||||
.setTitle(R.string.dialog_battery_low_title)
|
||||
.setMessage(R.string.dialog_battery_low_message)
|
||||
.setPositiveButton(android.R.string.ok, null);
|
||||
}
|
||||
UpdateInfo update = mUpdaterController.getUpdate(downloadId);
|
||||
int resId;
|
||||
try {
|
||||
@@ -529,4 +536,10 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
||||
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
|
||||
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
private boolean isBatteryLevelOk() {
|
||||
BatteryManager bm = mActivity.getSystemService(BatteryManager.class);
|
||||
int percent = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
||||
return percent >= mActivity.getResources().getInteger(R.integer.battery_ok_percentage);
|
||||
}
|
||||
}
|
||||
|
@@ -17,10 +17,8 @@ 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;
|
||||
|
||||
@@ -68,27 +66,12 @@ 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