Posted by Nevin Mital – Developer Relations Engineer, Android Media
The Android ecosystem includes a various vary of units, and it may be tough to construct experiences that benefit from new or premium {hardware} options whereas nonetheless working effectively for customers on all units. With Android 12, we launched the Media Efficiency Class (MPC) commonplace to assist builders higher perceive a tool’s capabilities and determine high-performing units. For a refresher on what MPC is, please see our final weblog submit, Utilizing efficiency class to optimize your person expertise, or take a look at the Efficiency Class documentation.
Earlier this yr, we revealed the first steady launch of the Jetpack Core Efficiency library because the really useful answer for extra reliably acquiring a tool’s MPC degree. Particularly, this library introduces the PlayServicesDevicePerformance class, an API that queries Google Play Providers to get essentially the most up-to-date MPC degree for the present system and construct. I’ll get into the technical particulars additional down, however let’s begin by having a look at how Google Maps was in a position to tailor a characteristic launch to finest match every system with MPC.
Efficiency Class unblocks premium expertise launch for Google Maps
Google Maps lately took benefit of the expanded system protection enabled by the Play Providers module to unblock a characteristic launch. Google Maps wished to replace their UI by rising the transparency of some layers. Consequently, this meant they would wish to render extra of the map, and located they needed to cease the rollout resulting from latency will increase on many units, particularly in direction of the low-end. To resolve this, the Maps workforce began by slicing an current key metric, “seconds to UI merchandise visibility”, by MPC degree, which revealed that whereas all units had a small improve on this latency, units with out an MPC degree had the most important improve.
With these ends in hand, Google Maps began their rollout once more, however this time solely launching the characteristic on units that report an MPC degree. As units proceed to get up to date and meet the bar for MPC, the up to date Google Maps UI will probably be out there to them as effectively.
The brand new Play Providers module
MPC degree necessities are outlined within the Android Compatibility Definition Doc (CDD), then units and Android builds are validated in opposition to these necessities by the Android Compatibility Check Suite (CTS). The Play Providers module of the Jetpack Core Efficiency library leverages these check outcomes to repeatedly replace a tool’s reported MPC degree with none further effort in your finish. This additionally implies that you’ll instantly have entry to the MPC degree for brand new system launches with no need to accumulate and check every system your self, because it already handed CTS. If the MPC degree just isn’t out there from Google Play Providers, the library will fall again to the MPC degree declared by the OEM as a construct fixed.
As of writing, greater than 190M in-market units protecting over 500 fashions throughout 40+ manufacturers report an MPC degree. This protection will proceed to develop over time, as older units replace to newer builds, from Android 11 and up.
Utilizing the Core Efficiency library
To make use of Jetpack Core Efficiency, begin by including a dependency for the related modules in your Gradle configuration, and create an occasion of DevicePerformance. Initializing a DevicePerformance ought to solely occur as soon as in your app, as early as potential – for instance, within the onCreate() lifecycle occasion of your Utility. On this instance, we’ll use the Google Play companies implementation of DevicePerformance.
// Implementation of Jetpack Core library. implementation("androidx.core:core-ktx:1.12.0") // Allow APIs to question for device-reported efficiency class. implementation("androidx.core:core-performance:1.0.0") // Allow APIs to question Google Play Providers for efficiency class. implementation("androidx.core:core-performance-play-services:1.0.0")
import androidx.core.efficiency.play.companies.PlayServicesDevicePerformance class MyApplication : Utility() { lateinit var devicePerformance: DevicePerformance override enjoyable onCreate() { // Use a category derived from the DevicePerformance interface devicePerformance = PlayServicesDevicePerformance(applicationContext) } }
Then, later in your app once you wish to retrieve the system’s MPC degree, you’ll be able to name getMediaPerformanceClass():
class MyActivity : Exercise() { non-public lateinit var devicePerformance: DevicePerformance override enjoyable onCreate(savedInstanceState: Bundle?) { tremendous.onCreate(savedInstanceState) // Be aware: Good app structure is to make use of a dependency framework. See // https://developer.android.com/coaching/dependency-injection for extra // data. devicePerformance = (utility as MyApplication).devicePerformance } override enjoyable onResume() { tremendous.onResume() when { devicePerformance.mediaPerformanceClass >= Construct.VERSION_CODES.UPSIDE_DOWN_CAKE -> { // MPC degree 34 and later. // Present essentially the most premium expertise for the very best performing units. } devicePerformance.mediaPerformanceClass == Construct.VERSION_CODES.TIRAMISU -> { // MPC degree 33. // Present a top quality expertise. } else -> { // MPC degree 31, 30, or undefined. // Take away extras to maintain expertise useful. } } } }
Methods for utilizing Efficiency Class
MPC is meant to determine high-end units, so you’ll be able to anticipate to see MPC ranges for the highest units from every year, that are the units you’re prone to need to have the ability to help for the longest time. For instance, the Pixel 9 Professional launched with Android 14 and experiences an MPC degree of 34, the newest degree definition when it launched.
You need to use MPC as a complement to any current Gadget Clustering options you already use, akin to querying a tool’s static specs or manually blocklisting problematic units. An space the place MPC generally is a significantly useful device is for brand new system launches. New units ought to be included at launch, so you need to use MPC to gauge new units’ capabilities proper from the beginning, with no need to accumulate the {hardware} your self or manually check every system.
An incredible first step to become involved is to incorporate MPC ranges in your telemetry. This may also help you determine patterns in error experiences or usually get a greater sense of the units your person base makes use of if you happen to phase key metrics by MPC degree. From there, you would possibly think about using MPC as a dimension in your experimentation pipeline, for instance by establishing A/B testing teams primarily based on MPC degree, or by beginning a characteristic rollout with the very best MPC degree and dealing your method down. As mentioned beforehand, that is the method that Google Maps took.
You could possibly additional use MPC to tune a user-facing characteristic, for instance by adjusting the variety of concurrent video playbacks your app makes an attempt primarily based on the MPC degree’s concurrent codec ensures. Nevertheless, be certain to nonetheless question a tool’s runtime capabilities when utilizing this method, as they could differ relying on the atmosphere and state the system is in.
Get in contact!
If MPC sounds prefer it may very well be helpful to your app, please give it a strive! You will get began by having a look at our pattern code or documentation. We welcome you to share any questions or suggestions you’ve gotten on this brief kind.
This weblog submit is part of Digicam and Media Highlight Week. We’re offering sources – weblog posts, movies, pattern code, and extra – all designed that can assist you uplevel the media experiences in your app.
To study extra about what Highlight Week has to supply and the way it can profit you, be sure you learn our overview weblog submit.