Component - Android IPC Mechanisms - About the “Bridge” module API - DataStorage using ContentProvider - EventHandler using BroadcastReceiver - RequestHandler using Messenger with Service - Use case of each Bridge API in Migration SDK 2
built upon multi-user Linux system - Each application has a unique Linux user id. - Each application runs in its own, separate process. - Process isolation is done between the apps. - By default, all components of the same application run in the same process. 3 https://developer.android.com/guide/platform/
Android App. - Each type serves a distinct purpose. - Activity : Provides user interface and interacts with the user, representing a single screen. - Content Provider : Manages a shared set of app data that is stored in the file system. - Broadcast Receiver : Receives and handle messages sent from other component. - Service : Performs long-running operations in the background - Can also be bound to another component which can even do Inter Process Communication(IPC)
design is that any app can start another app’s component. - Each component can be an entry point of the app. - The system runs each app in a separate process with file permissions that restrict access to other apps. - Cannot directly activate a component from another app. - Need to do frequent Inter-Process Communication. 5
- Binder (with AIDL) - Messenger - Intent - The latter is the abstracted version of the former. - Binder is the lowest level API that Android provides - Messenger = Binder + Predefined AIDL + Restricted Thread (Handler) - Intent = Messenger + Connection control 7
Interface Definition Language) to be used as IPC. - AIDL decomposes Objects into primitives that the OS can understand, and passes them across processes to perform IPC. - Directly invoke methods on other processes. - Need to ensure thread safety and handle multi threading while using it. 8 Deep Dive into Android IPC/Binder Framework at Android Builders Summit 2013, Aleksandar (Saša) Gargenta.
is associated with a single thread and handles that thread’s event queue. - Creates a queue of all the client requests in a single thread, receiving requests one at a time (Thread safety). - Only asynchronous communications. - How to use - The server implements a Handler that receives a callback for each call from a client and create a Messenger using the handler. - When the client is bound to the server, the Messenger reference is given to the client which also references the server’s handler. - The client uses the Messenger to send Message objects to the server. - The server receives each Message in its Handler. 10
the app components. - The most abstracted, easiest form to use. - Only need to set the target component or declare a general action to perform. - Can start the other components : Broadcast Receiver, Service, Activity. - High latency issue. - No callbacks after firing a intent. 12 Deep Dive into Android IPC/Binder Framework at Android Builders Summit 2013, Aleksandar (Saša) Gargenta.
the Migration issue. - https://github.com/Buzzvil/buzzscreen-sdk-publisher-migration/wiki/COMMUNICATION-UTILS - Utility for easy communication between two apps, L app and M app. - Bridge module’s class should be initialized with each other app’s package name to set the destination of communication. - Restrict each component with the signature-level permission - The system grants only if the requesting application is signed with the same certificate as the application that declared the permission. - 3 types of communication - DataStorage for sharing data between two apps. - EventHandler for one-way communication, designating each app as a sender and a receiver. - RequestHandler for two-way communication, similar to that of server-client relationship. 13
Implemented using ContentProvider - Data is stored in a key-value structure - Calling ‘put’ stores the value mapped to the key in current app’s storage. - Calling ‘get’ queries data from the partner and itself’s ContentProvider. MigrationXXX.getDataStorage().put("SHARED_CONFIG_KEY", "config_value"); String value = MigrationXXX.getDataStorage().get("SHARED_CONFIG_KEY"); 14
Each event is distinguished by its unique name - The sender sends intents to the receiver specifying which event is currently sent. - The receiver registers listener for each event. 15
other processes to interact with the service, send requests, receive results. - Implemented using Messenger with bound Service. - Each request is distinguished by its own request code. - Handles client-server connection and retries when request failed. - The server responds to the client’s request. - The client requests to server with callback indicating whether the request have succeeded or not. 17
whether the lock screen of the L app is active. - The L app updates the value in the DataStorage whenever the lock screen is activated or deactivated. - the M app reads the value from the DataStorage when it wants to check the status of the L app. - EventHandler - To disable the L app lock screen from the M app. - The L app implements logic that disables the lock screen as a receiver and registers it as an event. - The M app sends the event as a Sender. - RequestHandler - To retrieve BuzzScreen settings data for M apps from L apps. - The L app requests the settings data to the M app as a client. - The M app responds with the BuzzScreen settings data when it receives this request as a server. 19