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

Commit 4eba1d46 authored by jackqdyulei's avatar jackqdyulei Committed by android-build-merger
Browse files

Merge "Bind service in onCreate" into oc-dr1-dev

am: 4e4c73bf

Change-Id: Id317c4003fd560c5cff4da7191198aa17ea97f7b
parents 99eab3d5 4e4c73bf
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.IntentFilter;
import android.database.ContentObserver;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;
@@ -37,6 +38,7 @@ import com.android.settings.TetherSettings;
import com.android.settings.core.PreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnCreate;
import com.android.settingslib.core.lifecycle.events.OnDestroy;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
@@ -44,11 +46,12 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
import java.util.concurrent.atomic.AtomicReference;

import static android.os.UserManager.DISALLOW_CONFIG_TETHERING;

import static com.android.settingslib.RestrictedLockUtils.checkIfRestrictionEnforced;
import static com.android.settingslib.RestrictedLockUtils.hasBaseUserRestriction;

public class TetherPreferenceController extends PreferenceController
        implements LifecycleObserver, OnResume, OnPause, OnDestroy {
        implements LifecycleObserver, OnCreate, OnResume, OnPause, OnDestroy {

    private static final String KEY_TETHER_SETTINGS = "tether_settings";

@@ -56,7 +59,8 @@ public class TetherPreferenceController extends PreferenceController
    private final AtomicReference<BluetoothPan> mBluetoothPan;
    private final ConnectivityManager mConnectivityManager;
    private final BluetoothAdapter mBluetoothAdapter;
    private final BluetoothProfile.ServiceListener mBtProfileServiceListener =
    @VisibleForTesting
    final BluetoothProfile.ServiceListener mBtProfileServiceListener =
            new android.bluetooth.BluetoothProfile.ServiceListener() {
                public void onServiceConnected(int profile, BluetoothProfile proxy) {
                    mBluetoothPan.set((BluetoothPan) proxy);
@@ -92,10 +96,6 @@ public class TetherPreferenceController extends PreferenceController
        if (lifecycle != null) {
            lifecycle.addObserver(this);
        }
        if (mBluetoothAdapter != null) {
            mBluetoothAdapter.getProfileProxy(context, mBtProfileServiceListener,
                    BluetoothProfile.PAN);
        }
    }

    @Override
@@ -130,6 +130,14 @@ public class TetherPreferenceController extends PreferenceController
        return KEY_TETHER_SETTINGS;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        if (mBluetoothAdapter != null) {
            mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
                    BluetoothProfile.PAN);
        }
    }

    @Override
    public void onResume() {
        if (mAirplaneModeObserver == null) {
+11 −3
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.settings.network;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
@@ -77,6 +76,14 @@ public class TetherPreferenceControllerTest {
        ReflectionHelpers.setField(mController, "mPreference", mPreference);
    }

    @Test
    public void lifeCycle_onCreate_shouldInitBluetoothPan() {
        mController.onCreate(null);

        verify(mBluetoothAdapter).getProfileProxy(mContext, mController.mBtProfileServiceListener,
                BluetoothProfile.PAN);
    }

    @Test
    public void goThroughLifecycle_shouldDestoryBluetoothProfile() {
        final BluetoothPan pan = mock(BluetoothPan.class);
@@ -161,7 +168,8 @@ public class TetherPreferenceControllerTest {
        mController.onResume();

        verify(mContext).registerReceiver(
            any(TetherPreferenceController.TetherBroadcastReceiver.class), any(IntentFilter.class));
                any(TetherPreferenceController.TetherBroadcastReceiver.class),
                any(IntentFilter.class));
    }

    @Test