Unlike traditional computing platforms (such as desktops and servers), mobile platforms provide a volatile running environment for apps where the state of an app may get destroyed and recreated frequently, either by runtime configuration changes (e.g., changing the phone orientation) or by limited resources available on the device (e.g., low memory). When the app state is not saved and restored appropriately, the app restarts may cause a wide range of runtime issues, ranging from loss of user progress and poor responsiveness to malfunctioned UI and app crashes. The goal of this thesis is to address the fundamental issue of state management for mobile apps. To achieve the above goal, this thesis proposes a runtime system and a novel static analysis.
First, it studies a large number of real-world mobile apps, a high percentage of them fail to handle restarts appropriately, posing a great challenge to mobile computing. To address the state issues caused by app restarts, this thesis explores two orthogonal directions: (i) a system-oriented solution and (ii) an application-oriented solution.
In the first direction, it aims to prevent apps from restarting by developing a restart-free runtime system, called RuntimeDroid, which completely avoids the needs of configuration-related app restarts. The purpose of restarts in the existing runtime system is to load resources for the new configuration (e.g., a layout for the portrait mode). RuntimeDroid achieves this by automatically identifying and "hot"-loading the resources while the app is running.
In the other direction, this thesis approaches the state issues with a more direct solution -- first, identify the necessary app state, then automatically preserve it at runtime. More specifically, it first uses static analysis to systematically reason about the app source code and the associated resource files to find the critical program variables and properties of GUI elements that are necessary to be preserved. Then, it leverages automatic code generation techniques to insert the state saving and restoring routines to the app code. As a result, a tool (named LiveDroid) can precisely identify and preserve the app state in real-world Android apps, which not only ensures the state correctness during app restarts but also makes the app restarts more responsive.
Besides the above, this thesis also proposes the static user transaction graph (SUTG), which leverages static analysis to encode operations of interests in the form of a graph. SUTG can serve as the basis for a variety of mobile app testing tools, such as latency profiling and state testing in the presence of asynchronous threads. As a result, the automated tools help developers to identify performance bottlenecks and incorrect state handling in their apps.