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.Activity; 20 import android.app.PendingIntent; 21 import android.app.PendingIntent.CanceledException; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.telephony.TelephonyManager; 25 26 import com.android.phone.PhoneGlobals; 27 import com.android.services.telephony.Log; 28 29 /** 30 * Invisible activity that handles the android.intent.action.SIM_ACTIVATION_REQUEST intent. 31 * This activity is protected by the android.permission.PERFORM_SIM_ACTIVATION permission. 32 */ 33 public class SimActivationActivity extends Activity { 34 @Override onCreate(Bundle icicle)35 protected void onCreate(Bundle icicle) { 36 super.onCreate(icicle); 37 Log.i(this, "onCreate"); 38 39 Intent intent = getIntent(); 40 if (Intent.ACTION_SIM_ACTIVATION_REQUEST.equals(intent.getAction())) { 41 Log.i(this, "Activation requested " + intent); 42 43 runActivation(intent); 44 } 45 finish(); 46 } 47 runActivation(Intent intent)48 private void runActivation(Intent intent) { 49 final PendingIntent response = 50 intent.getParcelableExtra(Intent.EXTRA_SIM_ACTIVATION_RESPONSE); 51 52 Log.i(this, "Running activation w/ response " + response); 53 54 PhoneGlobals app = PhoneGlobals.getInstance(); 55 app.simActivationManager.runActivation(SimActivationManager.Triggers.EXPLICIT_REQUEST, 56 new SimActivationManager.Response() { 57 @Override 58 public void onResponse(int status) { 59 if (response != null) { 60 try { 61 response.send(); 62 } catch (CanceledException e) { 63 Log.w(this, "Could not respond to SIM Activation."); 64 } 65 } 66 } 67 }); 68 69 // TODO: Set this status to the return value of runActivation 70 // Return the response as an activity result and the pending intent. 71 setResult(TelephonyManager.SIM_ACTIVATION_RESULT_IN_PROGRESS); 72 } 73 } 74