1 /* 2 * Copyright (C) 2023 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.settings.localepicker; 18 19 import static com.android.settings.localepicker.AppLocalePickerActivity.EXTRA_APP_LOCALE; 20 import static com.android.settings.localepicker.AppLocalePickerActivity.EXTRA_NOTIFICATION_ID; 21 22 import android.app.settings.SettingsEnums; 23 import android.content.BroadcastReceiver; 24 import android.content.Context; 25 import android.content.Intent; 26 import android.util.Log; 27 28 import androidx.annotation.VisibleForTesting; 29 30 import com.android.settings.overlay.FeatureFactory; 31 32 /** 33 * A Broadcast receiver that handles the locale notification which is swiped away. 34 */ 35 public class NotificationCancelReceiver extends BroadcastReceiver { 36 private static final String TAG = NotificationCancelReceiver.class.getSimpleName(); 37 38 @Override onReceive(Context context, Intent intent)39 public void onReceive(Context context, Intent intent) { 40 String appLocale = intent.getExtras().getString(EXTRA_APP_LOCALE); 41 int notificationId = intent.getExtras().getInt(EXTRA_NOTIFICATION_ID, -1); 42 int savedNotificationID = getNotificationController(context).getNotificationId( 43 appLocale); 44 Log.i(TAG, "Locale notification is swiped away."); 45 if (savedNotificationID == notificationId) { 46 getNotificationController(context).incrementDismissCount(appLocale); 47 FeatureFactory.getFeatureFactory().getMetricsFeatureProvider().action(context, 48 SettingsEnums.ACTION_NOTIFICATION_SWIPE_FOR_SYSTEM_LOCALE); 49 } 50 } 51 52 @VisibleForTesting getNotificationController(Context context)53 NotificationController getNotificationController(Context context) { 54 return NotificationController.getInstance(context); 55 } 56 } 57