am 08f3cdb3: Hide app icon when keyboard is a system app.

* commit '08f3cdb3c87e56ac62f5ac3c573beade592b4b06':
  Hide app icon when keyboard is a system app.
main
Dan Zivkovic 2015-02-23 18:29:55 +00:00 committed by Android Git Automerger
commit 3466a3bd7e
2 changed files with 38 additions and 15 deletions

View File

@ -35,7 +35,7 @@ public class DictionaryFacilitatorLruCache {
private final String mDictionaryNamePrefix; private final String mDictionaryNamePrefix;
private final Object mLock = new Object(); private final Object mLock = new Object();
private final DictionaryFacilitator mDictionaryFacilitator; private final DictionaryFacilitator mDictionaryFacilitator;
private boolean mUseContactsDictionary = false; private boolean mUseContactsDictionary;
private Locale mLocale; private Locale mLocale;
public DictionaryFacilitatorLruCache(final Context context, final String dictionaryNamePrefix) { public DictionaryFacilitatorLruCache(final Context context, final String dictionaryNamePrefix) {
@ -71,13 +71,13 @@ public class DictionaryFacilitatorLruCache {
mDictionaryNamePrefix, null /* listener */); mDictionaryNamePrefix, null /* listener */);
} }
public void setUseContactsDictionary(final boolean useContectsDictionary) { public void setUseContactsDictionary(final boolean useContactsDictionary) {
synchronized (mLock) { synchronized (mLock) {
if (mUseContactsDictionary == useContectsDictionary) { if (mUseContactsDictionary == useContactsDictionary) {
// The value has not been changed. // The value has not been changed.
return; return;
} }
mUseContactsDictionary = useContectsDictionary; mUseContactsDictionary = useContactsDictionary;
resetDictionariesForLocaleLocked(); resetDictionariesForLocaleLocked();
waitForLoadingMainDictionary(mDictionaryFacilitator); waitForLoadingMainDictionary(mDictionaryFacilitator);
} }

View File

@ -20,6 +20,7 @@ import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Process; import android.os.Process;
import android.util.Log; import android.util.Log;
@ -35,6 +36,22 @@ import com.android.inputmethod.latin.utils.UncachedInputMethodManagerUtils;
* package has been replaced by a newer version of the same package. This class also detects * package has been replaced by a newer version of the same package. This class also detects
* {@link Intent#ACTION_BOOT_COMPLETED} and {@link Intent#ACTION_USER_INITIALIZE} broadcast intent. * {@link Intent#ACTION_BOOT_COMPLETED} and {@link Intent#ACTION_USER_INITIALIZE} broadcast intent.
* *
* If this IME has already been installed in the system image and a new version of this IME has
* been installed, {@link Intent#ACTION_MY_PACKAGE_REPLACED} is received by this receiver and it
* will hide the setup wizard's icon.
*
* If this IME has already been installed in the data partition and a new version of this IME has
* been installed, {@link Intent#ACTION_MY_PACKAGE_REPLACED} is received by this receiver but it
* will not hide the setup wizard's icon, and the icon will appear on the launcher.
*
* If this IME hasn't been installed yet and has been newly installed, no
* {@link Intent#ACTION_MY_PACKAGE_REPLACED} will be sent and the setup wizard's icon will appear
* on the launcher.
*
* When the device has been booted, {@link Intent#ACTION_BOOT_COMPLETED} is received by this
* receiver and it checks whether the setup wizard's icon should be appeared or not on the launcher
* depending on which partition this IME is installed.
*
* When the system locale has been changed, {@link Intent#ACTION_LOCALE_CHANGED} is received by * When the system locale has been changed, {@link Intent#ACTION_LOCALE_CHANGED} is received by
* this receiver and the {@link KeyboardLayoutSet}'s cache is cleared. * this receiver and the {@link KeyboardLayoutSet}'s cache is cleared.
*/ */
@ -52,21 +69,22 @@ public final class SystemBroadcastReceiver extends BroadcastReceiver {
final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
final InputMethodSubtype[] additionalSubtypes = richImm.getAdditionalSubtypes(); final InputMethodSubtype[] additionalSubtypes = richImm.getAdditionalSubtypes();
richImm.setAdditionalInputMethodSubtypes(additionalSubtypes); richImm.setAdditionalInputMethodSubtypes(additionalSubtypes);
showAppIcon(context); toggleAppIcon(context);
} else if (Intent.ACTION_BOOT_COMPLETED.equals(intentAction)) { } else if (Intent.ACTION_BOOT_COMPLETED.equals(intentAction)) {
Log.i(TAG, "Boot has been completed"); Log.i(TAG, "Boot has been completed");
showAppIcon(context); toggleAppIcon(context);
} else if (Intent.ACTION_LOCALE_CHANGED.equals(intentAction)) { } else if (Intent.ACTION_LOCALE_CHANGED.equals(intentAction)) {
Log.i(TAG, "System locale changed"); Log.i(TAG, "System locale changed");
KeyboardLayoutSet.onSystemLocaleChanged(); KeyboardLayoutSet.onSystemLocaleChanged();
} }
// The process that hosts this broadcast receiver is invoked and remains alive even after // The process that hosts this broadcast receiver is invoked and remains alive even after
// 1) the package has been re-installed, 2) the device has just booted, // 1) the package has been re-installed,
// 2) the device has just booted,
// 3) a new user has been created. // 3) a new user has been created.
// There is no good reason to keep the process alive if this IME isn't a current IME. // There is no good reason to keep the process alive if this IME isn't a current IME.
final InputMethodManager imm = final InputMethodManager imm = (InputMethodManager)
(InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); context.getSystemService(Context.INPUT_METHOD_SERVICE);
// Called to check whether this IME has been triggered by the current user or not // Called to check whether this IME has been triggered by the current user or not
final boolean isInputMethodManagerValidForUserOfThisProcess = final boolean isInputMethodManagerValidForUserOfThisProcess =
!imm.getInputMethodList().isEmpty(); !imm.getInputMethodList().isEmpty();
@ -79,12 +97,17 @@ public final class SystemBroadcastReceiver extends BroadcastReceiver {
} }
} }
private static void showAppIcon(final Context context) { private static void toggleAppIcon(final Context context) {
final ComponentName setupWizardActivity = new ComponentName(context, SetupActivity.class); final int appInfoFlags = context.getApplicationInfo().flags;
final PackageManager pm = context.getPackageManager(); final boolean isSystemApp = (appInfoFlags & ApplicationInfo.FLAG_SYSTEM) > 0;
pm.setComponentEnabledSetting( if (Log.isLoggable(TAG, Log.INFO)) {
setupWizardActivity, Log.i(TAG, "toggleAppIcon() : FLAG_SYSTEM = " + isSystemApp);
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, }
context.getPackageManager().setComponentEnabledSetting(
new ComponentName(context, SetupActivity.class),
isSystemApp
? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
: PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP); PackageManager.DONT_KILL_APP);
} }
} }