Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 6d2c1a2

Browse files
committed
Add missing system services
Lot of system services were missing which are added in newer Android versions. Now AndroidAnnotations support those. Also added tests for all services, and commented out those which cannot be tested due to Android version or Robolectric issues.
1 parent 20204df commit 6d2c1a2

4 files changed

Lines changed: 214 additions & 76 deletions

File tree

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/model/AndroidSystemServices.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,54 @@ public class AndroidSystemServices {
2929
private Map<String, String> registeredServices = new HashMap<String, String>();
3030

3131
public AndroidSystemServices() {
32+
// in alphabetical order
3233
registeredServices.put("android.view.accessibility.AccessibilityManager", "android.content.Context.ACCESSIBILITY_SERVICE");
3334
registeredServices.put("android.accounts.AccountManager", "android.content.Context.ACCOUNT_SERVICE");
3435
registeredServices.put("android.app.ActivityManager", "android.content.Context.ACTIVITY_SERVICE");
3536
registeredServices.put("android.app.AlarmManager", "android.content.Context.ALARM_SERVICE");
37+
registeredServices.put("android.app.AppOpsManager", "android.content.Context.APP_OPS_SERVICE");
38+
registeredServices.put("android.appwidget.AppWidgetManager", "android.content.Context.APPWIDGET_SERVICE");
3639
registeredServices.put("android.media.AudioManager", "android.content.Context.AUDIO_SERVICE");
40+
registeredServices.put("android.app.backup.IBackupManager", "android.content.Context.BACKUP_SERVICE");
41+
registeredServices.put("android.bluetooth.BluetoothAdapter", "android.content.Context.BLUETOOTH_SERVICE");
42+
registeredServices.put("android.hardware.camera2.CameraManager", "android.content.Context.CAMERA_SERVICE");
43+
registeredServices.put("android.view.accessibility.CaptioningManager", "android.content.Context.CAPTIONING_SERVICE");
3744
registeredServices.put("android.content.ClipboardManager", "android.content.Context.CLIPBOARD_SERVICE");
3845
registeredServices.put("android.text.ClipboardManager", "android.content.Context.CLIPBOARD_SERVICE");
3946
registeredServices.put("android.net.ConnectivityManager", "android.content.Context.CONNECTIVITY_SERVICE");
47+
registeredServices.put("android.hardware.ConsumerIrManager", "android.content.Context.CONSUMER_IR_SERVICE");
4048
registeredServices.put("android.location.CountryDetector", "android.content.Context.COUNTRY_DETECTOR");
4149
registeredServices.put("android.app.admin.DevicePolicyManager", "android.content.Context.DEVICE_POLICY_SERVICE");
50+
registeredServices.put("android.hardware.display.DisplayManager", "android.content.Context.DISPLAY_SERVICE");
4251
registeredServices.put("android.app.DownloadManager", "android.content.Context.DOWNLOAD_SERVICE");
4352
registeredServices.put("android.os.DropBoxManager", "android.content.Context.DROPBOX_SERVICE");
53+
registeredServices.put("android.hardware.input.InputManager", "android.content.Context.INPUT_SERVICE");
4454
registeredServices.put("android.view.inputmethod.InputMethodManager", "android.content.Context.INPUT_METHOD_SERVICE");
4555
registeredServices.put("android.app.KeyguardManager", "android.content.Context.KEYGUARD_SERVICE");
4656
registeredServices.put("android.view.LayoutInflater", "android.content.Context.LAYOUT_INFLATER_SERVICE");
4757
registeredServices.put("android.location.LocationManager", "android.content.Context.LOCATION_SERVICE");
58+
registeredServices.put("android.media.MediaRouter", "android.content.Context.MEDIA_ROUTER_SERVICE");
4859
registeredServices.put("android.net.NetworkManagementService", "android.content.Context.NETWORKMANAGEMENT_SERVICE");
4960
registeredServices.put("android.net.NetworkPolicyManager", "android.content.Context.NETWORK_POLICY_SERVICE");
61+
registeredServices.put("android.net.NetworkStatsService", "android.content.Context.NETWORK_STATS_SERVICE");
5062
registeredServices.put("android.nfc.NfcManager", "android.content.Context.NFC_SERVICE");
5163
registeredServices.put("android.app.NotificationManager", "android.content.Context.NOTIFICATION_SERVICE");
64+
registeredServices.put("android.net.nsd.NsdManager", "android.content.Context.NSD_SERVICE");
65+
registeredServices.put("android.print.PrintManager", "android.content.Context.PRINT_SERVICE");
5266
registeredServices.put("android.os.PowerManager", "android.content.Context.POWER_SERVICE");
5367
registeredServices.put("android.app.SearchManager", "android.content.Context.SEARCH_SERVICE");
54-
registeredServices.put("android.appwidget.AppWidgetManager", "android.content.Context.APPWIDGET_SERVICE");
68+
registeredServices.put("android.hardware.SerialManager", "android.content.Context.SERIAL_SERVICE");
5569
registeredServices.put("android.hardware.SensorManager", "android.content.Context.SENSOR_SERVICE");
70+
registeredServices.put("android.net.sip.SipManager", "android.content.Context.SIP_SERVICE");
5671
registeredServices.put("android.app.StatusBarManager", "android.content.Context.STATUS_BAR_SERVICE");
5772
registeredServices.put("android.os.storage.StorageManager", "android.content.Context.STORAGE_SERVICE");
5873
registeredServices.put("android.telephony.TelephonyManager", "android.content.Context.TELEPHONY_SERVICE");
5974
registeredServices.put("android.view.textservice.TextServicesManager", "android.content.Context.TEXT_SERVICES_MANAGER_SERVICE");
6075
registeredServices.put("android.net.ThrottleManager", "android.content.Context.THROTTLE_SERVICE");
6176
registeredServices.put("android.app.UiModeManager", "android.content.Context.UI_MODE_SERVICE");
77+
registeredServices.put("android.os.IUpdateLock", "android.content.Context.UPDATE_LOCK_SERVICE");
6278
registeredServices.put("android.hardware.usb.UsbManager", "android.content.Context.USB_SERVICE");
79+
registeredServices.put("android.os.UserManager", "android.content.Context.USER_SERVICE");
6380
registeredServices.put("android.os.Vibrator", "android.content.Context.VIBRATOR_SERVICE");
6481
registeredServices.put("android.app.WallpaperManager", "android.content.Context.WALLPAPER_SERVICE");
6582
registeredServices.put("android.net.wifi.WifiManager", "android.content.Context.WIFI_SERVICE");

‎AndroidAnnotations/functional-test-1-5-tests/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>com.google.android</groupId>
2222
<artifactId>android</artifactId>
23-
<version>4.0.1.2</version>
23+
<version>4.1.1.4</version>
2424
<scope>test</scope>
2525
</dependency>
2626
<dependency>

‎AndroidAnnotations/functional-test-1-5-tests/src/test/java/org/androidannotations/test15/ServiceInjectionTest.java‎

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,60 @@ public class ServiceInjectionTest {
2929
public void servicesAreInjected() {
3030
ActivityWithServices_ activity = Robolectric.buildActivity(ActivityWithServices_.class).create().get();
3131

32-
assertThat(activity.windowManager).isNotNull();
33-
assertThat(activity.layoutInflater).isNotNull();
32+
// in alphabetical order
33+
34+
// assertThat(activity.accessibilityManager).isNotNull(); // TODO Robolectric 2.4
35+
// assertThat(activity.accountManager).isNotNull(); // TODO no support yet in Robolectric
3436
assertThat(activity.activityManager).isNotNull();
35-
assertThat(activity.powerManager).isNotNull();
3637
assertThat(activity.alarmManager).isNotNull();
37-
assertThat(activity.notificationManager).isNotNull();
38+
// assertThat(activity.appOpsManager).isNotNull(); // TODO API 19
39+
// assertThat(activity.appWidgetManager).isNotNull(); // hidden API
40+
assertThat(activity.audioManager).isNotNull();
41+
// assertThat(activity.backupManager).isNotNull(); // hidden API
42+
// assertThat(activity.bluetoothAdapter).isNotNull(); // TODO API 18
43+
// assertThat(activity.cameraManager).isNotNull(); // hidden API
44+
// assertThat(activity.captioningManager).isNotNull(); // TODO API 19
45+
assertThat(activity.contentClipboardManager).isNotNull();
46+
assertThat(activity.textClipboardManager).isNotNull();
47+
assertThat(activity.connectivityManager).isNotNull();
48+
// assertThat(activity.consumerIrManager).isNotNull(); // TODO API 19
49+
// assertThat(activity.countryDetector).isNotNull(); // hidden API
50+
assertThat(activity.devicePolicyManager).isNotNull();
51+
// assertThat(activity.displayManager).isNotNull(); // TODO API 17
52+
assertThat(activity.downloadManager).isNotNull();
53+
assertThat(activity.dropBoxManager).isNotNull();
54+
// assertThat(activity.inputManager).isNotNull(); // TODO no support yet in Robolectric
55+
assertThat(activity.inputMethodManager).isNotNull();
3856
assertThat(activity.keyguardManager).isNotNull();
57+
assertThat(activity.layoutInflater).isNotNull();
3958
assertThat(activity.locationManager).isNotNull();
59+
// assertThat(activity.mediaRouter).isNotNull(); // TODO Robolectric 2.4
60+
// assertThat(activity.networkManagementService).isNotNull(); // hidden API
61+
// assertThat(activity.networkPolicyManager).isNotNull(); // hidden API
62+
// assertThat(activity.networkStatsService).isNotNull(); // hidden API
63+
// assertThat(activity.nfcManager).isNotNull(); // TODO no support yet in Robolectric
64+
assertThat(activity.notificationManager).isNotNull();
65+
// assertThat(activity.nsdManager).isNotNull(); // TODO no support yet in Robolectric
66+
// assertThat(activity.printManager).isNotNull(); // TODO API 19
67+
assertThat(activity.powerManager).isNotNull();
4068
assertThat(activity.searchManager).isNotNull();
41-
assertThat(activity.vibrator).isNotNull();
42-
assertThat(activity.connectivityManager).isNotNull();
43-
assertThat(activity.wifiManager).isNotNull();
44-
assertThat(activity.inputMethodManager).isNotNull();
4569
assertThat(activity.sensorManager).isNotNull();
70+
// assertThat(activity.serialManager).isNotNull(); // hidden API
71+
// assertThat(activity.sipManager).isNotNull(); // hidden API
72+
// assertThat(activity.statusBarManager).isNotNull(); // hidden API
73+
assertThat(activity.storageManager).isNotNull();
4674
assertThat(activity.telephonyManager).isNotNull();
47-
assertThat(activity.audioManager).isNotNull();
48-
assertThat(activity.textClipboardManager).isNotNull();
49-
assertThat(activity.contentClipboardManager).isNotNull();
75+
assertThat(activity.textServicesManager).isNotNull();
76+
// assertThat(activity.throttleManager).isNotNull(); // hidden API
77+
assertThat(activity.uiModeManager).isNotNull();
78+
// assertThat(activity.updateLock).isNotNull(); // hidden API
79+
// assertThat(activity.usbManager).isNotNull(); // TODO no support yet in Robolectric
80+
// assertThat(activity.userManager).isNotNull(); // TODO API 19
81+
assertThat(activity.vibrator).isNotNull();
82+
// assertThat(activity.wallpaperManager).isNotNull(); // TODO no support yet in Robolectric
83+
assertThat(activity.wifiManager).isNotNull();
84+
// assertThat(activity.wifiP2pManager).isNotNull(); // TODO no support yet in Robolectric
85+
assertThat(activity.windowManager).isNotNull();
5086
}
5187

5288
}

0 commit comments

Comments
 (0)