OtaUtils.java revision 5c0517ae3c17505ffd466be79ab0026b7fe6c959
1af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville/*
2af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * Copyright (C) 2009 The Android Open Source Project
3af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville *
4af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * Licensed under the Apache License, Version 2.0 (the "License");
5af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * you may not use this file except in compliance with the License.
6af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * You may obtain a copy of the License at
7af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville *
8af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville *      http://www.apache.org/licenses/LICENSE-2.0
9af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville *
10af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * Unless required by applicable law or agreed to in writing, software
11af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * distributed under the License is distributed on an "AS IS" BASIS,
12af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * See the License for the specific language governing permissions and
14af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * limitations under the License.
15af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville */
16af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
17af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savillepackage com.android.phone;
18af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
19af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport com.android.internal.telephony.Phone;
205c0517ae3c17505ffd466be79ab0026b7fe6c959Wink Savilleimport com.android.phone.OtaUtils.CdmaOtaInCallScreenUiState.State;
21af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
22af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.app.AlertDialog;
23af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.content.Context;
24af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.content.DialogInterface;
25af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.content.Intent;
26839b14d460986608fe577f89f789de854dc85b58Jim Millerimport android.content.pm.ResolveInfo;
27af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.os.AsyncResult;
28839b14d460986608fe577f89f789de854dc85b58Jim Millerimport android.os.Handler;
29839b14d460986608fe577f89f789de854dc85b58Jim Millerimport android.os.Message;
30af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.os.SystemClock;
31af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.os.SystemProperties;
32839b14d460986608fe577f89f789de854dc85b58Jim Millerimport android.provider.Settings;
33af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
34af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.util.Log;
35af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.view.KeyEvent;
36af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.view.View;
37af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.view.ViewGroup;
38af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.view.ViewStub;
39af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.view.WindowManager;
40af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
41af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.widget.Button;
42af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.widget.ToggleButton;
43af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.widget.ProgressBar;
44af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savilleimport android.widget.TextView;
45af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
46af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville/**
47af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville * Handles all OTA Call related logic and UI functionality.
48e31831f42ffa08456ef0d5d1461ddc70b9d1fcfeDavid Brown * The InCallScreen interacts with this class to perform an OTA Call.
49e31831f42ffa08456ef0d5d1461ddc70b9d1fcfeDavid Brown *
50e31831f42ffa08456ef0d5d1461ddc70b9d1fcfeDavid Brown * OTA is a CDMA-specific feature:
51e31831f42ffa08456ef0d5d1461ddc70b9d1fcfeDavid Brown *   OTA or OTASP == Over The Air service provisioning
52e31831f42ffa08456ef0d5d1461ddc70b9d1fcfeDavid Brown *   SPC == Service Programming Code
53e31831f42ffa08456ef0d5d1461ddc70b9d1fcfeDavid Brown *   TODO: Include pointer to more detailed documentation.
54af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville */
55af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Savillepublic class OtaUtils {
56af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private static final String LOG_TAG = "OtaUtils";
57839b14d460986608fe577f89f789de854dc85b58Jim Miller    private static final String UNACTIVATED_MIN2_VALUE = "000000";
58839b14d460986608fe577f89f789de854dc85b58Jim Miller    private static final String UNACTIVATED_MIN_VALUE = "1111110111";
595c0517ae3c17505ffd466be79ab0026b7fe6c959Wink Saville    private static final boolean DBG = (PhoneApp.DBG_LEVEL >= 1);
60af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
61af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static final int OTA_SHOW_ACTIVATION_SCREEN_OFF = 0;
62af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static final int OTA_SHOW_ACTIVATION_SCREEN_ON = 1;
63af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static final int OTA_SHOW_LISTENING_SCREEN_OFF =0;
64af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static final int OTA_SHOW_LISTENING_SCREEN_ON =1;
65af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static final int OTA_SHOW_ACTIVATE_FAIL_COUNT_OFF = 0;
66af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static final int OTA_SHOW_ACTIVATE_FAIL_COUNT_THREE = 3;
67af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static final int OTA_PLAY_SUCCESS_FAILURE_TONE_OFF = 0;
68af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static final int OTA_PLAY_SUCCESS_FAILURE_TONE_ON = 1;
69af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
7017c36a10d09fac3e2312c0bcb839e0a704f42105w    // SPC Timeout is 60 seconds
7117c36a10d09fac3e2312c0bcb839e0a704f42105w    public final int OTA_SPC_TIMEOUT = 60;
72af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public final int OTA_FAILURE_DIALOG_TIMEOUT = 2;
73af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
74af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private InCallScreen mInCallScreen;
75af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private Context mContext;
76af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private PhoneApp mApplication;
77af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private OtaWidgetData mOtaWidgetData;
78af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private ViewGroup mInCallPanel;
79af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private CallCard mCallCard;
80af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private DTMFTwelveKeyDialer mDialer;
8157a38778e8c9f58b24cea1062e451934cadc4b3dJim Miller    private static boolean mIsWizardMode = true;
82af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
83af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
84af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * OtaWidgetData class represent all OTA UI elements
85af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
86af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private class OtaWidgetData {
87af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public Button otaEndButton;
88af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public Button otaActivateButton;
89af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public Button otaCancelButton;
90986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        public Button otaNextButton;
91af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public ToggleButton otaSpeakerButton;
92af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public View otaCallCardBase;
93af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public View callCardOtaButtonsFailSuccess;
94af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public ProgressBar otaTextProgressBar;
95af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public TextView otaTextSuccessFail;
96af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public View callCardOtaButtonsActivate;
97af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public View callCardOtaButtonsListenProgress;
98af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public TextView otaTextActivate;
99af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public TextView otaTextListenProgress;
100af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public AlertDialog spcErrorDialog;
101af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public AlertDialog otaFailureDialog;
102986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        public TextView otaTitle;
103986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        public DTMFTwelveKeyDialerView otaDtmfDialerView;
104986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        public Button otaTryAgainButton;
105af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
106af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
107af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public OtaUtils(Context context,
108af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    InCallScreen inCallScreen,
109af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    ViewGroup inCallPanel,
110af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    CallCard callCard,
1118df5c508da2c836b841ee24120fa7c5cc92df387David Brown                    DTMFTwelveKeyDialer dialer) {
112af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
113af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("Enter OtaUtil constructor");
114af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
115af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mInCallScreen = inCallScreen;
116af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mContext = context;
117af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mInCallPanel = inCallPanel;
118af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mCallCard = callCard;
119af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mDialer = dialer;
120af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication = PhoneApp.getInstance();
121af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData = new OtaWidgetData();
122af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
123af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        // inflate OTA Call card and footers
124af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        ViewStub otaCallCardStub = (ViewStub) mInCallScreen.findViewById(R.id.otaCallCardStub);
125af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        otaCallCardStub.inflate();
126af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        readXmlSettings();
127af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        initOtaInCallScreen();
128af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
129a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent
130839b14d460986608fe577f89f789de854dc85b58Jim Miller    /**
131839b14d460986608fe577f89f789de854dc85b58Jim Miller     * Returns true if the phone needs activation.
132a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent     *
133839b14d460986608fe577f89f789de854dc85b58Jim Miller     * @param minString the phone's MIN configuration string
134839b14d460986608fe577f89f789de854dc85b58Jim Miller     * @return true if phone needs activation
135839b14d460986608fe577f89f789de854dc85b58Jim Miller     * @throws OtaConfigurationException if the string is invalid
136839b14d460986608fe577f89f789de854dc85b58Jim Miller     */
137839b14d460986608fe577f89f789de854dc85b58Jim Miller    public static boolean needsActivation(String minString) throws IllegalArgumentException {
138839b14d460986608fe577f89f789de854dc85b58Jim Miller        if (minString == null || (minString.length() < 6)) {
139839b14d460986608fe577f89f789de854dc85b58Jim Miller            throw new IllegalArgumentException();
140839b14d460986608fe577f89f789de854dc85b58Jim Miller        }
141a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent        return (minString.equals(UNACTIVATED_MIN_VALUE)
142839b14d460986608fe577f89f789de854dc85b58Jim Miller                || minString.substring(0,6).equals(UNACTIVATED_MIN2_VALUE))
143839b14d460986608fe577f89f789de854dc85b58Jim Miller                || SystemProperties.getBoolean("test_cdma_setup", false);
144839b14d460986608fe577f89f789de854dc85b58Jim Miller    }
145a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent
146839b14d460986608fe577f89f789de854dc85b58Jim Miller    /**
147839b14d460986608fe577f89f789de854dc85b58Jim Miller     * Starts the OTA provisioning call.  If the MIN isn't available yet, it returns false and adds
148a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent     * an event to return the request to the calling app when it becomes available.
149a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent     *
150839b14d460986608fe577f89f789de854dc85b58Jim Miller     * @param context
151839b14d460986608fe577f89f789de854dc85b58Jim Miller     * @param handler
152839b14d460986608fe577f89f789de854dc85b58Jim Miller     * @param request
153839b14d460986608fe577f89f789de854dc85b58Jim Miller     * @return true if we were able to launch Ota activity or it's not required; false otherwise
154839b14d460986608fe577f89f789de854dc85b58Jim Miller     */
155839b14d460986608fe577f89f789de854dc85b58Jim Miller    public static boolean maybeDoOtaCall(Context context, Handler handler, int request) {
156839b14d460986608fe577f89f789de854dc85b58Jim Miller        PhoneApp app = PhoneApp.getInstance();
157839b14d460986608fe577f89f789de854dc85b58Jim Miller        Phone phone = app.phone;
158839b14d460986608fe577f89f789de854dc85b58Jim Miller
159839b14d460986608fe577f89f789de854dc85b58Jim Miller        if (!isCdmaPhone()) {
160839b14d460986608fe577f89f789de854dc85b58Jim Miller            if (DBG) Log.v("OtaUtils", "Can't run provisioning on a non-CDMA phone");
161839b14d460986608fe577f89f789de854dc85b58Jim Miller            return true; // sanity check - a non-cdma phone doesn't need to run this
162839b14d460986608fe577f89f789de854dc85b58Jim Miller        }
163839b14d460986608fe577f89f789de854dc85b58Jim Miller
164839b14d460986608fe577f89f789de854dc85b58Jim Miller        if (!phone.isMinInfoReady()) {
165839b14d460986608fe577f89f789de854dc85b58Jim Miller            if (DBG) log("MIN is not ready. Registering to receive notification.");
166839b14d460986608fe577f89f789de854dc85b58Jim Miller            phone.registerForSubscriptionInfoReady(handler, request, null);
167839b14d460986608fe577f89f789de854dc85b58Jim Miller            return false;
168839b14d460986608fe577f89f789de854dc85b58Jim Miller        }
169839b14d460986608fe577f89f789de854dc85b58Jim Miller
170839b14d460986608fe577f89f789de854dc85b58Jim Miller        phone.unregisterForSubscriptionInfoReady(handler);
171839b14d460986608fe577f89f789de854dc85b58Jim Miller        String min = phone.getCdmaMin();
172839b14d460986608fe577f89f789de854dc85b58Jim Miller
173839b14d460986608fe577f89f789de854dc85b58Jim Miller        if (DBG) log("min_string: " + min);
174839b14d460986608fe577f89f789de854dc85b58Jim Miller
175839b14d460986608fe577f89f789de854dc85b58Jim Miller        boolean phoneNeedsActivation = false;
176839b14d460986608fe577f89f789de854dc85b58Jim Miller        try {
177839b14d460986608fe577f89f789de854dc85b58Jim Miller            phoneNeedsActivation = needsActivation(min);
178839b14d460986608fe577f89f789de854dc85b58Jim Miller        } catch (IllegalArgumentException e) {
179839b14d460986608fe577f89f789de854dc85b58Jim Miller            if (DBG) log("invalid MIN string, exit");
180839b14d460986608fe577f89f789de854dc85b58Jim Miller            return true; // If the MIN string is wrong, there's nothing else we can do.
181839b14d460986608fe577f89f789de854dc85b58Jim Miller        }
182839b14d460986608fe577f89f789de854dc85b58Jim Miller
183839b14d460986608fe577f89f789de854dc85b58Jim Miller        if (DBG) log("phoneNeedsActivation is set to " + phoneNeedsActivation);
184a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent
185839b14d460986608fe577f89f789de854dc85b58Jim Miller        int otaShowActivationScreen = context.getResources().getInteger(
186839b14d460986608fe577f89f789de854dc85b58Jim Miller                R.integer.OtaShowActivationScreen);
187839b14d460986608fe577f89f789de854dc85b58Jim Miller
188839b14d460986608fe577f89f789de854dc85b58Jim Miller        if (DBG) log("otaShowActivationScreen: " + otaShowActivationScreen);
189839b14d460986608fe577f89f789de854dc85b58Jim Miller
190839b14d460986608fe577f89f789de854dc85b58Jim Miller        if (phoneNeedsActivation && (otaShowActivationScreen == OTA_SHOW_ACTIVATION_SCREEN_ON)) {
191839b14d460986608fe577f89f789de854dc85b58Jim Miller            app.cdmaOtaProvisionData.isOtaCallIntentProcessed = false;
192839b14d460986608fe577f89f789de854dc85b58Jim Miller            Intent newIntent = new Intent(InCallScreen.ACTION_SHOW_ACTIVATION);
193839b14d460986608fe577f89f789de854dc85b58Jim Miller            newIntent.setClass(context, InCallScreen.class);
194839b14d460986608fe577f89f789de854dc85b58Jim Miller            newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
19557a38778e8c9f58b24cea1062e451934cadc4b3dJim Miller            mIsWizardMode = false;
196839b14d460986608fe577f89f789de854dc85b58Jim Miller            context.startActivity(newIntent);
197839b14d460986608fe577f89f789de854dc85b58Jim Miller            if (DBG) log("activation intent sent.");
198839b14d460986608fe577f89f789de854dc85b58Jim Miller        } else {
199839b14d460986608fe577f89f789de854dc85b58Jim Miller            if (DBG) log("activation intent NOT sent.");
200839b14d460986608fe577f89f789de854dc85b58Jim Miller        }
201839b14d460986608fe577f89f789de854dc85b58Jim Miller        return true;
202839b14d460986608fe577f89f789de854dc85b58Jim Miller    }
203af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
204af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void setSpeaker(boolean state) {
205af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("setSpeaker : " + state );
206af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (state == PhoneUtils.isSpeakerOn(mContext)) {
207af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("no change. returning");
208af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            return;
209af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
210af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
211af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (state && mInCallScreen.isBluetoothAvailable()
212af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                && mInCallScreen.isBluetoothAudioConnected()) {
213af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mInCallScreen.disconnectBluetoothAudio();
214af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
215425b8e3c9846d5e0e76466604b35cad8856d79deEric Laurent        PhoneUtils.turnOnSpeaker(mContext, state, true);
216af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
217af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
218af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
219af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Handle OTA Provision events from Framework. Possible events are:
220af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * OTA Commit Event - OTA provisioning was successful
221af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * SPC retries exceeded - SPC failure retries has exceeded, and Phone needs to
222af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     *    power down.
223af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
224af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public void onOtaProvisionStatusChanged(AsyncResult r) {
225af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        int OtaStatus[] = (int[]) r.result;
226af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("onOtaProvisionStatusChanged(): OtaStatus[0]" + OtaStatus[0]);
227af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
228af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        otaShowInProgressScreen();
229af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        switch(OtaStatus[0]) {
230af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            case Phone.CDMA_OTA_PROVISION_STATUS_SPC_RETRIES_EXCEEDED:
231af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mApplication.cdmaOtaProvisionData.otaSpcUptime = SystemClock.elapsedRealtime();
232af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                otaShowSpcErrorNotice(OTA_SPC_TIMEOUT);
233af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                // Power.shutdown();
234af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                break;
235af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            case Phone.CDMA_OTA_PROVISION_STATUS_COMMITTED:
236af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mApplication.cdmaOtaProvisionData.isOtaCallCommitted = true;
237af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                if (DBG) log("onOtaProvisionStatusChanged(): isOtaCallCommitted set to true");
238af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                break;
239af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
240af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
241af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
242af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void otaShowHome() {
243af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowHome()...");
244af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication.cdmaOtaScreenState.otaScreenState =
245af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED;
246af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        cleanOtaScreen();
247af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        Intent intent = new Intent(Intent.ACTION_MAIN);
248af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        intent.addCategory (Intent.CATEGORY_HOME);
249af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
250af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mContext.startActivity(intent);
251af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mInCallScreen.finish();
252af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        return;
253af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
254af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
255af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
256af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Show Activation Screen when phone powers up and OTA provision is
257af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * required. Also shown when activation fails and user needs
258af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * to re-attempt it. Contains ACTIVE and CANCEL buttons
259af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * which allow user to start OTA activation or cancel the activation process.
260af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
261af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public void otaShowActivateScreen() {
262af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowActivationScreen()...");
263af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mApplication.cdmaOtaConfigData.otaShowActivationScreen
264af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                == OTA_SHOW_ACTIVATION_SCREEN_ON) {
265af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("OtaShowActivationScreen(): show activation screen");
266e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman            if (!isDialerOpened()) {
267af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                otaScreenInitialize();
26857a38778e8c9f58b24cea1062e451934cadc4b3dJim Miller                mOtaWidgetData.otaCancelButton.setVisibility(mIsWizardMode ?
26957a38778e8c9f58b24cea1062e451934cadc4b3dJim Miller                        View.VISIBLE : View.INVISIBLE);
270af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mOtaWidgetData.otaTextActivate.setVisibility(View.VISIBLE);
271af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.VISIBLE);
272e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman            } else {
2738df5c508da2c836b841ee24120fa7c5cc92df387David Brown                mDialer.setHandleVisible(true);
274af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            }
275af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mApplication.cdmaOtaScreenState.otaScreenState =
276af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION;
277af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        } else {
278af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("OtaShowActivationScreen(): show home screen");
279af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowHome();
280af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
281af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     }
282af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
283af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
284af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Show "Listen for Instruction" screen during OTA call. Shown when OTA Call
285af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * is initiated and user needs to listen for network instructions and press
286af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * appropriate DTMF digits to proceed to the "Programming in Progress" phase.
287af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
288af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void otaShowListeningScreen() {
289af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowListeningScreen()...");
290af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mApplication.cdmaOtaConfigData.otaShowListeningScreen
291af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                == OTA_SHOW_LISTENING_SCREEN_ON) {
292af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("OtaShowListeningScreen(): show listening screen");
293e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman            if (!isDialerOpened()) {
294af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                otaScreenInitialize();
295af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mOtaWidgetData.otaTextListenProgress.setVisibility(View.VISIBLE);
296af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mOtaWidgetData.otaTextListenProgress.setText(R.string.ota_listen);
297986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller                mOtaWidgetData.otaDtmfDialerView.setVisibility(View.VISIBLE);
298af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.VISIBLE);
299986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller                mOtaWidgetData.otaSpeakerButton.setVisibility(View.VISIBLE);
300a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent                boolean speakerOn = PhoneUtils.isSpeakerOn(mContext);
301a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent                mOtaWidgetData.otaSpeakerButton.setChecked(speakerOn);
302e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman            } else {
3038df5c508da2c836b841ee24120fa7c5cc92df387David Brown                mDialer.setHandleVisible(true);
304af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            }
305af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mApplication.cdmaOtaScreenState.otaScreenState =
306af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    CdmaOtaScreenState.OtaScreenState.OTA_STATUS_LISTENING;
307af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
308af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            // Update the state of the in-call menu items.
309af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mInCallScreen.updateMenuItems();
310af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        } else {
311af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("OtaShowListeningScreen(): show progress screen");
312af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowInProgressScreen();
313af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
314af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
315af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
316af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
317af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Show "Programming In Progress" screen during OTA call. Shown when OTA
318af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * provisioning is in progress after user has selected an option.
319af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
320af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void otaShowInProgressScreen() {
321af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowInProgressScreen()...");
322e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman        if (!isDialerOpened()) {
323af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaScreenInitialize();
324af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.otaTextListenProgress.setVisibility(View.VISIBLE);
325af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.otaTextListenProgress.setText(R.string.ota_progress);
326af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.otaTextProgressBar.setVisibility(View.VISIBLE);
327af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.VISIBLE);
3289bd141ba20a6cf6dcb745aca6c5c05a9c88f3a98Jim Miller            mOtaWidgetData.otaSpeakerButton.setVisibility(View.VISIBLE);
329a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent            boolean speakerOn = PhoneUtils.isSpeakerOn(mContext);
330a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent            mOtaWidgetData.otaSpeakerButton.setChecked(speakerOn);
331e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman        } else {
3328df5c508da2c836b841ee24120fa7c5cc92df387David Brown            mDialer.setHandleVisible(true);
333af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
334af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication.cdmaOtaScreenState.otaScreenState =
335af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            CdmaOtaScreenState.OtaScreenState.OTA_STATUS_PROGRESS;
336af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
337af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        // Update the state of the in-call menu items.
338af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mInCallScreen.updateMenuItems();
339af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
340af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
341af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
342af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Show programming failure dialog when OTA provisioning fails.
343af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * If OTA provisioning attempts fail more than 3 times, then unsuccessful
344af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * dialog is shown. Otherwise a two-second notice is shown with unsuccessful
345af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * information. When notice expires, phone returns to activation screen.
346af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
347986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller    private void otaShowProgramFailure(int length) {
348af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowProgramFailure()...");
349af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication.cdmaOtaProvisionData.activationCount++;
350af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if ((mApplication.cdmaOtaProvisionData.activationCount <
351af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mApplication.cdmaOtaConfigData.otaShowActivateFailTimes)
352af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                && (mApplication.cdmaOtaConfigData.otaShowActivationScreen ==
353af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                OTA_SHOW_ACTIVATION_SCREEN_ON)) {
354af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("OtaShowProgramFailure(): activationCount"
355af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    + mApplication.cdmaOtaProvisionData.activationCount);
356af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("OtaShowProgramFailure(): show failure notice");
357af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowProgramFailureNotice(length);
358af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        } else {
359af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("OtaShowProgramFailure(): show failure dialog");
360af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowProgramFailureDialog();
361af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
362af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
363af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
364af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
365af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Show either programming success dialog when OTA provisioning succeeds, or
366af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * programming failure dialog when it fails. See {@link otaShowProgramFailure}
367af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * for more details.
368af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
369af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public void otaShowSuccessFailure() {
370af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowSuccessFailure()...");
371af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        otaScreenInitialize();
372af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowSuccessFailure(): isOtaCallCommitted"
373af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                + mApplication.cdmaOtaProvisionData.isOtaCallCommitted);
374af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mApplication.cdmaOtaProvisionData.isOtaCallCommitted) {
375af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("OtaShowSuccessFailure(), show success dialog");
376af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowProgramSuccessDialog();
377af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        } else {
378af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("OtaShowSuccessFailure(), show failure dialog");
379af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowProgramFailure(OTA_FAILURE_DIALOG_TIMEOUT);
380af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
381af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        return;
382af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
383af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
384af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
385af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Show programming failure dialog when OTA provisioning fails more than 3
386af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * times.
387af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
388af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void otaShowProgramFailureDialog() {
389af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowProgramFailureDialog()...");
390af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication.cdmaOtaScreenState.otaScreenState =
391af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                CdmaOtaScreenState.OtaScreenState.OTA_STATUS_SUCCESS_FAILURE_DLG;
392986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTitle.setText(R.string.ota_title_problem_with_activation);
393af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextSuccessFail.setVisibility(View.VISIBLE);
394af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextSuccessFail.setText(R.string.ota_unsuccessful);
395af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.VISIBLE);
396986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTryAgainButton.setVisibility(View.VISIBLE);
397af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        //close the dialer if open
398e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman        if (isDialerOpened()) {
399af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mDialer.closeDialer(false);
400af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
401af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
402af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
403af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
404af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Show programming success dialog when OTA provisioning succeeds.
405af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
406af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void otaShowProgramSuccessDialog() {
407af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowProgramSuccessDialog()...");
408af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication.cdmaOtaScreenState.otaScreenState =
409af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                CdmaOtaScreenState.OtaScreenState.OTA_STATUS_SUCCESS_FAILURE_DLG;
410986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTitle.setText(R.string.ota_title_activate_success);
411af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextSuccessFail.setVisibility(View.VISIBLE);
412af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextSuccessFail.setText(R.string.ota_successful);
413af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.VISIBLE);
414986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaNextButton.setVisibility(View.VISIBLE);
415af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        //close the dialer if open
416e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman        if (isDialerOpened()) {
417af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mDialer.closeDialer(false);
418af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
419af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
420af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
421af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
422af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Show SPC failure notice when SPC attempts exceed 15 times.
423af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * During OTA provisioning, if SPC code is incorrect OTA provisioning will
424af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * fail. When SPC attempts are over 15, it shows SPC failure notice for one minute and
425af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * then phone will power down.
426af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
427af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void otaShowSpcErrorNotice(int length) {
428af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowSpcErrorNotice()...");
429af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mOtaWidgetData.spcErrorDialog == null) {
430af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mApplication.cdmaOtaProvisionData.inOtaSpcState = true;
431af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            DialogInterface.OnKeyListener keyListener;
432af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            keyListener = new DialogInterface.OnKeyListener() {
433af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
434af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    log("Ignoring key events...");
435af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    return true;
436af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                }};
437af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.spcErrorDialog = new AlertDialog.Builder(mInCallScreen)
438af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    .setMessage(R.string.ota_spc_failure)
439af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    .setOnKeyListener(keyListener)
440af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    .create();
441af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.spcErrorDialog.getWindow().addFlags(
442af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
443af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
444af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.spcErrorDialog.show();
445af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            //close the dialer if open
446e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman            if (isDialerOpened()) {
447af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mDialer.closeDialer(false);
448af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            }
449af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            long noticeTime = length*1000;
450325cc2ced6f1ff5fb1708abfcc5e9c73ac0cd962David Brown            if (DBG) log("OtaShowSpcErrorNotice(), remaining SPC noticeTime" + noticeTime);
451325cc2ced6f1ff5fb1708abfcc5e9c73ac0cd962David Brown            mInCallScreen.requestCloseSpcErrorNotice(noticeTime);
452af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
453af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
454af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
455af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
456af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * When SPC notice times out, force phone to power down.
457af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
458af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public void onOtaCloseSpcNotice() {
45917c36a10d09fac3e2312c0bcb839e0a704f42105w        if (DBG) log("onOtaCloseSpcNotice(), send shutdown intent");
46017c36a10d09fac3e2312c0bcb839e0a704f42105w        Intent shutdown = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
46117c36a10d09fac3e2312c0bcb839e0a704f42105w        shutdown.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
46217c36a10d09fac3e2312c0bcb839e0a704f42105w        shutdown.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
46317c36a10d09fac3e2312c0bcb839e0a704f42105w        mContext.startActivity(shutdown);
464af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
465af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
466af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
467af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Show two-second notice when OTA provisioning fails and number of failed attempts
468af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * is less then 3.
469af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
470af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void otaShowProgramFailureNotice(int length) {
471af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaShowProgramFailureNotice()...");
472af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mOtaWidgetData.otaFailureDialog == null) {
473af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.otaFailureDialog = new AlertDialog.Builder(mInCallScreen)
474af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    .setMessage(R.string.ota_failure)
475af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    .create();
476af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.otaFailureDialog.getWindow().addFlags(
477af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
478af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
479af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.otaFailureDialog.show();
480af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
481af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            long noticeTime = length*1000;
482325cc2ced6f1ff5fb1708abfcc5e9c73ac0cd962David Brown            mInCallScreen.requestCloseOtaFailureNotice(noticeTime);
483af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
484af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
485af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
486af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
487af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Handle OTA unsuccessful notice expiry. Dismisses the
488af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * two-second notice and shows the activation screen.
489af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
490af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public void onOtaCloseFailureNotice() {
491af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("onOtaCloseFailureNotice()...");
492af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mOtaWidgetData.otaFailureDialog != null) {
493af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.otaFailureDialog.dismiss();
494af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.otaFailureDialog = null;
495af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
496af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        otaShowActivateScreen();
497af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
498af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
499af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
500af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Initialize all OTA UI elements to be gone. Also set inCallPanel,
5018df5c508da2c836b841ee24120fa7c5cc92df387David Brown     * callCard and the dialpad handle to be gone. This is called before any OTA screen
502af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * gets drawn.
503af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
504af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void otaScreenInitialize() {
505af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OtaScreenInitialize()...");
506af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
507af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mInCallPanel != null) mInCallPanel.setVisibility(View.GONE);
508af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mCallCard != null) mCallCard.hideCallCardElements();
5098df5c508da2c836b841ee24120fa7c5cc92df387David Brown        mDialer.setHandleVisible(false);
510af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
511986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTitle.setText(R.string.ota_title_activate);
512af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextActivate.setVisibility(View.GONE);
513af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextListenProgress.setVisibility(View.GONE);
514af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextProgressBar.setVisibility(View.GONE);
515af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextSuccessFail.setVisibility(View.GONE);
516af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.GONE);
517af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.GONE);
518af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.GONE);
519986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaDtmfDialerView.setVisibility(View.GONE);
520986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaSpeakerButton.setVisibility(View.GONE);
521986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTryAgainButton.setVisibility(View.GONE);
522986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaNextButton.setVisibility(View.GONE);
523af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaCallCardBase.setVisibility(View.VISIBLE);
52457a38778e8c9f58b24cea1062e451934cadc4b3dJim Miller        mOtaWidgetData.otaCancelButton.setVisibility(View.VISIBLE);
525af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
526af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
527af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public void hideOtaScreen() {
528af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("hideOtaScreen()...");
529af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
530af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.GONE);
531af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.GONE);
532af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.GONE);
533af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaCallCardBase.setVisibility(View.GONE);
534af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
535af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
536e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman    public boolean isDialerOpened() {
537e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman        return (mDialer != null && mDialer.isOpened());
538e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman    }
539e4a6da04f5ed72f8be2e578b91d041493277e248Paul Berman
540af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
541af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Show the appropriate OTA screen based on the current state of OTA call.
542af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Shown whenever calling screen is resumed.
543af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
544af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public void otaShowProperScreen() {
545af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("otaShowProperScreen()...");
546af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mInCallScreen.isForegroundActivity()) {
547af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("otaShowProperScreen(), OTA is foreground activity, currentstate ="
548af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    + mApplication.cdmaOtaScreenState.otaScreenState);
549af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (mInCallPanel != null) {
550af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mInCallPanel.setVisibility(View.GONE);
551af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            }
552af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (mApplication.cdmaOtaScreenState.otaScreenState
553af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    == CdmaOtaScreenState.OtaScreenState.OTA_STATUS_ACTIVATION) {
554af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                otaShowActivateScreen();
555af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            } else if (mApplication.cdmaOtaScreenState.otaScreenState
556af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    == CdmaOtaScreenState.OtaScreenState.OTA_STATUS_LISTENING) {
557af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                otaShowListeningScreen();
558af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            } else if (mApplication.cdmaOtaScreenState.otaScreenState
559af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    == CdmaOtaScreenState.OtaScreenState.OTA_STATUS_PROGRESS) {
560af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                otaShowInProgressScreen();
561af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            }
562af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
563af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (mApplication.cdmaOtaProvisionData.inOtaSpcState) {
564af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                otaShowSpcErrorNotice(getOtaSpcDisplayTime());
565af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            }
566af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
567af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
568af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
569af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
570af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Read configuration values for each OTA screen from config.xml.
571af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * These configuration values control visibility of each screen.
572af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
573af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void readXmlSettings() {
574af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("readXmlSettings()...");
575af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mApplication.cdmaOtaConfigData.configComplete) {
576af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            return;
577af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
578af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
579af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication.cdmaOtaConfigData.configComplete = true;
580af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        int tmpOtaShowActivationScreen =
581af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mContext.getResources().getInteger(R.integer.OtaShowActivationScreen);
582af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication.cdmaOtaConfigData.otaShowActivationScreen = tmpOtaShowActivationScreen;
583af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("readXmlSettings(), otaShowActivationScreen"
584af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                + mApplication.cdmaOtaConfigData.otaShowActivationScreen);
585af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
586af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        int tmpOtaShowListeningScreen =
587af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mContext.getResources().getInteger(R.integer.OtaShowListeningScreen);
588af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication.cdmaOtaConfigData.otaShowListeningScreen = tmpOtaShowListeningScreen;
589af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("readXmlSettings(), otaShowListeningScreen"
590af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                + mApplication.cdmaOtaConfigData.otaShowListeningScreen);
591af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
592af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        int tmpOtaShowActivateFailTimes =
593af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mContext.getResources().getInteger(R.integer.OtaShowActivateFailTimes);
594af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication.cdmaOtaConfigData.otaShowActivateFailTimes = tmpOtaShowActivateFailTimes;
595af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("readXmlSettings(), otaShowActivateFailTimes"
596af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                + mApplication.cdmaOtaConfigData.otaShowActivateFailTimes);
597af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
598af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        int tmpOtaPlaySuccessFailureTone =
599af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                mContext.getResources().getInteger(R.integer.OtaPlaySuccessFailureTone);
600af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mApplication.cdmaOtaConfigData.otaPlaySuccessFailureTone = tmpOtaPlaySuccessFailureTone;
601af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("readXmlSettings(), otaPlaySuccessFailureTone"
602af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                + mApplication.cdmaOtaConfigData.otaPlaySuccessFailureTone);
603af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
604af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
605af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
606af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Handle the click events for OTA buttons.
607af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
608af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public void onClickHandler(int id) {
609af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        switch (id) {
610af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            case R.id.otaEndButton:
611af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                onClickOtaEndButton();
612af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                break;
613af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
614af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            case R.id.otaSpeakerButton:
615af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                onClickOtaSpeakerButton();
616af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                break;
617af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
618af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            case R.id.otaActivateButton:
619af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                onClickOtaActivateButton();
620af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                break;
621af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
622af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            case R.id.otaCancelButton:
623af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                onClickOtaActivateCancelButton();
624af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                break;
625af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
626986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller            case R.id.otaNextButton:
627986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller                onClickOtaActivateNextButton();
628af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                break;
629af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
630986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller            case R.id.otaTryAgainButton:
631986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller                onClickOtaTryAgainButton();
632af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                break;
633af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
634af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            default:
635af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                if (DBG) log ("onClickHandler: received a click event for unrecognized id");
636af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                break;
637af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
638af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
639af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
640986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller    private void onClickOtaTryAgainButton() {
641986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        if (DBG) log("Activation Try Again Clicked!");
642986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
643986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller            otaShowActivateScreen();
644986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        }
645986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller    }
646986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller
647af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void onClickOtaEndButton() {
648986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        if (DBG) log("Activation End Call Button Clicked!");
649af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
650a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent            if (PhoneUtils.hangup(mApplication.phone) == false) {
651a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent                // If something went wrong when placing the OTA call,
652a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent                // the screen is not updated by the call disconnect
653a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent                // handler and we have to do it here
654a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent                setSpeaker(false);
655a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent                mInCallScreen.handleOtaCallEnd();
656a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent            }
657af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
658af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
659af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
660af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void onClickOtaSpeakerButton() {
661af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OTA Speaker button Clicked!");
662af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
663af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            boolean isChecked = !PhoneUtils.isSpeakerOn(mContext);
664af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            setSpeaker(isChecked);
665af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
666af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
667af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
668af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void onClickOtaActivateButton() {
669af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("Call Activation Clicked!");
670af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
671af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            Intent newIntent = new Intent(Intent.ACTION_CALL);
672af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            newIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, InCallScreen.OTA_NUMBER);
673af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mInCallScreen.internalResolveIntent(newIntent);
674af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowListeningScreen();
675af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
676af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
677af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
678af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void onClickOtaActivateCancelButton() {
679af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("Activation Cancel Clicked!");
680af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
681af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowHome();
682af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
683af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
684af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
685986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller    private void onClickOtaActivateNextButton() {
686986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        if (DBG) log("Dialog Next Clicked!");
687af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (!mApplication.cdmaOtaProvisionData.inOtaSpcState) {
688af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mApplication.cdmaOtaScreenState.otaScreenState =
689af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                    CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED;
690af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowHome();
691af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mInCallScreen.finish();
692af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
693af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
694af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
695af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public void dismissAllOtaDialogs() {
696af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mOtaWidgetData.spcErrorDialog != null) {
697af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("- DISMISSING mSpcErrorDialog.");
698af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.spcErrorDialog.dismiss();
699af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.spcErrorDialog = null;
700af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
701af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mOtaWidgetData.otaFailureDialog != null) {
702af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("- DISMISSING mOtaFailureDialog.");
703af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.otaFailureDialog.dismiss();
704af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            mOtaWidgetData.otaFailureDialog = null;
705af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
706af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
707af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
708af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private int getOtaSpcDisplayTime() {
709af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("getOtaSpcDisplayTime()...");
710af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        int tmpSpcTime = 1;
711af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (mApplication.cdmaOtaProvisionData.inOtaSpcState) {
712af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            long tmpOtaSpcRunningTime = 0;
713af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            long tmpOtaSpcLeftTime = 0;
714af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            tmpOtaSpcRunningTime = SystemClock.elapsedRealtime();
715af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            tmpOtaSpcLeftTime =
716af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                tmpOtaSpcRunningTime - mApplication.cdmaOtaProvisionData.otaSpcUptime;
71717c36a10d09fac3e2312c0bcb839e0a704f42105w            if (tmpOtaSpcLeftTime >= OTA_SPC_TIMEOUT*1000) {
718af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                tmpSpcTime = 1;
719af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            } else {
720af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                tmpSpcTime = OTA_SPC_TIMEOUT - (int)tmpOtaSpcLeftTime/1000;
721af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            }
722af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
723af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("getOtaSpcDisplayTime(), time for SPC error notice: " + tmpSpcTime);
724af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        return tmpSpcTime;
725af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
726af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
727af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
728af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Initialize the OTA widgets for all OTA screens.
729af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
730af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private void initOtaInCallScreen() {
731af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("initOtaInCallScreen()...");
732986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTitle = (TextView) mInCallScreen.findViewById(R.id.otaTitle);
733af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextActivate = (TextView) mInCallScreen.findViewById(R.id.otaActivate);
734af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextActivate.setVisibility(View.GONE);
735af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextListenProgress =
736af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                (TextView) mInCallScreen.findViewById(R.id.otaListenProgress);
737af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextProgressBar =
738af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                (ProgressBar) mInCallScreen.findViewById(R.id.progress_large);
739af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextProgressBar.setIndeterminate(true);
740af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaTextSuccessFail =
741af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                (TextView) mInCallScreen.findViewById(R.id.otaSuccessFailStatus);
742af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
743af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaCallCardBase = (View) mInCallScreen.findViewById(R.id.otaBase);
744af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsListenProgress =
745af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                (View) mInCallScreen.findViewById(R.id.callCardOtaListenProgress);
746af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsActivate =
747af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                (View) mInCallScreen.findViewById(R.id.callCardOtaActivate);
748af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.callCardOtaButtonsFailSuccess =
749af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                (View) mInCallScreen.findViewById(R.id.callCardOtaFailOrSuccessful);
750af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
751af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaEndButton = (Button) mInCallScreen.findViewById(R.id.otaEndButton);
752af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaEndButton.setOnClickListener(mInCallScreen);
753af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaSpeakerButton =
754af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                (ToggleButton) mInCallScreen.findViewById(R.id.otaSpeakerButton);
755af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaSpeakerButton.setOnClickListener(mInCallScreen);
756af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaActivateButton =
757af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville                (Button) mInCallScreen.findViewById(R.id.otaActivateButton);
758af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaActivateButton.setOnClickListener(mInCallScreen);
759986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaCancelButton = (Button) mInCallScreen.findViewById(R.id.otaCancelButton);
760af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        mOtaWidgetData.otaCancelButton.setOnClickListener(mInCallScreen);
761986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaNextButton = (Button) mInCallScreen.findViewById(R.id.otaNextButton);
762986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaNextButton.setOnClickListener(mInCallScreen);
763986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTryAgainButton =
764986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller                (Button) mInCallScreen.findViewById(R.id.otaTryAgainButton);
765986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTryAgainButton.setOnClickListener(mInCallScreen);
766a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent
767dfa83d531cdb88513f09e913424b7a16628b37d3David Brown        mOtaWidgetData.otaDtmfDialerView =
768dfa83d531cdb88513f09e913424b7a16628b37d3David Brown                (DTMFTwelveKeyDialerView) mInCallScreen.findViewById(R.id.otaDtmfDialer);
769dfa83d531cdb88513f09e913424b7a16628b37d3David Brown        // Sanity-check: the otaDtmfDialer widget should *always* be present.
770dfa83d531cdb88513f09e913424b7a16628b37d3David Brown        if (mOtaWidgetData.otaDtmfDialerView == null) {
771dfa83d531cdb88513f09e913424b7a16628b37d3David Brown            Log.e(LOG_TAG, "onCreate: couldn't find otaDtmfDialer", new IllegalStateException());
772af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
773dfa83d531cdb88513f09e913424b7a16628b37d3David Brown        DTMFTwelveKeyDialer dialer = new DTMFTwelveKeyDialer(mInCallScreen,
7745aadc2633b13d6676598dc0954be25c108d05fcdDavid Brown                                                             mOtaWidgetData.otaDtmfDialerView,
7755aadc2633b13d6676598dc0954be25c108d05fcdDavid Brown                                                             null /* no SlidingDrawer used here */);
776dfa83d531cdb88513f09e913424b7a16628b37d3David Brown        mOtaWidgetData.otaDtmfDialerView.setDialer(dialer);
777af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
778af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
779af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
780af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Clear out all OTA UI widget elements. Needs to get called
781af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * when OTA call ends or InCallScreen is destroyed.
782af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
783af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public void cleanOtaScreen() {
784af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        if (DBG) log("OTA ends, cleanOtaScreen!");
785af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
786986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mApplication.cdmaOtaScreenState.otaScreenState =
787986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller                CdmaOtaScreenState.OtaScreenState.OTA_STATUS_UNDEFINED;
788986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mApplication.cdmaOtaProvisionData.isOtaCallCommitted = false;
789986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mApplication.cdmaOtaProvisionData.isOtaCallIntentProcessed = false;
790986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mApplication.cdmaOtaProvisionData.inOtaSpcState = false;
791986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mApplication.cdmaOtaProvisionData.activationCount = 0;
792986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mApplication.cdmaOtaProvisionData.otaSpcUptime = 0;
7935c0517ae3c17505ffd466be79ab0026b7fe6c959Wink Saville        mApplication.cdmaOtaInCallScreenUiState.state = State.UNDEFINED;
794986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller
795986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        if (mInCallPanel != null) mInCallPanel.setVisibility(View.VISIBLE);
796986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        if (mCallCard != null) mCallCard.hideCallCardElements();
7978df5c508da2c836b841ee24120fa7c5cc92df387David Brown        mDialer.setHandleVisible(true);
798986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller
799986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTextActivate.setVisibility(View.GONE);
800986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTextListenProgress.setVisibility(View.GONE);
801986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTextProgressBar.setVisibility(View.GONE);
802986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTextSuccessFail.setVisibility(View.GONE);
803986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.callCardOtaButtonsActivate.setVisibility(View.GONE);
804986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.callCardOtaButtonsListenProgress.setVisibility(View.GONE);
805986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.callCardOtaButtonsFailSuccess.setVisibility(View.GONE);
806986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaCallCardBase.setVisibility(View.GONE);
807986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaDtmfDialerView.setVisibility(View.GONE);
808986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaNextButton.setVisibility(View.GONE);
809986d2f46bd9572b563b89627fa60a9ea0853a91fJim Miller        mOtaWidgetData.otaTryAgainButton.setVisibility(View.GONE);
810a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent
811a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent        // turn off the speaker in case it was turned on
812a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent        // but the OTA call could not be completed
813a44a437fae34920b0ecbf66400ac50e10e5ae49eEric Laurent        setSpeaker(false);
814af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
815af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
816af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
817af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Defines OTA information that needs to be maintained during
818af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * an OTA call when display orientation changes.
819af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
820af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static class CdmaOtaProvisionData {
821af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public boolean isOtaCallCommitted;
822af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public boolean isOtaCallIntentProcessed;
823af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public boolean inOtaSpcState;
824af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public int activationCount;
825af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public long otaSpcUptime;
826af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
827af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
828af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
829af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * Defines OTA screen configuration items read from config.xml
830af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * and used to control OTA display.
831af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
832af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static class CdmaOtaConfigData {
833af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public int otaShowActivationScreen;
834af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public int otaShowListeningScreen;
835af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public int otaShowActivateFailTimes;
836af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public int otaPlaySuccessFailureTone;
837af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public boolean configComplete;
838af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public CdmaOtaConfigData() {
839af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            if (DBG) log("CdmaOtaConfigData constructor!");
840af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowActivationScreen = OTA_SHOW_ACTIVATION_SCREEN_OFF;
841af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowListeningScreen = OTA_SHOW_LISTENING_SCREEN_OFF;
842af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaShowActivateFailTimes = OTA_SHOW_ACTIVATE_FAIL_COUNT_OFF;
843af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaPlaySuccessFailureTone = OTA_PLAY_SUCCESS_FAILURE_TONE_OFF;
844af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
845af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
846af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
847af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    /**
848f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville     * The state of the OTA InCallScreen UI.
849f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville     */
850f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville    public static class CdmaOtaInCallScreenUiState {
851f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville        public enum State {
852f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville            UNDEFINED,
853f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville            NORMAL,
854f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville            ENDED
855f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville        }
856f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville
857f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville        public State state;
858f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville
859f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville        public CdmaOtaInCallScreenUiState() {
860f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville            if (DBG) log("CdmaOtaInCallScreenState: constructor init to UNDEFINED");
861f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville            state = CdmaOtaInCallScreenUiState.State.UNDEFINED;
862f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville        }
863f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville    }
864f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville
865f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville    /**
866f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville     * Save the Ota InCallScreen UI state
867f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville     */
868f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville    public void setCdmaOtaInCallScreenUiState(CdmaOtaInCallScreenUiState.State state) {
869f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville        if (DBG) log("setCdmaOtaInCallScreenState: " + state);
870f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville        mApplication.cdmaOtaInCallScreenUiState.state = state;
871f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville    }
872f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville
873f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville    /**
874f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville     * Get the Ota InCallScreen UI state
875f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville     */
876f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville    public CdmaOtaInCallScreenUiState.State getCdmaOtaInCallScreenUiState() {
877f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville        if (DBG) log("getCdmaOtaInCallScreenState: " + mApplication.cdmaOtaInCallScreenUiState.state);
878f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville        return mApplication.cdmaOtaInCallScreenUiState.state;
879f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville    }
880f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville
881f6eb7893215a875863e1e0200e4aa3174137f76cWink Saville    /**
882af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     * The OTA screen state machine.
883af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville     */
884af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    public static class CdmaOtaScreenState {
885af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public enum OtaScreenState {
886af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            OTA_STATUS_UNDEFINED,
887af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            OTA_STATUS_ACTIVATION,
888af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            OTA_STATUS_LISTENING,
889af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            OTA_STATUS_PROGRESS,
890af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            OTA_STATUS_SUCCESS_FAILURE_DLG
891af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
892af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
893af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public OtaScreenState otaScreenState;
894af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
895af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        public CdmaOtaScreenState() {
896af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville            otaScreenState = OtaScreenState.OTA_STATUS_UNDEFINED;
897af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        }
898af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
899af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville
900af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    private static void log(String msg) {
901af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville        Log.d(LOG_TAG, msg);
902af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville    }
903839b14d460986608fe577f89f789de854dc85b58Jim Miller
904839b14d460986608fe577f89f789de854dc85b58Jim Miller    public static boolean isCdmaPhone() {
90579b9f6e30e8402b103f1ec3ed9dda1fcad2b1cd5Tammo Spalink        return (PhoneApp.getInstance().phone.getPhoneType() == Phone.PHONE_TYPE_CDMA);
906839b14d460986608fe577f89f789de854dc85b58Jim Miller    }
907af684393e2c6d0c051b9d5a189c2cd1de2506831Wink Saville}
908