תכונות וממשקי API

ב-Android 17 יש תכונות וממשקי API חדשים ומעולים למפתחים. בקטעים הבאים מפורטות התכונות האלה, כדי לעזור לכם להתחיל לעבוד עם ממשקי ה-API הקשורים.

לרשימה מפורטת של ממשקי API חדשים, ששונו או שהוסרו, קראו את דוח ההבדלים ב-API. לפרטים על ממשקי API חדשים, עיינו במאמרי העזרה של ה-API של Android – ממשקי API חדשים מודגשים כדי שיהיה קל לזהות אותם.

כדאי גם לבדוק תחומים שבהם שינויים בפלטפורמה עשויים להשפיע על האפליקציות שלכם. למידע נוסף, ראו את הדפים הבאים:

פונקציונליות עיקרית

ב-Android 17 נוספו התכונות החדשות הבאות שקשורות לפונקציונליות הליבה של Android.

טריגרים חדשים של ProfilingManager

Android 17 向 ProfilingManager 添加了多个新的系统触发器,可帮助您收集深入的数据来调试性能问题。

新触发条件包括:

如需了解如何设置系统触发器,请参阅有关基于触发器的性能分析以及如何检索和上传配置文件和分析性能分析数据的文档。

应用异常性能分析触发器

Android 17 引入了设备端异常值检测服务,用于监控资源密集型行为和潜在的兼容性回归。此服务与 ProfilingManager 集成,可让您的应用接收由系统检测到的特定事件触发的性能分析工件。

使用 TRIGGER_TYPE_ANOMALY 触发器检测系统性能问题,例如 Binder 调用过多和内存用量过多。当应用超出操作系统定义的内存限制时,异常触发器可让开发者接收应用专属堆转储,以帮助识别和修复内存问题。此外,对于过多的 binder 垃圾内容,异常触发器会提供 binder 事务的堆栈采样分析。

此 API 回调会在系统强制执行任何操作之前发生。例如,它可以帮助开发者在应用因超出内存限制而被系统终止之前收集调试数据。

fun registerAnomalyTrigger(context: Context) {
    val profilingManager =
        context.getSystemService(ProfilingManager::class.java) ?: return
    val triggers = listOf(
        ProfilingTrigger.Builder(ProfilingTrigger.TRIGGER_TYPE_ANOMALY).build()
    )
    val callbackExecutor: Executor = Executors.newSingleThreadExecutor()
    val resultCallback = Consumer<ProfilingResult> { profilingResult ->
        if (profilingResult.errorCode == ProfilingResult.ERROR_NONE) {
            // Upload profile result to server for further analysis
            profilingResult.resultFilePath?.let { setupProfileUploadWorker(it) }
        }
    }
    profilingManager.registerForAllProfilingResults(
        callbackExecutor,
        resultCallback
    )
    profilingManager.addProfilingTriggers(triggers)
}

ממשקי API של JobDebugInfo

Android 17 引入了新的 JobDebugInfo API,可帮助开发者调试其 JobScheduler 作业,例如作业未运行的原因、作业运行了多长时间以及其他聚合信息。

扩展后的 JobDebugInfo API 的第一个方法是 getPendingJobReasonStats(),它会返回一个映射,其中包含作业处于待执行状态的原因及其各自的累计待处理时长。此方法结合了 getPendingJobReasonsHistory() 和 getPendingJobReasons() 方法,可让您深入了解预定作业未按预期运行的原因,但通过在单个方法中提供时长和作业原因,简化了信息检索。

例如,对于指定的 jobId,该方法可能会返回 PENDING_JOB_REASON_CONSTRAINT_CHARGING 和 60000 毫秒的时长,表示由于充电限制未得到满足,作业处于待处理状态的时长为 60000 毫秒。

צמצום חסימות מצב שינה באמצעות תמיכה במאזינים להתראות שפועלות במצב המתנה

Android 17 introduces a new variant of AlarmManager.setExactAndAllowWhileIdle that accepts an OnAlarmListener instead of a PendingIntent. This new callback-based mechanism is ideal for apps that currently rely on continuous wakelocks to perform periodic tasks, such as messaging apps maintaining socket connections.

פרטיות

‫Android 17 כוללת את התכונות החדשות הבאות לשיפור פרטיות המשתמשים.

תמיכה בפלטפורמה של Encrypted Client Hello (ECH)‎

Android 17 introduces platform support for Encrypted Client Hello (ECH), a significant privacy enhancement for network communications. ECH is a TLS 1.3 extension that encrypts the Server Name Indication (SNI) during the initial TLS handshake. This encryption helps protect user privacy by making it more difficult for network intermediaries to identify the specific domain an app is connecting to.

The platform now includes the necessary APIs for networking libraries to implement ECH. This includes new capabilities in DnsResolver to query for HTTPS DNS records containing ECH configurations, and new methods in Conscrypt's SSLEngines and SSLSockets to enable ECH by passing in these configurations when connecting to a domain. Developers can configure ECH preferences, such as enabling it opportunistically or mandating its use, through the new <domainEncryption> element within the Network Security Configuration file, applicable globally or on a per-domain basis.

Popular networking libraries such as HttpEngine, WebView, and OkHttp are expected to integrate these platform APIs in future updates, making it easier for apps to adopt ECH and enhance user privacy.

For more information, see the Encrypted Client Hello documentation.

הכלי לבחירת אנשי קשר ב-Android

הכלי לבחירת אנשי קשר ב-Android הוא ממשק סטנדרטי שמאפשר למשתמשים לשתף אנשי קשר עם האפליקציה שלכם. הכלי זמין במכשירים עם Android בגרסה 17 (רמת API‏ 37) ומעלה, והוא מאפשר לשמור על הפרטיות במקום להשתמש בהרשאה הרחבה READ_CONTACTS. במקום לבקש גישה לכל פנקס הכתובות של המשתמש, האפליקציה מציינת את שדות הנתונים שהיא צריכה, כמו מספרי טלפון או כתובות אימייל, והמשתמש בוחר אנשי קשר ספציפיים לשיתוף. כך האפליקציה מקבלת גישת קריאה רק לנתונים שנבחרו, מה שמבטיח שליטה פרטנית תוך מתן חוויית משתמש עקבית עם יכולות מובנות של חיפוש, החלפת פרופילים ובחירה מרובה, בלי צורך לבנות או לתחזק את ממשק המשתמש.

מידע נוסף זמין במסמכי התיעוד של הכלי לבחירת אנשי קשר.

אבטחה

ב-Android 17 נוספו התכונות החדשות הבאות כדי לשפר את האבטחה של המכשיר והאפליקציות.

מצב ההגנה המתקדמת ב-Android‏ (AAPM)

Android Advanced Protection Mode offers Android users a powerful new set of security features, marking a significant step in safeguarding users—particularly those at higher risk—from sophisticated attacks. Designed as an opt-in feature, AAPM is activated with a single configuration setting that users can turn on at any time to apply an opinionated set of security protections.

These core configurations include blocking app installation from unknown sources (sideloading), restricting USB data signaling, and mandating Google Play Protect scanning, which significantly reduces the device's attack surface area. Developers can integrate with this feature using the AdvancedProtectionManager API to detect the mode's status, enabling applications to automatically adopt a hardened security posture or restrict high-risk functionality when a user has opted in.

חתימה על קובצי APK באמצעות PQC

עכשיו Android תומכת בסכימת חתימה היברידית של APK כדי להגן על זהות החתימה של האפליקציה מפני איום פוטנציאלי של התקפות שמשתמשות במחשוב קוונטי. התכונה הזו מציגה סכימת חתימה חדשה של APK, שמאפשרת להתאים בין מפתח חתימה קלאסי (כמו RSA או EC) לבין אלגוריתם חדש של הצפנה פוסט-קוונטית (PQC) ‏ (ML-DSA).

הגישה ההיברידית הזו מבטיחה שהאפליקציה תישאר מאובטחת מפני התקפות קוונטיות בעתיד, תוך שמירה על תאימות לדורות קודמים של גרסאות Android ומכשירים ישנים יותר שמסתמכים על אימות חתימה קלאסי.

ההשפעה על המפתחים

  • אפליקציות שמשתמשות בחתימת אפליקציה ב-Play: אם אתם משתמשים בחתימת אפליקציה ב-Play, אתם יכולים לחכות ש-Google Play תיתן לכם את האפשרות לשדרג לחתימה היברידית באמצעות מפתח PQC שנוצר על ידי Google Play. כך האפליקציה תהיה מוגנת בלי שתצטרכו לנהל את המפתחות באופן ידני.
  • אפליקציות שמשתמשות במפתחות בניהול עצמי: מפתחים שמנהלים את מפתחות החתימה שלהם יכולים להשתמש בכלי פיתוח מעודכנים של Android (כמו apksigner) כדי לעבור לזהות היברידית, שמשלבת מפתח PQC עם מפתח קלאסי חדש. (צריך ליצור מפתח קלאסי חדש, אי אפשר להשתמש שוב במפתח הישן).

קישוריות

ב-Android 17 נוספו התכונות הבאות כדי לשפר את הקישוריות של המכשיר והאפליקציה.

רשתות לוויין מוגבלות

מבצעת אופטימיזציות כדי לאפשר לאפליקציות לפעול ביעילות ברשתות לווייניות עם רוחב פס נמוך.

חוויית המשתמש וממשק המשתמש של המערכת

‫Android 17 כוללת את השינויים הבאים, שנועדו לשפר את חוויית המשתמש.

ערוץ ייעודי לעוצמת הקול של Assistant

Android 17 introduces a dedicated Assistant volume stream for Assistant apps, for playback with USAGE_ASSISTANT. This change decouples Assistant audio from the standard media stream, providing users with isolated control over both volumes. This enables scenarios such as muting media playback while maintaining audibility for Assistant responses, and the other way around.

Assistant apps with access to the new MODE_ASSISTANT_CONVERSATION audio mode can further improve the volume control consistency. Assistant apps can use this mode to provide a hint to the system about an active Assistant session, ensuring the Assistant stream can be controlled outside of the active USAGE_ASSISTANT playback or with connected Bluetooth peripherals.

הפעלה רציפה

‫Handoff היא תכונה חדשה וממשק API חדש שיופיעו ב-Android 17. מפתחי אפליקציות יכולים לשלב אותם כדי לספק למשתמשים המשכיות בין מכשירים. הוא מאפשר למשתמש להתחיל פעילות באפליקציה במכשיר Android אחד ולהעביר אותה למכשיר Android אחר. התכונה "העברה" פועלת ברקע של מכשיר המשתמש ומציגה פעילויות זמינות ממכשירים אחרים של המשתמש שנמצאים בקרבת מקום, דרך נקודות כניסה שונות, כמו מרכז האפליקציות ושורת המשימות, במכשיר המקבל.

אפליקציות יכולות להגדיר את Handoff כך שתפעיל את אותה אפליקציית Android מקורית, אם היא מותקנת וזמינה במכשיר המקבל. בתהליך הזה, המשתמש מועבר בקישור עומק מאפליקציה לאפליקציה לפעילות הייעודית. לחלופין, אפשר להציע את התכונה "העברה מאפליקציה לאתר" כאפשרות חלופית או להטמיע אותה ישירות באמצעות "העברה באמצעות כתובת URL".

התמיכה בהעברה בין מכשירים מקושרים מיושמת על בסיס כל פעילות בנפרד. כדי להפעיל את Handoff, צריך להפעיל את השיטה setHandoffEnabled() לפעילות. יכול להיות שיהיה צורך להעביר נתונים נוספים יחד עם ההעברה, כדי שהפעילות שנוצרה מחדש במכשיר המקבל תוכל לשחזר את המצב המתאים. מטמיעים את הקריאה החוזרת (callback) של onHandoffActivityDataRequested() כדי להחזיר אובייקט HandoffActivityData שמכיל פרטים שמציינים איך התכונה Handoff צריכה לטפל בפעילות וליצור אותה מחדש במכשיר המקבל.

עדכון בזמן אמת – Semantic color API

With Android 17, Live Update launches the Semantic Coloring APIs to support colors with universal meaning.

The following classes support semantic coloring:

Coloring

  • Green: Associated with safety. This color should be used for the case where it lets people know you are in the safe situation.
  • Orange: For designating caution and marking physical hazards. This color should be used in the situation where users need to pay attention to set better protection setting.
  • Red: Generally indicates danger, stop. It should be presented for the case where need people's attention urgently.
  • Blue: Neutral color for content that is informational and should stand out from other content.

The following example shows how to apply semantic styles to text in a notification:

  val ssb = SpannableStringBuilder()
        .append("Colors: ")
        .append("NONE", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_UNSPECIFIED), 0)
        .append(", ")
        .append("INFO", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_INFO), 0)
        .append(", ")
        .append("SAFE", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_SAFE), 0)
        .append(", ")
        .append("CAUTION", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_CAUTION), 0)
        .append(", ")
        .append("DANGER", Notification.createSemanticStyleAnnotation(SEMANTIC_STYLE_DANGER), 0)

    Notification.Builder(context, channelId)
          .setSmallIcon(R.drawable.ic_icon)
          .setContentTitle("Hello World!")
          .setContentText(ssb)
          .setOngoing(true)
              .setRequestPromotedOngoing(true)

‫UWB Downlink-TDoA API ל-Android 17

Downlink Time Difference of Arrival (DL-TDoA) ranging lets a device determine its position relative to multiple UWB anchors by measuring the relative arrival times of signals.

For more information and code samples, see UWB Downlink-TDoA API.