summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/notification.aconfig7
-rw-r--r--services/core/java/com/android/server/backup/SystemBackupAgent.java1
-rw-r--r--services/core/java/com/android/server/notification/NotificationBackupHelper.java (renamed from core/java/com/android/server/backup/NotificationBackupHelper.java)28
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerInternal.java6
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java47
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java15
6 files changed, 83 insertions, 21 deletions
diff --git a/core/java/android/app/notification.aconfig b/core/java/android/app/notification.aconfig
index 4ec869a143c3..11e885055162 100644
--- a/core/java/android/app/notification.aconfig
+++ b/core/java/android/app/notification.aconfig
@@ -272,3 +272,10 @@ flag {
description: "[RONs] Guards new promotion logic and UI, including AOD notification and Colorization"
bug: "367705002"
}
+
+flag {
+ name: "backup_restore_logging"
+ namespace: "systemui"
+ description: "Adds logging for notification/modes backup and restore events"
+ bug: "289524803"
+} \ No newline at end of file
diff --git a/services/core/java/com/android/server/backup/SystemBackupAgent.java b/services/core/java/com/android/server/backup/SystemBackupAgent.java
index 1ea72d7da2fc..f66c7e115fc0 100644
--- a/services/core/java/com/android/server/backup/SystemBackupAgent.java
+++ b/services/core/java/com/android/server/backup/SystemBackupAgent.java
@@ -36,6 +36,7 @@ import android.os.UserManager;
import android.util.Slog;
import com.android.server.backup.Flags;
+import com.android.server.notification.NotificationBackupHelper;
import com.google.android.collect.Sets;
diff --git a/core/java/com/android/server/backup/NotificationBackupHelper.java b/services/core/java/com/android/server/notification/NotificationBackupHelper.java
index faa0509086fc..ee9ec159a5e0 100644
--- a/core/java/com/android/server/backup/NotificationBackupHelper.java
+++ b/services/core/java/com/android/server/notification/NotificationBackupHelper.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.server.backup;
+package com.android.server.notification;
import android.app.INotificationManager;
import android.app.backup.BlobBackupHelper;
@@ -22,6 +22,8 @@ import android.os.ServiceManager;
import android.util.Log;
import android.util.Slog;
+import com.android.server.LocalServices;
+
public class NotificationBackupHelper extends BlobBackupHelper {
static final String TAG = "NotifBackupHelper"; // must be < 23 chars
static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -34,9 +36,13 @@ public class NotificationBackupHelper extends BlobBackupHelper {
private final int mUserId;
+ private final NotificationManagerInternal mNm;
+
public NotificationBackupHelper(int userId) {
super(BLOB_VERSION, KEY_NOTIFICATIONS);
mUserId = userId;
+
+ mNm = LocalServices.getService(NotificationManagerInternal.class);
}
@Override
@@ -44,9 +50,13 @@ public class NotificationBackupHelper extends BlobBackupHelper {
byte[] newPayload = null;
if (KEY_NOTIFICATIONS.equals(key)) {
try {
- INotificationManager nm = INotificationManager.Stub.asInterface(
- ServiceManager.getService("notification"));
- newPayload = nm.getBackupPayload(mUserId);
+ if (android.app.Flags.backupRestoreLogging()) {
+ newPayload = mNm.getBackupPayload(mUserId, getLogger());
+ } else {
+ INotificationManager nm = INotificationManager.Stub.asInterface(
+ ServiceManager.getService("notification"));
+ newPayload = nm.getBackupPayload(mUserId);
+ }
} catch (Exception e) {
// Treat as no data
Slog.e(TAG, "Couldn't communicate with notification manager", e);
@@ -64,9 +74,13 @@ public class NotificationBackupHelper extends BlobBackupHelper {
if (KEY_NOTIFICATIONS.equals(key)) {
try {
- INotificationManager nm = INotificationManager.Stub.asInterface(
- ServiceManager.getService("notification"));
- nm.applyRestore(payload, mUserId);
+ if (android.app.Flags.backupRestoreLogging()) {
+ mNm.applyRestore(payload, mUserId, getLogger());
+ } else {
+ INotificationManager nm = INotificationManager.Stub.asInterface(
+ ServiceManager.getService("notification"));
+ nm.applyRestore(payload, mUserId);
+ }
} catch (Exception e) {
Slog.e(TAG, "Couldn't communicate with notification manager", e);
}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerInternal.java b/services/core/java/com/android/server/notification/NotificationManagerInternal.java
index 4b8de4e8c6f1..f3d6a2dd0a75 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerInternal.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerInternal.java
@@ -19,6 +19,7 @@ package com.android.server.notification;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
+import android.app.backup.BackupRestoreEventLogger;
import android.service.notification.DeviceEffectsApplier;
import java.util.Set;
@@ -73,4 +74,9 @@ public interface NotificationManagerInternal {
* Otherwise an {@link IllegalStateException} will be thrown.
*/
void setDeviceEffectsApplier(DeviceEffectsApplier applier);
+
+ // Backup/restore interface
+ byte[] getBackupPayload(int user, BackupRestoreEventLogger logger);
+
+ void applyRestore(byte[] payload, int user, BackupRestoreEventLogger logger);
}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 88334ebe2abb..4342abf111ff 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -216,6 +216,7 @@ import android.app.StatsManager;
import android.app.UriGrantsManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.backup.BackupManager;
+import android.app.backup.BackupRestoreEventLogger;
import android.app.compat.CompatChanges;
import android.app.role.OnRoleHoldersChangedListener;
import android.app.role.RoleManager;
@@ -1102,7 +1103,8 @@ public class NotificationManagerService extends SystemService {
return false;
}
- void readPolicyXml(InputStream stream, boolean forRestore, int userId)
+ void readPolicyXml(InputStream stream, boolean forRestore, int userId,
+ BackupRestoreEventLogger logger)
throws XmlPullParserException, NumberFormatException, IOException {
final TypedXmlPullParser parser;
if (forRestore) {
@@ -1189,7 +1191,7 @@ public class NotificationManagerService extends SystemService {
InputStream infile = null;
try {
infile = mPolicyFile.openRead();
- readPolicyXml(infile, false /*forRestore*/, USER_ALL);
+ readPolicyXml(infile, false /*forRestore*/, USER_ALL, null);
// We re-load the default dnd packages to allow the newly added and denined.
final boolean isWatch = mPackageManagerClient.hasSystemFeature(
@@ -1239,7 +1241,7 @@ public class NotificationManagerService extends SystemService {
}
try {
- writePolicyXml(stream, false /*forBackup*/, USER_ALL);
+ writePolicyXml(stream, false /*forBackup*/, USER_ALL, null);
mPolicyFile.finishWrite(stream);
} catch (IOException e) {
Slog.w(TAG, "Failed to save policy file, restoring backup", e);
@@ -1250,8 +1252,8 @@ public class NotificationManagerService extends SystemService {
}
}
- private void writePolicyXml(OutputStream stream, boolean forBackup, int userId)
- throws IOException {
+ private void writePolicyXml(OutputStream stream, boolean forBackup, int userId,
+ BackupRestoreEventLogger logger) throws IOException {
final TypedXmlSerializer out;
if (forBackup) {
out = Xml.newFastSerializer();
@@ -6171,7 +6173,7 @@ public class NotificationManagerService extends SystemService {
if (DBG) Slog.d(TAG, "getBackupPayload u=" + user);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
- writePolicyXml(baos, true /*forBackup*/, user);
+ writePolicyXml(baos, true /*forBackup*/, user, null);
return baos.toByteArray();
} catch (IOException e) {
Slog.w(TAG, "getBackupPayload: error writing payload for user " + user, e);
@@ -6190,7 +6192,7 @@ public class NotificationManagerService extends SystemService {
}
final ByteArrayInputStream bais = new ByteArrayInputStream(payload);
try {
- readPolicyXml(bais, true /*forRestore*/, user);
+ readPolicyXml(bais, true /*forRestore*/, user, null);
handleSavePolicyFile();
} catch (NumberFormatException | XmlPullParserException | IOException e) {
Slog.w(TAG, "applyRestore: error reading payload", e);
@@ -7392,6 +7394,37 @@ public class NotificationManagerService extends SystemService {
*/
private final NotificationManagerInternal mInternalService = new NotificationManagerInternal() {
+ public byte[] getBackupPayload(int user, BackupRestoreEventLogger logger) {
+ checkCallerIsSystem();
+ if (DBG) Slog.d(TAG, "getBackupPayload u=" + user);
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ writePolicyXml(baos, true /*forBackup*/, user, logger);
+ return baos.toByteArray();
+ } catch (IOException e) {
+ Slog.w(TAG, "getBackupPayload: error writing payload for user " + user, e);
+ }
+ return null;
+ }
+
+ @Override
+ public void applyRestore(byte[] payload, int user, BackupRestoreEventLogger logger) {
+ checkCallerIsSystem();
+ if (DBG) Slog.d(TAG, "applyRestore u=" + user + " payload="
+ + (payload != null ? new String(payload, StandardCharsets.UTF_8) : null));
+ if (payload == null) {
+ Slog.w(TAG, "applyRestore: no payload to restore for user " + user);
+ return;
+ }
+ final ByteArrayInputStream bais = new ByteArrayInputStream(payload);
+ try {
+ readPolicyXml(bais, true /*forRestore*/, user, logger);
+ handleSavePolicyFile();
+ } catch (NumberFormatException | XmlPullParserException | IOException e) {
+ Slog.w(TAG, "applyRestore: error reading payload", e);
+ }
+ }
+
@Override
public NotificationChannel getNotificationChannel(String pkg, int uid, String
channelId) {
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 1349ee04696d..becb9fdabfcf 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -201,6 +201,7 @@ import android.app.RemoteInput;
import android.app.RemoteInputHistoryItem;
import android.app.StatsManager;
import android.app.admin.DevicePolicyManagerInternal;
+import android.app.backup.BackupRestoreEventLogger;
import android.app.job.JobScheduler;
import android.app.role.RoleManager;
import android.app.usage.UsageStatsManagerInternal;
@@ -6340,7 +6341,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(upgradeXml.getBytes())),
false,
- UserHandle.USER_ALL);
+ UserHandle.USER_ALL, null);
verify(mListeners, times(1)).readXml(any(), any(), anyBoolean(), anyInt());
verify(mConditionProviders, times(1)).readXml(any(), any(), anyBoolean(), anyInt());
verify(mAssistants, times(1)).readXml(any(), any(), anyBoolean(), anyInt());
@@ -6360,7 +6361,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(upgradeXml.getBytes())),
false,
- UserHandle.USER_ALL);
+ UserHandle.USER_ALL, null);
verify(mSnoozeHelper, times(1)).readXml(any(TypedXmlPullParser.class), anyLong());
}
@@ -6372,7 +6373,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(preupgradeXml.getBytes())),
false,
- UserHandle.USER_ALL);
+ UserHandle.USER_ALL, null);
verify(mListeners, never()).readXml(any(), any(), anyBoolean(), anyInt());
verify(mConditionProviders, never()).readXml(any(), any(), anyBoolean(), anyInt());
verify(mAssistants, never()).readXml(any(), any(), anyBoolean(), anyInt());
@@ -6404,7 +6405,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(policyXml.getBytes())),
true,
- 10);
+ 10, null);
verify(mListeners, never()).readXml(any(), any(), eq(true), eq(10));
verify(mConditionProviders, never()).readXml(any(), any(), eq(true), eq(10));
verify(mAssistants, never()).readXml(any(), any(), eq(true), eq(10));
@@ -6430,7 +6431,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(policyXml.getBytes())),
true,
- 10);
+ 10, null);
verify(mListeners, never()).readXml(any(), any(), eq(true), eq(10));
verify(mConditionProviders, never()).readXml(any(), any(), eq(true), eq(10));
verify(mAssistants, never()).readXml(any(), any(), eq(true), eq(10));
@@ -6458,7 +6459,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(policyXml.getBytes())),
true,
- 10);
+ 10, null);
verify(mListeners, never()).readXml(any(), any(), eq(true), eq(10));
verify(mConditionProviders, never()).readXml(any(), any(), eq(true), eq(10));
verify(mAssistants, never()).readXml(any(), any(), eq(true), eq(10));
@@ -6485,7 +6486,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(policyXml.getBytes())),
true,
- 10);
+ 10, null);
verify(mListeners, times(1)).readXml(any(), any(), eq(true), eq(10));
verify(mConditionProviders, times(1)).readXml(any(), any(), eq(true), eq(10));
verify(mAssistants, times(1)).readXml(any(), any(), eq(true), eq(10));