Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8881325
Implement Firebase segmentation SDK device local cache
diwu-arete Jun 13, 2019
864748f
[Firebase Segmentation] Add custom installation id cache layer and te…
diwu-arete Jun 14, 2019
0a3ebf6
Add test for updating cache
diwu-arete Jun 14, 2019
2d158ed
Switch to use SQLiteOpenHelper
diwu-arete Jun 15, 2019
f118d39
Switch to use SharedPreferences from SQLite.
diwu-arete Jun 17, 2019
4da5d31
Change the cache class to be singleton
diwu-arete Jun 18, 2019
d1ff0ec
Wrap shared pref commit in a async task.
diwu-arete Jun 18, 2019
2c5102c
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jun 18, 2019
41fbfee
Address comments
diwu-arete Jun 18, 2019
5fd2fa0
Google format fix
diwu-arete Jun 18, 2019
e950003
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jun 18, 2019
dba0c0e
Replace some deprecated code.
diwu-arete Jun 18, 2019
dc37bf8
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 18, 2019
ebdd626
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jun 18, 2019
f26741e
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 18, 2019
38c403f
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 18, 2019
a9a43a4
Package refactor
diwu-arete Jun 18, 2019
ca6dacf
nit
diwu-arete Jun 18, 2019
e7fff81
nit
diwu-arete Jun 18, 2019
bb8bf45
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 18, 2019
b381889
Add the state machine of updating custom installation id in the local
diwu-arete Jun 19, 2019
a72cf60
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 19, 2019
1adcfbd
minor format fix
diwu-arete Jun 20, 2019
6091f82
Address comments #1
diwu-arete Jun 20, 2019
ada5577
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jun 20, 2019
af5bcd1
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 20, 2019
de6fb6d
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jun 24, 2019
75e523b
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 24, 2019
134f06e
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 24, 2019
6a0f502
Http client in Firebase Segmentation SDK to call backend service.
diwu-arete Jun 26, 2019
4ac7db5
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jun 26, 2019
7f40978
Revert unintentional change
diwu-arete Jun 26, 2019
b2fc302
Fix connected device test
diwu-arete Jun 26, 2019
1f2ab34
Fix connected device test
diwu-arete Jun 26, 2019
402d8b6
Merge branch 'arete-floc' of github.com:firebase/firebase-android-sdk…
diwu-arete Jun 26, 2019
ce698cf
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jul 8, 2019
0e0278e
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jul 8, 2019
9880624
1. Add a few annotations to make java code Kotlin friendly
diwu-arete Jul 8, 2019
8ffb5bb
Fix java format
diwu-arete Jul 8, 2019
daf4698
Fix API version
diwu-arete Jul 8, 2019
7985e14
Change the segmentation API implementation to synchronous and put the
diwu-arete Jul 9, 2019
9f36d35
Fix a async getResult race issue.
diwu-arete Jul 9, 2019
047c0af
OkHttpClient -> HttpsUrlConnection
diwu-arete Jul 10, 2019
8b39c31
Use gzip for compressing content and fix ourput stream memory leak risk.
diwu-arete Jul 18, 2019
dc1a63c
Addressed a few comments
diwu-arete Jul 22, 2019
b401d31
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jul 22, 2019
8ba1c9b
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jul 22, 2019
143ed74
FirebaseSegmentation SDK
diwu-arete Jul 30, 2019
e5f0cd3
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Jul 30, 2019
a5250c1
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Jul 30, 2019
6daae2a
Merge branch 'master' of github.com:firebase/firebase-android-sdk int…
diwu-arete Aug 5, 2019
4d5b2de
Merge branch 'floc-master' of github.com:firebase/firebase-android-sd…
diwu-arete Aug 6, 2019
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
Prev Previous commit
Next Next commit
OkHttpClient -> HttpsUrlConnection
  • Loading branch information
diwu-arete committed Jul 10, 2019
commit 047c0af81eff97623b823400b0d9293d1a1d449f
1 change: 0 additions & 1 deletion firebase-segmentation/firebase-segmentation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
implementation 'com.squareup.okhttp:okhttp:2.7.5'

compileOnly "com.google.auto.value:auto-value-annotations:1.6.5"
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
package com.google.firebase.segmentation.remote;

import androidx.annotation.NonNull;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -35,10 +33,6 @@ public class SegmentationServiceClient {
"projects/%s/installations/%s/customSegmentationData:clear";
private static final String FIREBASE_SEGMENTATION_API_VERSION = "v1alpha";

private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

private final OkHttpClient httpClient;

public enum Code {
OK,

Expand All @@ -53,10 +47,6 @@ public enum Code {
UNAUTHORIZED,
}

public SegmentationServiceClient() {
httpClient = new OkHttpClient();
}

@NonNull
public Code updateCustomInstallationId(
long projectNumber,
Expand All @@ -66,36 +56,35 @@ public Code updateCustomInstallationId(
@NonNull String firebaseInstanceIdToken) {
String resourceName =
String.format(UPDATE_REQUEST_RESOURCE_NAME_FORMAT, projectNumber, firebaseInstanceId);

RequestBody requestBody;
try {
requestBody =
RequestBody.create(
JSON,
buildUpdateCustomSegmentationDataRequestBody(resourceName, customInstallationId)
.toString());
} catch (JSONException e) {
// This should never happen
throw new IllegalStateException(e);
}

Request request =
new Request.Builder()
.url(
String.format(
"https://%s/%s/%s?key=%s",
FIREBASE_SEGMENTATION_API_DOMAIN,
FIREBASE_SEGMENTATION_API_VERSION,
resourceName,
apiKey))
.header("Authorization", "FIREBASE_INSTALLATIONS_AUTH " + firebaseInstanceIdToken)
.header("Content-Type", "application/json")
.patch(requestBody)
.build();
URL url =
new URL(
String.format(
"https://%s/%s/%s?key=%s",
FIREBASE_SEGMENTATION_API_DOMAIN,
FIREBASE_SEGMENTATION_API_VERSION,
resourceName,
apiKey));

HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setRequestMethod("PATCH");
httpsURLConnection.addRequestProperty(
"Authorization", "FIREBASE_INSTALLATIONS_AUTH " + firebaseInstanceIdToken);
httpsURLConnection.addRequestProperty("Content-Type", "application/json");
OutputStream os = httpsURLConnection.getOutputStream();
try {
os.write(
buildUpdateCustomSegmentationDataRequestBody(resourceName, customInstallationId)
.toString()
.getBytes("UTF-8"));
} catch (JSONException e) {
throw new IllegalStateException(e);
}
httpsURLConnection.connect();

try {
Response response = httpClient.newCall(request).execute();
switch (response.code()) {
int httpResponseCode = httpsURLConnection.getResponseCode();
switch (httpResponseCode) {
case 200:
return Code.OK;
case 401:
Expand Down Expand Up @@ -126,34 +115,33 @@ public Code clearCustomInstallationId(
@NonNull String firebaseInstanceIdToken) {
String resourceName =
String.format(CLEAR_REQUEST_RESOURCE_NAME_FORMAT, projectNumber, firebaseInstanceId);

RequestBody requestBody;
try {
requestBody =
RequestBody.create(
JSON, buildClearCustomSegmentationDataRequestBody(resourceName).toString());
} catch (JSONException e) {
// This should never happen
throw new IllegalStateException(e);
}

Request request =
new Request.Builder()
.url(
String.format(
"https://%s/%s/%s?key=%s",
FIREBASE_SEGMENTATION_API_DOMAIN,
FIREBASE_SEGMENTATION_API_VERSION,
resourceName,
apiKey))
.header("Authorization", "FIREBASE_INSTALLATIONS_AUTH " + firebaseInstanceIdToken)
.header("Content-Type", "application/json")
.post(requestBody)
.build();
URL url =
new URL(
String.format(
"https://%s/%s/%s?key=%s",
FIREBASE_SEGMENTATION_API_DOMAIN,
FIREBASE_SEGMENTATION_API_VERSION,
resourceName,
apiKey));

HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setRequestMethod("POST");
httpsURLConnection.addRequestProperty(
"Authorization", "FIREBASE_INSTALLATIONS_AUTH " + firebaseInstanceIdToken);
httpsURLConnection.addRequestProperty("Content-Type", "application/json");
OutputStream os = httpsURLConnection.getOutputStream();
try {
os.write(
buildClearCustomSegmentationDataRequestBody(resourceName).toString().getBytes("UTF-8"));
} catch (JSONException e) {
throw new IllegalStateException(e);
}
httpsURLConnection.connect();

try {
Response response = httpClient.newCall(request).execute();
switch (response.code()) {
int httpResponseCode = httpsURLConnection.getResponseCode();
switch (httpResponseCode) {
case 200:
return Code.OK;
case 401:
Expand Down