1 /*
2 * Copyright (C) 2022 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.settings.spa.app
18
19 import android.os.UserManager
20 import androidx.compose.material3.Text
21 import androidx.compose.runtime.Composable
22 import androidx.compose.runtime.getValue
23 import androidx.compose.runtime.remember
24 import androidx.compose.ui.platform.LocalContext
25 import androidx.compose.ui.res.stringResource
26 import androidx.lifecycle.compose.collectAsStateWithLifecycle
27 import com.android.settings.R
28 import com.android.settings.applications.manageapplications.ResetAppsHelper
29 import com.android.settings.network.telephony.CallStateRepository
30 import com.android.settingslib.spa.widget.dialog.AlertDialogButton
31 import com.android.settingslib.spa.widget.dialog.AlertDialogPresenter
32 import com.android.settingslib.spa.widget.dialog.rememberAlertDialogPresenter
33 import com.android.settingslib.spa.widget.scaffold.MoreOptionsScope
34 import com.android.settingslib.spaprivileged.model.enterprise.Restrictions
35 import com.android.settingslib.spaprivileged.template.scaffold.RestrictedMenuItem
36
37 @Composable
MoreOptionsScopenull38 fun MoreOptionsScope.ResetAppPreferences(onClick: () -> Unit) {
39 RestrictedMenuItem(
40 text = stringResource(R.string.reset_app_preferences),
41 restrictions = Restrictions(keys = listOf(UserManager.DISALLOW_APPS_CONTROL)),
42 onClick = onClick,
43 )
44 }
45
46 @Composable
rememberResetAppDialogPresenternull47 fun rememberResetAppDialogPresenter(): AlertDialogPresenter {
48 val context = LocalContext.current
49 // Reset app preference will dismiss all the notification, disable "Reset app preference" during
50 // call so in call notification not get dismissed.
51 val isInCall by remember { CallStateRepository(context).isInCallFlow() }
52 .collectAsStateWithLifecycle(initialValue = false)
53 return rememberAlertDialogPresenter(
54 confirmButton = AlertDialogButton(
55 text = stringResource(R.string.reset_app_preferences_button),
56 enabled = !isInCall,
57 ) {
58 ResetAppsHelper(context).resetApps()
59 },
60 dismissButton = AlertDialogButton(stringResource(R.string.cancel)),
61 title = stringResource(R.string.reset_app_preferences_title),
62 text = { Text(stringResource(R.string.reset_app_preferences_desc)) },
63 )
64 }
65