1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.screenshot.message 18 19 import android.content.Context 20 import javax.inject.Inject 21 22 /** 23 * An interfaces for the settings related to the profile first run experience, storing a bit 24 * indicating whether the user has already dismissed the message for the given profile. 25 */ 26 interface ProfileFirstRunSettings { 27 /** @return true if the user has already dismissed the first run message for this profile. */ messageAlreadyDismissednull28 fun messageAlreadyDismissed(profileType: ProfileMessageController.FirstRunProfile): Boolean 29 /** 30 * Update storage to reflect the fact that the user has dismissed a first run message for the 31 * given profile. 32 */ 33 fun onMessageDismissed(profileType: ProfileMessageController.FirstRunProfile) 34 } 35 36 class ProfileFirstRunSettingsImpl @Inject constructor(private val context: Context) : 37 ProfileFirstRunSettings { 38 39 override fun messageAlreadyDismissed( 40 profileType: ProfileMessageController.FirstRunProfile 41 ): Boolean { 42 val preferenceKey = preferenceKey(profileType) 43 return sharedPreference().getBoolean(preferenceKey, false) 44 } 45 46 override fun onMessageDismissed(profileType: ProfileMessageController.FirstRunProfile) { 47 val preferenceKey = preferenceKey(profileType) 48 val editor = sharedPreference().edit() 49 editor.putBoolean(preferenceKey, true) 50 editor.apply() 51 } 52 53 private fun preferenceKey(profileType: ProfileMessageController.FirstRunProfile): String { 54 return when (profileType) { 55 ProfileMessageController.FirstRunProfile.WORK -> WORK_PREFERENCE_KEY 56 ProfileMessageController.FirstRunProfile.PRIVATE -> PRIVATE_PREFERENCE_KEY 57 } 58 } 59 60 private fun sharedPreference() = 61 context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) 62 63 companion object { 64 const val SHARED_PREFERENCES_NAME = "com.android.systemui.screenshot" 65 const val WORK_PREFERENCE_KEY = "work_profile_first_run" 66 const val PRIVATE_PREFERENCE_KEY = "private_profile_first_run" 67 } 68 } 69