Constants.java revision 888485a3f5fe991116c5536bb6d6903d47b63a70
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 33package com.android.bluetooth.opp; 34 35import java.io.IOException; 36import java.util.regex.Pattern; 37 38import javax.obex.HeaderSet; 39 40import android.content.ContentValues; 41import android.content.Context; 42import android.content.Intent; 43import android.net.Uri; 44import android.util.Config; 45import android.util.Log; 46 47/** 48 * Bluetooth OPP internal constants definition 49 */ 50public class Constants { 51 /** Tag used for debugging/logging */ 52 public static final String TAG = "BluetoothOpp"; 53 54 /** 55 * The intent that gets sent when the service must wake up for a retry Note: 56 * only retry Outbound transfer 57 */ 58 public static final String ACTION_RETRY = "android.btopp.intent.action.RETRY"; 59 60 /** the intent that gets sent when clicking a successful transfer */ 61 public static final String ACTION_OPEN = "android.btopp.intent.action.OPEN"; 62 63 /** the intent that gets sent when clicking an incomplete/failed transfer */ 64 public static final String ACTION_LIST = "android.btopp.intent.action.LIST"; 65 66 /** 67 * the intent that gets sent when deleting the notification of a completed 68 * transfer 69 */ 70 public static final String ACTION_HIDE = "android.btopp.intent.action.HIDE"; 71 72 /** 73 * the intent that gets sent when clicking a incoming file confirm 74 * notification 75 */ 76 public static final String ACTION_INCOMING_FILE_CONFIRM = "android.btopp.intent.action.CONFIRM"; 77 78 public static final String THIS_PACKAGE_NAME = "com.android.bluetooth"; 79 80 /** 81 * The column that is used to remember whether the media scanner was invoked 82 */ 83 public static final String MEDIA_SCANNED = "scanned"; 84 85 public static final int MEDIA_SCANNED_NOT_SCANNED = 0; 86 87 public static final int MEDIA_SCANNED_SCANNED_OK = 1; 88 89 public static final int MEDIA_SCANNED_SCANNED_FAILED = 2; 90 91 /** 92 * The MIME type(s) of we could share to other device. 93 */ 94 /* 95 * TODO: define correct type list 96 */ 97 public static final String[] ACCEPTABLE_SHARE_OUTBOUND_TYPES = new String[] { 98 "image/*", 99 }; 100 101 /** 102 * The MIME type(s) of we could not share to other device. TODO: define 103 * correct type list 104 */ 105 public static final String[] UNACCEPTABLE_SHARE_OUTBOUND_TYPES = new String[] { 106 "virus/*", 107 }; 108 109 /** 110 * The MIME type(s) of we could accept from other device. TODO: define 111 * correct type list 112 */ 113 public static final String[] ACCEPTABLE_SHARE_INBOUND_TYPES = new String[] { 114 "image/*", 115 }; 116 117 /** 118 * The MIME type(s) of we could not accept from other device. TODO: define 119 * correct type list 120 */ 121 public static final String[] UNACCEPTABLE_SHARE_INBOUND_TYPES = new String[] { 122 "text/x-vcalendar", 123 "text/x-vcard", 124 }; 125 126 /** Where we store Bluetooth received files on the external storage */ 127 public static final String DEFAULT_STORE_SUBDIR = "/bluetooth"; 128 129 /** 130 * Debug level logging 131 * Enable by setting system property log.tag.BluetoothOpp=DEBUG 132 * STOPSHIP: set to false 133 */ 134 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); 135 136 /** 137 * Verbose level logging 138 * Enable by setting system property log.tag.BluetoothOpp=VERBOSE 139 * This also enables debug level logging 140 * STOPSHIP: set to false 141 */ 142 public static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE); 143 144 /** use TCP socket instead of Rfcomm Socket to develop */ 145 public static final boolean USE_TCP_DEBUG = false; 146 147 /** use simple TCP server started from TestActivity */ 148 public static final boolean USE_TCP_SIMPLE_SERVER = false; 149 150 /** Test TCP socket port */ 151 public static final int TCP_DEBUG_PORT = 6500; 152 153 /** use emulator to debug */ 154 public static final boolean USE_EMULATOR_DEBUG = false; 155 156 public static final int MAX_RECORDS_IN_DATABASE = 20; 157 158 public static final int BATCH_STATUS_PENDING = 0; 159 160 public static final int BATCH_STATUS_RUNNING = 1; 161 162 public static final int BATCH_STATUS_FINISHED = 2; 163 164 public static final int BATCH_STATUS_FAILED = 3; 165 166 public static final String BLUETOOTHOPP_NAME_PREFERENCE = "btopp_names"; 167 168 public static final String BLUETOOTHOPP_CHANNEL_PREFERENCE = "btopp_channels"; 169 170 public static String filename_SEQUENCE_SEPARATOR = "-"; 171 172 public static void updateShareStatus(Context context, int id, int status) { 173 Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + id); 174 ContentValues updateValues = new ContentValues(); 175 updateValues.put(BluetoothShare.STATUS, status); 176 context.getContentResolver().update(contentUri, updateValues, null, null); 177 Constants.sendIntentIfCompleted(context, contentUri, status); 178 } 179 180 /* 181 * This function should be called whenever transfer status change to 182 * completed. 183 */ 184 public static void sendIntentIfCompleted(Context context, Uri contentUri, int status) { 185 if (BluetoothShare.isStatusCompleted(status)) { 186 Intent intent = new Intent(BluetoothShare.TRANSFER_COMPLETED_ACTION); 187 intent.setClassName(THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName()); 188 intent.setData(contentUri); 189 context.sendBroadcast(intent); 190 } 191 } 192 193 public static boolean mimeTypeMatches(String mimeType, String[] matchAgainst) { 194 for (String matchType : matchAgainst) { 195 if (mimeTypeMatches(mimeType, matchType)) { 196 return true; 197 } 198 } 199 return false; 200 } 201 202 public static boolean mimeTypeMatches(String mimeType, String matchAgainst) { 203 Pattern p = Pattern.compile(matchAgainst.replaceAll("\\*", "\\.\\*"), 204 Pattern.CASE_INSENSITIVE); 205 return p.matcher(mimeType).matches(); 206 } 207 208 public static void logHeader(HeaderSet hs) { 209 Log.v(TAG, "Dumping HeaderSet " + hs.toString()); 210 try { 211 212 Log.v(TAG, "COUNT : " + hs.getHeader(HeaderSet.COUNT)); 213 Log.v(TAG, "NAME : " + hs.getHeader(HeaderSet.NAME)); 214 Log.v(TAG, "TYPE : " + hs.getHeader(HeaderSet.TYPE)); 215 Log.v(TAG, "LENGTH : " + hs.getHeader(HeaderSet.LENGTH)); 216 Log.v(TAG, "TIME_ISO_8601 : " + hs.getHeader(HeaderSet.TIME_ISO_8601)); 217 Log.v(TAG, "TIME_4_BYTE : " + hs.getHeader(HeaderSet.TIME_4_BYTE)); 218 Log.v(TAG, "DESCRIPTION : " + hs.getHeader(HeaderSet.DESCRIPTION)); 219 Log.v(TAG, "TARGET : " + hs.getHeader(HeaderSet.TARGET)); 220 Log.v(TAG, "HTTP : " + hs.getHeader(HeaderSet.HTTP)); 221 Log.v(TAG, "WHO : " + hs.getHeader(HeaderSet.WHO)); 222 Log.v(TAG, "OBJECT_CLASS : " + hs.getHeader(HeaderSet.OBJECT_CLASS)); 223 Log.v(TAG, "APPLICATION_PARAMETER : " + hs.getHeader(HeaderSet.APPLICATION_PARAMETER)); 224 } catch (IOException e) { 225 Log.e(TAG, "dump HeaderSet error " + e); 226 } 227 } 228} 229