• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
16 
17 package com.android.permissioncontroller.permission.ui.handheld
18 
19 import android.app.Application
20 import android.os.Bundle
21 import android.os.UserHandle
22 import android.view.MenuItem
23 import androidx.preference.Preference
24 import androidx.preference.PreferenceCategory
25 import com.android.permissioncontroller.R
26 import com.android.permissioncontroller.hibernation.isHibernationEnabled
27 import com.android.permissioncontroller.permission.ui.UnusedAppsFragment
28 import com.android.permissioncontroller.permission.ui.UnusedAppsFragment.Companion.INFO_MSG_CATEGORY
29 
30 /**
31  * Handheld wrapper, with customizations, around [UnusedAppsFragment].
32  */
33 class HandheldUnusedAppsFragment : PermissionsFrameFragment(),
34     UnusedAppsFragment.Parent<UnusedAppPreference> {
35 
36     companion object {
37         /** Create a new instance of this fragment.  */
38         @JvmStatic
newInstancenull39         fun newInstance(): HandheldUnusedAppsFragment {
40             return HandheldUnusedAppsFragment()
41         }
42     }
43 
onCreatenull44     override fun onCreate(savedInstanceState: Bundle?) {
45         super.onCreate(savedInstanceState)
46         setHasOptionsMenu(true)
47     }
48 
onStartnull49     override fun onStart() {
50         super.onStart()
51         mUseShadowController = false
52     }
53 
onActivityCreatednull54     override fun onActivityCreated(savedInstanceState: Bundle?) {
55         super.onActivityCreated(savedInstanceState)
56         if (savedInstanceState == null) {
57             val fragment:
58                 UnusedAppsFragment<HandheldUnusedAppsFragment, UnusedAppPreference> =
59                 UnusedAppsFragment.newInstance()
60             fragment.arguments = arguments
61             // child fragment does not have its own UI - it will add to the preferences of this
62             // parent fragment
63             childFragmentManager.beginTransaction()
64                 .add(fragment, null)
65                 .commit()
66         }
67     }
68 
onOptionsItemSelectednull69     override fun onOptionsItemSelected(item: MenuItem): Boolean {
70         if (item.itemId == android.R.id.home) {
71             this.pressBack()
72             return true
73         }
74         return super.onOptionsItemSelected(item)
75     }
76 
getEmptyViewStringnull77     override fun getEmptyViewString(): Int {
78         return if (isHibernationEnabled()) R.string.no_unused_apps else super.getEmptyViewString()
79     }
80 
createFooterPreferencenull81     override fun createFooterPreference(): Preference {
82         var preference: Preference
83         if (isHibernationEnabled()) {
84             preference = com.android.settingslib.widget.FooterPreference(requireContext())
85             preference.summary = getString(R.string.unused_apps_page_summary)
86         } else {
87             preference = FooterPreference(requireContext())
88 
89             preference.summary = getString(R.string.auto_revoked_apps_page_summary)
90             preference.secondSummary = getString(R.string.auto_revoke_open_app_message)
91         }
92         preference.setIcon(R.drawable.ic_info_outline)
93         preference.isSelectable = false
94         return preference
95     }
96 
setLoadingStatenull97     override fun setLoadingState(loading: Boolean, animate: Boolean) {
98         setLoading(loading, animate)
99     }
100 
createUnusedAppPrefnull101     override fun createUnusedAppPref(
102         app: Application,
103         packageName: String,
104         user: UserHandle
105     ): UnusedAppPreference {
106         return UnusedAppPreference(app, packageName, user, requireContext())
107     }
108 
setTitlenull109     override fun setTitle(title: CharSequence) {
110         requireActivity().setTitle(title)
111     }
112 
setEmptyStatenull113     override fun setEmptyState(empty: Boolean) {
114         val infoMsgCategory =
115                 preferenceScreen.findPreference<PreferenceCategory>(INFO_MSG_CATEGORY)!!
116         infoMsgCategory.isVisible = !empty
117     }
118 }