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 WifiInjector mWifiInjector; 45 private final FrameworkFacade mFrameworkFacade; 46 WakeupNotificationFactory(WifiContext context, WifiInjector wifiInjector, FrameworkFacade frameworkFacade)47 WakeupNotificationFactory(WifiContext context, WifiInjector wifiInjector, 48 FrameworkFacade frameworkFacade) { 49 mContext = context; 50 mWifiInjector = wifiInjector; 51 mFrameworkFacade = frameworkFacade; 52 } 53 54 /** 55 * Creates a Wifi Wake onboarding notification. 56 */ createOnboardingNotification()57 public Notification createOnboardingNotification() { 58 CharSequence title = mContext.getText(R.string.wifi_wakeup_onboarding_title); 59 CharSequence content = mContext.getText(R.string.wifi_wakeup_onboarding_subtext); 60 CharSequence disableText = mContext.getText(R.string.wifi_wakeup_onboarding_action_disable); 61 int color = mContext.getResources() 62 .getColor(android.R.color.system_notification_accent_color, mContext.getTheme()); 63 64 final Notification.Action disableAction = new Notification.Action.Builder( 65 null /* icon */, disableText, getPrivateBroadcast(ACTION_TURN_OFF_WIFI_WAKE)) 66 .build(); 67 68 return mFrameworkFacade.makeNotificationBuilder(mContext, 69 WifiService.NOTIFICATION_NETWORK_STATUS) 70 .setSmallIcon(Icon.createWithResource(mContext.getWifiOverlayApkPkgName(), 71 R.drawable.ic_wifi_settings)) 72 .setTicker(title) 73 .setContentTitle(title) 74 .setContentText(content) 75 .setContentIntent(getPrivateBroadcast(ACTION_OPEN_WIFI_PREFERENCES)) 76 .setDeleteIntent(getPrivateBroadcast(ACTION_DISMISS_NOTIFICATION)) 77 .addAction(disableAction) 78 .setShowWhen(false) 79 .setLocalOnly(true) 80 .setColor(color) 81 .build(); 82 } 83 84 getPrivateBroadcast(String action)85 private PendingIntent getPrivateBroadcast(String action) { 86 Intent intent = new Intent(action) 87 .setPackage(mWifiInjector.getWifiStackPackageName()); 88 return mFrameworkFacade.getBroadcast( 89 mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 90 } 91 } 92