1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.display; 18 19 import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE; 20 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; 21 22 import static com.google.common.truth.Truth.assertThat; 23 24 import static org.mockito.ArgumentMatchers.any; 25 import static org.mockito.ArgumentMatchers.anyInt; 26 import static org.mockito.Mockito.doReturn; 27 import static org.mockito.Mockito.when; 28 29 import android.content.ContentResolver; 30 import android.content.Context; 31 import android.content.pm.PackageManager; 32 import android.content.pm.ResolveInfo; 33 import android.content.pm.ServiceInfo; 34 35 import com.android.settings.testutils.ResolveInfoBuilder; 36 import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager; 37 38 import org.junit.Before; 39 import org.junit.Test; 40 import org.junit.runner.RunWith; 41 import org.mockito.Mockito; 42 import org.mockito.MockitoAnnotations; 43 import org.robolectric.RobolectricTestRunner; 44 import org.robolectric.RuntimeEnvironment; 45 import org.robolectric.annotation.Config; 46 47 @RunWith(RobolectricTestRunner.class) 48 @Config(shadows = ShadowSensorPrivacyManager.class) 49 public class SmartAutoRotateCameraStateControllerTest { 50 51 private static final String PACKAGE_NAME = "package_name"; 52 53 private SmartAutoRotateCameraStateController mController; 54 55 @Before setUp()56 public void setUp() { 57 MockitoAnnotations.initMocks(this); 58 final Context context = Mockito.spy(RuntimeEnvironment.application); 59 final ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver(); 60 when(context.getContentResolver()).thenReturn(contentResolver); 61 final PackageManager packageManager = Mockito.mock(PackageManager.class); 62 when(context.getPackageManager()).thenReturn(packageManager); 63 doReturn(PACKAGE_NAME).when(packageManager).getRotationResolverPackageName(); 64 mController = new SmartAutoRotateCameraStateController(context, "smart_auto_rotate"); 65 when(mController.isCameraLocked()).thenReturn(false); 66 67 final ResolveInfo resolveInfo = new ResolveInfoBuilder(PACKAGE_NAME).build(); 68 resolveInfo.serviceInfo = new ServiceInfo(); 69 when(packageManager.resolveService(any(), anyInt())).thenReturn(resolveInfo); 70 } 71 72 @Test getAvailabilityStatus_returnUnsupportedOnDevice()73 public void getAvailabilityStatus_returnUnsupportedOnDevice() { 74 assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); 75 } 76 77 @Test getAvailabilityStatus_cameraNotEnabled_returnAvailableUnSearchAble()78 public void getAvailabilityStatus_cameraNotEnabled_returnAvailableUnSearchAble() { 79 when(mController.isCameraLocked()).thenReturn(true); 80 assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE); 81 } 82 } 83