Skip to content

Commit

Permalink
Switch DirectBootMigrationService to a background service
Browse files Browse the repository at this point in the history
There seem to be two issues with the foreground service:

* Some Android builds seem to be broken and throw a
  ForegroundServiceDidNotStartInTimeException even though the service
  unconditionally calls startForeground() in onStartCommand(). The root
  cause of this is unknown. Perhaps these devices are exceptionally slow
  during boot?
* The persistent notification does not get dismissed when the file
  migration runs too quickly.

We may be able to work around the second issue by not setting the
FOREGROUND_SERVICE_IMMEDIATE notification behavior flag, but given how
fast the file migration is, let's just switch to a background service.
We're unlikely to hit Android's limitations on background services.

Closes: #574
Closes: #576

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
  • Loading branch information
chenxiaolong committed Aug 2, 2024
1 parent b963456 commit 17f6d19
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 14 deletions.
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Expand Down Expand Up @@ -62,8 +61,7 @@

<service
android:name=".DirectBootMigrationService"
android:exported="false"
android:foregroundServiceType="specialUse" />
android:exported="false" />

<service
android:name=".RecorderInCallService"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class DirectBootMigrationReceiver : BroadcastReceiver() {
return
}

context.startForegroundService(Intent(context, DirectBootMigrationService::class.java))
context.startService(Intent(context, DirectBootMigrationService::class.java))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,12 @@ class DirectBootMigrationService : Service() {

private fun startThread() {
Log.i(TAG, "Starting direct boot file migration")

val notification = notifications.createPersistentNotification(
R.string.notification_direct_boot_migration_in_progress,
null,
emptyList(),
)
startForeground(prefs.nextNotificationId, notification)

thread.start()
}

private fun tryStop() {
if (!thread.isAlive) {
Log.d(TAG, "Stopping service")
stopForeground(STOP_FOREGROUND_REMOVE)
stopSelf()
}
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
<string name="notification_channel_failure_desc">Alerts for errors during call recording</string>
<string name="notification_channel_success_name">Success alerts</string>
<string name="notification_channel_success_desc">Alerts for successful call recordings</string>
<string name="notification_direct_boot_migration_in_progress">Migrating recordings</string>
<string name="notification_direct_boot_migration_failed">Failed to migrate recordings</string>
<string name="notification_direct_boot_migration_error">Some recordings saved before the device was initially unlocked could not be moved to the output directory.</string>
<string name="notification_recording_initializing">Call recording initializing</string>
Expand Down

0 comments on commit 17f6d19

Please sign in to comment.