mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
am 77f63c8a: Don\'t use RichInputMethodManager in setup wizard
* commit '77f63c8ac64c46de36002fd62c71f1eeebcaf2ac': Don't use RichInputMethodManager in setup wizard
This commit is contained in:
commit
c68632af62
@ -54,13 +54,6 @@ public final class RichInputMethodManager {
|
|||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Caveat: This may cause IPC
|
|
||||||
public static boolean isInputMethodManagerValidForUserOfThisProcess(final Context context) {
|
|
||||||
// Basically called to check whether this IME has been triggered by the current user or not
|
|
||||||
return !((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).
|
|
||||||
getInputMethodList().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void init(final Context context) {
|
public static void init(final Context context) {
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
sInstance.initInternal(context, prefs);
|
sInstance.initInternal(context, prefs);
|
||||||
|
@ -25,9 +25,9 @@ import android.content.pm.PackageManager;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import com.android.inputmethod.compat.IntentCompatUtils;
|
import com.android.inputmethod.compat.IntentCompatUtils;
|
||||||
import com.android.inputmethod.latin.RichInputMethodManager;
|
|
||||||
import com.android.inputmethod.latin.Settings;
|
import com.android.inputmethod.latin.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,17 +65,16 @@ public final class LauncherIconVisibilityManager extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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 been booted,
|
// 1) the package has been re-installed, 2) the device has just booted,
|
||||||
// 3) a multiuser 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 boolean isCurrentImeOfCurrentUser;
|
final InputMethodManager imm =
|
||||||
if (RichInputMethodManager.isInputMethodManagerValidForUserOfThisProcess(context)) {
|
(InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
RichInputMethodManager.init(context);
|
// Called to check whether this IME has been triggered by the current user or not
|
||||||
isCurrentImeOfCurrentUser = SetupActivity.isThisImeCurrent(context);
|
final boolean isInputMethodManagerValidForUserOfThisProcess =
|
||||||
} else {
|
!imm.getInputMethodList().isEmpty();
|
||||||
isCurrentImeOfCurrentUser = false;
|
final boolean isCurrentImeOfCurrentUser = isInputMethodManagerValidForUserOfThisProcess
|
||||||
}
|
&& SetupActivity.isThisImeCurrent(context, imm);
|
||||||
|
|
||||||
if (!isCurrentImeOfCurrentUser) {
|
if (!isCurrentImeOfCurrentUser) {
|
||||||
final int myPid = Process.myPid();
|
final int myPid = Process.myPid();
|
||||||
Log.i(TAG, "Killing my process: pid=" + myPid);
|
Log.i(TAG, "Killing my process: pid=" + myPid);
|
||||||
|
@ -24,8 +24,6 @@ import android.provider.Settings;
|
|||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.RichInputMethodManager;
|
|
||||||
|
|
||||||
public final class SetupActivity extends Activity {
|
public final class SetupActivity extends Activity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
@ -40,17 +38,24 @@ public final class SetupActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We may not be able to get our own {@link InputMethodInfo} just after this IME is installed
|
||||||
|
* because {@link InputMethodManagerService} may not be aware of this IME yet.
|
||||||
|
* Note: {@link RichInputMethodManager} has similar methods. Here in setup wizard, we can't
|
||||||
|
* use it for the reason above.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the IME specified by the context is enabled.
|
* Check if the IME specified by the context is enabled.
|
||||||
* Note that {@link RichInputMethodManager} must have been initialized before calling this
|
* CAVEAT: This may cause a round trip IPC.
|
||||||
* method.
|
|
||||||
*
|
*
|
||||||
* @param context package context of the IME to be checked.
|
* @param context package context of the IME to be checked.
|
||||||
|
* @param imm the {@link InputMethodManager}.
|
||||||
* @return true if this IME is enabled.
|
* @return true if this IME is enabled.
|
||||||
*/
|
*/
|
||||||
public static boolean isThisImeEnabled(final Context context) {
|
/* package */ static boolean isThisImeEnabled(final Context context,
|
||||||
|
final InputMethodManager imm) {
|
||||||
final String packageName = context.getPackageName();
|
final String packageName = context.getPackageName();
|
||||||
final InputMethodManager imm = RichInputMethodManager.getInstance().getInputMethodManager();
|
|
||||||
for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
|
for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
|
||||||
if (packageName.equals(imi.getPackageName())) {
|
if (packageName.equals(imi.getPackageName())) {
|
||||||
return true;
|
return true;
|
||||||
@ -61,17 +66,36 @@ public final class SetupActivity extends Activity {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the IME specified by the context is the current IME.
|
* Check if the IME specified by the context is the current IME.
|
||||||
* Note that {@link RichInputMethodManager} must have been initialized before calling this
|
* CAVEAT: This may cause a round trip IPC.
|
||||||
* method.
|
|
||||||
*
|
*
|
||||||
* @param context package context of the IME to be checked.
|
* @param context package context of the IME to be checked.
|
||||||
|
* @param imm the {@link InputMethodManager}.
|
||||||
* @return true if this IME is the current IME.
|
* @return true if this IME is the current IME.
|
||||||
*/
|
*/
|
||||||
public static boolean isThisImeCurrent(final Context context) {
|
/* package */ static boolean isThisImeCurrent(final Context context,
|
||||||
final InputMethodInfo myImi =
|
final InputMethodManager imm) {
|
||||||
RichInputMethodManager.getInstance().getInputMethodInfoOfThisIme();
|
final InputMethodInfo imi = getInputMethodInfoOf(context.getPackageName(), imm);
|
||||||
final String currentImeId = Settings.Secure.getString(
|
final String currentImeId = Settings.Secure.getString(
|
||||||
context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||||
return myImi.getId().equals(currentImeId);
|
return imi != null && imi.getId().equals(currentImeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get {@link InputMethodInfo} of the IME specified by the package name.
|
||||||
|
* CAVEAT: This may cause a round trip IPC.
|
||||||
|
*
|
||||||
|
* @param packageName package name of the IME.
|
||||||
|
* @param imm the {@link InputMethodManager}.
|
||||||
|
* @return the {@link InputMethodInfo} of the IME specified by the <code>packageName</code>,
|
||||||
|
* or null if not found.
|
||||||
|
*/
|
||||||
|
/* package */ static InputMethodInfo getInputMethodInfoOf(final String packageName,
|
||||||
|
final InputMethodManager imm) {
|
||||||
|
for (final InputMethodInfo imi : imm.getInputMethodList()) {
|
||||||
|
if (packageName.equals(imi.getPackageName())) {
|
||||||
|
return imi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import android.provider.Settings;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.VideoView;
|
import android.widget.VideoView;
|
||||||
@ -36,7 +37,6 @@ import com.android.inputmethod.compat.TextViewCompatUtils;
|
|||||||
import com.android.inputmethod.compat.ViewCompatUtils;
|
import com.android.inputmethod.compat.ViewCompatUtils;
|
||||||
import com.android.inputmethod.latin.CollectionUtils;
|
import com.android.inputmethod.latin.CollectionUtils;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.RichInputMethodManager;
|
|
||||||
import com.android.inputmethod.latin.SettingsActivity;
|
import com.android.inputmethod.latin.SettingsActivity;
|
||||||
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
|
||||||
|
|
||||||
@ -48,6 +48,8 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
|
|||||||
|
|
||||||
private static final boolean ENABLE_WELCOME_VIDEO = true;
|
private static final boolean ENABLE_WELCOME_VIDEO = true;
|
||||||
|
|
||||||
|
private InputMethodManager mImm;
|
||||||
|
|
||||||
private View mSetupWizard;
|
private View mSetupWizard;
|
||||||
private View mWelcomeScreen;
|
private View mWelcomeScreen;
|
||||||
private View mSetupScreen;
|
private View mSetupScreen;
|
||||||
@ -69,15 +71,19 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
|
|||||||
private static final int STEP_LAUNCHING_IME_SETTINGS = 4;
|
private static final int STEP_LAUNCHING_IME_SETTINGS = 4;
|
||||||
private static final int STEP_BACK_FROM_IME_SETTINGS = 5;
|
private static final int STEP_BACK_FROM_IME_SETTINGS = 5;
|
||||||
|
|
||||||
final SettingsPoolingHandler mHandler = new SettingsPoolingHandler(this);
|
private SettingsPoolingHandler mHandler;
|
||||||
|
|
||||||
static final class SettingsPoolingHandler
|
private static final class SettingsPoolingHandler
|
||||||
extends StaticInnerHandlerWrapper<SetupWizardActivity> {
|
extends StaticInnerHandlerWrapper<SetupWizardActivity> {
|
||||||
private static final int MSG_POLLING_IME_SETTINGS = 0;
|
private static final int MSG_POLLING_IME_SETTINGS = 0;
|
||||||
private static final long IME_SETTINGS_POLLING_INTERVAL = 200;
|
private static final long IME_SETTINGS_POLLING_INTERVAL = 200;
|
||||||
|
|
||||||
public SettingsPoolingHandler(final SetupWizardActivity outerInstance) {
|
private final InputMethodManager mImmInHandler;
|
||||||
|
|
||||||
|
public SettingsPoolingHandler(final SetupWizardActivity outerInstance,
|
||||||
|
final InputMethodManager imm) {
|
||||||
super(outerInstance);
|
super(outerInstance);
|
||||||
|
mImmInHandler = imm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,7 +94,7 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
|
|||||||
}
|
}
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case MSG_POLLING_IME_SETTINGS:
|
case MSG_POLLING_IME_SETTINGS:
|
||||||
if (SetupActivity.isThisImeEnabled(setupWizardActivity)) {
|
if (SetupActivity.isThisImeEnabled(setupWizardActivity, mImmInHandler)) {
|
||||||
setupWizardActivity.invokeSetupWizardOfThisIme();
|
setupWizardActivity.invokeSetupWizardOfThisIme();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -112,11 +118,12 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
|
|||||||
setTheme(android.R.style.Theme_Translucent_NoTitleBar);
|
setTheme(android.R.style.Theme_Translucent_NoTitleBar);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
|
||||||
|
mHandler = new SettingsPoolingHandler(this, mImm);
|
||||||
|
|
||||||
setContentView(R.layout.setup_wizard);
|
setContentView(R.layout.setup_wizard);
|
||||||
mSetupWizard = findViewById(R.id.setup_wizard);
|
mSetupWizard = findViewById(R.id.setup_wizard);
|
||||||
|
|
||||||
RichInputMethodManager.init(this);
|
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mStepNumber = determineSetupStepNumberFromLauncher();
|
mStepNumber = determineSetupStepNumberFromLauncher();
|
||||||
} else {
|
} else {
|
||||||
@ -143,11 +150,12 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
|
|||||||
R.string.setup_step1_title, R.string.setup_step1_instruction,
|
R.string.setup_step1_title, R.string.setup_step1_instruction,
|
||||||
R.string.setup_step1_finished_instruction, R.drawable.ic_setup_step1,
|
R.string.setup_step1_finished_instruction, R.drawable.ic_setup_step1,
|
||||||
R.string.setup_step1_action);
|
R.string.setup_step1_action);
|
||||||
|
final SettingsPoolingHandler handler = mHandler;
|
||||||
step1.setAction(new Runnable() {
|
step1.setAction(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
invokeLanguageAndInputSettings();
|
invokeLanguageAndInputSettings();
|
||||||
mHandler.startPollingImeSettings();
|
handler.startPollingImeSettings();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mSetupStepGroup.addStep(step1);
|
mSetupStepGroup.addStep(step1);
|
||||||
@ -265,14 +273,15 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
|
|||||||
|
|
||||||
void invokeInputMethodPicker() {
|
void invokeInputMethodPicker() {
|
||||||
// Invoke input method picker.
|
// Invoke input method picker.
|
||||||
RichInputMethodManager.getInstance().getInputMethodManager()
|
mImm.showInputMethodPicker();
|
||||||
.showInputMethodPicker();
|
|
||||||
mNeedsToAdjustStepNumberToSystemState = true;
|
mNeedsToAdjustStepNumberToSystemState = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void invokeSubtypeEnablerOfThisIme() {
|
void invokeSubtypeEnablerOfThisIme() {
|
||||||
final InputMethodInfo imi =
|
final InputMethodInfo imi = SetupActivity.getInputMethodInfoOf(getPackageName(), mImm);
|
||||||
RichInputMethodManager.getInstance().getInputMethodInfoOfThisIme();
|
if (imi == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.setAction(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
|
intent.setAction(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
|
||||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
@ -293,10 +302,10 @@ public final class SetupWizardActivity extends Activity implements View.OnClickL
|
|||||||
|
|
||||||
private int determineSetupStepNumber() {
|
private int determineSetupStepNumber() {
|
||||||
mHandler.cancelPollingImeSettings();
|
mHandler.cancelPollingImeSettings();
|
||||||
if (!SetupActivity.isThisImeEnabled(this)) {
|
if (!SetupActivity.isThisImeEnabled(this, mImm)) {
|
||||||
return STEP_1;
|
return STEP_1;
|
||||||
}
|
}
|
||||||
if (!SetupActivity.isThisImeCurrent(this)) {
|
if (!SetupActivity.isThisImeCurrent(this, mImm)) {
|
||||||
return STEP_2;
|
return STEP_2;
|
||||||
}
|
}
|
||||||
return STEP_3;
|
return STEP_3;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user