🦄️ v1.0.0版本的 MD5 值为:4c87b9e954b061221b9d64460ccc9054
以下内容为反编译后的 Browser.java 源代码,内容仅作参考
package im.ugrceipbov.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.ugrceipbov.messenger.AndroidUtilities;
import im.ugrceipbov.messenger.ApplicationLoader;
import im.ugrceipbov.messenger.BuildVars;
import im.ugrceipbov.messenger.CustomTabsCopyReceiver;
import im.ugrceipbov.messenger.FileLog;
import im.ugrceipbov.messenger.LocaleController;
import im.ugrceipbov.messenger.NotificationCenter;
import im.ugrceipbov.messenger.R;
import im.ugrceipbov.messenger.ShareBroadcastReceiver;
import im.ugrceipbov.messenger.SharedConfig;
import im.ugrceipbov.messenger.UserConfig;
import im.ugrceipbov.messenger.support.customtabs.CustomTabsCallback;
import im.ugrceipbov.messenger.support.customtabs.CustomTabsClient;
import im.ugrceipbov.messenger.support.customtabs.CustomTabsIntent;
import im.ugrceipbov.messenger.support.customtabs.CustomTabsServiceConnection;
import im.ugrceipbov.messenger.support.customtabs.CustomTabsSession;
import im.ugrceipbov.messenger.support.customtabsclient.shared.CustomTabsHelper;
import im.ugrceipbov.messenger.support.customtabsclient.shared.ServiceConnection;
import im.ugrceipbov.messenger.support.customtabsclient.shared.ServiceConnectionCallback;
import im.ugrceipbov.tgnet.ConnectionsManager;
import im.ugrceipbov.tgnet.RequestDelegate;
import im.ugrceipbov.tgnet.TLObject;
import im.ugrceipbov.tgnet.TLRPC;
import im.ugrceipbov.ui.LaunchActivity;
import im.ugrceipbov.ui.actionbar.AlertDialog;
import im.ugrceipbov.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 session) {
customTabsCurrentSession = new WeakReference<>(session);
}
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 currentActivity = weakReference == null ? null : weakReference.get();
if (currentActivity != null && currentActivity != activity) {
unbindCustomTabsService(currentActivity);
}
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 client) {
CustomTabsClient unused = Browser.customTabsClient = client;
if (SharedConfig.customTabs && Browser.customTabsClient != null) {
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)) {
customTabsServiceConnection = null;
}
} catch (Exception e) {
FileLog.e(e);
}
}
public static void unbindCustomTabsService(Activity activity) {
if (customTabsServiceConnection == null) {
return;
}
WeakReference<Activity> weakReference = currentCustomTabsActivity;
Activity currentActivity = weakReference == null ? null : weakReference.get();
if (currentActivity == activity) {
currentCustomTabsActivity.clear();
}
try {
activity.unbindService(customTabsServiceConnection);
} catch (Exception e) {
}
customTabsClient = null;
customTabsSession = null;
}
public static class NavigationCallback extends CustomTabsCallback {
private NavigationCallback() {
}
@Override
public void onNavigationEvent(int navigationEvent, Bundle extras) {
}
}
public static void openUrl(Context context, String url) {
if (url == null) {
return;
}
openUrl(context, Uri.parse(url), true);
}
public static void openUrl(Context context, Uri uri) {
openUrl(context, uri, true);
}
public static void openUrl(Context context, String url, boolean allowCustom) {
if (context == null || url == null) {
return;
}
openUrl(context, Uri.parse(url), allowCustom);
}
public static void openUrl(Context context, Uri uri, boolean allowCustom) {
openUrl(context, uri, allowCustom, true);
}
public static void openUrl(Context context, String url, boolean allowCustom, boolean tryTelegraph) {
openUrl(context, Uri.parse(url), allowCustom, tryTelegraph);
}
public static void openUrl(final Context context, final Uri uri, final boolean allowCustom, boolean tryTelegraph) {
String scheme;
Uri uri2 = uri;
if (context == null || uri2 == null) {
return;
}
final int currentAccount = UserConfig.selectedAccount;
boolean[] forceBrowser = {false};
boolean internalUri = isInternalUri(uri2, forceBrowser);
if (tryTelegraph) {
try {
if (!uri.getHost().toLowerCase().equals("telegra.ph") && !uri.toString().toLowerCase().contains("m12345.com/faq")) {
}
final AlertDialog[] progressDialog = {new AlertDialog(context, 3)};
TLRPC.TL_messages_getWebPagePreview req = new TLRPC.TL_messages_getWebPagePreview();
req.message = uri.toString();
final int reqId = ConnectionsManager.getInstance(UserConfig.selectedAccount).sendRequest(req, 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(progressDialog, reqId);
}
}, 1000L);
return;
} catch (Exception e) {
}
}
try {
try {
scheme = uri.getScheme() != null ? uri.getScheme().toLowerCase() : "";
if ("http".equals(scheme) || "https".equals(scheme)) {
try {
uri2 = uri.normalizeScheme();
} catch (Exception e2) {
FileLog.e(e2);
}
}
} catch (Exception e3) {
e = e3;
FileLog.e(e);
Intent intent = new Intent("android.intent.action.VIEW", uri2);
if (internalUri) {
}
intent.putExtra("create_new_tab", true);
intent.putExtra("com.android.browser.application_id", context.getPackageName());
context.startActivity(intent);
}
try {
String host = uri2.getHost();
if (allowCustom && SharedConfig.customTabs && !internalUri && !scheme.equals("tel") && host != null && !"www.shareinstall.com.cn".equals(host)) {
String[] browserPackageNames = null;
try {
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com"));
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(browserIntent, 0);
if (list != null && !list.isEmpty()) {
browserPackageNames = new String[list.size()];
for (int a = 0; a < list.size(); a++) {
browserPackageNames[a] = list.get(a).activityInfo.packageName;
if (BuildVars.LOGS_ENABLED) {
FileLog.d("default browser name = " + browserPackageNames[a]);
}
}
}
} catch (Exception e4) {
}
List<ResolveInfo> allActivities = null;
try {
Intent viewIntent = new Intent("android.intent.action.VIEW", uri2);
allActivities = context.getPackageManager().queryIntentActivities(viewIntent, 0);
if (browserPackageNames != null) {
int a2 = 0;
while (a2 < allActivities.size()) {
int b = 0;
while (true) {
if (b < browserPackageNames.length) {
if (!browserPackageNames[b].equals(allActivities.get(a2).activityInfo.packageName)) {
b++;
} else {
allActivities.remove(a2);
a2--;
break;
}
} else {
break;
}
}
a2++;
}
} else {
int a3 = 0;
while (a3 < allActivities.size()) {
if (allActivities.get(a3).activityInfo.packageName.toLowerCase().contains("browser") || allActivities.get(a3).activityInfo.packageName.toLowerCase().contains("chrome")) {
allActivities.remove(a3);
a3--;
}
a3++;
}
}
if (BuildVars.LOGS_ENABLED) {
for (int a4 = 0; a4 < allActivities.size(); a4++) {
FileLog.d("device has " + allActivities.get(a4).activityInfo.packageName + " to open " + uri2.toString());
}
}
} catch (Exception e5) {
}
if (forceBrowser[0] || allActivities == null || allActivities.isEmpty()) {
Intent share = new Intent(ApplicationLoader.applicationContext, ShareBroadcastReceiver.class);
share.setAction("android.intent.action.SEND");
PendingIntent copy = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, CustomTabsCopyReceiver.class), 134217728);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getSession());
builder.addMenuItem(LocaleController.getString("CopyLink", R.string.CopyLink), copy);
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, share, 0), false);
CustomTabsIntent intent2 = builder.build();
intent2.setUseNewTask();
intent2.launchUrl(context, uri2);
return;
}
}
} catch (Exception e6) {
e = e6;
FileLog.e(e);
Intent intent3 = new Intent("android.intent.action.VIEW", uri2);
if (internalUri) {
}
intent3.putExtra("create_new_tab", true);
intent3.putExtra("com.android.browser.application_id", context.getPackageName());
context.startActivity(intent3);
}
Intent intent32 = new Intent("android.intent.action.VIEW", uri2);
if (internalUri) {
ComponentName componentName = new ComponentName(context.getPackageName(), LaunchActivity.class.getName());
intent32.setComponent(componentName);
}
intent32.putExtra("create_new_tab", true);
intent32.putExtra("com.android.browser.application_id", context.getPackageName());
context.startActivity(intent32);
} catch (Exception e7) {
FileLog.e(e7);
}
}
public static void lambda$null$0(AlertDialog[] progressDialog, TLObject response, int currentAccount, Uri finalUri, Context context, boolean allowCustom) {
try {
progressDialog[0].dismiss();
} catch (Throwable th) {
}
progressDialog[0] = null;
boolean ok = false;
if (response instanceof TLRPC.TL_messageMediaWebPage) {
TLRPC.TL_messageMediaWebPage webPage = (TLRPC.TL_messageMediaWebPage) response;
if ((webPage.webpage instanceof TLRPC.TL_webPage) && webPage.webpage.cached_page != null) {
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.openArticle, webPage.webpage, finalUri.toString());
ok = true;
}
}
if (!ok) {
openUrl(context, finalUri, allowCustom, false);
}
}
public static void lambda$openUrl$3(AlertDialog[] progressDialog, final int reqId) {
if (progressDialog[0] == null) {
return;
}
try {
progressDialog[0].setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public final void onCancel(DialogInterface dialogInterface) {
ConnectionsManager.getInstance(UserConfig.selectedAccount).cancelRequest(reqId, true);
}
});
progressDialog[0].show();
} catch (Exception e) {
}
}
public static boolean isPassportUrl(String url) {
String url2;
if (url == null) {
return false;
}
try {
url2 = url.toLowerCase();
} catch (Throwable th) {
}
if (!url2.startsWith("hchat:passport") && !url2.startsWith("hchat://passport") && !url2.startsWith("hchat:secureid")) {
if (url2.contains("resolve")) {
if (url2.contains("domain=hchatpassport")) {
return true;
}
}
return false;
}
return true;
}
public static boolean isInternalUrl(String url, boolean[] forceBrowser) {
return isInternalUri(Uri.parse(url), forceBrowser);
}
public static boolean isInternalUri(Uri uri, boolean[] forceBrowser) {
String path;
String host = uri.getHost();
String host2 = host != null ? host.toLowerCase() : "";
if ("hchat".equals(uri.getScheme()) || "www.shareinstall.com.cn".equals(host2)) {
return true;
}
if (!"m12345.com".equals(host2) || (path = uri.getPath()) == null || path.length() <= 1) {
return false;
}
String path2 = path.substring(1).toLowerCase();
if (path2.startsWith("blog") || path2.equals("iv") || path2.startsWith("faq") || path2.equals("apps") || path2.startsWith("s/")) {
if (forceBrowser != null) {
forceBrowser[0] = true;
}
return false;
}
return true;
}
}