Commit Graph

23 Commits

Author SHA1 Message Date
David Crawshaw 5c91e60c93 app: android activity lifecycle awareness
This CL fixes two bugs in the existing app implementation on android.
The first, is it assumed a single NativeActivity instance is created
per process. This is not true. If you open an app, hit the back
button, then open it again, the original activity is destroyed and a
new one is created. So only call main.main in the first onCreate.

The second bug has to do with window lifetimes. Previously we only
processed GL work while the window existed, as part of a paint cycle.
This missed GL events called as part of a lifecycle downgrade when
the window was destroyed. (I.e. the contents of onStop.) This CL
fixes this by making the main android event processing loop last for
the life of the process, not the window.

Fixes golang/go#11804.

Change-Id: Ia03e464aab5bc10ba75564b7ca11054515cda011
Reviewed-on: https://go-review.googlesource.com/12533
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-29 14:29:11 +00:00
David Crawshaw 34f7142b5a app: be more careful about android redraw events
EGL is a poor source of window dimensions. On some fraction of
rotations, it reported the old dimensions. Switch to extracting the
data from ANativeWindow, which appears to be more reliable.

While here, plumb through orientation, and follow the recommendation
in the Android platform docs to block onNativeWindowRedrawNeeded
until the draw is complete.

Fixes golang/go#11741.

Change-Id: I6b29b6a1e5743c612c9af2a8cce4260c5d7e9ca6
Reviewed-on: https://go-review.googlesource.com/12381
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-22 15:25:30 +00:00
Hyang-Ah (Hana) Kim 136fa9bbbb bind/java: reenable asset access.
This is done by moving app.Context to internal/mobileinit,
introducing mobileinit.SetCurrentContext and,
making bind/java depend on it.

TODO: check gomobile bind's proguard rule - context lookup
was implemented through reflection on android.app.AppGlobals class.

Change-Id: Ieb6ad503eeef8c2c1c5836a21c667938c5a701a2
Reviewed-on: https://go-review.googlesource.com/12279
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-16 21:15:37 +00:00
David Crawshaw 8f20c3e9d3 app, cmd/gomobile: subclass NativeActivity
Subclassing NativeActivity makes two things possible. Firstly, we can
implement an InputConnection to offer good support for IMEs,
necessary for good keyboard support. Secondly, we can use it to
overlay WebViews onto the NativeActivity.

But to sublcass NativeActivity, we need to compile Java. To keep the
toolchain go gettable, this is done with go generate.

While here, check the exception after FindClass. Apparently it can
throw an exception.

Updates golang/go#9361.
Updates golang/go#10247.

Change-Id: I672545997f0c9a7580f06988a273c03404772247
Reviewed-on: https://go-review.googlesource.com/11980
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-13 19:05:26 +00:00
David Crawshaw 8bb4ca139b asset: move app.Open to its own package
This does not break the dependency on the app package's AndroidContext
for loading assets on android. A potential answer for gobind-based
apps: add a SetAndroidContext method to app.Context. But I'll explore
that separately after the long weekend.

Change-Id: I812f899740e288c379eee7900f42d9d53926d4ce
Reviewed-on: https://go-review.googlesource.com/11675
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-29 21:49:28 +00:00
David Crawshaw 8144405762 app, bind: separate the app package from gobind
Historically, the app package implemented Go runtime initialization.
This was convoluted, so the package was used both by all-Go apps
(currently based on Android's NativeActivity) and bind-based apps.

With Go 1.5 we have -buildmode=c-shared, which does a lot of the work
of the old app package. That code was removed a while back, but both
all-Go and gobind-based apps still used package app. The intermingled
initialization processes led to some strange states.

This CL separates gobind-based apps completely from the app package.
As part of that users are now expected to use System.loadLibrary
themselves. (A future CL may want to make the loadLibrary call part
of the .aar generated by gomobile bind.)

Delete the libhello example, which has been replaced by gomobile bind,
which could do with its own example at some point. Also delete the
libhellojni example, which now has nothing to do with the x/mobile
repository.

Change-Id: I444397f246dbafe81e5c53532eb482c197d26f70
Reviewed-on: https://go-review.googlesource.com/11654
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-29 11:40:40 +00:00
Nigel Tao e47fb7683e app: delete the unused Config.ClassFinder method.
Change-Id: I8eea69f3ac6406fd58a9338f3aa358fead1afc0e
Reviewed-on: https://go-review.googlesource.com/11473
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-26 01:34:58 +00:00
David Crawshaw 5cddc1460e app: introduce Config and start registration
Config provides a way to concurrently access Width and Height.

Register provides a way for packages to run code on app state change
without plumbing changes all the way to the process main function.
This is motivated by gl/glutil.Image which needs to rebuild its
textures on start/stop and can be deeply nested.
(See golang.org/cl/9707 for the followup.)

Tested manually on android and darwin/amd64. Doing this kind makes it
clear any CL modifying this code needs a lot of manual testing right
now, so some kind of trybot support is something I'm going to
prioritise.

Fixes golang/go#10686
Fixes golang/go#10461
Fixes golang/go#10442
Fixes golang/go#10226
Updates golang/go#10327

Change-Id: I2882ebf3995b6ed857cda823e94fbb17c54b43a8
Reviewed-on: https://go-review.googlesource.com/9708
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-05-06 17:32:53 +00:00
Hyang-Ah (Hana) Kim 601608a0e0 bind/java: use the class loader cached during JNI_OnLoad call.
This allows the application class loader to be used when
the bind/java package or other part of JNI dynamically
loads java classes from a non-Java thread.

http://developer.android.com/training/articles/perf-jni.html#faq_FindClass

Fixes golang/go#10668.

Change-Id: I44df3a9362617fa6dd26ddf88247e4fdaee7c7e8
Reviewed-on: https://go-review.googlesource.com/9732
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-05-06 03:41:18 +00:00
David Crawshaw 66ea9e5b49 app: simplify and document init sequence
The global constructor added for -buildmode=c-shared takes care
of a lot of the messier steps that were being done here.

Change-Id: I00525765855b2ad0fcecb0639d6a7ee3feea9ed9
Reviewed-on: https://go-review.googlesource.com/9648
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-05-04 12:09:13 +00:00
David Crawshaw d77bba0a9f app: call main.main on app startup
There is some cleanup to be done in this package now, but I'm
deferring it until later in the cycle.

We should probably also change the semantics slightly: main should
be called for all-Go apps (that is, apps that use NativeActivity),
but it would be more consistent with buildmode=c-shared and c-archive
if we did not call main for Go shared libraries being included in
Java android apps.

Change-Id: I13ca797a478edb22b0c602c1ee6e616fe4fea1e6
Reviewed-on: https://go-review.googlesource.com/9016
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-04-17 16:08:58 +00:00
Hyang-Ah Hana Kim 595ca5ba2c app: initialize asset manager for gobind android app.
Tested manually by modifying example/libhello to read an asset file,
and checking crawshaw's balloon app continues to work.

Fixes golang/go#9422.

Change-Id: I17b25d9456a4023c68be1de82ee071ea01299e68
Reviewed-on: https://go-review.googlesource.com/5680
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-02-24 16:06:04 +00:00
David Crawshaw 6bd177a50f app: set TMPDIR and plumb through to Go
Change-Id: Ia39f134c5ffe39decc04c2bd59b69981c1c46e41
Reviewed-on: https://go-review.googlesource.com/5579
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-02-23 18:26:05 +00:00
David Crawshaw b2dee7a880 app, cmd/gomobile: expose an app.State variable
The State can be used in the Start callback (and lazily-initialized
packages) instead of JavaInit. This stores a reference to the
android.context.Context for the (future) keyboard package and for
setting TMPDIR.

Second attempt at https://golang.org/cl/4400.

Change-Id: I673997b26ab25ce5140cb31950593d8c6dbd9c51
Reviewed-on: https://go-review.googlesource.com/5555
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-02-23 17:54:17 +00:00
David Crawshaw 8602f76ecd Revert "app: repalce JavaInit with RegisterAndroidInit"
Not thought through. For gobind-based apps, JNI_OnLoad is called and there is never any NativeActivity.

This reverts commit b781b80ee8.

Change-Id: Ib076f30d144cbacb7926d54981ac86bbb8a5a4ff
Reviewed-on: https://go-review.googlesource.com/4440
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-02-10 19:28:17 +00:00
David Crawshaw b781b80ee8 app: repalce JavaInit with RegisterAndroidInit
I am working on a virtual keyboard package that needs access to the
*ANativeActivity. As the *ANativeActivity contains *JavaVM, this CL
deprecates JavaInit. I'll remove it in a subsequent CL that updates
gobind to use RegisterAndroidInit.

Change-Id: Ib1d60bbaac5de4583b368c93ab90b764c6081291
Reviewed-on: https://go-review.googlesource.com/4400
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-02-10 18:52:00 +00:00
David Crawshaw 32030f7750 app: build fake auxv
Some Android systems cannot read from /proc/self/auxv. Work around
this by creating a minimal fake auxv for the Go runtime.

Fixes #9229

Change-Id: Id2d743f43d91be23006aac708a5b5b5cd60a6dca
Reviewed-on: https://go-review.googlesource.com/1284
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2014-12-10 17:26:16 +00:00
David Crawshaw fb47a1752b x/mobile/app: zero buffer at end of read
LGTM=hyangah
R=hyangah
CC=an.olive.tree, golang-codereviews
https://golang.org/cl/176130045
2014-12-04 14:29:48 -05:00
Nigel Tao 0d93f8d8be go.mobile/app: tabs/spaces clean-up.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/159820043
2014-10-13 21:04:04 +11:00
Nigel Tao c2d8ff3468 go.mobile/app: add an X11 implementation, for non-Android Linux.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/155270043
2014-10-13 09:24:05 +11:00
Gautham Thambidorai 7aa683c173 go.mobile/app: Add an entrypoint for non Java libraries to use for initializing a go runtime.
LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=golang-codereviews
https://golang.org/cl/156040044
2014-10-09 14:23:40 -07:00
David Crawshaw 56cb2dac4e go.mobile/app: Touch callback
LGTM=adg, nigeltao
R=nigeltao, adg, bryanturley
CC=davidday, golang-codereviews
https://golang.org/cl/140450043
2014-09-11 19:39:16 -04:00
David Crawshaw 3d312b5a2b go.mobile: break dependency on gobind
Preparation for NativeActivity-based apps.

LGTM=nigeltao
R=golang-codereviews, nigeltao
CC=golang-codereviews
https://golang.org/cl/126520043
2014-09-03 09:03:00 -04:00