0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-27 05:23:00 +00:00

added signature verification check and cleaned up junk

This commit is contained in:
X1nto 2020-06-08 15:23:45 +04:00
parent 581cf62911
commit a9a35cdd57
20 changed files with 248 additions and 130 deletions

File diff suppressed because one or more lines are too long

View file

@ -19,8 +19,6 @@ android {
vectorDrawables.useSupportLibrary = true
}
lintOptions {
disable 'MissingTranslation'
}
@ -59,8 +57,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.activity:activity-ktx:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.fragment:fragment-ktx:1.2.4'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
@ -76,7 +73,4 @@ dependencies {
implementation 'com.github.100rabhkr:GetJSON:1.0'
implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.8'
implementation 'com.github.topjohnwu.libsu:core:2.5.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

View file

@ -1,24 +0,0 @@
package com.vanced.manager
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.vanced.manager", appContext.packageName)
}
}

View file

@ -58,6 +58,7 @@
<service android:name=".core.installer.SplitInstallerService" />
<service android:name=".core.installer.RootSplitInstallerService" />
<service android:name=".core.installer.RootAPKInstaller" />
<service android:name=".core.installer.RootAppUninstaller" />
</application>

View file

@ -1,8 +0,0 @@
/*___Generated_by_IDEA___*/
package com.vanced.manager;
/* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */
public final class BuildConfig {
public final static boolean DEBUG = Boolean.parseBoolean(null);
}

View file

@ -1,7 +0,0 @@
/*___Generated_by_IDEA___*/
package com.vanced.manager;
/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */
public final class Manifest {
}

View file

@ -1,7 +0,0 @@
/*___Generated_by_IDEA___*/
package com.vanced.manager;
/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
public final class R {
}

View file

@ -287,15 +287,4 @@ open class BaseFragment : Fragment() {
)
}
/*fun uninstallApk(pkgUri: String) {
try {
val uri = Uri.parse("package:$pkgUri")
val uninstall = Intent(Intent.ACTION_DELETE, uri)
startActivity(uninstall)
} catch (e: ActivityNotFoundException) {
Toast.makeText(activity, "Failed to uninstall", Toast.LENGTH_SHORT).show()
}
}
*/
}

View file

@ -1,18 +0,0 @@
package com.vanced.manager.core.base
import android.util.Log
class RootHelper {
private val TAG: String = "VMRoot"
fun rootRequest(): Boolean {
return try {
true
} catch (e: Exception) {
Log.d(TAG, "Unable to acquire root access")
false
}
}
}

View file

@ -12,14 +12,24 @@ import com.vanced.manager.R
import com.vanced.manager.core.base.BaseFragment
import com.vanced.manager.ui.MainActivity
import com.vanced.manager.utils.MiuiHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.rxkotlin.subscribeBy
import zlc.season.rxdownload4.download
import zlc.season.rxdownload4.file
import zlc.season.rxdownload4.task.Task
import zlc.season.rxdownload4.utils.getFileNameFromUrl
open class Home : BaseFragment() {
private var disposable: Disposable? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val microginstallbtn = view.findViewById<MaterialButton>(R.id.microg_installbtn)
val vancedinstallbtn = view.findViewById<MaterialButton>(R.id.vanced_installbtn)
val signaturebtn = view.findViewById<MaterialButton>(R.id.signature_button)
val microgProgress = view.findViewById<ProgressBar>(R.id.microg_progress)
val prefs = activity?.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
@ -75,6 +85,38 @@ open class Home : BaseFragment() {
}
}
signaturebtn.setOnClickListener {
val loadCircle = view.findViewById<ProgressBar>(R.id.signature_loading)
activity?.filesDir?.delete()
val dwnldUrl = "https://x1nto.github.io/VancedFiles/stub.apk"
val task = activity?.filesDir?.path?.let {
Task(
url = dwnldUrl,
saveName = getFileNameFromUrl(dwnldUrl),
savePath = it
)
}
if (task?.file()?.exists()!!)
task.file().delete()
disposable = task
.download()
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(
onNext = {
loadCircle.visibility = View.VISIBLE
},
onComplete = {
},
onError = { throwable ->
Toast.makeText(requireContext(), throwable.toString(), Toast.LENGTH_SHORT)
.show()
}
)
}
}
override fun onResume() {

View file

@ -9,6 +9,7 @@ import androidx.annotation.WorkerThread
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.topjohnwu.superuser.Shell
import com.vanced.manager.ui.MainActivity
import com.vanced.manager.ui.fragments.HomeFragment
import com.vanced.manager.utils.FileInfo
import java.io.File
import java.text.SimpleDateFormat
@ -27,13 +28,17 @@ class RootAPKInstaller: Service() {
Log.d("AppLog", "succeeded installing?${installResult.isSuccess}")
if (installResult.isSuccess) {
getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply()
val mIntent = Intent(MainActivity.INSTALL_COMPLETED)
mIntent.action = MainActivity.INSTALL_COMPLETED
val mIntent = Intent(HomeFragment.SIGNATURE_DISABLED)
mIntent.action = HomeFragment.SIGNATURE_DISABLED
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
} else {
val mIntent = Intent(HomeFragment.SIGNATURE_ENABLED)
mIntent.action = HomeFragment.SIGNATURE_ENABLED
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
}
}
return super.onStartCommand(intent, flags, startId)
return START_NOT_STICKY
}
@WorkerThread

View file

@ -0,0 +1,28 @@
package com.vanced.manager.core.installer
import android.app.Service
import android.content.Intent
import android.os.Bundle
import android.os.IBinder
import android.util.Log
import com.topjohnwu.superuser.Shell
class RootAppUninstaller: Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val serviceData: Bundle? = intent?.extras
val data = serviceData?.get("Data")
val uninstall = Shell.su("pm uninstall $data").exec()
if (uninstall.isSuccess) {
Log.d("VMUninstall", "Succesfully uninstalled $data")
} else {
Log.d("VMUninstall", "Failed to uninstall $data")
}
return START_NOT_STICKY
}
override fun onBind(intent: Intent?): IBinder? {
return null
}
}

View file

@ -21,7 +21,7 @@ class AboutFragment : About() {
savedInstanceState: Bundle?
): View? {
activity?.title = getString(R.string.title_about)
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false)
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_about, container, false)
return binding.root
}

View file

@ -1,13 +1,19 @@
package com.vanced.manager.ui.fragments
import android.animation.ObjectAnimator
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.os.Bundle
import android.view.*
import android.widget.ProgressBar
import android.widget.TextView
import androidx.core.animation.addListener
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.viewModels
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import androidx.viewpager2.widget.ViewPager2
import com.dezlum.codelabs.getjson.GetJson
@ -20,6 +26,8 @@ import com.vanced.manager.R
import com.vanced.manager.adapter.SectionPageAdapter
import com.vanced.manager.adapter.SectionPageRootAdapter
import com.vanced.manager.core.fragments.Home
import com.vanced.manager.core.installer.RootAppUninstaller
import com.vanced.manager.core.installer.RootSplitInstallerService
import com.vanced.manager.databinding.FragmentHomeBinding
import com.vanced.manager.ui.viewmodels.HomeViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
@ -53,14 +61,22 @@ class HomeFragment : Home() {
binding.viewModel = viewModel
val variantPref = getDefaultSharedPreferences(activity).getString("vanced_variant", "nonroot")
registerReceivers()
if (variantPref == "root")
val vancedinstallbtn = view.findViewById<MaterialButton>(R.id.vanced_installbtn)
if (variantPref == "root") {
attachRootChangelog()
else
vancedinstallbtn.isEnabled = false
} else
attachNonrootChangelog()
}
override fun onPause() {
super.onPause()
activity?.let { LocalBroadcastManager.getInstance(it).unregisterReceiver(broadcastReceiver) }
}
private fun initNetworkFun() {
val pm = activity?.packageManager
val variant = getDefaultSharedPreferences(activity).getString("vanced_variant", "nonroot")
@ -116,6 +132,8 @@ class HomeFragment : Home() {
activity?.getDrawable(R.drawable.outline_cloud_done_24)
}
}
} else {
vancedinstallbtn?.isEnabled = false
}
}
@ -201,6 +219,42 @@ class HomeFragment : Home() {
}
}
private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val statusTxt = view?.findViewById<TextView>(R.id.signature_status)
val vancedinstallbtn = view?.findViewById<MaterialButton>(R.id.vanced_installbtn)
val loadCircle = view?.findViewById<ProgressBar>(R.id.signature_loading)
when (intent.action) {
SIGNATURE_DISABLED -> {
loadCircle?.visibility = View.GONE
statusTxt?.text = "Disabled"
vancedinstallbtn?.isEnabled = true
val mIntent = Intent(activity, RootAppUninstaller::class.java)
intent.putExtra("Data", "com.vanced.stub")
activity?.startService(mIntent)
}
SIGNATURE_ENABLED -> {
statusTxt?.text = "Enabled"
loadCircle?.visibility = View.GONE
}
}
}
}
private fun registerReceivers() {
activity?.let {
LocalBroadcastManager.getInstance(it).registerReceiver(broadcastReceiver, IntentFilter(
SIGNATURE_DISABLED
))
}
activity?.let {
LocalBroadcastManager.getInstance(it).registerReceiver(broadcastReceiver, IntentFilter(
SIGNATURE_ENABLED
)
)
}
}
private fun attachNonrootChangelog() {
sectionPageAdapter = SectionPageAdapter(this)
val tabLayout = view?.findViewById(R.id.tablayout) as TabLayout
@ -235,5 +289,10 @@ class HomeFragment : Home() {
super .onCreateOptionsMenu(menu, inflater)
}
companion object {
const val SIGNATURE_DISABLED = "Signature verification disabled"
const val SIGNATURE_ENABLED = "Signature verification enabled"
}
}

View file

@ -1,6 +1,7 @@
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
@ -13,6 +14,7 @@ open class AboutViewModel(application: Application): AndroidViewModel(applicatio
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))
}

View file

@ -122,6 +122,7 @@ open class HomeViewModel(application: Application): AndroidViewModel(application
val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(getApplication(), color))
val customTabsIntent = builder.build()
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
customTabsIntent.launchUrl(getApplication(), Uri.parse(Url))
}

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="29dp"
android:height="29dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM12,11.99h7c-0.53,4.12 -3.28,7.79 -7,8.94L12,12L5,12L5,6.3l7,-3.11v8.8z"/>
</vector>

View file

@ -56,6 +56,17 @@
android:visibility="@{viewModel.nonrootModeSelected ? View.VISIBLE : View.GONE}"
bind:viewModel="@{viewModel}"/>
<include
android:id="@+id/home_signature_wrapper"
layout="@layout/include_signature_verification"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/stdp"
android:layout_marginTop="@dimen/stdp"
android:layout_marginEnd="@dimen/stdp"
android:visibility="@{viewModel.nonrootModeSelected ? View.GONE : View.VISIBLE}"
bind:viewModel="@{viewModel}"/>
<include
layout="@layout/include_changelogs"
android:layout_width="match_parent"

View file

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
style="@style/MaterialCard"
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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/signature_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_security_black_24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/signature_barrier"/>
<TextView
style="@style/TextAppTitle"
android:id="@+id/signature_title"
android:text="Signature Verification"
app:layout_constraintStart_toEndOf="@id/signature_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/signature_barrier"/>
<com.google.android.material.button.MaterialButton
style="@style/ButtonStyle"
android:id="@+id/signature_button"
android:text="Check"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/signature_barrier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:constraint_referenced_ids="signature_button"
app:barrierDirection="bottom"/>
<LinearLayout
android:id="@+id/signature_status_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/signature_barrier">
<TextView
style="@style/AppVer"
android:text="status:" />
<TextView
style="@style/AppVer.Bold"
android:id="@+id/signature_status"
android:text="@string/unavailable"/>
</LinearLayout>
<ProgressBar
android:id="@+id/signature_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/signature_status_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

View file

@ -1,17 +0,0 @@
package com.vanced.manager
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}