Allow a custom component to receive notification of missed call.
By setting the custom component, the system notification is suppressed. Change-Id: Idfc0354aaa97776e19ad642e44a88978577559a9
This commit is contained in:
parent
b152170f43
commit
41045b499a
|
@ -20,6 +20,9 @@
|
|||
coreApp="true"
|
||||
android:sharedUserId="android.uid.system">
|
||||
|
||||
|
||||
<protected-broadcast android:name="android.intent.action.SHOW_MISSED_CALLS_NOTIFICATION" />
|
||||
|
||||
<!-- Prevents the activity manager from delaying any activity-start
|
||||
requests by this package, including requests immediately after
|
||||
the user presses "home". -->
|
||||
|
|
|
@ -38,4 +38,8 @@
|
|||
|
||||
<!-- Flag indicating if the tty is enabled -->
|
||||
<bool name="tty_enabled">false</bool>
|
||||
|
||||
<!-- Component name for the notification handler. The presence of this value will disable
|
||||
MissedCallNotifierImpl's presentation of missed call/voice notifications [DO NOT TRANSLATE] -->
|
||||
<string name="notification_component" translatable="false"></string>
|
||||
</resources>
|
||||
|
|
|
@ -48,6 +48,7 @@ import com.android.internal.telephony.SmsApplication;
|
|||
import com.android.server.telecom.ContactsAsyncHelper.OnImageLoadCompleteListener;
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import java.lang.String;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
@ -666,6 +667,10 @@ public class Call implements CreateConnectionResponse {
|
|||
return mCallerInfo == null ? null : mCallerInfo.name;
|
||||
}
|
||||
|
||||
public String getPhoneNumber() {
|
||||
return mCallerInfo == null ? null : mCallerInfo.phoneNumber;
|
||||
}
|
||||
|
||||
public Bitmap getPhotoIcon() {
|
||||
return mCallerInfo == null ? null : mCallerInfo.cachedPhotoIcon;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.android.server.telecom.ui;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.telecom.TelecomManager;
|
||||
import com.android.server.telecom.Call;
|
||||
import com.android.server.telecom.CallState;
|
||||
import com.android.server.telecom.CallerInfoAsyncQueryFactory;
|
||||
|
@ -54,6 +56,9 @@ import android.text.BidiFormatter;
|
|||
import android.text.TextDirectionHeuristics;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.lang.Override;
|
||||
import java.lang.String;
|
||||
|
||||
// TODO: Needed for move to system service: import com.android.internal.R;
|
||||
|
||||
/**
|
||||
|
@ -89,6 +94,8 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
|
|||
private final Context mContext;
|
||||
private final NotificationManager mNotificationManager;
|
||||
|
||||
private final ComponentName mNotificationComponent;
|
||||
|
||||
// Used to track the number of missed calls.
|
||||
private int mMissedCallCount = 0;
|
||||
|
||||
|
@ -96,6 +103,10 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
|
|||
mContext = context;
|
||||
mNotificationManager =
|
||||
(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
final String notificationComponent = context.getString(R.string.notification_component);
|
||||
|
||||
mNotificationComponent = notificationComponent != null
|
||||
? ComponentName.unflattenFromString(notificationComponent) : null;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -134,6 +145,37 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
|
|||
cancelMissedCallNotification();
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts missed call notification to custom component if set.
|
||||
* @param number The phone number associated with the notification. null if
|
||||
* no call.
|
||||
* @param count The number of calls associated with the notification.
|
||||
* @return {@code true} if the broadcast was sent. {@code false} otherwise.
|
||||
*/
|
||||
private boolean sendNotificationCustomComponent(Call call, int count) {
|
||||
if (mNotificationComponent != null) {
|
||||
Intent intent = new Intent();
|
||||
intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||
intent.setComponent(mNotificationComponent);
|
||||
intent.setAction(TelecomManager.ACTION_SHOW_MISSED_CALLS_NOTIFICATION);
|
||||
intent.putExtra(TelecomManager.EXTRA_NOTIFICATION_COUNT, count);
|
||||
intent.putExtra(TelecomManager.EXTRA_NOTIFICATION_PHONE_NUMBER,
|
||||
call != null ? call.getPhoneNumber() : null);
|
||||
intent.putExtra(TelecomManager.EXTRA_CLEAR_MISSED_CALLS_INTENT,
|
||||
createClearMissedCallsPendingIntent());
|
||||
|
||||
if (count == 1 && call != null) {
|
||||
intent.putExtra(TelecomManager.EXTRA_CALL_BACK_INTENT,
|
||||
createCallBackPendingIntent(call.getHandle()));
|
||||
}
|
||||
|
||||
mContext.sendBroadcast(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a system notification for the missed call.
|
||||
*
|
||||
|
@ -143,6 +185,10 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
|
|||
public void showMissedCallNotification(Call call) {
|
||||
mMissedCallCount++;
|
||||
|
||||
if (sendNotificationCustomComponent(call, mMissedCallCount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int titleResId;
|
||||
final String expandedText; // The text in the notification's line 1 and 2.
|
||||
|
||||
|
@ -218,6 +264,12 @@ public class MissedCallNotifierImpl extends CallsManagerListenerBase implements
|
|||
private void cancelMissedCallNotification() {
|
||||
// Reset the number of missed calls to 0.
|
||||
mMissedCallCount = 0;
|
||||
|
||||
|
||||
if (sendNotificationCustomComponent(null, mMissedCallCount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mNotificationManager.cancelAsUser(null, MISSED_CALL_NOTIFICATION_ID,
|
||||
|
|
Loading…
Reference in New Issue