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.net.cts.legacy.api22.permission; 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 * Verify that calling {@link ConnectivityManager#requestRouteToHost(int, int)} 41 * requires permissions. 42 * <p>Tests Permission: 43 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. 44 */ 45 @SmallTest 46 public void testRequestRouteToHost() { 47 try { 48 mConnectivityManager.requestRouteToHost(ConnectivityManager.TYPE_MOBILE, 1); 49 fail("Was able to call requestRouteToHost"); 50 } catch (SecurityException e) { 51 // expected 52 } 53 } 54 } 55