1 /* 2 * Copyright (C) 2018 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.wifi; 18 19 import android.app.Notification; 20 import android.app.PendingIntent; 21 import android.content.Intent; 22 import android.graphics.drawable.Icon; 23 24 import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; 25 import com.android.wifi.resources.R; 26 27 28 /** Factory for Wifi Wake notifications. */ 29 public class WakeupNotificationFactory { 30 31 public static final String ACTION_DISMISS_NOTIFICATION = 32 "com.android.server.wifi.wakeup.DISMISS_NOTIFICATION"; 33 public static final String ACTION_OPEN_WIFI_PREFERENCES = 34 "com.android.server.wifi.wakeup.OPEN_WIFI_PREFERENCES"; 35 public static final String ACTION_OPEN_WIFI_SETTINGS = 36 "com.android.server.wifi.wakeup.OPEN_WIFI_SETTINGS"; 37 public static final String ACTION_TURN_OFF_WIFI_WAKE = 38 "com.android.server.wifi.wakeup.TURN_OFF_WIFI_WAKE"; 39 40 /** Notification channel ID for onboarding messages. */ 41 public static final int ONBOARD_ID = SystemMessage.NOTE_WIFI_WAKE_ONBOARD; 42 43 private final WifiContext mContext; 44 private final FrameworkFacade mFrameworkFacade; 45 WakeupNotificationFactory(WifiContext context, FrameworkFacade frameworkFacade)46 WakeupNotificationFactory(WifiContext context, FrameworkFacade frameworkFacade) { 47 mContext = context; 48 mFrameworkFacade = frameworkFacade; 49 } 50 51 /** 52 * Creates a Wifi Wake onboarding notification. 53 */ createOnboardingNotification()54 public Notification createOnboardingNotification() { 55 CharSequence title = mContext.getText(R.string.wifi_wakeup_onboarding_title); 56 CharSequence content = mContext.getText(R.string.wifi_wakeup_onboarding_subtext); 57 CharSequence disableText = mContext.getText(R.string.wifi_wakeup_onboarding_action_disable); 58 int color = mContext.getResources() 59 .getColor(android.R.color.system_notification_accent_color, mContext.getTheme()); 60 61 final Notification.Action disableAction = new Notification.Action.Builder( 62 null /* icon */, disableText, getPrivateBroadcast(ACTION_TURN_OFF_WIFI_WAKE)) 63 .build(); 64 65 return mFrameworkFacade.makeNotificationBuilder(mContext, 66 WifiService.NOTIFICATION_NETWORK_STATUS) 67 .setSmallIcon(Icon.createWithResource(mContext.getWifiOverlayApkPkgName(), 68 R.drawable.ic_wifi_settings)) 69 .setTicker(title) 70 .setContentTitle(title) 71 .setContentText(content) 72 .setContentIntent(getPrivateBroadcast(ACTION_OPEN_WIFI_PREFERENCES)) 73 .setDeleteIntent(getPrivateBroadcast(ACTION_DISMISS_NOTIFICATION)) 74 .addAction(disableAction) 75 .setShowWhen(false) 76 .setLocalOnly(true) 77 .setColor(color) 78 .build(); 79 } 80 81 getPrivateBroadcast(String action)82 private PendingIntent getPrivateBroadcast(String action) { 83 Intent intent = new Intent(action).setPackage(mContext.getServiceWifiPackageName()); 84 return mFrameworkFacade.getBroadcast(mContext, 0, intent, 85 PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); 86 } 87 } 88