blob: a59c2e60bb27354459859f25a501595089edf565 [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 com.android.internal.telephony.Phone;
20import com.android.internal.telephony.PhoneConstants;
21import com.android.internal.telephony.TelephonyCapabilities;
22import com.android.internal.telephony.TelephonyProperties;
23import com.android.phone.OtaUtils.CdmaOtaInCallScreenUiState.State;
24
25import android.app.Activity;
26import android.app.ActivityManager;
27import android.app.AlertDialog;
28import android.app.PendingIntent;
29import android.app.PendingIntent.CanceledException;
30import android.content.ActivityNotFoundException;
31import android.content.Context;
32import android.content.DialogInterface;
33import android.content.Intent;
34import android.net.Uri;
35import android.os.AsyncResult;
36import android.os.Handler;
37import android.os.SystemClock;
38import android.os.SystemProperties;
39import android.os.UserHandle;
40import android.telephony.TelephonyManager;
41import android.util.Log;
42import android.view.KeyEvent;
43import android.view.View;
44import android.view.ViewGroup;
45import android.view.ViewStub;
46import android.view.WindowManager;
47import android.widget.Button;
48import android.widget.ProgressBar;
49import android.widget.ScrollView;
50import android.widget.TextView;
51import android.widget.ToggleButton;
52
53/**
54 * Handles all OTASP Call related logic and UI functionality.
55 * The InCallScreen interacts with this class to perform an OTASP Call.
56 *
57 * OTASP is a CDMA-specific feature:
58 * OTA or OTASP == Over The Air service provisioning
59 * SPC == Service Programming Code
60 * TODO: Include pointer to more detailed documentation.
61 *
62 * TODO: This is Over The Air Service Provisioning (OTASP)
63 * A better name would be OtaspUtils.java.
64 */
65public class OtaUtils {
66 private static final String LOG_TAG = "OtaUtils";
67 private static final boolean DBG = false;
68
69 public static final int OTA_SHOW_ACTIVATION_SCREEN_OFF = 0;
70 public static final int OTA_SHOW_ACTIVATION_SCREEN_ON = 1;
71 public static final int OTA_SHOW_LISTENING_SCREEN_OFF =0;
72 public static final int OTA_SHOW_LISTENING_SCREEN_ON =1;
73 public static final int OTA_SHOW_ACTIVATE_FAIL_COUNT_OFF = 0;
74 public static final int OTA_SHOW_ACTIVATE_FAIL_COUNT_THREE = 3;
75 public static final int OTA_PLAY_SUCCESS_FAILURE_TONE_OFF = 0;
76 public static final int OTA_PLAY_SUCCESS_FAILURE_TONE_ON = 1;
77
78 // SPC Timeout is 60 seconds
79 public final int OTA_SPC_TIMEOUT = 60;
80 public final int OTA_FAILURE_DIALOG_TIMEOUT = 2;
81
82 // Constants for OTASP-related Intents and intent extras.
83 // Watch out: these must agree with the corresponding constants in
84 // apps/SetupWizard!
85
86 // Intent action to launch an OTASP call.
87 public static final String ACTION_PERFORM_CDMA_PROVISIONING =
88 "com.android.phone.PERFORM_CDMA_PROVISIONING";
89
90 // Intent action to launch activation on a non-voice capable device
91 public static final String ACTION_PERFORM_VOICELESS_CDMA_PROVISIONING =
92 "com.android.phone.PERFORM_VOICELESS_CDMA_PROVISIONING";
93
94 // Intent action to display the InCallScreen in the OTASP "activation" state.
95 public static final String ACTION_DISPLAY_ACTIVATION_SCREEN =
96 "com.android.phone.DISPLAY_ACTIVATION_SCREEN";
97
98 // boolean voiceless provisioning extra that enables a "don't show this again" checkbox
99 // the user can check to never see the activity upon bootup again
100 public static final String EXTRA_VOICELESS_PROVISIONING_OFFER_DONTSHOW =
101 "com.android.phone.VOICELESS_PROVISIONING_OFFER_DONTSHOW";
102
103 // Activity result codes for the ACTION_PERFORM_CDMA_PROVISIONING intent
104 // (see the InCallScreenShowActivation activity.)
105 //
106 // Note: currently, our caller won't ever actually receive the
107 // RESULT_INTERACTIVE_OTASP_STARTED result code; see comments in
108 // InCallScreenShowActivation.onCreate() for details.
109
110 public static final int RESULT_INTERACTIVE_OTASP_STARTED = Activity.RESULT_FIRST_USER;
111 public static final int RESULT_NONINTERACTIVE_OTASP_STARTED = Activity.RESULT_FIRST_USER + 1;
112 public static final int RESULT_NONINTERACTIVE_OTASP_FAILED = Activity.RESULT_FIRST_USER + 2;
113
114 // Testing: Extra for the ACTION_PERFORM_CDMA_PROVISIONING intent that
115 // allows the caller to manually enable/disable "interactive mode" for
116 // the OTASP call. Only available in userdebug or eng builds.
117 public static final String EXTRA_OVERRIDE_INTERACTIVE_MODE =
118 "ota_override_interactive_mode";
119
120 // Extra for the ACTION_PERFORM_CDMA_PROVISIONING intent, holding a
121 // PendingIntent which the phone app can use to send a result code
122 // back to the caller.
123 public static final String EXTRA_OTASP_RESULT_CODE_PENDING_INTENT =
124 "otasp_result_code_pending_intent";
125
126 // Extra attached to the above PendingIntent that indicates
127 // success or failure.
128 public static final String EXTRA_OTASP_RESULT_CODE =
129 "otasp_result_code";
130 public static final int OTASP_UNKNOWN = 0;
131 public static final int OTASP_USER_SKIPPED = 1; // Only meaningful with interactive OTASP
132 public static final int OTASP_SUCCESS = 2;
133 public static final int OTASP_FAILURE = 3;
134 // failed due to CDMA_OTA_PROVISION_STATUS_SPC_RETRIES_EXCEEDED
135 public static final int OTASP_FAILURE_SPC_RETRIES = 4;
136 // TODO: Distinguish between interactive and non-interactive success
137 // and failure. Then, have the PendingIntent be sent after
138 // interactive OTASP as well (so the caller can find out definitively
139 // when interactive OTASP completes.)
140
141 private static final String OTASP_NUMBER = "*228";
142 private static final String OTASP_NUMBER_NON_INTERACTIVE = "*22899";
143
144 private InCallScreen mInCallScreen;
145 private Context mContext;
146 private PhoneGlobals mApplication;
147 private OtaWidgetData mOtaWidgetData;
148 private ViewGroup mInCallTouchUi; // UI controls for regular calls
149 private CallCard mCallCard;
150
151 // The DTMFTwelveKeyDialer instance. We create this in
152 // initOtaInCallScreen(), and attach it to the DTMFTwelveKeyDialerView
153 // ("otaDtmfDialerView") that comes from otacall_card.xml.
154 private DTMFTwelveKeyDialer mOtaCallCardDtmfDialer;
155
156 private static boolean sIsWizardMode = true;
157
158 // How many times do we retry maybeDoOtaCall() if the LTE state is not known yet,
159 // and how long do we wait between retries
160 private static final int OTA_CALL_LTE_RETRIES_MAX = 5;
161 private static final int OTA_CALL_LTE_RETRY_PERIOD = 3000;
162 private static int sOtaCallLteRetries = 0;
163
164 // In "interactive mode", the OtaUtils object is tied to an
165 // InCallScreen instance, where we display a bunch of UI specific to
166 // the OTASP call. But on devices that are not "voice capable", the
167 // OTASP call runs in a non-interactive mode, and we don't have
168 // an InCallScreen or CallCard or any OTASP UI elements at all.
169 private boolean mInteractive = true;
170
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700171 // used when setting speakerphone
172 private final BluetoothManager mBluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173
174 /**
175 * OtaWidgetData class represent all OTA UI elements
176 *
177 * TODO(OTASP): It's really ugly for the OtaUtils object to reach into the
178 * InCallScreen like this and directly manipulate its widgets.
179 *
180 * Instead, the model/view separation should be more clear: OtaUtils
181 * should only know about a higher-level abstraction of the
182 * OTASP-specific UI state (just like how the CallController uses the
183 * InCallUiState object), and the InCallScreen itself should translate
184 * that higher-level abstraction into actual onscreen views and widgets.
185 */
186 private class OtaWidgetData {
187 public Button otaEndButton;
188 public Button otaActivateButton;
189 public Button otaSkipButton;
190 public Button otaNextButton;
191 public ToggleButton otaSpeakerButton;
192 public ViewGroup otaUpperWidgets;
193 public View callCardOtaButtonsFailSuccess;
194 public ProgressBar otaTextProgressBar;
195 public TextView otaTextSuccessFail;
196 public View callCardOtaButtonsActivate;
197 public View callCardOtaButtonsListenProgress;
198 public TextView otaTextActivate;
199 public TextView otaTextListenProgress;
200 public AlertDialog spcErrorDialog;
201 public AlertDialog otaFailureDialog;
202 public AlertDialog otaSkipConfirmationDialog;
203 public TextView otaTitle;
204 public DTMFTwelveKeyDialerView otaDtmfDialerView;
205 public Button otaTryAgainButton;
206 }
207
208 /**
209 * OtaUtils constructor.
210 *
211 * @param context the Context of the calling Activity or Application
212 * @param interactive if true, use the InCallScreen to display the progress
213 * and result of the OTASP call. In practice this is
214 * true IFF the current device is a voice-capable phone.
215 *
216 * Note if interactive is true, you must also call updateUiWidgets() as soon
217 * as the InCallScreen instance is ready.
218 */
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700219 public OtaUtils(Context context, boolean interactive, BluetoothManager bluetoothManager) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220 if (DBG) log("OtaUtils constructor...");
221 mApplication = PhoneGlobals.getInstance();
222 mContext = context;
223 mInteractive = interactive;
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700224 mBluetoothManager = bluetoothManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225 }
226
227 /**
228 * Updates the OtaUtils object's references to some UI elements belonging to
229 * the InCallScreen. This is used only in interactive mode.
230 *
231 * Use clearUiWidgets() to clear out these references. (The InCallScreen
232 * is responsible for doing this from its onDestroy() method.)
233 *
234 * This method has no effect if the UI widgets have already been set up.
235 * (In other words, it's safe to call this every time through
236 * InCallScreen.onResume().)
237 */
238 public void updateUiWidgets(InCallScreen inCallScreen,
239 ViewGroup inCallTouchUi, CallCard callCard) {
240 if (DBG) log("updateUiWidgets()... mInCallScreen = " + mInCallScreen);
241
242 if (!mInteractive) {
243 throw new IllegalStateException("updateUiWidgets() called in non-interactive mode");
244 }
245
246 if (mInCallScreen != null) {
247 if (DBG) log("updateUiWidgets(): widgets already set up, nothing to do...");
248 return;
249 }
250
251 mInCallScreen = inCallScreen;
252 mInCallTouchUi = inCallTouchUi;
253 mCallCard = callCard;
254 mOtaWidgetData = new OtaWidgetData();
255
256 // Inflate OTASP-specific UI elements:
257 ViewStub otaCallCardStub = (ViewStub) mInCallScreen.findViewById(R.id.otaCallCardStub);
258 if (otaCallCardStub != null) {
259 // If otaCallCardStub is null here, that means it's already been
260 // inflated (which could have happened in the current InCallScreen
261 // instance for a *prior* OTASP call.)
262 otaCallCardStub.inflate();
263 }
264
265 readXmlSettings();
266 initOtaInCallScreen();
267 }
268
269 /**
270 * Clear out the OtaUtils object's references to any InCallScreen UI
271 * elements. This is the opposite of updateUiWidgets().
272 */
273 public void clearUiWidgets() {
274 mInCallScreen = null;
275 mInCallTouchUi = null;
276 mCallCard = null;
277 mOtaWidgetData = null;
278 }
279
280 /**
281 * Starts the OTA provisioning call. If the MIN isn't available yet, it returns false and adds
282 * an event to return the request to the calling app when it becomes available.
283 *
284 * @param context
285 * @param handler
286 * @param request
287 * @return true if we were able to launch Ota activity or it's not required; false otherwise
288 */
289 public static boolean maybeDoOtaCall(Context context, Handler handler, int request) {
290 PhoneGlobals app = PhoneGlobals.getInstance();
291 Phone phone = app.phone;
292
293 if (ActivityManager.isRunningInTestHarness()) {
294 Log.i(LOG_TAG, "Don't run provisioning when in test harness");
295 return true;
296 }
297
298 if (!TelephonyCapabilities.supportsOtasp(phone)) {
299 // Presumably not a CDMA phone.
300 if (DBG) log("maybeDoOtaCall: OTASP not supported on this device");
301 return true; // Nothing to do here.
302 }
303
304 if (!phone.isMinInfoReady()) {
305 if (DBG) log("MIN is not ready. Registering to receive notification.");
306 phone.registerForSubscriptionInfoReady(handler, request, null);
307 return false;
308 }
309 phone.unregisterForSubscriptionInfoReady(handler);
310
311 if (getLteOnCdmaMode(context) == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
312 if (sOtaCallLteRetries < OTA_CALL_LTE_RETRIES_MAX) {
313 if (DBG) log("maybeDoOtaCall: LTE state still unknown: retrying");
314 handler.sendEmptyMessageDelayed(request, OTA_CALL_LTE_RETRY_PERIOD);
315 sOtaCallLteRetries++;
316 return false;
317 } else {
318 Log.w(LOG_TAG, "maybeDoOtaCall: LTE state still unknown: giving up");
319 return true;
320 }
321 }
322
323 boolean phoneNeedsActivation = phone.needsOtaServiceProvisioning();
324 if (DBG) log("phoneNeedsActivation is set to " + phoneNeedsActivation);
325
326 int otaShowActivationScreen = context.getResources().getInteger(
327 R.integer.OtaShowActivationScreen);
328 if (DBG) log("otaShowActivationScreen: " + otaShowActivationScreen);
329
330 // Run the OTASP call in "interactive" mode only if
331 // this is a non-LTE "voice capable" device.
332 if (PhoneGlobals.sVoiceCapable && getLteOnCdmaMode(context) == PhoneConstants.LTE_ON_CDMA_FALSE) {
333 if (phoneNeedsActivation
334 && (otaShowActivationScreen == OTA_SHOW_ACTIVATION_SCREEN_ON)) {
335 app.cdmaOtaProvisionData.isOtaCallIntentProcessed = false;
336 sIsWizardMode = false;
337
338 if (DBG) Log.d(LOG_TAG, "==> Starting interactive CDMA provisioning...");
339 OtaUtils.startInteractiveOtasp(context);
340
341 if (DBG) log("maybeDoOtaCall: voice capable; activation started.");
342 } else {
343 if (DBG) log("maybeDoOtaCall: voice capable; activation NOT started.");
344 }
345 } else {
346 if (phoneNeedsActivation) {
347 app.cdmaOtaProvisionData.isOtaCallIntentProcessed = false;
348 Intent newIntent = new Intent(ACTION_PERFORM_VOICELESS_CDMA_PROVISIONING);
349 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
350 newIntent.putExtra(EXTRA_VOICELESS_PROVISIONING_OFFER_DONTSHOW, true);
351 try {
352 context.startActivity(newIntent);
353 } catch (ActivityNotFoundException e) {
354 loge("No activity Handling PERFORM_VOICELESS_CDMA_PROVISIONING!");
355 return false;
356 }
357 if (DBG) log("maybeDoOtaCall: non-interactive; activation intent sent.");
358 } else {
359 if (DBG) log("maybeDoOtaCall: non-interactive, no need for OTASP.");
360 }
361 }
362 return true;
363 }
364
365 /**
366 * Starts a normal "interactive" OTASP call (i.e. CDMA activation
367 * for regular voice-capable phone devices.)
368 *
369 * This method is called from the InCallScreenShowActivation activity when
370 * handling the ACTION_PERFORM_CDMA_PROVISIONING intent.
371 */
372 public static void startInteractiveOtasp(Context context) {
373 if (DBG) log("startInteractiveOtasp()...");
374 PhoneGlobals app = PhoneGlobals.getInstance();
375
376 // There are two ways to start OTASP on voice-capable devices:
377 //
378 // (1) via the PERFORM_CDMA_PROVISIONING intent
379 // - this is triggered by the "Activate device" button in settings,
380 // or can be launched automatically upon boot if the device
381 // thinks it needs to be provisioned.
382 // - the intent is handled by InCallScreenShowActivation.onCreate(),
383 // which calls this method
384 // - we prepare for OTASP by initializing the OtaUtils object
385 // - we bring up the InCallScreen in the ready-to-activate state
386 // - when the user presses the "Activate" button we launch the
387 // call by calling CallController.placeCall() via the
388 // otaPerformActivation() method.
389 //
390 // (2) by manually making an outgoing call to a special OTASP number
391 // like "*228" or "*22899".
392 // - That sequence does NOT involve this method (OtaUtils.startInteractiveOtasp()).
393 // Instead, the outgoing call request goes straight to CallController.placeCall().
394 // - CallController.placeCall() notices that it's an OTASP
395 // call, and initializes the OtaUtils object.
396 // - The InCallScreen is launched (as the last step of
397 // CallController.placeCall()). The InCallScreen notices that
398 // OTASP is active and shows the correct UI.
399
400 // Here, we start sequence (1):
401 // Do NOT immediately start the call. Instead, bring up the InCallScreen
402 // in the special "activate" state (see OtaUtils.otaShowActivateScreen()).
403 // We won't actually make the call until the user presses the "Activate"
404 // button.
405
406 Intent activationScreenIntent = new Intent().setClass(context, InCallScreen.class)
407 .setAction(ACTION_DISPLAY_ACTIVATION_SCREEN);
408
409 // Watch out: in the scenario where OTASP gets triggered from the
410 // BOOT_COMPLETED broadcast (see OtaStartupReceiver.java), we might be
411 // running in the PhoneApp's context right now.
412 // So the FLAG_ACTIVITY_NEW_TASK flag is required here.
413 activationScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
414
415 // We're about to start the OTASP sequence, so create and initialize the
416 // OtaUtils instance. (This needs to happen before bringing up the
417 // InCallScreen.)
418 OtaUtils.setupOtaspCall(activationScreenIntent);
419
420 // And bring up the InCallScreen...
421 Log.i(LOG_TAG, "startInteractiveOtasp: launching InCallScreen in 'activate' state: "
422 + activationScreenIntent);
423 context.startActivity(activationScreenIntent);
424 }
425
426 /**
427 * Starts the OTASP call *without* involving the InCallScreen or
428 * displaying any UI.
429 *
430 * This is used on data-only devices, which don't support any kind of
431 * in-call phone UI.
432 *
433 * @return PhoneUtils.CALL_STATUS_DIALED if we successfully
434 * dialed the OTASP number, or one of the other
435 * CALL_STATUS_* constants if there was a failure.
436 */
437 public static int startNonInteractiveOtasp(Context context) {
438 if (DBG) log("startNonInteractiveOtasp()...");
439 PhoneGlobals app = PhoneGlobals.getInstance();
440
441 if (app.otaUtils != null) {
442 // An OtaUtils instance already exists, presumably from a previous OTASP call.
443 Log.i(LOG_TAG, "startNonInteractiveOtasp: "
444 + "OtaUtils already exists; nuking the old one and starting again...");
445 }
446
447 // Create the OtaUtils instance.
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700448 app.otaUtils = new OtaUtils(context, false /* non-interactive mode */,
449 app.getBluetoothManager());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 if (DBG) log("- created OtaUtils: " + app.otaUtils);
451
452 // ... and kick off the OTASP call.
453 // TODO(InCallScreen redesign): This should probably go through
454 // the CallController, rather than directly calling
455 // PhoneUtils.placeCall().
456 Phone phone = PhoneGlobals.getPhone();
457 String number = OTASP_NUMBER_NON_INTERACTIVE;
458 Log.i(LOG_TAG, "startNonInteractiveOtasp: placing call to '" + number + "'...");
459 int callStatus = PhoneUtils.placeCall(context,
460 phone,
461 number,
462 null, // contactRef
463 false, //isEmergencyCall
464 null); // gatewayUri
465
466 if (callStatus == PhoneUtils.CALL_STATUS_DIALED) {
467 if (DBG) log(" ==> successful return from placeCall(): callStatus = " + callStatus);
468 } else {
469 Log.w(LOG_TAG, "Failure from placeCall() for OTA number '"
470 + number + "': code " + callStatus);
471 return callStatus;
472 }
473
474 // TODO: Any other special work to do here?
475 // Such as:
476 //
477 // - manually kick off progress updates, either using TelephonyRegistry
478 // or else by sending PendingIntents directly to our caller?
479 //
480 // - manually silence the in-call audio? (Probably unnecessary
481 // if Stingray truly has no audio path from phone baseband
482 // to the device's speakers.)
483 //
484
485 return callStatus;
486 }
487
488 /**
489 * @return true if the specified Intent is a CALL action that's an attempt
490 * to initate an OTASP call.
491 *
492 * OTASP is a CDMA-specific concept, so this method will always return false
493 * on GSM phones.
494 *
495 * This code was originally part of the InCallScreen.checkIsOtaCall() method.
496 */
497 public static boolean isOtaspCallIntent(Intent intent) {
498 if (DBG) log("isOtaspCallIntent(" + intent + ")...");
499 PhoneGlobals app = PhoneGlobals.getInstance();
500 Phone phone = app.mCM.getDefaultPhone();
501
502 if (intent == null) {
503 return false;
504 }
505 if (!TelephonyCapabilities.supportsOtasp(phone)) {
506 return false;
507 }
508
509 String action = intent.getAction();
510 if (action == null) {
511 return false;
512 }
513 if (!action.equals(Intent.ACTION_CALL)) {
514 if (DBG) log("isOtaspCallIntent: not a CALL action: '" + action + "' ==> not OTASP");
515 return false;
516 }
517
518 if ((app.cdmaOtaScreenState == null) || (app.cdmaOtaProvisionData == null)) {
519 // Uh oh -- something wrong with our internal OTASP state.
520 // (Since this is an OTASP-capable device, these objects
521 // *should* have already been created by PhoneApp.onCreate().)
522 throw new IllegalStateException("isOtaspCallIntent: "
523 + "app.cdmaOta* objects(s) not initialized");
524 }
525
526 // This is an OTASP call iff the number we're trying to dial is one of
527 // the magic OTASP numbers.
528 String number;
529 try {
530 number = PhoneUtils.getInitialNumber(intent);
531 } catch (PhoneUtils.VoiceMailNumberMissingException ex) {
532 // This was presumably a "voicemail:" intent, so it's
533 // obviously not an OTASP number.
534 if (DBG) log("isOtaspCallIntent: VoiceMailNumberMissingException => not OTASP");
535 return false;
536 }
537 if (phone.isOtaSpNumber(number)) {
538 if (DBG) log("isOtaSpNumber: ACTION_CALL to '" + number + "' ==> OTASP call!");
539 return true;
540 }
541 return false;
542 }
543
544 /**
545 * Set up for an OTASP call.
546 *
547 * This method is called as part of the CallController placeCall() sequence
548 * before initiating an outgoing OTASP call.
549 *
550 * The purpose of this method is mainly to create and initialize the
551 * OtaUtils instance, along with some other misc pre-OTASP cleanup.
552 */
553 public static void setupOtaspCall(Intent intent) {
554 if (DBG) log("setupOtaspCall(): preparing for OTASP call to " + intent);
555 PhoneGlobals app = PhoneGlobals.getInstance();
556
557 if (app.otaUtils != null) {
558 // An OtaUtils instance already exists, presumably from a prior OTASP call.
559 // Nuke the old one and start this call with a fresh instance.
560 Log.i(LOG_TAG, "setupOtaspCall: "
561 + "OtaUtils already exists; replacing with new instance...");
562 }
563
564 // Create the OtaUtils instance.
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700565 app.otaUtils = new OtaUtils(app.getApplicationContext(), true /* interactive */,
566 app.getBluetoothManager());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700567 if (DBG) log("- created OtaUtils: " + app.otaUtils);
568
569 // NOTE we still need to call OtaUtils.updateUiWidgets() once the
570 // InCallScreen instance is ready; see InCallScreen.checkOtaspStateOnResume()
571
572 // Make sure the InCallScreen knows that it needs to switch into OTASP mode.
573 //
574 // NOTE in gingerbread and earlier, we used to do
575 // setInCallScreenMode(InCallScreenMode.OTA_NORMAL);
576 // directly in the InCallScreen, back when this check happened inside the InCallScreen.
577 //
578 // But now, set the global CdmaOtaInCallScreenUiState object into
579 // NORMAL mode, which will then cause the InCallScreen (when it
580 // comes up) to realize that an OTA call is active.
581
582 app.otaUtils.setCdmaOtaInCallScreenUiState(
583 OtaUtils.CdmaOtaInCallScreenUiState.State.NORMAL);
584
585 // TODO(OTASP): note app.inCallUiState.inCallScreenMode and
586 // app.cdmaOtaInCallScreenUiState.state are mostly redundant. Combine them.
587 app.inCallUiState.inCallScreenMode = InCallUiState.InCallScreenMode.OTA_NORMAL;
588
589 // TODO(OTASP / bug 5092031): we ideally should call
590 // otaShowListeningScreen() here to make sure that the DTMF dialpad
591 // becomes visible at the start of the "*228" call:
592 //
593 // // ...and get the OTASP-specific UI into the right state.
594 // app.otaUtils.otaShowListeningScreen();
595 // if (app.otaUtils.mInCallScreen != null) {
596 // app.otaUtils.mInCallScreen.requestUpdateScreen();
597 // }
598 //
599 // But this doesn't actually work; the call to otaShowListeningScreen()
600 // *doesn't* actually bring up the listening screen, since the
601 // cdmaOtaConfigData.otaShowListeningScreen config parameter hasn't been
602 // initialized (we haven't run readXmlSettings() yet at this point!)
603
604 // Also, since the OTA call is now just starting, clear out
605 // the "committed" flag in app.cdmaOtaProvisionData.
606 if (app.cdmaOtaProvisionData != null) {
607 app.cdmaOtaProvisionData.isOtaCallCommitted = false;
608 }
609 }
610
611 private void setSpeaker(boolean state) {
612 if (DBG) log("setSpeaker : " + state );
613
614 if (!mInteractive) {
615 if (DBG) log("non-interactive mode, ignoring setSpeaker.");
616 return;
617 }
618
619 if (state == PhoneUtils.isSpeakerOn(mContext)) {
620 if (DBG) log("no change. returning");
621 return;
622 }
623
Santos Cordon27a3c1f2013-08-06 07:49:27 -0700624 if (state && mBluetoothManager.isBluetoothAvailable()
625 && mBluetoothManager.isBluetoothAudioConnected()) {
626 mBluetoothManager.disconnectBluetoothAudio();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700627 }
628 PhoneUtils.turnOnSpeaker(mContext, state, true);
629 }
630
631 /**
632 * Handles OTA Provision events from the telephony layer.
633 * These events come in to this method whether or not
634 * the InCallScreen is visible.
635 *
636 * Possible events are:
637 * OTA Commit Event - OTA provisioning was successful
638 * SPC retries exceeded - SPC failure retries has exceeded, and Phone needs to
639 * power down.
640 */
641 public void onOtaProvisionStatusChanged(AsyncResult r) {
642 int OtaStatus[] = (int[]) r.result;
643 if (DBG) log("Provision status event!");
644 if (DBG) log("onOtaProvisionStatusChanged(): status = "
645 + OtaStatus[0] + " ==> " + otaProvisionStatusToString(OtaStatus[0]));
646
647 // In practice, in a normal successful OTASP call, events come in as follows:
648 // - SPL_UNLOCKED within a couple of seconds after the call starts
649 // - then a delay of around 45 seconds
650 // - then PRL_DOWNLOADED and MDN_DOWNLOADED and COMMITTED within a span of 2 seconds
651
652 switch(OtaStatus[0]) {
653 case Phone.CDMA_OTA_PROVISION_STATUS_SPC_RETRIES_EXCEEDED:
654 if (DBG) log("onOtaProvisionStatusChanged(): RETRIES EXCEEDED");
655 updateOtaspProgress();
656 mApplication.cdmaOtaProvisionData.otaSpcUptime = SystemClock.elapsedRealtime();
657 if (mInteractive) {
658 otaShowSpcErrorNotice(OTA_SPC_TIMEOUT);
659 } else {
660 sendOtaspResult(OTASP_FAILURE_SPC_RETRIES);
661 }
662 // Power.shutdown();
663 break;
664
665 case Phone.CDMA_OTA_PROVISION_STATUS_COMMITTED:
666 if (DBG) {
667 log("onOtaProvisionStatusChanged(): DONE, isOtaCallCommitted set to true");
668 }
669 mApplication.cdmaOtaProvisionData.isOtaCallCommitted = true;
670 if (mApplication.cdmaOtaScreenState.otaScreenState !=
671 CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED) {
672 updateOtaspProgress();
673 }
674
675 break;
676
677 case Phone.CDMA_OTA_PROVISION_STATUS_SPL_UNLOCKED:
678 case Phone.CDMA_OTA_PROVISION_STATUS_A_KEY_EXCHANGED:
679 case Phone.CDMA_OTA_PROVISION_STATUS_SSD_UPDATED:
680 case Phone.CDMA_OTA_PROVISION_STATUS_NAM_DOWNLOADED:
681 case Phone.CDMA_OTA_PROVISION_STATUS_MDN_DOWNLOADED:
682 case Phone.CDMA_OTA_PROVISION_STATUS_IMSI_DOWNLOADED:
683 case Phone.CDMA_OTA_PROVISION_STATUS_PRL_DOWNLOADED:
684 case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_STARTED:
685 case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_STOPPED:
686 case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_ABORTED:
687 // Only update progress when OTA call is in normal state
688 if (getCdmaOtaInCallScreenUiState() == CdmaOtaInCallScreenUiState.State.NORMAL) {
689 if (DBG) log("onOtaProvisionStatusChanged(): change to ProgressScreen");
690 updateOtaspProgress();
691 }
692 break;
693
694 default:
695 if (DBG) log("onOtaProvisionStatusChanged(): Ignoring OtaStatus " + OtaStatus[0]);
696 break;
697 }
698 }
699
700 /**
701 * Handle a disconnect event from the OTASP call.
702 */
703 public void onOtaspDisconnect() {
704 if (DBG) log("onOtaspDisconnect()...");
705 // We only handle this event explicitly in non-interactive mode.
706 // (In interactive mode, the InCallScreen does any post-disconnect
707 // cleanup.)
708 if (!mInteractive) {
709 // Send a success or failure indication back to our caller.
710 updateNonInteractiveOtaSuccessFailure();
711 }
712 }
713
714 private void otaShowHome() {
715 if (DBG) log("otaShowHome()...");
716 mApplication.cdmaOtaScreenState.otaScreenState =
717 CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED;
718 mInCallScreen.endInCallScreenSession();
719 Intent intent = new Intent(Intent.ACTION_MAIN);
720 intent.addCategory (Intent.CATEGORY_HOME);
721 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
722 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
723 return;
724 }
725
726 private void otaSkipActivation() {
727 if (DBG) log("otaSkipActivation()...");
728
729 sendOtaspResult(OTASP_USER_SKIPPED);
730
731 if (mInteractive) mInCallScreen.finish();
732 return;
733 }
734
735 /**
736 * Actually initiate the OTASP call. This method is triggered by the
737 * onscreen "Activate" button, and is only used in interactive mode.
738 */
739 private void otaPerformActivation() {
740 if (DBG) log("otaPerformActivation()...");
741 if (!mInteractive) {
742 // We shouldn't ever get here in non-interactive mode!
743 Log.w(LOG_TAG, "otaPerformActivation: not interactive!");
744 return;
745 }
746
747 if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
748 // Place an outgoing call to the special OTASP number:
749 Intent newIntent = new Intent(Intent.ACTION_CALL);
750 newIntent.setData(Uri.fromParts(Constants.SCHEME_TEL, OTASP_NUMBER, null));
751
752 // Initiate the outgoing call:
753 mApplication.callController.placeCall(newIntent);
754
755 // ...and get the OTASP-specific UI into the right state.
756 otaShowListeningScreen();
757 mInCallScreen.requestUpdateScreen();
758 }
759 return;
760 }
761
762 /**
763 * Show Activation Screen when phone powers up and OTA provision is
764 * required. Also shown when activation fails and user needs
765 * to re-attempt it. Contains ACTIVATE and SKIP buttons
766 * which allow user to start OTA activation or skip the activation process.
767 */
768 public void otaShowActivateScreen() {
769 if (DBG) log("otaShowActivateScreen()...");
770 if (mApplication.cdmaOtaConfigData.otaShowActivationScreen
771 == OTA_SHOW_ACTIVATION_SCREEN_ON) {
772 if (DBG) log("otaShowActivateScreen(): show activation screen");
773 if (!isDialerOpened()) {
774 otaScreenInitialize();
775 mOtaWidgetData.otaSkipButton.setVisibility(sIsWizardMode ?
776 View.VISIBLE : View.INVISIBLE);
777 mOtaWidgetData.otaTextActivate.setVisibility(View.VISIBLE);
778 mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.VISIBLE);
779 }
780 mApplication.cdmaOtaScreenState.otaScreenState =
781 CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION;
782 } else {
783 if (DBG) log("otaShowActivateScreen(): show home screen");
784 otaShowHome();
785 }
786 }
787
788 /**
789 * Show "Listen for Instruction" screen during OTA call. Shown when OTA Call
790 * is initiated and user needs to listen for network instructions and press
791 * appropriate DTMF digits to proceed to the "Programming in Progress" phase.
792 */
793 private void otaShowListeningScreen() {
794 if (DBG) log("otaShowListeningScreen()...");
795 if (!mInteractive) {
796 // We shouldn't ever get here in non-interactive mode!
797 Log.w(LOG_TAG, "otaShowListeningScreen: not interactive!");
798 return;
799 }
800
801 if (mApplication.cdmaOtaConfigData.otaShowListeningScreen
802 == OTA_SHOW_LISTENING_SCREEN_ON) {
803 if (DBG) log("otaShowListeningScreen(): show listening screen");
804 if (!isDialerOpened()) {
805 otaScreenInitialize();
806 mOtaWidgetData.otaTextListenProgress.setVisibility(View.VISIBLE);
807 mOtaWidgetData.otaTextListenProgress.setText(R.string.ota_listen);
808 mOtaWidgetData.otaDtmfDialerView.setVisibility(View.VISIBLE);
809 mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.VISIBLE);
810 mOtaWidgetData.otaSpeakerButton.setVisibility(View.VISIBLE);
811 boolean speakerOn = PhoneUtils.isSpeakerOn(mContext);
812 mOtaWidgetData.otaSpeakerButton.setChecked(speakerOn);
813 }
814 mApplication.cdmaOtaScreenState.otaScreenState =
815 CdmaOtaScreenState.OtaScreenState.OTA_STATUS_LISTENING;
816 } else {
817 if (DBG) log("otaShowListeningScreen(): show progress screen");
818 otaShowInProgressScreen();
819 }
820 }
821
822 /**
823 * Do any necessary updates (of onscreen UI, for example)
824 * based on the latest status of the OTASP call.
825 */
826 private void updateOtaspProgress() {
827 if (DBG) log("updateOtaspProgress()... mInteractive = " + mInteractive);
828 if (mInteractive) {
829 // On regular phones we just call through to
830 // otaShowInProgressScreen(), which updates the
831 // InCallScreen's onscreen UI.
832 otaShowInProgressScreen();
833 } else {
834 // We're not using the InCallScreen to show OTA progress.
835
836 // For now, at least, there's nothing to do here.
837 // The overall "success" or "failure" indication we send back
838 // (to our caller) is triggered by the DISCONNECT event;
839 // see updateNonInteractiveOtaSuccessFailure().
840
841 // But if we ever need to send *intermediate* progress updates back
842 // to our caller, we'd do that here, possbily using the same
843 // PendingIntent that we already use to indicate success or failure.
844 }
845 }
846
847 /**
848 * When a non-interactive OTASP call completes, send a success or
849 * failure indication back to our caller.
850 *
851 * This is basically the non-interactive equivalent of
852 * otaShowSuccessFailure().
853 */
854 private void updateNonInteractiveOtaSuccessFailure() {
855 // This is basically the same logic as otaShowSuccessFailure(): we
856 // check the isOtaCallCommitted bit, and if that's true it means
857 // that activation was successful.
858
859 if (DBG) log("updateNonInteractiveOtaSuccessFailure(): isOtaCallCommitted = "
860 + mApplication.cdmaOtaProvisionData.isOtaCallCommitted);
861 int resultCode =
862 mApplication.cdmaOtaProvisionData.isOtaCallCommitted
863 ? OTASP_SUCCESS : OTASP_FAILURE;
864 sendOtaspResult(resultCode);
865 }
866
867 /**
868 * Sends the specified OTASP result code back to our caller (presumably
869 * SetupWizard) via the PendingIntent that they originally sent along with
870 * the ACTION_PERFORM_CDMA_PROVISIONING intent.
871 */
872 private void sendOtaspResult(int resultCode) {
873 if (DBG) log("sendOtaspResult: resultCode = " + resultCode);
874
875 // Pass the success or failure indication back to our caller by
876 // adding an additional extra to the PendingIntent we already
877 // have.
878 // (NB: there's a PendingIntent send() method that takes a resultCode
879 // directly, but we can't use that here since that call is only
880 // meaningful for pending intents that are actually used as activity
881 // results.)
882
883 Intent extraStuff = new Intent();
884 extraStuff.putExtra(EXTRA_OTASP_RESULT_CODE, resultCode);
885 // When we call PendingIntent.send() below, the extras from this
886 // intent will get merged with any extras already present in
887 // cdmaOtaScreenState.otaspResultCodePendingIntent.
888
889 if (mApplication.cdmaOtaScreenState == null) {
890 Log.e(LOG_TAG, "updateNonInteractiveOtaSuccessFailure: no cdmaOtaScreenState object!");
891 return;
892 }
893 if (mApplication.cdmaOtaScreenState.otaspResultCodePendingIntent == null) {
894 Log.w(LOG_TAG, "updateNonInteractiveOtaSuccessFailure: "
895 + "null otaspResultCodePendingIntent!");
896 return;
897 }
898
899 try {
900 if (DBG) log("- sendOtaspResult: SENDING PENDING INTENT: " +
901 mApplication.cdmaOtaScreenState.otaspResultCodePendingIntent);
902 mApplication.cdmaOtaScreenState.otaspResultCodePendingIntent.send(
903 mContext,
904 0, /* resultCode (unused) */
905 extraStuff);
906 } catch (CanceledException e) {
907 // should never happen because no code cancels the pending intent right now,
908 Log.e(LOG_TAG, "PendingIntent send() failed: " + e);
909 }
910 }
911
912 /**
913 * Show "Programming In Progress" screen during OTA call. Shown when OTA
914 * provisioning is in progress after user has selected an option.
915 */
916 private void otaShowInProgressScreen() {
917 if (DBG) log("otaShowInProgressScreen()...");
918 if (!mInteractive) {
919 // We shouldn't ever get here in non-interactive mode!
920 Log.w(LOG_TAG, "otaShowInProgressScreen: not interactive!");
921 return;
922 }
923
924 mApplication.cdmaOtaScreenState.otaScreenState =
925 CdmaOtaScreenState.OtaScreenState.OTA_STATUS_PROGRESS;
926
927 if ((mOtaWidgetData == null) || (mInCallScreen == null)) {
928 Log.w(LOG_TAG, "otaShowInProgressScreen: UI widgets not set up yet!");
929
930 // TODO(OTASP): our CdmaOtaScreenState is now correct; we just set
931 // it to OTA_STATUS_PROGRESS. But we still need to make sure that
932 // when the InCallScreen eventually comes to the foreground, it
933 // notices that state and does all the same UI updating we do below.
934 return;
935 }
936
937 if (!isDialerOpened()) {
938 otaScreenInitialize();
939 mOtaWidgetData.otaTextListenProgress.setVisibility(View.VISIBLE);
940 mOtaWidgetData.otaTextListenProgress.setText(R.string.ota_progress);
941 mOtaWidgetData.otaTextProgressBar.setVisibility(View.VISIBLE);
942 mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.VISIBLE);
943 mOtaWidgetData.otaSpeakerButton.setVisibility(View.VISIBLE);
944 boolean speakerOn = PhoneUtils.isSpeakerOn(mContext);
945 mOtaWidgetData.otaSpeakerButton.setChecked(speakerOn);
946 }
947 }
948
949 /**
950 * Show programming failure dialog when OTA provisioning fails.
951 * If OTA provisioning attempts fail more than 3 times, then unsuccessful
952 * dialog is shown. Otherwise a two-second notice is shown with unsuccessful
953 * information. When notice expires, phone returns to activation screen.
954 */
955 private void otaShowProgramFailure(int length) {
956 if (DBG) log("otaShowProgramFailure()...");
957 mApplication.cdmaOtaProvisionData.activationCount++;
958 if ((mApplication.cdmaOtaProvisionData.activationCount <
959 mApplication.cdmaOtaConfigData.otaShowActivateFailTimes)
960 && (mApplication.cdmaOtaConfigData.otaShowActivationScreen ==
961 OTA_SHOW_ACTIVATION_SCREEN_ON)) {
962 if (DBG) log("otaShowProgramFailure(): activationCount"
963 + mApplication.cdmaOtaProvisionData.activationCount);
964 if (DBG) log("otaShowProgramFailure(): show failure notice");
965 otaShowProgramFailureNotice(length);
966 } else {
967 if (DBG) log("otaShowProgramFailure(): show failure dialog");
968 otaShowProgramFailureDialog();
969 }
970 }
971
972 /**
973 * Show either programming success dialog when OTA provisioning succeeds, or
974 * programming failure dialog when it fails. See {@link #otaShowProgramFailure}
975 * for more details.
976 */
977 public void otaShowSuccessFailure() {
978 if (DBG) log("otaShowSuccessFailure()...");
979 if (!mInteractive) {
980 // We shouldn't ever get here in non-interactive mode!
981 Log.w(LOG_TAG, "otaShowSuccessFailure: not interactive!");
982 return;
983 }
984
985 otaScreenInitialize();
986 if (DBG) log("otaShowSuccessFailure(): isOtaCallCommitted"
987 + mApplication.cdmaOtaProvisionData.isOtaCallCommitted);
988 if (mApplication.cdmaOtaProvisionData.isOtaCallCommitted) {
989 if (DBG) log("otaShowSuccessFailure(), show success dialog");
990 otaShowProgramSuccessDialog();
991 } else {
992 if (DBG) log("otaShowSuccessFailure(), show failure dialog");
993 otaShowProgramFailure(OTA_FAILURE_DIALOG_TIMEOUT);
994 }
995 return;
996 }
997
998 /**
999 * Show programming failure dialog when OTA provisioning fails more than 3
1000 * times.
1001 */
1002 private void otaShowProgramFailureDialog() {
1003 if (DBG) log("otaShowProgramFailureDialog()...");
1004 mApplication.cdmaOtaScreenState.otaScreenState =
1005 CdmaOtaScreenState.OtaScreenState.OTA_STATUS_SUCCESS_FAILURE_DLG;
1006 mOtaWidgetData.otaTitle.setText(R.string.ota_title_problem_with_activation);
1007 mOtaWidgetData.otaTextSuccessFail.setVisibility(View.VISIBLE);
1008 mOtaWidgetData.otaTextSuccessFail.setText(R.string.ota_unsuccessful);
1009 mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.VISIBLE);
1010 mOtaWidgetData.otaTryAgainButton.setVisibility(View.VISIBLE);
1011 //close the dialer if open
1012 if (isDialerOpened()) {
1013 mOtaCallCardDtmfDialer.closeDialer(false);
1014 }
1015 }
1016
1017 /**
1018 * Show programming success dialog when OTA provisioning succeeds.
1019 */
1020 private void otaShowProgramSuccessDialog() {
1021 if (DBG) log("otaShowProgramSuccessDialog()...");
1022 mApplication.cdmaOtaScreenState.otaScreenState =
1023 CdmaOtaScreenState.OtaScreenState.OTA_STATUS_SUCCESS_FAILURE_DLG;
1024 mOtaWidgetData.otaTitle.setText(R.string.ota_title_activate_success);
1025 mOtaWidgetData.otaTextSuccessFail.setVisibility(View.VISIBLE);
1026 mOtaWidgetData.otaTextSuccessFail.setText(R.string.ota_successful);
1027 mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.VISIBLE);
1028 mOtaWidgetData.otaNextButton.setVisibility(View.VISIBLE);
1029 //close the dialer if open
1030 if (isDialerOpened()) {
1031 mOtaCallCardDtmfDialer.closeDialer(false);
1032 }
1033 }
1034
1035 /**
1036 * Show SPC failure notice when SPC attempts exceed 15 times.
1037 * During OTA provisioning, if SPC code is incorrect OTA provisioning will
1038 * fail. When SPC attempts are over 15, it shows SPC failure notice for one minute and
1039 * then phone will power down.
1040 */
1041 private void otaShowSpcErrorNotice(int length) {
1042 if (DBG) log("otaShowSpcErrorNotice()...");
1043 if (mOtaWidgetData.spcErrorDialog == null) {
1044 mApplication.cdmaOtaProvisionData.inOtaSpcState = true;
1045 DialogInterface.OnKeyListener keyListener;
1046 keyListener = new DialogInterface.OnKeyListener() {
1047 public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
1048 log("Ignoring key events...");
1049 return true;
1050 }};
1051 mOtaWidgetData.spcErrorDialog = new AlertDialog.Builder(mInCallScreen)
1052 .setMessage(R.string.ota_spc_failure)
1053 .setOnKeyListener(keyListener)
1054 .create();
1055 mOtaWidgetData.spcErrorDialog.getWindow().addFlags(
1056 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1057 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
1058 mOtaWidgetData.spcErrorDialog.show();
1059 //close the dialer if open
1060 if (isDialerOpened()) {
1061 mOtaCallCardDtmfDialer.closeDialer(false);
1062 }
1063 long noticeTime = length*1000;
1064 if (DBG) log("otaShowSpcErrorNotice(), remaining SPC noticeTime" + noticeTime);
1065 mInCallScreen.requestCloseSpcErrorNotice(noticeTime);
1066 }
1067 }
1068
1069 /**
1070 * When SPC notice times out, force phone to power down.
1071 */
1072 public void onOtaCloseSpcNotice() {
1073 if (DBG) log("onOtaCloseSpcNotice(), send shutdown intent");
1074 Intent shutdown = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
1075 shutdown.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
1076 shutdown.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1077 mContext.startActivity(shutdown);
1078 }
1079
1080 /**
1081 * Show two-second notice when OTA provisioning fails and number of failed attempts
1082 * is less then 3.
1083 */
1084 private void otaShowProgramFailureNotice(int length) {
1085 if (DBG) log("otaShowProgramFailureNotice()...");
1086 if (mOtaWidgetData.otaFailureDialog == null) {
1087 mOtaWidgetData.otaFailureDialog = new AlertDialog.Builder(mInCallScreen)
1088 .setMessage(R.string.ota_failure)
1089 .create();
1090 mOtaWidgetData.otaFailureDialog.getWindow().addFlags(
1091 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1092 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
1093 mOtaWidgetData.otaFailureDialog.show();
1094
1095 long noticeTime = length*1000;
1096 mInCallScreen.requestCloseOtaFailureNotice(noticeTime);
1097 }
1098 }
1099
1100 /**
1101 * Handle OTA unsuccessful notice expiry. Dismisses the
1102 * two-second notice and shows the activation screen.
1103 */
1104 public void onOtaCloseFailureNotice() {
1105 if (DBG) log("onOtaCloseFailureNotice()...");
1106 if (mOtaWidgetData.otaFailureDialog != null) {
1107 mOtaWidgetData.otaFailureDialog.dismiss();
1108 mOtaWidgetData.otaFailureDialog = null;
1109 }
1110 otaShowActivateScreen();
1111 }
1112
1113 /**
1114 * Initialize all OTA UI elements to be gone. Also set inCallPanel,
1115 * callCard and the dialpad handle to be gone. This is called before any OTA screen
1116 * gets drawn.
1117 */
1118 private void otaScreenInitialize() {
1119 if (DBG) log("otaScreenInitialize()...");
1120
1121 if (!mInteractive) {
1122 // We should never be doing anything with UI elements in
1123 // non-interactive mode.
1124 Log.w(LOG_TAG, "otaScreenInitialize: not interactive!");
1125 return;
1126 }
1127
1128 if (mInCallTouchUi != null) mInCallTouchUi.setVisibility(View.GONE);
1129 if (mCallCard != null) {
1130 mCallCard.setVisibility(View.GONE);
1131 // TODO: try removing this.
1132 mCallCard.hideCallCardElements();
1133 }
1134
1135 mOtaWidgetData.otaTitle.setText(R.string.ota_title_activate);
1136 mOtaWidgetData.otaTextActivate.setVisibility(View.GONE);
1137 mOtaWidgetData.otaTextListenProgress.setVisibility(View.GONE);
1138 mOtaWidgetData.otaTextProgressBar.setVisibility(View.GONE);
1139 mOtaWidgetData.otaTextSuccessFail.setVisibility(View.GONE);
1140 mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.GONE);
1141 mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.GONE);
1142 mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.GONE);
1143 mOtaWidgetData.otaDtmfDialerView.setVisibility(View.GONE);
1144 mOtaWidgetData.otaSpeakerButton.setVisibility(View.GONE);
1145 mOtaWidgetData.otaTryAgainButton.setVisibility(View.GONE);
1146 mOtaWidgetData.otaNextButton.setVisibility(View.GONE);
1147 mOtaWidgetData.otaUpperWidgets.setVisibility(View.VISIBLE);
1148 mOtaWidgetData.otaSkipButton.setVisibility(View.VISIBLE);
1149 }
1150
1151 public void hideOtaScreen() {
1152 if (DBG) log("hideOtaScreen()...");
1153
1154 mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.GONE);
1155 mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.GONE);
1156 mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.GONE);
1157 mOtaWidgetData.otaUpperWidgets.setVisibility(View.GONE);
1158 }
1159
1160 public boolean isDialerOpened() {
1161 boolean retval = (mOtaCallCardDtmfDialer != null && mOtaCallCardDtmfDialer.isOpened());
1162 if (DBG) log("- isDialerOpened() ==> " + retval);
1163 return retval;
1164 }
1165
1166 /**
1167 * Show the appropriate OTA screen based on the current state of OTA call.
1168 *
1169 * This is called from the InCallScreen when the screen needs to be
1170 * refreshed (and thus is only ever used in interactive mode.)
1171 *
1172 * Since this is called as part of the InCallScreen.updateScreen() sequence,
1173 * this method does *not* post an mInCallScreen.requestUpdateScreen()
1174 * request.
1175 */
1176 public void otaShowProperScreen() {
1177 if (DBG) log("otaShowProperScreen()...");
1178 if (!mInteractive) {
1179 // We shouldn't ever get here in non-interactive mode!
1180 Log.w(LOG_TAG, "otaShowProperScreen: not interactive!");
1181 return;
1182 }
1183
1184 if ((mInCallScreen != null) && mInCallScreen.isForegroundActivity()) {
1185 if (DBG) log("otaShowProperScreen(): InCallScreen in foreground, currentstate = "
1186 + mApplication.cdmaOtaScreenState.otaScreenState);
1187 if (mInCallTouchUi != null) {
1188 mInCallTouchUi.setVisibility(View.GONE);
1189 }
1190 if (mCallCard != null) {
1191 mCallCard.setVisibility(View.GONE);
1192 }
1193 if (mApplication.cdmaOtaScreenState.otaScreenState
1194 == CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION) {
1195 otaShowActivateScreen();
1196 } else if (mApplication.cdmaOtaScreenState.otaScreenState
1197 == CdmaOtaScreenState.OtaScreenState.OTA_STATUS_LISTENING) {
1198 otaShowListeningScreen();
1199 } else if (mApplication.cdmaOtaScreenState.otaScreenState
1200 == CdmaOtaScreenState.OtaScreenState.OTA_STATUS_PROGRESS) {
1201 otaShowInProgressScreen();
1202 }
1203
1204 if (mApplication.cdmaOtaProvisionData.inOtaSpcState) {
1205 otaShowSpcErrorNotice(getOtaSpcDisplayTime());
1206 }
1207 }
1208 }
1209
1210 /**
1211 * Read configuration values for each OTA screen from config.xml.
1212 * These configuration values control visibility of each screen.
1213 */
1214 private void readXmlSettings() {
1215 if (DBG) log("readXmlSettings()...");
1216 if (mApplication.cdmaOtaConfigData.configComplete) {
1217 return;
1218 }
1219
1220 mApplication.cdmaOtaConfigData.configComplete = true;
1221 int tmpOtaShowActivationScreen =
1222 mContext.getResources().getInteger(R.integer.OtaShowActivationScreen);
1223 mApplication.cdmaOtaConfigData.otaShowActivationScreen = tmpOtaShowActivationScreen;
1224 if (DBG) log("readXmlSettings(), otaShowActivationScreen = "
1225 + mApplication.cdmaOtaConfigData.otaShowActivationScreen);
1226
1227 int tmpOtaShowListeningScreen =
1228 mContext.getResources().getInteger(R.integer.OtaShowListeningScreen);
1229 mApplication.cdmaOtaConfigData.otaShowListeningScreen = tmpOtaShowListeningScreen;
1230 if (DBG) log("readXmlSettings(), otaShowListeningScreen = "
1231 + mApplication.cdmaOtaConfigData.otaShowListeningScreen);
1232
1233 int tmpOtaShowActivateFailTimes =
1234 mContext.getResources().getInteger(R.integer.OtaShowActivateFailTimes);
1235 mApplication.cdmaOtaConfigData.otaShowActivateFailTimes = tmpOtaShowActivateFailTimes;
1236 if (DBG) log("readXmlSettings(), otaShowActivateFailTimes = "
1237 + mApplication.cdmaOtaConfigData.otaShowActivateFailTimes);
1238
1239 int tmpOtaPlaySuccessFailureTone =
1240 mContext.getResources().getInteger(R.integer.OtaPlaySuccessFailureTone);
1241 mApplication.cdmaOtaConfigData.otaPlaySuccessFailureTone = tmpOtaPlaySuccessFailureTone;
1242 if (DBG) log("readXmlSettings(), otaPlaySuccessFailureTone = "
1243 + mApplication.cdmaOtaConfigData.otaPlaySuccessFailureTone);
1244 }
1245
1246 /**
1247 * Handle the click events for OTA buttons.
1248 */
1249 public void onClickHandler(int id) {
1250 switch (id) {
1251 case R.id.otaEndButton:
1252 onClickOtaEndButton();
1253 break;
1254
1255 case R.id.otaSpeakerButton:
1256 onClickOtaSpeakerButton();
1257 break;
1258
1259 case R.id.otaActivateButton:
1260 onClickOtaActivateButton();
1261 break;
1262
1263 case R.id.otaSkipButton:
1264 onClickOtaActivateSkipButton();
1265 break;
1266
1267 case R.id.otaNextButton:
1268 onClickOtaActivateNextButton();
1269 break;
1270
1271 case R.id.otaTryAgainButton:
1272 onClickOtaTryAgainButton();
1273 break;
1274
1275 default:
1276 if (DBG) log ("onClickHandler: received a click event for unrecognized id");
1277 break;
1278 }
1279 }
1280
1281 private void onClickOtaTryAgainButton() {
1282 if (DBG) log("Activation Try Again Clicked!");
1283 if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
1284 otaShowActivateScreen();
1285 }
1286 }
1287
1288 private void onClickOtaEndButton() {
1289 if (DBG) log("Activation End Call Button Clicked!");
1290 if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
1291 if (PhoneUtils.hangup(mApplication.mCM) == false) {
1292 // If something went wrong when placing the OTA call,
1293 // the screen is not updated by the call disconnect
1294 // handler and we have to do it here
1295 setSpeaker(false);
1296 mInCallScreen.handleOtaCallEnd();
1297 }
1298 }
1299 }
1300
1301 private void onClickOtaSpeakerButton() {
1302 if (DBG) log("OTA Speaker button Clicked!");
1303 if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
1304 boolean isChecked = !PhoneUtils.isSpeakerOn(mContext);
1305 setSpeaker(isChecked);
1306 }
1307 }
1308
1309 private void onClickOtaActivateButton() {
1310 if (DBG) log("Call Activation Clicked!");
1311 otaPerformActivation();
1312 }
1313
1314 private void onClickOtaActivateSkipButton() {
1315 if (DBG) log("Activation Skip Clicked!");
1316 DialogInterface.OnKeyListener keyListener;
1317 keyListener = new DialogInterface.OnKeyListener() {
1318 public boolean onKey(DialogInterface dialog, int keyCode,
1319 KeyEvent event) {
1320 if (DBG) log("Ignoring key events...");
1321 return true;
1322 }
1323 };
1324 mOtaWidgetData.otaSkipConfirmationDialog = new AlertDialog.Builder(mInCallScreen)
1325 .setTitle(R.string.ota_skip_activation_dialog_title)
1326 .setMessage(R.string.ota_skip_activation_dialog_message)
1327 .setPositiveButton(
1328 android.R.string.ok,
1329 // "OK" means "skip activation".
1330 new AlertDialog.OnClickListener() {
1331 public void onClick(DialogInterface dialog, int which) {
1332 otaSkipActivation();
1333 }
1334 })
1335 .setNegativeButton(
1336 android.R.string.cancel,
1337 // "Cancel" means just dismiss the dialog.
1338 // Don't actually start an activation call.
1339 null)
1340 .setOnKeyListener(keyListener)
1341 .create();
1342 mOtaWidgetData.otaSkipConfirmationDialog.show();
1343 }
1344
1345 private void onClickOtaActivateNextButton() {
1346 if (DBG) log("Dialog Next Clicked!");
1347 if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
1348 mApplication.cdmaOtaScreenState.otaScreenState =
1349 CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED;
1350 otaShowHome();
1351 }
1352 }
1353
1354 public void dismissAllOtaDialogs() {
1355 if (mOtaWidgetData != null) {
1356 if (mOtaWidgetData.spcErrorDialog != null) {
1357 if (DBG) log("- DISMISSING mSpcErrorDialog.");
1358 mOtaWidgetData.spcErrorDialog.dismiss();
1359 mOtaWidgetData.spcErrorDialog = null;
1360 }
1361 if (mOtaWidgetData.otaFailureDialog != null) {
1362 if (DBG) log("- DISMISSING mOtaFailureDialog.");
1363 mOtaWidgetData.otaFailureDialog.dismiss();
1364 mOtaWidgetData.otaFailureDialog = null;
1365 }
1366 }
1367 }
1368
1369 private int getOtaSpcDisplayTime() {
1370 if (DBG) log("getOtaSpcDisplayTime()...");
1371 int tmpSpcTime = 1;
1372 if (mApplication.cdmaOtaProvisionData.inOtaSpcState) {
1373 long tmpOtaSpcRunningTime = 0;
1374 long tmpOtaSpcLeftTime = 0;
1375 tmpOtaSpcRunningTime = SystemClock.elapsedRealtime();
1376 tmpOtaSpcLeftTime =
1377 tmpOtaSpcRunningTime - mApplication.cdmaOtaProvisionData.otaSpcUptime;
1378 if (tmpOtaSpcLeftTime >= OTA_SPC_TIMEOUT*1000) {
1379 tmpSpcTime = 1;
1380 } else {
1381 tmpSpcTime = OTA_SPC_TIMEOUT - (int)tmpOtaSpcLeftTime/1000;
1382 }
1383 }
1384 if (DBG) log("getOtaSpcDisplayTime(), time for SPC error notice: " + tmpSpcTime);
1385 return tmpSpcTime;
1386 }
1387
1388 /**
1389 * Initialize the OTA widgets for all OTA screens.
1390 */
1391 private void initOtaInCallScreen() {
1392 if (DBG) log("initOtaInCallScreen()...");
1393 mOtaWidgetData.otaTitle = (TextView) mInCallScreen.findViewById(R.id.otaTitle);
1394 mOtaWidgetData.otaTextActivate = (TextView) mInCallScreen.findViewById(R.id.otaActivate);
1395 mOtaWidgetData.otaTextActivate.setVisibility(View.GONE);
1396 mOtaWidgetData.otaTextListenProgress =
1397 (TextView) mInCallScreen.findViewById(R.id.otaListenProgress);
1398 mOtaWidgetData.otaTextProgressBar =
1399 (ProgressBar) mInCallScreen.findViewById(R.id.progress_large);
1400 mOtaWidgetData.otaTextProgressBar.setIndeterminate(true);
1401 mOtaWidgetData.otaTextSuccessFail =
1402 (TextView) mInCallScreen.findViewById(R.id.otaSuccessFailStatus);
1403
1404 mOtaWidgetData.otaUpperWidgets =
1405 (ViewGroup) mInCallScreen.findViewById(R.id.otaUpperWidgets);
1406 mOtaWidgetData.callCardOtaButtonsListenProgress =
1407 (View) mInCallScreen.findViewById(R.id.callCardOtaListenProgress);
1408 mOtaWidgetData.callCardOtaButtonsActivate =
1409 (View) mInCallScreen.findViewById(R.id.callCardOtaActivate);
1410 mOtaWidgetData.callCardOtaButtonsFailSuccess =
1411 (View) mInCallScreen.findViewById(R.id.callCardOtaFailOrSuccessful);
1412
1413 mOtaWidgetData.otaEndButton = (Button) mInCallScreen.findViewById(R.id.otaEndButton);
1414 mOtaWidgetData.otaEndButton.setOnClickListener(mInCallScreen);
1415 mOtaWidgetData.otaSpeakerButton =
1416 (ToggleButton) mInCallScreen.findViewById(R.id.otaSpeakerButton);
1417 mOtaWidgetData.otaSpeakerButton.setOnClickListener(mInCallScreen);
1418 mOtaWidgetData.otaActivateButton =
1419 (Button) mInCallScreen.findViewById(R.id.otaActivateButton);
1420 mOtaWidgetData.otaActivateButton.setOnClickListener(mInCallScreen);
1421 mOtaWidgetData.otaSkipButton = (Button) mInCallScreen.findViewById(R.id.otaSkipButton);
1422 mOtaWidgetData.otaSkipButton.setOnClickListener(mInCallScreen);
1423 mOtaWidgetData.otaNextButton = (Button) mInCallScreen.findViewById(R.id.otaNextButton);
1424 mOtaWidgetData.otaNextButton.setOnClickListener(mInCallScreen);
1425 mOtaWidgetData.otaTryAgainButton =
1426 (Button) mInCallScreen.findViewById(R.id.otaTryAgainButton);
1427 mOtaWidgetData.otaTryAgainButton.setOnClickListener(mInCallScreen);
1428
1429 mOtaWidgetData.otaDtmfDialerView =
1430 (DTMFTwelveKeyDialerView) mInCallScreen.findViewById(R.id.otaDtmfDialerView);
1431 // Sanity-check: the otaDtmfDialerView widget should *always* be present.
1432 if (mOtaWidgetData.otaDtmfDialerView == null) {
1433 throw new IllegalStateException("initOtaInCallScreen: couldn't find otaDtmfDialerView");
1434 }
1435
1436 // Create a new DTMFTwelveKeyDialer instance purely for use by the
1437 // DTMFTwelveKeyDialerView ("otaDtmfDialerView") that comes from
1438 // otacall_card.xml.
1439 mOtaCallCardDtmfDialer = new DTMFTwelveKeyDialer(mInCallScreen,
1440 mOtaWidgetData.otaDtmfDialerView);
1441
1442 // Initialize the new DTMFTwelveKeyDialer instance. This is
1443 // needed to play local DTMF tones.
1444 mOtaCallCardDtmfDialer.startDialerSession();
1445
1446 mOtaWidgetData.otaDtmfDialerView.setDialer(mOtaCallCardDtmfDialer);
1447 }
1448
1449 /**
1450 * Clear out all OTA UI widget elements. Needs to get called
1451 * when OTA call ends or InCallScreen is destroyed.
1452 * @param disableSpeaker parameter control whether Speaker should be turned off.
1453 */
1454 public void cleanOtaScreen(boolean disableSpeaker) {
1455 if (DBG) log("OTA ends, cleanOtaScreen!");
1456
1457 mApplication.cdmaOtaScreenState.otaScreenState =
1458 CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED;
1459 mApplication.cdmaOtaProvisionData.isOtaCallCommitted = false;
1460 mApplication.cdmaOtaProvisionData.isOtaCallIntentProcessed = false;
1461 mApplication.cdmaOtaProvisionData.inOtaSpcState = false;
1462 mApplication.cdmaOtaProvisionData.activationCount = 0;
1463 mApplication.cdmaOtaProvisionData.otaSpcUptime = 0;
1464 mApplication.cdmaOtaInCallScreenUiState.state = State.UNDEFINED;
1465
1466 if (mInteractive && (mOtaWidgetData != null)) {
1467 if (mInCallTouchUi != null) mInCallTouchUi.setVisibility(View.VISIBLE);
1468 if (mCallCard != null) {
1469 mCallCard.setVisibility(View.VISIBLE);
1470 mCallCard.hideCallCardElements();
1471 }
1472
1473 // Free resources from the DTMFTwelveKeyDialer instance we created
1474 // in initOtaInCallScreen().
1475 if (mOtaCallCardDtmfDialer != null) {
1476 mOtaCallCardDtmfDialer.stopDialerSession();
1477 }
1478
1479 mOtaWidgetData.otaTextActivate.setVisibility(View.GONE);
1480 mOtaWidgetData.otaTextListenProgress.setVisibility(View.GONE);
1481 mOtaWidgetData.otaTextProgressBar.setVisibility(View.GONE);
1482 mOtaWidgetData.otaTextSuccessFail.setVisibility(View.GONE);
1483 mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.GONE);
1484 mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.GONE);
1485 mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.GONE);
1486 mOtaWidgetData.otaUpperWidgets.setVisibility(View.GONE);
1487 mOtaWidgetData.otaDtmfDialerView.setVisibility(View.GONE);
1488 mOtaWidgetData.otaNextButton.setVisibility(View.GONE);
1489 mOtaWidgetData.otaTryAgainButton.setVisibility(View.GONE);
1490 }
1491
1492 // turn off the speaker in case it was turned on
1493 // but the OTA call could not be completed
1494 if (disableSpeaker) {
1495 setSpeaker(false);
1496 }
1497 }
1498
1499 /**
1500 * Defines OTA information that needs to be maintained during
1501 * an OTA call when display orientation changes.
1502 */
1503 public static class CdmaOtaProvisionData {
1504 public boolean isOtaCallCommitted;
1505 public boolean isOtaCallIntentProcessed;
1506 public boolean inOtaSpcState;
1507 public int activationCount;
1508 public long otaSpcUptime;
1509 }
1510
1511 /**
1512 * Defines OTA screen configuration items read from config.xml
1513 * and used to control OTA display.
1514 */
1515 public static class CdmaOtaConfigData {
1516 public int otaShowActivationScreen;
1517 public int otaShowListeningScreen;
1518 public int otaShowActivateFailTimes;
1519 public int otaPlaySuccessFailureTone;
1520 public boolean configComplete;
1521 public CdmaOtaConfigData() {
1522 if (DBG) log("CdmaOtaConfigData constructor!");
1523 otaShowActivationScreen = OTA_SHOW_ACTIVATION_SCREEN_OFF;
1524 otaShowListeningScreen = OTA_SHOW_LISTENING_SCREEN_OFF;
1525 otaShowActivateFailTimes = OTA_SHOW_ACTIVATE_FAIL_COUNT_OFF;
1526 otaPlaySuccessFailureTone = OTA_PLAY_SUCCESS_FAILURE_TONE_OFF;
1527 }
1528 }
1529
1530 /**
1531 * The state of the OTA InCallScreen UI.
1532 */
1533 public static class CdmaOtaInCallScreenUiState {
1534 public enum State {
1535 UNDEFINED,
1536 NORMAL,
1537 ENDED
1538 }
1539
1540 public State state;
1541
1542 public CdmaOtaInCallScreenUiState() {
1543 if (DBG) log("CdmaOtaInCallScreenState: constructor init to UNDEFINED");
1544 state = CdmaOtaInCallScreenUiState.State.UNDEFINED;
1545 }
1546 }
1547
1548 /**
1549 * Save the Ota InCallScreen UI state
1550 */
1551 public void setCdmaOtaInCallScreenUiState(CdmaOtaInCallScreenUiState.State state) {
1552 if (DBG) log("setCdmaOtaInCallScreenState: " + state);
1553 mApplication.cdmaOtaInCallScreenUiState.state = state;
1554 }
1555
1556 /**
1557 * Get the Ota InCallScreen UI state
1558 */
1559 public CdmaOtaInCallScreenUiState.State getCdmaOtaInCallScreenUiState() {
1560 if (DBG) log("getCdmaOtaInCallScreenState: "
1561 + mApplication.cdmaOtaInCallScreenUiState.state);
1562 return mApplication.cdmaOtaInCallScreenUiState.state;
1563 }
1564
1565 /**
1566 * The OTA screen state machine.
1567 */
1568 public static class CdmaOtaScreenState {
1569 public enum OtaScreenState {
1570 OTA_STATUS_UNDEFINED,
1571 OTA_STATUS_ACTIVATION,
1572 OTA_STATUS_LISTENING,
1573 OTA_STATUS_PROGRESS,
1574 OTA_STATUS_SUCCESS_FAILURE_DLG
1575 }
1576
1577 public OtaScreenState otaScreenState;
1578
1579 public CdmaOtaScreenState() {
1580 otaScreenState = OtaScreenState.OTA_STATUS_UNDEFINED;
1581 }
1582
1583 /**
1584 * {@link PendingIntent} used to report an OTASP result status code
1585 * back to our caller. Can be null.
1586 *
1587 * Our caller (presumably SetupWizard) may create this PendingIntent,
1588 * pointing back at itself, and passes it along as an extra with the
1589 * ACTION_PERFORM_CDMA_PROVISIONING intent. Then, when there's an
1590 * OTASP result to report, we send that PendingIntent back, adding an
1591 * extra called EXTRA_OTASP_RESULT_CODE to indicate the result.
1592 *
1593 * Possible result values are the OTASP_RESULT_* constants.
1594 */
1595 public PendingIntent otaspResultCodePendingIntent;
1596 }
1597
1598 /** @see com.android.internal.telephony.Phone */
1599 private static String otaProvisionStatusToString(int status) {
1600 switch (status) {
1601 case Phone.CDMA_OTA_PROVISION_STATUS_SPL_UNLOCKED:
1602 return "SPL_UNLOCKED";
1603 case Phone.CDMA_OTA_PROVISION_STATUS_SPC_RETRIES_EXCEEDED:
1604 return "SPC_RETRIES_EXCEEDED";
1605 case Phone.CDMA_OTA_PROVISION_STATUS_A_KEY_EXCHANGED:
1606 return "A_KEY_EXCHANGED";
1607 case Phone.CDMA_OTA_PROVISION_STATUS_SSD_UPDATED:
1608 return "SSD_UPDATED";
1609 case Phone.CDMA_OTA_PROVISION_STATUS_NAM_DOWNLOADED:
1610 return "NAM_DOWNLOADED";
1611 case Phone.CDMA_OTA_PROVISION_STATUS_MDN_DOWNLOADED:
1612 return "MDN_DOWNLOADED";
1613 case Phone.CDMA_OTA_PROVISION_STATUS_IMSI_DOWNLOADED:
1614 return "IMSI_DOWNLOADED";
1615 case Phone.CDMA_OTA_PROVISION_STATUS_PRL_DOWNLOADED:
1616 return "PRL_DOWNLOADED";
1617 case Phone.CDMA_OTA_PROVISION_STATUS_COMMITTED:
1618 return "COMMITTED";
1619 case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_STARTED:
1620 return "OTAPA_STARTED";
1621 case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_STOPPED:
1622 return "OTAPA_STOPPED";
1623 case Phone.CDMA_OTA_PROVISION_STATUS_OTAPA_ABORTED:
1624 return "OTAPA_ABORTED";
1625 default:
1626 return "<unknown status" + status + ">";
1627 }
1628 }
1629
1630 private static int getLteOnCdmaMode(Context context) {
1631 final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(
1632 Context.TELEPHONY_SERVICE);
1633 // If the telephony manager is not available yet, or if it doesn't know the answer yet,
1634 // try falling back on the system property that may or may not be there
1635 if (telephonyManager == null
1636 || telephonyManager.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_UNKNOWN) {
1637 return SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE,
1638 PhoneConstants.LTE_ON_CDMA_UNKNOWN);
1639 }
1640 return telephonyManager.getLteOnCdmaMode();
1641 }
1642
1643 private static void log(String msg) {
1644 Log.d(LOG_TAG, msg);
1645 }
1646
1647 private static void loge(String msg) {
1648 Log.e(LOG_TAG, msg);
1649 }
1650}