165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/* 265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Copyright (C) 2014 The Android Open Source Project 365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License"); 565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License. 665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at 765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * http://www.apache.org/licenses/LICENSE-2.0 965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software 1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS, 1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and 1465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * limitations under the License. 1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.accessories; 1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport static android.provider.Settings.Secure.TTS_DEFAULT_RATE; 2065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.ActionBehavior; 2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.ActionKey; 2365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.BaseSettingsActivity; 2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.R; 2565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.dialog.old.Action; 2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.dialog.old.ActionAdapter; 2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.bluetooth.BluetoothAdapter; 2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.bluetooth.BluetoothDevice; 3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.BroadcastReceiver; 3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Context; 3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Intent; 3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.IntentFilter; 3465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Bundle; 3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Handler; 3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Message; 3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.util.Log; 3865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport java.util.Set; 3965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepublic class BluetoothAccessoryActivity extends BaseSettingsActivity 4165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane implements ActionAdapter.Listener { 4265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static final String EXTRA_ACCESSORY_ADDRESS = "accessory_address"; 4465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static final String EXTRA_ACCESSORY_NAME = "accessory_name"; 4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static final String EXTRA_ACCESSORY_ICON_ID = "accessory_icon_res"; 4665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final int MSG_UNPAIR_TIMEOUT = 1; 4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final int UNPAIR_TIMEOUT = 5000; 5065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 5165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String TAG = "aah.BluetoothAccessoryActivity"; 5265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final boolean DEBUG = false; 5365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 5465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private BluetoothDevice mDevice; 5565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected String mDeviceAddress; 5665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected String mDeviceName; 5765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected int mDeviceImgId; 5865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected boolean mDone; 5965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 6065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static Intent getIntent(Context context, String deviceAddress, 6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane String deviceName, int iconId) { 6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Intent i = new Intent(context, BluetoothAccessoryActivity.class); 6365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane i.putExtra(EXTRA_ACCESSORY_ADDRESS, deviceAddress); 6465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane i.putExtra(EXTRA_ACCESSORY_NAME, deviceName); 6565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane i.putExtra(EXTRA_ACCESSORY_ICON_ID, iconId); 6665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return i; 6765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 6865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 6965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // Broadcast Receiver for Bluetooth related events 7065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 7265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onReceive(Context context, Intent intent) { 7365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane BluetoothDevice device = intent 7465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 7565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mDone) { 7665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mDevice.equals(device)) { 7765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // Done removing device, finish the activity 7865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mMsgHandler.removeMessages(MSG_UNPAIR_TIMEOUT); 7965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane finish(); 8065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 8165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 8265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 8365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane }; 8465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 8565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // Internal message handler 8665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private Handler mMsgHandler = new Handler() { 8765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 8865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void handleMessage(Message msg) { 8965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane switch (msg.what) { 9065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case MSG_UNPAIR_TIMEOUT: 9165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane finish(); 9265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 9365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane default: 9465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 9565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 9665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane }; 9765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 9865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 9965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onCreate(Bundle savedInstanceState) { 10065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Bundle bundle = getIntent().getExtras(); 10165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (bundle != null) { 10265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDeviceAddress = bundle.getString(EXTRA_ACCESSORY_ADDRESS); 10365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDeviceName = bundle.getString(EXTRA_ACCESSORY_NAME); 10465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDeviceImgId = bundle.getInt(EXTRA_ACCESSORY_ICON_ID); 10565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 10665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDeviceName = getString(R.string.accessory_options); 10765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDeviceImgId = R.drawable.ic_qs_bluetooth_not_connected; 10865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 10965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 11065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super.onCreate(savedInstanceState); 11165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 11265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDone = false; 11365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 11465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); 11565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (btAdapter != null) { 11665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Set<BluetoothDevice> bondedDevices = btAdapter.getBondedDevices(); 11765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane for (BluetoothDevice device : bondedDevices) { 11865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mDeviceAddress.equals(device.getAddress())) { 11965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDevice = device; 12065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 12165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 12665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 12765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onResume() { 12865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // Set a broadcast receiver to let us know when the device has been removed 12965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane IntentFilter adapterIntentFilter = new IntentFilter(); 13065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane adapterIntentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); 13165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane registerReceiver(mBroadcastReceiver, adapterIntentFilter); 13265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super.onResume(); 13365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 13465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 13565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 13665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onPause() { 13765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane unregisterReceiver(mBroadcastReceiver); 13865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super.onPause(); 13965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 14165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 14265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onActionClicked(Action action) { 14365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mDone) { 14465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return; 14565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /* 14765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * For regular states 14865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 14965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ActionKey<ActionType, ActionBehavior> actionKey = new ActionKey<ActionType, ActionBehavior>( 15065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ActionType.class, ActionBehavior.class, action.getKey()); 15165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final ActionType type = actionKey.getType(); 15265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (type != null) { 15365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane switch (type) { 15465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case BLUETOOTH_DEVICE_RENAME: 15565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // TODO: Will be implemented in a separate CL 15665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return; 15765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case OK: 15865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane unpairDevice(); 15965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return; 16065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case CANCEL: 16165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane goBack(); // Cancelled request to STOP service 16265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return; 16365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane default: 16465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 16565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 16665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane setState(type, true); 16765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 16865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 16965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 17065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected Object getInitialState() { 17165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return ActionType.BLUETOOTH_DEVICE_OVERVIEW; 17265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 17365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 17465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 17565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected void goBack() { 17665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (!mDone) { 17765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super.goBack(); 17865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 17965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 18065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 18165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 18265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected void refreshActionList() { 18365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mActions.clear(); 18465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane switch ((ActionType) mState) { 18565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case BLUETOOTH_DEVICE_OVERVIEW: 18665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // Disabled for now, until the name input screen is implemented 18765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // mActions.add(ActionType.BLUETOOTH_DEVICE_RENAME.toAction(mResources)); 18865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mActions.add(ActionType.BLUETOOTH_DEVICE_UNPAIR.toAction(mResources)); 18965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 19065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case BLUETOOTH_DEVICE_UNPAIR: 19165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mActions.add(ActionType.OK.toAction(mResources)); 19265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mActions.add(ActionType.CANCEL.toAction(mResources)); 19365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 19465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane default: 19565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 19665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 19765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 19865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 19965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 20065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected void updateView() { 20165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane refreshActionList(); 20265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane switch ((ActionType) mState) { 20365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case BLUETOOTH_DEVICE_OVERVIEW: 20465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane setView(mDeviceName, getString(R.string.header_category_accessories), null, 20565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDeviceImgId); 20665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 20765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case BLUETOOTH_DEVICE_UNPAIR: 20865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane setView(getString(R.string.accessory_unpair), mDeviceName, null, mDeviceImgId); 20965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 21065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane default: 21165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 21265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 21365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 21465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 21565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane void unpairDevice() { 21665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mDevice != null) { 21765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int state = mDevice.getBondState(); 21865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 21965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (state == BluetoothDevice.BOND_BONDING) { 22065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDevice.cancelBondProcess(); 22165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 22365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (state != BluetoothDevice.BOND_NONE) { 22465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDone = true; 22565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // Set a timeout, just in case we don't receive the unpair notification we 22665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // use to finish the activity 22765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mMsgHandler.sendEmptyMessageDelayed(MSG_UNPAIR_TIMEOUT, UNPAIR_TIMEOUT); 22865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final boolean successful = mDevice.removeBond(); 22965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (successful) { 23065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (DEBUG) { 23165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Log.d(TAG, "Bluetooth device successfully unpaired."); 23265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 23365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // set the dialog to a waiting state 23465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mActions.clear(); 23565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane setView(getString(R.string.accessory_unpair), mDeviceName, 23665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane getString(R.string.accessory_unpairing), mDeviceImgId); 23765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 23865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Log.e(TAG, "Failed to unpair Bluetooth Device: " + mDevice.getName()); 23965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 24265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Log.e(TAG, "Bluetooth device not found. Address = " + mDeviceAddress); 24365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 24665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 24765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected void setProperty(boolean enable) { 24865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane} 250