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.consent.ConsentManager.NO_MANUAL_INTERACTIONS_RECORDED; 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 /** Enroll through consent notification debug mode. Currently only supported for GA UX. */ 33 @RequiresApi(Build.VERSION_CODES.S) 34 public class ReconsentNotificationChannel implements PrivacySandboxEnrollmentChannel { 35 36 /** Determines if user is eligible for the reconsent enrollment channel. */ isEligible( PrivacySandboxUxCollection uxCollection, ConsentManager consentManager, UxStatesManager uxStatesManager)37 public boolean isEligible( 38 PrivacySandboxUxCollection uxCollection, 39 ConsentManager consentManager, 40 UxStatesManager uxStatesManager) { 41 return consentManager.wasNotificationDisplayed() 42 && (consentManager.getConsent().isGiven() 43 || consentManager.getUserManualInteractionWithConsent() 44 == NO_MANUAL_INTERACTIONS_RECORDED); 45 } 46 47 /** Enroll user through the reconsent enrollment channel. */ enroll(Context context, ConsentManager consentManager)48 public void enroll(Context context, ConsentManager consentManager) { 49 ConsentNotificationJobService.schedule( 50 context, 51 /* adidEnabled= */ consentManager.isAdIdEnabled(), 52 /* reConsentStatus= */ true); 53 } 54 } 55