Page MenuHomePhabricator

Implement native method on Android to get notifications olm account storage path
ClosedPublic

Authored by marcin on Feb 20 2023, 3:13 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 28, 9:04 AM
Unknown Object (File)
Sun, Apr 28, 9:04 AM
Unknown Object (File)
Sun, Apr 28, 9:04 AM
Unknown Object (File)
Sun, Apr 28, 9:04 AM
Unknown Object (File)
Sun, Apr 28, 9:04 AM
Unknown Object (File)
Sun, Apr 28, 9:04 AM
Unknown Object (File)
Sun, Apr 28, 9:02 AM
Unknown Object (File)
Sun, Apr 28, 8:21 AM
Subscribers

Details

Summary

This differential extends PlatformSpecificTools.java with method to retrieve notifications olm account path. This functionality requires main application context to be accessible in PlatformSpecificTools. Usually we would pass it in constructor or as method argument, but this
class is designed to be static method only class callable from C++. Therefore we need a "static" way of accessing main application context here. This approach is described here: https://stackoverflow.com/questions/2002288/static-way-to-get-context-in-android. Further diffs will extend
C++ header to include this method.

Test Plan

Call this method from CommNotificationsHandler on each message and log path to the console.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

marcin published this revision for review.Feb 20 2023, 4:42 AM

Looks good to me, but I'd like to give some more context ;) on this.
Exposing app context as a static variable is a common technique. It would be considered an anti-pattern if there was an easy way to do it by passing it through function arguments. In this case, it will be called from JNI, where doing so would be extremely cumbersome, although possible (but requiring much more code). This is why I'm accepting.

Some related threads about this:

A counter-argument article describing why this is an anti-pattern:

Generally, doing this is safe unless we're calling it before the main app has been initialized / after it is destroyed - so in practice: always.

native/android/app/src/main/java/app/comm/android/MainApplication.java
83–86 ↗(On Diff #22708)

This comment about TurboModules is unrelated to this line ;)

This revision is now accepted and ready to land.Feb 21 2023, 12:58 AM

Would be good to get CI builds passing before landing (rebase on master)