Fix volume panel hang
SliceLiveData changed its behavior, if slice is null, it will not notify LiveData observer but callback to onErrorListener. We only reduce PanelSlicesLoaderCountdownLatch in LiveData observer. Therefore the error slice caused PanelSlicesLoaderCountdownLatch never count to 0, the UI was not displayed. It is solved by reducing PanelSlicesLoaderCountdownLatch in onErrorListener and also not return null in MediaOutputIndicatorSlice. Test: manual Fixes: 141084035 Change-Id: Iddb2dbdc0e0d2ac3e26071960bb667937f181121
This commit is contained in:
@@ -53,9 +53,10 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import com.google.android.setupdesign.DividerItemDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PanelFragment extends Fragment {
|
||||
|
||||
@@ -86,7 +87,7 @@ public class PanelFragment extends Fragment {
|
||||
private MetricsFeatureProvider mMetricsProvider;
|
||||
private String mPanelClosedKey;
|
||||
|
||||
private final List<LiveData<Slice>> mSliceLiveData = new ArrayList<>();
|
||||
private final Map<Uri, LiveData<Slice>> mSliceLiveData = new LinkedHashMap<>();
|
||||
|
||||
@VisibleForTesting
|
||||
PanelSlicesLoaderCountdownLatch mPanelSlicesLoaderCountdownLatch;
|
||||
@@ -97,14 +98,14 @@ public class PanelFragment extends Fragment {
|
||||
|
||||
private final ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener =
|
||||
new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
animateIn();
|
||||
if (mPanelSlices != null) {
|
||||
mPanelSlices.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
animateIn();
|
||||
if (mPanelSlices != null) {
|
||||
mPanelSlices.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private PanelSlicesAdapter mAdapter;
|
||||
|
||||
@@ -121,9 +122,9 @@ public class PanelFragment extends Fragment {
|
||||
* Animate the old panel out from the screen, then update the panel with new content once the
|
||||
* animation is done.
|
||||
* <p>
|
||||
* Takes the entire panel and animates out from behind the navigation bar.
|
||||
* Takes the entire panel and animates out from behind the navigation bar.
|
||||
* <p>
|
||||
* Call createPanelContent() once animation end.
|
||||
* Call createPanelContent() once animation end.
|
||||
*/
|
||||
void updatePanelWithAnimation() {
|
||||
final View panelContent = mLayoutView.findViewById(R.id.panel_container);
|
||||
@@ -210,10 +211,14 @@ public class PanelFragment extends Fragment {
|
||||
mPanelSlicesLoaderCountdownLatch = new PanelSlicesLoaderCountdownLatch(sliceUris.size());
|
||||
|
||||
for (Uri uri : sliceUris) {
|
||||
final LiveData<Slice> sliceLiveData = SliceLiveData.fromUri(getActivity(), uri);
|
||||
final LiveData<Slice> sliceLiveData = SliceLiveData.fromUri(getActivity(), uri,
|
||||
(int type, Throwable source)-> {
|
||||
removeSliceLiveData(uri);
|
||||
mPanelSlicesLoaderCountdownLatch.markSliceLoaded(uri);
|
||||
});
|
||||
|
||||
// Add slice first to make it in order. Will remove it later if there's an error.
|
||||
mSliceLiveData.add(sliceLiveData);
|
||||
mSliceLiveData.put(uri, sliceLiveData);
|
||||
|
||||
sliceLiveData.observe(getViewLifecycleOwner(), slice -> {
|
||||
// If the Slice has already loaded, do nothing.
|
||||
@@ -238,12 +243,7 @@ public class PanelFragment extends Fragment {
|
||||
*/
|
||||
final SliceMetadata metadata = SliceMetadata.from(getActivity(), slice);
|
||||
if (slice == null || metadata.isErrorSlice()) {
|
||||
final List<String> whiteList = Arrays.asList(
|
||||
getResources().getStringArray(
|
||||
R.array.config_panel_keep_observe_uri));
|
||||
if (!whiteList.contains(uri.toString())) {
|
||||
mSliceLiveData.remove(sliceLiveData);
|
||||
}
|
||||
removeSliceLiveData(uri);
|
||||
mPanelSlicesLoaderCountdownLatch.markSliceLoaded(uri);
|
||||
} else if (metadata.getLoadingState() == SliceMetadata.LOADED_ALL) {
|
||||
mPanelSlicesLoaderCountdownLatch.markSliceLoaded(uri);
|
||||
@@ -260,12 +260,21 @@ public class PanelFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private void removeSliceLiveData(Uri uri) {
|
||||
final List<String> whiteList = Arrays.asList(
|
||||
getResources().getStringArray(
|
||||
R.array.config_panel_keep_observe_uri));
|
||||
if (!whiteList.contains(uri.toString())) {
|
||||
mSliceLiveData.remove(uri);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When all of the Slices have loaded for the first time, then we can setup the
|
||||
* {@link RecyclerView}.
|
||||
* <p>
|
||||
* When the Recyclerview has been laid out, we can begin the animation with the
|
||||
* {@link mOnGlobalLayoutListener}, which calls {@link #animateIn()}.
|
||||
* When the Recyclerview has been laid out, we can begin the animation with the
|
||||
* {@link mOnGlobalLayoutListener}, which calls {@link #animateIn()}.
|
||||
*/
|
||||
private void loadPanelWhenReady() {
|
||||
if (mPanelSlicesLoaderCountdownLatch.isPanelReadyToLoad()) {
|
||||
@@ -286,9 +295,9 @@ public class PanelFragment extends Fragment {
|
||||
/**
|
||||
* Animate a Panel onto the screen.
|
||||
* <p>
|
||||
* Takes the entire panel and animates in from behind the navigation bar.
|
||||
* Takes the entire panel and animates in from behind the navigation bar.
|
||||
* <p>
|
||||
* Relies on the Panel being having a fixed height to begin the animation.
|
||||
* Relies on the Panel being having a fixed height to begin the animation.
|
||||
*/
|
||||
private void animateIn() {
|
||||
final View panelContent = mLayoutView.findViewById(R.id.panel_container);
|
||||
@@ -319,7 +328,7 @@ public class PanelFragment extends Fragment {
|
||||
animatorSet.setInterpolator(new DecelerateInterpolator());
|
||||
animatorSet.playTogether(
|
||||
ObjectAnimator.ofFloat(sheet, View.TRANSLATION_Y, startY, endY),
|
||||
ObjectAnimator.ofFloat(sheet, View.ALPHA, startAlpha,endAlpha));
|
||||
ObjectAnimator.ofFloat(sheet, View.ALPHA, startAlpha, endAlpha));
|
||||
return animatorSet;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user