summaryrefslogtreecommitdiffstats
path: root/core/java/android/server/BluetoothAdapterProperties.java
diff options
context:
space:
mode:
authorJake Hamby <jhamby@google.com>2010-12-09 14:47:57 -0800
committerJaikumar Ganesh <jaikumar@google.com>2011-02-24 16:26:20 -0800
commit9a62c9cd6585656f4e29ba971b1f88a510d674bd (patch)
tree59a53987458c799b35d14b3ed693879cc81aa9a7 /core/java/android/server/BluetoothAdapterProperties.java
parent5936245654f8d361a983b4f72bd7ea10e1a8c756 (diff)
downloadframeworks_base-9a62c9cd6585656f4e29ba971b1f88a510d674bd.zip
frameworks_base-9a62c9cd6585656f4e29ba971b1f88a510d674bd.tar.gz
frameworks_base-9a62c9cd6585656f4e29ba971b1f88a510d674bd.tar.bz2
Refactor android.server.BluetoothService classes.
Several cleanups to BluetoothService: - Move BluetoothService.BondState inner class to top level. - Extract adapter and remote device properties cache management logic into two new classes: BluetoothAdapterProperties and BluetoothDeviceProperties. - Add getter methods for other classes in the package to access the new properties cache objects for multi-part operations. - Inline log() method in BluetoothService and selected the appropriate Log method (Log.d, Log.w, Log.e) for each message. - Refactor dump() method into smaller sized pieces. - Clean up logic of updateCountersAndCheckForConnectionStateChange() method for better readability. - Change sendConnectionStateChange() to return instead of sending an intent if the current or previous state values are invalid. Previously the code sent an intent with -1 for the invalid state. - Added Javadoc comments to document the methods that are called from native Bluez code. - Fixed some typos and code style issues. Original Change by: Jake Hamby Modified by: Jaikumar Ganesh Change-Id: I76ebac00ecd29566dcb2d1ad3e7a486b7530ce24
Diffstat (limited to 'core/java/android/server/BluetoothAdapterProperties.java')
-rw-r--r--core/java/android/server/BluetoothAdapterProperties.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/core/java/android/server/BluetoothAdapterProperties.java b/core/java/android/server/BluetoothAdapterProperties.java
new file mode 100644
index 0000000..ae8104b
--- /dev/null
+++ b/core/java/android/server/BluetoothAdapterProperties.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.server;
+
+import android.content.Context;
+import android.util.Log;
+
+import java.util.HashMap;
+import java.util.Map;
+
+class BluetoothAdapterProperties {
+
+ private static final String TAG = "BluetoothAdapterProperties";
+
+ private final Map<String, String> mPropertiesMap;
+ private final Context mContext;
+ private final BluetoothService mService;
+
+ BluetoothAdapterProperties(Context context, BluetoothService service) {
+ mPropertiesMap = new HashMap<String, String>();
+ mContext = context;
+ mService = service;
+ }
+
+ synchronized String getProperty(String name) {
+ if (mPropertiesMap.isEmpty()) {
+ getAllProperties();
+ }
+ return mPropertiesMap.get(name);
+ }
+
+ String getObjectPath() {
+ return getProperty("ObjectPath");
+ }
+
+ synchronized void clear() {
+ mPropertiesMap.clear();
+ }
+
+ synchronized boolean isEmpty() {
+ return mPropertiesMap.isEmpty();
+ }
+
+ synchronized void setProperty(String name, String value) {
+ mPropertiesMap.put(name, value);
+ }
+
+ synchronized void getAllProperties() {
+ mContext.enforceCallingOrSelfPermission(
+ BluetoothService.BLUETOOTH_PERM,
+ "Need BLUETOOTH permission");
+ mPropertiesMap.clear();
+
+ String properties[] = (String[]) mService
+ .getAdapterPropertiesNative();
+ // The String Array consists of key-value pairs.
+ if (properties == null) {
+ Log.e(TAG, "*Error*: GetAdapterProperties returned NULL");
+ return;
+ }
+
+ for (int i = 0; i < properties.length; i++) {
+ String name = properties[i];
+ String newValue = null;
+ int len;
+ if (name == null) {
+ Log.e(TAG, "Error:Adapter Property at index " + i + " is null");
+ continue;
+ }
+ if (name.equals("Devices") || name.equals("UUIDs")) {
+ StringBuilder str = new StringBuilder();
+ len = Integer.valueOf(properties[++i]);
+ for (int j = 0; j < len; j++) {
+ str.append(properties[++i]);
+ str.append(",");
+ }
+ if (len > 0) {
+ newValue = str.toString();
+ }
+ } else {
+ newValue = properties[++i];
+ }
+ mPropertiesMap.put(name, newValue);
+ }
+
+ // Add adapter object path property.
+ String adapterPath = mService.getAdapterPathNative();
+ if (adapterPath != null) {
+ mPropertiesMap.put("ObjectPath", adapterPath + "/dev_");
+ }
+ }
+}