Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 094c71fd authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Set DISABLED_UNTIL_USED for the correct user in IMMS.

This CL makes If8ff1b2b95c36d33148def2ab87bd006aa520cc0
multi-user aware.

It turns out that DISABLED_UNTIL_USED has not been correctly
set to IMEs seen from secondary users because we have used
  IMMS#mContext.getPackageManager(),
which always returns the PackageManager with the primary
users' context, when specifying
COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED.

We should use IPackageManager instead as we have already done
in many places of IMMS since Ib23849d352db33f0747aa9d5a178f00.

Bug: 8148605
Bug: 8365223
Bug: 21953608
Change-Id: I4b9d6510bf965204bb1f68c8b527d1a4df23fac4
parent 93297d20
Loading
Loading
Loading
Loading
+29 −10
Original line number Original line Diff line number Diff line
@@ -22,9 +22,10 @@ import android.app.AppOpsManager;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources;
import android.os.RemoteException;
import android.provider.Settings;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Settings.SettingNotFoundException;
import android.text.TextUtils;
import android.text.TextUtils;
@@ -646,7 +647,8 @@ public class InputMethodUtils {
    }
    }


    public static void setNonSelectedSystemImesDisabledUntilUsed(
    public static void setNonSelectedSystemImesDisabledUntilUsed(
            PackageManager packageManager, List<InputMethodInfo> enabledImis) {
            IPackageManager packageManager, List<InputMethodInfo> enabledImis,
            int userId, String callingPackage) {
        if (DEBUG) {
        if (DEBUG) {
            Slog.d(TAG, "setNonSelectedSystemImesDisabledUntilUsed");
            Slog.d(TAG, "setNonSelectedSystemImesDisabledUntilUsed");
        }
        }
@@ -685,9 +687,11 @@ public class InputMethodUtils {
            ApplicationInfo ai = null;
            ApplicationInfo ai = null;
            try {
            try {
                ai = packageManager.getApplicationInfo(packageName,
                ai = packageManager.getApplicationInfo(packageName,
                        PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
                        PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, userId);
            } catch (NameNotFoundException e) {
            } catch (RemoteException e) {
                Slog.w(TAG, "NameNotFoundException: " + packageName, e);
                Slog.w(TAG, "getApplicationInfo failed. packageName=" + packageName
                        + " userId=" + userId, e);
                continue;
            }
            }
            if (ai == null) {
            if (ai == null) {
                // No app found for packageName
                // No app found for packageName
@@ -697,19 +701,34 @@ public class InputMethodUtils {
            if (!isSystemPackage) {
            if (!isSystemPackage) {
                continue;
                continue;
            }
            }
            setDisabledUntilUsed(packageManager, packageName);
            setDisabledUntilUsed(packageManager, packageName, userId, callingPackage);
        }
        }
    }
    }


    private static void setDisabledUntilUsed(PackageManager packageManager, String packageName) {
    private static void setDisabledUntilUsed(IPackageManager packageManager, String packageName,
        final int state = packageManager.getApplicationEnabledSetting(packageName);
            int userId, String callingPackage) {
        final int state;
        try {
            state = packageManager.getApplicationEnabledSetting(packageName, userId);
        } catch (RemoteException e) {
            Slog.w(TAG, "getApplicationEnabledSetting failed. packageName=" + packageName
                    + " userId=" + userId, e);
            return;
        }
        if (state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
        if (state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
                || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
                || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
            if (DEBUG) {
            if (DEBUG) {
                Slog.d(TAG, "Update state(" + packageName + "): DISABLED_UNTIL_USED");
                Slog.d(TAG, "Update state(" + packageName + "): DISABLED_UNTIL_USED");
            }
            }
            try {
                packageManager.setApplicationEnabledSetting(packageName,
                packageManager.setApplicationEnabledSetting(packageName,
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED, 0);
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED,
                        0 /* newState */, userId, callingPackage);
            } catch (RemoteException e) {
                Slog.w(TAG, "setApplicationEnabledSetting failed. packageName=" + packageName
                        + " userId=" + userId + " callingPackage=" + callingPackage, e);
                return;
            }
        } else {
        } else {
            if (DEBUG) {
            if (DEBUG) {
                Slog.d(TAG, packageName + " is already DISABLED_UNTIL_USED");
                Slog.d(TAG, packageName + " is already DISABLED_UNTIL_USED");
+6 −5
Original line number Original line Diff line number Diff line
@@ -1009,8 +1009,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        resetAllInternalStateLocked(false  /* updateOnlyWhenLocaleChanged */,
        resetAllInternalStateLocked(false  /* updateOnlyWhenLocaleChanged */,
                initialUserSwitch /* needsToResetDefaultIme */);
                initialUserSwitch /* needsToResetDefaultIme */);
        if (initialUserSwitch) {
        if (initialUserSwitch) {
            InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mContext.getPackageManager(),
            InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager,
                    mSettings.getEnabledInputMethodListLocked());
                    mSettings.getEnabledInputMethodListLocked(), newUserId,
                    mContext.getBasePackageName());
        }
        }


        if (DEBUG) Slog.d(TAG, "Switching user stage 3/3. newUserId=" + newUserId
        if (DEBUG) Slog.d(TAG, "Switching user stage 3/3. newUserId=" + newUserId
@@ -1067,9 +1068,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                if (!mImeSelectedOnBoot) {
                if (!mImeSelectedOnBoot) {
                    Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here.");
                    Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here.");
                    resetStateIfCurrentLocaleChangedLocked();
                    resetStateIfCurrentLocaleChangedLocked();
                    InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(
                    InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager,
                            mContext.getPackageManager(),
                            mSettings.getEnabledInputMethodListLocked(),
                            mSettings.getEnabledInputMethodListLocked());
                            mSettings.getCurrentUserId(), mContext.getBasePackageName());
                }
                }
                mLastSystemLocale = mRes.getConfiguration().locale;
                mLastSystemLocale = mRes.getConfiguration().locale;
                try {
                try {