From 9bf2271511b577b4d0e37b44adcd71d6eb7ed974 Mon Sep 17 00:00:00 2001 From: songjinshi Date: Sat, 4 Feb 2017 10:47:45 +0800 Subject: [PATCH] [NotificationManagerService]: Fixes the thread-safe issue. Add missed sync for backup realted access. https://code.google.com/p/android/issues/detail?id=233435 Change-Id: I8499f79f491cec545d348bc9c3204aa79ccb6706 Signed-off-by: songjinshi --- .../NotificationManagerService.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index d31c7b54cee5d..22c5e853819fc 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2078,12 +2078,14 @@ public class NotificationManagerService extends SystemService { Slog.w(TAG, "getBackupPayload: cannot backup policy for user " + user); return null; } - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - writePolicyXml(baos, true /*forBackup*/); - return baos.toByteArray(); - } catch (IOException e) { - Slog.w(TAG, "getBackupPayload: error writing payload for user " + user, e); + synchronized(mPolicyFile) { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + writePolicyXml(baos, true /*forBackup*/); + return baos.toByteArray(); + } catch (IOException e) { + Slog.w(TAG, "getBackupPayload: error writing payload for user " + user, e); + } } return null; } @@ -2101,12 +2103,14 @@ public class NotificationManagerService extends SystemService { Slog.w(TAG, "applyRestore: cannot restore policy for user " + user); return; } - final ByteArrayInputStream bais = new ByteArrayInputStream(payload); - try { - readPolicyXml(bais, true /*forRestore*/); - savePolicyFile(); - } catch (NumberFormatException | XmlPullParserException | IOException e) { - Slog.w(TAG, "applyRestore: error reading payload", e); + synchronized(mPolicyFile) { + final ByteArrayInputStream bais = new ByteArrayInputStream(payload); + try { + readPolicyXml(bais, true /*forRestore*/); + savePolicyFile(); + } catch (NumberFormatException | XmlPullParserException | IOException e) { + Slog.w(TAG, "applyRestore: error reading payload", e); + } } }