• 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.WifiContext;
24 
25 import com.android.internal.annotations.VisibleForTesting;
26 import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
27 import com.android.wifi.resources.R;
28 
29 /**
30  * Helper class for SoftApManager to generator notification.
31  */
32 public class SoftApNotifier {
33     private static final String TAG = "SoftApNotifier";
34 
35     @VisibleForTesting
36     public static final String ACTION_HOTSPOT_PREFERENCES =
37             "com.android.settings.WIFI_TETHER_SETTINGS";
38 
39     @VisibleForTesting
40     public static final int NOTIFICATION_ID_SOFTAP_AUTO_DISABLED =
41             SystemMessage.NOTE_SOFTAP_AUTO_DISABLED;
42 
43     private final WifiContext mContext;
44     private final FrameworkFacade mFrameworkFacade;
45     private final WifiNotificationManager mNotificationManager;
46 
SoftApNotifier(WifiContext context, FrameworkFacade framework, WifiNotificationManager wifiNotificationManager)47     public SoftApNotifier(WifiContext context, FrameworkFacade framework,
48             WifiNotificationManager wifiNotificationManager) {
49         mContext = context;
50         mFrameworkFacade = framework;
51         mNotificationManager = wifiNotificationManager;
52     }
53 
54     /**
55      * Show notification to notify user softap disable because auto shutdown timeout expired.
56      */
showSoftApShutdownTimeoutExpiredNotification()57     public void showSoftApShutdownTimeoutExpiredNotification() {
58         mNotificationManager.notify(NOTIFICATION_ID_SOFTAP_AUTO_DISABLED,
59                 buildSoftApShutdownTimeoutExpiredNotification());
60     }
61 
62     /**
63      * Dismiss notification which used to notify user softap disable because auto shutdown
64      * timeout expired.
65      */
dismissSoftApShutdownTimeoutExpiredNotification()66     public void dismissSoftApShutdownTimeoutExpiredNotification() {
67         mNotificationManager.cancel(NOTIFICATION_ID_SOFTAP_AUTO_DISABLED);
68     }
69 
buildSoftApShutdownTimeoutExpiredNotification()70     private Notification buildSoftApShutdownTimeoutExpiredNotification() {
71         String title = mContext.getResources().getString(
72                 R.string.wifi_softap_auto_shutdown_timeout_expired_title);
73         String contentSummary = mContext.getResources().getString(
74                 R.string.wifi_softap_auto_shutdown_timeout_expired_summary);
75 
76         return mFrameworkFacade.makeNotificationBuilder(mContext,
77                 WifiService.NOTIFICATION_NETWORK_STATUS)
78                 .setSmallIcon(Icon.createWithResource(mContext.getWifiOverlayApkPkgName(),
79                         R.drawable.ic_wifi_settings))
80                 .setContentTitle(title)
81                 .setContentText(contentSummary)
82                 .setContentIntent(launchWifiTetherSettings())
83                 .setTicker(title)
84                 .setShowWhen(false)
85                 .setLocalOnly(true)
86                 .setColor(mContext.getResources().getColor(
87                         android.R.color.system_notification_accent_color, mContext.getTheme()))
88                 .setAutoCancel(true)
89                 .build();
90     }
91 
launchWifiTetherSettings()92     private PendingIntent launchWifiTetherSettings() {
93         Intent intent = new Intent(ACTION_HOTSPOT_PREFERENCES)
94                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
95                 .setPackage(mFrameworkFacade.getSettingsPackageName(mContext));
96         return mFrameworkFacade.getActivity(mContext, 0, intent,
97                 PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
98     }
99 
100 
101 }
102