Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mywalkb committed Jul 15, 2023
2 parents 0b79a90 + a483aa3 commit 2cfda57
Show file tree
Hide file tree
Showing 72 changed files with 332 additions and 529 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ android {
}

autoResConfig {
generateClass.set(true)
generateRes.set(false)
generatedClassFullName.set("org.lsposed.manager.util.LangList")
generatedArrayFirstItem.set("SYSTEM")
generateClass = true
generateRes = false
generatedClassFullName = "org.lsposed.manager.util.LangList"
generatedArrayFirstItem = "SYSTEM"
}

materialThemeBuilder {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
<activity
android:name=".ui.activity.CrashReportActivity"
android:process=":error" />

<provider
android:name="androidx.startup.InitializationProvider"
Expand Down
90 changes: 42 additions & 48 deletions app/src/main/java/org/lsposed/manager/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@

package org.lsposed.manager;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.provider.MediaStore;
import android.provider.Settings;
import android.system.Os;
import android.text.TextUtils;
Expand All @@ -43,8 +45,8 @@

import org.lsposed.hiddenapibypass.HiddenApiBypass;
import org.lsposed.manager.adapters.AppHelper;
import org.lsposed.manager.receivers.LSPManagerServiceHolder;
import org.lsposed.manager.repo.RepoLoader;
import org.lsposed.manager.ui.activity.CrashReportActivity;
import org.lsposed.manager.util.CloudflareDNS;
import org.lsposed.manager.util.ModuleUtil;
import org.lsposed.manager.util.ThemeUtil;
Expand All @@ -54,8 +56,8 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -95,23 +97,12 @@ private static String readWebviewHTML(String name) {
var list = AppHelper.getAppList(false);
var pm = App.getInstance().getPackageManager();
list.parallelStream().forEach(i -> AppHelper.getAppLabel(i, pm));
AppHelper.getDenyList(false);
ModuleUtil.getInstance();
RepoLoader.getInstance();
});
return false;
});

Looper.myQueue().addIdleHandler(() -> {
if (App.getInstance() == null || App.getExecutorService() == null) return true;
App.getExecutorService().submit(() -> AppHelper.getDenyList(false));
return false;
});
Looper.myQueue().addIdleHandler(() -> {
if (App.getInstance() == null || App.getExecutorService() == null) return true;
App.getExecutorService().submit(ModuleUtil::getInstance);
return false;
});
Looper.myQueue().addIdleHandler(() -> {
if (App.getInstance() == null || App.getExecutorService() == null) return true;
App.getExecutorService().submit(RepoLoader::getInstance);
App.getExecutorService().submit(HTML_TEMPLATE);
App.getExecutorService().submit(HTML_TEMPLATE_DARK);
return false;
});
}
Expand Down Expand Up @@ -165,41 +156,47 @@ protected void attachBaseContext(Context base) {
}
}

@SuppressLint("WrongConstant")
private void setCrashReport() {
var handler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
String stackTraceString = sw.toString();

//Reduce data to 128KB so we don't get a TransactionTooLargeException when sending the intent.
//The limit is 1MB on Android but some devices seem to have it lower.
//See: http://developer.android.com/reference/android/os/TransactionTooLargeException.html
//And: http://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception#comment46697371_12809171
if (stackTraceString.length() > 131071) {
String disclaimer = " [stack trace too large]";
stackTraceString = stackTraceString.substring(0, 131071 - disclaimer.length()) + disclaimer;
var time = OffsetDateTime.now();
var dir = new File(getCacheDir(), "crash");
//noinspection ResultOfMethodCallIgnored
dir.mkdir();
var file = new File(dir, time.toEpochSecond() + ".log");
try (var pw = new PrintWriter(file)) {
pw.println(BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")");
pw.println(time);
pw.println("pid: " + Os.getpid() + " uid: " + Os.getuid());
throwable.printStackTrace(pw);
} catch (IOException ignored) {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
var table = MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
var values = new ContentValues();
values.put(MediaStore.Downloads.DISPLAY_NAME, "LSPosed_crash_report" + time.toEpochSecond() + ".zip");
values.put(MediaStore.Downloads.RELATIVE_PATH, Environment.DIRECTORY_DOCUMENTS);
var cr = getContentResolver();
var uri = cr.insert(table, values);
if (uri == null) return;
try (var zipFd = cr.openFileDescriptor(uri, "wt")) {
LSPManagerServiceHolder.getService().getLogs(zipFd);
} catch (Exception ignored) {
cr.delete(uri, null, null);
}
}
if (handler != null) {
handler.uncaughtException(thread, throwable);
}
Intent intent = new Intent(App.this, CrashReportActivity.class);
intent.putExtra(BuildConfig.APPLICATION_ID + ".EXTRA_STACK_TRACE", stackTraceString);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
App.this.startActivity(intent);
System.exit(10);
Process.killProcess(Os.getpid());
});
}

@Override
public void onCreate() {
super.onCreate();
if (!BuildConfig.DEBUG && !isParasitic) {
setCrashReport();
}

instance = this;

setCrashReport();
pref = PreferenceManager.getDefaultSharedPreferences(this);
if (!pref.contains("doh")) {
var name = "private_dns_mode";
Expand Down Expand Up @@ -252,17 +249,14 @@ public void onReceive(Context context, Intent inIntent) {
}, intentFilter, Context.RECEIVER_NOT_EXPORTED);

UpdateUtil.loadRemoteVersion();

executorService.submit(HTML_TEMPLATE);
executorService.submit(HTML_TEMPLATE_DARK);
}

@NonNull
public static OkHttpClient getOkHttpClient() {
if (okHttpClient != null) return okHttpClient;
var builder = new OkHttpClient.Builder()
.cache(getOkHttpCache())
.dns(new CloudflareDNS());
.cache(getOkHttpCache())
.dns(new CloudflareDNS());
if (BuildConfig.DEBUG) {
var log = new HttpLoggingInterceptor();
log.setLevel(HttpLoggingInterceptor.Level.HEADERS);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

public static void showIfNeed(FragmentManager fm) {
if (shown) return;
if (!ConfigManager.isBinderAlive()) return;
if (App.getPreferences().getBoolean("never_show_welcome", false)) return;
if (!ConfigManager.isBinderAlive() ||
App.getPreferences().getBoolean("never_show_welcome", false) ||
(App.isParasitic && ShortcutUtil.isLaunchShortcutPinned())) {
shown = true;
return;
}
new WelcomeDialog().show(fm, "welcome");
shown = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ public void onBindViewHolder(@NonNull RepoAdapter.ViewHolder holder, int positio
sb.setSpan(styleSpan, sb.length() - hint.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
}
sb.setSpan(foregroundColorSpan, sb.length() - hint.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
} else if (moduleUtil.getModule(module.getName()) != null) {
String installed = getString(R.string.installed);
sb.append(installed);
final StyleSpan styleSpan = new StyleSpan(Typeface.ITALIC);
sb.setSpan(styleSpan, sb.length() - installed.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourceUtils.resolveColor(requireActivity().getTheme(), com.google.android.material.R.attr.colorSecondary));
sb.setSpan(foregroundColorSpan, sb.length() - installed.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
}
if (sb.length() > 0) {
holder.hint.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
}
}

private void renderGithubMarkdown(WebView view, String text) {
private void renderGithubMarkdown(WebView view, @Nullable String text) {
try {
view.setBackgroundColor(Color.TRANSPARENT);
var setting = view.getSettings();
Expand All @@ -173,6 +173,9 @@ private void renderGithubMarkdown(WebView view, String text) {
} else {
direction = "ltr";
}
if (text == null) {
text = "<center>" + App.getInstance().getString(R.string.list_empty) + "</center>";
}
if (ResourceUtils.isNightMode(getResources().getConfiguration())) {
body = App.HTML_TEMPLATE_DARK.get().replace("@dir@", direction).replace("@body@", text);
} else {
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/org/lsposed/manager/util/ShortcutUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,12 @@ public static boolean updateShortcut() {
public static boolean isLaunchShortcutPinned() {
var context = App.getInstance();
var sm = context.getSystemService(ShortcutManager.class);
boolean pinned = false;
for (var info : sm.getPinnedShortcuts()) {
if (SHORTCUT_ID.equals(info.getId())) {
pinned = true;
break;
return true;
}
}
return pinned;
return false;
}

public static boolean shouldAllowPinShortcut(Context context) {
Expand Down
Loading

0 comments on commit 2cfda57

Please sign in to comment.