NAS setting migration

Cancel onboarding notification when user migrates from settings

Test: make RunSettingsRoboTests
Bug: 185428329
Change-Id: I8b6b2eb8340442907c363e686bbd0b32b62d0db0
This commit is contained in:
Chloris Kuo
2021-04-20 19:03:56 -07:00
parent 2affde3202
commit f06f289a85
3 changed files with 9 additions and 13 deletions

View File

@@ -77,11 +77,7 @@ public class NotificationAssistantPreferenceController extends TogglePreferenceC
protected void setNotificationAssistantGranted(ComponentName cn) { protected void setNotificationAssistantGranted(ComponentName cn) {
if (Settings.Secure.getIntForUser(mContext.getContentResolver(), if (Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 0, mUserId) == 0) { Settings.Secure.NAS_SETTINGS_UPDATED, 0, mUserId) == 0) {
for (int profileId : mUserManager.getProfileIds(mUserId, false)) { mNotificationBackend.setNASMigrationDoneAndResetDefault(mUserId, cn != null);
Settings.Secure.putIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 1, profileId);
}
mNotificationBackend.resetDefaultNotificationAssistant(cn != null);
} }
mNotificationBackend.setNotificationAssistantGranted(cn); mNotificationBackend.setNotificationAssistantGranted(cn);
} }

View File

@@ -570,9 +570,9 @@ public class NotificationBackend {
} }
} }
public void resetDefaultNotificationAssistant(boolean loadFromConfig) { public void setNASMigrationDoneAndResetDefault(int userId, boolean loadFromConfig) {
try { try {
sINM.resetDefaultNotificationAssistant(loadFromConfig); sINM.setNASMigrationDoneAndResetDefault(userId, loadFromConfig);
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Error calling NoMan", e); Log.w(TAG, "Error calling NoMan", e);
} }

View File

@@ -122,13 +122,13 @@ public class NotificationAssistantPreferenceControllerTest {
assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(), assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 0, 10)); Settings.Secure.NAS_SETTINGS_UPDATED, 0, 10));
verify(mBackend, times(1)) verify(mBackend, times(1))
.resetDefaultNotificationAssistant(eq(true)); .setNASMigrationDoneAndResetDefault(eq(0), eq(true));
//Test user enable again, migration should not happen //Test user enable again, migration should not happen
mPreferenceController.setNotificationAssistantGranted(mNASComponent); mPreferenceController.setNotificationAssistantGranted(mNASComponent);
//Number of invocations should not increase //Number of invocations should not increase
verify(mBackend, times(1)) verify(mBackend, times(1))
.resetDefaultNotificationAssistant(eq(true)); .setNASMigrationDoneAndResetDefault(eq(0), eq(true));
} }
@Test @Test
@@ -146,13 +146,13 @@ public class NotificationAssistantPreferenceControllerTest {
assertEquals(0, Settings.Secure.getIntForUser(mContext.getContentResolver(), assertEquals(0, Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 0, 20)); Settings.Secure.NAS_SETTINGS_UPDATED, 0, 20));
verify(mBackend, times(1)) verify(mBackend, times(1))
.resetDefaultNotificationAssistant(eq(true)); .setNASMigrationDoneAndResetDefault(eq(0), eq(true));
//Test user enable again, migration should not happen //Test user enable again, migration should not happen
mPreferenceController.setNotificationAssistantGranted(mNASComponent); mPreferenceController.setNotificationAssistantGranted(mNASComponent);
//Number of invocations should not increase //Number of invocations should not increase
verify(mBackend, times(1)) verify(mBackend, times(1))
.resetDefaultNotificationAssistant(eq(true)); .setNASMigrationDoneAndResetDefault(eq(0), eq(true));
} }
@Test @Test
@@ -170,13 +170,13 @@ public class NotificationAssistantPreferenceControllerTest {
assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(), assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 0, 10)); Settings.Secure.NAS_SETTINGS_UPDATED, 0, 10));
verify(mBackend, times(1)) verify(mBackend, times(1))
.resetDefaultNotificationAssistant(eq(false)); .setNASMigrationDoneAndResetDefault(eq(0), eq(false));
//Test user disable again, migration should not happen //Test user disable again, migration should not happen
mPreferenceController.setChecked(false); mPreferenceController.setChecked(false);
//Number of invocations should not increase //Number of invocations should not increase
verify(mBackend, times(1)) verify(mBackend, times(1))
.resetDefaultNotificationAssistant(eq(false)); .setNASMigrationDoneAndResetDefault(eq(0), eq(false));
} }
} }