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; |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 22 | import android.content.DialogInterface; |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 23 | import android.os.Bundle; |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 24 | import android.util.Log; |
| 25 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Starts and displays status for Hands Free Activation (HFA). |
| 28 | * |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 29 | * This class operates with Hands Free Activation apps. It comes up during activation |
| 30 | * requests that occur outside of setup wizard and so provides its own UI. |
| 31 | * It uses {@link HfaLogic} to perform the actual activation and during the process |
| 32 | * displays a "performing activation..." dialog. This will remain up until the user |
| 33 | * chooses to skip the activation (still happens in the background) or the activation |
| 34 | * is successful. Upon failure, the dialog also goes away but a subsequent dialog will |
| 35 | * ask the user if they would like to try again or cancel. |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 36 | */ |
| 37 | public class HfaActivity extends Activity { |
| 38 | private static final String TAG = HfaActivity.class.getSimpleName(); |
| 39 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 40 | private AlertDialog mDialog; |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 41 | private HfaLogic mHfaLogic; |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 42 | |
| 43 | @Override |
| 44 | protected void onCreate(Bundle savedInstanceState) { |
| 45 | super.onCreate(savedInstanceState); |
Santos Cordon | cd76f8b | 2013-09-23 17:59:50 -0700 | [diff] [blame^] | 46 | Log.i(TAG, "onCreate"); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 47 | |
Santos Cordon | cd76f8b | 2013-09-23 17:59:50 -0700 | [diff] [blame^] | 48 | final PendingIntent otaResponseIntent = getIntent().getParcelableExtra( |
| 49 | OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 50 | |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 51 | mHfaLogic = new HfaLogic(this.getApplicationContext(), new HfaLogic.HfaLogicCallback() { |
| 52 | @Override |
| 53 | public void onSuccess() { |
| 54 | onHfaSuccess(); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public void onError(String error) { |
| 59 | onHfaError(error); |
| 60 | } |
Santos Cordon | cd76f8b | 2013-09-23 17:59:50 -0700 | [diff] [blame^] | 61 | }, otaResponseIntent); |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 62 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 63 | startProvisioning(); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | protected void onDestroy() { |
| 68 | super.onDestroy(); |
| 69 | |
Santos Cordon | cd76f8b | 2013-09-23 17:59:50 -0700 | [diff] [blame^] | 70 | Log.i(TAG, "onDestroy"); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 71 | |
| 72 | if (mDialog != null && mDialog.isShowing()) { |
| 73 | mDialog.dismiss(); |
| 74 | mDialog = null; |
| 75 | } |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | private void startProvisioning() { |
| 79 | buildAndShowDialog(); |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 80 | mHfaLogic.start(); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | private void buildAndShowDialog() { |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 84 | mDialog = new AlertDialog.Builder(this) |
| 85 | .setTitle(R.string.ota_hfa_activation_title) |
| 86 | .setMessage(R.string.ota_hfa_activation_dialog_message) |
| 87 | .setPositiveButton(R.string.ota_skip_activation_dialog_skip_label, |
| 88 | new DialogInterface.OnClickListener() { |
| 89 | @Override |
| 90 | public void onClick(DialogInterface di, int which) { |
Santos Cordon | cd76f8b | 2013-09-23 17:59:50 -0700 | [diff] [blame^] | 91 | onUserSkip(); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 92 | }}) |
| 93 | /*.setOnCancelListener(new DialogInterface.OnCancelListener() { |
| 94 | @Override |
| 95 | public void onCancel(DialogInterface di) { |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 96 | sendFinalResponse(OTASP_USER_SKIPPED); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 97 | }})*/ |
| 98 | .create(); |
| 99 | |
Santos Cordon | 00d7a43 | 2013-09-17 14:07:14 -0700 | [diff] [blame] | 100 | // Do not allow user to dismiss dialog unless they are clicking "skip" |
| 101 | mDialog.setCanceledOnTouchOutside(false); |
| 102 | mDialog.setCancelable(false); |
| 103 | |
Santos Cordon | cd76f8b | 2013-09-23 17:59:50 -0700 | [diff] [blame^] | 104 | Log.i(TAG, "showing dialog"); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 105 | mDialog.show(); |
| 106 | } |
| 107 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 108 | private void onHfaError(String errorMsg) { |
| 109 | mDialog.dismiss(); |
| 110 | |
| 111 | AlertDialog errorDialog = new AlertDialog.Builder(this) |
| 112 | .setMessage(errorMsg) |
| 113 | .setPositiveButton(R.string.ota_skip_activation_dialog_skip_label, |
| 114 | new DialogInterface.OnClickListener() { |
| 115 | @Override |
| 116 | public void onClick(DialogInterface di, int which) { |
| 117 | di.dismiss(); |
Santos Cordon | cd76f8b | 2013-09-23 17:59:50 -0700 | [diff] [blame^] | 118 | onUserSkip(); |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 119 | } |
| 120 | }) |
| 121 | .setNegativeButton(R.string.ota_try_again, |
| 122 | new DialogInterface.OnClickListener() { |
| 123 | @Override |
| 124 | public void onClick(DialogInterface di, int which) { |
| 125 | di.dismiss(); |
| 126 | startProvisioning(); |
| 127 | } |
| 128 | }) |
| 129 | .create(); |
| 130 | |
| 131 | errorDialog.show(); |
| 132 | } |
| 133 | |
| 134 | private void onHfaSuccess() { |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 135 | finish(); |
| 136 | } |
Santos Cordon | cd76f8b | 2013-09-23 17:59:50 -0700 | [diff] [blame^] | 137 | |
| 138 | private void onUserSkip() { |
| 139 | finish(); |
| 140 | } |
| 141 | |
Santos Cordon | 8357047 | 2013-09-06 15:45:10 -0700 | [diff] [blame] | 142 | } |