Fix NPE in SyncManager#isSyncSetting.

Fixes: 183243522
Test: atest SyncManagerTest
Change-Id: I8df3d2cd590e448c92035a422430b4011e378dba
This commit is contained in:
Varun Shah
2021-03-22 20:50:15 -07:00
parent c3f3255c38
commit 32fea82fc5
2 changed files with 21 additions and 0 deletions

View File

@@ -3978,6 +3978,9 @@ public class SyncManager {
* @return true if the provided key is used by the SyncManager in scheduling the sync.
*/
private static boolean isSyncSetting(String key) {
if (key == null) {
return false;
}
if (key.equals(ContentResolver.SYNC_EXTRAS_EXPEDITED)) {
return true;
}

View File

@@ -16,6 +16,7 @@
package com.android.server.content;
import android.content.ContentResolver;
import android.os.Bundle;
import android.test.suitebuilder.annotation.SmallTest;
@@ -57,6 +58,23 @@ public class SyncManagerTest extends TestCase {
SyncManager.syncExtrasEquals(b1, b2, false /* don't care about system extras */));
}
public void testSyncExtrasEqualsFails_WithNull() throws Exception {
Bundle b1 = new Bundle();
b1.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
b1.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
Bundle b2 = new Bundle();
b2.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
b2.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
b2.putString(null, "Hello NPE!");
b2.putString("a", "b");
b2.putString("c", "d");
b2.putString("e", "f");
assertFalse("Extras not properly compared between bundles.",
SyncManager.syncExtrasEquals(b1, b2, false /* don't care about system extras */));
}
public void testSyncExtrasEqualsFails_differentValues() throws Exception {
Bundle b1 = new Bundle();
Bundle b2 = new Bundle();