summaryrefslogtreecommitdiffstats
path: root/core/java/android/server/BluetoothService.java
diff options
context:
space:
mode:
authorJaikumar Ganesh <jaikumar@google.com>2011-06-16 21:43:29 -0700
committerJaikumar Ganesh <jaikumar@google.com>2011-06-21 09:27:12 -0700
commitd762f063be970033314d3f77194bfe5cb284b605 (patch)
tree906bf2dee1e0d5ea781048e09012170ec8d22298 /core/java/android/server/BluetoothService.java
parentc7b87766b21fe5cf2f644efa8753b936d413dc9a (diff)
downloadframeworks_base-d762f063be970033314d3f77194bfe5cb284b605.zip
frameworks_base-d762f063be970033314d3f77194bfe5cb284b605.tar.gz
frameworks_base-d762f063be970033314d3f77194bfe5cb284b605.tar.bz2
DO NOT MERGE Incoming Bluetooth Connection requests - dialog.
This sends the intents to the Settings app to show the dialogs for the incoming connection requests. Change-Id: Ibe267f7cda28ce2a46c25800df2e8ac685b0b9e6
Diffstat (limited to 'core/java/android/server/BluetoothService.java')
-rw-r--r--core/java/android/server/BluetoothService.java133
1 files changed, 126 insertions, 7 deletions
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index 4d4d309..064c86c 100644
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -27,8 +27,8 @@ package android.server;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothDeviceProfileState;
+import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfileState;
import android.bluetooth.BluetoothSocket;
import android.bluetooth.BluetoothUuid;
@@ -67,6 +67,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -143,6 +144,11 @@ public class BluetoothService extends IBluetooth.Stub {
private static String mDockAddress;
private String mDockPin;
+ private static final String INCOMING_CONNECTION_FILE =
+ "/data/misc/bluetooth/incoming_connection.conf";
+ private HashMap<String, Pair<Integer, String>> mIncomingConnections;
+
+
private static class RemoteService {
public String address;
public ParcelUuid uuid;
@@ -210,6 +216,7 @@ public class BluetoothService extends IBluetooth.Stub {
filter.addAction(Intent.ACTION_DOCK_EVENT);
mContext.registerReceiver(mReceiver, filter);
+ mIncomingConnections = new HashMap<String, Pair<Integer, String>>();
}
public static synchronized String readDockBluetoothAddress() {
@@ -743,8 +750,6 @@ public class BluetoothService extends IBluetooth.Stub {
if (state == BluetoothDevice.BOND_BONDED) {
addProfileState(address);
- } else if (state == BluetoothDevice.BOND_NONE) {
- removeProfileState(address);
}
if (DBG) log(address + " bond state " + oldState + " -> " + state + " (" +
@@ -1326,6 +1331,8 @@ public class BluetoothService extends IBluetooth.Stub {
}
public synchronized boolean removeBondInternal(String address) {
+ // Unset the trusted device state and then unpair
+ setTrust(address, false);
return removeDeviceNative(getObjectPathFromAddress(address));
}
@@ -2175,10 +2182,6 @@ public class BluetoothService extends IBluetooth.Stub {
return state;
}
- private void removeProfileState(String address) {
- mDeviceProfileState.remove(address);
- }
-
private void initProfileState() {
String []bonds = null;
String val = getPropertyInternal("Devices");
@@ -2227,6 +2230,11 @@ public class BluetoothService extends IBluetooth.Stub {
mA2dpService = a2dpService;
}
+ /*package*/ Integer getAuthorizationAgentRequestData(String address) {
+ Integer data = mEventLoop.getAuthorizationAgentRequestData().remove(address);
+ return data;
+ }
+
public void sendProfileStateMessage(int profile, int cmd) {
Message msg = new Message();
msg.what = cmd;
@@ -2237,6 +2245,116 @@ public class BluetoothService extends IBluetooth.Stub {
}
}
+ private void createIncomingConnectionStateFile() {
+ File f = new File(INCOMING_CONNECTION_FILE);
+ if (!f.exists()) {
+ try {
+ f.createNewFile();
+ } catch (IOException e) {
+ Log.e(TAG, "IOException: cannot create file");
+ }
+ }
+ }
+
+ /** @hide */
+ public Pair<Integer, String> getIncomingState(String address) {
+ if (mIncomingConnections.isEmpty()) {
+ createIncomingConnectionStateFile();
+ readIncomingConnectionState();
+ }
+ return mIncomingConnections.get(address);
+ }
+
+ private void readIncomingConnectionState() {
+ synchronized(mIncomingConnections) {
+ FileInputStream fstream = null;
+ try {
+ fstream = new FileInputStream(INCOMING_CONNECTION_FILE);
+ DataInputStream in = new DataInputStream(fstream);
+ BufferedReader file = new BufferedReader(new InputStreamReader(in));
+ String line;
+ while((line = file.readLine()) != null) {
+ line = line.trim();
+ if (line.length() == 0) continue;
+ String[] value = line.split(",");
+ if (value != null && value.length == 3) {
+ Integer val1 = Integer.parseInt(value[1]);
+ Pair<Integer, String> val = new Pair(val1, value[2]);
+ mIncomingConnections.put(value[0], val);
+ }
+ }
+ } catch (FileNotFoundException e) {
+ log("FileNotFoundException: readIncomingConnectionState" + e.toString());
+ } catch (IOException e) {
+ log("IOException: readIncomingConnectionState" + e.toString());
+ } finally {
+ if (fstream != null) {
+ try {
+ fstream.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+
+ private void truncateIncomingConnectionFile() {
+ RandomAccessFile r = null;
+ try {
+ r = new RandomAccessFile(INCOMING_CONNECTION_FILE, "rw");
+ r.setLength(0);
+ } catch (FileNotFoundException e) {
+ log("FileNotFoundException: truncateIncomingConnectionState" + e.toString());
+ } catch (IOException e) {
+ log("IOException: truncateIncomingConnectionState" + e.toString());
+ } finally {
+ if (r != null) {
+ try {
+ r.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ /** @hide */
+ public void writeIncomingConnectionState(String address, Pair<Integer, String> data) {
+ synchronized(mIncomingConnections) {
+ mIncomingConnections.put(address, data);
+
+ truncateIncomingConnectionFile();
+ BufferedWriter out = null;
+ StringBuilder value = new StringBuilder();
+ try {
+ out = new BufferedWriter(new FileWriter(INCOMING_CONNECTION_FILE, true));
+ for (String devAddress: mIncomingConnections.keySet()) {
+ Pair<Integer, String> val = mIncomingConnections.get(devAddress);
+ value.append(devAddress);
+ value.append(",");
+ value.append(val.first.toString());
+ value.append(",");
+ value.append(val.second);
+ value.append("\n");
+ }
+ out.write(value.toString());
+ } catch (FileNotFoundException e) {
+ log("FileNotFoundException: writeIncomingConnectionState" + e.toString());
+ } catch (IOException e) {
+ log("IOException: writeIncomingConnectionState" + e.toString());
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+
private static void log(String msg) {
Log.d(TAG, msg);
}
@@ -2287,4 +2405,5 @@ public class BluetoothService extends IBluetooth.Stub {
short channel);
private native boolean removeServiceRecordNative(int handle);
private native boolean setLinkTimeoutNative(String path, int num_slots);
+ native boolean setAuthorizationNative(String address, boolean value, int data);
}