Fixes for android 4.1

This commit is contained in:
世界 2020-12-25 00:33:17 +08:00
parent 09db5347f6
commit a5326bddde
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
12 changed files with 111 additions and 23 deletions

View File

@ -84,9 +84,12 @@ dependencies {
implementation 'org.dizitart:nitrite'
implementation 'org.dizitart:nitrite-mvstore-adapter'
implementation ('cn.hutool:hutool-crypto:5.5.4') {
implementation ('cn.hutool:hutool-http:5.5.4') {
exclude group: "org.apache.poi"
}
implementation ('cn.hutool:hutool-crypto:5.5.4') {
exclude module: "hutool-core"
}
implementation 'com.jakewharton:process-phoenix:2.0.0'
implementation project(":openpgp-api")

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.nio.charset;
/**
* Constant definitions for the standard {@link Charset Charsets}. These
* charsets are guaranteed to be available on every implementation of the Java
* platform.
*
* @see <a href="Charset#standard">Standard Charsets</a>
* @since 1.7
*/
public final class StandardCharsets {
private StandardCharsets() {
throw new AssertionError("No java.nio.charset.StandardCharsets instances for you!");
}
/**
* Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the
* Unicode character set
*/
public static final Charset US_ASCII = Charset.forName("US-ASCII");
/**
* ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
*/
public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
/**
* Eight-bit UCS Transformation Format
*/
public static final Charset UTF_8 = Charset.forName("UTF-8");
/**
* Sixteen-bit UCS Transformation Format, big-endian byte order
*/
public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
/**
* Sixteen-bit UCS Transformation Format, little-endian byte order
*/
public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
/**
* Sixteen-bit UCS Transformation Format, byte order identified by an
* optional byte-order mark
*/
public static final Charset UTF_16 = Charset.forName("UTF-16");
}

View File

@ -84,6 +84,9 @@ public class ApplicationLoader extends Application {
if (SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
MultiDex.install(this);
}
Thread.currentThread().setUncaughtExceptionHandler((thread, error) -> {
Log.e("nekox", "from " + thread.toString(), error);
});
}
/**

View File

@ -287,7 +287,10 @@ public class Emoji {
String emoji = fixEmoji(EmojiData.data[info.page][info.emojiIndex]);
if (!NekoConfig.useSystemEmoji && EmojiProvider.isFont) {
textPaint.setTypeface(EmojiProvider.getFont());
try {
textPaint.setTypeface(EmojiProvider.getFont());
} catch (RuntimeException ignored) {
}
}
textPaint.setTextSize(b.height() * 0.8f);

View File

@ -10,13 +10,13 @@ package org.telegram.messenger;
import android.util.Log;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.lang.caller.CallerUtil;
import cn.hutool.core.lang.caller.StackTraceCaller;
import cn.hutool.core.util.StrUtil;
public class FileLog {
private final static StackTraceCaller caller = new StackTraceCaller();
public static String getNetworkLogPath() {
if (BuildVars.DEBUG_VERSION) return "/dev/null";
return "";
@ -25,8 +25,7 @@ public class FileLog {
private static String mkTag() {
final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
return StrUtil.subAfter(stackTrace[2].getClassName(), ".", true);
return StrUtil.subAfter(stackTrace[4].getClassName(), ".", true);
}

View File

@ -129,6 +129,7 @@ import org.telegram.ui.Components.ThemeEditorView;
import org.telegram.ui.Components.voip.VoIPHelper;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -928,7 +929,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
SubManager.getSubList().update(subInfo, true);
SharedConfig.reloadProxyList();
} catch (SubInfo.AllTriesFailed allTriesFailed) {
} catch (IOException allTriesFailed) {
FileLog.e(allTriesFailed);

View File

@ -73,6 +73,7 @@ import org.telegram.ui.Components.RecyclerListView;
import org.telegram.ui.Components.URLSpanNoUnderline;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@ -1173,7 +1174,7 @@ public class ProxyListActivity extends BaseFragment implements NotificationCente
subInfo.proxies = subInfo.reloadProxies();
subInfo.lastFetch = System.currentTimeMillis();
} catch (SubInfo.AllTriesFailed allTriesFailed) {
} catch (IOException allTriesFailed) {
if (canceled.get()) return;

View File

@ -33,6 +33,7 @@ import org.telegram.ui.ActionBar.ThemeDescription;
import org.telegram.ui.Components.EditTextBoldCursor;
import org.telegram.ui.Components.LayoutHelper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
@ -265,7 +266,7 @@ public class SubSettingsActivity extends BaseFragment {
subInfo.proxies = subInfo.reloadProxies();
subInfo.lastFetch = System.currentTimeMillis();
} catch (SubInfo.AllTriesFailed allTriesFailed) {
} catch (IOException allTriesFailed) {
if (canceled.get()) return;

View File

@ -1,7 +1,11 @@
package tw.nekomimi.nekogram.sub;
import android.os.Build;
import androidx.annotation.NonNull;
import com.google.android.gms.common.util.HttpUtils;
import org.dizitart.no2.collection.Document;
import org.dizitart.no2.mapper.Mappable;
import org.dizitart.no2.mapper.NitriteMapper;
@ -43,7 +47,7 @@ public class SubInfo implements Mappable {
}
public List<String> reloadProxies() throws AllTriesFailed {
public List<String> reloadProxies() throws IOException {
HashMap<String, Exception> exceptions = new HashMap<>();
@ -51,7 +55,13 @@ public class SubInfo implements Mappable {
try {
String source = HttpUtil.get(url);
String source;
if (Build.VERSION.SDK_INT < 21) {
source = cn.hutool.http.HttpUtil.get(url);
} else {
source = HttpUtil.get(url);
}
return ProxyUtil.parseProxies(source);

View File

@ -16,7 +16,7 @@ object SubManager {
@JvmStatic
val subList by lazy {
database.getRepository(SubInfo::class.java, "proxy_sub").apply {
database.getRepository(SubInfo::class.java, "sub_list").apply {
val public = find(where("id").eq(1L)).firstOrNull()

View File

@ -29,22 +29,20 @@ object GoogleAppTranslator : Translator {
"&tl=" + to +
"&ie=UTF-8&oe=UTF-8&client=at&dt=t&otf=2"
val response = runCatching {
(if (NekoConfig.translationProvider == 2) HttpUtil.okHttpClientNoDoh else HttpUtil.okHttpClient).newCall(Request.Builder().url(url)
.header("User-Agent", "GoogleTranslate/6.14.0.04.343003216 (Linux; U; Android 10; Redmi K20 Pro)").build()).execute()
}.recoverCatching {
HttpUtil.okHttpClientWithCurrProxy.newCall(Request.Builder().url(url).applyUserAgent().build()).execute()
}.getOrThrow()
val response = cn.hutool.http.HttpUtil
.createGet(url)
.header("User-Agent", "GoogleTranslate/6.14.0.04.343003216 (Linux; U; Android 10; Redmi K20 Pro)")
.execute()
if (response.code != 200) {
if (response.status != 200) {
error("HTTP ${response.code} : ${response.body?.string()}")
error("HTTP ${response.status} : ${response.body()}")
}
val result = StringBuilder()
val array = JSONObject(response.body!!.string()).getJSONArray("sentences")
val array = JSONObject(response.body()).getJSONArray("sentences")
for (index in 0 until array.length()) {
result.append(array.getJSONObject(index).getString("trans"))
}

View File

@ -2,6 +2,7 @@ package tw.nekomimi.nekogram.utils
import android.os.Build
import cn.hutool.core.io.resource.ResourceUtil
import okhttp3.internal.closeQuietly
import org.telegram.messenger.ApplicationLoader
import org.telegram.messenger.FileLog
import java.io.File
@ -95,9 +96,9 @@ object FileUtil {
val libDirs = mutableListOf<String>()
ZipFile(ApplicationLoader.applicationContext.applicationInfo.sourceDir).use {
ZipFile(ApplicationLoader.applicationContext.applicationInfo.sourceDir).also {
it.getEntry("lib/") ?: return@use
it.getEntry("lib/") ?: return@also
for (entry in it.entries()) {
@ -109,6 +110,8 @@ object FileUtil {
}
it.closeQuietly()
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {