blob: 8933c03c43e7b73d43898a22729f9f82d8e48f88 [file] [log] [blame]
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -07001/*
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
17package com.android.settings;
18
19import android.app.NotificationManager;
20import android.bluetooth.BluetoothDevice;
21import android.bluetooth.BluetoothIntent;
22import android.content.Context;
23import android.content.Intent;
24import android.os.Bundle;
25import android.util.Log;
26
27public 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}