1 /*
2  * Copyright (C) 2023 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.adservices.service.ui.enrollment.impl;
18 
19 import static com.android.adservices.service.DebugFlagsConstants.KEY_CONSENT_NOTIFICATION_DEBUG_MODE;
20 
21 import android.content.Context;
22 import android.os.Build;
23 
24 import androidx.annotation.RequiresApi;
25 
26 import com.android.adservices.service.common.ConsentNotificationJobService;
27 import com.android.adservices.service.consent.ConsentManager;
28 import com.android.adservices.service.ui.data.UxStatesManager;
29 import com.android.adservices.service.ui.enrollment.base.PrivacySandboxEnrollmentChannel;
30 import com.android.adservices.service.ui.ux.collection.PrivacySandboxUxCollection;
31 
32 /** Enrollment channel controlled by the consent notification debug mode. */
33 @RequiresApi(Build.VERSION_CODES.S)
34 public class ConsentNotificationDebugChannel implements PrivacySandboxEnrollmentChannel {
35 
36     /** Determines if user is eligible for the consent debugging channel. */
isEligible( PrivacySandboxUxCollection uxCollection, ConsentManager consentManager, UxStatesManager uxStatesManager)37     public boolean isEligible(
38             PrivacySandboxUxCollection uxCollection,
39             ConsentManager consentManager,
40             UxStatesManager uxStatesManager) {
41         return uxStatesManager.getFlag(KEY_CONSENT_NOTIFICATION_DEBUG_MODE);
42     }
43 
44     /** Enroll the user through consent notification. */
enroll(Context context, ConsentManager consentManager)45     public void enroll(Context context, ConsentManager consentManager) {
46         // The reconsent bit does not matter to the debug mode.
47         ConsentNotificationJobService.schedule(
48                 context,
49                 /* adidEnabled= */ consentManager.isAdIdEnabled(),
50                 /* reConsentStatus= */ false);
51     }
52 }
53