blob: d0d4956725d4524c6fad328e3bd097087c34ad26 [file] [log] [blame]
David Su6c07c9f2019-11-20 18:16:56 -08001/*
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 */
16package com.android.providers.settings;
17
18import android.app.Notification;
19import android.app.NotificationChannel;
20import android.app.NotificationManager;
21import android.app.PendingIntent;
22import android.content.Context;
23import android.content.Intent;
24import android.content.res.Resources;
25
26import com.android.internal.messages.nano.SystemMessageProto;
27import com.android.internal.notification.SystemNotificationChannels;
28
29/**
30 * Helper class for sending notifications when the user's Soft AP Band was changed upon restore.
31 */
32public class WifiSoftApBandChangedNotifier {
33 private WifiSoftApBandChangedNotifier() {}
34
35 /**
36 * Send a notification informing the user that their' Soft AP Band was changed upon restore.
37 * When the user taps on the notification, they are taken to the Wifi Tethering page in
38 * Settings.
39 */
40 public static void notifyUserOfApBandConversion(Context context) {
41 NotificationManager notificationManager =
42 context.getSystemService(NotificationManager.class);
43
44 // create channel, or update it if it already exists
45 NotificationChannel channel = new NotificationChannel(
46 SystemNotificationChannels.NETWORK_STATUS,
47 context.getString(android.R.string.notification_channel_network_status),
48 NotificationManager.IMPORTANCE_LOW);
49 notificationManager.createNotificationChannel(channel);
50
51 notificationManager.notify(
52 SystemMessageProto.SystemMessage.NOTE_SOFTAP_CONFIG_CHANGED,
53 createConversionNotification(context));
54 }
55
56 private static Notification createConversionNotification(Context context) {
57 Resources resources = context.getResources();
58 CharSequence title = resources.getText(R.string.wifi_softap_config_change);
59 CharSequence contentSummary = resources.getText(R.string.wifi_softap_config_change_summary);
60 CharSequence content = resources.getText(R.string.wifi_softap_config_change_detailed);
61 int color = resources.getColor(
62 android.R.color.system_notification_accent_color, context.getTheme());
63
64 return new Notification.Builder(context, SystemNotificationChannels.NETWORK_STATUS)
65 .setSmallIcon(R.drawable.ic_wifi_settings)
66 .setPriority(Notification.PRIORITY_HIGH)
67 .setCategory(Notification.CATEGORY_SYSTEM)
68 .setContentTitle(title)
69 .setContentText(contentSummary)
70 .setContentIntent(getPendingActivity(context))
71 .setTicker(title)
72 .setShowWhen(false)
73 .setLocalOnly(true)
74 .setColor(color)
75 .setStyle(new Notification.BigTextStyle()
76 .bigText(content)
77 .setBigContentTitle(title)
78 .setSummaryText(contentSummary))
79 .setAutoCancel(true)
80 .build();
81 }
82
83 private static PendingIntent getPendingActivity(Context context) {
84 Intent intent = new Intent("com.android.settings.WIFI_TETHER_SETTINGS")
85 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
86 return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
87 }
88}