David Su | 6c07c9f | 2019-11-20 18:16:56 -0800 | [diff] [blame] | 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 | package com.android.providers.settings; |
| 17 | |
| 18 | import android.app.Notification; |
| 19 | import android.app.NotificationChannel; |
| 20 | import android.app.NotificationManager; |
| 21 | import android.app.PendingIntent; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.content.res.Resources; |
| 25 | |
| 26 | import com.android.internal.messages.nano.SystemMessageProto; |
| 27 | import 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 | */ |
| 32 | public 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 | } |