1 /* 2 * Copyright (C) 2024 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.settings.deviceinfo.legal 17 18 import android.content.Context 19 import com.android.settings.R 20 import com.android.settingslib.metadata.PreferenceAvailabilityProvider 21 import com.android.settingslib.metadata.ProvidePreferenceScreen 22 import com.android.settingslib.metadata.preferenceHierarchy 23 import com.android.settingslib.preference.PreferenceScreenCreator 24 25 // LINT.IfChange 26 @ProvidePreferenceScreen(ModuleLicensesScreen.KEY) 27 class ModuleLicensesScreen : PreferenceScreenCreator, PreferenceAvailabilityProvider { 28 override val key: String 29 get() = KEY 30 31 override val title: Int 32 get() = R.string.module_license_title 33 34 // We need to avoid directly assign fragment attribute in the bind() API. So we need to create 35 // a screen and provide it to its parent screen LegalSettingsScreen. 36 // By the way, we also need to set the isFlagEnabled() as false. Let system render the legacy 37 // UI. The hierarchy will be added while migrating this page. isFlagEnablednull38 override fun isFlagEnabled(context: Context) = false 39 40 override fun fragmentClass() = ModuleLicensesDashboard::class.java 41 42 override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(context, this) {} 43 isAvailablenull44 override fun isAvailable(context: Context): Boolean { 45 val modules = context.packageManager.getInstalledModules(/* flags= */ 0) 46 return modules.any { 47 try { 48 ModuleLicenseProvider.getPackageAssetManager(context.packageManager, it.packageName) 49 .list("") 50 ?.contains(ModuleLicenseProvider.GZIPPED_LICENSE_FILE_NAME) == true 51 } catch (e: Exception) { 52 false 53 } 54 } 55 } 56 57 companion object { 58 const val KEY = "module_license" 59 } 60 } 61 // LINT.ThenChange(ModuleLicensesListPreferenceController.java) 62