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