diff options
author | Chris Wren <cwren@android.com> | 2014-02-27 10:49:20 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-02-27 10:49:20 -0800 |
commit | ff8c6974c421070d3e2d3490f5821ae642811d15 (patch) | |
tree | 46df1211c22595963644d81893b9e4e85e15c905 | |
parent | 1cd204555beea34d926a203e9b406357fdf746c5 (diff) | |
parent | 72aa15de5bb974c95db67f8d631f0e10007903fc (diff) |
am d52e4929: add actions to the incoming call notification
* commit 'd52e4929af6e83e9fcb9ffef3f2f8c74a14e5aca':
add actions to the incoming call notification
-rw-r--r-- | InCallUI/AndroidManifest.xml | 2 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallApp.java | 14 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallPresenter.java | 35 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/StatusBarNotifier.java | 51 |
4 files changed, 98 insertions, 4 deletions
diff --git a/InCallUI/AndroidManifest.xml b/InCallUI/AndroidManifest.xml index efab0331a..0716eb082 100644 --- a/InCallUI/AndroidManifest.xml +++ b/InCallUI/AndroidManifest.xml @@ -60,6 +60,8 @@ <receiver android:name="InCallApp$NotificationBroadcastReceiver" android:exported="false"> <intent-filter> <action android:name="com.android.incallui.ACTION_HANG_UP_ONGOING_CALL" /> + <action android:name="com.android.incallui.ACTION_ANSWER_INCOMING_CALL" /> + <action android:name="com.android.incallui.ACTION_DECLINE_INCOMING_CALL" /> </intent-filter> </receiver> diff --git a/InCallUI/src/com/android/incallui/InCallApp.java b/InCallUI/src/com/android/incallui/InCallApp.java index 7d276bce9..01bdf3bf1 100644 --- a/InCallUI/src/com/android/incallui/InCallApp.java +++ b/InCallUI/src/com/android/incallui/InCallApp.java @@ -34,6 +34,10 @@ public class InCallApp extends Application { */ public static final String ACTION_HANG_UP_ONGOING_CALL = "com.android.incallui.ACTION_HANG_UP_ONGOING_CALL"; + public static final String ACTION_ANSWER_INCOMING_CALL = + "com.android.incallui.ACTION_ANSWER_INCOMING_CALL"; + public static final String ACTION_DECLINE_INCOMING_CALL = + "com.android.incallui.ACTION_DECLINE_INCOMING_CALL"; public InCallApp() { } @@ -59,11 +63,15 @@ public class InCallApp extends Application { final String action = intent.getAction(); Log.i(this, "Broadcast from Notification: " + action); + // TODO: Commands of this nature should exist in the CallList or a + // CallController class that has access to CallCommandClient and + // CallList. if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) { - // TODO: Commands of this nature should exist in the CallList or a - // CallController class that has access to CallCommandClient and - // CallList. InCallPresenter.getInstance().hangUpOngoingCall(context); + } else if (action.equals(ACTION_ANSWER_INCOMING_CALL)) { + InCallPresenter.getInstance().answerIncomingCall(context); + } else if (action.equals(ACTION_DECLINE_INCOMING_CALL)) { + InCallPresenter.getInstance().declineIncomingCall(context); } } } diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index 6260e9547..bc7c41a2c 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -368,6 +368,41 @@ public class InCallPresenter implements CallList.Listener { } /** + * Answers any incoming call. + */ + public void answerIncomingCall(Context context) { + // By the time we receive this intent, we could be shut down and call list + // could be null. Bail in those cases. + if (mCallList == null) { + StatusBarNotifier.clearInCallNotification(context); + return; + } + + Call call = mCallList.getIncomingCall(); + if (call != null) { + CallCommandClient.getInstance().answerCall(call.getCallId()); + showInCall(false); + } + } + + /** + * Declines any incoming call. + */ + public void declineIncomingCall(Context context) { + // By the time we receive this intent, we could be shut down and call list + // could be null. Bail in those cases. + if (mCallList == null) { + StatusBarNotifier.clearInCallNotification(context); + return; + } + + Call call = mCallList.getIncomingCall(); + if (call != null) { + CallCommandClient.getInstance().rejectCall(call, false, null); + } + } + + /** * Returns true if the incall app is the foreground application. */ public boolean isShowingInCallUi() { diff --git a/InCallUI/src/com/android/incallui/StatusBarNotifier.java b/InCallUI/src/com/android/incallui/StatusBarNotifier.java index 83878a5b0..dccef220a 100644 --- a/InCallUI/src/com/android/incallui/StatusBarNotifier.java +++ b/InCallUI/src/com/android/incallui/StatusBarNotifier.java @@ -302,6 +302,12 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener { Call.State.isDialing(state)) { addHangupAction(builder); } + // Add answer/decline options for incomng calls (incoming | call_waiting) + if (state == Call.State.INCOMING || + state == Call.State.CALL_WAITING) { + addAnswerAction(builder); + addDeclineAction(builder); + } /* * Fire off the notification @@ -452,6 +458,24 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener { createHangUpOngoingCallPendingIntent(mContext)); } + private void addAnswerAction(Notification.Builder builder) { + Log.i(this, "Will show \"answer\" action in the incoming call Notification"); + + // TODO: use better asset and string + builder.addAction(R.drawable.stat_sys_phone_call, + mContext.getText(R.string.description_target_answer), + createAnswerCallPendingIntent(mContext)); + } + + private void addDeclineAction(Notification.Builder builder) { + Log.i(this, "Will show \"decline\" action in the incoming call Notification"); + + // TODO: use better asset and string + builder.addAction(R.drawable.stat_sys_phone_call_end, + mContext.getText(R.string.description_target_decline), + createDeclineCallPendingIntent(mContext)); + } + /** * Adds fullscreen intent to the builder. */ @@ -530,8 +554,33 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener { * Notification context. */ private static PendingIntent createHangUpOngoingCallPendingIntent(Context context) { - final Intent intent = new Intent(InCallApp.ACTION_HANG_UP_ONGOING_CALL, null, + return createNotificationPendingIntent(context, InCallApp.ACTION_HANG_UP_ONGOING_CALL); + } + + /** + * Returns PendingIntent for answering a phone call. This will typically be used from + * Notification context. + */ + private static PendingIntent createAnswerCallPendingIntent(Context context) { + return createNotificationPendingIntent(context, InCallApp.ACTION_ANSWER_INCOMING_CALL); + } + + /** + * Returns PendingIntent for declining a phone call. This will typically be used from + * Notification context. + */ + private static PendingIntent createDeclineCallPendingIntent(Context context) { + return createNotificationPendingIntent(context, InCallApp.ACTION_DECLINE_INCOMING_CALL); + } + + /** + * Returns PendingIntent for answering a phone call. This will typically be used from + * Notification context. + */ + private static PendingIntent createNotificationPendingIntent(Context context, String action) { + final Intent intent = new Intent(action, null, context, NotificationBroadcastReceiver.class); return PendingIntent.getBroadcast(context, 0, intent, 0); } + } |