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.ui; 18 19 20 import android.annotation.RequiresApi; 21 import android.os.Build; 22 23 import com.android.adservices.service.FlagsFactory; 24 import com.android.adservices.service.consent.ConsentConstants.EndUserUx; 25 import com.android.adservices.service.ui.data.UxStatesManager; 26 import com.android.adservices.service.ui.ux.collection.PrivacySandboxUxCollection; 27 28 /** 29 * Activities and Action Delegates should implement this interface to ensure they implement all 30 * existing modes of AdServices. 31 */ 32 @RequiresApi(Build.VERSION_CODES.S) 33 public interface UxSelector { 34 35 /** 36 * This method will be called in during initialization of class to determine which ux to choose. 37 * 38 * @return Ux that end user should see. 39 */ initWithUx()40 default EndUserUx initWithUx() { 41 return initWithUx(false); 42 } 43 44 /** 45 * This method will be called in during initialization of class to determine which ux to choose. 46 * 47 * @param beforePasUxActive if the current activity is before PAS UX is active, so it is part of 48 * the process of activating PAS UX and should be shown if flag is on. 49 * @return Ux that end user should see. 50 */ initWithUx(boolean beforePasUxActive)51 default EndUserUx initWithUx(boolean beforePasUxActive) { 52 EndUserUx endUserUx = getEndUserUx(beforePasUxActive); 53 switch (endUserUx) { 54 case GA: 55 initGA(); 56 break; 57 case GA_WITH_PAS: 58 initGaUxWithPas(); 59 break; 60 case U18: 61 initU18(); 62 break; 63 default: 64 initGA(); 65 } 66 return endUserUx; 67 } 68 69 /** 70 * Returns the UX that the end user should be seeing currently. 71 * 72 * @return Ux that end user should see. 73 */ getEndUserUx()74 default EndUserUx getEndUserUx() { 75 return getEndUserUx(false); 76 } 77 78 /** 79 * Returns the UX that the end user should be seeing currently. 80 * 81 * @param beforePasUxActive if the current context is before PAS UX is active. 82 * @return Ux that end user should see. 83 */ getEndUserUx(boolean beforePasUxActive)84 default EndUserUx getEndUserUx(boolean beforePasUxActive) { 85 if (FlagsFactory.getFlags().getAdServicesConsentBusinessLogicMigrationEnabled()) { 86 return UxStatesManager.getInstance().getEndUserUx(); 87 } 88 switch (UxUtil.getUx()) { 89 case U18_UX: 90 return EndUserUx.U18; 91 case GA_UX: 92 if (UxUtil.pasUxIsActive(beforePasUxActive)) { 93 // ROW UI views should be updated only once notification is sent. 94 // EEA UI views should be updated only once notification is opened. 95 return EndUserUx.GA_WITH_PAS; 96 } 97 return EndUserUx.GA; 98 default: 99 // TODO: log some warning or error 100 return EndUserUx.GA; 101 } 102 } 103 104 /** 105 * This method will be called in {@link #initWithUx} if app is in {@link 106 * PrivacySandboxUxCollection#GA_UX} mode and PAS Ux feature is disabled. 107 */ initGA()108 void initGA(); 109 110 /** 111 * This method will be called in {@link #initWithUx} if app is in {@link 112 * PrivacySandboxUxCollection#U18_UX} mode. 113 */ initU18()114 void initU18(); 115 116 /** 117 * This method will be called in {@link #initWithUx} if app is in {@link 118 * PrivacySandboxUxCollection#GA_UX} mode and PAS Ux feature is enabled. 119 */ initGaUxWithPas()120 void initGaUxWithPas(); 121 } 122