Merge changes Idf05ffee,Ie7371ba4

* changes:
  Update "More" button text to "Advanced"
  Fix NPE when adding account but prefManager doesn't exist
This commit is contained in:
TreeHugger Robot
2017-01-11 22:02:32 +00:00
committed by Android (Google) Code Review
3 changed files with 27 additions and 6 deletions

View File

@@ -286,6 +286,9 @@ public class AccountPreferenceController extends PreferenceController
}
private void updateProfileUi(final UserInfo userInfo) {
if (mParent.getPreferenceManager() == null) {
return;
}
final Context context = mContext;
final ProfileData profileData = new ProfileData();
profileData.userInfo = userInfo;
@@ -402,6 +405,10 @@ public class AccountPreferenceController extends PreferenceController
}
private void updateAccountTypes(ProfileData profileData) {
if (mParent.getPreferenceManager() == null) {
// This could happen if activity is finishing
return;
}
profileData.preferenceGroup.removeAll();
if (profileData.userInfo.isEnabled()) {
final ArrayList<AccountTypePreference> preferences = getAccountTypePreferences(

View File

@@ -48,7 +48,7 @@ public class ExpandPreference extends Preference {
private void init() {
setLayoutResource(R.layout.expand_preference);
setIcon(R.drawable.ic_arrow_down_24dp);
setTitle(R.string.wifi_more);
setTitle(R.string.advanced_section_header);
setOrder(999);
}
}

View File

@@ -20,13 +20,12 @@ import android.accounts.AccountManager;
import android.accounts.AuthenticatorDescription;
import android.content.Context;
import android.content.pm.UserInfo;
import android.os.UserManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.support.v14.preference.PreferenceFragment;
import android.util.SparseArray;
import com.android.settings.AccessiblePreferenceCategory;
import com.android.settings.R;
@@ -37,8 +36,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowAccountManager;
import com.android.settings.testutils.shadow.ShadowContentResolver;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,6 +44,9 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Matchers.any;
@@ -207,6 +207,20 @@ public class AccountPreferenceControllerTest {
// Should not crash
}
@Test
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
public void onResume_noPreferenceManager_shouldNotCrash() {
when(mFragment.getPreferenceManager()).thenReturn(null);
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 0));
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.isLinkedUser()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
mController.onResume();
// Should not crash
}
@Test
public void updateRawDataToIndex_ManagedProfile_shouldNotUpdate() {
final List<SearchIndexableRaw> data = new ArrayList<>();