Deprecate ContextUtils.getApplicationContext.

Allows passing in the application context to NetworkMonitor in
startMonitoring. The audio code will refactored once it is moved under
sdk/android.

Bug: webrtc:8937
Change-Id: I50c917a845fc4f711899a97d34c04813cc68b68c
Reviewed-on: https://webrtc-review.googlesource.com/58091
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22231}
This commit is contained in:
Sami Kalliomäki
2018-02-27 16:43:13 +01:00
committed by Commit Bot
parent d2ed0a4c9e
commit 9ddc14daca
7 changed files with 75 additions and 16 deletions

View File

@ -83,24 +83,30 @@ public class NetworkMonitor {
* multi-networking. This requires the embedding app have the platform ACCESS_NETWORK_STATE and
* CHANGE_NETWORK_STATE permission.
*/
public void startMonitoring() {
public void startMonitoring(Context applicationContext) {
synchronized (autoDetectorLock) {
++numMonitors;
if (autoDetector == null) {
autoDetector = createAutoDetector(ContextUtils.getApplicationContext());
autoDetector = createAutoDetector(applicationContext);
}
currentConnectionType =
NetworkMonitorAutoDetect.getConnectionType(autoDetector.getCurrentNetworkState());
}
}
/** Deprecated, pass in application context in startMonitoring instead. */
@Deprecated
public void startMonitoring() {
startMonitoring(ContextUtils.getApplicationContext());
}
/**
* Enables auto detection of the network state change and brings up mobile networks for using
* multi-networking. This requires the embedding app have the platform ACCESS_NETWORK_STATE and
* CHANGE_NETWORK_STATE permission.
*/
@CalledByNative
private void startMonitoring(long nativeObserver) {
private void startMonitoring(Context applicationContext, long nativeObserver) {
Logging.d(TAG, "Start monitoring with native observer " + nativeObserver);
startMonitoring();
@ -213,21 +219,31 @@ public class NetworkMonitor {
nativeNotifyOfActiveNetworkList(nativeObserver, networkInfos);
}
/** Adds an observer for any connection type changes. */
/**
* Adds an observer for any connection type changes.
*
* @deprecated Use getInstance(appContext).addObserver instead.
*/
@Deprecated
public static void addNetworkObserver(NetworkObserver observer) {
getInstance().addNetworkObserverInternal(observer);
getInstance().addObserver(observer);
}
private void addNetworkObserverInternal(NetworkObserver observer) {
public void addObserver(NetworkObserver observer) {
networkObservers.add(observer);
}
/** Removes an observer for any connection type changes. */
/**
* Removes an observer for any connection type changes.
*
* @deprecated Use getInstance(appContext).removeObserver instead.
*/
@Deprecated
public static void removeNetworkObserver(NetworkObserver observer) {
getInstance().removeNetworkObserverInternal(observer);
getInstance().removeObserver(observer);
}
private void removeNetworkObserverInternal(NetworkObserver observer) {
public void removeObserver(NetworkObserver observer) {
networkObservers.remove(observer);
}