Add default IME to Privacy Settings page
This CL adds information about default IMEs set by Device Owner and/or Profile Owners to the Enterprise Privacy Setting page. Test: make RunSettingsRoboTests Bug: 32692748 Change-Id: I9f78ab4792a5a1d444808048ff33e3e20a0483dc
This commit is contained in:
@@ -8164,6 +8164,8 @@
|
||||
<item quantity="one"><xliff:g id="count">%d</xliff:g> default app set by your admin</item>
|
||||
<item quantity="other"><xliff:g id="count">%d</xliff:g> default apps set by your admin</item>
|
||||
</plurals>
|
||||
<!-- Label explaining that the current input method was set by the admin. [CHAR LIMIT=NONE] -->
|
||||
<string name="enterprise_privacy_input_method">Default keyboard set to <xliff:g id="app_label" example="Example Keyboard">%s</xliff:g> by your admin</string>
|
||||
<!-- Label explaining that an always-on VPN was set by the admin for the entire device. [CHAR LIMIT=NONE] -->
|
||||
<string name="enterprise_privacy_always_on_vpn_device">Always-on VPN turned on</string>
|
||||
<!-- Label explaining that an always-on VPN was set by the admin in the personal profile. [CHAR LIMIT=NONE] -->
|
||||
|
@@ -88,6 +88,10 @@
|
||||
android:title="@string/enterprise_privacy_always_on_vpn_work"
|
||||
settings:allowDividerBelow="true"
|
||||
settings:multiLine="true"/>
|
||||
<com.android.settings.DividerPreference
|
||||
android:key="input_method"
|
||||
settings:allowDividerBelow="true"
|
||||
settings:multiLine="true"/>
|
||||
<com.android.settings.DividerPreference
|
||||
android:key="global_http_proxy"
|
||||
android:title="@string/enterprise_privacy_global_http_proxy"
|
||||
|
@@ -216,7 +216,7 @@ public class ChooseAccountActivity extends SettingsPreferenceFragment {
|
||||
}
|
||||
|
||||
private void addEnterpriseDisclosure() {
|
||||
final CharSequence disclosure = mFeatureProvider.getDeviceOwnerDisclosure(getActivity());
|
||||
final CharSequence disclosure = mFeatureProvider.getDeviceOwnerDisclosure();
|
||||
if (disclosure == null) {
|
||||
return;
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.os.UserHandle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@@ -89,4 +90,11 @@ public interface DevicePolicyManagerWrapper {
|
||||
* @see android.app.admin.DevicePolicyManager#getLastNetworkLogRetrievalTime
|
||||
*/
|
||||
long getLastNetworkLogRetrievalTime();
|
||||
|
||||
/**
|
||||
* Calls {@code DevicePolicyManager.isCurrentInputMethodSetByOwner()}.
|
||||
*
|
||||
* @see android.app.admin.DevicePolicyManager#isCurrentInputMethodSetByOwner
|
||||
*/
|
||||
boolean isCurrentInputMethodSetByOwner();
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.enterprise;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.os.UserHandle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public class DevicePolicyManagerWrapperImpl implements DevicePolicyManagerWrapper {
|
||||
@@ -72,4 +73,9 @@ public class DevicePolicyManagerWrapperImpl implements DevicePolicyManagerWrappe
|
||||
public long getLastNetworkLogRetrievalTime() {
|
||||
return mDpm.getLastNetworkLogRetrievalTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurrentInputMethodSetByOwner() {
|
||||
return mDpm.isCurrentInputMethodSetByOwner();
|
||||
}
|
||||
}
|
||||
|
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public interface EnterprisePrivacyFeatureProvider {
|
||||
@@ -37,10 +35,8 @@ public interface EnterprisePrivacyFeatureProvider {
|
||||
* Returns a message informing the user that the device is managed by a Device Owner app. The
|
||||
* message includes a Learn More link that takes the user to the enterprise privacy section of
|
||||
* Settings. If the device is not managed by a Device Owner app, returns {@code null}.
|
||||
*
|
||||
* @param context The context in which to show the enterprise privacy section of Settings
|
||||
*/
|
||||
CharSequence getDeviceOwnerDisclosure(Context context);
|
||||
CharSequence getDeviceOwnerDisclosure();
|
||||
|
||||
/**
|
||||
* Returns the time at which the Device Owner last retrieved security logs, or {@code null} if
|
||||
@@ -86,4 +82,10 @@ public interface EnterprisePrivacyFeatureProvider {
|
||||
* user's managed profile (if any) is wiped, or zero if no such limit is set.
|
||||
*/
|
||||
int getMaximumFailedPasswordsBeforeWipeInManagedProfile();
|
||||
|
||||
/**
|
||||
* Returns the label of the current user's input method if that input method was set by a Device
|
||||
* Owner or Profile Owner in that user. Otherwise, returns {@code null}.
|
||||
*/
|
||||
String getImeLabelIfOwnerSet();
|
||||
}
|
||||
|
@@ -17,8 +17,10 @@
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.Resources;
|
||||
@@ -39,6 +41,7 @@ import java.util.List;
|
||||
|
||||
public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFeatureProvider {
|
||||
|
||||
private final Context mContext;
|
||||
private final DevicePolicyManagerWrapper mDpm;
|
||||
private final PackageManagerWrapper mPm;
|
||||
private final UserManager mUm;
|
||||
@@ -47,9 +50,10 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
||||
|
||||
private static final int MY_USER_ID = UserHandle.myUserId();
|
||||
|
||||
public EnterprisePrivacyFeatureProviderImpl(DevicePolicyManagerWrapper dpm,
|
||||
public EnterprisePrivacyFeatureProviderImpl(Context context, DevicePolicyManagerWrapper dpm,
|
||||
PackageManagerWrapper pm, UserManager um, ConnectivityManagerWrapper cm,
|
||||
Resources resources) {
|
||||
mContext = context.getApplicationContext();
|
||||
mDpm = dpm;
|
||||
mPm = pm;
|
||||
mUm = um;
|
||||
@@ -80,7 +84,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getDeviceOwnerDisclosure(Context context) {
|
||||
public CharSequence getDeviceOwnerDisclosure() {
|
||||
if (!hasDeviceOwner()) {
|
||||
return null;
|
||||
}
|
||||
@@ -95,7 +99,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
||||
}
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more_separator));
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more),
|
||||
new EnterprisePrivacySpan(context), 0);
|
||||
new EnterprisePrivacySpan(mContext), 0);
|
||||
return disclosure;
|
||||
}
|
||||
|
||||
@@ -156,6 +160,24 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
||||
return mDpm.getMaximumFailedPasswordsForWipe(profileOwner, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImeLabelIfOwnerSet() {
|
||||
if (!mDpm.isCurrentInputMethodSetByOwner()) {
|
||||
return null;
|
||||
}
|
||||
final String packageName = Settings.Secure.getStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.DEFAULT_INPUT_METHOD, MY_USER_ID);
|
||||
if (packageName == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return mPm.getApplicationInfoAsUser(packageName, 0 /* flags */, MY_USER_ID)
|
||||
.loadLabel(mPm.getPackageManager()).toString();
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class EnterprisePrivacySpan extends ClickableSpan {
|
||||
private final Context mContext;
|
||||
|
||||
|
@@ -65,6 +65,7 @@ public class EnterprisePrivacySettings extends DashboardFragment {
|
||||
controllers.add(new GlobalHttpProxyPreferenceController(context));
|
||||
controllers.add(new FailedPasswordWipePrimaryUserPreferenceController(context));
|
||||
controllers.add(new FailedPasswordWipeManagedProfilePreferenceController(context));
|
||||
controllers.add(new ImePreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.content.res.Resources;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
public class ImePreferenceController extends PreferenceController {
|
||||
|
||||
private static final String KEY_INPUT_METHOD = "input_method";
|
||||
private final EnterprisePrivacyFeatureProvider mFeatureProvider;
|
||||
|
||||
public ImePreferenceController(Context context) {
|
||||
super(context);
|
||||
mFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getEnterprisePrivacyFeatureProvider(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final String ownerSetIme = mFeatureProvider.getImeLabelIfOwnerSet();
|
||||
if (ownerSetIme == null) {
|
||||
preference.setVisible(false);
|
||||
return;
|
||||
}
|
||||
preference.setTitle(mContext.getResources().getString(
|
||||
R.string.enterprise_privacy_input_method, ownerSetIme));
|
||||
preference.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_INPUT_METHOD;
|
||||
}
|
||||
}
|
@@ -116,7 +116,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
@Override
|
||||
public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) {
|
||||
if (mEnterprisePrivacyFeatureProvider == null) {
|
||||
mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(
|
||||
mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(context,
|
||||
new DevicePolicyManagerWrapperImpl((DevicePolicyManager) context
|
||||
.getSystemService(Context.DEVICE_POLICY_SERVICE)),
|
||||
new PackageManagerWrapperImpl(context.getPackageManager()),
|
||||
|
@@ -18,12 +18,14 @@ package com.android.settings.enterprise;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ProxyInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -46,6 +48,7 @@ import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
@@ -61,11 +64,16 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
private final int MY_USER_ID = UserHandle.myUserId();
|
||||
private final int MANAGED_PROFILE_USER_ID = MY_USER_ID + 1;
|
||||
private final String VPN_PACKAGE_ID = "com.example.vpn";
|
||||
private final String IME_PACKAGE_ID = "com.example.ime";
|
||||
private final String OTHER_PACKAGE_ID = "com.example.other";
|
||||
private final String IME_PACKAGE_LABEL = "Test IME";
|
||||
|
||||
private List<UserInfo> mProfiles = new ArrayList();
|
||||
|
||||
private @Mock Context mContext;
|
||||
private @Mock DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
private @Mock PackageManagerWrapper mPackageManager;
|
||||
private @Mock PackageManagerWrapper mPackageManagerWrapper;
|
||||
private @Mock PackageManager mPackageManager;
|
||||
private @Mock UserManager mUserManager;
|
||||
private @Mock ConnectivityManagerWrapper mConnectivityManger;
|
||||
private Resources mResources;
|
||||
@@ -76,14 +84,14 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN))
|
||||
.thenReturn(true);
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
resetAndInitializePackageManagerWrapper();
|
||||
when(mUserManager.getProfiles(MY_USER_ID)).thenReturn(mProfiles);
|
||||
mProfiles.add(new UserInfo(MY_USER_ID, "", "", 0 /* flags */));
|
||||
mResources = ShadowApplication.getInstance().getApplicationContext().getResources();
|
||||
|
||||
mProvider = new EnterprisePrivacyFeatureProviderImpl(mDevicePolicyManager, mPackageManager,
|
||||
mUserManager, mConnectivityManger, mResources);
|
||||
mProvider = new EnterprisePrivacyFeatureProviderImpl(mContext, mDevicePolicyManager,
|
||||
mPackageManagerWrapper, mUserManager, mConnectivityManger, mResources);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,28 +114,26 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
|
||||
@Test
|
||||
public void testGetDeviceOwnerDisclosure() {
|
||||
final Context context = mock(Context.class);
|
||||
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
|
||||
assertThat(mProvider.getDeviceOwnerDisclosure(context)).isNull();
|
||||
assertThat(mProvider.getDeviceOwnerDisclosure()).isNull();
|
||||
|
||||
SpannableStringBuilder disclosure = new SpannableStringBuilder();
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_generic));
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more_separator));
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more),
|
||||
new EnterprisePrivacyFeatureProviderImpl.EnterprisePrivacySpan(context), 0);
|
||||
new EnterprisePrivacyFeatureProviderImpl.EnterprisePrivacySpan(mContext), 0);
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(OWNER);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
|
||||
assertThat(mProvider.getDeviceOwnerDisclosure(context)).isEqualTo(disclosure);
|
||||
assertThat(mProvider.getDeviceOwnerDisclosure()).isEqualTo(disclosure);
|
||||
|
||||
disclosure = new SpannableStringBuilder();
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_with_name,
|
||||
OWNER_ORGANIZATION));
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more_separator));
|
||||
disclosure.append(mResources.getString(R.string.do_disclosure_learn_more),
|
||||
new EnterprisePrivacyFeatureProviderImpl.EnterprisePrivacySpan(context), 0);
|
||||
new EnterprisePrivacyFeatureProviderImpl.EnterprisePrivacySpan(mContext), 0);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(OWNER_ORGANIZATION);
|
||||
assertThat(mProvider.getDeviceOwnerDisclosure(context)).isEqualTo(disclosure);
|
||||
assertThat(mProvider.getDeviceOwnerDisclosure()).isEqualTo(disclosure);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,4 +223,43 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
mProfiles.add(new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE));
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInManagedProfile()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetImeLabelIfOwnerSet() throws Exception {
|
||||
final ApplicationInfo applicationInfo = mock(ApplicationInfo.class);
|
||||
when(applicationInfo.loadLabel(mPackageManager)).thenReturn(IME_PACKAGE_LABEL);
|
||||
|
||||
Settings.Secure.putString(null, Settings.Secure.DEFAULT_INPUT_METHOD, IME_PACKAGE_ID);
|
||||
when(mPackageManagerWrapper.getApplicationInfoAsUser(IME_PACKAGE_ID, 0, MY_USER_ID))
|
||||
.thenReturn(applicationInfo);
|
||||
|
||||
// IME not set by Device Owner.
|
||||
when(mDevicePolicyManager.isCurrentInputMethodSetByOwner()).thenReturn(false);
|
||||
assertThat(mProvider.getImeLabelIfOwnerSet()).isNull();
|
||||
|
||||
// Device Owner set IME to empty string.
|
||||
when(mDevicePolicyManager.isCurrentInputMethodSetByOwner()).thenReturn(true);
|
||||
Settings.Secure.putString(null, Settings.Secure.DEFAULT_INPUT_METHOD, null);
|
||||
assertThat(mProvider.getImeLabelIfOwnerSet()).isNull();
|
||||
|
||||
// Device Owner set IME to nonexistent package.
|
||||
Settings.Secure.putString(null, Settings.Secure.DEFAULT_INPUT_METHOD, IME_PACKAGE_ID);
|
||||
when(mPackageManagerWrapper.getApplicationInfoAsUser(IME_PACKAGE_ID, 0, MY_USER_ID))
|
||||
.thenThrow(new PackageManager.NameNotFoundException());
|
||||
assertThat(mProvider.getImeLabelIfOwnerSet()).isNull();
|
||||
|
||||
// Device Owner set IME to existent package.
|
||||
resetAndInitializePackageManagerWrapper();
|
||||
when(mPackageManagerWrapper.getApplicationInfoAsUser(IME_PACKAGE_ID, 0, MY_USER_ID))
|
||||
.thenReturn(applicationInfo);
|
||||
assertThat(mProvider.getImeLabelIfOwnerSet()).isEqualTo(IME_PACKAGE_LABEL);
|
||||
}
|
||||
|
||||
private void resetAndInitializePackageManagerWrapper() {
|
||||
reset(mPackageManagerWrapper);
|
||||
when(mPackageManagerWrapper.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN))
|
||||
.thenReturn(true);
|
||||
when(mPackageManagerWrapper.getPackageManager()).thenReturn(mPackageManager);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -73,7 +73,7 @@ public final class EnterprisePrivacySettingsTest {
|
||||
final List<PreferenceController> controllers = mSettings.getPreferenceControllers(
|
||||
ShadowApplication.getInstance().getApplicationContext());
|
||||
assertThat(controllers).isNotNull();
|
||||
assertThat(controllers.size()).isEqualTo(14);
|
||||
assertThat(controllers.size()).isEqualTo(15);
|
||||
assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class);
|
||||
assertThat(controllers.get(1)).isInstanceOf(NetworkLogsPreferenceController.class);
|
||||
assertThat(controllers.get(2)).isInstanceOf(BugReportsPreferenceController.class);
|
||||
@@ -95,5 +95,6 @@ public final class EnterprisePrivacySettingsTest {
|
||||
assertThat(controllers.get(11)).isInstanceOf(GlobalHttpProxyPreferenceController.class);
|
||||
assertThat(controllers.get(12)).isInstanceOf(FailedPasswordWipePrimaryUserPreferenceController.class);
|
||||
assertThat(controllers.get(13)).isInstanceOf(FailedPasswordWipeManagedProfilePreferenceController.class);
|
||||
assertThat(controllers.get(14)).isInstanceOf(ImePreferenceController.class);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.content.res.Resources;
|
||||
import com.android.settings.R;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link ImePreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class ImePreferenceControllerTest {
|
||||
|
||||
private final String DEFAULT_IME_LABEL = "Test IME";
|
||||
private final String DEFAULT_IME_TEXT = "IME set to Test IME";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private ImePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new ImePreferenceController(mContext);
|
||||
when(mContext.getResources().getString(R.string.enterprise_privacy_input_method,
|
||||
DEFAULT_IME_LABEL)).thenReturn(DEFAULT_IME_TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
preference.setVisible(true);
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
|
||||
.thenReturn(null);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.isVisible()).isFalse();
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getImeLabelIfOwnerSet())
|
||||
.thenReturn(DEFAULT_IME_LABEL);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.isVisible()).isTrue();
|
||||
assertThat(preference.getTitle()).isEqualTo(DEFAULT_IME_TEXT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick() {
|
||||
assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceKey() {
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo("input_method");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user