Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a30e55b authored by Paul McLean's avatar Paul McLean
Browse files

Disable "use always" button in the UsbResoveActivity for USB capture

device and non-record-permission apps.

Bug: 145857629
Test: install UsbAccess and UsbPersistentPermissionsTestApp,
connect USB audio capture device. Select the app to resolve to
notice that the "use always" checkbox is disabled.
Tested also after granting RECORD PERMISSION, "use always" is enabled.
Tested with non-audio USB device, "use always" is enabled.

Change-Id: I04eabaab3e36a5904e4447a0a7e0d40e169d8bee
parent 6ba1d759
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.PermissionChecker;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -657,8 +658,9 @@ public class ResolverActivity extends Activity implements
    private void setAlwaysButtonEnabled(boolean hasValidSelection, int checkedPos,
            boolean filtered) {
        boolean enabled = false;
        ResolveInfo ri = null;
        if (hasValidSelection) {
            ResolveInfo ri = mAdapter.resolveInfoForPosition(checkedPos, filtered);
            ri = mAdapter.resolveInfoForPosition(checkedPos, filtered);
            if (ri == null) {
                Log.e(TAG, "Invalid position supplied to setAlwaysButtonEnabled");
                return;
@@ -676,6 +678,24 @@ public class ResolverActivity extends Activity implements
                        .getString(R.string.activity_resolver_use_always));
            }
        }

        ActivityInfo activityInfo = ri.activityInfo;

        boolean hasRecordPermission =
                PermissionChecker.checkPermissionForPreflight(
                        getApplicationContext(),
                        android.Manifest.permission.RECORD_AUDIO, -1,
                        activityInfo.applicationInfo.uid,
                        activityInfo.packageName)
                        == android.content.pm.PackageManager.PERMISSION_GRANTED;

        if (!hasRecordPermission) {
            // OK, we know the record permission, is this a capture device
            boolean hasAudioCapture =
                    getIntent().getBooleanExtra(
                            ResolverActivity.EXTRA_IS_AUDIO_CAPTURE_DEVICE, false);
            enabled = !hasAudioCapture;
        }
        mAlwaysButton.setEnabled(enabled);
    }

@@ -1048,7 +1068,6 @@ public class ResolverActivity extends Activity implements
        Intent startIntent = getIntent();
        boolean isAudioCaptureDevice =
                startIntent.getBooleanExtra(EXTRA_IS_AUDIO_CAPTURE_DEVICE, false);

        return new ResolverListAdapter(context, payloadIntents, initialIntents, rList,
                filterLastUsed, createListController(), useLayoutForBrowsables, this,
                isAudioCaptureDevice);