From 0de2737031fd18aeeadcbc8f46cd0ebcb18ee730 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Fri, 18 May 2012 13:26:01 -0700 Subject: Bluetooth Beam: generate unique filenames. When moving files to beam/, make sure the destination file is unique. Also, give the transfer a little more time to be initiated; OPP can take quite some time to startup, especially with debug logging. Change-Id: I304c297587e3ad2f339438201bb0b53152084af4 --- src/com/android/nfc/handover/HandoverManager.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/com') diff --git a/src/com/android/nfc/handover/HandoverManager.java b/src/com/android/nfc/handover/HandoverManager.java index 9458472..a1458b9 100644 --- a/src/com/android/nfc/handover/HandoverManager.java +++ b/src/com/android/nfc/handover/HandoverManager.java @@ -255,7 +255,7 @@ public class HandoverManager implements BluetoothProfile.ServiceListener, // We need to receive an update within this time period // to still consider this transfer to be "alive" (ie // a reason to keep the handover transport enabled). - static final int ALIVE_CHECK_MS = 10000; + static final int ALIVE_CHECK_MS = 20000; // The amount of time to wait for a new transfer // once the current one completes. @@ -452,7 +452,9 @@ public class HandoverManager implements BluetoothProfile.ServiceListener, String mimeType = btMimeTypes.get(i); File srcFile = new File(uri.getPath()); - File dstFile = new File(beamPath + "/" + uri.getLastPathSegment()); + + File dstFile = generateUniqueDestination(beamPath + "/" + + uri.getLastPathSegment()); if (!srcFile.renameTo(dstFile)) { if (DBG) Log.d(TAG, "Failed to rename from " + srcFile + " to " + dstFile); srcFile.delete(); @@ -548,6 +550,17 @@ public class HandoverManager implements BluetoothProfile.ServiceListener, return pi; } + synchronized File generateUniqueDestination(String baseFileName) { + File dstFile = new File(baseFileName); + int count = 0; + while (dstFile.exists()) { + dstFile = new File(baseFileName + "-" + Integer.toString(count)); + count++; + } + + return dstFile; + } + synchronized File generateMultiplePath(String beamRoot) { // Generate a unique directory with the date String format = "yyyy-MM-dd"; -- cgit v1.1