1 /*
2  * Copyright (C) 2018 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 package android.ext.services.autofill;
17 
18 import static android.ext.services.autofill.EditDistanceScorer.DEFAULT_ALGORITHM;
19 
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.os.Bundle;
23 import android.service.autofill.AutofillFieldClassificationService;
24 import android.util.Log;
25 import android.view.autofill.AutofillValue;
26 
27 import com.android.internal.util.ArrayUtils;
28 
29 import java.util.List;
30 
31 public class AutofillFieldClassificationServiceImpl extends AutofillFieldClassificationService {
32 
33     private static final String TAG = "AutofillFieldClassificationServiceImpl";
34 
35     @Nullable
36     @Override
onGetScores(@ullable String algorithmName, @Nullable Bundle algorithmArgs, @NonNull List<AutofillValue> actualValues, @NonNull List<String> userDataValues)37     public float[][] onGetScores(@Nullable String algorithmName,
38             @Nullable Bundle algorithmArgs, @NonNull List<AutofillValue> actualValues,
39             @NonNull List<String> userDataValues) {
40         if (ArrayUtils.isEmpty(actualValues) || ArrayUtils.isEmpty(userDataValues)) {
41             Log.w(TAG, "getScores(): empty currentvalues (" + actualValues + ") or userValues ("
42                     + userDataValues + ")");
43             return null;
44         }
45         if (algorithmName != null && !algorithmName.equals(DEFAULT_ALGORITHM)) {
46             Log.w(TAG, "Ignoring invalid algorithm (" + algorithmName + ") and using "
47                     + DEFAULT_ALGORITHM + " instead");
48         }
49 
50         return EditDistanceScorer.getScores(actualValues, userDataValues);
51     }
52 }
53