♬♬ v1.0.0版本的 MD5 值为:04cc17073568ba22bfb83ea139fbe521

以下内容为反编译后的 Browser.java 源代码,内容仅作参考


package im.wgogsutsuz.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.wgogsutsuz.messenger.AndroidUtilities;
import im.wgogsutsuz.messenger.ApplicationLoader;
import im.wgogsutsuz.messenger.BuildVars;
import im.wgogsutsuz.messenger.CustomTabsCopyReceiver;
import im.wgogsutsuz.messenger.FileLog;
import im.wgogsutsuz.messenger.LocaleController;
import im.wgogsutsuz.messenger.NotificationCenter;
import im.wgogsutsuz.messenger.R;
import im.wgogsutsuz.messenger.ShareBroadcastReceiver;
import im.wgogsutsuz.messenger.SharedConfig;
import im.wgogsutsuz.messenger.UserConfig;
import im.wgogsutsuz.messenger.support.customtabs.CustomTabsCallback;
import im.wgogsutsuz.messenger.support.customtabs.CustomTabsClient;
import im.wgogsutsuz.messenger.support.customtabs.CustomTabsIntent;
import im.wgogsutsuz.messenger.support.customtabs.CustomTabsServiceConnection;
import im.wgogsutsuz.messenger.support.customtabs.CustomTabsSession;
import im.wgogsutsuz.messenger.support.customtabsclient.shared.CustomTabsHelper;
import im.wgogsutsuz.messenger.support.customtabsclient.shared.ServiceConnection;
import im.wgogsutsuz.messenger.support.customtabsclient.shared.ServiceConnectionCallback;
import im.wgogsutsuz.tgnet.ConnectionsManager;
import im.wgogsutsuz.tgnet.RequestDelegate;
import im.wgogsutsuz.tgnet.TLObject;
import im.wgogsutsuz.tgnet.TLRPC;
import im.wgogsutsuz.ui.LaunchActivity;
import im.wgogsutsuz.ui.actionbar.AlertDialog;
import im.wgogsutsuz.ui.actionbar.Theme;
import java.lang.ref.WeakReference;
import java.util.List;
import obfuse.NPStringFog;

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;
        String decode = NPStringFog.decode("505F55435E58551F585F45545F451F505245585E5F1F67787466");
        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(NPStringFog.decode("5C00030205041F525E5C1E575040"))) {
                }
                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 {
            scheme = uri.getScheme() != null ? uri.getScheme().toLowerCase() : NPStringFog.decode("");
            if (NPStringFog.decode("59454541").equals(scheme) || NPStringFog.decode("5945454142").equals(scheme)) {
                try {
                    uri2 = uri.normalizeScheme();
                } catch (Exception e2) {
                    FileLog.e(e2);
                }
            }
        } catch (Exception e3) {
            e = e3;
        }
        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(decode, Uri.parse(NPStringFog.decode("594545410B1E1E4646461F565E5E565D541F525E5C")));
                    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(NPStringFog.decode("55545750445D451153435E46425443115F505C54110C11") + browserPackageNames[a]);
                            }
                        }
                    }
                } catch (Exception e4) {
                }
                List<ResolveInfo> allActivities = null;
                try {
                    Intent viewIntent = new Intent(decode, 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) {
                                    break;
                                }
                                if (!browserPackageNames[b].equals(allActivities.get(a2).activityInfo.packageName)) {
                                    b++;
                                } else {
                                    allActivities.remove(a2);
                                    a2--;
                                    break;
                                }
                            }
                            a2++;
                        }
                    } else {
                        int a3 = 0;
                        while (a3 < allActivities.size()) {
                            if (allActivities.get(a3).activityInfo.packageName.toLowerCase().contains(NPStringFog.decode("53435E46425443")) || allActivities.get(a3).activityInfo.packageName.toLowerCase().contains(NPStringFog.decode("5259435E5C54"))) {
                                allActivities.remove(a3);
                                a3--;
                            }
                            a3++;
                        }
                    }
                    if (BuildVars.LOGS_ENABLED) {
                        for (int a4 = 0; a4 < allActivities.size(); a4++) {
                            FileLog.d(NPStringFog.decode("5554475852541159504211") + allActivities.get(a4).activityInfo.packageName + NPStringFog.decode("11455E115E41545F11") + uri2.toString());
                        }
                    }
                } catch (Exception e5) {
                }
                if (forceBrowser[0] || allActivities == null || allActivities.isEmpty()) {
                    Intent share = new Intent(ApplicationLoader.applicationContext, (Class<?>) ShareBroadcastReceiver.class);
                    share.setAction(NPStringFog.decode("505F55435E58551F585F45545F451F505245585E5F1F62747F75"));
                    PendingIntent copy = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, (Class<?>) CustomTabsCopyReceiver.class), 134217728);
                    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getSession());
                    builder.addMenuItem(LocaleController.getString(NPStringFog.decode("725E41487D585F5A"), R.string.CopyLink), copy);
                    builder.setToolbarColor(Theme.getColor(NPStringFog.decode("505245585E5F73504373435E46425443")));
                    builder.setShowTitle(true);
                    builder.setActionButton(BitmapFactory.decodeResource(context.getResources(), R.drawable.abc_ic_menu_share_mtrl_alpha), LocaleController.getString(NPStringFog.decode("625950435477585D54"), R.string.ShareFile), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 0, share, 0), false);
                    CustomTabsIntent intent = builder.build();
                    intent.setUseNewTask();
                    intent.launchUrl(context, uri2);
                    return;
                }
            }
        } catch (Exception e6) {
            e = e6;
            FileLog.e(e);
            Intent intent2 = new Intent(decode, uri2);
            if (internalUri) {
            }
            intent2.putExtra(NPStringFog.decode("5243545045546E5F54466E455053"), true);
            intent2.putExtra(NPStringFog.decode("525E5C1F505F55435E58551F53435E464254431F5041415D58525045585E5F6E5855"), context.getPackageName());
            context.startActivity(intent2);
        }
        try {
            Intent intent22 = new Intent(decode, uri2);
            if (internalUri) {
                ComponentName componentName = new ComponentName(context.getPackageName(), LaunchActivity.class.getName());
                intent22.setComponent(componentName);
            }
            intent22.putExtra(NPStringFog.decode("5243545045546E5F54466E455053"), true);
            intent22.putExtra(NPStringFog.decode("525E5C1F505F55435E58551F53435E464254431F5041415D58525045585E5F6E5855"), context.getPackageName());
            context.startActivity(intent22);
        } 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(NPStringFog.decode("59525950450B41504242415E4345")) && !url2.startsWith(NPStringFog.decode("59525950450B1E1E41504242415E4345")) && !url2.startsWith(NPStringFog.decode("59525950450B4254524443545855"))) {
            if (url2.contains(NPStringFog.decode("4354425E5D4754"))) {
                if (url2.contains(NPStringFog.decode("555E5C50585F0C595259504541504242415E4345"))) {
                    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() : NPStringFog.decode("");
        if (NPStringFog.decode("5952595045").equals(uri.getScheme()) || "www.shareinstall.com.cn".equals(host2)) {
            return true;
        }
        if (!NPStringFog.decode("5C00030205041F525E5C").equals(host2) || (path = uri.getPath()) == null || path.length() <= 1) {
            return false;
        }
        String path2 = path.substring(1).toLowerCase();
        if (!path2.startsWith(NPStringFog.decode("535D5E56")) && !path2.equals(NPStringFog.decode("5847")) && !path2.startsWith(NPStringFog.decode("575040")) && !path2.equals(NPStringFog.decode("50414142")) && !path2.startsWith(NPStringFog.decode("421E"))) {
            return true;
        }
        if (forceBrowser != null) {
            forceBrowser[0] = true;
        }
        return false;
    }
}