summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/map/BluetoothMapFolderElement.java
diff options
context:
space:
mode:
authorCasper Bonde <c.bonde@samsung.com>2014-07-24 13:47:23 +0200
committerMatthew Xie <mattx@google.com>2014-08-06 00:06:12 -0700
commit326b5e610063ac24c0ba467ac585bd4c7f618a67 (patch)
tree863e6fa83714e668d7fc9eeab1c693942763b219 /src/com/android/bluetooth/map/BluetoothMapFolderElement.java
parentf021c4ee6ba53c8512807c1469b2432278cf6cca (diff)
downloadandroid_packages_apps_Bluetooth-326b5e610063ac24c0ba467ac585bd4c7f618a67.tar.gz
android_packages_apps_Bluetooth-326b5e610063ac24c0ba467ac585bd4c7f618a67.tar.bz2
android_packages_apps_Bluetooth-326b5e610063ac24c0ba467ac585bd4c7f618a67.zip
BT MAP: added support for email sharing over BT
- added support for Emails - added activity to do setup of the email accounts to share - added improved handling of MMS, SMS and Email - Many optimizations to speed (especially getMessageListing) - fixed wakelock problem - fixed user timeout problem when user do not react to msg access request - added missing privileges - support for Quoted Printable format - added accountId in test case URIs - fixed problem with service numbers being strings - fixed problem with read flag in getMessage - added support for transparent flag in Email Push - added missing send-event for non-imap accounts - set attachment size to 0 if text-only message - fixed double send for sms messages with retry - removed secondary phone numbers from recipient/originator - removed insert-address-token in MMS messages - fixed null-pointer exception in settings (missing extra in intent) - send text-only mms as sms (workaround to make it cheaper) - fixed rejection of native and fraction requests - better handling of unknown message types in push - fixed problem with possible illigal xml chars in message listing - added missing WRITE_APN_SETTINGS permission to manifest - fixed problem with notifications when pushing to folders other than OUTBOX - removed debugging code - added support for threadId - fixed permission problems - changed to use ContentProviderClients for Email app access - fixed names for member vars UPDATE: Moved the MAP E-mail API to the bluetooth package. UPDATE: Added check for the presense of MMS parts. This is needed due to a change in the MMS app/subsystem, where deleted messages gets corrupted. Signed-off-by: Casper Bonde <c.bonde@samsung.com> Change-Id: Ib5dbe7c2d5c0ba8d978ae843d840028592e3cab4
Diffstat (limited to 'src/com/android/bluetooth/map/BluetoothMapFolderElement.java')
-rw-r--r--src/com/android/bluetooth/map/BluetoothMapFolderElement.java209
1 files changed, 168 insertions, 41 deletions
diff --git a/src/com/android/bluetooth/map/BluetoothMapFolderElement.java b/src/com/android/bluetooth/map/BluetoothMapFolderElement.java
index d3909ddad..42728b1ff 100644
--- a/src/com/android/bluetooth/map/BluetoothMapFolderElement.java
+++ b/src/com/android/bluetooth/map/BluetoothMapFolderElement.java
@@ -1,5 +1,5 @@
/*
-* Copyright (C) 2013 Samsung System LSI
+* Copyright (C) 2014 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
@@ -14,32 +14,62 @@
*/
package com.android.bluetooth.map;
+
+import android.util.Log;
+import org.xmlpull.v1.XmlSerializer;
+
+import com.android.internal.util.FastXmlSerializer;
+
import java.io.IOException;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map.Entry;
-import org.xmlpull.v1.XmlSerializer;
-
-import android.util.Xml;
/**
- * @author cbonde
+ * Class to contain a single folder element representation.
*
*/
public class BluetoothMapFolderElement {
- private String name;
- private BluetoothMapFolderElement parent = null;
- private ArrayList<BluetoothMapFolderElement> subFolders;
+ private String mName;
+ private BluetoothMapFolderElement mParent = null;
+ private boolean mHasSmsMmsContent = false;
+ private long mEmailFolderId = -1;
+ private HashMap<String, BluetoothMapFolderElement> mSubFolders;
+
+ private static final boolean D = BluetoothMapService.DEBUG;
+ private static final boolean V = BluetoothMapService.VERBOSE;
+
+ private final static String TAG = "BluetoothMapFolderElement";
- public BluetoothMapFolderElement( String name, BluetoothMapFolderElement parrent ){
- this.name = name;
- this.parent = parrent;
- subFolders = new ArrayList<BluetoothMapFolderElement>();
+ public BluetoothMapFolderElement( String name, BluetoothMapFolderElement parrent){
+ this.mName = name;
+ this.mParent = parrent;
+ mSubFolders = new HashMap<String, BluetoothMapFolderElement>();
}
public String getName() {
- return name;
+ return mName;
+ }
+
+ public boolean hasSmsMmsContent(){
+ return mHasSmsMmsContent;
+ }
+
+ public long getEmailFolderId(){
+ return mEmailFolderId;
+ }
+
+ public void setEmailFolderId(long emailFolderId) {
+ this.mEmailFolderId = emailFolderId;
+ }
+
+ public void setHasSmsMmsContent(boolean hasSmsMmsContent) {
+ this.mHasSmsMmsContent = hasSmsMmsContent;
}
/**
@@ -47,10 +77,68 @@ public class BluetoothMapFolderElement {
* @return the parent folder or null if we are at the root folder.
*/
public BluetoothMapFolderElement getParent() {
- return parent;
+ return mParent;
}
/**
+ * Build the full path to this folder
+ * @return a string representing the full path.
+ */
+ public String getFullPath() {
+ StringBuilder sb = new StringBuilder(mName);
+ BluetoothMapFolderElement current = mParent;
+ while(current != null) {
+ if(current.getParent() != null) {
+ sb.insert(0, current.mName + "/");
+ }
+ current = current.getParent();
+ }
+ //sb.insert(0, "/"); Should this be included? The MAP spec. do not include it in examples.
+ return sb.toString();
+ }
+
+
+ public BluetoothMapFolderElement getEmailFolderByName(String name) {
+ BluetoothMapFolderElement folderElement = this.getRoot();
+ folderElement = folderElement.getSubFolder("telecom");
+ folderElement = folderElement.getSubFolder("msg");
+ folderElement = folderElement.getSubFolder(name);
+ if (folderElement != null && folderElement.getEmailFolderId() == -1 )
+ folderElement = null;
+ return folderElement;
+ }
+
+ public BluetoothMapFolderElement getEmailFolderById(long id) {
+ return getEmailFolderById(id, this);
+ }
+
+ public static BluetoothMapFolderElement getEmailFolderById(long id,
+ BluetoothMapFolderElement folderStructure) {
+ if(folderStructure == null) {
+ return null;
+ }
+ return findEmailFolderById(id, folderStructure.getRoot());
+ }
+
+ private static BluetoothMapFolderElement findEmailFolderById(long id,
+ BluetoothMapFolderElement folder) {
+ if(folder.getEmailFolderId() == id) {
+ return folder;
+ }
+ /* Else */
+ for(BluetoothMapFolderElement subFolder : folder.mSubFolders.values().toArray(
+ new BluetoothMapFolderElement[folder.mSubFolders.size()]))
+ {
+ BluetoothMapFolderElement ret = findEmailFolderById(id, subFolder);
+ if(ret != null) {
+ return ret;
+ }
+ }
+ return null;
+ }
+
+
+ /**
* Fetch the root folder.
* @return the parent folder or null if we are at the root folder.
*/
@@ -62,13 +150,53 @@ public class BluetoothMapFolderElement {
}
/**
- * Add a folder.
+ * Add a virtual folder.
* @param name the name of the folder to add.
* @return the added folder element.
*/
public BluetoothMapFolderElement addFolder(String name){
- BluetoothMapFolderElement newFolder = new BluetoothMapFolderElement(name, this);
- subFolders.add(newFolder);
+ name = name.toLowerCase(Locale.US);
+ BluetoothMapFolderElement newFolder = mSubFolders.get(name);
+ if(D) Log.i(TAG,"addFolder():" + name);
+ if(newFolder == null) {
+ newFolder = new BluetoothMapFolderElement(name, this);
+ mSubFolders.put(name, newFolder);
+ }
+ return newFolder;
+ }
+
+ /**
+ * Add a sms/mms folder.
+ * @param name the name of the folder to add.
+ * @return the added folder element.
+ */
+ public BluetoothMapFolderElement addSmsMmsFolder(String name){
+ name = name.toLowerCase(Locale.US);
+ BluetoothMapFolderElement newFolder = mSubFolders.get(name);
+ if(D) Log.i(TAG,"addSmsMmsFolder():" + name);
+ if(newFolder == null) {
+ newFolder = new BluetoothMapFolderElement(name, this);
+ mSubFolders.put(name, newFolder);
+ }
+ newFolder.setHasSmsMmsContent(true);
+ return newFolder;
+ }
+
+ /**
+ * Add an Email folder.
+ * @param name the name of the folder to add.
+ * @return the added folder element.
+ */
+ public BluetoothMapFolderElement addEmailFolder(String name, long emailFolderId){
+ name = name.toLowerCase();
+ BluetoothMapFolderElement newFolder = mSubFolders.get(name);
+ if(V) Log.v(TAG,"addEmailFolder(): name = " + name
+ + "id = " + emailFolderId);
+ if(newFolder == null) {
+ newFolder = new BluetoothMapFolderElement(name, this);
+ mSubFolders.put(name, newFolder);
+ }
+ newFolder.setEmailFolderId(emailFolderId);
return newFolder;
}
@@ -77,7 +205,7 @@ public class BluetoothMapFolderElement {
* @return returns the number of sub folders.
*/
public int getSubFolderCount(){
- return subFolders.size();
+ return mSubFolders.size();
}
/**
@@ -86,47 +214,46 @@ public class BluetoothMapFolderElement {
* @return the subFolder element if found {@code null} otherwise.
*/
public BluetoothMapFolderElement getSubFolder(String folderName){
- for(BluetoothMapFolderElement subFolder : subFolders){
- if(subFolder.getName().equals(folderName))
- return subFolder;
- }
- return null;
+ return mSubFolders.get(folderName.toLowerCase());
}
public byte[] encode(int offset, int count) throws UnsupportedEncodingException {
StringWriter sw = new StringWriter();
- XmlSerializer xmlMsgElement = Xml.newSerializer();
+ XmlSerializer xmlMsgElement = new FastXmlSerializer();
int i, stopIndex;
- if(offset > subFolders.size())
+ // We need index based access to the subFolders
+ BluetoothMapFolderElement[] folders = mSubFolders.values().toArray(new BluetoothMapFolderElement[mSubFolders.size()]);
+
+ if(offset > mSubFolders.size())
throw new IllegalArgumentException("FolderListingEncode: offset > subFolders.size()");
stopIndex = offset + count;
- if(stopIndex > subFolders.size())
- stopIndex = subFolders.size();
+ if(stopIndex > mSubFolders.size())
+ stopIndex = mSubFolders.size();
try {
xmlMsgElement.setOutput(sw);
- xmlMsgElement.startDocument(null, null);
- xmlMsgElement.text("\n");
- xmlMsgElement.startTag("", "folder-listing");
- xmlMsgElement.attribute("", "version", "1.0");
+ xmlMsgElement.startDocument("UTF-8", true);
+ xmlMsgElement.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+ xmlMsgElement.startTag(null, "folder-listing");
+ xmlMsgElement.attribute(null, "version", "1.0");
for(i = offset; i<stopIndex; i++)
{
- xmlMsgElement.startTag("", "folder");
- xmlMsgElement.attribute("", "name", subFolders.get(i).getName());
- xmlMsgElement.endTag("", "folder");
+ xmlMsgElement.startTag(null, "folder");
+ xmlMsgElement.attribute(null, "name", folders[i].getName());
+ xmlMsgElement.endTag(null, "folder");
}
- xmlMsgElement.endTag("", "folder-listing");
+ xmlMsgElement.endTag(null, "folder-listing");
xmlMsgElement.endDocument();
} catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ if(D) Log.w(TAG,e);
+ throw new IllegalArgumentException("error encoding folderElement");
} catch (IllegalStateException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ if(D) Log.w(TAG,e);
+ throw new IllegalArgumentException("error encoding folderElement");
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ if(D) Log.w(TAG,e);
+ throw new IllegalArgumentException("error encoding folderElement");
}
return sw.toString().getBytes("UTF-8");
}