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
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;
}
}
void DeviceStorageFile::GetStatus(nsAString& aStatus)
void DeviceStorageFile::GetStorageStatus(nsAString& aStatus)
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
In MDN - File Change
DeviceStorageChangeEvent.reason which gives the reason of the change (created, modified or deleted).
Not In MDN - Volume Change
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