Skip to content

Commit 2a89edd

Browse files
committed
Initial checkin of Google Sign-In plugin for Unity.
This checkin includes the Android support. The implementation uses a Java implementation of an Android fragment to call the Auth methods. This java code is accessed from a native C++ layer, which is invoked via the PInvoke API in Unity. Change-Id: I6fbf978d5aff87b12039ab28f70c5a8ab336f96b
1 parent 2eb0061 commit 2a89edd

File tree

70 files changed

+5010
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+5010
-0
lines changed

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.gradle/
2+
.idea/
3+
bin/
4+
build/
5+
*.iml
6+
local.properties
7+
local.settings
8+
.externalNativeBuild/
9+
*.apk
10+
11+
*.sln
12+
*.userprefs
13+
Library/
14+
ProjectSettings/
15+
Temp/
16+
obj/
17+
18+
# Don't check in the resolver
19+
GoogleSignInPlugin/Assets/PlayServicesResolver/
20+
21+
# don't checkin client plists
22+
GoogleSignInPlugin/Assets/Plugins/iOS/client*.plist*
23+
24+
Assembly-CSharp-Editor.csproj
25+
Assembly-CSharp.csproj

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Want to contribute? Great! First, read this page (including the small print at the end).
2+
3+
### Before you contribute
4+
Before we can use your code, you must sign the
5+
[Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1)
6+
(CLA), which you can do online. The CLA is necessary mainly because you own the
7+
copyright to your changes, even after your contribution becomes part of our
8+
codebase, so we need your permission to use and distribute your code. We also
9+
need to be sure of various other things — for instance that you'll tell us if you
10+
know that your code infringes on other people's patents. You don't have to sign
11+
the CLA until after you've submitted your code for review and a member has
12+
approved it, but you must do it before we can put your code into our codebase.
13+
Before you start working on a larger contribution, you should get in touch with
14+
us first through the issue tracker with your idea so that we can help out and
15+
possibly guide you. Coordinating up front makes it much easier to avoid
16+
frustration later on.
17+
18+
### Code reviews
19+
All submissions, including submissions by project members, require review. We
20+
use Github pull requests for this purpose.
21+
22+
### The small print
23+
Contributions made by corporations are covered by a different agreement than
24+
the one above, the Software Grant and Corporate Contributor License Agreement.

GoogleSignInPlugin/Assets/GoogleSignIn.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GoogleSignInPlugin/Assets/GoogleSignIn/Editor.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// <copyright file="GoogleSignInDependencies.cs" company="Google Inc.">
2+
// Copyright (C) 2017 Google Inc. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
// </copyright>
16+
17+
namespace GoogleSignIn.Editor {
18+
using System;
19+
using System.Collections.Generic;
20+
using UnityEditor;
21+
using UnityEngine;
22+
23+
/// <summary>
24+
/// Google sign in dependencies. This class registers the dependendies
25+
/// on Google Play Services with the JarResolver plugin.
26+
/// </summary>
27+
[InitializeOnLoad]
28+
public class GoogleSignInDependencies : AssetPostprocessor {
29+
30+
static GoogleSignInDependencies() {
31+
AddDependencies();
32+
}
33+
34+
#if UNITY_ANDROID
35+
public static object svcSupport;
36+
37+
static void AddDependencies() {
38+
// Setup the resolver using reflection as the module may not be
39+
// available at compile time.
40+
Type playServicesSupport = Google.VersionHandler.FindClass(
41+
"Google.JarResolver", "Google.JarResolver.PlayServicesSupport");
42+
if (playServicesSupport == null) {
43+
return;
44+
}
45+
svcSupport = svcSupport ?? Google.VersionHandler.InvokeStaticMethod(
46+
playServicesSupport, "CreateInstance",
47+
new object[] {"GoogleSignIn",
48+
EditorPrefs.GetString("AndroidSdkRoot"),
49+
"ProjectSettings"}
50+
);
51+
if (svcSupport != null) {
52+
// The only direct dependency is on auth, min version 10.2.0.
53+
Google.VersionHandler.InvokeInstanceMethod(svcSupport,
54+
"DependOn", new object[] {
55+
"com.google.android.gms",
56+
"play-services-auth",
57+
"10.2+" },
58+
namedArgs: new Dictionary<string, object>() {
59+
{"packageIds", new string[] {
60+
"extra-google-m2repository"
61+
}
62+
}
63+
});
64+
} else {
65+
Debug.LogError("Jar resolver service not available. " +
66+
"Please add the Jar resolver to your project or ignore this error " +
67+
" and manage the Google Play Services dependencies manually");
68+
}
69+
}
70+
#elif UNITY_IOS
71+
static void AddDependencies() {
72+
Type iosResolver = Google.VersionHandler.FindClass(
73+
"Google.IOSResolver", "Google.IOSResolver");
74+
if (iosResolver == null) {
75+
return;
76+
}
77+
78+
Google.VersionHandler.InvokeStaticMethod(
79+
iosResolver, "AddPod",
80+
new object[] { "GoogleSignIn" },
81+
namedArgs: new Dictionary<string, object>() {
82+
{ "version", ">= 4.0.2" },
83+
{ "bitcodeEnabled", false },
84+
});
85+
}
86+
#endif // UNITY_ANDROID / iOS
87+
}
88+
}

GoogleSignInPlugin/Assets/GoogleSignIn/Editor/GoogleSignInDependencies.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// <copyright file="Future.cs" company="Google Inc.">
2+
// Copyright (C) 2017 Google Inc. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
// </copyright>
16+
namespace Google {
17+
using System.Collections;
18+
using System.Threading.Tasks;
19+
using UnityEngine;
20+
21+
/// <summary>
22+
/// Interface for implementations of the Future<T> API.
23+
/// </summary>
24+
internal interface FutureAPIImpl<T> {
25+
bool Pending { get; }
26+
GoogleSignInStatusCode Status { get; }
27+
T Result { get; }
28+
}
29+
30+
/// <summary>
31+
/// Future return value.
32+
/// </summary>
33+
/// <remarks>This class provides a promise of a result from a method call.
34+
/// The typical usage is to check the Pending property until it is false.
35+
/// At this time either the Status or Result will be available for use.
36+
/// Result is only set if the operation was successful.
37+
/// As a convience, a coroutine to complete a Task is provided.
38+
/// </remarks>
39+
public class Future<T> {
40+
41+
private FutureAPIImpl<T> apiImpl;
42+
43+
internal Future(FutureAPIImpl<T> impl) {
44+
apiImpl = impl;
45+
}
46+
47+
/// <summary>
48+
/// Gets a value indicating whether this
49+
/// <see cref="T:Google.Future`1"/> is pending.
50+
/// </summary>
51+
/// <value><c>true</c> if pending; otherwise, <c>false</c>.</value>
52+
public bool Pending { get { return apiImpl.Pending; } }
53+
54+
/// <summary>
55+
/// Gets the status.
56+
/// </summary>
57+
/// <value>The status is set when Pending == false.</value>
58+
GoogleSignInStatusCode Status { get { return apiImpl.Status; } }
59+
60+
/// <summary>
61+
/// Gets the result.
62+
/// </summary>
63+
/// <value>The result is set when Pending == false and there is no error.
64+
/// </value>
65+
T Result { get { return apiImpl.Result; } }
66+
67+
/// <summary>
68+
/// Waits for result then completes the TaskCompleationSource.
69+
/// </summary>
70+
/// <returns>The for result.</returns>
71+
/// <param name="tcs">Tcs.</param>
72+
internal IEnumerator WaitForResult(TaskCompletionSource<T> tcs) {
73+
yield return new WaitUntil(() => !Pending);
74+
if (Status == GoogleSignInStatusCode.Canceled) {
75+
tcs.SetCanceled();
76+
} else if (Status == GoogleSignInStatusCode.Success ||
77+
Status == GoogleSignInStatusCode.SuccessCached) {
78+
tcs.SetResult(Result);
79+
} else {
80+
tcs.SetException(new GoogleSignIn.SignInException(Status));
81+
}
82+
}
83+
}
84+
}

GoogleSignInPlugin/Assets/GoogleSignIn/Future.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)