• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.inputmethod.latin;
18 
19 import com.android.inputmethod.latin.settings.Settings;
20 
21 import android.content.pm.ApplicationInfo;
22 import android.content.pm.PackageManager;
23 import android.os.Build.VERSION_CODES;
24 import android.test.suitebuilder.annotation.LargeTest;
25 import android.view.inputmethod.EditorInfo;
26 
27 @LargeTest
28 public class AppWorkaroundsTests extends InputTestsBase {
29     String packageNameOfAppBeforeJellyBean;
30     String packageNameOfAppAfterJellyBean;
31 
32     @Override
setUp()33     protected void setUp() throws Exception {
34         // NOTE: this will fail if there is no app installed that targets an SDK
35         // before Jelly Bean. For the moment, it's fine.
36         final PackageManager pm = getContext().getPackageManager();
37         for (ApplicationInfo ai : pm.getInstalledApplications(0 /* flags */)) {
38             if (ai.targetSdkVersion < VERSION_CODES.JELLY_BEAN) {
39                 packageNameOfAppBeforeJellyBean = ai.packageName;
40             } else {
41                 packageNameOfAppAfterJellyBean = ai.packageName;
42             }
43         }
44         super.setUp();
45     }
46 
47     // We want to test if the app package info is correctly retrieved by LatinIME. Since it
48     // asks this information to the package manager from the package name, and that it takes
49     // the package name from the EditorInfo, all we have to do it put the correct package
50     // name in the editor info.
51     // To this end, our base class InputTestsBase offers a hook for us to touch the EditorInfo.
52     // We override this hook to write the package name that we need.
53     @Override
enrichEditorInfo(final EditorInfo ei)54     protected EditorInfo enrichEditorInfo(final EditorInfo ei) {
55         if ("testBeforeJellyBeanTrue".equals(getName())) {
56             ei.packageName = packageNameOfAppBeforeJellyBean;
57         } else if ("testBeforeJellyBeanFalse".equals(getName())) {
58             ei.packageName = packageNameOfAppAfterJellyBean;
59         }
60         return ei;
61     }
62 
testBeforeJellyBeanTrue()63     public void testBeforeJellyBeanTrue() {
64         assertTrue("Couldn't successfully detect this app targets < Jelly Bean (package is "
65                 + packageNameOfAppBeforeJellyBean + ")",
66                 Settings.getInstance().getCurrent().isBeforeJellyBean());
67     }
68 
testBeforeJellyBeanFalse()69     public void testBeforeJellyBeanFalse() {
70         assertFalse("Couldn't successfully detect this app targets >= Jelly Bean (package is "
71                 + packageNameOfAppAfterJellyBean + ")",
72                 Settings.getInstance().getCurrent().isBeforeJellyBean());
73     }
74 }