From 15be5e6f1c19ff329a6382c5063aa58bc92fb36e Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Fri, 25 Jan 2019 17:27:03 -0800 Subject: [PATCH] Take CLONE_TO_MANAGED_PROFILE into account in InputMethodSettings This is a preparation to clone SHOW_IME_WITH_HARD_KEYBOARD to profile users. With this CL, InputMethodSettings takes CLONE_TO_MANAGED_PROFILE into account when writing secure settings. The point is that when a secure settings key is in Settings.Secure.CLONE_TO_MANAGED_PROFILE, the value needs to be written into the profile parent's settings, not the current user's one. In this way, InputMethodSettings doesn't need to be updated when a new entry is added to / removed from CLONE_TO_MANAGED_PROFILE. This CL does not change Settings.Secure.CLONE_TO_MANAGED_PROFILE hence there should be no behavior change. Bug: 123379418 Test: make -j checkbuild Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases Change-Id: Ieefefb8630ddef3b247ebb865a604e5c72dfb49c --- .../server/inputmethod/InputMethodUtils.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java index cfc85dac8a538..326984c7202c5 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java @@ -34,6 +34,7 @@ import android.os.UserManagerInternal; import android.provider.Settings; import android.text.TextUtils; import android.util.ArrayMap; +import android.util.ArraySet; import android.util.IntArray; import android.util.Pair; import android.util.Printer; @@ -756,6 +757,14 @@ final class InputMethodUtils { */ private final ArrayMap mCopyOnWriteDataStore = new ArrayMap<>(); + private static final ArraySet CLONE_TO_MANAGED_PROFILE = new ArraySet<>(); + static { + Settings.Secure.getCloneToManagedProfileSettings(CLONE_TO_MANAGED_PROFILE); + } + + private static final UserManagerInternal sUserManagerInternal = + LocalServices.getService(UserManagerInternal.class); + private boolean mCopyOnWrite = false; @NonNull private String mEnabledInputMethodsStrCache = ""; @@ -833,7 +842,9 @@ final class InputMethodUtils { if (mCopyOnWrite) { mCopyOnWriteDataStore.put(key, str); } else { - Settings.Secure.putStringForUser(mResolver, key, str, mCurrentUserId); + final int userId = CLONE_TO_MANAGED_PROFILE.contains(key) + ? sUserManagerInternal.getProfileParentId(mCurrentUserId) : mCurrentUserId; + Settings.Secure.putStringForUser(mResolver, key, str, userId); } } @@ -852,7 +863,9 @@ final class InputMethodUtils { if (mCopyOnWrite) { mCopyOnWriteDataStore.put(key, String.valueOf(value)); } else { - Settings.Secure.putIntForUser(mResolver, key, value, mCurrentUserId); + final int userId = CLONE_TO_MANAGED_PROFILE.contains(key) + ? sUserManagerInternal.getProfileParentId(mCurrentUserId) : mCurrentUserId; + Settings.Secure.putIntForUser(mResolver, key, value, userId); } }