Commit 75a37adc authored by d8ahazard's avatar d8ahazard

Merge remote-tracking branch 'refs/remotes/origin/digitalhigh_autodownload'...

Merge remote-tracking branch 'refs/remotes/origin/digitalhigh_autodownload' into digitalhigh_automount

Yeeeeaaaaaaaaaahhhhhhhhhh baby!
parents c3b1070b 339ca7ac
...@@ -14,6 +14,7 @@ android { ...@@ -14,6 +14,7 @@ android {
enabled true enabled true
} }
} }
buildTypes { buildTypes {
release { release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
...@@ -24,13 +25,17 @@ android { ...@@ -24,13 +25,17 @@ android {
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
} }
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
dependencies { dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:recyclerview-v7:24.2.0' compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0' compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.android.support:design:24.2.0' compile 'com.android.support:design:24.2.0'
compile 'com.jakewharton:butterknife:8.4.0' compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.github.michalis-vitos:aFileChooser:master'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest package="com.topjohnwu.magisk"
xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"
package="com.topjohnwu.magisk"> xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application <application
android:allowBackup="true" android:allowBackup="true"
...@@ -21,35 +16,54 @@ ...@@ -21,35 +16,54 @@
tools:ignore="AllowBackup,GoogleAppIndexingWarning"> tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity <activity
android:name=".WelcomeActivity" android:name=".WelcomeActivity"
android:exported="true"
android:configChanges="orientation|screenSize"> android:configChanges="orientation|screenSize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name="com.ipaulpro.afilechooser.FileChooserActivity"
android:icon="@drawable/ic_chooser"
android:enabled="@bool/use_activity"
android:exported="true"
android:label="@string/choose_file" >
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
<provider
android:name="com.ianhanniballake.localstorage.LocalStorageProvider"
android:authorities="com.topjohnwu.magisk.documents"
android:enabled="@bool/use_provider"
android:exported="true"
android:grantUriPermissions="true"
android:permission="android.permission.MANAGE_DOCUMENTS" >
<intent-filter>
<action android:name="android.content.action.DOCUMENTS_PROVIDER" />
</intent-filter>
</provider>
<activity <activity
android:name=".AboutActivity" android:name=".AboutActivity"
android:theme="@style/AppTheme.Transparent" /> android:theme="@style/AppTheme.Transparent"/>
<provider <provider
android:name="android.support.v4.content.FileProvider" android:name="android.support.v4.content.FileProvider"
android:authorities="com.topjohnwu.magisk.provider" android:authorities="com.topjohnwu.magisk.provider"
android:exported="false" android:grantUriPermissions="true"
android:grantUriPermissions="true"> android:exported="false">
<meta-data <meta-data
android:name="android.support.FILE_PROVIDER_PATHS" android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" /> android:resource="@xml/file_paths" />
</provider> </provider>
<receiver android:name=".AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name=".MonitorService"
android:exported="false" />
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -24,7 +24,7 @@ import java.io.InputStream; ...@@ -24,7 +24,7 @@ import java.io.InputStream;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class AboutActivity extends AppCompatActivity { public class AboutActivity extends AppCompatActivity {
private static final String SOURCE_CODE_URL = "https://github.com/topjohnwu/MagiskManager"; private static final String SOURCE_CODE_URL = "https://github.com/topjohnwu/MagiskManager";
private static final String XDA_THREAD = "http://forum.xda-developers.com/android/software/mod-magisk-v1-universal-systemless-t3432382"; private static final String XDA_THREAD = "http://forum.xda-developers.com/android/software/mod-magisk-v1-universal-systemless-t3432382";
......
...@@ -25,17 +25,13 @@ import android.widget.ScrollView; ...@@ -25,17 +25,13 @@ import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
......
package com.topjohnwu.magisk;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHolder> {
private final List<Module> mList;
private final Utils.ItemClickListener chboxListener;
private final Utils.ItemClickListener deleteBtnListener;
private final Utils.ItemClickListener unDeleteBtnListener;
public ModulesAdapter(List<Module> list, Utils.ItemClickListener chboxListener, Utils.ItemClickListener deleteBtnListener, Utils.ItemClickListener undeleteBtnListener) {
this.mList = list;
this.chboxListener = chboxListener;
this.deleteBtnListener = deleteBtnListener;
this.unDeleteBtnListener = undeleteBtnListener;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_module, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final Module module = mList.get(position);
holder.title.setText(module.getName());
holder.versionName.setText(module.getVersion());
holder.description.setText(module.getDescription());
holder.checkBox.setChecked(module.isEnabled());
holder.checkBox.setOnCheckedChangeListener((compoundButton, b) -> chboxListener.onItemClick(compoundButton, holder.getAdapterPosition()));
holder.delete.setOnClickListener(view -> {
if (module.willBeRemoved()) {
unDeleteBtnListener.onItemClick(holder.delete, holder.getAdapterPosition());
} else {
deleteBtnListener.onItemClick(holder.delete, holder.getAdapterPosition());
}
updateDeleteButton(holder, module);
});
updateDeleteButton(holder, module);
}
private void updateDeleteButton(ViewHolder holder, Module module) {
holder.warning.setVisibility(module.willBeRemoved() ? View.VISIBLE : View.GONE);
if (module.willBeRemoved()) {
holder.delete.setImageResource(R.drawable.ic_undelete);
} else {
holder.delete.setImageResource(R.drawable.ic_delete);
}
}
@Override
public int getItemCount() {
return mList.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.title) TextView title;
@BindView(R.id.version_name) TextView versionName;
@BindView(R.id.description) TextView description;
@BindView(R.id.warning) TextView warning;
@BindView(R.id.checkbox) CheckBox checkBox;
@BindView(R.id.delete) ImageView delete;
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
if (!Shell.rootAccess()) {
checkBox.setEnabled(false);
delete.setEnabled(false);
}
}
}
}
\ No newline at end of file
...@@ -2,9 +2,12 @@ package com.topjohnwu.magisk; ...@@ -2,9 +2,12 @@ package com.topjohnwu.magisk;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
...@@ -12,98 +15,121 @@ import android.support.v4.app.Fragment; ...@@ -12,98 +15,121 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager; 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.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Toast;
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.utils.Shell; import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.io.File;
import java.io.FileNotFoundException;
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 java.util.concurrent.ExecutionException;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class ModulesFragment extends Fragment { public class ModulesFragment extends Fragment {
private static final int FETCH_ZIP_CODE = 2;
public static List<Module> listModules = new ArrayList<>(); public static List<Module> listModules = new ArrayList<>();
public static List<Module> listModulesCache = new ArrayList<>(); public static List<Module> listModulesCache = new ArrayList<>();
private static final int FILE_SELECT_CODE = 0; @BindView(R.id.progressBar)
private File input; ProgressBar progressBar;
@BindView(R.id.fab)
@BindView(R.id.progressBar) ProgressBar progressBar; FloatingActionButton fabio;
@BindView(R.id.fab) FloatingActionButton fabio; @BindView(R.id.pager)
@BindView(R.id.pager) ViewPager viewPager; ViewPager viewPager;
@BindView(R.id.tab_layout) TabLayout tabLayout; @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 view = inflater.inflate(R.layout.modules_fragment, container, false);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
fabio.setOnClickListener(v -> {
Intent getContentIntent = FileUtils.createGetContentIntent(null);
getContentIntent.setType("application/zip");
Intent fileIntent = Intent.createChooser(getContentIntent, "Select a file");
new updateUI().execute(); startActivityForResult(fileIntent, FETCH_ZIP_CODE);
setHasOptionsMenu(true); });
return view;
}
@Override new Utils.LoadModules(getActivity(), false).execute();
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { mTaskDelegate = result -> {
super.onCreateOptionsMenu(menu, inflater); if (result.equals("OK")) {
inflater.inflate(R.menu.menu_module, menu); RefreshUI();
fabio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("*/zip");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,FILE_SELECT_CODE);
} }
};
}); new updateUI().execute();
return view;
} }
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) { if (data != null) {
case FILE_SELECT_CODE: // Get the URI of the selected file
if (resultCode == Activity.RESULT_OK) { final Uri uri = data.getData();
// Get the Uri of the selected file Log.i("Magisk", "ModulesFragment: Uri = " + uri.toString() + " or ");
Uri uri = data.getData(); new Utils.FlashZIP(getActivity(),uri).execute();
String path = uri.getPath(); try {
String fileName = uri.getLastPathSegment(); // Get the file path from the URI
new Utils.FlashZIP(getActivity(), fileName, path).execute(); FileInfo fileInfo = FileUtils.getFileInfo(getActivity(), uri);
Toast.makeText(getActivity(),
"File Selected: " + fileInfo.getDisplayName() + " size: " + fileInfo.getSize(), Toast.LENGTH_LONG).show();
if (!fileInfo.isExternal()) {
} else {
} }
break; } catch (Exception e) {
}} Log.e("FileSelectorTestAc...", "File select error", e);
}
}
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
switch (item.getItemId()) { super.onCreateOptionsMenu(menu, inflater);
case R.id.force_reload: inflater.inflate(R.menu.menu_module, menu);
listModules.clear();
listModulesCache.clear();
progressBar.setVisibility(View.VISIBLE);
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
tabLayout.setupWithViewPager(viewPager);
new Utils.LoadModules(getContext()).execute();
new updateUI().execute();
break;
}
return super.onOptionsItemSelected(item); }
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(), true).execute();
Collections.sort(listModules, new CustomComparator());
Collections.sort(listModulesCache, new CustomComparator());
new updateUI().execute();
}
void selectPage(int pageIndex) {
tabLayout.setScrollPosition(pageIndex, 0f, true);
viewPager.setCurrentItem(pageIndex);
} }
public static class NormalModuleFragment extends BaseModuleFragment { public static class NormalModuleFragment extends BaseModuleFragment {
...@@ -134,11 +160,11 @@ public class ModulesFragment extends Fragment { ...@@ -134,11 +160,11 @@ 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); progressBar.setVisibility(View.GONE);
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager())); viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
tabLayout.setupWithViewPager(viewPager); tabLayout.setupWithViewPager(viewPager);
selectPage(viewPagePosition);
} }
} }
...@@ -165,10 +191,22 @@ public class ModulesFragment extends Fragment { ...@@ -165,10 +191,22 @@ public class ModulesFragment extends Fragment {
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
if (position == 0) { if (position == 0) {
return new NormalModuleFragment(); NormalModuleFragment nmf = new NormalModuleFragment();
nmf.SetDelegate(mTaskDelegate);
return nmf;
} else { } else {
return new CacheModuleFragment(); CacheModuleFragment cmf = new CacheModuleFragment();
cmf.SetDelegate(mTaskDelegate);
return cmf;
} }
} }
} }
}
public class CustomComparator implements Comparator<Module> {
@Override
public int compare(Module o1, Module o2) {
return o1.getName().compareTo(o2.getName());
}
}
}
\ No newline at end of file
This diff is collapsed.
package com.topjohnwu.magisk;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.utils.Utils;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class ReposFragment extends Fragment {
public static List<Repo> mListRepos = new ArrayList<>();
public static List<Repo> mListReposToUpdate = new ArrayList<>();
@BindView(R.id.recyclerView)
RecyclerView recyclerView;
@BindView(R.id.empty_rv)
TextView emptyTv;
@BindView(R.id.swipeRefreshLayout)
SwipeRefreshLayout swipeRefreshLayout;
private View mView;
private boolean mCanUpdate;
private boolean alertUpdate;
private boolean ignoreAlertUpdate;
private String alertPackage;
private SharedPreferences prefs;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.single_repo_fragment, container, false);
mView = view;
ButterKnife.bind(this, view);
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
if (prefs.contains("ignoreUpdateAlerts")) {
ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false);
}
swipeRefreshLayout.setOnRefreshListener(() -> {
this.LoadRepo(true);
ignoreAlertUpdate = false;
prefs.edit().putBoolean("ignoreUpdateAlerts",false).apply();
});
LoadRepo(false);
setHasOptionsMenu(false);
alertUpdate = false;
if (mListRepos.size() == 0) {
emptyTv.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
return view;
}
CheckForUpdates();
Log.d("Magisk", "ReposFragment: ListRepos size is " + listRepos().size());
recyclerView.setAdapter(new ReposAdapter(this, mListRepos));
return view;
}
@Override
public void onStart() {
super.onStart();
NotifyOfAlerts();
}
private void CheckForUpdates() {
for (int i = 0; i < mListRepos.size(); i++) {
if (mListRepos.get(i).canUpdate()) {
alertUpdate = true;
mListReposToUpdate.add(mListRepos.get(i));
}
}
}
@Override
public void onAttachFragment(Fragment childFragment) {
super.onAttachFragment(childFragment);
}
private void LoadRepo (boolean doReload) {
RepoHelper.TaskDelegate taskDelegate = result -> {
if (result.equals("Complete")) {
Log.d("Magisk", "ReposFragment, got delegate");
UpdateUI();
if (mView != null) {
mView.invalidate();
mView.requestLayout();
}
}
};
Log.d("Magisk","ReposFragment, LoadRepo called");
mListRepos.clear();
RepoHelper mr = new RepoHelper();
List<Repo> magiskRepos = mr.listRepos(getActivity(), doReload, taskDelegate);
for (Repo repo : magiskRepos) {
Log.d("Magisk", "ReposFragment: Adding repo from string " + repo.getId());
mListRepos.add(repo);
}
}
private void NotifyOfAlerts() {
if (alertUpdate && !ignoreAlertUpdate) {
Iterator<Repo> iterRepo = mListReposToUpdate.iterator();
while (iterRepo.hasNext()) {
Repo repo = iterRepo.next();
DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
Utils.DownloadReceiver receiver = new Utils.DownloadReceiver() {
@Override
public void task(File file) {
Log.d("Magisk", "Task firing");
new Utils.FlashZIP(getActivity(), repo.getId(), file.toString()).execute();
}
};
String filename = repo.getId().replace(" ", "") + ".zip";
Utils.downloadAndReceive(getActivity(), receiver, repo.getmZipUrl(), filename);
break;
case DialogInterface.BUTTON_NEGATIVE:
ignoreAlertUpdate = true;
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate);
editor.apply();
break;
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("An update is available for " + repo.getName() + ". Would you like to install it?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
iterRepo.remove();
}
}
}
@Override
public void onResume() {
super.onResume();
LoadRepo(false);
}
protected List<Repo> listRepos() {
return mListRepos;
}
private void UpdateUI() {
Log.d("Magisk","ReposFragment: UpdateUI Called, size is " + listRepos().size());
if (listRepos().size() == 0) {
emptyTv.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
}
Log.d("Magisk", "ReposFragment: ListRepos size is " + listRepos().size());
recyclerView.setAdapter(new ReposAdapter(this, listRepos()));
if (swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(false);
CheckForUpdates();
NotifyOfAlerts();
}
}
}
package com.topjohnwu.magisk; package com.topjohnwu.magisk;
import android.Manifest; import android.Manifest;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
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.IdRes; import android.support.annotation.IdRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
...@@ -25,6 +23,7 @@ import android.support.v7.widget.Toolbar; ...@@ -25,6 +23,7 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import butterknife.BindView; import butterknife.BindView;
...@@ -33,15 +32,13 @@ import butterknife.ButterKnife; ...@@ -33,15 +32,13 @@ import butterknife.ButterKnife;
public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID"; private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
private Context mContext;
private final Handler mDrawerHandler = new Handler(); private final Handler mDrawerHandler = new Handler();
@BindView(R.id.toolbar) @BindView(R.id.toolbar) Toolbar toolbar;
Toolbar toolbar; @BindView(R.id.drawer_layout) DrawerLayout drawer;
@BindView(R.id.drawer_layout) @BindView(R.id.nav_view) NavigationView navigationView;
DrawerLayout drawer;
@BindView(R.id.nav_view)
NavigationView navigationView;
@IdRes @IdRes
private int mSelectedId = R.id.magisk; private int mSelectedId = R.id.magisk;
...@@ -51,28 +48,34 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView ...@@ -51,28 +48,34 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
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) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} }
// Startups // 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 if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
&& 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();
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); setSupportActionBar(toolbar);
...@@ -102,12 +105,10 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView ...@@ -102,12 +105,10 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
} }
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
if (getIntent().hasExtra("relaunch")) {
navigate(R.id.root);
}
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
...@@ -134,25 +135,6 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView ...@@ -134,25 +135,6 @@ 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 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) { private void navigate(final int itemId) {
Fragment navFragment = null; Fragment navFragment = null;
String tag = ""; String tag = "";
...@@ -167,16 +149,16 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView ...@@ -167,16 +149,16 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
tag = "root"; tag = "root";
navFragment = new RootFragment(); navFragment = new RootFragment();
break; break;
case R.id.autoroot:
setTitle(R.string.auto_root);
tag = "ic_autoroot";
navFragment = new AutoRootFragment();
break;
case R.id.modules: case R.id.modules:
setTitle(R.string.modules); setTitle(R.string.modules);
tag = "modules"; tag = "modules";
navFragment = new ModulesFragment(); navFragment = new ModulesFragment();
break; break;
case R.id.downloads:
setTitle(R.string.downloads);
tag = "downloads";
navFragment = new ReposFragment();
break;
case R.id.log: case R.id.log:
setTitle(R.string.log); setTitle(R.string.log);
tag = "log"; tag = "log";
...@@ -198,6 +180,4 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView ...@@ -198,6 +180,4 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
} }
} }
} }
}
\ No newline at end of file
}
package com.topjohnwu.magisk.module; package com.topjohnwu.magisk.module;
import android.content.Context;
import android.content.SharedPreferences;
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;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class Module { public class Module {
private String mRemoveFile; private String mRemoveFile;
...@@ -17,50 +15,143 @@ public class Module { ...@@ -17,50 +15,143 @@ public class Module {
private String mName = null; private String mName = null;
private String mVersion = "(No version provided)"; private String mVersion = "(No version provided)";
private String mDescription = "(No description provided)"; private String mDescription = "(No description provided)";
private String mUrl,mSupportUrl,mDonateUrl,mZipUrl,mBaseUrl,mManifestUrl,mAuthor,mLogUrl;
private boolean mEnable, mRemove,mUpdateAvailable, mIsInstalled,mIsCacheModule;
private boolean mEnable;
private boolean mRemove;
private String mId; private String mId;
private int mVersionCode; private int mVersionCode;
public Module(String path, Context context) {
public Module(String path) {
mRemoveFile = path + "/remove"; mRemoveFile = path + "/remove";
mDisableFile = path + "/disable"; mDisableFile = path + "/disable";
for (String line : Utils.readFile(path + "/module.prop")) { for (String line : Utils.readFile(path + "/module.prop")) {
String[] parts = line.split("=", 2); String[] props = line.split("=", 2);
if (parts.length != 2) { if (props.length != 2) {
continue; continue;
} }
String key = parts[0].trim(); String key = props[0].trim();
if (key.charAt(0) == '#') { if (key.charAt(0) == '#') {
continue; continue;
} }
String value = parts[1].trim(); switch (props[0]) {
switch (key) { case "versionCode":
this.mVersionCode = Integer.valueOf(props[1]);
break;
case "name": case "name":
mName = value; this.mName = props[1];
break;
case "author":
this.mAuthor = props[1];
break;
case "id":
this.mId = props[1];
break; break;
case "version": case "version":
mVersion = value; this.mVersion = props[1];
break; break;
case "description": case "description":
mDescription = value; this.mDescription = props[1];
break; break;
case "id": case "donate":
mId = value; this.mDonateUrl = props[1];
break; break;
case "versionCode": case "cacheModule":
try { this.mIsCacheModule = Boolean.valueOf(props[1]);
mVersionCode = Integer.parseInt(value); break;
} catch (NumberFormatException e) { case "support":
mVersionCode = 0; 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; break;
} }
}
Log.d("Magisk","Module: Loaded module with ID of " + this.mId + " or " + mId);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (this.mId != null && !this.mId.isEmpty()) {
String preferenceString = "repo_" + this.mId;
String preferenceKey = prefs.getString(preferenceString,"nope");
Log.d("Magisk", "Module: Checking for preference named " + preferenceString);
if (!preferenceKey.equals("nope")) {
Log.d("Magisk", "Module: repo_" + mId + " found.");
String entryString = prefs.getString("repo_" + mId, "");
String[] subStrings = entryString.split("\n");
for (String subKeys : subStrings) {
String[] idEntry = subKeys.split("=", 2);
if (idEntry[0].equals("id")) {
if (idEntry.length != 2) {
continue;
}
if (idEntry[1].equals(mId)) {
Log.d("Magisk", "Module: Hey, I know " + mId + " is online...");
mIsInstalled = true;
} else mIsInstalled = false;
}
if (idEntry[0].equals("logUrl")) {
mLogUrl = idEntry[1];
}
if (idEntry[0].equals("support")) {
mSupportUrl = idEntry[1];
}
if (idEntry[0].equals("zipUrl")) {
mZipUrl = idEntry[1];
}
if (idEntry[0].equals("donate")) {
mDonateUrl = idEntry[1];
}
if (idEntry[0].equals("versionCode")) {
if (idEntry.length != 2) {
continue;
}
if (Integer.valueOf(idEntry[1]) > mVersionCode) {
mUpdateAvailable = true;
Log.d("Magisk", "Module: Hey, I have an update...");
} else mUpdateAvailable = false;
}
}
}
SharedPreferences.Editor editor = prefs.edit();
if (mIsInstalled) {
editor.putBoolean("repo-isInstalled_" + mId, true);
} else {
editor.putBoolean("repo-isInstalled_" + mId, false);
}
if (mUpdateAvailable) {
editor.putBoolean("repo-canUpdate_" + mId, true);
} else {
editor.putBoolean("repo-canUpdate_" + mId, false);
}
editor.apply();
} }
if (mName == null) { if (mName == null) {
...@@ -74,6 +165,21 @@ public class Module { ...@@ -74,6 +165,21 @@ public class Module {
} }
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() { public String getName() {
return mName; return mName;
} }
...@@ -82,6 +188,14 @@ public class Module { ...@@ -82,6 +188,14 @@ public class Module {
return mVersion; return mVersion;
} }
public String getAuthor() {
return mAuthor;
}
public String getId() {return mId; }
public String getmLogUrl() {return mLogUrl; }
public String getDescription() { public String getDescription() {
return mDescription; return mDescription;
} }
...@@ -110,4 +224,22 @@ public class Module { ...@@ -110,4 +224,22 @@ public class Module {
return mRemove; return mRemove;
} }
public String getmDonateUrl() {
return mDonateUrl;
}
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; }
} }
\ No newline at end of file
package com.topjohnwu.magisk.module;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Date;
public class Repo {
private String mBaseUrl;
private String mZipUrl;
private String mLogUrl;
private String mManifestUrl;
private String mVersion;
private String mName;
private String mDescription;
private String mAuthor;
public String mAuthorUrl;
private String mId;
private String mVersionCode;
private String mSupportUrl;
private String mDonateUrl;
private String lastUpdate;
private Context appContext;
private boolean mIsInstalled,mCanUpdate,mIsCacheModule;
public Repo(String manifestString, Context context) {
appContext = context;
ParseProps(manifestString);
}
public Repo(String name, String url, Date updated, Context context) {
appContext = context;
this.mName = name;
this.mBaseUrl = url;
this.lastUpdate = updated.toString();
this.fetch();
}
public Repo(String moduleName, String moduleDescription, String zipUrl, Date lastUpdated, Context context) {
appContext = context;
this.mZipUrl = zipUrl;
this.mDescription = moduleDescription;
this.mName = moduleName;
this.lastUpdate = lastUpdated.toString();
this.fetch();
}
public void fetch() {
WebRequest webreq = new WebRequest();
// Construct initial url for contents
String repoString = webreq.makeWebServiceCall(mBaseUrl + "/contents?access_token=" + Utils.procFile(appContext.getString(R.string.some_string),appContext), WebRequest.GET);
try {
JSONArray repoArray = new JSONArray(repoString);
for (int f = 0; f < repoArray.length(); f++) {
JSONObject jsonobject = repoArray.getJSONObject(f);
String name = jsonobject.getString("name");
String url = jsonobject.getString("download_url").trim();
Log.d("Magisk","Repo - checking object named " + name + " with value of " + url);
if (name.contains(".zip")) {
this.mZipUrl = url;
}
if (name.equals("module.prop")) {
this.mManifestUrl = url;
}
if (name.contains("log.txt")) {
Log.d("Magisk","Repo: Setting log URL for " + name + " of " + url);
this.mLogUrl = url;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
WebRequest propReq = new WebRequest();
String manifestString = propReq.makeWebServiceCall(mManifestUrl,WebRequest.GET,true);
if (ParseProps(manifestString)) {
PutProps(manifestString);
}
}
private void PutProps(String manifestString) {
manifestString = manifestString + "zipUrl=" + mZipUrl + "\nbaseUrl=" + mBaseUrl + "\nlogUrl=" + mLogUrl + "\nmanifestUrl=" + mManifestUrl;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("repo_" + mId, manifestString);
editor.putBoolean("hasCachedRepos", true);
editor.putString("updated_" + mId, this.lastUpdate);
editor.apply();
}
private boolean ParseProps(String string) {
if ((string.length() <= 1) | (!string.contains("id"))) {
return false;
} else {
String lines[] = string.split("\\n");
for (String line : lines) {
if (line != "") {
String props[] = line.split("=");
switch (props[0]) {
case "versionCode":
this.mVersionCode = props[1];
break;
case "name":
this.mName = props[1];
break;
case "author":
this.mAuthor = props[1];
break;
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 "logUrl":
this.mLogUrl = 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;
default:
Log.d("Magisk", "Manifest string not recognized: " + props[0]);
break;
}
}
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
if (prefs.contains("repo-isInstalled_" + this.mId)) {
mIsInstalled = prefs.getBoolean("repo-isInstalled_" + this.mId,false);
}
if (prefs.contains("repo-canUpdate_" + this.mId)) {
mCanUpdate = prefs.getBoolean("repo-canUpdate_" + this.mId,false);
}
if (prefs.contains("updated_" + this.mId)) {
lastUpdate = prefs.getString("updated_" + this.mId,"");
}
return this.mId != null;
}
}
public String getStringProperty(String mValue) {
switch (mValue) {
case "author":
return mAuthor;
case "id":
return mId;
case "version":
return mVersion;
case "description":
return mDescription;
case "supportUrl":
return mSupportUrl;
case "donateUrl":
return mDonateUrl;
case "baseeUrl":
return mBaseUrl;
case "zipUrl":
return mZipUrl;
default:
return null;
}
}
public String getName() {
return mName;
}
public String getmVersion() {
return mVersion;
}
public int getmVersionCode() {
return Integer.valueOf(mVersionCode);
}
public String getDescription() {
return mDescription;
}
public String getId() {
return mId;
}
public String getmZipUrl() {
return mZipUrl;
}
public String getmBaseUrl() {
return mBaseUrl;
}
public String getmLogUrl() {
return mLogUrl;
}
public String getmAuthor() {
return mAuthor;
}
public String getmDonateUrl() {
return mDonateUrl;
}
public String getmManifestUrl() {
return mManifestUrl;
}
public String getmSupportUrl() {
return mSupportUrl;
}
public String getLastUpdate() {
return lastUpdate;
}
public boolean isInstalled() { return mIsInstalled; }
public boolean canUpdate() { return mCanUpdate; }
public boolean isCacheModule() { return mIsCacheModule; }
}
package com.topjohnwu.magisk.module;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class RepoHelper {
private static List<Repo> repos = new ArrayList<>();
private static String TAG = "Magisk";
private Context activityContext;
private Date updatedDate;
private SharedPreferences prefs;
private boolean apiFail;
public RepoHelper() {
}
public List<Repo> listRepos(Context context, boolean refresh, TaskDelegate delegate) {
prefs = PreferenceManager.getDefaultSharedPreferences(context);
activityContext = context;
if (!prefs.contains("hasCachedRepos") | refresh) {
Log.d(TAG, "RepoHelper: Building from web");
new BuildFromWeb(delegate).execute();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
String date = format.format(Calendar.getInstance().getTime());
prefs.edit().putString("last_update",date).apply();
} else {
Log.d(TAG, "RepoHelper: Building from cache");
BuildFromCache();
}
Collections.sort(repos, new CustomComparator());
return repos;
}
private void BuildFromCache() {
repos.clear();
Map<String, ?> map = prefs.getAll();
for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getKey().contains("repo_")) {
String repoString = entry.getValue().toString().replace("&quot;", "\"");
repos.add(new Repo(repoString, activityContext));
}
}
}
class BuildFromWeb extends AsyncTask<String, String, Void> {
private TaskDelegate delegate;
public BuildFromWeb(TaskDelegate delegate) {
this.delegate = delegate;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply();
Toast.makeText(activityContext, "Refreshing online modules", Toast.LENGTH_SHORT).show();
}
@Override
protected Void doInBackground(String... params) {
publishProgress();
// Creating service handler class instance
WebRequest webreq = new WebRequest();
// Making a request to url and getting response
String token = activityContext.getString(R.string.some_string);
String url1 = activityContext.getString(R.string.url_main);
String jsonStr = webreq.makeWebServiceCall(url1 + Utils.procFile(token, activityContext), WebRequest.GET);
if (jsonStr != null && !jsonStr.isEmpty()) {
try {
repos.clear();
JSONArray jsonArray = new JSONArray(jsonStr);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonobject = jsonArray.getJSONObject(i);
String name = jsonobject.getString("name");
String url = jsonobject.getString("url");
String lastUpdate = jsonobject.getString("updated_at");
String mId = "";
String cacheUpdate = "";
String manifestString = "";
boolean doUpdate = true;
boolean hasCachedDate = false;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
Map<String, ?> map = prefs.getAll();
for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getValue().toString().contains(url)) {
Log.d("Magisk", "RepoHelper: found matching URL");
manifestString = entry.getValue().toString();
String[] entryStrings = entry.getValue().toString().split("\n");
for (String valueString : entryStrings) {
String[] valueSub = valueString.split("=");
if (valueSub[0].equals("id")) {
mId = valueSub[1];
if (prefs.contains("updated_" + mId)) {
cacheUpdate = prefs.getString("updated_" + mId, "");
hasCachedDate = true;
}
}
}
}
}
try {
updatedDate = format.parse(lastUpdate);
Log.d("Magisk", "RepoHelper: Dates found, online is " + updatedDate + " and cached is " + cacheUpdate);
if (hasCachedDate) {
doUpdate = !cacheUpdate.equals(updatedDate.toString());
Log.d("Magisk", "RepoHelper: DoUpdate is " + doUpdate);
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!name.contains("Repo.github.io")) {
if (doUpdate) {
repos.add(new Repo(name, url, updatedDate, activityContext));
Log.d(TAG, "RepoHelper: Trying to add new repo for online refresh - " + name);
} else {
repos.add(new Repo(manifestString, activityContext));
Log.d(TAG, "RepoHelper: Trying to add new repo using manifestString of " + mId);
}
}
for (int f = 0; f < repos.size(); f++) {
repos.get(f).fetch();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
apiFail = false;
} else {
apiFail = true;
}
return null;
}
protected void onPostExecute(Void v) {
if (apiFail) {
Toast.makeText(activityContext, "GitHub API Limit reached, please try refreshing again in an hour.", Toast.LENGTH_LONG).show();
} else {
Log.d("Magisk", "RepoHelper: postExecute fired");
delegate.taskCompletionResult("Complete");
BuildFromCache();
}
}
}
public interface TaskDelegate {
void taskCompletionResult(String result);
}
public class CustomComparator implements Comparator<Repo> {
@Override
public int compare(Repo o1, Repo o2) {
return o1.getName().compareTo(o2.getName());
}
}
}
package com.topjohnwu.magisk.utils;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.LinearLayout;
public class AnimationHelper {
public static void expand(final View v) {
v.measure(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
final int targetHeight = v.getMeasuredHeight();
v.getLayoutParams().height = 0;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1
? LinearLayout.LayoutParams.WRAP_CONTENT
: (int) (targetHeight * interpolatedTime);
v.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}
public static void collapse(final View v) {
final int initialHeight = v.getMeasuredHeight();
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if (interpolatedTime == 1) {
v.setVisibility(View.GONE);
} else {
v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
v.requestLayout();
}
}
@Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}
}
\ No newline at end of file
package com.topjohnwu.magisk.utils;
public class GitAgent {
}
package com.topjohnwu.magisk.utils; package com.topjohnwu.magisk.utils;
import android.os.AsyncTask;
import android.util.Log;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
......
package com.topjohnwu.magisk.utils; package com.topjohnwu.magisk.utils;
import android.util.Log;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
......
package com.topjohnwu.magisk.utils;
import android.util.Log;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
public class WebRequest {
static String response = null;
public final static int GET = 1;
public final static int POST = 2;
private boolean addNewLine;
//Constructor with no parameter
public WebRequest() {
}
/**
* Making web service call
*
* @url - url to make request
* @requestmethod - http request method
*/
public String makeWebServiceCall(String url, int requestmethod) {
addNewLine=false;
Log.d("Magisk","WebRequest: Service call received for URL " + url);
return this.makeWebServiceCall(url, requestmethod, null);
}
public String makeWebServiceCall(String url, int requestmethod, boolean addNewLines) {
addNewLine = addNewLines;
Log.d("Magisk","WebRequest: Service call(bool) received for URL " + url);
return this.makeWebServiceCall(url, requestmethod, null);
}
/**
* Making service call
*
* @url - url to make request
* @requestmethod - http request method
* @params - http request params
*/
public String makeWebServiceCall(String urladdress, int requestmethod,
HashMap<String, String> params) {
URL url;
String response = "";
try {
url = new URL(urladdress);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setDoInput(true);
if (requestmethod == POST) {
conn.setRequestMethod("POST");
} else if (requestmethod == GET) {
conn.setRequestMethod("GET");
}
if (params != null) {
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
StringBuilder result = new StringBuilder();
boolean first = true;
for (Map.Entry<String, String> entry : params.entrySet()) {
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
}
writer.write(result.toString());
writer.flush();
writer.close();
os.close();
}
int responseCode = conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = br.readLine()) != null) {
if (addNewLine) {
response += line + "\n";
} else {
response += line;
}
}
} else {
response = "";
}
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
}
\ No newline at end of file
package com.topjohnwu.magisk.utils;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebWindow {
public WebWindow(String title, String url, Context context) {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle(title);
WebView wv = new WebView(context);
wv.loadUrl(url);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(url);
return true;
}
});
alert.setView(wv);
alert.setNegativeButton("Close", (dialog, id) -> {
dialog.dismiss();
});
alert.show();
}
}
<vector android:height="30dp" android:viewportHeight="512.0"
android:viewportWidth="512.0" android:width="30dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M356.2,365.6C326.6,382.4 292.4,392 256,392c-36.4,0 -70.6,-9.6 -100.1,-26.4C77.5,389.5 29.4,443 11.7,512h488.5C482.6,442.9 434.6,389.5 356.2,365.6z"/>
<path android:fillColor="#FF000000" android:pathData="M256,0C158.8,0 80,78.8 80,176s78.8,176 176,176s176,-78.8 176,-176S353.2,0 256,0zM256,308c-56,0 -103.8,-34.8 -123,-84h246C359.8,273.2 312,308 256,308z"/>
</vector>
<vector android:height="30dp" android:viewportHeight="1024.0"
android:viewportWidth="896.0" android:width="30dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M128,768h256v64L128,832v-64zM448,384L128,384v64h320v-64zM576,576L576,448L384,640l192,192L576,704h320L896,576L576,576zM288,512L128,512v64h160v-64zM128,704h160v-64L128,640v64zM704,768h64v128c-1,18 -7,33 -19,45s-27,18 -45,19L64,960c-35,0 -64,-29 -64,-64L0,192c0,-35 29,-64 64,-64h192C256,57 313,0 384,0s128,57 128,128h192c35,0 64,29 64,64v320h-64L704,320L64,320v576h640L704,768zM128,256h512c0,-35 -29,-64 -64,-64h-64c-35,0 -64,-29 -64,-64s-29,-64 -64,-64 -64,29 -64,64 -29,64 -64,64h-64c-35,0 -64,29 -64,64z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="30dp"
android:height="30dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#000"
android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/>
</vector>
<vector android:height="30dp" android:viewportHeight="512.0"
android:viewportWidth="512.0" android:width="30dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M256,0C114.8,0 0,114.8 0,256C0,397.2 114.8,512 256,512C397.2,512 512,397.2 512,256C512,114.8 397.2,0 256,0zM368.4,302.6c6,-14.4 9.3,-30.1 9.3,-46.6c0,-16.5 -3.3,-32.2 -9.3,-46.6l113.6,-47c12,28.9 18.7,60.5 18.7,93.6c0,33.2 -6.7,64.8 -18.7,93.6L368.4,302.6zM256,366.3c-60.8,0 -110.3,-49.5 -110.3,-110.3c0,-60.8 49.5,-110.3 110.3,-110.3c60.8,0 110.3,49.5 110.3,110.3C366.3,316.8 316.8,366.3 256,366.3zM30,349.6c-12,-28.8 -18.6,-60.4 -18.6,-93.6c0,-33.1 6.7,-64.7 18.6,-93.6l113.6,47c-6,14.3 -9.3,30.1 -9.3,46.6c0,16.5 3.3,32.2 9.3,46.6L30,349.6zM349.6,30L302.6,143.6c-14.4,-6 -30.1,-9.3 -46.6,-9.3c-16.5,0 -32.2,3.3 -46.6,9.3L162.4,30c28.9,-12 60.5,-18.7 93.6,-18.7C289.1,11.4 320.8,18 349.6,30zM162.4,482l47,-113.6c14.4,6 30.1,9.3 46.6,9.3c16.5,0 32.2,-3.3 46.6,-9.3L349.6,482c-28.8,12 -60.5,18.7 -93.6,18.7C222.9,500.6 191.2,494 162.4,482z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#757575"
android:pathData="M12,16.5l4,-4h-3v-9h-2v9L8,12.5l4,4zM21,3.5h-6v1.99h6v14.03L3,19.52L3,5.49h6L9,3.5L3,3.5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2v-14c0,-1.1 -0.9,-2 -2,-2z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="3dip"
android:layout_marginLeft="8dip"
android:layout_marginRight="8dip"
android:layout_marginTop="3dip"
android:background="?android:attr/selectableItemBackground"
android:minHeight="?android:attr/listPreferredItemHeight"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:padding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
>
<TextView
android:id="@+id/title"
android:layout_width="300dip"
android:layout_height="wrap_content"
android:singleLine="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textIsSelectable="false"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp" />
<TextView
android:id="@+id/version_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false"
android:textStyle="bold|italic"
android:layout_alignParentStart="true"
android:layout_below="@id/title"
/>
<ImageView
android:id="@+id/update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="end"
android:background="@drawable/ic_file_download_black"
android:backgroundTint="@color/icon_grey"
android:layout_gravity="end"
android:layout_alignBaseline="@id/title"
android:layout_alignParentEnd="true"
/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"
android:layout_alignParentStart="true"
android:layout_below="@id/update"
/>
<LinearLayout
android:id="@+id/expand_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:orientation="vertical"
android:layout_below="@id/description"
android:layout_alignParentStart="true"
>
<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false"
android:textStyle="bold|italic"/>
<TextView
android:id="@+id/installedStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"/>
<TextView
android:id="@+id/updateStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"
android:layout_marginBottom="20dip" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dip"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_marginBottom="0dip">
<ImageView
android:id="@+id/changeLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:backgroundTint="@color/icon_grey"
android:background="@drawable/ic_changelog"/>
<ImageView
android:id="@+id/authorLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:backgroundTint="@color/icon_grey"
android:background="@drawable/ic_author"/>
<ImageView
android:id="@+id/supportLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:backgroundTint="@color/icon_grey"
android:background="@drawable/ic_support"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="@+id/installed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:visibility="gone"
android:gravity="end"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.SwipeRefreshLayout
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent" android:id="@+id/swipeRefreshLayout"
android:orientation="vertical"> android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView" android:id="@+id/recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="60dip"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/> app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<TextView <TextView
...@@ -23,4 +28,4 @@ ...@@ -23,4 +28,4 @@
android:textStyle="italic" android:textStyle="italic"
android:visibility="gone"/> android:visibility="gone"/>
</LinearLayout> </android.support.v4.widget.SwipeRefreshLayout>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginTop="?attr/actionBarSize"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
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
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
android:icon="@drawable/ic_extension" android:icon="@drawable/ic_extension"
android:title="@string/modules"/> android:title="@string/modules"/>
<item
android:id="@+id/downloads"
android:icon="@drawable/ic_file_download_black"
android:title="@string/downloads"/>
<item <item
android:id="@+id/log" android:id="@+id/log"
android:icon="@drawable/ic_bug_report" android:icon="@drawable/ic_bug_report"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<color name="accent">#FFC107</color> <color name="accent">#FFC107</color>
<color name="primary_text">#212121</color> <color name="primary_text">#212121</color>
<color name="icons">#FFFFFF</color> <color name="icons">#FFFFFF</color>
<color name="icon_grey">#757575</color>
<color name="red500">#F44336</color> <color name="red500">#F44336</color>
<color name="green500">#4CAF50</color> <color name="green500">#4CAF50</color>
<color name="blue500">#2196F3</color> <color name="blue500">#2196F3</color>
......
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
<resources> <resources>
<dimen name="floating_height">650dp</dimen> <dimen name="floating_height">650dp</dimen>
<dimen name="floating_width">500dp</dimen> <dimen name="floating_width">500dp</dimen>
<dimen name="min_rowheight">100dp</dimen>
</resources> </resources>
\ No newline at end of file
...@@ -43,10 +43,15 @@ ...@@ -43,10 +43,15 @@
<!--Module Fragment--> <!--Module Fragment-->
<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_up_to_date">Module is up-to-date</string>
<string name="module_installed">Module is installed</string>
<string name="module_not_installed">Module is not installed</string>
<string name="remove_file_created">Module will be removed at next reboot</string> <string name="remove_file_created">Module will be removed at next reboot</string>
<string name="remove_file_deleted">Module will not be removed at next reboot</string> <string name="remove_file_deleted">Module will not be removed at next reboot</string>
<string name="disable_file_created">Module will be disabled at next reboot</string> <string name="disable_file_created">Module will be disabled at next reboot</string>
<string name="disable_file_removed">Module will be enabled at next reboot</string> <string name="disable_file_removed">Module will be enabled at next reboot</string>
<string name="author">Created by </string>
<!--Log Fragment--> <!--Log Fragment-->
<string name="menuSaveToSd">Save to SD</string> <string name="menuSaveToSd">Save to SD</string>
...@@ -90,4 +95,8 @@ ...@@ -90,4 +95,8 @@
<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="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string>
<string name="downloads">Downloads</string>
<string name="url_main">https://api.github.com/orgs/Magisk-Modules-Repo/repos?access_token=</string>
</resources> </resources>
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