From 1ffdaafd836b6cfff78774432268b380ef6b25b5 Mon Sep 17 00:00:00 2001
From: "Tadashi G. Takaoka" <takaoka@google.com>
Date: Tue, 26 Feb 2013 17:56:54 +0900
Subject: [PATCH] Add setup wizard launcher icon

The setup wizard icon will be hidden if the Android Keyboard is in
system image.

Bug: 8239067
Change-Id: Ib0c0c9e3a0954512c3e03e42a661cdf86eff0dca
---
 java/AndroidManifest.xml                      |  12 +-
 java/res/drawable-hdpi/ic_setup_wizard.png    | Bin 0 -> 702 bytes
 java/res/drawable-mdpi/ic_setup_wizard.png    | Bin 0 -> 626 bytes
 java/res/drawable-xhdpi/ic_setup_wizard.png   | Bin 0 -> 737 bytes
 java/res/drawable-xxhdpi/ic_setup_wizard.png  | Bin 0 -> 892 bytes
 .../inputmethod/compat/IntentCompatUtils.java |  36 +++++
 .../setup/LauncherIconVisibilityManager.java  | 125 ++++++++++++++++++
 .../latin/setup/SetupActivity.java            |  55 +++++---
 8 files changed, 208 insertions(+), 20 deletions(-)
 create mode 100644 java/res/drawable-hdpi/ic_setup_wizard.png
 create mode 100644 java/res/drawable-mdpi/ic_setup_wizard.png
 create mode 100644 java/res/drawable-xhdpi/ic_setup_wizard.png
 create mode 100644 java/res/drawable-xxhdpi/ic_setup_wizard.png
 create mode 100644 java/src/com/android/inputmethod/compat/IntentCompatUtils.java
 create mode 100644 java/src/com/android/inputmethod/latin/setup/LauncherIconVisibilityManager.java

diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml
index b88c18ee5..c05b318b9 100644
--- a/java/AndroidManifest.xml
+++ b/java/AndroidManifest.xml
@@ -24,6 +24,7 @@
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
     <uses-permission android:name="android.permission.READ_CONTACTS" />
+    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
 
     <application android:label="@string/aosp_android_keyboard_ime_name"
             android:icon="@mipmap/ic_ime_settings"
@@ -50,12 +51,21 @@
 
         <activity android:name=".setup.SetupActivity"
                 android:label="@string/aosp_android_keyboard_ime_name"
-                android:icon="@mipmap/ic_ime_settings">
+                android:icon="@drawable/ic_setup_wizard">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
 
+        <receiver android:name=".setup.LauncherIconVisibilityManager">
+            <intent-filter>
+                <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
+                <action android:name="android.intent.action.BOOT_COMPLETED" />
+                <action android:name="android.intent.action.USER_INITIALIZE" />
+            </intent-filter>
+        </receiver>
+
         <activity android:name="SettingsActivity" android:label="@string/english_ime_settings"
                   android:uiOptions="splitActionBarWhenNarrow">
             <intent-filter>
diff --git a/java/res/drawable-hdpi/ic_setup_wizard.png b/java/res/drawable-hdpi/ic_setup_wizard.png
new file mode 100644
index 0000000000000000000000000000000000000000..38fca6d9dd11c50c42b79e374efa63bf51bb4b90
GIT binary patch
literal 702
zcmV;v0zv(WP)<h;3K|Lk000e1NJLTq002k;002k`1^@s6RqeA!0007oNkl<Zc-rlm
zJ&V*p7{^ZqwNdaDY<xXI(K~jt$?Bn?g(9MzD83=09)17|Ei5ej0_ryqt3wdkotZ2M
zwidQFTG+^4W@cCPR1OP?GY8q5gnj1XvGElCKlnG{m&wdSGBZg=MgRZ+0000000000
z002})gR41{w2;R+N2s?0ocRP?JuI~Mo^nm@X5J|Ou%^M~Ps$C2zLdG=r_xpC*euxx
zA+Pp3kftllG3n`pn>iE+1ww&PpntqT`i||mn<$niTqk7moaylGL5V~+%DF;cBweOz
z?w|v%Cn-0G)u=n@kgFS%TWhJkxjt}tjdI;In7)N&8dS`IsduXvi@n9&+kIJFmj~&}
zO5DM7knEXx=Z7!NPO{7K_xRkfogB>EnwZ(?b>nW+SqP4L+;7cSpEfPbG3vC(owW-<
z<_1h%pk3Kp>ME8?)Rw#Z7c`Tn*JsIC=Gwyg+`5nxnHzC^%;WxQw5B&N3|gP{xyN6B
zT-zTX)0eAQ=20LN2n8BafrPqea^IJ+_LmKre~9<iheF+?G7*2>n7Kz@>UBPMypwG0
z_aoNZd~R;gt<T#@*K8>5Ce&S2C^r!5I`%Q3V(M&qhuyD~jlI3y^X+3oxph9X#dYoD
zN49Gov9j&D^U-4M`eMgElu5df@9z2LZT>m!%4fN2G4+Uc^_#*=^b7j!T|X`K;mIG4
zVYsUp3WNfoKqydE1+t$j?S`pzxW3|^Z@&_nHck;4&kefM-AB4SIh_A0sOpsK?$+nW
z(C+T{^npys<Voyf0QkSKFO6mX82rr?clXQtFW+qQm$+h7msp=cflwe62n9lc00000
k00000000000D$uR1_JTag(aT$y#N3J07*qoM6N<$f+w$8egFUf

literal 0
HcmV?d00001

diff --git a/java/res/drawable-mdpi/ic_setup_wizard.png b/java/res/drawable-mdpi/ic_setup_wizard.png
new file mode 100644
index 0000000000000000000000000000000000000000..66e62b820b2a65f396c2925d19e7866c824f4dec
GIT binary patch
literal 626
zcmV-&0*(ENP)<h;3K|Lk000e1NJLTq001xm001xu1^@s6R|5Hm0006xNkl<Zc-rlj
zPe>GT6vx-p2q6%a>R1OUQ)G8`cC|l*<*7~)i0GkHmr$fj5JBLfL$|th5jrM|Ae%eC
zaY67BbkIW-bm-zGbmliB;w4CkU+<0cbAS8B6<dsSd0+T~{yy`2zxUYpelw{Qi^XEG
zSS%K+F_aZ@2dvPRknfH4pL#v^H-mj5O!XGjX=JvLvy^4T=GEPO{$t9rPVfjBK9gV-
z?{ERfw*Xf@gT$Ys;eh*k9TJ(eMDRr07XCxc;Mq}=p+^d;IojvSdz9sueso6rT)&?(
zyX5sDySBL9L76t>IMu*ITncVyTyNMkuBDV}LY`ib-IS;2x7v~Qm%Ve8<;&hBWH*Yz
zS<0+Z*b^NJu`LnaF<H(Hb9*^C-asOs!^}X%{;%w+YK>dzb)u&oc`I(ek>uXsMZ7PQ
z>~}d6?St6x|8JAQ^D9P9U+NlSF5rI@U@wMwOL&8(aZS&_K+!*+Er(aCys+M;`+OhP
zg=}bf?F?l(M_$k~Kv~+|xTtf&IWn2;2A3Q77J{D@{H~_scLUzxl)>7AD9E%rMdQG`
z;-%3Nuc~7PZ!6~q;|HF<>zTit0i!n^e>(2zyOil9hn7{#K5@PpXM87YTem3u{pO(a
z>m1^fRR9KGt7UwZ$2ZPR_$fb|wj4Qu3_l})uU0W3=Zw#i4^?}G{HP0nHhfCsQkypv
z>%=Kn@~_wWN<0ex^E(~~^$<f=x1oSBE})?cV6j*%7K_DVv5r)K0Od=ZFR7P1djJ3c
M07*qoM6N<$g6vo>-T(jq

literal 0
HcmV?d00001

diff --git a/java/res/drawable-xhdpi/ic_setup_wizard.png b/java/res/drawable-xhdpi/ic_setup_wizard.png
new file mode 100644
index 0000000000000000000000000000000000000000..53f70a6175b9e547132483b692261a9cf7b0c9f4
GIT binary patch
literal 737
zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7Ro>U|Qkn;uunK>+P+**&>b-$3K3K
zU7WGfY+nOMmBPJyaf=qrh++x!%uG#Q*&2~C@&5s*4ch}P0<RRO`76a_C#ohTPgE+{
zIoI=&go{p0IbUmO*(Aw5rzbx6&g?(=P4VX4`zOquJKKvDXdMDH{CA37^>mL>_|Zk>
zHw*t9@;Wa5s`ak8_g94l`m4*X%u9-&vLxK;*Q?H1MRQ)e*RQXOw+f#a$1Sxv<}`}~
z0|E(%Ib^@Q@G|9J$Ld#W-$nfV@$SaT?R)R8zH0b0wf$~*ZrbhI+GSdi+g9E%zj|g{
z%NO6WO>4i+NS|H2`%mp=>$m$Z7``pKtIrT|e$h57dG#uzC1*BHeVJ3d@%|rv-j{1T
z-z8SRajV|<>UFk9?ZPiIS+AQFll@K{-CJ+^?0KHu`RnF-Up`){t=e3m^x_{+vDlLp
z>z^GAd-L9Y4Rh7!$P2c|Z=7eUs-Kdk*||&5C{3k0{Z0F(pL-f+UR-=>XV;gLCzdZn
z_+-O2#+q~4W^2Bv|Gv6c@k-;La@qK!N_*c$6wmzj)z#^|1=9`*qcmT=c{<-_s!ob{
zRerD7_siQ$wO&_h>*sq_Y-D6$>29r>XYX)CA$9%3=f-Wb@9lHh|7QLF==+j0^oyB}
z?b&^Z`R?`aH|(x=hQIvhxc<NY%<7%jE(fIF6c_dUYOvsab!}Sa{Jk5d|Nk?)zG~$>
zt98ySJ(lVEYJL0P$;y8D<^EF+DdZ1xDNOnmHf2dU+saE*0#?nsxqNff*YEdgPHYqX
zeWq-}pU>-lRlRlHc0b$n`JP&*_)Y&Ke%<!8sa=@*&ER7aGlRs+`kU@M<4$euFFkzs
tPtC8d#T~&r1H-!+I2sTLkzBwmvxfK{$2IS25)2DKd{0+Dmvv4FO#qF(Um^ei

literal 0
HcmV?d00001

diff --git a/java/res/drawable-xxhdpi/ic_setup_wizard.png b/java/res/drawable-xxhdpi/ic_setup_wizard.png
new file mode 100644
index 0000000000000000000000000000000000000000..6414b4f36b93d96b6b0d5c36e986eebd173d69f4
GIT binary patch
literal 892
zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q4M;wBd$farf!W#9#WAGf*4w+*9WkL22R^!T
zW_<{h*s#e^>4(-F>)8^M9ipr`-GU+_Il`KHy=ugqx)hX}6q2T@X)1Laf8V9Dt2Z=a
z%@zUH?u;ANdDj#kEuMYnw&t@rz43E)NY~r{SQWd^viSM^GjnTobbyv(0iQ#zzD%;;
ztUcqt`HkXtT;Kns9xJWV-d=3t>+f2|xB2xM{_?oI=Z#a}=fB(kuQ=uTikETc=a$B7
zuU?$Kc3C$6^Yz)^vnulI^te16n1m)Yu&5|7a-uOWnDV~3T(|E=!K^Po*{biYef8~!
z{anRKISyZMEuJ{{u+5H1d3)bjhNs_NmHEq{<k~XZ8P>1YWtPW(S<`*`bve+6-!3Kj
ziFO|(c^DWDO#9+-`JJTirGKku{d@au;pENIoBIRT+Y8*Zp0~z!%56)VdykgX>TD`6
z{CWJ+?Pqg0zP=E;bTi-gPNnK{{jKFszwzb&SGI1y{%8M=i4n87cfbC6o7?=b9pAgy
zb8qkLzH;|k{om;q?y2pavRCoOlJ80BZ}**gE3?k`zimBB{uaB*d)Hn5@+oYWur8)A
zp?-hyU+Th#<XL|YEe<!ooBjRT{d-et7x~^Y&)apl(Q?AwomRK6#otj^u6Ccy{XKpC
z@g=LB($`*oyma%o>kk4_-alHhclj5=z!yKo>oy57Ff{nCU3L4sTd9@x^~_!A+}{`a
zxt4`p{!)|oeBR{ec`v`ObNM#y{q7R|mUFk32y^G3$<x@wcKq2tsXsq${$}sHnWvIx
z@OF0V@&9@|K1bv|{}8?MVto8NW~(5J*VYF&*Tr&WglzZzT+eIveQpLutU>&f`>)~L
z_s_RumV2&$B3B<%p8o6oPc;MmwE36SpKt#j|KDia_FBFAYb7e1ibIy~s!`unZC}Bg
zba~0udff#N`vbp;*BqadzMH=nl=9ZqFJ4w##rOaH!(B59=i06E`(M)T<;CcGd;9v2
wYk#dZ*+1={kT!B6GD70GIbcb=K%qZpRV!aey-J)I;{{US>FVdQ&MBb@0L&4aEdT%j

literal 0
HcmV?d00001

diff --git a/java/src/com/android/inputmethod/compat/IntentCompatUtils.java b/java/src/com/android/inputmethod/compat/IntentCompatUtils.java
new file mode 100644
index 000000000..df2e22fe8
--- /dev/null
+++ b/java/src/com/android/inputmethod/compat/IntentCompatUtils.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013 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.inputmethod.compat;
+
+import android.content.Intent;
+
+public final class IntentCompatUtils {
+    // Note that Intent.ACTION_USER_INITIALIZE have been introduced in API level 17
+    // (Build.VERSION_CODE.JELLY_BEAN_MR1).
+    public static final String ACTION_USER_INITIALIZE =
+            (String)CompatUtils.getFieldValue(null, null,
+                    CompatUtils.getField(Intent.class, "ACTION_USER_INITIALIZE"));
+
+    private IntentCompatUtils() {
+        // This utility class is not publicly instantiable.
+    }
+
+    public static boolean has_ACTION_USER_INITIALIZE(final Intent intent) {
+        return ACTION_USER_INITIALIZE != null && intent != null
+                && ACTION_USER_INITIALIZE.equals(intent.getAction());
+    }
+}
diff --git a/java/src/com/android/inputmethod/latin/setup/LauncherIconVisibilityManager.java b/java/src/com/android/inputmethod/latin/setup/LauncherIconVisibilityManager.java
new file mode 100644
index 000000000..ad34011ea
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/setup/LauncherIconVisibilityManager.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2013 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.inputmethod.latin.setup;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.os.Process;
+import android.util.Log;
+
+import com.android.inputmethod.compat.IntentCompatUtils;
+import com.android.inputmethod.latin.RichInputMethodManager;
+
+/**
+ * This class detects the {@link Intent#ACTION_MY_PACKAGE_REPLACED} broadcast intent when this IME
+ * 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.
+ *
+ * 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 a multiuser account has been created, {@link Intent#ACTION_USER_INITIALIZE} is received
+ * by this receiver and it checks the whether the setup wizard's icon should be appeared or not on
+ * the launcher depending on which partition this IME is installed.
+ */
+public final class LauncherIconVisibilityManager extends BroadcastReceiver {
+    private static final String TAG = LauncherIconVisibilityManager.class.getSimpleName();
+
+    @Override
+    public void onReceive(final Context context, final Intent intent) {
+        if (shouldHandleThisIntent(intent, context)) {
+            if (isInSystemImage(context)) {
+                disableActivity(context, SetupActivity.class);
+            } else {
+                Log.i(TAG, "This package isn't in system image: " + context.getPackageName());
+            }
+        }
+
+        // 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,
+        // 3) a multiuser has been created.
+        // There is no good reason to keep the process alive if this IME isn't a current IME.
+        RichInputMethodManager.init(context);
+        if (!SetupActivity.isThisImeCurrent(context)) {
+            final int myPid = Process.myPid();
+            Log.i(TAG, "Killing my process: pid=" + myPid);
+            Process.killProcess(myPid);
+        }
+    }
+
+    private static boolean shouldHandleThisIntent(final Intent intent, final Context context) {
+        final String action = intent.getAction();
+        if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(action)) {
+            Log.i(TAG, "Package has been replaced: " + context.getPackageName());
+            return true;
+        } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
+            Log.i(TAG, "Boot has been completed");
+            return true;
+        } else if (IntentCompatUtils.has_ACTION_USER_INITIALIZE(intent)) {
+            Log.i(TAG, "User initialize");
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Disable an activity of the specified package. Disabling an activity will also hide its
+     * icon from the launcher.
+     *
+     * @param context package context of an activity to be disabled
+     * @param activityClass activity class to be disabled
+     */
+    private static void disableActivity(final Context context,
+            final Class<? extends Activity> activityClass) {
+        final ComponentName activityComponent = new ComponentName(context, activityClass);
+        final PackageManager pm = context.getPackageManager();
+        final int activityComponentState = pm.getComponentEnabledSetting(activityComponent);
+        if (activityComponentState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
+            // This activity is already disabled.
+            Log.i(TAG, "Activity has already been disabled: " + activityComponent);
+            return;
+        }
+        // Disabling an activity will also hide its icon from the launcher.
+        pm.setComponentEnabledSetting(activityComponent,
+                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+                PackageManager.DONT_KILL_APP);
+        Log.i(TAG, "Disable activity: " + activityComponent);
+    }
+
+    private static boolean isInSystemImage(final Context context) {
+        final ApplicationInfo appInfo = context.getApplicationInfo();
+        return (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
+    }
+}
diff --git a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
index c30ecfb16..e009fbc39 100644
--- a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
+++ b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java
@@ -17,6 +17,7 @@
 package com.android.inputmethod.latin.setup;
 
 import android.app.Activity;
+import android.content.Context;
 import android.content.Intent;
 import android.content.res.Resources;
 import android.graphics.PorterDuff;
@@ -43,7 +44,7 @@ public final class SetupActivity extends Activity {
     private SetupStepIndicatorView mStepIndicatorView;
     private final SetupStepGroup mSetupSteps = new SetupStepGroup();
     private static final String STATE_STEP = "step";
-    private int mStepNo;
+    private int mStepNumber;
     private static final int STEP_1 = 1;
     private static final int STEP_2 = 2;
     private static final int STEP_3 = 3;
@@ -63,7 +64,7 @@ public final class SetupActivity extends Activity {
             final SetupActivity setupActivity = getOuterInstance();
             switch (msg.what) {
             case MSG_POLLING_IME_SETTINGS:
-                if (setupActivity.isMyImeEnabled()) {
+                if (SetupActivity.isThisImeEnabled(setupActivity)) {
                     setupActivity.invokeSetupWizardOfThisIme();
                     return;
                 }
@@ -92,12 +93,12 @@ public final class SetupActivity extends Activity {
         RichInputMethodManager.init(this);
 
         if (savedInstanceState == null) {
-            mStepNo = determineSetupStepNo();
+            mStepNumber = determineSetupStepNumber();
         } else {
-            mStepNo = savedInstanceState.getInt(STATE_STEP);
+            mStepNumber = savedInstanceState.getInt(STATE_STEP);
         }
 
-        if (mStepNo == STEP_3) {
+        if (mStepNumber == STEP_3) {
             // This IME already has been enabled and set as current IME.
             // TODO: Implement tutorial.
             invokeSettingsOfThisIme();
@@ -182,8 +183,16 @@ public final class SetupActivity extends Activity {
         startActivity(intent);
     }
 
-    private boolean isMyImeEnabled() {
-        final String packageName = getPackageName();
+    /**
+     * Check if the IME specified by the context is enabled.
+     * Note that {@link RichInputMethodManager} must have been initialized before calling this
+     * method.
+     *
+     * @param context package context of the IME to be checked.
+     * @return true if this IME is enabled.
+     */
+    public static boolean isThisImeEnabled(final Context context) {
+        final String packageName = context.getPackageName();
         final InputMethodManager imm = RichInputMethodManager.getInstance().getInputMethodManager();
         for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
             if (packageName.equals(imi.getPackageName())) {
@@ -193,20 +202,28 @@ public final class SetupActivity extends Activity {
         return false;
     }
 
-    private boolean isMyImeCurrent() {
+    /**
+     * Check if the IME specified by the context is the current IME.
+     * Note that {@link RichInputMethodManager} must have been initialized before calling this
+     * method.
+     *
+     * @param context package context of the IME to be checked.
+     * @return true if this IME is the current IME.
+     */
+    public static boolean isThisImeCurrent(final Context context) {
         final InputMethodInfo myImi =
                 RichInputMethodManager.getInstance().getInputMethodInfoOfThisIme();
         final String currentImeId = Settings.Secure.getString(
-                getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
+                context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
         return myImi.getId().equals(currentImeId);
     }
 
-    private int determineSetupStepNo() {
+    private int determineSetupStepNumber() {
         mHandler.cancelPollingImeSettings();
-        if (!isMyImeEnabled()) {
+        if (!isThisImeEnabled(this)) {
             return STEP_1;
         }
-        if (!isMyImeCurrent()) {
+        if (!isThisImeCurrent(this)) {
             return STEP_2;
         }
         return STEP_3;
@@ -215,25 +232,25 @@ public final class SetupActivity extends Activity {
     @Override
     protected void onSaveInstanceState(final Bundle outState) {
         super.onSaveInstanceState(outState);
-        outState.putInt(STATE_STEP, mStepNo);
+        outState.putInt(STATE_STEP, mStepNumber);
     }
 
     @Override
     protected void onRestoreInstanceState(final Bundle savedInstanceState) {
         super.onRestoreInstanceState(savedInstanceState);
-        mStepNo = savedInstanceState.getInt(STATE_STEP);
+        mStepNumber = savedInstanceState.getInt(STATE_STEP);
     }
 
     @Override
     protected void onStart() {
         super.onStart();
-        mStepNo = determineSetupStepNo();
+        mStepNumber = determineSetupStepNumber();
     }
 
     @Override
     protected void onRestart() {
         super.onRestart();
-        mStepNo = determineSetupStepNo();
+        mStepNumber = determineSetupStepNumber();
     }
 
     @Override
@@ -248,15 +265,15 @@ public final class SetupActivity extends Activity {
         if (!hasFocus) {
             return;
         }
-        mStepNo = determineSetupStepNo();
+        mStepNumber = determineSetupStepNumber();
         updateSetupStepView();
     }
 
     private void updateSetupStepView() {
         final int layoutDirection = ViewCompatUtils.getLayoutDirection(mStepIndicatorView);
         mStepIndicatorView.setIndicatorPosition(
-                getIndicatorPosition(mStepNo, mSetupSteps.getTotalStep(), layoutDirection));
-        mSetupSteps.enableStep(mStepNo);
+                getIndicatorPosition(mStepNumber, mSetupSteps.getTotalStep(), layoutDirection));
+        mSetupSteps.enableStep(mStepNumber);
     }
 
     private static float getIndicatorPosition(final int step, final int totalStep,