|
16 | 16 |
|
17 | 17 | package com.mobileer.oboetester; |
18 | 18 |
|
| 19 | +import static android.content.pm.PackageManager.GET_ATTRIBUTIONS; |
| 20 | +import static android.content.pm.PackageManager.GET_ATTRIBUTIONS_LONG; |
19 | 21 | import static com.mobileer.oboetester.AudioForegroundService.ACTION_START; |
20 | 22 | import static com.mobileer.oboetester.AudioForegroundService.ACTION_STOP; |
21 | 23 |
|
22 | 24 | import android.content.Context; |
23 | 25 | import android.content.Intent; |
| 26 | +import android.content.pm.ApplicationInfo; |
| 27 | +import android.content.pm.Attribution; |
24 | 28 | import android.content.pm.PackageInfo; |
25 | 29 | import android.content.pm.PackageManager; |
26 | 30 | import android.content.pm.ServiceInfo; |
@@ -733,6 +737,38 @@ private void openStreamContext(StreamContext streamContext) throws IOException { |
733 | 737 | return; |
734 | 738 | } |
735 | 739 |
|
| 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 | + |
736 | 772 | streamContext.tester.open(); // OPEN the stream |
737 | 773 |
|
738 | 774 | mSampleRate = actualConfig.getSampleRate(); |
|
0 commit comments