1 /* 2 * Copyright (C) 2017 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.settings.intelligence.suggestions; 18 19 import android.service.settings.suggestions.Suggestion; 20 import android.util.Log; 21 22 import com.android.settings.intelligence.overlay.FeatureFactory; 23 24 import java.util.ArrayList; 25 import java.util.List; 26 27 public class SuggestionService extends android.service.settings.suggestions.SuggestionService { 28 29 private static final String TAG = "SuggestionService"; 30 31 @Override onGetSuggestions()32 public List<Suggestion> onGetSuggestions() { 33 final long startTime = System.currentTimeMillis(); 34 final List<Suggestion> list = FeatureFactory.get(this) 35 .suggestionFeatureProvider() 36 .getSuggestions(this); 37 38 final List<String> ids = new ArrayList<>(list.size()); 39 for (Suggestion suggestion : list) { 40 ids.add(suggestion.getId()); 41 } 42 final long endTime = System.currentTimeMillis(); 43 FeatureFactory.get(this) 44 .metricsFeatureProvider(this) 45 .logGetSuggestion(ids, endTime - startTime); 46 return list; 47 } 48 49 @Override onSuggestionDismissed(Suggestion suggestion)50 public void onSuggestionDismissed(Suggestion suggestion) { 51 final long startTime = System.currentTimeMillis(); 52 final String id = suggestion.getId(); 53 Log.d(TAG, "dismissing suggestion " + id); 54 final long endTime = System.currentTimeMillis(); 55 FeatureFactory.get(this) 56 .suggestionFeatureProvider() 57 .markSuggestionDismissed(this /* context */, id); 58 FeatureFactory.get(this) 59 .metricsFeatureProvider(this) 60 .logDismissSuggestion(id, endTime - startTime); 61 } 62 63 @Override onSuggestionLaunched(Suggestion suggestion)64 public void onSuggestionLaunched(Suggestion suggestion) { 65 final long startTime = System.currentTimeMillis(); 66 final String id = suggestion.getId(); 67 Log.d(TAG, "Suggestion is launched" + id); 68 final long endTime = System.currentTimeMillis(); 69 FeatureFactory.get(this) 70 .suggestionFeatureProvider() 71 .markSuggestionLaunched(this, id); 72 FeatureFactory.get(this) 73 .metricsFeatureProvider(this) 74 .logLaunchSuggestion(id, endTime - startTime); 75 } 76 } 77