Add a factory method to create a Lifecycle.

Some unit tests in other packages want to override the mLifecycle member
with their own value. When the Lifecycle class moves into SettingsLib,
the classpath of ObservableDialogFragment and Lifecycle have to remain
consistent. This change allows dependent classes to remain agnostic to
Lifecycle's classpath.

Test: make RunSettingsGoogleRoboTests && make RunSettingsLibRoboTests &&
      make RunSettingsRoboTests

Change-Id: I594e447741aeeb3ba95afb4044d496b1540bd92c
diff --git a/src/com/android/settings/core/lifecycle/ObservableDialogFragment.java b/src/com/android/settings/core/lifecycle/ObservableDialogFragment.java
index c3265dd..f902934 100644
--- a/src/com/android/settings/core/lifecycle/ObservableDialogFragment.java
+++ b/src/com/android/settings/core/lifecycle/ObservableDialogFragment.java
@@ -17,6 +17,7 @@
 
 import android.app.DialogFragment;
 import android.content.Context;
+import android.support.annotation.VisibleForTesting;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -26,7 +27,7 @@
  */
 public class ObservableDialogFragment extends DialogFragment {
 
-    protected final Lifecycle mLifecycle = new Lifecycle();
+    protected final Lifecycle mLifecycle = createLifecycle();
 
     @Override
     public void onAttach(Context context) {
@@ -84,4 +85,10 @@
         }
         return lifecycleHandled;
     }
+
+    @VisibleForTesting(otherwise = VisibleForTesting.NONE)
+    /** @return a new lifecycle. */
+    public static Lifecycle createLifecycle() {
+        return new Lifecycle();
+    }
 }