From 9fb316de8b7c2f8ab2973465702855b13e3400ce Mon Sep 17 00:00:00 2001 From: songferngwang Date: Thu, 25 Jul 2024 10:18:41 +0000 Subject: [PATCH] Can not reset the sim name in the onboarding sim flow After the sim name has been changed, the user changed back to original one. The map did not remove the sim item, so the onboarding flow change the sim name. Bug: 355138239 Flag: EXEMPT bugfix Test: atest SimOnboardingServiceTest Change-Id: If4276320c939604b48cf2ce8c1b6b553da699c28 --- .../settings/network/SimOnboardingService.kt | 1 + .../network/SimOnboardingServiceTest.kt | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/spa_unit/src/com/android/settings/network/SimOnboardingServiceTest.kt diff --git a/src/com/android/settings/network/SimOnboardingService.kt b/src/com/android/settings/network/SimOnboardingService.kt index ea0b5acc1f2..59dc35ead8d 100644 --- a/src/com/android/settings/network/SimOnboardingService.kt +++ b/src/com/android/settings/network/SimOnboardingService.kt @@ -237,6 +237,7 @@ class SimOnboardingService { fun addItemForRenaming(subInfo: SubscriptionInfo, newName: String) { if (subInfo.displayName == newName) { + renameMutableMap.remove(subInfo.subscriptionId) return } renameMutableMap[subInfo.subscriptionId] = newName diff --git a/tests/spa_unit/src/com/android/settings/network/SimOnboardingServiceTest.kt b/tests/spa_unit/src/com/android/settings/network/SimOnboardingServiceTest.kt new file mode 100644 index 00000000000..6f9029e6609 --- /dev/null +++ b/tests/spa_unit/src/com/android/settings/network/SimOnboardingServiceTest.kt @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.network + +import android.telephony.SubscriptionInfo +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.google.common.truth.Truth.assertThat +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class SimOnboardingServiceTest { + + @Test + fun addItemForRenaming_addItemWithNewName_findItem() { + val simOnboardingService = SimOnboardingService() + val newName = "NewName" + + simOnboardingService.addItemForRenaming(SUB_INFO_1, newName) + + assertThat(simOnboardingService.renameMutableMap) + .containsEntry(SUB_INFO_1.subscriptionId, newName) + } + + @Test + fun addItemForRenaming_sameNameAndItemNotInList_removeItem() { + val simOnboardingService = SimOnboardingService() + + simOnboardingService.addItemForRenaming(SUB_INFO_1, DISPLAY_NAME_1) + + assertThat(simOnboardingService.renameMutableMap) + .doesNotContainKey(SUB_INFO_1.subscriptionId) + } + + @Test + fun addItemForRenaming_sameNameAndItemInList_removeItem() { + val simOnboardingService = SimOnboardingService() + simOnboardingService.renameMutableMap[SUB_INFO_1.subscriptionId] = "NewName" + + simOnboardingService.addItemForRenaming(SUB_INFO_1, DISPLAY_NAME_1) + + assertThat(simOnboardingService.renameMutableMap) + .doesNotContainKey(SUB_INFO_1.subscriptionId) + } + + private companion object { + const val SUB_ID_1 = 1 + const val DISPLAY_NAME_1 = "Sub 1" + + val SUB_INFO_1: SubscriptionInfo = SubscriptionInfo.Builder().apply { + setId(SUB_ID_1) + setDisplayName(DISPLAY_NAME_1) + }.build() + } +} \ No newline at end of file