mirror of
https://github.com/topjohnwu/Magisk.git
synced 2026-01-11 20:45:56 -08:00
Merge remote-tracking branch 'refs/remotes/origin/digitalhigh_autodownload' into digitalhigh_automount
Yeeeeaaaaaaaaaahhhhhhhhhh baby!
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.NavigationView;
|
||||
@@ -25,6 +23,7 @@ import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.topjohnwu.magisk.module.RepoHelper;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import butterknife.BindView;
|
||||
@@ -33,15 +32,13 @@ import butterknife.ButterKnife;
|
||||
public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
|
||||
private Context mContext;
|
||||
|
||||
private final Handler mDrawerHandler = new Handler();
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@BindView(R.id.drawer_layout)
|
||||
DrawerLayout drawer;
|
||||
@BindView(R.id.nav_view)
|
||||
NavigationView navigationView;
|
||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||
@BindView(R.id.drawer_layout) DrawerLayout drawer;
|
||||
@BindView(R.id.nav_view) NavigationView navigationView;
|
||||
|
||||
@IdRes
|
||||
private int mSelectedId = R.id.magisk;
|
||||
@@ -51,28 +48,34 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_welcome);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
}
|
||||
|
||||
|
||||
// Startups
|
||||
PreferenceManager.setDefaultValues(this, R.xml.defaultpref, false);
|
||||
if (!isMyServiceRunning(MonitorService.class)) {
|
||||
Intent myIntent = new Intent(getApplication(), MonitorService.class);
|
||||
getApplication().startService(myIntent);
|
||||
}
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
|
||||
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
||||
}
|
||||
if (!hasPermission()) {
|
||||
startActivityForResult(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS), 100);
|
||||
}
|
||||
|
||||
new Utils.Initialize(this).execute();
|
||||
new Utils.CheckUpdates(this).execute();
|
||||
new Utils.LoadModules(this).execute();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
RepoHelper.TaskDelegate delegate = result -> {
|
||||
//Do a thing here when we get a result we want
|
||||
};
|
||||
if (!prefs.contains("oauth_key")) {
|
||||
|
||||
}
|
||||
if (!prefs.contains("hasCachedRepos")) {
|
||||
new Utils.LoadModules(this, true).execute();
|
||||
new Utils.LoadRepos(this, true,delegate).execute();
|
||||
|
||||
} else {
|
||||
new Utils.LoadModules(getApplication(),false).execute();
|
||||
new Utils.LoadRepos(this, false,delegate).execute();
|
||||
|
||||
}
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
@@ -102,12 +105,10 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
}
|
||||
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
if (getIntent().hasExtra("relaunch")) {
|
||||
navigate(R.id.root);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
@@ -134,25 +135,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasPermission() {
|
||||
AppOpsManager appOps = (AppOpsManager)
|
||||
getSystemService(Context.APP_OPS_SERVICE);
|
||||
int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
|
||||
android.os.Process.myUid(), getPackageName());
|
||||
return mode == AppOpsManager.MODE_ALLOWED;
|
||||
|
||||
}
|
||||
|
||||
private boolean isMyServiceRunning(Class<?> serviceClass) {
|
||||
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (serviceClass.getName().equals(service.service.getClassName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void navigate(final int itemId) {
|
||||
Fragment navFragment = null;
|
||||
String tag = "";
|
||||
@@ -167,16 +149,16 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
tag = "root";
|
||||
navFragment = new RootFragment();
|
||||
break;
|
||||
case R.id.autoroot:
|
||||
setTitle(R.string.auto_root);
|
||||
tag = "ic_autoroot";
|
||||
navFragment = new AutoRootFragment();
|
||||
break;
|
||||
case R.id.modules:
|
||||
setTitle(R.string.modules);
|
||||
tag = "modules";
|
||||
navFragment = new ModulesFragment();
|
||||
break;
|
||||
case R.id.downloads:
|
||||
setTitle(R.string.downloads);
|
||||
tag = "downloads";
|
||||
navFragment = new ReposFragment();
|
||||
break;
|
||||
case R.id.log:
|
||||
setTitle(R.string.log);
|
||||
tag = "log";
|
||||
@@ -198,6 +180,4 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user