Skip to content

Commit

Permalink
Snap for 6549063 from 82352f9 to rvc-release
Browse files Browse the repository at this point in the history
Change-Id: I113a60f4b52b0df71b1f6ba78d4f96666ff049b2
  • Loading branch information
android-build-team Robot committed Jun 2, 2020
2 parents 12cea18 + 82352f9 commit 957c113
Show file tree
Hide file tree
Showing 182 changed files with 6,577 additions and 1,040 deletions.
124 changes: 90 additions & 34 deletions apex/media/framework/java/android/media/MediaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ public interface OutputConsumer {
* onSampleDataFound(int, MediaParser.InputReader)} for the specified track, since the
* last byte belonging to the sample whose metadata is being passed.
* @param cryptoInfo Encryption data required to decrypt the sample. May be null for
* unencrypted samples. MediaParser may reuse {@link CryptoInfo} instances to avoid
* allocations, so implementations of this method must not write to or keep reference to
* the fields of this parameter.
* unencrypted samples. Implementors should treat any output {@link CryptoInfo}
* instances as immutable. MediaParser will not modify any output {@code cryptoInfos}
* and implementors should not modify them either.
*/
void onSampleCompleted(
int trackIndex,
Expand Down Expand Up @@ -1409,23 +1409,28 @@ public void seekMap(com.google.android.exoplayer2.extractor.SeekMap exoplayerSee
private class TrackOutputAdapter implements TrackOutput {

private final int mTrackIndex;
private final CryptoInfo mCryptoInfo;

private CryptoInfo mLastOutputCryptoInfo;
private CryptoInfo.Pattern mLastOutputEncryptionPattern;
private CryptoData mLastReceivedCryptoData;

@EncryptionDataReadState private int mEncryptionDataReadState;
private int mEncryptionDataSizeToSubtractFromSampleDataSize;
private int mEncryptionVectorSize;
private byte[] mScratchIvSpace;
private int mSubsampleEncryptionDataSize;
private int[] mScratchSubsampleEncryptedBytesCount;
private int[] mScratchSubsampleClearBytesCount;
private boolean mHasSubsampleEncryptionData;
private CryptoInfo.Pattern mEncryptionPattern;
private int mSkippedSupplementalDataBytes;

private TrackOutputAdapter(int trackIndex) {
mTrackIndex = trackIndex;
mCryptoInfo = new CryptoInfo();
mCryptoInfo.iv = new byte[16]; // Size documented in CryptoInfo.
mCryptoInfo.numBytesOfClearData = new int[0];
mCryptoInfo.numBytesOfEncryptedData = new int[0];
mScratchIvSpace = new byte[16]; // Size documented in CryptoInfo.
mScratchSubsampleEncryptedBytesCount = new int[32];
mScratchSubsampleClearBytesCount = new int[32];
mEncryptionDataReadState = STATE_READING_SIGNAL_BYTE;
mEncryptionPattern =
mLastOutputEncryptionPattern =
new CryptoInfo.Pattern(/* blocksToEncrypt= */ 0, /* blocksToSkip= */ 0);
}

Expand Down Expand Up @@ -1466,35 +1471,39 @@ public void sampleData(
mEncryptionDataReadState = STATE_READING_INIT_VECTOR;
break;
case STATE_READING_INIT_VECTOR:
Arrays.fill(mCryptoInfo.iv, (byte) 0); // Ensure 0-padding.
data.readBytes(mCryptoInfo.iv, /* offset= */ 0, mEncryptionVectorSize);
Arrays.fill(mScratchIvSpace, (byte) 0); // Ensure 0-padding.
data.readBytes(mScratchIvSpace, /* offset= */ 0, mEncryptionVectorSize);
length -= mEncryptionVectorSize;
if (mHasSubsampleEncryptionData) {
mEncryptionDataReadState = STATE_READING_SUBSAMPLE_ENCRYPTION_SIZE;
} else {
mCryptoInfo.numSubSamples = 0;
mSubsampleEncryptionDataSize = 0;
mEncryptionDataReadState = STATE_READING_SIGNAL_BYTE;
}
break;
case STATE_READING_SUBSAMPLE_ENCRYPTION_SIZE:
int numSubSamples = data.readUnsignedShort();
mCryptoInfo.numSubSamples = numSubSamples;
if (mCryptoInfo.numBytesOfClearData.length < numSubSamples) {
mCryptoInfo.numBytesOfClearData = new int[numSubSamples];
mCryptoInfo.numBytesOfEncryptedData = new int[numSubSamples];
mSubsampleEncryptionDataSize = data.readUnsignedShort();
if (mScratchSubsampleClearBytesCount.length
< mSubsampleEncryptionDataSize) {
mScratchSubsampleClearBytesCount =
new int[mSubsampleEncryptionDataSize];
mScratchSubsampleEncryptedBytesCount =
new int[mSubsampleEncryptionDataSize];
}
length -= 2;
mEncryptionDataSizeToSubtractFromSampleDataSize +=
2 + numSubSamples * BYTES_PER_SUBSAMPLE_ENCRYPTION_ENTRY;
2
+ mSubsampleEncryptionDataSize
* BYTES_PER_SUBSAMPLE_ENCRYPTION_ENTRY;
mEncryptionDataReadState = STATE_READING_SUBSAMPLE_ENCRYPTION_DATA;
break;
case STATE_READING_SUBSAMPLE_ENCRYPTION_DATA:
for (int i = 0; i < mCryptoInfo.numSubSamples; i++) {
mCryptoInfo.numBytesOfClearData[i] = data.readUnsignedShort();
mCryptoInfo.numBytesOfEncryptedData[i] = data.readInt();
for (int i = 0; i < mSubsampleEncryptionDataSize; i++) {
mScratchSubsampleClearBytesCount[i] = data.readUnsignedShort();
mScratchSubsampleEncryptedBytesCount[i] = data.readInt();
}
length -=
mCryptoInfo.numSubSamples
mSubsampleEncryptionDataSize
* BYTES_PER_SUBSAMPLE_ENCRYPTION_ENTRY;
mEncryptionDataReadState = STATE_READING_SIGNAL_BYTE;
if (length != 0) {
Expand Down Expand Up @@ -1536,24 +1545,71 @@ private CryptoInfo getPopulatedCryptoInfo(@Nullable CryptoData cryptoData) {
if (cryptoData == null) {
// The sample is not encrypted.
return null;
} else if (mInBandCryptoInfo) {
if (cryptoData != mLastReceivedCryptoData) {
mLastOutputCryptoInfo =
createNewCryptoInfoAndPopulateWithCryptoData(cryptoData);
}
} else /* We must populate the full CryptoInfo. */ {
// CryptoInfo.pattern is not accessible to the user, so the user needs to feed
// this CryptoInfo directly to MediaCodec. We need to create a new CryptoInfo per
// sample because of per-sample initialization vector changes.
CryptoInfo newCryptoInfo = createNewCryptoInfoAndPopulateWithCryptoData(cryptoData);
newCryptoInfo.iv = Arrays.copyOf(mScratchIvSpace, mScratchIvSpace.length);
boolean canReuseSubsampleInfo =
mLastOutputCryptoInfo != null
&& mLastOutputCryptoInfo.numSubSamples
== mSubsampleEncryptionDataSize;
for (int i = 0; i < mSubsampleEncryptionDataSize && canReuseSubsampleInfo; i++) {
canReuseSubsampleInfo =
mLastOutputCryptoInfo.numBytesOfClearData[i]
== mScratchSubsampleClearBytesCount[i]
&& mLastOutputCryptoInfo.numBytesOfEncryptedData[i]
== mScratchSubsampleEncryptedBytesCount[i];
}
newCryptoInfo.numSubSamples = mSubsampleEncryptionDataSize;
if (canReuseSubsampleInfo) {
newCryptoInfo.numBytesOfClearData = mLastOutputCryptoInfo.numBytesOfClearData;
newCryptoInfo.numBytesOfEncryptedData =
mLastOutputCryptoInfo.numBytesOfEncryptedData;
} else {
newCryptoInfo.numBytesOfClearData =
Arrays.copyOf(
mScratchSubsampleClearBytesCount, mSubsampleEncryptionDataSize);
newCryptoInfo.numBytesOfEncryptedData =
Arrays.copyOf(
mScratchSubsampleEncryptedBytesCount,
mSubsampleEncryptionDataSize);
}
mLastOutputCryptoInfo = newCryptoInfo;
}
mCryptoInfo.key = cryptoData.encryptionKey;
// ExoPlayer modes match MediaCodec modes.
mCryptoInfo.mode = cryptoData.cryptoMode;
if (cryptoData.clearBlocks != 0) {
// Content is pattern-encrypted.
mCryptoInfo.setPattern(mEncryptionPattern);
mEncryptionPattern.set(cryptoData.encryptedBlocks, cryptoData.clearBlocks);
} else {
mCryptoInfo.setPattern(null);
mLastReceivedCryptoData = cryptoData;
return mLastOutputCryptoInfo;
}

private CryptoInfo createNewCryptoInfoAndPopulateWithCryptoData(CryptoData cryptoData) {
CryptoInfo cryptoInfo = new CryptoInfo();
cryptoInfo.key = cryptoData.encryptionKey;
cryptoInfo.mode = cryptoData.cryptoMode;
if (cryptoData.clearBlocks != mLastOutputEncryptionPattern.getSkipBlocks()
|| cryptoData.encryptedBlocks
!= mLastOutputEncryptionPattern.getEncryptBlocks()) {
mLastOutputEncryptionPattern =
new CryptoInfo.Pattern(cryptoData.encryptedBlocks, cryptoData.clearBlocks);
}
return mCryptoInfo;
cryptoInfo.setPattern(mLastOutputEncryptionPattern);
return cryptoInfo;
}

private void outputSampleData(ParsableByteArray data, int length) {
mScratchParsableByteArrayAdapter.resetWithByteArray(data, length);
try {
mOutputConsumer.onSampleDataFound(mTrackIndex, mScratchParsableByteArrayAdapter);
// Read all bytes from data. ExoPlayer extractors expect all sample data to be
// consumed by TrackOutput implementations when passing a ParsableByteArray.
while (mScratchParsableByteArrayAdapter.getLength() > 0) {
mOutputConsumer.onSampleDataFound(
mTrackIndex, mScratchParsableByteArrayAdapter);
}
} catch (IOException e) {
// Unexpected.
throw new RuntimeException(e);
Expand Down
10 changes: 9 additions & 1 deletion apex/statsd/framework/java/android/app/StatsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,15 @@ public void onPullAtom(int atomTag, IPullAtomResultReceiver resultReceiver) {
try {
resultReceiver.pullFinished(atomTag, success, parcels);
} catch (RemoteException e) {
Log.w(TAG, "StatsPullResultReceiver failed for tag " + mAtomId);
Log.w(TAG, "StatsPullResultReceiver failed for tag " + mAtomId
+ " due to TransactionTooLarge. Calling pullFinish with no data");
StatsEventParcel[] emptyData = new StatsEventParcel[0];
try {
resultReceiver.pullFinished(atomTag, /*success=*/false, emptyData);
} catch (RemoteException nestedException) {
Log.w(TAG, "StatsPullResultReceiver failed for tag " + mAtomId
+ " with empty payload");
}
}
});
} finally {
Expand Down
14 changes: 10 additions & 4 deletions cmds/statsd/src/condition/CombinationConditionTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ CombinationConditionTracker::~CombinationConditionTracker() {
bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConfig,
const vector<sp<ConditionTracker>>& allConditionTrackers,
const unordered_map<int64_t, int>& conditionIdIndexMap,
vector<bool>& stack) {
vector<bool>& stack,
vector<ConditionState>& initialConditionCache) {
VLOG("Combination predicate init() %lld", (long long)mConditionId);
if (mInitialized) {
return true;
Expand Down Expand Up @@ -73,9 +74,9 @@ bool CombinationConditionTracker::init(const vector<Predicate>& allConditionConf
return false;
}


bool initChildSucceeded = childTracker->init(allConditionConfig, allConditionTrackers,
conditionIdIndexMap, stack);
bool initChildSucceeded =
childTracker->init(allConditionConfig, allConditionTrackers, conditionIdIndexMap,
stack, initialConditionCache);

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

mUnSlicedPartCondition = evaluateCombinationCondition(mUnSlicedChildren, mLogicalOperation,
initialConditionCache);
initialConditionCache[mIndex] =
evaluateCombinationCondition(mChildren, mLogicalOperation, initialConditionCache);

// unmark this node in the recursion stack.
stack[mIndex] = false;

Expand Down
4 changes: 2 additions & 2 deletions cmds/statsd/src/condition/CombinationConditionTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class CombinationConditionTracker : public virtual ConditionTracker {

bool init(const std::vector<Predicate>& allConditionConfig,
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
std::vector<bool>& stack) override;
const std::unordered_map<int64_t, int>& conditionIdIndexMap, std::vector<bool>& stack,
std::vector<ConditionState>& initialConditionCache) override;

void evaluateCondition(const LogEvent& event,
const std::vector<MatchingState>& eventMatcherValues,
Expand Down
4 changes: 3 additions & 1 deletion cmds/statsd/src/condition/ConditionTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class ConditionTracker : public virtual RefBase {
// need to call init() on children conditions)
// conditionIdIndexMap: the mapping from condition id to its index.
// stack: a bit map to keep track which nodes have been visited on the stack in the recursion.
// initialConditionCache: tracks initial conditions of all ConditionTrackers.
virtual bool init(const std::vector<Predicate>& allConditionConfig,
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
std::vector<bool>& stack) = 0;
std::vector<bool>& stack,
std::vector<ConditionState>& initialConditionCache) = 0;

// evaluate current condition given the new event.
// event: the new log event
Expand Down
4 changes: 3 additions & 1 deletion cmds/statsd/src/condition/SimpleConditionTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ SimpleConditionTracker::~SimpleConditionTracker() {
bool SimpleConditionTracker::init(const vector<Predicate>& allConditionConfig,
const vector<sp<ConditionTracker>>& allConditionTrackers,
const unordered_map<int64_t, int>& conditionIdIndexMap,
vector<bool>& stack) {
vector<bool>& stack,
vector<ConditionState>& initialConditionCache) {
// SimpleConditionTracker does not have dependency on other conditions, thus we just return
// if the initialization was successful.
initialConditionCache[mIndex] = mInitialValue;
return mInitialized;
}

Expand Down
4 changes: 2 additions & 2 deletions cmds/statsd/src/condition/SimpleConditionTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class SimpleConditionTracker : public virtual ConditionTracker {

bool init(const std::vector<Predicate>& allConditionConfig,
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
const std::unordered_map<int64_t, int>& conditionIdIndexMap,
std::vector<bool>& stack) override;
const std::unordered_map<int64_t, int>& conditionIdIndexMap, std::vector<bool>& stack,
std::vector<ConditionState>& initialConditionCache) override;

void evaluateCondition(const LogEvent& event,
const std::vector<MatchingState>& eventMatcherValues,
Expand Down
8 changes: 4 additions & 4 deletions cmds/statsd/src/metrics/CountMetricProducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ const int FIELD_ID_END_BUCKET_ELAPSED_MILLIS = 6;

CountMetricProducer::CountMetricProducer(
const ConfigKey& key, const CountMetric& metric, const int conditionIndex,
const sp<ConditionWizard>& wizard, const int64_t timeBaseNs, const int64_t startTimeNs,

const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
const int64_t timeBaseNs, const int64_t startTimeNs,
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap,
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap,
const vector<int>& slicedStateAtoms,
const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap)
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, wizard, eventActivationMap,
eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
: MetricProducer(metric.id(), key, timeBaseNs, conditionIndex, initialConditionCache, wizard,
eventActivationMap, eventDeactivationMap, slicedStateAtoms, stateGroupMap) {
if (metric.has_bucket()) {
mBucketSizeNs =
TimeUnitToBucketSizeInMillisGuardrailed(key.GetUid(), metric.bucket()) * 1000000;
Expand Down
3 changes: 2 additions & 1 deletion cmds/statsd/src/metrics/CountMetricProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class CountMetricProducer : public MetricProducer {
public:
CountMetricProducer(
const ConfigKey& key, const CountMetric& countMetric, const int conditionIndex,
const sp<ConditionWizard>& wizard, const int64_t timeBaseNs, const int64_t startTimeNs,
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
const int64_t timeBaseNs, const int64_t startTimeNs,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {},
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
eventDeactivationMap = {},
Expand Down
Loading

0 comments on commit 957c113

Please sign in to comment.