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