Merge "Update Managed Device Info text for a financed device" into sc-dev
This commit is contained in:
@@ -13,6 +13,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.enterprise;
|
package com.android.settings.enterprise;
|
||||||
|
|
||||||
|
import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
|
||||||
|
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -39,6 +42,10 @@ public class EnterprisePrivacyPreferenceController extends AbstractPreferenceCon
|
|||||||
if (preference == null) {
|
if (preference == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (isFinancedDevice()) {
|
||||||
|
preference.setTitle(R.string.financed_privacy_settings);
|
||||||
|
}
|
||||||
|
|
||||||
final String organizationName = mFeatureProvider.getDeviceOwnerOrganizationName();
|
final String organizationName = mFeatureProvider.getDeviceOwnerOrganizationName();
|
||||||
if (organizationName == null) {
|
if (organizationName == null) {
|
||||||
preference.setSummary(R.string.enterprise_privacy_settings_summary_generic);
|
preference.setSummary(R.string.enterprise_privacy_settings_summary_generic);
|
||||||
@@ -57,4 +64,10 @@ public class EnterprisePrivacyPreferenceController extends AbstractPreferenceCon
|
|||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY_ENTERPRISE_PRIVACY;
|
return KEY_ENTERPRISE_PRIVACY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isFinancedDevice() {
|
||||||
|
final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
|
||||||
|
return dpm.isDeviceManaged() && dpm.getDeviceOwnerType(
|
||||||
|
dpm.getDeviceOwnerComponentOnAnyUser()) == DEVICE_OWNER_TYPE_FINANCED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,10 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.enterprise;
|
package com.android.settings.enterprise;
|
||||||
|
|
||||||
|
import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_DEFAULT;
|
||||||
|
import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -42,9 +47,14 @@ public class EnterprisePrivacyPreferenceControllerTest {
|
|||||||
private static final String MANAGED_WITH_NAME = "managed by Foo, Inc.";
|
private static final String MANAGED_WITH_NAME = "managed by Foo, Inc.";
|
||||||
private static final String MANAGING_ORGANIZATION = "Foo, Inc.";
|
private static final String MANAGING_ORGANIZATION = "Foo, Inc.";
|
||||||
private static final String KEY_ENTERPRISE_PRIVACY = "enterprise_privacy";
|
private static final String KEY_ENTERPRISE_PRIVACY = "enterprise_privacy";
|
||||||
|
private static final String FINANCED_PREFERENCE_TITLE = "Financed device info";
|
||||||
|
private static final ComponentName DEVICE_OWNER_COMPONENT =
|
||||||
|
new ComponentName("com.android.foo", "bar");
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private DevicePolicyManager mDevicePolicyManager;
|
||||||
private FakeFeatureFactory mFeatureFactory;
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
|
||||||
private EnterprisePrivacyPreferenceController mController;
|
private EnterprisePrivacyPreferenceController mController;
|
||||||
@@ -54,6 +64,14 @@ public class EnterprisePrivacyPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mController = new EnterprisePrivacyPreferenceController(mContext);
|
mController = new EnterprisePrivacyPreferenceController(mContext);
|
||||||
|
|
||||||
|
when((Object) mContext.getSystemService(DevicePolicyManager.class))
|
||||||
|
.thenReturn(mDevicePolicyManager);
|
||||||
|
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||||
|
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser())
|
||||||
|
.thenReturn(DEVICE_OWNER_COMPONENT);
|
||||||
|
when(mDevicePolicyManager.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
|
||||||
|
.thenReturn(DEVICE_OWNER_TYPE_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -76,6 +94,25 @@ public class EnterprisePrivacyPreferenceControllerTest {
|
|||||||
assertThat(preference.getSummary()).isEqualTo(MANAGED_WITH_NAME);
|
assertThat(preference.getSummary()).isEqualTo(MANAGED_WITH_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateState_verifyPreferenceTitleIsUpdatedForFinancedDevice() {
|
||||||
|
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||||
|
when(mContext.getResources().getString(
|
||||||
|
R.string.enterprise_privacy_settings_summary_with_name, MANAGING_ORGANIZATION))
|
||||||
|
.thenReturn(MANAGED_WITH_NAME);
|
||||||
|
when(mContext.getString(R.string.financed_privacy_settings))
|
||||||
|
.thenReturn(FINANCED_PREFERENCE_TITLE);
|
||||||
|
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getDeviceOwnerOrganizationName())
|
||||||
|
.thenReturn(MANAGING_ORGANIZATION);
|
||||||
|
when(mDevicePolicyManager.getDeviceOwnerType(DEVICE_OWNER_COMPONENT))
|
||||||
|
.thenReturn(DEVICE_OWNER_TYPE_FINANCED);
|
||||||
|
|
||||||
|
mController.updateState(preference);
|
||||||
|
|
||||||
|
assertThat(preference.getTitle()).isEqualTo(FINANCED_PREFERENCE_TITLE);
|
||||||
|
assertThat(preference.getSummary()).isEqualTo(MANAGED_WITH_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable() {
|
public void testIsAvailable() {
|
||||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner()).thenReturn(false);
|
when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner()).thenReturn(false);
|
||||||
|
Reference in New Issue
Block a user