diff options
| author | 2023-03-23 17:25:14 +0000 | |
|---|---|---|
| committer | 2023-03-23 17:25:14 +0000 | |
| commit | 70aba1b8a6547438cf97d3d020cda5c68f590b0c (patch) | |
| tree | d834e36821763c862bea64e2efc0bd7c52a508f3 /java/src | |
| parent | 9b0f802546a877164f38691c2c8f7e61feb1dbe2 (diff) | |
| parent | d600faec9328df33c867cfb64f0e8aa2c852bc0b (diff) | |
Merge "Adds a reciever for pin migration data" into udc-dev am: d600faec93
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/IntentResolver/+/22119004
Change-Id: Ie47702912cbc7a0dfafc02f0038e023ab9aee119
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'java/src')
| -rw-r--r-- | java/src/com/android/intentresolver/ChooserPinMigrationReceiver.kt | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/java/src/com/android/intentresolver/ChooserPinMigrationReceiver.kt b/java/src/com/android/intentresolver/ChooserPinMigrationReceiver.kt new file mode 100644 index 00000000..a3ba2192 --- /dev/null +++ b/java/src/com/android/intentresolver/ChooserPinMigrationReceiver.kt @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.intentresolver + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.util.Log + +/** + * Broadcast receiver for receiving Chooser pin data from the legacy chooser. + * + * Unions the legacy pins with any existing pins. This receiver is protected by the ADD_CHOOSER_PINS + * permission. The receiver is required to have the RECEIVE_CHOOSER_PIN_MIGRATION to receive the + * broadcast. + */ +class ChooserPinMigrationReceiver( + private val pinnedSharedPrefsProvider: (Context) -> SharedPreferences = + { context -> ChooserActivity.getPinnedSharedPrefs(context) }, +) : BroadcastReceiver() { + + override fun onReceive(context: Context, intent: Intent) { + val bundle = intent.extras ?: return + Log.i(TAG, "Starting migration") + + val prefsEditor = pinnedSharedPrefsProvider.invoke(context).edit() + bundle.keySet().forEach { key -> + if(bundle.getBoolean(key)) { + prefsEditor.putBoolean(key, true) + } + } + prefsEditor.apply() + + Log.i(TAG, "Migration complete") + } + + companion object { + private const val TAG = "ChooserPinMigrationReceiver" + } +}
\ No newline at end of file |