1 /*
2  * Copyright (C) 2024 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.provider;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.SuppressLint;
21 import android.annotation.SystemApi;
22 
23 import androidx.annotation.NonNull;
24 import androidx.annotation.Nullable;
25 
26 import com.android.providers.media.flags.Flags;
27 
28 import java.util.List;
29 
30 
31 
32 /**
33  * <p>
34  * The response class for {@link MediaCognitionProcessingRequest}.
35  * Use Builder class and setter functions like {@link Builder#setImageOcrLatin(String)}
36  * to set results of cognition processing.
37  * </p>
38  * @hide
39  */
40 @SystemApi
41 @FlaggedApi(Flags.FLAG_MEDIA_COGNITION_SERVICE)
42 public class MediaCognitionProcessingResponse {
43 
44     private MediaCognitionProcessingRequest mRequest;
45     private List<String> mImageLabels;
46     private String mImageOcrLatin;
47 
48 
MediaCognitionProcessingResponse(Builder builder)49     private MediaCognitionProcessingResponse(Builder builder) {
50         mRequest = builder.mRequest;
51         mImageLabels = builder.mImageLabels;
52         mImageOcrLatin = builder.mImageOcrLatin;
53     }
54 
55     /**
56      * Builder class to build {@link MediaCognitionProcessingResponse} instances.
57      */
58     public static final class Builder {
59         private MediaCognitionProcessingRequest mRequest; // Required
60         private List<String> mImageLabels = null;
61         private String mImageOcrLatin = null;
62 
Builder(@onNull MediaCognitionProcessingRequest request)63         public Builder(@NonNull MediaCognitionProcessingRequest request) {
64             this.mRequest = request;
65         }
66 
67         /**
68          * Call this setter function in response of the
69          * processing: {@link MediaCognitionService.ProcessingTypes#IMAGE_LABEL}
70          * @param imageLabels list of image labels
71          */
72         @NonNull
setImageLabels(@ullable List<String> imageLabels)73         public Builder setImageLabels(@Nullable List<String> imageLabels) {
74             this.mImageLabels = imageLabels;
75             return this;
76         }
77 
78         /**
79          * Call this setter function in response of the
80          * processing: {@link MediaCognitionService.ProcessingTypes#IMAGE_OCR_LATIN}
81          * @param imageOcrLatin latin text content in the image
82          */
83         @NonNull
setImageOcrLatin(@ullable String imageOcrLatin)84         public Builder setImageOcrLatin(@Nullable String imageOcrLatin) {
85             this.mImageOcrLatin = imageOcrLatin;
86             return this;
87         }
88 
89         /**
90          * Instantiate a {@link MediaCognitionProcessingResponse} from this {@link Builder}
91          * @return {@link MediaCognitionProcessingResponse} representation of this builder
92          */
93         @NonNull
build()94         public MediaCognitionProcessingResponse build() {
95             return new MediaCognitionProcessingResponse(this);
96         }
97     }
98 
99     /**
100      * get {@link MediaCognitionProcessingRequest} set by {@link Builder}
101      */
102     @NonNull
getRequest()103     public MediaCognitionProcessingRequest getRequest() {
104         return mRequest;
105     }
106 
107     /**
108      * get Image Labels set by {@link Builder#setImageLabels(List)}
109      */
110     @SuppressLint("NullableCollection") // return value can be null
111     @Nullable
getImageLabels()112     public List<String> getImageLabels() {
113         return mImageLabels;
114     }
115 
116     /**
117      * get Image Ocr Latin set by {@link Builder#setImageOcrLatin(String)}
118      */
119     @Nullable
getImageOcrLatin()120     public String getImageOcrLatin() {
121         return mImageOcrLatin;
122     }
123 
124 }
125