|
42 | 42 | public class CodePushNativeModule extends ReactContextBaseJavaModule { |
43 | 43 | private String mBinaryContentsHash = null; |
44 | 44 | private String mClientUniqueId = null; |
| 45 | + private boolean mTelemetryEnabled = true; |
45 | 46 | private LifecycleEventListener mLifecycleEventListener = null; |
46 | 47 | private int mMinimumBackgroundDuration = 0; |
47 | 48 |
|
@@ -71,6 +72,17 @@ public CodePushNativeModule(ReactApplicationContext reactContext, CodePush codeP |
71 | 72 | mClientUniqueId = UUID.randomUUID().toString(); |
72 | 73 | preferences.edit().putString(CodePushConstants.CLIENT_UNIQUE_ID_KEY, mClientUniqueId).apply(); |
73 | 74 | } |
| 75 | + |
| 76 | + if (preferences.contains(CodePushConstants.TELEMETRY_ENABLED_KEY)) { |
| 77 | + mTelemetryEnabled = preferences.getBoolean(CodePushConstants.TELEMETRY_ENABLED_KEY, true); |
| 78 | + } else { |
| 79 | + int defaultTelemetryEnabledResId = reactContext.getResources().getIdentifier("CodePushDefaultTelemetryEnabled", "bool", reactContext.getPackageName()); |
| 80 | + if (defaultTelemetryEnabledResId != 0) { |
| 81 | + mTelemetryEnabled = reactContext.getResources().getBoolean(defaultTelemetryEnabledResId); |
| 82 | + } else { |
| 83 | + mTelemetryEnabled = true; |
| 84 | + } |
| 85 | + } |
74 | 86 | } |
75 | 87 |
|
76 | 88 | @Override |
@@ -396,6 +408,7 @@ public void getConfiguration(Promise promise) { |
396 | 408 | configMap.putString("clientUniqueId", mClientUniqueId); |
397 | 409 | configMap.putString("releaseChannelPublicId", mCodePush.getReleaseChannelPublicId()); |
398 | 410 | configMap.putString("serverUrl", mCodePush.getServerUrl()); |
| 411 | + configMap.putBoolean("telemetryEnabled", mTelemetryEnabled); |
399 | 412 |
|
400 | 413 | // The binary hash may be null in debug builds |
401 | 414 | if (mBinaryContentsHash != null) { |
@@ -745,6 +758,24 @@ public void resetClientUniqueId(Promise promise) { |
745 | 758 | } |
746 | 759 | } |
747 | 760 |
|
| 761 | + @ReactMethod |
| 762 | + public void setTelemetryEnabled(boolean enabled, Promise promise) { |
| 763 | + try { |
| 764 | + SharedPreferences preferences = mCodePush.getContext().getSharedPreferences(CodePushConstants.CODE_PUSH_PREFERENCES, 0); |
| 765 | + preferences.edit().putBoolean(CodePushConstants.TELEMETRY_ENABLED_KEY, enabled).apply(); |
| 766 | + mTelemetryEnabled = enabled; |
| 767 | + promise.resolve(null); |
| 768 | + } catch (Exception e) { |
| 769 | + CodePushUtils.log(e); |
| 770 | + promise.reject(e); |
| 771 | + } |
| 772 | + } |
| 773 | + |
| 774 | + @ReactMethod |
| 775 | + public void getTelemetryEnabled(Promise promise) { |
| 776 | + promise.resolve(mTelemetryEnabled); |
| 777 | + } |
| 778 | + |
748 | 779 | @ReactMethod |
749 | 780 | public void addListener(String eventName) { |
750 | 781 | // Set up any upstream listeners or background tasks as necessary |
|
0 commit comments