Skip to content

Commit 592ba0d

Browse files
author
Android Build Coastguard Worker
committed
Snap for 12710726 from d3ca472 to 25Q1-release
Change-Id: I65018bf876da48690798e19263e256229959dd22
2 parents 4be1e63 + d3ca472 commit 592ba0d

22 files changed

Lines changed: 713 additions & 179 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2024 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+
<!-- This is the standard feature indicating that the device has a Vulkan
18+
driver that supports API version 1.4 (0x00404000) -->
19+
<permissions>
20+
<feature name="android.hardware.vulkan.version" version="4210688" />
21+
</permissions>

include/audiomanager/AudioManager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace android {
2222
// must be kept in sync with definitions in AudioPlaybackConfiguration.java
2323
#define PLAYER_PIID_INVALID -1
2424

25+
// TODO (b/309532236) remove manual IAudioManager impl in favor of AIDL.
2526
typedef enum {
2627
PLAYER_TYPE_SLES_AUDIOPLAYER_BUFFERQUEUE = 11,
2728
PLAYER_TYPE_SLES_AUDIOPLAYER_URI_FD = 12,
@@ -60,6 +61,7 @@ enum {
6061
PLAYER_MUTE_CLIENT_VOLUME = (1 << 4),
6162
PLAYER_MUTE_VOLUME_SHAPER = (1 << 5),
6263
PLAYER_MUTE_PORT_VOLUME = (1 << 6),
64+
PLAYER_MUTE_OP_AUDIO_CONTROL = (1 << 7),
6365
};
6466

6567
struct mute_state_t {
@@ -77,6 +79,8 @@ struct mute_state_t {
7779
bool muteFromVolumeShaper = false;
7880
/** Flag used when volume is muted by port volume. */
7981
bool muteFromPortVolume = false;
82+
/** Flag used when volume is muted by audio control op. */
83+
bool muteFromOpAudioControl = false;
8084

8185
explicit operator int() const
8286
{
@@ -87,6 +91,7 @@ struct mute_state_t {
8791
result |= muteFromClientVolume * PLAYER_MUTE_CLIENT_VOLUME;
8892
result |= muteFromVolumeShaper * PLAYER_MUTE_VOLUME_SHAPER;
8993
result |= muteFromPortVolume * PLAYER_MUTE_PORT_VOLUME;
94+
result |= muteFromOpAudioControl * PLAYER_MUTE_OP_AUDIO_CONTROL;
9095
return result;
9196
}
9297

libs/binder/rust/src/system_only.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,32 @@ impl Accessor {
9191
Accessor { accessor }
9292
}
9393

94+
/// Creates a new Accessor instance based on an existing Accessor's binder.
95+
/// This is useful when the Accessor instance is hosted in another process
96+
/// that has the permissions to create the socket connection FD.
97+
///
98+
/// The `instance` argument must match the instance that the original Accessor
99+
/// is responsible for.
100+
/// `instance` must not contain null bytes and is used to create a CString to
101+
/// pass through FFI.
102+
/// The `binder` argument must be a valid binder from an Accessor
103+
pub fn from_binder(instance: &str, binder: SpIBinder) -> Option<Accessor> {
104+
let inst = CString::new(instance).unwrap();
105+
106+
// Safety: All `SpIBinder` objects (the `binder` argument) hold a valid pointer
107+
// to an `AIBinder` that is guaranteed to remain valid for the lifetime of the
108+
// SpIBinder. `ABinderRpc_Accessor_fromBinder` creates a new pointer to that binder
109+
// that it is responsible for.
110+
// The `inst` argument is a new CString that will copied by
111+
// `ABinderRpc_Accessor_fromBinder` and not modified.
112+
let accessor =
113+
unsafe { sys::ABinderRpc_Accessor_fromBinder(inst.as_ptr(), binder.as_raw()) };
114+
if accessor.is_null() {
115+
return None;
116+
}
117+
Some(Accessor { accessor })
118+
}
119+
94120
/// Get the underlying binder for this Accessor for when it needs to be either
95121
/// registered with service manager or sent to another process.
96122
pub fn as_binder(&self) -> Option<SpIBinder> {

libs/binder/rust/tests/integration.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,34 @@ mod tests {
10381038
assert!(deleted.load(Ordering::Relaxed));
10391039
}
10401040

1041+
#[test]
1042+
fn test_accessor_from_accessor_binder() {
1043+
let get_connection_info = move |_instance: &str| None;
1044+
let accessor = Accessor::new("foo.service", get_connection_info);
1045+
let accessor2 =
1046+
Accessor::from_binder("foo.service", accessor.as_binder().unwrap()).unwrap();
1047+
assert_eq!(accessor.as_binder(), accessor2.as_binder());
1048+
}
1049+
1050+
#[test]
1051+
fn test_accessor_from_non_accessor_binder() {
1052+
let service_name = "rust_test_ibinder";
1053+
let _process = ScopedServiceProcess::new(service_name);
1054+
let binder = binder::get_service(service_name).unwrap();
1055+
assert!(binder.is_binder_alive());
1056+
1057+
let accessor = Accessor::from_binder("rust_test_ibinder", binder);
1058+
assert!(accessor.is_none());
1059+
}
1060+
1061+
#[test]
1062+
fn test_accessor_from_wrong_accessor_binder() {
1063+
let get_connection_info = move |_instance: &str| None;
1064+
let accessor = Accessor::new("foo.service", get_connection_info);
1065+
let accessor2 = Accessor::from_binder("NOT.foo.service", accessor.as_binder().unwrap());
1066+
assert!(accessor2.is_none());
1067+
}
1068+
10411069
#[tokio::test]
10421070
async fn reassociate_rust_binder_async() {
10431071
let service_name = "testing_service";

libs/input/InputConsumerNoResampling.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ InputMessage createTimelineMessage(int32_t inputEventId, nsecs_t gpuCompletedTim
169169
msg.body.timeline.graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = presentTime;
170170
return msg;
171171
}
172+
173+
std::ostream& operator<<(std::ostream& out, const InputMessage& msg) {
174+
out << ftl::enum_string(msg.header.type);
175+
return out;
176+
}
177+
172178
} // namespace
173179

174180
// --- InputConsumerNoResampling ---
@@ -272,6 +278,15 @@ void InputConsumerNoResampling::processOutboundEvents() {
272278
return; // try again later
273279
}
274280

281+
if (result == DEAD_OBJECT) {
282+
// If there's no one to receive events in the channel, there's no point in sending them.
283+
// Drop all outbound events.
284+
LOG(INFO) << "Channel " << mChannel->getName() << " died. Dropping outbound event "
285+
<< outboundMsg;
286+
mOutboundQueue.pop();
287+
setFdEvents(0);
288+
continue;
289+
}
275290
// Some other error. Give up
276291
LOG(FATAL) << "Failed to send outbound event on channel '" << mChannel->getName()
277292
<< "'. status=" << statusToString(result) << "(" << result << ")";

libs/input/tests/InputPublisherAndConsumerNoResampling_test.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ class InputPublisherAndConsumerNoResamplingTest : public testing::Test,
319319

320320
protected:
321321
// Interaction with the looper thread
322+
void blockLooper();
323+
void unblockLooper();
322324
enum class LooperMessage : int {
323325
CALL_PROBABLY_HAS_INPUT,
324326
CREATE_CONSUMER,
@@ -389,6 +391,26 @@ class InputPublisherAndConsumerNoResamplingTest : public testing::Test,
389391
};
390392
};
391393

394+
void InputPublisherAndConsumerNoResamplingTest::blockLooper() {
395+
{
396+
std::scoped_lock l(mLock);
397+
mLooperMayProceed = false;
398+
}
399+
sendMessage(LooperMessage::BLOCK_LOOPER);
400+
{
401+
std::unique_lock l(mLock);
402+
mNotifyLooperWaiting.wait(l, [this] { return mLooperIsBlocked; });
403+
}
404+
}
405+
406+
void InputPublisherAndConsumerNoResamplingTest::unblockLooper() {
407+
{
408+
std::scoped_lock l(mLock);
409+
mLooperMayProceed = true;
410+
}
411+
mNotifyLooperMayProceed.notify_all();
412+
}
413+
392414
void InputPublisherAndConsumerNoResamplingTest::sendMessage(LooperMessage message) {
393415
Message msg{ftl::to_underlying(message)};
394416
mLooper->sendMessage(mMessageHandler, msg);
@@ -600,15 +622,7 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeSinglePointerMu
600622
std::queue<uint32_t> publishedSequenceNumbers;
601623

602624
// Block Looper to increase the chance of batching events
603-
{
604-
std::scoped_lock l(mLock);
605-
mLooperMayProceed = false;
606-
}
607-
sendMessage(LooperMessage::BLOCK_LOOPER);
608-
{
609-
std::unique_lock l(mLock);
610-
mNotifyLooperWaiting.wait(l, [this] { return mLooperIsBlocked; });
611-
}
625+
blockLooper();
612626

613627
uint32_t firstSampleId;
614628
for (size_t i = 0; i < nSamples; ++i) {
@@ -629,12 +643,7 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeSinglePointerMu
629643

630644
std::vector<MotionEvent> singleSampledMotionEvents;
631645

632-
// Unblock Looper
633-
{
634-
std::scoped_lock l(mLock);
635-
mLooperMayProceed = true;
636-
}
637-
mNotifyLooperMayProceed.notify_all();
646+
unblockLooper();
638647

639648
// We have no control over the socket behavior, so the consumer can receive
640649
// the motion as a batched event, or as a sequence of multiple single-sample MotionEvents (or a
@@ -809,6 +818,15 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeTouchModeEvent(
809818
verifyFinishedSignal(*mPublisher, seq, publishTime);
810819
}
811820

821+
/**
822+
* If the publisher has died, consumer should not crash when trying to send an outgoing message.
823+
*/
824+
TEST_F(InputPublisherAndConsumerNoResamplingTest, ConsumerWritesAfterPublisherDies) {
825+
mPublisher.reset(); // The publisher has died
826+
mReportTimelineArgs.emplace(/*inputEventId=*/10, /*gpuCompletedTime=*/20, /*presentTime=*/30);
827+
sendMessage(LooperMessage::CALL_REPORT_TIMELINE);
828+
}
829+
812830
TEST_F(InputPublisherAndConsumerNoResamplingTest, SendTimeline) {
813831
const int32_t inputEventId = 20;
814832
const nsecs_t gpuCompletedTime = 30;

0 commit comments

Comments
 (0)