正在查看: Plus 12 v10.13.1.1 应用的 Utilities.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Plus 12 v10.13.1.1 应用的 Utilities.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.telegram.messenger;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;
import com.carrotsearch.randomizedtesting.Xoroshiro128PlusRandom;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Collection;
import java.util.HashMap;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.ui.ActionBar.PlusSettings;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Components.Favorite;
import org.telegram.ui.Components.WallpaperUpdater;
import org.telegram.ui.LaunchActivity;
public class Utilities {
private static final String RANDOM_STRING_CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String TAG = "Utilities";
public static volatile DispatchQueue videoPlayerQueue;
public static Pattern pattern = Pattern.compile("[\\-0-9]+");
public static SecureRandom random = new SecureRandom();
public static Random fastRandom = new Xoroshiro128PlusRandom(random.nextLong());
public static volatile DispatchQueue stageQueue = new DispatchQueue("stageQueue");
public static volatile DispatchQueue globalQueue = new DispatchQueue("globalQueue");
public static volatile DispatchQueue cacheClearQueue = new DispatchQueue("cacheClearQueue");
public static volatile DispatchQueue searchQueue = new DispatchQueue("searchQueue");
public static volatile DispatchQueue phoneBookQueue = new DispatchQueue("phoneBookQueue");
public static volatile DispatchQueue themeQueue = new DispatchQueue("themeQueue");
public static volatile DispatchQueue externalNetworkQueue = new DispatchQueue("externalNetworkQueue");
public static final char[] hexArray = "0123456789ABCDEF".toCharArray();
public interface Callback<T> {
void run(T arg);
}
public interface Callback0Return<ReturnType> {
ReturnType run();
}
public interface Callback2<T, T2> {
void run(T arg, T2 arg2);
}
public interface Callback2Return<T1, T2, ReturnType> {
ReturnType run(T1 arg, T2 arg2);
}
public interface Callback3<T, T2, T3> {
void run(T arg, T2 arg2, T3 arg3);
}
public interface Callback3Return<T1, T2, T3, ReturnType> {
ReturnType run(T1 arg, T2 arg2, T3 arg3);
}
public interface Callback4<T, T2, T3, T4> {
void run(T arg, T2 arg2, T3 arg3, T4 arg4);
}
public interface Callback4Return<T, T2, T3, T4, ReturnType> {
ReturnType run(T arg, T2 arg2, T3 arg3, T4 arg4);
}
public interface Callback5<T, T2, T3, T4, T5> {
void run(T arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
}
public interface Callback5Return<T, T2, T3, T4, T5, ReturnType> {
ReturnType run(T arg, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
}
public interface CallbackReturn<Arg, ReturnType> {
ReturnType run(Arg arg);
}
public interface CallbackVoidReturn<ReturnType> {
ReturnType run();
}
public interface IndexedConsumer<T> {
void accept(T t, int index);
}
public static native void aesCbcEncryption(ByteBuffer buffer, byte[] key, byte[] iv, int offset, int length, int encrypt);
private static native void aesCbcEncryptionByteArray(byte[] buffer, byte[] key, byte[] iv, int offset, int length, int n, int encrypt);
public static native void aesCtrDecryption(ByteBuffer buffer, byte[] key, byte[] iv, int offset, int length);
public static native void aesCtrDecryptionByteArray(byte[] buffer, byte[] key, byte[] iv, int offset, long length, int n);
private static native void aesIgeEncryption(ByteBuffer buffer, byte[] key, byte[] iv, boolean encrypt, int offset, int length);
private static native void aesIgeEncryptionByteArray(byte[] buffer, byte[] key, byte[] iv, boolean encrypt, int offset, int length);
public static native void blurBitmap(Object bitmap, int radius, int unpin, int width, int height, int stride);
public static native void calcCDT(ByteBuffer hsvBuffer, int width, int height, ByteBuffer buffer, ByteBuffer calcBuffer);
public static native void clearDir(String path, int docType, long time, boolean subdirs);
public static native int convertVideoFrame(ByteBuffer src, ByteBuffer dest, int destFormat, int width, int height, int padding, int swap);
public static native void drawDitheredGradient(Bitmap bitmap, int[] colors, int startX, int startY, int endX, int endY);
public static native void generateGradient(Bitmap bitmap, boolean unpin, int phase, float progress, int width, int height, int stride, int[] colors);
public static native long getDirSize(String path, int docType, boolean subdirs);
public static String getError(int i) {
String str = i == 0 ? "0: SOURCE FILE DOESN'T EXIST" : "-1";
if (i == 1) {
str = "1: DESTINATION FILE DOESN'T EXIST";
}
if (i == 2) {
str = "2: NULL SOURCE & DESTINATION FILES";
}
if (i == 3) {
str = "3: NULL SOURCE FILE";
}
return i == 4 ? "4" : str;
}
public static native long getLastUsageFileTime(String path);
public static byte[] intToBytes(int value) {
return new byte[]{(byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value};
}
public static native boolean loadWebpImage(Bitmap bitmap, ByteBuffer buffer, int len, BitmapFactory.Options options, boolean unpin);
public static native int needInvert(Object bitmap, int unpin, int width, int height, int stride);
private static native int pbkdf2(byte[] password, byte[] salt, byte[] dst, int iterations);
public static native int pinBitmap(Bitmap bitmap);
public static native String readlink(String path);
public static native String readlinkFd(int fd);
public static native int saveProgressiveJpeg(Bitmap bitmap, int width, int height, int stride, int quality, String path);
public static native void setupNativeCrashesListener(String path);
public static native void stackBlurBitmap(Bitmap bitmap, int radius);
public static native void unpinBitmap(Bitmap bitmap);
static {
try {
FileInputStream fileInputStream = new FileInputStream(new File("/dev/urandom"));
byte[] bArr = new byte[1024];
fileInputStream.read(bArr);
fileInputStream.close();
random.setSeed(bArr);
} catch (Exception e) {
FileLog.e(e);
}
}
public static Bitmap stackBlurBitmapMax(Bitmap bitmap) {
return stackBlurBitmapMax(bitmap, false);
}
public static Bitmap stackBlurBitmapMax(Bitmap bitmap, boolean round) {
int dp = AndroidUtilities.dp(20.0f);
int dp2 = (int) ((AndroidUtilities.dp(20.0f) * bitmap.getHeight()) / bitmap.getWidth());
Bitmap createBitmap = Bitmap.createBitmap(dp, dp2, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(createBitmap);
canvas.save();
canvas.scale(createBitmap.getWidth() / bitmap.getWidth(), createBitmap.getHeight() / bitmap.getHeight());
if (round) {
Path path = new Path();
path.addCircle(bitmap.getWidth() / 2.0f, bitmap.getHeight() / 2.0f, (Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2.0f) - 1.0f, Path.Direction.CW);
canvas.clipPath(path);
}
canvas.drawBitmap(bitmap, 0.0f, 0.0f, (Paint) null);
canvas.restore();
stackBlurBitmap(createBitmap, Math.max(10, Math.max(dp, dp2) / ImageReceiver.DEFAULT_CROSSFADE_DURATION));
return createBitmap;
}
public static Bitmap stackBlurBitmapWithScaleFactor(Bitmap bitmap, float scaleFactor) {
int max = (int) Math.max(AndroidUtilities.dp(20.0f), bitmap.getWidth() / scaleFactor);
int max2 = (int) Math.max((AndroidUtilities.dp(20.0f) * bitmap.getHeight()) / bitmap.getWidth(), bitmap.getHeight() / scaleFactor);
Bitmap createBitmap = Bitmap.createBitmap(max, max2, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(createBitmap);
canvas.save();
canvas.scale(createBitmap.getWidth() / bitmap.getWidth(), createBitmap.getHeight() / bitmap.getHeight());
canvas.drawBitmap(bitmap, 0.0f, 0.0f, (Paint) null);
canvas.restore();
stackBlurBitmap(createBitmap, Math.max(10, Math.max(max, max2) / ImageReceiver.DEFAULT_CROSSFADE_DURATION));
return createBitmap;
}
public static Bitmap blurWallpaper(Bitmap src) {
Bitmap createBitmap;
if (src == null) {
return null;
}
if (src.getHeight() > src.getWidth()) {
createBitmap = Bitmap.createBitmap(Math.round((src.getWidth() * 450.0f) / src.getHeight()), 450, Bitmap.Config.ARGB_8888);
} else {
createBitmap = Bitmap.createBitmap(450, Math.round((src.getHeight() * 450.0f) / src.getWidth()), Bitmap.Config.ARGB_8888);
}
new Canvas(createBitmap).drawBitmap(src, (Rect) null, new Rect(0, 0, createBitmap.getWidth(), createBitmap.getHeight()), new Paint(2));
stackBlurBitmap(createBitmap, 12);
return createBitmap;
}
public static Bitmap blurWallpaper(Bitmap src, int radius) {
Bitmap createBitmap;
if (src == null) {
return null;
}
if (src.getHeight() > src.getWidth()) {
createBitmap = Bitmap.createBitmap(Math.round((src.getWidth() * 450.0f) / src.getHeight()), 450, Bitmap.Config.ARGB_8888);
} else {
createBitmap = Bitmap.createBitmap(450, Math.round((src.getHeight() * 450.0f) / src.getWidth()), Bitmap.Config.ARGB_8888);
}
new Canvas(createBitmap).drawBitmap(src, (Rect) null, new Rect(0, 0, createBitmap.getWidth(), createBitmap.getHeight()), new Paint(2));
stackBlurBitmap(createBitmap, radius);
return createBitmap;
}
public static void aesIgeEncryption(ByteBuffer buffer, byte[] key, byte[] iv, boolean encrypt, boolean changeIv, int offset, int length) {
if (!changeIv) {
iv = (byte[]) iv.clone();
}
aesIgeEncryption(buffer, key, iv, encrypt, offset, length);
}
public static void aesIgeEncryptionByteArray(byte[] buffer, byte[] key, byte[] iv, boolean encrypt, boolean changeIv, int offset, int length) {
if (!changeIv) {
iv = (byte[]) iv.clone();
}
aesIgeEncryptionByteArray(buffer, key, iv, encrypt, offset, length);
}
public static void aesCbcEncryptionByteArraySafe(byte[] buffer, byte[] key, byte[] iv, int offset, int length, int n, int encrypt) {
aesCbcEncryptionByteArray(buffer, key, (byte[]) iv.clone(), offset, length, n, encrypt);
}
public static Integer parseInt(CharSequence value) {
if (value == null) {
return 0;
}
Matcher matcher = pattern.matcher(value);
if (!matcher.find()) {
return 0;
}
return Integer.valueOf(matcher.group());
}
private static int parseInt(final String s) {
boolean z;
int length = s.length();
int i = 0;
char charAt = s.charAt(0);
if (charAt == '-') {
z = false;
} else {
i = '0' - charAt;
z = true;
}
for (int i2 = 1; i2 < length; i2++) {
i = ((i * 10) + 48) - s.charAt(i2);
}
return z ? -i : i;
}
public static Long parseLong(String value) {
long j = 0;
if (value == null) {
return 0L;
}
try {
Matcher matcher = pattern.matcher(value);
if (matcher.find()) {
j = Long.parseLong(matcher.group(0));
}
} catch (Exception unused) {
}
return Long.valueOf(j);
}
public static String parseIntToString(String value) {
Matcher matcher = pattern.matcher(value);
if (matcher.find()) {
return matcher.group(0);
}
return null;
}
public static String bytesToHex(byte[] bytes) {
if (bytes == null) {
return BuildConfig.APP_CENTER_HASH;
}
char[] cArr = new char[bytes.length * 2];
for (int i = 0; i < bytes.length; i++) {
int i2 = bytes[i] & 255;
int i3 = i * 2;
char[] cArr2 = hexArray;
cArr[i3] = cArr2[i2 >>> 4];
cArr[i3 + 1] = cArr2[i2 & 15];
}
return new String(cArr);
}
public static byte[] hexToBytes(String hex) {
if (hex == null) {
return null;
}
int length = hex.length();
byte[] bArr = new byte[length / 2];
for (int i = 0; i < length; i += 2) {
bArr[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16));
}
return bArr;
}
public static boolean isGoodPrime(byte[] prime, int g) {
return ConnectionsManager.native_isGoodPrime(prime, g);
}
public static boolean isGoodGaAndGb(BigInteger g_a, BigInteger p) {
return g_a.compareTo(BigInteger.valueOf(1L)) > 0 && g_a.compareTo(p.subtract(BigInteger.valueOf(1L))) < 0;
}
public static boolean arraysEquals(byte[] arr1, int offset1, byte[] arr2, int offset2) {
if (arr1 == null || arr2 == null || offset1 < 0 || offset2 < 0 || arr1.length - offset1 > arr2.length - offset2 || arr1.length - offset1 < 0 || arr2.length - offset2 < 0) {
return false;
}
boolean z = true;
for (int i = offset1; i < arr1.length; i++) {
if (arr1[i + offset1] != arr2[i + offset2]) {
z = false;
}
}
return z;
}
public static byte[] computeSHA1(byte[] convertme, int offset, int len) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
messageDigest.update(convertme, offset, len);
return messageDigest.digest();
} catch (Exception e) {
FileLog.e(e);
return new byte[20];
}
}
public static byte[] computeSHA1(ByteBuffer convertme, int offset, int len) {
int position = convertme.position();
int limit = convertme.limit();
try {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
convertme.position(offset);
convertme.limit(len);
messageDigest.update(convertme);
return messageDigest.digest();
} catch (Exception e) {
FileLog.e(e);
convertme.limit(limit);
convertme.position(position);
return new byte[20];
}
} finally {
convertme.limit(limit);
convertme.position(position);
}
}
public static byte[] computeSHA1(ByteBuffer convertme) {
return computeSHA1(convertme, 0, convertme.limit());
}
public static byte[] computeSHA1(byte[] convertme) {
return computeSHA1(convertme, 0, convertme.length);
}
public static byte[] computeSHA256(byte[] convertme) {
return computeSHA256(convertme, 0, convertme.length);
}
public static byte[] computeSHA256(byte[] convertme, int offset, long len) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(convertme, offset, (int) len);
return messageDigest.digest();
} catch (Exception e) {
FileLog.e(e);
return new byte[32];
}
}
public static byte[] computeSHA256(byte[]... args) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
for (int i = 0; i < args.length; i++) {
messageDigest.update(args[i], 0, args[i].length);
}
return messageDigest.digest();
} catch (Exception e) {
FileLog.e(e);
return new byte[32];
}
}
public static byte[] computeSHA512(byte[] convertme) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
messageDigest.update(convertme, 0, convertme.length);
return messageDigest.digest();
} catch (Exception e) {
FileLog.e(e);
return new byte[64];
}
}
public static byte[] computeSHA512(byte[] convertme, byte[] convertme2) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
messageDigest.update(convertme, 0, convertme.length);
messageDigest.update(convertme2, 0, convertme2.length);
return messageDigest.digest();
} catch (Exception e) {
FileLog.e(e);
return new byte[64];
}
}
public static byte[] computePBKDF2(byte[] password, byte[] salt) {
byte[] bArr = new byte[64];
pbkdf2(password, salt, bArr, 100000);
return bArr;
}
public static byte[] computeSHA512(byte[] convertme, byte[] convertme2, byte[] convertme3) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
messageDigest.update(convertme, 0, convertme.length);
messageDigest.update(convertme2, 0, convertme2.length);
messageDigest.update(convertme3, 0, convertme3.length);
return messageDigest.digest();
} catch (Exception e) {
FileLog.e(e);
return new byte[64];
}
}
public static byte[] computeSHA256(byte[] b1, int o1, int l1, ByteBuffer b2, int o2, int l2) {
int position = b2.position();
int limit = b2.limit();
try {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(b1, o1, l1);
b2.position(o2);
b2.limit(l2);
messageDigest.update(b2);
return messageDigest.digest();
} catch (Exception e) {
FileLog.e(e);
b2.limit(limit);
b2.position(position);
return new byte[32];
}
} finally {
b2.limit(limit);
b2.position(position);
}
}
public static long bytesToLong(byte[] bytes) {
return (bytes[7] << 56) + ((bytes[6] & 255) << 48) + ((bytes[5] & 255) << 40) + ((bytes[4] & 255) << 32) + ((bytes[3] & 255) << 24) + ((bytes[2] & 255) << 16) + ((bytes[1] & 255) << 8) + (bytes[0] & 255);
}
public static int bytesToInt(byte[] bytes) {
return ((bytes[3] & 255) << 24) + ((bytes[2] & 255) << 16) + ((bytes[1] & 255) << 8) + (bytes[0] & 255);
}
public static String MD5(String md5) {
if (md5 == null) {
return null;
}
try {
byte[] digest = MessageDigest.getInstance("MD5").digest(AndroidUtilities.getStringBytes(md5));
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
sb.append(Integer.toHexString((b & 255) | 256).substring(1, 3));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
FileLog.e(e);
return null;
}
}
public static String SHA256(String x) {
if (x == null) {
return null;
}
try {
byte[] digest = MessageDigest.getInstance("SHA-256").digest(AndroidUtilities.getStringBytes(x));
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
sb.append(Integer.toHexString((b & 255) | 256).substring(1, 3));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
FileLog.e(e);
return null;
}
}
public static int clamp(int value, int maxValue, int minValue) {
return Math.max(Math.min(value, maxValue), minValue);
}
public static long clamp(long value, long maxValue, long minValue) {
return Math.max(Math.min(value, maxValue), minValue);
}
public static float clamp(float value, float maxValue, float minValue) {
return Float.isNaN(value) ? minValue : Float.isInfinite(value) ? maxValue : Math.max(Math.min(value, maxValue), minValue);
}
public static double clamp(double value, double maxValue, double minValue) {
return Double.isNaN(value) ? minValue : Double.isInfinite(value) ? maxValue : Math.max(Math.min(value, maxValue), minValue);
}
public static String generateRandomString() {
return generateRandomString(16);
}
public static String generateRandomString(int chars) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < chars; i++) {
sb.append(RANDOM_STRING_CHARS.charAt(fastRandom.nextInt(62)));
}
return sb.toString();
}
public static String getExtension(String fileName) {
int lastIndexOf = fileName.lastIndexOf(46);
String substring = lastIndexOf != -1 ? fileName.substring(lastIndexOf + 1) : null;
if (substring == null) {
return null;
}
return substring.toUpperCase();
}
public static <Key, Value> Value getOrDefault(HashMap<Key, Value> map, Key key, Value defaultValue) {
Value value = map.get(key);
return value == null ? defaultValue : value;
}
public static void doCallbacks(Callback<Runnable>... actions) {
doCallbacks(0, actions);
}
private static void doCallbacks(final int i, final Callback<Runnable>... actions) {
if (actions == null || actions.length <= i) {
return;
}
actions[i].run(new Runnable() {
@Override
public final void run() {
Utilities.lambda$doCallbacks$0(i, actions);
}
});
}
public static void lambda$doCallbacks$0(int i, Callback[] callbackArr) {
doCallbacks(i + 1, callbackArr);
}
public static void raceCallbacks(final Runnable onFinish, final Callback<Runnable>... actions) {
if (actions == null || actions.length == 0) {
if (onFinish != null) {
onFinish.run();
}
} else {
final int[] iArr = {0};
Runnable runnable = new Runnable() {
@Override
public final void run() {
Utilities.lambda$raceCallbacks$1(iArr, actions, onFinish);
}
};
for (Callback<Runnable> callback : actions) {
callback.run(runnable);
}
}
}
public static void lambda$raceCallbacks$1(int[] iArr, Callback[] callbackArr, Runnable runnable) {
iArr[0] = iArr[0] + 1;
if (iArr[0] != callbackArr.length || runnable == null) {
return;
}
runnable.run();
}
public static DispatchQueue getOrCreatePlayerQueue() {
if (videoPlayerQueue == null) {
videoPlayerQueue = new DispatchQueue("playerQueue");
}
return videoPlayerQueue;
}
public static boolean isNullOrEmpty(final Collection<?> list) {
return list == null || list.isEmpty();
}
public static void restartApp(int ms) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
Utilities.lambda$restartApp$2();
}
}, ms);
}
public static void lambda$restartApp$2() {
((AlarmManager) ApplicationLoader.applicationContext.getSystemService("alarm")).set(1, System.currentTimeMillis() + 1000, PendingIntent.getActivity(ApplicationLoader.applicationContext, 123456, new Intent(ApplicationLoader.applicationContext, (Class<?>) LaunchActivity.class), 301989888));
System.exit(0);
}
public static void restartApp() {
restartApp(0);
}
public static void savePreferencesToSD(String folder, String prefName, String tName, boolean toast) {
File file = new File(findPrefFolder(ApplicationLoader.applicationContext), prefName);
if (checkSDStatus() <= 1) {
if (toast) {
Toast.makeText(ApplicationLoader.applicationContext, "ERROR: " + ApplicationLoader.applicationContext.getString(R.string.NoMediaMessage), 1).show();
return;
}
return;
}
String telegramPath = ImageLoader.getInstance().getTelegramPath();
if (telegramPath.endsWith(folder)) {
telegramPath = telegramPath.replace(folder, BuildConfig.APP_CENTER_HASH);
}
File file2 = new File(telegramPath, folder);
file2.mkdirs();
File file3 = new File(file2, tName);
String error = getError(copyFile(file, file3, true));
if (error.equalsIgnoreCase("4")) {
if (!toast || file3.getName() == BuildConfig.APP_CENTER_HASH) {
return;
}
PlusUtils.showToast(ApplicationLoader.applicationContext.getString(R.string.SavedTo, file3.getName(), folder));
return;
}
if (error.contains("0")) {
if (toast) {
PlusUtils.showToast("ERROR: " + ApplicationLoader.applicationContext.getString(R.string.SaveErrorMsg0));
return;
}
return;
}
if (toast) {
PlusUtils.showToast("ERROR: " + error);
PlusUtils.showToast(file.getAbsolutePath());
}
}
public static void copyWallpaperToSD(Context context, String tName, boolean toast) {
if (checkSDStatus() > 0) {
try {
File file = new File(ApplicationLoader.getFilesDirFixed(), Theme.getActiveTheme().overrideWallpaper.fileName);
if (!file.exists() || file.length() <= 1) {
return;
}
StringBuilder sb = new StringBuilder();
sb.append(PlusSettings.usePlusFolder() ? "/Plus" : "/Telegram");
sb.append("/Themes");
String sb2 = sb.toString();
String telegramPath = ImageLoader.getInstance().getTelegramPath();
if (telegramPath.endsWith(sb2)) {
telegramPath = telegramPath.replace(sb2, BuildConfig.APP_CENTER_HASH);
}
File file2 = new File(telegramPath, sb2);
file2.mkdirs();
File file3 = new File(file2, tName + "_wallpaper.jpg");
String error = getError(copyFile(file, file3, true));
if (error.contains("4")) {
if (toast && file3.getName() != BuildConfig.APP_CENTER_HASH && sb2 != BuildConfig.APP_CENTER_HASH) {
Toast.makeText(context, context.getString(R.string.SavedTo, file3.getName(), sb2), 0).show();
}
if (file3.getName() == BuildConfig.APP_CENTER_HASH || sb2 == BuildConfig.APP_CENTER_HASH) {
Toast.makeText(context, "ERROR: " + error, 0).show();
return;
}
return;
}
Toast.makeText(context, "ERROR: " + error + "\n" + file.getAbsolutePath(), 1).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void saveDBToSD(String folder, String dbIn, String dbOut, boolean toast) {
Context context = ApplicationLoader.applicationContext;
File databasePath = context.getDatabasePath(dbIn);
if (checkSDStatus() > 1) {
String telegramPath = ImageLoader.getInstance().getTelegramPath();
if (telegramPath.endsWith(folder)) {
telegramPath = telegramPath.replace(folder, BuildConfig.APP_CENTER_HASH);
}
File file = new File(telegramPath, folder);
file.mkdirs();
File file2 = new File(file, dbOut);
String error = getError(copyFile(databasePath, file2, true));
try {
if (error.equalsIgnoreCase("4")) {
if (toast && file2.getName() != BuildConfig.APP_CENTER_HASH) {
Toast.makeText(context, context.getString(R.string.SavedTo, file2.getName(), folder), 0).show();
}
} else if (error.contains("0")) {
Toast.makeText(context, "ERROR: " + context.getString(R.string.SaveErrorMsg0), 1).show();
} else {
Toast.makeText(context, "ERROR: " + error, 1).show();
Toast.makeText(context, databasePath.getAbsolutePath(), 1).show();
}
return;
} catch (Exception e) {
e.printStackTrace();
return;
}
}
Toast.makeText(context, "ERROR: " + context.getString(R.string.NoMediaMessage), 1).show();
}
public static int savePreferencesToCache(String prefName, String tName) {
Context context = ApplicationLoader.applicationContext;
File file = new File(findPrefFolder(context), prefName);
if (checkSDStatus() > 1) {
return copyFile(file, new File(context.getCacheDir(), tName), true);
}
return -1;
}
public static int saveDBToCache(String dbIn, String dbOut) {
Context context = ApplicationLoader.applicationContext;
File databasePath = context.getDatabasePath(dbIn);
if (checkSDStatus() > 1) {
return copyFile(databasePath, new File(context.getCacheDir(), dbOut), true);
}
return -1;
}
public static String findPrefFolder(Context context) {
String absolutePath = context.getFilesDir().getAbsolutePath();
File file = new File(absolutePath.substring(0, absolutePath.lastIndexOf(47) + 1) + "shared_prefs/");
if (!file.exists()) {
file = new File("/dbdata/databases/" + context.getPackageName() + "/shared_prefs/");
}
return file.getAbsolutePath();
}
public static int loadPrefFromSD(String prefPath, String name) {
return copyFile(new File(prefPath), new File(getPrefsFolder(), name + ".xml"), false);
}
public static int copyFile(String fileIn, String fileOut) {
return copyFile(new File(fileIn), new File(fileOut), false);
}
public static File savePrefFromSD(String prefPath, String name) {
File file = new File(getPrefsFolder(), name + ".xml");
int copyFile = copyFile(new File(prefPath), file, false);
getError(copyFile);
if (copyFile == 4) {
return file;
}
return null;
}
private static String getPrefsFolder() {
String absolutePath = ApplicationLoader.getFilesDirFixed().getAbsolutePath();
File file = new File(absolutePath.substring(0, absolutePath.lastIndexOf(47) + 1) + "shared_prefs/");
if (!file.exists()) {
file = new File("/dbdata/databases/" + ApplicationLoader.applicationContext.getPackageName() + "/shared_prefs/");
}
return file.getAbsolutePath();
}
private static int checkSDStatus() {
String externalStorageState = Environment.getExternalStorageState();
if (externalStorageState.equals("mounted")) {
return 2;
}
return externalStorageState.equals("mounted_ro") ? 1 : 0;
}
private static int copyFile(File sourceFile, File destFile, boolean save) {
try {
} catch (Exception e) {
System.err.println("Error saving preferences: " + e.getMessage());
Log.e("Error", e.toString());
}
if (!sourceFile.exists()) {
return 0;
}
if (!destFile.exists()) {
r0 = save ? 1 : -1;
destFile.createNewFile();
}
FileInputStream fileInputStream = new FileInputStream(sourceFile);
FileChannel channel = fileInputStream.getChannel();
FileOutputStream fileOutputStream = new FileOutputStream(destFile);
FileChannel channel2 = fileOutputStream.getChannel();
if (channel2 != null && channel != null) {
channel2.transferFrom(channel, 0L, channel.size());
r0 = 2;
}
if (channel != null) {
channel.close();
r0 = 3;
}
if (channel2 != null) {
channel2.close();
r0 = 4;
}
fileInputStream.close();
fileOutputStream.close();
return r0;
}
public static void applyWallpaperWithUpdater(Activity activity) {
new WallpaperUpdater(activity, null, new WallpaperUpdater.WallpaperUpdaterDelegate() {
@Override
public void needOpenColorPicker() {
}
@Override
public void didSelectWallpaper(File file, Bitmap bitmap, boolean gallery) {
Theme.setThemeWallpaper((Theme.ThemeInfo) null, bitmap, file);
}
});
}
public static void applyWallpaper(java.lang.String r5) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.Utilities.applyWallpaper(java.lang.String):void");
}
public static int loadPrefFromSD(Context context, String prefPath) {
File file = new File(findPrefFolder(context), "theme.xml");
File file2 = new File(prefPath);
int copyFile = copyFile(file2, file, false);
String error = getError(copyFile);
if (copyFile != 4) {
StringBuilder sb = new StringBuilder();
sb.append("ERROR: ");
sb.append(error);
sb.append("\n");
int i = R.string.restoreErrorMsg;
Object[] objArr = new Object[1];
objArr[0] = copyFile == 0 ? file2.getAbsolutePath() : file.getAbsolutePath();
sb.append(context.getString(i, objArr));
Toast.makeText(context, sb.toString(), 1).show();
}
return copyFile;
}
public static int loadPrefFromSD(Context context, String prefPath, String name, boolean toast) {
File file = new File(findPrefFolder(context), name + ".xml");
File file2 = new File(prefPath);
int copyFile = copyFile(file2, file, false);
if (toast) {
String error = getError(copyFile);
if (copyFile != 4) {
Toast.makeText(context, "ERROR: " + error + "\n" + context.getString(R.string.restoreErrorMsg, file2.getAbsolutePath()), 1).show();
}
}
return copyFile;
}
public static int deletePrefFile(Context context, String name) {
File file = new File(findPrefFolder(context), name + ".xml");
if (!file.exists()) {
return 0;
}
file.delete();
return 1;
}
public static int loadDBFromSD(String sdPath, String name) {
if (Favorite.getInstance(UserConfig.selectedAccount).getCount() == 0) {
Favorite.getInstance(UserConfig.selectedAccount).addFavorite(-1L);
Favorite.getInstance(UserConfig.selectedAccount).deleteFavorite(-1L);
}
File file = new File(ApplicationLoader.applicationContext.getDatabasePath(name).getAbsolutePath());
File file2 = new File(sdPath);
int copyFile = copyFile(file2, file, false);
String error = getError(copyFile);
if (copyFile != 4) {
Toast.makeText(ApplicationLoader.applicationContext, "ERROR: " + error + "\n" + ApplicationLoader.applicationContext.getString(R.string.restoreErrorMsg, file2.getAbsolutePath()), 1).show();
}
return copyFile;
}
public static int loadPrefFromCache(String cacheName, String name, boolean delete) {
File file = new File(findPrefFolder(ApplicationLoader.applicationContext), name + ".xml");
File file2 = new File(ApplicationLoader.applicationContext.getCacheDir(), cacheName);
int copyFile = copyFile(file2, file, false);
String error = getError(copyFile);
if (copyFile != 4) {
Toast.makeText(ApplicationLoader.applicationContext, "ERROR: " + error + "\n" + ApplicationLoader.applicationContext.getString(R.string.restoreErrorMsg, file2.getAbsolutePath()), 1).show();
}
if (delete) {
file2.delete();
}
return copyFile;
}
public static int loadDBFromCache(String cacheName, String dbName, boolean delete) {
File file = new File(ApplicationLoader.applicationContext.getDatabasePath(dbName).getAbsolutePath());
File file2 = new File(ApplicationLoader.applicationContext.getCacheDir(), cacheName);
int copyFile = copyFile(file2, file, false);
String error = getError(copyFile);
if (copyFile != 4) {
Toast.makeText(ApplicationLoader.applicationContext, "ERROR: " + error + "\n" + ApplicationLoader.applicationContext.getString(R.string.restoreErrorMsg, file2.getAbsolutePath()), 1).show();
}
if (delete) {
file2.delete();
}
return copyFile;
}
public static String isPlusThemeFile(File file) {
try {
String str = getXmlFileStrings(file).get("themeName");
if (str == null) {
return null;
}
if (str.length() > 0) {
return str;
}
return null;
} catch (Exception e) {
FileLog.e(e);
return null;
}
}
public static String isPlusSettingsFile(File file) {
try {
String str = getXmlFileStrings(file).get("tabs_list");
if (str != null && str.length() > 0 && !str.contains("&")) {
if (!str.contains("|")) {
return str;
}
}
return null;
} catch (Exception e) {
FileLog.e(e);
}
return null;
}
public static String applyThemeFile(File file) {
try {
HashMap<String, String> xmlFileStrings = getXmlFileStrings(file);
String absolutePath = file.getAbsolutePath();
String str = xmlFileStrings.get("themeName");
if (str == null || str.length() <= 0 || loadPrefFromSD(ApplicationLoader.applicationContext, absolutePath) != 4) {
return BuildConfig.APP_CENTER_HASH;
}
String str2 = absolutePath.substring(0, absolutePath.lastIndexOf(".")) + "_wallpaper.jpg";
if (new File(str2).exists()) {
SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", 0);
if (sharedPreferences.getInt("selectedBackground", 1000001) == 1000001) {
SharedPreferences.Editor edit = sharedPreferences.edit();
edit.putInt("selectedBackground", R.styleable.AppCompatTheme_toolbarStyle);
edit.putInt("selectedColor", 0);
edit.commit();
}
applyWallpaper(str2);
}
return str;
} catch (Exception e) {
FileLog.e(e);
}
return BuildConfig.APP_CENTER_HASH;
}
private static java.util.HashMap<java.lang.String, java.lang.String> getXmlFileStrings(java.io.File r8) {
throw new UnsupportedOperationException("Method not decompiled: org.telegram.messenger.Utilities.getXmlFileStrings(java.io.File):java.util.HashMap");
}
}