Commit Graph

3057 Commits

Author SHA1 Message Date
Adam Stone
741645a4be Add UsageTableHeader metrics
[ Merge from http://go/wvgerrit/72183 ]

Adds basic metrics for the usage table header.

Bug: http://b/112919252
Test: Unit tests. Manual GPlay
Change-Id: I14d406766d8b2aba3b6e4f1a02c75eedc674b011
2019-02-25 17:09:31 -08:00
Srujan Gaddam
9be36c1d4b Flush whole page + use percentile for page size
Bug: b/123559319, b/112824791, b/120287622 (partially)
Test: Android unit/integration tests, Linux unit tests,
GTS tests on Taimen, GTS tests on Crosshatch
Merge of http://go/wvgerrit/72483

This is a revert of http://go/ag/6216663. This addresses the
failures that led to the seg faults in the 64 bit Level 3 library. Cache
flushing must be done to the entire mmap'd page regardless of whether or
not we use the entire page. Since we now have to cache flush the entire
page, this gives us a performance hit due to us using the max page size.
To get around this, we reuse mmap'd pages only for the 95th percentile
page size or lower.

Change-Id: I14bc0d7e21faae6b6816ea589ba25f9661dcec93
2019-02-21 17:11:51 -08:00
John W. Bruce
85d8e961f8 Protect Session Map with a Recursive Mutex
(This is a merge of http://go/wvgerrit/72764)

Netflix has identified a calling pattern that causes this mutex to be
taken recursively. This is not guaranteed to be safe for Widevine's
old custom Lock implementation nor std::mutex. However, it is guaranteed
to be safe for std::recursive_mutex. This patch updates the mutex in use
accordingly.

In the long-term, this lock needs to be reconsidered, as already noted
by comments in the code. It would be great if the reconsidered locking
did not require a recursive-safe lock. The TODO for this has been spun
off into its own bug and the comment has been updated to point to this.

Bug: 120471929
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I34df64456de4b469b75caf25a33f0bc53a5da330
2019-02-21 16:07:16 -08:00
Fred Gylys-Colwell
d925048c35 Merge "Set max output buffer size in Mod Mock" 2019-02-21 22:30:46 +00:00
Fred Gylys-Colwell
36e845d00d Merge "Keep OEMCrypto testbed singleton after terminate" 2019-02-21 22:30:35 +00:00
Fred Gylys-Colwell
e03739585f Merge "Update build_and_run script" 2019-02-21 20:18:46 +00:00
Rahul Frias
d45ce337a3 Merge "Move WV unit/integration tests to /data/nativetest" 2019-02-21 20:04:47 +00:00
John Bruce
34553f649c Merge changes Iea5df62b,I346c04a5
* changes:
  Do Not Add Parallel Unit Tests
  Split CryptoSession Lock into Three
2019-02-21 19:37:15 +00:00
John Bruce
0144293022 Merge "Add Lock to ValueMetric" 2019-02-21 19:35:26 +00:00
Rahul Frias
088c5afa02 Move WV unit/integration tests to /data/nativetest
[ Merge of http://go/wvgerrit/73044 ]

The tests currently get copied to /data/bin. Changes in location
of system libraries causes test failures when tests are unable to
find dependent dynamic libraries.

Bug: 123879070
Test: WV unit/integration tests
Change-Id: I86edbe33b4753238fcf8b84243ac6e6c058ea145
2019-02-21 09:53:06 -08:00
Rahul Frias
4916cb1e9c Correction to logging when SRM version is queried
[ Merge of http://go/wvgerrit/72703 ]

SRM is an optional feature and whether it is implemented is upto the
discretion of OEMs. If it is not, avoid logging this information.

Bug: 124391178
Test: WV unit/integration tests
Change-Id: If8d2b1e0b59fb11825f832a5d4259b03c482fd6b
2019-02-20 18:13:07 -08:00
Fred Gylys-Colwell
6c4a10ea15 Update build_and_run script
Merge from Widevine repo of http://go/wvgerrit/73024

This updates the build_and_run_all_unit_tests.sh to only build a
predefined list of tests.  This prevents the accidental inclusion of
android.hardware.drm@1.2-service-lazy.widevine.rc.

Bug: b/123885511
Test: Unit tests build and extra library does not.
Change-Id: I4368817103720976de2b21de2591a0712944c8d0
2019-02-20 17:21:45 -08:00
Srujan Gaddam
007153889e Merge "Test to ensure rollback doesn't affect key duration" 2019-02-20 18:53:23 +00:00
John W. Bruce
d9de4c0304 Add Lock to ValueMetric
(This is a merge of http://go/wvgerrit/72723)

ValueMetric, unlike the other metrics, was not safe to call from
multiple threads. This patch adds internal locking to ValueMetric to
ensure its safety.

Bug: 124459322
Bug: 70889998
Bug: 118584039
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: I55855ba8a5cdb2bbe1e15be7742304293245b5aa
2019-02-19 14:05:40 -08:00
John W. Bruce
42e21600a0 Do Not Add Parallel Unit Tests
(This is a merge of http://go/wvgerrit/71325)

Widevine CE CDM and the buildbot now have parallel operations unit
tests. These tests are not relevant on Android since it is not possible
to call into the Android CDM from multiple threads. However, there is
one change in CdmEngine that needs to be copied over to Android for
consistency's sake.

Bug: 70889998
Bug: 118584039
Test: Android Build
Change-Id: Iea5df62be256383e832b4fcfbd5ff5090e3f3b03
2019-02-19 13:59:16 -08:00
John W. Bruce
7e97ba4383 Split CryptoSession Lock into Three
(This is a merge of http://go/wvgerrit/71324)

This patch increases the granularity of the locking in CryptoSession
without substantially changing its locking semantics. Where before
there was a single |crypto_lock_| performing multiple duties, now
there are three locks:

1) |static_field_lock_|, which is used when needing to access the
   non-atomic static member fields of CryptoSession.
2) |oem_crypto_lock_|, which is used when needing to call into
   OEMCrypto.
3) |factory_lock_|, used only by the functions that interact with the
   CryptoSession factory.

All the code in CryptoSession has been updated to use these locks. It
has also been updated to only hold them for the minimal amount of time
necessary, as opposed to holding them for a whole function. This should
help some with the ability of CryptoSession calls to happen
concurrently. To assist in taking locks in a consistent manner, two
helper functions, |WithStaticFieldLock()| and |WithOecLock()| have been
added. Also, for the very common case of reading |initialized_|, the
accessor |IsInitialized()| will read the value safely.

While changing all the code to lock differently, I found that some
places in CryptoSession were *not* locking before accessing static state
or calling into OEMCrypto. I have made these callsites consistent with
the rest of CryptoSession.

As a result of taking locks for only the minimum time necessary, it is
no longer necessary for functions to make assumptions about whether the
lock will already be held before they are called. Locks should not be
held while calling helper functions, and code should always take a lock
for the brief time it is necessary to do so.

In tests, including the concurrent unit tests coming in the following
patch, this code did not perform substantially better or worse than the
code that preceded it, but the hope is that it will experience less
contention on devices that are more resource-constrained than my
desktop, such as older game consoles.

This patch appears to address some real threading issues. Hopefully, it
will also make it easier to maintain soundness in the future and to
reason about when code in CryptoSession needs to take a lock.

This is the first step to implementing the "Finer-Grained Locking in
CryptoSession" specification. A future patch will make some of these
locks reader-writer locks, to allow even greater parallelism.

Bug: 70889998
Bug: 118584039
Bug: 123319961
Test: CE CDM Unit Tests
Test: Android Unit Tests
Test: GTS
Test: Play Movies
Test: Netflix
Change-Id: I346c04a5d9875723db54af33ee91772bf49ca12f
2019-02-19 13:59:00 -08:00
Fred Gylys-Colwell
4389e262d1 Set max output buffer size in Mod Mock
Merge from Widevine repo of http://go/wvgerrit/72392

This adds the ability of the reference code to set the maximum output
buffer size error discussed in the Recoverable Errors section of
http://go/wvdelta15

Bug: http://b/120572363 Add Recoverable Errors (mod mock)
Change-Id: I688caca22929e29b3548c3f7d1df5de5bd37bfa1
2019-02-14 12:39:37 -08:00
Fred Gylys-Colwell
d20cf6c892 Keep OEMCrypto testbed singleton after terminate
Merge from Widevine repo of http://go/wvgerrit/72388

The unreleased oemcrypto test code has been modifed to keep a
singleton for the life of the process.  In order to do that, several
functions in the reference code have been made virtual, and some
initialization and termination has been moved from the constructor and
destructor to Initialize and Terminate.

Bug: http://b/120572363 Add Recoverable Errors (mod mock)
Test: unit tests
Change-Id: I300559195567a537c0700167514be0ea42363695
2019-02-13 21:51:59 -08:00
Fred Gylys-Colwell
b34c9db4c7 Update key control block logging
Merge from Widevine repo of http://go/wvgerrit/72386

This CL changes reference and testbed OEMCyrpto only.

Updates the logging of the key control block for testing by adding new
bits to log and cleaning up the format.

Also, update access to entitlement keys so that they can also have
their key control block logged in tests.

Test: reference and test code only.
Bug: http://b/113594182 Full Decrypt Path Testing - Top Level
Bug: http://b/68648263 Log Key Control Block
Change-Id: I259d6f29eceb9f097640aa50f43443e308797f69
2019-02-13 21:51:41 -08:00
Adam Stone
3448b2d4ec Merge changes I18139f67,Ib48361ef
* changes:
  Add device files error detail to metrics.
  Add error detail metric to some session methods
2019-02-13 18:31:21 +00:00
Adam Stone
5b49bf83a2 Add device files error detail to metrics.
[ Merge from http://go/wvgerrit/71923 ]

Plumb through the device files error detail and add the detail to
metrics.

Bug: http://b/115382201
Test: Unit tests, manual GPlay.
Change-Id: I18139f6712b6670be5fed863a97f9f03440745c7
2019-02-11 15:28:00 -08:00
Fred Gylys-Colwell
c54c2be6e8 Remove obsolete paragraph from docs
Merge from Widevine repo of http://go/wvgerrit/71743

Bug: 123436444 Update OEMCrypto threading documentation
Test: Doc change only
Change-Id: I186c803d5dfc20ce7e4fef6b9e16fd66c6dd3ad5
2019-02-11 10:09:10 -08:00
Adam Stone
605ff83103 Add error detail metric to some session methods
[ Merge from http://go/wvgerrit/71726 ]

Adds an error detail metric attribute to RestoreUsageSession and
RestoreOfflineSession. These metrics will now report an additional
attribute providing additional error detail for debugging.

BUG: http://b/115517916

Test: CDM Unit Tests. Manually tried GPlay.

Change-Id: Ib48361ef29d33a16150473d8967e4850bc0c623d
2019-02-08 12:51:12 -08:00
TreeHugger Robot
b56fd5e7bb Merge "Add a script to run the GTS and CTS media tests" 2019-02-08 20:22:39 +00:00
Peter Kalauskas
058e9a67d0 Add a script to run the GTS and CTS media tests
Test: Manual, use script
Change-Id: I16fe3cf6dbb0795b2397e8844480029403784d0b
2019-02-08 10:19:51 -08:00
Srujan Gaddam
6bd5c564d8 Test to ensure rollback doesn't affect key duration
Bug: b/78359032
Merge of http://go/wvgerrit/70544
Test: Android unit + integration tests/manual checking of system time to
make sure it's restored correctly

Integration tests are added to make sure that clock rollback of the
device system time does not affect key duration for both streaming and
offline licenses. These tests require root access as they modify system
time and restore them.

Change-Id: I3e1802205e2fc2056093c1e39b0ff6e0a8816abc
2019-02-07 17:26:32 -08:00
Adam Stone
05599927b9 Switch to using shared_ptr for Session Metrics
[ Merge from http://go/wvgerrit/71443 ]

The assumption that the metrics will always outlive the CdmSession
instance appears not to always hold (at least in a non-android
multi-threaded solution). The shared_ptr ensures that the metrics
are available even in these rare race conditions.

BUG: http://b/123321465
Test: CDM unit tests. Also http://go/wvgerrit/71264 parallel tests.
Change-Id: Iaa6a8f6c0fdc46a911789759d6e1228d849aa237
2019-02-04 10:19:06 -08:00
Adam Stone
9f31068de6 Merge "Add a metric decorator around cdm engine" 2019-02-04 17:55:35 +00:00
Rahul Frias
c9f7085f92 Merge "Enable provider client token test" 2019-02-01 21:44:02 +00:00
John Bruce
f8e46ebb34 Merge "Add a Reader-Writer Lock" 2019-02-01 19:32:43 +00:00
Fred Gylys-Colwell
4287df7d3d Merge "Revert "Remove Test Keybox Again"" 2019-02-01 19:23:31 +00:00
Rahul Frias
f83e813ea8 Enable provider client token test
[ Merge of http://go/wvgerrit/71907 ]

The client token needed to be enabled in the license request.

Bug: 123369846
Bug: 123370099
Test: WV unit/integration tests
Change-Id: I4d3e944b1d79010977c119291594878c406b00c5
2019-02-01 11:17:45 -08:00
Adam Stone
46eecb6b80 Add a metric decorator around cdm engine
[ Merge from http://go/wvgerrit/69105 ]

This adds a metric collecting decorator class around cdm engine. This
implementation uses a templated decorator. The decorator enables:

1) Wrapping the CDM Engine methods to capture timing and error
information.
2) Allows use of a mock CDM Engine for testing.

Test: Unit tests. GPlay manual testing and GTS tests.
BUG: http://b/64724336
Change-Id: I5e4a0f552974fab1939bc7ab02719a1f5849cf3f
2019-02-01 10:32:44 -08:00
Peter Kalauskas
7af3070120 Fix typo in comment
Test: None
Change-Id: I36dd6e8beb195cf4e6548b2486c2eb1195659c52
2019-01-31 22:36:19 +00:00
Rahul Frias
1cc4f71975 Merge "Add recoverable errors" 2019-01-31 15:26:38 +00:00
Rahul Frias
272e60db27 Add recoverable errors
[ Merge of http://go/wvgerrit/71326 ]

Nonce flood, frame size, session and system invalidation errors
will now bubble up to the app. OEMCrypto v15 returns
OEMCrypto_ERROR_BUFFER_TOO_LARGE, OEMCrypto_ERROR_SESSION_LOST_STATE,
OEMCrypto_ERROR_SYSTEM_INVALIDATED and a variety of nonce errors.
These will be reported to HIDL as OUTPUT_TOO_LARGE_ERROR,
ERROR_DRM_SESSION_LOST_STATE, ERROR_DRM_INVALID_STATE and
ERROR_DRM_RESOURCE_CONTENTION.

Bug: 120572706
Test: Unit/Integration tests
Change-Id: Ida177300046327ce81592a273028ef6c3a0d9fd9
2019-01-31 00:44:02 -08:00
Srujan Gaddam
137c472f7e Merge "Revert "Add relocs param to TerminateRuntime"" 2019-01-31 00:22:46 +00:00
Srujan Gaddam
252e437cc4 Revert "Add relocs param to TerminateRuntime"
This reverts commit ee45468c22.

Reason for revert: Segfaults occurring with 64-bit devices (B1 and C1) with the latest changes. The error condition points to SEGV_MAPERR, which combined with the build diff, leads me to believe this change caused the issue. b/123559319

Change-Id: I5255e14f74e2be229ffd8cd0765ca61a2a074139
2019-01-30 22:42:04 +00:00
Peter Kalauskas
afc46da6dc Merge "Add lazy service target to widevine" 2019-01-30 21:54:58 +00:00
Fred Gylys-Colwell
fca89868f8 Revert "Remove Test Keybox Again"
This reverts commit 408509efdc.

Reason for revert: just kidding. We want to run the tests on 
old devices, too.

Change-Id: I920fa825380638122f638e057bcfbe98b5f7b301
2019-01-30 19:17:06 +00:00
Peter Kalauskas
1afc15fba3 Add lazy service target to widevine
Test: Run widevine media GTS tests
Bug: 112386116
Change-Id: Id0a735def8d3bf4e71df1952c3d4d8034f3aabda
2019-01-30 09:26:09 -08:00
Jeff Tinker
8084bd5375 Implement isCryptoSchemeSupported in the Widevine drm plugin
Support overloaded isCryptoSchemeSupported method that
accepts a security level parameter

bug:110701831
test: cts media test cases, widevine integration tests, gts media tests

Change-Id: Ia84e40ff8d4f13fc06478e338e3238061e283dac
2019-01-30 07:10:10 +00:00
John W. Bruce
a1b5b42d55 Add a Reader-Writer Lock
(This is a merge of http://go/wvgerrit/70666)

We need a reader-writer lock implementation in order to make use of the
new threading guarantees in OEMCrypto v15. However, we do not have
access to an STL reader-writer lock due to only being on C++11. This
patch adds a home-grown reader-writer lock, as well as tests to verify
that its behavior is sound.

Bug: 70889998
Bug: 118584039
Test: CE CDM Unit Tests
Test: Android Unit Tests
Change-Id: Iaddcefb50e72452fbd27d04879eacf775484e675
2019-01-29 13:41:38 -08:00
Edwin Wong
54104c7a22 Implement MediaDrm offline license support in Widevine hidl service.
Merged from http://go/wvgerrit/69723.

The new APIs are getOfflineLicenseIds, getOfflineLicenseState and
removeOfflineLicense. These methods are currently stubbed out in
Widevine hidl service. This CL completes the implementation.

Test: unit tests - libwvdrmdrmplugin_hidl_test

Test: GTS
  --test com.google.android.media.gts.MediaDrmTest#testWidevineApi29

bug: 117570686
Change-Id: I96ffb75f453e36e931effefd3664b5faa8d69d30
2019-01-29 13:41:08 -08:00
Rahul Frias
19c4996b3c Merge "Modified return values for Restore operations" 2019-01-28 21:31:54 +00:00
Rahul Frias
7eb408e181 Merge "Support both PEM format and DER format intermediate certs" 2019-01-28 21:08:43 +00:00
Rahul Frias
61ef6b691a Merge "Add CDM integration test for offline renewal and release" 2019-01-28 21:06:48 +00:00
Rahul Frias
f60d2b87fa Merge "Add logging to Usage Table Header" 2019-01-28 20:03:09 +00:00
John Bruce
d21695d395 Merge "Add a cross-platform argument parser." 2019-01-28 18:29:10 +00:00
Srujan Gaddam
5e883463da Merge "Add relocs param to TerminateRuntime" 2019-01-28 18:28:48 +00:00