Skip to content

Commit 957c113

Browse files
author
android-build-team Robot
committed
Snap for 6549063 from 82352f9 to rvc-release
Change-Id: I113a60f4b52b0df71b1f6ba78d4f96666ff049b2
2 parents 12cea18 + 82352f9 commit 957c113

182 files changed

Lines changed: 6577 additions & 1040 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apex/media/framework/java/android/media/MediaParser.java

Lines changed: 90 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ public interface OutputConsumer {
402402
* onSampleDataFound(int, MediaParser.InputReader)} for the specified track, since the
403403
* last byte belonging to the sample whose metadata is being passed.
404404
* @param cryptoInfo Encryption data required to decrypt the sample. May be null for
405-
* unencrypted samples. MediaParser may reuse {@link CryptoInfo} instances to avoid
406-
* allocations, so implementations of this method must not write to or keep reference to
407-
* the fields of this parameter.
405+
* unencrypted samples. Implementors should treat any output {@link CryptoInfo}
406+
* instances as immutable. MediaParser will not modify any output {@code cryptoInfos}
407+
* and implementors should not modify them either.
408408
*/
409409
void onSampleCompleted(
410410
int trackIndex,
@@ -1409,23 +1409,28 @@ public void seekMap(com.google.android.exoplayer2.extractor.SeekMap exoplayerSee
14091409
private class TrackOutputAdapter implements TrackOutput {
14101410

14111411
private final int mTrackIndex;
1412-
private final CryptoInfo mCryptoInfo;
1412+
1413+
private CryptoInfo mLastOutputCryptoInfo;
1414+
private CryptoInfo.Pattern mLastOutputEncryptionPattern;
1415+
private CryptoData mLastReceivedCryptoData;
14131416

14141417
@EncryptionDataReadState private int mEncryptionDataReadState;
14151418
private int mEncryptionDataSizeToSubtractFromSampleDataSize;
14161419
private int mEncryptionVectorSize;
1420+
private byte[] mScratchIvSpace;
1421+
private int mSubsampleEncryptionDataSize;
1422+
private int[] mScratchSubsampleEncryptedBytesCount;
1423+
private int[] mScratchSubsampleClearBytesCount;
14171424
private boolean mHasSubsampleEncryptionData;
1418-
private CryptoInfo.Pattern mEncryptionPattern;
14191425
private int mSkippedSupplementalDataBytes;
14201426

14211427
private TrackOutputAdapter(int trackIndex) {
14221428
mTrackIndex = trackIndex;
1423-
mCryptoInfo = new CryptoInfo();
1424-
mCryptoInfo.iv = new byte[16]; // Size documented in CryptoInfo.
1425-
mCryptoInfo.numBytesOfClearData = new int[0];
1426-
mCryptoInfo.numBytesOfEncryptedData = new int[0];
1429+
mScratchIvSpace = new byte[16]; // Size documented in CryptoInfo.
1430+
mScratchSubsampleEncryptedBytesCount = new int[32];
1431+
mScratchSubsampleClearBytesCount = new int[32];
14271432
mEncryptionDataReadState = STATE_READING_SIGNAL_BYTE;
1428-
mEncryptionPattern =
1433+
mLastOutputEncryptionPattern =
14291434
new CryptoInfo.Pattern(/* blocksToEncrypt= */ 0, /* blocksToSkip= */ 0);
14301435
}
14311436

@@ -1466,35 +1471,39 @@ public void sampleData(
14661471
mEncryptionDataReadState = STATE_READING_INIT_VECTOR;
14671472
break;
14681473
case STATE_READING_INIT_VECTOR:
1469-
Arrays.fill(mCryptoInfo.iv, (byte) 0); // Ensure 0-padding.
1470-
data.readBytes(mCryptoInfo.iv, /* offset= */ 0, mEncryptionVectorSize);
1474+
Arrays.fill(mScratchIvSpace, (byte) 0); // Ensure 0-padding.
1475+
data.readBytes(mScratchIvSpace, /* offset= */ 0, mEncryptionVectorSize);
14711476
length -= mEncryptionVectorSize;
14721477
if (mHasSubsampleEncryptionData) {
14731478
mEncryptionDataReadState = STATE_READING_SUBSAMPLE_ENCRYPTION_SIZE;
14741479
} else {
1475-
mCryptoInfo.numSubSamples = 0;
1480+
mSubsampleEncryptionDataSize = 0;
14761481
mEncryptionDataReadState = STATE_READING_SIGNAL_BYTE;
14771482
}
14781483
break;
14791484
case STATE_READING_SUBSAMPLE_ENCRYPTION_SIZE:
1480-
int numSubSamples = data.readUnsignedShort();
1481-
mCryptoInfo.numSubSamples = numSubSamples;
1482-
if (mCryptoInfo.numBytesOfClearData.length < numSubSamples) {
1483-
mCryptoInfo.numBytesOfClearData = new int[numSubSamples];
1484-
mCryptoInfo.numBytesOfEncryptedData = new int[numSubSamples];
1485+
mSubsampleEncryptionDataSize = data.readUnsignedShort();
1486+
if (mScratchSubsampleClearBytesCount.length
1487+
< mSubsampleEncryptionDataSize) {
1488+
mScratchSubsampleClearBytesCount =
1489+
new int[mSubsampleEncryptionDataSize];
1490+
mScratchSubsampleEncryptedBytesCount =
1491+
new int[mSubsampleEncryptionDataSize];
14851492
}
14861493
length -= 2;
14871494
mEncryptionDataSizeToSubtractFromSampleDataSize +=
1488-
2 + numSubSamples * BYTES_PER_SUBSAMPLE_ENCRYPTION_ENTRY;
1495+
2
1496+
+ mSubsampleEncryptionDataSize
1497+
* BYTES_PER_SUBSAMPLE_ENCRYPTION_ENTRY;
14891498
mEncryptionDataReadState = STATE_READING_SUBSAMPLE_ENCRYPTION_DATA;
14901499
break;
14911500
case STATE_READING_SUBSAMPLE_ENCRYPTION_DATA:
1492-
for (int i = 0; i < mCryptoInfo.numSubSamples; i++) {
1493-
mCryptoInfo.numBytesOfClearData[i] = data.readUnsignedShort();
1494-
mCryptoInfo.numBytesOfEncryptedData[i] = data.readInt();
1501+
for (int i = 0; i < mSubsampleEncryptionDataSize; i++) {
1502+
mScratchSubsampleClearBytesCount[i] = data.readUnsignedShort();
1503+
mScratchSubsampleEncryptedBytesCount[i] = data.readInt();
14951504
}
14961505
length -=
1497-
mCryptoInfo.numSubSamples
1506+
mSubsampleEncryptionDataSize
14981507
* BYTES_PER_SUBSAMPLE_ENCRYPTION_ENTRY;
14991508
mEncryptionDataReadState = STATE_READING_SIGNAL_BYTE;
15001509
if (length != 0) {
@@ -1536,24 +1545,71 @@ private CryptoInfo getPopulatedCryptoInfo(@Nullable CryptoData cryptoData) {
15361545
if (cryptoData == null) {
15371546
// The sample is not encrypted.
15381547
return null;
1548+
} else if (mInBandCryptoInfo) {
1549+
if (cryptoData != mLastReceivedCryptoData) {
1550+
mLastOutputCryptoInfo =
1551+
createNewCryptoInfoAndPopulateWithCryptoData(cryptoData);
1552+
}
1553+
} else /* We must populate the full CryptoInfo. */ {
1554+
// CryptoInfo.pattern is not accessible to the user, so the user needs to feed
1555+
// this CryptoInfo directly to MediaCodec. We need to create a new CryptoInfo per
1556+
// sample because of per-sample initialization vector changes.
1557+
CryptoInfo newCryptoInfo = createNewCryptoInfoAndPopulateWithCryptoData(cryptoData);
1558+
newCryptoInfo.iv = Arrays.copyOf(mScratchIvSpace, mScratchIvSpace.length);
1559+
boolean canReuseSubsampleInfo =
1560+
mLastOutputCryptoInfo != null
1561+
&& mLastOutputCryptoInfo.numSubSamples
1562+
== mSubsampleEncryptionDataSize;
1563+
for (int i = 0; i < mSubsampleEncryptionDataSize && canReuseSubsampleInfo; i++) {
1564+
canReuseSubsampleInfo =
1565+
mLastOutputCryptoInfo.numBytesOfClearData[i]
1566+
== mScratchSubsampleClearBytesCount[i]
1567+
&& mLastOutputCryptoInfo.numBytesOfEncryptedData[i]
1568+
== mScratchSubsampleEncryptedBytesCount[i];
1569+
}
1570+
newCryptoInfo.numSubSamples = mSubsampleEncryptionDataSize;
1571+
if (canReuseSubsampleInfo) {
1572+
newCryptoInfo.numBytesOfClearData = mLastOutputCryptoInfo.numBytesOfClearData;
1573+
newCryptoInfo.numBytesOfEncryptedData =
1574+
mLastOutputCryptoInfo.numBytesOfEncryptedData;
1575+
} else {
1576+
newCryptoInfo.numBytesOfClearData =
1577+
Arrays.copyOf(
1578+
mScratchSubsampleClearBytesCount, mSubsampleEncryptionDataSize);
1579+
newCryptoInfo.numBytesOfEncryptedData =
1580+
Arrays.copyOf(
1581+
mScratchSubsampleEncryptedBytesCount,
1582+
mSubsampleEncryptionDataSize);
1583+
}
1584+
mLastOutputCryptoInfo = newCryptoInfo;
15391585
}
1540-
mCryptoInfo.key = cryptoData.encryptionKey;
1541-
// ExoPlayer modes match MediaCodec modes.
1542-
mCryptoInfo.mode = cryptoData.cryptoMode;
1543-
if (cryptoData.clearBlocks != 0) {
1544-
// Content is pattern-encrypted.
1545-
mCryptoInfo.setPattern(mEncryptionPattern);
1546-
mEncryptionPattern.set(cryptoData.encryptedBlocks, cryptoData.clearBlocks);
1547-
} else {
1548-
mCryptoInfo.setPattern(null);
1586+
mLastReceivedCryptoData = cryptoData;
1587+
return mLastOutputCryptoInfo;
1588+
}
1589+
1590+
private CryptoInfo createNewCryptoInfoAndPopulateWithCryptoData(CryptoData cryptoData) {
1591+
CryptoInfo cryptoInfo = new CryptoInfo();
1592+
cryptoInfo.key = cryptoData.encryptionKey;
1593+
cryptoInfo.mode = cryptoData.cryptoMode;
1594+
if (cryptoData.clearBlocks != mLastOutputEncryptionPattern.getSkipBlocks()
1595+
|| cryptoData.encryptedBlocks
1596+
!= mLastOutputEncryptionPattern.getEncryptBlocks()) {
1597+
mLastOutputEncryptionPattern =
1598+
new CryptoInfo.Pattern(cryptoData.encryptedBlocks, cryptoData.clearBlocks);
15491599
}
1550-
return mCryptoInfo;
1600+
cryptoInfo.setPattern(mLastOutputEncryptionPattern);
1601+
return cryptoInfo;
15511602
}
15521603

15531604
private void outputSampleData(ParsableByteArray data, int length) {
15541605
mScratchParsableByteArrayAdapter.resetWithByteArray(data, length);
15551606
try {
1556-
mOutputConsumer.onSampleDataFound(mTrackIndex, mScratchParsableByteArrayAdapter);
1607+
// Read all bytes from data. ExoPlayer extractors expect all sample data to be
1608+
// consumed by TrackOutput implementations when passing a ParsableByteArray.
1609+
while (mScratchParsableByteArrayAdapter.getLength() > 0) {
1610+
mOutputConsumer.onSampleDataFound(
1611+
mTrackIndex, mScratchParsableByteArrayAdapter);
1612+
}
15571613
} catch (IOException e) {
15581614
// Unexpected.
15591615
throw new RuntimeException(e);

apex/statsd/framework/java/android/app/StatsManager.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,15 @@ public void onPullAtom(int atomTag, IPullAtomResultReceiver resultReceiver) {
561561
try {
562562
resultReceiver.pullFinished(atomTag, success, parcels);
563563
} catch (RemoteException e) {
564-
Log.w(TAG, "StatsPullResultReceiver failed for tag " + mAtomId);
564+
Log.w(TAG, "StatsPullResultReceiver failed for tag " + mAtomId
565+
+ " due to TransactionTooLarge. Calling pullFinish with no data");
566+
StatsEventParcel[] emptyData = new StatsEventParcel[0];
567+
try {
568+
resultReceiver.pullFinished(atomTag, /*success=*/false, emptyData);
569+
} catch (RemoteException nestedException) {
570+
Log.w(TAG, "StatsPullResultReceiver failed for tag " + mAtomId
571+
+ " with empty payload");
572+
}
565573
}
566574
});
567575
} finally {

cmds/statsd/src/condition/CombinationConditionTracker.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ CombinationConditionTracker::~CombinationConditionTracker() {
3737
bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConfig,
3838
const vector<sp<ConditionTracker>>& allConditionTrackers,
3939
const unordered_map<int64_t, int>& conditionIdIndexMap,
40-
vector<bool>& stack) {
40+
vector<bool>& stack,
41+
vector<ConditionState>& initialConditionCache) {
4142
VLOG("Combination predicate init() %lld", (long long)mConditionId);
4243
if (mInitialized) {
4344
return true;
@@ -73,9 +74,9 @@ bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConf
7374
return false;
7475
}
7576

76-
77-
bool initChildSucceeded = childTracker->init(allConditionConfig, allConditionTrackers,
78-
conditionIdIndexMap, stack);
77+
bool initChildSucceeded =
78+
childTracker->init(allConditionConfig, allConditionTrackers, conditionIdIndexMap,
79+
stack, initialConditionCache);
7980

8081
if (!initChildSucceeded) {
8182
ALOGW("Child initialization failed %lld ", (long long)child);
@@ -95,6 +96,11 @@ bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConf
9596
childTracker->getLogTrackerIndex().end());
9697
}
9798

99+
mUnSlicedPartCondition = evaluateCombinationCondition(mUnSlicedChildren, mLogicalOperation,
100+
initialConditionCache);
101+
initialConditionCache[mIndex] =
102+
evaluateCombinationCondition(mChildren, mLogicalOperation, initialConditionCache);
103+
98104
// unmark this node in the recursion stack.
99105
stack[mIndex] = false;
100106

cmds/statsd/src/condition/CombinationConditionTracker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class CombinationConditionTracker : public virtual ConditionTracker {
3232

3333
bool init(const std::vector<Predicate>& allConditionConfig,
3434
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
35-
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
36-
std::vector<bool>& stack) override;
35+
const std::unordered_map<int64_t, int>& conditionIdIndexMap, std::vector<bool>& stack,
36+
std::vector<ConditionState>& initialConditionCache) override;
3737

3838
void evaluateCondition(const LogEvent& event,
3939
const std::vector<MatchingState>& eventMatcherValues,

cmds/statsd/src/condition/ConditionTracker.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ class ConditionTracker : public virtual RefBase {
5151
// need to call init() on children conditions)
5252
// conditionIdIndexMap: the mapping from condition id to its index.
5353
// stack: a bit map to keep track which nodes have been visited on the stack in the recursion.
54+
// initialConditionCache: tracks initial conditions of all ConditionTrackers.
5455
virtual bool init(const std::vector<Predicate>& allConditionConfig,
5556
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
5657
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
57-
std::vector<bool>& stack) = 0;
58+
std::vector<bool>& stack,
59+
std::vector<ConditionState>& initialConditionCache) = 0;
5860

5961
// evaluate current condition given the new event.
6062
// event: the new log event

cmds/statsd/src/condition/SimpleConditionTracker.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ SimpleConditionTracker::~SimpleConditionTracker() {
9595
bool SimpleConditionTracker::init(const vector<Predicate>& allConditionConfig,
9696
const vector<sp<ConditionTracker>>& allConditionTrackers,
9797
const unordered_map<int64_t, int>& conditionIdIndexMap,
98-
vector<bool>& stack) {
98+
vector<bool>& stack,
99+
vector<ConditionState>& initialConditionCache) {
99100
// SimpleConditionTracker does not have dependency on other conditions, thus we just return
100101
// if the initialization was successful.
102+
initialConditionCache[mIndex] = mInitialValue;
101103
return mInitialized;
102104
}
103105

cmds/statsd/src/condition/SimpleConditionTracker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class SimpleConditionTracker : public virtual ConditionTracker {
3737

3838
bool init(const std::vector<Predicate>& allConditionConfig,
3939
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
40-
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
41-
std::vector<bool>& stack) override;
40+
const std::unordered_map<int64_t, int>& conditionIdIndexMap, std::vector<bool>& stack,
41+
std::vector<ConditionState>& initialConditionCache) override;
4242

4343
void evaluateCondition(const LogEvent& event,
4444
const std::vector<MatchingState>& eventMatcherValues,

cmds/statsd/src/metrics/CountMetricProducer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 6;
6868

6969
CountMetricProducer::CountMetricProducer(
7070
const ConfigKey& key, const CountMetric& metric, const int conditionIndex,
71-
const sp<ConditionWizard>& wizard, const int64_t timeBaseNs, const int64_t startTimeNs,
72-
71+
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
72+
const int64_t timeBaseNs, const int64_t startTimeNs,
7373
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap,
7474
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
7575
const vector<int>& slicedStateAtoms,
7676
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
77-
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard, eventActivationMap,
78-
eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
77+
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard,
78+
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
7979
if (metric.has_bucket()) {
8080
mBucketSizeNs =
8181
TimeUnitToBucketSizeInMillisGuardrailed(key.GetUid(), metric.bucket()) * 1000000;

cmds/statsd/src/metrics/CountMetricProducer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class CountMetricProducer : public MetricProducer {
4343
public:
4444
CountMetricProducer(
4545
const ConfigKey& key, const CountMetric& countMetric, const int conditionIndex,
46-
const sp<ConditionWizard>& wizard, const int64_t timeBaseNs, const int64_t startTimeNs,
46+
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
47+
const int64_t timeBaseNs, const int64_t startTimeNs,
4748
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {},
4849
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
4950
eventDeactivationMap = {},

0 commit comments

Comments
 (0)