1 /*
2  * Copyright (C) 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 android.speech;
18 
19 /**
20  * Listener for model download events. It makes {@link RecognitionService} let callers know about
21  * the progress of model download for a single recognition request.
22  */
23 public interface ModelDownloadListener {
24     /**
25      * Called by {@link RecognitionService} only if the download has started after the request.
26      *
27      * <p> The number of calls to this method varies depending of the {@link RecognitionService}
28      * implementation. If the download finished quickly enough, {@link #onSuccess()} may be called
29      * directly. In other cases, this method may be called any number of times during the download.
30      *
31      * @param completedPercent the percentage of download that is completed
32      */
onProgress(int completedPercent)33     void onProgress(int completedPercent);
34 
35     /**
36      * This method is called:
37      * <li> if the model is already available;
38      * <li> if the {@link RecognitionService} has started and completed the download.
39      *
40      * <p> Once this method is called, the model can be safely used to satisfy recognition requests.
41      */
onSuccess()42     void onSuccess();
43 
44     /**
45      * Called when {@link RecognitionService} scheduled the download, but won't satisfy it
46      * immediately. There will be no further updates on this listener.
47      */
onScheduled()48     void onScheduled();
49 
50     /**
51      * A network or scheduling error occurred.
52      *
53      * @param error code is defined in {@link SpeechRecognizer}
54      */
onError(@peechRecognizer.RecognitionError int error)55     void onError(@SpeechRecognizer.RecognitionError int error);
56 }
57