koral-- / android-gif-drawable

Views and Drawable for displaying animated GIFs on Android
Other
9.55k stars 1.78k forks source link

Crash in Samsung with Android 9.0 #644

Closed coderloveryan closed 2 years ago

coderloveryan commented 5 years ago
(21147): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-09 11:15:33.889 F/DEBUG   (21147): Build fingerprint: 'samsung/star2qltezc/star2qltechn:9/PPR1.180610.011/G9650ZCU3CSAB:user/release-keys'
04-09 11:15:33.889 F/DEBUG   (21147): Revision: '14'
04-09 11:15:33.889 F/DEBUG   (21147): ABI: 'arm'
04-09 11:15:33.889 F/DEBUG   (21147): pid: 20725, tid: 20964, name: pool-14-thread-  >>> com.h.u.u <<<
04-09 11:15:33.889 F/DEBUG   (21147): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
04-09 11:15:33.889 F/DEBUG   (21147): Cause: null pointer dereference
04-09 11:15:33.889 F/DEBUG   (21147):     r0  00000000  r1  00000000  r2  00430000  r3  edc38a59
04-09 11:15:33.889 F/DEBUG   (21147):     r4  cc41a300  r5  cc41a318  r6  00000014  r7  c3eff410
04-09 11:15:33.889 F/DEBUG   (21147):     r8  c3eff460  r9  001a020d  r10 ce92a670  r11 00000000
04-09 11:15:33.889 F/DEBUG   (21147):     ip  eeb237c0  sp  c3eff3e0  lr  ee883185  pc  ee8830f8
04-09 11:15:33.950 F/DEBUG   (21147): 
04-09 11:15:33.950 F/DEBUG   (21147): backtrace:
04-09 11:15:33.950 F/DEBUG   (21147):     #00 pc 003970f8  /system/lib/libhwui.so (SkPixelRef::callGenIDChangeListeners()+40)
04-09 11:15:33.950 F/DEBUG   (21147):     #01 pc 00397181  /system/lib/libhwui.so (SkPixelRef::notifyPixelsChanged()+4)
04-09 11:15:33.950 F/DEBUG   (21147):     #02 pc 000d067b  /system/lib/libandroid_runtime.so (android::bitmap::unlockPixels(_JNIEnv*, _jobject*)+22)
04-09 11:15:33.950 F/DEBUG   (21147):     #03 pc 000008e7  /system/lib/libjnigraphics.so (AndroidBitmap_unlockPixels+20)
04-09 11:15:33.950 F/DEBUG   (21147):     #04 pc 00001eeb  /data/app/com.h.u.u-GNEfKS2wiZxOc8LYS6Sp-Q==/lib/arm/libpl_droidsonroids_gif.so
04-09 11:15:33.950 F/DEBUG   (21147):     #05 pc 00001fd5  /data/app/com.h.u.u-GNEfKS2wiZxOc8LYS6Sp-Q==/lib/arm/libpl_droidsonroids_gif.so (Java_pl_droidsonroids_gif_GifInfoHandle_renderFrame+104)
04-09 11:15:33.950 F/DEBUG   (21147):     #06 pc 000afd1b  /data/app/com.h.u.u-GNEfKS2wiZxOc8LYS6Sp-Q==/oat/arm/base.odex (offset 0xa7000) (pl.droidsonroids.gif.GifInfoHandle.renderFrame+130)
coderloveryan commented 5 years ago

The device model is Galaxy s9+,be thanks for your response.

koral-- commented 5 years ago

Could you attach affected GIF and/or code which reproduces this issue?

coderloveryan commented 5 years ago

image

coderloveryan commented 5 years ago
public class UplusRefreshHeader extends LinearLayout implements RefreshHeader {
    private GifImageView gifImageView;
    private GifDrawable gifDrawable;
    private TextView tvRefresh;
    protected Context context;
    private boolean isSuccess = true;
    private RefreshType refreshType = RefreshType.NORMAL;

    public UplusRefreshHeader(Context context) {
        super(context);
        initView(context);
    }

    public UplusRefreshHeader(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.initView(context);
    }

    public UplusRefreshHeader(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.initView(context);
    }

    public void setRefreshType(RefreshType refreshType) {
        this.refreshType = refreshType;
    }

    private void initView(Context context) {
        this.context = context;
        setOrientation(VERTICAL);
        setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        setPadding(0,0,0, DensityUtil.dp2px(14));
        gifImageView = new GifImageView(context);
        try {
            gifDrawable = new GifDrawable(getResources(), com.haier.uhome.uplus.phone.R.drawable.loading);
            gifDrawable.setSpeed(4.0f);
            gifImageView.setImageDrawable(gifDrawable);
        } catch (IOException e) {
            Log.logger().warn("init gifdrawable error so cannot play the animation");
            gifImageView.setImageResource(com.haier.uhome.uplus.phone.R.drawable.loading);
        }
        tvRefresh = new TextView(context);
        tvRefresh.setTextColor(Color.parseColor("#999999"));
        tvRefresh.setTextSize(COMPLEX_UNIT_SP,10);
        addView(gifImageView, DensityUtil.dp2px(35), DensityUtil.dp2px(18)); 
        addView(new View(context), LayoutParams.MATCH_PARENT, DensityUtil.dp2px(6)); 
        addView(tvRefresh, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
        setRefreshHeight();
    }

    protected void setRefreshHeight() {
        setMinimumHeight(DensityUtil.dp2px(60));
    }

    @NonNull
    @Override
    public View getView() {
        return this;
    }

    @NonNull
    @Override
    public SpinnerStyle getSpinnerStyle() {
        return SpinnerStyle.Translate;
    }

    @Override
    public void onStartAnimator(RefreshLayout layout, int headHeight, int maxDragHeight) {

        if (null != gifDrawable) {
            Log.logger().info("onStartAnimator");
            gifDrawable.start();
        }
    }

    @Override
    public int onFinish(RefreshLayout layout, boolean success) {
        if (null != gifImageView) {
            gifDrawable.seekToFrame(0);
            gifDrawable.stop();
        }
        isSuccess = success;
        refreshType = RefreshType.NORMAL;
        return 500;
    }

    @Override
    public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState
            newState) {
        switch (newState) {
            case None:
            case PullDownToRefresh:
                if (null != gifDrawable && gifDrawable.isPlaying()) {
                    gifDrawable.seekToFrame(0);
                    gifDrawable.stop();
                }
                changeRefreshText(RefreshState.PullDownToRefresh);
                break;
            case Refreshing:
                changeRefreshText(RefreshState.Refreshing);
                break;
            case RefreshFinish:
                changeRefreshText(RefreshState.RefreshFinish);
                isSuccess = true;
                break;
            case ReleaseToRefresh:
                changeRefreshText(RefreshState.ReleaseToRefresh);
                break;
            default:
                break;
        }
    }

    private void changeRefreshText(RefreshState state) {
        switch (state) {
            case None:
            case PullDownToRefresh:
                if (refreshType == RefreshType.NORMAL) {
                    tvRefresh.setText("loading");
                } else {
                    tvRefresh.setText("pull to refresh");
                }
                break;
            case Refreshing:
                tvRefresh.setText("loading");
                break;
            case RefreshFinish:
                if (isSuccess) {
                    tvRefresh.setText("loading complete");
                } else {
                    tvRefresh.setText("timeout!");
                }
                break;
            case ReleaseToRefresh:
                if (refreshType == RefreshType.NORMAL) {
                    tvRefresh.setText("release to refresh");
                } else {
                    tvRefresh.setText("loading");
                }
                break;
            default:
                break;
        }
    }
}
coderloveryan commented 5 years ago

I custom a refresh footer use https://github.com/scwang90/SmartRefreshLayout and then in one search page of app, it's no data and wait a few minutes, the device crash. here is the code of activity

class SearchModelActivity : Activity(), SearchModelContract.View, SearchModelContract.AdapterClickListener {

private var refreshLayout: SmartRefreshLayout? = null    private var uplusRefreshFooter: UplusRefreshFooter? = null
...
override fun initView() {
    manual_edit_search?.requestFocus()
    list = findViewById(R.id.manual_brand_items)
    refreshLayout = findViewById(R.id.search_model_view)

    linearLayoutManager = object : LinearLayoutManager(this) {
        override fun canScrollVertically(): Boolean {
            return true
        }
    }
    mAdapter = SearchModelAdapter(adapterDatas, this, this)
    list.apply {
        this.adapter = mAdapter
        this.layoutManager = linearLayoutManager
    }
}
    ...
    refreshLayout?.apply {
        isEnableLoadmore = true
        isEnableRefresh = false
        isEnableAutoLoadmore = false
        setEnableLoadmoreWhenContentNotFull(true)
        refreshFooter = uplusRefreshFooter
        setOnLoadmoreListener {
            if (adapterDatas.size % 20 != 0) {
                uplusRefreshFooter?.setLoadmoreFinished(true)
                finishLoadmore(UplusRefreshUtils.UPLOAD_MORE_DELAY_DURATION,true)
            } else {
                presenter?.loadNextPageData(false, "", manual_edit_search?.text.toString())
            }
        }
    }
    ...

}

coderloveryan commented 5 years ago

gif.zip

koral-- commented 5 years ago

Thanks, I'll investigate it.

koral-- commented 2 years ago

Sorry for the long delay. It seems to be a bug in Skia, fixed in https://android.googlesource.com/platform/external/skia/+/bf999383abd128f8db32fc2f24606679280a5b7d