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

Commit 220b6268 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5983947 from 4a1a68d3 to qt-qpr2-release

Change-Id: I1472c725f03ae97a19fda53ee38cc258a69fce05
parents ba679e34 4a1a68d3
Loading
Loading
Loading
Loading
+89 −12
Original line number Diff line number Diff line
@@ -868,6 +868,94 @@ public class ViewDebug {
        return null;
    }

    private static class StreamingPictureCallbackHandler implements AutoCloseable,
            HardwareRenderer.PictureCapturedCallback, Runnable {
        private final HardwareRenderer mRenderer;
        private final Callable<OutputStream> mCallback;
        private final Executor mExecutor;
        private final ReentrantLock mLock = new ReentrantLock(false);
        private final ArrayDeque<byte[]> mQueue = new ArrayDeque<>(3);
        private final ByteArrayOutputStream mByteStream = new ByteArrayOutputStream();
        private boolean mStopListening;
        private Thread mRenderThread;

        private StreamingPictureCallbackHandler(HardwareRenderer renderer,
                Callable<OutputStream> callback, Executor executor) {
            mRenderer = renderer;
            mCallback = callback;
            mExecutor = executor;
            mRenderer.setPictureCaptureCallback(this);
        }

        @Override
        public void close() {
            mLock.lock();
            mStopListening = true;
            mLock.unlock();
            mRenderer.setPictureCaptureCallback(null);
        }

        @Override
        public void onPictureCaptured(Picture picture) {
            mLock.lock();
            if (mStopListening) {
                mLock.unlock();
                mRenderer.setPictureCaptureCallback(null);
                return;
            }
            if (mRenderThread == null) {
                mRenderThread = Thread.currentThread();
            }
            boolean needsInvoke = true;
            if (mQueue.size() == 3) {
                mQueue.removeLast();
                needsInvoke = false;
            }
            picture.writeToStream(mByteStream);
            mQueue.add(mByteStream.toByteArray());
            mByteStream.reset();
            mLock.unlock();

            if (needsInvoke) {
                mExecutor.execute(this);
            }
        }

        @Override
        public void run() {
            mLock.lock();
            final byte[] picture = mQueue.poll();
            final boolean isStopped = mStopListening;
            mLock.unlock();
            if (Thread.currentThread() == mRenderThread) {
                close();
                throw new IllegalStateException(
                        "ViewDebug#startRenderingCommandsCapture must be given an executor that "
                        + "invokes asynchronously");
            }
            if (isStopped) {
                return;
            }
            OutputStream stream = null;
            try {
                stream = mCallback.call();
            } catch (Exception ex) {
                Log.w("ViewDebug", "Aborting rendering commands capture "
                        + "because callback threw exception", ex);
            }
            if (stream != null) {
                try {
                    stream.write(picture);
                } catch (IOException ex) {
                    Log.w("ViewDebug", "Aborting rendering commands capture "
                            + "due to IOException writing to output stream", ex);
                }
            } else {
                close();
            }
        }
    }

    /**
     * Begins capturing the entire rendering commands for the view tree referenced by the given
     * view. The view passed may be any View in the tree as long as it is attached. That is,
@@ -913,18 +1001,7 @@ public class ViewDebug {
        }
        final HardwareRenderer renderer = attachInfo.mThreadedRenderer;
        if (renderer != null) {
            return new PictureCallbackHandler(renderer, (picture -> {
                try {
                    OutputStream stream = callback.call();
                    if (stream != null) {
                        picture.writeToStream(stream);
                        return true;
                    }
                } catch (Exception ex) {
                    // fall through
                }
                return false;
            }), executor);
            return new StreamingPictureCallbackHandler(renderer, callback, executor);
        }
        return null;
    }
+5 −3
Original line number Diff line number Diff line
@@ -192,13 +192,15 @@ public class ImageWriter implements AutoCloseable {

        mMaxImages = maxImages;

        if (format == ImageFormat.UNKNOWN) {
            format = SurfaceUtils.getSurfaceFormat(surface);
        }
        // Note that the underlying BufferQueue is working in synchronous mode
        // to avoid dropping any buffers.
        mNativeContext = nativeInit(new WeakReference<>(this), surface, maxImages, format);

        // nativeInit internally overrides UNKNOWN format. So does surface format query after
        // nativeInit and before getEstimatedNativeAllocBytes().
        if (format == ImageFormat.UNKNOWN) {
            format = SurfaceUtils.getSurfaceFormat(surface);
        }
        // Estimate the native buffer allocation size and register it so it gets accounted for
        // during GC. Note that this doesn't include the buffers required by the buffer queue
        // itself and the buffers requested by the producer.
+3 −0
Original line number Diff line number Diff line
@@ -34,4 +34,7 @@
    <!-- The delay before the unlock dialog pops up -->
    <integer name="unlock_dialog_delay_ms">0</integer>

    <!-- Timeout values in milliseconds for displaying volume dialog-->
    <integer name="car_volume_dialog_display_normal_timeout">3000</integer>
    <integer name="car_volume_dialog_display_hovering_timeout">16000</integer>
</resources>
+66 −54
Original line number Diff line number Diff line
@@ -62,7 +62,6 @@ import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
@@ -76,8 +75,6 @@ public class CarVolumeDialogImpl implements VolumeDialog {

    private static final String XML_TAG_VOLUME_ITEMS = "carVolumeItems";
    private static final String XML_TAG_VOLUME_ITEM = "item";
    private static final int HOVERING_TIMEOUT = 16000;
    private static final int NORMAL_TIMEOUT = 3000;
    private static final int LISTVIEW_ANIMATION_DURATION_IN_MILLIS = 250;
    private static final int DISMISS_DELAY_IN_MILLIS = 50;
    private static final int ARROW_FADE_IN_START_DELAY_IN_MILLIS = 100;
@@ -91,12 +88,23 @@ public class CarVolumeDialogImpl implements VolumeDialog {
    // Volume items in the RecyclerView.
    private final List<CarVolumeItem> mCarVolumeLineItems = new ArrayList<>();
    private final KeyguardManager mKeyguard;
    private final int mNormalTimeout;
    private final int mHoveringTimeout;

    private Window mWindow;
    private CustomDialog mDialog;
    private RecyclerView mListView;
    private CarVolumeItemAdapter mVolumeItemsAdapter;
    private Car mCar;
    private CarAudioManager mCarAudioManager;
    private boolean mHovering;
    private int mCurrentlyDisplayingGroupId;
    private int mPreviouslyDisplayingGroupId;
    private boolean mShowing;
    private boolean mDismissing;
    private boolean mExpanded;
    private View mExpandIcon;

    private final CarAudioManager.CarVolumeCallback mVolumeChangeCallback =
            new CarAudioManager.CarVolumeCallback() {
                @Override
@@ -126,6 +134,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {
                        volumeItem.progress = value;
                    }
                    if ((flags & AudioManager.FLAG_SHOW_UI) != 0) {
                        mPreviouslyDisplayingGroupId = mCurrentlyDisplayingGroupId;
                        mCurrentlyDisplayingGroupId = groupId;
                        mHandler.obtainMessage(H.SHOW,
                                Events.SHOW_REASON_VOLUME_CHANGED).sendToTarget();
@@ -137,12 +146,6 @@ public class CarVolumeDialogImpl implements VolumeDialog {
                    // ignored
                }
            };
    private boolean mHovering;
    private int mCurrentlyDisplayingGroupId;
    private boolean mShowing;
    private boolean mDismissing;
    private boolean mExpanded;
    private View mExpandIcon;

    private final CarServiceLifecycleListener mCarServiceLifecycleListener = (car, ready) -> {
        if (!ready) {
@@ -158,7 +161,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {
            mAvailableVolumeItems.add(volumeItem);
            // The first one is the default item.
            if (groupId == 0) {
                setuptListItem(0);
                clearAllAndSetupDefaultCarVolumeLineItem(0);
            }
        }

@@ -169,18 +172,13 @@ public class CarVolumeDialogImpl implements VolumeDialog {
        mCarAudioManager.registerCarVolumeCallback(mVolumeChangeCallback);
    };

    private void setuptListItem(int groupId) {
        mCarVolumeLineItems.clear();
        VolumeItem volumeItem = mAvailableVolumeItems.get(groupId);
        volumeItem.defaultItem = true;
        addCarVolumeListItem(volumeItem, /* volumeGroupId = */ groupId,
                R.drawable.car_ic_keyboard_arrow_down, new ExpandIconListener()
        );
    }

    public CarVolumeDialogImpl(Context context) {
        mContext = context;
        mKeyguard = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
        mNormalTimeout = mContext.getResources().getInteger(
                R.integer.car_volume_dialog_display_normal_timeout);
        mHoveringTimeout = mContext.getResources().getInteger(
                R.integer.car_volume_dialog_display_hovering_timeout);
    }

    private static int getSeekbarValue(CarAudioManager carAudioManager, int volumeGroupId) {
@@ -204,7 +202,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {

    @Override
    public void destroy() {
        mHandler.removeCallbacksAndMessages(null);
        mHandler.removeCallbacksAndMessages(/* token= */ null);

        cleanupAudioManager();
        // unregisterVolumeCallback is not being called when disconnect car, so we manually cleanup
@@ -280,19 +278,36 @@ public class CarVolumeDialogImpl implements VolumeDialog {

        mHandler.removeMessages(H.SHOW);
        mHandler.removeMessages(H.DISMISS);

        rescheduleTimeoutH();

        // Refresh the data set before showing.
        mVolumeItemsAdapter.notifyDataSetChanged();

        if (mShowing) {
            if (mPreviouslyDisplayingGroupId == mCurrentlyDisplayingGroupId || mExpanded) {
                return;
            }

            clearAllAndSetupDefaultCarVolumeLineItem(mCurrentlyDisplayingGroupId);
            return;
        }

        mShowing = true;
        setuptListItem(mCurrentlyDisplayingGroupId);
        clearAllAndSetupDefaultCarVolumeLineItem(mCurrentlyDisplayingGroupId);
        mDialog.show();
        Events.writeEvent(mContext, Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked());
    }

    private void rescheduleTimeoutH() {
    private void clearAllAndSetupDefaultCarVolumeLineItem(int groupId) {
        mCarVolumeLineItems.clear();
        VolumeItem volumeItem = mAvailableVolumeItems.get(groupId);
        volumeItem.defaultItem = true;
        addCarVolumeListItem(volumeItem, /* volumeGroupId = */ groupId,
                R.drawable.car_ic_keyboard_arrow_down, new ExpandIconListener());
    }

    protected void rescheduleTimeoutH() {
        mHandler.removeMessages(H.DISMISS);
        final int timeout = computeTimeoutH();
        mHandler.sendMessageDelayed(mHandler
@@ -304,7 +319,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {
    }

    private int computeTimeoutH() {
        return mHovering ? HOVERING_TIMEOUT : NORMAL_TIMEOUT;
        return mHovering ? mHoveringTimeout : mNormalTimeout;
    }

    private void dismissH(int reason) {
@@ -366,12 +381,13 @@ public class CarVolumeDialogImpl implements VolumeDialog {
                if (XML_TAG_VOLUME_ITEM.equals(parser.getName())) {
                    TypedArray item = mContext.getResources().obtainAttributes(
                            attrs, R.styleable.carVolumeItems_item);
                    int usage = item.getInt(R.styleable.carVolumeItems_item_usage, -1);
                    int usage = item.getInt(R.styleable.carVolumeItems_item_usage,
                            /* defValue= */ -1);
                    if (usage >= 0) {
                        VolumeItem volumeItem = new VolumeItem();
                        volumeItem.rank = rank;
                        volumeItem.icon = item.getResourceId(R.styleable.carVolumeItems_item_icon,
                                0);
                        volumeItem.icon = item.getResourceId(
                                R.styleable.carVolumeItems_item_icon, /* defValue= */ 0);
                        mVolumeItems.put(usage, volumeItem);
                        rank++;
                    }
@@ -396,22 +412,22 @@ public class CarVolumeDialogImpl implements VolumeDialog {
        return result;
    }

    private CarVolumeItem addCarVolumeListItem(VolumeItem volumeItem, int volumeGroupId,
            int supplementalIconId,
    private CarVolumeItem createCarVolumeListItem(VolumeItem volumeItem, int volumeGroupId,
            Drawable supplementalIcon, int seekbarProgressValue,
            @Nullable View.OnClickListener supplementalIconOnClickListener) {
        CarVolumeItem carVolumeItem = new CarVolumeItem();
        carVolumeItem.setMax(getMaxSeekbarValue(mCarAudioManager, volumeGroupId));
        int color = mContext.getResources().getColor(R.color.car_volume_dialog_tint);
        int progress = getSeekbarValue(mCarAudioManager, volumeGroupId);
        carVolumeItem.setProgress(progress);
        carVolumeItem.setProgress(seekbarProgressValue);
        carVolumeItem.setOnSeekBarChangeListener(
                new CarVolumeDialogImpl.VolumeSeekBarChangeListener(volumeGroupId,
                        mCarAudioManager));
        Drawable primaryIcon = mContext.getResources().getDrawable(volumeItem.icon);
        carVolumeItem.setGroupId(volumeGroupId);

        int color = mContext.getColor(R.color.car_volume_dialog_tint);
        Drawable primaryIcon = mContext.getDrawable(volumeItem.icon);
        primaryIcon.mutate().setTint(color);
        carVolumeItem.setPrimaryIcon(primaryIcon);
        if (supplementalIconId != 0) {
            Drawable supplementalIcon = mContext.getResources().getDrawable(supplementalIconId);
        if (supplementalIcon != null) {
            supplementalIcon.mutate().setTint(color);
            carVolumeItem.setSupplementalIcon(supplementalIcon,
                    /* showSupplementalIconDivider= */ true);
@@ -420,21 +436,23 @@ public class CarVolumeDialogImpl implements VolumeDialog {
            carVolumeItem.setSupplementalIcon(/* drawable= */ null,
                    /* showSupplementalIconDivider= */ false);
        }
        carVolumeItem.setGroupId(volumeGroupId);
        mCarVolumeLineItems.add(carVolumeItem);

        volumeItem.carVolumeItem = carVolumeItem;
        volumeItem.progress = progress;
        volumeItem.progress = seekbarProgressValue;

        return carVolumeItem;
    }

    private VolumeItem findVolumeItem(CarVolumeItem targetItem) {
        for (int i = 0; i < mVolumeItems.size(); ++i) {
            VolumeItem volumeItem = mVolumeItems.valueAt(i);
            if (volumeItem.carVolumeItem == targetItem) {
                return volumeItem;
            }
        }
        return null;
    private CarVolumeItem addCarVolumeListItem(VolumeItem volumeItem, int volumeGroupId,
            int supplementalIconId,
            @Nullable View.OnClickListener supplementalIconOnClickListener) {
        int seekbarProgressValue = getSeekbarValue(mCarAudioManager, volumeGroupId);
        Drawable supplementalIcon = supplementalIconId == 0 ? null : mContext.getDrawable(
                supplementalIconId);
        CarVolumeItem carVolumeItem = createCarVolumeListItem(volumeItem, volumeGroupId,
                supplementalIcon, seekbarProgressValue, supplementalIconOnClickListener);
        mCarVolumeLineItems.add(carVolumeItem);
        return carVolumeItem;
    }

    private void cleanupAudioManager() {
@@ -530,21 +548,15 @@ public class CarVolumeDialogImpl implements VolumeDialog {
            for (int groupId = 0; groupId < mAvailableVolumeItems.size(); ++groupId) {
                if (groupId != mCurrentlyDisplayingGroupId) {
                    VolumeItem volumeItem = mAvailableVolumeItems.get(groupId);
                    addCarVolumeListItem(volumeItem, groupId, 0, null);
                    addCarVolumeListItem(volumeItem, groupId, /* supplementalIconId= */ 0,
                            /* supplementalIconOnClickListener= */ null);
                }
            }
            inAnimator = AnimatorInflater.loadAnimator(
                    mContext, R.anim.car_arrow_fade_in_rotate_up);

        } else {
            // Only keeping the default stream if it is not expended.
            Iterator itr = mCarVolumeLineItems.iterator();
            while (itr.hasNext()) {
                CarVolumeItem carVolumeItem = (CarVolumeItem) itr.next();
                if (carVolumeItem.getGroupId() != mCurrentlyDisplayingGroupId) {
                    itr.remove();
                }
            }
            clearAllAndSetupDefaultCarVolumeLineItem(mCurrentlyDisplayingGroupId);
            inAnimator = AnimatorInflater.loadAnimator(
                    mContext, R.anim.car_arrow_fade_in_rotate_down);
        }
+187 −9

File changed.

Preview size limit exceeded, changes collapsed.

Loading