debug logging draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 08 Apr 2017 19:16:31 +0200
changeset 568917 ef23bdfd3719f44f080df1bea14ff8d34c3ca26e
parent 568916 d29fae387705a1a18986728a0080b4a4216ac914
child 568918 2416d92b0470b6aa6edee2cb224eff9f110061a7
push id56020
push usermozilla@buttercookie.de
push dateWed, 26 Apr 2017 18:35:14 +0000
milestone55.0a1
debug logging MozReview-Commit-ID: FoUd4cklLKs
mobile/android/base/java/org/mozilla/gecko/GeckoActivityMonitor.java
mobile/android/base/java/org/mozilla/gecko/Tabs.java
mobile/android/base/java/org/mozilla/gecko/webapps/WebAppIndexer.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoActivityMonitor.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoActivityMonitor.java
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.app.Application;
 import android.os.Bundle;
+import android.util.Log;
 
 public class GeckoActivityMonitor implements Application.ActivityLifecycleCallbacks {
     private static final String LOGTAG = "GeckoActivityMonitor";
 
     // We only hold a reference to the currently running activity - when this activity pauses,
     // the reference is released or else overwritten by the next activity.
     @SuppressLint("StaticFieldLeak")
     private static final GeckoActivityMonitor instance = new GeckoActivityMonitor();
@@ -27,60 +28,69 @@ public class GeckoActivityMonitor implem
     private GeckoActivityMonitor() { }
 
     public Activity getCurrentActivity() {
         return currentActivity;
     }
 
     @Override
     public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
+        Log.d(LOGTAG, "onActivityCreated: " + activity.getClass().getName());
         currentActivity = activity;
     }
 
     // onNewIntent happens in-between a pause/resume cycle, which means that we wouldn't have
     // a current activity to report if we were using only the official ActivityLifecycleCallbacks.
     // For code that wants to know the current activity even at this point we therefore have to
     // handle this ourselves.
     public void onActivityNewIntent(Activity activity) {
+        Log.d(LOGTAG, "onActivityNewIntent: " + activity.getClass().getName());
         currentActivity = activity;
     }
 
     @Override
     public void onActivityStarted(Activity activity) {
+        Log.d(LOGTAG, "onActivityStarted: " + activity.getClass().getName());
         currentActivity = activity;
     }
 
     @Override
     public void onActivityResumed(Activity activity) {
+        Log.d(LOGTAG, "onActivityResumed: " + activity.getClass().getName());
         currentActivity = activity;
     }
 
     /**
      * Intended to be used if the current activity is required to be up-to-date for code that
      * executes in onCreate/onStart/... before calling the corresponding superclass method.
      */
     public void setCurrentActivity(Activity activity) {
+        Log.d(LOGTAG, "setCurrentActivity: " + activity.getClass().getName());
         currentActivity = activity;
     }
 
     @Override
     public void onActivityPaused(Activity activity) {
+        Log.d(LOGTAG, "onActivityPaused: " + activity.getClass().getName() +
+                ", finishing: " + activity.isFinishing());
         releaseIfCurrentActivity(activity);
     }
 
     @Override
     public void onActivityStopped(Activity activity) {
+        Log.d(LOGTAG, "onActivityStopped: " + activity.getClass().getName());
         releaseIfCurrentActivity(activity);
     }
 
     @Override
     public void onActivitySaveInstanceState(Activity activity, Bundle outState) { }
 
     @Override
     public void onActivityDestroyed(Activity activity) {
+        Log.d(LOGTAG, "onActivityDestroyed: " + activity.getClass().getName());
         releaseIfCurrentActivity(activity);
     }
 
     private void releaseIfCurrentActivity(Activity activity) {
         // If the next activity has already started by the time the previous activity is being
         // stopped/destroyed, we no longer need to clear the previous activity.
         if (currentActivity == activity) {
             currentActivity = null;
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -324,16 +324,27 @@ public class Tabs implements BundleEvent
         final Tab tab = mTabs.get(id);
 
         // This avoids a NPE below, but callers need to be careful to
         // handle this case.
         if (tab == null || oldTab == tab) {
             return tab;
         }
 
+        String oldTabType = oldTab != null ? oldTab.getType().name() : "<no tab>";
+        String oldTabId = Integer.toString(oldTab != null ? oldTab.getId() : -1);
+        String newTabType = tab.getType().name();
+        String newTabId = Integer.toString(tab.getId());
+        Activity currentActivity = GeckoActivityMonitor.getInstance().getCurrentActivity();
+        String currentActivityName = currentActivity != null ? currentActivity.getClass().getName() : "none";
+
+        Log.d(LOGTAG, "selectTab(), oldTab " + oldTabId + ", type = " + oldTabType
+                + ", tab " + newTabId + ", type = " + newTabType
+                + ", current activity = " + currentActivityName);
+
         if (switchActivities && oldTab != null && oldTab.getType() != tab.getType() &&
                 !currentActivityMatchesTab(tab)) {
             // We're in the wrong activity for this kind of tab, so launch the correct one
             // and then try again.
             launchActivityForTab(tab);
             return tab;
         }
 
@@ -364,16 +375,17 @@ public class Tabs implements BundleEvent
         if (currentActivity == null) {
             return false;
         }
         String currentActivityName = currentActivity.getClass().getName();
         return currentActivityName.equals(getClassNameForTab(tab));
     }
 
     private void launchActivityForTab(Tab tab) {
+        Log.d(LOGTAG, "selectTab(), handing off to target activity");
         final Intent intent;
         switch (tab.getType()) {
             case CUSTOMTAB:
                 if (tab.getCustomTabIntent() != null) {
                     intent = tab.getCustomTabIntent().getUnsafe();
                 } else {
                     intent = new Intent(Intent.ACTION_VIEW);
                     intent.setData(Uri.parse(tab.getURL()));
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppIndexer.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppIndexer.java
@@ -5,16 +5,17 @@
 
 package org.mozilla.gecko.webapps;
 
 import java.util.ArrayList;
 
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.support.annotation.UiThread;
+import android.util.Log;
 
 import org.mozilla.gecko.GeckoSharedPrefs;
 
 /**
  * WebAppIndexer lets us create bookmarks that behave like android applications
  * we create 10 slots of WebAppN in the manifest, when a bookmark is launched
  * we take its manifest and assign it an index, subsequent launches of that
  * bookmark are given the same index and therefore reopen the previous activity.
@@ -65,16 +66,17 @@ public class WebAppIndexer {
             index = mActivityList.get(0).index;
             final ActivityEntry newEntry = new ActivityEntry(index, manifest);
             mActivityList.set(0, newEntry);
         }
 
         // Put the index at the back of the queue to be recycled
         markActivityUsed(index, manifest, context);
 
+        Log.d("GeckoTabs", "using index " + index + " for manifest " + manifest);
         return index;
     }
 
     private int getManifestIndex(String manifest) {
         for (int i = mActivityList.size() - 1; i >= 0; i--) {
             if (manifest.equals(mActivityList.get(i).manifest)) {
                 return mActivityList.get(i).index;
             }