diff options
author | Chiao Cheng <chiaocheng@google.com> | 2013-07-22 15:44:22 -0700 |
---|---|---|
committer | Chiao Cheng <chiaocheng@google.com> | 2013-07-22 15:44:22 -0700 |
commit | 65c46da8d41a40110e19b0bbe3bc86ac341e3cbd (patch) | |
tree | 3691427f83deb892af6c9c8cd5234882cd20bdfe /InCallUI | |
parent | 550f92b42a5387875d994a9b72050eaec2018649 (diff) |
Adding singleton wrapper for ICallCommandService.
Change-Id: I1ab36019f4d754ba9bca5a4d24f6292b91f60d18
Diffstat (limited to 'InCallUI')
3 files changed, 71 insertions, 18 deletions
diff --git a/InCallUI/src/com/android/incallui/AnswerPresenter.java b/InCallUI/src/com/android/incallui/AnswerPresenter.java index 1d0f3950c..933d758df 100644 --- a/InCallUI/src/com/android/incallui/AnswerPresenter.java +++ b/InCallUI/src/com/android/incallui/AnswerPresenter.java @@ -33,7 +33,7 @@ public class AnswerPresenter { public void onAnswer() { // TODO(klp): hook in call id. - CallHandlerService.answerCall(1); + CallCommandService.getInstance().answerCall(1); mListener.onAnswered(); } diff --git a/InCallUI/src/com/android/incallui/CallCommandService.java b/InCallUI/src/com/android/incallui/CallCommandService.java new file mode 100644 index 000000000..0264af1a1 --- /dev/null +++ b/InCallUI/src/com/android/incallui/CallCommandService.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2013 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.incallui; + +import android.os.RemoteException; +import android.util.Log; + +import com.android.internal.util.Preconditions; +import com.android.services.telephony.common.ICallCommandService; + +/** + * Main interface for phone related commands. + */ +public class CallCommandService { + + private static final String TAG = CallCommandService.class.getSimpleName(); + + private static CallCommandService sInstance; + + public static CallCommandService getInstance() { + if (sInstance == null) { + throw new IllegalStateException("CallCommandService has not been initialized."); + } + return sInstance; + } + + // TODO(klp): Not sure if static call is ok. Might need to switch to normal service binding. + public static void init(ICallCommandService service) { + Preconditions.checkState(sInstance == null); + sInstance = new CallCommandService(service); + } + + + private ICallCommandService mCommandService; + + private CallCommandService(ICallCommandService service) { + mCommandService = service; + } + + public void answerCall(int callId) { + try { + mCommandService.answerCall(callId); + } catch (RemoteException e) { + Log.e(TAG, "answerCall : " + e); + } + } + + public void mute() { + + } + + public void turnSpeakerOn() { + + } +} diff --git a/InCallUI/src/com/android/incallui/CallHandlerService.java b/InCallUI/src/com/android/incallui/CallHandlerService.java index b5f149704..490adc08e 100644 --- a/InCallUI/src/com/android/incallui/CallHandlerService.java +++ b/InCallUI/src/com/android/incallui/CallHandlerService.java @@ -34,8 +34,6 @@ public class CallHandlerService extends Service { private static final String TAG = CallHandlerService.class.getSimpleName(); private static final boolean DBG = false; // TODO: Have a shared location for this. - private static ICallCommandService mCallCommandService; - @Override public void onCreate() { super.onCreate(); @@ -55,7 +53,7 @@ public class CallHandlerService extends Service { @Override public void setCallCommandService(ICallCommandService service) { logD("onConnected: " + service.toString()); - mCallCommandService = service; + CallCommandService.init(service); } @Override @@ -66,20 +64,6 @@ public class CallHandlerService extends Service { } }; - // TODO(klp): Not sure if static call is ok. Might need to switch to normal service binding. - public static void answerCall(int callId) { - //Preconditions.checkState(mCallCommandService != null); - // TODO(klp): enable fail fast later. - if (mCallCommandService == null) { - return; - } - try { - mCallCommandService.answerCall(callId); - } catch (RemoteException e) { - Log.e(TAG, "answerCall : " + e); - } - } - private void logD(String message) { if (DBG) { Log.d(TAG, message); |