1 /* 2 * Copyright 2023 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 androidx.appsearch.safeparcel; 18 19 import android.os.Parcel; 20 21 import androidx.annotation.RestrictTo; 22 23 /** 24 * AppSearch's own version of SafeParcelable so we don't need to include a complete version 25 * here, which is not needed inside Jetpack. 26 * 27 * <p>In Jetpack, annotation processor is not run, but we still need them so the classes, e.g. 28 * {@link androidx.appsearch.app.StorageInfo}, can mostly share the same code. 29 * 30 * <p>Most of its original annotations are moved to 31 * {@link AbstractSafeParcelable} so {@code AbstractSafeParcelable#NULL} can be package private. 32 * 33 * <p>This class is put in androidx.appsearch.app so we can restrict the scope to avoid making it 34 * public. 35 * 36 * <p>DON'T modify this class unless it is necessary. E.g. port new annotations from SafeParcelable. 37 */ 38 // @exportToFramework:skipFile() 39 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 40 public interface SafeParcelable { 41 /** 42 * This annotates your class and specifies the name of the generated "creator" class for 43 * marshalling/unmarshalling a SafeParcelable to/from a {@link Parcel}. The "creator" class is 44 * generated in the same package as the SafeParcelable class. You can also set "validate" to 45 * true, 46 * which will cause the "creator" to invoke the method validateContents() on your class after 47 * constructing an instance. 48 */ 49 @SuppressWarnings("JavaLangClash") 50 @interface Class { 51 /** 52 * Simple name of the generated "creator" class generated in the same package as the 53 * SafeParceable. 54 */ creator()55 String creator(); 56 57 /** 58 * When set to true, invokes the validateContents() method in this SafeParcelable object 59 * after 60 * constructing a new instance. 61 */ validate()62 boolean validate() default false; 63 64 /** 65 * When set to true, it will not write type default values to the Parcel. 66 * 67 * boolean: false 68 * byte/char/short/int/long: 0 69 * float: 0.0f 70 * double: 0.0 71 * Objects/arrays: null 72 * 73 * <p>Cannot be used with Field(defaultValue) 74 */ doNotParcelTypeDefaultValues()75 boolean doNotParcelTypeDefaultValues() default false; 76 } 77 78 /** Provide same interface as {@link android.os.Parcelable} for code sync purpose. */ describeContents()79 int describeContents(); 80 } 81