blob: 8cd46c2836d7d1a6fd2aef8589b1f0841c2011b1 [file] [log] [blame]
Phil Burk5ed503c2017-02-01 09:38:15 -08001/*
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#define LOG_TAG "AAudioService"
18//#define LOG_NDEBUG 0
19#include <utils/Log.h>
20
Phil Burk523b3042017-09-13 13:03:08 -070021#include <iomanip>
22#include <iostream>
Andy Hung47c5e532017-06-26 18:28:00 -070023#include <sstream>
Phil Burk5ed503c2017-02-01 09:38:15 -080024
Phil Burka4eb0d82017-04-12 15:44:06 -070025#include <aaudio/AAudio.h>
Phil Burkc0c70e32017-02-09 13:18:38 -080026#include <mediautils/SchedulingPolicyService.h>
27#include <utils/String16.h>
Phil Burk5ed503c2017-02-01 09:38:15 -080028
Phil Burkc0c70e32017-02-09 13:18:38 -080029#include "binding/AAudioServiceMessage.h"
Phil Burk11e8d332017-05-24 09:59:02 -070030#include "AAudioClientTracker.h"
Andy Hung47c5e532017-06-26 18:28:00 -070031#include "AAudioEndpointManager.h"
Phil Burk5ed503c2017-02-01 09:38:15 -080032#include "AAudioService.h"
Phil Burkc0c70e32017-02-09 13:18:38 -080033#include "AAudioServiceStreamMMAP.h"
34#include "AAudioServiceStreamShared.h"
Phil Burkc0c70e32017-02-09 13:18:38 -080035#include "binding/IAAudioService.h"
dimitryd81a84a2019-07-17 13:55:16 +020036#include "core/AudioGlobal.h"
Andy Hung47c5e532017-06-26 18:28:00 -070037#include "ServiceUtilities.h"
Phil Burk5ed503c2017-02-01 09:38:15 -080038
39using namespace android;
40using namespace aaudio;
41
Phil Burk91692942017-06-30 12:23:05 -070042#define MAX_STREAMS_PER_PROCESS 8
43
Phil Burk523b3042017-09-13 13:03:08 -070044using android::AAudioService;
Phil Burk5ed503c2017-02-01 09:38:15 -080045
46android::AAudioService::AAudioService()
47 : BnAAudioService() {
Eric Laurenta54f1282017-07-01 19:39:32 -070048 mAudioClient.clientUid = getuid(); // TODO consider using geteuid()
49 mAudioClient.clientPid = getpid();
50 mAudioClient.packageName = String16("");
Phil Burk11e8d332017-05-24 09:59:02 -070051 AAudioClientTracker::getInstance().setAAudioService(this);
Phil Burk5ed503c2017-02-01 09:38:15 -080052}
53
54AAudioService::~AAudioService() {
55}
56
Andy Hung47c5e532017-06-26 18:28:00 -070057status_t AAudioService::dump(int fd, const Vector<String16>& args) {
58 std::string result;
59
60 if (!dumpAllowed()) {
61 std::stringstream ss;
Andy Hung6357b5f2018-10-22 19:47:04 -070062 ss << "Permission Denial: can't dump AAudioService from pid="
Andy Hung47c5e532017-06-26 18:28:00 -070063 << IPCThreadState::self()->getCallingPid() << ", uid="
64 << IPCThreadState::self()->getCallingUid() << "\n";
65 result = ss.str();
66 ALOGW("%s", result.c_str());
67 } else {
Phil Burk523b3042017-09-13 13:03:08 -070068 result = "------------ AAudio Service ------------\n"
69 + mStreamTracker.dump()
Phil Burk4501b352017-06-29 18:12:36 -070070 + AAudioClientTracker::getInstance().dump()
71 + AAudioEndpointManager::getInstance().dump();
Andy Hung47c5e532017-06-26 18:28:00 -070072 }
73 (void)write(fd, result.c_str(), result.size());
74 return NO_ERROR;
75}
76
Phil Burk11e8d332017-05-24 09:59:02 -070077void AAudioService::registerClient(const sp<IAAudioClient>& client) {
78 pid_t pid = IPCThreadState::self()->getCallingPid();
79 AAudioClientTracker::getInstance().registerClient(pid, client);
80}
81
Phil Burkc0c70e32017-02-09 13:18:38 -080082aaudio_handle_t AAudioService::openStream(const aaudio::AAudioStreamRequest &request,
83 aaudio::AAudioStreamConfiguration &configurationOutput) {
84 aaudio_result_t result = AAUDIO_OK;
Phil Burk11e8d332017-05-24 09:59:02 -070085 sp<AAudioServiceStreamBase> serviceStream;
Phil Burkc0c70e32017-02-09 13:18:38 -080086 const AAudioStreamConfiguration &configurationInput = request.getConstantConfiguration();
Phil Burk71f35bb2017-04-13 16:05:07 -070087 bool sharingModeMatchRequired = request.isSharingModeMatchRequired();
Phil Burkc0c70e32017-02-09 13:18:38 -080088 aaudio_sharing_mode_t sharingMode = configurationInput.getSharingMode();
Phil Burkc0c70e32017-02-09 13:18:38 -080089
Phil Burk91692942017-06-30 12:23:05 -070090 // Enforce limit on client processes.
91 pid_t pid = request.getProcessId();
Eric Laurenta54f1282017-07-01 19:39:32 -070092 if (pid != mAudioClient.clientPid) {
Phil Burk91692942017-06-30 12:23:05 -070093 int32_t count = AAudioClientTracker::getInstance().getStreamCount(pid);
94 if (count >= MAX_STREAMS_PER_PROCESS) {
Phil Burkfbf031e2017-10-12 15:58:31 -070095 ALOGE("openStream(): exceeded max streams per process %d >= %d",
Phil Burk91692942017-06-30 12:23:05 -070096 count, MAX_STREAMS_PER_PROCESS);
97 return AAUDIO_ERROR_UNAVAILABLE;
98 }
99 }
100
Phil Burkc0c70e32017-02-09 13:18:38 -0800101 if (sharingMode != AAUDIO_SHARING_MODE_EXCLUSIVE && sharingMode != AAUDIO_SHARING_MODE_SHARED) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700102 ALOGE("openStream(): unrecognized sharing mode = %d", sharingMode);
Phil Burkc0c70e32017-02-09 13:18:38 -0800103 return AAUDIO_ERROR_ILLEGAL_ARGUMENT;
104 }
105
106 if (sharingMode == AAUDIO_SHARING_MODE_EXCLUSIVE) {
Eric Laurenta54f1282017-07-01 19:39:32 -0700107 // only trust audioserver for in service indication
108 bool inService = false;
109 if (mAudioClient.clientPid == IPCThreadState::self()->getCallingPid() &&
110 mAudioClient.clientUid == IPCThreadState::self()->getCallingUid()) {
111 inService = request.isInService();
112 }
Phil Burk39f02dd2017-08-04 09:13:31 -0700113 serviceStream = new AAudioServiceStreamMMAP(*this, inService);
114 result = serviceStream->open(request);
Phil Burkc0c70e32017-02-09 13:18:38 -0800115 if (result != AAUDIO_OK) {
Phil Burk39f02dd2017-08-04 09:13:31 -0700116 // Clear it so we can possibly fall back to using a shared stream.
Phil Burkfbf031e2017-10-12 15:58:31 -0700117 ALOGW("openStream(), could not open in EXCLUSIVE mode");
Phil Burk11e8d332017-05-24 09:59:02 -0700118 serviceStream.clear();
Phil Burkc0c70e32017-02-09 13:18:38 -0800119 }
120 }
121
122 // if SHARED requested or if EXCLUSIVE failed
Phil Burk71f35bb2017-04-13 16:05:07 -0700123 if (sharingMode == AAUDIO_SHARING_MODE_SHARED
Phil Burk523b3042017-09-13 13:03:08 -0700124 || (serviceStream.get() == nullptr && !sharingModeMatchRequired)) {
Phil Burkc0c70e32017-02-09 13:18:38 -0800125 serviceStream = new AAudioServiceStreamShared(*this);
Phil Burk39f02dd2017-08-04 09:13:31 -0700126 result = serviceStream->open(request);
Phil Burkc0c70e32017-02-09 13:18:38 -0800127 }
128
129 if (result != AAUDIO_OK) {
Phil Burk11e8d332017-05-24 09:59:02 -0700130 serviceStream.clear();
Phil Burkfbf031e2017-10-12 15:58:31 -0700131 ALOGE("openStream(): failed, return %d = %s",
dimitryd81a84a2019-07-17 13:55:16 +0200132 result, AudioGlobal_convertResultToText(result));
Phil Burk5ed503c2017-02-01 09:38:15 -0800133 return result;
134 } else {
Phil Burk523b3042017-09-13 13:03:08 -0700135 aaudio_handle_t handle = mStreamTracker.addStreamForHandle(serviceStream.get());
Phil Burkfbf031e2017-10-12 15:58:31 -0700136 ALOGD("openStream(): handle = 0x%08X", handle);
Phil Burk523b3042017-09-13 13:03:08 -0700137 serviceStream->setHandle(handle);
138 pid_t pid = request.getProcessId();
139 AAudioClientTracker::getInstance().registerClientStream(pid, serviceStream);
140 configurationOutput.copyFrom(*serviceStream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800141 return handle;
142 }
143}
144
Phil Burk94862522017-09-13 21:31:36 -0700145// If a close request is pending then close the stream
146bool AAudioService::releaseStream(const sp<AAudioServiceStreamBase> &serviceStream) {
147 bool closed = false;
Phil Burk2fe718b2018-05-14 12:28:32 -0700148 // decrementAndRemoveStreamByHandle() uses a lock so that if there are two simultaneous closes
149 // then only one will get the pointer and do the close.
150 sp<AAudioServiceStreamBase> foundStream = mStreamTracker.decrementAndRemoveStreamByHandle(
151 serviceStream->getHandle());
152 if (foundStream.get() != nullptr) {
153 foundStream->close();
154 pid_t pid = foundStream->getOwnerProcessId();
155 AAudioClientTracker::getInstance().unregisterClientStream(pid, foundStream);
Phil Burk94862522017-09-13 21:31:36 -0700156 closed = true;
157 }
158 return closed;
159}
160
161aaudio_result_t AAudioService::checkForPendingClose(
162 const sp<AAudioServiceStreamBase> &serviceStream,
163 aaudio_result_t defaultResult) {
164 return releaseStream(serviceStream) ? AAUDIO_ERROR_INVALID_STATE : defaultResult;
165}
166
Phil Burk5ed503c2017-02-01 09:38:15 -0800167aaudio_result_t AAudioService::closeStream(aaudio_handle_t streamHandle) {
Phil Burk98d6d922017-07-06 11:52:45 -0700168 // Check permission and ownership first.
169 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
Phil Burk523b3042017-09-13 13:03:08 -0700170 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700171 ALOGE("closeStream(0x%0x), illegal stream handle", streamHandle);
Phil Burk91692942017-06-30 12:23:05 -0700172 return AAUDIO_ERROR_INVALID_HANDLE;
173 }
174
Phil Burk94862522017-09-13 21:31:36 -0700175 pid_t pid = serviceStream->getOwnerProcessId();
176 AAudioClientTracker::getInstance().unregisterClientStream(pid, serviceStream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800177
Phil Burk2fe718b2018-05-14 12:28:32 -0700178 serviceStream->markCloseNeeded();
Phil Burk94862522017-09-13 21:31:36 -0700179 (void) releaseStream(serviceStream);
180 return AAUDIO_OK;
181}
Phil Burk523b3042017-09-13 13:03:08 -0700182
183sp<AAudioServiceStreamBase> AAudioService::convertHandleToServiceStream(
184 aaudio_handle_t streamHandle) {
Phil Burk2fe718b2018-05-14 12:28:32 -0700185 sp<AAudioServiceStreamBase> serviceStream = mStreamTracker.getStreamByHandleAndIncrement(
186 streamHandle);
Phil Burk523b3042017-09-13 13:03:08 -0700187 if (serviceStream.get() != nullptr) {
Phil Burk2ac035f2017-06-23 14:51:14 -0700188 // Only allow owner or the aaudio service to access the stream.
189 const uid_t callingUserId = IPCThreadState::self()->getCallingUid();
190 const uid_t ownerUserId = serviceStream->getOwnerUserId();
191 bool callerOwnsIt = callingUserId == ownerUserId;
Eric Laurenta54f1282017-07-01 19:39:32 -0700192 bool serverCalling = callingUserId == mAudioClient.clientUid;
193 bool serverOwnsIt = ownerUserId == mAudioClient.clientUid;
Phil Burk2ac035f2017-06-23 14:51:14 -0700194 bool allowed = callerOwnsIt || serverCalling || serverOwnsIt;
195 if (!allowed) {
196 ALOGE("AAudioService: calling uid %d cannot access stream 0x%08X owned by %d",
197 callingUserId, streamHandle, ownerUserId);
Phil Burk2fe718b2018-05-14 12:28:32 -0700198 // We incremented the reference count so we must check if it needs to be closed.
199 checkForPendingClose(serviceStream, AAUDIO_OK);
Phil Burk94862522017-09-13 21:31:36 -0700200 serviceStream.clear();
Phil Burk2ac035f2017-06-23 14:51:14 -0700201 }
202 }
203 return serviceStream;
Phil Burk5ed503c2017-02-01 09:38:15 -0800204}
205
206aaudio_result_t AAudioService::getStreamDescription(
207 aaudio_handle_t streamHandle,
208 aaudio::AudioEndpointParcelable &parcelable) {
Phil Burk523b3042017-09-13 13:03:08 -0700209 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
210 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700211 ALOGE("getStreamDescription(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800212 return AAUDIO_ERROR_INVALID_HANDLE;
213 }
Phil Burk523b3042017-09-13 13:03:08 -0700214
Phil Burkc0c70e32017-02-09 13:18:38 -0800215 aaudio_result_t result = serviceStream->getDescription(parcelable);
Phil Burkc0c70e32017-02-09 13:18:38 -0800216 // parcelable.dump();
Phil Burk94862522017-09-13 21:31:36 -0700217 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800218}
219
220aaudio_result_t AAudioService::startStream(aaudio_handle_t streamHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700221 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
222 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700223 ALOGE("startStream(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800224 return AAUDIO_ERROR_INVALID_HANDLE;
225 }
Eric Laurenta54f1282017-07-01 19:39:32 -0700226
Phil Burk94862522017-09-13 21:31:36 -0700227 aaudio_result_t result = serviceStream->start();
228 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800229}
230
231aaudio_result_t AAudioService::pauseStream(aaudio_handle_t streamHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700232 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
233 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700234 ALOGE("pauseStream(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800235 return AAUDIO_ERROR_INVALID_HANDLE;
236 }
237 aaudio_result_t result = serviceStream->pause();
Phil Burk94862522017-09-13 21:31:36 -0700238 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800239}
240
Phil Burk71f35bb2017-04-13 16:05:07 -0700241aaudio_result_t AAudioService::stopStream(aaudio_handle_t streamHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700242 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
243 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700244 ALOGE("stopStream(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk71f35bb2017-04-13 16:05:07 -0700245 return AAUDIO_ERROR_INVALID_HANDLE;
246 }
247 aaudio_result_t result = serviceStream->stop();
Phil Burk94862522017-09-13 21:31:36 -0700248 return checkForPendingClose(serviceStream, result);
Phil Burk71f35bb2017-04-13 16:05:07 -0700249}
250
Phil Burk5ed503c2017-02-01 09:38:15 -0800251aaudio_result_t AAudioService::flushStream(aaudio_handle_t streamHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700252 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
253 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700254 ALOGE("flushStream(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800255 return AAUDIO_ERROR_INVALID_HANDLE;
256 }
Phil Burk94862522017-09-13 21:31:36 -0700257 aaudio_result_t result = serviceStream->flush();
258 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800259}
260
261aaudio_result_t AAudioService::registerAudioThread(aaudio_handle_t streamHandle,
Phil Burk11e8d332017-05-24 09:59:02 -0700262 pid_t clientThreadId,
263 int64_t periodNanoseconds) {
Phil Burk94862522017-09-13 21:31:36 -0700264 aaudio_result_t result = AAUDIO_OK;
Phil Burk523b3042017-09-13 13:03:08 -0700265 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
266 if (serviceStream.get() == nullptr) {
Phil Burkfbf031e2017-10-12 15:58:31 -0700267 ALOGE("registerAudioThread(), illegal stream handle = 0x%0x", streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800268 return AAUDIO_ERROR_INVALID_HANDLE;
269 }
270 if (serviceStream->getRegisteredThread() != AAudioServiceStreamBase::ILLEGAL_THREAD_ID) {
Phil Burk94862522017-09-13 21:31:36 -0700271 ALOGE("AAudioService::registerAudioThread(), thread already registered");
272 result = AAUDIO_ERROR_INVALID_STATE;
Phil Burk5ed503c2017-02-01 09:38:15 -0800273 } else {
Phil Burk94862522017-09-13 21:31:36 -0700274 const pid_t ownerPid = IPCThreadState::self()->getCallingPid(); // TODO review
275 serviceStream->setRegisteredThread(clientThreadId);
276 int err = android::requestPriority(ownerPid, clientThreadId,
277 DEFAULT_AUDIO_PRIORITY, true /* isForApp */);
278 if (err != 0) {
279 ALOGE("AAudioService::registerAudioThread(%d) failed, errno = %d, priority = %d",
280 clientThreadId, errno, DEFAULT_AUDIO_PRIORITY);
281 result = AAUDIO_ERROR_INTERNAL;
282 }
Phil Burk5ed503c2017-02-01 09:38:15 -0800283 }
Phil Burk94862522017-09-13 21:31:36 -0700284 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800285}
286
287aaudio_result_t AAudioService::unregisterAudioThread(aaudio_handle_t streamHandle,
Phil Burkc0c70e32017-02-09 13:18:38 -0800288 pid_t clientThreadId) {
Phil Burk94862522017-09-13 21:31:36 -0700289 aaudio_result_t result = AAUDIO_OK;
Phil Burk523b3042017-09-13 13:03:08 -0700290 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
291 if (serviceStream.get() == nullptr) {
Phil Burkbbd52862018-04-13 11:37:42 -0700292 ALOGE("%s(), illegal stream handle = 0x%0x", __func__, streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800293 return AAUDIO_ERROR_INVALID_HANDLE;
294 }
295 if (serviceStream->getRegisteredThread() != clientThreadId) {
Phil Burkbbd52862018-04-13 11:37:42 -0700296 ALOGE("%s(), wrong thread", __func__);
Phil Burk94862522017-09-13 21:31:36 -0700297 result = AAUDIO_ERROR_ILLEGAL_ARGUMENT;
298 } else {
299 serviceStream->setRegisteredThread(0);
Phil Burk5ed503c2017-02-01 09:38:15 -0800300 }
Phil Burk94862522017-09-13 21:31:36 -0700301 return checkForPendingClose(serviceStream, result);
Phil Burk5ed503c2017-02-01 09:38:15 -0800302}
Eric Laurenta54f1282017-07-01 19:39:32 -0700303
304aaudio_result_t AAudioService::startClient(aaudio_handle_t streamHandle,
305 const android::AudioClient& client,
306 audio_port_handle_t *clientHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700307 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
308 if (serviceStream.get() == nullptr) {
Phil Burkbbd52862018-04-13 11:37:42 -0700309 ALOGE("%s(), illegal stream handle = 0x%0x", __func__, streamHandle);
Eric Laurenta54f1282017-07-01 19:39:32 -0700310 return AAUDIO_ERROR_INVALID_HANDLE;
311 }
Phil Burk94862522017-09-13 21:31:36 -0700312 aaudio_result_t result = serviceStream->startClient(client, clientHandle);
313 return checkForPendingClose(serviceStream, result);
Eric Laurenta54f1282017-07-01 19:39:32 -0700314}
315
316aaudio_result_t AAudioService::stopClient(aaudio_handle_t streamHandle,
Phil Burkbbd52862018-04-13 11:37:42 -0700317 audio_port_handle_t portHandle) {
Phil Burk523b3042017-09-13 13:03:08 -0700318 sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
319 if (serviceStream.get() == nullptr) {
Phil Burkbbd52862018-04-13 11:37:42 -0700320 ALOGE("%s(), illegal stream handle = 0x%0x", __func__, streamHandle);
Eric Laurenta54f1282017-07-01 19:39:32 -0700321 return AAUDIO_ERROR_INVALID_HANDLE;
322 }
Phil Burkbbd52862018-04-13 11:37:42 -0700323 aaudio_result_t result = serviceStream->stopClient(portHandle);
324 return checkForPendingClose(serviceStream, result);
325}
326
327// This is only called internally when AudioFlinger wants to tear down a stream.
328// So we do not have to check permissions.
329aaudio_result_t AAudioService::disconnectStreamByPortHandle(audio_port_handle_t portHandle) {
330 ALOGD("%s(%d) called", __func__, portHandle);
331 sp<AAudioServiceStreamBase> serviceStream =
Phil Burk2fe718b2018-05-14 12:28:32 -0700332 mStreamTracker.findStreamByPortHandleAndIncrement(portHandle);
Phil Burkbbd52862018-04-13 11:37:42 -0700333 if (serviceStream.get() == nullptr) {
334 ALOGE("%s(), could not find stream with portHandle = %d", __func__, portHandle);
335 return AAUDIO_ERROR_INVALID_HANDLE;
336 }
Phil Burkbbd52862018-04-13 11:37:42 -0700337 aaudio_result_t result = serviceStream->stop();
338 serviceStream->disconnect();
Phil Burk94862522017-09-13 21:31:36 -0700339 return checkForPendingClose(serviceStream, result);
Eric Laurenta54f1282017-07-01 19:39:32 -0700340}