Esempio n. 1
0
 /**
  * Check the cached value to figure out if the feature is enabled. We have to use the cached value
  * because native library may not yet been loaded.
  *
  * @return Whether the feature is enabled.
  */
 private static boolean isEnabledInPrefs() {
   // Will go away once the feature is enabled for everyone by default.
   StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
   try {
     return ChromePreferenceManager.getInstance(ContextUtils.getApplicationContext())
         .getCachedWebApkRuntimeEnabled();
   } finally {
     StrictMode.setThreadPolicy(oldPolicy);
   }
 }
 /** Caches whether Chrome is set as a default browser on the device. */
 @WorkerThread
 private void cacheIsChromeDefaultBrowser() {
   // Retrieve whether Chrome is default in background to avoid strict mode checks.
   Intent intent =
       new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.madeupdomainforcheck123.com/"));
   ResolveInfo info = mAppContext.getPackageManager().resolveActivity(intent, 0);
   boolean isDefault =
       (info != null
           && info.match != 0
           && mAppContext.getPackageName().equals(info.activityInfo.packageName));
   ChromePreferenceManager.getInstance(mAppContext).setCachedChromeDefaultBrowser(isDefault);
 }
Esempio n. 3
0
  /**
   * Once native is loaded we can consult the command-line (set via about:flags) and also finch
   * state to see if we should enable WebAPKs.
   */
  public static void cacheEnabledStateForNextLaunch() {
    boolean wasEnabled = isEnabledInPrefs();
    CommandLine instance = CommandLine.getInstance();
    String experiment = FieldTrialList.findFullName(WEBAPK_DISABLE_EXPERIMENT_NAME);
    boolean isEnabled =
        (!WEBAPK_RUNTIME_DISABLED.equals(experiment)
            && instance.hasSwitch(ChromeSwitches.ENABLE_WEBAPK));

    if (isEnabled != wasEnabled) {
      Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnabled);
      ChromePreferenceManager.getInstance(ContextUtils.getApplicationContext())
          .setCachedWebApkRuntimeEnabled(isEnabled);
    }
  }