Skip to content

Commit 305cb88

Browse files
committed
query actual attribution tag
1 parent 892aef7 commit 305cb88

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

apps/OboeTester/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3-
<attribution android:tag="AudioTag"
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.mobileer.oboetester">
4+
<attribution
5+
android:tag="AudioTag"
46
android:label="@string/audio_attribution_label" />
57

68
<uses-feature

apps/OboeTester/app/src/main/java/com/mobileer/oboetester/AudioStreamTester.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ AudioStreamBase getCurrentAudioStream() {
2828
}
2929

3030
public void open() throws IOException {
31-
requestedConfiguration.setPackageName(BuildConfig.APPLICATION_ID);
32-
requestedConfiguration.setAttributionTag("AudioTag"); // Match attribution in AndroidManifest.xml
3331
mCurrentAudioStream.open(requestedConfiguration, actualConfiguration,
3432
-1);
3533
}

apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestAudioActivity.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616

1717
package com.mobileer.oboetester;
1818

19+
import static android.content.pm.PackageManager.GET_ATTRIBUTIONS;
20+
import static android.content.pm.PackageManager.GET_ATTRIBUTIONS_LONG;
1921
import static com.mobileer.oboetester.AudioForegroundService.ACTION_START;
2022
import static com.mobileer.oboetester.AudioForegroundService.ACTION_STOP;
2123

2224
import android.content.Context;
2325
import android.content.Intent;
26+
import android.content.pm.ApplicationInfo;
27+
import android.content.pm.Attribution;
2428
import android.content.pm.PackageInfo;
2529
import android.content.pm.PackageManager;
2630
import android.content.pm.ServiceInfo;
@@ -733,6 +737,38 @@ private void openStreamContext(StreamContext streamContext) throws IOException {
733737
return;
734738
}
735739

740+
String packageName = "";
741+
String attributionTag = "";
742+
try {
743+
PackageManager packageManager = getPackageManager();
744+
packageName = getPackageName();
745+
746+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
747+
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, GET_ATTRIBUTIONS);
748+
749+
Attribution[] attributions = null;
750+
attributions = packageInfo.attributions;
751+
752+
if (attributions != null && attributions.length > 0) {
753+
Log.i(TAG, "Declared Attributions:");
754+
for (Attribution attribution : attributions) {
755+
String tag = attribution.getTag();
756+
attributionTag = tag;
757+
758+
Log.i(TAG, "Tag: " + tag);
759+
}
760+
} else {
761+
Log.i(TAG, "No attributions declared or found.");
762+
}
763+
}
764+
765+
} catch (PackageManager.NameNotFoundException e) {
766+
Log.e(TAG, "Package not found", e);
767+
}
768+
769+
requestedConfig.setPackageName(packageName);
770+
requestedConfig.setAttributionTag(attributionTag);
771+
736772
streamContext.tester.open(); // OPEN the stream
737773

738774
mSampleRate = actualConfig.getSampleRate();

0 commit comments

Comments
 (0)