Abstract
Android apps are event-driven, and their execution is often interrupted by external events. This interruption can cause data loss issues that annoy users. For instance, when the screen is rotated, the current app page will be destroyed and recreated. If the app state is improperly preserved, user data will be lost. In this work, we present an approach and tool iFixDataloss that automatically detects and fixes data loss issues in Android apps. To achieve this, we identify scenarios in which data loss issues may occur, develop strategies to reveal data loss issues, and design patch templates to fix them. Our experiments on 66 Android apps show iFixDataloss detected 374 data loss issues (284 of them were previously unknown) and successfully generated patches for 188 of the 374 issues. Out of 20 submitted patches, 16 have been accepted by developers. In comparison with state-of-the-art techniques, iFixDataloss performed significantly better in terms of the number of detected data loss issues and the quality of generated patches.
Introduction
Android applications operate in a highly dynamic environment where the operating system frequently interrupts execution to manage system resources. Common actions—such as rotating the screen, pressing the "Back" button, or switching to another application—trigger lifecycle events that can destroy and recreate the active "Activity" (the app's current page). Unless developers explicitly implement code to preserve the application state, any data entered by the user or generated during the session is lost.
While the concept of state preservation is fundamental to Android development, it remains a significant source of bugs. Developers face two primary challenges: the complexity of different lifecycle scenarios and the risk of "over-saving." Naive solutions that save every variable on a page can introduce significant performance overhead, leading to UI "jank" or "Application Not Responding" (ANR) errors. This paper introduces iFixDataloss, an automated framework designed to detect these issues with high precision and generate surgical, performance-conscious patches.
The iFixDataloss Framework
iFixDataloss employs a two-phase approach combining static analysis with guided dynamic exploration to identify and resolve data loss bugs.
1. Automated Detection
The detection phase begins with Static Analysis, where the tool constructs an Activity Transition Graph. This graph maps the potential navigation paths a user might take through the application. Using this map, the tool performs Guided Exploration to navigate the app dynamically. Upon reaching a UI state, iFixDataloss applies three specific "revealing strategies" to test for data loss:
- $P_{kill}$: Simulates the system killing the app process while it is in the background to reclaim memory.
- $P_{back}$: Simulates the user navigating away via the back button and subsequently returning to the page.
- $P_{rotate}$: Simulates a change in screen orientation.
An automated Oracle then compares the UI state before and after these events. If a discrepancy is found—such as a cleared text field or a reset checkbox—a data loss issue is flagged.
2. Template-Based Fixing
To avoid the performance pitfalls of saving unnecessary data, iFixDataloss utilizes template-based patching. It categorizes data into three types and applies the appropriate fix:
- Persistent Data: Saved to
SharedPreferencesto ensure it survives even across device reboots. - Session Data: Saved to a
Bundleobject, a lightweight mechanism intended for the duration of a single app run. - Non-editable Widgets: Managed via standard Android lifecycle methods like
onSaveInstanceStateto restore UI properties.
Following the generation of a patch, the tool performs a Patch Evaluation by re-running the application to verify that the data loss is resolved and that the new code does not introduce crashes or performance regressions.
Experimental Evaluation
The researchers evaluated iFixDataloss using a dataset of 66 Android apps sourced from the "Data Loss Detector" and "LiveDroid" benchmarks, as well as popular apps from the Google Play Store.
Key Results
- Detection Performance: iFixDataloss identified 374 data loss issues, 284 of which were previously undocumented. This represents a significant improvement over the previous state-of-the-art tool, DLD, which identified 152 issues on the same dataset.
- Patch Quality: The tool successfully generated 188 patches. Unlike prior tools that often suffered from low precision, iFixDataloss's patches were highly targeted, only saving the specific variables identified as vulnerable during the dynamic exploration phase.
- Real-World Impact: To test the practical utility of the tool, the authors submitted 20 automated patches to open-source developers on GitHub. 16 of these patches were accepted, with developers citing the precision and necessity of the fixes.
Discussion and Insights
A critical insight from this work is the distinction between different lifecycle events. For example, the user expectation for the "Back" button often differs from that of a "System Kill," yet both can lead to data loss if not handled correctly. Furthermore, the study quantified the cost of "over-saving." While saving all variables might seem like a safe fallback, the authors demonstrated that this can take over 300ms—well beyond the 100ms threshold required for a fluid user interface. By using dynamic witnesses to identify exactly what needs saving, iFixDataloss maintains app performance while ensuring data integrity.
Limitations and Future Work
While highly effective for GUI-visible data, iFixDataloss currently focuses less on internal program states that are not directly tied to UI widgets. Additionally, if a data loss issue involves complex dependencies that cause crashes during the patch validation phase, the tool currently discards the patch. Future iterations aim to improve the handling of these internal dependencies and refine the static analysis components to better navigate highly dynamic code execution paths.
Summary updated