Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for O system services #3729

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -9,12 +9,10 @@
import static android.os.Build.VERSION_CODES.N;
import static android.os.Build.VERSION_CODES.N_MR1;
import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.O_MR1;
import static org.robolectric.RuntimeEnvironment.getApiLevel;
import static org.robolectric.shadow.api.Shadow.newInstanceOf;

import android.accounts.IAccountManager;
import android.app.IWallpaperManager;
import android.app.admin.IDevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
Expand All @@ -38,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 @@ -94,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 @@ -161,25 +162,12 @@ public Object getSystemService(String name) {
ClassParameter.from(Handler.class, null));
}
} else if (serviceClassName.equals("android.app.SearchManager")
|| serviceClassName.equals("android.app.ActivityManager")) {
|| serviceClassName.equals("android.app.ActivityManager")
|| serviceClassName.equals("android.app.WallpaperManager")) {

service = ReflectionHelpers.callConstructor(clazz,
ClassParameter.from(Context.class, RuntimeEnvironment.application),
ClassParameter.from(Handler.class, null));
} else if (serviceClassName.equals("android.app.WallpaperManager")) {
if (getApiLevel() <= O_MR1) {
service = ReflectionHelpers.callConstructor(clazz,
ClassParameter.from(Context.class, RuntimeEnvironment.application),
ClassParameter.from(Handler.class, null));
}
// BEGIN-INTERNAL
else {
service = ReflectionHelpers.callConstructor(clazz,
ClassParameter.from(IWallpaperManager.class, null),
ClassParameter.from(Context.class, RuntimeEnvironment.application),
ClassParameter.from(Handler.class, null));
}
// END-INTERNAL
} else if (serviceClassName.equals("android.os.storage.StorageManager")) {
service = ReflectionHelpers.callConstructor(clazz);
} else if (serviceClassName.equals("android.nfc.NfcManager") || serviceClassName.equals("android.telecom.TelecomManager")) {
Expand Down Expand Up @@ -234,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