-
Notifications
You must be signed in to change notification settings - Fork 616
Add Firebase Segmentation SDK and some skeleton code in Firebase Android SDK #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
26eb1f5
Add Firebase Segmentation SDK and some skeleton code in Firebase Andr…
diwu-arete 938d1a8
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete 83d90ba
Add Firebase Segmentation SDK and some skeleton code in Firebase Andr…
diwu-arete 1c77a31
Merge branch 'arete-floc' of github.com:firebase/firebase-android-sdk…
diwu-arete 2dc0264
Address comments #1
diwu-arete 2f8cc32
Address comments #1
diwu-arete e12e282
Merge branch 'arete-floc' of github.com:firebase/firebase-android-sdk…
diwu-arete a453d96
Address comments #2
diwu-arete 16ef0b8
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// 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. | ||
|
||
plugins { | ||
id 'firebase-library' | ||
id 'com.google.protobuf' | ||
} | ||
|
||
firebaseLibrary { | ||
testLab.enabled = true | ||
} | ||
|
||
protobuf { | ||
// Configure the protoc executable | ||
protoc { | ||
// Download from repositories | ||
artifact = 'com.google.protobuf:protoc:3.4.0' | ||
} | ||
plugins { | ||
grpc { | ||
artifact = 'io.grpc:protoc-gen-grpc-java:1.12.0' | ||
} | ||
javalite { | ||
// The codegen for lite comes as a separate artifact | ||
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0' | ||
} | ||
} | ||
generateProtoTasks { | ||
all().each { task -> | ||
task.builtins { | ||
// In most cases you don't need the full Java output | ||
// if you use the lite output. | ||
remove java | ||
} | ||
task.plugins { | ||
grpc { | ||
option 'lite' | ||
} | ||
javalite {} | ||
} | ||
} | ||
} | ||
} | ||
|
||
android { | ||
compileSdkVersion project.targetSdkVersion | ||
|
||
defaultConfig { | ||
minSdkVersion project.minSdkVersion | ||
targetSdkVersion project.targetSdkVersion | ||
multiDexEnabled true | ||
versionName version | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
sourceSets { | ||
main { | ||
proto { | ||
srcDir 'src/main/proto' | ||
} | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
testOptions { | ||
unitTests { | ||
includeAndroidResources = true | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project(':firebase-common') | ||
|
||
implementation('com.google.firebase:firebase-iid:17.0.3') { | ||
exclude group: "com.google.firebase", module: "firebase-common" | ||
} | ||
implementation 'androidx.appcompat:appcompat:1.0.2' | ||
implementation 'androidx.multidex:multidex:2.0.0' | ||
implementation 'com.google.android.gms:play-services-tasks:16.0.1' | ||
|
||
testImplementation 'androidx.test:core:1.2.0' | ||
testImplementation 'junit:junit:4.12' | ||
testImplementation "org.robolectric:robolectric:$robolectricVersion" | ||
|
||
androidTestImplementation 'androidx.annotation:annotation:1.1.0' | ||
androidTestImplementation 'androidx.test:runner:1.2.0' | ||
androidTestImplementation 'androidx.test:rules:1.2.0' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version=17.1.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<lint> | ||
<!--gRPC's DNS name resolver checks for javax.naming at runtime to determine if it can be used, but fails gracefullt without it. This lint error is safe to ignore.--> | ||
<!--See : https://github.com/grpc/grpc-java/blob/b0f423295b4674cb5247a6143fd211b050ef0065/core/src/main/java/io/grpc/internal/JndiResourceResolverFactory.java#L73--> | ||
<issue id="InvalidPackage"> | ||
<ignore path="*/io.grpc/grpc-core/*"/> | ||
</issue> | ||
|
||
<!-- Disable the given check in this project --> | ||
<issue id="GradleCompatible" severity="ignore" /> | ||
</lint> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2019 Google LLC --> | ||
<!-- --> | ||
<!-- 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. --> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.google.firebase.segmentation"> | ||
|
||
<application> | ||
<uses-library android:name="android.test.runner"/> | ||
</application> | ||
|
||
<instrumentation | ||
android:name="androidx.test.runner.AndroidJUnitRunner" | ||
android:targetPackage="com.google.firebase.segmentation" /> | ||
</manifest> |
50 changes: 50 additions & 0 deletions
50
...droidTest/java/com/google/firebase/segmentation/FirebaseSegmentationInstrumentedTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// 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. | ||
|
||
package com.google.firebase.segmentation; | ||
|
||
import static org.junit.Assert.assertNull; | ||
|
||
import androidx.test.InstrumentationRegistry; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* 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 FirebaseSegmentationInstrumentedTest { | ||
|
||
private FirebaseApp firebaseApp; | ||
|
||
@Before | ||
public void setUp() { | ||
FirebaseApp.clearInstancesForTest(); | ||
firebaseApp = | ||
FirebaseApp.initializeApp( | ||
InstrumentationRegistry.getContext(), | ||
new FirebaseOptions.Builder().setApplicationId("1:123456789:android:abcdef").build()); | ||
} | ||
|
||
@Test | ||
public void useAppContext() { | ||
assertNull(FirebaseSegmentation.getInstance().setCustomInstallationId("123123").getResult()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2019 Google LLC --> | ||
<!-- --> | ||
<!-- 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. --> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.google.firebase.segmentation"> | ||
|
||
<application> | ||
<service | ||
android:name="com.google.firebase.components.ComponentDiscoveryService" | ||
android:exported="false"> | ||
<meta-data | ||
android:name="com.google.firebase.components:com.google.firebase.segmentation.FirebaseSegmentationRegistrar" | ||
android:value="com.google.firebase.components.ComponentRegistrar" /> | ||
</service> | ||
</application> | ||
</manifest> |
61 changes: 61 additions & 0 deletions
61
...ase-segmentation/src/main/java/com/google/firebase/segmentation/FirebaseSegmentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// 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. | ||
|
||
package com.google.firebase.segmentation; | ||
|
||
import androidx.annotation.NonNull; | ||
import com.google.android.gms.common.internal.Preconditions; | ||
import com.google.android.gms.tasks.Task; | ||
import com.google.android.gms.tasks.Tasks; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.iid.FirebaseInstanceId; | ||
|
||
/** Entry point of Firebase Segmentation SDK. */ | ||
public class FirebaseSegmentation { | ||
|
||
private final FirebaseApp firebaseApp; | ||
private final FirebaseInstanceId firebaseInstanceId; | ||
|
||
FirebaseSegmentation(FirebaseApp firebaseApp) { | ||
this.firebaseApp = firebaseApp; | ||
this.firebaseInstanceId = FirebaseInstanceId.getInstance(firebaseApp); | ||
} | ||
|
||
/** | ||
* Returns the {@link FirebaseSegmentation} initialized with the default {@link FirebaseApp}. | ||
* | ||
* @return a {@link FirebaseSegmentation} instance | ||
*/ | ||
@NonNull | ||
public static FirebaseSegmentation getInstance() { | ||
FirebaseApp defaultFirebaseApp = FirebaseApp.getInstance(); | ||
diwu-arete marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return getInstance(defaultFirebaseApp); | ||
} | ||
|
||
/** | ||
* Returns the {@link FirebaseSegmentation} initialized with a custom {@link FirebaseApp}. | ||
* | ||
* @param app a custom {@link FirebaseApp} | ||
* @return a {@link FirebaseSegmentation} instance | ||
*/ | ||
@NonNull | ||
public static FirebaseSegmentation getInstance(@NonNull FirebaseApp app) { | ||
Preconditions.checkArgument(app != null, "Null is not a valid value of FirebaseApp."); | ||
return app.get(FirebaseSegmentation.class); | ||
} | ||
|
||
Task<Void> setCustomInstallationId(String customInstallationId) { | ||
return Tasks.forResult(null); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ntation/src/main/java/com/google/firebase/segmentation/FirebaseSegmentationRegistrar.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// 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. | ||
|
||
package com.google.firebase.segmentation; | ||
|
||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.components.Component; | ||
import com.google.firebase.components.ComponentRegistrar; | ||
import com.google.firebase.components.Dependency; | ||
import com.google.firebase.platforminfo.LibraryVersionComponent; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class FirebaseSegmentationRegistrar implements ComponentRegistrar { | ||
|
||
@Override | ||
public List<Component<?>> getComponents() { | ||
return Arrays.asList( | ||
Component.builder(FirebaseSegmentation.class) | ||
.add(Dependency.required(FirebaseApp.class)) | ||
.factory(c -> new FirebaseSegmentation(c.get(FirebaseApp.class))) | ||
.build(), | ||
LibraryVersionComponent.create("fire-segmentation", BuildConfig.VERSION_NAME)); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ion/src/test/java/com/google/firebase/segmentation/FirebaseSegmentationRegistrarTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// 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. | ||
|
||
package com.google.firebase.segmentation; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import androidx.test.core.app.ApplicationProvider; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class FirebaseSegmentationRegistrarTest { | ||
|
||
@Before | ||
public void setUp() { | ||
FirebaseApp.clearInstancesForTest(); | ||
} | ||
|
||
@Test | ||
public void getFirebaseInstallationsInstance() { | ||
FirebaseApp defaultApp = | ||
FirebaseApp.initializeApp( | ||
ApplicationProvider.getApplicationContext(), | ||
new FirebaseOptions.Builder().setApplicationId("1:123456789:android:abcdef").build()); | ||
|
||
FirebaseApp anotherApp = | ||
FirebaseApp.initializeApp( | ||
ApplicationProvider.getApplicationContext(), | ||
new FirebaseOptions.Builder().setApplicationId("1:987654321:android:abcdef").build(), | ||
"firebase_app_1"); | ||
|
||
FirebaseSegmentation defaultSegmentation = FirebaseSegmentation.getInstance(); | ||
assertNotNull(defaultSegmentation); | ||
assertNull(defaultSegmentation.setCustomInstallationId("12345").getResult()); | ||
|
||
FirebaseSegmentation anotherSegmentation = FirebaseSegmentation.getInstance(anotherApp); | ||
assertNotNull(anotherSegmentation); | ||
assertNull(anotherSegmentation.setCustomInstallationId("ghdjaas").getResult()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.