Repository navigation
Description
Part of #485.
Scope
A profile made in Android Studio's device manager is fitted to images by everything Android Studio saved for it: its API range, its Play Store setting and its screen size, besides the device type #489 already uses. After this PR a custom profile that needs API 31 or newer is never created on API 30, as in Android Studio.
In short
Android Studio saves a custom profile in ~/.android/devices.xml. avdmanager list device reads that file too and lists the profile with OEM : User, but prints only its name, id and device type (Tag :). Simlock now reads the rest from devices.xml itself and adds it to that entry by name. The device is still created by avdmanager -d <id>, as today.
flowchart LR
A[avdmanager list device:<br/>My TV, OEM User, Tag android-tv] --> M[custom profile]:::changed
X[devices.xml: My TV<br/>api-level 31-, playstore-enabled, diagonal] --> M
M --> F[fits rule]
classDef changed stroke-width:3px
Custom profile in devices.xml |
Images after #489 | Images after this PR |
|---|---|---|
"My TV", type TV, api-level 31- |
TV images, any level | TV images, 31 and newer |
"My Phone", no type, api-level 33- |
phone images, any level | phone images, 33 and newer |
"My Phone", playstore-enabled false |
phone images | phone images, no Play Store image |
"My Watch", type Wear, playstore-enabled false |
Wear images | Wear images, Play Store too (every Wear profile allows it) |
| "My Tablet", no type, 10.1-inch screen | phone images, no tablet image |
phone images and tablet images |
| "My Phone", no type, no diagonal | phone images, no tablet image |
phone images, no tablet image |
"My Phone", api-level - |
any level | any level |
| "Old", nothing but a name | phone images | phone images |
Classes of custom profiles avdmanager lists do not change: they still come from the device type it prints. A devices.xml profile avdmanager does not list (rare: a different .android directory) gets its class from its tag-id by the same map, phone without one (ADR 0025 §5).
If this goes wrong, a custom profile loses images it used to get, or gets ones Android Studio would not offer.
Technical spec
Modules touched
flowchart LR
U[parseDevicesXml / UserDeviceProfileSource<br/>device-profile-source.ts]:::changed --> R[DeviceProfileRegistry]:::changed
B[BuiltinDeviceProfileSource] --> R
F[image-fit.ts fits]:::changed --> R
D[AndroidDriver listCatalog, resolveSpec] --> F
classDef changed stroke-width:3px
src/drivers/android/device-profile-source.ts:parseDevicesXmlalso reads, per<d:device>:<d:tag-id>: 1 to 64 characters ofa-z,0-9,-; anything else is ignored.- the first
<d:software><d:api-level>:-or empty is no range;N-is N and newer;N-Mis N to M;-Mis M and older;Nis exactly N. N and M are integers from 1 to 999, and N ≤ M. Anything else is ignored (no range). <d:playstore-enabled>:trueorfalse; anything else is ignored (allowed).- the first
<d:screen><d:diagonal-length>: a decimal from 0.1 to 100 (inches); anything else is ignored (not a tablet). - foldable: the first
<d:screen>has<d:x-folded-dimension>and<d:y-folded-dimension>both above 0, as sdklib'sScreen.isFoldable().
- The
propertiesprofile gainsimageKind(fromtag-id),apiRange,playStoreandtablet.tabletis true when the profile has notag-id, a diagonal of 7 or more, and does not fold, as sdklib'sDevice.isTablet(). A profile withtag-idandroid-wearalways allows Play Store, as sdklib does. - The CR/LF/NUL refusal applies to every new field first, through the parser's existing unreadable-file diagnostic: a line break or NUL inside a value rejects the file even where the value would otherwise be ignored.
DeviceProfileRegistrygives abuiltinprofile markedcustomtheapiRange,playStoreandtabletof thedevices.xmlprofile with the same name, ignoring case, when there is one, on both paths:resolveandcatalog. Its kind and class stay from itsTag :line. Which profile a name resolves to, the order and the catalog's model list do not change. Soresolvenow also reads thedevices.xmlsource after a custombuiltinmatch (a file read; an unreadable file reports its diagnostic and adds nothing); for a model that is not custom it still stops at the first source, as today.- The
devices.xmlpath follows the same orderavdmanageruses to find.android, read from the environment the driver passes toavdmanager:$ANDROID_USER_HOME/devices.xml, else$ANDROID_PREFS_ROOT/.android/devices.xml, else$ANDROID_SDK_HOME/.android/devices.xml, else<home>/.android/devices.xml. Today it reads onlyANDROID_SDK_HOMEand home, so both sources now read the same file. DeviceProfileRegistry.catalogclasses apropertiesprofile by itsimageKindthroughclassOfTag; with none it isphone, as today.
src/drivers/android/image-fit.ts:fitsreadsapiRange,playStoreandtabletfor a custombuiltinprofile and for apropertiesprofile; apropertiesprofile's kind is itsimageKind, none when it has notag-id.
Contract and event changes
None.
Other code on the same state
BuiltinDeviceProfileSource: lists everydevices.xmlprofile withOEM : User(avdmanagerreads the file itself); it comes beforeUserDeviceProfileSource, so a custom name resolves to that entry, as today. The merge above adds details to that entry; it does not change which entry wins.- The existing test "does not read a later source once an earlier one resolves the model" (
device-profile-source.test.ts) still holds for a model that is not custom; for a custom one it changes to expect thedevices.xmlread. UserDeviceProfileSource: itspropertiesprofiles still answer for adevices.xmlprofileavdmanagerdoes not list, and are created with#applyHardwarePropertiesas today. The new fields are not written toconfig.ini.- An Android model's class comes from the listed profile, not the one its name resolves to #341 (open): a model's class comes from the profile it was listed from. Not touched here; classes do not change.
customModels: still lists these profiles as custom.
Rules in play
safety.md:devices.xmlis read only, and its values are claims; every new field is bounded as above and checked for line breaks before use.architecture.md: the registry stays the only place that matches names; the merge goes throughmatchProfile.
Tests
Seam: parseDevicesXml and UserDeviceProfileSource in src/drivers/android/device-profile-source.test.ts; AndroidDriver listCatalog and resolveSpec through createDriver in src/drivers/android/index.test.ts (model on "device-profile sources", which writes devices.xml with writeDevicesXml), with the fake avdmanager list device printing the profile with OEM : User, as a real SDK does.
- reads
tag-id,api-level,playstore-enabled, the diagonal and the fold from adevices.xmlprofile - parses
-, empty,33-,24-33,-30and33as the ranges above, and40-30,abc,0-and1000-as no range - ignores a
tag-idoutside the allowed characters or length, a diagonal outside 0.1 to 100, and aplaystore-enabledother thantrue/false - a CR, LF or NUL inside a new field rejects the file through the unreadable-file diagnostic, even when the field's value would otherwise be ignored
- a profile with a
tag-idand a 10-inch screen is not a tablet - reads
devices.xmlfromANDROID_USER_HOME, thenANDROID_PREFS_ROOT, thenANDROID_SDK_HOME, then home - a custom profile listed by
avdmanagergets the API range of itsdevices.xmlentry:api-level31-drops levels below 31 from itsmodelRuntimes - a custom profile with
playstore-enabledfalsedrops Play Store images; a custom Wear profile withfalsekeeps an image taggedandroid-wear,google_apis_playstore, listed byavdmanagerordevices.xml-only resolveSpecwith--os 30andprovisionrefuse a custom profile whoseapi-levelis31-- a custom profile with no type and a 10.1-inch screen that does not fold fits
tabletimages; a 6-inch one, one with folded dimensions and one with no diagonal do not - a custom profile with nothing but a name pairs as after An Android lease only uses a system image that fits its model #489
- a custom profile's class still comes from
avdmanager'sTag :line - a
devices.xmlprofileavdmanagerdoes not list fits by its owntag-id, range, Play Store flag and screen, and is classed by itstag-id config.inifor adevices.xmlprofile holds the same keys as before this PR
Done when
- With a custom
devices.xmlprofile whoseapi-levelis31-, and images at 30 and 31,simlock catalog --platform android --jsonpairs it only with 31. docs/CLI.md("Where Android models come from") says a custom profile's API range, Play Store setting and screen size from Android Studio decide which images it gets.
Out of scope
- An Android model's class comes from the listed profile, not the one its name resolves to #341.
- Changing a custom profile's class.
- Writing any of these values to
config.ini. doctorreporting adevices.xmlprofile hidden by a library name (doctor reports a devices.xml profile that a library profile hides #491).
Depends on
Approval
- Approved for delivery
Written by an agent.
Activity
github-actions commentedon Oct 13, 2026
Now
task:ready: approved, technical spec present, #489 closed or reviewed in this feature's stack.test: fit a custom profile by what Android Studio saved for it (#490)
feat(android): fit a custom profile by what Android Studio saved for …
refactor(android): simpler api-level range parse (#490)
chore: fallow complexity ignore for the api-range parse (#490)
test(android): keys test installs a TV image its profile fits (#490)
test(android): image-fit test expects phone images for a tag-less dev…
chore: test helper comments start with why: (#490)
fix(android): api-level of 4+ digits is ignored, the devices.xml merg…
chore(android): parseDevicesXml doc starts with why: (#490)
feat(android): a devices.xml profile's API range, Play Store and scre…
feat(android): doctor reports a devices.xml profile hidden by a libra…