1 /* 2 * Copyright (C) 2022 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.server.nearby.fastpair.notification; 18 19 import android.app.Notification; 20 import android.content.Context; 21 import android.os.Bundle; 22 23 import com.android.internal.annotations.VisibleForTesting; 24 import com.android.nearby.halfsheet.R; 25 import com.android.server.nearby.fastpair.HalfSheetResources; 26 import com.android.server.nearby.fastpair.PackageUtils; 27 28 /** Wrapper class for Fast Pair specific logic for notification builder. */ 29 public class FastPairNotificationBuilder extends Notification.Builder { 30 31 @VisibleForTesting 32 static final String NOTIFICATION_OVERRIDE_NAME_EXTRA = "android.substName"; 33 final String mPackageName; 34 final Context mContext; 35 final HalfSheetResources mResources; 36 FastPairNotificationBuilder(Context context, String channelId)37 public FastPairNotificationBuilder(Context context, String channelId) { 38 super(context, channelId); 39 this.mContext = context; 40 this.mPackageName = PackageUtils.getHalfSheetApkPkgName(context); 41 this.mResources = new HalfSheetResources(context); 42 } 43 44 /** 45 * If the flag is enabled, all the devices notification should use "Devices" as the source name, 46 * and links/Apps uses "Nearby". If the flag is not enabled, all notifications use "Nearby" as 47 * source name. 48 */ setIsDevice(boolean isDevice)49 public FastPairNotificationBuilder setIsDevice(boolean isDevice) { 50 Bundle extras = new Bundle(); 51 String notificationOverrideName = 52 isDevice 53 ? mResources.get().getString(R.string.common_devices) 54 : mResources.get().getString(R.string.common_nearby_title); 55 extras.putString(NOTIFICATION_OVERRIDE_NAME_EXTRA, notificationOverrideName); 56 addExtras(extras); 57 return this; 58 } 59 60 /** Set the "ticker" text which is sent to accessibility services. */ setTickerForAccessibility(String tickerText)61 public FastPairNotificationBuilder setTickerForAccessibility(String tickerText) { 62 // On Lollipop and above, setTicker() tells Accessibility what to say about the notification 63 // (e.g. this is what gets announced when a HUN appears). 64 setTicker(tickerText); 65 return this; 66 } 67 } 68