Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 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 | package com.android.permissioncontroller.permission.ui.auto |
| 17 | |
| 18 | import android.app.Application |
| 19 | import android.content.Context |
| 20 | import android.os.Bundle |
| 21 | import android.os.UserHandle |
| 22 | import androidx.preference.Preference |
| 23 | import com.android.permissioncontroller.R |
| 24 | import com.android.permissioncontroller.auto.AutoSettingsFrameFragment |
Kevin Han | b2414c3 | 2021-03-09 00:34:15 -0800 | [diff] [blame] | 25 | import com.android.permissioncontroller.hibernation.isHibernationEnabled |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 26 | import com.android.permissioncontroller.permission.ui.UnusedAppsFragment |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 29 | * Auto wrapper, with customizations, around [UnusedAppsFragment]. |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 30 | */ |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 31 | class AutoUnusedAppsFragment : AutoSettingsFrameFragment(), |
| 32 | UnusedAppsFragment.Parent<AutoUnusedAppsPreference> { |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 33 | |
| 34 | companion object { |
| 35 | /** Create a new instance of this fragment. */ |
| 36 | @JvmStatic |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 37 | fun newInstance(): AutoUnusedAppsFragment { |
| 38 | return AutoUnusedAppsFragment() |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 43 | // Preferences will be added via shared logic in [UnusedAppsFragment]. |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | override fun onActivityCreated(savedInstanceState: Bundle?) { |
| 47 | super.onActivityCreated(savedInstanceState) |
| 48 | if (savedInstanceState == null) { |
| 49 | val fragment: |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 50 | UnusedAppsFragment<AutoUnusedAppsFragment, AutoUnusedAppsPreference> = |
| 51 | UnusedAppsFragment.newInstance() |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 52 | 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 Han | b2414c3 | 2021-03-09 00:34:15 -0800 | [diff] [blame] | 63 | if (isHibernationEnabled()) { |
| 64 | preference.summary = getString(R.string.unused_apps_page_summary) |
| 65 | } else { |
| 66 | preference.summary = """ |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 67 | ${getString(R.string.auto_revoked_apps_page_summary)} |
| 68 | ${getString(R.string.auto_revoke_open_app_message)} |
| 69 | """.trimIndent() |
Kevin Han | b2414c3 | 2021-03-09 00:34:15 -0800 | [diff] [blame] | 70 | } |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 71 | 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 Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 80 | override fun createUnusedAppPref( |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 81 | app: Application, |
| 82 | packageName: String, |
| 83 | user: UserHandle, |
| 84 | context: Context |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 85 | ): AutoUnusedAppsPreference { |
| 86 | return AutoUnusedAppsPreference(app, packageName, user, context) |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | override fun setTitle(title: CharSequence) { |
| 90 | headerLabel = title |
| 91 | } |
| 92 | } |