Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.google.android.car.kitchensink.bluetooth; |
| 18 | |
Anthony Chen | d12cd77 | 2018-04-16 16:20:44 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 20 | import android.annotation.TargetApi; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 21 | import android.app.PendingIntent; |
| 22 | import android.bluetooth.BluetoothAdapter; |
| 23 | import android.bluetooth.BluetoothDevice; |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 24 | import android.bluetooth.BluetoothDevicePicker; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 25 | import android.bluetooth.BluetoothMapClient; |
| 26 | import android.bluetooth.BluetoothProfile; |
| 27 | import android.content.BroadcastReceiver; |
| 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
| 30 | import android.content.IntentFilter; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 32 | import android.net.Uri; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 33 | import android.os.Build; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 34 | import android.os.Bundle; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 35 | import android.telecom.PhoneAccount; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 36 | import android.util.Log; |
| 37 | import android.view.LayoutInflater; |
| 38 | import android.view.View; |
| 39 | import android.view.ViewGroup; |
| 40 | import android.widget.Button; |
| 41 | import android.widget.CheckBox; |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 42 | import android.widget.EditText; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 43 | import android.widget.TextView; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 44 | import android.widget.Toast; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 45 | |
Anthony Chen | d12cd77 | 2018-04-16 16:20:44 -0700 | [diff] [blame] | 46 | import androidx.annotation.Nullable; |
| 47 | import androidx.fragment.app.Fragment; |
| 48 | |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 49 | import com.google.android.car.kitchensink.KitchenSinkActivity; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 50 | import com.google.android.car.kitchensink.R; |
| 51 | |
| 52 | import java.util.List; |
| 53 | |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 54 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 55 | public class MapMceTestFragment extends Fragment { |
| 56 | static final String MESSAGE_TO_SEND = "Im Busy Driving"; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 57 | static final String NEW_MESSAGE_TO_SEND = "This is new msg"; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 58 | private static final String TAG = "CAR.BLUETOOTH.KS"; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 59 | private static final int SEND_SMS_PERMISSIONS_REQUEST = 1; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 60 | BluetoothMapClient mMapProfile; |
| 61 | BluetoothAdapter mBluetoothAdapter; |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 62 | Button mDevicePicker; |
| 63 | Button mDeviceDisconnect; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 64 | TextView mMessage; |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 65 | EditText mOriginator; |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 66 | EditText mSmsTelNum; |
Joseph Pirozzo | a90995a | 2016-10-13 09:48:50 -0700 | [diff] [blame] | 67 | TextView mOriginatorDisplayName; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 68 | CheckBox mSent; |
| 69 | CheckBox mDelivered; |
| 70 | TextView mBluetoothDevice; |
| 71 | PendingIntent mSentIntent; |
| 72 | PendingIntent mDeliveredIntent; |
| 73 | NotificationReceiver mTransmissionStatusReceiver; |
| 74 | Object mLock = new Object(); |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 75 | private KitchenSinkActivity mActivity; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 76 | private Intent mSendIntent; |
| 77 | private Intent mDeliveryIntent; |
Vasu Nori | 937352c | 2018-09-26 17:14:04 -0700 | [diff] [blame^] | 78 | EditText mUploadingSupportedFeatureText; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 79 | |
| 80 | @Override |
| 81 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, |
| 82 | @Nullable Bundle savedInstanceState) { |
| 83 | View v = inflater.inflate(R.layout.sms_received, container, false); |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 84 | mActivity = (KitchenSinkActivity) getHost(); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 85 | Button reply = (Button) v.findViewById(R.id.reply); |
| 86 | Button checkMessages = (Button) v.findViewById(R.id.check_messages); |
| 87 | mBluetoothDevice = (TextView) v.findViewById(R.id.bluetoothDevice); |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 88 | Button sendNewMsg = (Button) v.findViewById(R.id.sms_new_message); |
| 89 | mSmsTelNum = (EditText) v.findViewById(R.id.sms_tel_num); |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 90 | mOriginator = (EditText) v.findViewById(R.id.messageOriginator); |
Joseph Pirozzo | a90995a | 2016-10-13 09:48:50 -0700 | [diff] [blame] | 91 | mOriginatorDisplayName = (TextView) v.findViewById(R.id.messageOriginatorDisplayName); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 92 | mSent = (CheckBox) v.findViewById(R.id.sent_checkbox); |
| 93 | mDelivered = (CheckBox) v.findViewById(R.id.delivered_checkbox); |
| 94 | mSendIntent = new Intent(BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY); |
| 95 | mDeliveryIntent = new Intent(BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY); |
| 96 | mMessage = (TextView) v.findViewById(R.id.messageContent); |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 97 | mDevicePicker = (Button) v.findViewById(R.id.bluetooth_pick_device); |
| 98 | mDeviceDisconnect = (Button) v.findViewById(R.id.bluetooth_disconnect_device); |
Vasu Nori | 937352c | 2018-09-26 17:14:04 -0700 | [diff] [blame^] | 99 | Button uploadingFeatureValue = (Button) v.findViewById(R.id.uploading_supported_feature); |
| 100 | mUploadingSupportedFeatureText = |
| 101 | (EditText) v.findViewById(R.id.uploading_supported_feature_value); |
| 102 | |
| 103 | uploadingFeatureValue.setOnClickListener(new View.OnClickListener() { |
| 104 | @Override |
| 105 | public void onClick(View view) { |
| 106 | int value = getUploadingFeatureValue(); |
| 107 | mUploadingSupportedFeatureText.setText(value + ""); |
| 108 | } |
| 109 | }); |
| 110 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 111 | //TODO add manual entry option for phone number |
| 112 | reply.setOnClickListener(new View.OnClickListener() { |
| 113 | @Override |
| 114 | public void onClick(View view) { |
| 115 | sendMessage(new Uri[]{Uri.parse(mOriginator.getText().toString())}, |
| 116 | MESSAGE_TO_SEND); |
| 117 | } |
| 118 | }); |
| 119 | |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 120 | sendNewMsg.setOnClickListener(new View.OnClickListener() { |
| 121 | @Override |
| 122 | public void onClick(View view) { |
| 123 | String s = mSmsTelNum.getText().toString(); |
| 124 | Toast.makeText(getContext(), "sending msg to " + s, Toast.LENGTH_SHORT).show(); |
| 125 | Uri.Builder builder = new Uri.Builder(); |
| 126 | Uri uri = builder.appendPath(s).scheme(PhoneAccount.SCHEME_TEL).build(); |
| 127 | sendMessage(new Uri[]{uri}, NEW_MESSAGE_TO_SEND); |
| 128 | } |
| 129 | }); |
| 130 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 131 | checkMessages.setOnClickListener(new View.OnClickListener() { |
| 132 | @Override |
| 133 | public void onClick(View view) { |
| 134 | getMessages(); |
| 135 | } |
| 136 | }); |
| 137 | |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 138 | // Pick a bluetooth device |
| 139 | mDevicePicker.setOnClickListener(new View.OnClickListener() { |
| 140 | @Override |
| 141 | public void onClick(View view) { |
| 142 | launchDevicePicker(); |
| 143 | } |
| 144 | }); |
| 145 | mDeviceDisconnect.setOnClickListener(new View.OnClickListener() { |
| 146 | @Override |
| 147 | public void onClick(View view) { |
| 148 | disconnectDevice(mBluetoothDevice.getText().toString()); |
| 149 | } |
| 150 | }); |
| 151 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 152 | mTransmissionStatusReceiver = new NotificationReceiver(); |
| 153 | return v; |
| 154 | } |
| 155 | |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 156 | void launchDevicePicker() { |
| 157 | IntentFilter filter = new IntentFilter(); |
| 158 | filter.addAction(BluetoothDevicePicker.ACTION_DEVICE_SELECTED); |
| 159 | getContext().registerReceiver(mPickerReceiver, filter); |
| 160 | |
| 161 | Intent intent = new Intent(BluetoothDevicePicker.ACTION_LAUNCH); |
| 162 | intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 163 | getContext().startActivity(intent); |
| 164 | } |
| 165 | |
| 166 | void disconnectDevice(String device) { |
| 167 | mMapProfile.disconnect(mBluetoothAdapter.getRemoteDevice((device))); |
| 168 | } |
| 169 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 170 | @Override |
| 171 | public void onResume() { |
| 172 | super.onResume(); |
| 173 | |
| 174 | mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); |
| 175 | mBluetoothAdapter.getProfileProxy(getContext(), new MapServiceListener(), |
| 176 | BluetoothProfile.MAP_CLIENT); |
| 177 | |
| 178 | IntentFilter intentFilter = new IntentFilter(); |
| 179 | intentFilter.addAction(BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY); |
| 180 | intentFilter.addAction(BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY); |
| 181 | intentFilter.addAction(BluetoothMapClient.ACTION_MESSAGE_RECEIVED); |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 182 | intentFilter.addAction(BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 183 | getContext().registerReceiver(mTransmissionStatusReceiver, intentFilter); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public void onPause() { |
| 188 | super.onPause(); |
| 189 | getContext().unregisterReceiver(mTransmissionStatusReceiver); |
| 190 | } |
| 191 | |
| 192 | private void getMessages() { |
| 193 | synchronized (mLock) { |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 194 | BluetoothDevice remoteDevice; |
| 195 | try { |
| 196 | remoteDevice = mBluetoothAdapter.getRemoteDevice( |
| 197 | mBluetoothDevice.getText().toString()); |
| 198 | } catch (java.lang.IllegalArgumentException e) { |
| 199 | Log.e(TAG, e.toString()); |
| 200 | return; |
| 201 | } |
| 202 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 203 | if (mMapProfile != null) { |
| 204 | Log.d(TAG, "Getting Messages"); |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 205 | mMapProfile.getUnreadMessages(remoteDevice); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
Vasu Nori | 937352c | 2018-09-26 17:14:04 -0700 | [diff] [blame^] | 210 | private int getUploadingFeatureValue() { |
| 211 | synchronized (mLock) { |
| 212 | BluetoothDevice remoteDevice; |
| 213 | try { |
| 214 | remoteDevice = mBluetoothAdapter.getRemoteDevice( |
| 215 | mBluetoothDevice.getText().toString()); |
| 216 | } catch (java.lang.IllegalArgumentException e) { |
| 217 | Log.e(TAG, e.toString()); |
| 218 | return -1; |
| 219 | } |
| 220 | |
| 221 | if (mMapProfile != null) { |
| 222 | Log.d(TAG, "getUploadingFeatureValue"); |
| 223 | return (mMapProfile.isUploadingSupported(remoteDevice)) ? 1 : 0; |
| 224 | } |
| 225 | return -1; |
| 226 | } |
| 227 | } |
| 228 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 229 | private void sendMessage(Uri[] recipients, String message) { |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 230 | if (mActivity.checkSelfPermission(Manifest.permission.SEND_SMS) |
| 231 | != PackageManager.PERMISSION_GRANTED) { |
| 232 | Log.d(TAG,"Don't have SMS permission in kitchesink app. Requesting it"); |
| 233 | mActivity.requestPermissions(new String[]{Manifest.permission.SEND_SMS}, |
| 234 | SEND_SMS_PERMISSIONS_REQUEST); |
| 235 | Toast.makeText(getContext(), "Try again after granting SEND_SMS perm!", |
| 236 | Toast.LENGTH_SHORT).show(); |
| 237 | return; |
| 238 | } |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 239 | synchronized (mLock) { |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 240 | BluetoothDevice remoteDevice; |
| 241 | try { |
| 242 | remoteDevice = mBluetoothAdapter.getRemoteDevice( |
| 243 | mBluetoothDevice.getText().toString()); |
| 244 | } catch (java.lang.IllegalArgumentException e) { |
| 245 | Log.e(TAG, e.toString()); |
| 246 | return; |
| 247 | } |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 248 | mSent.setChecked(false); |
| 249 | mDelivered.setChecked(false); |
| 250 | if (mMapProfile != null) { |
| 251 | Log.d(TAG, "Sending reply"); |
| 252 | if (recipients == null) { |
| 253 | Log.d(TAG, "Recipients is null"); |
| 254 | return; |
| 255 | } |
| 256 | if (mBluetoothDevice == null) { |
| 257 | Log.d(TAG, "BluetoothDevice is null"); |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | mSentIntent = PendingIntent.getBroadcast(getContext(), 0, mSendIntent, |
| 262 | PendingIntent.FLAG_ONE_SHOT); |
| 263 | mDeliveredIntent = PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent, |
| 264 | PendingIntent.FLAG_ONE_SHOT); |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 265 | Log.d(TAG,"Sending message in kitchesink app: " + message); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 266 | mMapProfile.sendMessage( |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 267 | remoteDevice, |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 268 | recipients, message, mSentIntent, mDeliveredIntent); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
Vasu Nori | 0ab0af5 | 2017-12-06 14:39:21 -0800 | [diff] [blame] | 273 | @Override |
| 274 | public void onRequestPermissionsResult(int requestCode, String[] permissions, |
| 275 | int[] grantResults) { |
| 276 | Log.d(TAG, "onRequestPermissionsResult reqCode=" + requestCode); |
| 277 | if (SEND_SMS_PERMISSIONS_REQUEST == requestCode) { |
| 278 | for (int i=0; i<permissions.length; i++) { |
| 279 | if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { |
| 280 | if (permissions[i] == Manifest.permission.SEND_SMS) { |
| 281 | Log.d(TAG, "Got the SEND_SMS perm"); |
| 282 | return; |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 289 | class MapServiceListener implements BluetoothProfile.ServiceListener { |
| 290 | @Override |
| 291 | public void onServiceConnected(int profile, BluetoothProfile proxy) { |
| 292 | synchronized (mLock) { |
| 293 | mMapProfile = (BluetoothMapClient) proxy; |
| 294 | List<BluetoothDevice> connectedDevices = proxy.getConnectedDevices(); |
| 295 | if (connectedDevices.size() > 0) { |
| 296 | mBluetoothDevice.setText(connectedDevices.get(0).getAddress()); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public void onServiceDisconnected(int profile) { |
| 303 | synchronized (mLock) { |
| 304 | mMapProfile = null; |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | private class NotificationReceiver extends BroadcastReceiver { |
| 310 | @Override |
| 311 | public void onReceive(Context context, Intent intent) { |
| 312 | String action = intent.getAction(); |
| 313 | synchronized (mLock) { |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 314 | if (action.equals(BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED)) { |
| 315 | if (intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0) |
| 316 | == BluetoothProfile.STATE_CONNECTED) { |
| 317 | mBluetoothDevice.setText(((BluetoothDevice) intent.getParcelableExtra( |
| 318 | BluetoothDevice.EXTRA_DEVICE)).getAddress()); |
| 319 | } else if (intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0) |
| 320 | == BluetoothProfile.STATE_DISCONNECTED) { |
| 321 | mBluetoothDevice.setText("Disconnected"); |
| 322 | } |
| 323 | } else if (action.equals(BluetoothMapClient.ACTION_MESSAGE_SENT_SUCCESSFULLY)) { |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 324 | mSent.setChecked(true); |
| 325 | } else if (action.equals( |
| 326 | BluetoothMapClient.ACTION_MESSAGE_DELIVERED_SUCCESSFULLY)) { |
| 327 | mDelivered.setChecked(true); |
| 328 | } else if (action.equals(BluetoothMapClient.ACTION_MESSAGE_RECEIVED)) { |
Srinivas Visvanathan | 3bb97c6 | 2017-03-08 16:15:07 -0800 | [diff] [blame] | 329 | String senderUri = |
| 330 | intent.getStringExtra(BluetoothMapClient.EXTRA_SENDER_CONTACT_URI); |
| 331 | if (senderUri == null) { |
| 332 | senderUri = "<null>"; |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Srinivas Visvanathan | 3bb97c6 | 2017-03-08 16:15:07 -0800 | [diff] [blame] | 335 | String senderName = intent.getStringExtra( |
Srinivas Visvanathan | 6b90bbf | 2017-03-03 10:01:09 -0800 | [diff] [blame] | 336 | BluetoothMapClient.EXTRA_SENDER_CONTACT_NAME); |
Srinivas Visvanathan | 3bb97c6 | 2017-03-08 16:15:07 -0800 | [diff] [blame] | 337 | if (senderName == null) { |
| 338 | senderName = "<null>"; |
Joseph Pirozzo | a90995a | 2016-10-13 09:48:50 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 341 | mMessage.setText(intent.getStringExtra(android.content.Intent.EXTRA_TEXT)); |
Srinivas Visvanathan | 3bb97c6 | 2017-03-08 16:15:07 -0800 | [diff] [blame] | 342 | mOriginator.setText(senderUri); |
| 343 | mOriginatorDisplayName.setText(senderName); |
Joseph Pirozzo | caa94c6 | 2016-10-06 09:29:43 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | } |
| 347 | } |
Joseph Pirozzo | 9cddbe9 | 2017-02-08 18:23:56 -0800 | [diff] [blame] | 348 | |
| 349 | private final BroadcastReceiver mPickerReceiver = new BroadcastReceiver() { |
| 350 | @Override |
| 351 | public void onReceive(Context context, Intent intent) { |
| 352 | String action = intent.getAction(); |
| 353 | |
| 354 | Log.v(TAG, "mPickerReceiver got " + action); |
| 355 | |
| 356 | if (BluetoothDevicePicker.ACTION_DEVICE_SELECTED.equals(action)) { |
| 357 | BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); |
| 358 | Log.v(TAG, "mPickerReceiver got " + device); |
| 359 | mMapProfile.connect(device); |
| 360 | |
| 361 | // The receiver can now be disabled. |
| 362 | getContext().unregisterReceiver(mPickerReceiver); |
| 363 | } |
| 364 | } |
| 365 | }; |
Anthony Chen | d12cd77 | 2018-04-16 16:20:44 -0700 | [diff] [blame] | 366 | } |