Skip to content

Commit

Permalink
Merge pull request #3729 from jongerrish/patch184337175
Browse files Browse the repository at this point in the history
Implement support for O system services
  • Loading branch information
jongerrish committed Feb 2, 2018
2 parents 335e662 + 11ac8d7 commit b70dc15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1;
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.O;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -38,6 +39,8 @@
import android.view.Gravity;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.CaptioningManager;
import android.view.autofill.AutofillManager;
import android.view.textclassifier.TextClassificationManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import java.util.List;
Expand Down Expand Up @@ -125,6 +128,17 @@ public void shouldProvideServicesIntroducedMarshmallow() throws Exception {
checkSystemService(Context.FINGERPRINT_SERVICE, FingerprintManager.class);
}

@Test
@Config(minSdk = O)
public void shouldProvideServicesIntroducedOreo() throws Exception {
// Context.AUTOFILL_MANAGER_SERVICE is marked @hide and this is the documented way to obtain this
// service.
AutofillManager autofillManager = RuntimeEnvironment.application.getSystemService(AutofillManager.class);
assertThat(autofillManager).isNotNull();

checkSystemService(Context.TEXT_CLASSIFICATION_SERVICE, TextClassificationManager.class);
}

@Test public void shouldProvideLayoutInflater() throws Exception {
Object systemService = RuntimeEnvironment.application.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assertThat(systemService).isInstanceOf(RoboLayoutInflater.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.os.UserHandle;
import android.view.Display;
import android.view.accessibility.AccessibilityManager;
import android.view.autofill.IAutoFillManager;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -92,6 +93,8 @@ public class ShadowContextImpl {
SYSTEM_SERVICE_MAP.put(Context.WALLPAPER_SERVICE, "android.app.WallpaperManager");
SYSTEM_SERVICE_MAP.put(Context.WIFI_P2P_SERVICE, "android.net.wifi.p2p.WifiP2pManager");
SYSTEM_SERVICE_MAP.put(Context.USB_SERVICE, "android.hardware.usb.UsbManager");
SYSTEM_SERVICE_MAP.put(Context.AUTOFILL_MANAGER_SERVICE, "android.view.autofill.AutofillManager");
SYSTEM_SERVICE_MAP.put(Context.TEXT_CLASSIFICATION_SERVICE, "android.view.textclassifier.TextClassificationManager");

if (getApiLevel() >= JELLY_BEAN_MR1) {
SYSTEM_SERVICE_MAP.put(Context.DISPLAY_SERVICE, "android.hardware.display.DisplayManager");
Expand Down Expand Up @@ -219,6 +222,13 @@ public Object getSystemService(String name) {
service = ReflectionHelpers.callConstructor(clazz,
ClassParameter.from(Context.class, RuntimeEnvironment.application),
ClassParameter.from(IFingerprintService.class, null));
} else if (getApiLevel() >= O && serviceClassName.equals("android.view.autofill.AutofillManager")) {
service = ReflectionHelpers.callConstructor(clazz,
ClassParameter.from(Context.class, RuntimeEnvironment.application),
ClassParameter.from(IAutoFillManager.class, null));
} else if (getApiLevel() >= O && serviceClassName.equals("android.view.textclassifier.TextClassificationManager")) {
service = ReflectionHelpers.callConstructor(clazz,
ClassParameter.from(Context.class, RuntimeEnvironment.application));
} else {
service = newInstanceOf(clazz);
}
Expand Down

0 comments on commit b70dc15

Please sign in to comment.