blob: b526d4654771325e8d9ce80c50a89f14f88d33d8 [file] [log] [blame]
Santos Cordon83570472013-09-06 15:45:10 -07001/*
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;
Santos Cordon83570472013-09-06 15:45:10 -070022import android.content.DialogInterface;
Santos Cordon83570472013-09-06 15:45:10 -070023import android.os.Bundle;
Santos Cordon83570472013-09-06 15:45:10 -070024import android.util.Log;
25
Santos Cordon83570472013-09-06 15:45:10 -070026/**
27 * Starts and displays status for Hands Free Activation (HFA).
28 *
Santos Cordon00d7a432013-09-17 14:07:14 -070029 * 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 Cordon83570472013-09-06 15:45:10 -070036 */
37public class HfaActivity extends Activity {
38 private static final String TAG = HfaActivity.class.getSimpleName();
39
Santos Cordon83570472013-09-06 15:45:10 -070040 private AlertDialog mDialog;
Santos Cordon00d7a432013-09-17 14:07:14 -070041 private HfaLogic mHfaLogic;
Santos Cordon83570472013-09-06 15:45:10 -070042
43 @Override
44 protected void onCreate(Bundle savedInstanceState) {
45 super.onCreate(savedInstanceState);
Santos Cordoncd76f8b2013-09-23 17:59:50 -070046 Log.i(TAG, "onCreate");
Santos Cordon83570472013-09-06 15:45:10 -070047
Santos Cordoncd76f8b2013-09-23 17:59:50 -070048 final PendingIntent otaResponseIntent = getIntent().getParcelableExtra(
49 OtaUtils.EXTRA_OTASP_RESULT_CODE_PENDING_INTENT);
Santos Cordon83570472013-09-06 15:45:10 -070050
Santos Cordon00d7a432013-09-17 14:07:14 -070051 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 Cordoncd76f8b2013-09-23 17:59:50 -070061 }, otaResponseIntent);
Santos Cordon00d7a432013-09-17 14:07:14 -070062
Santos Cordon83570472013-09-06 15:45:10 -070063 startProvisioning();
64 }
65
66 @Override
67 protected void onDestroy() {
68 super.onDestroy();
69
Santos Cordoncd76f8b2013-09-23 17:59:50 -070070 Log.i(TAG, "onDestroy");
Santos Cordon83570472013-09-06 15:45:10 -070071
72 if (mDialog != null && mDialog.isShowing()) {
73 mDialog.dismiss();
74 mDialog = null;
75 }
Santos Cordon83570472013-09-06 15:45:10 -070076 }
77
78 private void startProvisioning() {
79 buildAndShowDialog();
Santos Cordon00d7a432013-09-17 14:07:14 -070080 mHfaLogic.start();
Santos Cordon83570472013-09-06 15:45:10 -070081 }
82
83 private void buildAndShowDialog() {
Yorke Lee30b68db2014-09-25 18:05:22 -070084 mDialog = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)
Santos Cordon83570472013-09-06 15:45:10 -070085 .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 Cordoncd76f8b2013-09-23 17:59:50 -070091 onUserSkip();
Santos Cordon83570472013-09-06 15:45:10 -070092 }})
93 /*.setOnCancelListener(new DialogInterface.OnCancelListener() {
94 @Override
95 public void onCancel(DialogInterface di) {
Santos Cordon00d7a432013-09-17 14:07:14 -070096 sendFinalResponse(OTASP_USER_SKIPPED);
Santos Cordon83570472013-09-06 15:45:10 -070097 }})*/
98 .create();
99
Santos Cordon00d7a432013-09-17 14:07:14 -0700100 // Do not allow user to dismiss dialog unless they are clicking "skip"
101 mDialog.setCanceledOnTouchOutside(false);
102 mDialog.setCancelable(false);
103
Santos Cordoncd76f8b2013-09-23 17:59:50 -0700104 Log.i(TAG, "showing dialog");
Santos Cordon83570472013-09-06 15:45:10 -0700105 mDialog.show();
106 }
107
Santos Cordon83570472013-09-06 15:45:10 -0700108 private void onHfaError(String errorMsg) {
109 mDialog.dismiss();
110
Yorke Lee30b68db2014-09-25 18:05:22 -0700111 AlertDialog errorDialog = new AlertDialog.Builder(this,
112 AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)
Santos Cordon83570472013-09-06 15:45:10 -0700113 .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();
Santos Cordoncd76f8b2013-09-23 17:59:50 -0700119 onUserSkip();
Santos Cordon83570472013-09-06 15:45:10 -0700120 }
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() {
Santos Cordon83570472013-09-06 15:45:10 -0700136 finish();
137 }
Santos Cordoncd76f8b2013-09-23 17:59:50 -0700138
139 private void onUserSkip() {
140 finish();
141 }
142
Santos Cordon83570472013-09-06 15:45:10 -0700143}