1 /*
2  * Copyright (C) 2021 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.content;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 
22 import java.util.List;
23 
24 /**
25  * Marker interface for a class which can have an {@link AttributionSource}
26  * assigned to it; these are typically {@link android.os.Parcelable} classes
27  * which need to be updated after crossing Binder transaction boundaries.
28  *
29  * @hide
30  */
31 public interface Attributable {
setAttributionSource(@onNull AttributionSource attributionSource)32     void setAttributionSource(@NonNull AttributionSource attributionSource);
33 
setAttributionSource( @ullable T attributable, @NonNull AttributionSource attributionSource)34     static @Nullable <T extends Attributable> T setAttributionSource(
35             @Nullable T attributable,
36             @NonNull AttributionSource attributionSource) {
37         if (attributable != null) {
38             attributable.setAttributionSource(attributionSource);
39         }
40         return attributable;
41     }
42 
setAttributionSource( @ullable List<T> attributableList, @NonNull AttributionSource attributionSource)43     static @Nullable <T extends Attributable> List<T> setAttributionSource(
44             @Nullable List<T> attributableList,
45             @NonNull AttributionSource attributionSource) {
46         if (attributableList != null) {
47             final int size = attributableList.size();
48             for (int i = 0; i < size; i++) {
49                 setAttributionSource(attributableList.get(i), attributionSource);
50             }
51         }
52         return attributableList;
53     }
54 }
55