001package com.intentsoftware.addapptr; 002 003import android.app.Application; 004import android.util.Log; 005 006import com.intentsoftware.addapptr.module.Logger; 007 008import androidx.annotation.NonNull; 009 010/** 011 * Used to set up AATKit. 012 */ 013@SuppressWarnings({"WeakerAccess"}) 014public class AATKitConfiguration extends AATKitRuntimeConfiguration { 015 private String initialRules; 016 private boolean shouldCacheRules = true; 017 private boolean shouldSkipRules; 018 private String alternativeBundleId; 019 private boolean shouldReportUsingAlternativeBundleId = true; 020 private int testModeAccountId; 021 private AATKit.Delegate delegate; 022 private boolean useDebugShake = true; 023 private Application application; 024 025 /** 026 * Creates the default Configuration object to be used when initializing AATKit. 027 * 028 * @param application Reference to {@link Application}. 029 */ 030 public AATKitConfiguration(Application application) { 031 if (application == null) { 032 if (Logger.isLoggable(Log.ERROR)) { 033 Logger.e(AATKit.class, "Application cannot be null!"); 034 } 035 return; 036 } 037 038 this.application = application; 039 } 040 041 @NonNull 042 @Override 043 public String toString() { 044 return "AATKitConfiguration{" + 045 "initialRules='" + initialRules + '\'' + 046 ", shouldCacheRules=" + shouldCacheRules + 047 ", alternativeBundleId='" + alternativeBundleId + '\'' + 048 ", shouldReportUsingAlternativeBundleId=" + shouldReportUsingAlternativeBundleId + 049 ", testModeAccountId=" + testModeAccountId + 050 ", delegate=" + delegate + 051 ", useDebugShake=" + useDebugShake + 052 ", application=" + application + 053 "} " + super.toString(); 054 } 055 056 String getInitialRules() { 057 return initialRules; 058 } 059 060 /** 061 * Allows setting of ad rules that will be used before real rules from the server are downloaded. 062 * 063 * @param initialRules String containing the rules to be used. 064 */ 065 public void setInitialRules(String initialRules) { 066 this.initialRules = initialRules; 067 } 068 069 boolean isShouldCacheRules() { 070 return shouldCacheRules; 071 } 072 073 /** 074 * Allows the AATKit to preserve last downloaded ad rules when the application is closed. 075 * Such rules will be re-used next time the application is started, before new ones get downloaded. 076 * Enabled by default. 077 * 078 * @param shouldCacheRules True to enable, false to disable. 079 */ 080 public void setShouldCacheRules(boolean shouldCacheRules) { 081 this.shouldCacheRules = shouldCacheRules; 082 } 083 084 String getAlternativeBundleId() { 085 return alternativeBundleId; 086 } 087 088 /** 089 * Sets the fake bundle ID for testing purposes. It should only be used during development. 090 * Cannot be used together with classic test mode ({@link #setTestModeAccountId(int)}). 091 * 092 * @param alternativeBundleId Bundle ID to be used during testing. 093 */ 094 public void setAlternativeBundleId(String alternativeBundleId) { 095 if (this.alternativeBundleId != null) { 096 if (Logger.isLoggable(Log.WARN)) { 097 Logger.w(this, "Alternative bundle ID was already set! It will be overriden."); 098 } 099 } 100 if (testModeAccountId != 0) { 101 if (Logger.isLoggable(Log.WARN)) { 102 Logger.w(this, "Test mode was already enabled! It will be overriden by this bundle ID."); 103 } 104 } 105 106 this.alternativeBundleId = alternativeBundleId; 107 } 108 109 boolean isShouldReportUsingAlternativeBundleId() { 110 return shouldReportUsingAlternativeBundleId; 111 } 112 113 /** 114 * If used together with {@link #setAlternativeBundleId(String)} allows to set if the same fake bundle ID should be used in reporting. 115 * True by default. If set to false, real bundle ID will be used in reporting even if fake one is used for testing. 116 * 117 * @param shouldReportUsingAlternativeBundleId If the fake bundleId should be used in reporting. 118 */ 119 public void setShouldReportUsingAlternativeBundleId(boolean shouldReportUsingAlternativeBundleId) { 120 this.shouldReportUsingAlternativeBundleId = shouldReportUsingAlternativeBundleId; 121 } 122 123 int getTestModeAccountId() { 124 return testModeAccountId; 125 } 126 127 /** 128 * Enables AATKit test ads that should be for testing - only during development. 129 * Cannot be used with alternative bundle ID ({@link #setAlternativeBundleId(String)}). 130 * 131 * @param testModeAccountId Test application id obtained from addapptr.com account. 132 */ 133 public void setTestModeAccountId(int testModeAccountId) { 134 if (this.alternativeBundleId != null) { 135 if (Logger.isLoggable(Log.WARN)) { 136 Logger.w(this, "Alternative bundle ID was already set! The test mode account ID will be ignored."); 137 } 138 } 139 if (this.testModeAccountId != 0) { 140 if (Logger.isLoggable(Log.WARN)) { 141 Logger.w(this, "Test mode was already enabled! Old value for test account ID will be overriden."); 142 } 143 } 144 145 this.testModeAccountId = testModeAccountId; 146 } 147 148 AATKit.Delegate getDelegate() { 149 return delegate; 150 } 151 152 /** 153 * Sets the delegate notifying about AATKit events. 154 * 155 * @param delegate Delegate allowing to listen for AATKit events. 156 */ 157 public void setDelegate(AATKit.Delegate delegate) { 158 this.delegate = delegate; 159 } 160 161 boolean isUseDebugShake() { 162 return useDebugShake; 163 } 164 165 /** 166 * Sets if the debug screen should be displayed after shaking the device. Enabled by default. 167 * 168 * @param useDebugShake True to enable, false to disable. 169 */ 170 public void setUseDebugShake(boolean useDebugShake) { 171 this.useDebugShake = useDebugShake; 172 } 173 174 /** 175 * Sets if networks without TCF2 consent should be skipped (only works if TCF2 compliant CMP is used). False by default. 176 * 177 * @param shouldSkipRules True to enable rule skipping, false to disable. 178 */ 179 public void setShouldSkipRules(boolean shouldSkipRules) { 180 this.shouldSkipRules = shouldSkipRules; 181 } 182 183 Application getApplication() { 184 return application; 185 } 186 187 boolean isShouldSkipRules() { 188 return shouldSkipRules; 189 } 190}