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
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
74
Not 2 L8 JKでもわかるMaterial 3
bigbackboom
0
62
JKでもわかるSFace Recognition
bigbackboom
0
81
Androidタブレットアプリ作成_棚から牡丹餅を得るにはまず棚から
bigbackboom
0
70
Extended A Study in Bitmap: Is NDK the fast Processing method by CPU?
bigbackboom
0
34
Have A Dog in CircleCI
bigbackboom
0
93
Androidエンジニアのお仕事でのショボーン
bigbackboom
0
96
解明!楽しいプレゼンする話すスキル
bigbackboom
0
130
Pay for Businessのgradle.ktsへの移行の小噺
bigbackboom
0
88
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
890
Scaling GitHub
holman
464
140k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
410
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
490
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
Navigating Team Friction
lara
192
16k
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
以上、ありがとうございました!