Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.phone; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.PendingIntent; |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 21 | import android.content.Context; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 22 | import android.content.Intent; |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageManager; |
| 24 | import android.content.pm.ResolveInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.os.Bundle; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame^] | 26 | import android.os.PersistableBundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.os.SystemProperties; |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 28 | import android.provider.Settings; |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 29 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.util.Log; |
| 31 | |
| 32 | import com.android.internal.telephony.Phone; |
| 33 | import com.android.internal.telephony.TelephonyCapabilities; |
| 34 | |
| 35 | /** |
| 36 | * Invisible activity that handles the com.android.phone.PERFORM_CDMA_PROVISIONING intent. |
| 37 | * This activity is protected by the android.permission.PERFORM_CDMA_PROVISIONING permission. |
| 38 | * |
| 39 | * We handle the PERFORM_CDMA_PROVISIONING action by launching an OTASP |
| 40 | * call via one of the OtaUtils helper methods: startInteractiveOtasp() on |
| 41 | * regular phones, or startNonInteractiveOtasp() on data-only devices. |
| 42 | * |
| 43 | * TODO: The class name InCallScreenShowActivation is misleading, since |
| 44 | * this activity is totally unrelated to the InCallScreen (which |
| 45 | * implements the in-call UI.) Let's eventually rename this to something |
| 46 | * like CdmaProvisioningLauncher or CdmaProvisioningHandler... |
| 47 | */ |
| 48 | public class InCallScreenShowActivation extends Activity { |
| 49 | private static final String LOG_TAG = "InCallScreenShowActivation"; |
| 50 | private static final boolean DBG = |
| 51 | (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1); |
| 52 | |
| 53 | @Override |
| 54 | protected void onCreate(Bundle icicle) { |
| 55 | super.onCreate(icicle); |
| 56 | |
| 57 | Intent intent = getIntent(); |
| 58 | if (DBG) Log.d(LOG_TAG, "onCreate: intent = " + intent); |
| 59 | Bundle extras = intent.getExtras(); |
| 60 | if (DBG && (extras != null)) { |
| 61 | Log.d(LOG_TAG, " - has extras: size = " + extras.size()); // forces an unparcel() |
| 62 | Log.d(LOG_TAG, " - extras = " + extras); |
| 63 | } |
| 64 | |
| 65 | PhoneGlobals app = PhoneGlobals.getInstance(); |
| 66 | Phone phone = app.getPhone(); |
| 67 | if (!TelephonyCapabilities.supportsOtasp(phone)) { |
| 68 | Log.w(LOG_TAG, "CDMA Provisioning not supported on this device"); |
| 69 | setResult(RESULT_CANCELED); |
| 70 | finish(); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | if (intent.getAction().equals(OtaUtils.ACTION_PERFORM_CDMA_PROVISIONING)) { |
| 75 | |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame^] | 76 | PersistableBundle carrierConfig = app.getCarrierConfig(); |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 77 | boolean usesHfa = carrierConfig.getBoolean(CarrierConfigManager.BOOL_USE_HFA_FOR_PROVISIONING); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 78 | if (usesHfa) { |
Santos Cordon | b2bfd3c | 2014-10-08 15:12:41 -0700 | [diff] [blame] | 79 | Log.i(LOG_TAG, "Starting Hfa from ACTION_PERFORM_CDMA_PROVISIONING"); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 80 | startHfa(); |
| 81 | finish(); |
| 82 | return; |
| 83 | } |
| 84 | |
Junda Liu | 605148f | 2015-04-28 15:23:40 -0700 | [diff] [blame] | 85 | boolean usesOtasp = carrierConfig.getBoolean(CarrierConfigManager.BOOL_USE_OTASP_FOR_PROVISIONING); |
Santos Cordon | b2bfd3c | 2014-10-08 15:12:41 -0700 | [diff] [blame] | 86 | if (usesOtasp) { |
| 87 | // On voice-capable devices, we perform CDMA provisioning in |
| 88 | // "interactive" mode by directly launching the InCallScreen. |
| 89 | // boolean interactiveMode = PhoneGlobals.sVoiceCapable; |
| 90 | // TODO: Renable interactive mode for device provisioning. |
| 91 | boolean interactiveMode = false; |
| 92 | Log.i(LOG_TAG, "ACTION_PERFORM_CDMA_PROVISIONING (interactiveMode = " |
| 93 | + interactiveMode + ")..."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 94 | |
Santos Cordon | b2bfd3c | 2014-10-08 15:12:41 -0700 | [diff] [blame] | 95 | // Testing: this intent extra allows test apps manually |
| 96 | // enable/disable "interactive mode", regardless of whether |
| 97 | // the current device is voice-capable. This is allowed only |
| 98 | // in userdebug or eng builds. |
| 99 | if (intent.hasExtra(OtaUtils.EXTRA_OVERRIDE_INTERACTIVE_MODE) |
| 100 | && (SystemProperties.getInt("ro.debuggable", 0) == 1)) { |
| 101 | interactiveMode = |
| 102 | intent.getBooleanExtra(OtaUtils.EXTRA_OVERRIDE_INTERACTIVE_MODE, false); |
| 103 | Log.d(LOG_TAG, "==> MANUALLY OVERRIDING interactiveMode to " + interactiveMode); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | } |
Santos Cordon | b2bfd3c | 2014-10-08 15:12:41 -0700 | [diff] [blame] | 105 | |
| 106 | // We allow the caller to pass a PendingIntent (as the |
| 107 | // EXTRA_NONINTERACTIVE_OTASP_RESULT_PENDING_INTENT extra) |
| 108 | // which we'll later use to notify them when the OTASP call |
| 109 | // fails or succeeds. |
| 110 | // |
| 111 | // Stash that away here, and we'll fire it off later in |
| 112 | // OtaUtils.sendOtaspResult(). |
| 113 | app.cdmaOtaScreenState.otaspResultCodePendingIntent = |
| 114 | (PendingIntent) intent.getParcelableExtra( |
| 115 | OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT); |
| 116 | |
| 117 | if (interactiveMode) { |
| 118 | // On voice-capable devices, launch an OTASP call and arrange |
| 119 | // for the in-call UI to come up. (The InCallScreen will |
| 120 | // notice that an OTASP call is active, and display the |
| 121 | // special OTASP UI instead of the usual in-call controls.) |
| 122 | |
| 123 | if (DBG) Log.d(LOG_TAG, "==> Starting interactive CDMA provisioning..."); |
| 124 | OtaUtils.startInteractiveOtasp(this); |
| 125 | |
| 126 | // The result we set here is actually irrelevant, since the |
| 127 | // InCallScreen's "interactive" OTASP sequence never actually |
| 128 | // finish()es; it ends by directly launching the Home |
| 129 | // activity. So our caller won't actually ever get an |
| 130 | // onActivityResult() call in this case. |
| 131 | setResult(OtaUtils.RESULT_INTERACTIVE_OTASP_STARTED); |
| 132 | } else { |
| 133 | // On data-only devices, manually launch the OTASP call |
| 134 | // *without* displaying any UI. (Our caller, presumably |
| 135 | // SetupWizardActivity, is responsible for displaying some |
| 136 | // sort of progress UI.) |
| 137 | |
| 138 | if (DBG) Log.d(LOG_TAG, "==> Starting non-interactive CDMA provisioning..."); |
| 139 | int callStatus = OtaUtils.startNonInteractiveOtasp(this); |
| 140 | |
| 141 | if (callStatus == PhoneUtils.CALL_STATUS_DIALED) { |
| 142 | if (DBG) Log.d(LOG_TAG, |
| 143 | " ==> successful result from startNonInteractiveOtasp(): " + |
| 144 | callStatus); |
| 145 | setResult(OtaUtils.RESULT_NONINTERACTIVE_OTASP_STARTED); |
| 146 | } else { |
| 147 | Log.w(LOG_TAG, "Failure code from startNonInteractiveOtasp(): " + |
| 148 | callStatus); |
| 149 | setResult(OtaUtils.RESULT_NONINTERACTIVE_OTASP_FAILED); |
| 150 | } |
| 151 | } |
| 152 | } else { |
| 153 | Log.i(LOG_TAG, "Skipping activation."); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | } |
| 155 | } else { |
| 156 | Log.e(LOG_TAG, "Unexpected intent action: " + intent); |
| 157 | setResult(RESULT_CANCELED); |
| 158 | } |
| 159 | |
| 160 | finish(); |
| 161 | } |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 162 | |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 163 | /** |
| 164 | * On devices that provide a phone initialization wizard (such as Google Setup Wizard), |
| 165 | * the wizard displays it's own activation UI. The Hfa activation started by this class |
| 166 | * will show a UI or not depending on the status of the setup wizard. If the setup wizard |
| 167 | * is running, do not show a UI, otherwise show our own UI since setup wizard will not. |
| 168 | * |
| 169 | * The method checks two properties: |
| 170 | * 1. Does the device require a setup wizard (ro.setupwizard.mode == (REQUIRED|OPTIONAL)) |
| 171 | * 2. Is device_provisioned set to non-zero--a property that setup wizard sets at completion. |
| 172 | * @return true if wizard is running, false otherwise. |
| 173 | */ |
| 174 | private boolean isWizardRunning(Context context) { |
| 175 | Intent intent = new Intent("android.intent.action.DEVICE_INITIALIZATION_WIZARD"); |
| 176 | ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, |
| 177 | PackageManager.MATCH_DEFAULT_ONLY); |
| 178 | boolean provisioned = Settings.Global.getInt(context.getContentResolver(), |
| 179 | Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
| 180 | String mode = SystemProperties.get("ro.setupwizard.mode", "REQUIRED"); |
| 181 | boolean runningSetupWizard = "REQUIRED".equals(mode) || "OPTIONAL".equals(mode); |
| 182 | if (DBG) { |
| 183 | Log.v(LOG_TAG, "resolvInfo = " + resolveInfo + ", provisioned = " + provisioned |
| 184 | + ", runningSetupWizard = " + runningSetupWizard); |
| 185 | } |
| 186 | return resolveInfo != null && !provisioned && runningSetupWizard; |
| 187 | } |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * Starts the HFA provisioning process by bringing up the HFA Activity. |
| 191 | */ |
| 192 | private void startHfa() { |
Santos Cordon | 06cc448 | 2014-10-08 12:12:15 -0700 | [diff] [blame] | 193 | boolean isWizardRunning = isWizardRunning(this); |
| 194 | // We always run our HFA logic if we're in setup wizard, but if we're outside of setup |
| 195 | // wizard then we have to check a config to see if we should still run HFA. |
| 196 | if (isWizardRunning || |
| 197 | getResources().getBoolean(R.bool.config_allow_hfa_outside_of_setup_wizard)) { |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 198 | |
Santos Cordon | 06cc448 | 2014-10-08 12:12:15 -0700 | [diff] [blame] | 199 | final Intent intent = new Intent(); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 200 | |
Santos Cordon | 06cc448 | 2014-10-08 12:12:15 -0700 | [diff] [blame] | 201 | final PendingIntent otaResponseIntent = getIntent().getParcelableExtra( |
| 202 | OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT); |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 203 | |
Santos Cordon | 06cc448 | 2014-10-08 12:12:15 -0700 | [diff] [blame] | 204 | final boolean showUi = !isWizardRunning; |
| 205 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 206 | |
Santos Cordon | 06cc448 | 2014-10-08 12:12:15 -0700 | [diff] [blame] | 207 | if (otaResponseIntent != null) { |
| 208 | intent.putExtra(OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT, otaResponseIntent); |
| 209 | } |
| 210 | |
| 211 | Log.v(LOG_TAG, "Starting hfa activation activity"); |
| 212 | if (showUi) { |
| 213 | intent.setClassName(this, HfaActivity.class.getName()); |
| 214 | startActivity(intent); |
| 215 | } else { |
| 216 | intent.setClassName(this, HfaService.class.getName()); |
| 217 | startService(intent); |
| 218 | } |
| 219 | |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 220 | } |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 221 | setResult(RESULT_OK); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 222 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 223 | } |