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 import com.android.adservices.service.FlagsFactory; 20 21 /** 22 * Activities and Action Delegates should implement this interface to ensure they implement all 23 * existing modes of AdServices. 24 */ 25 public interface ModeSelector { 26 /** 27 * Contains all the modes for AdServices module. Each mode should have a corresponding method to 28 * get the layoutResId for that mode. 29 */ 30 enum ModeEnum { 31 BETA, 32 GA, 33 U18, 34 } 35 36 /** 37 * Temporary Utility class to get the current mode for AdServices module. This will be replace 38 * with UX Engine. 39 */ 40 class CurrentMode { 41 private static ModeEnum sCurrentMode; 42 get(boolean refresh)43 public static ModeEnum get(boolean refresh) { 44 if (refresh || sCurrentMode == null) { 45 sCurrentMode = 46 FlagsFactory.getFlags().getGaUxFeatureEnabled() 47 ? ModeEnum.GA 48 : ModeEnum.BETA; 49 } 50 return sCurrentMode; 51 } 52 } 53 54 /** 55 * This method will be called in during initialization of class to determine which mode to 56 * choose. 57 * 58 * @param refresh if true, will re-fetch current UI mode. Should only be true at start of UI 59 * flows (e.g. main view of settings, notification landing page, notification card) 60 */ initWithMode(boolean refresh)61 default void initWithMode(boolean refresh) { 62 switch (CurrentMode.get(refresh)) { 63 case BETA: 64 initBeta(); 65 break; 66 case GA: 67 initGA(); 68 break; 69 case U18: 70 initU18(); 71 break; 72 default: 73 // TODO: log some warning or error 74 initGA(); 75 } 76 } 77 78 /** 79 * This method will be called in {@link #initWithMode} if app is in {@link ModeEnum#BETA} mode. 80 */ initBeta()81 void initBeta(); 82 83 /** 84 * This method will be called in {@link #initWithMode} if app is in {@link ModeEnum#GA} mode. 85 */ initGA()86 void initGA(); 87 88 /** 89 * This method will be called in {@link #initWithMode} if app is in {@link ModeEnum#U18} mode. 90 */ initU18()91 void initU18(); 92 } 93