/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.privacy import android.content.Context import android.content.Intent import android.content.pm.PackageItemInfo import android.content.pm.PackageManager import android.content.pm.PackageManager.NameNotFoundException import android.content.res.Resources.NotFoundException import android.graphics.drawable.Drawable import android.graphics.drawable.LayerDrawable import android.os.Bundle import android.text.TextUtils import android.util.Log import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button import android.widget.ImageView import android.widget.TextView import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import androidx.annotation.WorkerThread import androidx.core.view.ViewCompat import androidx.core.view.accessibility.AccessibilityNodeInfoCompat import com.android.settingslib.Utils import com.android.systemui.res.R import com.android.systemui.animation.ViewHierarchyAnimator import com.android.systemui.statusbar.phone.SystemUIDialog import com.android.systemui.util.maybeForceFullscreen import java.lang.ref.WeakReference import java.util.concurrent.atomic.AtomicBoolean /** * Dialog to show ongoing and recent app ops element. * * @param context A context to create the dialog * @param list list of elements to show in the dialog. The elements will show in the same order they * appear in the list * @param manageApp a callback to start an activity for a given package name, user id, and intent * @param closeApp a callback to close an app for a given package name, user id * @param openPrivacyDashboard a callback to open the privacy dashboard * @see PrivacyDialogControllerV2 */ class PrivacyDialogV2( context: Context, private val list: List, private val manageApp: (String, Int, Intent) -> Unit, private val closeApp: (String, Int) -> Unit, private val openPrivacyDashboard: () -> Unit ) : SystemUIDialog(context, R.style.Theme_PrivacyDialog) { private val dismissListeners = mutableListOf>() private val dismissed = AtomicBoolean(false) // Note: this will call the dialog create method during init private val decorViewLayoutListener = maybeForceFullscreen()?.component2() /** * Add a listener that will be called when the dialog is dismissed. * * If the dialog has already been dismissed, the listener will be called immediately, in the * same thread. */ fun addOnDismissListener(listener: OnDialogDismissed) { if (dismissed.get()) { listener.onDialogDismissed() } else { dismissListeners.add(WeakReference(listener)) } } override fun stop() { dismissed.set(true) val iterator = dismissListeners.iterator() while (iterator.hasNext()) { val el = iterator.next() iterator.remove() el.get()?.onDialogDismissed() } // Remove the layout change listener we may have added to the DecorView. if (decorViewLayoutListener != null) { window!!.decorView.removeOnLayoutChangeListener(decorViewLayoutListener) } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) window!!.setGravity(Gravity.CENTER) setTitle(R.string.privacy_dialog_title) setContentView(R.layout.privacy_dialog_v2) val closeButton = requireViewById