Migrate LocaleNotification to main trunk
Bug: 248514263 Test: make RunSettingsRoboTests -j128 ROBOTEST_FILTER=AppLocalePickerActivityTest LocaleListEditorTest LocaleNotificationDataManagerTest NotificationCancelReceiverTest NotificationControllerTest Change-Id: Iac7ffd493485be8ebb10ae63e5ca4ea7a57c8c78
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.localepicker;
|
||||
|
||||
import static com.android.settings.localepicker.AppLocalePickerActivity.EXTRA_APP_LOCALE;
|
||||
import static com.android.settings.localepicker.AppLocalePickerActivity.EXTRA_NOTIFICATION_ID;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
/**
|
||||
* A Broadcast receiver that handles the locale notification which is swiped away.
|
||||
*/
|
||||
public class NotificationCancelReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = NotificationCancelReceiver.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String appLocale = intent.getExtras().getString(EXTRA_APP_LOCALE);
|
||||
int notificationId = intent.getExtras().getInt(EXTRA_NOTIFICATION_ID, -1);
|
||||
int savedNotificationID = getNotificationController(context).getNotificationId(
|
||||
appLocale);
|
||||
Log.i(TAG, "Locale notification is swiped away.");
|
||||
if (savedNotificationID == notificationId) {
|
||||
getNotificationController(context).incrementDismissCount(appLocale);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
NotificationController getNotificationController(Context context) {
|
||||
return NotificationController.getInstance(context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user