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

Commit 4e6b4435 authored by Zach Johnson's avatar Zach Johnson
Browse files

Remove ProfileObserver

Disabled profiles shouldn't be controlled via
settings global. If we need something like this,
it should be a proper API.

Bug: 145171640
Test: compile, verify starts up
Change-Id: If4a1561d9aad304bd631c8250c3b3576eeb21268
parent 5a1439af
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -210,7 +210,6 @@ public class AdapterService extends Service {
    private String mWakeLockName;
    private UserManager mUserManager;

    private ProfileObserver mProfileObserver;
    private PhonePolicy mPhonePolicy;
    private ActiveDeviceManager mActiveDeviceManager;
    private DatabaseManager mDatabaseManager;
@@ -445,8 +444,6 @@ public class AdapterService extends Service {

        mSdpManager = SdpManager.init(this);
        registerReceiver(mAlarmBroadcastReceiver, new IntentFilter(ACTION_ALARM_WAKEUP));
        mProfileObserver = new ProfileObserver(getApplicationContext(), this, new Handler());
        mProfileObserver.start();

        // Phone policy is specific to phone implementations and hence if a device wants to exclude
        // it out then it can be disabled by using the flag below.
@@ -520,7 +517,6 @@ public class AdapterService extends Service {
    @Override
    public void onDestroy() {
        debugLog("onDestroy()");
        mProfileObserver.stop();
        if (!isMock()) {
            // TODO(b/27859763)
            Log.i(TAG, "Force exit to cleanup internal state in Bluetooth stack");
+0 −70
Original line number Diff line number Diff line
package com.android.bluetooth.btservice;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.os.Handler;
import android.provider.Settings;

/**
 * This helper class monitors the state of the enabled profiles and will update and restart
 * the adapter when necessary.
 */
public class ProfileObserver extends ContentObserver {
    private Context mContext;
    private AdapterService mService;
    private AdapterStateObserver mStateObserver;

    public ProfileObserver(Context context, AdapterService service, Handler handler) {
        super(handler);
        mContext = context;
        mService = service;
        mStateObserver = new AdapterStateObserver(this);
    }

    public void start() {
        mContext.getContentResolver()
                .registerContentObserver(
                        Settings.Global.getUriFor(Settings.Global.BLUETOOTH_DISABLED_PROFILES),
                        false, this);
    }

    private void onBluetoothOff() {
        mContext.unregisterReceiver(mStateObserver);
        Config.init(mContext);
        mService.enable(false);
    }

    public void stop() {
        mContext.getContentResolver().unregisterContentObserver(this);
    }

    @Override
    public void onChange(boolean selfChange) {
        if (mService.isEnabled()) {
            mContext.registerReceiver(mStateObserver,
                    new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
            mService.disable();
        }
    }

    private static class AdapterStateObserver extends BroadcastReceiver {
        private ProfileObserver mProfileObserver;

        AdapterStateObserver(ProfileObserver observer) {
            mProfileObserver = observer;
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())
                    && intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1)
                    == BluetoothAdapter.STATE_OFF) {
                mProfileObserver.onBluetoothOff();
            }
        }
    }
}