android 8.1 开机壁纸下半部分黑屏2-3秒的问题解决

本文介绍了一个将原有异步加载壁纸的方法改为同步实现的过程。通过直接调用获取壁纸位图的方法,替代了使用 AsyncTask 进行后台加载的方式。该更改简化了代码流程并有助于测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/ImageWallpaper.java
private void loadWallpaper(boolean needsDraw, boolean needsReset)
上方法的异步改为同步进行测试(目的是将异步改为同步

	        private void loadWallpaper(boolean needsDraw, boolean needsReset) {
        mNeedsDrawAfterLoadingWallpaper |= needsDraw;
        if (mLoader != null) {
            if (needsReset) {
                mLoader.cancel(false /* interrupt */);
                mLoader = null;
            } else {
                if (DEBUG) {
                    Log.d(TAG, "Skipping loadWallpaper, already in flight ");
                }
                return;
            }
        }
        /* SUN:jicong.wang remove for ALPS03943376
        mLoader = new AsyncTask<Void, Void, Bitmap>() {
            @Override
            protected Bitmap doInBackground(Void... params) {
                Throwable exception;
                try {
                    if (needsReset) {
                        mWallpaperManager.forgetLoadedWallpaper();
                    }
                    return mWallpaperManager.getBitmap();
                } catch (RuntimeException | OutOfMemoryError e) {
                    exception = e;
                }

                if (isCancelled()) {
                    return null;
                }

                if (exception != null) {
                    // Note that if we do fail at this, and the default wallpaper can't
                    // be loaded, we will go into a cycle.  Don't do a build where the
                    // default wallpaper can't be loaded.
                    Log.w(TAG, "Unable to load wallpaper!", exception);
                    try {
                        mWallpaperManager.clear();
                    } catch (IOException ex) {
                        // now we're really screwed.
                        Log.w(TAG, "Unable reset to default wallpaper!", ex);
                    }

                    if (isCancelled()) {
                        return null;
                    }

                    try {
                        return mWallpaperManager.getBitmap();
                    } catch (RuntimeException | OutOfMemoryError e) {
                        Log.w(TAG, "Unable to load default wallpaper!", e);
                    }
                }
                return null;
            }

            @Override
            protected void onPostExecute(Bitmap b) {
                mBackground = null;
                mBackgroundWidth = -1;
                mBackgroundHeight = -1;

                if (b != null) {
                    mBackground = b;
                    mBackgroundWidth = mBackground.getWidth();
                    mBackgroundHeight = mBackground.getHeight();
                }

                if (DEBUG) {
                    Log.d(TAG, "Wallpaper loaded: " + mBackground);
                }
                updateSurfaceSize(getSurfaceHolder(), getDefaultDisplayInfo(),
                        false );
                if (mNeedsDrawAfterLoadingWallpaper) {
                    drawFrame();
                }

                mLoader = null;
                mNeedsDrawAfterLoadingWallpaper = false;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        */
        /*SUN:jicong.wang add start ALPS03943376 {@*/
        Bitmap  b = null;
        Throwable exception = null;
        try {
            if (needsReset) {
                mWallpaperManager.forgetLoadedWallpaper();
            }
            b =  mWallpaperManager.getBitmap();
        } catch (RuntimeException | OutOfMemoryError e) {
            exception = e;
        }

        if (exception != null) {
            // Note that if we do fail at this, and the default wallpaper can't
            // be loaded, we will go into a cycle.  Don't do a build where the
            // default wallpaper can't be loaded.
            Log.w(TAG, "Unable to load wallpaper!", exception);
            try {
                mWallpaperManager.clear();
            } catch (IOException ex) {
                // now we're really screwed.
                Log.w(TAG, "Unable reset to default wallpaper!", ex);
            }


            try {
                b =  mWallpaperManager.getBitmap();
            } catch (RuntimeException | OutOfMemoryError e) {
                Log.w(TAG, "Unable to load default wallpaper!", e);
            }
        }
        
        mBackground = null;
        mBackgroundWidth = -1;
        mBackgroundHeight = -1;

        if (b != null) {
            mBackground = b;
            mBackgroundWidth = mBackground.getWidth();
            mBackgroundHeight = mBackground.getHeight();
        }

        if (DEBUG) {
            Log.d(TAG, "Wallpaper loaded: " + mBackground);
        }
        updateSurfaceSize(getSurfaceHolder(), getDefaultDisplayInfo(),
                false );
        if (mNeedsDrawAfterLoadingWallpaper) {
            drawFrame();
        }

        mLoader = null;
        mNeedsDrawAfterLoadingWallpaper = false;    
        /*SUN:jicong.wang add end ALPS03943376 @}*/           
    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值