Work on SetupWizard

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/263/head
androidacy-user 1 year ago
parent ee4ad76b43
commit ba1357e307

@ -721,12 +721,12 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
@SuppressLint({"InflateParams", "RestrictedApi", "UnspecifiedImmutableFlag", "ApplySharedPref"})
private void checkShowInitialSetup() {
if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "Do setup now");
Log.d("SetupWizard", "Do setup now");
// Check if this is the first launch
SharedPreferences prefs = MainApplication.getSharedPreferences();
boolean firstLaunch = prefs.getBoolean("first_launch", true);
if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "First launch: " + firstLaunch);
Log.d("SetupWizard", "First launch: " + firstLaunch);
if (firstLaunch) {
doSetupNowRunning = true;
// Show setup box
@ -742,12 +742,18 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
builder.setPositiveButton(R.string.setup_button, (dialog, which) -> {
// Set the preferences and pref_first_launch to false
prefs.edit().putBoolean("first_launch", false).putBoolean("pref_background_update_check", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_background_update_check))).isChecked()).putBoolean("pref_crash_reporting", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_crash_reporting))).isChecked()).putBoolean("pref_androidacy_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_androidacy_repo))).isChecked()).putBoolean("pref_magisk_alt_repo_enabled", ((MaterialSwitch) Objects.requireNonNull(((AlertDialog) dialog).findViewById(R.id.setup_magisk_alt_repo))).isChecked()).commit();
// For debug builds, log the preferences
if (BuildConfig.DEBUG) {
Log.d("NoodleDebug", String.format("Setup: Background Update Check: %s, Crash Reporting: %s, Androidacy Repo: %s, Magisk Alt Repo: %s", prefs.getBoolean("pref_background_update_check", false), prefs.getBoolean("pref_crash_reporting", false), prefs.getBoolean("pref_androidacy_repo_enabled", false), prefs.getBoolean("pref_magisk_alt_repo_enabled", false)));
Log.d("SetupWizard", "First launch: " + prefs.getBoolean("first_launch", true));
Log.d("SetupWizard", "Background update check: " + prefs.getBoolean("pref_background_update_check", false));
Log.d("SetupWizard", "Crash reporting: " + prefs.getBoolean("pref_crash_reporting", false));
Log.d("SetupWizard", "Androidacy repo: " + prefs.getBoolean("pref_androidacy_repo_enabled", false));
Log.d("SetupWizard", "Magisk alt repo: " + prefs.getBoolean("pref_magisk_alt_repo_enabled", false));
}
dialog.dismiss();
// Sleep for 100ms. Who knows, it might fix it?
try {
Thread.sleep(500);
Thread.sleep(750);
} catch (InterruptedException e) {
e.printStackTrace();
}
@ -781,7 +787,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
*/
private boolean waitInitialSetupFinished() {
if (BuildConfig.DEBUG)
Log.d("NoodleDebug", "waitInitialSetupFinished");
Log.d("SetupWizard", "waitInitialSetupFinished");
if (doSetupNowRunning)
updateScreenInsets(); // Fix an edge case
try {

@ -13,6 +13,7 @@ import android.text.SpannableStringBuilder;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.StyleRes;
import androidx.core.app.NotificationManagerCompat;
import androidx.emoji2.text.DefaultEmojiCompatConfig;
@ -30,6 +31,7 @@ import com.fox2code.mmm.utils.Http;
import com.fox2code.rosettax.LanguageSwitcher;
import com.topjohnwu.superuser.Shell;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
@ -344,6 +346,41 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
super.onConfigurationChanged(newConfig);
}
@RequiresApi(api = Build.VERSION_CODES.N)
public void clearAppData() {
// Clear app data
try {
// Clearing app data
// We have to manually delete the files and directories
// because the cache directory is not cleared by the following method
File cacheDir = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
cacheDir = this.getDataDir();
}
if (cacheDir != null && cacheDir.isDirectory()) {
String[] children = cacheDir.list();
if (children != null) {
for (String s : children) {
if (BuildConfig.DEBUG) Log.w("MainApplication", "Deleting " + s);
if (!s.equals("lib")) {
new File(cacheDir, s).delete();
}
}
}
}
if (BuildConfig.DEBUG) Log.w("MainApplication", "Deleting cache dir");
this.deleteSharedPreferences("mmm_boot");
this.deleteSharedPreferences("mmm");
this.deleteSharedPreferences("sentry");
this.deleteSharedPreferences("androidacy");
if (BuildConfig.DEBUG) Log.w("MainApplication", "Deleting shared prefs");
this.getPackageManager().clearPackagePreferredActivities(this.getPackageName());
if (BuildConfig.DEBUG) Log.w("MainApplication", "Done clearing app data");
} catch (Exception e) {
Log.e("MainApplication", "Failed to clear app data", e);
}
}
private class Prism4jSwitchTheme implements Prism4jTheme {
private final Prism4jTheme light = new Prism4jThemeDefault(Color.TRANSPARENT);
private final Prism4jTheme dark = new Prism4jThemeDarkula(Color.TRANSPARENT);

@ -760,7 +760,7 @@ public class InstallerActivity extends FoxActivity {
this.progressIndicator.setVisibility(View.GONE);
// This should be improved ?
String reboot_cmd = "/system/bin/svc power reboot || /system/bin/reboot";
String reboot_cmd = "/system/bin/svc power reboot || /system/bin/reboot || setprop sys.powerctl reboot";
this.rebootFloatingButton.setOnClickListener(_view -> {
if (this.warnReboot || MainApplication.shouldPreventReboot()) {
MaterialAlertDialogBuilder builder =
@ -768,9 +768,10 @@ public class InstallerActivity extends FoxActivity {
builder
.setTitle(R.string.install_terminal_reboot_now)
.setMessage(R.string.install_terminal_reboot_now_message)
.setCancelable(false)
.setIcon(R.drawable.ic_reboot_24)
.setPositiveButton(R.string.yes, (x, y) -> Shell.cmd(reboot_cmd).submit())
.setPositiveButton(R.string.ok, (x, y) -> Shell.cmd(reboot_cmd).submit())
.setNegativeButton(R.string.no, (x, y) -> x.dismiss()).show();
} else {
Shell.cmd(reboot_cmd).submit();
@ -801,6 +802,9 @@ public class InstallerActivity extends FoxActivity {
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Config package \"" +
configPkg + "\" missing for installer view");
this.installerTerminal.addLine(String.format(
this.getString(R.string.install_terminal_config_missing),
configPkg));
}
}
}

@ -202,7 +202,7 @@ public class RepoData extends XRepo {
@Override
public boolean isEnabled() {
return MainApplication.getSharedPreferences().getBoolean("pref_" + this.getPreferenceId() + "_enabled", this.isEnabledByDefault());
return this.enabled;
}
@Override

@ -28,6 +28,7 @@ import android.widget.Button;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
@ -159,6 +160,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
}
public static class SettingsFragment extends PreferenceFragmentCompat implements FoxActivity.OnBackPressedCallback {
@RequiresApi(api = Build.VERSION_CODES.N)
@SuppressLint("UnspecifiedImmutableFlag")
@Override
@SuppressWarnings("ConstantConditions")
@ -397,12 +399,30 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
// Hide the pref_crash option if not in debug mode - stop users from purposely crashing the app
Log.d(TAG, String.format("Sentry installed: %s, debug: %s, magisk path: %s",
SentryMain.IS_SENTRY_INSTALLED, BuildConfig.DEBUG, InstallerInitializer.peekMagiskPath()));
Objects.requireNonNull((Preference) findPreference("pref_crash")).setVisible(false);
Objects.requireNonNull((Preference) findPreference("pref_test_crash")).setVisible(false);
// Find pref_clear_data and set it invisible
Objects.requireNonNull((Preference) findPreference("pref_clear_data")).setVisible(false);
} else {
findPreference("pref_crash").setOnPreferenceClickListener(preference -> {
// Hard crash the app
throw new Error("This is a test crash");
});
if (findPreference("pref_test_crash") != null && findPreference("pref_clear_data") != null) {
findPreference("pref_test_crash").setOnPreferenceClickListener(preference -> {
// Hard crash the app
throw new Error("This is a test crash");
});
findPreference("pref_clear_data").setOnPreferenceClickListener(preference -> {
// Clear app data
new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.clear_data_dialogue_title).setMessage(R.string.clear_data_dialogue_message).setPositiveButton(R.string.yes, (dialog, which) -> {
// Clear app data
MainApplication.getINSTANCE().clearAppData();
// Restart app
ProcessHelper.restartApplicationProcess(requireContext());
}).setNegativeButton(R.string.no, (dialog, which) -> {
}).show();
return true;
});
} else {
Log.e(TAG, String.format("Something is null: %s, %s",
findPreference("pref_test_crash"), findPreference("pref_clear_data")));
}
}
if (InstallerInitializer.peekMagiskVersion() < Constants.MAGISK_VER_CODE_INSTALL_COMMAND || !MainApplication.isDeveloper()) {
findPreference("pref_use_magisk_install_command").setVisible(false);

@ -236,5 +236,5 @@
<string name="setup_button_skip">Skip</string>
<string name="low_performance_device_dialogue_title">Enabling blur on lower-end device</string>
<string name="low_performance_device_dialogue_message">You are trying to enable blur on a device that may not perform well with it.\nYou may enable it, but this may lead to a poor user experience and we recommend you don\'t.</string>
<string name="alt_repo_info">This repo has less restrictions and reviews, which may lead to lower quality modules. Pretty barebones but has a lot of modules.</string>
<string name="alt_repo_info">This repo has less restrictions and reviews, which may lead to lower quality modules. Pretty barebones but has a lot of modules.</string><string name="install_terminal_reboot_now_message">You are about to reboot your device. If you\'ve saved your work, hit ok to continue. Otherwise, hit cancel.</string><string name="install_terminal_config_missing">Package %s is missing for module config, so we cannot launch it.</string><string name="clear_app_data">Clear app data</string><string name="clear_data_dialogue_title">Clear app data?</string><string name="clear_data_dialogue_message">You\'re about to clear the app data. Please confirm this action.</string>
</resources>

@ -126,9 +126,15 @@
<!-- Purposely crash the app -->
<Preference
app:icon="@drawable/ic_baseline_bug_report_24"
app:key="pref_crash"
app:key="pref_test_crash"
app:singleLineTitle="false"
app:title="@string/crash" />
<!-- Pref to clear the app data -->
<Preference
app:icon="@drawable/ic_baseline_delete_24"
app:key="pref_clear_data"
app:singleLineTitle="false"
app:title="@string/clear_app_data" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/pref_category_info">

Loading…
Cancel
Save