update 1.2.0 test

This commit is contained in:
X1nto 2020-07-10 23:09:51 +04:00
parent caa806bf21
commit 70cd3e0e58
8 changed files with 224 additions and 50 deletions

View File

@ -12,7 +12,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 12
versionName "1.1.1 (Rotten Eggs)"
versionName "1.2.0 (Weed)"
vectorDrawables.useSupportLibrary = true
}
@ -77,4 +77,5 @@ dependencies {
implementation 'com.github.100rabhkr:GetJSON:1.0'
implementation 'com.github.topjohnwu.libsu:core:2.5.1'
implementation 'com.mindorks.android:prdownloader:0.6.0'
implementation 'com.squareup.okhttp3:okhttp:4.7.2'
}

View File

@ -1,10 +1,14 @@
package com.vanced.manager.core.downloader
import android.app.DownloadManager
import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.IBinder
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager
import com.downloader.Error
import com.downloader.OnDownloadListener
import com.downloader.OnStartOrResumeListener
@ -12,6 +16,7 @@ import com.downloader.PRDownloader
import com.vanced.manager.R
import com.vanced.manager.core.installer.AppInstaller
import com.vanced.manager.ui.fragments.HomeFragment
import com.vanced.manager.utils.InternetTools.baseUrl
import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
import com.vanced.manager.utils.InternetTools.getObjectFromJson
import com.vanced.manager.utils.NotificationHelper
@ -20,17 +25,29 @@ import com.vanced.manager.utils.NotificationHelper.createBasicNotif
class MicrogDownloadService: Service() {
private var downloadId: Long = 0
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
registerReceiver(receiver, null)
downloadMicrog()
stopSelf()
return START_NOT_STICKY
}
private fun downloadMicrog() {
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
//val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val apkUrl = getObjectFromJson("${PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl)}/microg.json", "url", this)
val apkUrl = getObjectFromJson("https://vanced.app/api/v1/microg.json", "url", this)
val request = DownloadManager.Request(Uri.parse(apkUrl))
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
request.setTitle(getString(R.string.downloading_file, "MicroG"))
request.setDestinationUri(Uri.parse("${filesDir.path}/microg.apk"))
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
downloadId = downloadManager.enqueue(request)
/*
val channel = 420
PRDownloader.download(apkUrl, filesDir.path, "microg.apk")
.build()
@ -61,6 +78,24 @@ class MicrogDownloadService: Service() {
createBasicNotif(getString(R.string.error_downloading, "Microg"), channel, this@MicrogDownloadService)
}
})
*/
}
private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) == downloadId) {
//prefs?.edit()?.putBoolean("isMicrogDownloading", false)?.apply()
//cancelNotif(channel, this@MicrogDownloadService)
val bIntent = Intent(this@MicrogDownloadService, AppInstaller::class.java)
bIntent.putExtra("path", "${filesDir.path}/microg.apk")
bIntent.putExtra("pkg", "com.mgoogle.android.gms")
val mIntent = Intent(HomeFragment.MICROG_DOWNLOADED)
mIntent.action = HomeFragment.MICROG_DOWNLOADED
LocalBroadcastManager.getInstance(this@MicrogDownloadService).sendBroadcast(mIntent)
startService(bIntent)
}
}
}
override fun onDestroy() {

View File

@ -1,8 +1,11 @@
package com.vanced.manager.core.downloader
import android.app.DownloadManager
import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.IBinder
import androidx.localbroadcastmanager.content.LocalBroadcastManager
@ -24,8 +27,10 @@ import com.vanced.manager.utils.NotificationHelper.displayDownloadNotif
class VancedDownloadService: Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
private var downloadId: Long = 0
private var apkType: String = "arch"
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
downloadSplits()
stopSelf()
return START_NOT_STICKY
@ -34,8 +39,9 @@ class VancedDownloadService: Service() {
private fun downloadSplits(
type: String = "arch"
) {
val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl)
val vancedVer = getObjectFromJson("https://vanced.app/api/v1/vanced.json", "version", this)
val defPrefs = PreferenceManager.getDefaultSharedPreferences(this)
val baseUrl = defPrefs.getString("install_url", baseUrl)
val vancedVer = getObjectFromJson("$baseUrl/vanced.json", "version", this)
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val variant = PreferenceManager.getDefaultSharedPreferences(this).getString("vanced_variant", "nonroot")
@ -56,6 +62,17 @@ class VancedDownloadService: Service() {
else -> throw NotImplementedError("This type of APK is NOT valid. What the hell did you even do?")
}
apkType = type
val request = DownloadManager.Request(Uri.parse(url))
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
request.setTitle(getString(R.string.downloading_file, "MicroG"))
request.setDestinationUri(Uri.parse("${filesDir.path}/${getFileNameFromUrl(url)}"))
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
downloadId = downloadManager.enqueue(request)
/*
val channel = 69
PRDownloader
.download(url, cacheDir.path, getFileNameFromUrl(url))
@ -89,6 +106,33 @@ class VancedDownloadService: Service() {
createBasicNotif(getString(R.string.error_downloading, "Vanced"), channel, this@VancedDownloadService)
}
})
*/
}
private val receiver = object : BroadcastReceiver() {
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
val variant = PreferenceManager.getDefaultSharedPreferences(this@VancedDownloadService).getString("vanced_variant", "nonroot")
val lang = prefs?.getString("lang", "en")
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) == downloadId) {
when (apkType) {
"arch" -> downloadSplits("theme")
"theme" -> downloadSplits("lang")
"lang" -> {
if (lang == "en") {
prepareInstall(variant!!)
//cancelNotif(channel, this@VancedDownloadService)
} else {
downloadSplits("enlang")
}
}
"enlang" -> {
prepareInstall(variant!!)
//cancelNotif(channel, this@VancedDownloadService)
}
}
}
}
}
private fun prepareInstall(variant: String) {

View File

@ -4,9 +4,9 @@ import android.app.Activity
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat.startActivity
import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.vanced.manager.R
import com.vanced.manager.ui.MainActivity
import com.vanced.manager.utils.InternetTools.openUrl
@ -15,7 +15,7 @@ import com.vanced.manager.utils.MiuiHelper
object DialogContainer {
fun showSecurityDialog(context: Context) {
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle(context.resources.getString(R.string.welcome))
.setMessage(context.resources.getString(R.string.security_context))
.setCancelable(false)
@ -35,11 +35,11 @@ object DialogContainer {
}
private fun showMiuiDialog(context: Context) {
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle(context.getString(R.string.miui_one_title))
.setMessage(context.getString(R.string.miui_one))
.setPositiveButton(context.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
.setNeutralButton(context.getString(R.string.guide)) { _, _ ->
.setNeutralButton(context.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
.setPositiveButton(context.getString(R.string.guide)) { _, _ ->
openUrl("https://telegra.ph/How-to-install-v15-on-MIUI-02-11", R.color.Telegram, context)
}
.setCancelable(false)
@ -48,16 +48,15 @@ object DialogContainer {
}
fun showRootDialog(activity: Activity) {
AlertDialog.Builder(activity)
MaterialAlertDialogBuilder(activity)
.setTitle(activity.getString(R.string.hold_on))
.setMessage(activity.getString(R.string.disable_signature))
.setPositiveButton(activity.getString(R.string.button_dismiss)) { dialog, _ ->
.setNeutralButton(activity.getString(R.string.button_dismiss)) { dialog, _ ->
dialog.dismiss()
}
.setNeutralButton(activity.getString(R.string.guide)) { _, _ ->
.setPositiveButton(activity.getString(R.string.guide)) { _, _ ->
openUrl("https://lmgtfy.com/?q=andnixsh+apk+verification+disable", R.color.Twitter, activity)
}
.setCancelable(false)
.setOnDismissListener { PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean("show_root_dialog", false).apply() }
.create()
.show()
@ -65,7 +64,7 @@ object DialogContainer {
//Easter Egg
fun statementFalse(context: Context) {
AlertDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle("Wait what?")
.setMessage("So this statement is false huh? I'll go with True!")
.setPositiveButton("wut?") { dialog, _ -> dialog.dismiss() }
@ -77,7 +76,7 @@ object DialogContainer {
}
fun installAlertBuilder(msg: String, context: Context) {
AlertDialog.Builder(context).apply {
MaterialAlertDialogBuilder(context).apply {
setTitle(context.getString(R.string.error))
setMessage(msg)
setPositiveButton(context.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
@ -99,7 +98,7 @@ object DialogContainer {
}
fun regularPackageInstalled(msg: String, activity: MainActivity) {
AlertDialog.Builder(activity)
MaterialAlertDialogBuilder(activity)
.setTitle(activity.getString(R.string.success))
.setMessage(msg)
.setPositiveButton(activity.getString(R.string.close)) { _, _ -> activity.restartActivity() }
@ -109,7 +108,7 @@ object DialogContainer {
}
fun basicDialog(title: String, msg: String, activity: Activity) {
AlertDialog.Builder(activity)
MaterialAlertDialogBuilder(activity)
.setTitle(title)
.setMessage(msg)
.setPositiveButton(activity.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
@ -124,7 +123,7 @@ object DialogContainer {
ComponentName("com.google.android.youtube", "com.google.android.youtube.HomeActivity")
else
ComponentName("com.vanced.android.youtube", "com.google.android.youtube.HomeActivity")
AlertDialog.Builder(activity)
MaterialAlertDialogBuilder(activity)
.setTitle(activity.getString(R.string.success))
.setMessage(activity.getString(R.string.vanced_installed))
.setPositiveButton(activity.getString(R.string.launch)) { _, _ ->
@ -133,11 +132,9 @@ object DialogContainer {
activity.finish()
}
}
.setNegativeButton(activity.getString(R.string.close)) { dialog, _ ->
run {
dialog.dismiss()
activity.restartActivity()
}
.setNegativeButton(activity.getString(R.string.close)) { dialog, _ -> dialog.dismiss() }
.setOnDismissListener {
activity.restartActivity()
}
.setCancelable(false)
.create()

View File

@ -1,5 +1,9 @@
package com.vanced.manager.ui.fragments
import android.app.DownloadManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Context.DOWNLOAD_SERVICE
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
@ -27,6 +31,8 @@ import java.io.File
class UpdateCheckFragment : DialogFragment() {
private var downloadId: Long = 0
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
@ -39,11 +45,17 @@ class UpdateCheckFragment : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity?.registerReceiver(receiver, null)
checkUpdates()
view.findViewById<Button>(R.id.update_center_dismiss).setOnClickListener { dismiss() }
view.findViewById<MaterialButton>(R.id.update_center_recheck).setOnClickListener{ checkUpdates() }
}
override fun onPause() {
super.onPause()
activity?.unregisterReceiver(receiver)
}
private fun checkUpdates() {
val updatebtn = view?.findViewById<Button>(R.id.update_center_update)
val checkingTxt = view?.findViewById<TextView>(R.id.update_center_checking)
@ -64,9 +76,21 @@ class UpdateCheckFragment : DialogFragment() {
}
private fun upgradeManager() {
val dwnldUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/manager.json").get("url").asString
val loadBar = view?.findViewById<ProgressBar>(R.id.update_center_progressbar)
val dwnldUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/manager.json")
.get("url").asString
//val loadBar = view?.findViewById<ProgressBar>(R.id.update_center_progressbar)
val request = DownloadManager.Request(Uri.parse(dwnldUrl))
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
request.setTitle(activity?.getString(R.string.downloading_file, "Manager"))
request.setDestinationUri(Uri.parse("${activity?.filesDir?.path}/manager.apk"))
val downloadManager = activity?.getSystemService(DOWNLOAD_SERVICE) as DownloadManager
downloadId = downloadManager.enqueue(request)
}
/*
PRDownloader.download(dwnldUrl, activity?.filesDir?.path, "manager.apk")
.build()
.setOnProgressListener { progress ->
@ -99,6 +123,28 @@ class UpdateCheckFragment : DialogFragment() {
}
})
*/
private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) == downloadId) {
activity?.let {
val apk = File("${activity?.filesDir?.path}/manager.apk")
val uri =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
FileProvider.getUriForFile(activity!!, "${activity?.packageName}.provider", apk)
else
Uri.fromFile(apk)
val mIntent = Intent(Intent.ACTION_VIEW)
mIntent.setDataAndType(uri, "application/vnd.android.package-archive")
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
mIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
startActivity(mIntent)
}
}
}
}

View File

@ -14,9 +14,10 @@ import androidx.core.content.ContextCompat.startActivity
import androidx.databinding.ObservableField
import androidx.lifecycle.AndroidViewModel
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.crowdin.platform.Crowdin
import com.vanced.manager.R
import com.vanced.manager.utils.InternetTools.displayJsonInt
import com.vanced.manager.utils.InternetTools.displayJsonString
import com.vanced.manager.utils.InternetTools.getJsonInt
import com.vanced.manager.utils.InternetTools.getJsonString
import com.vanced.manager.utils.PackageHelper.isPackageInstalled
class HomeViewModel(application: Application): AndroidViewModel(application) {
@ -57,14 +58,15 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
//this too
fun fetchData() {
fetching.set(true)
vancedVersion.set(displayJsonString("vanced.json", "version", getApplication()))
microgVersion.set(displayJsonString("microg.json", "version", getApplication()))
Crowdin.forceUpdate(getApplication())
vancedVersion.set(getJsonString("vanced.json", "version", getApplication()))
microgVersion.set(getJsonString("microg.json", "version", getApplication()))
microgInstalled.set(isPackageInstalled("com.mgoogle.android.gms", pm))
vancedInstalled.set(isPackageInstalled(vancedPkgName, pm))
vancedInstalledVersion.set(getPkgInfo(vancedInstalled.get()!!, vancedPkgName, getApplication()))
microgInstalledVersion.set(getPkgInfo(microgInstalled.get()!!, "com.mgoogle.android.gms", getApplication()))
vancedVersionCode.set(displayJsonInt("vanced.json", "versionCode", getApplication()))
microgVersionCode.set(displayJsonInt("microg.json", "versionCode", getApplication()))
vancedVersionCode.set(getJsonInt("vanced.json", "versionCode", getApplication()))
microgVersionCode.set(getJsonInt("microg.json", "versionCode", getApplication()))
vancedInstalledVersionCode.set(getPkgVerCode(vancedInstalled.get()!!, vancedPkgName))
microgInstalledVersionCode.set(getPkgVerCode(microgInstalled.get()!!, "com.mgoogle.android.gms"))
microgInstallButtonTxt.set(compareInt(microgInstalledVersionCode.get()!!, microgVersionCode.get()!!, getApplication()))

View File

@ -3,12 +3,16 @@ package com.vanced.manager.utils
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.vanced.manager.BuildConfig
import com.dezlum.codelabs.getjson.GetJson
import okhttp3.*
import com.vanced.manager.R
import org.json.JSONObject
import java.io.IOException
object InternetTools {
@ -25,23 +29,6 @@ object InternetTools {
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/')+1, url.length)
fun displayJsonString(json: String, obj: String, context: Context): String {
val installUrl = getDefaultSharedPreferences(context).getString("install_url", baseUrl)
return if (GetJson().isConnected(context))
GetJson().AsJSONObject("$installUrl/$json").get(obj).asString
else
context.getString(R.string.unavailable)
}
fun displayJsonInt(json: String, obj: String, context: Context): Int {
val installUrl = getDefaultSharedPreferences(context).getString("install_url", baseUrl)
return if (GetJson().isConnected(context))
GetJson().AsJSONObject("$installUrl/$json").get(obj).asInt
else
0
}
fun getObjectFromJson(url: String, obj: String, context: Context): String {
return if (GetJson().isConnected(context))
GetJson().AsJSONObject(url).get(obj).asString
@ -49,6 +36,50 @@ object InternetTools {
""
}
fun getJsonInt(file: String, obj: String, context: Context): Int {
val client = OkHttpClient()
val url = "${getDefaultSharedPreferences(context).getString("install_url", baseUrl)}/$file"
var toReturn = 0
val request = Request.Builder().url(url).build()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
toReturn = 0
}
override fun onResponse(call: Call, response: Response) {
toReturn = JSONObject(response.body.toString()).getInt(obj)
Log.d("VMResponse", toReturn.toString())
}
})
return toReturn
}
fun getJsonString(file: String, obj: String, context: Context): String {
val client = OkHttpClient()
val url = "${getDefaultSharedPreferences(context).getString("install_url", baseUrl)}/$file"
var toReturn = ""
val request = Request.Builder().url(url).build()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
toReturn = context.getString(R.string.unavailable)
}
override fun onResponse(call: Call, response: Response) {
toReturn = JSONObject(response.body.toString()).getString(obj)
Log.d("VMResponse", toReturn)
}
})
return toReturn
}
fun isUpdateAvailable(): Boolean {
val checkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/manager.json")
val remoteVersion = checkUrl.get("versionCode").asInt

View File

@ -6,6 +6,14 @@
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="DialogStyle" parent="ThemeOverlay.MaterialComponents.Dialog.Alert">
<item name="android:buttonBarPositiveButtonStyle">@style/ButtonStyle</item>
<item name="android:buttonBarNeutralButtonStyle">@style/OutlinedButtonStyle</item>
<item name="android:buttonBarNegativeButtonStyle">@style/OutlinedButtonStyle</item>
<item name="backgroundColor">?DialogBG</item>
<item name="cornerRadius">8dp</item>
</style>
<style name="ButtonStyle" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="textAllCaps">false</item>
<item name="backgroundTint">?colorPrimary</item>
@ -15,6 +23,16 @@
<item name="fontFamily">@font/exo_bold</item>
</style>
<style name="OutlinedButtonStyle" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="textAllCaps">false</item>
<item name="android:textColor">#ffffff</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="fontFamily">@font/exo_bold</item>
<item name="android:strokeWidth">1dp</item>
<item name="android:strokeColor">?colorPrimary</item>
</style>
<style name="InstallButtonStyle" parent="ButtonStyle">
<item name="android:layout_marginEnd">6dp</item>
<item name="android:layout_gravity">end</item>