Commit fec12458 authored by d8ahazard's avatar d8ahazard

Moar merging, updates, fun

Because it's a big old mess...
parents ccab6eb7 c9f6e2e2
This diff is collapsed.
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.content.Intent; import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v7.widget.RecyclerView;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ProgressBar; import android.widget.CheckBox;
import android.widget.Toast; import android.widget.TextView;
import com.ipaulpro.afilechooser.FileInfo;
import com.ipaulpro.afilechooser.utils.FileUtils;
import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class ModulesFragment extends Fragment { public class ModulesFragment extends Fragment {
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.recyclerView) RecyclerView recyclerView;
@BindView(R.id.empty_rv) TextView emptyTv;
private static final int FETCH_ZIP_CODE = 2; private SharedPreferences prefs;
public static List<Module> listModules = new ArrayList<>(); public static List<Module> listModules = new ArrayList<>();
public static List<Module> listModulesCache = new ArrayList<>();
@BindView(R.id.progressBar)
ProgressBar progressBar;
@BindView(R.id.fab)
FloatingActionButton fabio;
@BindView(R.id.pager)
ViewPager viewPager;
@BindView(R.id.tab_layout)
TabLayout tabLayout;
private int viewPagePosition;
private RepoHelper.TaskDelegate mTaskDelegate;
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.modules_fragment, container, false); View viewMain = inflater.inflate(R.layout.modules_fragment, container, false);
ButterKnife.bind(this, view);
fabio.setOnClickListener(v -> {
Intent getContentIntent = FileUtils.createGetContentIntent(null);
getContentIntent.setType("application/zip");
Intent fileIntent = Intent.createChooser(getContentIntent, "Select a file");
startActivityForResult(fileIntent, FETCH_ZIP_CODE); ButterKnife.bind(this, viewMain);
}); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
mSwipeRefreshLayout.setOnRefreshListener(() -> {
recyclerView.setVisibility(View.GONE);
new Utils.LoadModules(getActivity()).execute(); new Utils.LoadModules(getActivity()).execute();
mTaskDelegate = result -> {
if (result.equals("OK")) {
RefreshUI();
}
};
new updateUI().execute(); new updateUI().execute();
return view; prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
// Get the URI of the selected file
final Uri uri = data.getData();
Log.i("Magisk", "ModulesFragment: Uri = " + uri.toString() + " or ");
new Utils.FlashZIP(getActivity(), uri).execute();
try {
// Get the file path from the URI
FileInfo fileInfo = FileUtils.getFileInfo(getActivity(), uri);
Toast.makeText(getActivity(),
"File Selected: " + fileInfo.getDisplayName() + " size: " + fileInfo.getSize(), Toast.LENGTH_LONG).show();
if (!fileInfo.isExternal()) {
} else {
}
} catch (Exception e) {
Log.e("FileSelectorTestAc...", "File select error", e);
}
}
} });
@Override prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, s) -> {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (s.contains("updated")) {
super.onCreateOptionsMenu(menu, inflater); viewMain.invalidate();
inflater.inflate(R.menu.menu_module, menu); viewMain.requestLayout();
} }
});
private void RefreshUI() {
viewPagePosition = tabLayout.getSelectedTabPosition();
listModules.clear();
listModulesCache.clear();
progressBar.setVisibility(View.VISIBLE);
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
tabLayout.setupWithViewPager(viewPager);
viewPager.setCurrentItem(viewPagePosition);
new Utils.LoadModules(getActivity()).execute();
Collections.sort(listModules, new CustomComparator());
Collections.sort(listModulesCache, new CustomComparator());
new updateUI().execute(); new updateUI().execute();
}
void selectPage(int pageIndex) {
tabLayout.setScrollPosition(pageIndex, 0f, true);
viewPager.setCurrentItem(pageIndex);
}
public static class NormalModuleFragment extends BaseModuleFragment {
@Override
protected List<Module> listModules() {
return listModules;
}
}
public static class CacheModuleFragment extends BaseModuleFragment {
@Override
protected List<Module> listModules() {
return listModulesCache;
}
return viewMain;
} }
private class updateUI extends AsyncTask<Void, Void, Void> { private class updateUI extends AsyncTask<Void, Void, Void> {
...@@ -156,52 +73,37 @@ public class ModulesFragment extends Fragment { ...@@ -156,52 +73,37 @@ public class ModulesFragment extends Fragment {
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
super.onPostExecute(v); super.onPostExecute(v);
progressBar.setVisibility(View.GONE);
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
tabLayout.setupWithViewPager(viewPager);
selectPage(viewPagePosition);
}
}
private class TabsAdapter extends FragmentPagerAdapter {
String[] tabTitles = new String[]{
getString(R.string.modules), getString(R.string.cache_modules)
};
public TabsAdapter(FragmentManager fm) { if (listModules.size() == 0) {
super(fm); emptyTv.setVisibility(View.VISIBLE);
} recyclerView.setVisibility(View.GONE);
} else {
@Override recyclerView.setVisibility(View.VISIBLE);
public int getCount() {
return tabTitles.length;
}
@Override
public String getPageTitle(int position) {
return tabTitles[position];
} }
recyclerView.setAdapter(new ModulesAdapter(listModules, (chk, position) -> {
// On Checkbox change listener
CheckBox chbox = (CheckBox) chk;
@Override if (!chbox.isChecked()) {
public Fragment getItem(int position) { listModules.get(position).createDisableFile();
if (position == 0) { Snackbar.make(chk, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show();
NormalModuleFragment nmf = new NormalModuleFragment();
nmf.SetDelegate(mTaskDelegate);
return nmf;
} else { } else {
CacheModuleFragment cmf = new CacheModuleFragment(); listModules.get(position).removeDisableFile();
cmf.SetDelegate(mTaskDelegate); Snackbar.make(chk, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show();
return cmf; }
} }, (deleteBtn, position) -> {
} // On delete button click listener
} listModules.get(position).createRemoveFile();
Snackbar.make(deleteBtn, R.string.remove_file_created, Snackbar.LENGTH_SHORT).show();
}, (undeleteBtn, position) -> {
// On undelete button click listener
listModules.get(position).deleteRemoveFile();
Snackbar.make(undeleteBtn, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show();
}));
if (mSwipeRefreshLayout.isRefreshing())
mSwipeRefreshLayout.setRefreshing(false);
public class CustomComparator implements Comparator<Module> {
@Override
public int compare(Module o1, Module o2) {
return o1.getName().compareTo(o2.getName());
} }
} }
......
...@@ -8,6 +8,8 @@ import android.app.usage.UsageStatsManager; ...@@ -8,6 +8,8 @@ import android.app.usage.UsageStatsManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
...@@ -34,6 +36,7 @@ public class MonitorService extends Service ...@@ -34,6 +36,7 @@ public class MonitorService extends Service
private Boolean disableroot; private Boolean disableroot;
private Boolean disablerootprev; private Boolean disablerootprev;
private int counter = 0; private int counter = 0;
private String mPackageName;
@Nullable @Nullable
@Override @Override
...@@ -49,6 +52,18 @@ public class MonitorService extends Service ...@@ -49,6 +52,18 @@ public class MonitorService extends Service
} }
@Override
public void onCreate() {
super.onCreate();
Log.d("Magisk","MonitorService: Service created");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d("Magisk","MonitorService: Service destroyed");
}
private Runnable checkProcesses = new Runnable() { private Runnable checkProcesses = new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -86,50 +101,19 @@ public class MonitorService extends Service ...@@ -86,50 +101,19 @@ public class MonitorService extends Service
private void ForceDisableRoot() { private void ForceDisableRoot() {
Log.d("Magisk", "MonitorService: Forcedisable called."); Log.d("Magisk", "MonitorService: Forcedisable called.");
Shell.su("setprop magisk.root 0"); Utils.toggleRoot(false);
if (Utils.rootEnabled()) {
if (Utils.rootStatus()) { Utils.toggleRoot(false);
Shell.su(("setprop magisk.root 0"));
Log.d(TAG, "MonitorService: FORCING.");
} else if (Utils.rootStatus()) {
Shell.su(("setprop magisk.root 0"));
Log.d(TAG, "MonitorService: FORCING.");
} else if (Utils.rootStatus()) {
Shell.su(("setprop magisk.root 0"));
Log.d(TAG, "MonitorService: FORCING.");
} else if (Utils.rootStatus()) {
Shell.su(("setprop magisk.root 0"));
Log.d(TAG, "MonitorService: FORCING.");
} else if (Utils.rootStatus()) {
Shell.su(("setprop magisk.root 0"));
Log.d(TAG, "MonitorService: FORCING.");
} else if (Utils.rootStatus()) {
Shell.su(("setprop magisk.root 0"));
Log.d(TAG, "MonitorService: FORCING."); Log.d(TAG, "MonitorService: FORCING.");
} }
Log.d("Magisk", "MonitorService: Forcedisable called. " + Utils.rootStatus()); Log.d("Magisk", "MonitorService: Forcedisable called. " + Utils.rootEnabled());
} }
private void ForceEnableRoot() { private void ForceEnableRoot() {
Log.d("Magisk", "MonitorService: ForceEnable called."); Log.d("Magisk", "MonitorService: ForceEnable called.");
if (!Utils.rootStatus()) { Utils.toggleRoot(true);
Shell.su(("setprop magisk.root 1")); if (!Utils.rootEnabled()) {
Log.d(TAG, "MonitorService: FORCING."); Utils.toggleRoot(true);
} else if (!Utils.rootStatus()) {
Shell.su(("setprop magisk.root 1"));
Log.d(TAG, "MonitorService: FORCING.");
} else if (!Utils.rootStatus()) {
Shell.su(("setprop magisk.root 1"));
Log.d(TAG, "MonitorService: FORCING.");
} else if (!Utils.rootStatus()) {
Shell.su(("setprop magisk.root 1"));
Log.d(TAG, "MonitorService: FORCING.");
} else if (!Utils.rootStatus()) {
Shell.su(("setprop magisk.root 1"));
Log.d(TAG, "MonitorService: FORCING.");
} else if (!Utils.rootStatus()) {
Shell.su(("setprop magisk.root 1"));
Log.d(TAG, "MonitorService: FORCING.");
} }
} }
...@@ -141,18 +125,23 @@ public class MonitorService extends Service ...@@ -141,18 +125,23 @@ public class MonitorService extends Service
Intent intent = new Intent(getApplication(), WelcomeActivity.class); Intent intent = new Intent(getApplication(), WelcomeActivity.class);
intent.putExtra("relaunch", "relaunch"); intent.putExtra("relaunch", "relaunch");
String rootMessage;
PendingIntent pendingIntent = PendingIntent.getActivity( PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(), getApplicationContext(),
0, 0,
intent, intent,
PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent.FLAG_UPDATE_CURRENT);
if (mPackageName.equals("")) {
rootMessage = "Root has been disabled";
} else {
rootMessage = "Root has been disabled for " + mPackageName;
}
mBuilder = mBuilder =
new NotificationCompat.Builder(getApplicationContext()) new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on) .setSmallIcon(disableroot ? R.drawable.ic_stat_notification_autoroot_off : R.drawable.ic_stat_notification_autoroot_on)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setContentTitle("Auto-root status changed") .setContentTitle("Auto-root status changed")
.setContentText("Root has been disabled."); .setContentText(rootMessage);
int mNotificationId = 1; int mNotificationId = 1;
mNotifyMgr.notify(mNotificationId, mBuilder.build()); mNotifyMgr.notify(mNotificationId, mBuilder.build());
} else { } else {
...@@ -178,6 +167,20 @@ public class MonitorService extends Service ...@@ -178,6 +167,20 @@ public class MonitorService extends Service
return false; return false;
} }
private String getAppName (String packageName) {
PackageManager pkManager = getPackageManager();
ApplicationInfo appInfo;
String appname = "";
try {
appInfo = pkManager.getApplicationInfo(packageName, 0);
appname = (String) ((appInfo != null) ? pkManager.getApplicationLabel(appInfo) : "???");
return appname;
} catch (final PackageManager.NameNotFoundException e) {
return null;
}
}
protected boolean isAppForeground(String packageName) { protected boolean isAppForeground(String packageName) {
UsageStatsManager usageStatsManager = (UsageStatsManager) getSystemService(Context.USAGE_STATS_SERVICE); UsageStatsManager usageStatsManager = (UsageStatsManager) getSystemService(Context.USAGE_STATS_SERVICE);
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
...@@ -195,8 +198,9 @@ public class MonitorService extends Service ...@@ -195,8 +198,9 @@ public class MonitorService extends Service
if (topPackageName.equals("com.topjohnwu.magisk")) { if (topPackageName.equals("com.topjohnwu.magisk")) {
mySortedMap.remove(mySortedMap.lastKey()); mySortedMap.remove(mySortedMap.lastKey());
topPackageName = mySortedMap.get(mySortedMap.lastKey()).getPackageName(); topPackageName = mySortedMap.get(mySortedMap.lastKey()).getPackageName();
mPackageName = getAppName(topPackageName);
} }
//Log.d("Magisk", "MonitorService: Hi Captain, the package we need to kill for is " + topPackageName);
} }
} }
......
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
...@@ -50,7 +48,7 @@ public class ReposFragment extends Fragment { ...@@ -50,7 +48,7 @@ public class ReposFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.single_repo_fragment, container, false); View view = inflater.inflate(R.layout.repos_fragment, container, false);
mView = view; mView = view;
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
...@@ -114,8 +112,7 @@ public class ReposFragment extends Fragment { ...@@ -114,8 +112,7 @@ public class ReposFragment extends Fragment {
}; };
Log.d("Magisk","ReposFragment, LoadRepo called"); Log.d("Magisk","ReposFragment, LoadRepo called");
mListRepos.clear(); mListRepos.clear();
RepoHelper mr = new RepoHelper(); List<Repo> magiskRepos = RepoHelper.listRepos(getActivity(), doReload, taskDelegate);
List<Repo> magiskRepos = mr.listRepos(getActivity(), doReload, taskDelegate);
for (Repo repo : magiskRepos) { for (Repo repo : magiskRepos) {
Log.d("Magisk", "ReposFragment: Adding repo from string " + repo.getId()); Log.d("Magisk", "ReposFragment: Adding repo from string " + repo.getId());
......
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
...@@ -8,8 +9,10 @@ import android.os.AsyncTask; ...@@ -8,8 +9,10 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -18,6 +21,7 @@ import android.widget.ImageView; ...@@ -18,6 +21,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
...@@ -90,6 +94,8 @@ public class RootFragment extends Fragment { ...@@ -90,6 +94,8 @@ public class RootFragment extends Fragment {
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (prefs.contains("autoRootEnable")) { if (prefs.contains("autoRootEnable")) {
autoRootStatus = prefs.getBoolean("autoRootEnable",false); autoRootStatus = prefs.getBoolean("autoRootEnable",false);
rootToggle.setEnabled(false); rootToggle.setEnabled(false);
...@@ -119,7 +125,35 @@ public class RootFragment extends Fragment { ...@@ -119,7 +125,35 @@ public class RootFragment extends Fragment {
return view; return view;
} }
private void CheckAccessPermissions() {
if (!Utils.hasStatsPermission(getActivity())) {
Toast.makeText(getActivity(),"Please allow Usage Access for auto root to work.",Toast.LENGTH_LONG).show();
startActivityForResult(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS), 100);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == 100) {
// Make sure the request was successful
if (resultCode == Activity.RESULT_OK) {
Log.d("Magisk","Got result code OK for permissions");
Toast.makeText(getActivity(),"Auto-root disabled, permissions required.",Toast.LENGTH_LONG).show();
} else {
autoRootToggle.setEnabled(false);
}
}
}
private void ToggleAutoRoot(boolean toggleState) { private void ToggleAutoRoot(boolean toggleState) {
CheckAccessPermissions();
if (Utils.hasStatsPermission(getActivity())) {
autoRootStatus = toggleState; autoRootStatus = toggleState;
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("autoRootEnable", (toggleState)); editor.putBoolean("autoRootEnable", (toggleState));
...@@ -137,6 +171,7 @@ public class RootFragment extends Fragment { ...@@ -137,6 +171,7 @@ public class RootFragment extends Fragment {
rootToggle.setEnabled(true); rootToggle.setEnabled(true);
} }
} }
}
@Override @Override
public void onResume() { public void onResume() {
...@@ -233,25 +268,25 @@ public class RootFragment extends Fragment { ...@@ -233,25 +268,25 @@ public class RootFragment extends Fragment {
break; break;
} else { } else {
rootToggle.setEnabled(true); rootToggle.setEnabled(true);
if (new File("/magisk/.core/bin/su").exists()) { if (Utils.rootEnabled()) {
// Mounted // Mounted
rootStatusContainer.setBackgroundColor(accent); rootStatusContainer.setBackgroundColor(accent);
rootStatusIcon.setImageResource(statusError); rootStatusIcon.setImageResource(statusError);
rootStatus.setTextColor(accent); rootStatus.setTextColor(accent);
rootStatus.setText(R.string.root_mounted); rootStatus.setText(R.string.root_enabled);
rootToggle.setChecked(true); rootToggle.setChecked(true);
safetyNetStatusIcon.setImageResource(statusError); safetyNetStatusIcon.setImageResource(statusError);
safetyNetStatus.setText(R.string.root_mounted_info); safetyNetStatus.setText(R.string.root_enabled_info);
break; break;
} else { } else {
// Not Mounted // Disabled
rootStatusContainer.setBackgroundColor(green500); rootStatusContainer.setBackgroundColor(green500);
rootStatusIcon.setImageResource(statusOK); rootStatusIcon.setImageResource(statusOK);
rootStatus.setTextColor(green500); rootStatus.setTextColor(green500);
rootStatus.setText(R.string.root_unmounted); rootStatus.setText(R.string.root_disabled);
rootToggle.setChecked(false); rootToggle.setChecked(false);
safetyNetStatusIcon.setImageResource(statusOK); safetyNetStatusIcon.setImageResource(statusOK);
safetyNetStatus.setText(R.string.root_unmounted_info); safetyNetStatus.setText(R.string.root_disabled_info);
break; break;
} }
} }
......
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.Manifest; import android.Manifest;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
...@@ -53,10 +52,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView ...@@ -53,10 +52,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
setContentView(R.layout.activity_welcome); setContentView(R.layout.activity_welcome);
ButterKnife.bind(this); ButterKnife.bind(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
// Startups // Startups
PreferenceManager.setDefaultValues(this, R.xml.defaultpref, false); PreferenceManager.setDefaultValues(this, R.xml.defaultpref, false);
if (!Utils.isMyServiceRunning(MonitorService.class, getApplicationContext())) { if (!Utils.isMyServiceRunning(MonitorService.class, getApplicationContext())) {
...@@ -67,9 +62,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView ...@@ -67,9 +62,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); 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.Initialize(this).execute();
new Utils.CheckUpdates(this).execute(); new Utils.CheckUpdates(this).execute();
...@@ -77,16 +70,12 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView ...@@ -77,16 +70,12 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
RepoHelper.TaskDelegate delegate = result -> { RepoHelper.TaskDelegate delegate = result -> {
//Do a thing here when we get a result we want //Do a thing here when we get a result we want
}; };
if (!prefs.contains("hasCachedRepos")) { new Utils.LoadModules(this).execute();
new Utils.LoadModules(this, true).execute();
new Utils.LoadRepos(this, true, delegate).execute(); new Utils.LoadRepos(this, true, delegate).execute();
new Utils.LoadRepos(this, !prefs.contains("hasCachedRepos"), delegate).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else { new Utils.LoadModules(getApplication()).execute();
new Utils.LoadModules(getApplication(), false).execute();
new Utils.LoadRepos(this, false, delegate).execute(); new Utils.LoadRepos(this, false, delegate).execute();
}
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
...@@ -146,14 +135,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView ...@@ -146,14 +135,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
return true; 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 void navigate(final int itemId) { private void navigate(final int itemId) {
Fragment navFragment = null; Fragment navFragment = null;
......
package com.topjohnwu.magisk.module;
import android.util.Log;
import java.util.List;
public abstract class BaseModule {
protected String mId, mName, mVersion, mDescription, mSupportUrl, mDonateUrl, mAuthor;
protected boolean mIsCacheModule = false;
protected int mVersionCode = 0;
public BaseModule(List<String> props) {
this(props.toArray(new String[props.size()]));
}
public BaseModule(String[] props) {
for (String line : props) {
String[] prop = line.split("=", 2);
if (prop.length != 2) {
continue;
}
String key = prop[0].trim();
if (key.charAt(0) == '#') {
continue;
}
switch (key) {
case "id":
this.mId = prop[1];
break;
case "name":
this.mName = prop[1];
break;
case "version":
this.mVersion = prop[1];
break;
case "versionCode":
this.mVersionCode = Integer.parseInt(prop[1]);
break;
case "author":
this.mAuthor = prop[1];
break;
case "description":
this.mDescription = prop[1];
break;
case "support":
this.mSupportUrl = prop[1];
break;
case "donate":
this.mDonateUrl = prop[1];
break;
case "cacheModule":
this.mIsCacheModule = Boolean.parseBoolean(prop[1]);
break;
default:
Log.d("Magisk", "Module: Manifest string not recognized: " + prop[0]);
break;
}
}
}
public String getName() {
return mName;
}
public String getVersion() {
return mVersion;
}
public String getAuthor() {
return mAuthor;
}
public String getId() {return mId; }
public String getDescription() {
return mDescription;
}
public boolean isCache() {
return mIsCacheModule;
}
public void setCache() {
mIsCacheModule = true;
}
public int getVersionCode() {
return mVersionCode;
}
public String getmDonateUrl() {
return mDonateUrl;
}
public String getmSupportUrl() {
return mSupportUrl;
}
}
...@@ -5,89 +5,39 @@ import android.content.SharedPreferences; ...@@ -5,89 +5,39 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
public class Module { public class Module extends BaseModule {
private String mRemoveFile; private String mRemoveFile;
private String mDisableFile; private String mDisableFile;
private String mName = null; private String mZipUrl, mLogUrl;
private String mVersion = "(No version provided)"; private boolean mEnable, mRemove, mUpdateAvailable = false, mIsInstalled;
private String mDescription = "(No description provided)";
private String mUrl,mSupportUrl,mDonateUrl,mZipUrl,mBaseUrl,mManifestUrl,mAuthor,mLogUrl;
private boolean mEnable, mRemove,mUpdateAvailable, mIsInstalled,mIsCacheModule;
private String mId;
private int mVersionCode;
public Module(String path, Context context) { public Module(String path, Context context) {
super(Utils.readFile(path + "/module.prop"));
mRemoveFile = path + "/remove"; mRemoveFile = path + "/remove";
mDisableFile = path + "/disable"; mDisableFile = path + "/disable";
for (String line : Utils.readFile(path + "/module.prop")) {
String[] props = line.split("=", 2);
if (props.length != 2) {
continue;
}
String key = props[0].trim(); if (mId == null) {
if (key.charAt(0) == '#') { int sep = path.lastIndexOf('/');
continue; mId = path.substring(sep + 1);
} }
switch (props[0]) { if (mName == null)
case "versionCode": mName = mId;
this.mVersionCode = Integer.valueOf(props[1]);
break; if (mDescription == null)
case "name": mDescription = context.getString(R.string.no_info_provided);
this.mName = props[1];
break; if (mVersion == null)
case "author": mVersion = context.getString(R.string.no_info_provided);
this.mAuthor = props[1];
break; Log.d("Magisk","Module: Loaded module with ID of " + mId );
case "id":
this.mId = props[1];
break;
case "version":
this.mVersion = props[1];
break;
case "description":
this.mDescription = props[1];
break;
case "donate":
this.mDonateUrl = props[1];
break;
case "cacheModule":
this.mIsCacheModule = Boolean.valueOf(props[1]);
break;
case "support":
this.mSupportUrl = props[1];
break;
case "donateUrl":
this.mDonateUrl = props[1];
break;
case "zipUrl":
this.mZipUrl = props[1];
break;
case "baseUrl":
this.mBaseUrl = props[1];
break;
case "manifestUrl":
this.mManifestUrl = props[1];
break;
case "logUrl":
this.mLogUrl = props[1];
break;
default:
Log.d("Magisk", "Module: Manifest string not recognized: " + props[0]);
break;
}
}
Log.d("Magisk","Module: Loaded module with ID of " + this.mId + " or " + mId);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
...@@ -154,52 +104,13 @@ public class Module { ...@@ -154,52 +104,13 @@ public class Module {
editor.apply(); editor.apply();
} }
if (mName == null) {
int sep = path.lastIndexOf('/');
mName = path.substring(sep + 1);
mId = mName;
}
mEnable = !Utils.fileExist(mDisableFile); mEnable = !Utils.fileExist(mDisableFile);
mRemove = Utils.fileExist(mRemoveFile); mRemove = Utils.fileExist(mRemoveFile);
} }
public Module(Repo repo) {
mName = repo.getName();
mVersion = repo.getmVersion();
mDescription = repo.getDescription();
mId = repo.getId();
mVersionCode = repo.getmVersionCode();
mUrl = repo.getmZipUrl();
mEnable = true;
mRemove = false;
}
public String getName() {
return mName;
}
public String getVersion() {
return mVersion;
}
public String getAuthor() {
return mAuthor;
}
public String getId() {return mId; }
public String getmLogUrl() {return mLogUrl; } public String getmLogUrl() {return mLogUrl; }
public String getDescription() {
return mDescription;
}
public void createDisableFile() { public void createDisableFile() {
mEnable = !Utils.createFile(mDisableFile); mEnable = !Utils.createFile(mDisableFile);
} }
...@@ -224,22 +135,8 @@ public class Module { ...@@ -224,22 +135,8 @@ public class Module {
return mRemove; return mRemove;
} }
public String getmDonateUrl() {
return mDonateUrl;
}
public String getmZipUrl() { return mZipUrl; } public String getmZipUrl() { return mZipUrl; }
public String getmManifestUrl() {
return mManifestUrl;
}
public String getmSupportUrl() {
return mSupportUrl;
}
public boolean isInstalled() {return mIsInstalled; }
public boolean isUpdateAvailable() { return mUpdateAvailable; } public boolean isUpdateAvailable() { return mUpdateAvailable; }
} }
\ No newline at end of file
...@@ -64,9 +64,8 @@ public class Repo { ...@@ -64,9 +64,8 @@ public class Repo {
public void fetch() { public void fetch() {
WebRequest webreq = new WebRequest();
// Construct initial url for contents // Construct initial url for contents
String repoString = webreq.makeWebServiceCall(mBaseUrl + "/contents?access_token=" + Utils.procFile(appContext.getString(R.string.some_string),appContext), WebRequest.GET); String repoString = WebRequest.makeWebServiceCall(mBaseUrl + "/contents?access_token=" + Utils.procFile(appContext.getString(R.string.some_string), appContext), WebRequest.GET);
try { try {
JSONArray repoArray = new JSONArray(repoString); JSONArray repoArray = new JSONArray(repoString);
for (int f = 0; f < repoArray.length(); f++) { for (int f = 0; f < repoArray.length(); f++) {
...@@ -89,8 +88,7 @@ public class Repo { ...@@ -89,8 +88,7 @@ public class Repo {
e.printStackTrace(); e.printStackTrace();
} }
WebRequest propReq = new WebRequest(); String manifestString = WebRequest.makeWebServiceCall(mManifestUrl, WebRequest.GET, true);
String manifestString = propReq.makeWebServiceCall(mManifestUrl,WebRequest.GET,true);
if (ParseProps(manifestString)) { if (ParseProps(manifestString)) {
PutProps(manifestString); PutProps(manifestString);
......
...@@ -29,35 +29,32 @@ import java.util.Map; ...@@ -29,35 +29,32 @@ import java.util.Map;
public class RepoHelper { public class RepoHelper {
private static List<Repo> repos = new ArrayList<>(); private static List<Repo> repos = new ArrayList<>();
private static String TAG = "Magisk"; private static String TAG = "Magisk";
private Context activityContext;
private Date updatedDate;
private SharedPreferences prefs;
private boolean apiFail;
public RepoHelper() { public RepoHelper() {
} }
public List<Repo> listRepos(Context context, boolean refresh, TaskDelegate delegate) { public static List<Repo> listRepos(Context context, boolean refresh, TaskDelegate delegate) {
prefs = PreferenceManager.getDefaultSharedPreferences(context);
activityContext = context; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (!prefs.contains("hasCachedRepos") | refresh) { if (!prefs.contains("hasCachedRepos") | refresh) {
Log.d(TAG, "RepoHelper: Building from web"); Log.d(TAG, "RepoHelper: Building from web");
new BuildFromWeb(delegate).execute(); new BuildFromWeb(delegate, context).execute();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
String date = format.format(Calendar.getInstance().getTime()); String date = format.format(Calendar.getInstance().getTime());
prefs.edit().putString("last_update", date).apply(); prefs.edit().putString("last_update", date).apply();
} else { } else {
Log.d(TAG, "RepoHelper: Building from cache"); Log.d(TAG, "RepoHelper: Building from cache");
BuildFromCache(); BuildFromCache(context);
} }
Collections.sort(repos, new CustomComparator()); Collections.sort(repos, new CustomComparator());
return repos; return repos;
} }
private void BuildFromCache() { private static void BuildFromCache(Context activityContext) {
repos.clear(); repos.clear();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activityContext);
Map<String, ?> map = prefs.getAll(); Map<String, ?> map = prefs.getAll();
for (Map.Entry<String, ?> entry : map.entrySet()) { for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getKey().contains("repo_")) { if (entry.getKey().contains("repo_")) {
...@@ -67,12 +64,16 @@ public class RepoHelper { ...@@ -67,12 +64,16 @@ public class RepoHelper {
} }
} }
class BuildFromWeb extends AsyncTask<String, String, Void> { static class BuildFromWeb extends AsyncTask<String, String, Boolean> {
private TaskDelegate delegate; private TaskDelegate delegate;
private SharedPreferences prefs;
private Context activityContext;
public BuildFromWeb(TaskDelegate delegate) { public BuildFromWeb(TaskDelegate delegate, Context activityContext) {
this.delegate = delegate; this.delegate = delegate;
this.activityContext = activityContext;
prefs = PreferenceManager.getDefaultSharedPreferences(activityContext);
} }
@Override @Override
...@@ -90,15 +91,13 @@ public class RepoHelper { ...@@ -90,15 +91,13 @@ public class RepoHelper {
} }
@Override @Override
protected Void doInBackground(String... params) { protected Boolean doInBackground(String... params) {
publishProgress(); publishProgress();
// Creating service handler class instance
WebRequest webreq = new WebRequest();
// Making a request to url and getting response // Making a request to url and getting response
String token = activityContext.getString(R.string.some_string); String token = activityContext.getString(R.string.some_string);
String url1 = activityContext.getString(R.string.url_main); String url1 = activityContext.getString(R.string.url_main);
String jsonStr = webreq.makeWebServiceCall(url1 + Utils.procFile(token, activityContext), WebRequest.GET); String jsonStr = WebRequest.makeWebServiceCall(url1 + Utils.procFile(token, activityContext), WebRequest.GET);
if (jsonStr != null && !jsonStr.isEmpty()) { if (jsonStr != null && !jsonStr.isEmpty()) {
try { try {
...@@ -115,6 +114,7 @@ public class RepoHelper { ...@@ -115,6 +114,7 @@ public class RepoHelper {
boolean doUpdate = true; boolean doUpdate = true;
boolean hasCachedDate = false; boolean hasCachedDate = false;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
Date updatedDate;
Map<String, ?> map = prefs.getAll(); Map<String, ?> map = prefs.getAll();
for (Map.Entry<String, ?> entry : map.entrySet()) { for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getValue().toString().contains(url)) { if (entry.getValue().toString().contains(url)) {
...@@ -147,6 +147,7 @@ public class RepoHelper { ...@@ -147,6 +147,7 @@ public class RepoHelper {
} catch (ParseException e) { } catch (ParseException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
return true;
} }
if (!name.contains("Repo.github.io")) { if (!name.contains("Repo.github.io")) {
if (doUpdate) { if (doUpdate) {
...@@ -164,21 +165,19 @@ public class RepoHelper { ...@@ -164,21 +165,19 @@ public class RepoHelper {
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
apiFail = false; return false;
} else { } else {
apiFail = true; return true;
} }
return null;
} }
protected void onPostExecute(Void v) { protected void onPostExecute(Boolean apiFail) {
if (apiFail) { if (apiFail) {
Toast.makeText(activityContext, "GitHub API Limit reached, please try refreshing again in an hour.", Toast.LENGTH_LONG).show(); Toast.makeText(activityContext, "GitHub API Limit reached, please try refreshing again in an hour.", Toast.LENGTH_LONG).show();
} else { } else {
Log.d("Magisk", "RepoHelper: postExecute fired"); Log.d("Magisk", "RepoHelper: postExecute fired");
delegate.taskCompletionResult("Complete"); delegate.taskCompletionResult("Complete");
BuildFromCache(); BuildFromCache(activityContext);
} }
...@@ -189,7 +188,7 @@ public class RepoHelper { ...@@ -189,7 +188,7 @@ public class RepoHelper {
void taskCompletionResult(String result); void taskCompletionResult(String result);
} }
public class CustomComparator implements Comparator<Repo> { public static class CustomComparator implements Comparator<Repo> {
@Override @Override
public int compare(Repo o1, Repo o2) { public int compare(Repo o1, Repo o2) {
return o1.getName().compareTo(o2.getName()); return o1.getName().compareTo(o2.getName());
......
...@@ -3,6 +3,7 @@ package com.topjohnwu.magisk.utils; ...@@ -3,6 +3,7 @@ package com.topjohnwu.magisk.utils;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
...@@ -170,6 +171,15 @@ public class Utils { ...@@ -170,6 +171,15 @@ public class Utils {
return value; return value;
} }
public static boolean hasStatsPermission(Context context) {
AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
android.os.Process.myUid(), context.getPackageName());
return mode == AppOpsManager.MODE_ALLOWED;
}
public abstract static class DownloadReceiver extends BroadcastReceiver { public abstract static class DownloadReceiver extends BroadcastReceiver {
public Context mContext; public Context mContext;
long downloadID; long downloadID;
...@@ -438,7 +448,7 @@ public class Utils { ...@@ -438,7 +448,7 @@ public class Utils {
try { try {
String rootStatus = Shell.su("getprop magisk.root").toString(); String rootStatus = Shell.su("getprop magisk.root").toString();
String fuckyeah = Shell.sh("which su").toString(); String fuckyeah = Shell.sh("which su").toString();
Log.d("Magisk","Utils: Rootstatus Checked, " + rootStatus + " and " + fuckyeah); Log.d("Magisk", "Utils: Rootstatus Checked, " + rootStatus + " and " + fuckyeah);
if (rootStatus.contains("0") && !fuckyeah.contains("su")) { if (rootStatus.contains("0") && !fuckyeah.contains("su")) {
return false; return false;
} else { } else {
...@@ -448,7 +458,6 @@ public class Utils { ...@@ -448,7 +458,6 @@ public class Utils {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
} }
public static boolean isMyServiceRunning(Class<?> serviceClass, Context context) { public static boolean isMyServiceRunning(Class<?> serviceClass, Context context) {
...@@ -472,7 +481,6 @@ public class Utils { ...@@ -472,7 +481,6 @@ public class Utils {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
ModulesFragment.listModules.clear(); ModulesFragment.listModules.clear();
ModulesFragment.listModulesCache.clear();
List<String> magisk = getModList(MAGISK_PATH); List<String> magisk = getModList(MAGISK_PATH);
Log.d("Magisk", "Utils: Reload called, loading modules"); Log.d("Magisk", "Utils: Reload called, loading modules");
List<String> magiskCache = getModList(MAGISK_CACHE_PATH); List<String> magiskCache = getModList(MAGISK_CACHE_PATH);
...@@ -484,7 +492,10 @@ public class Utils { ...@@ -484,7 +492,10 @@ public class Utils {
for (String mod : magiskCache) { for (String mod : magiskCache) {
Log.d("Magisk", "Utils: Adding cache module from string " + mod); Log.d("Magisk", "Utils: Adding cache module from string " + mod);
ModulesFragment.listModulesCache.add(new Module(mod, mContext)); Module cacheMod = new Module(mod, mContext);
// Prevent people forgot to change module.prop
cacheMod.setCache();
ModulesFragment.listModules.add(cacheMod);
} }
return null; return null;
...@@ -507,8 +518,7 @@ public class Utils { ...@@ -507,8 +518,7 @@ public class Utils {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
ReposFragment.mListRepos.clear(); ReposFragment.mListRepos.clear();
RepoHelper mr = new RepoHelper(); List<Repo> magiskRepos = RepoHelper.listRepos(mContext, doReload, mTaskDelegate);
List<Repo> magiskRepos = mr.listRepos(mContext, doReload, mTaskDelegate);
for (Repo repo : magiskRepos) { for (Repo repo : magiskRepos) {
Log.d("Magisk", "Utils: Adding repo from string " + repo.getId()); Log.d("Magisk", "Utils: Adding repo from string " + repo.getId());
...@@ -545,13 +555,13 @@ public class Utils { ...@@ -545,13 +555,13 @@ public class Utils {
final String docId = DocumentsContract.getDocumentId(mUri); final String docId = DocumentsContract.getDocumentId(mUri);
Log.d("Magisk", "Utils: FlashZip Running, " + docId + " and " + mUri.toString()); Log.d("Magisk", "Utils: FlashZip Running, " + docId + " and " + mUri.toString());
String[] split = docId.split(":"); if (docId.contains(":"))
mName = split[1]; mName = docId.split(":")[1];
if (mName.contains("/")) { else mName = docId;
split = mName.split("/"); if (mName.contains("/"))
} mName = mName.substring(mName.lastIndexOf('/') + 1);
if (split[1].contains(".zip")) { if (mName.contains(".zip")) {
file = mContext.getFilesDir() + "/" + split[1]; file = mContext.getFilesDir() + "/" + mName;
Log.d("Magisk", "Utils: FlashZip running for uRI " + mUri.toString()); Log.d("Magisk", "Utils: FlashZip running for uRI " + mUri.toString());
} else { } else {
Log.e("Magisk", "Utils: error parsing Zipfile " + mUri.getPath()); Log.e("Magisk", "Utils: error parsing Zipfile " + mUri.getPath());
...@@ -615,6 +625,7 @@ public class Utils { ...@@ -615,6 +625,7 @@ public class Utils {
protected Boolean doInBackground(Void... voids) { protected Boolean doInBackground(Void... voids) {
if (mPath != null) { if (mPath != null) {
Log.e("Magisk", "Utils: Error, flashZIP called without a valid zip file to flash."); Log.e("Magisk", "Utils: Error, flashZIP called without a valid zip file to flash.");
progress.dismiss();
this.cancel(true); this.cancel(true);
return false; return false;
} }
...@@ -622,11 +633,11 @@ public class Utils { ...@@ -622,11 +633,11 @@ public class Utils {
return false; return false;
} else { } else {
ret = Shell.su( ret = Shell.su(
"rm -rf /data/tmp", "rm -rf /dev/tmp",
"mkdir -p /data/tmp", "mkdir -p /dev/tmp",
"cp -af " + mPath + " /data/tmp/install.zip", "cp -af " + mPath + " /dev/tmp/install.zip",
"unzip -o /data/tmp/install.zip META-INF/com/google/android/* -d /data/tmp", "unzip -o /dev/tmp/install.zip META-INF/com/google/android/* -d /dev/tmp",
"BOOTMODE=true sh /data/tmp/META-INF/com/google/android/update-binary dummy 1 /data/tmp/install.zip", "BOOTMODE=true sh /dev/tmp/META-INF/com/google/android/update-binary dummy 1 /dev/tmp/install.zip",
"if [ $? -eq 0 ]; then echo true; else echo false; fi" "if [ $? -eq 0 ]; then echo true; else echo false; fi"
); );
return ret != null && Boolean.parseBoolean(ret.get(ret.size() - 1)); return ret != null && Boolean.parseBoolean(ret.get(ret.size() - 1));
...@@ -636,7 +647,6 @@ public class Utils { ...@@ -636,7 +647,6 @@ public class Utils {
@Override @Override
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
super.onPostExecute(result); super.onPostExecute(result);
Shell.su("rm -rf /data/tmp");
if (deleteFileAfter) { if (deleteFileAfter) {
Shell.su("rm -rf " + mPath); Shell.su("rm -rf " + mPath);
Log.d("Magisk", "Utils: Deleting file " + mPath); Log.d("Magisk", "Utils: Deleting file " + mPath);
......
...@@ -20,7 +20,6 @@ public class WebRequest { ...@@ -20,7 +20,6 @@ public class WebRequest {
static String response = null; static String response = null;
public final static int GET = 1; public final static int GET = 1;
public final static int POST = 2; public final static int POST = 2;
private boolean addNewLine;
//Constructor with no parameter //Constructor with no parameter
public WebRequest() { public WebRequest() {
...@@ -33,18 +32,16 @@ public class WebRequest { ...@@ -33,18 +32,16 @@ public class WebRequest {
* @url - url to make request * @url - url to make request
* @requestmethod - http request method * @requestmethod - http request method
*/ */
public String makeWebServiceCall(String url, int requestmethod) { public static String makeWebServiceCall(String url, int requestmethod) {
addNewLine=false;
Log.d("Magisk","WebRequest: Service call received for URL " + url); Log.d("Magisk","WebRequest: Service call received for URL " + url);
return this.makeWebServiceCall(url, requestmethod, null); return makeWebServiceCall(url, requestmethod, null, false);
} }
public String makeWebServiceCall(String url, int requestmethod, boolean addNewLines) { public static String makeWebServiceCall(String url, int requestmethod, boolean addNewLines) {
addNewLine = addNewLines;
Log.d("Magisk","WebRequest: Service call(bool) received for URL " + url); Log.d("Magisk","WebRequest: Service call(bool) received for URL " + url);
return this.makeWebServiceCall(url, requestmethod, null); return makeWebServiceCall(url, requestmethod, null, addNewLines);
} }
...@@ -55,8 +52,8 @@ public class WebRequest { ...@@ -55,8 +52,8 @@ public class WebRequest {
* @requestmethod - http request method * @requestmethod - http request method
* @params - http request params * @params - http request params
*/ */
public String makeWebServiceCall(String urladdress, int requestmethod, public static String makeWebServiceCall(String urladdress, int requestmethod,
HashMap<String, String> params) { HashMap<String, String> params, boolean addNewLines) {
URL url; URL url;
String response = ""; String response = "";
try { try {
...@@ -104,7 +101,7 @@ public class WebRequest { ...@@ -104,7 +101,7 @@ public class WebRequest {
String line; String line;
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
if (addNewLine) { if (addNewLines) {
response += line + "\n"; response += line + "\n";
} else { } else {
response += line; response += line;
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" > android:layout_height="wrap_content"
android:padding="5dp">
<ImageView <ImageView
android:id="@+id/app_icon" android:id="@+id/app_icon"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="50dp" android:layout_height="50dp"
android:padding="3dp" android:padding="3dp"
android:scaleType="centerCrop" /> android:scaleType="centerCrop"/>
<RelativeLayout <RelativeLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
...@@ -28,13 +30,13 @@ ...@@ -28,13 +30,13 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:textStyle="bold" /> android:textStyle="bold"/>
<TextView <TextView
android:id="@+id/app_paackage" android:id="@+id/app_paackage"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" /> android:gravity="center_vertical"/>
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -42,15 +44,16 @@ ...@@ -42,15 +44,16 @@
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/app_status" android:id="@+id/app_status"
android:layout_width="50dp" android:layout_width="30dp"
android:layout_height="50dp" android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_gravity="center_horizontal"
android:padding="3dp" android:padding="3dp"
android:scaleType="centerCrop" android:scaleType="centerCrop"/>
android:layout_gravity="right"
android:layout_alignParentEnd="true" />
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
android:orientation="vertical" > android:orientation="vertical" >
<ListView android:id="@android:id/list" <ListView android:id="@android:id/list"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"/> android:layout_height="fill_parent"/>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content" android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/llayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_marginTop="?attr/actionBarSize" android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical"> android:orientation="vertical">
<android.support.design.widget.TabLayout <android.support.v7.widget.RecyclerView
android:id="@+id/tab_layout" android:id="@+id/recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:background="?attr/colorPrimary" android:clipToPadding="false"
android:elevation="4dp" android:paddingBottom="60dip"
android:minHeight="?attr/actionBarSize" app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
app:tabGravity="fill"
app:tabIndicatorColor="?attr/colorAccent"
app:tabMode="fixed"
app:tabTextAppearance="@style/TextAppearance.Design.Tab" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<android.support.v4.view.ViewPager <TextView
android:id="@+id/pager" android:id="@+id/empty_rv"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:animateLayoutChanges="true" /> android:layout_gravity="center"
android:fontFamily="sans-serif-light"
</LinearLayout>
<LinearLayout
android:id="@+id/ly_bar_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:text="@string/no_modules_found"
<android.support.design.widget.FloatingActionButton android:textSize="20sp"
android:id="@+id/fab" android:textStyle="italic"
android:layout_width="wrap_content" android:visibility="gone"/>
android:layout_height="wrap_content"
android:layout_margin="16dp" </android.support.v4.widget.SwipeRefreshLayout>
android:baselineAlignBottom="false" \ No newline at end of file
android:clickable="true"
android:src="@drawable/ic_add"
app:layout_anchorGravity="bottom|right|end"
/>
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="60dip"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<TextView
android:id="@+id/empty_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="@string/no_modules_found"
android:textSize="20sp"
android:textStyle="italic"
android:visibility="gone"/>
</android.support.v4.widget.SwipeRefreshLayout>
\ No newline at end of file
...@@ -28,13 +28,12 @@ ...@@ -28,13 +28,12 @@
<string name="root_error_info">Safety Net Status Unknown</string> <string name="root_error_info">Safety Net Status Unknown</string>
<string name="root_none">Not Rooted</string> <string name="root_none">Not Rooted</string>
<string name="root_none_info">Safety Net (Android Pay) should work</string> <string name="root_none_info">Safety Net (Android Pay) should work</string>
<string name="root_mounted">Root mounted</string> <string name="root_enabled">Root enabled</string>
<string name="root_mounted_info">Root mounted and enabled. Safety Net (Android Pay) will NOT work.</string> <string name="root_enabled_info">Root enabled. Safety Net (Android Pay) will NOT work</string>
<string name="root_unmounted">Root not mounted</string> <string name="root_disabled">Root disabled</string>
<string name="root_unmounted_info">Safety Net (Android Pay) should work, but no root temporarily\nYou might need to manually add a card in Android Pay app to refresh the root status of AP</string> <string name="root_disabled_info">Safety Net (Android Pay) should work, but no root temporarily\nYou might need to manually add a card in Android Pay app to refresh the root status of AP</string>
<string name="root_auto_unmounted">Root set to auto-mount</string> <string name="root_auto_unmounted">Root set to auto-mount</string>
<string name="root_auto_unmounted_info">Root will auto unmount for selected applications. Safety Net (Android Pay) should work.</string> <string name="root_auto_unmounted_info">Root will auto unmount for selected applications. Safety Net (Android Pay) should work.</string>
<string name="root_system">Magisk Incompatible Root Detected</string> <string name="root_system">Magisk Incompatible Root Detected</string>
<string name="root_system_info">Root improperly installed. Safety Net (Android Pay) will NOT work, and impossible to toggle.</string> <string name="root_system_info">Root improperly installed. Safety Net (Android Pay) will NOT work, and impossible to toggle.</string>
...@@ -44,6 +43,7 @@ ...@@ -44,6 +43,7 @@
<string name="selinux_samsung_info">Samsung need custom kernel for switching SELinux status!</string> <string name="selinux_samsung_info">Samsung need custom kernel for switching SELinux status!</string>
<!--Module Fragment--> <!--Module Fragment-->
<string name="no_info_provided">(No info provided)</string>
<string name="cache_modules">Cache modules</string> <string name="cache_modules">Cache modules</string>
<string name="no_modules_found">No modules found</string> <string name="no_modules_found">No modules found</string>
<string name="module_update_available">An update is available!</string> <string name="module_update_available">An update is available!</string>
...@@ -98,6 +98,7 @@ ...@@ -98,6 +98,7 @@
<string name="phh">phh\'s superuser</string> <string name="phh">phh\'s superuser</string>
<string name="supersu">SuperSU</string> <string name="supersu">SuperSU</string>
<string name="root_system_msg">It seems that you have incompatible root installed\nDo you want to install Magisk compatible root now?</string> <string name="root_system_msg">It seems that you have incompatible root installed\nDo you want to install Magisk compatible root now?</string>
<string name="pass">MagiskRox666</string> <string name="pass">MagiskRox666</string>
<string name="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string> <string name="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string>
<string name="downloads">Downloads</string> <string name="downloads">Downloads</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment