service tests 3

This commit is contained in:
X1nto 2020-06-30 16:29:14 +04:00
parent 45aa99d30a
commit fb555e5370
4 changed files with 64 additions and 25 deletions

View File

@ -1,9 +1,11 @@
package com.vanced.manager.core.installer
import android.app.Notification
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInstaller
import android.os.Build
import android.os.IBinder
import android.util.Log
import android.widget.Toast
@ -13,6 +15,7 @@ import com.vanced.manager.R
import com.vanced.manager.ui.MainActivity
import com.vanced.manager.utils.MiuiHelper
import com.vanced.manager.utils.NotificationHelper
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
class AppInstallerService: Service() {
@ -22,11 +25,7 @@ class AppInstallerService: Service() {
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
Toast.makeText(this, "Installing...", Toast.LENGTH_SHORT).show()
Log.d(TAG, "Requesting user confirmation for installation")
NotificationHelper.createBasicNotif(
getString(R.string.installing_app, "MicroG"),
notifId,
this
)
startForegroundNotif(getString(R.string.installing_app, "MicroG"))
val confirmationIntent = intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
confirmationIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
try {
@ -41,16 +40,14 @@ class AppInstallerService: Service() {
mIntent.action = MainActivity.INSTALL_COMPLETED
mIntent.putExtra("package", "normal")
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
NotificationHelper.createBasicNotif(
getString(
createBasicNotif(getString(
R.string.successfully_installed,
"Microg"
), notifId, this
)
), notifId, this)
}
else -> {
sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999))
NotificationHelper.createBasicNotif(
createBasicNotif(
getErrorMessage(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)),
notifId,
this
@ -84,6 +81,23 @@ class AppInstallerService: Service() {
}
}
private fun startForegroundNotif(text: String) {
val notifBuilder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
Notification.Builder(this, 42.toString()).setChannelId("69420")
else
Notification.Builder(this).setPriority(Notification.PRIORITY_DEFAULT)
notifBuilder.apply {
setContentTitle(getString(R.string.app_name))
setContentText(text)
setSmallIcon(R.drawable.ic_stat_name)
}
val notif = notifBuilder.build()
startForeground(42, notif)
}
@Nullable
override fun onBind(intent: Intent?): IBinder? {
return null

View File

@ -1,5 +1,6 @@
package com.vanced.manager.core.installer
import android.app.Notification
import android.app.Service
import android.content.Context
import android.content.Intent
@ -52,7 +53,7 @@ class RootSplitInstallerService: Service() {
}
for (apkFile in apkFiles) {
Log.d("AppLog", "installing APK : ${apkFile.name} ${apkFile.fileSize} ")
createBasicNotif(getString(R.string.installing_app, "Vanced"), notifId, this)
startForegroundNotif(getString(R.string.installing_app, "Vanced"))
val command = arrayOf("su", "-c", "pm", "install-write", "-S", "${apkFile.fileSize}", "$sessionId", apkFile.name)
val process: Process = Runtime.getRuntime().exec(command)
val inputPipe = apkFile.getInputStream()
@ -136,6 +137,23 @@ class RootSplitInstallerService: Service() {
return result
}
private fun startForegroundNotif(text: String) {
val notifBuilder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
Notification.Builder(this, 666.toString()).setChannelId("69420")
else
Notification.Builder(this).setPriority(Notification.PRIORITY_DEFAULT)
notifBuilder.apply {
setContentTitle(getString(R.string.app_name))
setContentText(text)
setSmallIcon(R.drawable.ic_stat_name)
}
val notif = notifBuilder.build()
startForeground(666, notif)
}
@Nullable
override fun onBind(intent: Intent?): IBinder? {
return null

View File

@ -1,9 +1,11 @@
package com.vanced.manager.core.installer
import android.app.Notification
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.PackageInstaller
import android.os.Build
import android.os.IBinder
import android.util.Log
import android.widget.Toast
@ -21,11 +23,7 @@ class SplitInstallerService: Service() {
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) {
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
Toast.makeText(this, "Installing...", Toast.LENGTH_SHORT).show()
NotificationHelper.createBasicNotif(
getString(R.string.installing_app, "Vanced"),
notifId,
this
)
startForegroundNotif(getString(R.string.installing_app, "Vanced"))
Log.d(TAG, "Requesting user confirmation for installation")
val confirmationIntent =
intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
@ -84,6 +82,23 @@ class SplitInstallerService: Service() {
}
}
private fun startForegroundNotif(text: String) {
val notifBuilder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
Notification.Builder(this, 666.toString()).setChannelId("69420")
else
Notification.Builder(this).setPriority(Notification.PRIORITY_DEFAULT)
notifBuilder.apply {
setContentTitle(getString(R.string.app_name))
setContentText(text)
setSmallIcon(R.drawable.ic_stat_name)
}
val notif = notifBuilder.build()
startForeground(666, notif)
}
@Nullable
override fun onBind(intent: Intent?): IBinder? {
return null

View File

@ -31,20 +31,12 @@ object NotificationHelper {
else
Notification.Builder(context).setPriority(Notification.PRIORITY_HIGH)
val cancelDownload = Intent(context, DownloadBroadcastReceiver::class.java)
cancelDownload.putExtra("type", type)
val cancelPendingIntent = PendingIntent.getBroadcast(context, 0, cancelDownload, PendingIntent.FLAG_UPDATE_CURRENT)
notifBuilder.apply {
setContentTitle(context.getString(R.string.app_name))
setContentText(context.getString(R.string.downloading_file, filename))
setSmallIcon(R.drawable.ic_stat_name)
setOnlyAlertOnce(true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
addAction(Notification.Action.Builder(null, context.getString(R.string.cancel), cancelPendingIntent).build())
else
addAction(0, context.getString(R.string.cancel), cancelPendingIntent)
setOngoing(true)
}
val notif = notifBuilder.build()