arXiv:2611.00296cs.SEOct 2026

Manuscript Offprint

arXiv:2611.00296

Hardware-Aware Conditional Code in Android Apps

Marco Alecci, Jordan Samhi, Li Li, Tegawendé F. Bissyandé, Jacques Klein

MARCO ALECCI, SnT, University of Luxembourg, Luxembourg

JORDAN SAMHI, SnT, University of Luxembourg, Luxembourg

LI LI, School of Software, Beihang University, China

TEGAWENDÉ F. BISSYANDÉ, SnT, University of Luxembourg, Luxembourg

JACQUES KLEIN, SnT, University of Luxembourg, Luxembourg

Android OS runs on a highly diverse set of devices, spanning entry-level phones and flagships with substantially different hardware characteristics, including memory capacity, processors, displays, cameras, and sensors. Through APIs, apps can query device information at runtime, such as memory, hardware features, and manufacturer, among other device properties, allowing developers to execute different code paths on different devices. Existing studies cover only specific compatibility bugs or brand-specific behavior; however, the broader use of hardware information in app logic has not been comprehensively explored.

We address this question with a large-scale empirical study of hardware-related if statements in Android apps. We statically analyze 50 000 apps to identify the if statements whose conditions depend on the values of hardware-related APIs, and extract their conditions together with the code of their branches. Our results show that 95% of successfully analyzed apps contain at least one such statement, with an average of 74 per app, which suggests that hardware-related logic is widespread. We then apply an LLM-assisted open-coding process to the extracted code to build a structured taxonomy of the purposes behind hardware-related conditional code. The resulting characterization shows that developers use hardware information for feature availability checks, UI adaptation, emulator detection, device tiering, and resource management, among others.

1 Introduction

Android OS is used across a large and highly diverse ecosystem of devices. Its open-source nature, through the Android Open Source Project (AOSP), allows device manufacturers to adapt and customize the platform for their products [13]. As a result, Android applications (apps) execute on a wide variety of devices with different hardware characteristics, e.g., memory capacity, processors, displays, cameras, and sensors, as well as manufacturer-specific system customizations. This heterogeneity is also reflected in the wide range of market segments, from entry-level smartphones priced at around 40 USD in emerging markets to top-tier devices costing around 2000 USD [16, 21, 36]. Already in 2015, more than 24 000 distinct Android devices from over 1200 manufacturers had been observed in the wild [31]. More recently, a study published by Google Research reported that Android runs on over 3 billion active devices worldwide and analyzed 904 distinct devices from 6 major OEMs [17]. Such diversity challenges developers, as the same app may run on devices with substantially different hardware capabilities.

Android provides several mechanisms to help developers support heterogeneous device configurations without explicitly inspecting them in app code. For instance, developers can provide alternative resources for different screen sizes and densities, which Android selects according to the current device configuration [10]. Similarly, Android App Bundles allow Google Play to tailor the APKs delivered to each device [9]. Rather than delivering the same APK to every device, Google Play can install a base APK together with configuration-specific split APKs containing resources and native libraries for the device's screen density, CPU architecture, and language. Nevertheless, developers are not limited to these mechanisms. Indeed, Android exposes APIs that provide information about the device hardware and configuration. For example, ActivityManager.isLowRamDevice() indicates whether the app is running on a low-RAM device [8], while

Authors' Contact Information: Marco Alecci, SnT, University of Luxembourg, Luxembourg; Jordan Samhi, SnT, University of Luxembourg, Luxembourg; Li Li, School of Software, Beihang University, China; Tegawendé F. Bissyandé, SnT, University of Luxembourg, Luxembourg; Jacques Klein, SnT, University of Luxembourg, Luxembourg.

APIs such as Build.MODEL expose information about the device model [11]. Similar APIs provide access to display properties, available hardware features, supported CPU architectures, camera capabilities, sensors, and other device characteristics. Developers may use this information to make implementation decisions, for example, by disabling memory-intensive functionality on low-RAM devices, selecting implementations based on available hardware features, or applying workarounds to specific device models. Recent work has indeed provided evidence that the same Android app can exhibit different behaviors across different devices [19], but considers only behavior conditioned by device-identity information in Chinese app markets. Our goal is to characterize hardware-related if statements beyond device identity, covering memory, display, capability, camera, sensor, and CPU-related APIs. Other existing studies have investigated Android fragmentation and compatibility issues by focusing on specific cases of device- or API-induced failures and their handling [23, 43, 45]. However, we still have limited knowledge of how developers explicitly use hardware-related information to make such decisions in their code. In particular, it remains unclear which hardware-related information developers use in the conditions of if statements and, more importantly, what motivates such hardware-related conditional code. This raises our central question: how do Android developers use hardware-related information to shape the conditions and branches of if statements?

In this paper, we conduct a large-scale empirical study of hardware-related if statements across 50 000 Android apps and 85 Android APIs. We first use static analysis to identify hardware-related APIs whose values influence the conditions of if statements and, for each such statement, extract its condition and the code executed along its two branches. Our results show that 95% of successfully analyzed apps contain at least one such statement, with an average of 74 statements per app, suggesting that hardware-related logic is widespread in Android apps. We then leverage a Large Language Model (LLM) as an assistant to summarize this code context and support an open-coding process aimed at identifying why developers make decisions based on hardware information. We manually consolidate the resulting reasons into a structured taxonomy of motivations for hardware-related conditional code, including emulator-environment handling, compatibility handling, and resource management, among others. One particularly interesting case is device tiering, whereby apps assign a device to a specific tier or category that can subsequently be reused throughout the codebase to guide later decisions. Overall, our study characterizes how Android developers use hardware information to adapt app behavior across heterogeneous devices, showing that such code can complicate dynamic testing, increase compatibility risks, and lead to different user experiences across devices.

Contributions. We make the following key contributions:

  • We present the first large-scale empirical characterization of hardware-related if statements in Android apps. By analyzing 50 000 APKs, we show that 95% of successfully analyzed apps contain at least one hardware-related if statement, with an average of 74 statements per app.
  • We develop an LLM-assisted open-coding process to identify the motivations behind developers' choices, which are then manually consolidated into a structured taxonomy comprising 53 motivations organized into 14 domains such as Emulator and test environment handling, Device tiering and memory adaptation, and Vendor, model and ROM adaptation, among others.
  • We present real-world app examples showing how hardware-related APIs concretely affect app behavior, such as by controlling resource configurations on low-end devices, selecting vendor-specific code paths, and defining custom device tiers that can be reused across the app.
  • We release our taxonomy and all supporting research artifacts to the community to facilitate reproducibility and further research as described in the Data Availability statement.

References (15)