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

Commit c6f1535b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[CDM] Handle BackgroundServiceStartNotAllowedException being thrown by...

Merge "[CDM] Handle BackgroundServiceStartNotAllowedException being thrown by discovery service." into main
parents 005fc9ec d3d151b7
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -359,11 +359,7 @@ public class CompanionAssociationActivity extends FragmentActivity implements
                if (CompanionDeviceDiscoveryService.getScanResult().getValue().isEmpty()) {
                    // If the scan times out, do NOT close the activity automatically and let the
                    // user manually cancel the flow.
                    synchronized (LOCK) {
                        if (sDiscoveryStarted) {
                    stopDiscovery();
                        }
                    }
                    mTimeoutMessage.setText(getString(R.string.message_discovery_hard_timeout));
                    mTimeoutMessage.setVisibility(View.VISIBLE);
                }
@@ -455,10 +451,16 @@ public class CompanionAssociationActivity extends FragmentActivity implements
    }

    private void stopDiscovery() {
        if (mRequest != null && !mRequest.isSelfManaged()) {
        if (mRequest == null || mRequest.isSelfManaged()) {
            return;
        }

        synchronized (LOCK) {
            if (sDiscoveryStarted) {
                CompanionDeviceDiscoveryService.stop(this);
            }
        }
    }

    private void setResultAndFinish(@Nullable AssociationInfo association, int resultCode) {
        Slog.i(TAG, "setResultAndFinish(), association="
+12 −2
Original line number Diff line number Diff line
@@ -136,7 +136,12 @@ public class CompanionDeviceDiscoveryService extends Service {
        intent.setAction(ACTION_START_DISCOVERY);
        intent.putExtra(EXTRA_ASSOCIATION_REQUEST, associationRequest);

        try {
            context.startService(intent);
        } catch (IllegalStateException e) {
            Slog.e(TAG, "Failed to start discovery.", e);
            return false;
        }

        return true;
    }
@@ -144,7 +149,12 @@ public class CompanionDeviceDiscoveryService extends Service {
    static void stop(@NonNull Context context) {
        final Intent intent = new Intent(context, CompanionDeviceDiscoveryService.class);
        intent.setAction(ACTION_STOP_DISCOVERY);

        try {
            context.startService(intent);
        } catch (IllegalStateException e) {
            Slog.e(TAG, "Failed to stop discovery.", e);
        }
    }

    static LiveData<List<DeviceFilterPair<?>>> getScanResult() {