美文网首页
开机壁纸下半部分黑屏2-3秒

开机壁纸下半部分黑屏2-3秒

作者: 梧叶已秋声 | 来源:发表于2021-01-12 11:08 被阅读0次

    屏蔽掉AsyncTask,将异步改为同步,可能由于机器性能原因导致下半部分黑屏(加载太慢了)。

    //vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/ImageWallpaper.java
            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;
                    }
                }
             /*   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 *//* forDraw *//*);
                        if (mNeedsDrawAfterLoadingWallpaper) {
                            drawFrame();
                        }
    
                        mLoader = null;
                        mNeedsDrawAfterLoadingWallpaper = false;
                    }
                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);*/
                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;
            }
    

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

    相关文章

      网友评论

          本文标题:开机壁纸下半部分黑屏2-3秒

          本文链接:https://www.haomeiwen.com/subject/xgssaktx.html