• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/av


Commit MetaInfo

Revision6c94bb8058cddf934f4fbe209e796621edbbefec (tree)
Time2020-01-20 19:53:58
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Android 9.0.0 release 52
-----BEGIN PGP SIGNATURE-----

iF0EABECAB0WIQRDQNE1cO+UXoOBCWTorT+BmrEOeAUCXhOwnQAKCRDorT+BmrEO
eMkKAKCIV2wV0O0evOlVrBhhNDSkChezXQCfUinmEb5ARo4wCZJvTxB6Lrde4Ho=
=Pezi
-----END PGP SIGNATURE-----

Merge tag 'android-9.0.0_r52' into pie-x86

Android 9.0.0 release 52

Change Summary

Incremental Difference

--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1723,7 +1723,8 @@ sp<media::IAudioRecord> AudioFlinger::createRecord(const CreateRecordInput& inpu
17231723 &output.notificationFrameCount,
17241724 clientUid, &output.flags,
17251725 input.clientInfo.clientTid,
1726- &lStatus, portId);
1726+ &lStatus, portId,
1727+ input.opPackageName);
17271728 LOG_ALWAYS_FATAL_IF((lStatus == NO_ERROR) && (recordTrack == 0));
17281729
17291730 // lStatus == BAD_TYPE means FAST flag was rejected: request a new input from
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -48,7 +48,9 @@
4848 #include <utils/TypeHelpers.h>
4949 #include <utils/Vector.h>
5050
51+#include <binder/AppOpsManager.h>
5152 #include <binder/BinderService.h>
53+#include <binder/IAppOpsCallback.h>
5254 #include <binder/MemoryDealer.h>
5355
5456 #include <system/audio.h>
--- a/services/audioflinger/RecordTracks.h
+++ b/services/audioflinger/RecordTracks.h
@@ -19,6 +19,39 @@
1919 #error This header file should only be included from AudioFlinger.h
2020 #endif
2121
22+// Checks and monitors OP_RECORD_AUDIO
23+class OpRecordAudioMonitor : public RefBase {
24+public:
25+ ~OpRecordAudioMonitor() override;
26+ bool hasOpRecordAudio() const;
27+
28+ static sp<OpRecordAudioMonitor> createIfNeeded(uid_t uid, const String16& opPackageName);
29+
30+private:
31+ OpRecordAudioMonitor(uid_t uid, const String16& opPackageName);
32+ void onFirstRef() override;
33+
34+ AppOpsManager mAppOpsManager;
35+
36+ class RecordAudioOpCallback : public BnAppOpsCallback {
37+ public:
38+ explicit RecordAudioOpCallback(const wp<OpRecordAudioMonitor>& monitor);
39+ void opChanged(int32_t op, const String16& packageName) override;
40+
41+ private:
42+ const wp<OpRecordAudioMonitor> mMonitor;
43+ };
44+
45+ sp<RecordAudioOpCallback> mOpCallback;
46+ // called by RecordAudioOpCallback when OP_RECORD_AUDIO is updated in AppOp callback
47+ // and in onFirstRef()
48+ void checkRecordAudio();
49+
50+ std::atomic_bool mHasOpRecordAudio;
51+ const uid_t mUid;
52+ const String16 mPackage;
53+};
54+
2255 // record track
2356 class RecordTrack : public TrackBase {
2457 public:
@@ -35,6 +68,7 @@ public:
3568 uid_t uid,
3669 audio_input_flags_t flags,
3770 track_type type,
71+ const String16& opPackageName,
3872 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
3973 virtual ~RecordTrack();
4074 virtual status_t initCheck() const;
@@ -65,7 +99,7 @@ public:
6599 virtual bool isFastTrack() const { return (mFlags & AUDIO_INPUT_FLAG_FAST) != 0; }
66100
67101 void setSilenced(bool silenced) { if (!isPatchTrack()) mSilenced = silenced; }
68- bool isSilenced() const { return mSilenced; }
102+ bool isSilenced() const;
69103
70104 status_t getActiveMicrophones(std::vector<media::MicrophoneInfo>* activeMicrophones);
71105
@@ -99,6 +133,11 @@ private:
99133 audio_input_flags_t mFlags;
100134
101135 bool mSilenced;
136+
137+ // used to enforce OP_RECORD_AUDIO
138+ uid_t mUid;
139+ String16 mOpPackageName;
140+ sp<OpRecordAudioMonitor> mOpRecordAudioMonitor;
102141 };
103142
104143 // playback track, used by PatchPanel
--- a/services/audioflinger/ServiceUtilities.h
+++ b/services/audioflinger/ServiceUtilities.h
@@ -14,12 +14,21 @@
1414 * limitations under the License.
1515 */
1616
17+#include <cutils/multiuser.h>
18+#include <private/android_filesystem_config.h>
1719 #include <unistd.h>
1820
1921 #include <binder/PermissionController.h>
2022
2123 namespace android {
2224
25+// Used for calls that should originate from system services.
26+// We allow that some services might have separate processes to
27+// handle multiple users, e.g. u10_system, u10_bluetooth, u10_radio.
28+static inline bool isServiceUid(uid_t uid) {
29+ return multiuser_get_app_id(uid) < AID_APP_START;
30+}
31+
2332 extern pid_t getpid_cached;
2433 bool isTrustedCallingUid(uid_t uid);
2534 bool recordingAllowed(const String16& opPackageName, pid_t pid, uid_t uid);
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -6778,7 +6778,7 @@ reacquire_wakelock:
67786778 // Sanitize before releasing if the track has no access to the source data
67796779 // An idle UID receives silence from non virtual devices until active
67806780 if (activeTrack->isSilenced()) {
6781- memset(activeTrack->mSink.raw, 0, framesOut * mFrameSize);
6781+ memset(activeTrack->mSink.raw, 0, framesOut * activeTrack->frameSize());
67826782 }
67836783 activeTrack->releaseBuffer(&activeTrack->mSink);
67846784 }
@@ -6921,7 +6921,8 @@ sp<AudioFlinger::RecordThread::RecordTrack> AudioFlinger::RecordThread::createRe
69216921 audio_input_flags_t *flags,
69226922 pid_t tid,
69236923 status_t *status,
6924- audio_port_handle_t portId)
6924+ audio_port_handle_t portId,
6925+ const String16& opPackageName)
69256926 {
69266927 size_t frameCount = *pFrameCount;
69276928 size_t notificationFrameCount = *pNotificationFrameCount;
@@ -7047,7 +7048,7 @@ sp<AudioFlinger::RecordThread::RecordTrack> AudioFlinger::RecordThread::createRe
70477048 track = new RecordTrack(this, client, attr, sampleRate,
70487049 format, channelMask, frameCount,
70497050 nullptr /* buffer */, (size_t)0 /* bufferSize */, sessionId, uid,
7050- *flags, TrackBase::TYPE_DEFAULT, portId);
7051+ *flags, TrackBase::TYPE_DEFAULT, opPackageName, portId);
70517052
70527053 lStatus = track->initCheck();
70537054 if (lStatus != NO_ERROR) {
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -1413,7 +1413,8 @@ public:
14131413 audio_input_flags_t *flags,
14141414 pid_t tid,
14151415 status_t *status /*non-NULL*/,
1416- audio_port_handle_t portId);
1416+ audio_port_handle_t portId,
1417+ const String16& opPackageName);
14171418
14181419 status_t start(RecordTrack* recordTrack,
14191420 AudioSystem::sync_event_t event,
--- a/services/audioflinger/TrackBase.h
+++ b/services/audioflinger/TrackBase.h
@@ -115,6 +115,8 @@ protected:
115115
116116 uint32_t channelCount() const { return mChannelCount; }
117117
118+ size_t frameSize() const { return mFrameSize; }
119+
118120 audio_channel_mask_t channelMask() const { return mChannelMask; }
119121
120122 virtual uint32_t sampleRate() const { return mSampleRate; }
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -1601,6 +1601,99 @@ void AudioFlinger::PlaybackThread::PatchTrack::restartIfDisabled()
16011601 // Record
16021602 // ----------------------------------------------------------------------------
16031603
1604+// ----------------------------------------------------------------------------
1605+// AppOp for audio recording
1606+// -------------------------------
1607+
1608+// static
1609+sp<AudioFlinger::RecordThread::OpRecordAudioMonitor>
1610+AudioFlinger::RecordThread::OpRecordAudioMonitor::createIfNeeded(
1611+ uid_t uid, const String16& opPackageName)
1612+{
1613+ if (isServiceUid(uid)) {
1614+ ALOGV("not silencing record for service uid:%d pack:%s",
1615+ uid, String8(opPackageName).string());
1616+ return nullptr;
1617+ }
1618+
1619+ if (opPackageName.size() == 0) {
1620+ Vector<String16> packages;
1621+ // no package name, happens with SL ES clients
1622+ // query package manager to find one
1623+ PermissionController permissionController;
1624+ permissionController.getPackagesForUid(uid, packages);
1625+ if (packages.isEmpty()) {
1626+ return nullptr;
1627+ } else {
1628+ ALOGV("using pack:%s for uid:%d", String8(packages[0]).string(), uid);
1629+ return new OpRecordAudioMonitor(uid, packages[0]);
1630+ }
1631+ }
1632+
1633+ return new OpRecordAudioMonitor(uid, opPackageName);
1634+}
1635+
1636+AudioFlinger::RecordThread::OpRecordAudioMonitor::OpRecordAudioMonitor(
1637+ uid_t uid, const String16& opPackageName)
1638+ : mHasOpRecordAudio(true), mUid(uid), mPackage(opPackageName)
1639+{
1640+}
1641+
1642+AudioFlinger::RecordThread::OpRecordAudioMonitor::~OpRecordAudioMonitor()
1643+{
1644+ if (mOpCallback != 0) {
1645+ mAppOpsManager.stopWatchingMode(mOpCallback);
1646+ }
1647+ mOpCallback.clear();
1648+}
1649+
1650+void AudioFlinger::RecordThread::OpRecordAudioMonitor::onFirstRef()
1651+{
1652+ checkRecordAudio();
1653+ mOpCallback = new RecordAudioOpCallback(this);
1654+ ALOGV("start watching OP_RECORD_AUDIO for pack:%s", String8(mPackage).string());
1655+ mAppOpsManager.startWatchingMode(AppOpsManager::OP_RECORD_AUDIO, mPackage, mOpCallback);
1656+}
1657+
1658+bool AudioFlinger::RecordThread::OpRecordAudioMonitor::hasOpRecordAudio() const {
1659+ return mHasOpRecordAudio.load();
1660+}
1661+
1662+// Called by RecordAudioOpCallback when OP_RECORD_AUDIO is updated in AppOp callback
1663+// and in onFirstRef()
1664+// Note this method is never called (and never to be) for audio server / patch record track
1665+// due to the UID in createIfNeeded(). As a result for those record track, it's:
1666+// - not called from constructor,
1667+// - not called from RecordAudioOpCallback because the callback is not installed in this case
1668+void AudioFlinger::RecordThread::OpRecordAudioMonitor::checkRecordAudio()
1669+{
1670+ const int32_t mode = mAppOpsManager.checkOp(AppOpsManager::OP_RECORD_AUDIO,
1671+ mUid, mPackage);
1672+ const bool hasIt = (mode == AppOpsManager::MODE_ALLOWED);
1673+ // verbose logging only log when appOp changed
1674+ ALOGI_IF(hasIt != mHasOpRecordAudio.load(),
1675+ "OP_RECORD_AUDIO missing, %ssilencing record uid%d pack:%s",
1676+ hasIt ? "un" : "", mUid, String8(mPackage).string());
1677+ mHasOpRecordAudio.store(hasIt);
1678+}
1679+
1680+AudioFlinger::RecordThread::OpRecordAudioMonitor::RecordAudioOpCallback::RecordAudioOpCallback(
1681+ const wp<OpRecordAudioMonitor>& monitor) : mMonitor(monitor)
1682+{ }
1683+
1684+void AudioFlinger::RecordThread::OpRecordAudioMonitor::RecordAudioOpCallback::opChanged(int32_t op,
1685+ const String16& packageName) {
1686+ UNUSED(packageName);
1687+ if (op != AppOpsManager::OP_RECORD_AUDIO) {
1688+ return;
1689+ }
1690+ sp<OpRecordAudioMonitor> monitor = mMonitor.promote();
1691+ if (monitor != NULL) {
1692+ monitor->checkRecordAudio();
1693+ }
1694+}
1695+
1696+//----------------------------------------
16041697 AudioFlinger::RecordHandle::RecordHandle(
16051698 const sp<AudioFlinger::RecordThread::RecordTrack>& recordTrack)
16061699 : BnAudioRecord(),
@@ -1654,6 +1747,7 @@ AudioFlinger::RecordThread::RecordTrack::RecordTrack(
16541747 uid_t uid,
16551748 audio_input_flags_t flags,
16561749 track_type type,
1750+ const String16& opPackageName,
16571751 audio_port_handle_t portId)
16581752 : TrackBase(thread, client, attr, sampleRate, format,
16591753 channelMask, frameCount, buffer, bufferSize, sessionId, uid, false /*isOut*/,
@@ -1666,7 +1760,8 @@ AudioFlinger::RecordThread::RecordTrack::RecordTrack(
16661760 mResamplerBufferProvider(NULL), // initialize in case of early constructor exit
16671761 mRecordBufferConverter(NULL),
16681762 mFlags(flags),
1669- mSilenced(false)
1763+ mSilenced(false),
1764+ mOpRecordAudioMonitor(OpRecordAudioMonitor::createIfNeeded(uid, opPackageName))
16701765 {
16711766 if (mCblk == NULL) {
16721767 return;
@@ -1852,6 +1947,14 @@ void AudioFlinger::RecordThread::RecordTrack::updateTrackFrameInfo(
18521947 mServerProxy->setTimestamp(local);
18531948 }
18541949
1950+bool AudioFlinger::RecordThread::RecordTrack::isSilenced() const {
1951+ if (mSilenced) {
1952+ return true;
1953+ }
1954+ // The monitor is only created for record tracks that can be silenced.
1955+ return mOpRecordAudioMonitor ? !mOpRecordAudioMonitor->hasOpRecordAudio() : false;
1956+}
1957+
18551958 status_t AudioFlinger::RecordThread::RecordTrack::getActiveMicrophones(
18561959 std::vector<media::MicrophoneInfo>* activeMicrophones)
18571960 {
@@ -1875,7 +1978,7 @@ AudioFlinger::RecordThread::PatchRecord::PatchRecord(RecordThread *recordThread,
18751978 : RecordTrack(recordThread, NULL,
18761979 audio_attributes_t{} /* currently unused for patch track */,
18771980 sampleRate, format, channelMask, frameCount,
1878- buffer, bufferSize, AUDIO_SESSION_NONE, getuid(), flags, TYPE_PATCH),
1981+ buffer, bufferSize, AUDIO_SESSION_NONE, getuid(), flags, TYPE_PATCH, String16()),
18791982 mProxy(new ClientProxy(mCblk, mBuffer, frameCount, mFrameSize, false, true))
18801983 {
18811984 uint64_t mixBufferNs = ((uint64_t)2 * recordThread->frameCount() * 1000000000) /