AppFunctionService


@RequiresApi(value = 36)
public abstract class AppFunctionService extends AppFunctionService


Abstract base class to provide app functions to the system.

This class wraps AppFunctionService functionalities and provides an API that uses androidx.appfunctions classes.

Include the following in the manifest:

<service android:name=".YourService"
android:permission="android.permission.BIND_APP_FUNCTION_SERVICE">
<intent-filter>
<action android:name="android.app.appfunctions.AppFunctionService" />
</intent-filter>
</service>

Summary

Public constructors

Public methods

void

Implementing class can override this method to perform setup but should always call the superclass implementation.

void

Implementing class can override this method to perform cleanup but should always call the superclass implementation.

abstract void

Called by the system following an AppFunctionManager.executeAppFunction call that targets an app function identifier referenced by the XML asset associated with this service.

final void
onExecuteFunction(
    @NonNull ExecuteAppFunctionRequest request,
    @NonNull String callingPackage,
    @NonNull SigningInfo signingInfo,
    @NonNull CancellationSignal cancellationSignal,
    @NonNull OutcomeReceiver<@NonNull ExecuteAppFunctionResponse, @NonNull AppFunctionException> callback
)

Implements AppFunctionService.onExecuteFunction and delegates the execution to onExecuteFunction when called by the system.

AppFunctionInventory

Resolve the AppFunctionInventory.

Inherited methods

From android.app.appfunctions.AppFunctionService
final @NonNull IBinder
onBind(Intent intent)
From android.content.Context
boolean
bindIsolatedService(
    @NonNull Intent service,
    @NonNull Context.BindServiceFlags flags,
    @NonNull String instanceName,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
final int
getColor(int id)
final @NonNull ColorStateList
final Drawable
getDrawable(int id)
final @NonNull String
getString(int resId)
final @NonNull String
getString(int resId, @NonNull Object... formatArgs)
final @NonNull T
<T extends Object> getSystemService(@NonNull Class<@NonNull T> serviceClass)
final @NonNull CharSequence
getText(int resId)
@NonNull Context.BindServiceFlags
final @NonNull TypedArray
final @NonNull TypedArray
obtainStyledAttributes(int resid, @NonNull int[] attrs)
final @NonNull TypedArray
final @NonNull TypedArray
obtainStyledAttributes(
    AttributeSet set,
    @NonNull int[] attrs,
    int defStyleAttr,
    int defStyleRes
)
void
void
sendBroadcastWithMultiplePermissions(
    @NonNull Intent intent,
    @NonNull String[] receiverPermissions
)
From android.content.ContextWrapper
boolean
bindIsolatedService(
    @NonNull Intent service,
    int flags,
    @NonNull String instanceName,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    @NonNull Context.BindServiceFlags flags
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    int flags
)
boolean
bindService(
    @NonNull Intent service,
    @NonNull Context.BindServiceFlags flags,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindService(
    @NonNull Intent service,
    int flags,
    @NonNull Executor executor,
    @NonNull ServiceConnection conn
)
boolean
bindServiceAsUser(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    @NonNull Context.BindServiceFlags flags,
    @NonNull UserHandle user
)
boolean
bindServiceAsUser(
    @NonNull Intent service,
    @NonNull ServiceConnection conn,
    int flags,
    @NonNull UserHandle user
)
int
int
@NonNull int[]
checkCallingOrSelfUriPermissions(
    @NonNull List<@NonNull Uri> uris,
    int modeFlags
)
int
int
checkCallingUriPermission(@NonNull Uri uri, int modeFlags)
@NonNull int[]
int
checkContentUriPermissionFull(
    @NonNull Uri uri,
    int pid,
    int uid,
    int modeFlags
)
int
checkPermission(@NonNull String permission, int pid, int uid)
int
int
checkUriPermission(@NonNull Uri uri, int pid, int uid, int modeFlags)
int
checkUriPermission(
    Uri uri,
    String readPermission,
    String writePermission,
    int pid,
    int uid,
    int modeFlags
)
@NonNull int[]
checkUriPermissions(
    @NonNull List<@NonNull Uri> uris,
    int pid,
    int uid,
    int modeFlags
)
void
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
createDeviceContext(int deviceId)
@NonNull Context
@NonNull Context
@NonNull Context
createPackageContext(@NonNull String packageName, int flags)
@NonNull Context
createWindowContext(int type, Bundle options)
@NonNull Context
createWindowContext(@NonNull Display display, int type, Bundle options)
@NonNull String[]
boolean
boolean
boolean
void
enforceCallingOrSelfPermission(
    @NonNull String permission,
    String message
)
void
enforceCallingOrSelfUriPermission(
    @NonNull Uri uri,
    int modeFlags,
    @NonNull String message
)
void
void
enforceCallingUriPermission(
    @NonNull Uri uri,
    int modeFlags,
    @NonNull String message
)
void
enforcePermission(
    @NonNull String permission,
    int pid,
    int uid,
    String message
)
void
enforceUriPermission(
    @NonNull Uri uri,
    int pid,
    int uid,
    int modeFlags,
    @NonNull String message
)
void
enforceUriPermission(
    Uri uri,
    String readPermission,
    String writePermission,
    int pid,
    int uid,
    int modeFlags,
    String message
)
@NonNull String[]
@NonNull Context
@NonNull ApplicationInfo
@NonNull AssetManager
@NonNull AttributionSource
@Nullable String
@NonNull Context
@NonNull File
@NonNull ClassLoader
@NonNull File
@NonNull ContentResolver
@NonNull File
@NonNull File
int
@NonNull File
getDir(@NonNull String name, int mode)
@Nullable Display
@Nullable File
@NonNull File[]
File
@NonNull File[]
@NonNull File[]
@NonNull File
@NonNull File
@NonNull Executor
@NonNull Looper
@NonNull File
@NonNull File
@NonNull File[]
@NonNull String
@NonNull String
@NonNull PackageManager
@NonNull String
@NonNull String
@Nullable ContextParams
@NonNull Resources
@NonNull SharedPreferences
getSharedPreferences(@NonNull String name, int mode)
@NonNull Object
String
@NonNull Resources.Theme
@NonNull Drawable

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

void
grantUriPermission(
    @NonNull String toPackage,
    @NonNull Uri uri,
    int modeFlags
)
boolean
boolean
boolean
boolean
moveDatabaseFrom(@NonNull Context sourceContext, @NonNull String name)
boolean
moveSharedPreferencesFrom(
    @NonNull Context sourceContext,
    @NonNull String name
)
@NonNull FileInputStream
@NonNull FileOutputStream
openFileOutput(@NonNull String name, int mode)
@NonNull SQLiteDatabase
openOrCreateDatabase(
    @NonNull String name,
    int mode,
    @NonNull SQLiteDatabase.CursorFactory factory
)
@NonNull SQLiteDatabase
openOrCreateDatabase(
    @NonNull String name,
    int mode,
    @NonNull SQLiteDatabase.CursorFactory factory,
    DatabaseErrorHandler errorHandler
)
@NonNull Drawable
void
void
void
registerDeviceIdChangeListener(
    @NonNull Executor executor,
    @NonNull IntConsumer listener
)
Intent
registerReceiver(
    BroadcastReceiver receiver,
    @NonNull IntentFilter filter
)
Intent
registerReceiver(
    BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    int flags
)
Intent
registerReceiver(
    BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    String broadcastPermission,
    Handler scheduler
)
Intent
registerReceiver(
    BroadcastReceiver receiver,
    @NonNull IntentFilter filter,
    String broadcastPermission,
    Handler scheduler,
    int flags
)
void
void
void
void
revokeUriPermission(@NonNull Uri uri, int modeFlags)
void
revokeUriPermission(
    @NonNull String targetPackage,
    @NonNull Uri uri,
    int modeFlags
)
void
void
sendBroadcast(@NonNull Intent intent, String receiverPermission)
void
sendBroadcast(
    @NonNull Intent intent,
    String receiverPermission,
    Bundle options
)
void
void
sendBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    String receiverPermission
)
void
sendOrderedBroadcast(@NonNull Intent intent, String receiverPermission)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    String receiverPermission,
    Bundle options
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    String receiverPermission,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    String receiverPermission,
    Bundle options,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    String receiverPermission,
    String receiverAppOp,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)
void
sendOrderedBroadcast(
    @NonNull Intent intent,
    int initialCode,
    String receiverPermission,
    String receiverAppOp,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    String initialData,
    Bundle initialExtras,
    Bundle options
)
void
sendOrderedBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    String receiverPermission,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)
void
void
void
void
sendStickyOrderedBroadcast(
    @NonNull Intent intent,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)
void
sendStickyOrderedBroadcastAsUser(
    @NonNull Intent intent,
    @NonNull UserHandle user,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)
void
setTheme(int resid)
void
void
void
startActivities(@NonNull Intent[] intents)
void
startActivities(@NonNull Intent[] intents, Bundle options)
void
void
startActivity(@NonNull Intent intent, Bundle options)
ComponentName
boolean
startInstrumentation(
    @NonNull ComponentName className,
    String profileFile,
    Bundle arguments
)
void
startIntentSender(
    @NonNull IntentSender intent,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)
void
startIntentSender(
    @NonNull IntentSender intent,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    Bundle options
)
ComponentName
boolean
void
void
void
void
void
void
updateServiceGroup(
    @NonNull ServiceConnection conn,
    int group,
    int importance
)
From android.app.Service
void
void
dump(
    @NonNull FileDescriptor fd,
    @NonNull PrintWriter writer,
    @NonNull String[] args
)
final @NonNull Application
final int
void
void
void
void
onStart(@NonNull Intent intent, int startId)
int
onStartCommand(@NonNull Intent intent, int flags, int startId)
void
void
onTimeout(int startId)
void
onTimeout(int startId, int fgsType)
void
onTrimMemory(int level)
boolean
final void
startForeground(int id, @NonNull Notification notification)
final void
startForeground(
    int id,
    @NonNull Notification notification,
    int foregroundServiceType
)
final void
stopForeground(int notificationBehavior)
final void
stopForeground(boolean removeNotification)
final void
final void
stopSelf(int startId)
final boolean
stopSelfResult(int startId)

Public constructors

AppFunctionService

Added in 1.0.0-alpha10
public AppFunctionService()

Public methods

onCreate

@CallSuper
public void onCreate()

Implementing class can override this method to perform setup but should always call the superclass implementation.

onDestroy

@CallSuper
public void onDestroy()

Implementing class can override this method to perform cleanup but should always call the superclass implementation.

onExecuteFunction

Added in 1.0.0-alpha10
@MainThread
public abstract void onExecuteFunction(
    @NonNull ExecuteAppFunctionRequest request,
    @NonNull CancellationSignal cancellationSignal,
    @NonNull Consumer<@NonNull ExecuteAppFunctionResponse> callback
)

Called by the system following an AppFunctionManager.executeAppFunction call that targets an app function identifier referenced by the XML asset associated with this service.

You can determine which function to execute using ExecuteAppFunctionRequest.functionIdentifier. This allows your service to route the incoming request to the appropriate logic for handling the specific function. See ExecuteAppFunctionRequest for how to retrieve the function's arguments.

This method is always triggered in the main thread. You should run heavy tasks on a worker thread and dispatch the result with the given callback. You should always report back the result using the callback, no matter if the execution was successful or not.

The implementation should try to respect the provided CancellationSignal, if possible.

Parameters
@NonNull ExecuteAppFunctionRequest request

The function execution request.

@NonNull CancellationSignal cancellationSignal

A signal to cancel the execution.

@NonNull Consumer<@NonNull ExecuteAppFunctionResponse> callback

A callback to report back the result or error.

onExecuteFunction

Added in 1.0.0-alpha10
public final void onExecuteFunction(
    @NonNull ExecuteAppFunctionRequest request,
    @NonNull String callingPackage,
    @NonNull SigningInfo signingInfo,
    @NonNull CancellationSignal cancellationSignal,
    @NonNull OutcomeReceiver<@NonNull ExecuteAppFunctionResponse, @NonNull AppFunctionException> callback
)

Implements AppFunctionService.onExecuteFunction and delegates the execution to onExecuteFunction when called by the system.

Parameters
@NonNull ExecuteAppFunctionRequest request

The function execution request.

@NonNull String callingPackage

The package name of the app that is requesting the execution. It is strongly recommended that you do not alter your function’s behavior based on this value. Your function should behave consistently for all callers to ensure a predictable experience.

@NonNull SigningInfo signingInfo

The signing information of the app that is requesting the execution. It is strongly recommended that you do not alter your function’s behavior based on this value. Your function should behave consistently for all callers to ensure a predictable experience.

@NonNull CancellationSignal cancellationSignal

A signal to cancel the execution.

@NonNull OutcomeReceiver<@NonNull ExecuteAppFunctionResponse, @NonNull AppFunctionException> callback

A callback to report back the result or error.

resolveInventory

public AppFunctionInventory resolveInventory()

Resolve the AppFunctionInventory.