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.stats; 18 19 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED; 20 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__ACTION_UNSPECIFIED; 21 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__BLOCK_APP_SELECTED; 22 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__BLOCK_TOPIC_SELECTED; 23 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__CONFIRMATION_PAGE_DISMISSED; 24 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__CONFIRMATION_PAGE_DISPLAYED; 25 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__FLEDGE_OPT_IN_SELECTED; 26 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__FLEDGE_OPT_OUT_SELECTED; 27 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_CONFIRMATION_PAGE_DISMISSED; 28 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_ADDITIONAL_INFO_2_CLICKED; 29 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_ADDITIONAL_INFO_CLICKED; 30 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_DISMISSED; 31 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_GOT_IT_BUTTON_CLICKED; 32 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_MORE_BUTTON_CLICKED; 33 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_OPT_IN; 34 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_OPT_OUT; 35 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_SCROLLED; 36 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_SCROLLED_TO_BOTTOM; 37 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_SETTINGS_BUTTON_CLICKED; 38 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_NOTIFICATION_CONFIRMATION_PAGE_DISPLAYED; 39 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_NOTIFICATION_DISABLED; 40 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_NOTIFICATION_DISPLAYED; 41 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_NOTIFICATION_LANDING_PAGE_DISPLAYED; 42 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_NOTIFICATION_REQUESTED; 43 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_IN_CONFIRMATION_PAGE_GOT_IT_CLICKED; 44 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_IN_CONFIRMATION_PAGE_MORE_INFO_CLICKED; 45 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_IN_CONFIRMATION_PAGE_SETTINGS_CLICKED; 46 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_OUT_CONFIRMATION_PAGE_GOT_IT_CLICKED; 47 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_OUT_CONFIRMATION_PAGE_MORE_INFO_CLICKED; 48 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_OUT_CONFIRMATION_PAGE_SETTINGS_CLICKED; 49 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_ADDITIONAL_INFO_CLICKED; 50 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_DISMISSED; 51 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_DISPLAYED; 52 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_GOT_IT_BUTTON_CLICKED; 53 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_MORE_BUTTON_CLICKED; 54 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_OPT_IN; 55 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_OPT_OUT; 56 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_SCROLLED; 57 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_SCROLLED_TO_BOTTOM; 58 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_SETTINGS_BUTTON_CLICKED; 59 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__MANAGE_APPS_SELECTED; 60 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__MANAGE_MEASUREMENT_SELECTED; 61 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__MANAGE_TOPICS_SELECTED; 62 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__MEASUREMENT_OPT_IN_SELECTED; 63 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__MEASUREMENT_OPT_OUT_SELECTED; 64 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__NOTIFICATION_DISABLED; 65 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__NOTIFICATION_DISPLAYED; 66 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__NOTIFICATION_OPT_IN_SELECTED; 67 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__NOTIFICATION_OPT_OUT_SELECTED; 68 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_IN_CONFIRMATION_PAGE_GOT_IT_CLICKED; 69 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_IN_CONFIRMATION_PAGE_SETTINGS_CLICKED; 70 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_IN_SELECTED; 71 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_OUT_CONFIRMATION_PAGE_GOT_IT_CLICKED; 72 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_OUT_CONFIRMATION_PAGE_SETTINGS_CLICKED; 73 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_OUT_SELECTED; 74 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__PRIVACY_SANDBOX_ENTRY_POINT_CLICKED; 75 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__PRIVACY_SANDBOX_SETTINGS_PAGE_DISPLAYED; 76 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__REQUESTED_NOTIFICATION; 77 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__RESET_APP_SELECTED; 78 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__RESET_MEASUREMENT_SELECTED; 79 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__RESET_TOPIC_SELECTED; 80 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__TOPICS_OPT_IN_SELECTED; 81 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__TOPICS_OPT_OUT_SELECTED; 82 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__UNBLOCK_APP_SELECTED; 83 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__UNBLOCK_TOPIC_SELECTED; 84 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_AD_ID_STATE__AD_ID_DISABLED; 85 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_AD_ID_STATE__AD_ID_ENABLED; 86 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_AD_ID_STATE__STATE_UNSPECIFIED; 87 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__CONSENT_UNSPECIFIED; 88 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__FLEDGE_DEFAULT_OPT_IN; 89 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__FLEDGE_DEFAULT_OPT_OUT; 90 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__MEASUREMENT_DEFAULT_OPT_IN; 91 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__MEASUREMENT_DEFAULT_OPT_OUT; 92 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__PP_API_DEFAULT_OPT_IN; 93 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__PP_API_DEFAULT_OPT_OUT; 94 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__TOPICS_DEFAULT_OPT_IN; 95 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__TOPICS_DEFAULT_OPT_OUT; 96 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__ALREADY_ENROLLED_CHANNEL; 97 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__CONSENT_NOTIFICATION_DEBUG_CHANNEL; 98 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__FIRST_CONSENT_NOTIFICATION_CHANNEL; 99 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__PAS_FIRST_NOTIFICATION_CHANNEL; 100 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__PAS_RENOTIFY_NOTIFICATION_CHANNEL; 101 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__RVC_POST_OTA_NOTIFICATION_CHANNEL; 102 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__RECONSENT_NOTIFICATION_CHANNEL; 103 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__UNSPECIFIED_CHANNEL; 104 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__UNSUPPORTED_CHANNEL; 105 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__REGION__EU; 106 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__REGION__ROW; 107 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__BETA_UX; 108 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__GA_UX_WITH_PAS; 109 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__RVC_UX; 110 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__GA_UX; 111 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__UNSPECIFIED_UX; 112 import static com.android.adservices.service.stats.AdServicesStatsLog.AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__UNSUPPORTED_UX; 113 import static com.android.adservices.service.ui.constants.DebugMessages.PRIVACY_SANDBOX_UI_REQUEST_MESSAGE; 114 import static com.android.adservices.service.ui.ux.collection.PrivacySandboxUxCollection.RVC_UX; 115 116 import android.content.Context; 117 import android.os.Build; 118 119 import androidx.annotation.RequiresApi; 120 121 import com.android.adservices.LogUtil; 122 import com.android.adservices.service.FlagsFactory; 123 import com.android.adservices.service.consent.AdServicesApiType; 124 import com.android.adservices.service.consent.ConsentManager; 125 import com.android.adservices.service.consent.DeviceRegionProvider; 126 import com.android.adservices.service.ui.data.UxStatesManager; 127 import com.android.adservices.service.ui.enrollment.collection.BetaUxEnrollmentChannelCollection; 128 import com.android.adservices.service.ui.enrollment.collection.GaUxEnrollmentChannelCollection; 129 import com.android.adservices.service.ui.enrollment.collection.PrivacySandboxEnrollmentChannelCollection; 130 import com.android.adservices.service.ui.enrollment.collection.RvcUxEnrollmentChannelCollection; 131 import com.android.adservices.service.ui.enrollment.collection.U18UxEnrollmentChannelCollection; 132 import com.android.adservices.shared.common.ApplicationContextSingleton; 133 import com.android.internal.annotations.VisibleForTesting; 134 135 /** Logger for UiStats. */ 136 // TODO(b/269798827): Enable for R. 137 @RequiresApi(Build.VERSION_CODES.S) 138 public final class UiStatsLogger { 139 private static AdServicesLoggerImpl sLogger = AdServicesLoggerImpl.getInstance(); 140 141 /** Logs that a notification was displayed. */ logNotificationDisplayed()142 public static void logNotificationDisplayed() { 143 UIStats uiStats = getBaseUiStats(); 144 145 uiStats.setAction( 146 FlagsFactory.getFlags().getGaUxFeatureEnabled() 147 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_NOTIFICATION_DISPLAYED 148 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__NOTIFICATION_DISPLAYED); 149 150 getAdServicesLogger().logUIStats(uiStats); 151 } 152 153 /** Logs that the more button on the landing page was displayed. */ logLandingPageMoreButtonClicked()154 public static void logLandingPageMoreButtonClicked() { 155 UIStats uiStats = getBaseUiStats(); 156 157 uiStats.setAction( 158 FlagsFactory.getFlags().getGaUxFeatureEnabled() 159 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_MORE_BUTTON_CLICKED 160 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_MORE_BUTTON_CLICKED); 161 162 getAdServicesLogger().logUIStats(uiStats); 163 } 164 165 /** Logs that the additional info dropdown on the landing page was displayed. */ logLandingPageAdditionalInfoClicked()166 public static void logLandingPageAdditionalInfoClicked() { 167 UIStats uiStats = getBaseUiStats(); 168 169 uiStats.setAction( 170 FlagsFactory.getFlags().getGaUxFeatureEnabled() 171 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_ADDITIONAL_INFO_CLICKED 172 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_ADDITIONAL_INFO_CLICKED); 173 174 getAdServicesLogger().logUIStats(uiStats); 175 } 176 177 /** Logs that the user scrolled the landing page. */ logLandingPageScrolled()178 public static void logLandingPageScrolled() { 179 UIStats uiStats = getBaseUiStats(); 180 181 uiStats.setAction( 182 FlagsFactory.getFlags().getGaUxFeatureEnabled() 183 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_SCROLLED 184 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_SCROLLED); 185 186 getAdServicesLogger().logUIStats(uiStats); 187 } 188 189 /** Logs that the user scrolled to the bottom of the landing page. */ logLandingPageScrolledToBottom()190 public static void logLandingPageScrolledToBottom() { 191 UIStats uiStats = getBaseUiStats(); 192 193 uiStats.setAction( 194 FlagsFactory.getFlags().getGaUxFeatureEnabled() 195 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_SCROLLED_TO_BOTTOM 196 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_SCROLLED_TO_BOTTOM); 197 198 getAdServicesLogger().logUIStats(uiStats); 199 } 200 201 /** Logs that the user clicked the setting button on the landing page. */ logLandingPageSettingsButtonClicked()202 public static void logLandingPageSettingsButtonClicked() { 203 UIStats uiStats = getBaseUiStats(); 204 205 uiStats.setAction( 206 FlagsFactory.getFlags().getGaUxFeatureEnabled() 207 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_SETTINGS_BUTTON_CLICKED 208 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_SETTINGS_BUTTON_CLICKED); 209 210 getAdServicesLogger().logUIStats(uiStats); 211 } 212 213 /** Logs that the user dismissed the landing page. */ logLandingPageDismissed()214 public static void logLandingPageDismissed() { 215 UIStats uiStats = getBaseUiStats(); 216 217 uiStats.setAction( 218 FlagsFactory.getFlags().getGaUxFeatureEnabled() 219 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_DISMISSED 220 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_DISMISSED); 221 222 getAdServicesLogger().logUIStats(uiStats); 223 } 224 225 /** Logs that the user clicked the got it button on the landing page. */ logLandingPageGotItButtonClicked()226 public static void logLandingPageGotItButtonClicked() { 227 UIStats uiStats = getBaseUiStats(); 228 229 uiStats.setAction( 230 FlagsFactory.getFlags().getGaUxFeatureEnabled() 231 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_GOT_IT_BUTTON_CLICKED 232 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_GOT_IT_BUTTON_CLICKED); 233 234 getAdServicesLogger().logUIStats(uiStats); 235 } 236 237 /** Logs that the user opt-in from the landing page. */ logLandingPageOptIn()238 public static void logLandingPageOptIn() { 239 UIStats uiStats = getBaseUiStats(); 240 241 uiStats.setAction( 242 FlagsFactory.getFlags().getGaUxFeatureEnabled() 243 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_OPT_IN 244 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_OPT_IN); 245 246 getAdServicesLogger().logUIStats(uiStats); 247 } 248 249 /** Logs that the user opt-out from the landing page. */ logLandingPageOptOut()250 public static void logLandingPageOptOut() { 251 UIStats uiStats = getBaseUiStats(); 252 253 uiStats.setAction( 254 FlagsFactory.getFlags().getGaUxFeatureEnabled() 255 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_OPT_OUT 256 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_OPT_OUT); 257 258 getAdServicesLogger().logUIStats(uiStats); 259 } 260 261 /** Logs that the user clicked settings on the opt-in confirmation page. */ logOptInConfirmationPageSettingsClicked()262 public static void logOptInConfirmationPageSettingsClicked() { 263 UIStats uiStats = getBaseUiStats(); 264 265 uiStats.setAction( 266 FlagsFactory.getFlags().getGaUxFeatureEnabled() 267 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_IN_CONFIRMATION_PAGE_SETTINGS_CLICKED 268 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_IN_CONFIRMATION_PAGE_SETTINGS_CLICKED); 269 270 getAdServicesLogger().logUIStats(uiStats); 271 } 272 273 /** Logs that the user clicked settings on the opt-out confirmation page. */ logOptOutConfirmationPageSettingsClicked()274 public static void logOptOutConfirmationPageSettingsClicked() { 275 UIStats uiStats = getBaseUiStats(); 276 277 uiStats.setAction( 278 FlagsFactory.getFlags().getGaUxFeatureEnabled() 279 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_OUT_CONFIRMATION_PAGE_SETTINGS_CLICKED 280 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_OUT_CONFIRMATION_PAGE_SETTINGS_CLICKED); 281 282 getAdServicesLogger().logUIStats(uiStats); 283 } 284 285 /** Logs that the user clicked got it on the opt-in confirmation page. */ logOptInConfirmationPageGotItClicked()286 public static void logOptInConfirmationPageGotItClicked() { 287 UIStats uiStats = getBaseUiStats(); 288 289 uiStats.setAction( 290 FlagsFactory.getFlags().getGaUxFeatureEnabled() 291 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_IN_CONFIRMATION_PAGE_GOT_IT_CLICKED 292 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_IN_CONFIRMATION_PAGE_GOT_IT_CLICKED); 293 294 getAdServicesLogger().logUIStats(uiStats); 295 } 296 297 /** Logs that the user clicked got it on the opt-out confirmation page. */ logOptOutConfirmationPageGotItClicked()298 public static void logOptOutConfirmationPageGotItClicked() { 299 UIStats uiStats = getBaseUiStats(); 300 301 uiStats.setAction( 302 FlagsFactory.getFlags().getGaUxFeatureEnabled() 303 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_OUT_CONFIRMATION_PAGE_GOT_IT_CLICKED 304 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_OUT_CONFIRMATION_PAGE_GOT_IT_CLICKED); 305 306 getAdServicesLogger().logUIStats(uiStats); 307 } 308 309 /** GA only. Logs that the user clicked more info on the opt-in confirmation page. */ logOptInConfirmationPageMoreInfoClicked()310 public static void logOptInConfirmationPageMoreInfoClicked() { 311 UIStats uiStats = getBaseUiStats(); 312 313 uiStats.setAction( 314 AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_IN_CONFIRMATION_PAGE_MORE_INFO_CLICKED); 315 316 getAdServicesLogger().logUIStats(uiStats); 317 } 318 319 /** GA only. Logs that the user clicked more info on the opt-out confirmation page. */ logOptOutConfirmationPageMoreInfoClicked()320 public static void logOptOutConfirmationPageMoreInfoClicked() { 321 UIStats uiStats = getBaseUiStats(); 322 323 uiStats.setAction( 324 AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_OPT_OUT_CONFIRMATION_PAGE_MORE_INFO_CLICKED); 325 326 getAdServicesLogger().logUIStats(uiStats); 327 } 328 329 /** Logs that the user dismissed the confirmation page. */ logConfirmationPageDismissed()330 public static void logConfirmationPageDismissed() { 331 UIStats uiStats = getBaseUiStats(); 332 333 uiStats.setAction( 334 FlagsFactory.getFlags().getGaUxFeatureEnabled() 335 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_CONFIRMATION_PAGE_DISMISSED 336 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__CONFIRMATION_PAGE_DISMISSED); 337 338 getAdServicesLogger().logUIStats(uiStats); 339 } 340 341 /** Logs that a notification was requested. */ logRequestedNotification()342 public static void logRequestedNotification() { 343 UIStats uiStats = getBaseUiStats(); 344 345 uiStats.setUx(getUx(true)); 346 uiStats.setAction( 347 FlagsFactory.getFlags().getGaUxFeatureEnabled() 348 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_NOTIFICATION_REQUESTED 349 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__REQUESTED_NOTIFICATION); 350 351 getAdServicesLogger().logUIStats(uiStats); 352 } 353 354 /** Logs that notifications are disabled on a device. */ logNotificationDisabled()355 public static void logNotificationDisabled() { 356 UIStats uiStats = getBaseUiStats(); 357 358 uiStats.setUx(getUx(true)); 359 uiStats.setAction( 360 FlagsFactory.getFlags().getGaUxFeatureEnabled() 361 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_NOTIFICATION_DISABLED 362 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__NOTIFICATION_DISABLED); 363 364 getAdServicesLogger().logUIStats(uiStats); 365 } 366 367 /** Logs that the landing page was shown to a user. */ logLandingPageDisplayed()368 public static void logLandingPageDisplayed() { 369 UIStats uiStats = getBaseUiStats(); 370 371 uiStats.setAction( 372 FlagsFactory.getFlags().getGaUxFeatureEnabled() 373 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_NOTIFICATION_LANDING_PAGE_DISPLAYED 374 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__LANDING_PAGE_DISPLAYED); 375 376 getAdServicesLogger().logUIStats(uiStats); 377 } 378 379 /** Logs that the confirmation page was shown to a user. */ logConfirmationPageDisplayed()380 public static void logConfirmationPageDisplayed() { 381 UIStats uiStats = getBaseUiStats(); 382 383 uiStats.setAction( 384 FlagsFactory.getFlags().getGaUxFeatureEnabled() 385 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_NOTIFICATION_CONFIRMATION_PAGE_DISPLAYED 386 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__CONFIRMATION_PAGE_DISPLAYED); 387 388 getAdServicesLogger().logUIStats(uiStats); 389 } 390 391 /** Logs user opt-in action for PP API. */ logOptInSelected()392 public static void logOptInSelected() { 393 UIStats uiStats = getBaseUiStats(); 394 395 uiStats.setAction( 396 FlagsFactory.getFlags().getGaUxFeatureEnabled() 397 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__NOTIFICATION_OPT_IN_SELECTED 398 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_IN_SELECTED); 399 400 getAdServicesLogger().logUIStats(uiStats); 401 } 402 403 /** Logs user opt-out action for PP API. */ logOptOutSelected()404 public static void logOptOutSelected() { 405 UIStats uiStats = getBaseUiStats(); 406 407 uiStats.setAction( 408 FlagsFactory.getFlags().getGaUxFeatureEnabled() 409 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__NOTIFICATION_OPT_OUT_SELECTED 410 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__OPT_OUT_SELECTED); 411 412 getAdServicesLogger().logUIStats(uiStats); 413 } 414 415 /** Logs user opt-in action given an ApiType. */ logOptInSelected(AdServicesApiType apiType)416 public static void logOptInSelected(AdServicesApiType apiType) { 417 UIStats uiStats = getBaseUiStats(apiType); 418 419 uiStats.setAction(getPerApiConsentAction(apiType, /* isOptIn */ true)); 420 421 getAdServicesLogger().logUIStats(uiStats); 422 } 423 424 /** Logs user opt-out action given an ApiType. */ logOptOutSelected(AdServicesApiType apiType)425 public static void logOptOutSelected(AdServicesApiType apiType) { 426 UIStats uiStats = getBaseUiStats(apiType); 427 428 uiStats.setAction(getPerApiConsentAction(apiType, /* isOptIn */ false)); 429 430 getAdServicesLogger().logUIStats(uiStats); 431 } 432 433 /** Logs that a user has opened the settings page. */ logSettingsPageDisplayed()434 public static void logSettingsPageDisplayed() { 435 UIStats uiStats = getBaseUiStats(); 436 437 uiStats.setAction( 438 AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__PRIVACY_SANDBOX_SETTINGS_PAGE_DISPLAYED); 439 440 getAdServicesLogger().logUIStats(uiStats); 441 } 442 443 /** Logs that a user has clicked manage topics button. */ logManageTopicsSelected()444 public static void logManageTopicsSelected() { 445 UIStats uiStats = getBaseUiStats(); 446 447 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__MANAGE_TOPICS_SELECTED); 448 449 getAdServicesLogger().logUIStats(uiStats); 450 } 451 452 /** Logs that a user has clicked manage apps button. */ logManageAppsSelected()453 public static void logManageAppsSelected() { 454 UIStats uiStats = getBaseUiStats(); 455 456 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__MANAGE_APPS_SELECTED); 457 458 getAdServicesLogger().logUIStats(uiStats); 459 } 460 461 /** Logs that a user has clicked reset topics button. */ logResetTopicSelected()462 public static void logResetTopicSelected() { 463 UIStats uiStats = getBaseUiStats(); 464 465 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__RESET_TOPIC_SELECTED); 466 467 getAdServicesLogger().logUIStats(uiStats); 468 } 469 470 /** Logs that a user has clicked reset apps button. */ logResetAppSelected()471 public static void logResetAppSelected() { 472 UIStats uiStats = getBaseUiStats(); 473 474 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__RESET_APP_SELECTED); 475 476 getAdServicesLogger().logUIStats(uiStats); 477 } 478 479 /** Logs that a user has clicked block topic button. */ logBlockTopicSelected()480 public static void logBlockTopicSelected() { 481 UIStats uiStats = getBaseUiStats(); 482 483 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__BLOCK_TOPIC_SELECTED); 484 485 getAdServicesLogger().logUIStats(uiStats); 486 } 487 488 /** Logs that a user has clicked unblock topic button. */ logUnblockTopicSelected()489 public static void logUnblockTopicSelected() { 490 UIStats uiStats = getBaseUiStats(); 491 492 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__UNBLOCK_TOPIC_SELECTED); 493 494 getAdServicesLogger().logUIStats(uiStats); 495 } 496 497 /** Logs that a user has clicked block app button. */ logBlockAppSelected()498 public static void logBlockAppSelected() { 499 UIStats uiStats = getBaseUiStats(); 500 501 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__BLOCK_APP_SELECTED); 502 503 getAdServicesLogger().logUIStats(uiStats); 504 } 505 506 /** Logs that a user has clicked unblock app button. */ logUnblockAppSelected()507 public static void logUnblockAppSelected() { 508 UIStats uiStats = getBaseUiStats(); 509 510 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__UNBLOCK_APP_SELECTED); 511 512 getAdServicesLogger().logUIStats(uiStats); 513 } 514 515 /** Logs that a user has clicked manage measurement button. */ logManageMeasurementSelected()516 public static void logManageMeasurementSelected() { 517 UIStats uiStats = getBaseUiStats(); 518 519 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__MANAGE_MEASUREMENT_SELECTED); 520 521 getAdServicesLogger().logUIStats(uiStats); 522 } 523 524 /** Logs that a user has clicked reset measurement button. */ logResetMeasurementSelected()525 public static void logResetMeasurementSelected() { 526 UIStats uiStats = getBaseUiStats(); 527 528 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__RESET_MEASUREMENT_SELECTED); 529 530 getAdServicesLogger().logUIStats(uiStats); 531 } 532 533 /** Logs that the user has clicked the privacy sandbox entry point in the settings page. */ logEntryPointClicked()534 public static void logEntryPointClicked() { 535 UIStats uiStats = getBaseUiStats(); 536 537 uiStats.setAction( 538 AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__PRIVACY_SANDBOX_ENTRY_POINT_CLICKED); 539 540 getAdServicesLogger().logUIStats(uiStats); 541 542 LogUtil.d(PRIVACY_SANDBOX_UI_REQUEST_MESSAGE); 543 } 544 545 /** Logs that the second additional info button on the landing page was clicked. */ logLandingPageSecondAdditionalInfoClicked()546 public static void logLandingPageSecondAdditionalInfoClicked() { 547 UIStats uiStats = getBaseUiStats(); 548 549 uiStats.setAction( 550 AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__GA_UX_LANDING_PAGE_ADDITIONAL_INFO_2_CLICKED); 551 552 getAdServicesLogger().logUIStats(uiStats); 553 } 554 555 @VisibleForTesting getAdServicesLogger()556 public static AdServicesLogger getAdServicesLogger() { 557 return sLogger; 558 } 559 /** Logs that the user enter an unspecified ux flow. */ logRequestedNotificationIneligible()560 public static void logRequestedNotificationIneligible() { 561 UIStats uiStats = getBaseUiStats(); 562 563 /* Reuse beta's notification here, so that this track won't affect GA metrics */ 564 uiStats.setAction(AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__REQUESTED_NOTIFICATION); 565 uiStats.setUx(AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__UNSUPPORTED_UX); 566 sLogger.logUIStats(uiStats); 567 568 LogUtil.d(PRIVACY_SANDBOX_UI_REQUEST_MESSAGE); 569 } 570 getRegion()571 private static int getRegion() { 572 Context context = getApplicationContext(); 573 return DeviceRegionProvider.isEuDevice(context) 574 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__REGION__EU 575 : AD_SERVICES_SETTINGS_USAGE_REPORTED__REGION__ROW; 576 } 577 getDefaultConsent()578 private static int getDefaultConsent() { 579 if (UxStatesManager.getInstance().getUx() == RVC_UX) { 580 return getDefaultConsent(AdServicesApiType.MEASUREMENTS); 581 } 582 Boolean defaultConsent = ConsentManager.getInstance().getDefaultConsent(); 583 // edge case where the user opens the settings pages before receiving consent notification. 584 if (defaultConsent == null) { 585 return AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__CONSENT_UNSPECIFIED; 586 } else { 587 return defaultConsent 588 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__PP_API_DEFAULT_OPT_IN 589 : AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__PP_API_DEFAULT_OPT_OUT; 590 } 591 } 592 getDefaultAdIdState()593 private static int getDefaultAdIdState() { 594 Boolean defaultAdIdState = ConsentManager.getInstance().getDefaultAdIdState(); 595 // edge case where the user opens the settings pages before receiving consent notification. 596 if (defaultAdIdState == null) { 597 return AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_AD_ID_STATE__STATE_UNSPECIFIED; 598 } else { 599 return defaultAdIdState 600 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_AD_ID_STATE__AD_ID_ENABLED 601 : AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_AD_ID_STATE__AD_ID_DISABLED; 602 } 603 } 604 getDefaultConsent(AdServicesApiType apiType)605 private static int getDefaultConsent(AdServicesApiType apiType) { 606 switch (apiType) { 607 case TOPICS: 608 Boolean topicsDefaultConsent = 609 ConsentManager.getInstance().getTopicsDefaultConsent(); 610 // edge case where the user checks topic consent before receiving consent 611 // notification. 612 if (topicsDefaultConsent == null) { 613 return AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_AD_ID_STATE__STATE_UNSPECIFIED; 614 } else { 615 return topicsDefaultConsent 616 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__TOPICS_DEFAULT_OPT_IN 617 : AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__TOPICS_DEFAULT_OPT_OUT; 618 } 619 case FLEDGE: 620 Boolean fledgeDefaultConsent = 621 ConsentManager.getInstance().getFledgeDefaultConsent(); 622 // edge case where the user checks FLEDGE consent before receiving consent 623 // notification. 624 if (fledgeDefaultConsent == null) { 625 return AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_AD_ID_STATE__STATE_UNSPECIFIED; 626 } else { 627 return fledgeDefaultConsent 628 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__FLEDGE_DEFAULT_OPT_IN 629 : AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__FLEDGE_DEFAULT_OPT_OUT; 630 } 631 case MEASUREMENTS: 632 Boolean measurementDefaultConsent = 633 ConsentManager.getInstance().getMeasurementDefaultConsent(); 634 // edge case where the user checks measurement consent before receiving consent 635 // notification. 636 if (measurementDefaultConsent == null) { 637 return AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_AD_ID_STATE__STATE_UNSPECIFIED; 638 } else { 639 return measurementDefaultConsent 640 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__MEASUREMENT_DEFAULT_OPT_IN 641 : AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__MEASUREMENT_DEFAULT_OPT_OUT; 642 } 643 default: 644 return AD_SERVICES_SETTINGS_USAGE_REPORTED__DEFAULT_CONSENT__CONSENT_UNSPECIFIED; 645 } 646 } 647 getPerApiConsentAction(AdServicesApiType apiType, boolean isOptIn)648 private static int getPerApiConsentAction(AdServicesApiType apiType, boolean isOptIn) { 649 switch (apiType) { 650 case TOPICS: 651 return isOptIn 652 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__TOPICS_OPT_IN_SELECTED 653 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__TOPICS_OPT_OUT_SELECTED; 654 case FLEDGE: 655 return isOptIn 656 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__FLEDGE_OPT_IN_SELECTED 657 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__FLEDGE_OPT_OUT_SELECTED; 658 case MEASUREMENTS: 659 return isOptIn 660 ? AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__MEASUREMENT_OPT_IN_SELECTED 661 : AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__MEASUREMENT_OPT_OUT_SELECTED; 662 default: 663 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ACTION__ACTION_UNSPECIFIED; 664 } 665 } 666 getUx(boolean beforeNotificationShown)667 private static int getUx(boolean beforeNotificationShown) { 668 switch (UxStatesManager.getInstance().getUx()) { 669 case U18_UX: 670 return AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__UNSPECIFIED_UX; 671 case RVC_UX: 672 return AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__RVC_UX; 673 case GA_UX: 674 if (UxStatesManager.getInstance().pasUxIsActive(beforeNotificationShown)) { 675 // UI views should be updated only once notification is sent (ROW). 676 return AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__GA_UX_WITH_PAS; 677 } 678 return AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__GA_UX; 679 case BETA_UX: 680 return AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__BETA_UX; 681 default: 682 return AD_SERVICES_SETTINGS_USAGE_REPORTED__UX__UNSUPPORTED_UX; 683 } 684 } 685 getEnrollmentChannel()686 private static int getEnrollmentChannel() { 687 PrivacySandboxEnrollmentChannelCollection enrollmentChannel = 688 UxStatesManager.getInstance().getEnrollmentChannel(); 689 if (enrollmentChannel == GaUxEnrollmentChannelCollection.FIRST_CONSENT_NOTIFICATION_CHANNEL 690 || enrollmentChannel 691 == BetaUxEnrollmentChannelCollection.FIRST_CONSENT_NOTIFICATION_CHANNEL 692 || enrollmentChannel 693 == U18UxEnrollmentChannelCollection.FIRST_CONSENT_NOTIFICATION_CHANNEL 694 || enrollmentChannel 695 == RvcUxEnrollmentChannelCollection.FIRST_CONSENT_NOTIFICATION_CHANNEL) { 696 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__FIRST_CONSENT_NOTIFICATION_CHANNEL; 697 } else if (enrollmentChannel 698 == GaUxEnrollmentChannelCollection.PAS_FIRST_CONSENT_NOTIFICATION_CHANNEL) { 699 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__PAS_FIRST_NOTIFICATION_CHANNEL; 700 } else if (enrollmentChannel 701 == GaUxEnrollmentChannelCollection.CONSENT_NOTIFICATION_DEBUG_CHANNEL 702 || enrollmentChannel 703 == BetaUxEnrollmentChannelCollection.CONSENT_NOTIFICATION_DEBUG_CHANNEL 704 || enrollmentChannel 705 == U18UxEnrollmentChannelCollection.CONSENT_NOTIFICATION_DEBUG_CHANNEL 706 || enrollmentChannel 707 == RvcUxEnrollmentChannelCollection.CONSENT_NOTIFICATION_DEBUG_CHANNEL) { 708 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__CONSENT_NOTIFICATION_DEBUG_CHANNEL; 709 } else if (enrollmentChannel == GaUxEnrollmentChannelCollection.ALREADY_ENROLLED_CHANNEL 710 || enrollmentChannel == BetaUxEnrollmentChannelCollection.ALREADY_ENROLLED_CHANNEL 711 || enrollmentChannel == U18UxEnrollmentChannelCollection.ALREADY_ENROLLED_CHANNEL 712 || enrollmentChannel == RvcUxEnrollmentChannelCollection.ALREADY_ENROLLED_CHANNEL) { 713 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__ALREADY_ENROLLED_CHANNEL; 714 } else if (enrollmentChannel 715 == GaUxEnrollmentChannelCollection.RECONSENT_NOTIFICATION_CHANNEL) { 716 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__RECONSENT_NOTIFICATION_CHANNEL; 717 } else if (enrollmentChannel 718 == GaUxEnrollmentChannelCollection.PAS_RECONSENT_NOTIFICATION_CHANNEL) { 719 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__PAS_RENOTIFY_NOTIFICATION_CHANNEL; 720 } else if (enrollmentChannel == GaUxEnrollmentChannelCollection.GA_GRADUATION_CHANNEL) { 721 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__UNSPECIFIED_CHANNEL; 722 } else if (enrollmentChannel == U18UxEnrollmentChannelCollection.U18_DETENTION_CHANNEL) { 723 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__UNSPECIFIED_CHANNEL; 724 } else if (enrollmentChannel == GaUxEnrollmentChannelCollection.RVC_POST_OTA_CHANNEL) { 725 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__RVC_POST_OTA_NOTIFICATION_CHANNEL; 726 } 727 return AD_SERVICES_SETTINGS_USAGE_REPORTED__ENROLLMENT_CHANNEL__UNSUPPORTED_CHANNEL; 728 } 729 getBaseUiStats()730 private static UIStats getBaseUiStats() { 731 return new UIStats.Builder() 732 .setCode(AD_SERVICES_SETTINGS_USAGE_REPORTED) 733 .setRegion(getRegion()) 734 .setDefaultConsent(getDefaultConsent()) 735 .setDefaultAdIdState(getDefaultAdIdState()) 736 .setUx(getUx(/* beforeNotificationShown */ false)) 737 .setEnrollmentChannel(getEnrollmentChannel()) 738 .build(); 739 } 740 getBaseUiStats(AdServicesApiType apiType)741 private static UIStats getBaseUiStats(AdServicesApiType apiType) { 742 return new UIStats.Builder() 743 .setCode(AD_SERVICES_SETTINGS_USAGE_REPORTED) 744 .setRegion(getRegion()) 745 .setDefaultConsent(getDefaultConsent(apiType)) 746 .setDefaultAdIdState(getDefaultAdIdState()) 747 .setUx(getUx(/* beforeNotificationShown */ false)) 748 .setEnrollmentChannel(getEnrollmentChannel()) 749 .build(); 750 } 751 getApplicationContext()752 private static Context getApplicationContext() { 753 return ApplicationContextSingleton.get(); 754 } 755 UiStatsLogger()756 private UiStatsLogger() { 757 throw new UnsupportedOperationException(); 758 } 759 } 760