Skip to content

Commit

Permalink
get rid of status service alltogether
Browse files Browse the repository at this point in the history
  • Loading branch information
mandrigin committed Jan 25, 2019
1 parent 6e4d3c9 commit b471217
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 396 deletions.
4 changes: 0 additions & 4 deletions android/app/src/main/AndroidManifest.xml
Expand Up @@ -75,10 +75,6 @@
<data android:scheme="status-im" />
</intent-filter>
</activity>
<service
android:name=".module.StatusService"
android:enabled="true"
android:exported="true"/>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -50,7 +50,7 @@

import javax.annotation.Nullable;

class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ConnectorHandler, LifecycleObserver {
class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventListener, StatusNodeEventHandler {

private static final String TAG = "StatusModule";
private static final String logsZipFileName = "Status-debug-logs.zip";
Expand All @@ -60,7 +60,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
private final static int TESTNET_NETWORK_ID = 3;

private static StatusModule module;
private ServiceConnector status = null;
private ExecutorService executor = null;
private boolean debug;
private boolean devCluster;
Expand All @@ -87,45 +86,12 @@ public String getName() {
@Override
public void onHostResume() { // Activity `onResume`
module = this;
Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
Log.d(TAG, "On host Activity doesn't exist");
return;
}

if (status == null) {
status = new ServiceConnector(currentActivity, StatusService.class);
status.registerHandler(this);
}

safeStartAndBindService();
}

private void safeStartAndBindService() {
// If we bind StatusService too early on Android 9+, it will crash the app.
// This is a workaround, to listen to the app lifecycle,
// and to start the service only when the app is in foreground already.
Log.d(TAG, "[onHostResume] android 9+ delaying service binding.");
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
}

@OnLifecycleEvent(Lifecycle.Event.ON_START)
void onEnterForeground() {
Log.d(TAG, "[onEnterForeground] the app is foreground now, binding service");
doStartService();
ProcessLifecycleOwner.get().getLifecycle().removeObserver(this);
}

private void doStartService() {
status.bindService();
signalEvent("{\"type\":\"module.initialized\"}");
StatusService.INSTANCE.setSignalEventListener(this);
}

@Override
public void onHostPause() {
if (status != null) {
status.unbindService();
}

}

@Override
Expand All @@ -134,19 +100,18 @@ public void onHostDestroy() {
}

private boolean checkAvailability() {

Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
Log.d(TAG, "Activity doesn't exist");
return false;
if (getCurrentActivity() != null) {
return true;
}

return true;
}
Log.d(TAG, "Activity doesn't exist");
return false;

}

void signalEvent(String jsonEvent) {
Log.d(TAG, "Signal event: " + jsonEvent);
@Override
public void handleEvent(String jsonEvent) {
Log.d(TAG, "[handleEvent] event: " + jsonEvent);
WritableMap params = Arguments.createMap();
params.putString("jsonEvent", jsonEvent);
this.getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("gethEvent", params);
Expand Down Expand Up @@ -297,7 +262,6 @@ private void doStartNode(final String jsonConfigString) {
else {
Log.e(TAG, "StartNode failed: " + res);
}
status.sendMessage();
} catch (JSONException e) {
Log.e(TAG, "updateConfig failed: " + e.getMessage());
System.exit(1);
Expand Down Expand Up @@ -388,6 +352,7 @@ public void moveToInternalStorage(Callback callback) {
public void startNode(final String config) {
Log.d(TAG, "startNode");
if (!checkAvailability()) {
Log.e(TAG, "[startNode] Activity doesn't exists, cannot start node");
return;
}

Expand Down Expand Up @@ -817,28 +782,6 @@ public void clearStorageAPIs() {
}
}

@Override
public boolean handleMessage(Message message) {

Log.d(TAG, "Received message: " + message.toString());
Bundle bundle = message.getData();

String event = bundle.getString("event");
signalEvent(event);

return true;
}

@Override
public void onConnectorConnected() {

}

@Override
public void onConnectorDisconnected() {

}

@ReactMethod
public void callRPC(final String payload, final Callback callback) {
Runnable r = new Runnable() {
Expand Down
@@ -0,0 +1,5 @@
package im.status.ethereum.module;

public interface StatusNodeEventHandler {
void handleEvent(String eventJson);
}

0 comments on commit b471217

Please sign in to comment.