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:
@@ -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()),
|
||||
|
Reference in New Issue
Block a user