test new signature checker

This commit is contained in:
X1nto 2020-06-27 01:41:51 +04:00
parent fddce8ed85
commit 7117352591
9 changed files with 45 additions and 17 deletions

View File

@ -2,10 +2,12 @@ package com.vanced.manager.core.fragments
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.*
import androidx.fragment.app.viewModels
import androidx.navigation.findNavController
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.google.android.material.button.MaterialButton
@ -17,6 +19,7 @@ import com.vanced.manager.core.downloader.VancedDownloadService
import com.vanced.manager.core.installer.StubInstaller
import com.vanced.manager.ui.MainActivity
import com.vanced.manager.ui.dialogs.DialogContainer.secondMiuiDialog
import com.vanced.manager.ui.viewmodels.HomeViewModel
import com.vanced.manager.utils.MiuiHelper
import com.vanced.manager.utils.PackageHelper.uninstallApk
@ -103,7 +106,6 @@ open class Home : BaseFragment(), View.OnClickListener {
if (!isMicrogDownloading!!) {
try {
activity?.startService(Intent(activity, MicrogDownloadService::class.java))
} catch (e: Exception) {
Toast.makeText(activity, "Unable to start installation", Toast.LENGTH_SHORT).show()
}
@ -112,10 +114,35 @@ open class Home : BaseFragment(), View.OnClickListener {
}
}
R.id.signature_button -> {
val viewModel: HomeViewModel by viewModels()
val loadCircle = view?.findViewById<ProgressBar>(R.id.signature_loading)
loadCircle?.visibility = View.VISIBLE
val intent = Intent(activity, StubInstaller::class.java)
activity?.startService(intent)
//val intent = Intent(activity, StubInstaller::class.java)
//activity?.startService(intent)
val checkSig = activity?.packageManager?.checkSignatures("com.vanced.manager", "com.android.systemui")
if (checkSig == PackageManager.SIGNATURE_MATCH) {
activity?.runOnUiThread {
viewModel.signatureStatusTxt.value = getString(R.string.signature_disabled)
viewModel.vancedInstallButtonTxt.value = viewModel.compareInt(
viewModel.vancedVersionCode,
viewModel.vancedInstalledVersionCode,
viewModel.getApplication()
)
viewModel.vancedInstallButtonIcon.value = viewModel.compareIntDrawable(
viewModel.vancedVersionCode,
viewModel.vancedInstalledVersionCode,
viewModel.getApplication()
)
activity?.recreate()
}
} else {
activity?.runOnUiThread {
viewModel.signatureStatusTxt.value = getString(R.string.signature_enabled)
viewModel.vancedInstallButtonTxt.value = getString(R.string.signature_disable)
viewModel.vancedInstallButtonIcon.value = null
activity?.recreate()
}
}
}
R.id.microg_uninstallbtn -> activity?.let { uninstallApk("com.mgoogle.android.gms", it) }
R.id.vanced_uninstallbtn -> activity?.let { uninstallApk(vancedPkgName, it) }
@ -125,7 +152,7 @@ open class Home : BaseFragment(), View.OnClickListener {
writeToVariantPref("root", R.anim.slide_in_right, R.anim.slide_out_left)
else {
writeToVariantPref("nonroot", R.anim.slide_in_left, R.anim.slide_out_right)
Toast.makeText(activity, "Root access not granted", Toast.LENGTH_SHORT)
Toast.makeText(activity, "Root access not granted", Toast.LENGTH_SHORT).show()
}
}
}

View File

@ -16,9 +16,9 @@ class StubInstaller: Service() {
if (!apkFile.exists()) {
copyStub()
}
Log.d("VMpath", apkFile.canonicalPath)
Log.d("VMpath", apkFile.absolutePath)
Log.d("AppLog", "Installing stub...")
val installResult = Shell.su("pm install ${apkFile.canonicalPath}").exec()
val installResult = Shell.su("pm install ${apkFile.absolutePath}").exec()
Log.d("AppLog", "succeeded installing?${installResult.isSuccess}")
if (installResult.isSuccess) {
val mIntent = Intent(HomeFragment.SIGNATURE_DISABLED)

View File

@ -70,7 +70,6 @@ class HomeFragment : Home() {
}
}
view.findViewById<ViewGroup>(R.id.home_container).layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
view.findViewById<ImageButton>(R.id.changelog_button).setOnClickListener {
cardExpandCollapse()
}

View File

@ -46,10 +46,10 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
val vancedVersion: MutableLiveData<String> = MutableLiveData()
val microgVersion: MutableLiveData<String> = MutableLiveData()
private val vancedInstalledVersionCode = getPkgVerCode(vancedInstalled, vancedPkgName)
val vancedInstalledVersionCode = getPkgVerCode(vancedInstalled, vancedPkgName)
private val microgInstalledVersionCode = getPkgVerCode(microgInstalled, "com.mgoogle.android.gms")
private val vancedVersionCode = displayJsonInt("vanced.json", "versionCode", application)
val vancedVersionCode = displayJsonInt("vanced.json", "versionCode", application)
private val microgVersionCode = displayJsonInt("microg.json", "versionCode", application)
val microgInstallButtonTxt = compareInt(microgInstalledVersionCode, microgVersionCode, application)
@ -111,7 +111,7 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
} else 0
}
private fun compareInt(int1: Int, int2: Int, application: Application): String {
fun compareInt(int1: Int, int2: Int, application: Application): String {
return if (connected)
when {
int1 > int2 -> application.getString(R.string.update)
@ -120,7 +120,7 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
} else application.getString(R.string.install)
}
private fun compareIntDrawable(int1: Int, int2: Int, application: Application): Drawable? {
fun compareIntDrawable(int1: Int, int2: Int, application: Application): Drawable? {
return if (connected)
when {
int1 > int2 -> application.getDrawable(R.drawable.ic_cloud_upload_black_24dp)

View File

@ -14,17 +14,16 @@
</data>
<com.vanced.manager.ui.core.SlidingNestedScrollView
android:id="@+id/home_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:animateLayoutChanges="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:animateLayoutChanges="true"
android:orientation="vertical">
<RelativeLayout

View File

@ -4,7 +4,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/changelog_card"
android:animateLayoutChanges="true"
style="@style/MaterialCard">
<LinearLayout
@ -12,6 +11,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:animateLayoutChanges="true"
android:orientation="vertical">
<RelativeLayout

View File

@ -20,7 +20,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:animateLayoutChanges="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"

View File

@ -17,7 +17,8 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:animateLayoutChanges="true">
<ImageView
android:id="@+id/signature_icon"

View File

@ -21,7 +21,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:animateLayoutChanges="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"