Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/fitness/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,29 @@ sky_app("fitness") {
manifest = "flutter.yaml"

if (is_android) {
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")

apk_name = "Fitness"

android_library("java") {
java_files = [
"apk/src/org/domokit/fitness/FitnessApplication.java",
]

deps = [
"//base:base_java",
"//mojo/public/java:bindings",
"//mojo/public/java:system",
"//sky/services/gcm:gcm_lib",
"//sky/services/gcm:interfaces_java",
"//sky/shell:java",
]
}

deps = [
"//examples/fitness/apk:resources",
":java",
]
} else if (is_mac) {
info_plist = "mac/Info.plist"
Expand Down
41 changes: 40 additions & 1 deletion examples/fitness/apk/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />

<application android:icon="@mipmap/ic_launcher" android:label="Fitness" android:name="org.domokit.sky.shell.SkyApplication">
<!-- for GCM -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Supposedly this permission prevents other apps from receiving our
messages, but it doesn't seem to have any effect. -->
<permission android:name="org.domokit.sky.shell.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="org.domokit.sky.shell.permission.C2D_MESSAGE" />
<!-- end for GCM -->

<application android:icon="@mipmap/ic_launcher" android:label="Fitness" android:name="org.domokit.fitness.FitnessApplication">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize" android:hardwareAccelerated="true" android:launchMode="singleTask" android:name="org.domokit.sky.shell.SkyActivity" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -19,5 +29,34 @@
android:name="org.domokit.sky.shell.UpdateService"
android:exported="false"
android:process=":remote"/>

<!-- for GCM -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="org.domokit.sky.shell" />
</intent-filter>
</receiver>
<service
android:name="org.domokit.gcm.GcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="org.domokit.gcm.InstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name="org.domokit.gcm.RegistrationIntentService"
android:exported="false">
</service>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.domokit.fitness;

import android.content.Context;

import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.MessagePipeHandle;
import org.chromium.mojom.gcm.GcmService;
import org.domokit.gcm.RegistrationIntentService;
import org.domokit.sky.shell.ServiceFactory;
import org.domokit.sky.shell.ServiceRegistry;
import org.domokit.sky.shell.SkyApplication;

/**
* Sky implementation of {@link android.app.Application}, managing application-level global
* state and initializations.
*/
public class FitnessApplication extends SkyApplication {
/**
* Override this function to register more services.
*/
protected void onServiceRegistryAvailable(ServiceRegistry registry) {
super.onServiceRegistryAvailable(registry);

registry.register(GcmService.MANAGER.getName(), new ServiceFactory() {
@Override
public void connectToService(Context context, Core core, MessagePipeHandle pipe) {
GcmService.MANAGER.bind(
new RegistrationIntentService.MojoService(context), pipe);
}
});
}
}
15 changes: 14 additions & 1 deletion examples/fitness/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ library fitness;
import 'package:playfair/playfair.dart' as playfair;
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:gcm/gcm.dart' as gcm;

import 'user_data.dart';
import 'date_utils.dart';
Expand Down Expand Up @@ -161,6 +162,18 @@ class FitnessAppState extends State<FitnessApp> {
}
}

void main() {
initGcm() async {
// Register for GCM messages using the senderId provided in the
// google-services.json we received when registering our app.
String token;
token = await gcm.registerGcmService(
"858790231562", (String from, String message) {
print("onMessageReceived: $from; $message");
gcm.unsubscribeTopics(token, ["global"]);
});
gcm.subscribeTopics(token, ["global"]);
}

main() {
runApp(new FitnessApp());
}
2 changes: 2 additions & 0 deletions examples/fitness/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ dependencies:
path: ../../packages/flutter
playfair:
path: ../../packages/playfair
gcm:
path: ../../packages/gcm
4 changes: 2 additions & 2 deletions packages/flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ dependencies:
collection: '>=1.1.3 <2.0.0'
intl: '>=0.12.4+2 <0.13.0'
material_design_icons: '>=0.0.3 <0.1.0'
sky_engine: 0.0.75
sky_services: 0.0.75
sky_engine: 0.0.77
sky_services: 0.0.77
vector_math: '>=1.4.3 <2.0.0'
quiver: '>=0.21.4 <0.22.0'

Expand Down
7 changes: 7 additions & 0 deletions packages/gcm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.idea
.packages
.pub/
build/
packages
pubspec.lock
10 changes: 10 additions & 0 deletions packages/gcm/lib/gcm.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// Service exposed to Flutter apps that implements a subset of the GCM API.
///
/// This library will probably be moved into a separate package eventually.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably open a separate github repo for "third party services" and have this be one of them. @collinjackson has a similar issue with his work. cc @abarth.

Copy link
Contributor

Choose a reason for hiding this comment

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

(it doesn't have to be now, but it should be really soon. Having Google-specific services in the Flutter repo gives a very mixed message about what Flutter is. We want to make sure other companies and developers understand that they are peers, not subordinate in any way.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Our plan is to put them in the main repo first to see what is needed, then move them to a separate repo.

library gcm;

export 'src/gcm.dart';
43 changes: 43 additions & 0 deletions packages/gcm/lib/src/gcm.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2015, the Flutter authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:flutter/services.dart';
import 'package:sky_services/gcm/gcm.mojom.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like you didn't git add gcm.mojom.dart.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right.

Yeah we definitely don't want anything to end up in the engine repo for this eventually. But again, as you say, this is fine for initial discovery of the problem space. Might be worth putting comments around this saying this is all temporary and that eventually third-party services will have their own repo(s), just in case someone looks at the code in the meantime...


GcmServiceProxy _initGcmService() {
GcmServiceProxy gcmService = new GcmServiceProxy.unbound();
shell.connectToService(null, gcmService);
return gcmService;
}

final GcmServiceProxy _gcmService = _initGcmService();

typedef void GcmListenerCallback(String from, String message);
class _GcmListenerImpl implements GcmListener {
_GcmListenerImpl(this.callback);

GcmListenerCallback callback;

void onMessageReceived(String from, String message) {
callback(from, message);
}
}

Future<String> registerGcmService(String senderId, GcmListenerCallback listenerCallback) async {
GcmListenerStub listener = new GcmListenerStub.unbound()
..impl = new _GcmListenerImpl(listenerCallback);
GcmServiceRegisterResponseParams result =
await _gcmService.ptr.register(senderId, listener);
return result.token;
}

void subscribeTopics(String token, List<String> topics) {
_gcmService.ptr.subscribeTopics(token, topics);
}

void unsubscribeTopics(String token, List<String> topics) {
_gcmService.ptr.unsubscribeTopics(token, topics);
}
15 changes: 15 additions & 0 deletions packages/gcm/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: gcm
description: Bindings for Google Cloud Messaging API
version: 0.0.1
author: Flutter Authors <[email protected]>
homepage: https://github.com/flutter/flutter/tree/master/packages/playfair

dependencies:
flutter:
path: ../flutter

dev_dependencies:
test: 0.12.6+1

environment:
sdk: '>=1.12.0 <2.0.0'