Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): misc fixes: storage crashes, auth error messages, lint #5335

Merged
merged 4 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions .github/workflows/scripts/start-firebase-emulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,36 @@ if ! [ -x "$(command -v firebase)" ]; then
fi

EMU_START_COMMAND="firebase emulators:start --only auth,database,firestore --project react-native-firebase-testing"
#EMU_START_COMMAND="sleep 120"
MAX_RETRIES=3
MAX_CHECKATTEMPTS=60
CHECKATTEMPTS_WAIT=1

if [ "$1" == "--no-daemon" ]; then
$EMU_START_COMMAND
else
$EMU_START_COMMAND &
until curl --output /dev/null --silent --fail http://localhost:8080; do
echo "Waiting for Firestore emulator to come online..."
sleep 2
done
echo "Firestore emulator is online!"
fi

RETRIES=1
while [ $RETRIES -le $MAX_RETRIES ]; do

if [ "$1" == "--no-daemon" ]; then
echo "Starting Firebase Emulator Suite in foreground."
$EMU_START_COMMAND
else
echo "Starting Firebase Emulator Suite in background."
$EMU_START_COMMAND &
CHECKATTEMPTS=1
while [ $CHECKATTEMPTS -le $MAX_CHECKATTEMPTS ]; do
sleep $CHECKATTEMPTS_WAIT
if curl --output /dev/null --silent --fail http://localhost:8080; then
echo "Firebase Emulator Suite is online!"
exit 0;
fi
echo "Waiting for Firebase Emulator Suite to come online, check $CHECKATTEMPTS of $MAX_CHECKATTEMPTS..."
((CHECKATTEMPTS = CHECKATTEMPTS + 1))
done
fi

echo "Firebase Emulator Suite did not come online in $MAX_CHECKATTEMPTS checks. Try $RETRIES of $MAX_RETRIES."
((RETRIES = RETRIES + 1))

done
echo "Firebase Emulator Suite did not come online after $MAX_RETRIES attempts."
exit 1
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

import android.app.Activity;
import android.content.Context;
import com.facebook.react.bridge.*;
import io.invertase.firebase.interfaces.ContextProvider;
import io.invertase.firebase.common.TaskExecutorService;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;

import com.facebook.react.bridge.*;

import io.invertase.firebase.interfaces.ContextProvider;
import io.invertase.firebase.common.TaskExecutorService;

public class ReactNativeFirebaseModule extends ReactContextBaseJavaModule implements ContextProvider {
private final TaskExecutorService executorService;

Expand Down Expand Up @@ -67,6 +70,7 @@ public static void rejectPromiseWithCodeAndMessage(
}

@Override
@CallSuper
public void initialize() {
super.initialize();
}
Expand All @@ -75,24 +79,25 @@ public ReactContext getContext() {
return getReactApplicationContext();
}

public ExecutorService getExecutor() {
public final ExecutorService getExecutor() {
return executorService.getExecutor();
}

public ExecutorService getTransactionalExecutor() {
public final ExecutorService getTransactionalExecutor() {
return executorService.getTransactionalExecutor();
}

public ExecutorService getTransactionalExecutor(String identifier) {
public final ExecutorService getTransactionalExecutor(String identifier) {
return executorService.getTransactionalExecutor(identifier);
}

@Override
@CallSuper
public void onCatalystInstanceDestroy() {
executorService.shutdown();
}

public void removeEventListeningExecutor(String identifier) {
public final void removeEventListeningExecutor(String identifier) {
String executorName = executorService.getExecutorName(true, identifier);
executorService.removeExecutor(executorName);
}
Expand All @@ -105,12 +110,13 @@ public Activity getActivity() {
return getCurrentActivity();
}

@Nonnull
@NonNull
@Override
public String getName() {
return "RNFB" + moduleName + "Module";
}

@NonNull
@Override
public Map<String, Object> getConstants() {
return new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static WritableMap getExceptionMap(Exception exception) {

public static String timestampToUTC(long timestamp) {
long millisTimestamp = timestamp * 1000;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format.format(millisTimestamp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -1885,7 +1886,7 @@ private WritableMap getJSError(Exception exception) {
}

code = code
.toLowerCase()
.toLowerCase(Locale.ROOT)
.replace("error_", "")
.replace('_', '-');
error.putString("code", code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static void addEmulatorConfig(String appName, String dbURL, String host, int por
String configKey = appName + dbURL;
HashMap<String, Object> emulatorConfig = new HashMap<>();
emulatorConfig.put("host", host);
emulatorConfig.put("port", new Integer(port));
emulatorConfig.put("port", Integer.valueOf(port));
emulatorConfigs.put(configKey, emulatorConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class ReactNativeFirebaseDynamicLinksModule extends ReactNativeFirebaseMo
public void onCatalystInstanceDestroy() {
getReactApplicationContext().removeActivityEventListener(this);
getReactApplicationContext().addLifecycleEventListener(this);
super.onCatalystInstanceDestroy();
}

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void onCatalystInstanceDestroy() {
}

transactionHandlers.clear();
super.onCatalystInstanceDestroy();
}

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.StorageTask;

import java.util.Locale;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -143,7 +144,7 @@ static StorageMetadata buildMetadataFromMap(ReadableMap metadataMap, @Nullable U

if (mimeType == null) {
String fileExt = MimeTypeMap.getFileExtensionFromUrl(file.toString());
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExt.toLowerCase());
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExt.toLowerCase(Locale.ROOT));
}

if (mimeType != null) {
Expand Down
Loading