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 android.net.Uri;
36 import android.provider.BaseColumns;
37 
38 /** Exposes constants used to interact with the Bluetooth Share manager's content provider. */
39 public final class BluetoothShare implements BaseColumns {
BluetoothShare()40     private BluetoothShare() {}
41 
42     /** The permission to access the Bluetooth Share Manager */
43     public static final String PERMISSION_ACCESS = "android.permission.ACCESS_BLUETOOTH_SHARE";
44 
45     /** The content:// URI for the data table in the provider */
46     public static final Uri CONTENT_URI = Uri.parse("content://com.android.bluetooth.opp/btopp");
47 
48     /**
49      * Broadcast Action: this is sent by the Bluetooth Share component to transfer complete. The
50      * request detail could be retrieved by app * as _ID is specified in the intent's data.
51      */
52     public static final String TRANSFER_COMPLETED_ACTION =
53             "android.btopp.intent.action.TRANSFER_COMPLETE";
54 
55     /**
56      * This is sent by the Bluetooth Share component to indicate there is an incoming file request
57      * timeout and need update UI.
58      */
59     public static final String USER_CONFIRMATION_TIMEOUT_ACTION =
60             "android.btopp.intent.action.USER_CONFIRMATION_TIMEOUT";
61 
62     /**
63      * The name of the column containing the URI of the file being sent/received.
64      *
65      * <p>Type: TEXT
66      *
67      * <p>Owner can Init/Read
68      */
69     public static final String URI = "uri";
70 
71     /**
72      * The name of the column containing the filename that the incoming file request recommends.
73      * When possible, the Bluetooth Share manager will attempt to use this filename, or a variation,
74      * as the actual name for the file.
75      *
76      * <p>Type: TEXT
77      *
78      * <p>Owner can Init/Read
79      */
80     public static final String FILENAME_HINT = "hint";
81 
82     /**
83      * The name of the column containing the filename where the shared file was actually stored.
84      *
85      * <p>Type: TEXT
86      *
87      * <p>Owner can Read
88      */
89     public static final String _DATA = "_data";
90 
91     /**
92      * The name of the column containing the MIME type of the shared file.
93      *
94      * <p>Type: TEXT
95      *
96      * <p>Owner can Init/Read
97      */
98     public static final String MIMETYPE = "mimetype";
99 
100     /**
101      * The name of the column containing the direction (Inbound/Outbound) of the transfer. See the
102      * DIRECTION_* constants for a list of legal values.
103      *
104      * <p>Type: INTEGER
105      *
106      * <p>Owner can Init/Read
107      */
108     public static final String DIRECTION = "direction";
109 
110     /**
111      * The name of the column containing Bluetooth Device Address that the transfer is associated
112      * with.
113      *
114      * <p>Type: TEXT
115      *
116      * <p>Owner can Init/Read
117      */
118     public static final String DESTINATION = "destination";
119 
120     /**
121      * The name of the column containing the flags that controls whether the transfer is displayed
122      * by the UI. See the VISIBILITY_* constants for a list of legal values.
123      *
124      * <p>Type: INTEGER
125      *
126      * <p>Owner can Init/Read/Write
127      */
128     public static final String VISIBILITY = "visibility";
129 
130     /**
131      * The name of the column containing the current user confirmation state of the transfer.
132      * Applications can write to this to confirm the transfer. the USER_CONFIRMATION_* constants for
133      * a list of legal values.
134      *
135      * <p>Type: INTEGER
136      *
137      * <p>Owner can Init/Read/Write
138      */
139     public static final String USER_CONFIRMATION = "confirm";
140 
141     /**
142      * The name of the column containing the current status of the transfer. Applications can read
143      * this to follow the progress of each download. See the STATUS_* constants for a list of legal
144      * values.
145      *
146      * <p>Type: INTEGER
147      *
148      * <p>Owner can Read
149      */
150     public static final String STATUS = "status";
151 
152     /**
153      * The name of the column containing the total size of the file being transferred.
154      *
155      * <p>Type: INTEGER
156      *
157      * <p>Owner can Read
158      */
159     public static final String TOTAL_BYTES = "total_bytes";
160 
161     /**
162      * The name of the column containing the size of the part of the file that has been transferred
163      * so far.
164      *
165      * <p>Type: INTEGER
166      *
167      * <p>Owner can Read
168      */
169     public static final String CURRENT_BYTES = "current_bytes";
170 
171     /**
172      * The name of the column containing the timestamp when the transfer is initialized.
173      *
174      * <p>Type: INTEGER
175      *
176      * <p>Owner can Read
177      */
178     public static final String TIMESTAMP = "timestamp";
179 
180     /** This transfer is outbound, e.g. share file to other device. */
181     public static final int DIRECTION_OUTBOUND = 0;
182 
183     /** This transfer is inbound, e.g. receive file from other device. */
184     public static final int DIRECTION_INBOUND = 1;
185 
186     /** This transfer is waiting for user confirmation. */
187     public static final int USER_CONFIRMATION_PENDING = 0;
188 
189     /** This transfer is confirmed by user. */
190     public static final int USER_CONFIRMATION_CONFIRMED = 1;
191 
192     /** This transfer is auto-confirmed per previous user confirmation. */
193     public static final int USER_CONFIRMATION_AUTO_CONFIRMED = 2;
194 
195     /** This transfer is denied by user. */
196     public static final int USER_CONFIRMATION_DENIED = 3;
197 
198     /** This transfer is timeout before user action. */
199     public static final int USER_CONFIRMATION_TIMEOUT = 4;
200 
201     /**
202      * This transfer was initiated by a connection handover (for example WIFI, NFC) and has been
203      * auto-confirmed.
204      */
205     public static final int USER_CONFIRMATION_HANDOVER_CONFIRMED = 5;
206 
207     /**
208      * This transfer is visible and shows in the notifications while in progress and after
209      * completion.
210      */
211     public static final int VISIBILITY_VISIBLE = 0;
212 
213     /** This transfer doesn't show in the notifications. */
214     public static final int VISIBILITY_HIDDEN = 1;
215 
216     /** Returns whether the status is informational (i.e. 1xx). */
isStatusInformational(int status)217     public static boolean isStatusInformational(int status) {
218         return (status >= 100 && status < 200);
219     }
220 
221     /**
222      * Returns whether the transfer is suspended. (i.e. whether the transfer won't complete without
223      * some action from outside the transfer manager).
224      */
isStatusSuspended(int status)225     public static boolean isStatusSuspended(int status) {
226         return (status == STATUS_PENDING);
227     }
228 
229     /** Returns whether the status is a success (i.e. 2xx). */
isStatusSuccess(int status)230     public static boolean isStatusSuccess(int status) {
231         return (status >= 200 && status < 300);
232     }
233 
234     /** Returns whether the status is an error (i.e. 4xx or 5xx). */
isStatusError(int status)235     public static boolean isStatusError(int status) {
236         return (status >= 400 && status < 600);
237     }
238 
239     /** Returns whether the status is a client error (i.e. 4xx). */
isStatusClientError(int status)240     public static boolean isStatusClientError(int status) {
241         return (status >= 400 && status < 500);
242     }
243 
244     /** Returns whether the status is a server error (i.e. 5xx). */
isStatusServerError(int status)245     public static boolean isStatusServerError(int status) {
246         return (status >= 500 && status < 600);
247     }
248 
249     /** Returns whether the transfer has completed (either with success or error). */
isStatusCompleted(int status)250     public static boolean isStatusCompleted(int status) {
251         return (status >= 200 && status < 300) || (status >= 400 && status < 600);
252     }
253 
254     /** This transfer hasn't stated yet */
255     public static final int STATUS_PENDING = 190;
256 
257     /** This transfer has started */
258     public static final int STATUS_RUNNING = 192;
259 
260     /**
261      * This transfer has successfully completed. Warning: there might be other status values that
262      * indicate success in the future. Use isSucccess() to capture the entire category.
263      */
264     public static final int STATUS_SUCCESS = 200;
265 
266     /**
267      * This request couldn't be parsed. This is also used when processing requests with
268      * unknown/unsupported URI schemes.
269      */
270     public static final int STATUS_BAD_REQUEST = 400;
271 
272     /** This transfer is forbidden by target device. */
273     public static final int STATUS_FORBIDDEN = 403;
274 
275     /** This transfer can't be performed because the content cannot be handled. */
276     public static final int STATUS_NOT_ACCEPTABLE = 406;
277 
278     /**
279      * This transfer cannot be performed because the length cannot be determined accurately. This is
280      * the code for the HTTP error "Length Required", which is typically used when making requests
281      * that require a content length but don't have one, and it is also used in the client when a
282      * response is received whose length cannot be determined accurately (therefore making it
283      * impossible to know when a transfer completes).
284      */
285     public static final int STATUS_LENGTH_REQUIRED = 411;
286 
287     /**
288      * This transfer was interrupted and cannot be resumed. This is the code for the OBEX error
289      * "Precondition Failed", and it is also used in situations where the client doesn't have an
290      * ETag at all.
291      */
292     public static final int STATUS_PRECONDITION_FAILED = 412;
293 
294     /** This transfer was canceled */
295     public static final int STATUS_CANCELED = 490;
296 
297     /**
298      * This transfer has completed with an error. Warning: there will be other status values that
299      * indicate errors in the future. Use isStatusError() to capture the entire category.
300      */
301     public static final int STATUS_UNKNOWN_ERROR = 491;
302 
303     /**
304      * This transfer couldn't be completed because of a storage issue. Typically, that's because the
305      * file system is missing or full.
306      */
307     public static final int STATUS_FILE_ERROR = 492;
308 
309     /** This transfer couldn't be completed because of no sdcard. */
310     public static final int STATUS_ERROR_NO_SDCARD = 493;
311 
312     /** This transfer couldn't be completed because of sdcard full. */
313     public static final int STATUS_ERROR_SDCARD_FULL = 494;
314 
315     /** This transfer couldn't be completed because of an unspecified un-handled OBEX code. */
316     public static final int STATUS_UNHANDLED_OBEX_CODE = 495;
317 
318     /**
319      * This transfer couldn't be completed because of an error receiving or processing data at the
320      * OBEX level.
321      */
322     public static final int STATUS_OBEX_DATA_ERROR = 496;
323 
324     /** This transfer couldn't be completed because of an error when establishing connection. */
325     public static final int STATUS_CONNECTION_ERROR = 497;
326 }
327