Loading android/app/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiver.java +2 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,8 @@ public class BluetoothOppHandoverReceiver extends BroadcastReceiver { Thread t = new Thread(new Runnable() { public void run() { BluetoothOppManager.getInstance(finalContext) .saveSendingFileInfo(mimeType, finalUris, true); .saveSendingFileInfo(mimeType, finalUris, true /* isHandover */, true /* fromExternal */); BluetoothOppManager.getInstance(finalContext).startTransfer(device); } }); Loading android/app/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java +9 −5 Original line number Diff line number Diff line Loading @@ -110,7 +110,8 @@ public class BluetoothOppLauncherActivity extends Activity { // session to DB. Thread t = new Thread(new Runnable() { public void run() { sendFileInfo(type, stream.toString(), false); sendFileInfo(type, stream.toString(), false /* isHandover */, true /* fromExternal */); } }); t.start(); Loading @@ -122,7 +123,8 @@ public class BluetoothOppLauncherActivity extends Activity { if (fileUri != null) { Thread t = new Thread(new Runnable() { public void run() { sendFileInfo(type, fileUri.toString(), false); sendFileInfo(type, fileUri.toString(), false /* isHandover */, false /* fromExternal */); } }); t.start(); Loading @@ -147,7 +149,8 @@ public class BluetoothOppLauncherActivity extends Activity { public void run() { try { BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this) .saveSendingFileInfo(mimeType, uris, false); .saveSendingFileInfo(mimeType, uris, false /* isHandover */, true /* fromExternal */); //Done getting file info..Launch device picker //and finish this activity launchDevicePicker(); Loading Loading @@ -376,10 +379,11 @@ public class BluetoothOppLauncherActivity extends Activity { return text; } private void sendFileInfo(String mimeType, String uriString, boolean isHandover) { private void sendFileInfo( String mimeType, String uriString, boolean isHandover, boolean fromExternal) { BluetoothOppManager manager = BluetoothOppManager.getInstance(getApplicationContext()); try { manager.saveSendingFileInfo(mimeType, uriString, isHandover); manager.saveSendingFileInfo(mimeType, uriString, isHandover, fromExternal); launchDevicePicker(); finish(); } catch (IllegalArgumentException exception) { Loading android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java +10 −8 Original line number Diff line number Diff line Loading @@ -246,30 +246,32 @@ public class BluetoothOppManager { if (V) Log.v(TAG, "Application data stored to SharedPreference! "); } public void saveSendingFileInfo(String mimeType, String uriString, boolean isHandover) throws IllegalArgumentException { public void saveSendingFileInfo(String mimeType, String uriString, boolean isHandover, boolean fromExternal) throws IllegalArgumentException { synchronized (BluetoothOppManager.this) { mMultipleFlag = false; mMimeTypeOfSendingFile = mimeType; mUriOfSendingFile = uriString; mIsHandoverInitiated = isHandover; Uri uri = Uri.parse(uriString); BluetoothOppUtility.putSendFileInfo(uri, BluetoothOppSendFileInfo.generateFileInfo(mContext, uri, mimeType)); BluetoothOppUtility.putSendFileInfo( uri, BluetoothOppSendFileInfo.generateFileInfo( mContext, uri, mimeType, fromExternal)); storeApplicationData(); } } public void saveSendingFileInfo(String mimeType, ArrayList<Uri> uris, boolean isHandover) throws IllegalArgumentException { public void saveSendingFileInfo(String mimeType, ArrayList<Uri> uris, boolean isHandover, boolean fromExternal) throws IllegalArgumentException { synchronized (BluetoothOppManager.this) { mMultipleFlag = true; mMimeTypeOfSendingFiles = mimeType; mUrisOfSendingFiles = uris; mIsHandoverInitiated = isHandover; for (Uri uri : uris) { BluetoothOppUtility.putSendFileInfo(uri, BluetoothOppSendFileInfo.generateFileInfo(mContext, uri, mimeType)); BluetoothOppUtility.putSendFileInfo( uri, BluetoothOppSendFileInfo.generateFileInfo( mContext, uri, mimeType, fromExternal)); } storeApplicationData(); } Loading android/app/src/com/android/bluetooth/opp/BluetoothOppSendFileInfo.java +13 −2 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.provider.OpenableColumns; import android.util.EventLog; import android.util.Log; import java.io.File; Loading Loading @@ -96,8 +97,8 @@ public class BluetoothOppSendFileInfo { mStatus = status; } public static BluetoothOppSendFileInfo generateFileInfo(Context context, Uri uri, String type) { public static BluetoothOppSendFileInfo generateFileInfo( Context context, Uri uri, String type, boolean fromExternal) { ContentResolver contentResolver = context.getContentResolver(); String scheme = uri.getScheme(); String fileName = null; Loading Loading @@ -139,6 +140,16 @@ public class BluetoothOppSendFileInfo { fileName = uri.getLastPathSegment(); } } else if ("file".equals(scheme)) { if (uri.getPath() == null) { Log.e(TAG, "Invalid URI path: " + uri); return SEND_FILE_INFO_ERROR; } if (fromExternal && !BluetoothOppUtility.isInExternalStorageDir(uri)) { EventLog.writeEvent(0x534e4554, "35310991", -1, uri.getPath()); Log.e(TAG, "File based URI not in Environment.getExternalStorageDirectory() is not allowed."); return SEND_FILE_INFO_ERROR; } fileName = uri.getLastPathSegment(); contentType = type; File f = new File(uri.getPath()); Loading android/app/src/com/android/bluetooth/opp/BluetoothOppUtility.java +38 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import com.google.android.collect.Lists; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.net.Uri; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.content.ActivityNotFoundException; Loading @@ -45,6 +46,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.Cursor; import android.os.Environment; import android.util.Log; import java.io.File; Loading Loading @@ -352,4 +354,40 @@ public class BluetoothOppUtility { } } } /** * Checks if the URI is in Environment.getExternalStorageDirectory() as it * is the only directory that is possibly readable by both the sender and * the Bluetooth process. */ static boolean isInExternalStorageDir(Uri uri) { if (!ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { Log.e(TAG, "Not a file URI: " + uri); return false; } final File file = new File(uri.getCanonicalUri().getPath()); return isSameOrSubDirectory(Environment.getExternalStorageDirectory(), file); } /** * Checks, whether the child directory is the same as, or a sub-directory of the base * directory. Neither base nor child should be null. */ static boolean isSameOrSubDirectory(File base, File child) { try { base = base.getCanonicalFile(); child = child.getCanonicalFile(); File parentFile = child; while (parentFile != null) { if (base.equals(parentFile)) { return true; } parentFile = parentFile.getParentFile(); } return false; } catch (IOException ex) { Log.e(TAG, "Error while accessing file", ex); return false; } } } Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiver.java +2 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,8 @@ public class BluetoothOppHandoverReceiver extends BroadcastReceiver { Thread t = new Thread(new Runnable() { public void run() { BluetoothOppManager.getInstance(finalContext) .saveSendingFileInfo(mimeType, finalUris, true); .saveSendingFileInfo(mimeType, finalUris, true /* isHandover */, true /* fromExternal */); BluetoothOppManager.getInstance(finalContext).startTransfer(device); } }); Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java +9 −5 Original line number Diff line number Diff line Loading @@ -110,7 +110,8 @@ public class BluetoothOppLauncherActivity extends Activity { // session to DB. Thread t = new Thread(new Runnable() { public void run() { sendFileInfo(type, stream.toString(), false); sendFileInfo(type, stream.toString(), false /* isHandover */, true /* fromExternal */); } }); t.start(); Loading @@ -122,7 +123,8 @@ public class BluetoothOppLauncherActivity extends Activity { if (fileUri != null) { Thread t = new Thread(new Runnable() { public void run() { sendFileInfo(type, fileUri.toString(), false); sendFileInfo(type, fileUri.toString(), false /* isHandover */, false /* fromExternal */); } }); t.start(); Loading @@ -147,7 +149,8 @@ public class BluetoothOppLauncherActivity extends Activity { public void run() { try { BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this) .saveSendingFileInfo(mimeType, uris, false); .saveSendingFileInfo(mimeType, uris, false /* isHandover */, true /* fromExternal */); //Done getting file info..Launch device picker //and finish this activity launchDevicePicker(); Loading Loading @@ -376,10 +379,11 @@ public class BluetoothOppLauncherActivity extends Activity { return text; } private void sendFileInfo(String mimeType, String uriString, boolean isHandover) { private void sendFileInfo( String mimeType, String uriString, boolean isHandover, boolean fromExternal) { BluetoothOppManager manager = BluetoothOppManager.getInstance(getApplicationContext()); try { manager.saveSendingFileInfo(mimeType, uriString, isHandover); manager.saveSendingFileInfo(mimeType, uriString, isHandover, fromExternal); launchDevicePicker(); finish(); } catch (IllegalArgumentException exception) { Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java +10 −8 Original line number Diff line number Diff line Loading @@ -246,30 +246,32 @@ public class BluetoothOppManager { if (V) Log.v(TAG, "Application data stored to SharedPreference! "); } public void saveSendingFileInfo(String mimeType, String uriString, boolean isHandover) throws IllegalArgumentException { public void saveSendingFileInfo(String mimeType, String uriString, boolean isHandover, boolean fromExternal) throws IllegalArgumentException { synchronized (BluetoothOppManager.this) { mMultipleFlag = false; mMimeTypeOfSendingFile = mimeType; mUriOfSendingFile = uriString; mIsHandoverInitiated = isHandover; Uri uri = Uri.parse(uriString); BluetoothOppUtility.putSendFileInfo(uri, BluetoothOppSendFileInfo.generateFileInfo(mContext, uri, mimeType)); BluetoothOppUtility.putSendFileInfo( uri, BluetoothOppSendFileInfo.generateFileInfo( mContext, uri, mimeType, fromExternal)); storeApplicationData(); } } public void saveSendingFileInfo(String mimeType, ArrayList<Uri> uris, boolean isHandover) throws IllegalArgumentException { public void saveSendingFileInfo(String mimeType, ArrayList<Uri> uris, boolean isHandover, boolean fromExternal) throws IllegalArgumentException { synchronized (BluetoothOppManager.this) { mMultipleFlag = true; mMimeTypeOfSendingFiles = mimeType; mUrisOfSendingFiles = uris; mIsHandoverInitiated = isHandover; for (Uri uri : uris) { BluetoothOppUtility.putSendFileInfo(uri, BluetoothOppSendFileInfo.generateFileInfo(mContext, uri, mimeType)); BluetoothOppUtility.putSendFileInfo( uri, BluetoothOppSendFileInfo.generateFileInfo( mContext, uri, mimeType, fromExternal)); } storeApplicationData(); } Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppSendFileInfo.java +13 −2 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.provider.OpenableColumns; import android.util.EventLog; import android.util.Log; import java.io.File; Loading Loading @@ -96,8 +97,8 @@ public class BluetoothOppSendFileInfo { mStatus = status; } public static BluetoothOppSendFileInfo generateFileInfo(Context context, Uri uri, String type) { public static BluetoothOppSendFileInfo generateFileInfo( Context context, Uri uri, String type, boolean fromExternal) { ContentResolver contentResolver = context.getContentResolver(); String scheme = uri.getScheme(); String fileName = null; Loading Loading @@ -139,6 +140,16 @@ public class BluetoothOppSendFileInfo { fileName = uri.getLastPathSegment(); } } else if ("file".equals(scheme)) { if (uri.getPath() == null) { Log.e(TAG, "Invalid URI path: " + uri); return SEND_FILE_INFO_ERROR; } if (fromExternal && !BluetoothOppUtility.isInExternalStorageDir(uri)) { EventLog.writeEvent(0x534e4554, "35310991", -1, uri.getPath()); Log.e(TAG, "File based URI not in Environment.getExternalStorageDirectory() is not allowed."); return SEND_FILE_INFO_ERROR; } fileName = uri.getLastPathSegment(); contentType = type; File f = new File(uri.getPath()); Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppUtility.java +38 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import com.google.android.collect.Lists; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.net.Uri; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.content.ActivityNotFoundException; Loading @@ -45,6 +46,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.database.Cursor; import android.os.Environment; import android.util.Log; import java.io.File; Loading Loading @@ -352,4 +354,40 @@ public class BluetoothOppUtility { } } } /** * Checks if the URI is in Environment.getExternalStorageDirectory() as it * is the only directory that is possibly readable by both the sender and * the Bluetooth process. */ static boolean isInExternalStorageDir(Uri uri) { if (!ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { Log.e(TAG, "Not a file URI: " + uri); return false; } final File file = new File(uri.getCanonicalUri().getPath()); return isSameOrSubDirectory(Environment.getExternalStorageDirectory(), file); } /** * Checks, whether the child directory is the same as, or a sub-directory of the base * directory. Neither base nor child should be null. */ static boolean isSameOrSubDirectory(File base, File child) { try { base = base.getCanonicalFile(); child = child.getCanonicalFile(); File parentFile = child; while (parentFile != null) { if (base.equals(parentFile)) { return true; } parentFile = parentFile.getParentFile(); } return false; } catch (IOException ex) { Log.e(TAG, "Error while accessing file", ex); return false; } } }