예제 #1
0
 /**
  * Initializes the java application context.
  *
  * <p>This should be called exactly once early on during startup, before native is loaded and
  * before any other clients make use of the application context through this class.
  *
  * @param appContext The application context.
  */
 public static void initApplicationContext(Context appContext) {
   // Conceding that occasionally in tests, native is loaded before the browser process is
   // started, in which case the browser process re-sets the application context.
   if (sApplicationContext != null && sApplicationContext != appContext) {
     throw new RuntimeException("Attempting to set multiple global application contexts.");
   }
   initJavaSideApplicationContext(appContext);
 }
예제 #2
0
 /**
  * Occasionally tests cannot ensure the application context doesn't change between tests (junit)
  * and sometimes specific tests has its own special needs, initApplicationContext should be used
  * as much as possible, but this method can be used to override it.
  *
  * @param appContext The new application context.
  */
 @VisibleForTesting
 public static void initApplicationContextForTests(Context appContext) {
   initJavaSideApplicationContext(appContext);
   Holder.sSharedPreferences = fetchAppSharedPreferences();
 }