From 38a5dc33a9140a7bfd90cfa58185d357ab3df8f9 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Wed, 20 Jul 2016 15:10:18 -0700 Subject: [PATCH] Run the SELinux wallpaper restorecon operations on all users And only run them once per device boot lifetime. Bug 30229410 Change-Id: Ia6f7f7eea7f8985c83b531dfa16e96d08235b901 --- .../wallpaper/WallpaperManagerService.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index f7a92fe7d952c..75f6120c51e2b 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -487,6 +487,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub { final SparseArray mWallpaperMap = new SparseArray(); final SparseArray mLockWallpaperMap = new SparseArray(); + final SparseArray mUserRestorecon = new SparseArray(); int mCurrentUserId; static class WallpaperData { @@ -944,26 +945,32 @@ public class WallpaperManagerService extends IWallpaperManager.Stub { void onUnlockUser(final int userId) { synchronized (mLock) { - if (mCurrentUserId == userId && mWaitingForUnlock) { - switchUser(userId, null); + if (mCurrentUserId == userId) { + if (mWaitingForUnlock) { + // If we're switching users, now is when we transition the wallpaper + switchUser(userId, null); + } // Make sure that the SELinux labeling of all the relevant files is correct. // This corrects for mislabeling bugs that might have arisen from move-to // operations involving the wallpaper files. This isn't timing-critical, // so we do it in the background to avoid holding up the user unlock operation. - Runnable relabeler = new Runnable() { - @Override - public void run() { - final File wallpaperDir = getWallpaperDir(userId); - for (String filename : sPerUserFiles) { - File f = new File(wallpaperDir, filename); - if (f.exists()) { - SELinux.restorecon(f); + if (mUserRestorecon.get(userId) != Boolean.TRUE) { + mUserRestorecon.put(userId, Boolean.TRUE); + Runnable relabeler = new Runnable() { + @Override + public void run() { + final File wallpaperDir = getWallpaperDir(userId); + for (String filename : sPerUserFiles) { + File f = new File(wallpaperDir, filename); + if (f.exists()) { + SELinux.restorecon(f); + } } } - } - }; - BackgroundThread.getHandler().post(relabeler); + }; + BackgroundThread.getHandler().post(relabeler); + } } } }