From 9ef798f53491a5bd7beda617adc8565319b81a06 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 20 May 2017 03:04:14 +0800 Subject: [PATCH] Update SafetyNet check UI --- .../com/topjohnwu/magisk/MagiskManager.java | 3 +- .../com/topjohnwu/magisk/StatusFragment.java | 152 +++++++--- .../magisk/utils/SafetyNetHelper.java | 79 +++-- .../com/topjohnwu/magisk/utils/Utils.java | 11 +- app/src/main/res/layout/fragment_status.xml | 278 +++++++++++------- app/src/main/res/values-ar/strings.xml | 2 +- app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values-ja/strings.xml | 2 +- app/src/main/res/values-ko/strings.xml | 2 +- app/src/main/res/values-pl/strings.xml | 2 +- app/src/main/res/values-pt/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values-tr/strings.xml | 2 +- app/src/main/res/values-vi/strings.xml | 2 +- app/src/main/res/values-zh-rCN/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 2 +- app/src/main/res/values/strings.xml | 6 +- 21 files changed, 367 insertions(+), 192 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java index 36132e8fc..7899cc5f2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java @@ -13,6 +13,7 @@ import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.superuser.Policy; import com.topjohnwu.magisk.utils.CallbackEvent; +import com.topjohnwu.magisk.utils.SafetyNetHelper; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.ValueSortedMap; @@ -46,7 +47,7 @@ public class MagiskManager extends Application { public int remoteMagiskVersionCode = -1; public String magiskLink; public String releaseNoteLink; - public int SNCheckResult = -1; + public SafetyNetHelper.Result SNCheckResult; public String bootBlock = null; public boolean isSuClient = false; public String suVersion = null; diff --git a/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java b/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java index 3a102ab46..0ec84eb65 100644 --- a/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java @@ -1,12 +1,16 @@ package com.topjohnwu.magisk; +import android.animation.Animator; +import android.animation.ValueAnimator; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.widget.SwipeRefreshLayout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; @@ -41,25 +45,28 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener { magiskUpdateText.setText(R.string.checking_for_updates); magiskCheckUpdatesProgress.setVisibility(View.VISIBLE); magiskUpdateIcon.setVisibility(View.GONE); - safetyNetProgress.setVisibility(View.GONE); - safetyNetContainer.setBackgroundColor(colorNeutral); - safetyNetIcon.setImageResource(R.drawable.ic_safetynet); safetyNetStatusText.setText(R.string.safetyNet_check_text); - safetyNetStatusText.setTextColor(defaultColor); magiskManager.safetyNetDone.isTriggered = false; + collapse(); noDialog = false; updateUI(); @@ -217,37 +238,86 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener { + int value = (Integer) valueAnimator.getAnimatedValue(); + ViewGroup.LayoutParams layoutParams = expandLayout.getLayoutParams(); + layoutParams.height = value; + expandLayout.setLayoutParams(layoutParams); + }); + return animator; } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/SafetyNetHelper.java b/app/src/main/java/com/topjohnwu/magisk/utils/SafetyNetHelper.java index 32895f494..b985cac42 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/SafetyNetHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/SafetyNetHelper.java @@ -1,15 +1,16 @@ package com.topjohnwu.magisk.utils; -import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.app.FragmentActivity; import android.util.Base64; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.Status; import com.google.android.gms.safetynet.SafetyNet; +import com.topjohnwu.magisk.R; import org.json.JSONException; import org.json.JSONObject; @@ -20,39 +21,49 @@ public abstract class SafetyNetHelper implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks { private GoogleApiClient mGoogleApiClient; + private Result ret; + protected FragmentActivity mActivity; - public SafetyNetHelper(Context context) { - mGoogleApiClient = new GoogleApiClient.Builder(context) + public SafetyNetHelper(FragmentActivity activity) { + ret = new Result(); + mActivity = activity; + mGoogleApiClient = new GoogleApiClient.Builder(activity) + .enableAutoManage(activity, this) .addApi(SafetyNet.API) .addConnectionCallbacks(this) - .addOnConnectionFailedListener(this) .build(); } - @Override - public void onConnectionFailed(@NonNull ConnectionResult result) { - Logger.dev("SN: Google API fail"); - handleResults(-2); - } - - @Override - public void onConnected(@Nullable Bundle bundle) { - Logger.dev("SN: Google API Connected"); - safetyNetCheck(); - } - - @Override - public void onConnectionSuspended(int i) { - Logger.dev("SN: Google API Suspended"); - handleResults(-3); - } - + // Entry point to start test public void requestTest() { // Connect Google Service mGoogleApiClient.connect(); } - private void safetyNetCheck() { + @Override + public void onConnectionFailed(@NonNull ConnectionResult result) { + Logger.dev("SN: Google API fail"); + ret.errmsg = result.getErrorMessage(); + handleResults(ret); + } + + @Override + public void onConnectionSuspended(int i) { + Logger.dev("SN: Google API Suspended"); + switch (i) { + case CAUSE_NETWORK_LOST: + ret.errmsg = mActivity.getString(R.string.safetyNet_network_loss); + break; + case CAUSE_SERVICE_DISCONNECTED: + ret.errmsg = mActivity.getString(R.string.safetyNet_service_disconnected); + break; + } + handleResults(ret); + } + + @Override + public void onConnected(@Nullable Bundle bundle) { + Logger.dev("SN: Google API Connected"); // Create nonce byte[] nonce = new byte[24]; new SecureRandom().nextBytes(nonce); @@ -68,16 +79,30 @@ public abstract class SafetyNetHelper Logger.dev("SN: Response: " + json); try { JSONObject decoded = new JSONObject(json); - handleResults(decoded.getBoolean("ctsProfileMatch") ? 1 : 0); - } catch (JSONException ignored) {} + ret.ctsProfile = decoded.getBoolean("ctsProfileMatch"); + ret.basicIntegrity = decoded.getBoolean("basicIntegrity"); + ret.failed = false; + } catch (JSONException e) { + ret.errmsg = mActivity.getString(R.string.safetyNet_res_invalid); + } } else { Logger.dev("SN: No response"); - handleResults(-1); + ret.errmsg = mActivity.getString(R.string.safetyNet_no_response); } // Disconnect + mGoogleApiClient.stopAutoManage(mActivity); mGoogleApiClient.disconnect(); + handleResults(ret); }); } - public abstract void handleResults(int i); + // Callback function to save the results + public abstract void handleResults(Result result); + + public static class Result { + public boolean failed = true; + public String errmsg; + public boolean ctsProfile = false; + public boolean basicIntegrity = false; + } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 012cbe791..ee97b7beb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -13,6 +13,7 @@ import android.os.Environment; import android.provider.OpenableColumns; import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; +import android.support.v4.app.FragmentActivity; import android.text.TextUtils; import android.widget.Toast; @@ -144,12 +145,12 @@ public class Utils { return (MagiskManager) context.getApplicationContext(); } - public static void checkSafetyNet(MagiskManager magiskManager) { - new SafetyNetHelper(magiskManager) { + public static void checkSafetyNet(FragmentActivity activity) { + new SafetyNetHelper(activity) { @Override - public void handleResults(int i) { - magiskManager.SNCheckResult = i; - magiskManager.safetyNetDone.trigger(); + public void handleResults(Result result) { + getMagiskManager(mActivity).SNCheckResult = result; + getMagiskManager(mActivity).safetyNetDone.trigger(); } }.requestTest(); } diff --git a/app/src/main/res/layout/fragment_status.xml b/app/src/main/res/layout/fragment_status.xml index 26bfcfe7f..a9d4c099e 100644 --- a/app/src/main/res/layout/fragment_status.xml +++ b/app/src/main/res/layout/fragment_status.xml @@ -21,170 +21,244 @@ android:orientation="vertical"> - - - + android:layout_height="match_parent"> + + + android:text="@string/checking_for_updates" + android:textStyle="bold" /> - + + android:orientation="vertical"> - + - + + + + + + + + + + + + + + - - - - - - - - - - - - + android:layout_marginEnd="5dp" + android:layout_marginStart="4dp" + android:layout_marginTop="5dp" + android:minHeight="?android:attr/listPreferredItemHeight" + app:cardCornerRadius="@dimen/card_corner_radius" + app:cardElevation="@dimen/card_elevation"> - + android:layout_height="match_parent"> + android:id="@+id/safetyNet_refresh" + android:layout_width="25dp" + android:layout_height="25dp" + android:layout_centerVertical="true" + android:layout_margin="15dp" + android:layout_toStartOf="@+id/safetyNet_status" + android:src="@drawable/ic_refresh" /> + + + android:layout_centerHorizontal="true" + android:layout_centerVertical="true" + android:gravity="center" + android:minWidth="175dp" + android:padding="6dp" + android:text="@string/safetyNet_check_text" + android:textStyle="bold" /> - + - + android:orientation="vertical" + android:paddingEnd="10dp" + android:paddingStart="10dp"> + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 8ebc6d77b..0ba8cbabb 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -110,7 +110,7 @@ إبقاء dm-verity مروت لكن لا يوجد إذن الروت، غير مسموح به؟ وظائف محدودة إلى حد كبير - تعذر التحقق من SafetyNet، لا يوجد إنترنت؟ + تعذر التحقق من SafetyNet، لا يوجد إنترنت؟ SafetyNet تخطى فشل SafetyNet: عدم تطابق التشكيل الجانبي CTS الحالة diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 10be91b7b..c2f0602f3 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -27,7 +27,7 @@ Kontrola stavu SafetyNet… Nelze se spojit s Google API Spojení s Google API bylo přerušeno - Nelze zkontrolovat SafetyNet. Jste připojeni k Internetu? + Nelze zkontrolovat SafetyNet. Jste připojeni k Internetu? SafetyNet dopadl neúspěšně: CTS profile mismatch SafetyNet Schváleno Funkčnost omezena diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0a9794dc2..9eded30fd 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -30,7 +30,7 @@ Prüfe SafetyNet-Status… Verbindung zur Google-API fehlgeschlagen Verbindung zur Google-API wurde ausgesetzt - SafetyNet-Status konnte nicht geprüft werden. Ist eine Internetverbindung verfügbar? + SafetyNet-Status konnte nicht geprüft werden. Ist eine Internetverbindung verfügbar? SafetyNet nicht bestanden: \"CTS profile mismatch\" SafetyNet bestanden Funktionalität stark eingeschränkt diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index dee3777ef..89f973c43 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -27,7 +27,7 @@ Comprobando estado de SafetyNet… No puede conectar con la API de Google La conexión con la API de Google API fue suspendida - No puede comprobar SafetyNet, ¿No tiene internet? + No puede comprobar SafetyNet, ¿No tiene internet? SafetyNet: Error, no coincide el perfil CTS SafetyNet: Correcto Funcionalidad enormemente limitada diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 4f05ca5c7..4624eec4b 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -25,7 +25,7 @@ Vérification de l\'état de SafetyNet… Impossible de se connecter à l\'API Google La connexion à l\'API Google a été suspendue - Impossible de contrôler SafetyNet, pas d\'Internet? + Impossible de contrôler SafetyNet, pas d\'Internet? Échec SafetyNet: erreur de profil CTS SafetyNet réussi Fonctionnalités largement limitées diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 54cb8ad2e..adf6f0551 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -28,7 +28,7 @@ Controllo SafetyNet Impossibile collegarsi alle API Google Connessione alle API Google sospesa - Impossibile controllare SafetyNet. Nessuna connessione internet? + Impossibile controllare SafetyNet. Nessuna connessione internet? Errore SafetyNet. Il profilo CTS non corrisponde Controllo SafetyNet OK Funzionalità molto limitata diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index ac407596b..a20b5ed6e 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -28,7 +28,7 @@ SafetyNet Statusをチェック中… Google APIに接続できませんでした Google APIへの接続が中断されました - SafetyNetをチェックできませんでした。インターネットに接続されていますか? + SafetyNetをチェックできませんでした。インターネットに接続されていますか? SafetyNet Failed: CTSプロファイルが不一致 SafetyNet Passed 機能が大幅に制限されています diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 21169aaf8..3d94c2e21 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -28,7 +28,7 @@ SafetyNet 상태 확인 중… Google API에 연결할 수 없음 Google API에 대한 연결이 일시 중지됨 - SafetyNet 체크 실패. 인터넷 연결을 확인하세요. + SafetyNet 체크 실패. 인터넷 연결을 확인하세요. SafetyNet 실패: CTS 프로필 불일치 SafetyNet 통과 기능이 크게 제한됨 diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index f2a63ba1b..2031b7ec5 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -31,7 +31,7 @@ Sprawdzanie statusu SafetyNet… Nie można połączyć się z Google API Połączenie z Google API zostało zawieszone - Nie można sprawdzić SafetyNet bez internetu + Nie można sprawdzić SafetyNet bez internetu Błąd SafetyNet: Niezgodność profilu CTS SafetyNet Poprawny Funkcjonalność znacznie ograniczona diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index ba3b72a09..579c8ba39 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -31,7 +31,7 @@ Checando status do SafetyNet… Não é possível conectar-se à API do Google A conexão com API do Google foi suspensa - Não é possível verificar o SafetyNet, sem Internet? + Não é possível verificar o SafetyNet, sem Internet? SafetyNet Falhou: CTS profile mismatch SafetyNet Passado Funcionalidade muito limitada diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 6dcf53e74..c8757d81f 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -25,7 +25,7 @@ Проверка статуса SafetyNet… Невозможно соединиться с API Google Соединение с API Google было приостановлено - Невозможно выполнить проверку SafetyNet, нет соединения? + Невозможно выполнить проверку SafetyNet, нет соединения? SafetyNet не пройден: несовпадение профиля CTS SafetyNet пройден Функциональность значительно ограничена diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index a0ce9fa5b..f5791cb6b 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -25,7 +25,7 @@ SafetyNet durumu kontrol ediliyor… "Google API'ye bağlanılamıyor" Google API bağlantısı askıya alındı - SafetyNet kontrol edilemiyor, İnternet yok mu? + SafetyNet kontrol edilemiyor, İnternet yok mu? SafetyNet başarısız: CTS profili uyumsuzluğu SafetyNet Geçti İşlevsellik çok sınırlıdır diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 83fc0c541..feaec0d09 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -27,7 +27,7 @@ Đang kiểm tra trạng thái SafetyNet… Không thể kết nối với API của Google Kết nối với API của Google đã dừng - Không thể kiểm tra SafetyNet, không có Internet? + Không thể kiểm tra SafetyNet, không có Internet? SafetyNet thất bại: cấu hình CTS không phù hợp SafetyNet thành công Tính năng bị hạn chế rất nhiều diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 1471e6239..2ad1ba107 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -28,7 +28,7 @@ 正在检查 SafetyNet 状态… 无法连接至 Google API 与 Google API 的连接已暂停 - 无法检查 SafetyNet,没有网络连接? + 无法检查 SafetyNet,没有网络连接? SafetyNet 失败:CTS 配置文件不匹配 SafetyNet 已通过 功能严重受限 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 59fd6e370..176340f1f 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -27,7 +27,7 @@ 正在檢查 SafetyNet 狀態… 無法連接至 Google API 與 Google API 的連接已暫停 - 無法檢查 SafetyNet,沒有網絡連線? + 無法檢查 SafetyNet,沒有網絡連線? SafetyNet 失敗:CTS 配置文件不匹配 SafetyNet 已通過 功能嚴重受限 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e11554902..8d4e3349a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -29,11 +29,15 @@ Properly rooted Tap to start SafetyNet check Checking SafetyNet status… + SafetyNet Check Success Cannot connect to Google API Connection to Google API was suspended - Cannot check SafetyNet, no Internet? + Cannot check SafetyNet, no Internet? SafetyNet Failed: CTS profile mismatch SafetyNet Passed + Network connection loss + Service has been killed + The response is invalid Functionality greatly limited