1 /*
2  * Copyright (C) 2022 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.process;
18 
19 import static android.adservices.ondevicepersonalization.OnDevicePersonalizationException.ERROR_ISOLATED_SERVICE_FAILED;
20 
21 import android.adservices.ondevicepersonalization.aidl.IIsolatedService;
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.content.ComponentName;
25 
26 import com.android.federatedcompute.internal.util.AbstractServiceBinder;
27 import com.android.ondevicepersonalization.libraries.plugin.PluginController;
28 import com.android.ondevicepersonalization.services.OdpServiceException;
29 
30 import java.util.Objects;
31 
32 /** Wraps an instance of a loaded isolated service */
33 public class IsolatedServiceInfo {
34     private final long mStartTimeMillis;
35     @NonNull private final ComponentName mComponentName;
36     @Nullable private final PluginController mPluginController;
37     @Nullable private final AbstractServiceBinder<IIsolatedService> mIsolatedServiceBinder;
38 
IsolatedServiceInfo( long startTimeMillis, @NonNull ComponentName componentName, @Nullable PluginController pluginController, @Nullable AbstractServiceBinder<IIsolatedService> isolatedServiceBinder)39     IsolatedServiceInfo(
40             long startTimeMillis,
41             @NonNull ComponentName componentName,
42             @Nullable PluginController pluginController,
43             @Nullable AbstractServiceBinder<IIsolatedService> isolatedServiceBinder)
44             throws OdpServiceException {
45         mStartTimeMillis = startTimeMillis;
46         mComponentName = Objects.requireNonNull(componentName);
47         mPluginController = pluginController;
48         mIsolatedServiceBinder = isolatedServiceBinder;
49 
50         // TO-DO (323882182): Granular isolated servce failures.
51         if ((mPluginController != null && mIsolatedServiceBinder != null)
52                 || (mPluginController == null && mIsolatedServiceBinder == null)) {
53             throw new OdpServiceException(ERROR_ISOLATED_SERVICE_FAILED);
54         }
55     }
56 
getPluginController()57     PluginController getPluginController() {
58         return mPluginController;
59     }
60 
getIsolatedServiceBinder()61     AbstractServiceBinder<IIsolatedService> getIsolatedServiceBinder() {
62         return mIsolatedServiceBinder;
63     }
64 
65     /** Returns the service start time. */
getStartTimeMillis()66     public long getStartTimeMillis() {
67         return mStartTimeMillis;
68     }
69 
70     /** Returns the ComponentName to be loaded. */
getComponentName()71     @NonNull public ComponentName getComponentName() {
72         return mComponentName;
73     }
74 }
75