blob: 3b5fe1608d2a1980d7c1039d930fb24b9ea282f0 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
19import android.app.Activity;
20import android.app.PendingIntent;
Santos Cordon00d7a432013-09-17 14:07:14 -070021import android.content.Context;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.content.Intent;
Santos Cordon00d7a432013-09-17 14:07:14 -070023import android.content.pm.PackageManager;
24import android.content.pm.ResolveInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.os.Bundle;
26import android.os.SystemProperties;
Santos Cordon00d7a432013-09-17 14:07:14 -070027import android.provider.Settings;
Junda Liu605148f2015-04-28 15:23:40 -070028import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.util.Log;
30
31import com.android.internal.telephony.Phone;
32import com.android.internal.telephony.TelephonyCapabilities;
33
34/**
35 * Invisible activity that handles the com.android.phone.PERFORM_CDMA_PROVISIONING intent.
36 * This activity is protected by the android.permission.PERFORM_CDMA_PROVISIONING permission.
37 *
38 * We handle the PERFORM_CDMA_PROVISIONING action by launching an OTASP
39 * call via one of the OtaUtils helper methods: startInteractiveOtasp() on
40 * regular phones, or startNonInteractiveOtasp() on data-only devices.
41 *
42 * TODO: The class name InCallScreenShowActivation is misleading, since
43 * this activity is totally unrelated to the InCallScreen (which
44 * implements the in-call UI.) Let's eventually rename this to something
45 * like CdmaProvisioningLauncher or CdmaProvisioningHandler...
46 */
47public class InCallScreenShowActivation extends Activity {
48 private static final String LOG_TAG = "InCallScreenShowActivation";
49 private static final boolean DBG =
50 (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
51
52 @Override
53 protected void onCreate(Bundle icicle) {
54 super.onCreate(icicle);
55
56 Intent intent = getIntent();
57 if (DBG) Log.d(LOG_TAG, "onCreate: intent = " + intent);
58 Bundle extras = intent.getExtras();
59 if (DBG && (extras != null)) {
60 Log.d(LOG_TAG, " - has extras: size = " + extras.size()); // forces an unparcel()
61 Log.d(LOG_TAG, " - extras = " + extras);
62 }
63
64 PhoneGlobals app = PhoneGlobals.getInstance();
65 Phone phone = app.getPhone();
66 if (!TelephonyCapabilities.supportsOtasp(phone)) {
67 Log.w(LOG_TAG, "CDMA Provisioning not supported on this device");
68 setResult(RESULT_CANCELED);
69 finish();
70 return;
71 }
72
73 if (intent.getAction().equals(OtaUtils.ACTION_PERFORM_CDMA_PROVISIONING)) {
74
Junda Liu605148f2015-04-28 15:23:40 -070075 Bundle carrierConfig = app.getCarrierConfig();
76 boolean usesHfa = carrierConfig.getBoolean(CarrierConfigManager.BOOL_USE_HFA_FOR_PROVISIONING);
Santos Cordon83570472013-09-06 15:45:10 -070077 if (usesHfa) {
Santos Cordonb2bfd3c2014-10-08 15:12:41 -070078 Log.i(LOG_TAG, "Starting Hfa from ACTION_PERFORM_CDMA_PROVISIONING");
Santos Cordon83570472013-09-06 15:45:10 -070079 startHfa();
80 finish();
81 return;
82 }
83
Junda Liu605148f2015-04-28 15:23:40 -070084 boolean usesOtasp = carrierConfig.getBoolean(CarrierConfigManager.BOOL_USE_OTASP_FOR_PROVISIONING);
Santos Cordonb2bfd3c2014-10-08 15:12:41 -070085 if (usesOtasp) {
86 // On voice-capable devices, we perform CDMA provisioning in
87 // "interactive" mode by directly launching the InCallScreen.
88 // boolean interactiveMode = PhoneGlobals.sVoiceCapable;
89 // TODO: Renable interactive mode for device provisioning.
90 boolean interactiveMode = false;
91 Log.i(LOG_TAG, "ACTION_PERFORM_CDMA_PROVISIONING (interactiveMode = "
92 + interactiveMode + ")...");
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093
Santos Cordonb2bfd3c2014-10-08 15:12:41 -070094 // Testing: this intent extra allows test apps manually
95 // enable/disable "interactive mode", regardless of whether
96 // the current device is voice-capable. This is allowed only
97 // in userdebug or eng builds.
98 if (intent.hasExtra(OtaUtils.EXTRA_OVERRIDE_INTERACTIVE_MODE)
99 && (SystemProperties.getInt("ro.debuggable", 0) == 1)) {
100 interactiveMode =
101 intent.getBooleanExtra(OtaUtils.EXTRA_OVERRIDE_INTERACTIVE_MODE, false);
102 Log.d(LOG_TAG, "==> MANUALLY OVERRIDING interactiveMode to " + interactiveMode);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103 }
Santos Cordonb2bfd3c2014-10-08 15:12:41 -0700104
105 // We allow the caller to pass a PendingIntent (as the
106 // EXTRA_NONINTERACTIVE_OTASP_RESULT_PENDING_INTENT extra)
107 // which we'll later use to notify them when the OTASP call
108 // fails or succeeds.
109 //
110 // Stash that away here, and we'll fire it off later in
111 // OtaUtils.sendOtaspResult().
112 app.cdmaOtaScreenState.otaspResultCodePendingIntent =
113 (PendingIntent) intent.getParcelableExtra(
114 OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT);
115
116 if (interactiveMode) {
117 // On voice-capable devices, launch an OTASP call and arrange
118 // for the in-call UI to come up. (The InCallScreen will
119 // notice that an OTASP call is active, and display the
120 // special OTASP UI instead of the usual in-call controls.)
121
122 if (DBG) Log.d(LOG_TAG, "==> Starting interactive CDMA provisioning...");
123 OtaUtils.startInteractiveOtasp(this);
124
125 // The result we set here is actually irrelevant, since the
126 // InCallScreen's "interactive" OTASP sequence never actually
127 // finish()es; it ends by directly launching the Home
128 // activity. So our caller won't actually ever get an
129 // onActivityResult() call in this case.
130 setResult(OtaUtils.RESULT_INTERACTIVE_OTASP_STARTED);
131 } else {
132 // On data-only devices, manually launch the OTASP call
133 // *without* displaying any UI. (Our caller, presumably
134 // SetupWizardActivity, is responsible for displaying some
135 // sort of progress UI.)
136
137 if (DBG) Log.d(LOG_TAG, "==> Starting non-interactive CDMA provisioning...");
138 int callStatus = OtaUtils.startNonInteractiveOtasp(this);
139
140 if (callStatus == PhoneUtils.CALL_STATUS_DIALED) {
141 if (DBG) Log.d(LOG_TAG,
142 " ==> successful result from startNonInteractiveOtasp(): " +
143 callStatus);
144 setResult(OtaUtils.RESULT_NONINTERACTIVE_OTASP_STARTED);
145 } else {
146 Log.w(LOG_TAG, "Failure code from startNonInteractiveOtasp(): " +
147 callStatus);
148 setResult(OtaUtils.RESULT_NONINTERACTIVE_OTASP_FAILED);
149 }
150 }
151 } else {
152 Log.i(LOG_TAG, "Skipping activation.");
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153 }
154 } else {
155 Log.e(LOG_TAG, "Unexpected intent action: " + intent);
156 setResult(RESULT_CANCELED);
157 }
158
159 finish();
160 }
Santos Cordon83570472013-09-06 15:45:10 -0700161
Santos Cordon00d7a432013-09-17 14:07:14 -0700162 /**
163 * On devices that provide a phone initialization wizard (such as Google Setup Wizard),
164 * the wizard displays it's own activation UI. The Hfa activation started by this class
165 * will show a UI or not depending on the status of the setup wizard. If the setup wizard
166 * is running, do not show a UI, otherwise show our own UI since setup wizard will not.
167 *
168 * The method checks two properties:
169 * 1. Does the device require a setup wizard (ro.setupwizard.mode == (REQUIRED|OPTIONAL))
170 * 2. Is device_provisioned set to non-zero--a property that setup wizard sets at completion.
171 * @return true if wizard is running, false otherwise.
172 */
173 private boolean isWizardRunning(Context context) {
174 Intent intent = new Intent("android.intent.action.DEVICE_INITIALIZATION_WIZARD");
175 ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent,
176 PackageManager.MATCH_DEFAULT_ONLY);
177 boolean provisioned = Settings.Global.getInt(context.getContentResolver(),
178 Settings.Global.DEVICE_PROVISIONED, 0) != 0;
179 String mode = SystemProperties.get("ro.setupwizard.mode", "REQUIRED");
180 boolean runningSetupWizard = "REQUIRED".equals(mode) || "OPTIONAL".equals(mode);
181 if (DBG) {
182 Log.v(LOG_TAG, "resolvInfo = " + resolveInfo + ", provisioned = " + provisioned
183 + ", runningSetupWizard = " + runningSetupWizard);
184 }
185 return resolveInfo != null && !provisioned && runningSetupWizard;
186 }
Santos Cordon83570472013-09-06 15:45:10 -0700187
188 /**
189 * Starts the HFA provisioning process by bringing up the HFA Activity.
190 */
191 private void startHfa() {
Santos Cordon06cc4482014-10-08 12:12:15 -0700192 boolean isWizardRunning = isWizardRunning(this);
193 // We always run our HFA logic if we're in setup wizard, but if we're outside of setup
194 // wizard then we have to check a config to see if we should still run HFA.
195 if (isWizardRunning ||
196 getResources().getBoolean(R.bool.config_allow_hfa_outside_of_setup_wizard)) {
Santos Cordon83570472013-09-06 15:45:10 -0700197
Santos Cordon06cc4482014-10-08 12:12:15 -0700198 final Intent intent = new Intent();
Santos Cordon83570472013-09-06 15:45:10 -0700199
Santos Cordon06cc4482014-10-08 12:12:15 -0700200 final PendingIntent otaResponseIntent = getIntent().getParcelableExtra(
201 OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT);
Santos Cordon00d7a432013-09-17 14:07:14 -0700202
Santos Cordon06cc4482014-10-08 12:12:15 -0700203 final boolean showUi = !isWizardRunning;
204 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Santos Cordon00d7a432013-09-17 14:07:14 -0700205
Santos Cordon06cc4482014-10-08 12:12:15 -0700206 if (otaResponseIntent != null) {
207 intent.putExtra(OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT, otaResponseIntent);
208 }
209
210 Log.v(LOG_TAG, "Starting hfa activation activity");
211 if (showUi) {
212 intent.setClassName(this, HfaActivity.class.getName());
213 startActivity(intent);
214 } else {
215 intent.setClassName(this, HfaService.class.getName());
216 startService(intent);
217 }
218
Santos Cordon00d7a432013-09-17 14:07:14 -0700219 }
Santos Cordon00d7a432013-09-17 14:07:14 -0700220 setResult(RESULT_OK);
Santos Cordon83570472013-09-06 15:45:10 -0700221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222}