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 com.android.phone; 18 19 import android.app.Activity; 20 import android.app.PendingIntent; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.os.SystemProperties; 24 import android.util.Log; 25 26 import com.android.internal.telephony.Phone; 27 28 /** 29 * Invisible activity that handles the com.android.phone.PERFORM_CDMA_PROVISIONING intent. 30 * This activity is protected by the android.permission.PERFORM_CDMA_PROVISIONING permission. 31 * 32 * We handle the PERFORM_CDMA_PROVISIONING action by launching an OTASP 33 * call via one of the OtaUtils helper methods: startInteractiveOtasp() on 34 * regular phones, or startNonInteractiveOtasp() on data-only devices. 35 * 36 * TODO: The class name InCallScreenShowActivation is misleading, since 37 * this activity is totally unrelated to the InCallScreen (which 38 * implements the in-call UI.) Let's eventually rename this to something 39 * like CdmaProvisioningLauncher or CdmaProvisioningHandler... 40 */ 41 public class InCallScreenShowActivation extends Activity { 42 private static final String LOG_TAG = "InCallScreenShowActivation"; 43 private static final boolean DBG = 44 (PhoneApp.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); 45 46 @Override 47 protected void onCreate(Bundle icicle) { 48 super.onCreate(icicle); 49 50 Intent intent = getIntent(); 51 if (DBG) Log.d(LOG_TAG, "onCreate: intent = " + intent); 52 Bundle extras = intent.getExtras(); 53 if (DBG && (extras != null)) { 54 Log.d(LOG_TAG, " - has extras: size = " + extras.size()); // forces an unparcel() 55 Log.d(LOG_TAG, " - extras = " + extras); 56 } 57 58 PhoneApp app = PhoneApp.getInstance(); 59 Phone phone = app.getPhone(); 60 if (!TelephonyCapabilities.supportsOtasp(phone)) { 61 Log.w(LOG_TAG, "CDMA Provisioning not supported on this device"); 62 setResult(RESULT_CANCELED); 63 finish(); 64 return; 65 } 66 67 if (intent.getAction().equals(OtaUtils.ACTION_PERFORM_CDMA_PROVISIONING)) { 68 69 // On voice-capable devices, we perform CDMA provisioning in 70 // "interactive" mode by directly launching the InCallScreen. 71 boolean interactiveMode = PhoneApp.sVoiceCapable; 72 Log.d(LOG_TAG, "ACTION_PERFORM_CDMA_PROVISIONING (interactiveMode = " 73 + interactiveMode + ")..."); 74 75 // Testing: this intent extra allows test apps manually 76 // enable/disable "interactive mode", regardless of whether 77 // the current device is voice-capable. This is allowed only 78 // in userdebug or eng builds. 79 if (intent.hasExtra(OtaUtils.EXTRA_OVERRIDE_INTERACTIVE_MODE) 80 && (SystemProperties.getInt("ro.debuggable", 0) == 1)) { 81 interactiveMode = 82 intent.getBooleanExtra(OtaUtils.EXTRA_OVERRIDE_INTERACTIVE_MODE, false); 83 Log.d(LOG_TAG, "===> MANUALLY OVERRIDING interactiveMode to " + interactiveMode); 84 } 85 86 // We allow the caller to pass a PendingIntent (as the 87 // EXTRA_NONINTERACTIVE_OTASP_RESULT_PENDING_INTENT extra) 88 // which we'll later use to notify them when the OTASP call 89 // fails or succeeds. 90 // 91 // Stash that away here, and we'll fire it off later in 92 // OtaUtils.sendOtaspResult(). 93 app.cdmaOtaScreenState.otaspResultCodePendingIntent = 94 (PendingIntent) intent.getParcelableExtra( 95 OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT); 96 97 if (interactiveMode) { 98 // On voice-capable devices, launch an OTASP call and arrange 99 // for the in-call UI to come up. (The InCallScreen will 100 // notice that an OTASP call is active, and display the 101 // special OTASP UI instead of the usual in-call controls.) 102 103 if (DBG) Log.d(LOG_TAG, "==> Starting interactive CDMA provisioning..."); 104 OtaUtils.startInteractiveOtasp(this); 105 106 // The result we set here is actually irrelevant, since the 107 // InCallScreen's "interactive" OTASP sequence never actually 108 // finish()es; it ends by directly launching the Home 109 // activity. So our caller won't actually ever get an 110 // onActivityResult() call in this case. 111 setResult(OtaUtils.RESULT_INTERACTIVE_OTASP_STARTED); 112 } else { 113 // On data-only devices, manually launch the OTASP call 114 // *without* displaying any UI. (Our caller, presumably 115 // SetupWizardActivity, is responsible for displaying some 116 // sort of progress UI.) 117 118 if (DBG) Log.d(LOG_TAG, "==> Starting non-interactive CDMA provisioning..."); 119 int callStatus = OtaUtils.startNonInteractiveOtasp(this); 120 121 if (callStatus == PhoneUtils.CALL_STATUS_DIALED) { 122 if (DBG) Log.d(LOG_TAG, " ==> successful result from startNonInteractiveOtasp(): " 123 + callStatus); 124 setResult(OtaUtils.RESULT_NONINTERACTIVE_OTASP_STARTED); 125 } else { 126 Log.w(LOG_TAG, "Failure code from startNonInteractiveOtasp(): " + callStatus); 127 setResult(OtaUtils.RESULT_NONINTERACTIVE_OTASP_FAILED); 128 } 129 } 130 } else { 131 Log.e(LOG_TAG, "Unexpected intent action: " + intent); 132 setResult(RESULT_CANCELED); 133 } 134 135 finish(); 136 } 137 } 138