// Path: buruberi-core/src/main/java/is/hello/buruberi/bluetooth/stacks/BluetoothStack.java
// public interface BluetoothStack {
//     /**
//      * The log tag that of BluetoothStack use.
//      */
//     String LOG_TAG = "Bluetooth." + BluetoothStack.class.getSimpleName();
// 
//     /**
//      * A local broadcast that indicates an implicit pairing request has been initiated by the system.
//      * <p>
//      * Only available starting in API level 19, Android KitKat.
//      *
//      * @see GattPeripheral#EXTRA_NAME for the name of the affected peripheral.
//      * @see GattPeripheral#EXTRA_ADDRESS for the address of the affected peripheral.
//      */
//     String ACTION_PAIRING_REQUEST = BluetoothStack.class.getName() + ".ACTION_PAIRING_REQUEST";
// 
// 
//     /**
//      * Performs a scan for peripherals matching a given set of criteria.
//      * <p>
//      * Yields {@link UserDisabledBuruberiException} if
//      * the device's Bluetooth radio is currently disabled.
//      *
//      * @see PeripheralCriteria
//      */
//     @RequiresPermission(allOf = {
//             Manifest.permission.BLUETOOTH,
//             Manifest.permission.BLUETOOTH_ADMIN,
//     })
//     @NonNull Observable<List<GattPeripheral>> discoverPeripherals(@NonNull PeripheralCriteria peripheralCriteria);
// 
//     /**
//      * Returns the RxJava {@code Scheduler} used for all stack operations.
//      */
//     @NonNull Scheduler getScheduler();
// 
//     /**
//      * Vends an observable configured appropriately for use with this {@code BluetoothStack}.
//      * @return A configured {@code Observable}.
//      * @see #getScheduler()
//      */
//     <T> Observable<T> newConfiguredObservable(@NonNull Observable.OnSubscribe<T> onSubscribe);
// 
//     /**
//      * Returns an observable that will continuously report the power state
//      * of the device's bluetooth radio.
//      *
//      * @see #isEnabled() for one time values.
//      */
//     @RequiresPermission(Manifest.permission.BLUETOOTH)
//     Observable<Boolean> enabled();
// 
//     /**
//      * Returns the current power state of the device's bluetooth radio.
//      *
//      * @see #enabled() for observations over time.
//      */
//     @RequiresPermission(Manifest.permission.BLUETOOTH)
//     boolean isEnabled();
// 
//     /**
//      * Turns on the device's Bluetooth radio.
//      *
//      * @see ChangePowerStateException
//      */
//     @RequiresPermission(allOf = {
//             Manifest.permission.BLUETOOTH,
//             Manifest.permission.BLUETOOTH_ADMIN,
//     })
//     Observable<Void> turnOn();
// 
//     /**
//      * Turns off the device's Bluetooth radio.
//      *
//      * @see ChangePowerStateException
//      */
//     @RequiresPermission(allOf = {
//             Manifest.permission.BLUETOOTH,
//             Manifest.permission.BLUETOOTH_ADMIN,
//     })
//     Observable<Void> turnOff();
// 
// 
//     /**
//      * Returns the logger facade associated with the {@code BluetoothStack}.
//      */
//     @NonNull LoggerFacade getLogger();
// 
// 
//     /**
//      * Writes the state of a peripheral into a {@code Parcelable} object.
//      *
//      * @param peripheral    The peripheral whose state needs to be saved.
//      * @return The saved state.
//      */
//     @Nullable Parcelable saveState(@NonNull GattPeripheral peripheral);
// 
//     /**
//      * Restores the saved state of a peripheral into a new object.
//      *
//      * @param savedState    The state to restore.
//      * @return A new peripheral representing the saved state.
//      */
//     GattPeripheral restoreState(@Nullable Parcelable savedState);
// }
// 
// Path: buruberi-core/src/main/java/is/hello/buruberi/bluetooth/stacks/util/LoggerFacade.java
// public interface LoggerFacade {
//     void error(@NonNull String tag, @Nullable String message, @Nullable Throwable e);
//     void warn(@NonNull String tag, @Nullable String message, @Nullable Throwable e);
//     void warn(@NonNull String tag, @Nullable String message);
//     void info(@NonNull String tag, @Nullable String message);
//     void debug(@NonNull String tag, @Nullable String message);
// }


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.ParcelUuid;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import is.hello.buruberi.bluetooth.stacks.BluetoothStack;
import is.hello.buruberi.bluetooth.stacks.util.LoggerFacade;
import rx.Observable;
import rx.Scheduler;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Action0;
/*
 * Copyright 2015 Hello Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
package is.hello.buruberi.bluetooth.stacks.android;




class HighPowerPeripheralScanner extends BroadcastReceiver implements Observable.OnSubscribe<List<BluetoothDevice>> {
    /**
     * Roughly how long the documentation says a scan should take.
     */
    private static final int SCAN_DURATION_S = 15;

    private final Context context;
    private final BluetoothAdapter adapter;
    private final Scheduler.Worker worker;
// Path: buruberi-core/src/main/java/is/hello/buruberi/bluetooth/stacks/BluetoothStack.java
// public interface BluetoothStack {
//     /**
//      * The log tag that of BluetoothStack use.
//      */
//     String LOG_TAG = "Bluetooth." + BluetoothStack.class.getSimpleName();
// 
//     /**
//      * A local broadcast that indicates an implicit pairing request has been initiated by the system.
//      * <p>
//      * Only available starting in API level 19, Android KitKat.
//      *
//      * @see GattPeripheral#EXTRA_NAME for the name of the affected peripheral.
//      * @see GattPeripheral#EXTRA_ADDRESS for the address of the affected peripheral.
//      */
//     String ACTION_PAIRING_REQUEST = BluetoothStack.class.getName() + ".ACTION_PAIRING_REQUEST";
// 
// 
//     /**
//      * Performs a scan for peripherals matching a given set of criteria.
//      * <p>
//      * Yields {@link UserDisabledBuruberiException} if
//      * the device's Bluetooth radio is currently disabled.
//      *
//      * @see PeripheralCriteria
//      */
//     @RequiresPermission(allOf = {
//             Manifest.permission.BLUETOOTH,
//             Manifest.permission.BLUETOOTH_ADMIN,
//     })
//     @NonNull Observable<List<GattPeripheral>> discoverPeripherals(@NonNull PeripheralCriteria peripheralCriteria);
// 
//     /**
//      * Returns the RxJava {@code Scheduler} used for all stack operations.
//      */
//     @NonNull Scheduler getScheduler();
// 
//     /**
//      * Vends an observable configured appropriately for use with this {@code BluetoothStack}.
//      * @return A configured {@code Observable}.
//      * @see #getScheduler()
//      */
//     <T> Observable<T> newConfiguredObservable(@NonNull Observable.OnSubscribe<T> onSubscribe);
// 
//     /**
//      * Returns an observable that will continuously report the power state
//      * of the device's bluetooth radio.
//      *
//      * @see #isEnabled() for one time values.
//      */
//     @RequiresPermission(Manifest.permission.BLUETOOTH)
//     Observable<Boolean> enabled();
// 
//     /**
//      * Returns the current power state of the device's bluetooth radio.
//      *
//      * @see #enabled() for observations over time.
//      */
//     @RequiresPermission(Manifest.permission.BLUETOOTH)
//     boolean isEnabled();
// 
//     /**
//      * Turns on the device's Bluetooth radio.
//      *
//      * @see ChangePowerStateException
//      */
//     @RequiresPermission(allOf = {
//             Manifest.permission.BLUETOOTH,
//             Manifest.permission.BLUETOOTH_ADMIN,
//     })
//     Observable<Void> turnOn();
// 
//     /**
//      * Turns off the device's Bluetooth radio.
//      *
//      * @see ChangePowerStateException
//      */
//     @RequiresPermission(allOf = {
//             Manifest.permission.BLUETOOTH,
//             Manifest.permission.BLUETOOTH_ADMIN,
//     })
//     Observable<Void> turnOff();
// 
// 
//     /**
//      * Returns the logger facade associated with the {@code BluetoothStack}.
//      */
//     @NonNull LoggerFacade getLogger();
// 
// 
//     /**
//      * Writes the state of a peripheral into a {@code Parcelable} object.
//      *
//      * @param peripheral    The peripheral whose state needs to be saved.
//      * @return The saved state.
//      */
//     @Nullable Parcelable saveState(@NonNull GattPeripheral peripheral);
// 
//     /**
//      * Restores the saved state of a peripheral into a new object.
//      *
//      * @param savedState    The state to restore.
//      * @return A new peripheral representing the saved state.
//      */
//     GattPeripheral restoreState(@Nullable Parcelable savedState);
// }
// 
// Path: buruberi-core/src/main/java/is/hello/buruberi/bluetooth/stacks/util/LoggerFacade.java
// public interface LoggerFacade {
//     void error(@NonNull String tag, @Nullable String message, @Nullable Throwable e);
//     void warn(@NonNull String tag, @Nullable String message, @Nullable Throwable e);
//     void warn(@NonNull String tag, @Nullable String message);
//     void info(@NonNull String tag, @Nullable String message);
//     void debug(@NonNull String tag, @Nullable String message);
// }


// Path: buruberi-core/src/main/java/is/hello/buruberi/bluetooth/stacks/android/HighPowerPeripheralScanner.java
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.ParcelUuid;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import is.hello.buruberi.bluetooth.stacks.BluetoothStack;
import is.hello.buruberi.bluetooth.stacks.util.LoggerFacade;
import rx.Observable;
import rx.Scheduler;
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Action0;

/*
 * Copyright 2015 Hello Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
package is.hello.buruberi.bluetooth.stacks.android;




class HighPowerPeripheralScanner extends BroadcastReceiver implements Observable.OnSubscribe<List<BluetoothDevice>> {
    /**
     * Roughly how long the documentation says a scan should take.
     */
    private static final int SCAN_DURATION_S = 15;

    private final Context context;
    private final BluetoothAdapter adapter;
    private final Scheduler.Worker worker;
    private final LoggerFacade logger;