mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 10:35:26 +00:00
Network check
This commit is contained in:
parent
0917c79470
commit
e6f10176c6
@ -58,16 +58,17 @@ public class MagiskFragment extends Fragment implements CallbackEvent.Listener<V
|
|||||||
|
|
||||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
|
|
||||||
|
@BindView(R.id.magisk_update_card) CardView magiskUpdateCard;
|
||||||
@BindView(R.id.magisk_update_icon) ImageView magiskUpdateIcon;
|
@BindView(R.id.magisk_update_icon) ImageView magiskUpdateIcon;
|
||||||
@BindView(R.id.magisk_update_status) TextView magiskUpdateText;
|
@BindView(R.id.magisk_update_status) TextView magiskUpdateText;
|
||||||
@BindView(R.id.magisk_check_updates_progress) ProgressBar magiskCheckUpdatesProgress;
|
@BindView(R.id.magisk_update_progress) ProgressBar magiskUpdateProgress;
|
||||||
|
|
||||||
@BindView(R.id.magisk_status_icon) ImageView magiskStatusIcon;
|
@BindView(R.id.magisk_status_icon) ImageView magiskStatusIcon;
|
||||||
@BindView(R.id.magisk_version) TextView magiskVersionText;
|
@BindView(R.id.magisk_version) TextView magiskVersionText;
|
||||||
|
|
||||||
@BindView(R.id.root_status_icon) ImageView rootStatusIcon;
|
@BindView(R.id.root_status_icon) ImageView rootStatusIcon;
|
||||||
@BindView(R.id.root_status) TextView rootStatusText;
|
@BindView(R.id.root_status) TextView rootStatusText;
|
||||||
|
|
||||||
|
@BindView(R.id.safetyNet_card) CardView safetyNetCard;
|
||||||
@BindView(R.id.safetyNet_refresh) ImageView safetyNetRefreshIcon;
|
@BindView(R.id.safetyNet_refresh) ImageView safetyNetRefreshIcon;
|
||||||
@BindView(R.id.safetyNet_status) TextView safetyNetStatusText;
|
@BindView(R.id.safetyNet_status) TextView safetyNetStatusText;
|
||||||
@BindView(R.id.safetyNet_check_progress) ProgressBar safetyNetProgress;
|
@BindView(R.id.safetyNet_check_progress) ProgressBar safetyNetProgress;
|
||||||
@ -226,18 +227,27 @@ public class MagiskFragment extends Fragment implements CallbackEvent.Listener<V
|
|||||||
});
|
});
|
||||||
|
|
||||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||||
|
updateUI();
|
||||||
|
|
||||||
magiskUpdateText.setText(R.string.checking_for_updates);
|
magiskUpdateText.setText(R.string.checking_for_updates);
|
||||||
magiskCheckUpdatesProgress.setVisibility(View.VISIBLE);
|
magiskUpdateProgress.setVisibility(View.VISIBLE);
|
||||||
magiskUpdateIcon.setVisibility(View.GONE);
|
magiskUpdateIcon.setVisibility(View.GONE);
|
||||||
|
|
||||||
safetyNetStatusText.setText(R.string.safetyNet_check_text);
|
safetyNetStatusText.setText(R.string.safetyNet_check_text);
|
||||||
|
|
||||||
magiskManager.safetyNetDone.isTriggered = false;
|
magiskManager.safetyNetDone.isTriggered = false;
|
||||||
|
magiskManager.updateCheckDone.isTriggered = false;
|
||||||
|
magiskManager.remoteMagiskVersionString = null;
|
||||||
|
magiskManager.remoteMagiskVersionCode = -1;
|
||||||
collapse();
|
collapse();
|
||||||
noDialog = false;
|
noDialog = false;
|
||||||
|
|
||||||
updateVersionUI();
|
// Trigger state check
|
||||||
new CheckUpdates(getActivity()).exec();
|
if (Utils.checkNetworkStatus(magiskManager)) {
|
||||||
|
new CheckUpdates(getActivity()).exec();
|
||||||
|
} else {
|
||||||
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (magiskManager.magiskVersionCode < 0 && Shell.rootAccess() && !noDialog) {
|
if (magiskManager.magiskVersionCode < 0 && Shell.rootAccess() && !noDialog) {
|
||||||
@ -251,14 +261,7 @@ public class MagiskFragment extends Fragment implements CallbackEvent.Listener<V
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVersionUI();
|
updateUI();
|
||||||
|
|
||||||
if (magiskManager.updateCheckDone.isTriggered)
|
|
||||||
updateCheckUI();
|
|
||||||
if (magiskManager.safetyNetDone.isTriggered)
|
|
||||||
updateSafetyNetUI();
|
|
||||||
if (magiskManager.blockDetectionDone.isTriggered)
|
|
||||||
updateInstallUI();
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@ -277,6 +280,13 @@ public class MagiskFragment extends Fragment implements CallbackEvent.Listener<V
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
// Manual trigger if already done
|
||||||
|
if (magiskManager.updateCheckDone.isTriggered)
|
||||||
|
updateCheckUI();
|
||||||
|
if (magiskManager.safetyNetDone.isTriggered)
|
||||||
|
updateSafetyNetUI();
|
||||||
|
if (magiskManager.blockDetectionDone.isTriggered)
|
||||||
|
updateInstallUI();
|
||||||
magiskManager.updateCheckDone.register(this);
|
magiskManager.updateCheckDone.register(this);
|
||||||
magiskManager.safetyNetDone.register(this);
|
magiskManager.safetyNetDone.register(this);
|
||||||
magiskManager.blockDetectionDone.register(this);
|
magiskManager.blockDetectionDone.register(this);
|
||||||
@ -297,6 +307,22 @@ public class MagiskFragment extends Fragment implements CallbackEvent.Listener<V
|
|||||||
unbinder.unbind();
|
unbinder.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateUI() {
|
||||||
|
((MainActivity) getActivity()).checkHideSection();
|
||||||
|
final int ROOT = 0x1, NETWORK = 0x2, UPTODATE = 0x4;
|
||||||
|
int status = 0;
|
||||||
|
status |= Shell.rootAccess() ? ROOT : 0;
|
||||||
|
status |= Utils.checkNetworkStatus(magiskManager) ? NETWORK : 0;
|
||||||
|
status |= magiskManager.magiskVersionCode >= 130 ? UPTODATE : 0;
|
||||||
|
magiskUpdateCard.setVisibility(Utils.checkBits(status, NETWORK) ? View.VISIBLE : View.GONE);
|
||||||
|
safetyNetCard.setVisibility(Utils.checkBits(status, NETWORK) ? View.VISIBLE : View.GONE);
|
||||||
|
bootImageCard.setVisibility(Utils.checkBits(status, NETWORK, ROOT) ? View.VISIBLE : View.GONE);
|
||||||
|
installOptionCard.setVisibility(Utils.checkBits(status, NETWORK, ROOT) ? View.VISIBLE : View.GONE);
|
||||||
|
installButton.setVisibility(Utils.checkBits(status, NETWORK) ? View.VISIBLE : View.GONE);
|
||||||
|
uninstallButton.setVisibility(Utils.checkBits(status, UPTODATE, ROOT) ? View.VISIBLE : View.GONE);
|
||||||
|
updateVersionUI();
|
||||||
|
}
|
||||||
|
|
||||||
private void updateVersionUI() {
|
private void updateVersionUI() {
|
||||||
int image, color;
|
int image, color;
|
||||||
|
|
||||||
@ -356,20 +382,14 @@ public class MagiskFragment extends Fragment implements CallbackEvent.Listener<V
|
|||||||
magiskUpdateIcon.setColorFilter(color);
|
magiskUpdateIcon.setColorFilter(color);
|
||||||
magiskUpdateIcon.setVisibility(View.VISIBLE);
|
magiskUpdateIcon.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
magiskCheckUpdatesProgress.setVisibility(View.GONE);
|
magiskUpdateProgress.setVisibility(View.GONE);
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateInstallUI() {
|
private void updateInstallUI() {
|
||||||
if (!Shell.rootAccess()) {
|
if (!Shell.rootAccess()) {
|
||||||
installText.setText(R.string.download);
|
installText.setText(R.string.download);
|
||||||
bootImageCard.setVisibility(View.GONE);
|
|
||||||
installOptionCard.setVisibility(View.GONE);
|
|
||||||
uninstallButton.setVisibility(View.GONE);
|
|
||||||
} else {
|
} else {
|
||||||
bootImageCard.setVisibility(View.VISIBLE);
|
|
||||||
installOptionCard.setVisibility(View.VISIBLE);
|
|
||||||
uninstallButton.setVisibility(magiskManager.magiskVersionCode >= 130 ? View.VISIBLE : View.GONE);
|
|
||||||
installText.setText(R.string.download_install);
|
installText.setText(R.string.download_install);
|
||||||
|
|
||||||
List<String> items = new ArrayList<>();
|
List<String> items = new ArrayList<>();
|
||||||
|
@ -22,6 +22,7 @@ import android.view.View;
|
|||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.utils.CallbackEvent;
|
import com.topjohnwu.magisk.utils.CallbackEvent;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -81,7 +82,6 @@ public class MainActivity extends Activity
|
|||||||
|
|
||||||
navigationView.setNavigationItemSelectedListener(this);
|
navigationView.setNavigationItemSelectedListener(this);
|
||||||
getApplicationContext().reloadMainActivity.register(this);
|
getApplicationContext().reloadMainActivity.register(this);
|
||||||
getApplicationContext().updateCheckDone.register(this);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,16 +106,18 @@ public class MainActivity extends Activity
|
|||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
getApplicationContext().reloadMainActivity.unRegister(this);
|
getApplicationContext().reloadMainActivity.unRegister(this);
|
||||||
getApplicationContext().updateCheckDone.unRegister(this);
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (drawer.isDrawerOpen(navigationView))
|
if (drawer.isDrawerOpen(navigationView)) {
|
||||||
drawer.closeDrawer(navigationView);
|
drawer.closeDrawer(navigationView);
|
||||||
else
|
} else if (mDrawerItem != R.id.magisk) {
|
||||||
|
navigate(R.id.magisk);
|
||||||
|
} else {
|
||||||
finish();
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -128,21 +130,17 @@ public class MainActivity extends Activity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent<Void> event) {
|
public void onTrigger(CallbackEvent<Void> event) {
|
||||||
if (event == getApplicationContext().reloadMainActivity) {
|
recreate();
|
||||||
recreate();
|
|
||||||
} else if (event == getApplicationContext().updateCheckDone) {
|
|
||||||
checkHideSection();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkHideSection() {
|
public void checkHideSection() {
|
||||||
Menu menu = navigationView.getMenu();
|
Menu menu = navigationView.getMenu();
|
||||||
menu.findItem(R.id.magiskhide).setVisible(
|
menu.findItem(R.id.magiskhide).setVisible(
|
||||||
Shell.rootAccess() && getApplicationContext().magiskVersionCode >= 130
|
Shell.rootAccess() && getApplicationContext().magiskVersionCode >= 130
|
||||||
&& prefs.getBoolean("magiskhide", false));
|
&& prefs.getBoolean("magiskhide", false));
|
||||||
menu.findItem(R.id.modules).setVisible(
|
menu.findItem(R.id.modules).setVisible(
|
||||||
Shell.rootAccess() && getApplicationContext().magiskVersionCode >= 0);
|
Shell.rootAccess() && getApplicationContext().magiskVersionCode >= 0);
|
||||||
menu.findItem(R.id.downloads).setVisible(
|
menu.findItem(R.id.downloads).setVisible(Utils.checkNetworkStatus(this) &&
|
||||||
Shell.rootAccess() && getApplicationContext().magiskVersionCode >= 0);
|
Shell.rootAccess() && getApplicationContext().magiskVersionCode >= 0);
|
||||||
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
|
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
|
||||||
menu.findItem(R.id.superuser).setVisible(
|
menu.findItem(R.id.superuser).setVisible(
|
||||||
@ -154,6 +152,7 @@ public class MainActivity extends Activity
|
|||||||
if (item != null) {
|
if (item != null) {
|
||||||
switch (item) {
|
switch (item) {
|
||||||
case "magisk":
|
case "magisk":
|
||||||
|
case "install":
|
||||||
itemId = R.id.magisk;
|
itemId = R.id.magisk;
|
||||||
break;
|
break;
|
||||||
case "superuser":
|
case "superuser":
|
||||||
|
@ -6,14 +6,15 @@ import android.content.ComponentName;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
|
||||||
import com.topjohnwu.magisk.asyncs.GetBootBlocks;
|
import com.topjohnwu.magisk.asyncs.GetBootBlocks;
|
||||||
import com.topjohnwu.magisk.asyncs.LoadApps;
|
import com.topjohnwu.magisk.asyncs.LoadApps;
|
||||||
import com.topjohnwu.magisk.asyncs.LoadModules;
|
import com.topjohnwu.magisk.asyncs.LoadModules;
|
||||||
import com.topjohnwu.magisk.asyncs.LoadRepos;
|
import com.topjohnwu.magisk.asyncs.LoadRepos;
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.services.UpdateCheckService;
|
import com.topjohnwu.magisk.services.UpdateCheckService;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
public class SplashActivity extends Activity{
|
public class SplashActivity extends Activity{
|
||||||
|
|
||||||
@ -29,40 +30,39 @@ public class SplashActivity extends Activity{
|
|||||||
// Init the info and configs and root shell
|
// Init the info and configs and root shell
|
||||||
magiskManager.init();
|
magiskManager.init();
|
||||||
|
|
||||||
// Initialize the update check service, notify every 3 hours
|
|
||||||
if (!"install".equals(getIntent().getStringExtra(MagiskManager.INTENT_SECTION))) {
|
|
||||||
ComponentName service = new ComponentName(magiskManager, UpdateCheckService.class);
|
|
||||||
JobInfo jobInfo = new JobInfo.Builder(UPDATE_SERVICE_ID, service)
|
|
||||||
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
|
||||||
.setPersisted(true)
|
|
||||||
.setPeriodic(3 * 60 * 60 * 1000)
|
|
||||||
.build();
|
|
||||||
JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
|
||||||
scheduler.schedule(jobInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now fire all async tasks
|
// Now fire all async tasks
|
||||||
new GetBootBlocks(this).exec();
|
new GetBootBlocks(this).exec();
|
||||||
new LoadModules(this) {
|
new LoadModules(this) {
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
super.onPostExecute(v);
|
super.onPostExecute(v);
|
||||||
new LoadRepos(activity).exec();
|
if (Utils.checkNetworkStatus(activity)) {
|
||||||
|
new LoadRepos(activity).exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.exec();
|
}.exec();
|
||||||
new LoadApps(this).exec();
|
new LoadApps(this).exec();
|
||||||
new CheckUpdates(this, false){
|
|
||||||
@Override
|
if (Utils.checkNetworkStatus(this)) {
|
||||||
protected void onPostExecute(Void v) {
|
// Initialize the update check service, notify every 12 hours
|
||||||
super.onPostExecute(v);
|
if (!TextUtils.equals("install", getIntent().getStringExtra(MagiskManager.INTENT_SECTION))) {
|
||||||
String section = getIntent().getStringExtra(MagiskManager.INTENT_SECTION);
|
ComponentName service = new ComponentName(magiskManager, UpdateCheckService.class);
|
||||||
Intent intent = new Intent(magiskManager, MainActivity.class);
|
JobInfo jobInfo = new JobInfo.Builder(UPDATE_SERVICE_ID, service)
|
||||||
if (section != null) {
|
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
|
||||||
intent.putExtra(MagiskManager.INTENT_SECTION, section);
|
.setPersisted(true)
|
||||||
}
|
.setPeriodic(12 * 60 * 60 * 1000)
|
||||||
startActivity(intent);
|
.build();
|
||||||
finish();
|
JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||||
|
scheduler.schedule(jobInfo);
|
||||||
}
|
}
|
||||||
}.exec();
|
}
|
||||||
|
|
||||||
|
Intent intent = new Intent(magiskManager, MainActivity.class);
|
||||||
|
String section = getIntent().getStringExtra(MagiskManager.INTENT_SECTION);
|
||||||
|
if (section != null) {
|
||||||
|
intent.putExtra(MagiskManager.INTENT_SECTION, section);
|
||||||
|
}
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ import android.content.IntentFilter;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
@ -186,4 +188,18 @@ public class Utils {
|
|||||||
Snackbar.LENGTH_LONG)
|
Snackbar.LENGTH_LONG)
|
||||||
.setAction(R.string.ok, (v)->{}).show();
|
.setAction(R.string.ok, (v)->{}).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean checkNetworkStatus(Context context) {
|
||||||
|
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
|
||||||
|
return networkInfo != null && networkInfo.isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkBits(int bits, int... masks) {
|
||||||
|
for (int mask : masks) {
|
||||||
|
if ((bits & mask) == 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@ -21,6 +21,7 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<android.support.v7.widget.CardView
|
<android.support.v7.widget.CardView
|
||||||
|
android:id="@+id/magisk_update_card"
|
||||||
style="?attr/cardStyle"
|
style="?attr/cardStyle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -46,7 +47,7 @@
|
|||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/magisk_check_updates_progress"
|
android:id="@+id/magisk_update_progress"
|
||||||
android:layout_width="25dp"
|
android:layout_width="25dp"
|
||||||
android:layout_height="25dp"
|
android:layout_height="25dp"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
@ -149,6 +150,7 @@
|
|||||||
</android.support.v7.widget.CardView>
|
</android.support.v7.widget.CardView>
|
||||||
|
|
||||||
<android.support.v7.widget.CardView
|
<android.support.v7.widget.CardView
|
||||||
|
android:id="@+id/safetyNet_card"
|
||||||
style="?attr/cardStyle"
|
style="?attr/cardStyle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -7,7 +7,7 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.3.2'
|
classpath 'com.android.tools.build:gradle:2.3.2'
|
||||||
classpath 'me.tatarka:gradle-retrolambda:3.6.0'
|
classpath 'me.tatarka:gradle-retrolambda:3.6.1'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
Loading…
Reference in New Issue
Block a user