DeviceStorage Related Link

Volume State

dom/system/gonk/nsIVolume.idl

  // These MUST match the states from android's system/vold/Volume.h header
  const long STATE_INIT        = -1;
  const long STATE_NOMEDIA     = 0;
  const long STATE_IDLE        = 1;
  const long STATE_PENDING     = 2;
  const long STATE_CHECKING    = 3;
  const long STATE_MOUNTED     = 4;    // We can only use this volume in this state
  const long STATE_UNMOUNTING  = 5;
  const long STATE_FORMATTING  = 6;
  const long STATE_SHARED      = 7;
  const long STATE_SHAREDMNT   = 8;
  const long STATE_CHECKMNT    = 100;
  const long STATE_MOUNT_FAIL  = 101;        // this is new added by mozilla

NS_VOLUME_STATE_CHANGED

You can listen the the event called “NS_VOLUME_STATE_CHANGED” for volume state change. (related bug : 1118177)

//@constructor

if (NS_FAILED(obs->AddObserver(this, NS_VOLUME_STATE_CHANGED, false))) {
  WARNING("Failed to add ns volume observer!");
  return false;
}


//PS: Need to use RemoveObserver in @desturctor.


NS_IMETHODIMP
BluetoothOppManager::Observe(nsISupports* aSubject,
                             const char* aTopic,
                             const char16_t* aData)
{

  // if state of any volume was changed
  if (!strcmp(aTopic, NS_VOLUME_STATE_CHANGED)) {
    HandleVolumeStateChanged(aSubject);
    return NS_OK;
  }

}


Useful DS function

void DeviceStorageFile::GetStatus(nsAString& aStatus)
  • The possibility value of aStatus are “available”, “unavailable”, “shared
  • We can access this storage only when the status is “available”.
  • When this storage is in ums mode, the status is “shared”.

 

Useful DS function

void DeviceStorageFile::GetStorageStatus(nsAString& aStatus)
  • If you want to detail state, you can use this function.
  • The possibility value of aStatus are as “0. Volume State”.

 

Mount Lock

  • e.g. Get a mount lock to prevent the sdcard from being shared with the PC or being formatted
  • Related bug : 869259

File Change

  • Listen "file-watcher-update" event
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
obs->AddObserver(this, "file-watcher-update", false);
NS_IMETHOD
Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
{
  if (!strcmp(aTopic, "file-watcher-update")) {
    NS_ConvertUTF16toUTF8 eventType(aData);
    DeviceStorageFile* file = static_cast<DeviceStorageFile*>(aSubject);
    MTP_LOG("file-watcher-update: file %s %s",
                 NS_LossyConvertUTF16toASCII(file->mPath).get(),
              eventType.get());
  }
}

I. Add observer

II. Add event handle in observe function

Gaia Development

'change' event

'change' event

Not In MDN - Volume Change

  • The reasons for storage are :
    • available, unavailable, shared :
      • For volume state change.
    • low-disk-space <-> available-disk-space :
      • For the space status of vloume
    • default-location-changed <-> became-default-location :
      • For notify gaia about the change of default location. (related to settings key “"device.storage.writable.name"”)

'storage-state-change' Event

  • This event is for the change of real volume state change.

  • The possible reasons of this event are as below.


    STATE_INIT        = -1;
    STATE_NOMEDIA     = 0;
    STATE_IDLE        = 1;
    STATE_PENDING     = 2;
    STATE_CHECKING    = 3;
    STATE_MOUNTED     = 4;    // We can only use this volume in this state
    STATE_UNMOUNTING  = 5;
    STATE_FORMATTING  = 6;
    STATE_SHARED      = 7;
    STATE_SHAREDMNT   = 8;
    STATE_CHECKMNT    = 100;
    STATE_MOUNT_FAIL  = 101;        // this is new added by mozilla

MTP Test Case

DeviceStorage Related Link

By Alphan Chen

DeviceStorage Related Link

  • 903
Loading comments...

More from Alphan Chen