Loading src/org/lineageos/updater/UpdatesListAdapter.java +1 −22 Original line number Diff line number Diff line Loading @@ -16,10 +16,8 @@ package org.lineageos.updater; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.res.Resources; import android.os.BatteryManager; import android.os.PowerManager; import android.text.SpannableString; import android.text.format.Formatter; Loading Loading @@ -68,10 +66,6 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. private static final String TAG = "UpdateListAdapter"; private static final int BATTERY_PLUGGED_ANY = BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB | BatteryManager.BATTERY_PLUGGED_WIRELESS; private final float mAlphaDisabledValue; private List<String> mDownloadIds; Loading Loading @@ -494,7 +488,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. private AlertDialog.Builder getInstallDialog(final String downloadId) { Resources resources = mActivity.getResources(); if (!isBatteryLevelOk()) { if (!Utils.isBatteryLevelOk(mActivity)) { String message = resources.getString(R.string.dialog_battery_low_message_pct, resources.getInteger(R.integer.battery_ok_percentage_discharging), resources.getInteger(R.integer.battery_ok_percentage_charging)); Loading Loading @@ -618,19 +612,4 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. textView.setMovementMethod(LinkMovementMethod.getInstance()); } } private boolean isBatteryLevelOk() { Intent intent = mActivity.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (!intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)) { return true; } int percent = Math.round(100.f * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100) / intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100)); int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0); int required = (plugged & BATTERY_PLUGGED_ANY) != 0 ? mActivity.getResources().getInteger(R.integer.battery_ok_percentage_charging) : mActivity.getResources().getInteger(R.integer.battery_ok_percentage_discharging); return percent >= required; } } src/org/lineageos/updater/misc/Utils.java +22 −1 Original line number Diff line number Diff line Loading @@ -22,11 +22,11 @@ import static android.os.SystemUpdateManager.STATUS_IDLE; import static android.os.SystemUpdateManager.STATUS_WAITING_DOWNLOAD; import android.app.AlarmManager; import android.os.Build; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.database.Cursor; Loading @@ -34,6 +34,8 @@ import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkCapabilities; import android.net.Uri; import android.os.BatteryManager; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.PersistableBundle; Loading Loading @@ -72,6 +74,10 @@ import java.util.zip.ZipFile; public class Utils { private static final int BATTERY_PLUGGED_ANY = BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB | BatteryManager.BATTERY_PLUGGED_WIRELESS; private static final String TAG = "Utils"; private static final String CONTENT_URI_PATH = "content://custom.setting.Provider.OTA_SERVER/cte"; Loading Loading @@ -543,6 +549,21 @@ public class Utils { return new File(Constants.UPDATE_RECOVERY_EXEC).exists(); } public static boolean isBatteryLevelOk(Context context) { Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (!intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)) { return true; } int percent = Math.round(100.f * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100) / intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100)); int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0); int required = (plugged & BATTERY_PLUGGED_ANY) != 0 ? context.getResources().getInteger(R.integer.battery_ok_percentage_charging) : context.getResources().getInteger(R.integer.battery_ok_percentage_discharging); return percent >= required; } public static void updateSystemUpdaterService(Context context, int status, String version) { final SystemUpdateManager updateManager = context.getSystemService(SystemUpdateManager.class); Loading Loading
src/org/lineageos/updater/UpdatesListAdapter.java +1 −22 Original line number Diff line number Diff line Loading @@ -16,10 +16,8 @@ package org.lineageos.updater; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.res.Resources; import android.os.BatteryManager; import android.os.PowerManager; import android.text.SpannableString; import android.text.format.Formatter; Loading Loading @@ -68,10 +66,6 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. private static final String TAG = "UpdateListAdapter"; private static final int BATTERY_PLUGGED_ANY = BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB | BatteryManager.BATTERY_PLUGGED_WIRELESS; private final float mAlphaDisabledValue; private List<String> mDownloadIds; Loading Loading @@ -494,7 +488,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. private AlertDialog.Builder getInstallDialog(final String downloadId) { Resources resources = mActivity.getResources(); if (!isBatteryLevelOk()) { if (!Utils.isBatteryLevelOk(mActivity)) { String message = resources.getString(R.string.dialog_battery_low_message_pct, resources.getInteger(R.integer.battery_ok_percentage_discharging), resources.getInteger(R.integer.battery_ok_percentage_charging)); Loading Loading @@ -618,19 +612,4 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. textView.setMovementMethod(LinkMovementMethod.getInstance()); } } private boolean isBatteryLevelOk() { Intent intent = mActivity.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (!intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)) { return true; } int percent = Math.round(100.f * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100) / intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100)); int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0); int required = (plugged & BATTERY_PLUGGED_ANY) != 0 ? mActivity.getResources().getInteger(R.integer.battery_ok_percentage_charging) : mActivity.getResources().getInteger(R.integer.battery_ok_percentage_discharging); return percent >= required; } }
src/org/lineageos/updater/misc/Utils.java +22 −1 Original line number Diff line number Diff line Loading @@ -22,11 +22,11 @@ import static android.os.SystemUpdateManager.STATUS_IDLE; import static android.os.SystemUpdateManager.STATUS_WAITING_DOWNLOAD; import android.app.AlarmManager; import android.os.Build; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.database.Cursor; Loading @@ -34,6 +34,8 @@ import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkCapabilities; import android.net.Uri; import android.os.BatteryManager; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.PersistableBundle; Loading Loading @@ -72,6 +74,10 @@ import java.util.zip.ZipFile; public class Utils { private static final int BATTERY_PLUGGED_ANY = BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB | BatteryManager.BATTERY_PLUGGED_WIRELESS; private static final String TAG = "Utils"; private static final String CONTENT_URI_PATH = "content://custom.setting.Provider.OTA_SERVER/cte"; Loading Loading @@ -543,6 +549,21 @@ public class Utils { return new File(Constants.UPDATE_RECOVERY_EXEC).exists(); } public static boolean isBatteryLevelOk(Context context) { Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (!intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)) { return true; } int percent = Math.round(100.f * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100) / intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100)); int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0); int required = (plugged & BATTERY_PLUGGED_ANY) != 0 ? context.getResources().getInteger(R.integer.battery_ok_percentage_charging) : context.getResources().getInteger(R.integer.battery_ok_percentage_discharging); return percent >= required; } public static void updateSystemUpdaterService(Context context, int status, String version) { final SystemUpdateManager updateManager = context.getSystemService(SystemUpdateManager.class); Loading