gt:                         if (!ok) {
context: /*
   * This is the source code of Telegram for Android v. 5.x.x.
   * It is licensed under GNU GPL v. 2 or later.
   * You should have received a copy of the license in this archive (see LICENSE).
   *
   * Copyright Nikolai Kudashov, 2013-2018.
   */
  
  package org.telegram.messenger.browser;
  
  import android.app.Activity;
  import android.app.PendingIntent;
  import android.content.ComponentName;
  import android.content.Context;
  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 org.telegram.messenger.AndroidUtilities;
  import org.telegram.messenger.ApplicationLoader;
  import org.telegram.messenger.BuildVars;
  import org.telegram.messenger.CustomTabsCopyReceiver;
  import org.telegram.messenger.FileLog;
  import org.telegram.messenger.LocaleController;
  import org.telegram.messenger.NotificationCenter;
  import org.telegram.messenger.R;
  import org.telegram.messenger.ShareBroadcastReceiver;
  import org.telegram.messenger.SharedConfig;
  import org.telegram.messenger.UserConfig;
  import org.telegram.messenger.support.customtabs.CustomTabsCallback;
  import org.telegram.messenger.support.customtabs.CustomTabsClient;
  import org.telegram.messenger.support.customtabs.CustomTabsIntent;
  import org.telegram.messenger.support.customtabs.CustomTabsServiceConnection;
  import org.telegram.messenger.support.customtabs.CustomTabsSession;
  import org.telegram.messenger.support.customtabsclient.shared.CustomTabsHelper;
  import org.telegram.messenger.support.customtabsclient.shared.ServiceConnection;
  import org.telegram.messenger.support.customtabsclient.shared.ServiceConnectionCallback;
  import org.telegram.tgnet.ConnectionsManager;
  import org.telegram.tgnet.TLRPC;
  import org.telegram.ui.ActionBar.AlertDialog;
  import org.telegram.ui.ActionBar.Theme;
  import org.telegram.ui.LaunchActivity;
  
  import java.lang.ref.WeakReference;
  import java.util.List;
  
  public class Browser {
  
      private static WeakReference<CustomTabsSession> customTabsCurrentSession;
      private static CustomTabsSession customTabsSession;
      private static CustomTabsClient customTabsClient;
      private static CustomTabsServiceConnection customTabsServiceConnection;
      private static String customTabsPackageToBind;
      private static WeakReference<Activity> currentCustomTabsActivity;
  
      private static CustomTabsSession getCurrentSession() {
          return customTabsCurrentSession == null ? null : customTabsCurrentSession.get();
      }
  
      private static void setCurrentSession(CustomTabsSession session) {
          customTabsCurrentSession = new WeakReference<>(session);
      }
  
      private static CustomTabsSession getSession() {
          if (customTabsClient == null) {
              customTabsSession = null;
          } else if (customTabsSession == null) {
              customTabsSession = customTabsClient.newSession(new NavigationCallback());
              setCurrentSession(customTabsSession);
          }
          return customTabsSession;
      }
  
      public static void bindCustomTabsService(Activity activity) {
          Activity currentActivity = currentCustomTabsActivity == null ? null : currentCustomTabsActivity.get();
          if (currentActivity != null && currentActivity != activity) {
              unbindCustomTabsService(currentActivity);
          }
          if (customTabsClient != null) {
              return;
          }
          currentCustomTabsActivity = new WeakReference<>(activity);
          try {
              if (TextUtils.isEmpty(customTabsPackageToBind)) {
                  customTabsPackageToBind = CustomTabsHelper.getPackageNameToUse(activity);
                  if (customTabsPackageToBind == null) {
                      return;
                  }
              }
              customTabsServiceConnection = new ServiceConnection(new ServiceConnectionCallback() {
                  @Override
                  public void onServiceConnected(CustomTabsClient client) {
                      customTabsClient = client;
                      if (SharedConfig.customTabs) {
                          if (customTabsClient != null) {
                              try {
                                  customTabsClient.warmup(0);
                              } catch (Exception e) {
                                  FileLog.e(e);
                              }
                          }
                      }
                  }
  
                  @Override
                  public void onServiceDisconnected() {
                      customTabsClient = null;
                  }
              });
              if (!CustomTabsClient.bindCustomTabsService(activity, customTabsPackageToBind, customTabsServiceConnection)) {
                  customTabsServiceConnection = null;
              }
          } catch (Exception e) {
              FileLog.e(e);
          }
      }
  
      public static void unbindCustomTabsService(Activity activity) {
          if (customTabsServiceConnection == null) {
              return;
          }
          Activity currentActivity = currentCustomTabsActivity == null ? null : currentCustomTabsActivity.get();
          if (currentActivity == activity) {
              currentCustomTabsActivity.clear();
          }
          try {
              activity.unbindService(customTabsServiceConnection);
          } catch (Exception ignore) {
  
          }
          customTabsClient = null;
          customTabsSession = null;
      }
  
      private static class NavigationCallback extends CustomTabsCallback {
          @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(final Context context, final String url, final boolean allowCustom, boolean tryTelegraph) {
          openUrl(context, Uri.parse(url), allowCustom, tryTelegraph);
      }
  
      public static boolean isTelegraphUrl(String url, boolean equals) {
          if (equals) {
              return url.equals("telegra.ph") || url.equals("te.legra.ph") || url.equals("graph.org");
          }
          return url.contains("telegra.ph") || url.contains("te.legra.ph") || url.contains("graph.org");
      }
  
      public static void openUrl(final Context context, Uri uri, final boolean allowCustom, boolean tryTelegraph) {
          if (context == null || uri == null) {
              return;
          }
          final int currentAccount = UserConfig.selectedAccount;
          boolean[] forceBrowser = new boolean[]{false};
          boolean internalUri = isInternalUri(uri, forceBrowser);
          if (tryTelegraph) {
              try {
                  String host = uri.getHost().toLowerCase();
                  if (isTelegraphUrl(host, true) || uri.toString().toLowerCase().contains("telegram.org/faq")) {
                      final AlertDialog[] progressDialog = new AlertDialog[]{new AlertDialog(context, 3)};
  
                      Uri finalUri = uri;
                      TLRPC.TL_messages_getWebPagePreview req = new TLRPC.TL_messages_getWebPagePreview();
                      req.message = uri.toString();
                      final int reqId = ConnectionsManager.getInstance(UserConfig.selectedAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                          try {
                              progressDialog[0].dismiss();
                          } catch (Throwable ignore) {
  
                          }
                          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;
                              }
                          }
  