Skip to content
Open
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
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
*.iml
.gradle
/local.properties
/.idea
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures

app/src/main/res/raw/*.json
.externalNativeBuild
.cxx
6 changes: 6 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 9 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
# Google Cloud Speech API examples
# What is Aware?
Aware is an inter-car communication system designed to promote driver awareness and reduce traffic accidents. Drivers will use the Android app to send and respond to requests to change lanes, pass slow cars, and so on.

This directory contains Android example that uses the
[Google Cloud Speech API](https://cloud.google.com/speech/).
## Motivation
Did you know that traffic accidents are the leading cause of mortality in America? According to the US Department of Transportation, there are over 6 million automotive crashes each year. 60% of these 6 million could have been prevented had the driver been alerted a mere half second before the collision. Last summer, our teammate Colin drove 5 hours a day on what is known as "America's deadliest highway." He wished he was able to notify other cars when he wanted to pass them or merge into another lane.

## Prerequisites
## Why Aware?
The reason we chose to do this as an app rather than integrated in a car is because not everyone's car has the technology to communicate with other cars (also because we're broke college students and don't have Teslas to test on). If many cars can't send/receive messages, then that defeats the purpose of our idea. However, almost everyone has a phone, meaning that the majority of drivers on the road will immediately be able to download our app and start using it to communicate with each other. In the past, this was impossible due to latency, but now it is a viable idea because of the advent of 5G.

### Enable the Speech API
## How to run
Use Android studio to run the project

If you have not already done so,
[enable the Google Speech API for your project](https://cloud.google.com/speech/docs/getting-started). You
must be whitelisted to do this.

### Set Up to Authenticate With Your Project's Credentials

This Android app uses JSON credential file locally stored in the resources. ***You should not do
this in your production app.*** Instead, you should set up your own backend server that
authenticates app users. The server should delegate API calls from your client app. This way, you
can enforce usage quota per user. Alternatively, you should get the access token on the server side,
and supply client app with it. The access token will expire in a short while.

In this sample, we just put the Service Account in the client for ease of use. The app still gets
an access token using the service account credential, and use the token to call the API, so you can
see how to do so.

In order to try out this sample, visit the [Cloud Console](https://console.cloud.google.com/), and
navigate to:
`API Manager > Credentials > Create credentials > Service account key > New service account`.
Create a new service account, and download the JSON credentials file. Put the file in the app
resources as `app/src/main/res/raw/credential.json`.

Again, ***you should not do this in your production app.***

See the [Cloud Platform Auth Guide](https://cloud.google.com/docs/authentication#developer_workflow)
for more information.

### Test

Before running tests update the following environment variable with the service
account:

GOOGLE_APPLICATION=service-account.json

This environment variable will be used to update the service account used here
`app/src/main/res/raw/credential.json`.

Run tests by using:

gradle test

### Build signed release

*This step is optional.*

This sample uses ProGuard to decrease the number of methods generated by the gRPC library. It is
enabled by default for release build. If you want to build it, change the path, alias and passwords
of the keystore file specified in gradle.properties.
![Aware Logo](https://github.com/colinbking/aware/blob/master/app/src/main/res/mipmap-hdpi/car_icon.png)
138 changes: 21 additions & 117 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,133 +1,37 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'

ext {
supportLibraryVersion = '25.4.0'
grpcVersion = '1.4.0'
}
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 25
buildToolsVersion '25.0.3'

compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.google.cloud.android.speech"
targetSdkVersion 25
applicationId "com.example.aware"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName '1.0'
}

signingConfigs {
release {
storeFile file(project.properties.storeFile)
storePassword project.properties.storePassword
keyAlias project.properties.keyAlias
keyPassword project.properties.keyPassword
}
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

productFlavors {
dev {
// Minimum version with platform multi-dex support
minSdkVersion 21
}
prod {
// Minimum version that can run gRPC (TLS extension)
minSdkVersion 16
}
}

buildTypes {
debug {
minifyEnabled false
multiDexEnabled true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}

configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
resolutionStrategy.force "com.android.support:support-annotations:$supportLibraryVersion"
}
}

protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.3.0'
}
plugins {
javalite {
artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
}
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {}
grpc {
// Options added to --grpc_out
option 'lite'
}
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

// Support libraries
compile "com.android.support:design:$supportLibraryVersion"
compile "com.android.support:cardview-v7:$supportLibraryVersion"
compile "com.android.support:recyclerview-v7:$supportLibraryVersion"

// gRPC
compile "io.grpc:grpc-okhttp:$grpcVersion"
compile "io.grpc:grpc-protobuf-lite:$grpcVersion"
compile "io.grpc:grpc-stub:$grpcVersion"
compile 'javax.annotation:javax.annotation-api:1.2'
protobuf 'com.google.protobuf:protobuf-java:3.3.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-analytics:17.0.1'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
implementation "androidx.work:work-runtime:2.2.0"
implementation 'com.squareup.okhttp3:okhttp:3.0.1'
implementation 'com.android.volley:volley:1.1.1'

// OAuth2 for Google API
compile('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
exclude module: 'httpclient'
}

// Tests
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}

task copySecretKey(type: Copy) {
def File secretKey = file "$System.env.GOOGLE_APPLICATION_CREDENTIALS"
from secretKey.getParent()
include secretKey.getName()
into 'src/main/res/raw'
rename secretKey.getName(), "credential.json"
}
preBuild.dependsOn(copySecretKey)

48 changes: 48 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"project_info": {
"project_number": "172468782986",
"firebase_url": "https://pennapps-de7f1.firebaseio.com",
"project_id": "pennapps-de7f1",
"storage_bucket": "pennapps-de7f1.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:172468782986:android:25b820b50ec18b3f4b6a73",
"android_client_info": {
"package_name": "com.example.aware"
}
},
"oauth_client": [
{
"client_id": "172468782986-jr0t7j1sd7d15ink0m7ct4a3b69rqboi.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.aware",
"certificate_hash": "535e4e914a7cf5ff00c539623b01797d8a002141"
}
},
{
"client_id": "172468782986-d8mrk7lr730k8h0s4g03nmu3uujd88t6.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAouq-OIthWuM3iKzllN5NHy7ut50V00M4"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "172468782986-dtg4bpp6m55ip0fhmeq64m06aj5mcss2.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
40 changes: 19 additions & 21 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# Copyright 2016 Google Inc. All Rights Reserved.
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# Suppress warnings from gRPC dependencies
-dontwarn com.google.common.**
-dontwarn com.google.api.client.**
-dontwarn com.google.protobuf.**
-dontwarn io.grpc.**
-dontwarn okio.**
-dontwarn com.google.errorprone.annotations.**
-keep class io.grpc.internal.DnsNameResolveProvider
-keep class io.grpc.okhttp.OkHttpChannelProvider
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.aware;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

assertEquals("com.example.aware", appContext.getPackageName());
}
}
Loading