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.adservices.ondevicepersonalization.DownloadCompletedOutputParcel; 20 import android.adservices.ondevicepersonalization.EventOutputParcel; 21 import android.adservices.ondevicepersonalization.RequestLogRecord; 22 import android.adservices.ondevicepersonalization.aidl.IExecuteCallback; 23 import android.adservices.ondevicepersonalization.aidl.IRegisterMeasurementEventCallback; 24 import android.adservices.ondevicepersonalization.aidl.IRequestSurfacePackageCallback; 25 import android.content.ComponentName; 26 import android.content.Context; 27 import android.os.Bundle; 28 import android.os.IBinder; 29 30 import com.android.ondevicepersonalization.services.data.events.EventUrlPayload; 31 import com.android.ondevicepersonalization.services.display.WebViewFlow; 32 import com.android.ondevicepersonalization.services.download.DownloadFlow; 33 import com.android.ondevicepersonalization.services.request.AppRequestFlow; 34 import com.android.ondevicepersonalization.services.request.RenderFlow; 35 import com.android.ondevicepersonalization.services.webtrigger.WebTriggerFlow; 36 37 import com.google.common.util.concurrent.FutureCallback; 38 39 /** Factory for service flow instances. */ 40 public class ServiceFlowFactory { 41 42 /** Create a service flow instance give the type. */ createInstance(ServiceFlowType serviceFlowType, Object... args)43 public static ServiceFlow createInstance(ServiceFlowType serviceFlowType, Object... args) { 44 return switch (serviceFlowType) { 45 case APP_REQUEST_FLOW -> 46 new AppRequestFlow((String) args[0], (ComponentName) args[1], (Bundle) args[2], 47 (IExecuteCallback) args[3], (Context) args[4], (long) args[5], 48 (long) args[6]); 49 case RENDER_FLOW -> 50 new RenderFlow((String) args[0], (IBinder) args[1], (int) args[2], 51 (int) args[3], (int) args[4], (IRequestSurfacePackageCallback) args[5], 52 (Context) args[6], (long) args[7], (long) args[8]); 53 case WEB_TRIGGER_FLOW -> 54 new WebTriggerFlow((Bundle) args[0], (Context) args[1], 55 (IRegisterMeasurementEventCallback) args[2], (long) args[3], 56 (long) args[4]); 57 case WEB_VIEW_FLOW -> 58 new WebViewFlow((Context) args[0], (ComponentName) args[1], (long) args[2], 59 (RequestLogRecord) args[3], (FutureCallback<EventOutputParcel>) args[4], 60 (EventUrlPayload) args[5]); 61 case DOWNLOAD_FLOW -> 62 new DownloadFlow((String) args[0], (Context) args[1], 63 (FutureCallback<DownloadCompletedOutputParcel>) args[2]); 64 default -> throw new IllegalArgumentException( 65 "Invalid service flow type: " + serviceFlowType); 66 }; 67 } 68 } 69