Fast lite mode (native code) #864

Merged
akinwale merged 5 commits from fast-lite-mode into master 2020-03-11 15:21:42 +01:00
3 changed files with 17 additions and 42 deletions
Showing only changes of commit 93c87a226b - Show all commits

View file

@ -31,7 +31,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 fast-lite-mode https://github.com/lbryio/lbry-react-native
- cd lbry-react-native
- chmod u+x bundle-android.sh
- yarn

View file

@ -18,6 +18,7 @@ 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.util.ArrayList;
@ -104,6 +105,11 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
// default to home page
url = "lbry://?discover";
}
} else {
if (!MainActivity.isServiceRunning(this, LbrynetService.class)) {
// cold start
url = url + ((url.indexOf("?") > -1) ? "&liteMode=1" : "?liteMode=1");
}
}
Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

View file

@ -153,7 +153,7 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
registerDownloadEventReceiver();
// Start the daemon service if it is not started
serviceRunning = isServiceRunning(LbrynetService.class);
serviceRunning = isServiceRunning(this, LbrynetService.class);
if (!serviceRunning) {
CurrentLaunchTiming.setColdStart(true);
ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice");
@ -383,9 +383,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 +444,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,7 +463,7 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
super.onResume();
SharedPreferences sp = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
serviceRunning = isServiceRunning(LbrynetService.class);
serviceRunning = isServiceRunning(this, LbrynetService.class);
if (!serviceRunning) {
ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice");
}
@ -510,7 +479,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);
}
@ -544,7 +513,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 +604,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;