Merge "Restrict SimDialogActivity" into udc-dev

This commit is contained in:
TreeHugger Robot
2023-06-02 20:41:47 +00:00
committed by Android (Google) Code Review
2 changed files with 102 additions and 1 deletions

View File

@@ -39,10 +39,12 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.network.CarrierConfigCache;
import com.android.settings.network.SubscriptionUtil;
import com.android.settings.network.ims.WifiCallingQueryImsState;
import com.android.settings.network.telephony.MobileNetworkUtils;
import com.android.settings.network.telephony.SubscriptionActionDialogActivity;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -77,7 +79,10 @@ public class SimDialogActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isUiRestricted()) {
finish();
return;
}
if (!SubscriptionUtil.isSimHardwareVisible(this)) {
Log.d(TAG, "Not support on device without SIM.");
finish();
@@ -91,6 +96,15 @@ public class SimDialogActivity extends FragmentActivity {
showOrUpdateDialog();
}
@VisibleForTesting
boolean isUiRestricted() {
if (MobileNetworkUtils.isMobileNetworkUserRestricted(getApplicationContext())) {
Log.e(TAG, "This setting isn't available due to user restriction.");
return true;
}
return false;
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);

View File

@@ -0,0 +1,87 @@
/*
* Copyright (C) 2023 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 android.os.UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.UserManager;
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@RunWith(AndroidJUnit4.class)
@UiThreadTest
public class SimDialogActivityTest {
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Spy
private final Context mContext = ApplicationProvider.getApplicationContext();
@Mock
private UserManager mUserManager;
private MockSimDialogActivity mActivity;
@Before
public void setUp() {
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mUserManager.isGuestUser()).thenReturn(false);
when(mUserManager.hasUserRestriction(DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(false);
mActivity = new MockSimDialogActivity();
}
@Test
public void isUiRestricted_normally_returnFalse() {
assertThat(mActivity.isUiRestricted()).isFalse();
}
@Test
public void isUiRestricted_isGuestUser_returnTrue() {
when(mUserManager.isGuestUser()).thenReturn(true);
assertThat(mActivity.isUiRestricted()).isTrue();
}
@Test
public void isUiRestricted_hasUserRestriction_returnTrue() {
when(mUserManager.hasUserRestriction(DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(true);
assertThat(mActivity.isUiRestricted()).isTrue();
}
public class MockSimDialogActivity extends SimDialogActivity {
@Override
public Context getApplicationContext() {
return mContext;
}
}
}