Android: Run custom MDM commands
- This is how you see the results for custom MDM commands: https://github.com/fleetdm/fleet/issues/33158
- @noahtalerman: Can we built this in a such a way that you can send a command to auto install software? That way, technical customers can build an automation on top of Fleet's API before we ship this story:
- #40689
- @allenhouchins:
cisnerosrequested the following commands supported, in order of priority:- LOCK - must have urgently
- WIPE - must have urgently
- RESET_PASSWORD - must have, less urgent
- REQUEST_DEVICE_INFO - must have, less urgent
- Confirmed no longer needed by
cisneros. They were looking for the equivalent of a Get inventory command (Refetch) not realizing it only captures eSIM info, which is not something they capture today.
- Confirmed no longer needed by
- LOST_MODE - don't need urgently
- RELINQUISH_OWNERSHIP - don't need urgently
The last two are less urgent since customer does not currently support company-provide Android devices.
Goal
| User story |
|---|
| As an IT admin, |
| I want to use Fleet to run any command in the Android Management API as a custom MDM command |
| so that I can do things like reset a host's password or reboot a host remotely. |
Changes
Product
-
[x] UI changes: No changes
-
[ ] CLI (fleetctl) usage changes:
fleetctl mdm run-command --payload=example.json --hosts="test-host1,test-host2"whereexample.jsonis a JSON that matches the request JSON in AMAPI.- LOCK and RESET_PASSWORD are available on Fleet premium only (WIPE is free for Android company-owned, not BYOD). If these request types are passed into the JSON and the user doesn't have premium, then surface an error saying that that feature is only supported for premium users.
- LOCK and RESET_PASSWORD are available on Fleet premium only (WIPE is free for Android company-owned, not BYOD). If these request types are passed into the JSON and the user doesn't have premium, then surface an error saying that that feature is only supported for premium users.
-
[ ] YAML changes: No changes
-
[ ] REST API changes: Documentation changes here. Example with LOCK:
POST /api/v1/fleet/commands/run-
Request payload:
-
Response:
Status: 200
-
-
[ ] Fleet's agent (fleetd) changes: No changes
-
[ ] GitOps mode changes: No changes
-
[ ] Activity changes: No changes
-
[ ] Permissions changes: No changes
-
[ ] Changes to paid features or tiers: No changes
-
[ ] Transparency changes: No changes
-
[ ] First draft of test plan added
-
[ ] Other reference documentation changes: No changes
-
[ ] Once shipped, requester has been notified
-
[ ] Once shipped, dogfooding issue has been filed
Engineering
-
[ ] Test plan is finalized
-
[x] REST API doc changes: https://github.com/fleetdm/fleet/pull/50550
-
[x] Feature guide changes: Update
docs/REST API/rest-api.md: thePOST /api/v1/fleet/commands/rundocs currently say "macOS, iOS, iPadOS, or Windows". Add Android, note JSON format (vs XML for other platforms) Updatefleetctldocs for mdm run-command to note --payload accepts JSON for Android hosts -
[x] Database schema migrations: Add two columns to
mdm_android_commandsraw_command TEXT: stores the original JSON payload sent to AMAPI (mirrorswindows_mdm_commands.raw_commandandnano_commands.command)raw_result TEXT: stores the raw Operation response from pub/sub (mirrorsnano_command_results.resultandwindows_mdm_command_results.result) -
[x] Load testing: Probably not. Priority commands are operational, "lock a lost phone", "wipe a device". These are inherently single-device actions. Very unlikely that you will be locking 100+ devices. If we do want to support some sort of multi-host bulk operations we should do so in serial. Accept the list, call AMAPI per-host in a loop.
ℹ️ Please read this issue carefully and understand it. Pay special attention to UI wireframes, especially "dev notes".
QA
Risk assessment
- Requires load testing: TODO
- Risk level: Low / High TODO
- Risk description: TODO
Test plan
-
Test premium features with a "free" user and ensure that it is gated by error message. LOCK and RESET_PASSWORD are available on Fleet premium only (WIPE is free for company-owned Android)
-
[ ] TODO: BYOD vs company owned
Prerequisites
- Fleet instance with Android Enterprise connected
- At least one enrolled Android BYOD device
Sending commands
- [ ] Send POST /api/v1/fleet/commands/run with {"type": "REBOOT"} targeting an enrolled Android host. Verify 200 response with command_uuid and request_type.
- [ ] Verify mdm_android_commands row is created with status=pending, correct command_type, and raw_command storing the original JSON payload.
- [ ] Wait for device to execute (pub/sub callback). Verify status transitions to acknowledged.
- [ ] Verify GET /api/v1/fleet/commands/results?command_uuid=
returns the result with status, hostname, host_uuid, and payload (raw command JSON) and result (raw AMAPI Operation response). - [ ] Send a command with parameters: {"clearAppsDataParams": {"packageNames": ["com.example.app"]}}. Verify the type is inferred as CLEAR_APP_DATA and the result includes per-app status from the AMAPI response.
- [ ] Send {"type": "LOCK"} to an Android host. Verify the command succeeds.
- [ ] Send {"type": "RESET_PASSWORD"} to an Android host. Verify the command succeeds.
Fleetctl
- [ ] Run fleetctl mdm run-command --payload=reboot.json --hosts=
where reboot.json contains {"type": "REBOOT"}. Verify success and a command UUID is returned. - [ ] Run fleetctl get mdm-command-results --id=
. Verify the result is displayed with correct status and host info. - [ ] Run fleetctl get mdm-commands --host=
. Verify Android commands appear in the listing. - [ ] Run fleetctl mdm run-command --payload=reboot.json --hosts=
. Verify appropriate error message.
Activity logging
- [ ] After sending a custom command via API, verify a ran_custom_mdm_command activity appears in GET /api/v1/fleet/activities with correct actor_full_name, host_display_name, host_uuid, command_uuid, request_type, and platform=android.
- [ ] Verify the activity appears in the host-specific activity feed.
- [ ] Send a command as a different user. Verify the activity shows the correct actor.
Command listing
- [ ] Issue multiple commands to an Android host. Verify GET /api/v1/fleet/commands?host_identifier=<host_uuid> returns Android commands with correct command_type, status, updated_at, and host_display_name.
Premium gating
- [ ] Without Premium license: Send {"type": "LOCK"} via API. Verify 402 error indicating premium-only feature.
- [ ] Without Premium license: Send {"type": "RESET_PASSWORD"} via API. Verify same 402 error.
- [ ] Without Premium license: Send {"type": "REBOOT"} via API. Verify 200 success (not premium-gated).
- [ ] Without Premium license: Send {"type": "LOCK"} via fleetctl. Verify premium error is surfaced in CLI output.
- [ ] Without Premium license: Send {"type": "RESET_PASSWORD"} via API. Verify premium error is surfaced in CLI output.
Permissions
- [ ] As global admin: Send command. Verify allowed.
- [ ] As global maintainer: Send command. Verify allowed.
- [ ] As global observer: Send command. Verify 403 forbidden.
- [ ] As global observer: View command results. Verify allowed.
- [ ] As team admin (Team A): Send command to Team A host. Verify allowed.
- [ ] As team admin (Team A): Send command to Team B host. Verify 403 forbidden.
- [ ] As team observer (Team A): Send command to Team A host. Verify 403 forbidden.
- [ ] As team observer (Team A): View Team A command results. Verify allowed.
Error handling
- [ ] Send a command to a host UUID that is not enrolled in Android MDM. Verify an appropriate error is returned (not a 500).
- [ ] Send a command to a non-Android host (e.g., macOS) with Android JSON payload. Verify an error indicating platform mismatch.
- [ ] Send an invalid type value (e.g., {"type": "INVALID_COMMAND"}). Verify AMAPI error is propagated back to the user.
- [ ] Send {"type": "REBOOT"} to a work-profile (BYOD) device (REBOOT is only supported on fully managed). Verify the pub/sub callback captures the AMAPI error and status transitions to error with error_code and error_message populated.
- [ ] Verify GET /api/v1/fleet/commands/results?command_uuid=
for the failed command shows the error details. - [ ] Send a command targeting multiple hosts where one is Android and one is macOS. Verify error: "All hosts must be on the same platform."
Edge cases
- [ ] Send a command to an Android host, then delete the host from Fleet before the pub/sub callback arrives. Verify the pub/sub handler does not crash (graceful handling).
- [ ] Send a command, then unenroll the device. Verify the command status reflects the error or is handled gracefully.
- [ ] Verify that re-sending the same command type to the same host creates a new, separate command entry (no deduplication).
- [ ] Verify activity still renders correctly if the actor (user who ran the command) is later deleted from Fleet.
- [ ] Verify GET /commands/results for an Android command UUID returns results even if Android MDM is later disabled on the Fleet instance.
Testing notes
Confirmation
- [ ] Engineer: Added comment to user story confirming successful completion of test plan.
- [ ] QA: Added comment to user story confirming successful completion of test plan.
Lost phone in the wind, Fleet secures with a swift wipe, Data safe, fear quelled.
UPDATE: @noahtalerman: Closing this out. Fleet will add the ability to remotely wipe (remove) a BYOD Android hosts work profile. This will be the best practice way to protect company data when an employee's Android phone is lost or stolen.
That's tracked in a separate user story here: #26010
Re-opening this. Being able to send any command as a custom command is core to Fleet: https://developers.google.com/android/management
T-shirt size: S
cisneros requested the following commands supported, in order of priority:
LOCK - must have urgently
WIPE - must have urgently
RESET_PASSWORD - must have, less urgent
REQUEST_DEVICE_INFO - must have, less urgent
LOST_MODE - don't need urgently
RELINQUISH_OWNERSHIP - don't need urgently
The last two are less urgent since customer does not currently support company-provide Android devices.
I want to say adding the ability to target a host and run the command will be XS / S
Storing results and being able to include it all in the mdm commands probably makes this closer to a M
Added comment to original issue description.
- REQUEST_DEVICE_INFO - must have, less urgent
- Confirmed no longer needed by
cisneros. They were looking for the equivalent of a Get inventory command (Refetch) not realizing it only captures eSIM info, which is not something they capture.
@lukeheath, for visibility only. BYOD added, PWR-TO-PC removed.
These are the current commands supported by AMAPI.
Creating a POC ticket to investigate
QA: test plan complete
Verified on 4.92.0-rc.2609171840 (rev 7ee7f5a548), across a personally-owned (BYOD) work profile and a
company-owned fully-managed enrollment of the same handset (Samsung SM-S906U1, Android 16).
Passing: sending commands (all 7 items) · fleetctl (4/4) · activity logging (3/3) · command listing · premium gating (5/5, no bypass across 7 payload variants) · permissions (8/8) · error handling (6/6) · edge cases (no-dedup, actor-deleted, results-after-disable).
Highlights worth calling out:
- Secret redaction holds on both enrollment types — a
RESET_PASSWORDwith a distinctive password produced 0 hits inraw_command,raw_result, and the server log. - The premium gate resists
lock," LOCK ",{"TYPE":"LOCK"}, duplicate JSON keys, and thenewPassword-only inference path; fleetctl surfaces the exact specified message. - Per-app
clearAppsDataStatusdetail is preserved for bothSUCCESSandAPP_NOT_FOUND. - Activities survive actor deletion:
actor_idgoes null, name/email/details remain, renders in API and UI.
Bugs filed from this story (all verified fixed on the RC unless noted):
#53151 · #53152 · #53159 · #53161 (status code fixed; upstream message still opaque) · #53163 (payload fixed;
injected 10-year duration still undocumented) · #53454 (open — released in 4.91.0, not a 4.92 regression)
Two test-plan lines are now out of date with the implementation:
- "Send
{"type":"REBOOT"}to a work-profile device… verify the pub/sub callback captures the AMAPI error" — after #53151 the command is refused with a 400 before reaching AMAPI, so no row and no callback exist. The line should assert the refusal instead. - "Send a command with parameters
{"clearAppsDataParams": …}. Verify the type is inferred as CLEAR_APP_DATA" — Fleet's Android proxy rejects any payload withouttype(E_MISSING_OR_INVALID_PARAMS). Fleet does infer internally (WIPE fromwipeParams, lost-mode from its params), but only after the proxy accepts the call.
Notified customer-rosner and customer-cisneros
notified all customers
Admins lock lost phones Custom Android commands flow through Fleet's open gates