From 15b12159723ffce8c00db17b63942c5e5fb7c0dc Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 9 Aug 2020 04:39:12 -0700 Subject: [PATCH] Only show SafetyNet when GMS exists --- .../main/java/com/topjohnwu/magisk/net/Networking.java | 3 +-- app/src/main/java/com/topjohnwu/magisk/core/Info.kt | 7 +++---- .../java/com/topjohnwu/magisk/di/NetworkingModule.kt | 6 +++++- .../java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt | 7 ++++++- app/src/main/res/layout/fragment_home_md2.xml | 10 +++++++--- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/shared/src/main/java/com/topjohnwu/magisk/net/Networking.java b/app/shared/src/main/java/com/topjohnwu/magisk/net/Networking.java index c23961340..3e050658b 100644 --- a/app/shared/src/main/java/com/topjohnwu/magisk/net/Networking.java +++ b/app/shared/src/main/java/com/topjohnwu/magisk/net/Networking.java @@ -47,10 +47,9 @@ public class Networking { } catch (Exception e) { if (Build.VERSION.SDK_INT < 21) { // Failed to update SSL provider, use NoSSLv3SocketFactory on SDK < 21 - // and return false to notify potential issues HttpsURLConnection.setDefaultSSLSocketFactory(new NoSSLv3SocketFactory()); - return false; } + return false; } return true; } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt index 04761b936..2bedcb94c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Info.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Info.kt @@ -18,11 +18,9 @@ object Info { val envRef = CachedValue { loadState() } - @JvmStatic - val env by envRef // Local + @JvmStatic val env by envRef // Local + @JvmStatic var stub: DynAPK.Data? = null // Stub var remote = UpdateInfo() // Remote - @JvmStatic - var stub: DynAPK.Data? = null // Stub // Toggle-able options @JvmStatic var keepVerity = false @@ -33,6 +31,7 @@ object Info { @JvmStatic var isSAR = false @JvmStatic var isAB = false @JvmStatic var ramdisk = false + @JvmStatic var hasGMS = true val isConnected by lazy { ObservableBoolean(false).also { field -> diff --git a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt index dfe194c0c..5502d308b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt @@ -1,8 +1,10 @@ package com.topjohnwu.magisk.di import android.content.Context +import android.os.Build import com.squareup.moshi.Moshi import com.topjohnwu.magisk.core.Const +import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.data.network.GithubApiServices import com.topjohnwu.magisk.data.network.GithubRawServices import com.topjohnwu.magisk.net.Networking @@ -40,7 +42,9 @@ fun createOkHttpClient(context: Context): OkHttpClient { // builder.addInterceptor(httpLoggingInterceptor) if (!Networking.init(context)) { - builder.sslSocketFactory(NoSSLv3SocketFactory()) + Info.hasGMS = false + if (Build.VERSION.SDK_INT < 21) + builder.sslSocketFactory(NoSSLv3SocketFactory()) } val doh = DnsOverHttps.Builder().client(builder.build()) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index 67a787d4b..eed55bbde 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -46,7 +46,7 @@ class HomeViewModel( @get:Bindable var stateMagisk = MagiskState.LOADING - set(value) = set(value, field, { field = it }, BR.stateMagisk) + set(value) = set(value, field, { field = it }, BR.stateMagisk, BR.showUninstall) @get:Bindable var stateManager = MagiskState.LOADING @@ -73,6 +73,10 @@ class HomeViewModel( var stateManagerProgress = 0 set(value) = set(value, field, { field = it }, BR.stateManagerProgress) + @get:Bindable + val showUninstall get() = + Info.env.magiskVersionCode > 0 && stateMagisk != MagiskState.LOADING && isConnected.get() + val items = listOf(DeveloperItem.Mainline, DeveloperItem.App, DeveloperItem.Project) val itemBinding = itemBindingOf { it.bindExtra(BR.viewModel, this) @@ -92,6 +96,7 @@ class HomeViewModel( } override fun refresh() = viewModelScope.launch { + notifyPropertyChanged(BR.showUninstall) repoMagisk.fetchUpdate()?.apply { stateMagisk = when { !Info.env.isActive -> MagiskState.NOT_INSTALLED diff --git a/app/src/main/res/layout/fragment_home_md2.xml b/app/src/main/res/layout/fragment_home_md2.xml index a0e85fff2..b8b3e0d57 100644 --- a/app/src/main/res/layout/fragment_home_md2.xml +++ b/app/src/main/res/layout/fragment_home_md2.xml @@ -103,17 +103,22 @@ android:layout_marginTop="@dimen/l1" app:layout_constraintTop_toBottomOf="@+id/home_magisk_wrapper" /> + + @@ -121,14 +126,13 @@ style="@style/WidgetFoundation.Button.Outlined.Error" android:layout_marginStart="@dimen/l1" android:layout_marginEnd="@dimen/l1" - android:layout_marginTop="@dimen/l_125" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/uninstall_magisk_title" android:textAllCaps="false" android:textSize="12sp" android:onClick="@{() -> viewModel.onDeletePressed()}" - gone="@{Info.env.magiskVersionCode < 0 || viewModel.stateMagisk == MagiskState.LOADING || !viewModel.isConnected}" + gone="@{!viewModel.showUninstall}" app:cornerRadius="@dimen/r1" app:icon="@drawable/ic_delete_md2" />