Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2009 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 
     17 package android.permission.cts;
     18 
     19 import android.content.Context;
     20 import android.net.ConnectivityManager;
     21 import android.test.AndroidTestCase;
     22 import android.test.suitebuilder.annotation.SmallTest;
     23 
     24 /**
     25 * Test that protected android.net.ConnectivityManager methods cannot be called without
     26 * permissions
     27 */
     28 public class ConnectivityManagerPermissionTest extends AndroidTestCase {
     29 
     30     private ConnectivityManager mConnectivityManager = null;
     31 
     32     @Override
     33     protected void setUp() throws Exception {
     34         super.setUp();
     35         mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
     36         assertNotNull(mConnectivityManager);
     37     }
     38 
     39 
     40 
     41     /**
     42      * Verify that calling {@link ConnectivityManager#getNetworkInfo(int))}
     43      * requires permissions.
     44      * <p>Tests Permission:
     45      *   {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
     46      */
     47     @SmallTest
     48     public void testGetNetworkInfo() {
     49         try {
     50             mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
     51             fail("Was able to call getNetworkInfo");
     52         } catch (SecurityException e) {
     53             // expected
     54         }
     55     }
     56 }
     57