Merge "Persist pending notification history on shutdown" into rvc-dev am: f460a9cd1f am: b5fe464ea0

Change-Id: I4034d2313069af2a28591c92d942ec6b0bea2d14
This commit is contained in:
Automerger Merge Worker
2020-03-04 17:29:35 +00:00
6 changed files with 12 additions and 6 deletions

View File

@@ -87,4 +87,6 @@ public interface NotificationDelegate {
*/ */
void onNotificationSmartReplySent(String key, int clickedIndex, CharSequence reply, void onNotificationSmartReplySent(String key, int clickedIndex, CharSequence reply,
int notificationLocation, boolean modifiedBeforeSending); int notificationLocation, boolean modifiedBeforeSending);
void prepareForPossibleShutdown();
} }

View File

@@ -157,9 +157,7 @@ public class NotificationHistoryDatabase {
} }
public void forceWriteToDisk() { public void forceWriteToDisk() {
if (!mFileWriteHandler.hasCallbacks(mWriteBufferRunnable)) { mFileWriteHandler.post(mWriteBufferRunnable);
mFileWriteHandler.post(mWriteBufferRunnable);
}
} }
public void onPackageRemoved(String packageName) { public void onPackageRemoved(String packageName) {

View File

@@ -181,7 +181,6 @@ public class NotificationHistoryManager {
} }
} }
// TODO: wire this up to AMS when power button is long pressed
public void triggerWriteToDisk() { public void triggerWriteToDisk() {
synchronized (mLock) { synchronized (mLock) {
final int userCount = mUserState.size(); final int userCount = mUserState.size();

View File

@@ -875,6 +875,11 @@ public class NotificationManagerService extends SystemService {
@VisibleForTesting @VisibleForTesting
final NotificationDelegate mNotificationDelegate = new NotificationDelegate() { final NotificationDelegate mNotificationDelegate = new NotificationDelegate() {
@Override
public void prepareForPossibleShutdown() {
mHistoryManager.triggerWriteToDisk();
}
@Override @Override
public void onSetDisabled(int status) { public void onSetDisabled(int status) {
synchronized (mNotificationLock) { synchronized (mNotificationLock) {

View File

@@ -1169,6 +1169,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
enforceStatusBarService(); enforceStatusBarService();
long identity = Binder.clearCallingIdentity(); long identity = Binder.clearCallingIdentity();
try { try {
mNotificationDelegate.prepareForPossibleShutdown();
// ShutdownThread displays UI, so give it a UI context. // ShutdownThread displays UI, so give it a UI context.
mHandler.post(() -> mHandler.post(() ->
ShutdownThread.shutdown(getUiContext(), ShutdownThread.shutdown(getUiContext(),
@@ -1186,6 +1187,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub implements D
enforceStatusBarService(); enforceStatusBarService();
long identity = Binder.clearCallingIdentity(); long identity = Binder.clearCallingIdentity();
try { try {
mNotificationDelegate.prepareForPossibleShutdown();
mHandler.post(() -> { mHandler.post(() -> {
// ShutdownThread displays UI, so give it a UI context. // ShutdownThread displays UI, so give it a UI context.
if (safeMode) { if (safeMode) {

View File

@@ -162,10 +162,10 @@ public class NotificationHistoryDatabaseTest extends UiServiceTestCase {
} }
@Test @Test
public void testOnlyOneWriteRunnableInQueue() { public void testForceWriteToDisk_bypassesExistingWrites() {
when(mFileWriteHandler.hasCallbacks(any())).thenReturn(true); when(mFileWriteHandler.hasCallbacks(any())).thenReturn(true);
mDataBase.forceWriteToDisk(); mDataBase.forceWriteToDisk();
verify(mFileWriteHandler, never()).post(any()); verify(mFileWriteHandler, times(1)).post(any());
} }
@Test @Test