blob: 5e5744003331ff41e22d0dcdcd15509676b3ebf5 [file] [log] [blame]
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -08001/*
2 * Copyright (C) 2021 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 */
16package com.android.permissioncontroller.permission.ui.auto
17
18import android.app.Application
19import android.content.Context
20import android.os.Bundle
21import android.os.UserHandle
22import androidx.preference.Preference
23import com.android.permissioncontroller.R
24import com.android.permissioncontroller.auto.AutoSettingsFrameFragment
Kevin Hanb2414c32021-03-09 00:34:15 -080025import com.android.permissioncontroller.hibernation.isHibernationEnabled
Kevin Hane76098b2021-03-04 18:36:55 -080026import com.android.permissioncontroller.permission.ui.UnusedAppsFragment
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080027
28/**
Kevin Hane76098b2021-03-04 18:36:55 -080029 * Auto wrapper, with customizations, around [UnusedAppsFragment].
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080030 */
Kevin Hane76098b2021-03-04 18:36:55 -080031class AutoUnusedAppsFragment : AutoSettingsFrameFragment(),
32 UnusedAppsFragment.Parent<AutoUnusedAppsPreference> {
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080033
34 companion object {
35 /** Create a new instance of this fragment. */
36 @JvmStatic
Kevin Hane76098b2021-03-04 18:36:55 -080037 fun newInstance(): AutoUnusedAppsFragment {
38 return AutoUnusedAppsFragment()
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080039 }
40 }
41
42 override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
Kevin Hane76098b2021-03-04 18:36:55 -080043 // Preferences will be added via shared logic in [UnusedAppsFragment].
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080044 }
45
46 override fun onActivityCreated(savedInstanceState: Bundle?) {
47 super.onActivityCreated(savedInstanceState)
48 if (savedInstanceState == null) {
49 val fragment:
Kevin Hane76098b2021-03-04 18:36:55 -080050 UnusedAppsFragment<AutoUnusedAppsFragment, AutoUnusedAppsPreference> =
51 UnusedAppsFragment.newInstance()
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080052 fragment.arguments = arguments
53 // child fragment does not have its own UI - it will add to the preferences of this
54 // parent fragment
55 childFragmentManager.beginTransaction()
56 .add(fragment, null)
57 .commit()
58 }
59 }
60
61 override fun createFooterPreference(context: Context): Preference {
62 val preference = Preference(context)
Kevin Hanb2414c32021-03-09 00:34:15 -080063 if (isHibernationEnabled()) {
64 preference.summary = getString(R.string.unused_apps_page_summary)
65 } else {
66 preference.summary = """
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080067 ${getString(R.string.auto_revoked_apps_page_summary)}
68 ${getString(R.string.auto_revoke_open_app_message)}
69 """.trimIndent()
Kevin Hanb2414c32021-03-09 00:34:15 -080070 }
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080071 preference.setIcon(R.drawable.ic_info_outline)
72 preference.isSelectable = false
73 return preference
74 }
75
76 override fun setLoadingState(loading: Boolean, animate: Boolean) {
77 setLoading(false)
78 }
79
Kevin Hane76098b2021-03-04 18:36:55 -080080 override fun createUnusedAppPref(
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080081 app: Application,
82 packageName: String,
83 user: UserHandle,
84 context: Context
Kevin Hane76098b2021-03-04 18:36:55 -080085 ): AutoUnusedAppsPreference {
86 return AutoUnusedAppsPreference(app, packageName, user, context)
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080087 }
88
89 override fun setTitle(title: CharSequence) {
90 headerLabel = title
91 }
92}