Adding a link to Setting activity for the Home app

The link is only visible if there is a default home add and it
implements a settings activity

Test: make -j20 RunSettingsRoboTests
Change-Id: Iac5d0ebd561bed2e5b2f84236cdb728362ed8663
This commit is contained in:
Sunny Goyal
2017-11-13 10:09:09 -08:00
parent 136c6888ae
commit 43fccf9842
3 changed files with 56 additions and 4 deletions

View File

@@ -17,6 +17,9 @@
package com.android.settings.applications.defaultapps;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Matchers.anyList;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
@@ -26,6 +29,8 @@ import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.UserManager;
import android.support.v7.preference.Preference;
@@ -42,6 +47,9 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import java.util.Arrays;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DefaultHomePreferenceControllerTest {
@@ -112,4 +120,32 @@ public class DefaultHomePreferenceControllerTest {
assertThat(DefaultHomePreferenceController.isHomeDefault(pkgName, mPackageManager))
.isFalse();
}
@Test
public void testGetSettingIntent_homeHasNoSetting_shouldNotReturnSettingIntent() {
when(mPackageManager.getHomeActivities(anyList())).thenReturn(
new ComponentName("test.pkg", "class"));
assertThat(mController.getSettingIntent(mController.getDefaultAppInfo())).isNull();
}
@Test
public void testGetSettingIntent_homeHasOneSetting_shouldReturnSettingIntent() {
when(mPackageManager.getHomeActivities(anyList())).thenReturn(
new ComponentName("test.pkg", "class"));
when(mPackageManager.queryIntentActivities(any(), eq(0))).thenReturn(
Arrays.asList(mock(ResolveInfo.class)));
Intent intent = mController.getSettingIntent(mController.getDefaultAppInfo());
assertThat(intent).isNotNull();
assertThat(intent.getPackage()).isEqualTo("test.pkg");
}
@Test
public void testGetSettingIntent_homeHasMultipleSettings_shouldNotReturnSettingIntent() {
when(mPackageManager.getHomeActivities(anyList())).thenReturn(
new ComponentName("test.pkg", "class"));
when(mPackageManager.queryIntentActivities(any(), eq(0))).thenReturn(
Arrays.asList(mock(ResolveInfo.class), mock(ResolveInfo.class)));
assertThat(mController.getSettingIntent(mController.getDefaultAppInfo())).isNull();
}
}