Bachelor of Science in Computer Science May 2020

Investigation of battery consumption by using Accelerometer sensor in Android: A comparative study between Unity and 4

Sesha Sai Kaushik, Upadhyayula

Faculty of Computing, Blekinge Institute of Technology, 371 79 Karlskrona, Sweden This thesis is submitted to the Faculty of Computing at Blekinge Institute of Technology in partial fulfilment of the requirements for the degree of Bachelor of Science in Computer Science. The thesis is equivalent to 20 weeks of full time studies.

The authors declare that they are the sole authors of this thesis and that they have not used any sources other than those listed in the bibliography and identified as references. They further declare that they have not submitted this thesis at any other institution to obtain a degree.

Contact Information: Author(s): Sesha Sai Kaushik, Upadhyayula [email protected]

University Advisor: Anwar, Mahwish [email protected] Department of Compter Science

Faculty of Computing Internet : www.bth.se Blekinge Institute of Technology Phone : +46 455 38 50 00 SE–371 79 Karlskrona, Sweden Fax : +46 455 38 50 57 Abstract

Smartphones consist of various applications and their development has increased in the past years. Several applications that are developed using game engines rely upon sensors that use plenty of battery life. This study evaluates the battery performance of two popular game engines by developing applications with usage of Accelerometer sensor and to find the most battery friendly engine. Unity and Unreal Engine 4 were selected for this study. It aims to fill how Game Engines performance differs when integrated with Accelerometer usage. Two similar test applications were developed in each for the experiment and the battery values were recorded by AccuBattery. All these tests were performed to find out which game engine is battery friendly when integrated with the sensor and also compares how battery consumption differs in the game engines with and without sensor integration. The results show that Unity consumed 5.4 %(243 mAh) battery and Unreal Engine consumed 6.6 %(297.5 mAh) battery when applications were run at a frame lock of 60 FPS. When the tests were conducted at a frame lock of 30 FPS Unity consumed 1.84 % (82.8 mAh) battery and the Unreal Engine consumed 1.29 % (58.05 mAh) battery. These test results were analyzed with a previous study that compared Unity and Unreal Engine battery performance without any sensor integration. This test resulted in the Unreal Engine being battery-friendly when integrated sensor usage.

Keywords: Unreal Engine, Unity, Android, Accelerometer, Sensors, Engine performance Acknowledgments

I would like to express my sincere gratitude to my supervisor Mahwish Anwar for her valuable guidance and support during my Bachelor Thesis. This work would not be possible without her guidance and support. I would like to thank my parents for their everlasting love and blessings. I would like to thank my siblings and friends for their moral support through tough times.

ii Contents

Abstract i

Acknowledgments ii

1 Introduction 2

2 Background and Related Work 3 2.1Unity...... 3 2.2 Unreal Engine 4 ...... 4 2.3 Related Work ...... 4

3 Research Questions and Method 5 3.1 Research Questions ...... 5 3.1.1 Research Method ...... 5 3.1.2 Development Environment and Settings ...... 5 3.1.3 Test Application Implementation ...... 6 3.1.4 Test Device ...... 8

4 Results and Analysis 9 4.1 Results ...... 9

5 Discussion 12 5.1 Limitations ...... 13

6 Conclusions and Future Work 14

7 Appendix 15

References 18

iii List of Figures

3.1 Mapping input in Unity ...... 6 3.2 Mapping input in Unreal ...... 7 3.3 Blueprint in Unreal ...... 7

4.1 Test results for applications run at 60 FPS ...... 9 4.2 Test results for applications run at 30 FPS ...... 10 4.3 Test results for applications ...... 11

7.1 Unity camera ...... 15 7.2 Unreal camera ...... 15 7.3 Unreal application quality ...... 16 7.4 Unity application quality ...... 16 7.5 Unity FPS control ...... 16 7.6 Unreal FPS control ...... 17 7.7 Unity accelerometer code ...... 17

iv List of Tables

3.1 Specifications ...... 8

1 Chapter 1 Introduction

Android has become one of the most used platforms in smartphones. There are over two billion smartphones that run on Android [1]. Android offers the play store which houses millions of applications, ranging from social applications such as Facebook, Instagram, to games such as PUBG, Sky, etc. In recent years there has been an increase in the number of applications released in play store [2] of which approximately 0.3% new games are added each quarter [3]. Android games are developed using game engines that are optimised for Android development. One of the major compromises of Android games is that they consume substantial battery [4]. There are many games available for Android, the level of optimisation and battery consumption might be different for each game, respectively. Most of the games are designed by using game engines that provide a basic template to design an application in Android. Unreal Engine and Unity are two of the most used game engines for Android game development. Each game engine provides different kinds of optimisations, some of which are built in the engine while some can be set by the developer. Accelerometer is used to measure the linear acceleration of the device [5]. It is widely used in developing games which track movements of the device in the developed application environment. The level of optimisations can be of several types such as graphical, level, build, and compile optimisations. Developers use sensors in an Android application to create an interaction between the user and the application. Sensor integrations lead to an increase in battery consumption. Sensor integrated applications should contain optimisations for typical usage and graphical inputs by adding extra layers to the existing Android optimisations, which can increase the battery life of the smartphone. Battery optimisations are frequently done for hand-held devices because applica- tions tend to consume as much power it receives in any other platform. So, battery optimisations must be done and it plays an essential role in smartphone performance as it leads to longer battery life. This study is inspired by [6] where the research was conducted on the battery performance of Unity and Unreal Engine on Android with limitation to sensor usage. This work will overcome the identified limitation by investigating the impact on battery consumption when the Accelerometer sensor is integrated with the application.

2 Chapter 2 Background and Related Work

Android is an operating system developed for hand-held devices. The first Android phone was released in 2008. All the smartphones launched in this period were prone to short battery life [7]. Optimisations were made to decrease the battery consumption in the software that extended the battery life of the devices. Smartphones now last for around 5-8 hours with heavy usage. More and more optimisations are being developed to increase the functionality, privacy of the smartphones which are rolled out in the form of updates. Android games tend to use hefty amounts of battery to provide the best quality and performance to the user. Specific optimisations can decrease battery consumption such as lower graphical input, frame rate, etc. The battery optimisation can increase the screen time of the device but compromises the performance of the application and vice versa. Another factor that influences battery consumption is its background applications. Certain applications such as UI, Android Web View, etc. run in the background and results to battery consumption. Games downloaded from the play store also consume battery until they are loaded in the memory of the phone. Games are developed for Android by using game engines where Unreal Engine and Unity are popular choices for game development.

2.1 Unity

Unity game engine was launched in the year 2005 in Mac OS X. In the year 2008 when the App Store was launched for the iPhone, Unity added support for iPhones. In 2010, Unity was released for development in Android, PC, and Consoles. It provides developers with API(Application Program Interface) and frameworks. Fractal was the first game to be developed in Unity for iOS and Android [8][9]. Key Features of Unity connected to this thesis are:

• All-in-One Editor and configured 3D objects and shapes.

• Native C++ which can be used for multi-platform support.

• Easy control over design and placing objects and scaling.

• Control over Android sensors with coding using Android development API.

• Real-time graphics rendering.

3 Chapter 2. Background and Related Work 4 2.2 Unreal Engine 4

Unreal Engine was launched in 1998. It was initially developed for first-person shooters but also used in other genres of development. Unreal Engine 2, released in 2008 added features like skeletal animation and physical simulations. Unreal Engine 3 was released in 2004 with fully programmable shader hardware, lighting, and shadowing effects per pixel. It stepped into Android and iOS game development in 2010 with Infinity Blade and Dungeon Defenders being the first games in the respective platforms. The latest Unreal Engine 4 was released in 2012 [10][11]. Key features of Unreal Engine 4 connected to this thesis are:

• Create without Code using Blueprints.

• Realistic graphics rendering in real-time.

• 3D support.

• Android development kit to make use of Android features and sensors.

• Easy accessible setup for application performance settings and quality.

2.3 Related Work

Some of the factors that influence battery consumption consists of mobile sensors such as Bluetooth, Global Positioning System(GPS), Near Field Communication(NFC), and other sensors available on the smartphone. To inform users about abnormal battery consumption caused due to background processes an application called Carat was developed. The application developers also have conducted a study on how to automate the process of running diagnostics on energy anomalies. Data from around 500,000 devices were collected and compared with similar devices. By generating a report on how the user can improve their battery life, Carat improved the battery life of the users by 21% [12]. Some applications use graphics as well as sensor data such as Google Maps, Doodle Jump, Pókemon GO, where Google Maps and Pókemon GO use the GPS sensor and Doodle jump uses the accelerometer sensor. No matter how optimized these applications are they consume more battery because they rely on the sensor data to provide a precise output to the user [13]. Nilsson. et. al. conducted a study on battery performance comparison of Unity and Unreal Engines where applications were developed in the respective engines and their battery consumption was recorded to obtain the engine which consumes lesser battery [6]. The previous two studies addressed how sensors affect the battery life of a smart- phone and how different gaming engine applications affect the battery life of an Android device. There are no studies that focus on sensors battery usage along with application battery usage in Android. This thesis aims to find how different game engines affect the battery life of smartphones when integrated with sensor usage. This study will give an insight to developers on how different game engines manage the sensor data and battery in the Android platform. Chapter 3 Research Questions and Method

3.1 Research Questions

The goal of the thesis relates to the following questions RQ 1: Which of the two engines namely Unity and Unreal Engine 4 utilize more battery when integrated with a Accelerometer sensor? To answer this an application that uses accelerometer sensor on both engines was developed. The application was run, and the battery consumption of both the engines were compared to identify the engine that consumes more battery. RQ 2: How does the sensor integration in Unity and Unreal Engine 4 impact the battery consumption of a device? To answer this we compared the results with data from previous research [6], where battery consumption of applications developed in Unity and Unreal game engines are recorded.

3.1.1 Research Method To answer the research questions, an experimental evaluation is conducted. Applica- tions are developed in Unity and Unreal Engine 4 with accelerometer sensor. The battery usage of the application from each engine is recorded using AccuBattery [14].

3.1.2 Development Environment and Settings Before developing applications, Unity and Unreal engines were studied to understand their working and features. A set of common features were identified in both engines to be able to have a common denominator to compare the battery performance in both the engines. To execute the study, the game engines must be set up in an order which can produce a comparable and similar output in both the engines. Hence, the setup of these game engines in a similar manner is vital to produce comparable results. The implementation of the applications is done by using Unity version 2019.3.7f1 and Unreal Engine 4.24.3 which are the latest versions of both gaming engines at the time of implementation. Since this thesis compares the builds of two game engines, the engines must have the same preconditions. Settings like resolution, game quality, Screen orientation must be alike in both the engines. The games were locked to 30 and 60 FPS(Frames Per Second) in two test cases, Unreal Engine 4 provided with pre-implemented FPS setting while Unity needed an

5 Chapter 3. Research Questions and Method 6

Figure 3.1: Mapping input in Unity

’FPS’ script. Coding in Unity was done using Visual Studios. To create an application in Unreal Engine 4 it follows as: create a new project > Blank > Select Mobile/Tablet > Set name > start implementing. Creating a project in Unity follows as: create new project > Set name > select 2D or 3D > start implementing. The applications developed in these engines have similar backgrounds and actors.

3.1.3 Test Application Implementation By using the rolling ball scenario, applications are developed for testing where the sphere acts as the actor which moves according to the accelerometer values from the device. There are certain obstructions placed in the map which are 3D cubes and contain certain boundaries in the form of walls, so the ball remains in a certain boundary. In Unity, the data from the accelerometer is obtained from the script ’Acelero’(see Figure 7.7) which contains the code required to gather the data from the sensor. The script will only be implemented when it is added as a component to the actor. As shown in Figure 3.1 the sphere is the actor that needs to have the script attached to obtain movement according to the sensor data. In Unreal Engine the data can be accessed by clicking on window > project settings > inputs, and by adding gravity as an input to the actor. By doing this the accelerometer sensor will obtain the values, cause forward/backward motion and left/right motion of the object. The given inputs can be accessed in the sphere blueprint by using InputAxis MoveRight and InputAxis MoveForward functions, as in Figure 3.2, for the inputs which give the axis values of the sensors. Roll Torque is the speed of the sphere. The Roll torque and input are joined to Make vector function that will return the torque value for the sphere movement through Add Torque in Radius function which has a Chapter 3. Research Questions and Method 7

Figure 3.2: Mapping input in Unreal

Figure 3.3: Blueprint in Unreal Chapter 3. Research Questions and Method 8 target and torque inputs. In Figure 3.3, Ball represents the sphere. The camera is in a fixed position where the movement of the sphere can be seen throughout the map in both the applications. The maps created and objects used in both the engines have similar behavior.

3.1.4 Test Device All tests were performed on a Samsung Galaxy A70 and these tests were conducted after turning off all the other features like Wi-Fi, Location, Bluetooth, Always on Display, NFC, and Power saving. The RAM was cleared before running the tests. During the tests, only two applications were running, which were AccuBattery [14] and the developed application. The phone always had the battery percentage in between 65 to 100. Due to the limited availability of resources, the experiments were conducted on the available device at the time of experimentation. The detailed specifications of the device are shown in table 3.1.

Model number: SM-A705GM Operating System: Android 10, Samsung One UI 2.0 Resolution: HD 1080p Processor: Qualcomm Snapdragon 675 2.02 GHz Storage:128 GB RAM:6GB

Table 3.1: Specifications Chapter 4 Results and Analysis

We discuss the results obtained from each application’s test runs and they are compared with each other.

4.1 Results

The Figures in this section represent the results obtained from running the test applications where the blue bars indicate Unity and red bars indicate the Unreal engine. The results are represented in the form of how much battery percentage is used. The tests are performed in a Samsung Galaxy A-70 which has a battery capacity of 4500 mAh, which means that 1% of battery usage is around 45 mAh. All the applications were tested five times and the average was calculated excluding the extreme values to ensure normal test results. The tests were conducted on two different conditions where Figure 4.1 consists of the application results which were given frame lock to 60 FPS and Figure 4.2 consists of application results which were run at 30 FPS.

8.7 8.4 8

6.46.4 6.1 6 5.6 5.1 4.7 4.6

Battery Percentage 4.5 4

test1 test2 test3 test4 test5 Unity Unreal

Figure 4.1: Test results for applications run at 60 FPS

In Figure 4.1, we can see the number of tests conducted and their battery usage for both the applications. The applications were locked to 60 FPS and had a huge difference in battery consumption. This test was conducted as there are many games

9 Chapter 4. Results and Analysis 10 that run in 60 frames and use the sensor data, this test can serve as an example for a feature rich game. In these tests, Unity has consumed an average of 5.44 % of the battery. The Unreal Engine 4 consumed an average of 6.6 % of the smartphones battery.The Unreal Engine produced some inconsistent battery usage values in some of the test runs and they were removed inorder to analyze the normal values of the application. The tests for 60 FPS application was done for thirty minutes.

2 1.9 1.9 1.81.8 1.7 1.51.5 1.5 1.3 1.35

1

Battery Percentage 0.8

test1 test2 test3 test4 test5 Unity Unreal

Figure 4.2: Test results for applications run at 30 FPS

In Figure 4.2 we can see that there is a change in the results obtained from the tests. The tests for 30 FPS application was done ten minutes and their battery usage was recorded from Accubattery [14]. From the obtained results and by calculating their average battery consumption values, Unity consumed an average of 1.84 % and the Unreal Engine consumed an average of 1.29 % battery. As the setup for this experiment is similar to [6], The test results at 30 FPS can be compared with the previous results that were obtained from Nilssons study [6], where battery performance of Unity and Unreal Engine were compared. Nilsson.et.al compared the engines in terms of 2D objects, 2D multiple objects, 3D objects, and constraints. Figure 4.3 shows the comparison of results obtained in this study and [6]. Both have Single 3D moving object and Multiple cubes in 3D. The combined averages of the two categories were calculated from the previous study [6] and compared to experimental values achieved in this study. The averages were 1.25% and 1.45% for Unity and Unreal Engine respectively. These average values are compared with the results obtained in this experiment which are 1.84% and 1.29% for Unity and Unreal Engine respectively. In Figure 4.3, one can see an observable change in the performance of the engines. In the previous study [6], Unity had a more battery- friendly performance but, when sensor integration comes into the picture Unreal Engine was more battery-friendly compared to Unity. This leads to the conclusion that under sensor load, Unity consumes more battery life than the Unreal engine. Chapter 4. Results and Analysis 11

1.84 1.8

1.6 1.45 1.4 1.29

Battery Percentage 1.25 1.2

Unity Unreal Nilsson [6] Sesha (This study)

Figure 4.3: Test results for applications Chapter 5 Discussion

Looking at the results, it can be observed that Unity has used a substantial amount of battery than the Unreal Engine at 60 FPS in the experiment. This means that for every 10 minutes, the Unity application consumed about 1.82 % that translates to 81.9 mAh and the Unreal application consumed about 1.29 %which converts to 58.05 mAh. There is a difference of 23.85 mAh that is consumed every ten minutes by Unity, which means that for every half hour of application usage, the Unity application consumes about 243 mAh of extra battery life which is very huge and may affect the battery performance of the device in extensive usage. The Unreal engine, on the other hand, has produced very promising battery values and if used for thirty minutes, it consumes a battery of 174.15 mAh battery which brings out a 68 mAh gap between the power consumptions of the game engines. The first experiment was conducted with a frame lock of 60 FPS. Each test was conducted for thirty minutes because on average a person spends thirty minutes a day in games [15]. This experiment resulted in Unity being more battery-friendly than the Unreal engine. This was conducted to inspect how different frame rates affect the battery of the device. The first few tests provided a similar output. There was a sudden jump in battery consumption of the Unreal Engine in the second test but, Unity continued to provide similar values. The Unreal Engine was unable to provide optimised result values when tested continuously. Several inconsistent values were neglected to analyze the normal usage of the application. The second experiment was conducted at a frame lock of 30 FPS and each test was conducted for ten minutes. This experiment resulted in the Unreal Engine being more battery-friendly than Unity. The obtained results were compared with the previous study [6] to obtain a result on how the game engines differ with and without integrated sensor usage. The tests conducted in the second experiment were used to contrast with existing results on the engines and find out which game engine is optimized for sensor usage. The second experiment results were very different from the previous study values. The previous study concluded that Unity consumed less battery than Unreal. By analyzing the second experiment values and previous study results we can say that the Unreal Engine used less battery when compared to Unity.

12 Chapter 5. Discussion 13 5.1 Limitations

There are certain limitations in the study such as the similar components in both game engines may behave differently in different scenarios. The sphere is common in both the engines but contains different layers. In Unity the sphere will not be a rigid body, it must be applied from the inspector menu. In Unreal the sphere will be a rigid body when placed on the plane. The colors used in both the applications are similar but may have different visual outputs when they are run on the device. This study was conducted on the accelerometer sensor. The results could be different if any other sensor is used. The size of the application can also be a limitation as there will be certain fixed background processes that cannot be controlled and may increase or decrease the battery usage of the application. Chapter 6 Conclusions and Future Work

To answer the research questions, we can conclude that there is a small variation between the battery usage of the applications. There are some components such as a sphere that is always in a state of motion and may have an impact on battery consumption. All the components used in the applications are 3D objects and affect battery consumption. Unity engine consumed more battery than the Unreal Engine in all the tests conducted regarding the battery consumption, making the Unreal Engine more battery-friendly for a game that uses sensor input on Android at 30 FPS. But, when the applications are run at 60 FPS the Unreal Engine has more battery usage than Unity. Some elements may result in a different conclusion, such as the effect of background applications in overall battery consumption. This study can be improved further by adding more components and sensors in the engines. There are also many other sensors available in a smartphone that can be useful for applications and consume less battery life. After conducting the experiment we have known that an increase in Performance will increase battery usage. This thesis is limited to single sensor usage which can be extended to multiple sensors battery usage which are not tested in this study but, may provide interesting results on how the sensors affect the battery life of the smartphone.

14 Chapter 7 Appendix

Figure 7.1: Unity camera

Figure 7.2: Unreal camera

15 Chapter 7. Appendix 16

Figure 7.3: Unreal application quality

Figure 7.4: Unity application quality

Figure 7.5: Unity FPS control Chapter 7. Appendix 17

Figure 7.6: Unreal FPS control

Figure 7.7: Unity accelerometer code References

[1] Moutaz Alazab, Mamoun Alazab, Andrii Shalaginov, Abdelwadood Mesleh, and Albara Awajan. Intelligent mobile malware detection using permission requests and api calls. Future Generation Computer Systems, 107:509–521, 2020.

[2] Number of android apps. Online: https://www.appbrain.com/stats/number-of- android-apps.

[3] Global games market revenues 2018 | per region & segment | newzoo. shorturl. at/dCJOZ. (Accessed on 05/20/2020).

[4] Zengwen Yuan. The future of devices: A reality check. XRDS: Crossroads, The ACM Magazine for Students, 26(1):8–9, 2019.

[5] Motion sensors | android developers. https://developer.android.com/ guide/topics/sensors/sensors_motion. (Accessed on 06/08/2020).

[6] Robin Nilsson. Battery performance comparison of unreal engine 4 and unity applications running on android, 2019.

[7] Xinbo Chen and Ziliang Zong. Android app energy efficiency: The impact of language, runtime, compiler, and implementation. In 2016 IEEE interna- tional conferences on big data and cloud computing (BDCloud), social com- puting and networking (socialcom), sustainable computing and communications (sustaincom)(BDCloud-socialcom-sustaincom), pages 485–492. IEEE, 2016.

[8] John K Haas. A history of the unity game engine. 2014.

[9] Unity Game Engine. Unity game engine-official site. Online][Cited: October 9, 2008.] http://unity3d. com, pages 1534–4320, 2008.

[10] Andrew Sanders. An introduction to unreal engine 4. CRC Press, 2016.

[11] Epic Games. Unreal engine. Online: https://www. unrealengine. com, 2007.

[12] Adam J Oliner, Anand P Iyer, Ion Stoica, Eemil Lagerspetz, and Sasu Tarkoma. Carat: Collaborative energy diagnosis for mobile devices. In Proceedings of the 11th ACM Conference on Embedded Networked Sensor Systems, pages 1–14, 2013.

[13] A first inside look at pokémon go battery drain. you won’t catch many, if your battery dies so quickly. – mobile enerlytics. shorturl.at/akwIS.

18 [14] Accubattery app. https://accubatteryapp.com/.

[15] On their tenth anniversary, mobile apps start... | flurry blog. https://www.flurry.com/post/155761509355/ on-their-tenth-anniversary-mobile-apps-start. (Accessed on 05/18/2020). Faculty of Computing, Blekinge Institute of Technology, 371 79 Karlskrona, Sweden