Have QS fragment keep track of some state on recreate
Test: runtest systemui
Change-Id: I1cf84a0943092fcfc5428fcfccb4a887a83b294b
Fixes: 35205198
Fixes: 36592148
(cherry picked from commit 78187249c3)
This commit is contained in:
@@ -21,6 +21,7 @@ import android.app.Fragment;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -39,6 +40,8 @@ import com.android.systemui.statusbar.stack.StackStateAnimator;
|
||||
public class QSFragment extends Fragment implements QS {
|
||||
private static final String TAG = "QS";
|
||||
private static final boolean DEBUG = false;
|
||||
private static final String EXTRA_EXPANDED = "expanded";
|
||||
private static final String EXTRA_LISTENING = "listening";
|
||||
|
||||
private final Rect mQsBounds = new Rect();
|
||||
private boolean mQsExpanded;
|
||||
@@ -85,6 +88,35 @@ public class QSFragment extends Fragment implements QS {
|
||||
|
||||
mQSCustomizer = view.findViewById(R.id.qs_customize);
|
||||
mQSCustomizer.setQs(this);
|
||||
if (savedInstanceState != null) {
|
||||
setExpanded(savedInstanceState.getBoolean(EXTRA_EXPANDED));
|
||||
setListening(savedInstanceState.getBoolean(EXTRA_LISTENING));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mListening) {
|
||||
setListening(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(EXTRA_EXPANDED, mQsExpanded);
|
||||
outState.putBoolean(EXTRA_LISTENING, mListening);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isListening() {
|
||||
return mListening;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isExpanded() {
|
||||
return mQsExpanded;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
package com.android.systemui.qs;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import android.app.FragmentController;
|
||||
import android.app.FragmentManagerNonConfig;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
@@ -24,6 +27,7 @@ import com.android.keyguard.CarrierText;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.R;
|
||||
|
||||
import android.os.Parcelable;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
|
||||
import com.android.systemui.SysuiBaseFragmentTest;
|
||||
@@ -90,4 +94,23 @@ public class QSFragmentTest extends SysuiBaseFragmentTest {
|
||||
host.destroy();
|
||||
processAllMessages();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveState() {
|
||||
QSFragment qs = (QSFragment) mFragment;
|
||||
|
||||
mFragments.dispatchResume();
|
||||
processAllMessages();
|
||||
|
||||
qs.setListening(true);
|
||||
qs.setExpanded(true);
|
||||
processAllMessages();
|
||||
recreateFragment();
|
||||
processAllMessages();
|
||||
|
||||
// Get the reference to the new fragment.
|
||||
qs = (QSFragment) mFragment;
|
||||
assertTrue(qs.isListening());
|
||||
assertTrue(qs.isExpanded());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,14 +133,7 @@ public abstract class BaseFragmentTest {
|
||||
public void testRecreate() {
|
||||
mFragments.dispatchResume();
|
||||
processAllMessages();
|
||||
mFragments.dispatchPause();
|
||||
Parcelable p = mFragments.saveAllState();
|
||||
mFragments.dispatchDestroy();
|
||||
|
||||
mFragments = FragmentController.createController(new HostCallbacks());
|
||||
mFragments.attachHost(null);
|
||||
mFragments.restoreAllState(p, (FragmentManagerNonConfig) null);
|
||||
mFragments.dispatchResume();
|
||||
recreateFragment();
|
||||
processAllMessages();
|
||||
}
|
||||
|
||||
@@ -154,6 +147,18 @@ public abstract class BaseFragmentTest {
|
||||
processAllMessages();
|
||||
}
|
||||
|
||||
protected void recreateFragment() {
|
||||
mFragments.dispatchPause();
|
||||
Parcelable p = mFragments.saveAllState();
|
||||
mFragments.dispatchDestroy();
|
||||
|
||||
mFragments = FragmentController.createController(new HostCallbacks());
|
||||
mFragments.attachHost(null);
|
||||
mFragments.restoreAllState(p, (FragmentManagerNonConfig) null);
|
||||
mFragments.dispatchResume();
|
||||
mFragment = mFragments.getFragmentManager().findFragmentById(VIEW_ID);
|
||||
}
|
||||
|
||||
protected void attachFragmentToWindow() {
|
||||
ViewUtils.attachView(mView);
|
||||
TestableLooper.get(this).processMessages(1);
|
||||
|
||||
Reference in New Issue
Block a user