Skip to content

Conversation

@swift-kim
Copy link
Member

@swift-kim swift-kim commented Apr 11, 2022

Part of the code refactoring project.

  • Extract the DeviceBattery class from BatteryPlusTizenPlugin for better separation of the platform channel communication and the device API usage. (I referred to the battery_plus_windows implementation.)
    • Create an enum BatteryStatus to indicate the current status of the device battery or an error status.
    • RegisterObserver/UnregisterObserverStartListen/StopListen
    • StartListen takes BatteryStatusCallback as an argument.
    • Create a new method GetLevel.
    • Let GetStatus (previously GetBatteryStatus) return a value of type BatteryStatus.
  • Create typedefs of long commonly-used types (also taken from battery_plus_windows) for improved readability. For example,

    - std::unique_ptr<flutter::EventSink<flutter::EncodableValue>> events_;
    + std::unique_ptr<FlEventSink> events_;
  • Create an explicit BatteryStatusStreamHandler class. Now the lifecycle of EventSink is solely managed by this class.
    • OnListenInternal returns a StreamHandlerError on initialization failure.
  • Minor cleanups.
    • Remove SetupChannels and combine with RegisterWithRegistrar.
    • Style log messages and error codes in a consistent manner.
    • Wrap the non-public implementation with an anonymous namespace.

Additional note: The batteryState getter API has been added the platform interface and will be implemented in a later PR.

Comment on lines +61 to +63
return std::make_unique<FlStreamHandlerError>(
std::to_string(battery_.GetLastError()),
battery_.GetLastErrorString(), nullptr);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently results in an app crash. There will be a fix in the engine code soon.

Issue: flutter/flutter#101682

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swift-kim Any progress on this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbrto21 It isn't likely the fix will land very soon. How do you think of this or this workaround?

Copy link
Contributor

@bbrto21 bbrto21 Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swift-kim Actually, I also made a patch to prevent crash. how about this?
First one has intentional leak and the second solution you mentioned doesn't seem very good as it depends on instances of other classes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The holder_ suffix seems redundant. Otherwise looks good to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swift-kim Can I make PR to apply all place where have same problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Just one thing I forgot to mention: the private: section header is missing in the class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants