IsolatedService

public abstract class IsolatedService
extends Service

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.adservices.ondevicepersonalization.IsolatedService


ODP 在调用 OnDevicePersonalizationManager#execute(ComponentName, PersistableBundle, java.util.concurrent.Executor, OutcomeReceiver) 时所启动且在独立进程中运行的服务的适用基类。该服务可以生成要在调用应用的 SurfaceView 中显示的内容,并将永久性结果写入设备端存储空间,以便联邦分析进行跨设备统计分析或联邦学习进行模型训练。客户端应用使用 OnDevicePersonalizationManagerIsolatedService 交互。

摘要

继承的常量

int START_CONTINUATION_MASK

onStartCommand(Intent, int, int) 返回的位,用于描述如何在服务被终止时继续运行服务。

int START_FLAG_REDELIVERY

如果 intent 是之前传送的 intent 的重新传送,则系统会在 onStartCommand(Intent, int, int) 中设置此标志,因为服务之前返回了 START_REDELIVER_INTENT,但在为该 intent 调用 stopSelf(int) 之前已被终止。

int START_FLAG_RETRY

如果 intent 为重试,则在 onStartCommand(Intent, int, int) 中设置此标志,因为原始尝试从未到达或从 onStartCommand(android.content.Intent, int, int) 返回。

int START_NOT_STICKY

onStartCommand(Intent, int, int) 返回的常量:如果此服务在启动期间(从 onStartCommand(Intent, int, int) 返回后)被终止,并且没有要传递给它的新启动 intent,则将服务从已启动状态移出,并在以后明确调用 Context.startService(Intent) 之前不再重新创建。

int START_REDELIVER_INTENT

onStartCommand(Intent, int, int) 返回的常量:如果此服务在启动期间(从 onStartCommand(Intent, int, int) 返回后)被终止,则系统会安排其重启,并通过 onStartCommand(Intent, int, int) 再次将上次传递的 intent 传递给它。

int START_STICKY

onStartCommand(Intent, int, int) 返回的常量:如果此服务的进程在启动期间被终止(从 onStartCommand(Intent, int, int) 返回后),则将其保留在启动状态,但不保留此传递的 intent。

int START_STICKY_COMPATIBILITY

onStartCommand(Intent, int, int) 返回的常量:START_STICKY 的兼容性版本,不保证在被终止后会再次调用 onStartCommand(Intent, int, int)

int STOP_FOREGROUND_DETACH

stopForeground(int) 的选择器:如果设置,之前提供给 startForeground(int, Notification) 的通知将与服务的生命周期分离。

int STOP_FOREGROUND_LEGACY

此常量在 API 级别 33 中已废弃。 请改用 STOP_FOREGROUND_DETACH。旧版行为不一致,导致出现有关不可预测结果的错误。

int STOP_FOREGROUND_REMOVE

stopForeground(int) 的选择器:如果提供,系统会取消之前向 startForeground(int, Notification) 提供的通知,并将其从显示屏中移除。

String ACCESSIBILITY_SERVICE

getSystemService(java.lang.String) 配合使用以检索 AccessibilityManager,以便通过已注册的事件监听器为用户提供对界面事件的反馈。

String ACCOUNT_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索 AccountManager 以便在您选择的时间接收 intent。

String ACTIVITY_SERVICE

getSystemService(java.lang.String) 配合使用以检索 ActivityManager,以便与全局系统状态进行交互。

String ALARM_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索 AlarmManager 以便在您选择的时间接收 intent。

String APPWIDGET_SERVICE

getSystemService(java.lang.String) 配合使用以检索 AppWidgetManager,以便访问 AppWidget。

String APP_OPS_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 AppOpsManager 以跟踪设备上的应用操作。

String APP_SEARCH_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 AppSearchManager,以便为系统管理的应用数据编制索引和查询。

String AUDIO_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 AudioManager 以处理音量、铃声模式和音频路由的管理。

String BATTERY_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索用于管理电池状态的 BatteryManager

int BIND_ABOVE_CLIENT

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的标志:表示绑定到此服务的客户端应用认为该服务比应用本身更重要。

int BIND_ADJUST_WITH_ACTIVITY

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的标志:如果从 activity 进行绑定,则允许根据 activity 对用户是否可见来提高目标服务的进程重要性,无论是否使用其他标志来减少客户端进程的整体重要性对其的影响。

int BIND_ALLOW_ACTIVITY_STARTS

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的标志:如果从可见的应用进行绑定,则允许绑定的服务从后台启动 activity。

int BIND_ALLOW_OOM_MANAGEMENT

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的标志:允许托管绑定服务的进程进行正常的内存管理。

int BIND_AUTO_CREATE

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的标志:只要绑定存在,系统就会自动创建服务。

int BIND_DEBUG_UNBIND

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的标志:添加了针对与解绑不匹配的调用的调试帮助。

int BIND_EXTERNAL_SERVICE

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的标志:要绑定的服务是 isolatedexternal 服务。

long BIND_EXTERNAL_SERVICE_LONG

BIND_EXTERNAL_SERVICE 的工作原理相同,但它被定义为与 BindServiceFlags 兼容的 (@code long) 值。

int BIND_IMPORTANT

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 标记:此服务对客户端来说非常重要,因此应在客户端处于前台时置于前台进程级别。

int BIND_INCLUDE_CAPABILITIES

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的标志:如果从因其前台状态(例如 activity 或前台服务)而具有特定功能的应用进行绑定,则此标志将允许绑定的应用获得相同的功能,前提是该应用也具有所需的权限。

int BIND_NOT_FOREGROUND

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的标志:不允许此绑定将目标服务的进程提升到前台调度优先级。

int BIND_NOT_PERCEPTIBLE

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 标记:如果要从可见或用户可感知的应用进行绑定,请将目标服务的重要性降低到可察觉的水平。

int BIND_SHARED_ISOLATED_PROCESS

bindIsolatedService(Intent, BindServiceFlags, String, Executor, ServiceConnection) 的标志:将服务绑定到共享的隔离进程。

int BIND_WAIVE_PRIORITY

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的标志:不会影响目标服务的托管进程的调度或内存管理优先级。

String BIOMETRIC_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索 BiometricManager 来处理生物识别和 PIN 码/图案/密码身份验证。

String BLOB_STORE_SERVICE

getSystemService(java.lang.String) 配合使用以检索 BlobStoreManager,以便从系统维护的 blob 存储区中贡献和访问数据 blob。

String BLUETOOTH_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索用于使用蓝牙的 BluetoothManager

String BUGREPORT_SERVICE

用于获取 bug 报告的服务。

String CAMERA_SERVICE

getSystemService(java.lang.String) 配合使用以检索 CameraManager,以便与相机设备进行交互。

String CAPTIONING_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 CaptioningManager,以获取字幕属性并监听字幕偏好设置的更改。

String CARRIER_CONFIG_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索 CarrierConfigManager 以读取运营商配置值。

String CLIPBOARD_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 ClipboardManager,以访问和修改全局剪贴板的内容。

String COMPANION_DEVICE_SERVICE

getSystemService(java.lang.String) 配合使用以检索 CompanionDeviceManager,用于管理配套设备

String CONNECTIVITY_DIAGNOSTICS_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 ConnectivityDiagnosticsManager 以执行网络连接诊断以及从系统接收网络连接信息。

String CONNECTIVITY_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 ConnectivityManager 以处理网络连接的管理。

String CONSUMER_IR_SERVICE

getSystemService(java.lang.String) 配合使用以检索 ConsumerIrManager,用于从设备传输红外信号。

int CONTEXT_IGNORE_SECURITY

可与 createPackageContext(String, int) 搭配使用的标志:忽略对请求的上下文的任何安全限制,允许始终加载该上下文。

int CONTEXT_INCLUDE_CODE

可与 createPackageContext(String, int) 搭配使用的标志:将应用代码包含在上下文中。

int CONTEXT_RESTRICTED

createPackageContext(String, int) 一起使用的标志:受限上下文可能会停用特定功能。

String CREDENTIAL_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 CredentialManager 以对应用的用户进行身份验证。

String CROSS_PROFILE_APPS_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 CrossProfileApps 以执行跨资料操作。

int DEVICE_ID_DEFAULT

默认设备 ID,即主要(非虚拟)设备的 ID。

int DEVICE_ID_INVALID

设备 ID 无效。

String DEVICE_LOCK_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 DeviceLockManager

String DEVICE_POLICY_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索 DevicePolicyManager 以便处理全局设备政策管理。

String DISPLAY_HASH_SERVICE

getSystemService(java.lang.String) 搭配使用,以访问 DisplayHashManager 来处理显示哈希。

String DISPLAY_SERVICE

getSystemService(java.lang.String) 配合使用以检索 DisplayManager,以便与显示设备进行交互。

String DOMAIN_VERIFICATION_SERVICE

getSystemService(java.lang.String) 搭配使用可访问 DomainVerificationManager,以检索已声明网域的审批状态和用户状态。

String DOWNLOAD_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索用于请求 HTTP 下载的 DownloadManager

String DROPBOX_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 DropBoxManager 实例以记录诊断日志。

String EUICC_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 EuiccManager 以管理设备 eUICC(嵌入式 SIM 卡)。

String FILE_INTEGRITY_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 FileIntegrityManager

String FINGERPRINT_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 FingerprintManager 以处理指纹管理。

String GAME_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 GameManager

String GRAMMATICAL_INFLECTION_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 GrammaticalInflectionManager

String HARDWARE_PROPERTIES_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 HardwarePropertiesManager 以访问硬件属性服务。

String HEALTHCONNECT_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 HealthConnectManager

String INPUT_METHOD_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 InputMethodManager 以访问输入方法。

String INPUT_SERVICE

getSystemService(java.lang.String) 配合使用以检索 InputManager,以便与输入设备进行交互。

String IPSEC_SERVICE

getSystemService(java.lang.String) 配合使用以检索 IpSecManager,以便通过 IPSec 加密套接字或网络。

String JOB_SCHEDULER_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 JobScheduler 实例以管理不定时后台任务。

String KEYGUARD_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索用于控制屏幕保护程序的 KeyguardManager

String LAUNCHER_APPS_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 LauncherApps,以便跨用户的个人资料查询和监控可启动的应用。

String LAYOUT_INFLATER_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 LayoutInflater,以便在此上下文中膨胀布局资源。

String LOCALE_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 LocaleManager

String LOCATION_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 LocationManager 以控制位置信息更新。

String MEDIA_COMMUNICATION_SERVICE

getSystemService(java.lang.String) 搭配使用可检索用于管理 MediaSession2MediaCommunicationManager

String MEDIA_METRICS_SERVICE

getSystemService(java.lang.String) 配合使用以检索 MediaMetricsManager,以便与设备上的媒体指标进行交互。

String MEDIA_PROJECTION_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 MediaProjectionManager 实例以管理媒体投影会话。

String MEDIA_ROUTER_SERVICE

getSystemService(Class) 搭配使用可检索 MediaRouter,以控制和管理媒体路由。

String MEDIA_SESSION_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索用于管理媒体会话的 MediaSessionManager

String MIDI_SERVICE

getSystemService(java.lang.String) 结合使用可检索用于访问 MIDI 服务的 MidiManager

int MODE_APPEND

文件创建模式:与 openFileOutput(String, int) 搭配使用时,如果文件已存在,则将数据写入现有文件的末尾,而不是擦除该文件。

int MODE_ENABLE_WRITE_AHEAD_LOGGING

数据库打开标志:设置后,系统会默认启用提前写入日志记录功能来打开数据库。

int MODE_MULTI_PROCESS

此常量在 API 级别 23 中已废弃。 MODE_MULTI_PROCESS 在某些 Android 版本中无法可靠运行,此外,它也不提供任何用于协调跨进程并发修改的机制。应用不应尝试使用它。相反,它们应使用显式跨进程数据管理方法,例如 ContentProvider

int MODE_NO_LOCALIZED_COLLATORS

数据库打开标志:设置后,系统会打开数据库,但不支持本地化排序键。

int MODE_PRIVATE

文件创建模式:默认模式,其中创建的文件只能由调用应用(或共享相同用户 ID 的所有应用)访问。

int MODE_WORLD_READABLE

此常量已在 API 级别 17 中废弃。 创建全局可读文件非常危险,可能会导致应用出现安全漏洞。强烈建议不要这样做;相反,应用应使用更正式的交互机制,例如 ContentProviderBroadcastReceiverService。 无法保证此访问模式会一直存在于文件中,例如在进行备份和恢复时。

int MODE_WORLD_WRITEABLE

此常量在 API 级别 17 中已废弃。 创建全局可写文件非常危险,可能会导致应用出现安全漏洞。强烈建议不要这样做;相反,应用应使用更正式的交互机制,例如 ContentProviderBroadcastReceiverService。 我们无法保证文件会一直保持此访问模式,例如在进行备份和恢复时。

String NETWORK_STATS_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索 NetworkStatsManager 以查询网络使用情况统计信息。

String NFC_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索用于使用 NFC 的 NfcManager

String NOTIFICATION_SERVICE

getSystemService(java.lang.String) 配合使用以检索 NotificationManager,以便将后台事件通知用户。

String NSD_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 NsdManager 以处理网络服务发现的管理

String OVERLAY_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索用于管理叠加层软件包的 OverlayManager

String PEOPLE_SERVICE

getSystemService(java.lang.String) 搭配使用,以访问 PeopleManager 与已发布的对话进行互动。

String PERFORMANCE_HINT_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索 PerformanceHintManager 以访问性能提示服务。

String POWER_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 PowerManager 以控制电源管理,包括“唤醒锁定”,让您可以在运行长时间任务时让设备保持开启状态。

String PRINT_SERVICE

PrintManager,用于打印和管理打印机和打印任务。

int RECEIVER_EXPORTED

registerReceiver(BroadcastReceiver, IntentFilter) 的标志:接收器可以接收来自其他应用的广播。

int RECEIVER_NOT_EXPORTED

registerReceiver(BroadcastReceiver, IntentFilter) 的标志:接收器无法接收来自其他应用的广播。

int RECEIVER_VISIBLE_TO_INSTANT_APPS

registerReceiver(BroadcastReceiver, IntentFilter) 的标志:接收器可以接收来自免安装应用的广播。

String RESTRICTIONS_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 RestrictionsManager,以检索应用限制并请求执行受限操作的权限。

String ROLE_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索用于管理角色的 RoleManager

String SEARCH_SERVICE

getSystemService(java.lang.String) 配合使用可检索用于处理搜索的 SearchManager

String SENSOR_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索用于访问传感器的 SensorManager

String SHORTCUT_SERVICE

getSystemService(java.lang.String) 搭配使用,以检索用于访问启动器快捷方式服务的 ShortcutManager

String STATUS_BAR_SERVICE

getSystemService(java.lang.String) 配合使用以检索 StatusBarManager,以便与状态栏和快捷设置进行交互。

String STORAGE_SERVICE

getSystemService(java.lang.String) 配合使用以检索用于访问系统存储函数的 StorageManager

String STORAGE_STATS_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 StorageStatsManager,以访问系统存储统计信息。

String SYSTEM_HEALTH_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 SystemHealthManager,以访问系统运行状况(电池、电源、内存等)指标。

String TELECOM_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 TelecomManager,以管理设备的与电信相关的功能。

String TELEPHONY_IMS_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 ImsManager

String TELEPHONY_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 TelephonyManager 以处理设备的电话功能管理。

String TELEPHONY_SUBSCRIPTION_SERVICE

getSystemService(java.lang.String) 配合使用以检索 SubscriptionManager,用于管理设备的电话订阅。

String TEXT_CLASSIFICATION_SERVICE

getSystemService(java.lang.String) 配合使用以检索文本分类服务的 TextClassificationManager

String TEXT_SERVICES_MANAGER_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 TextServicesManager 以访问短信服务。

String TV_INPUT_SERVICE

getSystemService(java.lang.String) 配合使用以检索 TvInputManager,以便与设备上的 TV 输入进行交互。

String TV_INTERACTIVE_APP_SERVICE

getSystemService(java.lang.String) 配合使用以检索 TvInteractiveAppManager,以便与设备上的 TV 互动式应用进行交互。

String UI_MODE_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索用于控制界面模式的 UiModeManager

String USAGE_STATS_SERVICE

getSystemService(java.lang.String) 配合使用以检索 UsageStatsManager,用于查询设备使用情况统计信息。

String USB_SERVICE

getSystemService(java.lang.String) 配合使用以检索 UsbManager,以便访问 USB 设备(作为 USB 主机)以及控制此设备作为 USB 设备的行为。

String USER_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 UserManager,以便在支持多用户的设备上管理用户。

String VIBRATOR_MANAGER_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 VibratorManager,以访问设备振动器、与各个振动器互动,以及在多个振动器上播放同步效果。

String VIBRATOR_SERVICE

此常量已在 API 级别 31 中废弃。 使用 VibratorManager 检索默认的系统振动器。

String VIRTUAL_DEVICE_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索用于管理虚拟设备的 VirtualDeviceManager

String VPN_MANAGEMENT_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 VpnManager,以管理平台内置 VPN 的配置文件。

String WALLPAPER_SERVICE

getSystemService(java.lang.String) 配合使用以检索 com.android.server.WallpaperService,以便访问壁纸。

String WIFI_AWARE_SERVICE

getSystemService(java.lang.String) 配合使用以检索 WifiAwareManager,以便处理 Wi-Fi 感知管理。

String WIFI_P2P_SERVICE

getSystemService(java.lang.String) 配合使用以检索 WifiP2pManager,用于处理 Wi-Fi 点对点连接管理。

String WIFI_RTT_RANGING_SERVICE

getSystemService(java.lang.String) 搭配使用,可为具有 Wi-Fi 的测距设备检索 WifiRttManager

String WIFI_SERVICE

getSystemService(java.lang.String) 搭配使用,用于检索 WifiManager 以处理 Wi-Fi 访问权限的管理。

String WINDOW_SERVICE

getSystemService(java.lang.String) 搭配使用可检索 WindowManager,以访问系统的窗口管理器。

int TRIM_MEMORY_BACKGROUND

onTrimMemory(int) 的级别:进程已进入 LRU 列表。

int TRIM_MEMORY_COMPLETE

onTrimMemory(int) 的级别:进程已接近后台 LRU 列表的末尾,如果很快未找到更多内存,该进程将被终止。

int TRIM_MEMORY_MODERATE

onTrimMemory(int) 的级别:该进程位于后台 LRU 列表的中间位置;释放内存有助于系统让列表中较后运行的其他进程保持运行,从而提升整体性能。

int TRIM_MEMORY_RUNNING_CRITICAL

onTrimMemory(int) 的级别:进程不是可舍弃的后台进程,但设备的内存用量极低,即将无法继续运行任何后台进程。

int TRIM_MEMORY_RUNNING_LOW

onTrimMemory(int) 的级别:进程不是可舍弃的后台进程,但设备内存不足。

int TRIM_MEMORY_RUNNING_MODERATE

onTrimMemory(int) 的级别:该进程不是可扩展的后台进程,但设备的内存适度较低。

int TRIM_MEMORY_UI_HIDDEN

onTrimMemory(int) 的级别:该进程之前显示了界面,但现在不再显示。

公共构造函数

IsolatedService()

公共方法

final EventUrlProvider getEventUrlProvider(RequestToken requestToken)

返回当前请求的 EventUrlProvider

final FederatedComputeScheduler getFederatedComputeScheduler(RequestToken requestToken)

返回当前请求的 FederatedComputeScheduler

final MutableKeyValueStore getLocalData(RequestToken requestToken)

返回 LOCAL_DATA 表的数据访问对象。

final LogReader getLogReader(RequestToken requestToken)

返回 REQUESTS 和 EVENTS 表的 DAO,用于提供对 IsolatedService 可读取的行访问权限。

final KeyValueStore getRemoteData(RequestToken requestToken)

返回 REMOTE_DATA 表的数据访问对象。

final UserData getUserData(RequestToken requestToken)

返回当前请求的平台提供的 UserData

IBinder onBind(Intent intent)

处理与 IsolatedService 的绑定。

void onCreate()

IsolatedService 创建 binder。

abstract IsolatedWorker onRequest(RequestToken requestToken)

返回用于处理客户端请求的 IsolatedWorker 实例。

继承的方法

void attachBaseContext(Context newBase)

设置此 ContextWrapper 的基本上下文。

void dump(FileDescriptor fd, PrintWriter writer, String[] args)

将服务的状态输出到给定流中。

final Application getApplication()

返回拥有此服务的应用。

final int getForegroundServiceType()

如果服务已通过调用 startForeground(int, android.app.Notification)startForeground(int, android.app.Notification, int) 成为前台服务,getForegroundServiceType() 会返回当前的前台服务类型。

abstract IBinder onBind(Intent intent)

将通信通道返回给服务。

void onConfigurationChanged(Configuration newConfig)

当组件运行时设备配置发生变化时,系统会调用此方法。

void onCreate()

系统在首次创建服务时调用。

void onDestroy()

由系统调用,用于通知服务它已不再使用且将被移除。

void onLowMemory()

当整个系统内存不足时,系统会调用此方法,并且正在运行的进程应缩减其内存用量。

void onRebind(Intent intent)

在新客户端连接到服务时调用此语句(之前已收到通知,所有客户端均已在其 onUnbind(Intent) 中断开连接)。

void onStart(Intent intent, int startId)

此方法在 API 级别 15 中已废弃。 改为实现 onStartCommand(android.content.Intent, int, int)

int onStartCommand(Intent intent, int flags, int startId)

每当客户端通过调用 Context.startService(Intent) 显式启动服务时,系统都会调用此方法,并提供它提供的参数以及表示启动请求的唯一整数令牌。

void onTaskRemoved(Intent rootIntent)

如果服务当前正在运行,并且用户已移除来自服务应用的任务,则调用此方法。

void onTimeout(int startId)

ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE 超时时调用的回调。

void onTrimMemory(int level)

当操作系统确定进程从其进程中剪除不需要的内存时调用。

boolean onUnbind(Intent intent)

当所有客户端都与服务发布的特定接口断开连接时调用。

final void startForeground(int id, Notification notification)

如果您的服务已启动(通过 Context#startService(Intent) 运行),请同时让此服务在前台运行,并提供持续性通知,以便在这种状态下向用户显示。

final void startForeground(int id, Notification notification, int foregroundServiceType)

具有额外 foregroundServiceType 参数的 startForeground(int, android.app.Notification) 过载版本。

final void stopForeground(int notificationBehavior)

将此服务从前台状态移除,以便在需要更多内存时将其终止。

final void stopForeground(boolean removeNotification)

此方法在 API 级别 33 中已废弃。 请改为调用 stopForeground(int) 并显式传递 STOP_FOREGROUND_REMOVESTOP_FOREGROUND_DETACH

final void stopSelf()

停止服务(如果之前已启动)。

final void stopSelf(int startId)

旧版 stopSelfResult(int) 不会返回结果。

final boolean stopSelfResult(int startId)

如果服务最近一次启动的时间为 startId,则停止该服务。

void attachBaseContext(Context base)

设置此 ContextWrapper 的基本上下文。

boolean bindIsolatedService(Intent service, int flags, String instanceName, Executor executor, ServiceConnection conn)

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的变体,在隔离服务的特定情况下,允许调用方从单个组件声明生成服务的多个实例。

boolean bindService(Intent service, int flags, Executor executor, ServiceConnection conn)

bindService(Intent, ServiceConnection, int) 相同,具有执行器来控制 ServiceConnection 回调。

boolean bindService(Intent service, ServiceConnection conn, Context.BindServiceFlags flags)

请参阅 bindService(android.content.Intent, android.content.ServiceConnection, int) 调用 BindServiceFlags#of(long) 以获取 BindServiceFlags 对象。

boolean bindService(Intent service, ServiceConnection conn, int flags)

连接到应用服务,并根据需要创建该服务。

boolean bindService(Intent service, Context.BindServiceFlags flags, Executor executor, ServiceConnection conn)

请参阅 bindService(android.content.Intent, int, java.util.concurrent.Executor, android.content.ServiceConnection) 调用 BindServiceFlags#of(long) 以获取 BindServiceFlags 对象。

int checkCallingOrSelfPermission(String permission)

确定 IPC 的调用进程或您是否已获得特定权限。

int checkCallingOrSelfUriPermission(Uri uri, int modeFlags)

确定 IPC 的调用进程或您是否已获得访问特定 URI 的权限。

int[] checkCallingOrSelfUriPermissions(List<Uri> uris, int modeFlags)

确定 IPC 的调用进程或您是否已获准访问 URI 列表。

int checkCallingPermission(String permission)

确定您正在处理的 IPC 的调用进程是否已获得特定权限。

int checkCallingUriPermission(Uri uri, int modeFlags)

确定是否已向调用进程和用户 ID 授予访问特定 URI 的权限。

int[] checkCallingUriPermissions(List<Uri> uris, int modeFlags)

确定调用进程和用户 ID 是否已获得访问 URI 列表的权限。

int checkPermission(String permission, int pid, int uid)

确定是否允许为系统中运行的特定进程和用户 ID 授予给定权限。

int checkSelfPermission(String permission)

确定是否已获得特定权限。

int checkUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags)

检查 URI 和一般权限。

int checkUriPermission(Uri uri, int pid, int uid, int modeFlags)

确定是否已向特定进程和用户 ID 授予访问特定 URI 的权限。

int[] checkUriPermissions(List<Uri> uris, int pid, int uid, int modeFlags)

确定是否已向特定进程和用户 ID 授予访问 URI 列表的权限。

void clearWallpaper()

此方法已废弃。 请改用 WallpaperManager.clear()

此方法要求调用方拥有 Manifest.permission.SET_WALLPAPER 权限。

Context createAttributionContext(String attributionTag)

为当前上下文返回一个新的上下文对象,但将其归因于其他代码。

Context createConfigurationContext(Configuration overrideConfiguration)

返回当前上下文的新上下文对象,但其资源会调整为与给定配置相匹配。

Context createContext(ContextParams contextParams)

创建具有特定属性和行为的上下文。

Context createDeviceContext(int deviceId)

从当前上下文返回一个新的 Context 对象,但具有 deviceId 提供的设备关联。

Context createDeviceProtectedStorageContext()

为当前 Context 返回一个新的 Context 对象,但其存储 API 由设备保护的存储空间支持。

Context createDisplayContext(Display display)

从当前上下文返回一个新的 Context 对象,但系统会调整资源以匹配 display 的指标。

Context createPackageContext(String packageName, int flags)

为指定的应用名称返回一个新的 Context 对象。

Context createWindowContext(int type, Bundle options)

为非 activity 窗口创建上下文。

Context createWindowContext(Display display, int type, Bundle options)

为给定 Display 上的非 activity 窗口创建 Context

String[] databaseList()

返回一个字符串数组,其中包含与此上下文的应用软件包关联的私有数据库的名称。

boolean deleteDatabase(String name)

删除与此上下文的应用软件包关联的现有私有 SQLiteDatabase。

boolean deleteFile(String name)

删除与此上下文的应用软件包关联的给定私有文件。

boolean deleteSharedPreferences(String name)

删除现有的共享偏好设置文件。

void enforceCallingOrSelfPermission(String permission, String message)

如果您或您正在处理的 IPC 的调用进程都未获得特定权限,请抛出 SecurityException

void enforceCallingOrSelfUriPermission(Uri uri, int modeFlags, String message)

如果 IPC 的调用进程或您未获准访问特定 URI,请抛出 SecurityException

void enforceCallingPermission(String permission, String message)

如果您正在处理的 IPC 的调用进程尚未获得特定权限,请抛出 SecurityException

void enforceCallingUriPermission(Uri uri, int modeFlags, String message)

如果未向调用进程和用户 ID 授予访问特定 URI 的权限,则抛出 SecurityException

void enforcePermission(String permission, int pid, int uid, String message)

如果不允许在系统中运行的特定进程和用户 ID 使用给定权限,请抛出 SecurityException

void enforceUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags, String message)

同时强制执行 URI 权限和普通权限。

void enforceUriPermission(Uri uri, int pid, int uid, int modeFlags, String message)

如果未向特定进程和用户 ID 授予访问特定 URI 的权限,则抛出 SecurityException

String[] fileList()

返回一个字符串数组,其中包含与此上下文的应用软件包关联的私有文件的名称。

Context getApplicationContext()

返回当前进程的单个全局 Application 对象的上下文。

ApplicationInfo getApplicationInfo()

返回此上下文软件包的完整应用信息。

AssetManager getAssets()

返回应用软件包的 AssetManager 实例。

AttributionSource getAttributionSource()

Context getBaseContext()
File getCacheDir()

返回文件系统上应用专属缓存目录的绝对路径。

ClassLoader getClassLoader()

返回一个可用于检索此软件包中的类的类加载器。

File getCodeCacheDir()

返回文件系统上用于存储缓存代码的应用的专属缓存目录的绝对路径。

ContentResolver getContentResolver()

返回应用软件包的 ContentResolver 实例。

File getDataDir()

返回文件系统上存储属于此应用的所有不公开文件的目录的绝对路径。

File getDatabasePath(String name)

返回文件系统中用于存储使用 openOrCreateDatabase(String, int, CursorFactory) 创建的数据库的绝对路径。

int getDeviceId()

获取此上下文关联的设备 ID。

File getDir(String name, int mode)

检索和创建(如果需要)一个新目录,应用可在该目录中放置自己的自定义数据文件。

Display getDisplay()

获取与此上下文关联的显示屏。

File getExternalCacheDir()

返回主共享/外部存储设备上应用专用目录的绝对路径,应用可在该目录中放置其拥有的缓存文件。

File[] getExternalCacheDirs()

返回所有共享/外部存储设备(应用可以将自己的缓存文件放在其中)上的应用专属目录的绝对路径。

File getExternalFilesDir(String type)

返回主要共享/外部存储设备上目录的绝对路径,应用可以将其拥有的永久性文件放置在此目录中。

File[] getExternalFilesDirs(String type)

返回所有共享/外部存储设备上应用专用目录的绝对路径,应用可以将其拥有的永久性文件放置在这些目录中。

File[] getExternalMediaDirs()

此方法已废弃。 这些目录仍然存在并会被扫描,但我们建议开发者改为直接将内容插入 MediaStore 集合,因为从 Build.VERSION_CODES.Q 开始,任何应用都可以向 MediaStore 贡献新媒体,而无需任何权限。

File getFileStreamPath(String name)

返回文件系统中存储使用 openFileOutput(String, int) 创建的文件的绝对路径。

File getFilesDir()

返回文件系统中用于存储使用 openFileOutput(String, int) 创建的文件的目录的绝对路径。

Executor getMainExecutor()

返回一个 Executor,该 Executor 将在与此上下文关联的主线程上运行已加入队列的任务。

Looper getMainLooper()

返回当前进程的主线程的 Looper。

File getNoBackupFilesDir()

返回文件系统上目录的绝对路径,类似于 getFilesDir()

File getObbDir()

返回可找到此应用的 OBB 文件(如果有)的主要共享/外部存储目录。

File[] getObbDirs()

返回所有共享/外部存储设备(其中可以找到应用的 OBB 文件(如果有))上的应用专用目录的绝对路径。

String getPackageCodePath()

返回此上下文的主要 Android 软件包的完整路径。

PackageManager getPackageManager()

返回 PackageManager 实例以查找全局软件包信息。

String getPackageName()

返回此应用软件包的名称。

String getPackageResourcePath()

返回此上下文的主要 Android 软件包的完整路径。

ContextParams getParams()

返回用于创建此上下文的一组参数(如果是通过 createContext(android.content.ContextParams) 创建的)。

Resources getResources()

返回应用软件包的 Resources 实例。

SharedPreferences getSharedPreferences(String name, int mode)

检索并保留偏好设置文件“name”的内容,返回一个 SharedPreferences,您可以通过该 SharedPreferences 检索和修改其值。

Object getSystemService(String name)

按名称将句柄返回到系统级服务。

String getSystemServiceName(Class<?> serviceClass)

获取由指定类表示的系统级服务的名称。

Resources.Theme getTheme()

返回与此上下文关联的 Theme 对象。

Drawable getWallpaper()

此方法已废弃。 请改用 WallpaperManager.get()

int getWallpaperDesiredMinimumHeight()

此方法已废弃。 请改用 WallpaperManager.getDesiredMinimumHeight()

int getWallpaperDesiredMinimumWidth()

此方法已废弃。 请改用 WallpaperManager.getDesiredMinimumWidth()

void grantUriPermission(String toPackage, Uri uri, int modeFlags)

向其他软件包授予访问特定 URI 的权限,无论该软件包是否具有访问该 URI 的内容提供程序的一般权限。

boolean isDeviceProtectedStorage()

指示此上下文的存储 API 是否由设备保护的存储空间支持。

boolean isRestricted()

指示此 Context 是否受到限制。

boolean moveDatabaseFrom(Context sourceContext, String name)

将现有数据库文件从给定的来源存储上下文移至此上下文。

boolean moveSharedPreferencesFrom(Context sourceContext, String name)

将现有的共享偏好设置文件从给定的源存储上下文移至此上下文。

FileInputStream openFileInput(String name)

打开与此 Context 的应用软件包关联的私有文件以供读取。

FileOutputStream openFileOutput(String name, int mode)

打开与此上下文的应用软件包关联的私有文件以进行写入。

SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler)

打开与此上下文的应用软件包关联的新私有 SQLiteDatabase。

SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory)

打开与此上下文的应用软件包关联的新私有 SQLiteDatabase。

Drawable peekWallpaper()

此方法已废弃。 请改用 WallpaperManager.peek()

void registerComponentCallbacks(ComponentCallbacks callback)

将新的 ComponentCallbacks 添加到 Context 的基础应用中,系统会在调用 Activity 和其他组件的 ComponentCallbacks 方法的同时调用该应用。

void registerDeviceIdChangeListener(Executor executor, IntConsumer listener)

Context 添加新的设备 ID 已更改监听器,系统会在系统更改设备关联时调用该监听器。

Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter)

注册要在主 activity 线程中运行的 BroadcastReceiver。

Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, int flags)

注册以接收 intent 广播,接收器可选择性地公开给即时应用。

Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler, int flags)

注册以接收 intent 广播,以便在 scheduler 上下文中运行。

Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler)

注册以接收 intent 广播,以便在 scheduler 上下文中运行。

void removeStickyBroadcast(Intent intent)

此方法已废弃。 请勿使用粘性广播。它们既不提供安全保障(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某项内容已发生变化,并使用其他机制让应用根据需要检索当前值。

void removeStickyBroadcastAsUser(Intent intent, UserHandle user)

此方法已废弃。 请勿使用粘性广播。它们不提供任何安全性(任何人都可以访问它们)、不提供任何保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播来报告某些内容发生了变化,同时为应用提供另一种机制来在需要时检索当前值。

void revokeSelfPermissionsOnKill(Collection<String> permissions)

触发撤消调用软件包的一项或多项权限。

void revokeUriPermission(Uri uri, int modeFlags)

移除之前使用 grantUriPermission(String, Uri, int)任何其他机制添加的特定 content provider URI 的所有访问权限。

void revokeUriPermission(String targetPackage, Uri uri, int modeFlags)

移除了之前为特定目标软件包使用 grantUriPermission(String, Uri, int) 添加的用于访问特定 content provider URI 的权限。

void sendBroadcast(Intent intent, String receiverPermission, Bundle options)

将给定 intent 广播给所有感兴趣的 BroadcastReceiver,以便强制执行可选的必需权限。

void sendBroadcast(Intent intent, String receiverPermission)

将给定 intent 广播给所有感兴趣的 BroadcastReceiver,以便强制执行可选的必需权限。

void sendBroadcast(Intent intent)

将给定 intent 广播给所有感兴趣的 BroadcastReceiver。

void sendBroadcastAsUser(Intent intent, UserHandle user)

sendBroadcast(android.content.Intent) 版本,可让您指定要将广播发送给哪个用户。

void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission)

sendBroadcast(android.content.Intent, java.lang.String) 版本,可让您指定要将广播发送给哪位用户。

void sendOrderedBroadcast(Intent intent, String receiverPermission, String receiverAppOp, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle) 的版本,可让您指定应用操作以强制限制将广播发送到哪些接收器。

void sendOrderedBroadcast(Intent intent, int initialCode, String receiverPermission, String receiverAppOp, BroadcastReceiver resultReceiver, Handler scheduler, String initialData, Bundle initialExtras, Bundle options)

void sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

允许您从广播接收返回数据的 sendBroadcast(android.content.Intent) 版本。

void sendOrderedBroadcast(Intent intent, String receiverPermission, Bundle options)

将给定 intent 广播给所有感兴趣的 BroadcastReceiver,一次发送一个,以便让更优先的接收器先收到广播,然后再发送给优先级较低的接收器。

void sendOrderedBroadcast(Intent intent, String receiverPermission, Bundle options, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

sendBroadcast(android.content.Intent) 版本,可让您从广播接收数据。

void sendOrderedBroadcast(Intent intent, String receiverPermission)

向所有感兴趣的 BroadcastReceiver 广播给定的 intent,一次传送一个 intent,以便更多首选接收器在传送给不太偏好的接收器之前使用广播。

void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle) 的版本,可让您指定接收广播的用户。

void sendStickyBroadcast(Intent intent)

此方法已废弃。 请勿使用粘性广播。它们既不提供安全性(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某项内容已发生变化,并使用其他机制让应用根据需要检索当前值。

void sendStickyBroadcast(Intent intent, Bundle options)

此方法已废弃。 请勿使用粘性广播。它们既不提供安全性(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某项内容已发生变化,并使用其他机制让应用根据需要检索当前值。

void sendStickyBroadcastAsUser(Intent intent, UserHandle user)

此方法已废弃。 请勿使用粘性广播。它们既不提供安全性(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某项内容已发生变化,并使用其他机制让应用根据需要检索当前值。

void sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

此方法已废弃。 请勿使用粘性广播。它们既不提供安全性(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某项内容已发生变化,并使用其他机制让应用根据需要检索当前值。

void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

此方法已废弃。 请勿使用粘性广播。它们既不提供安全性(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某些内容已发生变化,并使用其他机制让应用根据需要检索当前值。

void setTheme(int resid)

为此上下文设置基础主题。

void setWallpaper(Bitmap bitmap)

此方法已废弃。 请改用 WallpaperManager.set()

此方法要求调用方拥有 Manifest.permission.SET_WALLPAPER 权限。

void setWallpaper(InputStream data)

此方法已废弃。 请改用 WallpaperManager.set()

此方法要求调用方拥有 Manifest.permission.SET_WALLPAPER 权限。

void startActivities(Intent[] intents, Bundle options)

启动多个新 activity。

void startActivities(Intent[] intents)

与未指定任何选项的 startActivities(android.content.Intent[], android.os.Bundle) 相同。

void startActivity(Intent intent)

startActivity(android.content.Intent, android.os.Bundle) 相同,但不指定任何选项。

void startActivity(Intent intent, Bundle options)

启动一个新 activity。

ComponentName startForegroundService(Intent service)

startService(android.content.Intent) 类似,但带有隐式 promise,即 Service 会在开始运行后调用 startForeground(int, android.app.Notification)

boolean startInstrumentation(ComponentName className, String profileFile, Bundle arguments)

开始执行 Instrumentation 类。

void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)

startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int, android.os.Bundle) 相同,未指定选项。

void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)

startActivity(android.content.Intent, android.os.Bundle) 类似,但使用 IntentSender 进行启动。

ComponentName startService(Intent service)

请求启动给定应用服务。

boolean stopService(Intent name)

请求停止给定应用服务。

void unbindService(ServiceConnection conn)

断开与应用服务的连接。

void unregisterComponentCallbacks(ComponentCallbacks callback)

移除之前使用 registerComponentCallbacks(android.content.ComponentCallbacks) 注册的 ComponentCallbacks 对象。

void unregisterDeviceIdChangeListener(IntConsumer listener)

从上下文中移除设备 ID 更改监听器。

void unregisterReceiver(BroadcastReceiver receiver)

取消注册之前注册的 BroadcastReceiver。

void updateServiceGroup(ServiceConnection conn, int group, int importance)

对于先前与 bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 或相关方法绑定的服务,更改系统管理该服务进程相对于其他进程的方式。

boolean bindIsolatedService(Intent service, int flags, String instanceName, Executor executor, ServiceConnection conn)

bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 的变体,在隔离服务的特定情况下,允许调用方从单个组件声明生成服务的多个实例。

boolean bindIsolatedService(Intent service, Context.BindServiceFlags flags, String instanceName, Executor executor, ServiceConnection conn)

请参阅 bindIsolatedService(android.content.Intent, int, java.lang.String, java.util.concurrent.Executor, android.content.ServiceConnection) 调用 BindServiceFlags#of(long) 以获取 BindServiceFlags 对象。

boolean bindService(Intent service, int flags, Executor executor, ServiceConnection conn)

bindService(Intent, ServiceConnection, int) 相同,但使用执行器来控制 ServiceConnection 回调。

boolean bindService(Intent service, ServiceConnection conn, Context.BindServiceFlags flags)

请参阅 bindService(android.content.Intent, android.content.ServiceConnection, int) 调用 BindServiceFlags#of(long) 以获取 BindServiceFlags 对象。

abstract boolean bindService(Intent service, ServiceConnection conn, int flags)

连接到应用服务,并根据需要创建该服务。

boolean bindService(Intent service, Context.BindServiceFlags flags, Executor executor, ServiceConnection conn)

请参阅bindService(android.content.Intent, int, java.util.concurrent.Executor, android.content.ServiceConnection) 调用 BindServiceFlags#of(long) 以获取 BindServiceFlags 对象。

boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user)

以与 bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 相同的方式绑定到给定 user 中的服务。

boolean bindServiceAsUser(Intent service, ServiceConnection conn, Context.BindServiceFlags flags, UserHandle user)

请参阅bindServiceAsUser(android.content.Intent, android.content.ServiceConnection, int, android.os.UserHandle) 调用 BindServiceFlags#of(long) 以获取 BindServiceFlags 对象。

abstract int checkCallingOrSelfPermission(String permission)

确定 IPC 的调用进程或您是否已获得特定权限。

abstract int checkCallingOrSelfUriPermission(Uri uri, int modeFlags)

确定 IPC 的调用进程或您是否已获得访问特定 URI 的权限。

int[] checkCallingOrSelfUriPermissions(List<Uri> uris, int modeFlags)

确定 IPC 的调用进程或您是否已获准访问 URI 列表。

abstract int checkCallingPermission(String permission)

确定您正在处理的 IPC 的调用进程是否已获得特定权限。

abstract int checkCallingUriPermission(Uri uri, int modeFlags)

确定是否已向调用进程和用户 ID 授予访问特定 URI 的权限。

int[] checkCallingUriPermissions(List<Uri> uris, int modeFlags)

确定调用进程和用户 ID 是否已获得访问 URI 列表的权限。

abstract int checkPermission(String permission, int pid, int uid)

确定是否允许为系统中运行的特定进程和用户 ID 授予给定权限。

abstract int checkSelfPermission(String permission)

确定是否已获得特定权限。

abstract int checkUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags)

检查 URI 和一般权限。

abstract int checkUriPermission(Uri uri, int pid, int uid, int modeFlags)

确定是否已向特定进程和用户 ID 授予访问特定 URI 的权限。

int[] checkUriPermissions(List<Uri> uris, int pid, int uid, int modeFlags)

确定是否已向特定进程和用户 ID 授予访问 URI 列表的权限。

abstract void clearWallpaper()

此方法在 API 级别 15 中已废弃。 请改用 WallpaperManager.clear()

此方法要求调用方拥有 Manifest.permission.SET_WALLPAPER 权限。

Context createAttributionContext(String attributionTag)

为当前上下文返回一个新的上下文对象,但将其归因于其他代码。

abstract Context createConfigurationContext(Configuration overrideConfiguration)

返回当前上下文的新上下文对象,但其资源会调整为与给定配置相匹配。

Context createContext(ContextParams contextParams)

创建具有特定属性和行为的上下文。

abstract Context createContextForSplit(String splitName)

返回指定分屏名称的新 Context 对象。

Context createDeviceContext(int deviceId)

从当前上下文返回一个新的 Context 对象,但该对象具有 deviceId 指定的设备关联。

abstract Context createDeviceProtectedStorageContext()

为当前 Context 返回一个新的 Context 对象,但其存储 API 由设备保护的存储空间支持。

abstract Context createDisplayContext(Display display)

从当前上下文返回一个新的 Context 对象,但系统会调整资源以匹配 display 的指标。

abstract Context createPackageContext(String packageName, int flags)

为指定的应用名称返回一个新的 Context 对象。

Context createWindowContext(int type, Bundle options)

为非 activity 窗口创建 Context。

Context createWindowContext(Display display, int type, Bundle options)

为给定 Display 上的非 activity 窗口创建 Context

abstract String[] databaseList()

返回一个字符串数组,其中包含与此上下文的应用软件包关联的私有数据库的名称。

abstract boolean deleteDatabase(String name)

删除与此上下文的应用软件包关联的现有私有 SQLiteDatabase。

abstract boolean deleteFile(String name)

删除与此上下文的应用软件包关联的给定私有文件。

abstract boolean deleteSharedPreferences(String name)

删除现有的共享偏好设置文件。

abstract void enforceCallingOrSelfPermission(String permission, String message)

如果您或您正在处理的 IPC 的调用进程都未获得特定权限,请抛出 SecurityException

abstract void enforceCallingOrSelfUriPermission(Uri uri, int modeFlags, String message)

如果 IPC 的调用进程或您未获得访问特定 URI 的权限,请抛出 SecurityException

abstract void enforceCallingPermission(String permission, String message)

如果您正在处理的 IPC 的调用进程未获得特定权限,请抛出 SecurityException

abstract void enforceCallingUriPermission(Uri uri, int modeFlags, String message)

如果调用进程和用户 ID 未获得访问特定 URI 的权限,请抛出 SecurityException

abstract void enforcePermission(String permission, int pid, int uid, String message)

如果不允许在系统中运行的特定进程和用户 ID 使用给定权限,请抛出 SecurityException

abstract void enforceUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags, String message)

同时强制执行 URI 权限和普通权限。

abstract void enforceUriPermission(Uri uri, int pid, int uid, int modeFlags, String message)

如果特定进程和用户 ID 未获得访问特定 URI 的权限,请抛出 SecurityException

abstract String[] fileList()

返回一个字符串数组,其中包含与此上下文的应用软件包关联的私有文件的名称。

abstract Context getApplicationContext()

返回当前进程的单个全局 Application 对象的上下文。

abstract ApplicationInfo getApplicationInfo()

返回此上下文软件包的完整应用信息。

abstract AssetManager getAssets()

返回应用软件包的 AssetManager 实例。

AttributionSource getAttributionSource()
String getAttributionTag()

在复杂的应用中,可以使用归因工具从逻辑上分离应用的各个部分。

abstract File getCacheDir()

返回文件系统上应用专属缓存目录的绝对路径。

abstract ClassLoader getClassLoader()

返回一个可用于检索此软件包中的类的类加载器。

abstract File getCodeCacheDir()

返回文件系统中用于存储缓存代码的应用专用缓存目录的绝对路径。

final int getColor(int id)

返回与特定资源 ID 相关联且采用当前主题样式的颜色。

final ColorStateList getColorStateList(int id)

返回与特定资源 ID 相关联且采用当前主题样式的颜色状态列表。

abstract ContentResolver getContentResolver()

返回应用软件包的 ContentResolver 实例。

abstract File getDataDir()

返回文件系统上存储属于此应用的所有不公开文件的目录的绝对路径。

abstract File getDatabasePath(String name)

返回文件系统中用于存储使用 openOrCreateDatabase(String, int, CursorFactory) 创建的数据库的绝对路径。

int getDeviceId()

获取此上下文关联的设备 ID。

abstract File getDir(String name, int mode)

检索和创建(如果需要)一个新目录,应用可在该目录中放置自己的自定义数据文件。

Display getDisplay()

获取与此上下文关联的屏幕。

final Drawable getDrawable(int id)

返回与特定资源 ID 关联且采用当前主题样式的可绘制对象。

abstract File getExternalCacheDir()

返回主共享/外部存储设备上应用专用目录的绝对路径,应用可在该目录中放置其拥有的缓存文件。

abstract File[] getExternalCacheDirs()

返回所有共享/外部存储设备(应用可以将自己的缓存文件放在其中)上的应用专属目录的绝对路径。

abstract File getExternalFilesDir(String type)

返回主要共享/外部存储设备上目录的绝对路径,应用可以将其拥有的永久性文件放置在此目录中。

abstract File[] getExternalFilesDirs(String type)

返回所有共享/外部存储设备上应用专用目录的绝对路径,应用可以将其拥有的永久性文件放置在这些目录中。

abstract File[] getExternalMediaDirs()

此方法在 API 级别 30 中已废弃。 这些目录仍然存在并会被扫描,但我们建议开发者改为直接将内容插入 MediaStore 集合,因为从 Build.VERSION_CODES.Q 开始,任何应用都可以向 MediaStore 贡献新媒体,而无需任何权限。

abstract File getFileStreamPath(String name)

返回文件系统中存储使用 openFileOutput(String, int) 创建的文件的绝对路径。

abstract File getFilesDir()

返回文件系统中用于存储使用 openFileOutput(String, int) 创建的文件的目录的绝对路径。

Executor getMainExecutor()

返回一个 Executor,它会在与此上下文关联的主线程上运行已加入队列的任务。

abstract Looper getMainLooper()

为当前进程的主线程返回环路。

abstract File getNoBackupFilesDir()

返回文件系统上目录的绝对路径,类似于 getFilesDir()

abstract File getObbDir()

返回主要的共享/外部存储目录,您可以在其中找到此应用的 OBB 文件(如果有)。

abstract File[] getObbDirs()

返回所有共享/外部存储设备上应用专用目录的绝对路径,其中包含应用的 OBB 文件(如果有)。

String getOpPackageName()

返回应在此上下文中用于 AppOpsManager 调用的软件包名称,以便应用操作管理器的 uid 验证能够使用该名称。

abstract String getPackageCodePath()

返回此上下文的主要 Android 软件包的完整路径。

abstract PackageManager getPackageManager()

返回 PackageManager 实例以查找全局软件包信息。

abstract String getPackageName()

返回此应用软件包的名称。

abstract String getPackageResourcePath()

返回此上下文的主要 Android 软件包的完整路径。

ContextParams getParams()

如果 Context 是通过 createContext(android.content.ContextParams) 创建的,则返回创建此 Context 时所用的参数集。

abstract Resources getResources()

返回应用软件包的 Resources 实例。

abstract SharedPreferences getSharedPreferences(String name, int mode)

检索并保留偏好设置文件“name”的内容,返回一个 SharedPreferences,您可以通过该 SharedPreferences 检索和修改其值。

final String getString(int resId)

从应用软件包的默认字符串表中返回已本地化的字符串。

final String getString(int resId, Object... formatArgs)

从应用软件包的默认字符串表中返回已本地化的格式字符串,替换 FormatterString.format(String, Object) 中定义的格式参数。

final <T> T getSystemService(Class<T> serviceClass)

将句柄按类别返回到系统级服务。

abstract Object getSystemService(String name)

按名称将句柄返回到系统级服务。

abstract String getSystemServiceName(Class<?> serviceClass)

获取由指定类表示的系统级服务的名称。

final CharSequence getText(int resId)

从应用软件包的默认字符串表中返回已本地化的样式化 CharSequence。

abstract Resources.Theme getTheme()

返回与此 Context 关联的 Theme 对象。

abstract Drawable getWallpaper()

此方法在 API 级别 15 中已废弃。 请改用 WallpaperManager.get()

abstract int getWallpaperDesiredMinimumHeight()

此方法在 API 级别 15 中已废弃。 请改用 WallpaperManager.getDesiredMinimumHeight()

abstract int getWallpaperDesiredMinimumWidth()

此方法在 API 级别 15 中已废弃。 请改用 WallpaperManager.getDesiredMinimumWidth()

abstract void grantUriPermission(String toPackage, Uri uri, int modeFlags)

向其他软件包授予访问特定 URI 的权限,无论该软件包是否具有访问该 URI 的内容提供程序的一般权限。

abstract boolean isDeviceProtectedStorage()

指示此上下文的存储 API 是否由设备保护的存储空间支持。

boolean isRestricted()

指示此 Context 是否受到限制。

boolean isUiContext()

如果上下文是可以访问 WindowManagerLayoutInflaterWallpaperManager 等界面组件的界面上下文,则返回 true

abstract boolean moveDatabaseFrom(Context sourceContext, String name)

将现有数据库文件从给定的源存储上下文移至此上下文。

abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name)

将现有的共享偏好设置文件从给定的源存储上下文移至此上下文。

final TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs)

在此 Context 的主题中检索带样式的属性信息。

final TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes)

在此 Context 的主题中检索带样式的属性信息。

final TypedArray obtainStyledAttributes(int resid, int[] attrs)

在此 Context 的主题中检索带样式的属性信息。

final TypedArray obtainStyledAttributes(int[] attrs)

检索此上下文主题中的样式属性信息。

abstract FileInputStream openFileInput(String name)

打开与此 Context 的应用软件包关联的私有文件以供读取。

abstract FileOutputStream openFileOutput(String name, int mode)

打开与此上下文的应用软件包关联的私有文件以进行写入。

abstract SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler)

打开与此上下文的应用软件包关联的新私有 SQLiteDatabase。

abstract SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory)

打开与此上下文的应用软件包关联的新私有 SQLiteDatabase。

abstract Drawable peekWallpaper()

此方法在 API 级别 15 中已废弃。 请改用 WallpaperManager.peek()

void registerComponentCallbacks(ComponentCallbacks callback)

将新的 ComponentCallbacks 添加到上下文的基础应用中,系统会在调用 activity 和其他组件的 ComponentCallbacks 方法时调用该 ComponentCallbacks

void registerDeviceIdChangeListener(Executor executor, IntConsumer listener)

Context 添加了新的设备 ID 更改监听器,系统更改设备关联时会调用该监听器。

abstract Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter)

注册要在主 activity 线程中运行的 BroadcastReceiver。

abstract Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, int flags)

注册以接收 intent 广播,接收器可选择性地公开给即时应用。

abstract Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler, int flags)

注册以接收 intent 广播,以便在 scheduler 上下文中运行。

abstract Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler)

注册以接收 intent 广播,以便在 scheduler 上下文中运行。

abstract void removeStickyBroadcast(Intent intent)

此方法在 API 级别 21 中已废弃。 请勿使用粘性广播。它们既不提供安全保障(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某些内容已发生变化,并使用其他机制让应用根据需要检索当前值。

abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user)

此方法在 API 级别 21 中已废弃。 请勿使用粘性广播。它们既不提供安全保障(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某些内容已发生变化,并使用其他机制让应用根据需要检索当前值。

void revokeSelfPermissionOnKill(String permName)

触发异步撤消运行时权限。

void revokeSelfPermissionsOnKill(Collection<String> permissions)

触发撤消调用软件包的一项或多项权限。

abstract void revokeUriPermission(Uri uri, int modeFlags)

移除之前使用 grantUriPermission(String, Uri, int)任何其他机制添加的用于访问特定 content provider Uri 的所有权限。

abstract void revokeUriPermission(String toPackage, Uri uri, int modeFlags)

移除了之前为特定目标软件包使用 grantUriPermission(String, Uri, int) 添加的用于访问特定内容提供方 URI 的权限。

void sendBroadcast(Intent intent, String receiverPermission, Bundle options)

将给定 intent 广播给所有感兴趣的 BroadcastReceiver,以便强制执行可选的必需权限。

abstract void sendBroadcast(Intent intent, String receiverPermission)

将给定 intent 广播给所有感兴趣的 BroadcastReceiver,以便强制执行可选的必需权限。

abstract void sendBroadcast(Intent intent)

将给定 intent 广播给所有感兴趣的 BroadcastReceiver。

abstract void sendBroadcastAsUser(Intent intent, UserHandle user)

sendBroadcast(android.content.Intent) 版本,可让您指定要将广播发送给哪个用户。

abstract void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission)

sendBroadcast(android.content.Intent, java.lang.String) 版本,可让您指定要将广播发送给哪个用户。

void sendBroadcastWithMultiplePermissions(Intent intent, String[] receiverPermissions)

将给定 intent 广播给所有感兴趣的 BroadcastReceiver,以便强制执行一系列所需权限。

void sendOrderedBroadcast(Intent intent, String receiverPermission, String receiverAppOp, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle) 版本,可让您指定应用操作,以对要将广播发送到的接收器施加限制。

abstract void sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

sendBroadcast(android.content.Intent) 版本,可让您从广播接收数据。

void sendOrderedBroadcast(Intent intent, String receiverPermission, Bundle options)

将给定 intent 广播给所有感兴趣的 BroadcastReceiver,一次发送一个,以便让更优先的接收器先收到广播,然后再发送给优先级较低的接收器。

void sendOrderedBroadcast(Intent intent, String receiverPermission, Bundle options, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

sendBroadcast(android.content.Intent) 版本,可让您从广播接收数据。

abstract void sendOrderedBroadcast(Intent intent, String receiverPermission)

向所有感兴趣的 BroadcastReceiver 广播给定的 intent,一次传送一个 intent,以便更多首选接收器在传送给不太偏好的接收器之前使用广播。

abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle) 版本,可让您指定要将广播发送给哪个用户。

abstract void sendStickyBroadcast(Intent intent)

此方法在 API 级别 21 中已废弃。 请勿使用粘性广播。它们既不提供安全保障(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某些内容已发生变化,并使用其他机制让应用根据需要检索当前值。

void sendStickyBroadcast(Intent intent, Bundle options)

此方法在 API 级别 31 中已废弃。 请勿使用粘性广播。它们不提供任何安全性(任何人都可以访问它们)、不提供任何保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某些内容已发生变化,并使用其他机制让应用根据需要检索当前值。

abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user)

此方法在 API 级别 21 中已废弃。 请勿使用粘性广播。它们既不提供安全保障(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播来报告某些内容发生了变化,同时为应用提供另一种机制来在需要时检索当前值。

abstract void sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

此方法在 API 级别 21 中已废弃。 请勿使用粘性广播。它们既不提供安全保障(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播来报告某些内容发生了变化,同时为应用提供另一种机制来在需要时检索当前值。

abstract void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

此方法在 API 级别 21 中已废弃。 请勿使用粘性广播。它们既不提供安全性(任何人都可以访问它们),也不提供保护(任何人都可以修改它们),还存在许多其他问题。 推荐的模式是使用非粘性广播报告某项内容已发生变化,并使用其他机制让应用根据需要检索当前值。

abstract void setTheme(int resid)

为此上下文设置基本主题。

abstract void setWallpaper(Bitmap bitmap)

此方法在 API 级别 15 中已废弃。 请改用 WallpaperManager.set()

此方法要求调用方拥有 Manifest.permission.SET_WALLPAPER 权限。

abstract void setWallpaper(InputStream data)

此方法在 API 级别 15 中已废弃。 请改用 WallpaperManager.set()

此方法要求调用方拥有 Manifest.permission.SET_WALLPAPER 权限。

abstract void startActivities(Intent[] intents, Bundle options)

启动多个新 activity。

abstract void startActivities(Intent[] intents)

startActivities(android.content.Intent[], android.os.Bundle) 相同,但不指定任何选项。

abstract void startActivity(Intent intent)

startActivity(android.content.Intent, android.os.Bundle) 相同,但不指定任何选项。

abstract void startActivity(Intent intent, Bundle options)

启动新的 activity。

abstract ComponentName startForegroundService(Intent service)

startService(android.content.Intent) 类似,但隐式地承诺服务会在开始运行后调用 startForeground(int, android.app.Notification)

abstract boolean startInstrumentation(ComponentName className, String profileFile, Bundle arguments)

开始执行 Instrumentation 类。

abstract void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)

与未指定任何选项的 startIntentSender(android.content.IntentSender, android.content.Intent, int, int, int, android.os.Bundle) 相同。

abstract void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)

startActivity(android.content.Intent, android.os.Bundle) 类似,但需要启动 IntentSender。

abstract ComponentName startService(Intent service)

请求启动给定应用服务。

abstract boolean stopService(Intent service)

请求停止给定应用服务。

abstract void unbindService(ServiceConnection conn)

断开与应用服务的连接。

void unregisterComponentCallbacks(ComponentCallbacks callback)

移除之前使用 registerComponentCallbacks(android.content.ComponentCallbacks) 注册的 ComponentCallbacks 对象。

void unregisterDeviceIdChangeListener(IntConsumer listener)

从上下文中移除设备 ID 更改监听器。

abstract void unregisterReceiver(BroadcastReceiver receiver)

取消注册之前注册的 BroadcastReceiver。

void updateServiceGroup(ServiceConnection conn, int group, int importance)

对于之前使用 bindService(Intent, BindServiceFlags, Executor, ServiceConnection) 或相关方法绑定的服务,请更改系统管理该服务进程与其他进程关系的方式。

Object clone()

创建并返回此对象的副本。

boolean equals(Object obj)

指示某个其他对象是否“等于”此对象。

void finalize()

当垃圾回收功能确定对某个对象没有更多引用时,由垃圾回收器针对此对象调用该方法。

final Class<?> getClass()

返回此 Object 的运行时类。

int hashCode()

返回对象的哈希代码值。

final void notify()

唤醒正在等待此对象的监控器的单个线程。

final void notifyAll()

唤醒等待此对象监视器的所有线程。

String toString()

返回对象的字符串表示。

final void wait(long timeoutMillis, int nanos)

让当前线程进入等待状态,直到其被唤醒(通常在收到通知或被中断时),或者实际经过了一定的时间为止。

final void wait(long timeoutMillis)

使当前线程处于等待状态,直到其被唤醒(通常在收到通知或被中断时),或者实际经过了一定的时间。

final void wait()

让当前线程进入等待状态,直到其被唤醒(通常在收到通知或被中断时)

abstract void onTrimMemory(int level)

当操作系统确定进程从其进程中剪除不需要的内存时调用。

abstract void onConfigurationChanged(Configuration newConfig)

当组件运行时设备配置发生变化时,系统会调用此方法。

abstract void onLowMemory()

当整个系统内存不足时,系统会调用此方法,并且正在运行的进程应缩减其内存用量。

公共构造函数

IsolatedService 类中的静态方法

public IsolatedService ()

公共方法

getEventUrlProvider

public final EventUrlProvider getEventUrlProvider (RequestToken requestToken)

返回当前请求的 EventUrlProviderEventUrlProvider 提供可嵌入 HTML 中的网址。在 WebView 中呈现 HTML 时,平台会拦截对这些网址的请求并调用 IsolatedWorker#onEvent(EventInput, Consumer)

参数
requestToken RequestToken:一个不透明令牌,用于标识服务的当前请求。此值不能为 null

返回
EventUrlProvider 用于返回事件跟踪网址的 EventUrlProvider。此值不能为 null

getFederatedComputeScheduler

public final FederatedComputeScheduler getFederatedComputeScheduler (RequestToken requestToken)

返回当前请求的 FederatedComputeSchedulerFederatedComputeScheduler 可用于安排和取消联合计算作业。联邦计算包括联邦学习和联邦分析作业。

参数
requestToken RequestToken:一个不透明令牌,用于标识服务的当前请求。此值不能为 null

返回
FederatedComputeScheduler 用于返回联合计算作业调度程序的 FederatedComputeScheduler。 此值不能为 null

getLocalData

public final MutableKeyValueStore getLocalData (RequestToken requestToken)

返回 LOCAL_DATA 表的数据访问对象。LOCAL_DATA 表是一个持久性键值对存储区,该服务可以使用该存储区存储任何数据。此表的内容仅对在隔离进程中运行的服务可见,无法发送到设备外部。

参数
requestToken RequestToken:一个不透明令牌,用于标识服务的当前请求。此值不能为 null

返回
MutableKeyValueStore 用于访问 LOCAL_DATA 表的 MutableKeyValueStore 对象。 返回的 MutableKeyValueStore 中的方法是阻塞操作,应从工作器线程调用,而不是从主线程或 binder 线程调用。此值不能为 null

getLogReader

public final LogReader getLogReader (RequestToken requestToken)

为 REQUESTS 和 EVENTS 表返回一个 DAO,该表提供对 IsolatedService 可读取的行的访问权限。

参数
requestToken RequestToken:一个不透明令牌,用于标识服务的当前请求。此值不能为 null

返回
LogReader 一个 LogReader 对象,用于访问 REQUESTS 和 EVENTS 表。 返回的 LogReader 中的方法是阻塞操作,应从工作器线程调用,而不是从主线程或 binder 线程调用。此值不能为 null

getRemoteData

public final KeyValueStore getRemoteData (RequestToken requestToken)

返回 REMOTE_DATA 表的数据访问对象。REMOTE_DATA 表是一个只读键值对存储区,其中包含从服务 ODP 清单的 标记中声明的端点定期下载的数据,如以下示例所示。

<!-- Contents of res/xml/OdpSettings.xml -->
 <on-device-personalization>
 <!-- Name of the service subclass -->
 <service "com.example.odpsample.SampleService">
   <!-- If this tag is present, ODP will periodically poll this URL and
    download content to populate REMOTE_DATA. Adopters that do not need to
    download content from their servers can skip this tag. -->
   <download-settings url="https://example.com/get" />
 </service>
 </on-device-personalization>
 

参数
requestToken RequestToken:一个不透明令牌,用于标识服务的当前请求。此值不能为 null

返回
KeyValueStore 提供对 REMOTE_DATA 表的访问权限的 KeyValueStore 对象。返回的 KeyValueStore 中的方法是阻塞操作,应从工作器线程调用,而不是从主线程或 binder 线程调用。此值不能为 null

getUserData

public final UserData getUserData (RequestToken requestToken)

返回当前请求的平台提供的 UserData

参数
requestToken RequestToken:一个不透明令牌,用于标识服务的当前请求。此值不能为 null

返回
UserData 一个 UserData 对象。 此值可以为 null

onBind

public IBinder onBind (Intent intent)

处理与 IsolatedService 的绑定。

参数
intent Intent:用于绑定到此服务的 intent,已提供给 Context.bindService。请注意,此时与 intent 一起包含的任何 extra 都不会显示在此处。 此值不能为 null

返回
IBinder 此值可以为 null

onCreate

public void onCreate ()

IsolatedService 创建 binder。

onRequest

public abstract IsolatedWorker onRequest (RequestToken requestToken)

返回用于处理客户端请求的 IsolatedWorker 实例。

参数
requestToken RequestToken:一个不透明令牌,用于标识服务的当前请求,必须传递给依赖于每个请求状态的服务方法。 此值不能为 null

返回
IsolatedWorker 此值不能为 null