[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Garage Mode\n\nTo provide periods of idle time in vehicles, *Garage Mode* keeps the system\nawake so that jobs in\n[`JobScheduler`](https://developer.android.com/reference/android/app/job/JobScheduler) constrained with\n[idleness](https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresDeviceIdle(boolean)) can be executed.\n\nWhat is Garage Mode?\n--------------------\n\n\nOn connected devices such as phones, users rely on the system to ensure devices\nare stable, up-to-date, and optimized. To achieve that state, the Android platform\nprovides an\n[idle\ntime](https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresDeviceIdle(boolean))\nwindow during which apps can perform tasks when the user doesn't\ninteract with the device. A phone is considered to be *idle* when the user doesn't touch\nit for an extended duration (60 minutes or more) and the screen is turned off.\nUnlike a phone, when a car isn't being used, it's turned off, which means the car\nhas no\n[idle time](https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresDeviceIdle(boolean))\nwindow. Garage Mode ensures idle time in a car.\n\n\nWhen a car is turned off by the user, the system enters Garage Mode. While a\ncar is in Garage Mode, the system is powered on, the display is turned off, and\nidle jobs in the `JobScheduler` queue are executed. To implement Garage Mode, see\n[Device implementation guidelines](/docs/automotive/power/garage_mode#device).\n\nDevice implementation guidelines\n--------------------------------\n\n\nTo activate Garage Mode, when turning off the vehicle, the Vehicle HAL (VHAL)\nmust send\n[AP_POWER_STATE_REQ](https://developer.android.com/reference/android/car/VehiclePropertyIds.html#AP_POWER_STATE_REQ) with the state `SHUTDOWN_PREPARE`\nwith the parameter set to `SHUTDOWN_ONLY` or `CAN_SLEEP`.\n\n\nFor the state `SHUTDOWN_PREPARE` to be effective, the VHAL must specify the two\nparameters (state and the additional parameter) for the [AP_POWER_STATE_REQ](https://developer.android.com/reference/android/car/VehiclePropertyIds.html#AP_POWER_STATE_REQ) command. This enables the device to enter Garage Mode,\nwhich detects scheduled jobs in\n[`JobScheduler`](https://developer.android.com/reference/android/app/job/JobScheduler)\nand prevents the system from proceeding to either suspend or shut down until the jobs\nare completed.\n\nHow do device implementations connect to the Android framework?\n---------------------------------------------------------------\n\n\nFor Garage Mode, the framework requests the VHAL to extend the shutdown time\nuntil either the required duration is exceeded or all jobs have been executed,\nat which time the system shuts down. Under specific circumstances defined\nin the CDD, device implementations can shut down the system sooner. For details\non Android compatibility requirements, see the Android\n[Compatibility Definition Document (CDD)](/docs/compatibility/cdd).\n\nIf the VHAL must shut down the system before Garage Mode completes, the VHAL can issue\n`SHUTDOWN_PREPARE` with the parameter set to\n`SHUTDOWN_IMMEDIATELY` or `SLEEP_IMMEDIATELY`. Device\nimplementations can use this under specific circumstances *only*, typically\nwhen the resources needed to keep the system running are unavailable. For\nexample, when battery capacity is insufficient.\n\n**Figure 1.** Garage Mode flow\n\nHow do app developers work with Garage Mode?\n--------------------------------------------\n\n\nApps and services don't interact directly with Garage Mode. Instead,\napps schedule jobs in\n[`JobScheduler`](https://developer.android.com/reference/android/app/job/JobScheduler).\nThose jobs constrained by\n[idleness](https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresDeviceIdle(boolean)) are executed during Garage Mode.\n\nThe following code shows how to schedule a job to run during Garage Mode: \n\n```gdscript\npublic class MyGarageModeJob extends JobService { ... }\n\nContext context = ...;\nint jobId = ...;\n\nComponentName myGarageModeJobName = new componentName(context,\n MyGarageModeJob.class);\n\nJobInfo.Builder infoBuilder = new JobInfo.Builder(jobId, myGarageModeJobName)\n .setRequiresDeviceIdle(true);\n\n// Example of an optional constraint:\ninfoBuilder.setRequiredNetworkType(NetworkType.NETWORK_TYPE_UNMETERED);\n\nJobScheduler jobScheduler = (JobScheduler) context\n .getSystemService(Context.JOB_SCHEDULER_SERVICE);\n\njobScheduler.schedule(infoBuilder.build());\n```\n\nDebug Garage Mode\n-----------------\n\nTo debug Garage Mode:\n\n1. To enable logging categories relevant to Garage Mode: \n\n ```\n adb shell stop\n adb shell setprop log.tag.GarageMode VERBOSE\n adb shell setprop log.tag.Finsky VERBOSE\n adb shell setprop log.tag.CAR.POWER VERBOSE\n adb shell setprop log.tag.JobScheduler.Connectivity VERBOSE\n adb shell start\n ```\n | Stopping and starting Android services ensures log availability from service boot.\n2. To review the logcat output to indicate that Garage Mode is starting: \n\n ```transact-sql\n GarageMode: [Controller]: CPM state changed to SHUTDOWN_PREPARE\n GarageMode: [GarageMode]: Entering GarageMode\n GarageMode: [Controller]: Sending broadcast with action: com.android.server.jobscheduler.GARAGE_MODE_ON\n ```\n3. To determine that logcat output to indicate Garage Mode is finished (canceled or completed): \n\n ```transact-sql\n [GarageMode]: GarageMode was canceled\n ```\n *or* \n\n ```transact-sql\n [GarageMode]: GarageMode completed normally\n ```\n\n Garage Mode depends on the power state of the vehicle as described\n [above.](#how-do-device-implementations-connect-to-the-android-framework)\n4. Review the logcat output to indicate the correct power states are entered: \n\n ```transact-sql\n CAR.POWER: starting shutdown prepare without Garage Mode\n GarageMode: [Controller]: CPM state changed to SHUTDOWN_PREPARE\n GarageMode: [GarageMode]: Entering GarageMode\n CAR.POWER: send shutdown prepare\n CAR.POWER: setPowerState=SHUTDOWN_PREPARE(7) param=0\n ```"]]