Load modules in a listview
This commit is contained in:
parent
615bbcae74
commit
4692ed4b4a
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.topjohnwu.magisk">
|
||||
<manifest package="com.topjohnwu.magisk"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@ -10,11 +10,13 @@
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<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>
|
||||
</activity>
|
||||
<activity android:name=".ModulesActivity">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,6 +1,7 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@ -53,6 +54,8 @@ public class MainActivity extends Activity {
|
||||
new SU().execute("setenforce 0");
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.modules).setOnClickListener(view -> startActivity(new Intent(this, ModulesActivity.class)));
|
||||
}
|
||||
|
||||
private String execute(String command) {
|
||||
|
83
app/src/main/java/com/topjohnwu/magisk/Module.java
Normal file
83
app/src/main/java/com/topjohnwu/magisk/Module.java
Normal file
@ -0,0 +1,83 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
public class Module {
|
||||
|
||||
private final boolean isValid;
|
||||
private final boolean isCache;
|
||||
private File mPropFile;
|
||||
|
||||
private String mName;
|
||||
private String mVersion;
|
||||
private int mVersionCode;
|
||||
private String mDescription;
|
||||
|
||||
public Module(File file) {
|
||||
this.isCache = file.getPath().contains("cache");
|
||||
this.isValid = new File(file + "/module.prop").exists();
|
||||
|
||||
if (isValid) {
|
||||
mPropFile = new File(file + "/module.prop");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return isValid && mPropFile != null;
|
||||
}
|
||||
|
||||
public boolean isCache() {
|
||||
return isCache;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
public int getVersionCode() {
|
||||
return mVersionCode;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return mDescription;
|
||||
}
|
||||
|
||||
public void parse() throws Exception {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(mPropFile));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] parts = line.split("=", 2);
|
||||
if (parts.length != 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String key = parts[0].trim();
|
||||
if (key.charAt(0) == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
String value = parts[1].trim();
|
||||
switch (key) {
|
||||
case "name":
|
||||
mName = value;
|
||||
break;
|
||||
case "version":
|
||||
mVersion = value;
|
||||
break;
|
||||
case "versionCode":
|
||||
mVersionCode = Integer.parseInt(value);
|
||||
break;
|
||||
case "description":
|
||||
mDescription = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
}
|
132
app/src/main/java/com/topjohnwu/magisk/ModulesActivity.java
Normal file
132
app/src/main/java/com/topjohnwu/magisk/ModulesActivity.java
Normal file
@ -0,0 +1,132 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModulesActivity extends Activity {
|
||||
|
||||
private static final String MAGISK_PATH = "/magisk";
|
||||
private static final String MAGISK_CACHE_PATH = "/cache/magisk";
|
||||
|
||||
private List<Module> listModules = new ArrayList<>();
|
||||
private ListView mListView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_modules);
|
||||
|
||||
mListView = (ListView) findViewById(android.R.id.list);
|
||||
|
||||
new CheckFolders().execute();
|
||||
}
|
||||
|
||||
private class CheckFolders extends AsyncTask<Void, Integer, Boolean> {
|
||||
|
||||
private ProgressDialog progress;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
|
||||
progress = ProgressDialog.show(ModulesActivity.this, null, getString(R.string.loading), true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
File[] magisk = new File(MAGISK_PATH).listFiles(File::isDirectory);
|
||||
File[] magiskCache = new File(MAGISK_CACHE_PATH).listFiles(File::isDirectory);
|
||||
|
||||
if (magisk != null) {
|
||||
for (File mod : magisk) {
|
||||
listModules.add(new Module(mod));
|
||||
}
|
||||
}
|
||||
|
||||
if (magiskCache != null) {
|
||||
for (File mod : magiskCache) {
|
||||
listModules.add(new Module(mod));
|
||||
}
|
||||
}
|
||||
|
||||
//noinspection Convert2streamapi
|
||||
for (Module module : listModules) {
|
||||
if (module.isValid()) try {
|
||||
module.parse();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean aBoolean) {
|
||||
super.onPostExecute(aBoolean);
|
||||
|
||||
progress.dismiss();
|
||||
|
||||
mListView.setAdapter(new ModulesAdapter(ModulesActivity.this, R.layout.row));
|
||||
}
|
||||
}
|
||||
|
||||
private class ModulesAdapter extends ArrayAdapter<Module> {
|
||||
|
||||
public ModulesAdapter(Context context, int resource) {
|
||||
super(context, resource);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder vh;
|
||||
|
||||
if (convertView == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.row, null);
|
||||
|
||||
vh = new ViewHolder();
|
||||
vh.name = (TextView) convertView.findViewById(R.id.name);
|
||||
vh.version = (TextView) convertView.findViewById(R.id.version);
|
||||
vh.versionCode = (TextView) convertView.findViewById(R.id.versionCode);
|
||||
vh.description = (TextView) convertView.findViewById(R.id.description);
|
||||
vh.cache = (TextView) convertView.findViewById(R.id.cache);
|
||||
|
||||
convertView.setTag(vh);
|
||||
} else {
|
||||
vh = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
Module module = getItem(position);
|
||||
vh.name.setText("name= " + module.getName());
|
||||
vh.version.setText("version= " + module.getVersion());
|
||||
vh.versionCode.setText("versioncode= " + module.getVersionCode());
|
||||
vh.description.setText("description= " + module.getDescription());
|
||||
vh.cache.setText("is from cache= " + module.isCache());
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private class ViewHolder {
|
||||
public TextView name;
|
||||
public TextView version;
|
||||
public TextView versionCode;
|
||||
public TextView description;
|
||||
public TextView cache;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,127 +1,131 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:focusableInTouchMode="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="com.topjohnwu.magisk.MainActivity">
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:focusableInTouchMode="true"
|
||||
tools:context="com.topjohnwu.magisk.MainActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/magisk_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/magisk_label"
|
||||
android:id="@+id/magisk_label"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="10dp" />
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/magisk_label"
|
||||
android:textSize="20sp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/unavailable"
|
||||
android:id="@+id/magisk_version"
|
||||
android:textStyle="bold"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/magisk_label"
|
||||
android:layout_toEndOf="@+id/magisk_label" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/root_label"
|
||||
android:id="@+id/root_label"
|
||||
android:layout_below="@+id/magisk_label"
|
||||
android:layout_alignParentStart="true"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="10dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toEndOf="@+id/magisk_label"
|
||||
android:text="@string/unavailable"
|
||||
android:id="@+id/root_status"
|
||||
android:textStyle="bold"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_alignTop="@+id/root_label"
|
||||
android:layout_toEndOf="@+id/root_label" />
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/root_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/selinux_label"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/magisk_label"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/root_label"
|
||||
android:textSize="20sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/root_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/root_label"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_toEndOf="@+id/root_label"
|
||||
android:text="@string/unavailable"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/selinux_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/root_label"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginLeft="10dp" />
|
||||
android:text="@string/selinux_label"
|
||||
android:textSize="20sp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/unavailable"
|
||||
android:id="@+id/selinux_status"
|
||||
android:textStyle="bold"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/selinux_label"
|
||||
android:layout_toEndOf="@+id/selinux_label" />
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_toEndOf="@+id/selinux_label"
|
||||
android:text="@string/unavailable"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/unavailable"
|
||||
android:id="@+id/safety_net"
|
||||
android:layout_below="@+id/selinux_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_below="@+id/selinux_label"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="@string/unavailable"
|
||||
android:textSize="15sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/permissive"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/unavailable"
|
||||
android:id="@+id/permissive"
|
||||
android:layout_below="@+id/safety_net"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_below="@+id/safety_net"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="@string/unavailable"
|
||||
android:textSize="15sp" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/root_toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/root_toggle"
|
||||
android:id="@+id/root_toggle"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textSize="20sp"
|
||||
android:switchPadding="20dp"
|
||||
android:layout_below="@+id/permissive"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/permissive"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:checked="false" />
|
||||
android:layout_marginTop="10dp"
|
||||
android:checked="false"
|
||||
android:switchPadding="20dp"
|
||||
android:text="@string/root_toggle"
|
||||
android:textSize="20sp"/>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/selinux_toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/selinux_toggle"
|
||||
android:id="@+id/selinux_toggle"
|
||||
android:layout_marginTop="20dp"
|
||||
android:textSize="20sp"
|
||||
android:switchPadding="20dp"
|
||||
android:layout_below="@+id/root_toggle"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_below="@+id/root_toggle"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:checked="false" />
|
||||
android:layout_marginTop="20dp"
|
||||
android:checked="false"
|
||||
android:switchPadding="20dp"
|
||||
android:text="@string/selinux_toggle"
|
||||
android:textSize="20sp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/modules"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:text="modules activity"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
14
app/src/main/res/layout/activity_modules.xml
Normal file
14
app/src/main/res/layout/activity_modules.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.topjohnwu.magisk.ModulesActivity">
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</RelativeLayout>
|
32
app/src/main/res/layout/row.xml
Normal file
32
app/src/main/res/layout/row.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/version"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/versionCode"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cache"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
@ -1,6 +0,0 @@
|
||||
<resources>
|
||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
</resources>
|
@ -1,5 +0,0 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
</resources>
|
@ -18,4 +18,5 @@
|
||||
<string name="root_none_info">Safety Net (Android Pay) should work</string>
|
||||
<string name="magisk_version">Magisk v%1$s</string>
|
||||
<string name="selinux_samsung">Samsung do not support switching SELinux status!</string>
|
||||
<string name="loading">Loading...</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user