15d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey/* 25d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * Copyright (C) 2012 The Android Open Source Project 35d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * 45d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License"); 55d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * you may not use this file except in compliance with the License. 65d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * You may obtain a copy of the License at 75d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * 85d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * http://www.apache.org/licenses/LICENSE-2.0 95d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * 105d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * Unless required by applicable law or agreed to in writing, software 115d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS, 125d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * See the License for the specific language governing permissions and 145d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * limitations under the License. 155d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey */ 165d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey 175d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeypackage android.support.v4.net; 185d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey 195d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeyimport static android.net.ConnectivityManager.TYPE_MOBILE; 205d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeyimport static android.net.ConnectivityManager.TYPE_MOBILE_DUN; 215d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeyimport static android.net.ConnectivityManager.TYPE_MOBILE_HIPRI; 225d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeyimport static android.net.ConnectivityManager.TYPE_MOBILE_MMS; 235d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeyimport static android.net.ConnectivityManager.TYPE_MOBILE_SUPL; 245d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeyimport static android.net.ConnectivityManager.TYPE_WIFI; 255d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeyimport static android.net.ConnectivityManager.TYPE_WIMAX; 265d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey 275d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeyimport android.net.ConnectivityManager; 285d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeyimport android.net.NetworkInfo; 295d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey 305d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey/** 315d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey * Implementation of ConnectivityManagerCompat that can use Gingerbread APIs. 325d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey */ 335d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkeyclass ConnectivityManagerCompatGingerbread { 345d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey public static boolean isActiveNetworkMetered(ConnectivityManager cm) { 355d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey final NetworkInfo info = cm.getActiveNetworkInfo(); 365d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey if (info == null) { 375d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey // err on side of caution 385d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey return true; 395d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey } 405d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey 415d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey final int type = info.getType(); 425d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey switch (type) { 435d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey case TYPE_MOBILE: 445d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey case TYPE_MOBILE_DUN: 455d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey case TYPE_MOBILE_HIPRI: 465d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey case TYPE_MOBILE_MMS: 475d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey case TYPE_MOBILE_SUPL: 485d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey case TYPE_WIMAX: 495d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey return true; 505d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey case TYPE_WIFI: 515d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey return false; 525d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey default: 535d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey // err on side of caution 545d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey return true; 555d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey } 565d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey } 575d79c2b6211936177817f2492816c1dba76dac3eJeff Sharkey} 58