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;
import com.android.settingslib.core.AbstractPreferenceController;
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;
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 AbstractPreferenceController
- implements PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause, OnDestroy {
+public class TetherPreferenceController extends AbstractPreferenceController implements
+ PreferenceControllerMixin, LifecycleObserver, OnCreate, OnResume, OnPause, OnDestroy {
private static final String KEY_TETHER_SETTINGS = "tether_settings";
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);
if (lifecycle != null) {
lifecycle.addObserver(this);
}
- if (mBluetoothAdapter != null) {
- mBluetoothAdapter.getProfileProxy(context, mBtProfileServiceListener,
- BluetoothProfile.PAN);
- }
}
@Override
}
@Override
+ public void onCreate(Bundle savedInstanceState) {
+ if (mBluetoothAdapter != null) {
+ mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
+ BluetoothProfile.PAN);
+ }
+ }
+
+ @Override
public void onResume() {
if (mAirplaneModeObserver == null) {
mAirplaneModeObserver = new SettingObserver();
mTetherReceiver = new TetherBroadcastReceiver();
}
mContext.registerReceiver(
- mTetherReceiver, new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
+ mTetherReceiver, new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
mContext.getContentResolver()
.registerContentObserver(mAirplaneModeObserver.uri, false, mAirplaneModeObserver);
}
package com.android.settings.network;
-
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothProfile;
}
@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);
final AtomicReference<BluetoothPan> panRef =
mController.onResume();
verify(mContext).registerReceiver(
- any(TetherPreferenceController.TetherBroadcastReceiver.class), any(IntentFilter.class));
+ any(TetherPreferenceController.TetherBroadcastReceiver.class),
+ any(IntentFilter.class));
}
@Test
mController.onPause();
verify(mContext).unregisterReceiver(
- any(TetherPreferenceController.TetherBroadcastReceiver.class));
+ any(TetherPreferenceController.TetherBroadcastReceiver.class));
}
@Test