|
16 | 16 | import com.google.firebase.remoteconfig.ConfigUpdate;
|
17 | 17 | import com.google.firebase.remoteconfig.ConfigUpdateListener;
|
18 | 18 | import com.google.firebase.remoteconfig.ConfigUpdateListenerRegistration;
|
| 19 | +import com.google.firebase.remoteconfig.CustomSignals; |
19 | 20 | import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
|
20 | 21 | import com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException;
|
21 | 22 | import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
|
@@ -137,6 +138,36 @@ private FirebaseRemoteConfig getRemoteConfig(Map<String, Object> arguments) {
|
137 | 138 | return FirebaseRemoteConfig.getInstance(app);
|
138 | 139 | }
|
139 | 140 |
|
| 141 | + private Task<Void> setCustomSignals( |
| 142 | + FirebaseRemoteConfig remoteConfig, Map<String, Object> customSignalsArguments) { |
| 143 | + TaskCompletionSource<Void> taskCompletionSource = new TaskCompletionSource<>(); |
| 144 | + cachedThreadPool.execute( |
| 145 | + () -> { |
| 146 | + try { |
| 147 | + CustomSignals.Builder customSignals = new CustomSignals.Builder(); |
| 148 | + for (Map.Entry<String, Object> entry : customSignalsArguments.entrySet()) { |
| 149 | + Object value = entry.getValue(); |
| 150 | + if (value instanceof String) { |
| 151 | + customSignals.put(entry.getKey(), (String) value); |
| 152 | + } else if (value instanceof Long) { |
| 153 | + customSignals.put(entry.getKey(), (Long) value); |
| 154 | + } else if (value instanceof Integer) { |
| 155 | + customSignals.put(entry.getKey(), ((Integer) value).longValue()); |
| 156 | + } else if (value instanceof Double) { |
| 157 | + customSignals.put(entry.getKey(), (Double) value); |
| 158 | + } else if (value == null) { |
| 159 | + customSignals.put(entry.getKey(), null); |
| 160 | + } |
| 161 | + } |
| 162 | + Tasks.await(remoteConfig.setCustomSignals(customSignals.build())); |
| 163 | + taskCompletionSource.setResult(null); |
| 164 | + } catch (Exception e) { |
| 165 | + taskCompletionSource.setException(e); |
| 166 | + } |
| 167 | + }); |
| 168 | + return taskCompletionSource.getTask(); |
| 169 | + } |
| 170 | + |
140 | 171 | @Override
|
141 | 172 | public void onMethodCall(MethodCall call, @NonNull final MethodChannel.Result result) {
|
142 | 173 | Task<?> methodCallTask;
|
@@ -192,6 +223,13 @@ public void onMethodCall(MethodCall call, @NonNull final MethodChannel.Result re
|
192 | 223 | methodCallTask = Tasks.forResult(configProperties);
|
193 | 224 | break;
|
194 | 225 | }
|
| 226 | + case "RemoteConfig#setCustomSignals": |
| 227 | + { |
| 228 | + Map<String, Object> customSignals = |
| 229 | + Objects.requireNonNull(call.argument("customSignals")); |
| 230 | + methodCallTask = setCustomSignals(remoteConfig, customSignals); |
| 231 | + break; |
| 232 | + } |
195 | 233 | default:
|
196 | 234 | {
|
197 | 235 | result.notImplemented();
|
|
0 commit comments