• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.adservices.ondevicepersonalization;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.os.PersistableBundle;
23 
24 import com.android.adservices.ondevicepersonalization.flags.Flags;
25 import com.android.ondevicepersonalization.internal.util.ByteArrayParceledSlice;
26 import com.android.ondevicepersonalization.internal.util.PersistableBundleUtils;
27 
28 import java.util.Objects;
29 
30 /**
31  * The input data for {@link IsolatedWorker#onExecute(ExecuteInput, android.os.OutcomeReceiver)}.
32  *
33  */
34 @FlaggedApi(Flags.FLAG_ON_DEVICE_PERSONALIZATION_APIS_ENABLED)
35 public final class ExecuteInput {
36     @NonNull private final String mAppPackageName;
37     @Nullable private final ByteArrayParceledSlice mSerializedAppParams;
38     @NonNull private final Object mAppParamsLock = new Object();
39     @NonNull private volatile PersistableBundle mAppParams = null;
40 
41     /** @hide */
ExecuteInput(@onNull ExecuteInputParcel parcel)42     public ExecuteInput(@NonNull ExecuteInputParcel parcel) {
43         mAppPackageName = Objects.requireNonNull(parcel.getAppPackageName());
44         mSerializedAppParams = parcel.getSerializedAppParams();
45     }
46 
47     /**
48      * The package name of the calling app.
49      */
getAppPackageName()50     @NonNull public String getAppPackageName() {
51         return mAppPackageName;
52     }
53 
54     /**
55      * The parameters provided by the app to the {@link IsolatedService}. The service
56      * defines the expected keys in this {@link PersistableBundle}.
57      */
getAppParams()58     @NonNull public PersistableBundle getAppParams() {
59         if (mAppParams != null) {
60             return mAppParams;
61         }
62         synchronized (mAppParamsLock) {
63             if (mAppParams != null) {
64                 return mAppParams;
65             }
66             try {
67                 mAppParams = (mSerializedAppParams != null)
68                         ? PersistableBundleUtils.fromByteArray(
69                                 mSerializedAppParams.getByteArray())
70                         : PersistableBundle.EMPTY;
71                 return mAppParams;
72             } catch (Exception e) {
73                 throw new IllegalStateException(e);
74             }
75         }
76     }
77 }
78