از 27 مارس 2025، توصیه می کنیم از android-latest-release
به جای aosp-main
برای ساختن و کمک به AOSP استفاده کنید. برای اطلاعات بیشتر، به تغییرات AOSP مراجعه کنید.
HAL های موجود پویا
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
اندروید 9 از خاموش شدن پویا زیرسیستمهای سختافزاری اندروید در مواقعی که استفاده نمیشوند یا نیازی ندارند، پشتیبانی میکند. به عنوان مثال، هنگامی که کاربر از Wi-Fi استفاده نمی کند، زیرسیستم های Wi-Fi نباید حافظه، برق یا سایر منابع سیستم را مصرف کنند. در نسخههای قبلی اندروید، HAL/درایورها در تمام مدت زمانی که یک گوشی اندرویدی بوت میشد، در دستگاههای Android باز نگه داشته میشدند.
اجرای خاموشی پویا شامل سیم کشی جریان داده و اجرای فرآیندهای پویا است که در بخش های زیر به تفصیل شرح داده شده است.
تغییرات در تعاریف HAL
خاموش شدن پویا به اطلاعاتی نیاز دارد که کدام فرآیندها به چه واسطهای HAL خدمت میکنند (این اطلاعات ممکن است بعداً در زمینههای دیگر نیز مفید باشد) و همچنین فرآیندها را در هنگام بوت شروع نمیکند و آنها را مجدداً راهاندازی نمیکند (تا زمانی که دوباره درخواست شود) هنگام خروج.
# some init.rc script associated with the HAL
service vendor.some-service-name /vendor/bin/hw/some-binary-service
# init language extension, provides information of what service is served
# if multiple interfaces are served, they can be specified one on each line
interface android.hardware.light@2.0::ILight default
# restarted if hwservicemanager dies
# would also cause the hal to start early during boot if disabled wasn't set
class hal
# will not be restarted if it exits until it is requested to be restarted
oneshot
# will only be started when requested
disabled
# ... other properties
تغییرات در init و hwservicemanager
خاموش شدن پویا همچنین به hwservicemanager
نیاز دارد که به init
بگوید خدمات درخواستی را شروع کند. در اندروید 9، init
شامل سه پیام کنترلی اضافی است (مانند ctl.start
): ctl.interface_start
، ctl.interface_stop
و ctl.interface_restart
. از این پیام ها می توان برای سیگنال init
برای بالا و پایین آوردن رابط های سخت افزاری خاص استفاده کرد. هنگامی که یک سرویس درخواست می شود و ثبت نمی شود، hwservicemanager
درخواست می کند که سرویس راه اندازی شود. با این حال، HAL های پویا نیازی به استفاده از هیچ یک از این موارد ندارند.
خروجی HAL را تعیین کنید
در اندروید 9، خروج HAL باید به صورت دستی تعیین شود. برای اندروید 10 و بالاتر، میتوان آن را با چرخههای عمر خودکار نیز تعیین کرد.
خاموش شدن پویا به چند سیاست برای تصمیم گیری در مورد زمان شروع HAL و زمان خاموش کردن HAL نیاز دارد. اگر یک HAL به هر دلیلی تصمیم به خروج بگیرد، با استفاده از اطلاعات ارائه شده در تعریف HAL و زیرساخت ارائه شده توسط تغییرات در init
و hwservicemanager
، به طور خودکار در صورت نیاز دوباره راه اندازی مجدد می شود. این می تواند شامل چند استراتژی مختلف باشد، از جمله:
- یک HAL میتواند انتخاب کند که خروجی خود را فراخوانی کند، اگر کسی یک API نزدیک یا مشابه روی آن فراخوانی کند. این رفتار باید در رابط HAL مربوطه مشخص شود.
- HAL ها می توانند پس از اتمام کارشان خاموش شوند (مستند شده در فایل HAL).
چرخه عمر خودکار
اندروید 10 پشتیبانی بیشتری به هسته و hwservicemanager
اضافه میکند که به HALها اجازه میدهد تا زمانی که هیچ کلاینت ندارند، بهطور خودکار خاموش شوند. برای استفاده از این ویژگی، تمام مراحل موجود در تعاریف Changes to HAL و همچنین:
- برای مثال، به جای تابع عضو،
registerAsService
، سرویس را در C++ با LazyServiceRegistrar
ثبت کنید: // only one instance of LazyServiceRegistrar per process
LazyServiceRegistrar registrar;
registrar.registerAsService(myHidlService /* , "default" */);
- بررسی کنید که کلاینت HAL فقط زمانی که از آن استفاده میشود، به HAL سطح بالا (رابط ثبتشده در
hwservicemanager
) اشاره میکند. برای جلوگیری از تأخیر در صورت رها شدن این مرجع بر روی یک رشته hwbinder که به اجرا ادامه میدهد، مشتری باید IPCThreadState::self()->flushCommands()
پس از حذف مرجع فراخوانی کند تا اطمینان حاصل شود که درایور بایندر از تعداد مرجع مرتبط مطلع شده است. تغییر می کند.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Dynamically available HALs\n\nAndroid 9 supports the dynamic shutdown of Android hardware subsystems when they are not in use or not needed. For example, when a user is not using Wi-Fi, the Wi-Fi subsystems should not be taking up memory, power, or other system resources. In earlier versions of Android, HALs/drivers were kept open on Android devices for the entire duration an Android phone was booted.\n\nImplementing dynamic shutdown involves wiring up data flows and executing\ndynamic processes as detailed in the following sections.\n\nChanges to HAL definitions\n--------------------------\n\nDynamic shutdown requires information on which processes serve what HAL\ninterfaces (this information may also be useful later in other contexts) as\nwell as not starting processes on boot and not restarting them (until\nrequested again) when they exit. \n\n```objective-c\n# some init.rc script associated with the HAL\nservice vendor.some-service-name /vendor/bin/hw/some-binary-service\n # init language extension, provides information of what service is served\n # if multiple interfaces are served, they can be specified one on each line\n interface android.hardware.light@2.0::ILight default\n # restarted if hwservicemanager dies\n # would also cause the hal to start early during boot if disabled wasn't set\n class hal\n # will not be restarted if it exits until it is requested to be restarted\n oneshot\n # will only be started when requested\n disabled\n # ... other properties\n```\n\nChanges to init and hwservicemanager\n------------------------------------\n\nDynamic shutdown also requires the `hwservicemanager` to tell\n`init` to start requested services. In Android 9,\n`init` includes three additional control messages (e.g.\n`ctl.start`): `ctl.interface_start`,\n`ctl.interface_stop`, and `ctl.interface_restart`.\nThese messages can be used to signal `init` to bring up and down\nspecific hardware interfaces. When a service is requested and isn't\nregistered, `hwservicemanager` requests that the service be\nstarted. However, dynamic HALs don't require using any of these.\n\nDetermine HAL exit\n------------------\n\nIn Android 9, HAL exit has to be manually\ndetermined. For Android 10 and higher, it can also\nbe determined with\n[automatic lifecycles](#automatic-lifecycles).\n\nDynamic shutdown requires multiple policies for deciding when to start a\nHAL and when to shutdown a HAL. If a HAL decides to exit for any reason, it\nwill automatically be restarted when it is needed again using the information\nprovided in the HAL definition and the infrastructure provided by changes to\n`init` and `hwservicemanager`. This could involve a\ncouple of different strategies, including:\n\n- A HAL could choose to call exit on itself if someone calls a close or similar API on it. This behavior must be specified in the corresponding HAL interface.\n- HALs can shut down when their task is completed (documented in the HAL file).\n\nAutomatic lifecycles\n--------------------\n\nAndroid 10 adds more support to the kernel and\n`hwservicemanager`, which allows HALs to shut down automatically\nwhenever they have no clients. To use this feature, do all of the steps in\n[Changes to HAL definitions](#changes-HAL-definitions) as well\nas:\n\n- Register the service in C++ with `LazyServiceRegistrar` instead of the member function, `registerAsService`, for example: \n\n ```scilab\n // only one instance of LazyServiceRegistrar per process\n LazyServiceRegistrar registrar;\n registrar.registerAsService(myHidlService /* , \"default\" */);\n ```\n- Verify that the HAL client keeps a reference to the top-level HAL (the interface registered with `hwservicemanager`) only when it's in use. To avoid delays if this reference is dropped on a hwbinder thread that continues to execute, the client should also call `IPCThreadState::self()-\u003eflushCommands()` after dropping the reference to ensure that the binder driver is notified of the associated reference count changes."]]