127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang/*
2917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski * Copyright (C) 2017 The Android Open Source Project
327bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang *
427bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang * Licensed under the Apache License, Version 2.0 (the "License");
527bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang * you may not use this file except in compliance with the License.
627bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang * You may obtain a copy of the License at
727bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang *
827bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang *      http://www.apache.org/licenses/LICENSE-2.0
927bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang *
1027bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang * Unless required by applicable law or agreed to in writing, software
1127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang * distributed under the License is distributed on an "AS IS" BASIS,
1227bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1327bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang * See the License for the specific language governing permissions and
1427bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang * limitations under the License.
1527bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang */
1627bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
1727bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangpackage com.android.bluetooth.gatt;
1827bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
19917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowskiimport android.bluetooth.le.AdvertiseData;
20917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowskiimport android.bluetooth.le.AdvertisingSetParameters;
21917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowskiimport android.bluetooth.le.IAdvertisingSetCallback;
22917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowskiimport android.bluetooth.le.PeriodicAdvertisingParameters;
2327bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport android.os.Handler;
2427bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport android.os.HandlerThread;
25917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowskiimport android.os.IBinder;
26917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowskiimport android.os.IInterface;
2727bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport android.os.Looper;
2827bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport android.os.Message;
2927bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport android.os.RemoteException;
3027bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport android.util.Log;
3127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport com.android.bluetooth.Utils;
3227bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport com.android.bluetooth.btservice.AdapterService;
33917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowskiimport java.util.Collections;
34917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowskiimport java.util.HashMap;
3527bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport java.util.HashSet;
36917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowskiimport java.util.Map;
3727bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport java.util.Set;
3827bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport java.util.UUID;
3927bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport java.util.concurrent.CountDownLatch;
4027bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangimport java.util.concurrent.TimeUnit;
4127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
4227bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang/**
43a1664d61821a59145f8095a75373403a0c54244eWei Wang * Manages Bluetooth LE advertising operations and interacts with bluedroid stack. TODO: add tests.
4427bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang *
4527bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang * @hide
4627bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang */
4727bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wangclass AdvertiseManager {
4827bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    private static final boolean DBG = GattServiceConfig.DBG;
4927bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    private static final String TAG = GattServiceConfig.TAG_PREFIX + "AdvertiseManager";
5027bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
5127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    private final GattService mService;
52a1664d61821a59145f8095a75373403a0c54244eWei Wang    private final AdapterService mAdapterService;
53917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    private Handler mHandler;
54917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    Map<IBinder, AdvertiserInfo> mAdvertisers = Collections.synchronizedMap(new HashMap<>());
55917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    static int sTempRegistrationId = -1;
5627bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
5727bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    /**
5827bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang     * Constructor of {@link AdvertiseManager}.
5927bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang     */
60a1664d61821a59145f8095a75373403a0c54244eWei Wang    AdvertiseManager(GattService service, AdapterService adapterService) {
61792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) Log.d(TAG, "advertise manager created");
62a1664d61821a59145f8095a75373403a0c54244eWei Wang        mService = service;
63a1664d61821a59145f8095a75373403a0c54244eWei Wang        mAdapterService = adapterService;
6427bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    }
6527bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
6627bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    /**
6727bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang     * Start a {@link HandlerThread} that handles advertising operations.
6827bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang     */
6927bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    void start() {
70917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        initializeNative();
7127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang        HandlerThread thread = new HandlerThread("BluetoothAdvertiseManager");
7227bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang        thread.start();
73917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        mHandler = new Handler(thread.getLooper());
7427bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    }
7527bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
7627bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    void cleanup() {
77792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) Log.d(TAG, "cleanup()");
78917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        cleanupNative();
79917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        mAdvertisers.clear();
80917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        sTempRegistrationId = -1;
81ba73d4b554ff0016d6b11a6102c2a75b5b0c149dMatadeen Mishra
82ba73d4b554ff0016d6b11a6102c2a75b5b0c149dMatadeen Mishra        if (mHandler != null) {
83ba73d4b554ff0016d6b11a6102c2a75b5b0c149dMatadeen Mishra            // Shut down the thread
84ba73d4b554ff0016d6b11a6102c2a75b5b0c149dMatadeen Mishra            mHandler.removeCallbacksAndMessages(null);
85ba73d4b554ff0016d6b11a6102c2a75b5b0c149dMatadeen Mishra            Looper looper = mHandler.getLooper();
86ba73d4b554ff0016d6b11a6102c2a75b5b0c149dMatadeen Mishra            if (looper != null) {
87ba73d4b554ff0016d6b11a6102c2a75b5b0c149dMatadeen Mishra                looper.quit();
88ba73d4b554ff0016d6b11a6102c2a75b5b0c149dMatadeen Mishra            }
89ba73d4b554ff0016d6b11a6102c2a75b5b0c149dMatadeen Mishra            mHandler = null;
90ba73d4b554ff0016d6b11a6102c2a75b5b0c149dMatadeen Mishra        }
9127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    }
9227bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
93917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    class AdvertiserInfo {
94917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        /* When id is negative, the registration is ongoing. When the registration finishes, id
95917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski         * becomes equal to advertiser_id */
96917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        public Integer id;
97917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        public AdvertisingSetDeathRecipient deathRecipient;
98917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        public IAdvertisingSetCallback callback;
99917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski
100917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        AdvertiserInfo(Integer id, AdvertisingSetDeathRecipient deathRecipient,
101917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski                IAdvertisingSetCallback callback) {
102917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            this.id = id;
103917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            this.deathRecipient = deathRecipient;
104917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            this.callback = callback;
1057bdbdb9c5c81e08957c442f91d70fb34d8b34ddeJakub Pawlowski        }
10664bf8e33481bb787aec895c603748eedb634a93bJakub Pawlowski    }
10764bf8e33481bb787aec895c603748eedb634a93bJakub Pawlowski
108917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    IBinder toBinder(IAdvertisingSetCallback e) {
109917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        return ((IInterface) e).asBinder();
11027bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    }
11127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
112917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    class AdvertisingSetDeathRecipient implements IBinder.DeathRecipient {
113917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        IAdvertisingSetCallback callback;
114917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski
115917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        public AdvertisingSetDeathRecipient(IAdvertisingSetCallback callback) {
116917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            this.callback = callback;
11727bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang        }
11827bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
119917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        @Override
120917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        public void binderDied() {
121917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            if (DBG) Log.d(TAG, "Binder is dead - unregistering advertising set");
122917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            stopAdvertisingSet(callback);
12327bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang        }
12427bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    }
12527bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
126917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    Map.Entry<IBinder, AdvertiserInfo> findAdvertiser(int advertiser_id) {
127917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        Map.Entry<IBinder, AdvertiserInfo> entry = null;
128917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        for (Map.Entry<IBinder, AdvertiserInfo> e : mAdvertisers.entrySet()) {
129917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            if (e.getValue().id == advertiser_id) {
130917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski                entry = e;
131917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski                break;
13218999c2cfd477050de0ca88c3a73458235d82656Wei Wang            }
13318999c2cfd477050de0ca88c3a73458235d82656Wei Wang        }
134917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        return entry;
13518999c2cfd477050de0ca88c3a73458235d82656Wei Wang    }
13618999c2cfd477050de0ca88c3a73458235d82656Wei Wang
1378cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void onAdvertisingSetStarted(int reg_id, int advertiser_id, int tx_power, int status)
1388cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            throws Exception {
139792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) {
140917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            Log.d(TAG, "onAdvertisingSetStarted() - reg_id=" + reg_id + ", advertiser_id="
141917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski                            + advertiser_id + ", status=" + status);
142792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        }
143917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski
144917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(reg_id);
14527bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
146917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        if (entry == null) {
147917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            Log.i(TAG, "onAdvertisingSetStarted() - no callback found for reg_id " + reg_id);
148917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            // Advertising set was stopped before it was properly registered.
149917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            stopAdvertisingSetNative(advertiser_id);
150917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            return;
15127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang        }
15227bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
153917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        IAdvertisingSetCallback callback = entry.getValue().callback;
154917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        if (status == 0) {
155917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            entry.setValue(
156917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski                    new AdvertiserInfo(advertiser_id, entry.getValue().deathRecipient, callback));
157917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        } else {
158917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            IBinder binder = entry.getKey();
159917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            binder.unlinkToDeath(entry.getValue().deathRecipient, 0);
160917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            mAdvertisers.remove(binder);
16127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang        }
16227bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
1638cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        callback.onAdvertisingSetStarted(advertiser_id, tx_power, status);
164917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    }
16527bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
1668cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void onAdvertisingEnabled(int advertiser_id, boolean enable, int status) throws Exception {
167792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) {
168792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato            Log.d(TAG, "onAdvertisingSetEnabled() - advertiser_id=" + advertiser_id + ", enable="
169792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato                            + enable + ", status=" + status);
170792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        }
17127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
172917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiser_id);
173917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        if (entry == null) {
174917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            Log.i(TAG, "onAdvertisingSetEnable() - no callback found for advertiser_id "
175917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski                            + advertiser_id);
176917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            return;
17727bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang        }
178917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski
179917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        IAdvertisingSetCallback callback = entry.getValue().callback;
180917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        callback.onAdvertisingEnabled(advertiser_id, enable, status);
18127bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    }
18227bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
183917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    void startAdvertisingSet(AdvertisingSetParameters parameters, AdvertiseData advertiseData,
184917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            AdvertiseData scanResponse, PeriodicAdvertisingParameters periodicParameters,
1857f4a31f44f61bf765dad1d3b570e314fa1a98f85Jakub Pawlowski            AdvertiseData periodicData, int duration, int maxExtAdvEvents,
1867f4a31f44f61bf765dad1d3b570e314fa1a98f85Jakub Pawlowski            IAdvertisingSetCallback callback) {
187917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        AdvertisingSetDeathRecipient deathRecipient = new AdvertisingSetDeathRecipient(callback);
188917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        IBinder binder = toBinder(callback);
189917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        try {
190917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            binder.linkToDeath(deathRecipient, 0);
191917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        } catch (RemoteException e) {
192917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            throw new IllegalArgumentException("Can't link to advertiser's death");
19327bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang        }
19427bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
195917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        String deviceName = AdapterService.getAdapterService().getName();
196917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        byte[] adv_data = AdvertiseHelper.advertiseDataToBytes(advertiseData, deviceName);
197917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        byte[] scan_response = AdvertiseHelper.advertiseDataToBytes(scanResponse, deviceName);
198917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        byte[] periodic_data = AdvertiseHelper.advertiseDataToBytes(periodicData, deviceName);
199917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski
200917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        int cb_id = --sTempRegistrationId;
201917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        mAdvertisers.put(binder, new AdvertiserInfo(cb_id, deathRecipient, callback));
202917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski
203792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) Log.d(TAG, "startAdvertisingSet() - reg_id=" + cb_id + ", callback: " + binder);
204b3246f3a27d269b4c0ef19cb2c8772d039eb26ccJakub Pawlowski        startAdvertisingSetNative(parameters, adv_data, scan_response, periodicParameters,
2057f4a31f44f61bf765dad1d3b570e314fa1a98f85Jakub Pawlowski                periodic_data, duration, maxExtAdvEvents, cb_id);
206917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    }
207917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski
20800129680f9863701255425567f408e66ec84caf1Jakub Pawlowski    void onOwnAddressRead(int advertiser_id, int addressType, String address)
20900129680f9863701255425567f408e66ec84caf1Jakub Pawlowski            throws RemoteException {
210792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) Log.d(TAG, "onOwnAddressRead() advertiser_id=" + advertiser_id);
21100129680f9863701255425567f408e66ec84caf1Jakub Pawlowski
21200129680f9863701255425567f408e66ec84caf1Jakub Pawlowski        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiser_id);
21300129680f9863701255425567f408e66ec84caf1Jakub Pawlowski        if (entry == null) {
21400129680f9863701255425567f408e66ec84caf1Jakub Pawlowski            Log.i(TAG, "onOwnAddressRead() - bad advertiser_id " + advertiser_id);
21500129680f9863701255425567f408e66ec84caf1Jakub Pawlowski            return;
21600129680f9863701255425567f408e66ec84caf1Jakub Pawlowski        }
21700129680f9863701255425567f408e66ec84caf1Jakub Pawlowski
21800129680f9863701255425567f408e66ec84caf1Jakub Pawlowski        IAdvertisingSetCallback callback = entry.getValue().callback;
21900129680f9863701255425567f408e66ec84caf1Jakub Pawlowski        callback.onOwnAddressRead(advertiser_id, addressType, address);
22000129680f9863701255425567f408e66ec84caf1Jakub Pawlowski    }
22100129680f9863701255425567f408e66ec84caf1Jakub Pawlowski
22200129680f9863701255425567f408e66ec84caf1Jakub Pawlowski    void getOwnAddress(int advertiserId) {
22300129680f9863701255425567f408e66ec84caf1Jakub Pawlowski        getOwnAddressNative(advertiserId);
22400129680f9863701255425567f408e66ec84caf1Jakub Pawlowski    }
22500129680f9863701255425567f408e66ec84caf1Jakub Pawlowski
226917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    void stopAdvertisingSet(IAdvertisingSetCallback callback) {
227917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        IBinder binder = toBinder(callback);
228917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        if (DBG) Log.d(TAG, "stopAdvertisingSet() " + binder);
22927bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
230917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        AdvertiserInfo adv = mAdvertisers.remove(binder);
231917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        if (adv == null) {
232917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            Log.e(TAG, "stopAdvertisingSet() - no client found for callback");
233917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            return;
234917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        }
23564bf8e33481bb787aec895c603748eedb634a93bJakub Pawlowski
236917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        Integer advertiser_id = adv.id;
237917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        binder.unlinkToDeath(adv.deathRecipient, 0);
23864bf8e33481bb787aec895c603748eedb634a93bJakub Pawlowski
239917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        if (advertiser_id < 0) {
240917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            Log.i(TAG, "stopAdvertisingSet() - advertiser not finished registration yet");
241917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            // Advertiser will be freed once initiated in onAdvertisingSetStarted()
242917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            return;
243917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        }
244e82cce565b1549001f5a70526239c2d92106f85aJakub Pawlowski
245917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        stopAdvertisingSetNative(advertiser_id);
2461642b48f9d3b00ca80d43830f9bfd6c15fa5ba66Jakub Pawlowski
2471642b48f9d3b00ca80d43830f9bfd6c15fa5ba66Jakub Pawlowski        try {
2481642b48f9d3b00ca80d43830f9bfd6c15fa5ba66Jakub Pawlowski            callback.onAdvertisingSetStopped(advertiser_id);
2491642b48f9d3b00ca80d43830f9bfd6c15fa5ba66Jakub Pawlowski        } catch (RemoteException e) {
2501642b48f9d3b00ca80d43830f9bfd6c15fa5ba66Jakub Pawlowski            Log.i(TAG, "error sending onAdvertisingSetStopped callback", e);
2511642b48f9d3b00ca80d43830f9bfd6c15fa5ba66Jakub Pawlowski        }
25227bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    }
25327bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
2547f4a31f44f61bf765dad1d3b570e314fa1a98f85Jakub Pawlowski    void enableAdvertisingSet(int advertiserId, boolean enable, int duration, int maxExtAdvEvents) {
2557f4a31f44f61bf765dad1d3b570e314fa1a98f85Jakub Pawlowski        enableAdvertisingSetNative(advertiserId, enable, duration, maxExtAdvEvents);
2568cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
2578cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
2588cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void setAdvertisingData(int advertiserId, AdvertiseData data) {
2598cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        String deviceName = AdapterService.getAdapterService().getName();
2608cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        setAdvertisingDataNative(
2618cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski                advertiserId, AdvertiseHelper.advertiseDataToBytes(data, deviceName));
2628cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
2638cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
2648cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void setScanResponseData(int advertiserId, AdvertiseData data) {
2658cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        String deviceName = AdapterService.getAdapterService().getName();
2668cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        setScanResponseDataNative(
2678cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski                advertiserId, AdvertiseHelper.advertiseDataToBytes(data, deviceName));
2688cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
2698cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
2708cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void setAdvertisingParameters(int advertiserId, AdvertisingSetParameters parameters) {
2718cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        setAdvertisingParametersNative(advertiserId, parameters);
2728cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
2738cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
2748cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void setPeriodicAdvertisingParameters(
2758cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            int advertiserId, PeriodicAdvertisingParameters parameters) {
2768cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        setPeriodicAdvertisingParametersNative(advertiserId, parameters);
2778cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
2788cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
2798cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void setPeriodicAdvertisingData(int advertiserId, AdvertiseData data) {
2808cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        String deviceName = AdapterService.getAdapterService().getName();
2818cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        setPeriodicAdvertisingDataNative(
2828cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski                advertiserId, AdvertiseHelper.advertiseDataToBytes(data, deviceName));
2838cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
2848cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
2858cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void setPeriodicAdvertisingEnable(int advertiserId, boolean enable) {
2868cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        setPeriodicAdvertisingEnableNative(advertiserId, enable);
2878cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
2888cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
2898cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void onAdvertisingDataSet(int advertiser_id, int status) throws Exception {
290792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) {
291792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato            Log.d(TAG,
292792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato                    "onAdvertisingDataSet() advertiser_id=" + advertiser_id + ", status=" + status);
293792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        }
2948cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
2958cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiser_id);
2968cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        if (entry == null) {
2978cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            Log.i(TAG, "onAdvertisingDataSet() - bad advertiser_id " + advertiser_id);
2988cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            return;
2998cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        }
3008cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3018cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        IAdvertisingSetCallback callback = entry.getValue().callback;
3028cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        callback.onAdvertisingDataSet(advertiser_id, status);
3038cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
3048cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3058cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void onScanResponseDataSet(int advertiser_id, int status) throws Exception {
306792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG)
307792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato            Log.d(TAG, "onScanResponseDataSet() advertiser_id=" + advertiser_id + ", status="
308792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato                            + status);
3098cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3108cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiser_id);
3118cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        if (entry == null) {
3128cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            Log.i(TAG, "onScanResponseDataSet() - bad advertiser_id " + advertiser_id);
3138cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            return;
3148cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        }
3158cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3168cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        IAdvertisingSetCallback callback = entry.getValue().callback;
3178cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        callback.onScanResponseDataSet(advertiser_id, status);
3188cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
3198cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3208cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void onAdvertisingParametersUpdated(int advertiser_id, int tx_power, int status)
3218cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            throws Exception {
322792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) {
323792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato            Log.d(TAG, "onAdvertisingParametersUpdated() advertiser_id=" + advertiser_id
324792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato                            + ", tx_power=" + tx_power + ", status=" + status);
325792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        }
3268cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3278cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiser_id);
3288cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        if (entry == null) {
3298cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            Log.i(TAG, "onAdvertisingParametersUpdated() - bad advertiser_id " + advertiser_id);
3308cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            return;
3318cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        }
3328cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3338cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        IAdvertisingSetCallback callback = entry.getValue().callback;
3348cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        callback.onAdvertisingParametersUpdated(advertiser_id, tx_power, status);
3358cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
3368cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3378cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void onPeriodicAdvertisingParametersUpdated(int advertiser_id, int status) throws Exception {
338792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) {
339792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato            Log.d(TAG, "onPeriodicAdvertisingParametersUpdated() advertiser_id=" + advertiser_id
340792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato                            + ", status=" + status);
341792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        }
3428cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3438cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiser_id);
3448cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        if (entry == null) {
3458cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            Log.i(TAG, "onPeriodicAdvertisingParametersUpdated() - bad advertiser_id "
3468cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski                            + advertiser_id);
3478cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            return;
3488cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        }
3498cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3508cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        IAdvertisingSetCallback callback = entry.getValue().callback;
3518cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        callback.onPeriodicAdvertisingParametersUpdated(advertiser_id, status);
3528cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
3538cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3548cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    void onPeriodicAdvertisingDataSet(int advertiser_id, int status) throws Exception {
355792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) {
356792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato            Log.d(TAG, "onPeriodicAdvertisingDataSet() advertiser_id=" + advertiser_id + ", status="
357792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato                            + status);
358792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        }
3598cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3608cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiser_id);
3618cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        if (entry == null) {
3628cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            Log.i(TAG, "onPeriodicAdvertisingDataSet() - bad advertiser_id " + advertiser_id);
3638cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            return;
3648cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        }
3658cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3668cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        IAdvertisingSetCallback callback = entry.getValue().callback;
3678cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        callback.onPeriodicAdvertisingDataSet(advertiser_id, status);
3688cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
3698cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3708afb5229a27e775f16f920c43db30061a7a96593Jakub Pawlowski    void onPeriodicAdvertisingEnabled(int advertiser_id, boolean enable, int status)
3718cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            throws Exception {
372792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        if (DBG) {
373792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato            Log.d(TAG, "onPeriodicAdvertisingEnabled() advertiser_id=" + advertiser_id + ", status="
374792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato                            + status);
375792b3b63ea8109fb0d30135e9249256f3d891d9eJoe Onorato        }
3768cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3778cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        Map.Entry<IBinder, AdvertiserInfo> entry = findAdvertiser(advertiser_id);
3788cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        if (entry == null) {
3798cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            Log.i(TAG, "onAdvertisingSetEnable() - bad advertiser_id " + advertiser_id);
3808cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            return;
3818cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        }
3828cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
3838cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski        IAdvertisingSetCallback callback = entry.getValue().callback;
3848afb5229a27e775f16f920c43db30061a7a96593Jakub Pawlowski        callback.onPeriodicAdvertisingEnabled(advertiser_id, enable, status);
3858cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    }
3868cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski
387917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    static {
388917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski        classInitNative();
38927bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang    }
39027bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang
391917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    private native static void classInitNative();
392917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    private native void initializeNative();
393917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    private native void cleanupNative();
394917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    private native void startAdvertisingSetNative(AdvertisingSetParameters parameters,
395917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski            byte[] advertiseData, byte[] scanResponse,
3967f4a31f44f61bf765dad1d3b570e314fa1a98f85Jakub Pawlowski            PeriodicAdvertisingParameters periodicParameters, byte[] periodicData, int duration,
3977f4a31f44f61bf765dad1d3b570e314fa1a98f85Jakub Pawlowski            int maxExtAdvEvents, int reg_id);
39800129680f9863701255425567f408e66ec84caf1Jakub Pawlowski    private native void getOwnAddressNative(int advertiserId);
399917f34e18aa235e68ac0663e24f52100e95970b7Jakub Pawlowski    private native void stopAdvertisingSetNative(int advertiser_id);
4007f4a31f44f61bf765dad1d3b570e314fa1a98f85Jakub Pawlowski    private native void enableAdvertisingSetNative(
4017f4a31f44f61bf765dad1d3b570e314fa1a98f85Jakub Pawlowski            int advertiserId, boolean enable, int duration, int maxExtAdvEvents);
4028cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    private native void setAdvertisingDataNative(int advertiserId, byte[] data);
4038cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    private native void setScanResponseDataNative(int advertiserId, byte[] data);
4048cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    private native void setAdvertisingParametersNative(
4058cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            int advertiserId, AdvertisingSetParameters parameters);
4068cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    private native void setPeriodicAdvertisingParametersNative(
4078cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski            int advertiserId, PeriodicAdvertisingParameters parameters);
4088cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    private native void setPeriodicAdvertisingDataNative(int advertiserId, byte[] data);
4098cc4343c3b71c7a4d57c0b8c669b0a6188185f6bJakub Pawlowski    private native void setPeriodicAdvertisingEnableNative(int advertiserId, boolean enable);
41027bd5f277ccf471f2fa9cd9151a2a226b51bc825Wei Wang}
411