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