Merge "A separate entry for work profile CA cert" into oc-mr1-dev

am: e040ef4a39

Change-Id: I0774c8e5ebf959b5f6fb759566815bde966c0dfd
This commit is contained in:
Tony Mak
2017-08-22 18:21:35 +00:00
committed by android-build-merger
14 changed files with 401 additions and 81 deletions

View File

@@ -8880,8 +8880,12 @@
<string name="enterprise_privacy_always_on_vpn_work">Always-on VPN turned on in your work profile</string> <string name="enterprise_privacy_always_on_vpn_work">Always-on VPN turned on in your work profile</string>
<!-- Label explaining that a global HTTP proxy was set by the admin. [CHAR LIMIT=NONE] --> <!-- Label explaining that a global HTTP proxy was set by the admin. [CHAR LIMIT=NONE] -->
<string name="enterprise_privacy_global_http_proxy">Global HTTP proxy set</string> <string name="enterprise_privacy_global_http_proxy">Global HTTP proxy set</string>
<!-- Label explaining that the admin installed trusted CA certificates. [CHAR LIMIT=NONE] --> <!-- Label explaining that the admin installed trusted CA certificates for the entire device. [CHAR LIMIT=NONE] -->
<string name="enterprise_privacy_ca_certs">Trusted credentials</string> <string name="enterprise_privacy_ca_certs_device">Trusted credentials</string>
<!-- Label explaining that the admin installed trusted CA certificates in personal profile. [CHAR LIMIT=NONE] -->
<string name="enterprise_privacy_ca_certs_personal">Trusted credentials in your personal profile</string>
<!-- Label explaining that the admin installed trusted CA certificates in work profile. [CHAR LIMIT=NONE] -->
<string name="enterprise_privacy_ca_certs_work">Trusted credentials in your work profile</string>
<!-- Summary indicating the number of trusted CA certificates installed by the admin. The number shown is a minimum as there may be additional CA certificates we do not know about. [CHAR LIMIT=NONE] --> <!-- Summary indicating the number of trusted CA certificates installed by the admin. The number shown is a minimum as there may be additional CA certificates we do not know about. [CHAR LIMIT=NONE] -->
<plurals name="enterprise_privacy_number_ca_certs"> <plurals name="enterprise_privacy_number_ca_certs">
<item quantity="one">Minimum <xliff:g id="count">%d</xliff:g> CA certificate</item> <item quantity="one">Minimum <xliff:g id="count">%d</xliff:g> CA certificate</item>

View File

@@ -77,8 +77,11 @@
<Preference android:key="global_http_proxy" <Preference android:key="global_http_proxy"
android:title="@string/enterprise_privacy_global_http_proxy" android:title="@string/enterprise_privacy_global_http_proxy"
android:selectable="false"/> android:selectable="false"/>
<Preference android:key="ca_certs" <Preference android:key="ca_certs_current_user"
android:title="@string/enterprise_privacy_ca_certs" android:title="@string/enterprise_privacy_ca_certs_personal"
android:selectable="false"/>
<Preference android:key="ca_certs_managed_profile"
android:title="@string/enterprise_privacy_ca_certs_work"
android:selectable="false"/> android:selectable="false"/>
</PreferenceCategory> </PreferenceCategory>

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.android.settings.enterprise;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class CaCertsCurrentUserPreferenceController extends CaCertsPreferenceControllerBase {
@VisibleForTesting
static final String CA_CERTS_CURRENT_USER = "ca_certs_current_user";
public CaCertsCurrentUserPreferenceController(Context context,
Lifecycle lifecycle) {
super(context, lifecycle);
}
@Override
public String getPreferenceKey() {
return CA_CERTS_CURRENT_USER;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
preference.setTitle(mFeatureProvider.isInCompMode()
? R.string.enterprise_privacy_ca_certs_personal
: R.string.enterprise_privacy_ca_certs_device);
}
@Override
protected int getNumberOfCaCerts() {
return mFeatureProvider.getNumberOfOwnerInstalledCaCertsForCurrentUser();
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.android.settings.enterprise;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class CaCertsManagedProfilePreferenceController extends CaCertsPreferenceControllerBase {
@VisibleForTesting
static final String CA_CERTS_MANAGED_PROFILE = "ca_certs_managed_profile";
public CaCertsManagedProfilePreferenceController(Context context,
Lifecycle lifecycle) {
super(context, lifecycle);
}
@Override
public String getPreferenceKey() {
return CA_CERTS_MANAGED_PROFILE;
}
@Override
protected int getNumberOfCaCerts() {
return mFeatureProvider.getNumberOfOwnerInstalledCaCertsForManagedProfile();
}
}

View File

@@ -15,7 +15,6 @@
package com.android.settings.enterprise; package com.android.settings.enterprise;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import com.android.settings.R; import com.android.settings.R;
@@ -23,12 +22,12 @@ import com.android.settings.core.DynamicAvailabilityPreferenceController;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
public class CaCertsPreferenceController extends DynamicAvailabilityPreferenceController { public abstract class CaCertsPreferenceControllerBase
extends DynamicAvailabilityPreferenceController {
private static final String CA_CERTS = "ca_certs"; protected final EnterprisePrivacyFeatureProvider mFeatureProvider;
private final EnterprisePrivacyFeatureProvider mFeatureProvider;
public CaCertsPreferenceController(Context context, Lifecycle lifecycle) { public CaCertsPreferenceControllerBase(Context context, Lifecycle lifecycle) {
super(context, lifecycle); super(context, lifecycle);
mFeatureProvider = FeatureFactory.getFactory(context) mFeatureProvider = FeatureFactory.getFactory(context)
.getEnterprisePrivacyFeatureProvider(context); .getEnterprisePrivacyFeatureProvider(context);
@@ -36,23 +35,17 @@ public class CaCertsPreferenceController extends DynamicAvailabilityPreferenceCo
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
final int certs = final int certs = getNumberOfCaCerts();
mFeatureProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile();
preference.setSummary(mContext.getResources().getQuantityString( preference.setSummary(mContext.getResources().getQuantityString(
R.plurals.enterprise_privacy_number_ca_certs, certs, certs)); R.plurals.enterprise_privacy_number_ca_certs, certs, certs));
} }
@Override @Override
public boolean isAvailable() { public boolean isAvailable() {
final boolean available = final boolean available = getNumberOfCaCerts() > 0;
mFeatureProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()
> 0;
notifyOnAvailabilityUpdate(available); notifyOnAvailabilityUpdate(available);
return available; return available;
} }
@Override protected abstract int getNumberOfCaCerts();
public String getPreferenceKey() {
return CA_CERTS;
}
} }

View File

@@ -109,9 +109,15 @@ public interface EnterprisePrivacyFeatureProvider {
/** /**
* Returns the number of CA certificates that the Device Owner or Profile Owner installed in * Returns the number of CA certificates that the Device Owner or Profile Owner installed in
* the current user and the user's managed profile (if any). * current user.
*/ */
int getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile(); int getNumberOfOwnerInstalledCaCertsForCurrentUser();
/**
* Returns the number of CA certificates that the Device Owner or Profile Owner installed in
* the current user's managed profile (if any).
*/
int getNumberOfOwnerInstalledCaCertsForManagedProfile();
/** /**
* Returns the number of Device Admin apps active in the current user and the user's managed * Returns the number of Device Admin apps active in the current user and the user's managed

View File

@@ -200,20 +200,25 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
} }
@Override @Override
public int getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile() { public int getNumberOfOwnerInstalledCaCertsForCurrentUser() {
int num = 0; final List<String> certs = mDpm.getOwnerInstalledCaCerts(new UserHandle(MY_USER_ID));
List<String> certs = mDpm.getOwnerInstalledCaCerts(new UserHandle(MY_USER_ID)); if (certs == null) {
if (certs != null) { return 0;
num += certs.size();
} }
return certs.size();
}
@Override
public int getNumberOfOwnerInstalledCaCertsForManagedProfile() {
final int userId = getManagedProfileUserId(); final int userId = getManagedProfileUserId();
if (userId != UserHandle.USER_NULL) { if (userId == UserHandle.USER_NULL) {
certs = mDpm.getOwnerInstalledCaCerts(new UserHandle(userId)); return 0;
if (certs != null) {
num += certs.size();
} }
final List<String> certs = mDpm.getOwnerInstalledCaCerts(new UserHandle(userId));
if (certs == null) {
return 0;
} }
return num; return certs.size();
} }
@Override @Override

View File

@@ -82,7 +82,10 @@ public class EnterprisePrivacySettings extends DashboardFragment {
exposureChangesCategoryControllers.add(new ImePreferenceController(context, lifecycle)); exposureChangesCategoryControllers.add(new ImePreferenceController(context, lifecycle));
exposureChangesCategoryControllers.add(new GlobalHttpProxyPreferenceController(context, exposureChangesCategoryControllers.add(new GlobalHttpProxyPreferenceController(context,
lifecycle)); lifecycle));
exposureChangesCategoryControllers.add(new CaCertsPreferenceController(context, lifecycle)); exposureChangesCategoryControllers.add(new CaCertsCurrentUserPreferenceController(
context, lifecycle));
exposureChangesCategoryControllers.add(new CaCertsManagedProfilePreferenceController(
context, lifecycle));
controllers.addAll(exposureChangesCategoryControllers); controllers.addAll(exposureChangesCategoryControllers);
controllers.add(new ExposureChangesCategoryPreferenceController(context, lifecycle, controllers.add(new ExposureChangesCategoryPreferenceController(context, lifecycle,
exposureChangesCategoryControllers, async)); exposureChangesCategoryControllers, async));

View File

@@ -0,0 +1,88 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.enterprise;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;
import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
/**
* Tests for {@link CaCertsCurrentUserPreferenceController}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class CaCertsCurrentUserPreferenceControllerTest extends
CaCertsPreferenceControllerTestBase {
private static final String CA_CERT_DEVICE = "CA certs";
private static final String CA_CERT_PERSONAL = "CA certs in personal profile";
@Before
public void mockGetString() {
when(mContext.getString(R.string.enterprise_privacy_ca_certs_device))
.thenReturn(CA_CERT_DEVICE);
when(mContext.getString(R.string.enterprise_privacy_ca_certs_personal))
.thenReturn(CA_CERT_PERSONAL);
}
@Test
public void testUpdateState_nonCompMode() {
assertUpdateState(false /* isCompMode */, CA_CERT_DEVICE);
}
@Test
public void testUpdateState_compMode() {
assertUpdateState(true /* isCompMode */, CA_CERT_PERSONAL);
}
@Override
void mockGetNumberOfCaCerts(int numOfCaCerts) {
when(mFeatureFactory.enterprisePrivacyFeatureProvider
.getNumberOfOwnerInstalledCaCertsForCurrentUser()).thenReturn(numOfCaCerts);
}
@Override
String getPreferenceKey() {
return CaCertsCurrentUserPreferenceController.CA_CERTS_CURRENT_USER;
}
@Override
CaCertsPreferenceControllerBase createController() {
return new CaCertsCurrentUserPreferenceController(mContext, null /* lifecycle */);
}
private void assertUpdateState(boolean isCompMode, String expectedTitle) {
final Preference preference = new Preference(mContext, null, 0, 0);
mockGetNumberOfCaCerts(2);
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode())
.thenReturn(isCompMode);
mController.updateState(preference);
assertThat(preference.getTitle()).isEqualTo(expectedTitle);
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.enterprise;
import static org.mockito.Mockito.when;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
/**
* Tests for {@link CaCertsManagedProfilePreferenceController}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class CaCertsManagedProfilePreferenceControllerTest extends
CaCertsPreferenceControllerTestBase {
@Override
void mockGetNumberOfCaCerts(int numOfCaCerts) {
when(mFeatureFactory.enterprisePrivacyFeatureProvider
.getNumberOfOwnerInstalledCaCertsForManagedProfile()).thenReturn(numOfCaCerts);
}
@Override
String getPreferenceKey() {
return CaCertsManagedProfilePreferenceController.CA_CERTS_MANAGED_PROFILE;
}
@Override
CaCertsPreferenceControllerBase createController() {
return new CaCertsManagedProfilePreferenceController(mContext, null /* lifecycle */);
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.enterprise;
import android.content.Context;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
/**
* Tests for {@link CaCertsPreferenceControllerBase}.
*/
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class CaCertsPreferenceControllerBaseTest extends CaCertsPreferenceControllerTestBase {
private static final String PREF_KEY = "pref";
private int mNumOfCaCerts;
void mockGetNumberOfCaCerts(int numOfCaCerts) {
mNumOfCaCerts = numOfCaCerts;
}
String getPreferenceKey() {
return PREF_KEY;
}
CaCertsPreferenceControllerBase createController() {
return new CaCertsPreferenceControllerBaseTestable(mContext);
}
private class CaCertsPreferenceControllerBaseTestable extends
CaCertsPreferenceControllerBase {
public CaCertsPreferenceControllerBaseTestable(Context context) {
super(context, null);
}
@Override
public String getPreferenceKey() {
return PREF_KEY;
}
@Override
protected int getNumberOfCaCerts() {
return mNumOfCaCerts;
}
}
}

View File

@@ -16,50 +16,42 @@
package com.android.settings.enterprise; package com.android.settings.enterprise;
import android.content.Context; import static com.google.common.truth.Truth.assertThat;
import com.android.settings.R; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.core.PreferenceAvailabilityObserver; import com.android.settings.core.PreferenceAvailabilityObserver;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers; import org.mockito.Answers;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** /**
* Tests for {@link CaCertsPreferenceController}. * Base test class for testing {@link CaCertsPreferenceControllerBase}'s subclass.
*/ */
@RunWith(SettingsRobolectricTestRunner.class) public abstract class CaCertsPreferenceControllerTestBase {
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class CaCertsPreferenceControllerTest {
private static final String KEY_CA_CERTS = "ca_certs";
@Mock(answer = Answers.RETURNS_DEEP_STUBS) @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext; protected Context mContext;
private FakeFeatureFactory mFeatureFactory; protected FakeFeatureFactory mFeatureFactory;
@Mock private PreferenceAvailabilityObserver mObserver; protected CaCertsPreferenceControllerBase mController;
@Mock
private CaCertsPreferenceController mController; private PreferenceAvailabilityObserver mObserver;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext); FakeFeatureFactory.setupForTest(mContext);
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mController = new CaCertsPreferenceController(mContext, null /* lifecycle */); mController = createController();
mController.setAvailabilityObserver(mObserver); mController.setAvailabilityObserver(mObserver);
} }
@@ -74,23 +66,20 @@ public final class CaCertsPreferenceControllerTest {
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs, when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_ca_certs,
10, 10)).thenReturn("10 certs"); 10, 10)).thenReturn("10 certs");
when(mFeatureFactory.enterprisePrivacyFeatureProvider mockGetNumberOfCaCerts(10);
.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(10);
mController.updateState(preference); mController.updateState(preference);
assertThat(preference.getSummary()).isEqualTo("10 certs"); assertThat(preference.getSummary()).isEqualTo("10 certs");
} }
@Test @Test
public void testIsAvailable() { public void testIsAvailable() {
when(mFeatureFactory.enterprisePrivacyFeatureProvider mockGetNumberOfCaCerts(0);
.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(0);
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
verify(mObserver).onPreferenceAvailabilityUpdated(KEY_CA_CERTS, false); verify(mObserver).onPreferenceAvailabilityUpdated(getPreferenceKey(), false);
when(mFeatureFactory.enterprisePrivacyFeatureProvider mockGetNumberOfCaCerts(10);
.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()).thenReturn(10);
assertThat(mController.isAvailable()).isTrue(); assertThat(mController.isAvailable()).isTrue();
verify(mObserver).onPreferenceAvailabilityUpdated(KEY_CA_CERTS, true); verify(mObserver).onPreferenceAvailabilityUpdated(getPreferenceKey(), true);
} }
@Test @Test
@@ -101,6 +90,13 @@ public final class CaCertsPreferenceControllerTest {
@Test @Test
public void testGetPreferenceKey() { public void testGetPreferenceKey() {
assertThat(mController.getPreferenceKey()).isEqualTo(KEY_CA_CERTS); assertThat(mController.getPreferenceKey()).isEqualTo(getPreferenceKey());
} }
abstract void mockGetNumberOfCaCerts(int numOfCaCerts);
abstract String getPreferenceKey();
abstract CaCertsPreferenceControllerBase createController();
} }

View File

@@ -288,7 +288,7 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
} }
@Test @Test
public void testGetNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile() { public void testGetNumberOfOwnerInstalledCaCertsForCurrent() {
final UserHandle userHandle = new UserHandle(UserHandle.USER_SYSTEM); final UserHandle userHandle = new UserHandle(UserHandle.USER_SYSTEM);
final UserHandle managedProfileUserHandle = new UserHandle(MANAGED_PROFILE_USER_ID); final UserHandle managedProfileUserHandle = new UserHandle(MANAGED_PROFILE_USER_ID);
final UserInfo managedProfile = final UserInfo managedProfile =
@@ -299,33 +299,44 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle)) when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
.thenReturn(null); .thenReturn(null);
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()) assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUser())
.isEqualTo(0); .isEqualTo(0);
when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle)) when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
.thenReturn(new ArrayList<String>()); .thenReturn(new ArrayList<>());
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()) assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUser())
.isEqualTo(0); .isEqualTo(0);
when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle)) when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
.thenReturn(Arrays.asList(new String[] {"ca1", "ca2"})); .thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()) assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUser())
.isEqualTo(2); .isEqualTo(2);
}
@Test
public void testGetNumberOfOwnerInstalledCaCertsForManagedProfile() {
final UserHandle userHandle = new UserHandle(UserHandle.USER_SYSTEM);
final UserHandle managedProfileUserHandle = new UserHandle(MANAGED_PROFILE_USER_ID);
final UserInfo managedProfile =
new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE);
// Without a profile
when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
.thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForManagedProfile())
.isEqualTo(0);
// With a profile
mProfiles.add(managedProfile); mProfiles.add(managedProfile);
when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle)) when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
.thenReturn(null); .thenReturn(null);
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()) assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForManagedProfile())
.isEqualTo(2); .isEqualTo(0);
when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle)) when(mDevicePolicyManager.getOwnerInstalledCaCerts(userHandle))
.thenReturn(new ArrayList<String>()); .thenReturn(new ArrayList<>());
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()) assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForManagedProfile())
.isEqualTo(2); .isEqualTo(0);
when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle)) when(mDevicePolicyManager.getOwnerInstalledCaCerts(managedProfileUserHandle))
.thenReturn(Arrays.asList(new String[] {"ca1", "ca2"})); .thenReturn(Arrays.asList(new String[] {"ca1", "ca2"}));
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile()) assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForManagedProfile())
.isEqualTo(4);
mProfiles.remove(managedProfile);
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsForCurrentUserAndManagedProfile())
.isEqualTo(2); .isEqualTo(2);
} }

View File

@@ -128,7 +128,7 @@ public final class EnterprisePrivacySettingsTest {
private void verifyPreferenceControllers(List<AbstractPreferenceController> controllers) private void verifyPreferenceControllers(List<AbstractPreferenceController> controllers)
throws Exception { throws Exception {
assertThat(controllers).isNotNull(); assertThat(controllers).isNotNull();
assertThat(controllers.size()).isEqualTo(16); assertThat(controllers.size()).isEqualTo(17);
int position = 0; int position = 0;
assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class); assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class); assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class);
@@ -152,7 +152,9 @@ public final class EnterprisePrivacySettingsTest {
assertThat(controllers.get(position++)).isInstanceOf( assertThat(controllers.get(position++)).isInstanceOf(
GlobalHttpProxyPreferenceController.class); GlobalHttpProxyPreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf( assertThat(controllers.get(position++)).isInstanceOf(
CaCertsPreferenceController.class); CaCertsCurrentUserPreferenceController.class);
assertThat(controllers.get(position++)).isInstanceOf(
CaCertsManagedProfilePreferenceController.class);
final AbstractPreferenceController exposureChangesCategoryController = final AbstractPreferenceController exposureChangesCategoryController =
controllers.get(position); controllers.get(position);
final int exposureChangesCategoryControllerIndex = position; final int exposureChangesCategoryControllerIndex = position;