Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61303024 authored by yyalan's avatar yyalan Committed by Ya-Lan Yiue
Browse files

Backup & restore OOBE scheduler

Backup the DataStore file using AbsoluteFileBackupHelper

Test: manually with LocalTransport (see comment)
Flag: com.android.systemui.shared.new_touchpad_gestures_tutorial
Fixes: 373308024
Change-Id: I86f6bd4c2ef7c98431aea3163dbfbfa77074ece8
parent ec7b916a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.systemui.communal.data.backup.CommunalBackupUtils
import com.android.systemui.communal.domain.backup.CommunalPrefsBackupHelper
import com.android.systemui.controls.controller.AuxiliaryPersistenceWrapper
import com.android.systemui.controls.controller.ControlsFavoritePersistenceWrapper
import com.android.systemui.inputdevice.tutorial.domain.backup.TutorialSchedulerBackupHelper
import com.android.systemui.keyguard.domain.backup.KeyguardQuickAffordanceBackupHelper
import com.android.systemui.people.widget.PeopleBackupHelper
import com.android.systemui.qs.panels.domain.backup.QSPreferencesBackupHelper
@@ -63,6 +64,8 @@ open class BackupHelper : BackupAgentHelper() {
        private const val COMMUNAL_PREFS_BACKUP_KEY = "systemui.communal.shared_preferences"
        private const val COMMUNAL_STATE_BACKUP_KEY = "systemui.communal_state"
        private const val QS_PREFERENCES_BACKUP_KEY = "systemui.qs.shared_preferences"
        private const val INPUT_DEVICE_TUTORIAL_SCHEDULER_BACKUP_KEY =
            "systemui.inputdevice.tutorial_data_store"
        val controlsDataLock = Any()
        const val ACTION_RESTORE_FINISHED = "com.android.systemui.backup.RESTORE_FINISHED"
        const val PERMISSION_SELF = "com.android.systemui.permission.SELF"
@@ -86,6 +89,10 @@ open class BackupHelper : BackupAgentHelper() {
            QS_PREFERENCES_BACKUP_KEY,
            QSPreferencesBackupHelper(context = this, userId = userHandle.identifier),
        )
        addHelper(
            INPUT_DEVICE_TUTORIAL_SCHEDULER_BACKUP_KEY,
            TutorialSchedulerBackupHelper(context = applicationContext),
        )
        if (communalEnabled()) {
            addHelper(
                COMMUNAL_PREFS_BACKUP_KEY,
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.systemui.inputdevice.tutorial.domain.backup

import android.app.QueuedWork
import android.app.backup.AbsoluteFileBackupHelper
import android.app.backup.BackupDataOutput
import android.content.Context
import android.os.ParcelFileDescriptor
import androidx.datastore.preferences.preferencesDataStoreFile
import com.android.systemui.inputdevice.tutorial.data.repository.TutorialSchedulerRepository.Companion.DATASTORE_NAME

class TutorialSchedulerBackupHelper(context: Context) :
    AbsoluteFileBackupHelper(
        context,
        context.preferencesDataStoreFile(DATASTORE_NAME).absolutePath,
    ) {
    override fun performBackup(
        oldState: ParcelFileDescriptor?,
        data: BackupDataOutput?,
        newState: ParcelFileDescriptor?,
    ) {
        // Finish outstanding DataStore write
        QueuedWork.waitToFinish()

        super.performBackup(oldState, data, newState)
    }
}