summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/map/BluetoothMapUtils.java
diff options
context:
space:
mode:
authorMatthew Xie <mattx@google.com>2013-07-18 18:18:36 -0700
committerZhihai Xu <zhihaixu@google.com>2013-08-09 18:44:53 -0700
commitfd6603b8bf9ed72dcc8bd59aaef3209251b6e17c (patch)
treefecaf3c95adce97dc5176cc341d903fe488d5edf /src/com/android/bluetooth/map/BluetoothMapUtils.java
parentbb1ac417208c8e283f9b5b49f4413856500ed0f9 (diff)
downloadandroid_packages_apps_Bluetooth-fd6603b8bf9ed72dcc8bd59aaef3209251b6e17c.tar.gz
android_packages_apps_Bluetooth-fd6603b8bf9ed72dcc8bd59aaef3209251b6e17c.tar.bz2
android_packages_apps_Bluetooth-fd6603b8bf9ed72dcc8bd59aaef3209251b6e17c.zip
Bluetooth MAP profile - sms and mms support initial check-in
bug:10116530 Change-Id: If9ce878d71c1e1b12416014c433da03b3033e158
Diffstat (limited to 'src/com/android/bluetooth/map/BluetoothMapUtils.java')
-rw-r--r--src/com/android/bluetooth/map/BluetoothMapUtils.java116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/com/android/bluetooth/map/BluetoothMapUtils.java b/src/com/android/bluetooth/map/BluetoothMapUtils.java
new file mode 100644
index 000000000..e57cf16b1
--- /dev/null
+++ b/src/com/android/bluetooth/map/BluetoothMapUtils.java
@@ -0,0 +1,116 @@
+/*
+* Copyright (C) 2013 Samsung System LSI
+* 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 com.android.bluetooth.map;
+
+
+/**
+ * Various utility methods and generic defines that can be used throughout MAPS
+ */
+public class BluetoothMapUtils {
+
+ private static final String TAG = "MapUtils";
+ private static final boolean V = BluetoothMapService.VERBOSE;
+ /* We use the upper 5 bits for the type mask - avoid using the top bit, since it
+ * indicates a negative value, hence corrupting the formatter when converting to
+ * type String. (I really miss the unsigned type in Java:))
+ */
+ private static final long HANDLE_TYPE_MASK = 0xf<<59;
+ private static final long HANDLE_TYPE_MMS_MASK = 0x1<<59;
+ private static final long HANDLE_TYPE_EMAIL_MASK = 0x2<<59;
+ private static final long HANDLE_TYPE_SMS_GSM_MASK = 0x4<<59;
+ private static final long HANDLE_TYPE_SMS_CDMA_MASK = 0x8<<59;
+
+ /**
+ * This enum is used to convert from the bMessage type property to a type safe
+ * type. Hence do not change the names of the enum values.
+ */
+ public enum TYPE{
+ EMAIL,
+ SMS_GSM,
+ SMS_CDMA,
+ MMS
+ }
+
+ /**
+ * Convert a Content Provider handle and a Messagetype into a unique handle
+ * @param cpHandle content provider handle
+ * @param messageType message type (TYPE_MMS/TYPE_SMS_GSM/TYPE_SMS_CDMA/TYPE_EMAIL)
+ * @return String Formatted Map Handle
+ */
+ static public String getMapHandle(long cpHandle, TYPE messageType){
+ String mapHandle = "-1";
+ switch(messageType)
+ {
+ case MMS:
+ mapHandle = String.format("%016X",(cpHandle | HANDLE_TYPE_MMS_MASK));
+ break;
+ case SMS_GSM:
+ mapHandle = String.format("%016X",cpHandle | HANDLE_TYPE_SMS_GSM_MASK);
+ break;
+ case SMS_CDMA:
+ mapHandle = String.format("%016X",cpHandle | HANDLE_TYPE_SMS_CDMA_MASK);
+ break;
+ case EMAIL:
+ mapHandle = String.format("%016X",(cpHandle | HANDLE_TYPE_EMAIL_MASK)); //TODO correct when email support is implemented
+ break;
+ default:
+ throw new IllegalArgumentException("Message type not supported");
+ }
+ return mapHandle;
+
+ }
+
+ /**
+ * Convert a handle string the the raw long representation, including the type bit.
+ * @param mapHandle the handle string
+ * @return the handle value
+ */
+ static public long getMsgHandleAsLong(String mapHandle){
+ return Long.parseLong(mapHandle, 16);
+ }
+ /**
+ * Convert a Map Handle into a content provider Handle
+ * @param mapHandle handle to convert from
+ * @return content provider handle without message type mask
+ */
+ static public long getCpHandle(String mapHandle)
+ {
+ long cpHandle = getMsgHandleAsLong(mapHandle);
+ /* remove masks as the call should already know what type of message this handle is for */
+ cpHandle &= ~HANDLE_TYPE_MASK;
+ return cpHandle;
+ }
+
+ /**
+ * Extract the message type from the handle.
+ * @param mapHandle
+ * @return
+ */
+ static public TYPE getMsgTypeFromHandle(String mapHandle) {
+ long cpHandle = getMsgHandleAsLong(mapHandle);
+
+ if((cpHandle & HANDLE_TYPE_MMS_MASK) != 0)
+ return TYPE.MMS;
+ if((cpHandle & HANDLE_TYPE_EMAIL_MASK) != 0)
+ return TYPE.EMAIL;
+ if((cpHandle & HANDLE_TYPE_SMS_GSM_MASK) != 0)
+ return TYPE.SMS_GSM;
+ if((cpHandle & HANDLE_TYPE_SMS_CDMA_MASK) != 0)
+ return TYPE.SMS_CDMA;
+
+ throw new IllegalArgumentException("Message type not found in handle string.");
+ }
+}
+