Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Proto Datastoreを使う前の心構え
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
bigbackboom
November 11, 2024
320
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Proto Datastoreを使う前の心構え
bigbackboom
November 11, 2024
More Decks by bigbackboom
See All by bigbackboom
Learn as a Pair
bigbackboom
0
73
Not 2 L8 JKでもわかるMaterial 3
bigbackboom
0
60
JKでもわかるSFace Recognition
bigbackboom
0
80
Androidタブレットアプリ作成_棚から牡丹餅を得るにはまず棚から
bigbackboom
0
69
Extended A Study in Bitmap: Is NDK the fast Processing method by CPU?
bigbackboom
0
34
Have A Dog in CircleCI
bigbackboom
0
86
Androidエンジニアのお仕事でのショボーン
bigbackboom
0
94
解明!楽しいプレゼンする話すスキル
bigbackboom
0
120
Pay for Businessのgradle.ktsへの移行の小噺
bigbackboom
0
87
Featured
See All Featured
Making Projects Easy
brettharned
120
6.7k
Thoughts on Productivity
jonyablonski
76
5.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
190
The Cult of Friendly URLs
andyhume
79
6.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.3k
A Tale of Four Properties
chriscoyier
163
24k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
350
Transcript
Proto Datastoreを使う前の心構え キクチコウダイ
自己紹介 菊池 広大(キクチコウダイ) 2023年6月 株式会社マネーフォワードに入社 埼玉出身、Iターンで東京から福岡に引越し Androidエンジニア、たまにバックエンド。最近諸事 情でReact勉強中。 Github: https://github.com/BigBackBoom
WE ARE HIRING!!!!
Overview
Overview Androidの Proto Datastoreを使った際に 思ったよりも手順が多かったので その共有の知見となります
Jetpack Datastore
Jetpack Datastore SharedPreferenceの代替となる アプリにローカルデータを保存する ソリューションとなります
Jetpack Datastore • Preference Datastore ◦ Key-Value型 ◦ プリミティブ型と一部データ配列のみ対応 •
Proto Datastore ◦ カスタムデータ型
Jetpack Datastore • 共通の利点 ◦ DBと比べて導入が簡単 ◦ 両者裏でProtocol Bufferを利用しているので高速 •
共通の弱点 ◦ データは部分更新できないため複雑なデータは効率が悪い ◦ Protocol Buffer自体がマイナー
なぜ Proto Datastore?
なぜProto Datastore? • Shared Datastoreはシンプルなデータしか保存でき ない • 昔はSharePreferenceにJSON形式でテキスト変換し て、String型として入れたりとかしてたが・・・・
なぜProto Datastore? 冷静に考えて、 Proto Datastoreが カスタムデータ扱えるんだから、 そちら使うよね
導入が意外に面倒
導入が意外に面倒
導入が意外に面倒
導入が意外に面倒
導入が意外に面倒 はい! ここまで全部指示に従っても ビルドが通りません 😈
導入が意外に面倒 別にProtocol Bufferの 導入とビルド設定が必要 詳しくはCodelab参照
暗号化ないやん
暗号化ないやん EncryptedSharedPreferenceの 代替は用意されていない
暗号化ないやん • センシティブなデータはやはり暗号化しておきたい • 自分で暗号化機構を作る必要がある。 • tink-javaを利用して、暗号化ヘルパーを作ることが 可能
結論 class AeadEncryptionHelper(context: Context) { private val aead by lazy
{ AeadConfig.register() AndroidKeysetManager.Builder() .withSharedPref( context, KEY_SET_NAME, KEY_SET_FILE_NAME ) .withKeyTemplate(KeyTemplates.get( "AES256_GCM")) .withMasterKeyUri( KEY_SET_MASTER_URI ) .build() .keysetHandle .getPrimitive(Aead:: class.java) } fun encrypt(plaintext: String): ByteArray { return aead.encrypt(plaintext. toByteArray(), null) } fun decrypt(encryptedText: ByteArray): String { return String(aead.decrypt(encryptedText, null)) } private companion object { const val KEY_SET_NAME = "{key_set_name}" const val KEY_SET_FILE_NAME = "{key_set_file_name}" const val KEY_SET_MASTER_URI = " 適当な://名前" } } • 作成した暗号化クラス • ポイントは AndroidKeySetManag erの作成部分
結論 class AeadEncryptionHelper(context: Context) { private val aead by lazy
{ AeadConfig.register() AndroidKeysetManager.Builder() .withSharedPref( context, KEY_SET_NAME, KEY_SET_FILE_NAME ) .withKeyTemplate(KeyTemplates.get( "AES256_GCM")) .withMasterKeyUri( KEY_SET_MASTER_URI ) .build() .keysetHandle .getPrimitive(Aead:: class.java) } fun encrypt(plaintext: String): ByteArray { return aead.encrypt(plaintext. toByteArray(), null) } fun decrypt(encryptedText: ByteArray): String { return String(aead.decrypt(encryptedText, null)) } private companion object { const val KEY_SET_NAME = "{key_set_name}" const val KEY_SET_FILE_NAME = "{key_set_file_name}" const val KEY_SET_MASTER_URI = " 適当な://名前" } } • ポイントは AndroidKeySetManag erの作成部分 • KEY_SETの名前系の設 定を端折ると、アプリを 立ち上げ直すたびに複合 が不可能になる。
結論
結論 Proto Datastoreは便利だけど 完全に代替にはならない
結論 • 事前に導入のための時間をちゃんと取らないと、必要 以上に開発に時間がかかる。 • 暗号化の機構がない
Reference
Reference • https://developer.android.com/topic/libraries/ architecture/datastore?hl=ja#proto-datastore
以上、ありがとうございました!