• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.dashboard.suggestions;
18 
19 import android.content.Context;
20 import android.content.pm.PackageManager;
21 
22 import com.android.internal.logging.nano.MetricsProto;
23 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
24 import com.android.settings.overlay.FeatureFactory;
25 import com.android.settingslib.SuggestionParser;
26 import com.android.settingslib.drawer.Tile;
27 
28 import java.util.List;
29 
30 public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider {
31 
32     private final SuggestionRanker mSuggestionRanker;
33     private final MetricsFeatureProvider mMetricsFeatureProvider;
34 
35     @Override
isSmartSuggestionEnabled(Context context)36     public boolean isSmartSuggestionEnabled(Context context) {
37         return false;
38     }
39 
40     @Override
isPresent(String className)41     public boolean isPresent(String className) {
42         return false;
43     }
44 
45     @Override
isSuggestionCompleted(Context context)46     public boolean isSuggestionCompleted(Context context) {
47         return false;
48     }
49 
50 
SuggestionFeatureProviderImpl(Context context)51     public SuggestionFeatureProviderImpl(Context context) {
52         final Context appContext = context.getApplicationContext();
53         mSuggestionRanker = new SuggestionRanker(
54                 new SuggestionFeaturizer(new EventStore(appContext)));
55         mMetricsFeatureProvider = FeatureFactory.getFactory(appContext)
56                 .getMetricsFeatureProvider();
57     }
58 
59     @Override
rankSuggestions(final List<Tile> suggestions, List<String> suggestionIds)60     public void rankSuggestions(final List<Tile> suggestions, List<String> suggestionIds) {
61         mSuggestionRanker.rankSuggestions(suggestions, suggestionIds);
62     }
63 
64     @Override
dismissSuggestion(Context context, SuggestionParser parser, Tile suggestion)65     public void dismissSuggestion(Context context, SuggestionParser parser, Tile suggestion) {
66         if (parser == null || suggestion == null || context == null) {
67             return;
68         }
69         mMetricsFeatureProvider.action(
70                 context, MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
71                 getSuggestionIdentifier(context, suggestion));
72 
73         final boolean isSmartSuggestionEnabled = isSmartSuggestionEnabled(context);
74         if (!parser.dismissSuggestion(suggestion, isSmartSuggestionEnabled)) {
75             return;
76         }
77         context.getPackageManager().setComponentEnabledSetting(
78                 suggestion.intent.getComponent(),
79                 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
80                 PackageManager.DONT_KILL_APP);
81         parser.markCategoryDone(suggestion.category);
82     }
83 
84     @Override
getSuggestionIdentifier(Context context, Tile suggestion)85     public String getSuggestionIdentifier(Context context, Tile suggestion) {
86         if (suggestion.intent == null || suggestion.intent.getComponent() == null) {
87             return "unknown_suggestion";
88         }
89         String packageName = suggestion.intent.getComponent().getPackageName();
90         if (packageName.equals(context.getPackageName())) {
91             // Since Settings provides several suggestions, fill in the class instead of the
92             // package for these.
93             packageName = suggestion.intent.getComponent().getClassName();
94         }
95         return packageName;
96     }
97 
98 }
99