| Index: components/precache/android/java/src/org/chromium/components/precache/NetworkInfoDelegate.java
|
| diff --git a/components/precache/android/java/src/org/chromium/components/precache/NetworkInfoDelegate.java b/components/precache/android/java/src/org/chromium/components/precache/NetworkInfoDelegate.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cda3fee34f404f5d363bef8083fc71af9a306374
|
| --- /dev/null
|
| +++ b/components/precache/android/java/src/org/chromium/components/precache/NetworkInfoDelegate.java
|
| @@ -0,0 +1,61 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.components.precache;
|
| +
|
| +import android.content.Context;
|
| +import android.net.ConnectivityManager;
|
| +import android.net.NetworkInfo;
|
| +import android.os.Build;
|
| +
|
| +import org.chromium.base.VisibleForTesting;
|
| +
|
| +/**
|
| + * Wrapper class for NetworkInfo and ConnectivityManager.
|
| + */
|
| +public class NetworkInfoDelegate {
|
| + private NetworkInfo mNetworkInfo;
|
| + private ConnectivityManager mConnectivityManager;
|
| +
|
| + @VisibleForTesting
|
| + NetworkInfoDelegate() {}
|
| +
|
| + public NetworkInfoDelegate(Context context) {
|
| + getNetworkInfo(context);
|
| + }
|
| +
|
| + protected void getNetworkInfo(Context context) {
|
| + mConnectivityManager =
|
| + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
| + mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
|
| + }
|
| +
|
| + protected boolean isValid() {
|
| + return mNetworkInfo != null;
|
| + }
|
| +
|
| + protected int getType() {
|
| + return mNetworkInfo.getType();
|
| + }
|
| +
|
| + protected boolean isAvailable() {
|
| + return mNetworkInfo.isAvailable();
|
| + }
|
| +
|
| + protected boolean isConnected() {
|
| + return mNetworkInfo.isConnected();
|
| + }
|
| +
|
| + protected boolean isRoaming() {
|
| + return mNetworkInfo.isRoaming();
|
| + }
|
| +
|
| + protected boolean isActiveNetworkMetered() {
|
| + // ConnectivityManager.isActiveNetworkMetered was added in SDK API 16.
|
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
|
| + return false;
|
| + }
|
| + return mConnectivityManager.isActiveNetworkMetered();
|
| + }
|
| +}
|
|
|