Skip to content

Commit

Permalink
Add a manual sensor test script
Browse files Browse the repository at this point in the history
For the sensors that I currenlty mark as "bad", I see a RunBuiltinException
in my vessel log.
  • Loading branch information
aaaaalbert committed Feb 3, 2017
1 parent e945ca6 commit 8f354ac
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions testsV2/test_sensors.r2py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
list_of_noargs_sensor_calls = [
get_bluetooth_info,
get_bluetooth_scan_info,
is_wifi_enabled,
get_wifi_state,
get_wifi_connection_info,
get_wifi_scan_info,
get_network_info,
get_cellular_provider_info,
get_cell_info, get_sim_info,
get_phone_info, get_mode_settings,
get_display_info,
get_volume_info,
get_battery_info,
get_sensor_list,
get_acceleration,
get_ambient_temperature,
get_game_rotation_vector,
get_geomagnetic_rotation_vector,
get_gravity,
get_gyroscope,
get_gyroscope_uncalibrated,
get_heart_rate,
get_light,
get_linear_acceleration,
get_magnetic_field,
get_magnetic_field_uncalibrated,
get_pressure,
get_proximity,
get_relative_humidity,
get_rotation_vector,
get_step_counter,
is_media_playing,
is_tts_speaking,
get_location,
get_lastknown_location,
]

# On my Nexus 6 with Android 7.1.1, these sensors currently fail:
# get_wifi_connection_info, get_network_info, get_cell_info,
# get_sensor_list, get_lastknown_location
bad_sensor_indices = [4, 6, 8, 15, 36]

for sensor_number in range(len(list_of_noargs_sensor_calls)):
if sensor_number in bad_sensor_indices:
continue
sensor_call_void = list_of_noargs_sensor_calls[sensor_number]
log(getruntime(), sensor_number)
try:
log(sensor_call_void(), "\n")
except Exception, e:
log("FAILED with exception", repr(e), "\n")

2 comments on commit 8f354ac

@aaaaalbert
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After (re-?)applying 93d4e7a, the traceback turns into something actually useful for the "bad" sensor calls.

get_wifi_connection_info (number 4 in the bad sensors list) fails because my current SSID contains Unicode characters.

Exception (with class 'exception_hierarchy.InternalRepyError'):
Function 'get_wifi_connection_info' returned with unallowed return
type <type 'dict'> : _copy failed on {'ssid': u'".... \xe2\x9d\xa4 ...." (etc:)}
with message 'ascii' codec can't encode characters in position 13-15:
ordinal not in range(128)

get_network_info (number 6) fails for the same reason, although the return value is a list containing an uncopyable Unicode char this time.

get_cell_info (number 8) is far more interesting and points at a bug in our handling / requesting of permissions. (When I switch into the Sensibility app often enough so that I can finally enable the location permission request, things work out smoothly!)

Exception (with type 'exceptions.Exception'): java.lang.SecurityException: getAllCellInfo:
Neither user 10106 nor current process has android.permission.ACCESS_COARSE_LOCATION.

get_sensor_list (number 15) shows a puzzling

Exception (with type 'exceptions.Exception'): org.json.JSONException:
Forbidden numeric value: NaN

get_lastknown_location (number 36) sometimes blocks to death (see below), and sometimes returns None:

[Errno 2] No such file or directory: '/proc/20129/stat' Monitor death!
Impolitely killing repy process!

@aaaaalbert
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These issues are all fixed now!

  • get_wifi_connection_info and get_network_info are scrubbed from Unicode characters, see

    repy_v2/repysensors.py

    Lines 301 to 303 in 7350a00

    get_wifi_connection_info = unicode_scrub_wrap(sensorlock_wrap(miscinfo.get_wifi_connection_info))
    get_wifi_scan_info = unicode_scrub_wrap(sensorlock_wrap(miscinfo.get_wifi_scan_info))
    get_network_info = unicode_scrub_wrap(sensorlock_wrap(miscinfo.get_network_info))
  • get_cell_info is fixed as per Handling java.lang.SecurityExceptions from sensors  #4.
  • get_sensor_list is fixed as per Sanitize Java sensor readings before JSONifying them #6.
  • get_lastknown_location wasn't really the culprit; the sandbox shutting down by itself and the monitor trying to kill it at around the same time caused the fuzz, as the sandbox's procfs entry might have disappeared already. See ce553c4.

Please sign in to comment.