Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1fc1689 authored by Juan Lang's avatar Juan Lang
Browse files

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
parent 5b1bc2ac
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.settings.core.lifecycle;

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 @@ import android.view.MenuItem;
 */
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 @@ public class ObservableDialogFragment extends DialogFragment {
        }
        return lifecycleHandled;
    }

    @VisibleForTesting(otherwise = VisibleForTesting.NONE)
    /** @return a new lifecycle. */
    public static Lifecycle createLifecycle() {
        return new Lifecycle();
    }
}