fix bgutils when switching processes and exiting from notification

pull/1366/head
deniscerri 3 days ago
parent 861f7a8a5e
commit 80135d64c2
No known key found for this signature in database
GPG Key ID: 95C43D517D830350

@ -38,6 +38,14 @@ class App : Application() {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this@App)
setDefaultValues()
ThemeUtil.init(this)
val processName = getProcessNameImpl()
if (processName.endsWith(":incognito_process") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WebView.setDataDirectorySuffix("incognito_store")
return
}
applicationScope = CoroutineScope(SupervisorJob())
applicationScope.launch((Dispatchers.IO)) {
try {
@ -63,16 +71,6 @@ class App : Application() {
if (requiresServer) {
BgUtilsPoTokenGeneratorUtil.acquireServer(this@App)
}
val processName = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getProcessName()
} else {
packageName
}
if (processName.endsWith(":incognito_process") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WebView.setDataDirectorySuffix("incognito_store")
}
}catch (e: Exception){
Looper.prepare().runCatching {
Toast.makeText(this@App, e.message, Toast.LENGTH_SHORT).show()
@ -80,7 +78,6 @@ class App : Application() {
e.printStackTrace()
}
}
ThemeUtil.init(this)
}
@Throws(ExecuteException::class)
private fun initLibraries() {
@ -108,6 +105,14 @@ class App : Application() {
notificationUtil.createNotificationChannel()
}
private fun getProcessNameImpl() : String {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getProcessName()
} else {
packageName
}
}
companion object {
private const val TAG = "App"
private lateinit var applicationScope: CoroutineScope

@ -65,6 +65,7 @@ class BgUtilsPoTokenGeneratorService : Service() {
val runtimeManager = RuntimeManager.getInstance()
if (intent?.action == "ACTION_EXIT") {
BgUtilsPoTokenGeneratorUtil.resetState()
runtimeManager.destroyProcessById(currentRunningProcess)
stopForeground(STOP_FOREGROUND_REMOVE)
stopSelf()

@ -172,6 +172,11 @@ object BgUtilsPoTokenGeneratorUtil {
}
}
fun resetState() {
activeJobCount.set(0)
shutdownJob = null
}
fun releaseServer(context: Context, idleDelayMs: Long = 5000) {
if (activeJobCount.decrementAndGet() <= 0) {
activeJobCount.set(0)

Loading…
Cancel
Save