2012-05-24 21:03:07 -07: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 09:38:18 -07:00
|
|
|
#include "nsIVolume.h"
|
2012-07-16 09:38:18 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-05-24 21:03:07 -07:00
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
#include <vold/ResponseCode.h>
|
|
|
|
|
2012-05-24 21:03:07 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace system {
|
|
|
|
|
2014-11-03 16:26:59 -08:00
|
|
|
#if DEBUG_VOLUME_OBSERVER
|
|
|
|
void
|
|
|
|
VolumeObserverList::Broadcast(Volume* const& aVolume)
|
|
|
|
{
|
|
|
|
uint32_t size = mObservers.Length();
|
|
|
|
for (uint32_t i = 0; i < size; ++i) {
|
|
|
|
LOG("VolumeObserverList::Broadcast to [%u] %p volume '%s'",
|
|
|
|
i, mObservers[i], aVolume->NameStr());
|
|
|
|
mObservers[i]->Notify(aVolume);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
VolumeObserverList Volume::sEventObserverList;
|
2012-07-16 09:38:18 -07:00
|
|
|
|
2012-12-14 16:01:34 -08: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;
|
|
|
|
|
2014-08-19 13:41:35 -07:00
|
|
|
static uint32_t sNextId = 1;
|
|
|
|
|
2012-07-16 09:38:18 -07: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 08:43:02 -08:00
|
|
|
Volume::Volume(const nsCSubstring& aName)
|
2012-07-16 09:38:18 -07:00
|
|
|
: mMediaPresent(true),
|
2012-07-16 09:38:18 -07:00
|
|
|
mState(nsIVolume::STATE_INIT),
|
2012-12-14 16:01:34 -08:00
|
|
|
mName(aName),
|
|
|
|
mMountGeneration(-1),
|
2013-05-13 17:53:23 -07:00
|
|
|
mMountLocked(true), // Needs to agree with nsVolume::nsVolume
|
|
|
|
mSharingEnabled(false),
|
2013-09-05 23:11:58 -07:00
|
|
|
mFormatRequested(false),
|
2014-03-04 03:24:19 -08:00
|
|
|
mMountRequested(false),
|
|
|
|
mUnmountRequested(false),
|
2014-06-27 15:50:00 -07:00
|
|
|
mCanBeShared(true),
|
|
|
|
mIsSharing(false),
|
2014-08-19 13:41:35 -07:00
|
|
|
mIsFormatting(false),
|
2014-09-21 20:42:33 -07:00
|
|
|
mIsUnmounting(false),
|
2014-12-21 18:33:33 -08:00
|
|
|
mIsRemovable(false),
|
|
|
|
mIsHotSwappable(false),
|
2014-08-19 13:41:35 -07:00
|
|
|
mId(sNextId++)
|
2012-05-24 21:03:07 -07:00
|
|
|
{
|
|
|
|
DBG("Volume %s: created", NameStr());
|
|
|
|
}
|
|
|
|
|
2014-11-13 17:42:38 -08:00
|
|
|
void
|
|
|
|
Volume::Dump(const char* aLabel) const
|
|
|
|
{
|
|
|
|
LOG("%s: Volume: %s (%d) is %s and %s @ %s gen %d locked %d",
|
|
|
|
aLabel,
|
|
|
|
NameStr(),
|
|
|
|
Id(),
|
|
|
|
StateStr(),
|
|
|
|
MediaPresent() ? "inserted" : "missing",
|
|
|
|
MountPoint().get(),
|
|
|
|
MountGeneration(),
|
|
|
|
(int)IsMountLocked());
|
|
|
|
LOG("%s: Sharing %s Mounting %s Formating %s Unmounting %s",
|
|
|
|
aLabel,
|
|
|
|
CanBeShared() ? (IsSharingEnabled() ? (IsSharing() ? "en-y" : "en-n")
|
|
|
|
: "dis")
|
|
|
|
: "x",
|
|
|
|
IsMountRequested() ? "req" : "n",
|
|
|
|
IsFormatRequested() ? (IsFormatting() ? "req-y" : "req-n")
|
|
|
|
: (IsFormatting() ? "y" : "n"),
|
|
|
|
IsUnmountRequested() ? (IsUnmounting() ? "req-y" : "req-n")
|
|
|
|
: (IsUnmounting() ? "y" : "n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Volume::SetFakeVolume(const nsACString& aMountPoint)
|
|
|
|
{
|
|
|
|
this->mMountLocked = false;
|
|
|
|
this->mCanBeShared = false;
|
|
|
|
this->mMountPoint = aMountPoint;
|
|
|
|
SetState(nsIVolume::STATE_MOUNTED);
|
|
|
|
}
|
|
|
|
|
2013-08-22 16:12:25 -07:00
|
|
|
void
|
|
|
|
Volume::SetIsSharing(bool aIsSharing)
|
|
|
|
{
|
2013-10-18 20:21:52 -07:00
|
|
|
if (aIsSharing == mIsSharing) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-22 16:12:25 -07:00
|
|
|
mIsSharing = aIsSharing;
|
2013-10-18 20:21:52 -07:00
|
|
|
LOG("Volume %s: IsSharing set to %d state %s",
|
|
|
|
NameStr(), (int)mIsSharing, StateStr(mState));
|
2014-11-03 16:26:59 -08:00
|
|
|
sEventObserverList.Broadcast(this);
|
2013-08-22 16:12:25 -07:00
|
|
|
}
|
|
|
|
|
2013-09-05 23:11:58 -07: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) {
|
2014-11-03 16:26:59 -08:00
|
|
|
sEventObserverList.Broadcast(this);
|
2013-09-05 23:11:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-21 20:42:33 -07:00
|
|
|
void
|
|
|
|
Volume::SetIsUnmounting(bool aIsUnmounting)
|
|
|
|
{
|
|
|
|
if (aIsUnmounting == mIsUnmounting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mIsUnmounting = aIsUnmounting;
|
|
|
|
LOG("Volume %s: IsUnmounting set to %d state %s",
|
|
|
|
NameStr(), (int)mIsUnmounting, StateStr(mState));
|
2014-11-03 16:26:59 -08:00
|
|
|
sEventObserverList.Broadcast(this);
|
2014-09-21 20:42:33 -07:00
|
|
|
}
|
|
|
|
|
2014-12-21 18:33:33 -08:00
|
|
|
void
|
|
|
|
Volume::SetIsRemovable(bool aIsRemovable)
|
|
|
|
{
|
|
|
|
if (aIsRemovable == mIsRemovable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mIsRemovable = aIsRemovable;
|
|
|
|
if (!mIsRemovable) {
|
|
|
|
mIsHotSwappable = false;
|
|
|
|
}
|
|
|
|
LOG("Volume %s: IsRemovable set to %d state %s",
|
|
|
|
NameStr(), (int)mIsRemovable, StateStr(mState));
|
|
|
|
sEventObserverList.Broadcast(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Volume::SetIsHotSwappable(bool aIsHotSwappable)
|
|
|
|
{
|
|
|
|
if (aIsHotSwappable == mIsHotSwappable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mIsHotSwappable = aIsHotSwappable;
|
|
|
|
if (mIsHotSwappable) {
|
|
|
|
mIsRemovable = true;
|
|
|
|
}
|
|
|
|
LOG("Volume %s: IsHotSwappable set to %d state %s",
|
|
|
|
NameStr(), (int)mIsHotSwappable, StateStr(mState));
|
|
|
|
sEventObserverList.Broadcast(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Volume::BoolConfigValue(const nsCString& aConfigValue, bool& aBoolValue)
|
|
|
|
{
|
|
|
|
if (aConfigValue.EqualsLiteral("1") ||
|
|
|
|
aConfigValue.LowerCaseEqualsLiteral("true")) {
|
|
|
|
aBoolValue = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (aConfigValue.EqualsLiteral("0") ||
|
|
|
|
aConfigValue.LowerCaseEqualsLiteral("false")) {
|
|
|
|
aBoolValue = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Volume::SetConfig(const nsCString& aConfigName, const nsCString& aConfigValue)
|
|
|
|
{
|
|
|
|
if (aConfigName.LowerCaseEqualsLiteral("removable")) {
|
|
|
|
bool value = false;
|
|
|
|
if (BoolConfigValue(aConfigValue, value)) {
|
|
|
|
SetIsRemovable(value);
|
|
|
|
} else {
|
|
|
|
ERR("Volume %s: invalid value '%s' for configuration '%s'",
|
|
|
|
NameStr(), aConfigValue.get(), aConfigName.get());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aConfigName.LowerCaseEqualsLiteral("hotswappable")) {
|
|
|
|
bool value = false;
|
|
|
|
if (BoolConfigValue(aConfigValue, value)) {
|
|
|
|
SetIsHotSwappable(value);
|
|
|
|
} else {
|
|
|
|
ERR("Volume %s: invalid value '%s' for configuration '%s'",
|
|
|
|
NameStr(), aConfigValue.get(), aConfigName.get());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ERR("Volume %s: invalid config '%s'", NameStr(), aConfigName.get());
|
|
|
|
}
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
void
|
|
|
|
Volume::SetMediaPresent(bool aMediaPresent)
|
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-01-07 08:43:02 -08:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-07-16 09:38:18 -07: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-04 16:19:00 -08:00
|
|
|
if (mMediaPresent == aMediaPresent) {
|
|
|
|
return;
|
2012-07-16 09:38:18 -07:00
|
|
|
}
|
2013-01-04 16:19:00 -08:00
|
|
|
|
|
|
|
LOG("Volume: %s media %s", NameStr(), aMediaPresent ? "inserted" : "removed");
|
|
|
|
mMediaPresent = aMediaPresent;
|
2014-11-03 16:26:59 -08:00
|
|
|
sEventObserverList.Broadcast(this);
|
2012-07-16 09:38:18 -07:00
|
|
|
}
|
|
|
|
|
2013-05-13 17:53:23 -07:00
|
|
|
void
|
|
|
|
Volume::SetSharingEnabled(bool aSharingEnabled)
|
|
|
|
{
|
|
|
|
mSharingEnabled = aSharingEnabled;
|
|
|
|
|
|
|
|
LOG("SetSharingMode for volume %s to %d canBeShared = %d",
|
|
|
|
NameStr(), (int)mSharingEnabled, (int)mCanBeShared);
|
2014-11-03 16:26:59 -08:00
|
|
|
sEventObserverList.Broadcast(this);
|
2013-05-13 17:53:23 -07:00
|
|
|
}
|
|
|
|
|
2013-09-05 23:11:58 -07: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 03:24:19 -08: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-24 21:03:07 -07:00
|
|
|
void
|
|
|
|
Volume::SetState(Volume::STATE aNewState)
|
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-01-07 08:43:02 -08:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
2012-07-16 09:38:18 -07:00
|
|
|
if (aNewState == mState) {
|
|
|
|
return;
|
2012-05-24 21:03:07 -07:00
|
|
|
}
|
2012-08-08 15:44:59 -07:00
|
|
|
if (aNewState == nsIVolume::STATE_MOUNTED) {
|
2012-12-14 16:01:34 -08:00
|
|
|
mMountGeneration = ++sMountGeneration;
|
2014-08-19 13:41:35 -07:00
|
|
|
LOG("Volume %s (%u): changing state from %s to %s @ '%s' (%d observers) "
|
2012-12-14 16:01:34 -08:00
|
|
|
"mountGeneration = %d, locked = %d",
|
2014-08-19 13:41:35 -07:00
|
|
|
NameStr(), mId, StateStr(mState),
|
2014-11-03 16:26:59 -08:00
|
|
|
StateStr(aNewState), mMountPoint.get(), sEventObserverList.Length(),
|
2012-12-14 16:01:34 -08:00
|
|
|
mMountGeneration, (int)mMountLocked);
|
2012-08-08 15:44:59 -07:00
|
|
|
} else {
|
2014-08-19 13:41:35 -07:00
|
|
|
LOG("Volume %s (%u): changing state from %s to %s (%d observers)",
|
|
|
|
NameStr(), mId, StateStr(mState),
|
2014-11-03 16:26:59 -08:00
|
|
|
StateStr(aNewState), sEventObserverList.Length());
|
2012-08-08 15:44:59 -07:00
|
|
|
}
|
2012-07-16 09:38:18 -07:00
|
|
|
|
2013-08-22 16:12:25 -07: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 03:24:19 -08:00
|
|
|
mUnmountRequested = false;
|
|
|
|
mMountRequested = false;
|
2014-09-21 20:42:33 -07:00
|
|
|
mIsUnmounting = false;
|
2013-08-22 16:12:25 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIVolume::STATE_MOUNTED:
|
2015-01-11 20:01:07 -08:00
|
|
|
case nsIVolume::STATE_MOUNT_FAIL:
|
2014-03-04 03:24:19 -08:00
|
|
|
mMountRequested = false;
|
2013-09-05 23:11:58 -07:00
|
|
|
mIsFormatting = false;
|
|
|
|
mIsSharing = false;
|
2014-09-21 20:42:33 -07:00
|
|
|
mIsUnmounting = false;
|
2013-09-05 23:11:58 -07:00
|
|
|
break;
|
2015-01-11 20:01:07 -08:00
|
|
|
|
2013-08-22 16:12:25 -07:00
|
|
|
case nsIVolume::STATE_FORMATTING:
|
2013-09-05 23:11:58 -07:00
|
|
|
mFormatRequested = false;
|
|
|
|
mIsFormatting = true;
|
2013-08-22 16:12:25 -07:00
|
|
|
mIsSharing = false;
|
2014-09-21 20:42:33 -07:00
|
|
|
mIsUnmounting = false;
|
2013-08-22 16:12:25 -07:00
|
|
|
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;
|
2014-09-21 20:42:33 -07:00
|
|
|
mIsUnmounting = false;
|
|
|
|
mIsFormatting = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIVolume::STATE_UNMOUNTING:
|
|
|
|
mIsUnmounting = true;
|
|
|
|
mIsFormatting = false;
|
|
|
|
mIsSharing = false;
|
2013-08-22 16:12:25 -07:00
|
|
|
break;
|
|
|
|
|
2014-10-30 19:30:48 -07:00
|
|
|
case nsIVolume::STATE_IDLE: // Fall through
|
|
|
|
case nsIVolume::STATE_CHECKMNT: // Fall through
|
2013-08-22 16:12:25 -07:00
|
|
|
default:
|
|
|
|
break;
|
2012-07-16 09:38:18 -07:00
|
|
|
}
|
2012-07-16 09:38:18 -07:00
|
|
|
mState = aNewState;
|
2014-11-03 16:26:59 -08:00
|
|
|
sEventObserverList.Broadcast(this);
|
2012-05-24 21:03:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-07 08:43:02 -08:00
|
|
|
Volume::SetMountPoint(const nsCSubstring& aMountPoint)
|
2012-05-24 21:03:07 -07:00
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-01-07 08:43:02 -08:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
if (mMountPoint.Equals(aMountPoint)) {
|
|
|
|
return;
|
2012-05-24 21:03:07 -07:00
|
|
|
}
|
2012-07-16 09:38:18 -07:00
|
|
|
mMountPoint = aMountPoint;
|
|
|
|
DBG("Volume %s: Setting mountpoint to '%s'", NameStr(), mMountPoint.get());
|
2012-05-24 21:03:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-07 08:43:02 -08:00
|
|
|
Volume::StartMount(VolumeResponseCallback* aCallback)
|
2012-05-24 21:03:07 -07:00
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-01-07 08:43:02 -08:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-05-24 21:03:07 -07:00
|
|
|
StartCommand(new VolumeActionCommand(this, "mount", "", aCallback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-07 08:43:02 -08:00
|
|
|
Volume::StartUnmount(VolumeResponseCallback* aCallback)
|
2012-05-24 21:03:07 -07:00
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-01-07 08:43:02 -08:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-05-24 21:03:07 -07:00
|
|
|
StartCommand(new VolumeActionCommand(this, "unmount", "force", aCallback));
|
|
|
|
}
|
|
|
|
|
2013-09-05 23:11:58 -07:00
|
|
|
void
|
|
|
|
Volume::StartFormat(VolumeResponseCallback* aCallback)
|
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-09-05 23:11:58 -07:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
|
|
|
StartCommand(new VolumeActionCommand(this, "format", "", aCallback));
|
|
|
|
}
|
|
|
|
|
2012-05-24 21:03:07 -07:00
|
|
|
void
|
2013-01-07 08:43:02 -08:00
|
|
|
Volume::StartShare(VolumeResponseCallback* aCallback)
|
2012-05-24 21:03:07 -07:00
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-01-07 08:43:02 -08:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-05-24 21:03:07 -07:00
|
|
|
StartCommand(new VolumeActionCommand(this, "share", "ums", aCallback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-07 08:43:02 -08:00
|
|
|
Volume::StartUnshare(VolumeResponseCallback* aCallback)
|
2012-05-24 21:03:07 -07:00
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-01-07 08:43:02 -08:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-05-24 21:03:07 -07:00
|
|
|
StartCommand(new VolumeActionCommand(this, "unshare", "ums", aCallback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-07 08:43:02 -08:00
|
|
|
Volume::StartCommand(VolumeCommand* aCommand)
|
2012-05-24 21:03:07 -07:00
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-01-07 08:43:02 -08:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-05-24 21:03:07 -07:00
|
|
|
VolumeManager::PostCommand(aCommand);
|
|
|
|
}
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
//static
|
2012-07-16 09:38:18 -07:00
|
|
|
void
|
2014-11-03 16:26:59 -08:00
|
|
|
Volume::RegisterVolumeObserver(Volume::EventObserver* aObserver, const char* aName)
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2012-07-16 09:38:18 -07:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2014-11-03 16:26:59 -08:00
|
|
|
sEventObserverList.AddObserver(aObserver);
|
|
|
|
|
|
|
|
DBG("Added Volume Observer '%s' @%p, length = %u",
|
|
|
|
aName, aObserver, sEventObserverList.Length());
|
|
|
|
|
2012-07-16 09:38:18 -07: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 09:38:18 -07:00
|
|
|
}
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
//static
|
2012-07-16 09:38:18 -07:00
|
|
|
void
|
2014-11-03 16:26:59 -08:00
|
|
|
Volume::UnregisterVolumeObserver(Volume::EventObserver* aObserver, const char* aName)
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2012-07-16 09:38:18 -07:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2014-11-03 16:26:59 -08:00
|
|
|
sEventObserverList.RemoveObserver(aObserver);
|
|
|
|
|
|
|
|
DBG("Removed Volume Observer '%s' @%p, length = %u",
|
|
|
|
aName, aObserver, sEventObserverList.Length());
|
2012-07-16 09:38:18 -07:00
|
|
|
}
|
|
|
|
|
2012-12-14 16:01:34 -08:00
|
|
|
//static
|
|
|
|
void
|
2013-01-07 08:43:02 -08:00
|
|
|
Volume::UpdateMountLock(const nsACString& aVolumeName,
|
|
|
|
const int32_t& aMountGeneration,
|
|
|
|
const bool& aMountLocked)
|
2012-12-14 16:01:34 -08:00
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-01-07 08:43:02 -08:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-12-14 16:01:34 -08: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);
|
2014-11-03 16:26:59 -08:00
|
|
|
sEventObserverList.Broadcast(vol);
|
2012-12-14 16:01:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
void
|
2013-01-07 08:43:02 -08:00
|
|
|
Volume::HandleVoldResponse(int aResponseCode, nsCWhitespaceTokenizer& aTokenizer)
|
2012-07-16 09:38:18 -07:00
|
|
|
{
|
2015-07-03 18:29:00 -07:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2013-01-07 08:43:02 -08:00
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
|
2012-07-16 09:38:18 -07:00
|
|
|
// The volume name will have already been parsed, and the tokenizer will point
|
|
|
|
// to the token after the volume name
|
|
|
|
switch (aResponseCode) {
|
2014-09-25 07:10:42 -07:00
|
|
|
case ::ResponseCode::VolumeListResult: {
|
2012-07-16 09:38:18 -07:00
|
|
|
// Each line will look something like:
|
|
|
|
//
|
|
|
|
// sdcard /mnt/sdcard 1
|
|
|
|
//
|
|
|
|
nsDependentCSubstring mntPoint(aTokenizer.nextToken());
|
|
|
|
SetMountPoint(mntPoint);
|
2012-07-27 06:59:29 -07:00
|
|
|
nsresult errCode;
|
2012-07-16 09:38:18 -07:00
|
|
|
nsCString state(aTokenizer.nextToken());
|
2013-05-13 17:53:23 -07: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 09:38:18 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:10:42 -07:00
|
|
|
case ::ResponseCode::VolumeStateChange: {
|
2012-07-16 09:38:18 -07:00
|
|
|
// 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-01 19:35:17 -07:00
|
|
|
nsAutoCString token(aTokenizer.nextToken());
|
2014-05-21 20:48:51 -07:00
|
|
|
if (token.EqualsLiteral("to")) {
|
2012-07-27 06:59:29 -07:00
|
|
|
nsresult errCode;
|
2012-07-16 09:38:18 -07:00
|
|
|
token = aTokenizer.nextToken();
|
2014-10-30 19:30:48 -07:00
|
|
|
STATE newState = (STATE)(token.ToInteger(&errCode));
|
|
|
|
if (newState == nsIVolume::STATE_MOUNTED) {
|
|
|
|
// We set the state to STATE_CHECKMNT here, and the once the
|
|
|
|
// AutoMounter detects that the volume is actually accessible
|
|
|
|
// then the AutoMounter will set the volume as STATE_MOUNTED.
|
|
|
|
SetState(nsIVolume::STATE_CHECKMNT);
|
|
|
|
} else {
|
2015-01-11 20:01:07 -08:00
|
|
|
if (State() == nsIVolume::STATE_CHECKING && newState == nsIVolume::STATE_IDLE) {
|
|
|
|
LOG("Mount of volume '%s' failed", NameStr());
|
|
|
|
SetState(nsIVolume::STATE_MOUNT_FAIL);
|
|
|
|
} else {
|
|
|
|
SetState(newState);
|
|
|
|
}
|
2014-10-30 19:30:48 -07:00
|
|
|
}
|
2012-07-16 09:38:18 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:10:42 -07:00
|
|
|
case ::ResponseCode::VolumeDiskInserted:
|
2012-07-16 09:38:18 -07:00
|
|
|
SetMediaPresent(true);
|
|
|
|
break;
|
|
|
|
|
2014-09-25 07:10:42 -07:00
|
|
|
case ::ResponseCode::VolumeDiskRemoved: // fall-thru
|
|
|
|
case ::ResponseCode::VolumeBadRemoval:
|
2012-07-16 09:38:18 -07:00
|
|
|
SetMediaPresent(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
LOG("Volume: %s unrecognized reponse code (ignored)", NameStr());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-24 21:03:07 -07:00
|
|
|
} // namespace system
|
|
|
|
} // namespace mozilla
|