Skip to content

Commit

Permalink
fix(android): avoid send event when has no listener (#548)
Browse files Browse the repository at this point in the history
* fix(android): avoid send event when has no listener

This commit just make sure that module will not  read MAC info before add listener for it.
Everytime createConnectivityEventMap method called when send event, it will get wifiinfo.
It's illegal in China when app read MAC info before user agree the privacy agreement.

* fix(android): reset hasListener onCatalystInstanceDestroy
  • Loading branch information
HatCloud committed Dec 13, 2021
1 parent e32057e commit cad47d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -34,6 +34,7 @@ public abstract class ConnectivityReceiver {
private final WifiManager mWifiManager;
private final TelephonyManager mTelephonyManager;
private final ReactApplicationContext mReactContext;
public boolean hasListener = false;

@Nonnull
private ConnectionType mConnectionType = ConnectionType.UNKNOWN;
Expand Down Expand Up @@ -96,7 +97,9 @@ void updateConnectivity(
mConnectionType = connectionType;
mCellularGeneration = cellularGeneration;
mIsInternetReachable = isInternetReachable;
sendConnectivityChangedEvent();
if (hasListener) {
sendConnectivityChangedEvent();
}
}
}

Expand Down
Expand Up @@ -43,6 +43,7 @@ public void initialize() {
public void onCatalystInstanceDestroy() {
mAmazonConnectivityChecker.unregister();
mConnectivityReceiver.unregister();
mConnectivityReceiver.hasListener = false;
}

@Override
Expand All @@ -63,10 +64,14 @@ public void onAmazonFireDeviceConnectivityChanged(boolean isConnected) {
@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
mConnectivityReceiver.hasListener = true;
}

@ReactMethod
public void removeListeners(Integer count) {
// Keep: Required for RN built in Event Emitter Calls.
if (count == 0) {
mConnectivityReceiver.hasListener = false;
}
}
}

0 comments on commit cad47d8

Please sign in to comment.