19af99511111eeb5e9930185dc44259502811e3b6fionaxu 29af99511111eeb5e9930185dc44259502811e3b6fionaxu/* 39af99511111eeb5e9930185dc44259502811e3b6fionaxu * Copyright (C) 2016 The Android Open Source Project 49af99511111eeb5e9930185dc44259502811e3b6fionaxu * 59af99511111eeb5e9930185dc44259502811e3b6fionaxu * Licensed under the Apache License, Version 2.0 (the "License"); 69af99511111eeb5e9930185dc44259502811e3b6fionaxu * you may not use this file except in compliance with the License. 79af99511111eeb5e9930185dc44259502811e3b6fionaxu * You may obtain a copy of the License at 89af99511111eeb5e9930185dc44259502811e3b6fionaxu * 99af99511111eeb5e9930185dc44259502811e3b6fionaxu * http://www.apache.org/licenses/LICENSE-2.0 109af99511111eeb5e9930185dc44259502811e3b6fionaxu * 119af99511111eeb5e9930185dc44259502811e3b6fionaxu * Unless required by applicable law or agreed to in writing, software 129af99511111eeb5e9930185dc44259502811e3b6fionaxu * distributed under the License is distributed on an "AS IS" BASIS, 139af99511111eeb5e9930185dc44259502811e3b6fionaxu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 149af99511111eeb5e9930185dc44259502811e3b6fionaxu * See the License for the specific language governing permissions and 159af99511111eeb5e9930185dc44259502811e3b6fionaxu * limitations under the License. 169af99511111eeb5e9930185dc44259502811e3b6fionaxu */ 179af99511111eeb5e9930185dc44259502811e3b6fionaxupackage com.android.internal.telephony; 189af99511111eeb5e9930185dc44259502811e3b6fionaxu 199af99511111eeb5e9930185dc44259502811e3b6fionaxuimport junit.framework.AssertionFailedError; 209af99511111eeb5e9930185dc44259502811e3b6fionaxu 219af99511111eeb5e9930185dc44259502811e3b6fionaxuimport org.junit.After; 229af99511111eeb5e9930185dc44259502811e3b6fionaxuimport org.junit.Before; 239af99511111eeb5e9930185dc44259502811e3b6fionaxuimport org.junit.Test; 249af99511111eeb5e9930185dc44259502811e3b6fionaxu 259af99511111eeb5e9930185dc44259502811e3b6fionaxuimport java.security.InvalidParameterException; 269af99511111eeb5e9930185dc44259502811e3b6fionaxu 279af99511111eeb5e9930185dc44259502811e3b6fionaxuimport static org.junit.Assert.assertEquals; 289af99511111eeb5e9930185dc44259502811e3b6fionaxuimport static android.telephony.TelephonyManager.SIM_ACTIVATION_STATE_ACTIVATED; 299af99511111eeb5e9930185dc44259502811e3b6fionaxuimport static android.telephony.TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; 309af99511111eeb5e9930185dc44259502811e3b6fionaxuimport static android.telephony.TelephonyManager.SIM_ACTIVATION_STATE_RESTRICTED; 319af99511111eeb5e9930185dc44259502811e3b6fionaxuimport static android.telephony.TelephonyManager.SIM_ACTIVATION_STATE_DEACTIVATED; 329af99511111eeb5e9930185dc44259502811e3b6fionaxuimport static org.junit.Assert.assertFalse; 339af99511111eeb5e9930185dc44259502811e3b6fionaxuimport static org.junit.Assert.assertTrue; 349af99511111eeb5e9930185dc44259502811e3b6fionaxuimport static org.mockito.Matchers.eq; 359af99511111eeb5e9930185dc44259502811e3b6fionaxuimport static org.mockito.Mockito.times; 369af99511111eeb5e9930185dc44259502811e3b6fionaxuimport static org.mockito.Mockito.verify; 379af99511111eeb5e9930185dc44259502811e3b6fionaxu 389af99511111eeb5e9930185dc44259502811e3b6fionaxupublic class SimActivationTrackerTest extends TelephonyTest { 399af99511111eeb5e9930185dc44259502811e3b6fionaxu private SimActivationTracker mSAT; 409af99511111eeb5e9930185dc44259502811e3b6fionaxu 419af99511111eeb5e9930185dc44259502811e3b6fionaxu @Before 429af99511111eeb5e9930185dc44259502811e3b6fionaxu public void setUp() throws Exception { 439af99511111eeb5e9930185dc44259502811e3b6fionaxu super.setUp("SimActivaitonTrackerTest"); 449af99511111eeb5e9930185dc44259502811e3b6fionaxu mSAT = new SimActivationTracker(mPhone); 459af99511111eeb5e9930185dc44259502811e3b6fionaxu } 469af99511111eeb5e9930185dc44259502811e3b6fionaxu 479af99511111eeb5e9930185dc44259502811e3b6fionaxu @Test 489af99511111eeb5e9930185dc44259502811e3b6fionaxu public void testSetVoiceActivationState() { 499af99511111eeb5e9930185dc44259502811e3b6fionaxu // verify initial state is unknown 509af99511111eeb5e9930185dc44259502811e3b6fionaxu assertEquals(SIM_ACTIVATION_STATE_UNKNOWN, mSAT.getVoiceActivationState()); 519af99511111eeb5e9930185dc44259502811e3b6fionaxu 529af99511111eeb5e9930185dc44259502811e3b6fionaxu // verify activated state is set successfully 539af99511111eeb5e9930185dc44259502811e3b6fionaxu try { 549af99511111eeb5e9930185dc44259502811e3b6fionaxu mSAT.setVoiceActivationState(SIM_ACTIVATION_STATE_ACTIVATED); 55860f6ed5b6b1639460983449248b447d8bca418bfionaxu } catch (IllegalArgumentException ex) { 569af99511111eeb5e9930185dc44259502811e3b6fionaxu fail("Exception in setVoiceActivationState: " + ex); 579af99511111eeb5e9930185dc44259502811e3b6fionaxu } 589af99511111eeb5e9930185dc44259502811e3b6fionaxu 599af99511111eeb5e9930185dc44259502811e3b6fionaxu assertEquals(SIM_ACTIVATION_STATE_ACTIVATED, mSAT.getVoiceActivationState()); 609af99511111eeb5e9930185dc44259502811e3b6fionaxu verify(mPhone, times(1)).notifyVoiceActivationStateChanged( 619af99511111eeb5e9930185dc44259502811e3b6fionaxu eq(SIM_ACTIVATION_STATE_ACTIVATED)); 629af99511111eeb5e9930185dc44259502811e3b6fionaxu 639af99511111eeb5e9930185dc44259502811e3b6fionaxu // verify fails to set restricted voice activation state 649af99511111eeb5e9930185dc44259502811e3b6fionaxu try { 659af99511111eeb5e9930185dc44259502811e3b6fionaxu mSAT.setVoiceActivationState(SIM_ACTIVATION_STATE_RESTRICTED); 669af99511111eeb5e9930185dc44259502811e3b6fionaxu fail("Expect exception in setVoiceActivationState with wrong state: " 679af99511111eeb5e9930185dc44259502811e3b6fionaxu + SIM_ACTIVATION_STATE_RESTRICTED); 68860f6ed5b6b1639460983449248b447d8bca418bfionaxu } catch (IllegalArgumentException ex) { 699af99511111eeb5e9930185dc44259502811e3b6fionaxu //test pass 709af99511111eeb5e9930185dc44259502811e3b6fionaxu } 719af99511111eeb5e9930185dc44259502811e3b6fionaxu assertEquals(SIM_ACTIVATION_STATE_ACTIVATED, mSAT.getVoiceActivationState()); 729af99511111eeb5e9930185dc44259502811e3b6fionaxu verify(mPhone, times(0)).notifyVoiceActivationStateChanged( 739af99511111eeb5e9930185dc44259502811e3b6fionaxu eq(SIM_ACTIVATION_STATE_RESTRICTED)); 749af99511111eeb5e9930185dc44259502811e3b6fionaxu } 759af99511111eeb5e9930185dc44259502811e3b6fionaxu 769af99511111eeb5e9930185dc44259502811e3b6fionaxu @Test 779af99511111eeb5e9930185dc44259502811e3b6fionaxu public void testSetDataActivationState() { 789af99511111eeb5e9930185dc44259502811e3b6fionaxu // verify initial state is unknown 799af99511111eeb5e9930185dc44259502811e3b6fionaxu assertEquals(SIM_ACTIVATION_STATE_UNKNOWN, mSAT.getDataActivationState()); 809af99511111eeb5e9930185dc44259502811e3b6fionaxu 819af99511111eeb5e9930185dc44259502811e3b6fionaxu // verify deactivated state is set successfully 829af99511111eeb5e9930185dc44259502811e3b6fionaxu try { 839af99511111eeb5e9930185dc44259502811e3b6fionaxu mSAT.setDataActivationState(SIM_ACTIVATION_STATE_DEACTIVATED); 849af99511111eeb5e9930185dc44259502811e3b6fionaxu } catch (InvalidParameterException ex) { 859af99511111eeb5e9930185dc44259502811e3b6fionaxu fail("Exception in setDataActivationState: " + ex); 869af99511111eeb5e9930185dc44259502811e3b6fionaxu } 879af99511111eeb5e9930185dc44259502811e3b6fionaxu assertEquals(SIM_ACTIVATION_STATE_DEACTIVATED, mSAT.getDataActivationState()); 889af99511111eeb5e9930185dc44259502811e3b6fionaxu verify(mPhone, times(1)).notifyDataActivationStateChanged( 899af99511111eeb5e9930185dc44259502811e3b6fionaxu eq(SIM_ACTIVATION_STATE_DEACTIVATED)); 909af99511111eeb5e9930185dc44259502811e3b6fionaxu 919af99511111eeb5e9930185dc44259502811e3b6fionaxu // verify set restricted data activation state successfully 929af99511111eeb5e9930185dc44259502811e3b6fionaxu try { 939af99511111eeb5e9930185dc44259502811e3b6fionaxu mSAT.setDataActivationState(SIM_ACTIVATION_STATE_RESTRICTED); 949af99511111eeb5e9930185dc44259502811e3b6fionaxu } catch (InvalidParameterException ex) { 959af99511111eeb5e9930185dc44259502811e3b6fionaxu fail("Exception in setDataActivationState: " + ex); 969af99511111eeb5e9930185dc44259502811e3b6fionaxu } 979af99511111eeb5e9930185dc44259502811e3b6fionaxu 989af99511111eeb5e9930185dc44259502811e3b6fionaxu assertEquals(SIM_ACTIVATION_STATE_RESTRICTED, mSAT.getDataActivationState()); 999af99511111eeb5e9930185dc44259502811e3b6fionaxu verify(mPhone, times(1)).notifyDataActivationStateChanged( 1009af99511111eeb5e9930185dc44259502811e3b6fionaxu eq(SIM_ACTIVATION_STATE_RESTRICTED)); 1019af99511111eeb5e9930185dc44259502811e3b6fionaxu } 1029af99511111eeb5e9930185dc44259502811e3b6fionaxu 1039af99511111eeb5e9930185dc44259502811e3b6fionaxu @After 1049af99511111eeb5e9930185dc44259502811e3b6fionaxu public void tearDown() throws Exception { 1059af99511111eeb5e9930185dc44259502811e3b6fionaxu mSAT = null; 1069af99511111eeb5e9930185dc44259502811e3b6fionaxu super.tearDown(); 1079af99511111eeb5e9930185dc44259502811e3b6fionaxu } 1089af99511111eeb5e9930185dc44259502811e3b6fionaxu 1099af99511111eeb5e9930185dc44259502811e3b6fionaxu /** 1109af99511111eeb5e9930185dc44259502811e3b6fionaxu * Fails a test with the given message. 1119af99511111eeb5e9930185dc44259502811e3b6fionaxu */ 1129af99511111eeb5e9930185dc44259502811e3b6fionaxu static public void fail(String message) { 1139af99511111eeb5e9930185dc44259502811e3b6fionaxu if (message == null) { 1149af99511111eeb5e9930185dc44259502811e3b6fionaxu throw new AssertionFailedError(); 1159af99511111eeb5e9930185dc44259502811e3b6fionaxu } 1169af99511111eeb5e9930185dc44259502811e3b6fionaxu throw new AssertionFailedError(message); 1179af99511111eeb5e9930185dc44259502811e3b6fionaxu } 1189af99511111eeb5e9930185dc44259502811e3b6fionaxu}