Skip to content

Commit

Permalink
refactored cookie management
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarapaty committed Aug 28, 2018
1 parent efa6f04 commit 76cbf6c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 14 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

defaultConfig {
applicationId "com.potatoinc.instantappsample.app"
Expand Down
1 change: 0 additions & 1 deletion base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

baseFeature true
defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.example.android.instantappsample.base

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import com.google.android.gms.instantapps.InstantApps

object Util {
Expand All @@ -18,4 +20,31 @@ object Util {
)
}
}
}

fun Context.updateInstantAppCookie(byteArray: ByteArray): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (byteArray.size <= packageManager.instantAppCookieMaxBytes) {
packageManager.updateInstantAppCookie(byteArray)
} else {
return false
}
} else {
val packageManagerCompat = InstantApps.getPackageManagerCompat(this)
if (byteArray.size <= packageManagerCompat.instantAppCookieMaxSize) {
packageManagerCompat.setInstantAppCookie(byteArray)
} else {
return false
}
}

return true
}

fun Context.getInstantAppCookie(): ByteArray {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
packageManager.instantAppCookie
} else {
InstantApps.getPackageManagerCompat(this).instantAppCookie
}
}
1 change: 0 additions & 1 deletion character-details/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.minSdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package com.example.android.instantappsample.character_details

import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.os.Build
import android.os.Bundle
import android.os.PersistableBundle
import android.support.v7.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.google.android.gms.instantapps.InstantApps
import com.example.android.instantappsample.base.updateInstantAppCookie
import kotlinx.android.synthetic.main.activity_character_details.*
import timber.log.Timber
import java.nio.charset.Charset
Expand Down Expand Up @@ -40,13 +39,7 @@ class CharacterDetailsActivity : AppCompatActivity() {
}
})

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Timber.e("${packageManager.instantAppCookieMaxBytes}")
packageManager.updateInstantAppCookie(intent?.data.toString().toByteArray(Charset.defaultCharset()))
} else {
Timber.e("${InstantApps.getPackageManagerCompat(this).instantAppCookieMaxSize}")
}

updateInstantAppCookie(intent?.data.toString().toByteArray(Charset.defaultCharset()))
}

}
1 change: 0 additions & 1 deletion character-list/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.minSdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Build
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.example.android.instantappsample.base.getInstantAppCookie
import com.google.android.gms.auth.api.credentials.*
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.common.api.ResolvableApiException
Expand Down Expand Up @@ -88,6 +89,11 @@ public class CharacterListActivity : AppCompatActivity() {
}
}

override fun onResume() {
super.onResume()
Timber.e(String(getInstantAppCookie(), Charset.defaultCharset()))
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

Expand Down
1 change: 0 additions & 1 deletion instantapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.minSdkVersion
Expand Down
3 changes: 3 additions & 0 deletions proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
-keep, includedescriptorclasses class com.example.android.instantappsample.base.RestClient {
public protected *;
}
-keep, includedescriptorclasses class com.example.android.instantappsample.base.UtilKt {
public protected *;
}
-keep, includedescriptorclasses class com.example.android.instantappsample.base.data.Character {
public protected *;
}
Expand Down

0 comments on commit 76cbf6c

Please sign in to comment.