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