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