mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-01 05:43:46 +00:00
Bug 927961 - Add ums.status so that settings app can determine if files are open. r=gwagner
This commit is contained in:
parent
1b6c47fe99
commit
6a016e9163
@ -88,6 +88,8 @@ namespace system {
|
||||
|
||||
class AutoMounter;
|
||||
|
||||
static void SetAutoMounterStatus(int32_t aStatus);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
inline const char* SwitchStateStr(const SwitchEvent& aEvent)
|
||||
@ -376,6 +378,7 @@ AutoMounter::UpdateState()
|
||||
LOG("UpdateState: umsAvail:%d umsEnabled:%d mode:%d usbCablePluggedIn:%d tryToShare:%d",
|
||||
umsAvail, umsEnabled, mMode, usbCablePluggedIn, tryToShare);
|
||||
|
||||
bool filesOpen = false;
|
||||
VolumeArray::index_type volIndex;
|
||||
VolumeArray::size_type numVolumes = VolumeManager::NumVolumes();
|
||||
for (volIndex = 0; volIndex < numVolumes; volIndex++) {
|
||||
@ -437,6 +440,7 @@ AutoMounter::UpdateState()
|
||||
PostDelayedTask(FROM_HERE,
|
||||
NewRunnableMethod(this, &AutoMounter::UpdateState),
|
||||
5000);
|
||||
filesOpen = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -481,6 +485,14 @@ AutoMounter::UpdateState()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t status = AUTOMOUNTER_STATUS_DISABLED;
|
||||
if (filesOpen) {
|
||||
status = AUTOMOUNTER_STATUS_FILES_OPEN;
|
||||
} else if (enabled) {
|
||||
status = AUTOMOUNTER_STATUS_ENABLED;
|
||||
}
|
||||
SetAutoMounterStatus(status);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
@ -595,7 +607,7 @@ InitVolumeConfig()
|
||||
return;
|
||||
}
|
||||
while(fgets(line, sizeof(line), fp)) {
|
||||
char *delim = " \t\n";
|
||||
const char *delim = " \t\n";
|
||||
n++;
|
||||
|
||||
if (line[0] == '#')
|
||||
@ -644,6 +656,24 @@ InitAutoMounter()
|
||||
sUsbCableObserver = new UsbCableObserver();
|
||||
}
|
||||
|
||||
int32_t
|
||||
GetAutoMounterStatus()
|
||||
{
|
||||
if (sAutoMounterSetting) {
|
||||
return sAutoMounterSetting->GetStatus();
|
||||
}
|
||||
return AUTOMOUNTER_STATUS_DISABLED;
|
||||
}
|
||||
|
||||
//static
|
||||
void
|
||||
SetAutoMounterStatus(int32_t aStatus)
|
||||
{
|
||||
if (sAutoMounterSetting) {
|
||||
sAutoMounterSetting->SetStatus(aStatus);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SetAutoMounterMode(int32_t aMode)
|
||||
{
|
||||
|
@ -17,6 +17,11 @@ namespace system {
|
||||
#define AUTOMOUNTER_ENABLE 1
|
||||
#define AUTOMOUNTER_DISABLE_WHEN_UNPLUGGED 2
|
||||
|
||||
// Automounter statuses
|
||||
#define AUTOMOUNTER_STATUS_DISABLED 0
|
||||
#define AUTOMOUNTER_STATUS_ENABLED 1
|
||||
#define AUTOMOUNTER_STATUS_FILES_OPEN 2
|
||||
|
||||
/**
|
||||
* Initialize the automounter. This causes some of the phone's
|
||||
* directories to show up on the host when the phone is plugged
|
||||
@ -38,6 +43,12 @@ InitAutoMounter();
|
||||
void
|
||||
SetAutoMounterMode(int32_t aMode);
|
||||
|
||||
/**
|
||||
* Reports the status of the automounter.
|
||||
*/
|
||||
int32_t
|
||||
GetAutoMounterStatus();
|
||||
|
||||
/**
|
||||
* Sets the sharing mode of an individual volume.
|
||||
*
|
||||
|
@ -26,6 +26,7 @@
|
||||
#define ERR(args...) __android_log_print(ANDROID_LOG_ERROR, "AutoMounterSetting" , ## args)
|
||||
|
||||
#define UMS_MODE "ums.mode"
|
||||
#define UMS_STATUS "ums.status"
|
||||
#define UMS_VOLUME_ENABLED_PREFIX "ums.volume."
|
||||
#define UMS_VOLUME_ENABLED_SUFFIX ".enabled"
|
||||
#define MOZSETTINGS_CHANGED "mozsettings-changed"
|
||||
@ -87,7 +88,10 @@ private:
|
||||
NS_IMPL_ISUPPORTS1(CheckVolumeSettingsCallback, nsISettingsServiceCallback)
|
||||
|
||||
AutoMounterSetting::AutoMounterSetting()
|
||||
: mStatus(AUTOMOUNTER_STATUS_DISABLED)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Setup an observer to watch changes to the setting
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
mozilla::services::GetObserverService();
|
||||
@ -116,6 +120,7 @@ AutoMounterSetting::AutoMounterSetting()
|
||||
settingsService->CreateLock(getter_AddRefs(lock));
|
||||
nsCOMPtr<nsISettingsServiceCallback> callback = new SettingsServiceCallback();
|
||||
lock->Set(UMS_MODE, INT_TO_JSVAL(AUTOMOUNTER_DISABLE), callback, nullptr);
|
||||
lock->Set(UMS_STATUS, INT_TO_JSVAL(mStatus), nullptr, nullptr);
|
||||
}
|
||||
|
||||
AutoMounterSetting::~AutoMounterSetting()
|
||||
@ -129,6 +134,17 @@ AutoMounterSetting::~AutoMounterSetting()
|
||||
|
||||
NS_IMPL_ISUPPORTS1(AutoMounterSetting, nsIObserver)
|
||||
|
||||
const char *
|
||||
AutoMounterSetting::StatusStr(int32_t aStatus)
|
||||
{
|
||||
switch (aStatus) {
|
||||
case AUTOMOUNTER_STATUS_DISABLED: return "Disabled";
|
||||
case AUTOMOUNTER_STATUS_ENABLED: return "Enabled";
|
||||
case AUTOMOUNTER_STATUS_FILES_OPEN: return "FilesOpen";
|
||||
}
|
||||
return "??? Unknown ???";
|
||||
}
|
||||
|
||||
class CheckVolumeSettingsRunnable : public nsRunnable
|
||||
{
|
||||
public:
|
||||
@ -162,6 +178,39 @@ AutoMounterSetting::CheckVolumeSettings(const nsACString& aVolumeName)
|
||||
NS_DispatchToMainThread(new CheckVolumeSettingsRunnable(aVolumeName));
|
||||
}
|
||||
|
||||
class SetStatusRunnable : public nsRunnable
|
||||
{
|
||||
public:
|
||||
SetStatusRunnable(int32_t aStatus) : mStatus(aStatus) {}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
nsCOMPtr<nsISettingsService> settingsService =
|
||||
do_GetService("@mozilla.org/settingsService;1");
|
||||
NS_ENSURE_TRUE(settingsService, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsISettingsServiceLock> lock;
|
||||
settingsService->CreateLock(getter_AddRefs(lock));
|
||||
lock->Set(UMS_STATUS, INT_TO_JSVAL(mStatus), nullptr, nullptr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t mStatus;
|
||||
};
|
||||
|
||||
//static
|
||||
void
|
||||
AutoMounterSetting::SetStatus(int32_t aStatus)
|
||||
{
|
||||
if (aStatus != mStatus) {
|
||||
LOG("Changing status from '%s' to '%s'",
|
||||
StatusStr(mStatus), StatusStr(aStatus));
|
||||
mStatus = aStatus;
|
||||
NS_DispatchToMainThread(new SetStatusRunnable(aStatus));
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AutoMounterSetting::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
|
@ -22,6 +22,13 @@ public:
|
||||
virtual ~AutoMounterSetting();
|
||||
|
||||
static void CheckVolumeSettings(const nsACString& aVolumeName);
|
||||
|
||||
int32_t GetStatus() { return mStatus; }
|
||||
void SetStatus(int32_t aStatus);
|
||||
const char *StatusStr(int32_t aStatus);
|
||||
|
||||
private:
|
||||
int32_t mStatus;
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
|
Loading…
Reference in New Issue
Block a user