diff --git a/app/build.gradle b/app/build.gradle index 6bc8bde6..74110728 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,6 +5,7 @@ apply plugin: 'kotlin-kapt' apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.firebase-perf' apply plugin: 'com.google.firebase.crashlytics' +apply plugin: 'androidx.navigation.safeargs.kotlin' android { compileSdkVersion 30 diff --git a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt index 0ecbb658..737ed8fd 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt @@ -3,6 +3,7 @@ package com.vanced.manager.core.downloader import android.app.Service import android.content.Context import android.content.Intent +import android.content.SharedPreferences import android.os.Build import android.os.IBinder import android.widget.Toast @@ -32,8 +33,17 @@ import java.security.MessageDigest class VancedDownloadService: Service() { private var sha256Val: String? = null - private var vancedVersionCode: Int? = null + + private lateinit var prefs: SharedPreferences + private lateinit var defPrefs: SharedPreferences + private lateinit var arch: String + private var installUrl: String? = null + private var variant: String? = null + private var theme: String? = null + private var lang: Array? = null + private lateinit var themePath: String + //private var downloadId: Long = 0 //private var apkType: String = "arch" private var count: Int = 0 @@ -41,15 +51,26 @@ class VancedDownloadService: Service() { private var hashUrl = "" private val yPkg = "com.google.android.youtube" - - suspend fun getVer() - { - vancedVersionCode = InternetTools.getJsonInt("vanced.json", "versionCode", application) - } + private val vancedVersionCode: Int = runBlocking { InternetTools.getJsonInt("vanced.json", "versionCode", application) } + private val vancedVersion = runBlocking { getObjectFromJson("$installUrl/vanced.json", "version") } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { //registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) - runBlocking { getVer() } + File(getExternalFilesDir("apks")?.path as String).deleteRecursively() + defPrefs = PreferenceManager.getDefaultSharedPreferences(this) + installUrl = defPrefs.getString("install_url", baseUrl) + prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE) + variant = defPrefs.getString("vanced_variant", "nonroot") + lang = prefs.getString("lang", "en")?.split(", ")?.toTypedArray() + theme = prefs.getString("theme", "dark") + themePath = "$installUrl/apks/v$vancedVersion/$variant/Theme" + hashUrl = "apks/v$vancedVersion/$variant/Theme/hash.json" + arch = + when { + Build.SUPPORTED_ABIS.contains("x86") -> "x86" + Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm64_v8a" + else -> "armeabi_v7a" + } downloadSplits() stopSelf() return START_NOT_STICKY @@ -59,30 +80,13 @@ class VancedDownloadService: Service() { type: String = "theme" ) { CoroutineScope(Dispatchers.IO).launch { - File(getExternalFilesDir("apk")?.path as String).deleteRecursively() - val defPrefs = PreferenceManager.getDefaultSharedPreferences(this@VancedDownloadService) - val installUrl = defPrefs.getString("install_url", baseUrl) - val vancedVer = getObjectFromJson("$installUrl/vanced.json", "version") - - val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE) - val variant = defPrefs.getString("vanced_variant", "nonroot") - val lang = prefs?.getString("lang", "en")?.split(", ")?.toTypedArray() - val theme = prefs?.getString("theme", "dark") - val arch = - when { - Build.SUPPORTED_ABIS.contains("x86") -> "x86" - Build.SUPPORTED_ABIS.contains("arm64-v8a") -> "arm64_v8a" - else -> "armeabi_v7a" - } - val themePath = "$installUrl/apks/v$vancedVer/$variant/Theme" - hashUrl = "apks/v$vancedVer/$variant/Theme/hash.json" val url = when (type) { - "arch" -> "$installUrl/apks/v$vancedVer/$variant/Arch/split_config.$arch.apk" "theme" -> "$themePath/$theme.apk" + "arch" -> "$installUrl/apks/v$vancedVersion/$variant/Arch/split_config.$arch.apk" "stock" -> "$themePath/stock.apk" "dpi" -> "$themePath/dpi.apk" - "lang" -> "$installUrl/apks/v$vancedVer/$variant/Language/split_config.${lang?.get(count)}.apk" + "lang" -> "$installUrl/apks/v$vancedVersion/$variant/Language/split_config.${lang?.get(count)}.apk" else -> throw NotImplementedError("This type of APK is NOT valid. What the hell did you even do?") } @@ -100,10 +104,18 @@ class VancedDownloadService: Service() { .start(object : OnDownloadListener { override fun onDownloadComplete() { when (type) { - "theme" -> if(variant=="root") { - if(ValidateTheme()) {if(downloadStockCheck())downloadSplits("arch") else prepareInstall(variant)} else downloadSplits("theme") - } else downloadSplits("arch") - "arch" -> if(variant=="root") downloadSplits("stock") else downloadSplits("lang") + "theme" -> + if (variant == "root") { + if (ValidateTheme()) { + if(downloadStockCheck()) + downloadSplits("arch") + else + prepareInstall(variant!!) + } else + downloadSplits("theme") + } else + downloadSplits("arch") + "arch" -> if (variant == "root") downloadSplits("stock") else downloadSplits("lang") "stock" -> downloadSplits("dpi") "dpi" -> downloadSplits("lang") "lang" -> { @@ -116,7 +128,6 @@ class VancedDownloadService: Service() { } } - override fun onError(error: Error?) { installing = false Toast.makeText(this@VancedDownloadService, getString(R.string.error_downloading, "Vanced"), Toast.LENGTH_SHORT).show() @@ -125,14 +136,18 @@ class VancedDownloadService: Service() { } } - private fun downloadStockCheck():Boolean - { - - return try {getPkgVerCode(yPkg, packageManager) != vancedVersionCode}catch (e: Exception) {true} + private fun downloadStockCheck():Boolean { + return try { + getPkgVerCode(yPkg, packageManager) != vancedVersionCode + } catch (e: Exception) { + true + } } + suspend fun getSha256(obj: String) { sha256Val = InternetTools.getJsonString(hashUrl,obj,applicationContext) } + private fun ValidateTheme(): Boolean { val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE) @@ -223,4 +238,4 @@ class VancedDownloadService: Service() { } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/vanced/manager/core/installer/RootSplitInstallerService.kt b/app/src/main/java/com/vanced/manager/core/installer/RootSplitInstallerService.kt index c9267fff..5d798fd1 100644 --- a/app/src/main/java/com/vanced/manager/core/installer/RootSplitInstallerService.kt +++ b/app/src/main/java/com/vanced/manager/core/installer/RootSplitInstallerService.kt @@ -29,22 +29,14 @@ import java.util.* import java.util.regex.Pattern import kotlin.collections.ArrayList - class RootSplitInstallerService: Service() { - private var vancedVersionCode: Int = 0 + private var vancedVersionCode: Int = runBlocking { getJsonInt("vanced.json","versionCode", application) } val yPkg = "com.google.android.youtube" private val localBroadcastManager by lazy { LocalBroadcastManager.getInstance(this) } - - suspend fun getVer() - { - vancedVersionCode = getJsonInt("vanced.json","versionCode", application) - } - override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - Shell.enableVerboseLogging = BuildConfig.DEBUG Shell.setDefaultBuilder( Shell.Builder.create() @@ -52,24 +44,19 @@ class RootSplitInstallerService: Service() { .setTimeout(10) ) - runBlocking { getVer() } Shell.getShell { - var job = CoroutineScope(Dispatchers.IO).launch{ + CoroutineScope(Dispatchers.IO).launch { val apkFilesPath = getExternalFilesDir("apks")?.path val fileInfoList = apkFilesPath?.let { it1 -> getFileInfoList(it1) } if (fileInfoList != null) { var modApk: FileInfo? = null - for (fil in fileInfoList) - { - if(fil.name == "dark.apk" || fil.name == "black.apk") - { - modApk = fil + for (file in fileInfoList) { + if (file.name == "dark.apk" || file.name == "black.apk") { + modApk = file } } if (modApk != null) { - - if(overwriteBase(modApk, fileInfoList, vancedVersionCode)) - { + if (overwriteBase(modApk, fileInfoList, vancedVersionCode)) { with(localBroadcastManager) { sendBroadcast(Intent(HomeFragment.REFRESH_HOME)) sendBroadcast(Intent(HomeFragment.VANCED_INSTALLED)) @@ -184,16 +171,13 @@ class RootSplitInstallerService: Service() { } //install Vanced - private fun overwriteBase(apkFile: FileInfo,baseApkFiles: ArrayList, versionCode: Int): Boolean - { - if(checkVersion(versionCode,baseApkFiles)) - { + private fun overwriteBase(apkFile: FileInfo,baseApkFiles: ArrayList, versionCode: Int): Boolean { + if (checkVersion(versionCode,baseApkFiles)) { val path = getVPath() apkFile.file?.let { val apath = it.absolutePath - if(path?.let { it1 -> moveAPK(apath, it1) }!!) - { - val fpath = SuFile.open(path).parent!! + if(path?.let { it1 -> moveAPK(apath, it1) }!!) { + SuFile.open(path).parent!! return chConV(path) } @@ -223,35 +207,31 @@ class RootSplitInstallerService: Service() { return fixNoInstall(baseApkFiles) } - private fun getPkgInfo(pkg: String): PackageInfo? - { + private fun getPkgInfo(pkg: String): PackageInfo? { return try { - val m = packageManager - val info = m.getPackageInfo(pkg, 0) - info + packageManager.getPackageInfo(pkg, 0) } catch (e:Exception) { + Log.d("VMpm", "Unable to get package info") null } } - private fun compareVersion(pkgVerCode: Int, versionCode: Int): Int - { - return if(pkgVerCode > versionCode) - 1 - else if (pkgVerCode < versionCode) - -1 - else - 0 + private fun compareVersion(pkgVerCode: Int, versionCode: Int): Int { + return when { + pkgVerCode > versionCode -> 1 + pkgVerCode < versionCode -> -1 + else -> 0 + } } //uninstall current update and install base that works with patch private fun fixHigherVer(apkFiles: ArrayList) : Boolean { - - if(PackageHelper.uninstallApk(yPkg, applicationContext)) - { + if(PackageHelper.uninstallApk(yPkg, applicationContext)) { return installSplitApkFiles(apkFiles) } - with(localBroadcastManager) {sendFailure(listOf("Failed_Uninstall").toMutableList(), applicationContext)} + with(localBroadcastManager) { + sendFailure(listOf("Failed_Uninstall").toMutableList(), applicationContext) + } return false } @@ -269,7 +249,7 @@ class RootSplitInstallerService: Service() { private fun chConV(path: String): 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) { + return if (response.isSuccess) { true } else { sendFailure(response.out, applicationContext) @@ -283,8 +263,7 @@ class RootSplitInstallerService: Service() { val apkinF = SuFile.open(apkFile) val apkoutF = SuFile.open(path) - if(apkinF.exists()) - { + if(apkinF.exists()) { try { Shell.su("am force-stop $yPkg").exec() @@ -330,6 +309,6 @@ class RootSplitInstallerService: Service() { } +} -} \ No newline at end of file diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/VancedLanguageSelectionFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/VancedLanguageSelectionFragment.kt index bebcc56b..1d034f40 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/VancedLanguageSelectionFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/VancedLanguageSelectionFragment.kt @@ -51,8 +51,8 @@ class VancedLanguageSelectionFragment : Fragment() { } with(requireActivity()) { getSharedPreferences("installPrefs", Context.MODE_PRIVATE)?.edit()?.apply { - putString("lang", chosenLangs.joinToString())?.apply() - putBoolean("valuesModified", true).apply() + putString("lang", chosenLangs.joinToString())?.apply() + putBoolean("valuesModified", true).apply() } startService(Intent(this, VancedDownloadService::class.java)) } diff --git a/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt b/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt index 3f05cd81..913f9ad6 100644 --- a/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt +++ b/app/src/main/java/com/vanced/manager/utils/PackageHelper.kt @@ -27,6 +27,7 @@ object PackageHelper { "" } + @Suppress("DEPRECATION") fun getPkgVerCode(pkg: String, pm:PackageManager): Int? { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) pm.getPackageInfo(pkg, 0)?.longVersionCode?.and(0xFFFFFFFF)?.toInt() @@ -56,4 +57,4 @@ object PackageHelper { return false; } } -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/fragment_vanced_language_selection.xml b/app/src/main/res/layout/fragment_vanced_language_selection.xml index fafe3510..ea168226 100644 --- a/app/src/main/res/layout/fragment_vanced_language_selection.xml +++ b/app/src/main/res/layout/fragment_vanced_language_selection.xml @@ -36,10 +36,35 @@ android:layout_marginEnd="2dp" android:layout_weight="1"> - + android:fillViewport="true" + tools:ignore="HardcodedText"> + + + + + + + + @@ -53,4 +78,4 @@ - \ No newline at end of file + diff --git a/app/src/main/res/layout/fragment_vanced_theme_selection.xml b/app/src/main/res/layout/fragment_vanced_theme_selection.xml index 7215e65f..94267683 100644 --- a/app/src/main/res/layout/fragment_vanced_theme_selection.xml +++ b/app/src/main/res/layout/fragment_vanced_theme_selection.xml @@ -51,4 +51,4 @@ - \ No newline at end of file + diff --git a/app/src/main/res/layout/include_language_scrollview.xml b/app/src/main/res/layout/include_language_scrollview.xml deleted file mode 100644 index 8c907bff..00000000 --- a/app/src/main/res/layout/include_language_scrollview.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index 994f7632..b43c0285 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -3,6 +3,7 @@ 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:id="@+id/home" app:startDestination="@id/home_fragment"> - \ No newline at end of file + diff --git a/build.gradle b/build.gradle index c44896c8..6fb684ea 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ buildscript { classpath 'com.google.gms:google-services:4.3.3' classpath 'com.google.firebase:perf-plugin:1.3.1' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0' + classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files