Bug 869259 - Get a mount lock to prevent the sdcard from being shared with the PC, r=echou

This commit is contained in:
Shawn Huang 2013-06-07 15:10:24 +08:00
parent fe9da116c6
commit 114390b281
2 changed files with 30 additions and 2 deletions

View File

@ -27,6 +27,7 @@
#include "nsIInputStream.h"
#include "nsIMIMEService.h"
#include "nsIOutputStream.h"
#include "nsIVolumeService.h"
#include "nsNetUtil.h"
#define TARGET_SUBDIR "Download/Bluetooth/"
@ -451,6 +452,15 @@ BluetoothOppManager::AfterOppConnected()
mAbortFlag = false;
mWaitingForConfirmationFlag = true;
AfterFirstPut();
// Get a mount lock to prevent the sdcard from being shared with
// the PC while we're doing a OPP file transfer. After OPP transcation
// were done, the mount lock will be freed.
if (!AcquireSdcardMountLock()) {
// If we fail to get a mount lock, abort this transaction
// Directly sending disconnect-request is better than abort-request
NS_WARNING("BluetoothOPPManager couldn't get a mount lock!");
Disconnect();
}
}
void
@ -483,6 +493,11 @@ BluetoothOppManager::AfterOppDisconnected()
mReadFileThread->Shutdown();
mReadFileThread = nullptr;
}
// Release the Mount lock if file transfer completed
if (mMountLock) {
// The mount lock will be implicitly unlocked
mMountLock = nullptr;
}
}
void
@ -1493,3 +1508,15 @@ BluetoothOppManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
}
}
bool
BluetoothOppManager::AcquireSdcardMountLock()
{
nsCOMPtr<nsIVolumeService> volumeSrv =
do_GetService(NS_VOLUMESERVICE_CONTRACTID);
NS_ENSURE_TRUE(volumeSrv, false);
nsresult rv;
rv = volumeSrv->CreateMountLock(NS_LITERAL_STRING("sdcard"),
getter_AddRefs(mMountLock));
NS_ENSURE_SUCCESS(rv, false);
return true;
}

View File

@ -17,6 +17,7 @@
class nsIOutputStream;
class nsIInputStream;
class nsIVolumeMountLock;
BEGIN_BLUETOOTH_NAMESPACE
@ -111,7 +112,7 @@ private:
void ClearQueue();
void RetrieveSentFileName();
void NotifyAboutFileChange();
bool AcquireSdcardMountLock();
/**
* OBEX session status.
* Set when OBEX session is established.
@ -197,7 +198,7 @@ private:
nsCOMPtr<nsIThread> mReadFileThread;
nsCOMPtr<nsIOutputStream> mOutputStream;
nsCOMPtr<nsIInputStream> mInputStream;
nsCOMPtr<nsIVolumeMountLock> mMountLock;
nsRefPtr<BluetoothReplyRunnable> mRunnable;
nsRefPtr<DeviceStorageFile> mDsFile;