TestCarContext


public class TestCarContext extends CarContext


The CarContext that is used for testing.

This class will return the test version of car services for tracking calls during testing.

It also allows retrieving the car services already cast to the testing class by calling getCarService with the class name of the test services:

testCarContext.getCarService(TestAppManager.class)
testCarContext.getCarService(TestNavigationManager.class)
testCarContext.getCarService(TestScreenManager.class)

Allows retrieving all Intents sent via startCarApp.

Summary

Nested types

A representation of a permission request including the permissions that were requested as well as the callback provided.

Public methods

static @NonNull TestCarContext

Creates a TestCarContext to use for testing.

void

Requests to finish the car app.

@NonNull Object

Provides a car service by name.

@NonNull T
<T> getCarService(@NonNull Class<T> serviceClass)

Returns a car service by class.

@NonNull FakeHost

Retrieve the FakeHost being used.

@Nullable TestCarContext.PermissionRequestInfo

Returns a PermissionRequestInfo including the information with the last call made to requestPermissions, or null if no call was made.

@NonNull List<Intent>

Returns all Intents sent via startCarApp.

boolean

Verifies if finishCarApp has been called.

void
requestPermissions(
    @NonNull List<String> permissions,
    @NonNull Executor executor,
    @NonNull OnRequestPermissionsListener listener
)

Requests the provided permissions from the user.

void

Resets the values tracked by this TestCarContext.

void

Starts a car app on the car screen.

Inherited Constants

From androidx.car.app.CarContext
static final String
ACTION_NAVIGATE = "androidx.car.app.action.NAVIGATE"

Standard action for navigating to a location.

static final String
APP_SERVICE = "app"

Manages all app events such as invalidating the UI, showing a toast, etc.

static final String
CAR_SERVICE = "car"

Internal usage only.

static final String
@RequiresCarApi(value = 2)
CONSTRAINT_SERVICE = "constraints"

Manages constraints for the app as enforced by the connected host.

static final String
EXTRA_START_CAR_APP_BINDER_KEY = "androidx.car.app.extra.START_CAR_APP_BINDER_KEY"

Key for including a IStartCarApp in the notification Intent, for starting the app if it has not been opened yet.

static final String
@RequiresCarApi(value = 3)
HARDWARE_SERVICE = "hardware"

Manages access to androidx.car.app.hardware properties, sensors and actions.

static final String

Manages the media requests from 3p apps such as providing a media session token,

static final String
NAVIGATION_SERVICE = "navigation"

Manages all navigation events such as starting navigation when focus is granted, abandoning navigation when focus is lost, etc.

static final String
SCREEN_SERVICE = "screen"

Manages the screens of the app, including the screen stack.

static final String
SUGGESTION_SERVICE = "suggestion"

Manages posting suggestion events

From android.content.Context
static final String
ACCESSIBILITY_SERVICE = "accessibility"
static final String
ACCOUNT_SERVICE = "account"
static final String
ACTIVITY_SERVICE = "activity"
static final String
ADVANCED_PROTECTION_SERVICE = "advanced_protection"
static final String
ALARM_SERVICE = "alarm"
static final String
APPWIDGET_SERVICE = "appwidget"
static final String
APP_FUNCTION_SERVICE = "app_function"
static final String
APP_OPS_SERVICE = "appops"
static final String
APP_SEARCH_SERVICE = "app_search"
static final String
AUDIO_SERVICE = "audio"
static final String
BATTERY_SERVICE = "batterymanager"
static final int
static final int
static final int
static final int
static final int
static final int
static final int
BIND_EXTERNAL_SERVICE = -2147483648
static final long
BIND_EXTERNAL_SERVICE_LONG = 4611686018427387904
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final String
BIOMETRIC_SERVICE = "biometric"
static final String
BLOB_STORE_SERVICE = "blob_store"
static final String
BLUETOOTH_SERVICE = "bluetooth"
static final String
BUGREPORT_SERVICE = "bugreport"
static final String
CAMERA_SERVICE = "camera"
static final String
CAPTIONING_SERVICE = "captioning"
static final String
CARRIER_CONFIG_SERVICE = "carrier_config"
static final String
CLIPBOARD_SERVICE = "clipboard"
static final String
COMPANION_DEVICE_SERVICE = "companiondevice"
static final String
CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics"
static final String
CONNECTIVITY_SERVICE = "connectivity"
static final String
CONSUMER_IR_SERVICE = "consumer_ir"
static final String
CONTACT_KEYS_SERVICE = "contact_keys"
static final int
static final int
static final int
static final String
CREDENTIAL_SERVICE = "credential"
static final String
CROSS_PROFILE_APPS_SERVICE = "crossprofileapps"
static final int
static final int
static final String
DEVICE_LOCK_SERVICE = "device_lock"
static final String
DEVICE_POLICY_SERVICE = "device_policy"
static final String
DISPLAY_HASH_SERVICE = "display_hash"
static final String
DISPLAY_SERVICE = "display"
static final String
DOMAIN_VERIFICATION_SERVICE = "domain_verification"
static final String
DOWNLOAD_SERVICE = "download"
static final String
DROPBOX_SERVICE = "dropbox"
static final String
EUICC_SERVICE = "euicc"
static final String
FILE_INTEGRITY_SERVICE = "file_integrity"
static final String
FINGERPRINT_SERVICE = "fingerprint"
static final String
GAME_SERVICE = "game"
static final String
GRAMMATICAL_INFLECTION_SERVICE = "grammatical_inflection"
static final String
HARDWARE_PROPERTIES_SERVICE = "hardware_properties"
static final String
HEALTHCONNECT_SERVICE = "healthconnect"
static final String
INPUT_METHOD_SERVICE = "input_method"
static final String
INPUT_SERVICE = "input"
static final String
IPSEC_SERVICE = "ipsec"
static final String
JOB_SCHEDULER_SERVICE = "jobscheduler"
static final String
KEYGUARD_SERVICE = "keyguard"
static final String
KEYSTORE_SERVICE = "keystore"
static final String
LAUNCHER_APPS_SERVICE = "launcherapps"
static final String
LAYOUT_INFLATER_SERVICE = "layout_inflater"
static final String
LOCALE_SERVICE = "locale"
static final String
LOCATION_SERVICE = "location"
static final String
MEDIA_COMMUNICATION_SERVICE = "media_communication"
static final String
MEDIA_METRICS_SERVICE = "media_metrics"
static final String
MEDIA_PROJECTION_SERVICE = "media_projection"
static final String
MEDIA_QUALITY_SERVICE = "media_quality"
static final String
MEDIA_ROUTER_SERVICE = "media_router"
static final String
MEDIA_SESSION_SERVICE = "media_session"
static final String
MIDI_SERVICE = "midi"
static final int
MODE_APPEND = 32768
static final int
static final int

This field is deprecated.

static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final String
static final String
NFC_SERVICE = "nfc"
static final String
NOTIFICATION_SERVICE = "notification"
static final String
NSD_SERVICE = "servicediscovery"
static final String
OVERLAY_SERVICE = "overlay"
static final String
PEOPLE_SERVICE = "people"
static final String
PERFORMANCE_HINT_SERVICE = "performance_hint"
static final String
PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block"
static final String
POWER_SERVICE = "power"
static final String
PRINT_SERVICE = "print"
static final String
PROFILING_SERVICE = "profiling"
static final int
static final int
static final int
static final String
RESTRICTIONS_SERVICE = "restrictions"
static final String
ROLE_SERVICE = "role"
static final String
SATELLITE_SERVICE = "satellite"
static final String
SEARCH_SERVICE = "search"
static final String
SECURITY_STATE_SERVICE = "security_state"
static final String
SENSOR_SERVICE = "sensor"
static final String
SHORTCUT_SERVICE = "shortcut"
static final String
STATUS_BAR_SERVICE = "statusbar"
static final String
STORAGE_SERVICE = "storage"
static final String
STORAGE_STATS_SERVICE = "storagestats"
static final String
SYSTEM_HEALTH_SERVICE = "systemhealth"
static final String
TELECOM_SERVICE = "telecom"
static final String
TELEPHONY_IMS_SERVICE = "telephony_ims"
static final String
static final String
TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service"
static final String
TETHERING_SERVICE = "tethering"
static final String
TEXT_CLASSIFICATION_SERVICE = "textclassification"
static final String
static final String
TV_AD_SERVICE = "tv_ad"
static final String
TV_INPUT_SERVICE = "tv_input"
static final String
TV_INTERACTIVE_APP_SERVICE = "tv_interactive_app"
static final String
UI_MODE_SERVICE = "uimode"
static final String
USAGE_STATS_SERVICE = "usagestats"
static final String
USB_SERVICE = "usb"
static final String
USER_SERVICE = "user"
static final String
VIBRATOR_MANAGER_SERVICE = "vibrator_manager"
static final String
VIBRATOR_SERVICE = "vibrator"

This field is deprecated.

static final String
VIRTUAL_DEVICE_SERVICE = "virtualdevice"
static final String
VPN_MANAGEMENT_SERVICE = "vpn_management"
static final String
WALLPAPER_SERVICE = "wallpaper"
static final String
WIFI_AWARE_SERVICE = "wifiaware"
static final String
WIFI_P2P_SERVICE = "wifip2p"
static final String
static final String
WIFI_SERVICE = "wifi"
static final String
WINDOW_SERVICE = "window"

Inherited methods

From androidx.car.app.CarContext
@Nullable ComponentName

Return the component (service or activity) that invoked this car app.

int

Retrieves the API level negotiated with the host.

@NonNull String

Gets the name of the car service that is represented by the specified class.

@Nullable HostInfo

Returns information about the host attached to this service.

@NonNull OnBackPressedDispatcher

Returns the OnBackPressedDispatcher that will be triggered when the user clicks a back button.

boolean

Returns true if the car is set to dark mode.

void
requestPermissions(
    @NonNull List<String> permissions,
    @NonNull OnRequestPermissionsListener listener
)

Requests the provided permissions from the user, calling the provided listener in the main thread.

void
@RequiresCarApi(value = 2)
setCarAppResult(int resultCode, @Nullable Intent data)

Sets the result of this car app.

static void
startCarApp(@NonNull Intent notificationIntent, @NonNull Intent appIntent)

This method is deprecated.

use getCarApp to create the pending intent for the notification action.

From android.content.Context
final int
getColor(int id)
final ColorStateList
final Drawable
getDrawable(int id)
final String
getString(int resId)
final T
<T> getSystemService(Class<T> serviceClass)
final CharSequence
getText(int resId)
final TypedArray
void
void
sendBroadcastWithMultiplePermissions(
    Intent intent,
    String[] receiverPermissions
)
From android.content.ContextWrapper
void
boolean
bindIsolatedService(
    Intent service,
    int flags,
    String instanceName,
    Executor executor,
    ServiceConnection conn
)
boolean
bindService(
    Intent service,
    Context.BindServiceFlags flags,
    Executor executor,
    ServiceConnection conn
)
boolean
bindServiceAsUser(
    Intent service,
    ServiceConnection conn,
    Context.BindServiceFlags flags,
    UserHandle user
)
int
int
checkCallingOrSelfUriPermission(Uri uri, int modeFlags)
int[]
checkCallingOrSelfUriPermissions(List<Uri> uris, int modeFlags)
int
int
checkCallingUriPermission(Uri uri, int modeFlags)
int[]
checkCallingUriPermissions(List<Uri> uris, int modeFlags)
int
checkContentUriPermissionFull(Uri uri, int pid, int uid, int modeFlags)
int
checkPermission(String permission, int pid, int uid)
int
int
checkUriPermission(Uri uri, int pid, int uid, int modeFlags)
int[]
checkUriPermissions(List<Uri> uris, int pid, int uid, int modeFlags)
void

This method is deprecated.

Context
Context
Context
Context
Context
createDeviceContext(int deviceId)
Context
Context
Context
createPackageContext(String packageName, int flags)
Context
createWindowContext(Display display, int type, Bundle options)
String[]
boolean
boolean
boolean
void
void
enforceCallingOrSelfUriPermission(
    Uri uri,
    int modeFlags,
    String message
)
void
enforceCallingPermission(String permission, String message)
void
enforceCallingUriPermission(Uri uri, int modeFlags, String message)
void
enforcePermission(String permission, int pid, int uid, String message)
void
enforceUriPermission(
    Uri uri,
    int pid,
    int uid,
    int modeFlags,
    String message
)
String[]
Context
ApplicationInfo
AssetManager
AttributionSource
String
Context
File
ClassLoader
File
ContentResolver
File
File
int
File
getDir(String name, int mode)
Display
File
File[]
File
File[]
File[]

This method is deprecated.

File
File
Executor
Looper
File