Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some quick fixes to make Dhizuku working in BFU mode #75

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
}
}