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

Commit 1c98d85c authored by Marie Janssen's avatar Marie Janssen Committed by android-build-merger
Browse files

Merge "Bluetooth: remove BluetoothDiscoveryReceiver" am: 1ad23a71 am: 184506a7

am: 83fb10ae

Change-Id: Ib7a51c9cae91202087bfcc11e6eb18b219e84d36
parents 14db171c 83fb10ae
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -2047,15 +2047,6 @@
            </intent-filter>
        </activity>

        <receiver
            android:name=".bluetooth.BluetoothDiscoveryReceiver">
            <intent-filter>
                <action android:name="android.bluetooth.adapter.action.DISCOVERY_STARTED" />
                <action android:name="android.bluetooth.adapter.action.DISCOVERY_FINISHED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

        <receiver
            android:name=".bluetooth.DockEventReceiver">
            <intent-filter>
+0 −49
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * 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 com.android.settings.bluetooth;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.android.settingslib.bluetooth.BluetoothEventManager;

/**
 * BluetoothDiscoveryReceiver updates a timestamp when the
 * Bluetooth adapter starts or finishes discovery mode. This
 * is used to decide whether to open an alert dialog or
 * create a notification when we receive a pairing request.
 *
 * <p>Note that the discovery start/finish intents are also handled
 * by {@link BluetoothEventManager} to update the UI, if visible.
 */
public final class BluetoothDiscoveryReceiver extends BroadcastReceiver {
    private static final String TAG = "BluetoothDiscoveryReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.v(TAG, "Received: " + action);

        if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED) ||
                action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) {
            LocalBluetoothPreferences.persistDiscoveringTimestamp(context);
        }
    }
}
+1 −7
Original line number Diff line number Diff line
@@ -938,13 +938,7 @@ public final class DockService extends Service implements ServiceListener {
        public void onDeviceAdded(CachedBluetoothDevice cachedDevice) { }
        public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) { }
        public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { }

        @Override
        public void onScanningStateChanged(boolean started) {
            // TODO: Find a more unified place for a persistent BluetoothCallback to live
            // as this is not exactly dock related.
            LocalBluetoothPreferences.persistDiscoveringTimestamp(mContext);
        }
        public void onScanningStateChanged(boolean started) { }

        @Override
        public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
+7 −20
Original line number Diff line number Diff line
@@ -40,8 +40,6 @@ final class LocalBluetoothPreferences {
    // of raising notifications
    private static final int GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND = 60 * 1000;

    private static final String KEY_DISCOVERING_TIMESTAMP = "last_discovering_time";

    private static final String KEY_LAST_SELECTED_DEVICE = "last_selected_device";

    private static final String KEY_LAST_SELECTED_DEVICE_TIME = "last_selected_device_time";
@@ -95,12 +93,15 @@ final class LocalBluetoothPreferences {

        // If the device was discoverING recently
        LocalBluetoothAdapter adapter = manager.getBluetoothAdapter();
        if (adapter != null && adapter.isDiscovering()) {
        if (adapter != null) {
            if (adapter.isDiscovering()) {
                return true;
        } else if ((sharedPreferences.getLong(KEY_DISCOVERING_TIMESTAMP, 0) +
            }
            if ((adapter.getDiscoveryEndMillis() +
                GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
                return true;
            }
        }

        // If the device was picked in the device picker recently
        if (deviceAddress != null) {
@@ -147,20 +148,6 @@ final class LocalBluetoothPreferences {
        editor.apply();
    }

    static void persistDiscoveringTimestamp(final Context context) {
        // Load the shared preferences and edit it on a background
        // thread (but serialized!).
        QueuedWork.singleThreadExecutor().submit(new Runnable() {
                public void run() {
                    SharedPreferences.Editor editor = getSharedPreferences(context).edit();
                    editor.putLong(
                            KEY_DISCOVERING_TIMESTAMP,
                        System.currentTimeMillis());
                    editor.apply();
                }
            });
    }

    static boolean hasDockAutoConnectSetting(Context context, String addr) {
        return getSharedPreferences(context).contains(KEY_DOCK_AUTO_CONNECT + addr);
    }