1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ondevicepersonalization.services.serviceflow; 18 19 import android.content.ComponentName; 20 import android.os.Bundle; 21 22 import com.google.common.util.concurrent.ListenableFuture; 23 24 /** 25 * Interface for various on-device personalization service flows. 26 * 27 * @param <R> service flow return data type. 28 */ 29 public interface ServiceFlow<R> { 30 31 /** 32 * Checks pre-conditions for a given service flow and configures the necessary service 33 * flow parameters before execution. 34 */ isServiceFlowReady()35 boolean isServiceFlowReady(); 36 37 /** Returns the service used for loading/binding. */ getService()38 ComponentName getService(); 39 40 /** Returns the necessary service parameters. */ getServiceParams()41 Bundle getServiceParams(); 42 43 /** Uploads service flow metrics. */ uploadServiceFlowMetrics(ListenableFuture<Bundle> runServiceFuture)44 default void uploadServiceFlowMetrics(ListenableFuture<Bundle> runServiceFuture) {} 45 46 /** Gets service flow results. */ getServiceFlowResultFuture(ListenableFuture<Bundle> runServiceFuture)47 ListenableFuture<R> getServiceFlowResultFuture(ListenableFuture<Bundle> runServiceFuture); 48 49 /** Returns the service flow result through a callback. */ returnResultThroughCallback(ListenableFuture<R> serviceFlowResultFuture)50 default void returnResultThroughCallback(ListenableFuture<R> serviceFlowResultFuture) {} 51 52 /** Frees up resources used by service. */ cleanUpServiceParams()53 default void cleanUpServiceParams() {} 54 } 55