/*
 HeartRateServiceDiscoveryProfile
 Copyright (c) 2015 NTT DOCOMO,INC.
 Released under the MIT license
 http://opensource.org/licenses/mit-license.php
 */
package org.deviceconnect.android.deviceplugin.heartrate.profile;

import android.content.Intent;
import android.os.Bundle;

import org.deviceconnect.android.deviceplugin.heartrate.HeartRateApplication;
import org.deviceconnect.android.deviceplugin.heartrate.HeartRateDeviceService;
import org.deviceconnect.android.deviceplugin.heartrate.HeartRateManager;
import org.deviceconnect.android.deviceplugin.heartrate.ble.BleUtils;
import org.deviceconnect.android.deviceplugin.heartrate.data.HeartRateDevice;
import org.deviceconnect.android.profile.DConnectProfileProvider;
import org.deviceconnect.android.profile.ServiceDiscoveryProfile;
import org.deviceconnect.message.DConnectMessage;

import java.util.ArrayList;
import java.util.List;

/**
 * Implement ServiceDiscoveryProfile.
 * @author NTT DOCOMO, INC.
 */
public class HeartRateServiceDiscoveryProfile extends ServiceDiscoveryProfile {
    /**
     * コンストラクタ.
     * @param provider プロファイルプロバイダ
     */
    public HeartRateServiceDiscoveryProfile(final DConnectProfileProvider provider) {
        super(provider);
    }
    @Override
    protected boolean onGetServices(final Intent request, final Intent response) {
        if (!BleUtils.isBLESupported(getContext())) {
            mLogger.warning("BLE not supported.");
            List<Bundle> services = new ArrayList<>();
            setResult(response, DConnectMessage.RESULT_OK);
            setServices(response, services);
            return true;
        }

        List<Bundle> services = new ArrayList<>();
        List<HeartRateDevice> devices = getManager().getConnectedDevices();
        synchronized (devices) {
            for (HeartRateDevice device : devices) {
                Bundle service = new Bundle();
                service.putString(PARAM_ID, device.getAddress());
                service.putString(PARAM_NAME, device.getName());
                service.putString(PARAM_TYPE, NetworkType.BLE.getValue());
                service.putBoolean(PARAM_ONLINE, true);
                service.putString(PARAM_CONFIG, "");
                services.add(service);
            }
        }
        setResult(response, DConnectMessage.RESULT_OK);
        setServices(response, services);
        return true;
    }

    @Override
    protected boolean onPutOnServiceChange(Intent request, Intent response, String serviceId, String sessionKey) {
        return super.onPutOnServiceChange(request, response, serviceId, sessionKey);
    }

    @Override
    protected boolean onDeleteOnServiceChange(Intent request, Intent response, String serviceId, String sessionKey) {
        return super.onDeleteOnServiceChange(request, response, serviceId, sessionKey);
    }

    /**
     * Gets a instance of HeartRateManager.
     * @return instance of HeartRateManager
     */
    private HeartRateManager getManager() {
        HeartRateDeviceService service = (HeartRateDeviceService) getContext();
        HeartRateApplication app = (HeartRateApplication) service.getApplication();
        return app.getHeartRateManager();
    }
}

@@ -2197,24 +2197,82 @@
 ONFIG, %22%22);%0A
+                setScopes(service, getProfileProvider());%0A
             
@@ -2496,32 +2496,38 @@
 OnServiceChange(
+final 
 Intent request, 
@@ -2517,32 +2517,38 @@
  Intent request,
+ final
  Intent response
@@ -2540,32 +2540,81 @@
 Intent response,
+%0A                                           final
  String serviceI
@@ -2607,32 +2607,38 @@
 tring serviceId,
+ final
  String sessionK
@@ -2795,16 +2795,22 @@
 eChange(
+final 
 Intent r
@@ -2816,16 +2816,22 @@
 request,
+ final
  Intent 
@@ -2839,16 +2839,68 @@
 esponse,
+%0A                                              final
  String 
@@ -2909,16 +2909,22 @@
 rviceId,
+ final
  String 

Add "scopes" response parameter of Service Discovery API.