1 /* 2 * Copyright (C) 2023 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.wear 18 19 import android.content.Intent 20 import android.os.Build 21 import android.os.Bundle 22 import android.util.Log 23 import android.view.LayoutInflater 24 import android.view.View 25 import android.view.ViewGroup 26 import androidx.annotation.RequiresApi 27 import androidx.compose.ui.platform.ComposeView 28 import androidx.fragment.app.Fragment 29 import androidx.lifecycle.ViewModelProvider 30 import com.android.permissioncontroller.PermissionControllerApplication 31 import com.android.permissioncontroller.permission.ui.ManagePermissionsActivity 32 import com.android.permissioncontroller.permission.ui.model.v31.PermissionUsageDetailsViewModel 33 import com.android.permissioncontroller.permission.ui.model.v31.PermissionUsageDetailsViewModel.PermissionUsageDetailsViewModelFactory 34 import com.android.permissioncontroller.permission.utils.KotlinUtils.is7DayToggleEnabled 35 36 /** 37 * This is a condensed version of 38 * [com.android.permissioncontroller.permission.ui.handheld.v31.PermissionUsageDetailsFragment], 39 * tailored for Wear. 40 */ 41 @RequiresApi(Build.VERSION_CODES.S) 42 class WearPermissionUsageDetailsFragment : Fragment() { onCreateViewnull43 override fun onCreateView( 44 inflater: LayoutInflater, 45 container: ViewGroup?, 46 savedInstanceState: Bundle? 47 ): View? { 48 val permissionGroup = 49 arguments?.getString(Intent.EXTRA_PERMISSION_GROUP_NAME) 50 ?: let { 51 Log.e(TAG, "No permission group was provided for PermissionDetailsFragment") 52 return null 53 } 54 val showSystem = 55 arguments?.getBoolean(ManagePermissionsActivity.EXTRA_SHOW_SYSTEM, false) ?: false 56 val show7Days = 57 arguments?.getBoolean(ManagePermissionsActivity.EXTRA_SHOW_7_DAYS, false) ?: false 58 59 val factory = 60 PermissionUsageDetailsViewModelFactory( 61 PermissionControllerApplication.get(), 62 this, 63 permissionGroup 64 ) 65 val viewModel = 66 ViewModelProvider(this, factory).get(PermissionUsageDetailsViewModel::class.java) 67 viewModel.updateShowSystemAppsToggle(showSystem) 68 viewModel.updateShow7DaysToggle(is7DayToggleEnabled() && show7Days) 69 70 return ComposeView(requireContext()).apply { 71 setContent { WearPermissionUsageDetailsScreen(permissionGroup, viewModel) } 72 } 73 } 74 75 companion object { 76 private const val TAG = "WearPermissionUsageDetails" 77 78 @JvmStatic newInstancenull79 fun newInstance( 80 groupName: String?, 81 showSystem: Boolean, 82 show7Days: Boolean 83 ): WearPermissionUsageDetailsFragment { 84 return WearPermissionUsageDetailsFragment().apply { 85 val arguments = 86 Bundle().apply { 87 if (groupName != null) { 88 putString(Intent.EXTRA_PERMISSION_GROUP_NAME, groupName) 89 } 90 putBoolean(ManagePermissionsActivity.EXTRA_SHOW_SYSTEM, showSystem) 91 putBoolean(ManagePermissionsActivity.EXTRA_SHOW_7_DAYS, show7Days) 92 } 93 setArguments(arguments) 94 } 95 } 96 } 97 } 98