summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHamster Tian <th0928@126.com>2014-04-30 16:13:57 +0200
committerSteve Kondik <steve@cyngn.com>2015-03-14 23:47:22 -0700
commit24c74241fc14ade7635b96cf5a6d2a8a4d39cc64 (patch)
tree0ac229e949f0f2517ca12ba8af9bd0977202585d
parent629d23ccda05d5ab8268a10db7ca4ec843f30e7f (diff)
downloadandroid_packages_apps_Bluetooth-24c74241fc14ade7635b96cf5a6d2a8a4d39cc64.tar.gz
android_packages_apps_Bluetooth-24c74241fc14ade7635b96cf5a6d2a8a4d39cc64.tar.bz2
android_packages_apps_Bluetooth-24c74241fc14ade7635b96cf5a6d2a8a4d39cc64.zip
[2/3]Bluetooth: add "Accept all files" option for incoming files
* Renamed some variable. * Re-organized the comment. * Reworded the commit message. This patch will make OBEX server respect the "accept all files" setting. If enabled, it will skip checking MIME type of incoming file, so the file types not present in whitelist can be accepted. Blacklist will be ignored as well. (There's nothing in blacklist in fact) If it's disabled, the check will be performed as usual. Change-Id: I3904a25914d16d040126de43f5e6ed51993494c4
-rw-r--r--src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java93
1 files changed, 57 insertions, 36 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
index 831ea811d..e62e9d567 100644
--- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java
@@ -50,6 +50,7 @@ import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
+import android.provider.Settings;
import android.os.Process;
import android.util.Log;
import android.webkit.MimeTypeMap;
@@ -289,6 +290,8 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
}
boolean isWhitelisted = BluetoothOppManager.getInstance(mContext).
isWhitelisted(destination);
+ boolean isAcceptAllFilesEnabled = Settings.System.getInt(mContext.getContentResolver(),
+ Settings.System.BLUETOOTH_ACCEPT_ALL_FILES, 0) == 1;
try {
boolean pre_reject = false;
@@ -327,47 +330,65 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
obexResponse = ResponseCodes.OBEX_HTTP_BAD_REQUEST;
}
- if (!pre_reject) {
- /* first we look for Mimetype in Android map */
- String extension, type;
- int dotIndex = name.lastIndexOf(".");
- if (dotIndex < 0 && mimeType == null) {
- if (D) Log.w(TAG, "There is no file extension or mime type," +
- "reject the transfer");
- pre_reject = true;
- obexResponse = ResponseCodes.OBEX_HTTP_BAD_REQUEST;
- } else {
- extension = name.substring(dotIndex + 1).toLowerCase();
- MimeTypeMap map = MimeTypeMap.getSingleton();
- type = map.getMimeTypeFromExtension(extension);
- if (V) Log.v(TAG, "Mimetype guessed from extension " + extension + " is " + type);
- if (type != null) {
- mimeType = type;
-
+ if (!isAcceptAllFilesEnabled) {
+ if (!pre_reject) {
+ /* first we look for Mimetype in Android map */
+ String extension, type;
+ int dotIndex = name.lastIndexOf(".");
+ if (dotIndex < 0 && mimeType == null) {
+ if (D)
+ Log.w(TAG, "There is no file extension or mime type," +
+ "reject the transfer. File name:" + name);
+ pre_reject = true;
+ obexResponse = ResponseCodes.OBEX_HTTP_BAD_REQUEST;
} else {
- if (mimeType == null) {
- if (D) Log.w(TAG, "Can't get mimetype, reject the transfer");
- pre_reject = true;
- obexResponse = ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE;
+ extension = name.substring(dotIndex + 1).toLowerCase();
+ MimeTypeMap map = MimeTypeMap.getSingleton();
+ type = map.getMimeTypeFromExtension(extension);
+ if (V)
+ Log.v(TAG, "Mimetype guessed from extension " + extension + " is "
+ + type);
+ if (type != null) {
+ mimeType = type;
+
+ } else {
+ if (mimeType == null) {
+ if (D)
+ Log.w(TAG, "Can't get mimetype, reject the transfer");
+ pre_reject = true;
+ obexResponse = ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE;
+ }
+ }
+ if (mimeType != null) {
+ mimeType = mimeType.toLowerCase();
}
- }
- if (mimeType != null) {
- mimeType = mimeType.toLowerCase();
}
}
- }
- // Reject policy: anything outside the "white list" plus unspecified
- // MIME Types. Also reject everything in the "black list".
- if (!pre_reject
- && (mimeType == null
- || (!isWhitelisted && !Constants.mimeTypeMatches(mimeType,
- Constants.ACCEPTABLE_SHARE_INBOUND_TYPES))
- || Constants.mimeTypeMatches(mimeType,
- Constants.UNACCEPTABLE_SHARE_INBOUND_TYPES))) {
- if (D) Log.w(TAG, "mimeType is null or in unacceptable list, reject the transfer");
- pre_reject = true;
- obexResponse = ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE;
+ // Reject policy: anything outside the "white list" plus
+ // unspecified MIME Types.
+ // Also reject everything in the "black list".
+ if (!pre_reject
+ && (mimeType == null
+ || (!isWhitelisted && !Constants.mimeTypeMatches(mimeType,
+ Constants.ACCEPTABLE_SHARE_INBOUND_TYPES))
+ || Constants.mimeTypeMatches(mimeType,
+ Constants.UNACCEPTABLE_SHARE_INBOUND_TYPES))) {
+ if (D)
+ Log.w(TAG,
+ "mimeType is null or in unacceptable list, reject the transfer. mimeType is "
+ + ((mimeType == null) ? "null" : mimeType));
+ pre_reject = true;
+ obexResponse = ResponseCodes.OBEX_HTTP_UNSUPPORTED_TYPE;
+ }
+ } else {
+ if (D)
+ Log.i(TAG, "isAcceptAllFilesEnabled == true, skipped check of mime type");
+ if (mimeType == null) {
+ mimeType = "*/*";
+ if (D)
+ Log.i(TAG, "mimeType is null. Fixed to */*");
+ }
}
if (pre_reject && obexResponse != ResponseCodes.OBEX_HTTP_OK) {