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

Commit 6e99febd authored by Adrian Roos's avatar Adrian Roos Committed by Android (Google) Code Review
Browse files

Merge "Use actual lockscreen wallpaper" into nyc-dev

parents f498c8dd e381c169
Loading
Loading
Loading
Loading
+124 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.systemui.statusbar.phone;

import android.app.ActivityManager;
import android.app.IWallpaperManager;
import android.app.IWallpaperManagerCallback;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;

import libcore.io.IoUtils;

/**
 * Manages the lockscreen wallpaper.
 */
public class LockscreenWallpaper extends IWallpaperManagerCallback.Stub implements Runnable {

    private static final String TAG = "LockscreenWallpaper";

    private final Context mContext;
    private final PhoneStatusBar mBar;
    private final IWallpaperManager mService;
    private final Handler mH;

    private boolean mCached;
    private Bitmap mCache;
    private int mUserId;

    public LockscreenWallpaper(Context ctx, PhoneStatusBar bar, Handler h) {
        mContext = ctx;
        mBar = bar;
        mH = h;
        mService = IWallpaperManager.Stub.asInterface(
                ServiceManager.getService(Context.WALLPAPER_SERVICE));
        mUserId = ActivityManager.getCurrentUser();

        try {
            mService.setLockWallpaperCallback(this);
        } catch (RemoteException e) {
            Log.e(TAG, "System dead?" + e);
        }
    }

    public Bitmap getBitmap() {
        try {
            if (mCached) {
                return mCache;
            }
            if (!mService.isWallpaperSupported(mContext.getOpPackageName())) {
                mCached = true;
                mCache = null;
                return null;
            }
            ParcelFileDescriptor fd = mService.getWallpaper(null, WallpaperManager.FLAG_SET_LOCK,
                    new Bundle(), mUserId);
            if (fd != null) {
                try {
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    mCache = BitmapFactory.decodeFileDescriptor(
                            fd.getFileDescriptor(), null, options);
                    mCached = true;
                    return mCache;
                } catch (OutOfMemoryError e) {
                    Log.w(TAG, "Can't decode file", e);
                    return null;
                } finally {
                    IoUtils.closeQuietly(fd);
                }
            } else {
                mCached = true;
                mCache = null;
                return null;
            }
        } catch (RemoteException e) {
            Log.e(TAG, "System dead?" + e);
            return null;
        }
    }

    public void setUser(int user) {
        if (user != mUserId) {
            mCached = false;
            mUserId = user;
        }
    }

    @Override
    public void onWallpaperChanged() {
        // Called on Binder thread.
        mH.removeCallbacks(this);
        mH.post(this);
    }

    @Override
    public void run() {
        // Called in response to onWallpaperChanged on the main thread.
        mCached = false;
        mCache = null;
        getBitmap();
        mBar.updateMediaMetaData(true /* metaDataChanged */, true /* allowEnterAnimation */);
    }
}
+10 −12
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.app.IWallpaperManagerCallback;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.StatusBarManager;
@@ -248,9 +249,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    private static final boolean ONLY_CORE_APPS;

    /** If true, the lockscreen will show a distinct wallpaper */
    private static final boolean ENABLE_LOCKSCREEN_WALLPAPER =
            !ActivityManager.isLowRamDeviceStatic()
                    && SystemProperties.getBoolean("debug.lockscreen_wallpaper", false);
    private static final boolean ENABLE_LOCKSCREEN_WALLPAPER = true;

    /* If true, the device supports freeform window management.
     * This affects the status bar UI. */
@@ -296,6 +295,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    AccessibilityController mAccessibilityController;
    FingerprintUnlockController mFingerprintUnlockController;
    LightStatusBarController mLightStatusBarController;
    private LockscreenWallpaper mLockscreenWallpaper;

    int mNaturalBarHeight = -1;

@@ -792,6 +792,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
                mKeyguardBottomArea.getLockIcon());
        mKeyguardBottomArea.setKeyguardIndicationController(mKeyguardIndicationController);

        if (ENABLE_LOCKSCREEN_WALLPAPER) {
            mLockscreenWallpaper = new LockscreenWallpaper(mContext, this, mHandler);
        }

        // set the initial view visibility
        setAreThereNotifications();

@@ -1819,7 +1823,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    };

    /**
     * Refresh or remove lockscreen artwork from media metadata.
     * Refresh or remove lockscreen artwork from media metadata or the lockscreen wallpaper.
     */
    public void updateMediaMetaData(boolean metaDataChanged, boolean allowEnterAnimation) {
        if (!SHOW_LOCKSCREEN_MEDIA_ARTWORK) return;
@@ -1847,10 +1851,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            }
        }
        if (ENABLE_LOCKSCREEN_WALLPAPER && artworkBitmap == null) {
            // TODO: use real lockscreen wallpaper.
            WallpaperManager wallpaperManager = mContext
                    .getSystemService(WallpaperManager.class);
            artworkBitmap = wallpaperManager.getBitmap();
            artworkBitmap = mLockscreenWallpaper.getBitmap();
        }

        final boolean hasArtwork = artworkBitmap != null;
@@ -3084,10 +3085,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            else if (Intent.ACTION_SCREEN_ON.equals(action)) {
                notifyNavigationBarScreenOn(true);
            }
            else if (ENABLE_LOCKSCREEN_WALLPAPER
                    && Intent.ACTION_WALLPAPER_CHANGED.equals(action)) {
                updateMediaMetaData(true, true);
            }
        }
    };

@@ -3173,6 +3170,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        resetUserSetupObserver();
        setControllerUsers();
        clearCurrentMediaNotification();
        mLockscreenWallpaper.setUser(newUserId);
        updateMediaMetaData(true, false);
    }