• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2008-2009, Motorola, Inc.
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * - Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * - Neither the name of the Motorola, Inc. nor the names of its contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 package com.android.bluetooth.opp;
34 
35 import java.io.IOException;
36 import java.util.regex.Pattern;
37 
38 import javax.obex.HeaderSet;
39 
40 import android.content.ContentValues;
41 import android.content.Context;
42 import android.content.Intent;
43 import android.net.Uri;
44 import android.util.Log;
45 
46 /**
47  * Bluetooth OPP internal constants definition
48  */
49 public class Constants {
50     /** Tag used for debugging/logging */
51     public static final String TAG = "BluetoothOpp";
52 
53     /**
54      * The intent that gets sent when the service must wake up for a retry Note:
55      * only retry Outbound transfer
56      */
57     public static final String ACTION_RETRY = "android.btopp.intent.action.RETRY";
58 
59     /** the intent that gets sent when clicking a successful transfer */
60     public static final String ACTION_OPEN = "android.btopp.intent.action.OPEN";
61 
62     /** the intent that gets sent when clicking outbound transfer notification */
63     public static final String ACTION_OPEN_OUTBOUND_TRANSFER = "android.btopp.intent.action.OPEN_OUTBOUND";
64 
65     /** the intent that gets sent when clicking a inbound transfer notification */
66     public static final String ACTION_OPEN_INBOUND_TRANSFER = "android.btopp.intent.action.OPEN_INBOUND";
67 
68     /** the intent that gets sent when clicking an incomplete/failed transfer */
69     public static final String ACTION_LIST = "android.btopp.intent.action.LIST";
70 
71     /**
72      * the intent that gets sent when deleting the incoming file confirmation
73      * notification
74      */
75     public static final String ACTION_HIDE = "android.btopp.intent.action.HIDE";
76 
77     /**
78      * the intent that gets sent when deleting the notifications of outbound and
79      * inbound completed transfer
80      */
81     public static final String ACTION_COMPLETE_HIDE = "android.btopp.intent.action.HIDE_COMPLETE";
82 
83     /**
84      * the intent that gets sent when clicking a incoming file confirm
85      * notification
86      */
87     public static final String ACTION_INCOMING_FILE_CONFIRM = "android.btopp.intent.action.CONFIRM";
88 
89     public static final String THIS_PACKAGE_NAME = "com.android.bluetooth";
90 
91     /**
92      * The column that is used to remember whether the media scanner was invoked
93      */
94     public static final String MEDIA_SCANNED = "scanned";
95 
96     public static final int MEDIA_SCANNED_NOT_SCANNED = 0;
97 
98     public static final int MEDIA_SCANNED_SCANNED_OK = 1;
99 
100     public static final int MEDIA_SCANNED_SCANNED_FAILED = 2;
101 
102     /**
103      * The MIME type(s) of we could share to other device.
104      */
105     /*
106      * TODO: define correct type list
107      */
108     public static final String[] ACCEPTABLE_SHARE_OUTBOUND_TYPES = new String[] {
109         "image/*", "text/x-vcard",
110     };
111 
112     /**
113      * The MIME type(s) of we could not share to other device. TODO: define
114      * correct type list
115      */
116     public static final String[] UNACCEPTABLE_SHARE_OUTBOUND_TYPES = new String[] {
117         "virus/*",
118     };
119 
120     /**
121      * The MIME type(s) of we could accept from other device.
122      * This is in essence a "white list" of acceptable types.
123      * Today, restricted to images, audio, video and certain text types.
124      */
125     public static final String[] ACCEPTABLE_SHARE_INBOUND_TYPES = new String[] {
126         "image/*",
127         "video/*",
128         "audio/*",
129         "text/x-vcard",
130         "text/plain",
131         "text/html",
132         "application/zip",
133         "application/vnd.ms-excel",
134         "application/msword",
135         "application/vnd.ms-powerpoint",
136         "application/pdf",
137     };
138 
139     /**
140      * The MIME type(s) of we could not accept from other device. TODO: define
141      * correct type list
142      */
143     public static final String[] UNACCEPTABLE_SHARE_INBOUND_TYPES = new String[] {
144         "text/x-vcalendar",
145     };
146 
147     /** Where we store Bluetooth received files on the external storage */
148     public static final String DEFAULT_STORE_SUBDIR = "/bluetooth";
149 
150     /**
151      * Debug level logging
152      */
153     public static final boolean DEBUG = false;
154 
155     /**
156      * Verbose level logging
157      */
158     public static final boolean VERBOSE = false;
159 
160     /** use TCP socket instead of Rfcomm Socket to develop */
161     public static final boolean USE_TCP_DEBUG = false;
162 
163     /** use simple TCP server started from TestActivity */
164     public static final boolean USE_TCP_SIMPLE_SERVER = false;
165 
166     /** Test TCP socket port */
167     public static final int TCP_DEBUG_PORT = 6500;
168 
169     /** use emulator to debug */
170     public static final boolean USE_EMULATOR_DEBUG = false;
171 
172     public static final int MAX_RECORDS_IN_DATABASE = 1000;
173 
174     public static final int BATCH_STATUS_PENDING = 0;
175 
176     public static final int BATCH_STATUS_RUNNING = 1;
177 
178     public static final int BATCH_STATUS_FINISHED = 2;
179 
180     public static final int BATCH_STATUS_FAILED = 3;
181 
182     public static final String BLUETOOTHOPP_NAME_PREFERENCE = "btopp_names";
183 
184     public static final String BLUETOOTHOPP_CHANNEL_PREFERENCE = "btopp_channels";
185 
186     public static String filename_SEQUENCE_SEPARATOR = "-";
187 
updateShareStatus(Context context, int id, int status)188     public static void updateShareStatus(Context context, int id, int status) {
189         Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + id);
190         ContentValues updateValues = new ContentValues();
191         updateValues.put(BluetoothShare.STATUS, status);
192         context.getContentResolver().update(contentUri, updateValues, null, null);
193         Constants.sendIntentIfCompleted(context, contentUri, status);
194     }
195 
196     /*
197      * This function should be called whenever transfer status change to
198      * completed.
199      */
sendIntentIfCompleted(Context context, Uri contentUri, int status)200     public static void sendIntentIfCompleted(Context context, Uri contentUri, int status) {
201         if (BluetoothShare.isStatusCompleted(status)) {
202             Intent intent = new Intent(BluetoothShare.TRANSFER_COMPLETED_ACTION);
203             intent.setClassName(THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
204             intent.setData(contentUri);
205             context.sendBroadcast(intent);
206         }
207     }
208 
mimeTypeMatches(String mimeType, String[] matchAgainst)209     public static boolean mimeTypeMatches(String mimeType, String[] matchAgainst) {
210         for (String matchType : matchAgainst) {
211             if (mimeTypeMatches(mimeType, matchType)) {
212                 return true;
213             }
214         }
215         return false;
216     }
217 
mimeTypeMatches(String mimeType, String matchAgainst)218     public static boolean mimeTypeMatches(String mimeType, String matchAgainst) {
219         Pattern p = Pattern.compile(matchAgainst.replaceAll("\\*", "\\.\\*"),
220                 Pattern.CASE_INSENSITIVE);
221         return p.matcher(mimeType).matches();
222     }
223 
logHeader(HeaderSet hs)224     public static void logHeader(HeaderSet hs) {
225         Log.v(TAG, "Dumping HeaderSet " + hs.toString());
226         try {
227 
228             Log.v(TAG, "COUNT : " + hs.getHeader(HeaderSet.COUNT));
229             Log.v(TAG, "NAME : " + hs.getHeader(HeaderSet.NAME));
230             Log.v(TAG, "TYPE : " + hs.getHeader(HeaderSet.TYPE));
231             Log.v(TAG, "LENGTH : " + hs.getHeader(HeaderSet.LENGTH));
232             Log.v(TAG, "TIME_ISO_8601 : " + hs.getHeader(HeaderSet.TIME_ISO_8601));
233             Log.v(TAG, "TIME_4_BYTE : " + hs.getHeader(HeaderSet.TIME_4_BYTE));
234             Log.v(TAG, "DESCRIPTION : " + hs.getHeader(HeaderSet.DESCRIPTION));
235             Log.v(TAG, "TARGET : " + hs.getHeader(HeaderSet.TARGET));
236             Log.v(TAG, "HTTP : " + hs.getHeader(HeaderSet.HTTP));
237             Log.v(TAG, "WHO : " + hs.getHeader(HeaderSet.WHO));
238             Log.v(TAG, "OBJECT_CLASS : " + hs.getHeader(HeaderSet.OBJECT_CLASS));
239             Log.v(TAG, "APPLICATION_PARAMETER : " + hs.getHeader(HeaderSet.APPLICATION_PARAMETER));
240         } catch (IOException e) {
241             Log.e(TAG, "dump HeaderSet error " + e);
242         }
243     }
244 }
245