blob: 2a62d22f25ab2fabebc14bcb9dd0cc2849c1f0da [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 Jozwiak259693b2021-07-01 17:16:38 -070027import com.android.car.ui.utils.ViewUtils
28import com.android.car.ui.utils.ViewUtils.LazyLayoutView
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080029
30/**
Kevin Hane76098b2021-03-04 18:36:55 -080031 * Auto wrapper, with customizations, around [UnusedAppsFragment].
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080032 */
Kevin Hane76098b2021-03-04 18:36:55 -080033class AutoUnusedAppsFragment : AutoSettingsFrameFragment(),
34 UnusedAppsFragment.Parent<AutoUnusedAppsPreference> {
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080035
36 companion object {
37 /** Create a new instance of this fragment. */
38 @JvmStatic
Kevin Hane76098b2021-03-04 18:36:55 -080039 fun newInstance(): AutoUnusedAppsFragment {
40 return AutoUnusedAppsFragment()
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080041 }
42 }
43
44 override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
Kevin Hane76098b2021-03-04 18:36:55 -080045 // Preferences will be added via shared logic in [UnusedAppsFragment].
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080046 }
47
48 override fun onActivityCreated(savedInstanceState: Bundle?) {
49 super.onActivityCreated(savedInstanceState)
50 if (savedInstanceState == null) {
51 val fragment:
Kevin Hane76098b2021-03-04 18:36:55 -080052 UnusedAppsFragment<AutoUnusedAppsFragment, AutoUnusedAppsPreference> =
53 UnusedAppsFragment.newInstance()
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080054 fragment.arguments = arguments
55 // child fragment does not have its own UI - it will add to the preferences of this
56 // parent fragment
57 childFragmentManager.beginTransaction()
58 .add(fragment, null)
59 .commit()
60 }
Jordan Jozwiak259693b2021-07-01 17:16:38 -070061
62 // initially focus on focus parking view and then shift focus to recyclerview once it has
63 // loaded
64 ViewUtils.hideFocus(getListView().getRootView())
65 val lazyLayoutView = getListView() as LazyLayoutView
66 ViewUtils.initFocus(lazyLayoutView)
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080067 }
68
69 override fun createFooterPreference(context: Context): Preference {
70 val preference = Preference(context)
Kevin Hanb2414c32021-03-09 00:34:15 -080071 if (isHibernationEnabled()) {
72 preference.summary = getString(R.string.unused_apps_page_summary)
73 } else {
74 preference.summary = """
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080075 ${getString(R.string.auto_revoked_apps_page_summary)}
76 ${getString(R.string.auto_revoke_open_app_message)}
77 """.trimIndent()
Kevin Hanb2414c32021-03-09 00:34:15 -080078 }
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080079 preference.setIcon(R.drawable.ic_info_outline)
80 preference.isSelectable = false
81 return preference
82 }
83
84 override fun setLoadingState(loading: Boolean, animate: Boolean) {
85 setLoading(false)
86 }
87
Kevin Hane76098b2021-03-04 18:36:55 -080088 override fun createUnusedAppPref(
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080089 app: Application,
90 packageName: String,
91 user: UserHandle,
92 context: Context
Kevin Hane76098b2021-03-04 18:36:55 -080093 ): AutoUnusedAppsPreference {
94 return AutoUnusedAppsPreference(app, packageName, user, context)
Jordan Jozwiak8c41ccc2021-02-09 15:34:02 -080095 }
96
97 override fun setTitle(title: CharSequence) {
98 headerLabel = title
99 }
100}