finished code cleanup
This commit is contained in:
parent
bfa6885b26
commit
a63b549b91
|
@ -6,7 +6,6 @@ import com.downloader.Error
|
|||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.PRDownloader
|
||||
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.utils.AppUtils.installing
|
||||
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
||||
|
@ -34,18 +33,18 @@ object MicrogDownloader {
|
|||
microgProgress.get()?.showDownloadBar = true
|
||||
}
|
||||
.setOnProgressListener { progress ->
|
||||
microgProgress.get()?.setDownloadProgress(progress.currentBytes * 100 / progress.totalBytes)
|
||||
microgProgress.get()?.setDownloadProgress((progress.currentBytes * 100 / progress.totalBytes).toInt())
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
install("microg", "${context.getExternalFilesDir("apk")}/microg.apk", context)
|
||||
microgProgress.showDownloadBar = false
|
||||
microgProgress.showInstallCircle = true
|
||||
microgProgress.get()?.showDownloadBar = false
|
||||
microgProgress.get()?.showInstallCircle = true
|
||||
}
|
||||
|
||||
override fun onError(error: Error?) {
|
||||
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()
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package com.vanced.manager.core.downloader
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import com.downloader.Error
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.PRDownloader
|
||||
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.utils.AppUtils.installing
|
||||
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
||||
|
@ -28,7 +26,7 @@ object MusicDownloader {
|
|||
|
||||
//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()
|
||||
.setOnStartOrResumeListener {
|
||||
installing = true
|
||||
|
@ -36,18 +34,18 @@ object MusicDownloader {
|
|||
musicProgress.get()?.showDownloadBar = true
|
||||
}
|
||||
.setOnProgressListener { progress ->
|
||||
musicProgress.get()?.setDownloadProgress(progress.currentBytes * 100 / progress.totalBytes)
|
||||
musicProgress.get()?.setDownloadProgress((progress.currentBytes * 100 / progress.totalBytes).toInt())
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
install("music", "${context.getExternalFilesDir("apk")}/music.apk", context)
|
||||
musicProgress.get().showDownloadBar = false
|
||||
musicProgress.get().showInstallCircle = true
|
||||
musicProgress.get()?.showDownloadBar = false
|
||||
musicProgress.get()?.showInstallCircle = true
|
||||
}
|
||||
|
||||
override fun onError(error: Error?) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
package com.vanced.manager.core.downloader
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.widget.Toast
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.downloader.Error
|
||||
import com.downloader.OnDownloadListener
|
||||
import com.downloader.PRDownloader
|
||||
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.utils.AppUtils.installing
|
||||
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.PackageHelper.getPkgVerCode
|
||||
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.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -50,16 +46,16 @@ object VancedDownloader {
|
|||
private var count: Int = 0
|
||||
private var hashUrl = ""
|
||||
|
||||
private val yPkg = "com.google.android.youtube"
|
||||
private val vancedVersionCode by lazy {runBlocking { InternetTools.getJsonInt("vanced.json", "versionCode", applicationContext) }}
|
||||
private const val yPkg = "com.google.android.youtube"
|
||||
private var vancedVersionCode = 0
|
||||
private val vancedVersion by lazy { runBlocking { getObjectFromJson("$installUrl/vanced.json", "version") }}
|
||||
|
||||
fun downloadVanced(context: Context) {
|
||||
//registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
|
||||
File(context.getExternalFilesDir("apks")?.path as String).deleteRecursively()
|
||||
defPrefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
defPrefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
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")
|
||||
lang = prefs.getString("lang", "en")?.split(", ")?.toTypedArray()
|
||||
theme = prefs.getString("theme", "dark")
|
||||
|
@ -72,10 +68,11 @@ object VancedDownloader {
|
|||
Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm64_v8a"
|
||||
else -> "armeabi_v7a"
|
||||
}
|
||||
vancedVersionCode = runBlocking { InternetTools.getJsonInt("vanced.json", "versionCode", context) }
|
||||
downloadSplits(context)
|
||||
}
|
||||
|
||||
private fun downloadSplits(context,
|
||||
private fun downloadSplits(
|
||||
context: Context,
|
||||
type: String = "theme"
|
||||
) {
|
||||
|
@ -94,7 +91,7 @@ object VancedDownloader {
|
|||
//downloadId = download(url, "apks", getFileNameFromUrl(url), this@VancedDownloadService)
|
||||
|
||||
PRDownloader
|
||||
.download(url, getExternalFilesDir("apks")?.path, getFileNameFromUrl(url))
|
||||
.download(url, context.getExternalFilesDir("apks")?.path, getFileNameFromUrl(url))
|
||||
.build()
|
||||
.setOnStartOrResumeListener {
|
||||
installing = true
|
||||
|
@ -102,18 +99,18 @@ object VancedDownloader {
|
|||
vancedProgress.get()?.showDownloadBar = true
|
||||
}
|
||||
.setOnProgressListener { progress ->
|
||||
vancedProgress.get()?.setDownloadProgress(progress.currentBytes * 100 / progress.totalBytes)
|
||||
vancedProgress.get()?.setDownloadProgress((progress.currentBytes * 100 / progress.totalBytes).toInt())
|
||||
}
|
||||
.start(object : OnDownloadListener {
|
||||
override fun onDownloadComplete() {
|
||||
when (type) {
|
||||
"theme" ->
|
||||
if (variant == "root" && newInstaller == true) {
|
||||
if (ValidateTheme()) {
|
||||
if(downloadStockCheck())
|
||||
if (validateTheme(context)) {
|
||||
if(downloadStockCheck(context))
|
||||
downloadSplits(context, "arch")
|
||||
else
|
||||
prepareInstall(variant!!)
|
||||
prepareInstall(variant!!, context)
|
||||
} else
|
||||
downloadSplits(context, "theme")
|
||||
} else
|
||||
|
@ -126,7 +123,7 @@ object VancedDownloader {
|
|||
if (count < lang?.count()!!)
|
||||
downloadSplits(context, "lang")
|
||||
else
|
||||
prepareInstall(variant!!)
|
||||
prepareInstall(variant!!, context)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -137,35 +134,34 @@ object VancedDownloader {
|
|||
if (count < lang?.count()!!)
|
||||
downloadSplits(context, "lang")
|
||||
else
|
||||
prepareInstall(variant!!)
|
||||
prepareInstall(variant!!, context)
|
||||
} else {
|
||||
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 {
|
||||
getPkgVerCode(yPkg, packageManager) != vancedVersionCode
|
||||
getPkgVerCode(yPkg,context.packageManager) != vancedVersionCode
|
||||
} catch (e: Exception) {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getSha256(obj: String) {
|
||||
sha256Val = InternetTools.getJsonString(hashUrl,obj,applicationContext)
|
||||
private suspend fun getSha256(obj: String, context: Context) {
|
||||
sha256Val = InternetTools.getJsonString(hashUrl, obj, context)
|
||||
}
|
||||
|
||||
private fun ValidateTheme(): Boolean
|
||||
{
|
||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
private fun validateTheme(context: Context): Boolean {
|
||||
val prefs = context.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
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)
|
||||
runBlocking { getSha256(theme!!) }
|
||||
runBlocking { getSha256(theme!!, context) }
|
||||
return checkSHA256(sha256Val!!,themeF)
|
||||
}
|
||||
|
||||
|
@ -203,11 +199,7 @@ object VancedDownloader {
|
|||
if (variant == "root")
|
||||
installVancedRoot(context)
|
||||
else
|
||||
installvanced(context)
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return null
|
||||
installVanced(context)
|
||||
}
|
||||
|
||||
private fun checkSHA256(sha256: String, updateFile: File?): Boolean {
|
||||
|
|
|
@ -7,11 +7,10 @@ import android.os.IBinder
|
|||
import android.util.Log
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.microgProgress
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.musicProgress
|
||||
import com.vanced.manager.utils.AppUtils.sendFailure
|
||||
|
||||
class AppInstallerService: Service() {
|
||||
|
||||
private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(this) }
|
||||
|
||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999)) {
|
||||
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
|
||||
|
@ -26,7 +25,7 @@ class AppInstallerService: Service() {
|
|||
}
|
||||
PackageInstaller.STATUS_SUCCESS -> {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -5,11 +5,7 @@ import android.content.Intent
|
|||
import android.content.pm.PackageInstaller
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel.Companion.fetchData
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import com.vanced.manager.utils.AppUtils.sendRefresh
|
||||
|
||||
class AppUninstallerService: Service() {
|
||||
|
||||
|
@ -27,20 +23,14 @@ class AppUninstallerService: Service() {
|
|||
}
|
||||
//Delay broadcast until activity (and fragment) show up on the screen
|
||||
PackageInstaller.STATUS_SUCCESS -> {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
delay(500)
|
||||
fetchData()
|
||||
sendRefresh(this)
|
||||
Log.d("VMpm", "Successfully uninstalled $pkgName")
|
||||
}
|
||||
}
|
||||
PackageInstaller.STATUS_FAILURE -> {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
delay(500)
|
||||
fetchData()
|
||||
sendRefresh(this)
|
||||
Log.d("VMpm", "Failed to uninstall $pkgName")
|
||||
}
|
||||
}
|
||||
}
|
||||
stopSelf()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import android.content.pm.PackageInstaller
|
|||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
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.sendRefresh
|
||||
|
||||
class SplitInstallerService: Service() {
|
||||
|
||||
|
@ -24,8 +24,8 @@ class SplitInstallerService: Service() {
|
|||
}
|
||||
PackageInstaller.STATUS_SUCCESS -> {
|
||||
Log.d(TAG, "Installation succeed")
|
||||
vancedProgress.showInstallCircle = false
|
||||
fetchData()
|
||||
vancedProgress.get()?.showInstallCircle = false
|
||||
sendRefresh(this)
|
||||
}
|
||||
else -> sendFailure(intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999), this)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.vanced.manager.model
|
|||
|
||||
open class ProgressModel {
|
||||
|
||||
private var downloadProgres = 0
|
||||
private var downloadProgress = 0
|
||||
private var downloadingFile = ""
|
||||
|
||||
var showInstallCircle = false
|
||||
|
@ -12,12 +12,12 @@ open class ProgressModel {
|
|||
return downloadProgress
|
||||
}
|
||||
|
||||
open fun setDownloadProgress(progresss: Int) {
|
||||
open fun setDownloadProgress(progress: Int) {
|
||||
downloadProgress = progress
|
||||
}
|
||||
|
||||
open fun getDownloadingFile(): String {
|
||||
return downloadProgress
|
||||
return downloadingFile
|
||||
}
|
||||
|
||||
open fun setDownloadingFile(file: String) {
|
||||
|
|
|
@ -8,10 +8,10 @@ import androidx.core.content.ContextCompat.startActivity
|
|||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.downloader.VancedDownloadService
|
||||
import com.vanced.manager.core.installer.SplitInstaller
|
||||
import com.vanced.manager.core.downloader.VancedDownloader.downloadVanced
|
||||
import com.vanced.manager.utils.InternetTools.openUrl
|
||||
import com.vanced.manager.utils.MiuiHelper
|
||||
import com.vanced.manager.utils.PackageHelper.installVanced
|
||||
|
||||
object DialogContainer {
|
||||
|
||||
|
@ -63,11 +63,11 @@ object DialogContainer {
|
|||
setTitle("")
|
||||
setMessage("")
|
||||
setNegativeButton("") { dialog, _ ->
|
||||
context.startService(Intent(context, VancedDownloadService::class.java))
|
||||
downloadVanced(context)
|
||||
dialog.dismiss()
|
||||
}
|
||||
setPositiveButton(context.getString(R.string.button_reinstall)) { dialog, _ ->
|
||||
context.startService(Intent(context, SplitInstaller::class.java))
|
||||
installVanced(context)
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.vanced.manager.ui.fragments
|
|||
|
||||
import android.content.*
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import android.widget.Toast
|
||||
|
@ -10,8 +9,6 @@ import androidx.databinding.DataBindingUtil
|
|||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
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.TabLayoutMediator
|
||||
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.viewmodels.HomeViewModel
|
||||
import com.vanced.manager.utils.AppUtils.installing
|
||||
import com.vanced.manager.utils.PackageHelper
|
||||
|
||||
open class HomeFragment : Fragment(), View.OnClickListener {
|
||||
|
||||
|
@ -37,7 +33,7 @@ open class HomeFragment : Fragment(), View.OnClickListener {
|
|||
): View? {
|
||||
requireActivity().title = getString(R.string.title_home)
|
||||
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.viewModel = viewModel
|
||||
viewModel.variant = variant
|
||||
|
@ -139,6 +135,7 @@ open class HomeFragment : Fragment(), View.OnClickListener {
|
|||
installAlertBuilder(intent.getStringExtra("errorMsg") as String, requireActivity())
|
||||
installing = false
|
||||
}
|
||||
REFRESH_HOME -> viewModel.fetchData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,6 +153,7 @@ open class HomeFragment : Fragment(), View.OnClickListener {
|
|||
|
||||
companion object {
|
||||
const val INSTALL_FAILED = "install_failed"
|
||||
const val REFRESH_HOME = "refresh_home"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.vanced.manager.ui.fragments
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
@ -16,7 +15,7 @@ import androidx.preference.PreferenceManager
|
|||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.checkbox.MaterialCheckBox
|
||||
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.getArrayFromJson
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
@ -56,7 +55,7 @@ class VancedLanguageSelectionFragment : Fragment() {
|
|||
putString("lang", chosenLangs.joinToString())?.apply()
|
||||
putBoolean("valuesModified", true).apply()
|
||||
}
|
||||
startService(Intent(this, VancedDownloadService::class.java))
|
||||
downloadVanced(requireActivity())
|
||||
}
|
||||
view.findNavController().navigate(R.id.action_installTo_homeFragment)
|
||||
}
|
||||
|
|
|
@ -1,29 +1,14 @@
|
|||
package com.vanced.manager.ui.viewmodels
|
||||
|
||||
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.preference.PreferenceManager
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.InternetTools
|
||||
|
||||
class AboutViewModel(application: Application): AndroidViewModel(application) {
|
||||
|
||||
fun openUrl(Url: String) {
|
||||
val customTabPrefs = PreferenceManager.getDefaultSharedPreferences(getApplication()).getBoolean("use_customtabs", true)
|
||||
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)
|
||||
}
|
||||
fun openUrl(url: String) {
|
||||
InternetTools.openUrl(url, R.color.GitHub, getApplication())
|
||||
}
|
||||
|
||||
}
|
|
@ -5,25 +5,20 @@ import android.content.ActivityNotFoundException
|
|||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.widget.Toast
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
import androidx.databinding.ObservableBoolean
|
||||
import androidx.databinding.ObservableField
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.navigation.Navigation.findNavController
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import androidx.navigation.fragment.NavHostFragment.findNavController
|
||||
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.MusicDownloader.downloadMusic
|
||||
import com.vanced.manager.core.downloader.VancedDownloader.downloadVanced
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.model.DataModel
|
||||
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.InternetTools
|
||||
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 =
|
||||
if (variant == "root")
|
||||
|
@ -97,12 +93,12 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
|
|||
if (!installing) {
|
||||
if (!fetching.get()) {
|
||||
if (variant == "nonroot" && !microg.get()?.isAppInstalled()!!) {
|
||||
microgSnackbar.show()
|
||||
microgToast.show()
|
||||
} else {
|
||||
if (app.getSharedPreferences("installPrefs", Context.MODE_PRIVATE).getBoolean("valuesModified", false)!!) {
|
||||
downloadVanced()
|
||||
if (app.getSharedPreferences("installPrefs", Context.MODE_PRIVATE).getBoolean("valuesModified", false)) {
|
||||
downloadVanced(app)
|
||||
} 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 (!fetching.get()) {
|
||||
if (!microg.get()?.isAppInstalled()!!) {
|
||||
microgSnackbar.show()
|
||||
microgToast.show()
|
||||
} else {
|
||||
downloadMusic(getApplication())
|
||||
}
|
||||
|
|
|
@ -15,6 +15,13 @@ object AppUtils {
|
|||
|
||||
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) {
|
||||
//Delay error broadcast until activity (and fragment) get back to the screen
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
|
|
|
@ -1,17 +1,32 @@
|
|||
package com.vanced.manager.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
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.AppUninstallerService
|
||||
import com.vanced.manager.core.installer.SplitInstallerService
|
||||
import java.io.FileInputStream
|
||||
import java.io.InputStream
|
||||
import com.vanced.manager.ui.fragments.HomeFragment
|
||||
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 {
|
||||
|
||||
|
@ -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 {
|
||||
val callbackIntent = Intent(context, AppUninstallerService::class.java)
|
||||
callbackIntent.putExtra("pkg", pkg)
|
||||
val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0)
|
||||
try {
|
||||
return try {
|
||||
context.packageManager.packageInstaller.uninstall(pkg, pendingIntent.intentSender)
|
||||
return true
|
||||
}
|
||||
catch (e: Exception)
|
||||
{
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return false;
|
||||
false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +76,7 @@ object PackageHelper {
|
|||
val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0)
|
||||
val packageInstaller = context.packageManager.packageInstaller
|
||||
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 session = packageInstaller.openSession(sessionId)
|
||||
val inputStream: InputStream = FileInputStream(path)
|
||||
|
@ -172,8 +178,8 @@ object PackageHelper {
|
|||
try {
|
||||
try {
|
||||
session = context.packageManager.packageInstaller.openSession(sessionId)
|
||||
val callbackIntent = Intent(context.context, SplitInstallerService::class.java)
|
||||
val pendingIntent = PendingIntent.getService(context.context, 0, callbackIntent, 0)
|
||||
val callbackIntent = Intent(context, SplitInstallerService::class.java)
|
||||
val pendingIntent = PendingIntent.getService(context, 0, callbackIntent, 0)
|
||||
session.commit(pendingIntent.intentSender)
|
||||
session.close()
|
||||
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.setDefaultBuilder(
|
||||
Shell.Builder.create()
|
||||
|
@ -198,7 +204,8 @@ object PackageHelper {
|
|||
|
||||
Shell.getShell {
|
||||
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) }
|
||||
if (fileInfoList != null) {
|
||||
var modApk: FileInfo? = null
|
||||
|
@ -208,22 +215,14 @@ object PackageHelper {
|
|||
}
|
||||
}
|
||||
if (modApk != null) {
|
||||
if (getDefaultSharedPreferences(this@RootSplitInstallerService).getBoolean("new_installer", false)) {
|
||||
if (overwriteBase(modApk, fileInfoList, vancedVersionCode)) {
|
||||
with(localBroadcastManager) {
|
||||
sendBroadcast(Intent(HomeFragment.REFRESH_HOME))
|
||||
sendBroadcast(Intent(HomeFragment.VANCED_INSTALLED))
|
||||
if (overwriteBase(modApk, fileInfoList, vancedVersionCode, context)) {
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(Intent(
|
||||
HomeFragment.REFRESH_HOME))
|
||||
}
|
||||
}
|
||||
} else
|
||||
installSplitApkFiles(fileInfoList)
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
sendFailure(listOf("ModApk_Missing").toMutableList(), context)
|
||||
}
|
||||
//installSplitApkFiles(fileInfoList)
|
||||
}
|
||||
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?
|
||||
Log.d("AppLog", "installing split apk files:$apkFiles")
|
||||
run {
|
||||
|
@ -269,7 +268,7 @@ object PackageHelper {
|
|||
if (installResult.isSuccess) {
|
||||
return true
|
||||
} else
|
||||
sendFailure(installResult.out, this)
|
||||
sendFailure(installResult.out, context)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -318,9 +317,9 @@ object PackageHelper {
|
|||
}
|
||||
|
||||
//install Vanced
|
||||
private fun overwriteBase(apkFile: FileInfo,baseApkFiles: ArrayList<FileInfo>, versionCode: Int): Boolean {
|
||||
if (checkVersion(versionCode,baseApkFiles)) {
|
||||
val path = getPackageDir()
|
||||
private fun overwriteBase(apkFile: FileInfo,baseApkFiles: ArrayList<FileInfo>, versionCode: Int, context: Context): Boolean {
|
||||
if (checkVersion(versionCode, baseApkFiles, context)) {
|
||||
val path = getPackageDir(context)
|
||||
apkFile.file?.let {
|
||||
val apath = it.absolutePath
|
||||
|
||||
|
@ -328,9 +327,9 @@ object PackageHelper {
|
|||
if(path != null)
|
||||
{
|
||||
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))
|
||||
{
|
||||
|
@ -370,29 +369,29 @@ object PackageHelper {
|
|||
}
|
||||
|
||||
//check version and perform action based on result
|
||||
private fun checkVersion(versionCode: Int, baseApkFiles: ArrayList<FileInfo>): Boolean {
|
||||
val path = getPackageDir()
|
||||
private fun checkVersion(versionCode: Int, baseApkFiles: ArrayList<FileInfo>, context: Context): Boolean {
|
||||
val path = getPackageDir(context)
|
||||
if (path != null) {
|
||||
if(path.contains("/data/app/"))
|
||||
{
|
||||
when(getVersionNumber()?.let { compareVersion(it,versionCode) })
|
||||
when(getVersionNumber(context)?.let { compareVersion(it,versionCode) })
|
||||
{
|
||||
1 -> {return fixHigherVer(baseApkFiles) }
|
||||
-1 -> {return fixLowerVer(baseApkFiles) }
|
||||
1 -> {return fixHigherVer(baseApkFiles, context) }
|
||||
-1 -> {return fixLowerVer(baseApkFiles, context) }
|
||||
}
|
||||
return true
|
||||
}
|
||||
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 {
|
||||
packageManager.getPackageInfo(pkg, 0)
|
||||
context.packageManager.getPackageInfo(pkg, 0)
|
||||
} catch (e:Exception) {
|
||||
Log.d("VMpm", "Unable to get package info")
|
||||
null
|
||||
|
@ -408,26 +407,26 @@ object PackageHelper {
|
|||
}
|
||||
|
||||
//uninstall current update and install base that works with patch
|
||||
private fun fixHigherVer(apkFiles: ArrayList<FileInfo>) : Boolean {
|
||||
if(PackageHelper.uninstallApk(yPkg, context)) {
|
||||
return installSplitApkFiles(apkFiles)
|
||||
private fun fixHigherVer(apkFiles: ArrayList<FileInfo>, context: Context) : Boolean {
|
||||
if (uninstallApk(yPkg, context)) {
|
||||
return installSplitApkFiles(apkFiles, context)
|
||||
}
|
||||
sendFailure(listOf("Failed_Uninstall").toMutableList(), this)
|
||||
sendFailure(listOf("Failed_Uninstall").toMutableList(), context)
|
||||
return false
|
||||
}
|
||||
|
||||
//install newer stock youtube
|
||||
private fun fixLowerVer(apkFiles: ArrayList<FileInfo>): Boolean {
|
||||
return installSplitApkFiles(apkFiles)
|
||||
private fun fixLowerVer(apkFiles: ArrayList<FileInfo>, context: Context): Boolean {
|
||||
return installSplitApkFiles(apkFiles, context)
|
||||
}
|
||||
|
||||
//install stock youtube since no install was found
|
||||
private fun fixNoInstall(baseApkFiles: ArrayList<FileInfo>): Boolean {
|
||||
return installSplitApkFiles(baseApkFiles)
|
||||
private fun fixNoInstall(baseApkFiles: ArrayList<FileInfo>, context: Context): Boolean {
|
||||
return installSplitApkFiles(baseApkFiles, context)
|
||||
}
|
||||
|
||||
//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 -R u:object_r:system_file:s0 $path").exec()
|
||||
return if (response.isSuccess) {
|
||||
|
@ -439,7 +438,7 @@ object PackageHelper {
|
|||
}
|
||||
|
||||
//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 apkoutF = SuFile.open(path)
|
||||
|
||||
|
@ -479,9 +478,9 @@ object PackageHelper {
|
|||
}
|
||||
|
||||
//get path of the installed youtube
|
||||
private fun getVPath(): String? {
|
||||
private fun getVPath(context: Context): String? {
|
||||
return try {
|
||||
val p = getPkgInfo(yPkg)
|
||||
val p = getPkgInfo(yPkg, context)
|
||||
p?.applicationInfo?.sourceDir
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
|
@ -489,23 +488,19 @@ object PackageHelper {
|
|||
|
||||
}
|
||||
|
||||
private fun getVersionNumber(): Int?
|
||||
{
|
||||
private fun getVersionNumber(context: Context): Int? {
|
||||
try {
|
||||
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
|
||||
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()
|
||||
if(execRes.isSuccess)
|
||||
{
|
||||
if(execRes.isSuccess) {
|
||||
val result = execRes.out
|
||||
var version: Int = 0
|
||||
for(line in result)
|
||||
{
|
||||
var version = 0
|
||||
for(line in result) {
|
||||
val versionCode = line.substringAfter("=")
|
||||
val versionCodeFiltered = versionCode.substringBefore(" ")
|
||||
if(version < Integer.valueOf(versionCodeFiltered))
|
||||
|
@ -519,10 +514,10 @@ object PackageHelper {
|
|||
return null
|
||||
}
|
||||
|
||||
private fun getPackageDir(): String?
|
||||
private fun getPackageDir(context: Context): String?
|
||||
{
|
||||
return try {
|
||||
val p = getPkgInfo(yPkg)
|
||||
val p = getPkgInfo(yPkg, context)
|
||||
p?.applicationInfo?.sourceDir
|
||||
} catch (e: Exception) {
|
||||
val execRes = Shell.su("dumpsys package com.google.android.youtube | grep codePath").exec()
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
bind:refreshing="@{viewModel.fetching}"
|
||||
bind:onRefreshListener="@{()-> viewModel.Companion.fetchData()}">
|
||||
bind:onRefreshListener="@{()-> viewModel.fetchData()}">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.vanced.manager.ui.viewmodels.AboutViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.microg.manager.ui.viewmodels.HomeViewModel" />
|
||||
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.music.manager.ui.viewmodels.HomeViewModel" />
|
||||
type="com.vanced.manager.ui.viewmodels.HomeViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
|
|
|
@ -30,11 +30,6 @@
|
|||
android:defaultValue="true"
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue