The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2007 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.settings; |
| 18 | |
| 19 | import android.app.NotificationManager; |
| 20 | import android.bluetooth.BluetoothDevice; |
| 21 | import android.bluetooth.BluetoothIntent; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.os.Bundle; |
| 25 | import android.util.Log; |
| 26 | |
| 27 | public class BluetoothPINEntry extends BluetoothDataEntry { |
| 28 | private BluetoothDevice mBluetooth; |
| 29 | private String mAddress; |
| 30 | |
| 31 | @Override |
| 32 | public void onCreate(Bundle icicle) { |
| 33 | super.onCreate(icicle); |
| 34 | |
| 35 | Intent intent = getIntent(); |
| 36 | if (!intent.getAction().equals(BluetoothIntent.PAIRING_REQUEST_ACTION)) |
| 37 | { |
| 38 | Log.e(this.getClass().getName(), |
| 39 | "Error: this activity may be started only with intent " + |
| 40 | BluetoothIntent.PAIRING_REQUEST_ACTION); |
| 41 | finish(); |
| 42 | } |
| 43 | |
| 44 | // Cancel the notification, if any |
| 45 | NotificationManager manager = (NotificationManager) |
| 46 | getSystemService(Context.NOTIFICATION_SERVICE); |
| 47 | manager.cancel(0xb100ceee); |
| 48 | |
| 49 | mAddress = intent.getStringExtra(BluetoothIntent.ADDRESS); |
| 50 | |
| 51 | mBluetooth = (BluetoothDevice)getSystemService(BLUETOOTH_SERVICE); |
| 52 | |
| 53 | String remoteName = mBluetooth.getRemoteName(mAddress); |
| 54 | if (remoteName == null) { |
| 55 | remoteName = mAddress; |
| 56 | } |
| 57 | |
| 58 | mDataLabel.setText(getString(R.string.bluetooth_enter_pin_msg) + remoteName); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public void activityResult(int result, String data, Bundle extras) { |
| 63 | switch (result) { |
| 64 | case RESULT_OK: |
| 65 | byte[] pin = BluetoothDevice.convertPinToBytes(mDataEntry.getText().toString()); |
| 66 | if (pin == null) { |
| 67 | return; |
| 68 | } |
| 69 | mBluetooth.setPin(mAddress, pin); |
| 70 | break; |
| 71 | case RESULT_CANCELED: |
| 72 | mBluetooth.cancelPin(mAddress); |
| 73 | break; |
| 74 | } |
| 75 | finish(); |
| 76 | } |
| 77 | } |