1 /* 2 * Copyright (C) 2024 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.adselection; 18 19 import android.content.Context; 20 21 import androidx.annotation.NonNull; 22 23 import com.android.adservices.service.Flags; 24 import com.android.adservices.service.adselection.encryption.ObliviousHttpEncryptor; 25 import com.android.adservices.service.adselection.encryption.ProtectedServersEncryptionConfigManagerBase; 26 import com.android.adservices.service.common.CoordinatorOriginUriValidator; 27 import com.android.adservices.service.common.httpclient.AdServicesHttpsClient; 28 29 public class MultiCloudTestStrategyFactory { 30 static class MultiCloudTestStrategyFlagOff implements MultiCloudSupportStrategy { 31 32 private ObliviousHttpEncryptor mObliviousHttpEncryptor; 33 MultiCloudTestStrategyFlagOff(ObliviousHttpEncryptor obliviousHttpEncryptor)34 MultiCloudTestStrategyFlagOff(ObliviousHttpEncryptor obliviousHttpEncryptor) { 35 this.mObliviousHttpEncryptor = obliviousHttpEncryptor; 36 } 37 38 @Override getCoordinatorOriginUriValidator()39 public CoordinatorOriginUriValidator getCoordinatorOriginUriValidator() { 40 return CoordinatorOriginUriValidator.createDisabledInstance(); 41 } 42 43 @Override getObliviousHttpEncryptor( @onNull Context context, @NonNull Flags flags)44 public ObliviousHttpEncryptor getObliviousHttpEncryptor( 45 @NonNull Context context, @NonNull Flags flags) { 46 return mObliviousHttpEncryptor; 47 } 48 49 @Override getEncryptionConfigManager( @ndroid.annotation.NonNull Context context, @android.annotation.NonNull Flags flags, @android.annotation.NonNull AdServicesHttpsClient adServicesHttpsClient)50 public ProtectedServersEncryptionConfigManagerBase getEncryptionConfigManager( 51 @android.annotation.NonNull Context context, 52 @android.annotation.NonNull Flags flags, 53 @android.annotation.NonNull AdServicesHttpsClient adServicesHttpsClient) { 54 return null; 55 } 56 } 57 58 static class MultiCloudTestStrategyFlagOn implements MultiCloudSupportStrategy { 59 60 private ObliviousHttpEncryptor mObliviousHttpEncryptor; 61 private String mAllowList; 62 MultiCloudTestStrategyFlagOn( ObliviousHttpEncryptor obliviousHttpEncryptor, String allowList)63 MultiCloudTestStrategyFlagOn( 64 ObliviousHttpEncryptor obliviousHttpEncryptor, String allowList) { 65 this.mObliviousHttpEncryptor = obliviousHttpEncryptor; 66 this.mAllowList = allowList; 67 } 68 69 @Override getCoordinatorOriginUriValidator()70 public CoordinatorOriginUriValidator getCoordinatorOriginUriValidator() { 71 return CoordinatorOriginUriValidator.createEnabledInstance(mAllowList); 72 } 73 74 @Override getEncryptionConfigManager( @ndroid.annotation.NonNull Context context, @android.annotation.NonNull Flags flags, @android.annotation.NonNull AdServicesHttpsClient adServicesHttpsClient)75 public ProtectedServersEncryptionConfigManagerBase getEncryptionConfigManager( 76 @android.annotation.NonNull Context context, 77 @android.annotation.NonNull Flags flags, 78 @android.annotation.NonNull AdServicesHttpsClient adServicesHttpsClient) { 79 return null; 80 } 81 82 @Override getObliviousHttpEncryptor( @onNull Context context, @NonNull Flags flags)83 public ObliviousHttpEncryptor getObliviousHttpEncryptor( 84 @NonNull Context context, @NonNull Flags flags) { 85 return mObliviousHttpEncryptor; 86 } 87 } 88 89 /** Get a test strategy with multi cloud enabled */ getEnabledTestStrategy( ObliviousHttpEncryptor encryptor, String allowlist)90 public static MultiCloudSupportStrategy getEnabledTestStrategy( 91 ObliviousHttpEncryptor encryptor, String allowlist) { 92 return new MultiCloudTestStrategyFlagOn(encryptor, allowlist); 93 } 94 95 /** Get a test strategy with multi cloud disabled */ getDisabledTestStrategy( ObliviousHttpEncryptor encryptor)96 public static MultiCloudSupportStrategy getDisabledTestStrategy( 97 ObliviousHttpEncryptor encryptor) { 98 return new MultiCloudTestStrategyFlagOff(encryptor); 99 } 100 } 101