1 /* 2 * Copyright (C) 2019 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.plugins; 18 19 import android.annotation.Nullable; 20 import android.app.PendingIntent; 21 import android.graphics.drawable.Drawable; 22 import android.service.notification.StatusBarNotification; 23 24 import com.android.systemui.plugins.annotations.DependsOn; 25 import com.android.systemui.plugins.annotations.ProvidesInterface; 26 27 /** Custom logic that can extract a PeopleHub "person" from a notification. */ 28 @ProvidesInterface( 29 action = NotificationPersonExtractorPlugin.ACTION, 30 version = NotificationPersonExtractorPlugin.VERSION) 31 @DependsOn(target = NotificationPersonExtractorPlugin.PersonData.class) 32 public interface NotificationPersonExtractorPlugin extends Plugin { 33 34 String ACTION = "com.android.systemui.action.PEOPLE_HUB_PERSON_EXTRACTOR"; 35 int VERSION = 1; 36 37 /** 38 * Attempts to extract a person from a notification. Returns {@code null} if one is not found. 39 */ 40 @Nullable extractPerson(StatusBarNotification sbn)41 PersonData extractPerson(StatusBarNotification sbn); 42 43 /** 44 * Attempts to extract a person id from a notification. Returns {@code null} if one is not 45 * found. 46 * 47 * This method can be overridden in order to provide a faster implementation. 48 */ 49 @Nullable extractPersonKey(StatusBarNotification sbn)50 default String extractPersonKey(StatusBarNotification sbn) { 51 return extractPerson(sbn).key; 52 } 53 54 /** 55 * Determines whether or not a notification should be treated as having a person. Used for 56 * appropriate positioning in the notification shade. 57 */ isPersonNotification(StatusBarNotification sbn)58 default boolean isPersonNotification(StatusBarNotification sbn) { 59 return extractPersonKey(sbn) != null; 60 } 61 62 /** A person to be surfaced in PeopleHub. */ 63 @ProvidesInterface(version = PersonData.VERSION) 64 final class PersonData { 65 66 public static final int VERSION = 0; 67 68 public final String key; 69 public final CharSequence name; 70 public final Drawable avatar; 71 public final Runnable clickRunnable; 72 PersonData(String key, CharSequence name, Drawable avatar, Runnable clickRunnable)73 public PersonData(String key, CharSequence name, Drawable avatar, 74 Runnable clickRunnable) { 75 this.key = key; 76 this.name = name; 77 this.avatar = avatar; 78 this.clickRunnable = clickRunnable; 79 } 80 } 81 } 82