Make on-screen keyboard settings support tab layout
Introduces following fragments for work flow. - Add ProfileSelectKeyboardFragment which used to display personal/work fragment when user has work profile. - Introduce UserAwareContext in AvailableVirtualKeyboardFragment to support personal/work user installed input methods handling. Bug: 174360557 Bug: 197707782 Test: Manual test as bug video Change-Id: I1019e375c5d42de7bc7c048d5d66e8e2f58acce8
This commit is contained in:
@@ -90,13 +90,6 @@
|
|||||||
android:title="@string/language_and_input_for_work_category_title"
|
android:title="@string/language_and_input_for_work_category_title"
|
||||||
settings:searchable="false">
|
settings:searchable="false">
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="virtual_keyboards_for_work_pref"
|
|
||||||
android:title="@string/virtual_keyboards_for_work_title"
|
|
||||||
android:fragment="com.android.settings.inputmethod.AvailableVirtualKeyboardFragment"
|
|
||||||
settings:forWork="true"
|
|
||||||
settings:controller="com.android.settings.inputmethod.VirtualKeyboardForWorkPreferenceController" />
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="spellcheckers_settings_for_work_pref"
|
android:key="spellcheckers_settings_for_work_pref"
|
||||||
android:title="@string/spellcheckers_settings_for_work_title"
|
android:title="@string/spellcheckers_settings_for_work_title"
|
||||||
|
@@ -21,6 +21,7 @@ import android.util.ArrayMap;
|
|||||||
import com.android.settings.accounts.AccountDashboardFragment;
|
import com.android.settings.accounts.AccountDashboardFragment;
|
||||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||||
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
||||||
|
import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
|
||||||
import com.android.settings.location.LocationServices;
|
import com.android.settings.location.LocationServices;
|
||||||
import com.android.settings.location.RecentLocationAccessSeeAllFragment;
|
import com.android.settings.location.RecentLocationAccessSeeAllFragment;
|
||||||
|
|
||||||
@@ -49,5 +50,7 @@ public class ProfileFragmentBridge {
|
|||||||
ProfileSelectLocationServicesFragment.class.getName());
|
ProfileSelectLocationServicesFragment.class.getName());
|
||||||
FRAGMENT_MAP.put(StorageDashboardFragment.class.getName(),
|
FRAGMENT_MAP.put(StorageDashboardFragment.class.getName(),
|
||||||
ProfileSelectStorageFragment.class.getName());
|
ProfileSelectStorageFragment.class.getName());
|
||||||
|
FRAGMENT_MAP.put(AvailableVirtualKeyboardFragment.class.getName(),
|
||||||
|
ProfileSelectKeyboardFragment.class.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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.dashboard.profileselector;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When current user has work profile, this fragment used following fragments to represent the
|
||||||
|
* on-screen keyboard settings page.
|
||||||
|
*
|
||||||
|
* <p>{@link AvailableVirtualKeyboardFragment} used to show both of personal/work user installed
|
||||||
|
* IMEs.</p>
|
||||||
|
*/
|
||||||
|
public final class ProfileSelectKeyboardFragment extends ProfileSelectFragment {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.available_virtual_keyboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment[] getFragments() {
|
||||||
|
final Bundle personalOnly = new Bundle();
|
||||||
|
personalOnly.putInt(EXTRA_PROFILE, ProfileType.PERSONAL);
|
||||||
|
final Fragment personalFragment = new AvailableVirtualKeyboardFragment();
|
||||||
|
personalFragment.setArguments(personalOnly);
|
||||||
|
|
||||||
|
final Bundle workOnly = new Bundle();
|
||||||
|
workOnly.putInt(EXTRA_PROFILE, ProfileType.WORK);
|
||||||
|
final Fragment workFragment = new AvailableVirtualKeyboardFragment();
|
||||||
|
workFragment.setArguments(workOnly);
|
||||||
|
|
||||||
|
return new Fragment[]{
|
||||||
|
personalFragment,
|
||||||
|
workFragment
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@@ -16,18 +16,21 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.inputmethod.InputMethodAndSubtypeUtilCompat;
|
import com.android.settingslib.inputmethod.InputMethodAndSubtypeUtilCompat;
|
||||||
import com.android.settingslib.inputmethod.InputMethodPreference;
|
import com.android.settingslib.inputmethod.InputMethodPreference;
|
||||||
@@ -38,23 +41,41 @@ import java.text.Collator;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The fragment for on-screen keyboard settings which used to display user installed IMEs.
|
||||||
|
*
|
||||||
|
* TODO(b/207452897): Add test for AvailableVirtualKeyboardFragment
|
||||||
|
*/
|
||||||
@SearchIndexable
|
@SearchIndexable
|
||||||
public final class AvailableVirtualKeyboardFragment extends SettingsPreferenceFragment
|
public final class AvailableVirtualKeyboardFragment extends DashboardFragment
|
||||||
implements InputMethodPreference.OnSavePreferenceListener {
|
implements InputMethodPreference.OnSavePreferenceListener {
|
||||||
|
private static final String TAG = "AvailableVirtualKeyboardFragment";
|
||||||
|
|
||||||
private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList<>();
|
private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList<>();
|
||||||
private InputMethodSettingValuesWrapper mInputMethodSettingValues;
|
private InputMethodSettingValuesWrapper mInputMethodSettingValues;
|
||||||
private InputMethodManager mImm;
|
private Context mUserAwareContext;
|
||||||
private DevicePolicyManager mDpm;
|
private int mUserId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle bundle, String s) {
|
public void onCreatePreferences(Bundle bundle, String s) {
|
||||||
addPreferencesFromResource(R.xml.available_virtual_keyboard);
|
addPreferencesFromResource(R.xml.available_virtual_keyboard);
|
||||||
Activity activity = getActivity();
|
mInputMethodSettingValues = InputMethodSettingValuesWrapper.getInstance(mUserAwareContext);
|
||||||
|
}
|
||||||
|
|
||||||
mInputMethodSettingValues = InputMethodSettingValuesWrapper.getInstance(activity);
|
@Override
|
||||||
mImm = activity.getSystemService(InputMethodManager.class);
|
public void onAttach(Context context) {
|
||||||
mDpm = activity.getSystemService(DevicePolicyManager.class);
|
super.onAttach(context);
|
||||||
|
final int profileType = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE);
|
||||||
|
if (profileType == ProfileSelectFragment.ProfileType.WORK) {
|
||||||
|
final UserManager userManager = UserManager.get(context);
|
||||||
|
final UserHandle workUser = Utils.getManagedProfile(userManager);
|
||||||
|
// get work userId
|
||||||
|
mUserId = Utils.getManagedProfileId(userManager, UserHandle.myUserId());
|
||||||
|
mUserAwareContext = context.createContextAsUser(workUser, 0);
|
||||||
|
} else {
|
||||||
|
mUserId = UserHandle.myUserId();
|
||||||
|
mUserAwareContext = context;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,12 +87,25 @@ public final class AvailableVirtualKeyboardFragment extends SettingsPreferenceFr
|
|||||||
updateInputMethodPreferenceViews();
|
updateInputMethodPreferenceViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.available_virtual_keyboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInputMethodPreference(final InputMethodPreference pref) {
|
public void onSaveInputMethodPreference(final InputMethodPreference pref) {
|
||||||
final boolean hasHardwareKeyboard = getResources().getConfiguration().keyboard
|
final boolean hasHardwareKeyboard = getResources().getConfiguration().keyboard
|
||||||
== Configuration.KEYBOARD_QWERTY;
|
== Configuration.KEYBOARD_QWERTY;
|
||||||
InputMethodAndSubtypeUtilCompat.saveInputMethodSubtypeList(this, getContentResolver(),
|
InputMethodAndSubtypeUtilCompat.saveInputMethodSubtypeListForUser(this,
|
||||||
mImm.getInputMethodList(), hasHardwareKeyboard);
|
mUserAwareContext.getContentResolver(),
|
||||||
|
getContext().getSystemService(
|
||||||
|
InputMethodManager.class).getInputMethodListAsUser(mUserId),
|
||||||
|
hasHardwareKeyboard, mUserId);
|
||||||
// Update input method settings and preference list.
|
// Update input method settings and preference list.
|
||||||
mInputMethodSettingValues.refreshAllInputMethodAndSubtypes();
|
mInputMethodSettingValues.refreshAllInputMethodAndSubtypes();
|
||||||
for (final InputMethodPreference p : mInputMethodPreferenceList) {
|
for (final InputMethodPreference p : mInputMethodPreferenceList) {
|
||||||
@@ -88,10 +122,12 @@ public final class AvailableVirtualKeyboardFragment extends SettingsPreferenceFr
|
|||||||
mInputMethodSettingValues.refreshAllInputMethodAndSubtypes();
|
mInputMethodSettingValues.refreshAllInputMethodAndSubtypes();
|
||||||
// Clear existing "InputMethodPreference"s
|
// Clear existing "InputMethodPreference"s
|
||||||
mInputMethodPreferenceList.clear();
|
mInputMethodPreferenceList.clear();
|
||||||
List<String> permittedList = mDpm.getPermittedInputMethodsForCurrentUser();
|
final List<String> permittedList = mUserAwareContext.getSystemService(
|
||||||
final Context context = getPrefContext();
|
DevicePolicyManager.class).getPermittedInputMethods();
|
||||||
|
final Context prefContext = getPrefContext();
|
||||||
final List<InputMethodInfo> imis = mInputMethodSettingValues.getInputMethodList();
|
final List<InputMethodInfo> imis = mInputMethodSettingValues.getInputMethodList();
|
||||||
final List<InputMethodInfo> enabledImis = mImm.getEnabledInputMethodList();
|
final List<InputMethodInfo> enabledImis = getContext().getSystemService(
|
||||||
|
InputMethodManager.class).getEnabledInputMethodListAsUser(mUserId);
|
||||||
final int numImis = (imis == null ? 0 : imis.size());
|
final int numImis = (imis == null ? 0 : imis.size());
|
||||||
for (int i = 0; i < numImis; ++i) {
|
for (int i = 0; i < numImis; ++i) {
|
||||||
final InputMethodInfo imi = imis.get(i);
|
final InputMethodInfo imi = imis.get(i);
|
||||||
@@ -101,12 +137,12 @@ public final class AvailableVirtualKeyboardFragment extends SettingsPreferenceFr
|
|||||||
// allowed by organization. Doing so will allow the user to disable the input method and
|
// allowed by organization. Doing so will allow the user to disable the input method and
|
||||||
// remain complaint with the organization's policy. Once disabled, the input method
|
// remain complaint with the organization's policy. Once disabled, the input method
|
||||||
// cannot be re-enabled because it is not in the permitted list.
|
// cannot be re-enabled because it is not in the permitted list.
|
||||||
final boolean isAllowedByOrganization = permittedList == null
|
final boolean isAllowedByOrganization = permittedList.isEmpty()
|
||||||
|| permittedList.contains(imi.getPackageName())
|
|| permittedList.contains(imi.getPackageName())
|
||||||
|| enabledImis.contains(imi);
|
|| enabledImis.contains(imi);
|
||||||
final InputMethodPreference pref = new InputMethodPreference(
|
final InputMethodPreference pref = new InputMethodPreference(prefContext, imi,
|
||||||
context, imi, isAllowedByOrganization, this);
|
isAllowedByOrganization, this, mUserId);
|
||||||
pref.setIcon(imi.loadIcon(context.getPackageManager()));
|
pref.setIcon(imi.loadIcon(mUserAwareContext.getPackageManager()));
|
||||||
mInputMethodPreferenceList.add(pref);
|
mInputMethodPreferenceList.add(pref);
|
||||||
}
|
}
|
||||||
final Collator collator = Collator.getInstance();
|
final Collator collator = Collator.getInstance();
|
||||||
|
Reference in New Issue
Block a user