blob: 1535cc0b24647048f6001291e5ccd1f1ca67aacd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package com.android.launcher3.allapps;
import android.content.ComponentName;
import android.content.Context;
import android.os.Process;
import android.os.UserHandle;
import android.util.Log;
import com.android.launcher3.AppInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.discovery.suggestions.SuggestionCandidate;
import com.android.launcher3.discovery.suggestions.SuggestionsDatabaseHelper;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ComponentKeyMapper;
import java.util.ArrayList;
import java.util.List;
public class PredictiveAppsProvider {
public static final int MAX_SUGGESTIONS = 9;
private static final String TAG = "PredictiveAppsProvider";
private Context mContext;
private SuggestionsDatabaseHelper mHelper;
public PredictiveAppsProvider(Context context) {
mContext = context;
mHelper = SuggestionsDatabaseHelper.getInstance(context);
}
public void updateComponentCount(ComponentName component) {
if (component == null) {
Log.w(TAG, "Can not update component count because component is null!");
return;
}
if (!Utilities.arePredictiveAppsEnabled(mContext)) {
// Don't log when predictive apps are disabled
return;
}
SuggestionCandidate candidate = mHelper.getCandidate(component.getPackageName(),
component.getClassName());
mHelper.increaseCounter(mContext, candidate);
}
public List<ComponentKeyMapper<AppInfo>> getPredictions() {
List<SuggestionCandidate> candidates = mHelper.getSuggestionCandidates(mContext);
List<ComponentKeyMapper<AppInfo>> keys = new ArrayList<>();
UserHandle handle = Process.myUserHandle();
for (SuggestionCandidate candidate : candidates) {
ComponentName name = new ComponentName(candidate.getPackageName(),
candidate.getClassName());
keys.add(new ComponentKeyMapper<>(new ComponentKey(name, handle)));
}
return keys;
}
}
|