finished code cleanup

This commit is contained in:
Xinto 2020-09-15 11:06:29 -07:00
parent bfa6885b26
commit a63b549b91
19 changed files with 152 additions and 201 deletions

View File

@ -6,7 +6,6 @@ import com.downloader.Error
import com.downloader.OnDownloadListener import com.downloader.OnDownloadListener
import com.downloader.PRDownloader import com.downloader.PRDownloader
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.core.installer.AppInstaller
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.microgProgress import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.microgProgress
import com.vanced.manager.utils.AppUtils.installing import com.vanced.manager.utils.AppUtils.installing
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
@ -34,18 +33,18 @@ object MicrogDownloader {
microgProgress.get()?.showDownloadBar = true microgProgress.get()?.showDownloadBar = true
} }
.setOnProgressListener { progress -> .setOnProgressListener { progress ->
microgProgress.get()?.setDownloadProgress(progress.currentBytes * 100 / progress.totalBytes) microgProgress.get()?.setDownloadProgress((progress.currentBytes * 100 / progress.totalBytes).toInt())
} }
.start(object : OnDownloadListener { .start(object : OnDownloadListener {
override fun onDownloadComplete() { override fun onDownloadComplete() {
install("microg", "${context.getExternalFilesDir("apk")}/microg.apk", context) install("microg", "${context.getExternalFilesDir("apk")}/microg.apk", context)
microgProgress.showDownloadBar = false microgProgress.get()?.showDownloadBar = false
microgProgress.showInstallCircle = true microgProgress.get()?.showInstallCircle = true
} }
override fun onError(error: Error?) { override fun onError(error: Error?) {
installing = false installing = false
Toast.makeText(context, getString(R.string.error_downloading, "microG"), Toast.LENGTH_SHORT).show() Toast.makeText(context, context.getString(R.string.error_downloading, "microG"), Toast.LENGTH_SHORT).show()
} }
}) })

View File

@ -1,13 +1,11 @@
package com.vanced.manager.core.downloader package com.vanced.manager.core.downloader
import android.content.Intent import android.content.Context
import android.os.IBinder
import android.widget.Toast import android.widget.Toast
import com.downloader.Error import com.downloader.Error
import com.downloader.OnDownloadListener import com.downloader.OnDownloadListener
import com.downloader.PRDownloader import com.downloader.PRDownloader
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.core.installer.AppInstaller
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.musicProgress import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.musicProgress
import com.vanced.manager.utils.AppUtils.installing import com.vanced.manager.utils.AppUtils.installing
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
@ -28,7 +26,7 @@ object MusicDownloader {
//downloadId = download(url, "apk", "music.apk", this@MusicDownloadService) //downloadId = download(url, "apk", "music.apk", this@MusicDownloadService)
PRDownloader.download(url, getExternalFilesDir("apk")?.path, "music.apk") PRDownloader.download(url, context.getExternalFilesDir("apk")?.path, "music.apk")
.build() .build()
.setOnStartOrResumeListener { .setOnStartOrResumeListener {
installing = true installing = true
@ -36,18 +34,18 @@ object MusicDownloader {
musicProgress.get()?.showDownloadBar = true musicProgress.get()?.showDownloadBar = true
} }
.setOnProgressListener { progress -> .setOnProgressListener { progress ->
musicProgress.get()?.setDownloadProgress(progress.currentBytes * 100 / progress.totalBytes) musicProgress.get()?.setDownloadProgress((progress.currentBytes * 100 / progress.totalBytes).toInt())
} }
.start(object : OnDownloadListener { .start(object : OnDownloadListener {
override fun onDownloadComplete() { override fun onDownloadComplete() {
install("music", "${context.getExternalFilesDir("apk")}/music.apk", context) install("music", "${context.getExternalFilesDir("apk")}/music.apk", context)
musicProgress.get().showDownloadBar = false musicProgress.get()?.showDownloadBar = false
musicProgress.get().showInstallCircle = true musicProgress.get()?.showInstallCircle = true
} }
override fun onError(error: Error?) { override fun onError(error: Error?) {
installing = false installing = false
Toast.makeText(context, getString(R.string.error_downloading, "Music"), Toast.LENGTH_SHORT).show() Toast.makeText(context, context.getString(R.string.error_downloading, "Music"), Toast.LENGTH_SHORT).show()
} }
}) })
@ -70,8 +68,4 @@ object MusicDownloader {
} }
*/ */
override fun onBind(intent: Intent?): IBinder? {
return null
}
} }

View File

@ -1,18 +1,14 @@
package com.vanced.manager.core.downloader package com.vanced.manager.core.downloader
import android.content.Context import android.content.Context
import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Build import android.os.Build
import android.os.IBinder
import android.widget.Toast import android.widget.Toast
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.downloader.Error import com.downloader.Error
import com.downloader.OnDownloadListener import com.downloader.OnDownloadListener
import com.downloader.PRDownloader import com.downloader.PRDownloader
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.core.installer.RootSplitInstallerService
import com.vanced.manager.core.installer.SplitInstaller
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.vancedProgress import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.vancedProgress
import com.vanced.manager.utils.AppUtils.installing import com.vanced.manager.utils.AppUtils.installing
import com.vanced.manager.utils.InternetTools import com.vanced.manager.utils.InternetTools
@ -21,7 +17,7 @@ import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
import com.vanced.manager.utils.InternetTools.getObjectFromJson import com.vanced.manager.utils.InternetTools.getObjectFromJson
import com.vanced.manager.utils.PackageHelper.getPkgVerCode import com.vanced.manager.utils.PackageHelper.getPkgVerCode
import com.vanced.manager.utils.PackageHelper.installVanced import com.vanced.manager.utils.PackageHelper.installVanced
import com.vanced.manager.utils.PackageHelper.installvancedRoot import com.vanced.manager.utils.PackageHelper.installVancedRoot
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -50,16 +46,16 @@ object VancedDownloader {
private var count: Int = 0 private var count: Int = 0
private var hashUrl = "" private var hashUrl = ""
private val yPkg = "com.google.android.youtube" private const val yPkg = "com.google.android.youtube"
private val vancedVersionCode by lazy {runBlocking { InternetTools.getJsonInt("vanced.json", "versionCode", applicationContext) }} private var vancedVersionCode = 0
private val vancedVersion by lazy { runBlocking { getObjectFromJson("$installUrl/vanced.json", "version") }} private val vancedVersion by lazy { runBlocking { getObjectFromJson("$installUrl/vanced.json", "version") }}
fun downloadVanced(context: Context) { fun downloadVanced(context: Context) {
//registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) //registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
File(context.getExternalFilesDir("apks")?.path as String).deleteRecursively() File(context.getExternalFilesDir("apks")?.path as String).deleteRecursively()
defPrefs = PreferenceManager.getDefaultSharedPreferences(this) defPrefs = PreferenceManager.getDefaultSharedPreferences(context)
installUrl = defPrefs.getString("install_url", baseUrl) installUrl = defPrefs.getString("install_url", baseUrl)
prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE) prefs = context.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
variant = defPrefs.getString("vanced_variant", "nonroot") variant = defPrefs.getString("vanced_variant", "nonroot")
lang = prefs.getString("lang", "en")?.split(", ")?.toTypedArray() lang = prefs.getString("lang", "en")?.split(", ")?.toTypedArray()
theme = prefs.getString("theme", "dark") theme = prefs.getString("theme", "dark")
@ -72,10 +68,11 @@ object VancedDownloader {
Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm64_v8a" Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm64_v8a"
else -> "armeabi_v7a" else -> "armeabi_v7a"
} }
vancedVersionCode = runBlocking { InternetTools.getJsonInt("vanced.json", "versionCode", context) }
downloadSplits(context) downloadSplits(context)
} }
private fun downloadSplits(context, private fun downloadSplits(
context: Context, context: Context,
type: String = "theme" type: String = "theme"
) { ) {
@ -94,7 +91,7 @@ object VancedDownloader {
//downloadId = download(url, "apks", getFileNameFromUrl(url), this@VancedDownloadService) //downloadId = download(url, "apks", getFileNameFromUrl(url), this@VancedDownloadService)
PRDownloader PRDownloader
.download(url, getExternalFilesDir("apks")?.path, getFileNameFromUrl(url)) .download(url, context.getExternalFilesDir("apks")?.path, getFileNameFromUrl(url))
.build() .build()
.setOnStartOrResumeListener { .setOnStartOrResumeListener {
installing = true installing = true
@ -102,18 +99,18 @@ object VancedDownloader {
vancedProgress.get()?.showDownloadBar = true vancedProgress.get()?.showDownloadBar = true
} }
.setOnProgressListener { progress -> .setOnProgressListener { progress ->
vancedProgress.get()?.setDownloadProgress(progress.currentBytes * 100 / progress.totalBytes) vancedProgress.get()?.setDownloadProgress((progress.currentBytes * 100 / progress.totalBytes).toInt())
} }
.start(object : OnDownloadListener { .start(object : OnDownloadListener {
override fun onDownloadComplete() { override fun onDownloadComplete() {
when (type) { when (type) {
"theme" -> "theme" ->
if (variant == "root" && newInstaller == true) { if (variant == "root" && newInstaller == true) {
if (ValidateTheme()) { if (validateTheme(context)) {
if(downloadStockCheck()) if(downloadStockCheck(context))
downloadSplits(context, "arch") downloadSplits(context, "arch")
else else
prepareInstall(variant!!) prepareInstall(variant!!, context)
} else } else
downloadSplits(context, "theme") downloadSplits(context, "theme")
} else } else
@ -126,7 +123,7 @@ object VancedDownloader {
if (count < lang?.count()!!) if (count < lang?.count()!!)
downloadSplits(context, "lang") downloadSplits(context, "lang")
else else
prepareInstall(variant!!) prepareInstall(variant!!, context)
} }
} }
@ -137,35 +134,34 @@ object VancedDownloader {
if (count < lang?.count()!!) if (count < lang?.count()!!)
downloadSplits(context, "lang") downloadSplits(context, "lang")
else else
prepareInstall(variant!!) prepareInstall(variant!!, context)
} else { } else {
installing = false installing = false
Toast.makeText(context, getString(R.string.error_downloading, "Vanced"), Toast.LENGTH_SHORT).show() Toast.makeText(context, context.getString(R.string.error_downloading, "Vanced"), Toast.LENGTH_SHORT).show()
} }
} }
}) })
} }
} }
private fun downloadStockCheck():Boolean { private fun downloadStockCheck(context: Context) :Boolean {
return try { return try {
getPkgVerCode(yPkg, packageManager) != vancedVersionCode getPkgVerCode(yPkg,context.packageManager) != vancedVersionCode
} catch (e: Exception) { } catch (e: Exception) {
true true
} }
} }
suspend fun getSha256(obj: String) { private suspend fun getSha256(obj: String, context: Context) {
sha256Val = InternetTools.getJsonString(hashUrl,obj,applicationContext) sha256Val = InternetTools.getJsonString(hashUrl, obj, context)
} }
private fun ValidateTheme(): Boolean private fun validateTheme(context: Context): Boolean {
{ val prefs = context.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val theme = prefs?.getString("theme", "dark") val theme = prefs?.getString("theme", "dark")
val themeS = getExternalFilesDir("apks")?.path + "/${theme}.apk" val themeS = context.getExternalFilesDir("apks")?.path + "/${theme}.apk"
val themeF = File(themeS) val themeF = File(themeS)
runBlocking { getSha256(theme!!) } runBlocking { getSha256(theme!!, context) }
return checkSHA256(sha256Val!!,themeF) return checkSHA256(sha256Val!!,themeF)
} }
@ -203,11 +199,7 @@ object VancedDownloader {
if (variant == "root") if (variant == "root")
installVancedRoot(context) installVancedRoot(context)
else else
installvanced(context) installVanced(context)
}
override fun onBind(intent: Intent?): IBinder? {
return null
} }
private fun checkSHA256(sha256: String, updateFile: File?): Boolean { private fun checkSHA256(sha256: String, updateFile: File?): Boolean {

View File

@ -7,11 +7,10 @@ import android.os.IBinder
import android.util.Log import android.util.Log
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.microgProgress import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.microgProgress
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.musicProgress import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.musicProgress
import com.vanced.manager.utils.AppUtils.sendFailure
class AppInstallerService: Service() { class AppInstallerService: Service() {
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(this) }
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) { when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) {
PackageInstaller.STATUS_PENDING_USER_ACTION -> { PackageInstaller.STATUS_PENDING_USER_ACTION -> {
@ -26,7 +25,7 @@ class AppInstallerService: Service() {
} }
PackageInstaller.STATUS_SUCCESS -> { PackageInstaller.STATUS_SUCCESS -> {
Log.d(TAG, "Installation succeed") Log.d(TAG, "Installation succeed")
if (intent?.getStringExtra("app") == "microg") microgProgress.showInstallCircle = false else musicProgress.showInstallCircle = false if (intent.getStringExtra("app") == "microg") microgProgress.get()?.showInstallCircle = false else musicProgress.get()?.showInstallCircle = false
} }
else -> sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999), this) else -> sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999), this)
} }

View File

@ -5,11 +5,7 @@ import android.content.Intent
import android.content.pm.PackageInstaller import android.content.pm.PackageInstaller
import android.os.IBinder import android.os.IBinder
import android.util.Log import android.util.Log
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.fetchData import com.vanced.manager.utils.AppUtils.sendRefresh
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
class AppUninstallerService: Service() { class AppUninstallerService: Service() {
@ -27,18 +23,12 @@ class AppUninstallerService: Service() {
} }
//Delay broadcast until activity (and fragment) show up on the screen //Delay broadcast until activity (and fragment) show up on the screen
PackageInstaller.STATUS_SUCCESS -> { PackageInstaller.STATUS_SUCCESS -> {
CoroutineScope(Dispatchers.IO).launch { sendRefresh(this)
delay(500) Log.d("VMpm", "Successfully uninstalled $pkgName")
fetchData()
Log.d("VMpm", "Successfully uninstalled $pkgName")
}
} }
PackageInstaller.STATUS_FAILURE -> { PackageInstaller.STATUS_FAILURE -> {
CoroutineScope(Dispatchers.IO).launch { sendRefresh(this)
delay(500) Log.d("VMpm", "Failed to uninstall $pkgName")
fetchData()
Log.d("VMpm", "Failed to uninstall $pkgName")
}
} }
} }
stopSelf() stopSelf()

View File

@ -6,8 +6,8 @@ import android.content.pm.PackageInstaller
import android.os.IBinder import android.os.IBinder
import android.util.Log import android.util.Log
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.vancedProgress import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.vancedProgress
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.fetchData
import com.vanced.manager.utils.AppUtils.sendFailure import com.vanced.manager.utils.AppUtils.sendFailure
import com.vanced.manager.utils.AppUtils.sendRefresh
class SplitInstallerService: Service() { class SplitInstallerService: Service() {
@ -24,8 +24,8 @@ class SplitInstallerService: Service() {
} }
PackageInstaller.STATUS_SUCCESS -> { PackageInstaller.STATUS_SUCCESS -> {
Log.d(TAG, "Installation succeed") Log.d(TAG, "Installation succeed")
vancedProgress.showInstallCircle = false vancedProgress.get()?.showInstallCircle = false
fetchData() sendRefresh(this)
} }
else -> sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999), this) else -> sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999), this)

View File

@ -2,7 +2,7 @@ package com.vanced.manager.model
open class ProgressModel { open class ProgressModel {
private var downloadProgres = 0 private var downloadProgress = 0
private var downloadingFile = "" private var downloadingFile = ""
var showInstallCircle = false var showInstallCircle = false
@ -12,12 +12,12 @@ open class ProgressModel {
return downloadProgress return downloadProgress
} }
open fun setDownloadProgress(progresss: Int) { open fun setDownloadProgress(progress: Int) {
downloadProgress = progress downloadProgress = progress
} }
open fun getDownloadingFile(): String { open fun getDownloadingFile(): String {
return downloadProgress return downloadingFile
} }
open fun setDownloadingFile(file: String) { open fun setDownloadingFile(file: String) {

View File

@ -8,10 +8,10 @@ import androidx.core.content.ContextCompat.startActivity
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.core.downloader.VancedDownloadService import com.vanced.manager.core.downloader.VancedDownloader.downloadVanced
import com.vanced.manager.core.installer.SplitInstaller
import com.vanced.manager.utils.InternetTools.openUrl import com.vanced.manager.utils.InternetTools.openUrl
import com.vanced.manager.utils.MiuiHelper import com.vanced.manager.utils.MiuiHelper
import com.vanced.manager.utils.PackageHelper.installVanced
object DialogContainer { object DialogContainer {
@ -63,11 +63,11 @@ object DialogContainer {
setTitle("") setTitle("")
setMessage("") setMessage("")
setNegativeButton("") { dialog, _ -> setNegativeButton("") { dialog, _ ->
context.startService(Intent(context, VancedDownloadService::class.java)) downloadVanced(context)
dialog.dismiss() dialog.dismiss()
} }
setPositiveButton(context.getString(R.string.button_reinstall)) { dialog, _ -> setPositiveButton(context.getString(R.string.button_reinstall)) { dialog, _ ->
context.startService(Intent(context, SplitInstaller::class.java)) installVanced(context)
dialog.dismiss() dialog.dismiss()
} }
} }

View File

@ -2,7 +2,6 @@ package com.vanced.manager.ui.fragments
import android.content.* import android.content.*
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.* import android.view.*
import android.view.animation.AccelerateDecelerateInterpolator import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.Toast import android.widget.Toast
@ -10,8 +9,6 @@ import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.navigation.findNavController
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import com.vanced.manager.R import com.vanced.manager.R
@ -21,7 +18,6 @@ import com.vanced.manager.databinding.FragmentHomeBinding
import com.vanced.manager.ui.dialogs.DialogContainer.installAlertBuilder import com.vanced.manager.ui.dialogs.DialogContainer.installAlertBuilder
import com.vanced.manager.ui.viewmodels.HomeViewModel import com.vanced.manager.ui.viewmodels.HomeViewModel
import com.vanced.manager.utils.AppUtils.installing import com.vanced.manager.utils.AppUtils.installing
import com.vanced.manager.utils.PackageHelper
open class HomeFragment : Fragment(), View.OnClickListener { open class HomeFragment : Fragment(), View.OnClickListener {
@ -37,7 +33,7 @@ open class HomeFragment : Fragment(), View.OnClickListener {
): View? { ): View? {
requireActivity().title = getString(R.string.title_home) requireActivity().title = getString(R.string.title_home)
setHasOptionsMenu(true) setHasOptionsMenu(true)
variant = if (requireActivity().findViewById<TabLayout>(R.id.main_tablayout).getSelectedTabPosition() == 1) "root" else "nonroot" variant = if (requireActivity().findViewById<TabLayout>(R.id.main_tablayout).selectedTabPosition == 1) "root" else "nonroot"
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false) binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false)
binding.viewModel = viewModel binding.viewModel = viewModel
viewModel.variant = variant viewModel.variant = variant
@ -139,6 +135,7 @@ open class HomeFragment : Fragment(), View.OnClickListener {
installAlertBuilder(intent.getStringExtra("errorMsg") as String, requireActivity()) installAlertBuilder(intent.getStringExtra("errorMsg") as String, requireActivity())
installing = false installing = false
} }
REFRESH_HOME -> viewModel.fetchData()
} }
} }
} }
@ -156,6 +153,7 @@ open class HomeFragment : Fragment(), View.OnClickListener {
companion object { companion object {
const val INSTALL_FAILED = "install_failed" const val INSTALL_FAILED = "install_failed"
const val REFRESH_HOME = "refresh_home"
} }
} }

View File

@ -1,7 +1,6 @@
package com.vanced.manager.ui.fragments package com.vanced.manager.ui.fragments
import android.content.Context import android.content.Context
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -16,7 +15,7 @@ import androidx.preference.PreferenceManager
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.google.android.material.checkbox.MaterialCheckBox import com.google.android.material.checkbox.MaterialCheckBox
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.core.downloader.VancedDownloadService import com.vanced.manager.core.downloader.VancedDownloader.downloadVanced
import com.vanced.manager.utils.InternetTools.baseUrl import com.vanced.manager.utils.InternetTools.baseUrl
import com.vanced.manager.utils.InternetTools.getArrayFromJson import com.vanced.manager.utils.InternetTools.getArrayFromJson
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -56,7 +55,7 @@ class VancedLanguageSelectionFragment : Fragment() {
putString("lang", chosenLangs.joinToString())?.apply() putString("lang", chosenLangs.joinToString())?.apply()
putBoolean("valuesModified", true).apply() putBoolean("valuesModified", true).apply()
} }
startService(Intent(this, VancedDownloadService::class.java)) downloadVanced(requireActivity())
} }
view.findNavController().navigate(R.id.action_installTo_homeFragment) view.findNavController().navigate(R.id.action_installTo_homeFragment)
} }

View File

@ -1,29 +1,14 @@
package com.vanced.manager.ui.viewmodels package com.vanced.manager.ui.viewmodels
import android.app.Application import android.app.Application
import android.content.Intent
import android.net.Uri
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.preference.PreferenceManager
import com.vanced.manager.R import com.vanced.manager.R
import com.vanced.manager.utils.InternetTools
class AboutViewModel(application: Application): AndroidViewModel(application) { class AboutViewModel(application: Application): AndroidViewModel(application) {
fun openUrl(Url: String) { fun openUrl(url: String) {
val customTabPrefs = PreferenceManager.getDefaultSharedPreferences(getApplication()).getBoolean("use_customtabs", true) InternetTools.openUrl(url, R.color.GitHub, getApplication())
if (customTabPrefs) {
val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(getApplication(), R.color.GitHub))
val customTabsIntent = builder.build()
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
customTabsIntent.launchUrl(getApplication(), Uri.parse(Url))
} else {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(Url))
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
ContextCompat.startActivity(getApplication(), intent, null)
}
} }
} }

View File

@ -5,25 +5,20 @@ import android.content.ActivityNotFoundException
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri
import android.widget.Toast import android.widget.Toast
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.startActivity import androidx.core.content.ContextCompat.startActivity
import androidx.databinding.ObservableBoolean import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField import androidx.databinding.ObservableField
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.navigation.Navigation.findNavController import androidx.navigation.fragment.NavHostFragment.findNavController
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.crowdin.platform.Crowdin import com.crowdin.platform.Crowdin
import com.google.android.material.snackbar.Snackbar import com.vanced.manager.R
import com.vanced.manager.core.downloader.MicrogDownloader.downloadMicrog import com.vanced.manager.core.downloader.MicrogDownloader.downloadMicrog
import com.vanced.manager.core.downloader.MusicDownloader.downloadMusic import com.vanced.manager.core.downloader.MusicDownloader.downloadMusic
import com.vanced.manager.core.downloader.VancedDownloader.downloadVanced import com.vanced.manager.core.downloader.VancedDownloader.downloadVanced
import com.vanced.manager.R
import com.vanced.manager.model.DataModel import com.vanced.manager.model.DataModel
import com.vanced.manager.model.ProgressModel import com.vanced.manager.model.ProgressModel
import com.vanced.manager.ui.MainActivity import com.vanced.manager.ui.fragments.MainFragment
import com.vanced.manager.utils.AppUtils.installing import com.vanced.manager.utils.AppUtils.installing
import com.vanced.manager.utils.InternetTools import com.vanced.manager.utils.InternetTools
import com.vanced.manager.utils.PackageHelper.uninstallApk import com.vanced.manager.utils.PackageHelper.uninstallApk
@ -56,7 +51,8 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
} }
} }
private val microgSnackbar = Snackbar.make(, R.string.no_microg, Snackbar.LENGTH_LONG).setAction(R.string.install) { downloadMicrog(getApplication()) } //private val microgSnackbar = Snackbar.make(, R.string.no_microg, Snackbar.LENGTH_LONG).setAction(R.string.install) { downloadMicrog(getApplication()) }
private val microgToast = Toast.makeText(app, R.string.no_microg, Toast.LENGTH_LONG)
private val vancedPkgName = private val vancedPkgName =
if (variant == "root") if (variant == "root")
@ -97,12 +93,12 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
if (!installing) { if (!installing) {
if (!fetching.get()) { if (!fetching.get()) {
if (variant == "nonroot" && !microg.get()?.isAppInstalled()!!) { if (variant == "nonroot" && !microg.get()?.isAppInstalled()!!) {
microgSnackbar.show() microgToast.show()
} else { } else {
if (app.getSharedPreferences("installPrefs", Context.MODE_PRIVATE).getBoolean("valuesModified", false)!!) { if (app.getSharedPreferences("installPrefs", Context.MODE_PRIVATE).getBoolean("valuesModified", false)) {
downloadVanced() downloadVanced(app)
} else { } else {
findNavController(MainActivity, R.id.nav_host).navigate(R.id.toInstallThemeFragment) findNavController(MainFragment()).navigate(R.id.toInstallThemeFragment)
} }
} }
} }
@ -114,7 +110,7 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
if (!installing) { if (!installing) {
if (!fetching.get()) { if (!fetching.get()) {
if (!microg.get()?.isAppInstalled()!!) { if (!microg.get()?.isAppInstalled()!!) {
microgSnackbar.show() microgToast.show()
} else { } else {
downloadMusic(getApplication()) downloadMusic(getApplication())
} }

View File

@ -15,6 +15,13 @@ object AppUtils {
var installing = false var installing = false
fun sendRefresh(context: Context) {
CoroutineScope(Dispatchers.IO).launch {
delay(500)
LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
}
}
fun sendFailure(status: Int, context: Context) { fun sendFailure(status: Int, context: Context) {
//Delay error broadcast until activity (and fragment) get back to the screen //Delay error broadcast until activity (and fragment) get back to the screen
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {

View File

@ -1,17 +1,32 @@
package com.vanced.manager.utils package com.vanced.manager.utils
import android.app.Activity
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageInstaller
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build import android.os.Build
import android.util.Log import android.util.Log
import com.vanced.manager.core.installer.AppUninstallerService import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.io.SuFile
import com.vanced.manager.BuildConfig
import com.vanced.manager.core.installer.AppInstallerService import com.vanced.manager.core.installer.AppInstallerService
import com.vanced.manager.core.installer.AppUninstallerService
import com.vanced.manager.core.installer.SplitInstallerService import com.vanced.manager.core.installer.SplitInstallerService
import java.io.FileInputStream import com.vanced.manager.ui.fragments.HomeFragment
import java.io.InputStream import com.vanced.manager.utils.AppUtils.sendFailure
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.*
import java.text.SimpleDateFormat
import java.util.*
import java.util.regex.Pattern
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
object PackageHelper { object PackageHelper {
@ -43,25 +58,16 @@ object PackageHelper {
} }
fun uninstallApk(pkg: String, activity: Activity) {
val callbackIntent = Intent(activity.context, AppUninstallerService::class.java)
callbackIntent.putExtra("pkg", pkg)
val pendingIntent = PendingIntent.getService(activity.context, 0, callbackIntent, 0)
activity.packageManager.packageInstaller.uninstall(pkg, pendingIntent.intentSender)
}
fun uninstallApk(pkg: String, context: Context): Boolean { fun uninstallApk(pkg: String, context: Context): Boolean {
val callbackIntent = Intent(context, AppUninstallerService::class.java) val callbackIntent = Intent(context, AppUninstallerService::class.java)
callbackIntent.putExtra("pkg", pkg) callbackIntent.putExtra("pkg", pkg)
val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0) val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0)
try { return try {
context.packageManager.packageInstaller.uninstall(pkg, pendingIntent.intentSender) context.packageManager.packageInstaller.uninstall(pkg, pendingIntent.intentSender)
return true true
} } catch (e: Exception) {
catch (e: Exception)
{
e.printStackTrace() e.printStackTrace()
return false; false;
} }
} }
@ -70,7 +76,7 @@ object PackageHelper {
val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0) val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0)
val packageInstaller = context.packageManager.packageInstaller val packageInstaller = context.packageManager.packageInstaller
val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL) val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
params.setAppPackageName(intent?.getStringExtra("pkg")) params.setAppPackageName(if (app == "microg") "com.mgoogle.android.gms" else "com.vanced.android.music")
val sessionId = packageInstaller.createSession(params) val sessionId = packageInstaller.createSession(params)
val session = packageInstaller.openSession(sessionId) val session = packageInstaller.openSession(sessionId)
val inputStream: InputStream = FileInputStream(path) val inputStream: InputStream = FileInputStream(path)
@ -172,8 +178,8 @@ object PackageHelper {
try { try {
try { try {
session = context.packageManager.packageInstaller.openSession(sessionId) session = context.packageManager.packageInstaller.openSession(sessionId)
val callbackIntent = Intent(context.context, SplitInstallerService::class.java) val callbackIntent = Intent(context, SplitInstallerService::class.java)
val pendingIntent = PendingIntent.getService(context.context, 0, callbackIntent, 0) val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0)
session.commit(pendingIntent.intentSender) session.commit(pendingIntent.intentSender)
session.close() session.close()
Log.d("AppLog", "install request sent") Log.d("AppLog", "install request sent")
@ -188,7 +194,7 @@ object PackageHelper {
} }
} }
fun insallVancedRoot(context: Context) { fun installVancedRoot(context: Context) {
Shell.enableVerboseLogging = BuildConfig.DEBUG Shell.enableVerboseLogging = BuildConfig.DEBUG
Shell.setDefaultBuilder( Shell.setDefaultBuilder(
Shell.Builder.create() Shell.Builder.create()
@ -198,7 +204,8 @@ object PackageHelper {
Shell.getShell { Shell.getShell {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
val apkFilesPath = getExternalFilesDir("apks")?.path val vancedVersionCode = InternetTools.getJsonInt("vanced.json", "versionCode", context)
val apkFilesPath = context.getExternalFilesDir("apks")?.path
val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) } val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) }
if (fileInfoList != null) { if (fileInfoList != null) {
var modApk: FileInfo? = null var modApk: FileInfo? = null
@ -208,22 +215,14 @@ object PackageHelper {
} }
} }
if (modApk != null) { if (modApk != null) {
if (getDefaultSharedPreferences(this@RootSplitInstallerService).getBoolean("new_installer", false)) { if (overwriteBase(modApk, fileInfoList, vancedVersionCode, context)) {
if (overwriteBase(modApk, fileInfoList, vancedVersionCode)) { LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(
with(localBroadcastManager) { HomeFragment.REFRESH_HOME))
sendBroadcast(Intent(HomeFragment.REFRESH_HOME)) }
sendBroadcast(Intent(HomeFragment.VANCED_INSTALLED))
}
}
} else
installSplitApkFiles(fileInfoList)
} }
else else {
{
sendFailure(listOf("ModApk_Missing").toMutableList(), context) sendFailure(listOf("ModApk_Missing").toMutableList(), context)
} }
//installSplitApkFiles(fileInfoList)
} }
else else
{ {
@ -234,7 +233,7 @@ object PackageHelper {
} }
} }
private fun installSplitApkFiles(apkFiles: ArrayList<FileInfo>) : Boolean { private fun installSplitApkFiles(apkFiles: ArrayList<FileInfo>, context: Context) : Boolean {
var sessionId: Int? var sessionId: Int?
Log.d("AppLog", "installing split apk files:$apkFiles") Log.d("AppLog", "installing split apk files:$apkFiles")
run { run {
@ -269,7 +268,7 @@ object PackageHelper {
if (installResult.isSuccess) { if (installResult.isSuccess) {
return true return true
} else } else
sendFailure(installResult.out, this) sendFailure(installResult.out, context)
return false return false
} }
@ -318,9 +317,9 @@ object PackageHelper {
} }
//install Vanced //install Vanced
private fun overwriteBase(apkFile: FileInfo,baseApkFiles: ArrayList<FileInfo>, versionCode: Int): Boolean { private fun overwriteBase(apkFile: FileInfo,baseApkFiles: ArrayList<FileInfo>, versionCode: Int, context: Context): Boolean {
if (checkVersion(versionCode,baseApkFiles)) { if (checkVersion(versionCode, baseApkFiles, context)) {
val path = getPackageDir() val path = getPackageDir(context)
apkFile.file?.let { apkFile.file?.let {
val apath = it.absolutePath val apath = it.absolutePath
@ -328,9 +327,9 @@ object PackageHelper {
if(path != null) if(path != null)
{ {
val apkFPath = apkInstallPath + "base.apk" val apkFPath = apkInstallPath + "base.apk"
if(moveAPK(apath, apkFPath)) if(moveAPK(apath, apkFPath, context))
{ {
if(chConV(apkFPath)) if(chConV(apkFPath, context))
{ {
if(setupScript(apkFPath,path)) if(setupScript(apkFPath,path))
{ {
@ -370,29 +369,29 @@ object PackageHelper {
} }
//check version and perform action based on result //check version and perform action based on result
private fun checkVersion(versionCode: Int, baseApkFiles: ArrayList<FileInfo>): Boolean { private fun checkVersion(versionCode: Int, baseApkFiles: ArrayList<FileInfo>, context: Context): Boolean {
val path = getPackageDir() val path = getPackageDir(context)
if (path != null) { if (path != null) {
if(path.contains("/data/app/")) if(path.contains("/data/app/"))
{ {
when(getVersionNumber()?.let { compareVersion(it,versionCode) }) when(getVersionNumber(context)?.let { compareVersion(it,versionCode) })
{ {
1 -> {return fixHigherVer(baseApkFiles) } 1 -> {return fixHigherVer(baseApkFiles, context) }
-1 -> {return fixLowerVer(baseApkFiles) } -1 -> {return fixLowerVer(baseApkFiles, context) }
} }
return true return true
} }
else else
{ {
return fixNoInstall(baseApkFiles) return fixNoInstall(baseApkFiles, context)
} }
} }
return fixNoInstall(baseApkFiles) return fixNoInstall(baseApkFiles, context)
} }
private fun getPkgInfo(pkg: String): PackageInfo? { private fun getPkgInfo(pkg: String, context: Context): PackageInfo? {
return try { return try {
packageManager.getPackageInfo(pkg, 0) context.packageManager.getPackageInfo(pkg, 0)
} catch (e:Exception) { } catch (e:Exception) {
Log.d("VMpm", "Unable to get package info") Log.d("VMpm", "Unable to get package info")
null null
@ -408,26 +407,26 @@ object PackageHelper {
} }
//uninstall current update and install base that works with patch //uninstall current update and install base that works with patch
private fun fixHigherVer(apkFiles: ArrayList<FileInfo>) : Boolean { private fun fixHigherVer(apkFiles: ArrayList<FileInfo>, context: Context) : Boolean {
if(PackageHelper.uninstallApk(yPkg, context)) { if (uninstallApk(yPkg, context)) {
return installSplitApkFiles(apkFiles) return installSplitApkFiles(apkFiles, context)
} }
sendFailure(listOf("Failed_Uninstall").toMutableList(), this) sendFailure(listOf("Failed_Uninstall").toMutableList(), context)
return false return false
} }
//install newer stock youtube //install newer stock youtube
private fun fixLowerVer(apkFiles: ArrayList<FileInfo>): Boolean { private fun fixLowerVer(apkFiles: ArrayList<FileInfo>, context: Context): Boolean {
return installSplitApkFiles(apkFiles) return installSplitApkFiles(apkFiles, context)
} }
//install stock youtube since no install was found //install stock youtube since no install was found
private fun fixNoInstall(baseApkFiles: ArrayList<FileInfo>): Boolean { private fun fixNoInstall(baseApkFiles: ArrayList<FileInfo>, context: Context): Boolean {
return installSplitApkFiles(baseApkFiles) return installSplitApkFiles(baseApkFiles, context)
} }
//set chcon to apk_data_file //set chcon to apk_data_file
private fun chConV(path: String): Boolean { private fun chConV(path: String, context: Context): Boolean {
val response = Shell.su("chcon u:object_r:apk_data_file:s0 $path").exec() val response = Shell.su("chcon u:object_r:apk_data_file:s0 $path").exec()
//val response = Shell.su("chcon -R u:object_r:system_file:s0 $path").exec() //val response = Shell.su("chcon -R u:object_r:system_file:s0 $path").exec()
return if (response.isSuccess) { return if (response.isSuccess) {
@ -439,7 +438,7 @@ object PackageHelper {
} }
//move patch to data/app //move patch to data/app
private fun moveAPK(apkFile: String, path: String) : Boolean { private fun moveAPK(apkFile: String, path: String, context: Context) : Boolean {
val apkinF = SuFile.open(apkFile) val apkinF = SuFile.open(apkFile)
val apkoutF = SuFile.open(path) val apkoutF = SuFile.open(path)
@ -479,9 +478,9 @@ object PackageHelper {
} }
//get path of the installed youtube //get path of the installed youtube
private fun getVPath(): String? { private fun getVPath(context: Context): String? {
return try { return try {
val p = getPkgInfo(yPkg) val p = getPkgInfo(yPkg, context)
p?.applicationInfo?.sourceDir p?.applicationInfo?.sourceDir
} catch (e: Exception) { } catch (e: Exception) {
null null
@ -489,23 +488,19 @@ object PackageHelper {
} }
private fun getVersionNumber(): Int? private fun getVersionNumber(context: Context): Int? {
{
try { try {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
packageManager.getPackageInfo(yPkg, 0)?.longVersionCode?.and(0xFFFFFFFF)?.toInt() context.packageManager.getPackageInfo(yPkg, 0)?.longVersionCode?.and(0xFFFFFFFF)?.toInt()
else else
packageManager.getPackageInfo(yPkg, 0)?.versionCode context.packageManager.getPackageInfo(yPkg, 0)?.versionCode
} }
catch (e : Exception) catch (e : Exception) {
{
val execRes = Shell.su("dumpsys package com.google.android.youtube | grep versionCode").exec() val execRes = Shell.su("dumpsys package com.google.android.youtube | grep versionCode").exec()
if(execRes.isSuccess) if(execRes.isSuccess) {
{
val result = execRes.out val result = execRes.out
var version: Int = 0 var version = 0
for(line in result) for(line in result) {
{
val versionCode = line.substringAfter("=") val versionCode = line.substringAfter("=")
val versionCodeFiltered = versionCode.substringBefore(" ") val versionCodeFiltered = versionCode.substringBefore(" ")
if(version < Integer.valueOf(versionCodeFiltered)) if(version < Integer.valueOf(versionCodeFiltered))
@ -519,10 +514,10 @@ object PackageHelper {
return null return null
} }
private fun getPackageDir(): String? private fun getPackageDir(context: Context): String?
{ {
return try { return try {
val p = getPkgInfo(yPkg) val p = getPkgInfo(yPkg, context)
p?.applicationInfo?.sourceDir p?.applicationInfo?.sourceDir
} catch (e: Exception) { } catch (e: Exception) {
val execRes = Shell.su("dumpsys package com.google.android.youtube | grep codePath").exec() val execRes = Shell.su("dumpsys package com.google.android.youtube | grep codePath").exec()

View File

@ -18,7 +18,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
bind:refreshing="@{viewModel.fetching}" bind:refreshing="@{viewModel.fetching}"
bind:onRefreshListener="@{()-> viewModel.Companion.fetchData()}"> bind:onRefreshListener="@{()-> viewModel.fetchData()}">
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout> <layout>
<data> <data>
<variable <variable
name="viewModel" name="viewModel"
type="com.vanced.manager.ui.viewmodels.AboutViewModel" /> type="com.vanced.manager.ui.viewmodels.AboutViewModel" />
</data> </data>
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView

View File

@ -10,7 +10,7 @@
<variable <variable
name="viewModel" name="viewModel"
type="com.microg.manager.ui.viewmodels.HomeViewModel" /> type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
</data> </data>

View File

@ -10,7 +10,7 @@
<variable <variable
name="viewModel" name="viewModel"
type="com.music.manager.ui.viewmodels.HomeViewModel" /> type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
</data> </data>

View File

@ -30,11 +30,6 @@
android:defaultValue="true" android:defaultValue="true"
android:icon="@drawable/ic_notifications_black_24dp"/> android:icon="@drawable/ic_notifications_black_24dp"/>
<SwitchPreference
android:key="new_installer"
android:title="@string/new_installer_title"
android:summary="@string/new_installer_summary" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory