1 /*
2  * Copyright (C) 2024 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.intentresolver.emptystate;
18 
19 import android.app.admin.DevicePolicyEventLogger;
20 
21 import androidx.annotation.Nullable;
22 
23 /**
24  * Empty state that gets strings from the device policy manager and tracks events into
25  * event logger of the device policy events.
26  */
27 public class DevicePolicyBlockerEmptyState implements EmptyState {
28     private final String mTitle;
29     private final String mSubtitle;
30     private final int mEventId;
31     private final String mEventCategory;
32 
DevicePolicyBlockerEmptyState( String title, String subtitle, int devicePolicyEventId, String devicePolicyEventCategory)33     public DevicePolicyBlockerEmptyState(
34             String title,
35             String subtitle,
36             int devicePolicyEventId,
37             String devicePolicyEventCategory) {
38         mTitle = title;
39         mSubtitle = subtitle;
40         mEventId = devicePolicyEventId;
41         mEventCategory = devicePolicyEventCategory;
42     }
43 
44     @Nullable
45     @Override
getTitle()46     public String getTitle() {
47         return mTitle;
48     }
49 
50     @Nullable
51     @Override
getSubtitle()52     public String getSubtitle() {
53         return mSubtitle;
54     }
55 
56     @Override
onEmptyStateShown()57     public void onEmptyStateShown() {
58         if (mEventId != -1) {
59             DevicePolicyEventLogger.createEvent(mEventId)
60                     .setStrings(mEventCategory)
61                     .write();
62         }
63     }
64 
65     @Override
shouldSkipDataRebuild()66     public boolean shouldSkipDataRebuild() {
67         return true;
68     }
69 }
70