Remove REQUEST_IGNORE_BATTERY_OPTIMIZATIONS feature

This commit is contained in:
Koitharu
2021-01-29 07:20:10 +02:00
parent 33296217a4
commit c64115a268
7 changed files with 7 additions and 71 deletions

View File

@@ -11,7 +11,6 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<application
android:name="org.koitharu.kotatsu.KotatsuApp"

View File

@@ -176,7 +176,6 @@ class AppSettings private constructor(private val prefs: SharedPreferences) :
const val KEY_BACKUP = "backup"
const val KEY_RESTORE = "restore"
const val KEY_HISTORY_GROUPING = "history_grouping"
const val KEY_DOZE_WHITELIST = "doze_whitelist"
const val KEY_REVERSE_CHAPTERS = "reverse_chapters"
}
}

View File

@@ -1,17 +1,11 @@
package org.koitharu.kotatsu.settings
import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.PowerManager
import android.provider.Settings
import androidx.preference.MultiSelectListPreference
import androidx.preference.Preference
import com.google.android.material.snackbar.Snackbar
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.ui.BasePreferenceFragment
import org.koitharu.kotatsu.core.prefs.AppSettings
@@ -25,8 +19,6 @@ class TrackerSettingsFragment : BasePreferenceFragment(R.string.new_chapters_che
findPreference<MultiSelectListPreference>(AppSettings.KEY_TRACK_SOURCES)
?.summaryProvider = MultiSummaryProvider(R.string.dont_check)
findPreference<Preference>(AppSettings.KEY_DOZE_WHITELIST)
?.isVisible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
}
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
@@ -42,45 +34,7 @@ class TrackerSettingsFragment : BasePreferenceFragment(R.string.new_chapters_che
}
true
}
AppSettings.KEY_DOZE_WHITELIST -> {
disablePowerOptimization()
true
}
else -> super.onPreferenceTreeClick(preference)
}
}
@SuppressLint("BatteryLife")
private fun disablePowerOptimization() {
val context = context ?: return
val powerManager = context.getSystemService(Context.POWER_SERVICE) as? PowerManager
if (powerManager == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
Snackbar.make(
listView ?: return,
R.string.operation_not_supported,
Snackbar.LENGTH_LONG
).show()
return
}
val packageName = context.packageName
if (!powerManager.isIgnoringBatteryOptimizations(packageName)) {
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.setData(Uri.parse("package:$packageName"))
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
Snackbar.make(
listView ?: return,
R.string.operation_not_supported,
Snackbar.LENGTH_LONG
).show()
}
} else {
Snackbar.make(
listView ?: return,
R.string.power_optimization_already_disabled,
Snackbar.LENGTH_LONG
).show()
}
}
}

View File

@@ -52,9 +52,7 @@ class TrackWorker(context: Context, workerParams: WorkerParameters) :
if (tracks.isEmpty()) {
return Result.success()
}
if (tracks.size >= FOREGROUND_TRACKERS_THRESHOLD) {
setForeground(createForegroundInfo())
}
setForeground(createForegroundInfo())
var success = 0
val workData = Data.Builder()
.putInt(DATA_TOTAL, tracks.size)
@@ -204,8 +202,11 @@ class TrackWorker(context: Context, workerParams: WorkerParameters) :
private fun createForegroundInfo(): ForegroundInfo {
val title = applicationContext.getString(R.string.new_chapters_checking)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel =
NotificationChannel(WORKER_CHANNEL_ID, title, NotificationManager.IMPORTANCE_NONE)
val channel = NotificationChannel(
WORKER_CHANNEL_ID,
title,
NotificationManager.IMPORTANCE_LOW
)
channel.setShowBadge(false)
channel.enableVibration(false)
channel.setSound(null, null)
@@ -235,7 +236,6 @@ class TrackWorker(context: Context, workerParams: WorkerParameters) :
private const val DATA_PROGRESS = "progress"
private const val DATA_TOTAL = "total"
private const val TAG = "tracking"
private const val FOREGROUND_TRACKERS_THRESHOLD = 4
@RequiresApi(Build.VERSION_CODES.O)
private fun createNotificationChannel(context: Context) {

View File

@@ -195,9 +195,6 @@
<string name="chapers_checking_progress">Проверка новых глав: %1$d из %2$d</string>
<string name="clear_feed">Очистить ленту</string>
<string name="text_clear_updates_feed_prompt">Вся история обновлений будет очищена и её нельзя будет вернуть. Вы уверены?</string>
<string name="power_optimization_simmary">Может помочь с фоновыми операциями. Используйте только если фоновая проверка новых глав не работает</string>
<string name="disable_power_optimization">Отключить оптимизацию батареи</string>
<string name="power_optimization_already_disabled">Отпимизация батареи уже отключена</string>
<string name="new_chapters_checking">Проверка новых глав</string>
<string name="reverse">В обратном порядке</string>
<string name="sign_in">Войти</string>

View File

@@ -197,9 +197,6 @@
<string name="chapers_checking_progress">Checking for new chapters: %1$d of %2$d</string>
<string name="clear_feed">Clear feed</string>
<string name="text_clear_updates_feed_prompt">All updates history will be cleared and this action cannot be undone. Are you sure?</string>
<string name="power_optimization_already_disabled">Power optimization is already disabled</string>
<string name="power_optimization_simmary">Helps with background operations such as checking for new chapters. Use only if you have a troubles with it</string>
<string name="disable_power_optimization">Disable power optimization</string>
<string name="new_chapters_checking">New chapters checking</string>
<string name="reverse">Reverse</string>
<string name="sign_in">Sign in</string>

View File

@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
xmlns:app="http://schemas.android.com/apk/res-auto">
<MultiSelectListPreference
android:defaultValue="@array/values_track_sources_default"
@@ -12,15 +11,6 @@
android:title="@string/track_sources"
app:iconSpaceReserved="false" />
<Preference
android:key="doze_whitelist"
android:persistent="false"
android:summary="@string/power_optimization_simmary"
android:title="@string/disable_power_optimization"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false"
tools:isPreferenceVisible="true" />
<SwitchPreference
android:defaultValue="true"
android:key="tracker_notifications"