Skip to content

Commit

Permalink
Fix #953 - Call ES init prior to the initialization of ES Fragments (#…
Browse files Browse the repository at this point in the history
…954)

* Fix #953 - Call ES init prior to the initialization of ES Fragments

This is a workaround to make sure ES SDK is initialized in case we startup to ES Fragments.  The previous workaround that listens for an onStart() event from an application-wide ProcessLifecycleOwner Observer doesn't happen earlier enough in the Fragment lifecycle and results in an NPE.  This patches ensures that when starting HomeActivity, which could start up directly to showing an ES fragment, we call ES init before initializing the fragment being shown to the user.

When ES SDK no longer runs servers in the background Application.setUpSocial() can be made private again and all ES SDK initialization can happen in Application.onCreate()
  • Loading branch information
barbeau authored Dec 19, 2018
1 parent b4ca3c1 commit 1f4a362
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,14 @@
*/
package org.onebusaway.android.app;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.hardware.GeomagneticField;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.tasks.Task;

import com.microsoft.embeddedsocial.sdk.EmbeddedSocial;

import org.onebusaway.android.BuildConfig;
Expand All @@ -54,6 +40,21 @@
import org.onebusaway.android.util.LocationUtils;
import org.onebusaway.android.util.PreferenceUtils;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.hardware.GeomagneticField;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;

import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -599,8 +600,11 @@ private void reportAnalytics() {

/**
* Initializes Embedded Social if the device and current build support social functionality
* This method is only public as a workaround to avoid running ES SDK in the background - see
* #953. When ES SDK no longer runs servers in the background this can be made private again
* and all ES SDK initialization can happen in Application.onCreate().
*/
private synchronized void setUpSocial() {
public synchronized void setUpSocial() {
if (!mEmbeddedSocialInitiated) {
if (EmbeddedSocialUtils.isBuildVersionSupportedBySocial() &&
EmbeddedSocialUtils.isSocialApiKeyDefined()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@
*/
package org.onebusaway.android.ui;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import com.microsoft.embeddedsocial.sdk.EmbeddedSocial;
import com.microsoft.embeddedsocial.ui.fragment.ActivityFeedFragment;
import com.microsoft.embeddedsocial.ui.fragment.MyProfileFragment;
import com.microsoft.embeddedsocial.ui.fragment.PinsFragment;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;

import org.onebusaway.android.BuildConfig;
import org.onebusaway.android.R;
import org.onebusaway.android.app.Application;
import org.onebusaway.android.io.ObaAnalytics;
import org.onebusaway.android.io.elements.ObaRegion;
import org.onebusaway.android.io.elements.ObaRoute;
import org.onebusaway.android.io.elements.ObaStop;
import org.onebusaway.android.io.request.ObaArrivalInfoResponse;
import org.onebusaway.android.map.MapModeController;
import org.onebusaway.android.map.MapParams;
import org.onebusaway.android.map.googlemapsv2.BaseMapFragment;
import org.onebusaway.android.map.googlemapsv2.LayerInfo;
import org.onebusaway.android.region.ObaRegionsTask;
import org.onebusaway.android.report.ui.ReportActivity;
import org.onebusaway.android.tripservice.TripService;
import org.onebusaway.android.util.FragmentUtils;
import org.onebusaway.android.util.LocationUtils;
import org.onebusaway.android.util.PermissionUtils;
import org.onebusaway.android.util.PreferenceUtils;
import org.onebusaway.android.util.RegionUtils;
import org.onebusaway.android.util.ShowcaseViewUtils;
import org.onebusaway.android.util.UIUtils;
import org.opentripplanner.routing.bike_rental.BikeRentalStation;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
Expand Down Expand Up @@ -52,40 +87,6 @@
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.microsoft.embeddedsocial.sdk.EmbeddedSocial;
import com.microsoft.embeddedsocial.ui.fragment.ActivityFeedFragment;
import com.microsoft.embeddedsocial.ui.fragment.MyProfileFragment;
import com.microsoft.embeddedsocial.ui.fragment.PinsFragment;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;

import org.onebusaway.android.BuildConfig;
import org.onebusaway.android.R;
import org.onebusaway.android.app.Application;
import org.onebusaway.android.io.ObaAnalytics;
import org.onebusaway.android.io.elements.ObaRegion;
import org.onebusaway.android.io.elements.ObaRoute;
import org.onebusaway.android.io.elements.ObaStop;
import org.onebusaway.android.io.request.ObaArrivalInfoResponse;
import org.onebusaway.android.map.MapModeController;
import org.onebusaway.android.map.MapParams;
import org.onebusaway.android.map.googlemapsv2.BaseMapFragment;
import org.onebusaway.android.map.googlemapsv2.LayerInfo;
import org.onebusaway.android.region.ObaRegionsTask;
import org.onebusaway.android.report.ui.ReportActivity;
import org.onebusaway.android.tripservice.TripService;
import org.onebusaway.android.util.FragmentUtils;
import org.onebusaway.android.util.LocationUtils;
import org.onebusaway.android.util.PermissionUtils;
import org.onebusaway.android.util.PreferenceUtils;
import org.onebusaway.android.util.RegionUtils;
import org.onebusaway.android.util.ShowcaseViewUtils;
import org.onebusaway.android.util.UIUtils;
import org.opentripplanner.routing.bike_rental.BikeRentalStation;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -351,6 +352,9 @@ public static Intent makeIntent(Context context, String routeId) {
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
// Workaround to make sure ES SDK is initialized in case we startup to ES Fragments (#953)
Application.get().setUpSocial();

setContentView(R.layout.main);

mActivityWeakRef = new WeakReference<>(this);
Expand Down

0 comments on commit 1f4a362

Please sign in to comment.