pull/2468/head
kunfei 3 years ago
parent b6a6a58bcc
commit f8d3447e86
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 3
      app/src/main/java/io/legado/app/help/storage/BackupConfig.kt
  3. 11
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  4. 10
      app/src/main/java/io/legado/app/service/WebService.kt
  5. 2
      app/src/main/res/values-es-rES/strings.xml
  6. 2
      app/src/main/res/values-ja-rJP/strings.xml
  7. 2
      app/src/main/res/values-pt-rBR/strings.xml
  8. 2
      app/src/main/res/values-zh-rHK/strings.xml
  9. 2
      app/src/main/res/values-zh-rTW/strings.xml
  10. 2
      app/src/main/res/values-zh/strings.xml
  11. 2
      app/src/main/res/values/strings.xml
  12. 6
      app/src/main/res/xml/pref_config_other.xml

@ -119,6 +119,7 @@ object PreferKey {
const val ttsTimer = "ttsTimer" const val ttsTimer = "ttsTimer"
const val noAnimScrollPage = "noAnimScrollPage" const val noAnimScrollPage = "noAnimScrollPage"
const val webDavDeviceName = "webDavDeviceName" const val webDavDeviceName = "webDavDeviceName"
const val wakeLock = "wakeLock"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"

@ -31,7 +31,8 @@ object BackupConfig {
PreferKey.webDavAccount, PreferKey.webDavAccount,
PreferKey.webDavPassword, PreferKey.webDavPassword,
PreferKey.launcherIcon, PreferKey.launcherIcon,
PreferKey.bitmapCacheSize PreferKey.bitmapCacheSize,
PreferKey.wakeLock
) )
//配置忽略标题 //配置忽略标题

@ -9,7 +9,6 @@ import android.content.IntentFilter
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.media.AudioManager import android.media.AudioManager
import android.os.Bundle import android.os.Bundle
import android.os.PowerManager
import android.support.v4.media.session.MediaSessionCompat import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat import android.support.v4.media.session.PlaybackStateCompat
import androidx.annotation.CallSuper import androidx.annotation.CallSuper
@ -29,7 +28,6 @@ import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import splitties.systemservices.audioManager import splitties.systemservices.audioManager
import splitties.systemservices.powerManager
/** /**
* 朗读服务 * 朗读服务
@ -55,11 +53,6 @@ abstract class BaseReadAloudService : BaseService(),
} }
} }
private val wakeLock by lazy {
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "legado:readAloud").apply {
setReferenceCounted(false)
}
}
private val mFocusRequest: AudioFocusRequestCompat by lazy { private val mFocusRequest: AudioFocusRequestCompat by lazy {
MediaHelp.buildAudioFocusRequestCompat(this) MediaHelp.buildAudioFocusRequestCompat(this)
} }
@ -85,7 +78,6 @@ abstract class BaseReadAloudService : BaseService(),
@SuppressLint("WakelockTimeout") @SuppressLint("WakelockTimeout")
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
wakeLock.acquire()
isRun = true isRun = true
pause = false pause = false
observeLiveBus() observeLiveBus()
@ -107,7 +99,6 @@ abstract class BaseReadAloudService : BaseService(),
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
wakeLock.release()
isRun = false isRun = false
pause = true pause = true
abandonFocus() abandonFocus()
@ -176,7 +167,6 @@ abstract class BaseReadAloudService : BaseService(),
postEvent(EventBus.ALOUD_STATE, Status.PAUSE) postEvent(EventBus.ALOUD_STATE, Status.PAUSE)
ReadBook.uploadProgress() ReadBook.uploadProgress()
doDs() doDs()
wakeLock.release()
} }
@SuppressLint("WakelockTimeout") @SuppressLint("WakelockTimeout")
@ -185,7 +175,6 @@ abstract class BaseReadAloudService : BaseService(),
pause = false pause = false
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
postEvent(EventBus.ALOUD_STATE, Status.PLAY) postEvent(EventBus.ALOUD_STATE, Status.PLAY)
wakeLock.acquire()
} }
abstract fun upSpeechRate(reset: Boolean = false) abstract fun upSpeechRate(reset: Boolean = false)

@ -16,6 +16,7 @@ import io.legado.app.receiver.NetworkChangedListener
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.web.HttpServer import io.legado.app.web.HttpServer
import io.legado.app.web.WebSocketServer import io.legado.app.web.WebSocketServer
import splitties.init.appCtx
import splitties.systemservices.powerManager import splitties.systemservices.powerManager
import java.io.IOException import java.io.IOException
@ -36,6 +37,7 @@ class WebService : BaseService() {
} }
private val useWakeLock = appCtx.getPrefBoolean(PreferKey.wakeLock, false)
private val wakeLock by lazy { private val wakeLock by lazy {
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "legado:webService") powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "legado:webService")
} }
@ -49,7 +51,9 @@ class WebService : BaseService() {
@SuppressLint("WakelockTimeout") @SuppressLint("WakelockTimeout")
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
wakeLock.acquire() if (useWakeLock) {
wakeLock.acquire()
}
isRun = true isRun = true
notificationContent = getString(R.string.service_starting) notificationContent = getString(R.string.service_starting)
upNotification() upNotification()
@ -81,7 +85,9 @@ class WebService : BaseService() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
wakeLock.release() if (useWakeLock) {
wakeLock.release()
}
networkChangedListener.unRegister() networkChangedListener.unRegister()
isRun = false isRun = false
if (httpServer?.isAlive == true) { if (httpServer?.isAlive == true) {

@ -1045,4 +1045,6 @@
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string> <string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
<string name="no_anim_scroll_page">禁用滚动点击动画</string> <string name="no_anim_scroll_page">禁用滚动点击动画</string>
<string name="webdav_device_name">设备名称</string> <string name="webdav_device_name">设备名称</string>
<string name="wake_lock">唤醒锁</string>
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
</resources> </resources>

@ -1048,4 +1048,6 @@
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string> <string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
<string name="no_anim_scroll_page">禁用滚动点击动画</string> <string name="no_anim_scroll_page">禁用滚动点击动画</string>
<string name="webdav_device_name">设备名称</string> <string name="webdav_device_name">设备名称</string>
<string name="wake_lock">唤醒锁</string>
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
</resources> </resources>

@ -1048,4 +1048,6 @@
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string> <string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
<string name="no_anim_scroll_page">禁用滚动点击动画</string> <string name="no_anim_scroll_page">禁用滚动点击动画</string>
<string name="webdav_device_name">设备名称</string> <string name="webdav_device_name">设备名称</string>
<string name="wake_lock">唤醒锁</string>
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
</resources> </resources>

@ -1045,4 +1045,6 @@
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string> <string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
<string name="no_anim_scroll_page">禁用滚动点击动画</string> <string name="no_anim_scroll_page">禁用滚动点击动画</string>
<string name="webdav_device_name">设备名称</string> <string name="webdav_device_name">设备名称</string>
<string name="wake_lock">唤醒锁</string>
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
</resources> </resources>

@ -1047,4 +1047,6 @@
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string> <string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
<string name="no_anim_scroll_page">禁用滚动点击动画</string> <string name="no_anim_scroll_page">禁用滚动点击动画</string>
<string name="webdav_device_name">设备名称</string> <string name="webdav_device_name">设备名称</string>
<string name="wake_lock">唤醒锁</string>
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
</resources> </resources>

@ -1047,4 +1047,6 @@
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string> <string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
<string name="no_anim_scroll_page">禁用滚动点击动画</string> <string name="no_anim_scroll_page">禁用滚动点击动画</string>
<string name="webdav_device_name">设备名称</string> <string name="webdav_device_name">设备名称</string>
<string name="wake_lock">唤醒锁</string>
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
</resources> </resources>

@ -1048,4 +1048,6 @@
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string> <string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
<string name="no_anim_scroll_page">禁用滚动点击动画</string> <string name="no_anim_scroll_page">禁用滚动点击动画</string>
<string name="webdav_device_name">设备名称</string> <string name="webdav_device_name">设备名称</string>
<string name="wake_lock">唤醒锁</string>
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
</resources> </resources>

@ -56,6 +56,12 @@
android:key="userAgent" android:key="userAgent"
android:title="@string/user_agent" /> android:title="@string/user_agent" />
<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false"
android:key="wakeLock"
android:title="@string/wake_lock"
android:summary="@string/wake_lock_summary" />
<io.legado.app.lib.prefs.Preference <io.legado.app.lib.prefs.Preference
android:key="defaultBookTreeUri" android:key="defaultBookTreeUri"
android:summary="@string/book_tree_uri_s" android:summary="@string/book_tree_uri_s"

Loading…
Cancel
Save