mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-26 00:27:39 +00:00
Allow custom update channels
This commit is contained in:
parent
eed2816491
commit
a8f124704d
@ -75,6 +75,7 @@ public class MagiskManager extends Application {
|
||||
public String localeConfig;
|
||||
public int updateChannel;
|
||||
public String bootFormat;
|
||||
public String customChannelUrl;
|
||||
|
||||
// Global resources
|
||||
public SharedPreferences prefs;
|
||||
@ -152,6 +153,7 @@ public class MagiskManager extends Application {
|
||||
bootFormat = prefs.getString(Const.Key.BOOT_FORMAT, ".img");
|
||||
snet_version = prefs.getInt(Const.Key.SNET_VER, -1);
|
||||
updateServiceVersion = prefs.getInt(Const.Key.UPDATE_SERVICE_VER, -1);
|
||||
customChannelUrl = prefs.getString(Const.Key.CUSTOM_CHANNEL, "");
|
||||
}
|
||||
|
||||
public static void toast(String msg, int duration) {
|
||||
|
@ -8,16 +8,19 @@ import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.preference.SwitchPreference;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.InputType;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
||||
import com.topjohnwu.magisk.asyncs.HideManager;
|
||||
import com.topjohnwu.magisk.components.Activity;
|
||||
import com.topjohnwu.magisk.components.AlertDialogBuilder;
|
||||
import com.topjohnwu.magisk.utils.Const;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.utils.Topic;
|
||||
@ -71,8 +74,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragment
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
||||
Topic.Subscriber {
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener, Topic.Subscriber {
|
||||
|
||||
private SharedPreferences prefs;
|
||||
private PreferenceScreen prefScreen;
|
||||
@ -86,16 +88,16 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.app_settings);
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
prefScreen = getPreferenceScreen();
|
||||
mm = Utils.getMagiskManager(getActivity());
|
||||
prefs = mm.prefs;
|
||||
prefScreen = getPreferenceScreen();
|
||||
|
||||
generalCatagory = (PreferenceCategory) findPreference("general");
|
||||
PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk");
|
||||
PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser");
|
||||
Preference hideManager = findPreference("hide");
|
||||
findPreference("clear").setOnPreferenceClickListener((pref) -> {
|
||||
mm.prefs.edit().remove(Const.Key.ETAG_KEY).apply();
|
||||
prefs.edit().remove(Const.Key.ETAG_KEY).apply();
|
||||
mm.repoDB.clearRepo();
|
||||
MagiskManager.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
|
||||
return true;
|
||||
@ -110,6 +112,32 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
||||
namespaceMode = (ListPreference) findPreference(Const.Key.SU_MNT_NS);
|
||||
SwitchPreference reauth = (SwitchPreference) findPreference(Const.Key.SU_REAUTH);
|
||||
|
||||
updateChannel.setOnPreferenceChangeListener((pref, o) -> {
|
||||
mm.updateChannel = Integer.parseInt((String) o);
|
||||
if (mm.updateChannel == Const.Value.CUSTOM_CHANNEL) {
|
||||
LinearLayout layout = new LinearLayout(getActivity());
|
||||
EditText url = new EditText(getActivity());
|
||||
url.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
|
||||
url.setText(mm.customChannelUrl);
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
layout.addView(url);
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) url.getLayoutParams();
|
||||
params.setMargins(Utils.dpInPx(15), 0, Utils.dpInPx(15), 0);
|
||||
new AlertDialogBuilder(getActivity())
|
||||
.setTitle(R.string.settings_update_custom)
|
||||
.setMessage(R.string.settings_update_custom_msg)
|
||||
.setView(layout)
|
||||
.setPositiveButton(R.string.ok, (d, i) -> {
|
||||
prefs.edit().putString(Const.Key.CUSTOM_CHANNEL, url.getText().toString()).apply();
|
||||
})
|
||||
.setNegativeButton(R.string.close, (d, i) -> {
|
||||
mm.updateChannel = Const.Value.STABLE_CHANNEL;
|
||||
prefs.edit().putString(Const.Key.UPDATE_CHANNEL, String.valueOf(Const.Value.STABLE_CHANNEL)).apply();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
setSummary();
|
||||
|
||||
@ -235,8 +263,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
||||
mm.reloadActivity.publish(false);
|
||||
break;
|
||||
case Const.Key.UPDATE_CHANNEL:
|
||||
mm.updateChannel = Utils.getPrefsInt(prefs, Const.Key.UPDATE_CHANNEL);
|
||||
new CheckUpdates(true).exec();
|
||||
new CheckUpdates().exec();
|
||||
break;
|
||||
}
|
||||
mm.loadConfig();
|
||||
|
@ -24,7 +24,7 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
String jsonStr;
|
||||
String jsonStr = "";
|
||||
switch (mm.updateChannel) {
|
||||
case Const.Value.STABLE_CHANNEL:
|
||||
jsonStr = WebService.getString(Const.Url.STABLE_URL);
|
||||
@ -32,8 +32,9 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
||||
case Const.Value.BETA_CHANNEL:
|
||||
jsonStr = WebService.getString(Const.Url.BETA_URL);
|
||||
break;
|
||||
default:
|
||||
jsonStr = null;
|
||||
case Const.Value.CUSTOM_CHANNEL:
|
||||
jsonStr = WebService.getString(mm.customChannelUrl);
|
||||
break;
|
||||
}
|
||||
try {
|
||||
JSONObject json = new JSONObject(jsonStr);
|
||||
|
@ -68,7 +68,7 @@ public class Const {
|
||||
|
||||
public static class Url {
|
||||
public static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json";
|
||||
public static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json";
|
||||
public static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json";
|
||||
public static final String SNET_URL = "https://www.dropbox.com/s/vbq6y8pzfn4rq60/snet.apk?dl=1";
|
||||
public static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&page=%d";
|
||||
public static final String FILE_URL = "https://raw.githubusercontent.com/Magisk-Modules-Repo/%s/master/%s";
|
||||
@ -104,6 +104,7 @@ public class Const {
|
||||
// others
|
||||
public static final String UPDATE_NOTIFICATION = "notification";
|
||||
public static final String UPDATE_CHANNEL = "update_channel";
|
||||
public static final String CUSTOM_CHANNEL = "custom_channel";
|
||||
public static final String BOOT_FORMAT = "boot_format";
|
||||
public static final String SNET_VER = "snet_version";
|
||||
public static final String UPDATE_SERVICE_VER = "update_service_version";
|
||||
@ -121,6 +122,7 @@ public class Const {
|
||||
public static class Value {
|
||||
public static final int STABLE_CHANNEL = 0;
|
||||
public static final int BETA_CHANNEL = 1;
|
||||
public static final int CUSTOM_CHANNEL = 2;
|
||||
public static final int ROOT_ACCESS_DISABLED = 0;
|
||||
public static final int ROOT_ACCESS_APPS_ONLY = 1;
|
||||
public static final int ROOT_ACCESS_ADB_ONLY = 2;
|
||||
|
@ -244,4 +244,10 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int dpInPx(int dp) {
|
||||
Context context = MagiskManager.get();
|
||||
float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) (dp * scale + 0.5);
|
||||
}
|
||||
}
|
@ -9,12 +9,7 @@
|
||||
android:id="@+id/message_panel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="12dip"
|
||||
android:paddingEnd="20dip"
|
||||
android:paddingStart="20dip"
|
||||
@ -28,8 +23,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5dip" />
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ViewStub
|
||||
|
@ -75,6 +75,7 @@
|
||||
<string-array name="update_channel">
|
||||
<item>@string/settings_update_stable</item>
|
||||
<item>@string/settings_update_beta</item>
|
||||
<item>@string/settings_update_custom</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="boot_formats">
|
||||
|
@ -135,6 +135,8 @@
|
||||
<string name="settings_update_channel_title">Update Channel</string>
|
||||
<string name="settings_update_stable">Stable</string>
|
||||
<string name="settings_update_beta">Beta</string>
|
||||
<string name="settings_update_custom">Custom</string>
|
||||
<string name="settings_update_custom_msg">Insert a custom URL</string>
|
||||
<string name="settings_boot_format_title">Patched Boot Output Format</string>
|
||||
<string name="settings_boot_format_summary">Select the format of the output patched boot image.\nChoose .img to flash through fastboot/download mode; choose .img.tar to flash with ODIN.</string>
|
||||
<string name="settings_core_only_title">Magisk Core Only Mode</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user