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)
Thu, Nov 28, 1:37 AM
Unknown Object (File)
Wed, Nov 27, 10:34 PM
Unknown Object (File)
Oct 31 2024, 4:04 PM
Unknown Object (File)
Oct 30 2024, 7:57 AM
Unknown Object (File)
Oct 30 2024, 7:57 AM
Unknown Object (File)
Oct 30 2024, 7:57 AM
Unknown Object (File)
Oct 30 2024, 7:57 AM
Unknown Object (File)
Oct 30 2024, 7:57 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
Branch
marcin/eng-2901
Lint
No Lint Coverage
Unit
No Test Coverage

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

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)