summaryrefslogtreecommitdiff
path: root/src/com/android/stk
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/stk')
-rw-r--r--src/com/android/stk/StkAppService.java47
-rw-r--r--src/com/android/stk/UserPresentReceiver.java35
2 files changed, 48 insertions, 34 deletions
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index 52b06fb..4d26fa6 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -74,7 +74,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.ITelephony;
import com.android.internal.telephony.PhoneConfigurationManager;
-import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.cat.AppInterface;
import com.android.internal.telephony.cat.CatCmdMessage;
@@ -300,6 +299,7 @@ public class StkAppService extends Service implements Runnable {
private static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
private static final String SYSTEM_DIALOG_REASON_RECENTAPPS_KEY = "recentapps";
private BroadcastReceiver mHomeKeyEventReceiver = null;
+ private static final int NOTIFICATION_PENDING_INTENT_REQUEST_CODE = 0;
@Override
public void onCreate() {
@@ -1690,47 +1690,26 @@ public class StkAppService extends Service implements Runnable {
builder.setOnlyAlertOnce(true);
builder.setColor(getResources().getColor(
com.android.internal.R.color.system_notification_accent_color));
-
- registerUserPresentReceiver();
+ Intent userPresentIntent = new Intent(mContext, UserPresentReceiver.class);
+ userPresentIntent.setAction(Intent.ACTION_USER_PRESENT);
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext,
+ NOTIFICATION_PENDING_INTENT_REQUEST_CODE, userPresentIntent,
+ PendingIntent.FLAG_IMMUTABLE);
+ builder.setContentIntent(pendingIntent);
mNotificationManager.notify(getNotificationId(NOTIFICATION_ON_KEYGUARD, slotId),
builder.build());
mStkContext[slotId].mNotificationOnKeyguard = true;
}
- private void cancelNotificationOnKeyguard(int slotId) {
- mNotificationManager.cancel(getNotificationId(NOTIFICATION_ON_KEYGUARD, slotId));
- mStkContext[slotId].mNotificationOnKeyguard = false;
- unregisterUserPresentReceiver(slotId);
- }
-
- private synchronized void registerUserPresentReceiver() {
- if (mUserPresentReceiver == null) {
- mUserPresentReceiver = new BroadcastReceiver() {
- @Override public void onReceive(Context context, Intent intent) {
- if (Intent.ACTION_USER_PRESENT.equals(intent.getAction())) {
- for (int slot = 0; slot < mSimCount; slot++) {
- cancelNotificationOnKeyguard(slot);
- }
- }
- }
- };
- registerReceiver(mUserPresentReceiver, new IntentFilter(Intent.ACTION_USER_PRESENT));
+ public void cancelNotificationOnKeyguard() {
+ for (int slot = 0; slot < mSimCount; slot++) {
+ cancelNotificationOnKeyguard(slot);
}
}
- private synchronized void unregisterUserPresentReceiver(int slotId) {
- if (mUserPresentReceiver != null) {
- for (int slot = 0; slot < mSimCount; slot++) {
- if (slot != slotId) {
- if (mStkContext[slot].mNotificationOnKeyguard) {
- // The broadcast receiver is still necessary for other SIM card.
- return;
- }
- }
- }
- unregisterReceiver(mUserPresentReceiver);
- mUserPresentReceiver = null;
- }
+ private void cancelNotificationOnKeyguard(int slotId) {
+ mNotificationManager.cancel(getNotificationId(NOTIFICATION_ON_KEYGUARD, slotId));
+ mStkContext[slotId].mNotificationOnKeyguard = false;
}
private int getNotificationId(int notificationType, int slotId) {
diff --git a/src/com/android/stk/UserPresentReceiver.java b/src/com/android/stk/UserPresentReceiver.java
new file mode 100644
index 0000000..25c945c
--- /dev/null
+++ b/src/com/android/stk/UserPresentReceiver.java
@@ -0,0 +1,35 @@
+/*
+ * 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.stk;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import com.android.internal.telephony.cat.CatLog;
+
+public class UserPresentReceiver extends BroadcastReceiver {
+
+ private static final String LOG_TAG = UserPresentReceiver.class.getSimpleName();
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (Intent.ACTION_USER_PRESENT.equals(intent.getAction())) {
+ CatLog.d(LOG_TAG, "Broadcast received and clearing the notification");
+ StkAppService.getInstance().cancelNotificationOnKeyguard();
+ }
+ }
+}