|
49 | 49 | public class CodePushNativeModule extends BaseJavaModule { |
50 | 50 | private String mBinaryContentsHash = null; |
51 | 51 | private String mClientUniqueId = null; |
| 52 | + private boolean mTelemetryEnabled = true; |
52 | 53 | private LifecycleEventListener mLifecycleEventListener = null; |
53 | 54 | private int mMinimumBackgroundDuration = 0; |
54 | 55 |
|
@@ -78,6 +79,17 @@ public CodePushNativeModule(ReactApplicationContext reactContext, CodePush codeP |
78 | 79 | mClientUniqueId = UUID.randomUUID().toString(); |
79 | 80 | preferences.edit().putString(CodePushConstants.CLIENT_UNIQUE_ID_KEY, mClientUniqueId).apply(); |
80 | 81 | } |
| 82 | + |
| 83 | + if (preferences.contains(CodePushConstants.TELEMETRY_ENABLED_KEY)) { |
| 84 | + mTelemetryEnabled = preferences.getBoolean(CodePushConstants.TELEMETRY_ENABLED_KEY, true); |
| 85 | + } else { |
| 86 | + int defaultTelemetryEnabledResId = reactContext.getResources().getIdentifier("CodePushDefaultTelemetryEnabled", "bool", reactContext.getPackageName()); |
| 87 | + if (defaultTelemetryEnabledResId != 0) { |
| 88 | + mTelemetryEnabled = reactContext.getResources().getBoolean(defaultTelemetryEnabledResId); |
| 89 | + } else { |
| 90 | + mTelemetryEnabled = true; |
| 91 | + } |
| 92 | + } |
81 | 93 | } |
82 | 94 |
|
83 | 95 | @Override |
@@ -485,6 +497,7 @@ public void getConfiguration(Promise promise) { |
485 | 497 | configMap.putString("clientUniqueId", mClientUniqueId); |
486 | 498 | configMap.putString("releaseChannelPublicId", mCodePush.getReleaseChannelPublicId()); |
487 | 499 | configMap.putString("serverUrl", mCodePush.getServerUrl()); |
| 500 | + configMap.putBoolean("telemetryEnabled", mTelemetryEnabled); |
488 | 501 |
|
489 | 502 | // The binary hash may be null in debug builds |
490 | 503 | if (mBinaryContentsHash != null) { |
@@ -834,6 +847,24 @@ public void resetClientUniqueId(Promise promise) { |
834 | 847 | } |
835 | 848 | } |
836 | 849 |
|
| 850 | + @ReactMethod |
| 851 | + public void setTelemetryEnabled(boolean enabled, Promise promise) { |
| 852 | + try { |
| 853 | + SharedPreferences preferences = mCodePush.getContext().getSharedPreferences(CodePushConstants.CODE_PUSH_PREFERENCES, 0); |
| 854 | + preferences.edit().putBoolean(CodePushConstants.TELEMETRY_ENABLED_KEY, enabled).apply(); |
| 855 | + mTelemetryEnabled = enabled; |
| 856 | + promise.resolve(null); |
| 857 | + } catch (Exception e) { |
| 858 | + CodePushUtils.log(e); |
| 859 | + promise.reject(e); |
| 860 | + } |
| 861 | + } |
| 862 | + |
| 863 | + @ReactMethod |
| 864 | + public void getTelemetryEnabled(Promise promise) { |
| 865 | + promise.resolve(mTelemetryEnabled); |
| 866 | + } |
| 867 | + |
837 | 868 | @ReactMethod |
838 | 869 | public void addListener(String eventName) { |
839 | 870 | // Set up any upstream listeners or background tasks as necessary |
|
0 commit comments