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.model;
18 
19 import androidx.annotation.VisibleForTesting;
20 import android.text.format.DateUtils;
21 
22 import java.util.ArrayList;
23 import java.util.List;
24 
25 public class SuggestionCategoryRegistry {
26 
27     @VisibleForTesting
28     static final String CATEGORY_KEY_DEFERRED_SETUP =
29             "com.android.settings.suggested.category.DEFERRED_SETUP";
30     @VisibleForTesting
31     static final String CATEGORY_KEY_HIGH_PRIORITY =
32         "com.android.settings.suggested.category.HIGH_PRIORITY";
33     @VisibleForTesting
34     static final String CATEGORY_KEY_FIRST_IMPRESSION =
35             "com.android.settings.suggested.category.FIRST_IMPRESSION";
36 
37     public static final List<SuggestionCategory> CATEGORIES;
38 
39     private static final long NEVER_EXPIRE = -1L;
40 
41     // This is equivalent to packages/apps/settings/res/values/suggestion_ordering.xml
42     static {
43         CATEGORIES = new ArrayList<>();
buildCategory(CATEGORY_KEY_DEFERRED_SETUP, true , 14 * DateUtils.DAY_IN_MILLIS)44         CATEGORIES.add(buildCategory(CATEGORY_KEY_DEFERRED_SETUP,
45                 true /* exclusive */, 14 * DateUtils.DAY_IN_MILLIS));
buildCategory(CATEGORY_KEY_HIGH_PRIORITY, true , 3 * DateUtils.DAY_IN_MILLIS)46         CATEGORIES.add(buildCategory(CATEGORY_KEY_HIGH_PRIORITY,
47                 true /* exclusive */, 3 * DateUtils.DAY_IN_MILLIS));
buildCategory(CATEGORY_KEY_FIRST_IMPRESSION, true , 14 * DateUtils.DAY_IN_MILLIS)48         CATEGORIES.add(buildCategory(CATEGORY_KEY_FIRST_IMPRESSION,
49                 true /* exclusive */, 14 * DateUtils.DAY_IN_MILLIS));
50         CATEGORIES.add(buildCategory("com.android.settings.suggested.category.LOCK_SCREEN",
51                 false /* exclusive */, NEVER_EXPIRE));
52         CATEGORIES.add(buildCategory("com.android.settings.suggested.category.TRUST_AGENT",
53                 false /* exclusive */, NEVER_EXPIRE));
54         CATEGORIES.add(buildCategory("com.android.settings.suggested.category.EMAIL",
55                 false /* exclusive */, NEVER_EXPIRE));
56         CATEGORIES.add(buildCategory("com.android.settings.suggested.category.PARTNER_ACCOUNT",
57                 false /* exclusive */, NEVER_EXPIRE));
58         CATEGORIES.add(buildCategory("com.android.settings.suggested.category.GESTURE",
59                 false /* exclusive */, NEVER_EXPIRE));
60         CATEGORIES.add(buildCategory("com.android.settings.suggested.category.HOTWORD",
61                 false /* exclusive */, NEVER_EXPIRE));
62         CATEGORIES.add(buildCategory("com.android.settings.suggested.category.DEFAULT",
63                 false /* exclusive */, NEVER_EXPIRE));
64         CATEGORIES.add(buildCategory("com.android.settings.suggested.category.SETTINGS_ONLY",
65                 false /* exclusive */, NEVER_EXPIRE));
66     }
67 
buildCategory(String categoryName, boolean exclusive, long expireDaysInMillis)68     private static SuggestionCategory buildCategory(String categoryName, boolean exclusive,
69             long expireDaysInMillis) {
70         return new SuggestionCategory.Builder()
71                 .setCategory(categoryName)
72                 .setExclusive(exclusive)
73                 .setExclusiveExpireDaysInMillis(expireDaysInMillis)
74                 .build();
75     }
76 
77 }
78