Merge "Ignore ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED event if satellite session is started" into 24D1-dev am: fea80bf236
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/27071155 Change-Id: Idcbc71555ddbebbd28553530ca8ddd6e364635ae Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.sim;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.job.JobInfo;
|
||||
import android.app.job.JobScheduler;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PrimarySubscriptionListChangedServiceTest {
|
||||
|
||||
@Test
|
||||
public void schedulePrimarySubscriptionChanged_addSchedule_intentPassToJobInfo() {
|
||||
Robolectric.setupService(PrimarySubscriptionListChangedService.class);
|
||||
Context context = ApplicationProvider.getApplicationContext();
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("int", 1);
|
||||
intent.putExtra("string", "foo");
|
||||
|
||||
PrimarySubscriptionListChangedService.scheduleJob(context, intent);
|
||||
|
||||
List<JobInfo> jobs = Objects.requireNonNull(context.getSystemService(JobScheduler.class))
|
||||
.getAllPendingJobs();
|
||||
assertThat(jobs).hasSize(1);
|
||||
JobInfo job = jobs.get(0);
|
||||
assertThat(job.isPersisted()).isFalse();
|
||||
Bundle bundle = job.getTransientExtras();
|
||||
assertThat(bundle.getInt("int")).isEqualTo(1);
|
||||
assertThat(bundle.getString("string")).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void schedulePrimarySubscriptionChanged_addSchedule_whenInvoked() {
|
||||
Context context = spy(ApplicationProvider.getApplicationContext());
|
||||
JobScheduler jobScheduler = mock(JobScheduler.class);
|
||||
when(context.getSystemService(JobScheduler.class)).thenReturn(jobScheduler);
|
||||
|
||||
PrimarySubscriptionListChangedService.scheduleJob(context, new Intent());
|
||||
|
||||
verify(jobScheduler).schedule(any());
|
||||
}
|
||||
}
|
@@ -63,6 +63,7 @@ import android.util.DisplayMetrics;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.SatelliteRepository;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||
|
||||
@@ -141,6 +142,8 @@ public class SimSelectNotificationTest {
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(mSubInfo));
|
||||
when(mSubscriptionManager.isActiveSubscriptionId(mSubId)).thenReturn(true);
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfo(mSubId)).thenReturn(mSubInfo);
|
||||
SatelliteRepository.Companion.setIsSessionStartedForTesting(false);
|
||||
|
||||
when(mSubInfo.getSubscriptionId()).thenReturn(mSubId);
|
||||
when(mSubInfo.getDisplayName()).thenReturn(mFakeDisplayName);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
@@ -219,17 +222,30 @@ public class SimSelectNotificationTest {
|
||||
Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED);
|
||||
|
||||
// EXTRA_SUB_ID and EXTRA_ENABLE_MMS_DATA_REQUEST_REASON are required.
|
||||
mSimSelectNotification.onReceive(mContext, intent);
|
||||
SimSelectNotification.onPrimarySubscriptionListChanged(mContext, intent);
|
||||
verify(mNotificationManager, never()).createNotificationChannel(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onReceivePrimarySubListChange_isSatelliteEnabled_activityShouldNotStart() {
|
||||
SatelliteRepository.Companion.setIsSessionStartedForTesting(true);
|
||||
|
||||
Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED);
|
||||
intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE,
|
||||
EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA);
|
||||
|
||||
SimSelectNotification.onPrimarySubscriptionListChanged(mContext, intent);
|
||||
|
||||
verify(mContext, never()).startActivity(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onReceivePrimarySubListChange_WithDataPickExtra_shouldStartActivity() {
|
||||
Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED);
|
||||
intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE,
|
||||
EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA);
|
||||
|
||||
mSimSelectNotification.onReceive(mContext, intent);
|
||||
SimSelectNotification.onPrimarySubscriptionListChanged(mContext, intent);
|
||||
|
||||
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mContext).startActivity(intentCaptor.capture());
|
||||
@@ -252,12 +268,13 @@ public class SimSelectNotificationTest {
|
||||
intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE,
|
||||
EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS);
|
||||
|
||||
mSimSelectNotification.onReceive(mContext, intent);
|
||||
SimSelectNotification.onPrimarySubscriptionListChanged(mContext, intent);
|
||||
clearInvocations(mContext);
|
||||
|
||||
// Dismiss.
|
||||
verify(mExecutor).execute(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onReceivePrimarySubListChange_DualCdmaWarning_notificationShouldSend() {
|
||||
Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED);
|
||||
@@ -266,7 +283,7 @@ public class SimSelectNotificationTest {
|
||||
intent.putExtra(EXTRA_SIM_COMBINATION_WARNING_TYPE,
|
||||
EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA);
|
||||
|
||||
mSimSelectNotification.onReceive(mContext, intent);
|
||||
SimSelectNotification.onPrimarySubscriptionListChanged(mContext, intent);
|
||||
|
||||
// Capture the notification channel created and verify its fields.
|
||||
ArgumentCaptor<NotificationChannel> nc = ArgumentCaptor.forClass(NotificationChannel.class);
|
||||
|
Reference in New Issue
Block a user