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 17 package com.android.systemui.volume 18 19 import android.app.PendingIntent 20 import android.app.PendingIntent.FLAG_IMMUTABLE 21 import android.app.PendingIntent.FLAG_UPDATE_CURRENT 22 import android.content.Context 23 import android.content.Intent 24 25 /** 26 * label: Notification action label text. intent: The Intent used to start Activity or Broadcast. 27 * isActivity: Defines if the pending intent should start an activity. Default is to broadcast 28 */ 29 data class CsdWarningAction( 30 val label: String? = null, 31 val intent: Intent? = null, 32 val isActivity: Boolean = false, 33 ) { toPendingIntentnull34 fun toPendingIntent(context: Context): PendingIntent? { 35 if (label == null || intent == null) { 36 return null 37 } 38 if (isActivity) { 39 return PendingIntent.getActivity( 40 context, 41 0, 42 intent, 43 PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE 44 ) 45 } 46 return PendingIntent.getBroadcast(context, 0, intent, FLAG_IMMUTABLE) 47 } 48 } 49