| With the development of mobile Internet technology, smartphones are more and more popular and important in people’s life. Smartphones have a variety of operating system, among which Android is the most popular. However, due to the limited capacity of smartphone’s battery and the increasingly features, the energy consumption problem of Android smartphones becomes increasingly prominent, which reduces the users’ experience greatly. Researchers found that most of the unnecessary energy consumption is caused by energy bugs in Android applications. Energy bugs could cause Android smartphones to suffer an abnormal increase in power consumption. Therefore, to detect energy bugs in Android applications can help to reduce the unnecessary energy consumption, which has a practical significance.Most energy bugs of Android applications are caused by the improper use of resources, especially those high-energy components, such as WiFi, GPS, camera and so on. Existing related works considered either whether the resources are released in proper, or whether the resources are used effectively, that is, they did not fully consider the resources behavior. From the perspective of resource usage behaviors, we propose a static analysis to analyze and detect the energy bugs in Android applications, which is based on resource usage protocols.First, we use resource usage protocols to describe the proper resource usage behaviors, that is, reasonable sequences of resource actions. For example, a resource must be opened before being used, and must be closed eventually. We formalize resource usage protocols as finite state automata. Our resource usage protocols are general. Different resources can have different specific usage protocols. In addition, taking improper resource actions into account, we extend our resource usage protocols to resource usage behaviors.Second, based on our resource usage protocols, we present a static analysis to analyze and detect resource usage behaviors. Our Analysis tracks the current states of resources and the performed actions to check whether the resource behaviors conform to the corresponding protocols or not. Since our resource protocols are general, our analysis can be used to analyze not only Android phone resources(such as WIFI, GPS, etc.) but also PC platform resources(such as files, memory). Moreover, we also prove the correctness of our static analysis. And then, we use our analysis to analyze and detect energy bugs in Android applications. Our analysis takes resource usage protocols as a guide, so compared with the existing methods, our analysis can detect more improper resource usage behaviors.Finally, we implement a tool to detect energy bugs in real Android applications. Experimental results show that the tool can effectively detect energy bugs in Android applications, which false positive rate of 13.4%. Furthermore, the average runtime of our tool is about 18 s and the average memory overhead is about 1300 MB, which indicates that our tool is lightweight and easy to use in practice. |