Sunflower v2.7.0版本的 MD5 值为:0696e8ce118febedd4bd019622cb23b1
以下内容为反编译后的 Browser.java 源代码,内容仅作参考
package im.grnuohmoqd.messenger.browser;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import im.grnuohmoqd.messenger.AndroidUtilities;
import im.grnuohmoqd.messenger.ApplicationLoader;
import im.grnuohmoqd.messenger.BuildVars;
import im.grnuohmoqd.messenger.CustomTabsCopyReceiver;
import im.grnuohmoqd.messenger.FileLog;
import im.grnuohmoqd.messenger.LocaleController;
import im.grnuohmoqd.messenger.NotificationCenter;
import im.grnuohmoqd.messenger.R;
import im.grnuohmoqd.messenger.ShareBroadcastReceiver;
import im.grnuohmoqd.messenger.SharedConfig;
import im.grnuohmoqd.messenger.UserConfig;
import im.grnuohmoqd.messenger.support.customtabs.CustomTabsCallback;
import im.grnuohmoqd.messenger.support.customtabs.CustomTabsClient;
import im.grnuohmoqd.messenger.support.customtabs.CustomTabsIntent;
import im.grnuohmoqd.messenger.support.customtabs.CustomTabsServiceConnection;
import im.grnuohmoqd.messenger.support.customtabs.CustomTabsSession;
import im.grnuohmoqd.messenger.support.customtabsclient.shared.CustomTabsHelper;
import im.grnuohmoqd.messenger.support.customtabsclient.shared.ServiceConnection;
import im.grnuohmoqd.messenger.support.customtabsclient.shared.ServiceConnectionCallback;
import im.grnuohmoqd.tgnet.ConnectionsManager;
import im.grnuohmoqd.tgnet.RequestDelegate;
import im.grnuohmoqd.tgnet.TLObject;
import im.grnuohmoqd.tgnet.TLRPC;
import im.grnuohmoqd.ui.LaunchActivity;
import im.grnuohmoqd.ui.actionbar.AlertDialog;
import im.grnuohmoqd.ui.actionbar.Theme;
import java.lang.ref.WeakReference;
import java.util.List;
public class Browser {
private static WeakReference<Activity> currentCustomTabsActivity;
private static CustomTabsClient customTabsClient;
private static WeakReference<CustomTabsSession> customTabsCurrentSession;
private static String customTabsPackageToBind;
private static CustomTabsServiceConnection customTabsServiceConnection;
private static CustomTabsSession customTabsSession;
private static CustomTabsSession getCurrentSession() {
WeakReference<CustomTabsSession> weakReference = customTabsCurrentSession;
if (weakReference == null) {
return null;
}
return weakReference.get();
}
private static void setCurrentSession(CustomTabsSession customTabsSession2) {
customTabsCurrentSession = new WeakReference<>(customTabsSession2);
}
private static CustomTabsSession getSession() {
CustomTabsClient customTabsClient2 = customTabsClient;
if (customTabsClient2 == null) {
customTabsSession = null;
} else if (customTabsSession == null) {
CustomTabsSession newSession = customTabsClient2.newSession(new NavigationCallback());
customTabsSession = newSession;
setCurrentSession(newSession);
}
return customTabsSession;
}
public static void bindCustomTabsService(Activity activity) {
WeakReference<Activity> weakReference = currentCustomTabsActivity;
Activity activity2 = weakReference == null ? null : weakReference.get();
if (activity2 != null && activity2 != activity) {
unbindCustomTabsService(activity2);
}
if (customTabsClient != null) {
return;
}
currentCustomTabsActivity = new WeakReference<>(activity);
try {
if (TextUtils.isEmpty(customTabsPackageToBind)) {
String packageNameToUse = CustomTabsHelper.getPackageNameToUse(activity);
customTabsPackageToBind = packageNameToUse;
if (packageNameToUse == null) {
return;
}
}
ServiceConnection serviceConnection = new ServiceConnection(new ServiceConnectionCallback() {
@Override
public void onServiceConnected(CustomTabsClient customTabsClient2) {
CustomTabsClient unused = Browser.customTabsClient = customTabsClient2;
if (!SharedConfig.customTabs || Browser.customTabsClient == null) {
return;
}
try {
Browser.customTabsClient.warmup(0L);
} catch (Exception e) {
FileLog.e(e);
}
}
@Override
public void onServiceDisconnected() {
CustomTabsClient unused = Browser.customTabsClient = null;
}
});
customTabsServiceConnection = serviceConnection;
if (CustomTabsClient.bindCustomTabsService(activity, customTabsPackageToBind, serviceConnection)) {
return;
}
customTabsServiceConnection = null;
} catch (Exception e) {
FileLog.e(e);
}
}
public static void unbindCustomTabsService(Activity activity) {
if (customTabsServiceConnection == null) {
return;
}
WeakReference<Activity> weakReference = currentCustomTabsActivity;
if ((weakReference == null ? null : weakReference.get()) == activity) {
currentCustomTabsActivity.clear();
}
try {
activity.unbindService(customTabsServiceConnection);
} catch (Exception unused) {
}
customTabsClient = null;
customTabsSession = null;
}
public static class NavigationCallback extends CustomTabsCallback {
@Override
public void onNavigationEvent(int i, Bundle bundle) {
}
private NavigationCallback() {
}
}
public static void openUrl(Context context, String str) {
if (str == null) {
return;
}
openUrl(context, Uri.parse(str), true);
}
public static void openUrl(Context context, Uri uri) {
openUrl(context, uri, true);
}
public static void openUrl(Context context, String str, boolean z) {
if (context == null || str == null) {
return;
}
openUrl(context, Uri.parse(str), z);
}
public static void openUrl(Context context, Uri uri, boolean z) {
openUrl(context, uri, z, true);
}
public static void openUrl(Context context, String str, boolean z, boolean z2) {
openUrl(context, Uri.parse(str), z, z2);
}
public static void openUrl(final Context context, final Uri uri, final boolean z, boolean z2) {
String[] strArr;
List<ResolveInfo> queryIntentActivities;
Uri uri2 = uri;
if (context == null || uri2 == null) {
return;
}
final int i = UserConfig.selectedAccount;
boolean[] zArr = {false};
boolean isInternalUri = isInternalUri(uri2, zArr);
if (z2) {
try {
if (uri.getHost().toLowerCase().equals("telegra.ph") || uri.toString().toLowerCase().contains("m12345.cc/faq")) {
final AlertDialog[] alertDialogArr = {new AlertDialog(context, 3)};
TLRPC.TL_messages_getWebPagePreview tL_messages_getWebPagePreview = new TLRPC.TL_messages_getWebPagePreview();
tL_messages_getWebPagePreview.message = uri.toString();
final int sendRequest = ConnectionsManager.getInstance(UserConfig.selectedAccount).sendRequest(tL_messages_getWebPagePreview, new RequestDelegate() {
@Override
public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
Browser.lambda$null$0(r1, tLObject, r3, r4, r5, r6);
}
});
}
});
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
Browser.lambda$openUrl$3(alertDialogArr, sendRequest);
}
}, 1000L);
return;
}
} catch (Exception unused) {
}
}
try {
String lowerCase = uri.getScheme() != null ? uri.getScheme().toLowerCase() : "";
if ("http".equals(lowerCase) || "https".equals(lowerCase)) {
try {
uri2 = uri.normalizeScheme();
} catch (Exception e) {
FileLog.e(e);
}
}
String host = uri2.getHost();
if (z && SharedConfig.customTabs && !isInternalUri && !lowerCase.equals("tel") && host != null && !"www.shareinstall.com.cn".equals(host)) {
List<ResolveInfo> list = null;
try {
queryIntentActivities = context.getPackageManager().queryIntentActivities(new Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com")), 0);
} catch (Exception unused2) {
}
if (queryIntentActivities != null && !queryIntentActivities.isEmpty()) {
strArr = new String[queryIntentActivities.size()];
for (int i2 = 0; i2 < queryIntentActivities.size(); i2++) {
try {
strArr[i2] = queryIntentActivities.get(i2).activityInfo.packageName;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("default browser name = " + strArr[i2]);
}
} catch (Exception unused3) {
}
}
list = context.getPackageManager().queryIntentActivities(new Intent("android.intent.action.VIEW", uri2), 0);
if (strArr == null) {
int i3 = 0;
while (i3 < list.size()) {
int i4 = 0;
while (true) {
if (i4 >= strArr.length) {
break;
}
if (strArr[i4].equals(list.get(i3).activityInfo.packageName)) {
list.remove(i3);
i3--;
break;
}
i4++;
}
i3++;
}
} else {
int i5 = 0;
while (i5 < list.size()) {
if (list.get(i5).activityInfo.packageName.toLowerCase().contains("browser") || list.get(i5).activityInfo.packageName.toLowerCase().contains("chrome")) {
list.remove(i5);
i5--;
}
i5++;
}
}
if (BuildVars.LOGS_ENABLED) {
for (int i6 = 0; i6 < list.size(); i6++) {
FileLog.d("device has " + list.get(i6).activityInfo.packageName + " to open " + uri2.toString());
}
}
if (!zArr[0] || list == null || list.isEmpty()) {
Intent intent = new Intent(ApplicationLoader.applicationContext, (Class<?>) ShareBroadcastReceiver.class);
intent.setAction("android.intent.action.SEND");
PendingIntent broadcast = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, (Class<?>) CustomTabsCopyReceiver.class), 134217728);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getSession());
builder.addMenuItem(LocaleController.getString("CopyLink", R.string.CopyLink), broadcast);
builder.setToolbarColor(Theme.getColor(Theme.key_actionBarBrowser));
builder.setShowTitle(true);
builder.setActionButton(BitmapFactory.decodeResource(context.getResources(), 2131230758), LocaleController.getString("ShareFile", R.string.ShareFile), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 0, intent, 0), false);
CustomTabsIntent build = builder.build();
build.setUseNewTask();
build.launchUrl(context, uri2);
return;
}
}
strArr = null;
list = context.getPackageManager().queryIntentActivities(new Intent("android.intent.action.VIEW", uri2), 0);
if (strArr == null) {
}
if (BuildVars.LOGS_ENABLED) {
}
if (!zArr[0]) {
}
Intent intent2 = new Intent(ApplicationLoader.applicationContext, (Class<?>) ShareBroadcastReceiver.class);
intent2.setAction("android.intent.action.SEND");
PendingIntent broadcast2 = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, (Class<?>) CustomTabsCopyReceiver.class), 134217728);
CustomTabsIntent.Builder builder2 = new CustomTabsIntent.Builder(getSession());
builder2.addMenuItem(LocaleController.getString("CopyLink", R.string.CopyLink), broadcast2);
builder2.setToolbarColor(Theme.getColor(Theme.key_actionBarBrowser));
builder2.setShowTitle(true);
builder2.setActionButton(BitmapFactory.decodeResource(context.getResources(), 2131230758), LocaleController.getString("ShareFile", R.string.ShareFile), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 0, intent2, 0), false);
CustomTabsIntent build2 = builder2.build();
build2.setUseNewTask();
build2.launchUrl(context, uri2);
return;
}
} catch (Exception e2) {
FileLog.e(e2);
}
try {
Intent intent3 = new Intent("android.intent.action.VIEW", uri2);
if (isInternalUri) {
intent3.setComponent(new ComponentName(context.getPackageName(), LaunchActivity.class.getName()));
}
intent3.putExtra("create_new_tab", true);
intent3.putExtra("com.android.browser.application_id", context.getPackageName());
context.startActivity(intent3);
} catch (Exception e3) {
FileLog.e(e3);
}
}
public static void lambda$null$0(AlertDialog[] alertDialogArr, TLObject tLObject, int i, Uri uri, Context context, boolean z) {
try {
alertDialogArr[0].dismiss();
} catch (Throwable unused) {
}
alertDialogArr[0] = null;
boolean z2 = true;
if (tLObject instanceof TLRPC.TL_messageMediaWebPage) {
TLRPC.TL_messageMediaWebPage tL_messageMediaWebPage = (TLRPC.TL_messageMediaWebPage) tLObject;
if ((tL_messageMediaWebPage.webpage instanceof TLRPC.TL_webPage) && tL_messageMediaWebPage.webpage.cached_page != null) {
NotificationCenter.getInstance(i).postNotificationName(NotificationCenter.openArticle, tL_messageMediaWebPage.webpage, uri.toString());
if (z2) {
openUrl(context, uri, z, false);
return;
}
return;
}
}
z2 = false;
if (z2) {
}
}
public static void lambda$openUrl$3(AlertDialog[] alertDialogArr, final int i) {
if (alertDialogArr[0] == null) {
return;
}
try {
alertDialogArr[0].setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public final void onCancel(DialogInterface dialogInterface) {
ConnectionsManager.getInstance(UserConfig.selectedAccount).cancelRequest(i, true);
}
});
alertDialogArr[0].show();
} catch (Exception unused) {
}
}
public static boolean isPassportUrl(String str) {
String lowerCase;
if (str == null) {
return false;
}
try {
lowerCase = str.toLowerCase();
} catch (Throwable unused) {
}
if (lowerCase.startsWith("hchat:passport") || lowerCase.startsWith("hchat://passport") || lowerCase.startsWith("hchat:secureid")) {
return true;
}
if (lowerCase.contains("resolve")) {
if (lowerCase.contains("domain=hchatpassport")) {
return true;
}
}
return false;
}
public static boolean isInternalUrl(String str, boolean[] zArr) {
return isInternalUri(Uri.parse(str), zArr);
}
public static boolean isInternalUri(Uri uri, boolean[] zArr) {
String path;
String host = uri.getHost();
String lowerCase = host != null ? host.toLowerCase() : "";
if ("hchat".equals(uri.getScheme()) || "www.shareinstall.com.cn".equals(lowerCase)) {
return true;
}
if ("m12345.cc".equals(lowerCase) && (path = uri.getPath()) != null && path.length() > 1) {
String lowerCase2 = path.substring(1).toLowerCase();
if (!lowerCase2.startsWith("blog") && !lowerCase2.equals("iv") && !lowerCase2.startsWith("faq") && !lowerCase2.equals("apps") && !lowerCase2.startsWith("s/")) {
return true;
}
if (zArr != null) {
zArr[0] = true;
}
}
return false;
}
}