2012-05-25 08:03:07 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "Volume.h"
|
|
|
|
#include "VolumeCommand.h"
|
|
|
|
#include "VolumeManager.h"
|
|
|
|
#include "VolumeManagerLog.h"
|
2012-07-16 20:38:18 +04:00
|
|
|
#include "nsIVolume.h"
|
2012-07-16 20:38:18 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-05-25 08:03:07 +04:00
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
#include <vold/ResponseCode.h>
|
|
|
|
|
2012-05-25 08:03:07 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace system {
|
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
Volume::EventObserverList Volume::mEventObserverList;
|
|
|
|
|
2012-12-15 04:01:34 +04:00
|
|
|
// We have a feature where volumes can be locked when mounted. This
|
|
|
|
// is used to prevent a volume from being shared with the PC while
|
|
|
|
// it is actively being used (say for storing an update image)
|
|
|
|
//
|
|
|
|
// We use WakeLocks (a poor choice of name, but it does what we want)
|
|
|
|
// from the PowerManagerService to determine when we're locked.
|
|
|
|
// In particular we'll create a wakelock called volume-NAME-GENERATION
|
|
|
|
// (where NAME is the volume name, and GENERATION is its generation
|
|
|
|
// number), and if this wakelock is locked, then we'll prevent a volume
|
|
|
|
// from being shared.
|
|
|
|
//
|
|
|
|
// Implementation Details:
|
|
|
|
//
|
|
|
|
// Since the AutoMounter can only control when something gets mounted
|
|
|
|
// and not when it gets unmounted (for example: a user pulls the SDCard)
|
|
|
|
// and because Volume and nsVolume data structures are maintained on
|
|
|
|
// separate threads, we have the potential for some race conditions.
|
|
|
|
// We eliminate the race conditions by introducing the concept of a
|
|
|
|
// generation number. Every time a volume transitions to the Mounted
|
|
|
|
// state, it gets assigned a new generation number. Whenever the state
|
|
|
|
// of a Volume changes, we send the updated state and current generation
|
|
|
|
// number to the main thread where it gets updated in the nsVolume.
|
|
|
|
//
|
|
|
|
// Since WakeLocks can only be queried from the main-thread, the
|
|
|
|
// nsVolumeService looks for WakeLock status changes, and forwards
|
|
|
|
// the results to the IOThread.
|
|
|
|
//
|
|
|
|
// If the Volume (IOThread) recieves a volume update where the generation
|
|
|
|
// number mismatches, then the update is simply ignored.
|
|
|
|
//
|
|
|
|
// When a Volume (IOThread) initially becomes mounted, we assume it to
|
|
|
|
// be locked until we get our first update from nsVolume (MainThread).
|
|
|
|
static int32_t sMountGeneration = 0;
|
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
// We don't get media inserted/removed events at startup. So we
|
|
|
|
// assume it's present, and we'll be told that it's missing.
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::Volume(const nsCSubstring& aName)
|
2012-07-16 20:38:18 +04:00
|
|
|
: mMediaPresent(true),
|
2012-07-16 20:38:18 +04:00
|
|
|
mState(nsIVolume::STATE_INIT),
|
2012-12-15 04:01:34 +04:00
|
|
|
mName(aName),
|
|
|
|
mMountGeneration(-1),
|
2013-05-14 04:53:23 +04:00
|
|
|
mMountLocked(true), // Needs to agree with nsVolume::nsVolume
|
|
|
|
mSharingEnabled(false),
|
2013-08-23 03:12:25 +04:00
|
|
|
mCanBeShared(true),
|
2013-09-06 10:11:58 +04:00
|
|
|
mIsSharing(false),
|
|
|
|
mFormatRequested(false),
|
2014-03-04 15:24:19 +04:00
|
|
|
mMountRequested(false),
|
|
|
|
mUnmountRequested(false),
|
2013-09-06 10:11:58 +04:00
|
|
|
mIsFormatting(false)
|
2012-05-25 08:03:07 +04:00
|
|
|
{
|
|
|
|
DBG("Volume %s: created", NameStr());
|
|
|
|
}
|
|
|
|
|
2013-08-23 03:12:25 +04:00
|
|
|
void
|
|
|
|
Volume::SetIsSharing(bool aIsSharing)
|
|
|
|
{
|
2013-10-19 07:21:52 +04:00
|
|
|
if (aIsSharing == mIsSharing) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-23 03:12:25 +04:00
|
|
|
mIsSharing = aIsSharing;
|
2013-10-19 07:21:52 +04:00
|
|
|
LOG("Volume %s: IsSharing set to %d state %s",
|
|
|
|
NameStr(), (int)mIsSharing, StateStr(mState));
|
|
|
|
if (mIsSharing) {
|
|
|
|
mEventObserverList.Broadcast(this);
|
|
|
|
}
|
2013-08-23 03:12:25 +04:00
|
|
|
}
|
|
|
|
|
2013-09-06 10:11:58 +04:00
|
|
|
void
|
|
|
|
Volume::SetIsFormatting(bool aIsFormatting)
|
|
|
|
{
|
|
|
|
if (aIsFormatting == mIsFormatting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mIsFormatting = aIsFormatting;
|
|
|
|
LOG("Volume %s: IsFormatting set to %d state %s",
|
|
|
|
NameStr(), (int)mIsFormatting, StateStr(mState));
|
|
|
|
if (mIsFormatting) {
|
|
|
|
mEventObserverList.Broadcast(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
void
|
|
|
|
Volume::SetMediaPresent(bool aMediaPresent)
|
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
// mMediaPresent is slightly redunant to the state, however
|
|
|
|
// when media is removed (while Idle), we get the following:
|
|
|
|
// 631 Volume sdcard /mnt/sdcard disk removed (179:0)
|
|
|
|
// 605 Volume sdcard /mnt/sdcard state changed from 1 (Idle-Unmounted) to 0 (No-Media)
|
|
|
|
//
|
|
|
|
// And on media insertion, we get:
|
|
|
|
// 630 Volume sdcard /mnt/sdcard disk inserted (179:0)
|
|
|
|
// 605 Volume sdcard /mnt/sdcard state changed from 0 (No-Media) to 2 (Pending)
|
|
|
|
// 605 Volume sdcard /mnt/sdcard state changed from 2 (Pending) to 1 (Idle-Unmounted)
|
|
|
|
//
|
|
|
|
// On media removal while the media is mounted:
|
|
|
|
// 632 Volume sdcard /mnt/sdcard bad removal (179:1)
|
|
|
|
// 605 Volume sdcard /mnt/sdcard state changed from 4 (Mounted) to 5 (Unmounting)
|
|
|
|
// 605 Volume sdcard /mnt/sdcard state changed from 5 (Unmounting) to 1 (Idle-Unmounted)
|
|
|
|
// 631 Volume sdcard /mnt/sdcard disk removed (179:0)
|
|
|
|
// 605 Volume sdcard /mnt/sdcard state changed from 1 (Idle-Unmounted) to 0 (No-Media)
|
|
|
|
//
|
|
|
|
// When sharing with a PC, it goes Mounted -> Idle -> Shared
|
|
|
|
// When unsharing with a PC, it goes Shared -> Idle -> Mounted
|
|
|
|
//
|
|
|
|
// The AutoMounter needs to know whether the media is present or not when
|
|
|
|
// processing the Idle state.
|
|
|
|
|
2013-01-05 04:19:00 +04:00
|
|
|
if (mMediaPresent == aMediaPresent) {
|
|
|
|
return;
|
2012-07-16 20:38:18 +04:00
|
|
|
}
|
2013-01-05 04:19:00 +04:00
|
|
|
|
|
|
|
LOG("Volume: %s media %s", NameStr(), aMediaPresent ? "inserted" : "removed");
|
|
|
|
mMediaPresent = aMediaPresent;
|
|
|
|
mEventObserverList.Broadcast(this);
|
2012-07-16 20:38:18 +04:00
|
|
|
}
|
|
|
|
|
2013-05-14 04:53:23 +04:00
|
|
|
void
|
|
|
|
Volume::SetSharingEnabled(bool aSharingEnabled)
|
|
|
|
{
|
|
|
|
mSharingEnabled = aSharingEnabled;
|
|
|
|
|
|
|
|
LOG("SetSharingMode for volume %s to %d canBeShared = %d",
|
|
|
|
NameStr(), (int)mSharingEnabled, (int)mCanBeShared);
|
|
|
|
}
|
|
|
|
|
2013-09-06 10:11:58 +04:00
|
|
|
void
|
|
|
|
Volume::SetFormatRequested(bool aFormatRequested)
|
|
|
|
{
|
|
|
|
mFormatRequested = aFormatRequested;
|
|
|
|
|
|
|
|
LOG("SetFormatRequested for volume %s to %d CanBeFormatted = %d",
|
|
|
|
NameStr(), (int)mFormatRequested, (int)CanBeFormatted());
|
|
|
|
}
|
|
|
|
|
2014-03-04 15:24:19 +04:00
|
|
|
void
|
|
|
|
Volume::SetMountRequested(bool aMountRequested)
|
|
|
|
{
|
|
|
|
mMountRequested = aMountRequested;
|
|
|
|
|
|
|
|
LOG("SetMountRequested for volume %s to %d CanBeMounted = %d",
|
|
|
|
NameStr(), (int)mMountRequested, (int)CanBeMounted());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Volume::SetUnmountRequested(bool aUnmountRequested)
|
|
|
|
{
|
|
|
|
mUnmountRequested = aUnmountRequested;
|
|
|
|
|
|
|
|
LOG("SetUnmountRequested for volume %s to %d CanBeMounted = %d",
|
|
|
|
NameStr(), (int)mUnmountRequested, (int)CanBeMounted());
|
|
|
|
}
|
|
|
|
|
2012-05-25 08:03:07 +04:00
|
|
|
void
|
|
|
|
Volume::SetState(Volume::STATE aNewState)
|
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
2012-07-16 20:38:18 +04:00
|
|
|
if (aNewState == mState) {
|
|
|
|
return;
|
2012-05-25 08:03:07 +04:00
|
|
|
}
|
2012-08-09 02:44:59 +04:00
|
|
|
if (aNewState == nsIVolume::STATE_MOUNTED) {
|
2012-12-15 04:01:34 +04:00
|
|
|
mMountGeneration = ++sMountGeneration;
|
|
|
|
LOG("Volume %s: changing state from %s to %s @ '%s' (%d observers) "
|
|
|
|
"mountGeneration = %d, locked = %d",
|
2012-08-09 02:44:59 +04:00
|
|
|
NameStr(), StateStr(mState),
|
2012-12-15 04:01:34 +04:00
|
|
|
StateStr(aNewState), mMountPoint.get(), mEventObserverList.Length(),
|
|
|
|
mMountGeneration, (int)mMountLocked);
|
2012-08-09 02:44:59 +04:00
|
|
|
} else {
|
|
|
|
LOG("Volume %s: changing state from %s to %s (%d observers)",
|
|
|
|
NameStr(), StateStr(mState),
|
|
|
|
StateStr(aNewState), mEventObserverList.Length());
|
|
|
|
}
|
2012-07-16 20:38:18 +04:00
|
|
|
|
2013-08-23 03:12:25 +04:00
|
|
|
switch (aNewState) {
|
|
|
|
case nsIVolume::STATE_NOMEDIA:
|
|
|
|
// Cover the startup case where we don't get insertion/removal events
|
|
|
|
mMediaPresent = false;
|
|
|
|
mIsSharing = false;
|
2014-03-04 15:24:19 +04:00
|
|
|
mUnmountRequested = false;
|
|
|
|
mMountRequested = false;
|
2013-08-23 03:12:25 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIVolume::STATE_MOUNTED:
|
2014-03-04 15:24:19 +04:00
|
|
|
mMountRequested = false;
|
2013-09-06 10:11:58 +04:00
|
|
|
mIsFormatting = false;
|
|
|
|
mIsSharing = false;
|
|
|
|
break;
|
2013-08-23 03:12:25 +04:00
|
|
|
case nsIVolume::STATE_FORMATTING:
|
2013-09-06 10:11:58 +04:00
|
|
|
mFormatRequested = false;
|
|
|
|
mIsFormatting = true;
|
2013-08-23 03:12:25 +04:00
|
|
|
mIsSharing = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIVolume::STATE_SHARED:
|
|
|
|
case nsIVolume::STATE_SHAREDMNT:
|
|
|
|
// Covers startup cases. Normally, mIsSharing would be set to true
|
|
|
|
// when we issue the command to initiate the sharing process, but
|
|
|
|
// it's conceivable that a volume could already be in a shared state
|
|
|
|
// when b2g starts.
|
|
|
|
mIsSharing = true;
|
|
|
|
break;
|
|
|
|
|
2014-03-04 15:24:19 +04:00
|
|
|
case nsIVolume::STATE_IDLE:
|
|
|
|
break;
|
2013-08-23 03:12:25 +04:00
|
|
|
default:
|
|
|
|
break;
|
2012-07-16 20:38:18 +04:00
|
|
|
}
|
2012-07-16 20:38:18 +04:00
|
|
|
mState = aNewState;
|
|
|
|
mEventObserverList.Broadcast(this);
|
2012-05-25 08:03:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::SetMountPoint(const nsCSubstring& aMountPoint)
|
2012-05-25 08:03:07 +04:00
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
if (mMountPoint.Equals(aMountPoint)) {
|
|
|
|
return;
|
2012-05-25 08:03:07 +04:00
|
|
|
}
|
2012-07-16 20:38:18 +04:00
|
|
|
mMountPoint = aMountPoint;
|
|
|
|
DBG("Volume %s: Setting mountpoint to '%s'", NameStr(), mMountPoint.get());
|
2012-05-25 08:03:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::StartMount(VolumeResponseCallback* aCallback)
|
2012-05-25 08:03:07 +04:00
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-05-25 08:03:07 +04:00
|
|
|
StartCommand(new VolumeActionCommand(this, "mount", "", aCallback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::StartUnmount(VolumeResponseCallback* aCallback)
|
2012-05-25 08:03:07 +04:00
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-05-25 08:03:07 +04:00
|
|
|
StartCommand(new VolumeActionCommand(this, "unmount", "force", aCallback));
|
|
|
|
}
|
|
|
|
|
2013-09-06 10:11:58 +04:00
|
|
|
void
|
|
|
|
Volume::StartFormat(VolumeResponseCallback* aCallback)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
|
|
|
StartCommand(new VolumeActionCommand(this, "format", "", aCallback));
|
|
|
|
}
|
|
|
|
|
2012-05-25 08:03:07 +04:00
|
|
|
void
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::StartShare(VolumeResponseCallback* aCallback)
|
2012-05-25 08:03:07 +04:00
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-05-25 08:03:07 +04:00
|
|
|
StartCommand(new VolumeActionCommand(this, "share", "ums", aCallback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::StartUnshare(VolumeResponseCallback* aCallback)
|
2012-05-25 08:03:07 +04:00
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-05-25 08:03:07 +04:00
|
|
|
StartCommand(new VolumeActionCommand(this, "unshare", "ums", aCallback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::StartCommand(VolumeCommand* aCommand)
|
2012-05-25 08:03:07 +04:00
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-05-25 08:03:07 +04:00
|
|
|
VolumeManager::PostCommand(aCommand);
|
|
|
|
}
|
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
//static
|
2012-07-16 20:38:18 +04:00
|
|
|
void
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::RegisterObserver(Volume::EventObserver* aObserver)
|
2012-07-16 20:38:18 +04:00
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
2012-07-16 20:38:18 +04:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
|
|
|
mEventObserverList.AddObserver(aObserver);
|
2012-07-16 20:38:18 +04:00
|
|
|
// Send an initial event to the observer (for each volume)
|
|
|
|
size_t numVolumes = VolumeManager::NumVolumes();
|
|
|
|
for (size_t volIndex = 0; volIndex < numVolumes; volIndex++) {
|
|
|
|
RefPtr<Volume> vol = VolumeManager::GetVolume(volIndex);
|
|
|
|
aObserver->Notify(vol);
|
|
|
|
}
|
2012-07-16 20:38:18 +04:00
|
|
|
}
|
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
//static
|
2012-07-16 20:38:18 +04:00
|
|
|
void
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::UnregisterObserver(Volume::EventObserver* aObserver)
|
2012-07-16 20:38:18 +04:00
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
2012-07-16 20:38:18 +04:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
|
|
|
mEventObserverList.RemoveObserver(aObserver);
|
|
|
|
}
|
|
|
|
|
2012-12-15 04:01:34 +04:00
|
|
|
//static
|
|
|
|
void
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::UpdateMountLock(const nsACString& aVolumeName,
|
|
|
|
const int32_t& aMountGeneration,
|
|
|
|
const bool& aMountLocked)
|
2012-12-15 04:01:34 +04:00
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-12-15 04:01:34 +04:00
|
|
|
RefPtr<Volume> vol = VolumeManager::FindVolumeByName(aVolumeName);
|
|
|
|
if (!vol || (vol->mMountGeneration != aMountGeneration)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (vol->mMountLocked != aMountLocked) {
|
|
|
|
vol->mMountLocked = aMountLocked;
|
|
|
|
DBG("Volume::UpdateMountLock for '%s' to %d\n", vol->NameStr(), (int)aMountLocked);
|
|
|
|
mEventObserverList.Broadcast(vol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
void
|
2013-01-07 20:43:02 +04:00
|
|
|
Volume::HandleVoldResponse(int aResponseCode, nsCWhitespaceTokenizer& aTokenizer)
|
2012-07-16 20:38:18 +04:00
|
|
|
{
|
2013-01-07 20:43:02 +04:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-07-16 20:38:18 +04:00
|
|
|
// The volume name will have already been parsed, and the tokenizer will point
|
|
|
|
// to the token after the volume name
|
|
|
|
switch (aResponseCode) {
|
|
|
|
case ResponseCode::VolumeListResult: {
|
|
|
|
// Each line will look something like:
|
|
|
|
//
|
|
|
|
// sdcard /mnt/sdcard 1
|
|
|
|
//
|
|
|
|
nsDependentCSubstring mntPoint(aTokenizer.nextToken());
|
|
|
|
SetMountPoint(mntPoint);
|
2012-07-27 17:59:29 +04:00
|
|
|
nsresult errCode;
|
2012-07-16 20:38:18 +04:00
|
|
|
nsCString state(aTokenizer.nextToken());
|
2013-05-14 04:53:23 +04:00
|
|
|
if (state.EqualsLiteral("X")) {
|
|
|
|
// Special state for creating fake volumes which can't be shared.
|
|
|
|
mCanBeShared = false;
|
|
|
|
SetState(nsIVolume::STATE_MOUNTED);
|
|
|
|
} else {
|
|
|
|
SetState((STATE)state.ToInteger(&errCode));
|
|
|
|
}
|
2012-07-16 20:38:18 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ResponseCode::VolumeStateChange: {
|
|
|
|
// Format of the line looks something like:
|
|
|
|
//
|
|
|
|
// Volume sdcard /mnt/sdcard state changed from 7 (Shared-Unmounted) to 1 (Idle-Unmounted)
|
|
|
|
//
|
|
|
|
// So we parse out the state after the string " to "
|
|
|
|
while (aTokenizer.hasMoreTokens()) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString token(aTokenizer.nextToken());
|
2012-07-16 20:38:18 +04:00
|
|
|
if (token.Equals("to")) {
|
2012-07-27 17:59:29 +04:00
|
|
|
nsresult errCode;
|
2012-07-16 20:38:18 +04:00
|
|
|
token = aTokenizer.nextToken();
|
|
|
|
SetState((STATE)token.ToInteger(&errCode));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ResponseCode::VolumeDiskInserted:
|
|
|
|
SetMediaPresent(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ResponseCode::VolumeDiskRemoved: // fall-thru
|
|
|
|
case ResponseCode::VolumeBadRemoval:
|
|
|
|
SetMediaPresent(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
LOG("Volume: %s unrecognized reponse code (ignored)", NameStr());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 08:03:07 +04:00
|
|
|
} // namespace system
|
|
|
|
} // namespace mozilla
|