TL;DR
This paper introduces DROIDSTAR, a tool that automatically learns "callback typestates" for Android classes. These typestates describe the correct sequence of method calls and asynchronous callbacks, making it easier to understand and verify Android component interactions. DROIDSTAR uses an active learning approach, significantly improving scalability for complex Android APIs.
What Problem Does This Paper Address?
Modern software, especially event-driven frameworks like Android, relies heavily on asynchronous communication. Components interact not just through direct method calls (callins), but also by responding to events via callbacks. The correct order and conditions for these interactions can be complex and are often described by finite-state machines, which the authors call "callback typestates." While crucial for understanding and verifying code, manually creating these typestates is difficult, time-consuming, and error-prone. Existing documentation often lacks this level of detail, and developers struggle to ensure they're using Android APIs correctly. This paper aims to automate the generation of these callback typestates.
Methods
The core of DROIDSTAR is an active learning algorithm, specifically an adaptation of Angluin's L* algorithm, designed for learning Mealy machines (a type of finite-state machine that produces outputs). The process involves:
- Developer-Provided Snippets: Users provide minimal code to initialize objects, define callin methods (as input symbols), and specify how to detect callbacks (as output symbols).
- Synchronous Closure: The asynchronous nature of callbacks is transformed into a synchronous model by introducing "wait" and "quiet" symbols, allowing the L* algorithm to be applied.
- Membership and Equivalence Queries: The L* algorithm interacts with the system by making "membership queries" (testing sequences of inputs and observing outputs) and "equivalence queries" (checking if the learned model matches the actual behavior).
- Distinguisher Bounds: A key innovation is the introduction of "distinguisher bounds." Instead of relying on state bounds (which can lead to computationally infeasible equivalence checks), DROIDSTAR uses a tighter bound that leverages the fact that good API design often makes states easily distinguishable. This significantly improves the scalability of equivalence queries for Android classes.
Datasets
The paper evaluates DROIDSTAR on 16 Android framework classes and classes from popular third-party libraries. These are not presented as a single, formal dataset but rather as a collection of benchmarks used for evaluation. The authors mention that DROIDSTAR is available as an Android application, implying it can be used on live Android systems.
Key Insights and Ideas
- Callback Typestates are Essential but Hard to Get: The paper clearly articulates the value of callback typestates for understanding and verifying asynchronous interactions, while also highlighting the significant manual effort required to create them.
- Active Learning for Asynchronous Systems: Adapting L* for asynchronous callback-based interfaces is a non-trivial task, requiring the "synchronous closure" transformation.
- Distinguisher Bounds are Key to Scalability: The most significant technical contribution is the concept of distinguisher bounds. This insight allows the equivalence query to be performed efficiently, making active learning practical for complex, real-world systems like Android, where state bounds would be too large.
- Undocumented Behaviors are Common: The experiments revealed that Android's documentation is not always complete or accurate, and DROIDSTAR can uncover surprising, sometimes buggy, behaviors.
Key Results
- Accuracy and Efficiency: DROIDSTAR learned callback typestates accurately and efficiently for 16 Android classes. The learning time ranged from seconds to about 72 minutes, with most classes learning in under 10 minutes.
- Small Distinguisher Bounds: In practice, the required distinguisher bounds were very small (often 1 or 2), supporting the hypothesis that well-designed APIs have easily distinguishable states. This contrasts with theoretical bounds that could be much larger.
- Discovery of Undocumented/Buggy Behavior: In several cases, DROIDSTAR identified discrepancies between the learned typestates and existing documentation. This included:
- Minor documentation errors.
- Potential race conditions and unintended behaviors in classes like
AsyncTaskandMediaPlayer. ForAsyncTask, it found that callingexecute()aftercancel()but beforeonCancelled()is received results in the task never running without throwing an exception.
Limitations and Future Work
- Assumption of Determinism: DROIDSTAR assumes deterministic behavior. While it can detect non-determinism and prompt the user for refinements, it doesn't automatically handle all forms of it.
- Bounded Asynchrony: The system relies on timeouts to detect quiescence (when no more callbacks are expected). The choice of timeout is crucial and can be application-dependent.
- Ignoring Parameters: For simplicity, the initial version of DROIDSTAR ignores callin parameters, though it notes that parameters can sometimes influence behavior and suggests defining multiple input symbols for parameterized methods.
- Non-Regular Languages: L* is designed for regular languages. For non-regular protocols, DROIDSTAR uses "learning purposes" to find regular approximations.
- Future Work: The authors plan to investigate mining callin parameters from real user interactions and inferring structured typestates (e.g., typestates as products of simpler typestates).
Summary updated