Home | History | Annotate | Download | only in activation
      1 /*
      2  * Copyright (C) 2015 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 com.android.services.telephony.activation;
     18 
     19 import android.app.PendingIntent;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.test.AndroidTestCase;
     23 import android.test.suitebuilder.annotation.SmallTest;
     24 
     25 import com.android.services.telephony.Log;
     26 
     27 public class SimActivationTest extends AndroidTestCase {
     28 
     29     private static Object mActivationLock = new Object();
     30     private ResponseReceiver mResponseReceiver;
     31 
     32     @Override
     33     protected void setUp() throws Exception {
     34         super.setUp();
     35 
     36         mResponseReceiver = new ResponseReceiver(mActivationLock);
     37         mResponseReceiver.register(context());
     38     }
     39 
     40     /** ${inheritDoc} */
     41     @Override
     42     protected void tearDown() throws Exception {
     43         mResponseReceiver.unregister();
     44         super.tearDown();
     45     }
     46 
     47     @SmallTest
     48     public void testSimActivationResponse() throws Exception {
     49         Log.i(this, "Running activation test");
     50 
     51         Intent responseIntent = new Intent(ResponseReceiver.ACTION_ACTIVATION_RESPONSE);
     52         responseIntent.setPackage(context().getPackageName());
     53         PendingIntent pendingResponse = PendingIntent.getBroadcast(
     54                 context(), 0, responseIntent, 0);
     55 
     56         Intent intent = new Intent(Intent.ACTION_SIM_ACTIVATION_REQUEST);
     57         intent.putExtra(Intent.EXTRA_SIM_ACTIVATION_RESPONSE, pendingResponse);
     58         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     59 
     60         Log.i(this, "sent intent");
     61         context().startActivity(intent);
     62         synchronized (mActivationLock) {
     63             Log.i(this, "waiting ");
     64             mActivationLock.wait(5000);
     65             Log.i(this, "unwaiting");
     66         }
     67         assertTrue(ResponseReceiver.responseReceived);
     68     }
     69 
     70     private Context context() {
     71         return getContext();
     72     }
     73 }
     74