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 | 259693b | 2021-07-01 17:16:38 -0700 | [diff] [blame] | 27 | import com.android.car.ui.utils.ViewUtils |
| 28 | import com.android.car.ui.utils.ViewUtils.LazyLayoutView |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 31 | * Auto wrapper, with customizations, around [UnusedAppsFragment]. |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 32 | */ |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 33 | class AutoUnusedAppsFragment : AutoSettingsFrameFragment(), |
| 34 | UnusedAppsFragment.Parent<AutoUnusedAppsPreference> { |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 35 | |
| 36 | companion object { |
| 37 | /** Create a new instance of this fragment. */ |
| 38 | @JvmStatic |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 39 | fun newInstance(): AutoUnusedAppsFragment { |
| 40 | return AutoUnusedAppsFragment() |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 45 | // Preferences will be added via shared logic in [UnusedAppsFragment]. |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | override fun onActivityCreated(savedInstanceState: Bundle?) { |
| 49 | super.onActivityCreated(savedInstanceState) |
| 50 | if (savedInstanceState == null) { |
| 51 | val fragment: |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 52 | UnusedAppsFragment<AutoUnusedAppsFragment, AutoUnusedAppsPreference> = |
| 53 | UnusedAppsFragment.newInstance() |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 54 | 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 Jozwiak | 259693b | 2021-07-01 17:16:38 -0700 | [diff] [blame] | 61 | |
| 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 Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | override fun createFooterPreference(context: Context): Preference { |
| 70 | val preference = Preference(context) |
Kevin Han | b2414c3 | 2021-03-09 00:34:15 -0800 | [diff] [blame] | 71 | if (isHibernationEnabled()) { |
| 72 | preference.summary = getString(R.string.unused_apps_page_summary) |
| 73 | } else { |
| 74 | preference.summary = """ |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 75 | ${getString(R.string.auto_revoked_apps_page_summary)} |
| 76 | ${getString(R.string.auto_revoke_open_app_message)} |
| 77 | """.trimIndent() |
Kevin Han | b2414c3 | 2021-03-09 00:34:15 -0800 | [diff] [blame] | 78 | } |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 79 | 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 Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 88 | override fun createUnusedAppPref( |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 89 | app: Application, |
| 90 | packageName: String, |
| 91 | user: UserHandle, |
| 92 | context: Context |
Kevin Han | e76098b | 2021-03-04 18:36:55 -0800 | [diff] [blame] | 93 | ): AutoUnusedAppsPreference { |
| 94 | return AutoUnusedAppsPreference(app, packageName, user, context) |
Jordan Jozwiak | 8c41ccc | 2021-02-09 15:34:02 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | override fun setTitle(title: CharSequence) { |
| 98 | headerLabel = title |
| 99 | } |
| 100 | } |