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