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 import static com.android.settings.localepicker.LocaleListEditor.EXTRA_SYSTEM_LOCALE_DIALOG_TYPE; 22 import static com.android.settings.localepicker.LocaleListEditor.LOCALE_SUGGESTION; 23 24 import android.app.settings.SettingsEnums; 25 import android.content.Context; 26 import android.content.Intent; 27 import android.os.Bundle; 28 import android.provider.Settings; 29 import android.text.TextUtils; 30 31 import androidx.activity.result.ActivityResultLauncher; 32 import androidx.activity.result.contract.ActivityResultContracts; 33 import androidx.annotation.VisibleForTesting; 34 import androidx.appcompat.app.AppCompatActivity; 35 36 import com.android.settings.overlay.FeatureFactory; 37 38 /** 39 * An Activity that launches the system locale settings page. 40 */ 41 public class NotificationActionActivity extends AppCompatActivity { 42 private static final String TAG = "NotificationActionActivity"; 43 private static final int INVALID_NOTIFICATION_ID = -1; 44 private final ActivityResultLauncher<Intent> mStartForResult = 45 registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), 46 result -> { 47 }); 48 49 @Override onCreate(Bundle savedInstanceState)50 public void onCreate(Bundle savedInstanceState) { 51 super.onCreate(savedInstanceState); 52 Intent intent = getIntent(); 53 int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, INVALID_NOTIFICATION_ID); 54 String appLocale = intent.getStringExtra(EXTRA_APP_LOCALE); 55 if (TextUtils.isEmpty(appLocale) || notificationId == INVALID_NOTIFICATION_ID) { 56 finish(); 57 return; 58 } 59 int savedNotificationID = getNotificationController(this).getNotificationId(appLocale); 60 if (savedNotificationID == notificationId) { 61 Intent actionIntent = new Intent(Settings.ACTION_LOCALE_SETTINGS); 62 actionIntent.putExtra(EXTRA_SYSTEM_LOCALE_DIALOG_TYPE, LOCALE_SUGGESTION); 63 actionIntent.putExtra(EXTRA_APP_LOCALE, appLocale); 64 actionIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); 65 getLauncher().launch(actionIntent); 66 FeatureFactory.getFeatureFactory().getMetricsFeatureProvider().action(this, 67 SettingsEnums.ACTION_NOTIFICATION_CLICK_FOR_SYSTEM_LOCALE); 68 finish(); 69 return; 70 } 71 } 72 73 @VisibleForTesting getNotificationController(Context context)74 protected NotificationController getNotificationController(Context context) { 75 return NotificationController.getInstance(context); 76 } 77 78 @VisibleForTesting getLauncher()79 protected ActivityResultLauncher<Intent> getLauncher() { 80 return mStartForResult; 81 } 82 } 83