1 /*
<lambda>null2  * 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
18 
19 import android.content.Context
20 import android.content.Intent
21 import android.util.FeatureFlagUtils
22 import com.android.settings.applications.appinfo.AlarmsAndRemindersDetails
23 import com.android.settings.applications.appinfo.DrawOverlayDetails
24 import com.android.settings.applications.appinfo.ExternalSourcesDetails
25 import com.android.settings.applications.appinfo.ManageExternalStorageDetails
26 import com.android.settings.applications.appinfo.MediaManagementAppsDetails
27 import com.android.settings.applications.appinfo.WriteSettingsDetails
28 import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureDetails
29 import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureSettings
30 import com.android.settings.spa.SpaActivity.Companion.startSpaActivity
31 import com.android.settings.spa.SpaAppBridgeActivity.Companion.getDestinationForApp
32 import com.android.settings.spa.app.specialaccess.AlarmsAndRemindersAppListProvider
33 import com.android.settings.spa.app.specialaccess.AllFilesAccessAppListProvider
34 import com.android.settings.spa.app.specialaccess.DisplayOverOtherAppsAppListProvider
35 import com.android.settings.spa.app.specialaccess.InstallUnknownAppsListProvider
36 import com.android.settings.spa.app.specialaccess.MediaManagementAppsAppListProvider
37 import com.android.settings.spa.app.specialaccess.ModifySystemSettingsAppListProvider
38 import com.android.settings.spa.app.specialaccess.NfcTagAppsSettingsProvider
39 import com.android.settings.spa.app.specialaccess.PictureInPictureListProvider
40 import com.android.settings.spa.app.specialaccess.WifiControlAppListProvider
41 import com.android.settings.wifi.ChangeWifiStateDetails
42 
43 object SettingsActivityUtil {
44     private val FRAGMENT_TO_SPA_DESTINATION_MAP = mapOf(
45         PictureInPictureSettings::class.qualifiedName to
46             PictureInPictureListProvider.getAppListRoute(),
47     )
48 
49     private val FRAGMENT_TO_SPA_APP_DESTINATION_PREFIX_MAP = mapOf(
50         PictureInPictureDetails::class.qualifiedName to
51             PictureInPictureListProvider.getAppInfoRoutePrefix(),
52         DrawOverlayDetails::class.qualifiedName to
53             DisplayOverOtherAppsAppListProvider.getAppInfoRoutePrefix(),
54         WriteSettingsDetails::class.qualifiedName to
55             ModifySystemSettingsAppListProvider.getAppInfoRoutePrefix(),
56         AlarmsAndRemindersDetails::class.qualifiedName to
57             AlarmsAndRemindersAppListProvider.getAppInfoRoutePrefix(),
58         ExternalSourcesDetails::class.qualifiedName to
59             InstallUnknownAppsListProvider.getAppInfoRoutePrefix(),
60         ManageExternalStorageDetails::class.qualifiedName to
61             AllFilesAccessAppListProvider.getAppInfoRoutePrefix(),
62         MediaManagementAppsDetails::class.qualifiedName to
63             MediaManagementAppsAppListProvider.getAppInfoRoutePrefix(),
64         ChangeWifiStateDetails::class.qualifiedName to
65             WifiControlAppListProvider.getAppInfoRoutePrefix(),
66         NfcTagAppsSettingsProvider::class.qualifiedName to
67             NfcTagAppsSettingsProvider.getAppInfoRoutePrefix(),
68     )
69 
70     @JvmStatic
71     fun Context.launchSpaActivity(fragmentName: String, intent: Intent): Boolean {
72         if (FeatureFlagUtils.isEnabled(this, FeatureFlagUtils.SETTINGS_ENABLE_SPA)) {
73             getDestination(fragmentName, intent)?.let { destination ->
74                 startSpaActivity(destination)
75                 return true
76             }
77         }
78         return false
79     }
80 
81     private fun getDestination(fragmentName: String, intent: Intent): String? =
82         FRAGMENT_TO_SPA_DESTINATION_MAP[fragmentName]
83             ?: FRAGMENT_TO_SPA_APP_DESTINATION_PREFIX_MAP[fragmentName]?.let { destinationPrefix ->
84                 getDestinationForApp(destinationPrefix, intent)
85             }
86 }
87