Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Triển khai gói dữ liệu
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Android 9 cho phép nhà mạng trực tiếp cung cấp thông tin chi tiết chính xác về gói cho người dùng trong ứng dụng Cài đặt để giảm sự nhầm lẫn của người dùng và các cuộc gọi hỗ trợ. Trên các thiết bị chạy Android 4.0 trở lên, người dùng có thể tự định cấu hình chi tiết gói dữ liệu theo nhà mạng trong ứng dụng Cài đặt, chẳng hạn như đặt cảnh báo và giới hạn để quản lý mức sử dụng dữ liệu.
Cấu hình theo nhà mạng
Để định cấu hình gói dữ liệu, nhà mạng có thể thêm chức năng vào các ứng dụng Android hiện có bằng cách sử dụng SubscriptionPlan
API.
Các API này được thiết kế để hỗ trợ nhiều loại gói dữ liệu, bao gồm cả gói định kỳ và không định kỳ, cũng như các gói thay đổi theo thời gian.
Dưới đây là ví dụ về cách định cấu hình một loại gói dữ liệu phổ biến lặp lại hàng tháng:
SubscriptionManager sm =
context.getSystemService(SubscriptionManager.class);
sm.setSubscriptionPlans(subId, Lists.newArrayList(
SubscriptionPlan.Builder.createRecurringMonthly(
ZonedDateTime.parse("2016-12-03T10:00:00Z"))
.setTitle("G-Mobile")
.setDataLimit(4_000_000_000L,
SubscriptionPlan.LIMIT_BEHAVIOR_BILLED)
.setDataUsage(200_493_293L, dataUsageTimestamp)
.build()));
Thiết bị chỉ cho phép ứng dụng định cấu hình gói dữ liệu trong một trong các điều kiện sau:
Hai điều kiện đầu tiên cho phép người dùng cài đặt ứng dụng của nhà mạng mà không yêu cầu phải cài đặt sẵn ứng dụng đó vào hình ảnh hệ thống tại nhà máy.
Hệ điều hành thực thi (và CDD yêu cầu) rằng tất cả thông tin chi tiết về gói dữ liệu đã định cấu hình đều được bảo vệ và chỉ được cung cấp cho ứng dụng của nhà mạng ban đầu cung cấp thông tin chi tiết cho hệ điều hành.
Một thiết kế được đề xuất là ứng dụng của nhà mạng sử dụng dịch vụ bảo trì khi rảnh để cập nhật thông tin chi tiết về gói dữ liệu hằng ngày, nhưng nhà mạng có thể tự do sử dụng nhiều cơ chế, chẳng hạn như nhận thông tin chi tiết về gói dữ liệu thông qua tin nhắn SMS nội bộ của nhà mạng. Tốt nhất là bạn nên triển khai các dịch vụ bảo trì khi rảnh bằng một công việc JobScheduler
sử dụng setRequiresDeviceIdle()
và setRequiresCharging()
.
Mức sử dụng theo hệ điều hành
Hệ điều hành sử dụng thông tin chi tiết về gói dữ liệu do các API SubscriptionPlan cung cấp theo các cách sau:
- Thông tin chi tiết về gói được hiển thị thông qua ứng dụng Cài đặt để hiển thị mức sử dụng dữ liệu chính xác cho người dùng và cung cấp đường liên kết sâu trực tiếp đến ứng dụng của nhà mạng để có cơ hội nâng cấp/bán thêm.
- Các ngưỡng cảnh báo về mức sử dụng dữ liệu và thông báo giới hạn được tự động định cấu hình dựa trên thông tin chi tiết về gói; cảnh báo được đặt thành 90% giới hạn.
- Nếu nhà mạng tạm thời cho biết mạng đang "quá tải", thì hệ điều hành sẽ trì hoãn các công việc JobScheduler có thể được chuyển đổi thời gian, giảm tải trên mạng của nhà mạng.
- Nếu nhà mạng tạm thời cho biết mạng đang ở trạng thái "không tính cước", thì hệ điều hành có thể báo cáo kết nối di động là "không tính cước" cho đến khi nhà mạng xoá chế độ ghi đè hoặc cho đến khi đạt đến giá trị thời gian chờ (nếu có).
- Bằng cách so sánh mức sử dụng dữ liệu hiện tại của người dùng với hạn mức dữ liệu tổng thể, hệ điều hành sẽ ước tính mức sử dụng dữ liệu thông thường của người dùng vào cuối chu kỳ thanh toán và phân bổ một cách thận trọng 10% dữ liệu dư thừa để cải thiện trải nghiệm người dùng, chẳng hạn như bằng cách cho phép ứng dụng sử dụng dữ liệu nhiều đường dẫn.
Tuỳ chỉnh và xác thực
Ứng dụng Cài đặt Android hiển thị tất cả thông tin chi tiết về gói dữ liệu do nhà mạng thiết lập, đảm bảo rằng người dùng thấy trạng thái chính xác nhất về mối quan hệ với nhà mạng và cung cấp cho người dùng đường dẫn đến ứng dụng của nhà mạng để nâng cấp gói. Nhà sản xuất thiết bị chọn tuỳ chỉnh ứng dụng Cài đặt nên tiếp tục hiển thị những thông tin chi tiết này.
Các API SubscriptionManager
được mô tả trên trang này được kiểm thử bằng android.telephony.cts.SubscriptionManagerTest
, đảm bảo rằng ứng dụng của nhà mạng có thể định cấu hình thông tin chi tiết về gói dữ liệu và các thay đổi được truyền trong hệ điều hành.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],[],null,["# Implement data plans\n\nAndroid 9 lets carriers directly provide authoritative\nplan details to users in the Settings app to reduce user confusion and support\ncalls. On devices running Android 4.0 and higher, users are able to manually\nconfigure their carrier-specific data plan details in the Settings app, for\nexample, setting warnings and limits to manage their data usage.\n\nConfiguration by carrier\n------------------------\n\nTo configure data plans, carriers can add functionality to their existing\nAndroid apps using the\n[`SubscriptionPlan` APIs](https://developer.android.com/reference/android/telephony/SubscriptionPlan.Builder).\nThe APIs are designed to support a wide range of data plan types, including both\nrecurring and non-recurring plans, and plans that change over time.\n\nHere's an example of how to configure a common type of data plan that recurs\nmonthly: \n\n SubscriptionManager sm =\n context.getSystemService(SubscriptionManager.class);\n sm.setSubscriptionPlans(subId, Lists.newArrayList(\n SubscriptionPlan.Builder.createRecurringMonthly(\n ZonedDateTime.parse(\"2016-12-03T10:00:00Z\"))\n .setTitle(\"G-Mobile\")\n .setDataLimit(4_000_000_000L,\n SubscriptionPlan.LIMIT_BEHAVIOR_BILLED)\n .setDataUsage(200_493_293L, dataUsageTimestamp)\n .build()));\n\nThe device only lets an app configure data plans under one of these conditions:\n\n- The SIM card has explicitly defined an app that can manage it, as defined by [`SubscriptionManager.canManageSubscription()`](https://developer.android.com/reference/android/telephony/SubscriptionManager.html#canManageSubscription(android.telephony.SubscriptionInfo)).\n- The carrier has pushed the [`KEY_CONFIG_PLANS_PACKAGE_OVERRIDE_STRING`](https://developer.android.com/reference/android/telephony/CarrierConfigManager#KEY_CONFIG_PLANS_PACKAGE_OVERRIDE_STRING) value via `CarrierConfigManager` to indicate which app can manage the carrier's data plans.\n- The device has an app built into the system image that has the `MANAGE_SUBSCRIPTION_PLANS` permission.\n\nThe first two conditions enable the carrier app to be installed by the user,\nwithout requiring that it be pre-installed into the system image at the factory.\nThe OS enforces (and the CDD requires) that all configured data plan details are\nprotected and are only made available to the carrier app that originally\nprovided the details to the OS.\n\nOne suggested design is for a carrier app to use an idle maintenance service to\nupdate data plan details on a daily basis, but carriers are free to use a wide\nrange of mechanisms, such as receiving data plan details through carrier-internal\nSMS messages. Idle maintenance services are best implemented with a\n`JobScheduler` job that uses\n[`setRequiresDeviceIdle()`](https://developer.android.com/reference/android/app/job/JobInfo.Builder#setRequiresDeviceIdle(boolean))\nand\n[`setRequiresCharging()`](https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setRequiresCharging(boolean)).\n\nUsage by OS\n-----------\n\nThe OS uses the data plan details provided by the SubscriptionPlan APIs in the\nfollowing ways:\n\n- The plan details are surfaced via the Settings app to display accurate data usage to users and to provide [direct deep links into the carrier app](https://developer.android.com/reference/android/telephony/SubscriptionManager.html#ACTION_MANAGE_SUBSCRIPTION_PLANS) for upgrade/upsell opportunities.\n- The data usage warning and limit notification thresholds are automatically configured based on the plan details; the warning is set to 90% of the limit.\n- If the carrier temporarily indicates the network is [\"congested\"](https://developer.android.com/reference/android/telephony/SubscriptionManager.html#setSubscriptionOverrideCongested(int,%20boolean,%20long)), the OS delays JobScheduler jobs that can be time-shifted, reducing the load on the carrier network.\n- If the carrier temporarily indicates the network is [\"unmetered\"](https://developer.android.com/reference/android/telephony/SubscriptionManager#setSubscriptionOverrideUnmetered(int,%20boolean,%20long)), the OS can report the cellular connection as \"unmetered\" until the carrier clears the override, or until the timeout value (if provided) is reached.\n- By comparing the user's current data usage with the overall data limit, the OS estimates the user's normal data usage at the end of the billing cycle and conservatively allocates 10% of any surplus data to improve the user experience, for example, by letting apps use multi-path data.\n\nCustomization and validation\n----------------------------\n\nThe Android Settings app displays all carrier-configured data plan details,\nensuring that users see the most accurate status of their carrier relationship,\nand offering users a path into the carrier app to upgrade their plan. Device\nmanufacturers choosing to customize the Settings app are recommended to continue\nsurfacing these details.\n\nThe `SubscriptionManager` APIs described on this page are tested by\n`android.telephony.cts.SubscriptionManagerTest`, which ensures that data plan\ndetails can be configured by carrier apps and that changes are propagated within\nthe OS."]]