diff options
author | arunvoddu <arunvoddu@google.com> | 2023-09-12 12:23:44 +0000 |
---|---|---|
committer | arunvoddu <arunvoddu@google.com> | 2023-09-13 06:42:58 +0000 |
commit | 875d947f02d576f396a0b45326a2471cd4e4ecae (patch) | |
tree | 05712e7c1476a7e98bfaaadfcc104fc6c707ac32 | |
parent | 14a01c6a0c6096c5c3ecdc27cf51f59365bac69b (diff) | |
download | Stk-875d947f02d576f396a0b45326a2471cd4e4ecae.tar.gz |
Added notification pendingIntent to handle the click event.
Handles to show the unlock screen if the device is screen locked.
Please refer to bug for demo videos
Bug: 285328495
Test: Verified manually that on stk app notification click,
it is asking to unlock the device.
Change-Id: I63be4b7e35080f9a8eea6e9f35143bd78b82c4a2
-rw-r--r-- | AndroidManifest.xml | 6 | ||||
-rw-r--r-- | src/com/android/stk/StkAppService.java | 47 | ||||
-rw-r--r-- | src/com/android/stk/UserPresentReceiver.java | 35 |
3 files changed, 54 insertions, 34 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 348e798..d8aff68 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -130,6 +130,12 @@ </intent-filter> </receiver> + <receiver android:name="com.android.stk.UserPresentReceiver" + android:exported="true"> + <intent-filter> + <action android:name="android.intent.action.USER_PRESENT" /> + </intent-filter> + </receiver> <service android:name="StkAppService" /> </application> 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(); + } + } +} |