0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-26 21:13:01 +00:00

improvements

This commit is contained in:
X1nto 2020-08-25 13:05:20 +04:00
parent f6345c2dd5
commit c800383f30
10 changed files with 115 additions and 122 deletions

View file

@ -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

View file

@ -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<String>? = 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() {
}
}
}

View file

@ -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<FileInfo>, versionCode: Int): Boolean
{
if(checkVersion(versionCode,baseApkFiles))
{
private fun overwriteBase(apkFile: FileInfo,baseApkFiles: ArrayList<FileInfo>, 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<FileInfo>) : 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() {
}
}
}

View file

@ -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))
}

View file

@ -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;
}
}
}
}

View file

@ -36,10 +36,35 @@
android:layout_marginEnd="2dp"
android:layout_weight="1">
<include
layout="@layout/include_language_scrollview"
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:fillViewport="true"
tools:ignore="HardcodedText">
<LinearLayout
android:id="@+id/lang_button_ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/en"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="?colorDisabled"
android:fontFamily="@font/exo_semibold"
android:text="English"
android:tag="en"
android:textSize="18sp"
android:checked="true"
android:clickable="false"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</FrameLayout>
@ -53,4 +78,4 @@
</com.google.android.material.card.MaterialCardView>
</com.vanced.manager.ui.core.SlidingConstraintLayout>
</com.vanced.manager.ui.core.SlidingConstraintLayout>

View file

@ -51,4 +51,4 @@
</com.google.android.material.card.MaterialCardView>
</com.vanced.manager.ui.core.SlidingConstraintLayout>
</com.vanced.manager.ui.core.SlidingConstraintLayout>

View file

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true"
tools:ignore="HardcodedText">
<LinearLayout
android:id="@+id/lang_button_ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/en"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="?colorDisabled"
android:fontFamily="@font/exo_semibold"
android:text="English (default)"
android:tag="en"
android:textSize="18sp"
android:checked="true"
android:clickable="false"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View file

@ -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">
<fragment
@ -113,4 +114,4 @@
app:popUpTo="@id/home_fragment"
app:popUpToInclusive="true" />
</navigation>
</navigation>

View file

@ -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