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
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
95
解明!楽しいプレゼンする話すスキル
bigbackboom
0
130
Pay for Businessのgradle.ktsへの移行の小噺
bigbackboom
0
88
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
The Curse of the Amulet
leimatthew05
2
13k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Utilizing Notion as your number one productivity tool
mfonobong
4
330
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
210
The browser strikes back
jonoalderson
0
1.3k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Speed Design
sergeychernyshev
33
1.9k
Building the Perfect Custom Keyboard
takai
2
800
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
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
以上、ありがとうございました!