• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.annotation.NonNull;
20 import android.app.Notification;
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.net.wifi.WifiContext;
26 
27 import com.android.wifi.resources.R;
28 
29 /**
30  * Helper class for ConnectionFailureNotifier.
31  */
32 public class ConnectionFailureNotificationBuilder {
33     private static final String TAG = "ConnectionFailureNotifier";
34 
35     public static final String ACTION_SHOW_SET_RANDOMIZATION_DETAILS =
36             "com.android.server.wifi.ACTION_SHOW_SET_RANDOMIZATION_DETAILS";
37     public static final String RANDOMIZATION_SETTINGS_NETWORK_ID =
38             "com.android.server.wifi.RANDOMIZATION_SETTINGS_NETWORK_ID";
39     public static final String RANDOMIZATION_SETTINGS_NETWORK_SSID =
40             "com.android.server.wifi.RANDOMIZATION_SETTINGS_NETWORK_SSID";
41 
42     private final WifiContext mContext;
43     private final FrameworkFacade mFrameworkFacade;
44 
ConnectionFailureNotificationBuilder(WifiContext context, FrameworkFacade framework)45     public ConnectionFailureNotificationBuilder(WifiContext context,
46             FrameworkFacade framework) {
47         mContext = context;
48         mFrameworkFacade = framework;
49     }
50 
51     /**
52      * Creates a notification that alerts the user that the connection may be failing due to
53      * MAC randomization.
54      * @param config
55      */
buildNoMacRandomizationSupportNotification( @onNull WifiConfiguration config)56     public Notification buildNoMacRandomizationSupportNotification(
57             @NonNull WifiConfiguration config) {
58         String ssid = config.SSID;
59         String ssidAndSecurityType = config.getSsidAndSecurityTypeString();
60         String title = mContext.getResources().getString(
61                 R.string.wifi_cannot_connect_with_randomized_mac_title, ssid);
62         String content = mContext.getResources().getString(
63                 R.string.wifi_cannot_connect_with_randomized_mac_message);
64 
65         Intent showDetailIntent = new Intent(ACTION_SHOW_SET_RANDOMIZATION_DETAILS)
66                 .setPackage(mContext.getServiceWifiPackageName());
67         showDetailIntent.putExtra(RANDOMIZATION_SETTINGS_NETWORK_ID, config.networkId);
68         showDetailIntent.putExtra(RANDOMIZATION_SETTINGS_NETWORK_SSID, ssidAndSecurityType);
69         PendingIntent pendingShowDetailIntent = mFrameworkFacade.getBroadcast(
70                 mContext, 0, showDetailIntent,
71                 PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
72 
73         return mFrameworkFacade.makeNotificationBuilder(
74                 mContext, WifiService.NOTIFICATION_NETWORK_ALERTS)
75                 .setSmallIcon(Icon.createWithResource(mContext.getWifiOverlayApkPkgName(),
76                         com.android.wifi.resources.R.drawable.stat_notify_wifi_in_range))
77                 .setTicker(title)
78                 .setContentTitle(title)
79                 .setContentText(content)
80                 .setContentIntent(pendingShowDetailIntent)
81                 .setShowWhen(false)
82                 .setLocalOnly(true)
83                 .setColor(mContext.getResources().getColor(
84                         android.R.color.system_notification_accent_color, mContext.getTheme()))
85                 .setAutoCancel(true)
86                 .build();
87     }
88 }
89