Skip to content

Commit

Permalink
Fix crashes for rooted devices
Browse files Browse the repository at this point in the history
  • Loading branch information
reconman committed Aug 14, 2024
1 parent b79dd51 commit e603d01
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,19 @@ class ScriptRunnerNotification @Inject constructor(
.addAction(stopAction)
}

fun show() {
fun show(useRootForScreenshots: Boolean) {
val builder = startBuildNotification()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
var foregroundServiceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
if (!useRootForScreenshots) {
foregroundServiceType = foregroundServiceType.or(ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION)
}

service.startForeground(
Ids.foregroundNotification,
builder.build(),
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE or ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
foregroundServiceType
)
} else {
service.startForeground(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ class ScriptRunnerService: Service() {
controller.onCreate()
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)

// maybe fixes crashes on Android 14
// TODO remove once https://issuetracker.google.com/issues/307329994 is fixed
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) START_NOT_STICKY else START_STICKY
}

override fun onConfigurationChanged(newConfig: Configuration) {
controller.onScreenConfigChanged()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ScriptRunnerServiceController @Inject constructor(

fun onCreate() {
Timber.i("Script runner service created")
notification.show()
notification.show(prefs.useRootForScreenshots)

screenOffReceiver.register(service) {
Timber.v("SCREEN OFF")
Expand Down

0 comments on commit e603d01

Please sign in to comment.