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