Compare commits

..
17 Commits
Author SHA1 Message Date
Akinwale Ariwodola cc3055f1c9 bumpversion 0.14.1 --> 0.14.2 2020-03-31 21:32:35 +01:00
Akinwale Ariwodola 25a1eac43b sdk 0.67.1 2020-03-31 21:18:19 +01:00
Akinwale Ariwodola ff30e7f6a4 bumpversion 0.14.0 --> 0.14.1 2020-03-26 19:06:51 +01:00
Akinwale Ariwodola 3fcc01597d sdk 0.65.0 2020-03-26 19:03:47 +01:00
Akinwale Ariwodola cbc4a662e6 bumpversion 0.13.4 --> 0.14.0 2020-03-23 09:45:21 +01:00
Akinwale Ariwodola 5aa0513324 add getNativeBooleanSetting method 2020-03-21 09:18:48 +01:00
Akinwale Ariwodola 4d1f142f9c check sdk ready 2020-03-20 11:15:41 +01:00
Akinwale Ariwodola e9c8f9432f fix service notification not opening the app 2020-03-20 09:27:54 +01:00
Akinwale Ariwodola 56c375f344 lbry.tv hybrid mode (#869)
* lbry.tv experiment build
* add task for checking if the sdk is ready
* fix for special urls
* send onSdkStatusResponse events
* persist dht setting to file system
2020-03-20 08:30:34 +01:00
Akinwale Ariwodola 5b165a2339 remove dht debug logs 2020-03-17 23:10:10 +01:00
Akinwale Ariwodola bfd3c711ab 0.13.4 patch (#868)
* 0.13.4 patch
* update gitlab CI
2020-03-16 18:50:17 +01:00
Akinwale Ariwodola 4627e284fa sdk 0.64.0. check dht setting on startup. 2020-03-13 17:06:05 +01:00
Akinwale Ariwodola ea8ac783a8 bumpversion 0.13.2 --> 0.13.3 2020-03-13 08:32:09 +01:00
Akinwale Ariwodola 966dd2bf2c add log method to utility module 2020-03-13 02:03:39 +01:00
Akinwale Ariwodola 364de592fa use snake case for payload keys 2020-03-12 21:16:39 +01:00
Akinwale Ariwodola d38241f0d1 check for contentTitle and channelUrl in payload 2020-03-11 15:55:35 +01:00
Akinwale Ariwodola e217be6b67 Fast lite mode (native code) (#864)
* fast loading lite mode
* add react methods for lbrynet dir and platform
* send additional url parameters for cold start
* pending intent
* update gitlab CI
2020-03-11 15:21:41 +01:00
11 changed files with 251 additions and 103 deletions

No files matched your search

+6 -3
View File
@@ -3,6 +3,9 @@ stages:
- deploy
- release
variables:
REACT_NATIVE_BRANCH: "master"
build apk:
stage: build
image: lbry/android-base:platform-28
@@ -14,7 +17,7 @@ build apk:
- ln -fs /opt/node-v10.19.0-linux-x64/bin/npx /usr/bin/npx
- chmod u+x $CI_PROJECT_DIR/gradlew
- export ANDROID_SDK_ROOT=~/.buildozer/android/platform/android-sdk-23
- export BUILD_VERSION=$($CI_PROJECT_DIR/gradlew -q printVersionName --console=plain | tail -1)
- export BUILD_VERSION=$($CI_PROJECT_DIR/gradlew -q printVersionName --console=plain | tail -1)
artifacts:
paths:
- bin/browser-*-release__arm.apk
@@ -31,7 +34,7 @@ build apk:
- git secret reveal
- npm install -g react-native-cli
- cd ~/
- git clone https://github.com/lbryio/lbry-react-native
- git clone --single-branch --branch $REACT_NATIVE_BRANCH https://github.com/lbryio/lbry-react-native
- cd lbry-react-native
- chmod u+x bundle-android.sh
- yarn
@@ -44,7 +47,7 @@ build apk:
- cd $CI_PROJECT_DIR
- cp bin/browser-$BUILD_VERSION-release__arm.apk /dev/null
- cp bin/browser-$BUILD_VERSION-release__arm64.apk /dev/null
deploy build.lbry.io:
image: python:stretch
stage: deploy
+4 -4
View File
@@ -143,8 +143,8 @@ android {
applicationId "io.lbry.browser"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1302
versionName "0.13.2"
versionCode 1402
versionName "0.14.2"
missingDimensionStrategy 'react-native-camera', 'general'
multiDexEnabled true
}
@@ -210,8 +210,8 @@ dependencies {
implementation 'com.facebook.fresco:animated-gif:1.10.0'
implementation 'com.google.firebase:firebase-messaging:20.1.0'
__32bitImplementation files('libs/lbrysdk-0.62.0-release__arm.aar')
__64bitImplementation files('libs/lbrysdk-0.62.0-release__arm64.aar')
__32bitImplementation files('libs/lbrysdk-0.67.1-release__arm.aar')
__64bitImplementation files('libs/lbrysdk-0.67.1-release__arm64.aar')
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -12,10 +12,6 @@ import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import io.lbry.browser.receivers.NotificationDeletedReceiver;
import io.lbry.lbrysdk.LbrynetService;
@@ -18,8 +18,11 @@ import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import io.lbry.lbrysdk.LbrynetService;
import io.lbry.browser.reactmodules.UtilityModule;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -54,6 +57,11 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
String title = payload.get("title");
String body = payload.get("body");
String name = payload.get("name"); // notification name
String contentTitle = payload.get("content_title");
String channelUrl = payload.get("channel_url");
//String publishTime = payload.get("publish_time");
String publishTime = null;
if (type != null && getEnabledTypes().indexOf(type) > -1 && body != null && body.trim().length() > 0) {
// only log the receive event for valid notifications received
if (firebaseAnalytics != null) {
@@ -62,7 +70,7 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
firebaseAnalytics.logEvent("lbry_notification_receive", bundle);
}
sendNotification(title, body, type, url, name);
sendNotification(title, body, type, url, name, contentTitle, channelUrl, publishTime);
}
}
}
@@ -94,7 +102,8 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String title, String messageBody, String type, String url, String name) {
private void sendNotification(String title, String messageBody, String type, String url, String name,
String contentTitle, String channelUrl, String publishTime) {
//Intent intent = new Intent(this, MainActivity.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (url == null) {
@@ -104,6 +113,29 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
// default to home page
url = "lbry://?discover";
}
} else {
if (!MainActivity.isServiceRunning(this, LbrynetService.class) &&
contentTitle != null &&
channelUrl != null &&
!url.startsWith("lbry://?") /* not a special url */
) {
// only enter lite mode when contentTitle and channelUrl are set (and the service isn't running yet)
// cold start
url = url + ((url.indexOf("?") > -1) ? "&liteMode=1" : "?liteMode=1");
try {
if (contentTitle != null) {
url = url + "&contentTitle=" + URLEncoder.encode(contentTitle, "UTF-8");
}
if (channelUrl != null) {
url = url + "&channelUrl=" + URLEncoder.encode(channelUrl, "UTF-8");
}
if (publishTime != null) {
url = url + "&publishTime=" + URLEncoder.encode(publishTime, "UTF-8");
}
} catch (UnsupportedEncodingException ex) {
// shouldn't happen
}
}
}
Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
@@ -2,6 +2,10 @@ package io.lbry.browser;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
@@ -17,15 +21,16 @@ import android.content.SharedPreferences;
import android.database.Cursor;
import android.Manifest;
import android.net.Uri;
import android.os.Handler;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.provider.Settings;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.widget.Toast;
import com.azendoo.reactnativesnackbar.SnackbarPackage;
@@ -39,13 +44,10 @@ import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.ReadableNativeArray;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.core.PermissionAwareActivity;
import com.facebook.react.modules.core.PermissionListener;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.react.ReactRootView;
import com.facebook.soloader.SoLoader;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
@@ -56,23 +58,19 @@ import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import com.swmansion.reanimated.ReanimatedPackage;
import com.RNFetchBlob.RNFetchBlobPackage;
import io.lbry.browser.reactmodules.UtilityModule;
import io.lbry.browser.reactpackages.LbryReactPackage;
import io.lbry.browser.reactmodules.BackgroundMediaModule;
import io.lbry.lbrysdk.LbrynetService;
import io.lbry.lbrysdk.ServiceHelper;
import io.lbry.lbrysdk.Utils;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import org.json.JSONObject;
import org.json.JSONArray;
@@ -82,52 +80,35 @@ import org.reactnative.camera.RNCameraPackage;
public class MainActivity extends FragmentActivity implements DefaultHardwareBackBtnHandler, PermissionAwareActivity {
private static Activity currentActivity = null;
private static final int OVERLAY_PERMISSION_REQ_CODE = 101;
private static final int STORAGE_PERMISSION_REQ_CODE = 201;
private static final int PHONE_STATE_PERMISSION_REQ_CODE = 202;
private static final int RECEIVE_SMS_PERMISSION_REQ_CODE = 203;
public static final int DOCUMENT_PICKER_RESULT_CODE = 301;
public static final String SHARED_PREFERENCES_NAME = "LBRY";
public static final String SALT_KEY = "salt";
public static final String DEVICE_ID_KEY = "deviceId";
public static final String SOURCE_NOTIFICATION_ID_KEY = "sourceNotificationId";
public static final String SETTING_KEEP_DAEMON_RUNNING = "keepDaemonRunning";
public static List<Integer> downloadNotificationIds = new ArrayList<Integer>();
private BroadcastReceiver notificationsReceiver;
private BroadcastReceiver smsReceiver;
private BroadcastReceiver stopServiceReceiver;
private BroadcastReceiver serviceActionsReceiver;
private BroadcastReceiver downloadEventReceiver;
private FirebaseAnalytics firebaseAnalytics;
private ReactRootView mReactRootView;
private ReactInstanceManager mReactInstanceManager;
public static final String SHARED_PREFERENCES_NAME = "LBRY";
public static final String SALT_KEY = "salt";
public static final String DEVICE_ID_KEY = "deviceId";
public static final String SOURCE_NOTIFICATION_ID_KEY = "sourceNotificationId";
public static final String SETTING_KEEP_DAEMON_RUNNING = "keepDaemonRunning";
public static List<Integer> downloadNotificationIds = new ArrayList<Integer>();
/**
* Flag which indicates whether or not the service is running. Will be updated in the
* onResume method.
*/
private boolean serviceRunning;
private CheckSdkReadyTask checkSdkReadyTask;
private boolean receivedStopService;
private PermissionListener permissionListener;
public static boolean lbrySdkReady;
protected String getMainComponentName() {
return "LBRYApp";
@@ -144,7 +125,7 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
SoLoader.init(this, false);
// Register the stop service receiver (so that we close the activity if the user requests the service to stop)
registerStopReceiver();
registerServiceActionsReceiver();
// Register SMS receiver for handling verification texts
registerSmsReceiver();
@@ -152,12 +133,16 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
// Register the receiver to emit download events
registerDownloadEventReceiver();
// Start the daemon service if it is not started
serviceRunning = isServiceRunning(LbrynetService.class);
// Start the sdk service if it is not started
// Check the dht setting
SharedPreferences sp = getSharedPreferences(MainActivity.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
LbrynetService.setDHTEnabled(sp.getBoolean(UtilityModule.DHT_ENABLED, false));
serviceRunning = isServiceRunning(this, LbrynetService.class);
if (!serviceRunning) {
CurrentLaunchTiming.setColdStart(true);
ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice");
}
checkSdkReady();
checkNotificationOpenIntent(getIntent());
@@ -189,6 +174,22 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
setContentView(mReactRootView);
}
private void checkSdkReady() {
if (!lbrySdkReady) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (checkSdkReadyTask != null && checkSdkReadyTask.getStatus() != AsyncTask.Status.FINISHED) {
// task already running
return;
}
checkSdkReadyTask = new CheckSdkReadyTask();
checkSdkReadyTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}, 1000);
}
}
private void checkNotificationOpenIntent(Intent intent) {
if (intent != null) {
String notificationName = intent.getStringExtra("notification_name");
@@ -262,17 +263,53 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
registerReceiver(downloadEventReceiver, intentFilter);
}
private void registerStopReceiver() {
private void registerServiceActionsReceiver() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(LbrynetService.LBRY_SDK_SERVICE_STARTED);
intentFilter.addAction(LbrynetService.ACTION_STOP_SERVICE);
stopServiceReceiver = new BroadcastReceiver() {
serviceActionsReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
MainActivity.this.receivedStopService = true;
MainActivity.this.finish();
String action = intent.getAction();
if (LbrynetService.ACTION_STOP_SERVICE.equals(action)) {
MainActivity.this.receivedStopService = true;
MainActivity.this.finish();
} else if (LbrynetService.LBRY_SDK_SERVICE_STARTED.equals(action)) {
// Rebuild the service notification
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Notification svcNotification = buildServiceNotification();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, svcNotification);
}
}, 1000);
}
}
};
registerReceiver(stopServiceReceiver, intentFilter);
registerReceiver(serviceActionsReceiver, intentFilter);
}
private Notification buildServiceNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, LbrynetService.NOTIFICATION_CHANNEL_ID);
Intent contextIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, contextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent stopIntent = new Intent(LbrynetService.ACTION_STOP_SERVICE);
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0);
String serviceDescription = "The LBRY service is running in the background.";
Notification notification = builder.setColor(ContextCompat.getColor(this, R.color.lbryGreen))
.setContentIntent(pendingIntent)
.setContentText(serviceDescription)
.setGroup(LbrynetService.GROUP_SERVICE)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_lbry)
.setOngoing(true)
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Stop", stopPendingIntent)
.build();
return notification;
}
private void registerNotificationsReceiver() {
@@ -383,9 +420,9 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
switch (requestCode) {
case STORAGE_PERMISSION_REQ_CODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (BuildConfig.DEBUG && !Settings.canDrawOverlays(this)) {
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
}
if (reactContext != null) {
@@ -444,37 +481,6 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
}
}
public static String acquireDeviceId(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String id = null;
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
id = telephonyManager.getImei(); // GSM
if (id == null) {
id = telephonyManager.getMeid(); // CDMA
}
} else {
id = telephonyManager.getDeviceId();
}
} catch (SecurityException ex) {
// Maybe the permission was not granted? Try to acquire permission
checkPhoneStatePermission(context);
} catch (Exception ex) {
// id could not be obtained. Display a warning that rewards cannot be claimed.
}
if (id == null || id.trim().length() == 0) {
Toast.makeText(context, "Rewards cannot be claimed because we could not identify your device.", Toast.LENGTH_LONG).show();
}
SharedPreferences sp = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString(DEVICE_ID_KEY, id);
editor.commit();
return id;
}
@Override
public void invokeDefaultOnBackPressed() {
super.onBackPressed();
@@ -494,10 +500,13 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
super.onResume();
SharedPreferences sp = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
serviceRunning = isServiceRunning(LbrynetService.class);
LbrynetService.setDHTEnabled(sp.getBoolean(UtilityModule.DHT_ENABLED, false));
serviceRunning = isServiceRunning(this, LbrynetService.class);
if (!serviceRunning) {
ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice");
}
checkSdkReady();
if (mReactInstanceManager != null) {
mReactInstanceManager.onHostResume(this, this);
@@ -510,7 +519,7 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
SharedPreferences sp = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
boolean shouldKeepDaemonRunning = sp.getBoolean(SETTING_KEEP_DAEMON_RUNNING, true);
if (!shouldKeepDaemonRunning) {
serviceRunning = isServiceRunning(LbrynetService.class);
serviceRunning = isServiceRunning(this, LbrynetService.class);
if (serviceRunning) {
ServiceHelper.stop(this, LbrynetService.class);
}
@@ -531,9 +540,9 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
downloadEventReceiver = null;
}
if (stopServiceReceiver != null) {
unregisterReceiver(stopServiceReceiver);
stopServiceReceiver = null;
if (serviceActionsReceiver != null) {
unregisterReceiver(serviceActionsReceiver);
serviceActionsReceiver = null;
}
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
@@ -544,7 +553,7 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
notificationManager.cancel(downloadNotificationIds.get(i));
}
}
if (receivedStopService || !isServiceRunning(LbrynetService.class)) {
if (receivedStopService || !isServiceRunning(this, LbrynetService.class)) {
notificationManager.cancelAll();
}
super.onDestroy();
@@ -635,8 +644,8 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
true);
}
private boolean isServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
public static boolean isServiceRunning(Context context, Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(serviceInfo.service.getClassName())) {
return true;
@@ -701,7 +710,6 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
*/
@SuppressLint("NewApi")
public static String getRealPathFromURI_API19(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
@@ -852,6 +860,51 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
public static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}
private class CheckSdkReadyTask extends AsyncTask<Void, Void, Boolean> {
public Boolean doInBackground(Void... params) {
boolean sdkReady = false;
try {
String response = Utils.sdkCall("status");
if (response != null) {
JSONObject result = new JSONObject(response);
JSONObject status = result.getJSONObject("result");
// send status response for splash page updates
WritableMap sdkStatus = JSONObjectToMap(status);
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
if (reactContext != null) {
WritableMap evtParams = Arguments.createMap();
evtParams.putMap("status", sdkStatus);
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("onSdkStatusResponse", evtParams);
}
JSONObject startupStatus = status.getJSONObject("startup_status");
sdkReady = startupStatus.has("stream_manager") && startupStatus.has("wallet") &&
startupStatus.getBoolean("stream_manager") && startupStatus.getBoolean("wallet") &&
(status.getJSONObject("wallet").getLong("blocks_behind") <= 0);
}
} catch (ConnectException ex) {
// pass
} catch (JSONException ex) {
// pass
}
return sdkReady;
}
protected void onPostExecute(Boolean sdkReady) {
lbrySdkReady = sdkReady;
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
if (sdkReady && reactContext != null) {
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("onSdkReady", null);
}
if (!sdkReady) {
checkSdkReady();
}
}
}
public static class LaunchTiming {
private Date start;
@@ -77,8 +77,8 @@ public class FirebaseModule extends ReactContextBaseJavaModule {
@ReactMethod
public void logException(boolean fatal, String message, String error) {
Bundle bundle = new Bundle();
bundle.putString("message", message);
bundle.putString("error", error);
bundle.putString("exception_message", message);
bundle.putString("exception_error", error);
if (firebaseAnalytics != null) {
firebaseAnalytics.logEvent(fatal ? "reactjs_exception" : "reactjs_warning", bundle);
}
@@ -23,10 +23,12 @@ import android.view.WindowManager;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.squareup.picasso.Picasso;
import java.io.File;
@@ -34,6 +36,7 @@ import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
@@ -56,6 +59,7 @@ public class UtilityModule extends ReactContextBaseJavaModule {
public static final String ACTION_NOTIFICATION_LATER = "io.lbry.browser.ACTION_NOTIFICATION_LATER";
// Setting keys from React Native
public static final String RECEIVE_SUBSCRIPTION_NOTIFICATIONS = "receiveSubscriptionNotifications";
public static final String RECEIVE_REWARD_NOTIFICATIONS = "receiveRewardNotifications";
@@ -64,6 +68,8 @@ public class UtilityModule extends ReactContextBaseJavaModule {
public static final String RECEIVE_CREATOR_NOTIFICATIONS = "receiveCreatorNotifications";
public static final String DHT_ENABLED = "dhtEnabled";
// the last language set to be loaded
private static final String LANGUAGE_SETTING_KEY = "language";
@@ -90,6 +96,7 @@ public class UtilityModule extends ReactContextBaseJavaModule {
public Map<String, Object> getConstants() {
final Map<String, Object> constants = MapBuilder.newHashMap();
constants.put("language", language);
constants.put("dhtEnabled", LbrynetService.isDHTEnabled());
return constants;
}
@@ -419,13 +426,44 @@ public class UtilityModule extends ReactContextBaseJavaModule {
}
@ReactMethod
public void setNativeBooleanSetting(String key, boolean value) {
public void setNativeBooleanSetting(String key, final boolean value) {
if (context != null) {
SharedPreferences sp = context.getSharedPreferences(MainActivity.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean(key, value);
editor.commit();
}
if (DHT_ENABLED.equalsIgnoreCase(key)) {
(new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
String fileContent = value ? "on" : "off";
String path = String.format("%s/%s", Utils.getAppInternalStorageDir(context), "dht");
PrintStream out = null;
try {
out = new PrintStream(new FileOutputStream(path));
out.print(fileContent);
} catch (Exception ex) {
// pass
} finally {
if (out != null) {
out.close();
}
}
return null;
}
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@ReactMethod
public void getNativeBooleanSetting(String key, boolean defaultValue, Promise promise) {
if (context != null) {
SharedPreferences sp = context.getSharedPreferences(MainActivity.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
promise.resolve(sp.getBoolean(key, defaultValue));
} else {
promise.resolve(null);
}
}
@ReactMethod
@@ -470,4 +508,30 @@ public class UtilityModule extends ReactContextBaseJavaModule {
// This obtains a public default download directory after the storage permission has been granted
promise.resolve(Utils.getConfiguredDownloadDirectory(context));
}
@ReactMethod
public void getLbrynetDirectory(Promise promise) {
String path = String.format("%s/%s", Utils.getAppInternalStorageDir(context), "lbrynet");
promise.resolve(path);
}
@ReactMethod
public void getPlatform(Promise promise) {
String platform = String.format("Android %s (API %s)", Utils.getAndroidRelease(), Utils.getAndroidSdk());
promise.resolve(platform);
}
@ReactMethod
public void checkSdkReady() {
// check that the sdk ready when the service is already running so that we can send the ready event
ReactContext reactContext = (ReactContext) context;
if (MainActivity.lbrySdkReady && reactContext != null) {
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("onSdkReady", null);
}
}
@ReactMethod
public void log(String tag, String message) {
android.util.Log.d(tag, message);
}
}