Merge "Fixed Settings Crash" into qt-r1-dev am: 800e8a485f

am: d5cac4a3f6

Change-Id: I4cbc1adb869d6ca988827c6bdbd2106ab089c82c
This commit is contained in:
Joshua Mccloskey
2019-07-15 13:22:30 -07:00
committed by android-build-merger
2 changed files with 11 additions and 5 deletions

View File

@@ -54,7 +54,7 @@ public class FaceSetupSlice implements CustomSliceable {
@Override @Override
public Slice getSlice() { public Slice getSlice() {
final FaceManager faceManager = mContext.getSystemService(FaceManager.class); final FaceManager faceManager = Utils.getFaceManagerOrNull(mContext);
if (faceManager == null || faceManager.hasEnrolledTemplates(UserHandle.myUserId())) { if (faceManager == null || faceManager.hasEnrolledTemplates(UserHandle.myUserId())) {
return null; return null;
} }

View File

@@ -23,6 +23,7 @@ import static org.mockito.Mockito.when;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.face.FaceManager; import android.hardware.face.FaceManager;
import android.os.UserHandle; import android.os.UserHandle;
@@ -31,6 +32,7 @@ import androidx.slice.SliceProvider;
import androidx.slice.widget.SliceLiveData; import androidx.slice.widget.SliceLiveData;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Utils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -38,22 +40,24 @@ import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class FaceSetupSliceTest { public class FaceSetupSliceTest {
private Context mContext; private Context mContext;
private PackageManager mPackageManager;
@Before @Before
public void setUp() { public void setUp() {
// Set-up specs for SliceMetadata. // Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS); SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
mPackageManager = mock(PackageManager.class);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
} }
@Test @Test
public void getSlice_noFaceManager_shouldReturnNull() { public void getSlice_noFaceManager_shouldReturnNull() {
when(mContext.getSystemService(FaceManager.class)).thenReturn(null); when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(false);
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext); final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
assertThat(setupSlice.getSlice()).isNull(); assertThat(setupSlice.getSlice()).isNull();
} }
@@ -61,8 +65,9 @@ public class FaceSetupSliceTest {
@Test @Test
public void getSlice_faceEnrolled_shouldReturnNull() { public void getSlice_faceEnrolled_shouldReturnNull() {
final FaceManager faceManager = mock(FaceManager.class); final FaceManager faceManager = mock(FaceManager.class);
when(mContext.getSystemService(FaceManager.class)).thenReturn(faceManager); when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
when(faceManager.hasEnrolledTemplates(UserHandle.myUserId())).thenReturn(true); when(faceManager.hasEnrolledTemplates(UserHandle.myUserId())).thenReturn(true);
when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(faceManager);
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext); final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
assertThat(setupSlice.getSlice()).isNull(); assertThat(setupSlice.getSlice()).isNull();
} }
@@ -70,8 +75,9 @@ public class FaceSetupSliceTest {
@Test @Test
public void getSlice_faceNotEnrolled_shouldReturnNonNull() { public void getSlice_faceNotEnrolled_shouldReturnNonNull() {
final FaceManager faceManager = mock(FaceManager.class); final FaceManager faceManager = mock(FaceManager.class);
when(mContext.getSystemService(FaceManager.class)).thenReturn(faceManager); when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
when(faceManager.hasEnrolledTemplates(UserHandle.myUserId())).thenReturn(false); when(faceManager.hasEnrolledTemplates(UserHandle.myUserId())).thenReturn(false);
when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(faceManager);
final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext); final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
assertThat(setupSlice.getSlice()).isNotNull(); assertThat(setupSlice.getSlice()).isNotNull();
} }