Merge pull request #4398 from talregev/TalR_run_boinc_after_boot

[Android] Run boinc after boot
This commit is contained in:
Vitalii Koshura 2021-06-10 01:00:49 +02:00 committed by GitHub
commit fbeca5d11b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 8 deletions

View File

@ -27,8 +27,9 @@
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" /> <!-- Required Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
@ -122,20 +123,24 @@
android:process=":remote" />
<service android:name=".attach.ProjectAttachService" />
<receiver android:name=".receiver.BootReceiver">
<receiver android:name=".receiver.BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver android:name=".receiver.PowerConnectedReceiver">
<intent-filter>
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver android:name=".receiver.PackageReplacedReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:path="edu.berkeley.boinc"
android:scheme="package" />

View File

@ -21,6 +21,7 @@ package edu.berkeley.boinc.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import edu.berkeley.boinc.client.AppPreferences
import edu.berkeley.boinc.client.Monitor
@ -33,7 +34,11 @@ class BootReceiver : BroadcastReceiver() {
if (prefs.autostart) {
Log.d(Logging.TAG, "BootReceiver autostart enabled, start Monitor...")
context.startService(Intent(context, Monitor::class.java))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(Intent(context, Monitor::class.java))
} else {
context.startService(Intent(context, Monitor::class.java))
}
} else {
// do nothing
Log.d(Logging.TAG, "BootReceiver autostart disabled - do nothing")
@ -53,7 +58,11 @@ class PackageReplacedReceiver : BroadcastReceiver() {
if (intent.action == Intent.ACTION_PACKAGE_REPLACED) {
if (intent.dataString.toString().contains("edu.berkeley.boinc")) {
Log.d(Logging.TAG, "PackageReplacedReceiver: starting service...")
context.startService(Intent(context, Monitor::class.java))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(Intent(context, Monitor::class.java))
} else {
context.startService(Intent(context, Monitor::class.java))
}
} else {
Log.d(Logging.TAG, "PackageReplacedReceiver: other package: " + intent.dataString)
}
@ -65,8 +74,11 @@ class PowerConnectedReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_POWER_CONNECTED) {
Log.d(Logging.TAG, "power connected, start service...")
context.startService(Intent(context, Monitor::class.java))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(Intent(context, Monitor::class.java))
} else {
context.startService(Intent(context, Monitor::class.java))
}
}
}
}