Florian Eisl | f2b92fb | 2018-11-16 17:35:22 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import android.app.ActivityThread; |
| 20 | import android.app.WallpaperManager; |
| 21 | import android.content.BroadcastReceiver; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.graphics.Bitmap; |
| 25 | import android.os.AsyncTask; |
| 26 | import android.util.Slog; |
| 27 | |
| 28 | /** |
| 29 | * Receiver responsible for updating the wallpaper when the device |
| 30 | * configuration has changed. |
| 31 | * |
| 32 | * @hide |
| 33 | */ |
| 34 | public class WallpaperUpdateReceiver extends BroadcastReceiver { |
| 35 | |
| 36 | private static final String TAG = "WallpaperUpdateReceiver"; |
| 37 | private static final boolean DEBUG = false; |
| 38 | |
| 39 | @Override |
| 40 | public void onReceive(final Context context, final Intent intent) { |
| 41 | if (DEBUG) Slog.d(TAG, "onReceive: " + intent); |
| 42 | |
| 43 | if (intent != null && Intent.ACTION_DEVICE_CUSTOMIZATION_READY.equals(intent.getAction())) { |
| 44 | AsyncTask.execute(this::updateWallpaper); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | private void updateWallpaper() { |
| 49 | try { |
| 50 | ActivityThread currentActivityThread = ActivityThread.currentActivityThread(); |
| 51 | Context uiContext = currentActivityThread.getSystemUiContext(); |
| 52 | WallpaperManager wallpaperManager = WallpaperManager.getInstance(uiContext); |
| 53 | if (DEBUG) Slog.d(TAG, "Set customized default_wallpaper."); |
| 54 | Bitmap blank = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8); |
| 55 | // set a blank wallpaper to force a redraw of default_wallpaper |
| 56 | wallpaperManager.setBitmap(blank); |
| 57 | wallpaperManager.setResource(com.android.internal.R.drawable.default_wallpaper); |
| 58 | } catch (Exception e) { |
| 59 | Slog.w(TAG, "Failed to customize system wallpaper." + e); |
| 60 | } |
| 61 | } |
| 62 | } |