Add a bandaid to prevent a segfault which can occur while handling
timed audio buffers. There is a deeper problem which should
eventually be addressed, but for now this fix should prevent any
crashing.
The deeper problem is as follows.
When the AudioFlinger mixer gets data to mix from an AudioTrack, it
ends up getting a structure filled out which points into an IMemory
region owned by the AudioTrack. Unfortunately, this structure is not
holding a refcount on the IMemory which it points into. If the
IMemory refcount hits 0 and the chunk of RAM is retuned to the binder
heap it came from, there can still be a Buffer object being held by
the AudioFlinger mixer which points into the region of memory which
was retuned to the binfer heap. If AF reads from this buffer, it
could read corrupt data (if the region of memory gets handed back out
to a writer), or it could segfault (if the heap has been freed and the
pages unmapped). Similar problems could happen if AF attempts to
write to the buffer, heap corruption in one case, segfaulting in the
other.
In the past, this has not been an issue for AF, because tracks
allocate a single IMemory (which serves as a ring buffer) and the
IMemory lives for as long as the track lives. As an artifact of the
way the code came out, the mixer cannot be holding a Buffer structure
pointing into the IMemory which used to be owned by a track if the
track no longer exists. Tracks cannot come into or out of existence
during a mix operation, which is the only thing which makes this safe.
TimedTracks work differently, however. Timed tracks each allocate a
small binder heap, and then hand out IMemory instances broken out of
this heap. The heap lives as long as the track, so the worst which
could happen here is that a TimedTrack's IMemory gets returned to the
heap while there is still a buffer structure in flight pointing into
the memory region, then the region gets handed out again and
overwritten by new data causing the mixer to mix the wrong audio. The
timing to cause this to happen is very difficult to encounter, and you
to generate the timing conditions required, you need to be in a pretty
bad failure state where audio is already breaking up and skipping, so
its unlikely that anyone would notice (which is why I'm band-aiding
the segfault and letting the deeper issue slide for now).
In general, however, it might be a good idea to revisit this buffering
design. On principal, if someone is going to hold pointers into a
refcounted object, they should be holding a ref on the object at the
same time. Failure to do this will usually lead to a situation where
there are corruption or segfault issues, or to a system where the
refcounted object's lifetime must be implicitly managed very carefully
in ways which are usually non-obvious and are easy to break by new
engineers on a project.
Change-Id: Ib391075395ed0ef46a03c37aa38a82d09e88abeb
This patch is adding a capability so that OEM can override USB mode
in case the device is boot up with OEM specific mode. (i.e. modem
debug, factory test etc.)
Bug:5964042
Change-Id: Ic8e23d302563ce71eedb74ce94cca8c65838a4f7
Check the string returned by a HAL's implementation of get_parameters
for NULL before attempting to make use of it. That way, we won't
bring down the mediaserver because of a poorly written HAL.
Change-Id: I45f0fd3de003151f98acf32c36c42f58d053f3a0
Fix an issue I discovered while back-porting this code to master. The
common time service was using the MAC address of "eth0" (hardcoded) as
its device ID instead of fetching it from the interface it is
currently bound to. On phones (or any other device with no eth0) this
causes time service to never be able to fetch a device ID as it
should.
Change-Id: Icf8a2006924088efc86065927a648f7f53638657
Change the CCHelper class to be an instanced instead of a static
pattern. The CCHelper instances all share an interface to the common
clock service and register/unregister a callback handler in response
to there being CCHelper instance in the system or not. This brings
usage of the CCHelper into like with the new auto-disable
functionality of the common time service. For any given process,
whenever there are CCHelper instances active, the process will
maintain a callback target to the common clock service and will be
considered to be an active client.
Also change all of the users of the CCHelper interface to manage the
lifecycle of their new CCHelper instances.
Change-Id: I7c28c5d70d9b07ba7407b4ac706e7e7d7253001b
Add a small service to the high level core set of system services to
control the configuration of the native common time service. This
service is responsible for controlling policy regarding when the
common time service should be allowed to run, which networks it is
allowed to run on, what priority it runs at in the master election
algorithm, and so on.
Change-Id: I37308e882a0e8c4cd3e38c4f47b7c40b9150ba31
Major re-factor of the common_time (formally aah_timesrv) service in
preparation for up-integration into Android master. This work
includes bug fixes, new features, and general code cleanup. High
points are listed below.
+ CommonClock interface has been enhanced to allow querying of many
more low level synchronization details; mostly for debugging, but in
theory useful to an application as well.
+ CommonTimeConfig interface has been implemented. This allows a
management process to configure a number of different parameters
(many of them new) to control the behavior of the common_time
service. Most importantly, the time service can be bound to a
specific network interface and should only operate on that interface
an no others.
+ Enhance log messages to be more useful in determining what the time
service state machine is doing and why.
+ Enhance information provided by dumpsys to provide many more details
about the quality of time sync and the network conditions which gave
rise to the current quality conditions.
Features, features, features....
+ Add a feature which lets the high level choose a different master
election endpoint so that multiple time synchronization domains can
co-exist on the same subnet (mostly to support a potential use case
of multiple home domains in a multiple dwelling environment like a
hotel, dormitory or apartment complex).
+ Add a feature which lets the high level assign a 64-bit group ID
which allows partitioning of time synchronization domains even when
the master election endpoint is shared (as it might be if broadcast
is being used instead of multicast)
+ Add an auto-disable feature which lets the time service drop into
network-less mode when there are no active clients of the
common_time service in the device. Mostly for phones, this allows
phones to not consume network/battery resources when they don't need
to maintain common time.
+ Add a feature which lets the high level choose the priority of the
common_time service in the master election protocol. This allows
high level decisions about things like mobile vs non-mobile, wired
ethernet vs WiFi to affect who ends up with the job of master on a
given network. Priority overrides at the low level also allow
clients coming in from network-less mode to lower their effective
priority as they join a new network so as to not disrupt any
stable long-running timeline which may already be active on the
network.
+ Add the ability to control some of the core parameters of the time
sync service which effect network load (like the sync polling
interval and the master announce interval)
Change-Id: I71af15a83cfa5ef0417b406928967fb9e02f55c6
Define a native service interface for configuring and controlling the
common time service. Implement the native marshallers and stub the
implementation of the new interface.
Change-Id: Ia6a6a20ef3d221e8829c55be1dd5f98ed996c610
Add marshallers and stub implementations for new methods in the common
clock interface to support new functionality being added in the
process of integrating the common time service more closely with the
Java level of Android.
Change-Id: Iac2d3fb405d1b64cea1d8e13f988160afb76a06d
Move the State enum up to the ICommonClock interface so it can be
returned for status/debugging up to clients.
Change-Id: I81fef5b96ffc69a4f2e9801b3744feea099ccd47
Bulk name change to remove references to Android@Home from the common time
service in preparation for cleanup and up-integration into the master
branch. Basically, aah_timesrv is now common_time.
Change-Id: I3d3db212f96e8ba171aa36b9c58e27e4a336cb0a
This is between the two previous attempts. I returned the part from the
original that was breaking gallery, but have some new code to detect when
something about the window params has changed that would require a
layout pass to make sure we still do a layout then, even if the window is
not currently visible.
Change-Id: I07745e1f66022583e3076b84cc8bbe8bd2acd48f
When an AudioTrack is in underrun state, the AudioFlinger mixer will
sleep for a short period of time to give the app a chance to fill the
AudioTrack buffer. If the AudioTrack is still not ready during next mixing round,
the mixer will proceed with other tracks.
If an application keeps a steady underrun condition, the AudioFlinger mixer will
alternate between ready and not ready states. In the longer term this will cause the
audio HAL to underrun.
There is a mechanism to reduce the sleep period if the mixer is not ready several times in a
row but this mechanism is defeated by the alternating ready/not ready conditions.
The fix consists in only increasing sleep time if the mixer is ready for at least two
consecutive times.
Issue 5904527.
Change-Id: Id0139bca9be8c4e425ec6d428515c4d8f718e8c9
This fixes a complaint from carriers (that we used 8.8.8.8), but also
fixes the case where there is only room for one live radio
connection: the secondary connection (tethering) doesn't have a
default route to prevent on-device traffic from slipping out on the
tethering connection, but tethered dns is proxied through dnsmasq, so
it is appearing as on-device traffic and is unroutable. By switching
to the carrier-indicated dns servers we can use the host-routes
already set for those and kill two bugs with one fix.
bug:5898904
Change-Id: Ida8777687994f353b2d4f2c7db5d6ea4b6ac3882
This increases lock screen's thread priority from THREAD_PRIORITY_FOREGROUND
to THREAD_PRIORITY_DISPLAY to ensure it runs before other activities that
might stall lock screen when the screen turns on.
Change-Id: I14cf9f3f5c092817bc6cf2d0a254001a5d34f744
Don't consider a window as a candidate for the top fullscreen window
if it is not going to be a candiate for layout.
This fix does not include the change to ignore app tokens that are
hidden. This causes problems in some dialogs that stay hidden until
their app is ready to display, but need to perform a series of relayouts
during that time to get to the right size. Dropping this part of
the change still (mostly?) seems to allow us to avoid the bad states.
Change-Id: Ic052cb1499d3287f47e9ffeac5cd2470ee5a308c
This problem due to the way audio buffers are mixed when
low power mode is active was addressed by commits 19ddf0eb
and 8a04fe03 but only partially. As a matter of fact, when more
than one audio track is playing, the problem is still present.
This is most noticeable when playing music with screen off
and a notification or navigation instruction is played: in this case,
the music or notification is likely to skip.
The fix consists in declaring the mixer ready if all active tracks
are ready. Previous behavior was to declare ready if at least one track was
ready. To avoid that one application failing to fill the track buffer blocks other
tracks indefinitely, this condition is respected only if the mixer was ready
in the previous round.
Issue 5799167.
Change-Id: Iabd4ca08d3d45f563d9824c8a03c2c68a43ae179
This fixes a bug where the device fails to lock when DevicePolicyManagerService
requests the device to be locked and the screen was off because the user hit
the power button.
The change allows DPMS to directly invoke screen lock, bypasssing the screen state.
Change-Id: Iecdda6fc61e9c519119de495be23c69c3b983921