• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.federatedcompute.services.training;
18 
19 import static android.federatedcompute.common.ClientConstants.STATUS_INTERNAL_ERROR;
20 import static android.federatedcompute.common.ClientConstants.STATUS_SUCCESS;
21 
22 import android.federatedcompute.ResultHandlingService;
23 import android.federatedcompute.common.ExampleConsumption;
24 import android.federatedcompute.common.TrainingOptions;
25 import android.util.Log;
26 
27 import java.util.List;
28 import java.util.function.Consumer;
29 
30 /** A simple implementation of {@link ResultHandlingService}. */
31 public class SampleResultHandlingService extends ResultHandlingService {
32     private static final String TAG = "SampleResultHandlingService";
33 
handleResult( TrainingOptions trainingOptions, boolean success, List<ExampleConsumption> exampleConsumptionList, Consumer<Integer> callback)34     public void handleResult(
35             TrainingOptions trainingOptions,
36             boolean success,
37             List<ExampleConsumption> exampleConsumptionList,
38             Consumer<Integer> callback) {
39         Log.i(TAG, "Handling result for population: " + trainingOptions.getPopulationName());
40         if (exampleConsumptionList.isEmpty()) {
41             callback.accept(STATUS_INTERNAL_ERROR);
42             return;
43         }
44         callback.accept(STATUS_SUCCESS);
45     }
46 }
47