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_MOBILE;
20import static android.net.ConnectivityManager.TYPE_MOBILE_DUN;
21import static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI;
22import static android.net.ConnectivityManager.TYPE_MOBILE_MMS;
23import static android.net.ConnectivityManager.TYPE_MOBILE_SUPL;
24import static android.net.ConnectivityManager.TYPE_WIFI;
25import static android.net.ConnectivityManager.TYPE_WIMAX;
26
27import android.net.ConnectivityManager;
28import android.net.NetworkInfo;
29
30/**
31 * Implementation of ConnectivityManagerCompat that can use Gingerbread APIs.
32 */
33class ConnectivityManagerCompatGingerbread {
34    public static boolean isActiveNetworkMetered(ConnectivityManager cm) {
35        final NetworkInfo info = cm.getActiveNetworkInfo();
36        if (info == null) {
37            // err on side of caution
38            return true;
39        }
40
41        final int type = info.getType();
42        switch (type) {
43            case TYPE_MOBILE:
44            case TYPE_MOBILE_DUN:
45            case TYPE_MOBILE_HIPRI:
46            case TYPE_MOBILE_MMS:
47            case TYPE_MOBILE_SUPL:
48            case TYPE_WIMAX:
49                return true;
50            case TYPE_WIFI:
51                return false;
52            default:
53                // err on side of caution
54                return true;
55        }
56    }
57}
58