am 6078d450: Merge "b/2630339 Fixed the crash when an app requests BT to be enabled" into froyo

Merge commit '6078d4503d6bc29fe6d2ff7784124a66fe48186e' into froyo-plus-aosp

* commit '6078d4503d6bc29fe6d2ff7784124a66fe48186e':
  b/2630339 Fixed the crash when an app requests BT to be enabled
This commit is contained in:
Michael Chan
2010-04-28 13:14:35 -07:00
committed by Android Git Automerger

View File

@@ -16,11 +16,10 @@
package com.android.settings.bluetooth; package com.android.settings.bluetooth;
import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
import com.android.settings.R; import com.android.settings.R;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@@ -31,14 +30,12 @@ import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.widget.TextView;
/** /**
* RequestPermissionActivity asks the user whether to enable discovery. This is * RequestPermissionActivity asks the user whether to enable discovery. This is
* usually started by an application wanted to start bluetooth and or discovery * usually started by an application wanted to start bluetooth and or discovery
*/ */
public class RequestPermissionActivity extends AlertActivity implements public class RequestPermissionActivity extends Activity implements
DialogInterface.OnClickListener { DialogInterface.OnClickListener {
// Command line to test this // Command line to test this
// adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE // adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE
@@ -73,6 +70,8 @@ public class RequestPermissionActivity extends AlertActivity implements
private boolean mUserConfirmed = false; private boolean mUserConfirmed = false;
private AlertDialog mDialog = null;
private BroadcastReceiver mReceiver = new BroadcastReceiver() { private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override @Override
@@ -84,7 +83,7 @@ public class RequestPermissionActivity extends AlertActivity implements
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothDevice.ERROR); int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothDevice.ERROR);
if (state == BluetoothAdapter.STATE_ON) { if (state == BluetoothAdapter.STATE_ON) {
if (mUserConfirmed) { if (mUserConfirmed) {
proceedAndFinish(false); proceedAndFinish();
} }
} }
} }
@@ -136,7 +135,7 @@ public class RequestPermissionActivity extends AlertActivity implements
case BluetoothAdapter.STATE_ON: case BluetoothAdapter.STATE_ON:
if (mEnableOnly) { if (mEnableOnly) {
// Nothing to do. Already enabled. // Nothing to do. Already enabled.
proceedAndFinish(false); proceedAndFinish();
return; return;
} else { } else {
// Ask the user about enabling discovery mode // Ask the user about enabling discovery mode
@@ -147,28 +146,24 @@ public class RequestPermissionActivity extends AlertActivity implements
} }
private void createDialog() { private void createDialog() {
final AlertController.AlertParams p = mAlertParams; AlertDialog.Builder builder = new AlertDialog.Builder(this);
p.mIconId = android.R.drawable.ic_dialog_info; builder.setIcon(android.R.drawable.ic_dialog_info);
p.mTitle = getString(R.string.bluetooth_permission_request); builder.setTitle(getString(R.string.bluetooth_permission_request));
View view = getLayoutInflater().inflate(R.layout.bluetooth_discoverable, null);
p.mView = view;
TextView tv = (TextView) view.findViewById(R.id.message);
if (mNeededToEnableBluetooth) { if (mNeededToEnableBluetooth) {
// RequestPermissionHelperActivity has gotten confirmation from user // RequestPermissionHelperActivity has gotten confirmation from user
// to turn on BT // to turn on BT
tv.setText(getString(R.string.bluetooth_turning_on)); builder.setMessage(getString(R.string.bluetooth_turning_on));
builder.setCancelable(false);
} else { } else {
// Ask the user whether to turn on discovery mode or not // Ask the user whether to turn on discovery mode or not
tv.setText(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout)); builder.setMessage(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
p.mPositiveButtonText = getString(R.string.yes); builder.setPositiveButton(getString(R.string.yes), this);
p.mPositiveButtonListener = this; builder.setNegativeButton(getString(R.string.no), this);
p.mNegativeButtonText = getString(R.string.no);
p.mNegativeButtonListener = this;
} }
setupAlert(); mDialog = builder.create();
mDialog.show();
} }
@Override @Override
@@ -182,6 +177,7 @@ public class RequestPermissionActivity extends AlertActivity implements
if (resultCode != RESULT_BT_STARTING_OR_STARTED) { if (resultCode != RESULT_BT_STARTING_OR_STARTED) {
setResult(resultCode); setResult(resultCode);
finish(); finish();
return;
} }
// Back from RequestPermissionHelperActivity. User confirmed to enable // Back from RequestPermissionHelperActivity. User confirmed to enable
@@ -189,7 +185,7 @@ public class RequestPermissionActivity extends AlertActivity implements
mUserConfirmed = true; mUserConfirmed = true;
if (mLocalManager.getBluetoothState() == BluetoothAdapter.STATE_ON) { if (mLocalManager.getBluetoothState() == BluetoothAdapter.STATE_ON) {
proceedAndFinish(false); proceedAndFinish();
} else { } else {
// If BT is not up yet, show "Turning on Bluetooth..." // If BT is not up yet, show "Turning on Bluetooth..."
createDialog(); createDialog();
@@ -199,16 +195,17 @@ public class RequestPermissionActivity extends AlertActivity implements
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which) { switch (which) {
case DialogInterface.BUTTON_POSITIVE: case DialogInterface.BUTTON_POSITIVE:
proceedAndFinish(true); proceedAndFinish();
break; break;
case DialogInterface.BUTTON_NEGATIVE: case DialogInterface.BUTTON_NEGATIVE:
setResult(Activity.RESULT_CANCELED); setResult(Activity.RESULT_CANCELED);
finish();
break; break;
} }
} }
private void proceedAndFinish(boolean buttonPressed) { private void proceedAndFinish() {
int returnCode; int returnCode;
if (mEnableOnly) { if (mEnableOnly) {
@@ -227,10 +224,12 @@ public class RequestPermissionActivity extends AlertActivity implements
returnCode = Activity.RESULT_CANCELED; returnCode = Activity.RESULT_CANCELED;
} }
setResult(returnCode); if (mDialog != null) {
if (!buttonPressed) { mDialog.dismiss();
finish();
} }
setResult(returnCode);
finish();
} }
private boolean parseIntent() { private boolean parseIntent() {