Merge "Fix NPE in AutoSyncWorkDataPreferenceController"
This commit is contained in:
@@ -17,6 +17,7 @@ package com.android.settings.accounts;
|
|||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
@@ -34,4 +35,10 @@ public class AutoSyncWorkDataPreferenceController extends AutoSyncPersonalDataPr
|
|||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY_AUTO_SYNC_WORK_ACCOUNT;
|
return KEY_AUTO_SYNC_WORK_ACCOUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return mUserHandle != null && !mUserManager.isManagedProfile() && !mUserManager.isLinkedUser()
|
||||||
|
&& mUserManager.getProfiles(UserHandle.myUserId()).size() > 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -91,6 +91,21 @@ public class AutoSyncWorkDataPreferenceControllerTest {
|
|||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkIsAvailable_null_workProfileUserHandle_shouldNotDisplay() {
|
||||||
|
when(mUserManager.isManagedProfile()).thenReturn(false);
|
||||||
|
when(mUserManager.isLinkedUser()).thenReturn(false);
|
||||||
|
|
||||||
|
final List<UserInfo> infos = new ArrayList<>();
|
||||||
|
infos.add(new UserInfo(UserHandle.USER_SYSTEM, "user 1", 0 /* flags */));
|
||||||
|
infos.add(new UserInfo(999, "xspace", 800010));
|
||||||
|
when(mUserManager.getProfiles(eq(UserHandle.USER_SYSTEM))).thenReturn(infos);
|
||||||
|
mController = new AutoSyncWorkDataPreferenceController(mContext, mFragment);
|
||||||
|
|
||||||
|
assertThat(mController.mUserHandle).isEqualTo(null);
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipleProfile_shouldInitWithWorkProfileUserHandle() {
|
public void multipleProfile_shouldInitWithWorkProfileUserHandle() {
|
||||||
when(mUserManager.isManagedProfile()).thenReturn(false);
|
when(mUserManager.isManagedProfile()).thenReturn(false);
|
||||||
|
Reference in New Issue
Block a user