Closed
Bug 1282433
Opened 8 years ago
Closed 8 years ago
Battery API broken on linux
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
FIXED
mozilla52
Tracking | Status | |
---|---|---|
firefox52 | --- | fixed |
People
(Reporter: baku, Assigned: baku)
Details
Attachments
(1 file, 5 obsolete files)
4.74 KB,
patch
|
karlt
:
review+
|
Details | Diff | Splinter Review |
On linux no updates are received when the battery state changes.
Assignee | ||
Comment 1•8 years ago
|
||
overholt: Do you know anyone about to review dbus code?
Flags: needinfo?(overholt)
Comment 2•8 years ago
|
||
karlt? glandium?
Assignee | ||
Updated•8 years ago
|
Flags: needinfo?(overholt)
Attachment #8765516 -
Flags: review?(mh+mozilla)
Updated•8 years ago
|
Attachment #8765516 -
Flags: review?(mh+mozilla) → review?(karlt)
Comment 3•8 years ago
|
||
Comment on attachment 8765516 [details] [diff] [review] battery.patch Please provide a commit message.
Attachment #8765516 -
Flags: review?(karlt)
Assignee | ||
Comment 4•8 years ago
|
||
Attachment #8765516 -
Attachment is obsolete: true
Attachment #8765760 -
Flags: review?(karlt)
Assignee | ||
Comment 5•8 years ago
|
||
Comment on attachment 8765760 [details] [diff] [review] battery.patch Review of attachment 8765760 [details] [diff] [review]: ----------------------------------------------------------------- ::: hal/linux/UPowerClient.cpp @@ +235,5 @@ > + > + mUPowerProxyProp = dbus_g_proxy_new_for_name(mDBusConnection, > + "org.freedesktop.UPower", > + "/org/freedesktop/UPower", > + DBUS_INTERFACE_PROPERTIES); I already fixed the indentation here.
Comment 6•8 years ago
|
||
Comment on attachment 8765760 [details] [diff] [review] battery.patch > Bug 1282433 - UPowerClient should use dbus PropertiesChanged signal for retrieving battery status changes, r?=karlt There are some things I don't understand here. Can you explain for me, please? Why listen for "PropertiesChanged" on /org/freedesktop/UPower but get properties on the device path? In dbus-monitor --system, I see messages like these > signal time=1467196381.664556 sender=:1.11 -> destination=(null destination) serial=13464 path=/org/freedesktop/UPower/devices/battery_BAT0; interface=org.freedesktop.UPower.Device; member=Changed > signal time=1467196381.664655 sender=:1.11 -> destination=(null destination) serial=13465 path=/org/freedesktop/UPower; interface=org.freedesktop.UPower; member=DeviceChanged string "/org/freedesktop/UPower/devices/battery_BAT0" What does DeviceChanged indicate, if not changes in device properties?
Flags: needinfo?(amarchesini)
Attachment #8765760 -
Flags: review?(karlt)
Assignee | ||
Comment 7•8 years ago
|
||
> What does DeviceChanged indicate, if not changes in device properties?
Can you tell me which version of UPower do you have?
This is not what happens on my laptop having ubuntu xenial and upower 0.99 and in other linux system tested by others.
Also the official documentation of upower says that we should listen for PropertiesChanged notification.
Flags: needinfo?(amarchesini)
Comment 8•8 years ago
|
||
(In reply to Andrea Marchesini (:baku) from comment #7) > > What does DeviceChanged indicate, if not changes in device properties? > > Can you tell me which version of UPower do you have? I'm using 0.9.23. > This is not what happens on my laptop having ubuntu xenial and upower 0.99 > and in other linux system tested by others. > Also the official documentation of upower says that we should listen for > PropertiesChanged notification. It seems that 0.99 is using a different interface with the same name, as indicated in https://cgit.freedesktop.org/upower/commit/NEWS?id=384bae5af83fe05a91fc77c25e4d18eba9911cb1 So, listening for both DeviceChanged and PropertiesChanged does seem appropriate for now. Please add a comment to explain why two different mechanisms are used to listen for notification of the same changes.
Comment 10•8 years ago
|
||
No, I haven't reviewed yet. Still waiting for the answer to the first question in comment 6.
Flags: needinfo?(karlt)
Assignee | ||
Comment 11•8 years ago
|
||
Comment on attachment 8765760 [details] [diff] [review] battery.patch Review of attachment 8765760 [details] [diff] [review]: ----------------------------------------------------------------- ::: hal/linux/UPowerClient.cpp @@ +232,5 @@ > dbus_g_proxy_connect_signal(mUPowerProxy, "DeviceChanged", > G_CALLBACK (DeviceChanged), this, nullptr); > + > + > + mUPowerProxyProp = dbus_g_proxy_new_for_name(mDBusConnection, This is DBUS proxy for PropertyChanged. I cannot use the other proxy because it points to a different interface/service/name. @@ +239,5 @@ > + DBUS_INTERFACE_PROPERTIES); > + > + dbus_g_proxy_add_signal(mUPowerProxyProp, "PropertiesChanged", G_TYPE_STRING, > + dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), > + G_TYPE_STRV, G_TYPE_INVALID); DBus works in such a way that, in order to connect a signal to a callback you must describe the 'prototype' of that signal. This signal receives a string + an hashtable + strv. For hashtable you also need to describe what it contains. Here the reason why we have these 3 lines. Similar to what we have for the DeviceChanged signal. @@ +241,5 @@ > + dbus_g_proxy_add_signal(mUPowerProxyProp, "PropertiesChanged", G_TYPE_STRING, > + dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), > + G_TYPE_STRV, G_TYPE_INVALID); > + dbus_g_proxy_connect_signal(mUPowerProxyProp, "PropertiesChanged", > + G_CALLBACK (PropertiesChanged), this, nullptr); Finally the connect :) @@ +260,5 @@ > dbus_g_proxy_disconnect_signal(mUPowerProxy, "DeviceChanged", > G_CALLBACK (DeviceChanged), this); > > + dbus_g_proxy_disconnect_signal(mUPowerProxyProp, "PropertiesChanged", > + G_CALLBACK (PropertiesChanged), this); Disconnect is easy. @@ +274,5 @@ > g_object_unref(mUPowerProxy); > mUPowerProxy = nullptr; > > + g_object_unref(mUPowerProxyProp); > + mUPowerProxyProp = nullptr; nullify stuff... @@ +364,5 @@ > + UPowerClient* aListener) > +{ > + if (!aListener->mTrackedDevice) { > + return; > + } If we don't have a TrackedDevice, the initialization is unfinished, or we are in shuttingdown. Similar setup for DeviceChanged. @@ +371,5 @@ > + if (g_strcmp0(aObjectPath, "org.freedesktop.UPower")) { > +#else > + if (g_ascii_strcasecmp(aObjectPath, "org.freedesktop.UPower")) { > +#endif > + return; The main difference between PropertiesChanged and DeviceChanged, is that we don't receive the name of the device in aObjectPath. Instead we receive a generic org.freedesktop.UPower. In theory we can remove this block, or have it in #ifdef DEBUG/#endif. @@ +374,5 @@ > +#endif > + return; > + } > + > + aListener->GetDevicePropertiesAsync(aListener->mTrackedDeviceProxy); Here we continue as DeviceChanged does.
Attachment #8765760 -
Flags: review?(karlt)
Comment 12•8 years ago
|
||
Comment on attachment 8765760 [details] [diff] [review] battery.patch Hmm. I guess I was referring to the second question in comment 6. (In reply to Andrea Marchesini (:baku) from comment #11) > > + mUPowerProxyProp = dbus_g_proxy_new_for_name(mDBusConnection, > > This is DBUS proxy for PropertyChanged. I cannot use the other proxy because > it points to a different interface/service/name. The object path here is "/org/freedesktop/UPower". Presumably that means the signal is sent when a property on this UPower object changes, and not necessarily when a property changes on one of the device objects. https://dbus.freedesktop.org/doc/dbus-specification.html "If one or more properties change on an object, the org.freedesktop.DBus.Properties.PropertiesChanged signal may be emitted" > > + aListener->GetDevicePropertiesAsync(aListener->mTrackedDeviceProxy); > > Here we continue as DeviceChanged does. .. to get properties using a path describing a *device* object. > If we don't have a TrackedDevice, the initialization is unfinished, or we > are in shuttingdown. > Similar setup for DeviceChanged. > > @@ +371,5 @@ > > + if (g_strcmp0(aObjectPath, "org.freedesktop.UPower")) { > > +#else > > + if (g_ascii_strcasecmp(aObjectPath, "org.freedesktop.UPower")) { > > +#endif > > + return; > > The main difference between PropertiesChanged and DeviceChanged, is that we > don't receive the name of the device in aObjectPath. Instead we receive a > generic org.freedesktop.UPower. In theory we can remove this block, or have > it in #ifdef DEBUG/#endif. This check is cheap and so good, I think, to filter out changes on any other interfaces. Note that the |interface_name| parameter is not an object path, so please name it appropriately. Similarly, please name the other parameters consistently with the interface, or leave out the parameter names. GLib 2.22 is required to build, so just use g_strcmp0. A more significant difference is that DeviceChanged and PropertiesChanged are emitted on different objects. DeviceChanged was emitted on the UPower object when the device changed. The properties fetched are on the device object. I assume the PropertiesChanged signal on the device object is the one of interest? Please also add a comment to explain in the code why two different mechanisms are used to listen for notification of the same changes. > Bug 1282433 - UPowerClient should use dbus PropertiesChanged signal for retrieving battery status changes, r?=karlt Please use imperative mood in the first line of commit messages to describe what the patch changes, rather than subjunctive describing what should be done. "use dbus PropertiesChanged signal for notification of battery status changes From UPower 0.99, DeviceChanged has been removed from the UPower interface and PropertiesChanged support added."
Attachment #8765760 -
Flags: review?(karlt) → review-
Assignee | ||
Comment 13•8 years ago
|
||
Attachment #8765760 -
Attachment is obsolete: true
Attachment #8774228 -
Flags: review?(karlt)
Comment 14•8 years ago
|
||
Comment on attachment 8774228 [details] [diff] [review] battery.patch >+ mUPowerProxyProp = dbus_g_proxy_new_for_name(mDBusConnection, >+ "org.freedesktop.UPower", >+ "/org/freedesktop/UPower", >+ DBUS_INTERFACE_PROPERTIES); >+ >+ dbus_g_proxy_add_signal(mUPowerProxyProp, "PropertiesChanged", G_TYPE_STRING, This is the "UPower" object. Its properties are described at https://upower.freedesktop.org/docs/UPower.html#UPower.properties and not useful AFAICS. Listen to PropertiesChanged on the device object using mTrackedDeviceProxy, for changes in the properties used in UpdateSavedInfo(): https://upower.freedesktop.org/docs/Device.html#Device.properties
Attachment #8774228 -
Flags: review?(karlt) → review-
Assignee | ||
Comment 15•8 years ago
|
||
Both approaches have the same result. Here a patch with your comments applied.
Attachment #8774228 -
Attachment is obsolete: true
Attachment #8775935 -
Flags: review?(karlt)
Assignee | ||
Comment 17•8 years ago
|
||
BatteryAPI is not exposed to content anymore.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
Comment 18•8 years ago
|
||
Comment on attachment 8775935 [details] [diff] [review] battery.patch This makes sense, thanks. >+ static void PropertiesChanged(DBusGProxy* aProxy, const gchar* aInterfaceName, >+ GHashTable* aHashTable, char *word[], >+ UPowerClient* aListener); Please either name the GHashTable* and char** parameters consistently with the interface, or leave out the parameter names. Please also comments in the code to explain why two different mechanisms are used to listen for notification of the same changes. >+ dbus_g_proxy_add_signal(mTrackedDeviceProxy, "PropertiesChanged", G_TYPE_STRING, >+ dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), Please wrap to stay within 80 columns. >+UPowerClient::PropertiesChanged(DBusGProxy* aProxy, const gchar* aInterfaceName, >+ GHashTable* aHashTable, char *aWord[], >+ UPowerClient* aListener) >+{ >+ if (!aListener->mTrackedDevice) { >+ return; >+ } mTrackedDevice is always set here, so remove the dead return statement. An assert is fine if you like, but the member is not used anyway, so there's no need.
Flags: needinfo?(karlt)
Attachment #8775935 -
Flags: review?(karlt) → review-
Assignee | ||
Comment 19•8 years ago
|
||
We are not removing this API.
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
Assignee | ||
Comment 20•8 years ago
|
||
Attachment #8775935 -
Attachment is obsolete: true
Attachment #8805930 -
Flags: review?(karlt)
Comment 21•8 years ago
|
||
Comment on attachment 8805930 [details] [diff] [review] battery.patch >+ GHashTable*, char *aWord[], Please remove the name of the |aWord| parameter and place the '*' beside the type. The name is misleading because it is not a word, but a pointer to the first element of an array of names of invalidated_properties. Either "gchar*[]" or "gchar**" is fine as they are equivalent [1]. [1] http://stackoverflow.com/questions/4810664/how-do-i-use-arrays-in-c/4810672#4810672
Attachment #8805930 -
Flags: review?(karlt) → review-
Assignee | ||
Comment 22•8 years ago
|
||
Attachment #8805930 -
Attachment is obsolete: true
Attachment #8806236 -
Flags: review?(karlt)
Updated•8 years ago
|
Attachment #8806236 -
Flags: review?(karlt) → review+
Comment 23•8 years ago
|
||
Pushed by amarchesini@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/03ccd2a9b30c Use dbus PropertiesChanged signal for notification of battery status changes, r=karlt
Comment 24•8 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/03ccd2a9b30c
Status: REOPENED → RESOLVED
Closed: 8 years ago → 8 years ago
status-firefox52:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
Updated•5 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•