summaryrefslogtreecommitdiffstats
path: root/src/com/android/car/stream/telecom
diff options
context:
space:
mode:
authorAnthony Chen <ajchen@google.com>2017-11-06 15:35:25 -0800
committerAnthony Chen <ajchen@google.com>2017-11-06 15:35:25 -0800
commit0e9642bceb5e445863e45c70e9aaa01f4b791a04 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /src/com/android/car/stream/telecom
parent619b7be0fe3b88f702e5fa126237596d544dc034 (diff)
downloadplatform_packages_apps_Car_Stream-0e9642bceb5e445863e45c70e9aaa01f4b791a04.tar.gz
platform_packages_apps_Car_Stream-0e9642bceb5e445863e45c70e9aaa01f4b791a04.tar.bz2
platform_packages_apps_Car_Stream-0e9642bceb5e445863e45c70e9aaa01f4b791a04.zip
Remove Stream app.
Test: build mojave and ensured no breakages. Bug: 68951925 Change-Id: I729c2a59206950fdfc1d2bda07fc3803bd1db224
Diffstat (limited to 'src/com/android/car/stream/telecom')
-rw-r--r--src/com/android/car/stream/telecom/CurrentCallConverter.java126
-rw-r--r--src/com/android/car/stream/telecom/CurrentCallStreamProducer.java234
-rw-r--r--src/com/android/car/stream/telecom/RecentCallConverter.java59
-rw-r--r--src/com/android/car/stream/telecom/RecentCallStreamProducer.java135
-rw-r--r--src/com/android/car/stream/telecom/StreamInCallService.java100
-rw-r--r--src/com/android/car/stream/telecom/TelecomConstants.java28
-rw-r--r--src/com/android/car/stream/telecom/TelecomUtils.java359
7 files changed, 0 insertions, 1041 deletions
diff --git a/src/com/android/car/stream/telecom/CurrentCallConverter.java b/src/com/android/car/stream/telecom/CurrentCallConverter.java
deleted file mode 100644
index 8c29919..0000000
--- a/src/com/android/car/stream/telecom/CurrentCallConverter.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 2016, 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.car.stream.telecom;
-
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.drawable.VectorDrawable;
-import android.telecom.Call;
-import com.android.car.stream.BitmapUtils;
-import com.android.car.stream.CurrentCallExtension;
-import com.android.car.stream.R;
-import com.android.car.stream.StreamCard;
-import com.android.car.stream.StreamConstants;
-
-/**
- * A converter that creates a {@link StreamCard} for the current call events.
- */
-public class CurrentCallConverter {
- private static final int MUTE_BUTTON_REQUEST_CODE = 12;
- private static final int CALL_BUTTON_REQUEST_CODE = 13;
-
- private PendingIntent mMuteAction;
- private PendingIntent mUnMuteAction;
- private PendingIntent mAcceptCallAction;
- private PendingIntent mHangupCallAction;
-
- public CurrentCallConverter(Context context) {
- mMuteAction = getCurrentCallAction(context,
- TelecomConstants.ACTION_MUTE, MUTE_BUTTON_REQUEST_CODE);
- mUnMuteAction = getCurrentCallAction(context,
- TelecomConstants.ACTION_MUTE, MUTE_BUTTON_REQUEST_CODE);
-
- mAcceptCallAction = getCurrentCallAction(context,
- TelecomConstants.ACTION_ACCEPT_CALL, CALL_BUTTON_REQUEST_CODE);
- mHangupCallAction = getCurrentCallAction(context,
- TelecomConstants.ACTION_HANG_UP_CALL, CALL_BUTTON_REQUEST_CODE);
- }
-
- private PendingIntent getCurrentCallAction(Context context,
- String action, int requestcode) {
- Intent intent = new Intent(TelecomConstants.INTENT_ACTION_STREAM_CALL_CONTROL);
- intent.setPackage(context.getPackageName());
- intent.putExtra(TelecomConstants.EXTRA_STREAM_CALL_ACTION, action);
- PendingIntent pendingIntent =
- PendingIntent.getBroadcast(
- context,
- requestcode,
- intent,
- PendingIntent.FLAG_CANCEL_CURRENT
- );
- return pendingIntent;
- }
-
- public StreamCard convert(Call call, Context context, boolean isMuted,
- long callStartTime, String dialerPackage) {
- long timeStamp = System.currentTimeMillis() - call.getDetails().getConnectTimeMillis();
- int callState = call.getState();
- String number = TelecomUtils.getNumber(call);
- String displayName = TelecomUtils.getDisplayName(context, call);
- long digits = Long.valueOf(number.replaceAll("[^0-9]", ""));
-
- PendingIntent dialerPendingIntent =
- PendingIntent.getActivity(
- context,
- 0,
- context.getPackageManager().getLaunchIntentForPackage(dialerPackage),
- PendingIntent.FLAG_UPDATE_CURRENT
- );
-
- StreamCard.Builder builder = new StreamCard.Builder(StreamConstants.CARD_TYPE_CURRENT_CALL,
- digits /* id */, timeStamp);
- builder.setPrimaryText(displayName);
- builder.setSecondaryText(getCallState(context, callState));
-
- Bitmap phoneIcon = BitmapUtils.getBitmap(
- (VectorDrawable) context.getDrawable(R.drawable.ic_phone));
- builder.setPrimaryIcon(phoneIcon);
- builder.setSecondaryIcon(TelecomUtils.createStreamCardSecondaryIcon(context, number));
- builder.setClickAction(dialerPendingIntent);
- builder.setCardExtension(createCurrentCallExtension(context, callStartTime, displayName,
- callState, isMuted, number));
- return builder.build();
- }
-
- private CurrentCallExtension createCurrentCallExtension(Context context, long callStartTime,
- String displayName, int callState, boolean isMuted, String number) {
-
- Bitmap contactPhoto = TelecomUtils
- .getContactPhotoFromNumber(context.getContentResolver(), number);
- CurrentCallExtension extension
- = new CurrentCallExtension(callStartTime, displayName, callState, isMuted,
- contactPhoto, mMuteAction, mUnMuteAction, mAcceptCallAction, mHangupCallAction);
- return extension;
- }
-
- private String getCallState(Context context, int state) {
- switch (state) {
- case Call.STATE_ACTIVE:
- return context.getString(R.string.ongoing_call);
- case Call.STATE_DIALING:
- return context.getString(R.string.dialing_call);
- case Call.STATE_DISCONNECTING:
- return context.getString(R.string.disconnecting_call);
- case Call.STATE_RINGING:
- return context.getString(R.string.notification_incoming_call);
- default:
- return context.getString(R.string.unknown);
- }
- }
-
-}
diff --git a/src/com/android/car/stream/telecom/CurrentCallStreamProducer.java b/src/com/android/car/stream/telecom/CurrentCallStreamProducer.java
deleted file mode 100644
index 2b774b7..0000000
--- a/src/com/android/car/stream/telecom/CurrentCallStreamProducer.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Copyright (c) 2016, 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.car.stream.telecom;
-
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.ServiceConnection;
-import android.os.AsyncTask;
-import android.os.IBinder;
-import android.os.SystemClock;
-import android.telecom.Call;
-import android.telecom.CallAudioState;
-import android.telecom.TelecomManager;
-import android.util.Log;
-import com.android.car.stream.StreamCard;
-import com.android.car.stream.StreamProducer;
-import com.android.car.stream.telecom.StreamInCallService.StreamInCallServiceBinder;
-
-/**
- * A {@link StreamProducer} that listens for active call events and produces a {@link StreamCard}
- */
-public class CurrentCallStreamProducer extends StreamProducer
- implements StreamInCallService.InCallServiceCallback {
- private static final String TAG = "CurrentCallProducer";
-
- private StreamInCallService mInCallService;
- private PhoneCallback mPhoneCallback;
- private CurrentCallActionReceiver mCallActionReceiver;
- private Call mCurrentCall;
- private long mCurrentCallStartTime;
-
- private CurrentCallConverter mConverter;
- private AsyncTask mUpdateStreamItemTask;
-
- private String mDialerPackage;
- private TelecomManager mTelecomManager;
-
- public CurrentCallStreamProducer(Context context) {
- super(context);
- }
-
- @Override
- public void start() {
- super.start();
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "current call producer started");
- }
- mTelecomManager = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
- mDialerPackage = mTelecomManager.getDefaultDialerPackage();
- mConverter = new CurrentCallConverter(mContext);
- mPhoneCallback = new PhoneCallback();
-
- Intent inCallServiceIntent = new Intent(mContext, StreamInCallService.class);
- inCallServiceIntent.setAction(StreamInCallService.LOCAL_INCALL_SERVICE_BIND_ACTION);
- mContext.bindService(inCallServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
- }
-
- @Override
- public void stop() {
- mContext.unbindService(mServiceConnection);
- super.stop();
- }
-
- private void acceptCall() {
- synchronized (mTelecomManager) {
- if (mCurrentCall != null && mCurrentCall.getState() == Call.STATE_RINGING) {
- mCurrentCall.answer(0 /* videoState */);
- }
- }
- }
-
- private void disconnectCall() {
- synchronized (mTelecomManager) {
- if (mCurrentCall != null) {
- mCurrentCall.disconnect();
- }
- }
- }
-
- @Override
- public void onCallAdded(Call call) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "on call added, state: " + call.getState());
- }
- mCurrentCall = call;
- updateStreamCard(mCurrentCall, mContext);
- call.registerCallback(mPhoneCallback);
- }
-
- @Override
- public void onCallRemoved(Call call) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "on call removed, state: " + call.getState());
- }
- call.unregisterCallback(mPhoneCallback);
- updateStreamCard(call, mContext);
- mCurrentCall = null;
- }
-
- @Override
- public void onCallAudioStateChanged(CallAudioState audioState) {
- if (mCurrentCall != null && audioState != null) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "audio state changed, is muted? " + audioState.isMuted());
- }
- updateStreamCard(mCurrentCall, mContext);
- }
- }
-
- private void clearUpdateStreamItemTask() {
- if (mUpdateStreamItemTask != null) {
- mUpdateStreamItemTask.cancel(false);
- mUpdateStreamItemTask = null;
- }
- }
-
- private void updateStreamCard(final Call call, final Context context) {
- // Only one update may be active at a time.
- clearUpdateStreamItemTask();
-
- mUpdateStreamItemTask = new AsyncTask<Void, Void, StreamCard>() {
- @Override
- protected StreamCard doInBackground(Void... voids) {
- try {
- return mConverter.convert(call, context, mInCallService.isMuted(),
- mCurrentCallStartTime, mDialerPackage);
- } catch (Exception e) {
- Log.e(TAG, "Failed to create StreamItem.", e);
- throw e;
- }
- }
-
- @Override
- protected void onPostExecute(StreamCard card) {
- if (call.getState() == Call.STATE_DISCONNECTED) {
- removeCard(card);
- } else {
- postCard(card);
- }
- }
- }.execute();
- }
-
- private class PhoneCallback extends Call.Callback {
- @Override
- public void onStateChanged(Call call, int state) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "onStateChanged call: " + call + ", state: " + state);
- }
-
- if (state == Call.STATE_ACTIVE) {
- mCurrentCallStartTime = SystemClock.elapsedRealtime();
- } else {
- mCurrentCallStartTime = 0;
- }
-
- switch (state) {
- // TODO: Determine if a HUD or stream card should be displayed.
- case Call.STATE_RINGING: // Incoming call is ringing.
- case Call.STATE_DIALING: // Outgoing call that is dialing.
- case Call.STATE_ACTIVE: // Call is connected
- case Call.STATE_DISCONNECTING: // Call is being disconnected
- case Call.STATE_DISCONNECTED: // Call has finished.
- updateStreamCard(call, mContext);
- mCurrentCall = call;
- break;
- default:
- }
- }
- }
-
- private class CurrentCallActionReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- String intentAction = intent.getAction();
- if (!TelecomConstants.INTENT_ACTION_STREAM_CALL_CONTROL.equals(intentAction)) {
- return;
- }
-
- String action = intent.getStringExtra(TelecomConstants.EXTRA_STREAM_CALL_ACTION);
- switch (action) {
- case TelecomConstants.ACTION_MUTE:
- mInCallService.setMuted(true);
- break;
- case TelecomConstants.ACTION_UNMUTE:
- mInCallService.setMuted(false);
- break;
- case TelecomConstants.ACTION_ACCEPT_CALL:
- acceptCall();
- break;
- case TelecomConstants.ACTION_HANG_UP_CALL:
- disconnectCall();
- break;
- default:
- }
- }
- }
-
- private ServiceConnection mServiceConnection = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- StreamInCallServiceBinder binder = (StreamInCallServiceBinder) service;
- mInCallService = binder.getService();
- mInCallService.setCallback(CurrentCallStreamProducer.this);
-
- if (mCallActionReceiver == null) {
- mCallActionReceiver = new CurrentCallActionReceiver();
- mContext.registerReceiver(mCallActionReceiver,
- new IntentFilter(TelecomConstants.INTENT_ACTION_STREAM_CALL_CONTROL));
- }
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mInCallService = null;
- }
- };
-}
diff --git a/src/com/android/car/stream/telecom/RecentCallConverter.java b/src/com/android/car/stream/telecom/RecentCallConverter.java
deleted file mode 100644
index 77bcec8..0000000
--- a/src/com/android/car/stream/telecom/RecentCallConverter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2016, 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.car.stream.telecom;
-
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.drawable.VectorDrawable;
-import android.net.Uri;
-import com.android.car.stream.BitmapUtils;
-import com.android.car.stream.R;
-import com.android.car.stream.StreamCard;
-import com.android.car.stream.StreamConstants;
-
-public class RecentCallConverter {
-
- /**
- * Creates a StreamCard of type {@link StreamConstants#CARD_TYPE_RECENT_CALL}
- * @return
- */
- public StreamCard createStreamCard(Context context, String number, long timestamp) {
- StreamCard.Builder builder = new StreamCard.Builder(StreamConstants.CARD_TYPE_RECENT_CALL,
- Long.parseLong(number), timestamp);
- String displayName = TelecomUtils.getDisplayName(context, number);
-
- builder.setPrimaryText(displayName);
- builder.setSecondaryText(context.getString(R.string.recent_call));
- builder.setDescription(context.getString(R.string.recent_call));
- Bitmap phoneIcon = BitmapUtils.getBitmap(
- (VectorDrawable) context.getDrawable(R.drawable.ic_phone));
-
- builder.setPrimaryIcon(phoneIcon);
- builder.setSecondaryIcon(TelecomUtils.createStreamCardSecondaryIcon(context, number));
- builder.setClickAction(createCallPendingIntent(context, number));
- return builder.build();
- }
-
- private PendingIntent createCallPendingIntent(Context context, String number) {
- Intent callIntent = new Intent(Intent.ACTION_DIAL);
- callIntent.setData(Uri.parse("tel: " + number));
- callIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
- return PendingIntent.getActivity(context, 0, callIntent,
- PendingIntent.FLAG_UPDATE_CURRENT);
- }
-}
diff --git a/src/com/android/car/stream/telecom/RecentCallStreamProducer.java b/src/com/android/car/stream/telecom/RecentCallStreamProducer.java
deleted file mode 100644
index 9581226..0000000
--- a/src/com/android/car/stream/telecom/RecentCallStreamProducer.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) 2016, 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.car.stream.telecom;
-
-import android.content.Context;
-import android.content.CursorLoader;
-import android.content.Loader;
-import android.content.pm.PackageManager;
-import android.database.Cursor;
-import android.net.Uri;
-import android.provider.CallLog;
-import android.text.TextUtils;
-import android.text.format.DateUtils;
-import android.util.Log;
-import com.android.car.stream.StreamCard;
-import com.android.car.stream.StreamProducer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Loads recent calls from the call log and produces a {@link StreamCard} for each entry.
- */
-public class RecentCallStreamProducer extends StreamProducer
- implements Loader.OnLoadCompleteListener<Cursor> {
- private static final String TAG = "RecentCallProducer";
- private static final long RECENT_CALL_TIME_RANGE = 6 * DateUtils.HOUR_IN_MILLIS;
-
- /** Number of call log items to query for */
- private static final int CALL_LOG_QUERY_LIMIT = 1;
- private static final String[] EMPTY_STRING_ARRAY = new String[0];
-
- private CursorLoader mCursorLoader;
- private StreamCard mCurrentStreamCard;
- private long mCurrentNumber;
- private RecentCallConverter mConverter = new RecentCallConverter();
-
- public RecentCallStreamProducer(Context context) {
- super(context);
- mCursorLoader = createCallLogLoader();
- }
-
- @Override
- public void start() {
- super.start();
- if (!hasReadCallLogPermission()) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "Could not onStart RecentCallStreamProducer, permissions not granted");
- }
- return;
- }
-
- if (!mCursorLoader.isStarted()) {
- mCursorLoader.startLoading();
- }
- }
-
- @Override
- public void stop() {
- if (mCursorLoader.isStarted()) {
- mCursorLoader.stopLoading();
- removeCard(mCurrentStreamCard);
- mCurrentStreamCard = null;
- mCurrentNumber = 0;
- }
- super.stop();
- }
-
- @Override
- public void onLoadComplete(Loader<Cursor> loader, Cursor cursor) {
- if (cursor == null || !cursor.moveToFirst()) {
- return;
- }
-
- int column = cursor.getColumnIndex(CallLog.Calls.NUMBER);
- String number = cursor.getString(column);
- column = cursor.getColumnIndex(CallLog.Calls.DATE);
- long callTimeMs = cursor.getLong(column);
- // Display if we have a phone number, and the call was within 6hours.
- number = number.replaceAll("[^0-9]", "");
- long timestamp = System.currentTimeMillis();
- long digits = Long.parseLong(number);
-
- if (!TextUtils.isEmpty(number) &&
- (timestamp - callTimeMs) < RECENT_CALL_TIME_RANGE) {
- if (mCurrentStreamCard == null || mCurrentNumber != digits) {
- removeCard(mCurrentStreamCard);
- mCurrentStreamCard = mConverter.createStreamCard(mContext, number, timestamp);
- mCurrentNumber = digits;
- postCard(mCurrentStreamCard);
- }
- }
- }
-
- private boolean hasReadCallLogPermission() {
- return mContext.checkSelfPermission(android.Manifest.permission.READ_CALL_LOG)
- == PackageManager.PERMISSION_GRANTED;
- }
-
- /**
- * Creates a CursorLoader for Call data.
- * Note: NOT to be used with LoaderManagers.
- */
- private CursorLoader createCallLogLoader() {
- // We need to check for NULL explicitly otherwise entries with where READ is NULL
- // may not match either the query or its negation.
- // We consider the calls that are not yet consumed (i.e. IS_READ = 0) as "new".
- StringBuilder where = new StringBuilder();
- List<String> selectionArgs = new ArrayList<String>();
-
- String selection = where.length() > 0 ? where.toString() : null;
- Uri uri = CallLog.Calls.CONTENT_URI.buildUpon()
- .appendQueryParameter(CallLog.Calls.LIMIT_PARAM_KEY,
- Integer.toString(CALL_LOG_QUERY_LIMIT))
- .build();
- CursorLoader loader = new CursorLoader(mContext, uri, null, selection,
- selectionArgs.toArray(EMPTY_STRING_ARRAY), CallLog.Calls.DEFAULT_SORT_ORDER);
- loader.registerListener(0, this /* OnLoadCompleteListener */);
- return loader;
- }
-
-}
diff --git a/src/com/android/car/stream/telecom/StreamInCallService.java b/src/com/android/car/stream/telecom/StreamInCallService.java
deleted file mode 100644
index fef7155..0000000
--- a/src/com/android/car/stream/telecom/StreamInCallService.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2016, 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.car.stream.telecom;
-
-import android.content.Intent;
-import android.os.Binder;
-import android.os.IBinder;
-import android.telecom.Call;
-import android.telecom.CallAudioState;
-import android.telecom.InCallService;
-import android.util.Log;
-
-/**
- * {@link InCallService} to listen for incoming calls and changes in call state.
- */
-public class StreamInCallService extends InCallService {
- public static final String LOCAL_INCALL_SERVICE_BIND_ACTION = "stream_incall_service_action";
- private static final String TAG = "StreamInCallService";
- private final IBinder mBinder = new StreamInCallServiceBinder();
-
- private InCallServiceCallback mCallback;
-
- /**
- * Callback interface to receive changes in the call state.
- */
- public interface InCallServiceCallback {
- void onCallAdded(Call call);
-
- void onCallRemoved(Call call);
-
- void onCallAudioStateChanged(CallAudioState audioState);
- }
-
- public class StreamInCallServiceBinder extends Binder {
- StreamInCallService getService() {
- return StreamInCallService.this;
- }
- }
-
- public void setCallback(InCallServiceCallback callback) {
- mCallback = callback;
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- // This service can be bound by the framework or a local stream producer.
- // Check the action and return the appropriate IBinder.
- if (LOCAL_INCALL_SERVICE_BIND_ACTION.equals(intent.getAction())) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "onBind with action: LOCAL_INCALL_SERVICE_BIND_ACTION," +
- " returning StreamInCallServiceBinder");
- }
- return mBinder;
- }
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, "onBind without action specified, returning InCallService");
- }
- return super.onBind(intent);
- }
-
- @Override
- public void onCallAdded(Call call) {
- if (mCallback != null) {
- mCallback.onCallAdded(call);
- }
- }
-
- @Override
- public void onCallRemoved(Call call) {
- if (mCallback != null) {
- mCallback.onCallRemoved(call);
- }
- }
-
- @Override
- public void onCallAudioStateChanged(CallAudioState audioState) {
- if (mCallback != null) {
- mCallback.onCallAudioStateChanged(audioState);
- }
- super.onCallAudioStateChanged(audioState);
- }
-
- public boolean isMuted() {
- CallAudioState audioState = getCallAudioState();
- return audioState != null && audioState.isMuted();
- }
-}
diff --git a/src/com/android/car/stream/telecom/TelecomConstants.java b/src/com/android/car/stream/telecom/TelecomConstants.java
deleted file mode 100644
index c5189fc..0000000
--- a/src/com/android/car/stream/telecom/TelecomConstants.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2016, 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.car.stream.telecom;
-
-public class TelecomConstants {
- public static final String INTENT_ACTION_STREAM_CALL_CONTROL
- = "com.google.android.car.stream.telecom.CALL_CONTROL";
- public static final String EXTRA_STREAM_CALL_ACTION
- = "com.google.android.car.stream.telecom.ACTION";
-
- public static final String ACTION_MUTE = "mute";
- public static final String ACTION_UNMUTE = "unmute";
- public static final String ACTION_HANG_UP_CALL = "hang_up_call";
- public static final String ACTION_ACCEPT_CALL = "accept_call";
-}
diff --git a/src/com/android/car/stream/telecom/TelecomUtils.java b/src/com/android/car/stream/telecom/TelecomUtils.java
deleted file mode 100644
index 3d56e70..0000000
--- a/src/com/android/car/stream/telecom/TelecomUtils.java
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- * Copyright (c) 2016, 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.car.stream.telecom;
-
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.Context;
-import android.content.res.Resources;
-import android.database.Cursor;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Rect;
-import android.net.Uri;
-import android.provider.ContactsContract;
-import android.support.annotation.Nullable;
-import android.support.annotation.WorkerThread;
-import android.telecom.Call;
-import android.telecom.GatewayInfo;
-import android.telephony.PhoneNumberUtils;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-import android.util.LruCache;
-import com.android.car.apps.common.CircleBitmapDrawable;
-import com.android.car.apps.common.LetterTileDrawable;
-import com.android.car.stream.R;
-
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Locale;
-
-/**
- * Telecom related utility methods.
- */
-public class TelecomUtils {
- private static final int LRU_CACHE_SIZE = 4194304; /** 4 mb **/
-
- private static final String[] CONTACT_ID_PROJECTION = new String[] {
- ContactsContract.PhoneLookup.DISPLAY_NAME,
- ContactsContract.PhoneLookup.TYPE,
- ContactsContract.PhoneLookup.LABEL,
- ContactsContract.PhoneLookup._ID
- };
-
- private static String sVoicemailNumber;
-
- private static LruCache<String, Bitmap> sContactPhotoNumberCache;
- private static LruCache<Long, Bitmap> sContactPhotoIdCache;
- private static HashMap<String, String> sContactNameCache;
- private static HashMap<String, Integer> sContactIdCache;
- private static HashMap<String, String> sFormattedNumberCache;
- private static HashMap<String, String> sDisplayNameCache;
-
- /**
- * Create a round bitmap icon to represent the call. If a contact photo does not exist,
- * a letter tile will be used instead.
- */
- public static Bitmap createStreamCardSecondaryIcon(Context context, String number) {
- Resources res = context.getResources();
- Bitmap largeIcon
- = TelecomUtils.getContactPhotoFromNumber(context.getContentResolver(), number);
- if (largeIcon == null) {
- LetterTileDrawable ltd = new LetterTileDrawable(res);
- String name = TelecomUtils.getDisplayName(context, number);
- ltd.setContactDetails(name, number);
- ltd.setIsCircular(true);
- int size = res.getDimensionPixelSize(R.dimen.stream_card_secondary_icon_dimen);
- largeIcon = ltd.toBitmap(size);
- }
-
- return new CircleBitmapDrawable(res, largeIcon)
- .toBitmap(res.getDimensionPixelSize(R.dimen.stream_card_secondary_icon_dimen));
- }
-
-
- /**
- * Fetch contact photo by number from local cache.
- *
- * @param number
- * @return Contact photo if it's in the cache, otherwise null.
- */
- @Nullable
- public static Bitmap getCachedContactPhotoFromNumber(String number) {
- if (number == null) {
- return null;
- }
-
- if (sContactPhotoNumberCache == null) {
- sContactPhotoNumberCache = new LruCache<String, Bitmap>(LRU_CACHE_SIZE) {
- @Override
- protected int sizeOf(String key, Bitmap value) {
- return value.getByteCount();
- }
- };
- }
- return sContactPhotoNumberCache.get(number);
- }
-
- @WorkerThread
- public static Bitmap getContactPhotoFromNumber(ContentResolver contentResolver, String number) {
- if (number == null) {
- return null;
- }
-
- Bitmap photo = getCachedContactPhotoFromNumber(number);
- if (photo != null) {
- return photo;
- }
-
- int id = getContactIdFromNumber(contentResolver, number);
- if (id == 0) {
- return null;
- }
- photo = getContactPhotoFromId(contentResolver, id);
- if (photo != null) {
- sContactPhotoNumberCache.put(number, photo);
- }
- return photo;
- }
-
- /**
- * Return the contact id for the given contact id
- * @param id the contact id to get the photo for
- * @return the contact photo if it is found, null otherwise.
- */
- public static Bitmap getContactPhotoFromId(ContentResolver contentResolver, long id) {
- if (sContactPhotoIdCache == null) {
- sContactPhotoIdCache = new LruCache<Long, Bitmap>(LRU_CACHE_SIZE) {
- @Override
- protected int sizeOf(Long key, Bitmap value) {
- return value.getByteCount();
- }
- };
- } else if (sContactPhotoIdCache.get(id) != null) {
- return sContactPhotoIdCache.get(id);
- }
-
- Uri photoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
- InputStream photoDataStream = ContactsContract.Contacts.openContactPhotoInputStream(
- contentResolver, photoUri, true);
-
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferQualityOverSpeed = true;
- // Scaling will be handled by later. We shouldn't scale multiple times to avoid
- // quality lost due to multiple potential scaling up and down.
- options.inScaled = false;
-
- Rect nullPadding = null;
- Bitmap photo = BitmapFactory.decodeStream(photoDataStream, nullPadding, options);
- if (photo != null) {
- photo.setDensity(Bitmap.DENSITY_NONE);
- sContactPhotoIdCache.put(id, photo);
- }
- return photo;
- }
-
- /**
- * Return the contact id for the given phone number.
- * @param number Caller phone number
- * @return the contact id if it is found, 0 otherwise.
- */
- public static int getContactIdFromNumber(ContentResolver cr, String number) {
- if (number == null || number.isEmpty()) {
- return 0;
- }
- if (sContactIdCache == null) {
- sContactIdCache = new HashMap<>();
- } else if (sContactIdCache.containsKey(number)) {
- return sContactIdCache.get(number);
- }
-
- Uri uri = Uri.withAppendedPath(
- ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
- Uri.encode(number));
- Cursor cursor = cr.query(uri, CONTACT_ID_PROJECTION, null, null, null);
-
- try {
- if (cursor != null && cursor.moveToFirst()) {
- int id = cursor.getInt(cursor.getColumnIndex(ContactsContract.PhoneLookup._ID));
- sContactIdCache.put(number, id);
- return id;
- }
- }
- finally {
- if (cursor != null) {
- cursor.close();
- }
- }
- return 0;
- }
-
- public static String getDisplayName(Context context, String number) {
- return getDisplayName(context, number, (Uri)null);
- }
-
- public static String getDisplayName(Context context, Call call) {
- // A call might get created before its children are added. In that case, the display name
- // would go from "Unknown" to "Conference call" therefore we don't want to cache it.
- if (call.getChildren() != null && call.getChildren().size() > 0) {
- return context.getString(R.string.conference_call);
- }
- return getDisplayName(context, getNumber(call), getGatewayInfoOriginalAddress(call));
- }
-
- private static Uri getGatewayInfoOriginalAddress(Call call) {
- if (call == null || call.getDetails() == null) {
- return null;
- }
- GatewayInfo gatewayInfo = call.getDetails().getGatewayInfo();
-
- if (gatewayInfo != null && gatewayInfo.getOriginalAddress() != null) {
- return gatewayInfo.getGatewayAddress();
- }
- return null;
- }
-
- /**
- * Return the phone number of the call. This CAN return null under certain circumstances such
- * as if the incoming number is hidden.
- */
- public static String getNumber(Call call) {
- if (call == null || call.getDetails() == null) {
- return null;
- }
-
- Uri gatewayInfoOriginalAddress = getGatewayInfoOriginalAddress(call);
- if (gatewayInfoOriginalAddress != null) {
- return gatewayInfoOriginalAddress.getSchemeSpecificPart();
- }
-
- if (call.getDetails().getHandle() != null) {
- return call.getDetails().getHandle().getSchemeSpecificPart();
- }
- return null;
- }
-
- private static String getContactNameFromNumber(ContentResolver cr, String number) {
- if (sContactNameCache == null) {
- sContactNameCache = new HashMap<>();
- } else if (sContactNameCache.containsKey(number)) {
- return sContactNameCache.get(number);
- }
-
- Uri uri = Uri.withAppendedPath(
- ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
-
- Cursor cursor = null;
- String name = null;
- try {
- cursor = cr.query(uri,
- new String[] {ContactsContract.PhoneLookup.DISPLAY_NAME}, null, null, null);
- if (cursor != null && cursor.moveToFirst()) {
- name = cursor.getString(0);
- sContactNameCache.put(number, name);
- }
- } finally {
- if (cursor != null) {
- cursor.close();
- }
- }
- return name;
- }
-
- private static String getDisplayName(
- Context context, String number, Uri gatewayOriginalAddress) {
- if (sDisplayNameCache == null) {
- sDisplayNameCache = new HashMap<>();
- } else {
- if (sDisplayNameCache.containsKey(number)) {
- return sDisplayNameCache.get(number);
- }
- }
-
- if (TextUtils.isEmpty(number)) {
- return context.getString(R.string.unknown);
- }
- ContentResolver cr = context.getContentResolver();
- String name;
- if (number.equals(getVoicemailNumber(context))) {
- name = context.getString(R.string.voicemail);
- } else {
- name = getContactNameFromNumber(cr, number);
- }
-
- if (name == null) {
- name = getFormattedNumber(context, number);
- }
- if (name == null && gatewayOriginalAddress != null) {
- name = gatewayOriginalAddress.getSchemeSpecificPart();
- }
- if (name == null) {
- name = context.getString(R.string.unknown);
- }
- sDisplayNameCache.put(number, name);
- return name;
- }
-
- public static String getVoicemailNumber(Context context) {
- if (sVoicemailNumber == null) {
- TelephonyManager tm =
- (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- sVoicemailNumber = tm.getVoiceMailNumber();
- }
- return sVoicemailNumber;
- }
-
- public static String getFormattedNumber(Context context, @Nullable String number) {
- if (TextUtils.isEmpty(number)) {
- return "";
- }
-
- if (sFormattedNumberCache == null) {
- sFormattedNumberCache = new HashMap<>();
- } else {
- if (sFormattedNumberCache.containsKey(number)) {
- return sFormattedNumberCache.get(number);
- }
- }
-
- String countryIso = getSimRegionCode(context);
- String e164 = PhoneNumberUtils.formatNumberToE164(number, countryIso);
- String formattedNumber = PhoneNumberUtils.formatNumber(number, e164, countryIso);
- formattedNumber = TextUtils.isEmpty(formattedNumber) ? number : formattedNumber;
- sFormattedNumberCache.put(number, formattedNumber);
- return formattedNumber;
- }
-
- /**
- * Wrapper around TelephonyManager.getSimCountryIso() that will fallback to locale or USA ISOs
- * if it finds bogus data.
- */
- private static String getSimRegionCode(Context context) {
- TelephonyManager telephonyManager =
- (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
-
- // This can be null on some phones (and is null on robolectric default TelephonyManager)
- String countryIso = telephonyManager.getSimCountryIso();
- if (TextUtils.isEmpty(countryIso) || countryIso.length() != 2) {
- countryIso = Locale.getDefault().getCountry();
- if (countryIso == null || countryIso.length() != 2) {
- countryIso = "US";
- }
- }
-
- return countryIso.toUpperCase(Locale.US);
- }
-} \ No newline at end of file