/* * Copyright 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.permissioncontroller.permission.service import android.app.appfunctions.AppFunctionException import android.app.appfunctions.AppFunctionService import android.app.appfunctions.ExecuteAppFunctionRequest import android.app.appfunctions.ExecuteAppFunctionResponse import android.content.Intent import android.content.pm.SigningInfo import android.os.Build import android.os.CancellationSignal import android.os.OutcomeReceiver import androidx.annotation.CallSuper import androidx.annotation.RequiresApi import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner @RequiresApi(Build.VERSION_CODES.BAKLAVA) abstract class LifecycleAppFunctionService : AppFunctionService(), LifecycleOwner { val dispatcher = ServiceLifecycleDispatcher(this) override val lifecycle: Lifecycle get() = dispatcher.lifecycle @CallSuper override fun onCreate() { dispatcher.onServicePreSuperOnCreate() super.onCreate() } @Deprecated("Deprecated in Java") @Suppress("DEPRECATION") @CallSuper override fun onStart(intent: Intent?, startId: Int) { dispatcher.onServicePreSuperOnStart() super.onStart(intent, startId) } @CallSuper override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { return super.onStartCommand(intent, flags, startId) } @CallSuper override fun onDestroy() { dispatcher.onServicePreSuperOnDestroy() super.onDestroy() } @CallSuper override fun onExecuteFunction( request: ExecuteAppFunctionRequest, callingPackage: String, callingPackageSigningInfo: SigningInfo, cancellationSignal: CancellationSignal, callback: OutcomeReceiver, ) { if (lifecycle.currentState != Lifecycle.State.STARTED) { dispatcher.onServicePreSuperOnBind() } } }