Skip to content

Repository files navigation

Maven Central Version GitHub Issues GitHub Stars GitHub License


Droid Dex

Introduction

Droid Dex helps you make smart, device-aware decisions like:

  • Delivering high-definition images and advanced animations only to capable devices
  • Optimize layouts for mid-tier phones to prevent lag and freezes
  • Skip heavy video playback on lower-end hardware to avoid crashes

It is a powerful tool that classifies and analyzes Android device performance across multiple parameters:

PARAMETER DESCRIPTION
Core Microarchitecture, CPU Frequency, Media Performance Class, Low-End Hardware Signals
Total RAM, OEM Memory Class, Runtime Memory Pressure
Bandwidth Strength, Download Speed, Signal Strength
Available Storage
Percentage Remaining, If Phone is Charging or Not
Thermal Throttling Status, Thermal Headroom Forecast

into various levels: EXCELLENT, HIGH, AVERAGE, LOW, plus UNKNOWN for a parameter this device cannot measure (excluded from aggregation)

Droid Dex enhances your Android application's performance and elevates user experience by addressing key performance challenges such as Janky scrolling, Out of Memory (OOM) errors, High battery consumption, and Application Not Responding (ANR) instances.

More Info: https://lambda.blinkit.com/droid-dex-1f807901626f

Use Cases

  1. Battery-Aware API Polling: When background polling of an API is required, frequent requests can significantly drain the device's battery. Use the BATTERY performance level to dynamically adjust polling intervals:

    DroidDex.getPerformanceLevelLd(PerformanceClass.BATTERY).observe(this) {
       // Adjust the polling time interval
    }
  2. Adaptive Image Quality: When tailoring image quality based on device capabilities, both NETWORK and MEMORY conditions are important. Better image quality requires larger file sizes (impacting network) and generates heavier bitmaps (consuming memory). Optimize image quality delivery using weighted performance levels:

    DroidDex.getWeightedPerformanceLevelLd(PerformanceClass.NETWORK to 2F, PerformanceClass.MEMORY to 1F).observe(this) {
       // Implement image quality optimization
    }
  3. Heat-Aware Workloads: Sustained work such as video export, on-device inference or camera capture makes the device hot, and the platform then throttles it regardless of what the app wants. THERMAL reports how much sustained performance is still available, so heavy work can be scaled back before the throttling bites:

    DroidDex.getPerformanceLevelLd(PerformanceClass.THERMAL).observe(this) {
       // Shed background work, lower encode quality or pause inference as the level drops
    }

    THERMAL reports UNKNOWN below Android 10, where no public thermal API exists, and also on devices whose hardware exposes no usable thermal sensor HAL (where a real reading is unavailable rather than "not throttling"). Since UNKNOWN parameters are excluded from aggregation, THERMAL only contributes when it has a trustworthy signal, so it is safe to combine with other classes.

Usage

Initialize the library in your Application class using the following code snippet:

DroidDex.init(this) // Parameter: Application Context
  1. To get performance level for single/multiple parameters:

    DroidDex.getPerformanceLevel(params)

    For observing the changes:

    DroidDex.getPerformanceLevelLd(params).observe(this) {
    }

    Replace params with a comma-separated list of Performance Class(es).

    Example:

    DroidDex.getPerformanceLevel(PerformanceClass.CPU, PerformanceClass.MEMORY)
  2. To get performance level for multiple parameters with unequal weights:

    DroidDex.getWeightedPerformanceLevel(params)

    For observing the changes:

    DroidDex.getWeightedPerformanceLevelLd(params).observe(this) {
    }

    Replace params with a comma-separated list of Performance Classes mapped to their Weights.

    Example:

    DroidDex.getWeightedPerformanceLevelLd(PerformanceClass.CPU to 2F, PerformanceClass.MEMORY to 1F).observe(this) {
    }

See Example Project for further usage

Setup

For versions 3.+

The latest release is available on Maven Central.

implementation("com.eternal.kits:droid-dex:<<latest_version>>")

Pre-release builds are published as -betaNN (e.g. 4.0.0-beta01). Gradle treats them as pre-release versions, so dynamic versions and latest.release skip them - pin the exact string to opt in.

For versions 2.x and before

Add this to your settings.gradle[.kts] file

dependencyResolutionManagement {
	repositories {
		maven {
			url = uri("https://maven.pkg.github.com/grofers/*")
			credentials {
				username = "Blinkit"
				password = GITHUB_PERSONAL_ACCESS_TOKEN
			}
		}
	}
}

And add this dependency to your project level build.gradle[.kts] file:

implementation("com.blinkit.kits:droid-dex:<<your_version>>")

Releases

Packages

Used by

Contributors

Languages