From c8d8f05b1556d6323b5b80b78def7dc88bc0d3c3 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Mon, 9 Sep 2019 09:15:04 -0400 Subject: [PATCH] Remove main thread ipc call in QuickQSPanel This is done by caching the value in QuickQSPanel when it is obtained from onTuningChanged. static methods converted to bound methods. Test: manual Test: change value of setting and observe effects in QSAnimator and QSFooterImpl Fixes: 140052679 Change-Id: I7ee605a1f71ef930ac42efbaa95998e31d53dac6 --- .../com/android/systemui/qs/QSAnimator.java | 2 +- .../src/com/android/systemui/qs/QSFooter.java | 5 +++ .../com/android/systemui/qs/QSFooterImpl.java | 9 ++++- .../com/android/systemui/qs/QuickQSPanel.java | 33 ++++++++++++++----- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java index 41f66f7e2021f..9221b68521123 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java @@ -155,7 +155,7 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha } else if (MOVE_FULL_ROWS.equals(key)) { mFullRows = TunerService.parseIntegerSwitch(newValue, true); } else if (QuickQSPanel.NUM_QUICK_TILES.equals(key)) { - mNumQuickTiles = mQuickQsPanel.getNumQuickTiles(mQs.getContext()); + mNumQuickTiles = QuickQSPanel.parseNumTiles(newValue); clearAnimationState(); } updateAnimators(); diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java index b597a72ba8999..0a2533a8426ea 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java @@ -28,6 +28,11 @@ public interface QSFooter { */ void setQSPanel(@Nullable QSPanel panel); + /** + * Sets the given {@link QuickQSPanel} to be the one associated with quick settings. + */ + default void setQQSPanel(@Nullable QuickQSPanel panel) {}; + /** * Sets whether or not the footer should be visible. * diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java b/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java index 644664ecaeec8..0134aa3a15df6 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSFooterImpl.java @@ -81,6 +81,7 @@ public class QSFooterImpl extends FrameLayout implements QSFooter, private boolean mQsDisabled; private QSPanel mQsPanel; + private QuickQSPanel mQuickQsPanel; private boolean mExpanded; @@ -177,7 +178,8 @@ public class QSFooterImpl extends FrameLayout implements QSFooter, } private void updateAnimator(int width) { - int numTiles = QuickQSPanel.getNumQuickTiles(mContext); + int numTiles = mQuickQsPanel != null ? mQuickQsPanel.getNumQuickTiles() + : QuickQSPanel.getDefaultMaxTiles(); int size = mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size) - mContext.getResources().getDimensionPixelSize(dimen.qs_quick_tile_padding); int remaining = (width - numTiles * size) / (numTiles - 1); @@ -345,6 +347,11 @@ public class QSFooterImpl extends FrameLayout implements QSFooter, } } + @Override + public void setQQSPanel(@Nullable QuickQSPanel panel) { + mQuickQsPanel = panel; + } + @Override public void onClick(View v) { // Don't do anything until view are unhidden diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java index 37113cfac2f3d..985cee5a1f158 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java @@ -16,7 +16,6 @@ package com.android.systemui.qs; -import static com.android.systemui.DejankUtils.whitelistIpcs; import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; import android.content.Context; @@ -50,9 +49,10 @@ public class QuickQSPanel extends QSPanel { public static final String NUM_QUICK_TILES = "sysui_qqs_count"; private static final String TAG = "QuickQSPanel"; + // Start it at 6 so a non-zero value can be obtained statically. + private static int sDefaultMaxTiles = 6; private boolean mDisabledByPolicy; - private static int mDefaultMaxTiles; private int mMaxTiles; protected QSPanel mFullPanel; @@ -69,7 +69,7 @@ public class QuickQSPanel extends QSPanel { } removeView((View) mTileLayout); } - mDefaultMaxTiles = getResources().getInteger(R.integer.quick_qs_panel_max_columns); + sDefaultMaxTiles = getResources().getInteger(R.integer.quick_qs_panel_max_columns); mTileLayout = new HeaderTileLayout(context); mTileLayout.setListening(mListening); addView((View) mTileLayout, 0 /* Between brightness and footer */); @@ -160,14 +160,31 @@ public class QuickQSPanel extends QSPanel { private final Tunable mNumTiles = new Tunable() { @Override public void onTuningChanged(String key, String newValue) { - setMaxTiles(getNumQuickTiles(mContext)); + setMaxTiles(parseNumTiles(newValue)); } }; - public static int getNumQuickTiles(Context context) { - // TODO(b/140052679) - return whitelistIpcs(() -> - Dependency.get(TunerService.class).getValue(NUM_QUICK_TILES, mDefaultMaxTiles)); + public int getNumQuickTiles() { + return mMaxTiles; + } + + /** + * Parses the String setting into the number of tiles. Defaults to {@code mDefaultMaxTiles} + * + * @param numTilesValue value of the setting to parse + * @return parsed value of numTilesValue OR {@code mDefaultMaxTiles} on error + */ + public static int parseNumTiles(String numTilesValue) { + try { + return Integer.parseInt(numTilesValue); + } catch (NumberFormatException e) { + // Couldn't read an int from the new setting value. Use default. + return sDefaultMaxTiles; + } + } + + public static int getDefaultMaxTiles() { + return sDefaultMaxTiles; } void setDisabledByPolicy(boolean disabled) {