This commit is contained in:
X1nto 2020-06-30 17:58:31 +04:00
parent fb555e5370
commit 90f0859b31
13 changed files with 33 additions and 142 deletions

View File

@ -57,8 +57,6 @@
</provider>
<receiver android:name=".core.downloader.DownloadBroadcastReceiver"/>
<service android:name=".core.installer.SplitInstallerService" />
<service android:name=".core.installer.RootSplitInstallerService" />
<service android:name=".core.installer.SplitInstaller" />

View File

@ -1,27 +0,0 @@
package com.vanced.manager.core.downloader
import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
class DownloadBroadcastReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val notificationManager = context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
when (intent?.getStringExtra("type")) {
"vanced" -> {
context.stopService(Intent(context, VancedDownloadService::class.java))
notificationManager.cancel(69)
Log.d("VMNotification", "Canceled vanced download")
}
"microg" -> {
notificationManager.cancel(420)
context.stopService(Intent(context, MicrogDownloadService::class.java))
Log.d("VMNotification", "Canceled microg download")
}
}
}
}

View File

@ -48,7 +48,6 @@ class MicrogDownloadService: Service() {
NotificationHelper.displayDownloadNotif(
channel,
mProgress.toInt(),
"microg",
getFileNameFromUrl(dwnldUrl),
this
)
@ -60,10 +59,7 @@ class MicrogDownloadService: Service() {
val intent = Intent(this@MicrogDownloadService, AppInstaller::class.java)
intent.putExtra("path", "${filesDir.path}/microg.apk")
intent.putExtra("pkg", "com.mgoogle.android.gms")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
startForegroundService(intent)
else
startService(intent)
startService(intent)
}
override fun onError(error: Error) {
prefs?.edit()?.putBoolean("isMicrogDownloading", false)?.apply()

View File

@ -71,7 +71,7 @@ class VancedDownloadService: Service() {
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isVancedDownloading", true)?.apply() } }
.setOnProgressListener { progress ->
val mProgress = progress.currentBytes * 100 / progress.totalBytes
displayDownloadNotif(channel, mProgress.toInt(), "vanced", getFileNameFromUrl(url), this)
displayDownloadNotif(channel, mProgress.toInt(), getFileNameFromUrl(url), this)
}
.start(object : OnDownloadListener {
override fun onDownloadComplete() {
@ -104,16 +104,9 @@ class VancedDownloadService: Service() {
intent.action = HomeFragment.VANCED_DOWNLOADED
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
if (variant == "root")
startInstallService(Intent(this, RootSplitInstallerService::class.java))
startService(Intent(this, RootSplitInstallerService::class.java))
else
startInstallService(Intent(this, SplitInstaller::class.java))
}
private fun startInstallService(intent: Intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
startForegroundService(intent)
else
startService(intent)
startService(Intent(this, SplitInstaller::class.java))
}
override fun onDestroy() {

View File

@ -25,7 +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")
startForegroundNotif(getString(R.string.installing_app, "MicroG"))
createBasicNotif(getString(R.string.installing_app, "MicroG"), notifId, this)
val confirmationIntent = intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
confirmationIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
try {
@ -81,23 +81,6 @@ 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

@ -53,7 +53,7 @@ class RootSplitInstallerService: Service() {
}
for (apkFile in apkFiles) {
Log.d("AppLog", "installing APK : ${apkFile.name} ${apkFile.fileSize} ")
startForegroundNotif(getString(R.string.installing_app, "Vanced"))
createBasicNotif(getString(R.string.installing_app, "Vanced"), notifId, this)
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()
@ -137,23 +137,6 @@ 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

@ -14,7 +14,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.vanced.manager.R
import com.vanced.manager.ui.MainActivity
import com.vanced.manager.utils.MiuiHelper.isMiui
import com.vanced.manager.utils.NotificationHelper
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
class SplitInstallerService: Service() {
@ -23,7 +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()
startForegroundNotif(getString(R.string.installing_app, "Vanced"))
createBasicNotif(getString(R.string.installing_app, "Vanced"), notifId, this)
Log.d(TAG, "Requesting user confirmation for installation")
val confirmationIntent =
intent.getParcelableExtra<Intent>(Intent.EXTRA_INTENT)
@ -40,7 +40,7 @@ class SplitInstallerService: Service() {
mIntent.action = MainActivity.INSTALL_COMPLETED
mIntent.putExtra("package", "split")
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
NotificationHelper.createBasicNotif(
createBasicNotif(
getString(R.string.successfully_installed, "Vanced"),
notifId,
this
@ -48,7 +48,7 @@ class SplitInstallerService: Service() {
}
else -> {
sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999))
NotificationHelper.createBasicNotif(
createBasicNotif(
getErrorMessage(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)),
notifId,
this

View File

@ -24,7 +24,7 @@ object NotificationHelper {
}
}
fun displayDownloadNotif(channel: Int, progress:Int, type: String, filename: String, context: Context) {
fun displayDownloadNotif(channel: Int, progress:Int, filename: String, context: Context) {
val notifBuilder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
Notification.Builder(context, channel.toString()).setChannelId("69420")

View File

@ -37,8 +37,8 @@
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
@ -46,17 +46,19 @@
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginStart="4dp"
android:text="@string/reset"
android:textAllCaps="false"/>
android:textAllCaps="false"
android:layout_alignParentStart="true"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/url_save"
style="@style/ButtonStyle"
android:layout_marginStart="4dp"
android:text="@string/save" />
android:layout_marginEnd="4dp"
android:text="@string/save"
android:layout_alignParentEnd="true"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View File

@ -2,7 +2,6 @@
<com.vanced.manager.ui.core.SlidingConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

View File

@ -7,50 +7,24 @@
app:contentPaddingTop="2dp"
tools:ignore="HardcodedText">
<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
style="@style/AboutCardTitle"
android:id="@+id/about_card_vancedTeam"
android:text="@string/manager_devs"
android:text="@string/manager_dev"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<LinearLayout
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/about_card_vancedTeam"
android:layout_marginTop="2dp">
android:text="- Xinto"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="- MrDodojo"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="- Hope"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="- Moosd"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="- Xinto"
android:textSize="18sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

View File

@ -7,9 +7,10 @@
tools:ignore="HardcodedText"
app:contentPaddingTop="2dp">
<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
style="@style/AboutCardTitle"
@ -18,13 +19,6 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/about_card_vancedTeam"
android:layout_marginTop="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -49,9 +43,6 @@
android:text="- Laura Almeida"
android:textSize="18sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

View File

@ -89,7 +89,6 @@
<string name="launch">Launch</string>
<string name="welcome">Welcome</string>
<!-- Install Page -->
<string name="choose_preferred_language">Choose your preferred language for Vanced</string>
<string name="choose_preferred_language_note">Note: if you install anything other than English, English will still be installed as an additional language</string>
@ -101,7 +100,7 @@
<string name="next">Next</string>
<!-- About Page -->
<string name="manager_devs">Manager Devs</string>
<string name="manager_dev">Manager Dev</string>
<string name="sources">Sources</string>
<string name="vanced_team">Vanced Team</string>