2
0
mirror of synced 2025-02-23 14:58:12 +00:00

21 Commits

Author SHA1 Message Date
Elias Naur
b8c6dab863 all: skip or fix tests for GOOS=android
Some x/mobile tests are designed to run from a host with a device
or emulator attached. Some fail if they run directly from a device,
which is the case when GOOS=android.

Fix the tests by skipping them or adjusting them to work on GOOS=android.

Remove gomobile environment naïve variable expansion for $HOME; on
Android devices HOME=/ so every path separator is replaced with
$HOME.

Fixes golang/go#30482

Change-Id: I553e708226922f6284163f0b7d7b1011a9502e34
Reviewed-on: https://go-review.googlesource.com/c/164799
Run-TryBot: Elias Naur <mail@eliasnaur.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-02 06:36:18 +00:00
Burcu Dogan
1b12574c99 exp/sensor: don't enable a sensor on a sender
The underlying implementation was not enabling the sensors on a
particular sender even though the Enable signature accepts different
instances of Sender to enable.

Consider the following program:

  type A struct{}
  func (a A) Send(ev interface{}) {}

  type B struct{}
  func (b B) Send(ev interface{}) {}

  sensor.Enable(A{}, sensor.Gyroscope, time.Millisecond)
  sensor.Enable(B{}, sensor.Accelerometer, time.Millisecond)

is going to compile but only A will be notified when there are new
gyroscope and accelerometer events.

In order to improve the misleading APIs, this CL introduces a
Notify function that users can register a Sender implementation to
listen the changes. If set nil, the sensor package will keep
reading the events but will won't notify.

  sensor.Notify(A{})
  sensor.Enable(sensor.Gyroscope, time.Millisecond)
  sensor.Enable(sensor.Accelerometer, time.Millisecond)

Change-Id: I25e43349e4ae682930baa2d32430f46f24b588b7
Reviewed-on: https://go-review.googlesource.com/15650
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-19 21:21:50 +00:00
Burcu Dogan
d19d328d7b exp/sensor: avoid using naked returns
Naked returns must be used for self-documentary reasons. In this
unexported package, it is not useful to name return values.

The change has been contributed on a previous CL but I don't know
what happened, it should have been lost on a bad merge.

Change-Id: I6cb9c3a58ad397aeb646f3e57e482628fe31ca31
Reviewed-on: https://go-review.googlesource.com/15658
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-12 17:03:38 +00:00
Burcu Dogan
83be1bf497 exp/sensor: remove the unpopulated error from the readSignal
readEvents never return an error, readSignal should not have an
error field.

Change-Id: I9566a6905ee678599fdad18f85ae55d1fdc16cc1
Reviewed-on: https://go-review.googlesource.com/15550
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-08 21:24:20 +00:00
Burcu Dogan
6db2cde289 exp/sensor: remove obsolete TODOs
Several notices, notes and questions have become obsolete when
CL/15438 is merged. Removing the TODOs pointing to the bug explained
in CL/15438's description.

Change-Id: I8a94507a6d0aa507a58be451336eba36dd383d64
Reviewed-on: https://go-review.googlesource.com/15551
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-07 21:08:13 +00:00
Burcu Dogan
cc7d486c7d exp/sensor: remove the init signal
The init signal's job could be done at the top of the proxying
goroutine.

Change-Id: Icb907946a679d3eca6bec5e12adeb2bedc0908f0
Reviewed-on: https://go-review.googlesource.com/15490
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-07 15:45:14 +00:00
Burcu Dogan
e8b7f9598a exp/sensor: fix segfault while releasing thread looper
Only the loopers allocated with ALooper_acquire are releasable. We are
depending on the looper associated to the thread which will be
automatically released when the thread is being terminated.

Trying to re-release a looper makes the app crash with segfault.

Change-Id: Ib80549de01f5f44143752c13a82b6b4a2ab5610e
Reviewed-on: https://go-review.googlesource.com/15491
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-07 15:45:01 +00:00
Burcu Dogan
2fe453d27f exp/sensor: don't block the looper thread indefinitely
The sensor package had a deadlock case if it started to poll the
events but all sensors have been disabled on the underlying ALooper.

Consider the following program:

  app.Main(func(a app.App) {
    sensor.Enable(a, sensor.Gyroscope, time.Millisecond)
    go func() {
      time.Sleep(5 * time.Second)
      sensor.Disable(sensor.Gyroscope)
      time.Sleep(2 * time.Second)
      sensor.Enable(a, sensor.Gyroscope, time.Millisecond)
    }()
    for e := range a.Events() {
    case sensor.Event:
      //...
    }

The initial Enable will enable the gyroscope and start polling events
from the ALooper. After 5 seconds, the gyroscope will be disabled.

  ALooper_pollAll(-1, NULL, &events, NULL)

will block indefinately because there are no events will be
available until another sensor is enabled.

After 2 seconds, we will attempt to enable the gyroscope again. But,
the underlying thread will be blocked at pollAll and won't be able
to make the sensor enabling call on the same thread.

In order to overcome this deadlock case, this thread introduces a
hard timeout limit during polling. If timeout occurs, the looper
thread will be unblocked and select{} statement will be able to
handle {enable,disable,close}Signal cases.

Fixes golang/go#12501.

Change-Id: I35efa2e29057ca37f8ac0f38be8dc59c9b8262b3
Reviewed-on: https://go-review.googlesource.com/15438
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-06 21:59:44 +00:00
Burcu Dogan
c76d5c8830 exp/sensor: remove the manager type
The manager type is not required, because the APIs don't allow
more than one event sources as they used to. In this CL, I am
flattening out the underlying implementations by removing the
manager type.

Change-Id: I3b606ac160b9cecd85cb657e3df1d7d789604764
Reviewed-on: https://go-review.googlesource.com/14293
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-04 16:23:41 +00:00
Burcu Dogan
043428404d exp/sensor: enable magnetometer on darwin{arm,arm64}
Change-Id: Ib188121501ac96cb8743e57f907b23d0fdfc37a0
Reviewed-on: https://go-review.googlesource.com/14292
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-04 04:58:24 +00:00
Burcu Dogan
d4f6353bc3 exp/sensor: support gyro events on darwin{arm,arm64}
Change-Id: I47aa12cc942261b8035312d0eeba0caf52b562ac
Reviewed-on: https://go-review.googlesource.com/14257
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-04 03:40:30 +00:00
Burcu Dogan
931e394f4f exp/sensor: don't allow delays smaller than 10ms on ios
"You can set the reporting interval to be as small as 10 milliseconds
(ms), which corresponds to a 100 Hz update rate, but most app operate
sufficiently with a larger interval."

from https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html

Larger delay values makes the library poll more frequently than needed.

Change-Id: Ie3057813209746bff00b8ef534c9ae239396366e
Reviewed-on: https://go-review.googlesource.com/14252
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-03 16:03:29 +00:00
Burcu Dogan
7e79d05d9e exp/sensor: set sensor interval on ios
Change-Id: I5559f721b2e2c7506db89f804569c0b0f78abea8
Reviewed-on: https://go-review.googlesource.com/14251
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-03 06:02:53 +00:00
Burcu Dogan
679c68b58d exp/sensor: block forever until new events occur on android
The former Reader inspired APIs were designed to timeout if no events
occur after an excessive amount of time. As we switch to the app
event based model, timing out is not required. We can block on
pollAll forever until new events arrive.

Change-Id: I086fc908ebfe6ae9bd96ce9199636ad0242bbec5
Reviewed-on: https://go-review.googlesource.com/14223
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-03 02:54:22 +00:00
Burcu Dogan
5651add1eb exp/sensor: initiate the darwin/{arm,arm64} backend
The CL provides accelerometer events only, upcoming CLs will add
support for gyroscope and magnetometer.

Change-Id: Ib5629ca7c49c9dfc8ca533fe7acde371efc102b2
Reviewed-on: https://go-review.googlesource.com/14036
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-03 02:10:28 +00:00
Burcu Dogan
9ddeada810 exp/sensor: provide sensor events from the app event channel
We are also limiting the number of sensor managers to one.
The application provide sensor events to third-party packages
by consuming them in the main.

An application will be able to consume the sensor events similar
to the other events.

package main

func main() {
  app.Main(func(a app.App) {
    // enables the accelerometer
    sensor.Enable(a, sensor.Accelerometer, 100*time.Millisecond)

    var sz size.Event
    for e := range a.Events() {
      switch e := app.Filter(e).(type) {
      case sensor.Event:
        log.Println(e)
      }
    }
  })
}

Change-Id: Iaad1c59f8d2322c7620df62ed9b9283c91746fa8
Reviewed-on: https://go-review.googlesource.com/13983
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-01 04:44:55 +00:00
Hana Kim
49a82fefe3 all: support go get golang.org/x/mobile/... on Windows
Fixes golang/go#12212
Workaround for golang/go#12261 until golang/go#9306 is fixed.

Change-Id: I51c1bcfc92c1553fe2132586a0234b1c1af6aeb1
Reviewed-on: https://go-review.googlesource.com/13745
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-24 21:09:04 +00:00
Nigel Tao
f4bcb3cc2e exp/sensor: fix nsec to usec conversion.
Also remove an unnecessary constant type conversion.

Change-Id: Iff466553fac450bd531785f4fb4e2be97a991a52
Reviewed-on: https://go-review.googlesource.com/13715
Reviewed-by: Burcu Dogan <jbd@google.com>
2015-08-21 01:49:41 +00:00
Burcu Dogan
25faf494e1 exp/sensor: use a better prefix in C not to pollute the namespace
Change-Id: Iac80d3ca61812ece64ae5127e4b5d1f8c54ff5b3
Reviewed-on: https://go-review.googlesource.com/13620
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-13 17:46:42 +00:00
Burcu Dogan
b5583e233e exp/sensor: reorg package to create space for darwin/arm,arm64 impl
Change-Id: I41e4088a92fff2f411dd82102fc3c421d2679c21
Reviewed-on: https://go-review.googlesource.com/13582
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-12 22:18:05 +00:00
Burcu Dogan
e9faa8965b sensor: move to exp/sensor
Change-Id: I707a1555952355ccdd5e851062c4749dc94544eb
Reviewed-on: https://go-review.googlesource.com/11312
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-21 07:47:51 +00:00