Only show SafetyNet when GMS exists

This commit is contained in:
topjohnwu 2020-08-09 04:39:12 -07:00
parent 11222c89d4
commit 15b1215972
5 changed files with 22 additions and 11 deletions

View File

@ -47,10 +47,9 @@ public class Networking {
} catch (Exception e) { } catch (Exception e) {
if (Build.VERSION.SDK_INT < 21) { if (Build.VERSION.SDK_INT < 21) {
// Failed to update SSL provider, use NoSSLv3SocketFactory on SDK < 21 // Failed to update SSL provider, use NoSSLv3SocketFactory on SDK < 21
// and return false to notify potential issues
HttpsURLConnection.setDefaultSSLSocketFactory(new NoSSLv3SocketFactory()); HttpsURLConnection.setDefaultSSLSocketFactory(new NoSSLv3SocketFactory());
return false;
} }
return false;
} }
return true; return true;
} }

View File

@ -18,11 +18,9 @@ object Info {
val envRef = CachedValue { loadState() } val envRef = CachedValue { loadState() }
@JvmStatic @JvmStatic val env by envRef // Local
val env by envRef // Local @JvmStatic var stub: DynAPK.Data? = null // Stub
var remote = UpdateInfo() // Remote var remote = UpdateInfo() // Remote
@JvmStatic
var stub: DynAPK.Data? = null // Stub
// Toggle-able options // Toggle-able options
@JvmStatic var keepVerity = false @JvmStatic var keepVerity = false
@ -33,6 +31,7 @@ object Info {
@JvmStatic var isSAR = false @JvmStatic var isSAR = false
@JvmStatic var isAB = false @JvmStatic var isAB = false
@JvmStatic var ramdisk = false @JvmStatic var ramdisk = false
@JvmStatic var hasGMS = true
val isConnected by lazy { val isConnected by lazy {
ObservableBoolean(false).also { field -> ObservableBoolean(false).also { field ->

View File

@ -1,8 +1,10 @@
package com.topjohnwu.magisk.di package com.topjohnwu.magisk.di
import android.content.Context import android.content.Context
import android.os.Build
import com.squareup.moshi.Moshi import com.squareup.moshi.Moshi
import com.topjohnwu.magisk.core.Const 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.GithubApiServices
import com.topjohnwu.magisk.data.network.GithubRawServices import com.topjohnwu.magisk.data.network.GithubRawServices
import com.topjohnwu.magisk.net.Networking import com.topjohnwu.magisk.net.Networking
@ -40,6 +42,8 @@ fun createOkHttpClient(context: Context): OkHttpClient {
// builder.addInterceptor(httpLoggingInterceptor) // builder.addInterceptor(httpLoggingInterceptor)
if (!Networking.init(context)) { if (!Networking.init(context)) {
Info.hasGMS = false
if (Build.VERSION.SDK_INT < 21)
builder.sslSocketFactory(NoSSLv3SocketFactory()) builder.sslSocketFactory(NoSSLv3SocketFactory())
} }

View File

@ -46,7 +46,7 @@ class HomeViewModel(
@get:Bindable @get:Bindable
var stateMagisk = MagiskState.LOADING 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 @get:Bindable
var stateManager = MagiskState.LOADING var stateManager = MagiskState.LOADING
@ -73,6 +73,10 @@ class HomeViewModel(
var stateManagerProgress = 0 var stateManagerProgress = 0
set(value) = set(value, field, { field = it }, BR.stateManagerProgress) 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 items = listOf(DeveloperItem.Mainline, DeveloperItem.App, DeveloperItem.Project)
val itemBinding = itemBindingOf<HomeItem> { val itemBinding = itemBindingOf<HomeItem> {
it.bindExtra(BR.viewModel, this) it.bindExtra(BR.viewModel, this)
@ -92,6 +96,7 @@ class HomeViewModel(
} }
override fun refresh() = viewModelScope.launch { override fun refresh() = viewModelScope.launch {
notifyPropertyChanged(BR.showUninstall)
repoMagisk.fetchUpdate()?.apply { repoMagisk.fetchUpdate()?.apply {
stateMagisk = when { stateMagisk = when {
!Info.env.isActive -> MagiskState.NOT_INSTALLED !Info.env.isActive -> MagiskState.NOT_INSTALLED

View File

@ -103,17 +103,22 @@
android:layout_marginTop="@dimen/l1" android:layout_marginTop="@dimen/l1"
app:layout_constraintTop_toBottomOf="@+id/home_magisk_wrapper" /> app:layout_constraintTop_toBottomOf="@+id/home_magisk_wrapper" />
<Space
android:layout_width="match_parent"
android:layout_height="@dimen/l1"
gone="@{!Info.hasGMS &amp;&amp; !viewModel.showUninstall}" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
style="@style/WidgetFoundation.Button.Outlined" style="@style/WidgetFoundation.Button.Outlined"
android:layout_marginStart="@dimen/l1" android:layout_marginStart="@dimen/l1"
android:layout_marginEnd="@dimen/l1" android:layout_marginEnd="@dimen/l1"
android:layout_marginTop="@dimen/l1"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/home_check_safetynet" android:text="@string/home_check_safetynet"
android:textAllCaps="false" android:textAllCaps="false"
android:textSize="12sp" android:textSize="12sp"
android:onClick="@{() -> viewModel.onSafetyNetPressed()}" android:onClick="@{() -> viewModel.onSafetyNetPressed()}"
gone="@{!Info.hasGMS}"
app:cornerRadius="@dimen/r1" app:cornerRadius="@dimen/r1"
app:icon="@drawable/ic_safetynet_md2" /> app:icon="@drawable/ic_safetynet_md2" />
@ -121,14 +126,13 @@
style="@style/WidgetFoundation.Button.Outlined.Error" style="@style/WidgetFoundation.Button.Outlined.Error"
android:layout_marginStart="@dimen/l1" android:layout_marginStart="@dimen/l1"
android:layout_marginEnd="@dimen/l1" android:layout_marginEnd="@dimen/l1"
android:layout_marginTop="@dimen/l_125"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/uninstall_magisk_title" android:text="@string/uninstall_magisk_title"
android:textAllCaps="false" android:textAllCaps="false"
android:textSize="12sp" android:textSize="12sp"
android:onClick="@{() -> viewModel.onDeletePressed()}" android:onClick="@{() -> viewModel.onDeletePressed()}"
gone="@{Info.env.magiskVersionCode &lt; 0 || viewModel.stateMagisk == MagiskState.LOADING || !viewModel.isConnected}" gone="@{!viewModel.showUninstall}"
app:cornerRadius="@dimen/r1" app:cornerRadius="@dimen/r1"
app:icon="@drawable/ic_delete_md2" /> app:icon="@drawable/ic_delete_md2" />