Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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.AlertDialog; |
| 21 | import android.app.PendingIntent; |
| 22 | import android.app.PendingIntent.CanceledException; |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 23 | import android.content.DialogInterface; |
| 24 | import android.content.Intent; |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 25 | import android.os.Bundle; |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 26 | import android.util.Log; |
| 27 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Starts and displays status for Hands Free Activation (HFA). |
| 30 | * |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 31 | * This class operates with Hands Free Activation apps. It comes up during activation |
| 32 | * requests that occur outside of setup wizard and so provides its own UI. |
| 33 | * It uses {@link HfaLogic} to perform the actual activation and during the process |
| 34 | * displays a "performing activation..." dialog. This will remain up until the user |
| 35 | * chooses to skip the activation (still happens in the background) or the activation |
| 36 | * is successful. Upon failure, the dialog also goes away but a subsequent dialog will |
| 37 | * ask the user if they would like to try again or cancel. |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 38 | */ |
| 39 | public class HfaActivity extends Activity { |
| 40 | private static final String TAG = HfaActivity.class.getSimpleName(); |
| 41 | |
| 42 | private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE); |
| 43 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 44 | public static final int OTASP_UNKNOWN = 0; |
| 45 | public static final int OTASP_USER_SKIPPED = 1; |
| 46 | public static final int OTASP_SUCCESS = 2; |
| 47 | public static final int OTASP_FAILURE = 3; |
| 48 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 49 | private boolean mCanSkip; |
| 50 | private AlertDialog mDialog; |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 51 | private HfaLogic mHfaLogic; |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 52 | |
| 53 | @Override |
| 54 | protected void onCreate(Bundle savedInstanceState) { |
| 55 | super.onCreate(savedInstanceState); |
| 56 | |
| 57 | if (VERBOSE) Log.v(TAG, "onCreate"); |
| 58 | |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 59 | mHfaLogic = new HfaLogic(this.getApplicationContext(), new HfaLogic.HfaLogicCallback() { |
| 60 | @Override |
| 61 | public void onSuccess() { |
| 62 | onHfaSuccess(); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void onError(String error) { |
| 67 | onHfaError(error); |
| 68 | } |
| 69 | }); |
| 70 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 71 | startProvisioning(); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | protected void onDestroy() { |
| 76 | super.onDestroy(); |
| 77 | |
| 78 | if (VERBOSE) Log.v(TAG, "onDestroy"); |
| 79 | |
| 80 | if (mDialog != null && mDialog.isShowing()) { |
| 81 | mDialog.dismiss(); |
| 82 | mDialog = null; |
| 83 | } |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | private void startProvisioning() { |
| 87 | buildAndShowDialog(); |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 88 | mHfaLogic.start(); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | private void buildAndShowDialog() { |
| 92 | mCanSkip = true; |
| 93 | |
| 94 | mDialog = new AlertDialog.Builder(this) |
| 95 | .setTitle(R.string.ota_hfa_activation_title) |
| 96 | .setMessage(R.string.ota_hfa_activation_dialog_message) |
| 97 | .setPositiveButton(R.string.ota_skip_activation_dialog_skip_label, |
| 98 | new DialogInterface.OnClickListener() { |
| 99 | @Override |
| 100 | public void onClick(DialogInterface di, int which) { |
| 101 | if (mCanSkip) { |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 102 | sendFinalResponse(OTASP_USER_SKIPPED); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 103 | } |
| 104 | }}) |
| 105 | /*.setOnCancelListener(new DialogInterface.OnCancelListener() { |
| 106 | @Override |
| 107 | public void onCancel(DialogInterface di) { |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 108 | sendFinalResponse(OTASP_USER_SKIPPED); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 109 | }})*/ |
| 110 | .create(); |
| 111 | |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 112 | // Do not allow user to dismiss dialog unless they are clicking "skip" |
| 113 | mDialog.setCanceledOnTouchOutside(false); |
| 114 | mDialog.setCancelable(false); |
| 115 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 116 | if (VERBOSE) Log.v(TAG, "showing dialog"); |
| 117 | mDialog.show(); |
| 118 | } |
| 119 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 120 | private void onHfaError(String errorMsg) { |
| 121 | mDialog.dismiss(); |
| 122 | |
| 123 | AlertDialog errorDialog = new AlertDialog.Builder(this) |
| 124 | .setMessage(errorMsg) |
| 125 | .setPositiveButton(R.string.ota_skip_activation_dialog_skip_label, |
| 126 | new DialogInterface.OnClickListener() { |
| 127 | @Override |
| 128 | public void onClick(DialogInterface di, int which) { |
| 129 | di.dismiss(); |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 130 | sendFinalResponse(OTASP_USER_SKIPPED); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 131 | } |
| 132 | }) |
| 133 | .setNegativeButton(R.string.ota_try_again, |
| 134 | new DialogInterface.OnClickListener() { |
| 135 | @Override |
| 136 | public void onClick(DialogInterface di, int which) { |
| 137 | di.dismiss(); |
| 138 | startProvisioning(); |
| 139 | } |
| 140 | }) |
| 141 | .create(); |
| 142 | |
| 143 | errorDialog.show(); |
| 144 | } |
| 145 | |
| 146 | private void onHfaSuccess() { |
| 147 | // User can no longer skip after success. |
| 148 | mCanSkip = false; |
| 149 | |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 150 | sendFinalResponse(OTASP_SUCCESS); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 153 | private void sendFinalResponse(int responseCode) { |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 154 | final PendingIntent otaResponseIntent = getIntent().getParcelableExtra( |
| 155 | OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT); |
| 156 | |
Russell Brenner | afce7ad | 2013-09-13 15:29:21 -0700 | [diff] [blame] | 157 | if (otaResponseIntent != null) { |
| 158 | final Intent extraStuff = new Intent(); |
| 159 | extraStuff.putExtra(OtaUtils.EXTRA_OTASP_RESULT_CODE, responseCode); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 160 | |
Russell Brenner | afce7ad | 2013-09-13 15:29:21 -0700 | [diff] [blame] | 161 | try { |
| 162 | if (VERBOSE) Log.v(TAG, "Sending OTASP confirmation with result code: " |
| 163 | + responseCode); |
| 164 | otaResponseIntent.send(this, 0 /* resultCode (not used) */, extraStuff); |
| 165 | } catch (CanceledException e) { |
| 166 | Log.e(TAG, "Pending Intent canceled"); |
| 167 | } |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | finish(); |
| 171 | } |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 172 | } |