1
mirror of https://github.com/topjohnwu/Magisk synced 2024-11-14 22:28:37 +01:00

Hide SafetyNet check if no GMS

This commit is contained in:
vvb2060 2018-08-19 00:59:56 +08:00 committed by John Wu
parent 89a501a3af
commit e42b608444

View File

@ -2,6 +2,8 @@ package com.topjohnwu.magisk;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -208,15 +210,27 @@ public class MagiskFragment extends BaseFragment
return expandableContainer; return expandableContainer;
} }
private boolean hasGms() {
PackageManager pm = mm.getPackageManager();
PackageInfo info;
try {
info = pm.getPackageInfo("com.google.android.gms", 0);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
return info.applicationInfo.enabled;
}
private void updateUI() { private void updateUI() {
((MainActivity) requireActivity()).checkHideSection(); ((MainActivity) requireActivity()).checkHideSection();
boolean hasNetwork = Download.checkNetworkStatus(mm); boolean hasNetwork = Download.checkNetworkStatus(mm);
boolean hasRoot = Shell.rootAccess(); boolean hasRoot = Shell.rootAccess();
boolean hasGms = hasGms();
boolean isUpToDate = Data.magiskVersionCode > Const.MAGISK_VER.UNIFIED; boolean isUpToDate = Data.magiskVersionCode > Const.MAGISK_VER.UNIFIED;
magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
safetyNetCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); safetyNetCard.setVisibility(hasNetwork && hasGms ? View.VISIBLE : View.GONE);
installOptionCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); installOptionCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
uninstallButton.setVisibility(isUpToDate && hasRoot ? View.VISIBLE : View.GONE); uninstallButton.setVisibility(isUpToDate && hasRoot ? View.VISIBLE : View.GONE);
coreOnlyNotice.setVisibility(mm.prefs.getBoolean(Const.Key.COREONLY, false) ? View.VISIBLE : View.GONE); coreOnlyNotice.setVisibility(mm.prefs.getBoolean(Const.Key.COREONLY, false) ? View.VISIBLE : View.GONE);