-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
404 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.sealdice.dice | ||
|
||
import android.app.Service | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.IBinder | ||
import android.os.PowerManager | ||
|
||
class DimWakeLockService : Service(){ | ||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager | ||
val wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "DIM:LocationManagerService") | ||
wakeLock.acquire() | ||
return START_STICKY | ||
} | ||
override fun onBind(intent: Intent?): IBinder? { | ||
return null | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
app/src/main/java/com/sealdice/dice/NotificationService.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.sealdice.dice | ||
|
||
import android.app.* | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Binder | ||
import android.os.Build | ||
import android.os.IBinder | ||
import androidx.preference.PreferenceManager | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.launch | ||
import java.io.BufferedReader | ||
import java.io.File | ||
import java.io.InputStreamReader | ||
|
||
|
||
class ProcessService : Service(){ | ||
private val binder = MyBinder() | ||
private var processBuilder: ProcessBuilder = ProcessBuilder("sh").redirectErrorStream(true) | ||
private lateinit var process: Process | ||
private var isRunning = false | ||
private var shellLogs = "" | ||
inner class MyBinder : Binder() { | ||
fun getService(): ProcessService = this@ProcessService | ||
} | ||
fun getShellLogs(): String { | ||
return shellLogs | ||
} | ||
fun stopProcess() { | ||
isRunning = false | ||
Thread.sleep(5) | ||
process.destroy() | ||
} | ||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
if (Build.VERSION.SDK_INT >= 26) { | ||
val ns: String = Context.NOTIFICATION_SERVICE | ||
val mNotificationManager = getSystemService(ns) as NotificationManager | ||
val notificationChannel = NotificationChannel("sealdice","SealDice", NotificationManager.IMPORTANCE_HIGH) | ||
mNotificationManager.createNotificationChannel(notificationChannel) | ||
val pendingIntent = PendingIntent.getActivity(applicationContext, 0, Intent(applicationContext, NotificationActivity::class.java), PendingIntent.FLAG_MUTABLE) | ||
val notification: Notification = Notification.Builder(this,"sealdice") | ||
.setContentTitle("SealDice is running") | ||
.setSmallIcon(R.drawable.ic_launcher_foreground) | ||
.setContentIntent(pendingIntent) | ||
.build() | ||
startForeground(1, notification) | ||
} | ||
else { | ||
val pendingIntent = PendingIntent.getActivity(applicationContext, 0, Intent(applicationContext, NotificationActivity::class.java), PendingIntent.FLAG_MUTABLE) | ||
val notification: Notification = Notification.Builder(this) | ||
.setContentTitle("SealDice is running") | ||
.setSmallIcon(R.drawable.ic_launcher_foreground) | ||
.setContentIntent(pendingIntent) | ||
.build() | ||
startForeground(1, notification) | ||
} | ||
if (!isRunning) { | ||
isRunning = true | ||
process = processBuilder.directory(File(this.filesDir.absolutePath)).start() | ||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) | ||
val args = sharedPreferences.getString("launch_args", "") | ||
val cmd = "cd sealdice&&./sealdice-core $args" | ||
GlobalScope.launch(context = Dispatchers.IO) { | ||
val os = process.outputStream | ||
os.write(cmd.toByteArray()) | ||
os.flush() | ||
os.close() | ||
val data = process.inputStream | ||
val ir = BufferedReader(InputStreamReader(data)) | ||
while (isRunning) { | ||
var line: String? | ||
try { | ||
line = ir.readLine() | ||
} catch (e: Exception) { | ||
break | ||
} | ||
while (line != null && isRunning) { | ||
shellLogs += line | ||
shellLogs += "\n" | ||
try { | ||
line = ir.readLine() | ||
} catch (e: Exception) { | ||
break | ||
} | ||
} | ||
Thread.sleep(1000) | ||
} | ||
} | ||
} | ||
return START_STICKY | ||
} | ||
fun isRunning(): Boolean { | ||
return isRunning | ||
} | ||
override fun onBind(p0: Intent?): IBinder { | ||
return binder | ||
} | ||
override fun onDestroy() { | ||
super.onDestroy() | ||
stopProcess() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.