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.ClientConstants; 24 import android.federatedcompute.common.ExampleConsumption; 25 import android.os.Bundle; 26 import android.util.Log; 27 28 import java.util.ArrayList; 29 import java.util.function.Consumer; 30 31 /** A simple implementation of {@link ResultHandlingService}. */ 32 public class SampleResultHandlingService extends ResultHandlingService { 33 private static final String TAG = "SampleResultHandlingService"; 34 handleResult(Bundle params, Consumer<Integer> callback)35 public void handleResult(Bundle params, Consumer<Integer> callback) { 36 Log.i( 37 TAG, 38 "Handling result for population: " 39 + params.getString(ClientConstants.EXTRA_POPULATION_NAME)); 40 ArrayList<ExampleConsumption> exampleConsumptionList = 41 params.getParcelableArrayList( 42 ClientConstants.EXTRA_EXAMPLE_CONSUMPTION_LIST, ExampleConsumption.class); 43 if (exampleConsumptionList.isEmpty()) { 44 callback.accept(STATUS_INTERNAL_ERROR); 45 return; 46 } 47 callback.accept(STATUS_SUCCESS); 48 } 49 } 50