| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 package org.webrtc; | |
| 12 | |
| 13 import android.content.Context; | |
| 14 import org.webrtc.Logging; | |
| 15 | |
| 16 /** | |
| 17 * Class for storing the application context and retrieving it in a static conte
xt. Similar to | |
| 18 * org.chromium.base.ContextUtils. | |
| 19 */ | |
| 20 public class ContextUtils { | |
| 21 private static final String TAG = "ContextUtils"; | |
| 22 private static Context applicationContext; | |
| 23 | |
| 24 /** | |
| 25 * Stores the application context that will be returned by getApplicationConte
xt. This is called | |
| 26 * by PeerConnectionFactory.initializeAndroidGlobals. | |
| 27 */ | |
| 28 public static void initialize(Context applicationContext) { | |
| 29 if (ContextUtils.applicationContext != null) { | |
| 30 // TODO(sakal): Re-enable after the migration period. | |
| 31 // throw new RuntimeException("Multiple ContextUtils.initialize calls."); | |
| 32 Logging.e( | |
| 33 TAG, "Calling ContextUtils.initialize multiple times, this will crash
in the future!"); | |
| 34 } | |
| 35 if (applicationContext == null) { | |
| 36 throw new RuntimeException("Application context cannot be null for Context
Utils.initialize."); | |
| 37 } | |
| 38 ContextUtils.applicationContext = applicationContext; | |
| 39 } | |
| 40 | |
| 41 /** | |
| 42 * Returns the stored application context. | |
| 43 */ | |
| 44 public static Context getApplicationContext() { | |
| 45 return applicationContext; | |
| 46 } | |
| 47 } | |
| OLD | NEW |