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