From 442fcf921c11ebba4eae268cc026a902fdd20383 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 7 Jan 2017 01:19:18 +0800 Subject: [PATCH] Change SafetyNet check to manual start --- .../topjohnwu/magisk/MagiskHideFragment.java | 3 -- .../com/topjohnwu/magisk/SplashActivity.java | 1 - .../com/topjohnwu/magisk/StatusFragment.java | 40 +++++++++++++------ .../magisk/adapters/ApplicationAdapter.java | 1 - app/src/main/res/drawable/ic_safetynet.xml | 9 +++++ app/src/main/res/layout/status_fragment.xml | 11 +++-- app/src/main/res/values/strings.xml | 1 + 7 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 app/src/main/res/drawable/ic_safetynet.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java index 88403d0a6..1e686f931 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java @@ -19,12 +19,9 @@ import com.topjohnwu.magisk.adapters.ApplicationAdapter; import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.Logger; -import com.topjohnwu.magisk.utils.Shell; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; import java.util.List; import butterknife.BindView; diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index d897f3f69..a631b0abb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -34,7 +34,6 @@ public class SplashActivity extends AppCompatActivity { // Start all async tasks new Async.GetBootBlocks().exec(); new Async.CheckUpdates().exec(); - Async.checkSafetyNet(getApplicationContext()); new Async.LoadModules() { @Override protected void onPostExecute(Void v) { diff --git a/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java b/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java index 8b4269367..a0fadac01 100644 --- a/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java @@ -56,6 +56,7 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis @BindColor(R.color.grey500) int colorNeutral; @BindColor(R.color.blue500) int colorInfo; @BindColor(android.R.color.transparent) int trans; + int defaultColor; static { checkMagiskInfo(); @@ -67,30 +68,37 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis View v = inflater.inflate(R.layout.status_fragment, container, false); ButterKnife.bind(this, v); + defaultColor = magiskUpdateText.getCurrentTextColor(); + mSwipeRefreshLayout.setOnRefreshListener(() -> { magiskStatusContainer.setBackgroundColor(trans); magiskStatusIcon.setImageResource(0); magiskUpdateText.setText(R.string.checking_for_updates); magiskCheckUpdatesProgress.setVisibility(View.VISIBLE); + magiskUpdateText.setTextColor(defaultColor); + safetyNetProgress.setVisibility(View.GONE); + safetyNetContainer.setBackgroundColor(colorNeutral); + safetyNetIcon.setImageResource(R.drawable.ic_safetynet); + safetyNetStatusText.setText(R.string.safetyNet_check_text); + safetyNetStatusText.setTextColor(defaultColor); + + safetyNetDone.isTriggered = false; + + updateUI(); + new Async.CheckUpdates().exec(); + }); + + updateUI(); + + safetyNetContainer.setOnClickListener(view -> { safetyNetProgress.setVisibility(View.VISIBLE); safetyNetContainer.setBackgroundColor(trans); safetyNetIcon.setImageResource(0); safetyNetStatusText.setText(R.string.checking_safetyNet_status); - - updateUI(); - new Async.CheckUpdates().exec(); Async.checkSafetyNet(getActivity()); }); - updateUI(); - if (updateCheckDone.isTriggered) { - updateCheckUI(); - } - if (safetyNetDone.isTriggered) { - updateSafetyNetUI(); - } - if (magiskVersion < 0 && Shell.rootAccess()) { MainActivity.alertBuilder .setTitle(R.string.no_magisk_title) @@ -127,12 +135,18 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis super.onResume(); CallbackHandler.register(updateCheckDone, this); CallbackHandler.register(safetyNetDone, this); + if (updateCheckDone.isTriggered) { + updateCheckUI(); + } + if (safetyNetDone.isTriggered) { + updateSafetyNetUI(); + } getActivity().setTitle(R.string.status); } @Override - public void onDestroy() { - super.onDestroy(); + public void onPause() { + super.onPause(); CallbackHandler.unRegister(updateCheckDone, this); CallbackHandler.unRegister(safetyNetDone, this); } diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java b/app/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java index fd1bf54fd..841e1a50d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java @@ -16,7 +16,6 @@ import android.widget.TextView; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Async; -import java.util.Arrays; import java.util.List; import butterknife.BindView; diff --git a/app/src/main/res/drawable/ic_safetynet.xml b/app/src/main/res/drawable/ic_safetynet.xml new file mode 100644 index 000000000..a380b9bb4 --- /dev/null +++ b/app/src/main/res/drawable/ic_safetynet.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/status_fragment.xml b/app/src/main/res/layout/status_fragment.xml index b8e9a8ac6..bac2a3350 100644 --- a/app/src/main/res/layout/status_fragment.xml +++ b/app/src/main/res/layout/status_fragment.xml @@ -157,19 +157,22 @@ android:layout_width="match_parent" android:layout_height="100dp" android:foregroundGravity="center" - android:orientation="vertical"> + android:orientation="vertical" + android:background="@color/grey500"> + android:layout_gravity="center" + android:src="@drawable/ic_safetynet"/> + android:layout_gravity="center" + android:visibility="gone"/> @@ -181,7 +184,7 @@ android:gravity="center" android:padding="6dp" android:textStyle="bold" - android:text="@string/checking_safetyNet_status" /> + android:text="@string/safetyNet_check_text" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c2e79b24..f16d9c1a1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,6 +25,7 @@ Rooted but no root permission, not allowed? Not rooted Properly rooted + Tap to start SafetyNet check Checking SafetyNet status… Cannot connect to Google API Connection to Google API was suspended