Skip to content

Commit

Permalink
Merge pull request #75 from bakad3v/main
Browse files Browse the repository at this point in the history
Some quick fixes to make Dhizuku working in BFU mode
  • Loading branch information
iamr0s authored Sep 12, 2024
2 parents e528f2e + aaf4263 commit 798b53d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.rosan.dhizuku.data.settings.model.room

import android.content.Context
import android.os.Build
import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.Room
Expand All @@ -19,8 +21,13 @@ import org.koin.core.component.get
abstract class DhizukuRoom : RoomDatabase() {
companion object : KoinComponent {
fun createInstance(): DhizukuRoom {
val context = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
get<Context>().createDeviceProtectedStorageContext()
} else {
get()
}
return Room.databaseBuilder(
get(),
context,
DhizukuRoom::class.java,
"dhizuku.db",
).build()
Expand Down
54 changes: 11 additions & 43 deletions app/src/main/java/com/rosan/dhizuku/server/RunningService.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.rosan.dhizuku.server

import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
import androidx.core.app.JobIntentService
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
Expand All @@ -22,13 +21,12 @@ import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

class RunningService : Service(), KoinComponent {

class RunningService : JobIntentService(), KoinComponent {
companion object {
private const val JOB_ID = 1
fun start(context: Context) {
val intent = Intent(context, RunningService::class.java)
/*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
context.startForegroundService(intent)
else */context.startService(intent)
enqueueWork(context, RunningService::class.java, JOB_ID, Intent())
}
}

Expand All @@ -50,21 +48,21 @@ class RunningService : Service(), KoinComponent {
}
}

override fun onBind(intent: Intent?): IBinder? {
return null
}

override fun onCreate() {
super.onCreate()
runForeground()
registerPackageReceiver()
// runForeground()
// registerPackageReceiver()
}

override fun onDestroy() {
unregisterReceiver(packageReceiver)
super.onDestroy()
}

override fun onHandleWork(intent: Intent) {
registerPackageReceiver()
}

private fun registerPackageReceiver() {
scope.launch {
repo.all()
Expand All @@ -91,34 +89,4 @@ class RunningService : Service(), KoinComponent {

return true
}

private fun runForeground() {
val manager = NotificationManagerCompat.from(this)
val channelName = "running_service_channel"
val channel: NotificationChannelCompat =
NotificationChannelCompat.Builder(channelName, NotificationManagerCompat.IMPORTANCE_MAX)
.setName(getString(R.string.service_channel_name))
.setVibrationEnabled(false)
.setSound(null, null)
.setShowBadge(false)
.build()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
manager.createNotificationChannel(channel)
val notificationId = 1
val notification = NotificationCompat.Builder(this, channel.id)
.setSmallIcon(R.drawable.round_hourglass_empty_black_24)
.setContentTitle(getString(R.string.service_running))
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_DEFERRED)
.setPriority(NotificationCompat.PRIORITY_MIN)
.setAutoCancel(false)
.setOngoing(true)
.build()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
startForeground(notificationId, notification)
else startForeground(
notificationId,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING
)
}
}

0 comments on commit 798b53d

Please sign in to comment.