1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v4.net;
18
19import static android.net.ConnectivityManager.TYPE_BLUETOOTH;
20import static android.net.ConnectivityManager.TYPE_ETHERNET;
21import static android.net.ConnectivityManager.TYPE_MOBILE;
22import static android.net.ConnectivityManager.TYPE_MOBILE_DUN;
23import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI;
24import static android.net.ConnectivityManager.TYPE_MOBILE_MMS;
25import static android.net.ConnectivityManager.TYPE_MOBILE_SUPL;
26import static android.net.ConnectivityManager.TYPE_WIFI;
27import static android.net.ConnectivityManager.TYPE_WIMAX;
28
29import android.net.ConnectivityManager;
30import android.net.NetworkInfo;
31
32/**
33 * Implementation of ConnectivityManagerCompat that can use Honeycomb MR2 APIs.
34 */
35class ConnectivityManagerCompatHoneycombMR2 {
36    public static boolean isActiveNetworkMetered(ConnectivityManager cm) {
37        final NetworkInfo info = cm.getActiveNetworkInfo();
38        if (info == null) {
39            // err on side of caution
40            return true;
41        }
42
43        final int type = info.getType();
44        switch (type) {
45            case TYPE_MOBILE:
46            case TYPE_MOBILE_DUN:
47            case TYPE_MOBILE_HIPRI:
48            case TYPE_MOBILE_MMS:
49            case TYPE_MOBILE_SUPL:
50            case TYPE_WIMAX:
51                return true;
52            case TYPE_WIFI:
53            case TYPE_BLUETOOTH:
54            case TYPE_ETHERNET:
55                return false;
56            default:
57                // err on side of caution
58                return true;
59        }
60    }
61}
62