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.settings 18 19 import android.app.Activity 20 import android.os.Bundle 21 import android.view.Gravity 22 import android.widget.ImageView 23 import android.widget.TextView 24 import androidx.appcompat.app.AlertDialog 25 import com.android.settings.deviceinfo.regulatory.RegulatoryInfo.getRegulatoryInfo 26 import com.android.settings.overlay.FeatureFactory.Companion.featureFactory 27 28 /** 29 * [Activity] that displays regulatory information for the "Regulatory information" 30 * preference item, and when "*#07#" is dialed on the Phone keypad. To enable this feature, 31 * set the "config_show_regulatory_info" boolean to true in a device overlay resource, and in the 32 * same overlay, either add a drawable named "regulatory_info.png" containing a graphical version 33 * of the required regulatory info (If ro.bootloader.hardware.sku property is set use 34 * "regulatory_info_<sku>.png where sku is ro.bootloader.hardware.sku property value in lowercase"), 35 * or add a string resource named "regulatory_info_text" with an HTML version of the required 36 * information (text will be centered in the dialog). 37 */ 38 class RegulatoryInfoDisplayActivity : Activity() { 39 40 /** Display the regulatory info graphic in a dialog window. */ onCreatenull41 override fun onCreate(savedInstanceState: Bundle?) { 42 super.onCreate(savedInstanceState) 43 val builder = AlertDialog.Builder(this) 44 .setTitle(R.string.regulatory_labels) 45 .setOnDismissListener { finish() } // close the activity 46 .setPositiveButton(android.R.string.ok, null) 47 48 getRegulatoryInfo()?.let { 49 val view = layoutInflater.inflate(R.layout.regulatory_info, null) 50 val image = view.requireViewById<ImageView>(R.id.regulatoryInfo) 51 image.setImageDrawable(it) 52 builder.setView(view) 53 builder.show() 54 return 55 } 56 57 val regulatoryText = getRegulatoryText() 58 if (!regulatoryText.isNullOrEmpty()) { 59 builder.setMessage(regulatoryText) 60 val dialog = builder.show() 61 // we have to show the dialog first, or the setGravity() call will throw a NPE 62 dialog.findViewById<TextView>(android.R.id.message)?.gravity = Gravity.CENTER 63 } else { 64 // neither drawable nor text resource exists, finish activity 65 finish() 66 } 67 } 68 getRegulatoryTextnull69 private fun getRegulatoryText(): CharSequence? { 70 val regulatoryInfoText = resources.getText(R.string.regulatory_info_text) 71 if (regulatoryInfoText.isNotBlank()) return regulatoryInfoText 72 return featureFactory.hardwareInfoFeatureProvider?.countryIfOriginLabel 73 } 74 } 75