1 /* 2 * Copyright (C) 2020 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.NotificationManager; 21 import android.app.PendingIntent; 22 import android.content.Intent; 23 import android.graphics.drawable.Icon; 24 import android.net.wifi.WifiConfiguration; 25 import android.provider.Settings; 26 27 import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; 28 import com.android.wifi.resources.R; 29 /** 30 * Helper class to generate SIM required notification 31 * 32 */ 33 public class SimRequiredNotifier { 34 35 private final WifiContext mContext; 36 private final FrameworkFacade mFrameworkFacade; 37 private final NotificationManager mNotificationManager; 38 SimRequiredNotifier(WifiContext context, FrameworkFacade framework)39 public SimRequiredNotifier(WifiContext context, FrameworkFacade framework) { 40 mContext = context; 41 mFrameworkFacade = framework; 42 mNotificationManager = 43 mContext.getSystemService(NotificationManager.class); 44 } 45 46 /** 47 * Show notification 48 */ showSimRequiredNotification(WifiConfiguration config, String carrier)49 public void showSimRequiredNotification(WifiConfiguration config, String carrier) { 50 String name; 51 if (config.isPasspoint()) { 52 name = config.providerFriendlyName; 53 } else { 54 name = config.SSID; 55 } 56 mNotificationManager.notify(SystemMessage.NOTE_ID_WIFI_SIM_REQUIRED, 57 buildSimRequiredNotification(name, carrier)); 58 } 59 60 /** 61 * Dismiss notification 62 */ dismissSimRequiredNotification()63 public void dismissSimRequiredNotification() { 64 mNotificationManager.cancel(null, SystemMessage.NOTE_ID_WIFI_SIM_REQUIRED); 65 } 66 buildSimRequiredNotification(String ssid, String carrier)67 private Notification buildSimRequiredNotification(String ssid, String carrier) { 68 String title = mContext.getResources().getString( 69 R.string.wifi_sim_required_title); 70 String message = mContext.getResources().getString( 71 R.string.wifi_sim_required_message, 72 (ssid == null ? "" : ssid), 73 (carrier == null ? "" : carrier)); 74 75 return mFrameworkFacade.makeNotificationBuilder(mContext, 76 WifiService.NOTIFICATION_NETWORK_ALERTS) 77 .setAutoCancel(true) 78 .setShowWhen(false) 79 .setLocalOnly(true) 80 .setColor(mContext.getResources().getColor( 81 android.R.color.system_notification_accent_color, mContext.getTheme())) 82 .setContentTitle(title) 83 .setTicker(title) 84 .setContentText(message) 85 .setStyle(new Notification.BigTextStyle().bigText(message)) 86 .setSmallIcon(Icon.createWithResource(mContext.getWifiOverlayApkPkgName(), 87 R.drawable.stat_notify_wifi_in_range)) 88 .setContentIntent(launchWirelessSettings()) 89 .build(); 90 } 91 launchWirelessSettings()92 private PendingIntent launchWirelessSettings() { 93 Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS) 94 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 95 return mFrameworkFacade.getActivity(mContext, 0, intent, 96 PendingIntent.FLAG_UPDATE_CURRENT); 97 } 98 } 99