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 17package com.android.phone; 18 19import android.app.Activity; 20import android.app.AlertDialog; 21import android.app.PendingIntent; 22import android.content.DialogInterface; 23import android.os.Bundle; 24import android.util.Log; 25 26/** 27 * Starts and displays status for Hands Free Activation (HFA). 28 * 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. 36 */ 37public class HfaActivity extends Activity { 38 private static final String TAG = HfaActivity.class.getSimpleName(); 39 40 private AlertDialog mDialog; 41 private HfaLogic mHfaLogic; 42 43 @Override 44 protected void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 Log.i(TAG, "onCreate"); 47 48 final PendingIntent otaResponseIntent = getIntent().getParcelableExtra( 49 OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT); 50 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 } 61 }, otaResponseIntent); 62 63 startProvisioning(); 64 } 65 66 @Override 67 protected void onDestroy() { 68 super.onDestroy(); 69 70 Log.i(TAG, "onDestroy"); 71 72 if (mDialog != null && mDialog.isShowing()) { 73 mDialog.dismiss(); 74 mDialog = null; 75 } 76 } 77 78 private void startProvisioning() { 79 buildAndShowDialog(); 80 mHfaLogic.start(); 81 } 82 83 private void buildAndShowDialog() { 84 mDialog = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT) 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) { 91 onUserSkip(); 92 }}) 93 /*.setOnCancelListener(new DialogInterface.OnCancelListener() { 94 @Override 95 public void onCancel(DialogInterface di) { 96 sendFinalResponse(OTASP_USER_SKIPPED); 97 }})*/ 98 .create(); 99 100 // Do not allow user to dismiss dialog unless they are clicking "skip" 101 mDialog.setCanceledOnTouchOutside(false); 102 mDialog.setCancelable(false); 103 104 Log.i(TAG, "showing dialog"); 105 mDialog.show(); 106 } 107 108 private void onHfaError(String errorMsg) { 109 mDialog.dismiss(); 110 111 AlertDialog errorDialog = new AlertDialog.Builder(this, 112 AlertDialog.THEME_DEVICE_DEFAULT_LIGHT) 113 .setMessage(errorMsg) 114 .setPositiveButton(R.string.ota_skip_activation_dialog_skip_label, 115 new DialogInterface.OnClickListener() { 116 @Override 117 public void onClick(DialogInterface di, int which) { 118 di.dismiss(); 119 onUserSkip(); 120 } 121 }) 122 .setNegativeButton(R.string.ota_try_again, 123 new DialogInterface.OnClickListener() { 124 @Override 125 public void onClick(DialogInterface di, int which) { 126 di.dismiss(); 127 startProvisioning(); 128 } 129 }) 130 .create(); 131 132 errorDialog.show(); 133 } 134 135 private void onHfaSuccess() { 136 finish(); 137 } 138 139 private void onUserSkip() { 140 finish(); 141 } 142 143} 144