Posted on Leave a comment

Android IPC + gRPC

Inter-process communication

pdf

AIDL (Android Interface Definition Language) и коммуникация между процессами (IPC) [https://habrahabr.ru/post/139432/]


Основы безопасности операционной системы Android. Безопасность на уровне Application Framework. Binder IPC [https://habr.com/post/176093/]


Android IPC Mechanism [pdf]

What the Zygote!? [https://medium.com/@voodoomio/what-the-zygote-76f852d887d9]

Exploring Android Processes [https://medium.com/@kelvinma/exploring-android-processes-bf74ba63552c]


Communication between apps in Android

Problems to solve by communication

  • apps can start each other and can receive a result
  • apps can send notification about events
  • providing data
  • providing methods (RPC)
  • providing UI

Android API to communicate

  • startActivity, startActivityForResult
  • sendBroadcast
  • ContentProvider
  • AIDL, Messenger
  • system services: Notification listener, Mediasession etc.

How does it work under the hood

Features of startActivityForResult

  • transaction has 1 Mb limit
  • user leave your app
  • hence OS can kill your app or user might don’t come back to the app
  • you can pass primitive types, String, Parcelable, Serializable and list of them
  • the main goal – start other activities and receive their result

Features of sendBroadcast

  • at the moment there are 2 queues: for foreground and for background priority

    &amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
    /**&amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
     * BROADCASTS&amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
     *&amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
     * We keep two broadcast queues and associated bookkeeping, one for those at&amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
     * foreground priority, and one for normal (background-priority) broadcasts.&amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
     */&amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
    

  • transaction has 1 Mb limit
  • delivery time is not guaranteed
  • asynchronously
  • you don’t know when receiver receive Intent
  • you can pass primitive types, String, Parcelable, Serializable and list of them
  • the main goals:
    • notify about events if delivery time is not important
    • if delivery time is important and receiver is in foreground
    • you can receiver system events

AIDL

[https://developer.android.com/guide/components/aidl]

  • you can pass primitive types, String, Parcelable, Interface and list of them
  • AIDL can do everything
  • you can invoke another app methods synchronously and asynchronously
  • receive data by your own callback or by Messenger
  • 1 Mb limit [https://developer.android.com/reference/android/os/TransactionTooLargeException]

    &amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
    The Binder transaction failed because it was too large.&amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
    During a remote procedure call, the arguments and the return value of the call are transferred as Parcel objects stored in the Binder transaction buffer. If the arguments or the return value are too large to fit in the transaction buffer, then the call will fail and TransactionTooLargeException will be thrown.&amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
    The Binder transaction buffer has a limited fixed size, currently 1Mb, which is shared by all transactions in progress for the process. Consequently this exception can be thrown when there are many transactions in progress even when most of the individual transactions are of moderate size.&amp;amp;amp;lt;br&amp;amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;<br>
    

  • the main goal is RPC

ContentProvider

  • a row in cursor has 2 Mb limit
  • a number of rows is not limited
  • synchronously
  • you can pass primitive types, String, byte[], other data types use toString
  • the main goal is data transfer

System services

  • AccountManager – a way to store and share account info
  • App widgets
  • NotificationListenerService – a way to get all notification
  • Mediasession

Android Binder Framework [ https://android.jlelse.eu/android-binder-framework-8a28fb38699a ]



[https://t.me/android_live/585]


Подробнее о JSON RPC
[https://medium.com/nuances-of-programming/%D0%BF%D0%BE%D0%B4%D1%80%D0%BE%D0%B1%D0%BD%D0%B5%D0%B5-%D0%BE-json-rpc-b4ad927edcaf]

REST? Возьмите тупой JSON-RPC
[https://habr.com/ru/post/441854/]

gRPC в качестве протокола межсервисного взаимодействия. Доклад Яндекса
[https://habr.com/ru/company/yandex/blog/484068/]

Announcing gRPC Kotlin 1.0 for Android and Cloud
[https://developers.googleblog.com/2020/12/announcing-grpc-kotlin-10-for-android.html]

The legend about AIDL. Part 1. The roots
[https://unbreakable-titan.medium.com/the-legend-about-aidl-part-1-the-roots-c144be38d9a4]

Уязвимости в реализации межпроцессного взаимодействия в Android-приложениях
[https://habr.com/ru/company/odnoklassniki/blog/525280/]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.