Restrict SimDialogActivity
- Restrict UI if user is a guest - Restrict UI if user has DISALLOW_CONFIG_MOBILE_NETWORKS Bug: 262242946 Bug: 271849181 Test: manual test atest -c SimDialogActivityTest Change-Id: I227400aa71880895d8356f3d2961cb610ad2a357
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user