mirror of
https://github.com/YTVanced/VancedManager
synced 2025-01-06 23:41:00 +00:00
avoid detecting stock apps as installed
This commit is contained in:
parent
ce1cf2fdb4
commit
834dad0946
6 changed files with 65 additions and 13 deletions
|
@ -11,6 +11,7 @@ import com.github.florent37.viewtooltip.ViewTooltip
|
|||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.ViewAppBinding
|
||||
import com.vanced.manager.model.DataModel
|
||||
import com.vanced.manager.model.RootDataModel
|
||||
import com.vanced.manager.ui.dialogs.AppInfoDialog
|
||||
import com.vanced.manager.ui.viewmodels.HomeViewModel
|
||||
|
||||
|
@ -23,7 +24,7 @@ class AppListAdapter(
|
|||
|
||||
val apps = mutableListOf<String>()
|
||||
private val dataModels = mutableListOf<DataModel?>()
|
||||
private val rootDataModels = mutableListOf<DataModel?>()
|
||||
private val rootDataModels = mutableListOf<RootDataModel?>()
|
||||
private val prefs = getDefaultSharedPreferences(context)
|
||||
private var itemCount = 0
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ import kotlinx.coroutines.launch
|
|||
open class DataModel(
|
||||
private val jsonObject: LiveData<JsonObject?>,
|
||||
private val context: Context,
|
||||
val appPkg: String,
|
||||
val appName: String,
|
||||
val appIcon: Drawable?,
|
||||
open val appPkg: String,
|
||||
open val appName: String,
|
||||
open val appIcon: Drawable?,
|
||||
) {
|
||||
|
||||
private val versionCode = MutableLiveData<Int>()
|
||||
|
@ -64,7 +64,7 @@ open class DataModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getPkgVersionName(pkg: String): String {
|
||||
open fun getPkgVersionName(pkg: String): String {
|
||||
val pm = context.packageManager
|
||||
return if (isAppInstalled.value == true) {
|
||||
pm.getPackageInfo(pkg, 0).versionName.removeSuffix("-vanced")
|
||||
|
@ -84,7 +84,7 @@ open class DataModel(
|
|||
} else 0
|
||||
}
|
||||
|
||||
private fun compareInt(int1: Int?, int2: Int?): String {
|
||||
open fun compareInt(int1: Int?, int2: Int?): String {
|
||||
if (int2 != null && int1 != null) {
|
||||
return when {
|
||||
int1 == 0 -> context.getString(R.string.install)
|
||||
|
|
37
app/src/main/java/com/vanced/manager/model/RootDataModel.kt
Normal file
37
app/src/main/java/com/vanced/manager/model/RootDataModel.kt
Normal file
|
@ -0,0 +1,37 @@
|
|||
package com.vanced.manager.model
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.beust.klaxon.JsonObject
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.PackageHelper
|
||||
|
||||
open class RootDataModel(
|
||||
jsonObject: LiveData<JsonObject?>,
|
||||
private val context: Context,
|
||||
override val appPkg: String,
|
||||
override val appName: String,
|
||||
override val appIcon: Drawable?,
|
||||
private val scriptName: String
|
||||
): DataModel(
|
||||
jsonObject, context, appPkg, appName, appIcon
|
||||
) {
|
||||
|
||||
override fun getPkgVersionName(pkg: String): String {
|
||||
return if (PackageHelper.scriptExists(scriptName)) {
|
||||
super.getPkgVersionName(pkg)
|
||||
} else {
|
||||
context.getString(R.string.unavailable)
|
||||
}
|
||||
}
|
||||
|
||||
override fun compareInt(int1: Int?, int2: Int?): String {
|
||||
return if (PackageHelper.scriptExists(scriptName)) {
|
||||
super.compareInt(int1, int2)
|
||||
} else {
|
||||
context.getString(R.string.install)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -13,6 +13,7 @@ import com.vanced.manager.utils.Extensions.writeServiceDScript
|
|||
import com.vanced.manager.utils.PackageHelper
|
||||
import com.vanced.manager.utils.PackageHelper.getPackageDir
|
||||
import com.vanced.manager.utils.PackageHelper.getPkgNameRoot
|
||||
import com.vanced.manager.utils.PackageHelper.scriptExists
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
|
@ -39,8 +40,10 @@ class ServiceDTimerDialog : BindingDialogFragment<DialogServicedTimerBinding>()
|
|||
servicedSave.setOnClickListener {
|
||||
try {
|
||||
arrayOf("vanced", "music").forEach { app ->
|
||||
val apkFPath = "${PackageHelper.apkInstallPath}/${app.capitalize(Locale.ROOT)}/base.apk"
|
||||
getPackageDir(requireActivity(), getPkgNameRoot(app))?.let { it1 -> requireActivity().writeServiceDScript(apkFPath, it1, app) }
|
||||
if (scriptExists(app)) {
|
||||
val apkFPath = "${PackageHelper.apkInstallPath}/${app.capitalize(Locale.ROOT)}/base.apk"
|
||||
getPackageDir(requireActivity(), getPkgNameRoot(app))?.let { it1 -> requireActivity().writeServiceDScript(apkFPath, it1, app) }
|
||||
}
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Toast.makeText(requireActivity(), R.string.script_save_failed, Toast.LENGTH_SHORT).show()
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.vanced.manager.adapter.LinkAdapter.Companion.TELEGRAM
|
|||
import com.vanced.manager.adapter.LinkAdapter.Companion.TWITTER
|
||||
import com.vanced.manager.adapter.SponsorAdapter.Companion.BRAVE
|
||||
import com.vanced.manager.model.DataModel
|
||||
import com.vanced.manager.model.RootDataModel
|
||||
import com.vanced.manager.ui.dialogs.AppDownloadDialog
|
||||
import com.vanced.manager.ui.dialogs.InstallationFilesDetectedDialog
|
||||
import com.vanced.manager.ui.dialogs.MusicPreferencesDialog
|
||||
|
@ -46,10 +47,10 @@ open class HomeViewModel(private val activity: FragmentActivity): ViewModel() {
|
|||
private val prefs = getDefaultSharedPreferences(activity)
|
||||
|
||||
val vanced = MutableLiveData<DataModel>()
|
||||
val vancedRoot = MutableLiveData<DataModel>()
|
||||
val vancedRoot = MutableLiveData<RootDataModel>()
|
||||
val microg = MutableLiveData<DataModel>()
|
||||
val music = MutableLiveData<DataModel>()
|
||||
val musicRoot = MutableLiveData<DataModel>()
|
||||
val musicRoot = MutableLiveData<RootDataModel>()
|
||||
val manager = MutableLiveData<DataModel>()
|
||||
|
||||
fun fetchData() {
|
||||
|
@ -157,9 +158,9 @@ open class HomeViewModel(private val activity: FragmentActivity): ViewModel() {
|
|||
|
||||
init {
|
||||
vanced.value = DataModel(InternetTools.vanced, activity, vancedPkg, activity.getString(R.string.vanced), AppCompatResources.getDrawable(activity, R.drawable.ic_vanced))
|
||||
vancedRoot.value = DataModel(InternetTools.vanced, activity, vancedRootPkg, activity.getString(R.string.vanced), AppCompatResources.getDrawable(activity, R.drawable.ic_vanced))
|
||||
vancedRoot.value = RootDataModel(InternetTools.vanced, activity, vancedRootPkg, activity.getString(R.string.vanced), AppCompatResources.getDrawable(activity, R.drawable.ic_vanced), "vanced")
|
||||
music.value = DataModel(InternetTools.music, activity, musicPkg, activity.getString(R.string.music), AppCompatResources.getDrawable(activity, R.drawable.ic_music))
|
||||
musicRoot.value = DataModel(InternetTools.music, activity, musicRootPkg, activity.getString(R.string.music), AppCompatResources.getDrawable(activity, R.drawable.ic_music))
|
||||
musicRoot.value = RootDataModel(InternetTools.music, activity, musicRootPkg, activity.getString(R.string.music), AppCompatResources.getDrawable(activity, R.drawable.ic_music), "music")
|
||||
microg.value = DataModel(InternetTools.microg, activity, microgPkg, activity.getString(R.string.microg), AppCompatResources.getDrawable(activity, R.drawable.ic_microg))
|
||||
manager.value = DataModel(InternetTools.manager, activity, managerPkg, activity.getString(R.string.app_name), AppCompatResources.getDrawable(activity, R.mipmap.ic_launcher))
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ import kotlin.collections.HashMap
|
|||
object PackageHelper {
|
||||
|
||||
const val apkInstallPath = "/data/adb"
|
||||
const val INSTALLER_TAG = "VMInstall"
|
||||
private const val INSTALLER_TAG = "VMInstall"
|
||||
private val vancedThemes = arrayOf("black", "dark", "pink", "blue")
|
||||
|
||||
init {
|
||||
|
@ -54,6 +54,16 @@ object PackageHelper {
|
|||
}
|
||||
}
|
||||
|
||||
fun scriptExists(scriptName: String): Boolean {
|
||||
val serviceDScript = SuFile.open("$apkInstallPath/service.d/$scriptName.sh")
|
||||
val postFsDataScript = SuFile.open("$apkInstallPath/post-fs-data.d/$scriptName.sh")
|
||||
if (serviceDScript.exists() && postFsDataScript.exists()) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
fun getPkgNameRoot(app: String): String {
|
||||
return when (app) {
|
||||
"vanced" -> vancedRootPkg
|
||||
|
|
Loading…
Reference in a new issue