Merge changes Ie1f934b4,Ic3b045a6
* changes: Create BluetoothSwitchPreference Add ConnectedUsbDeviceUpdater
This commit is contained in:
@@ -38,6 +38,7 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
//TODO(b/69926683): remove this controller in Android P.
|
||||
public class BluetoothMasterSwitchPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, OnSummaryChangeListener, LifecycleObserver, OnResume,
|
||||
OnPause, OnStart, OnStop {
|
||||
|
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.content.Context;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.SwitchWidgetController;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
/**
|
||||
* PreferenceController to update of bluetooth {@link SwitchPreference}. It will
|
||||
*
|
||||
* 1. Invoke the user toggle
|
||||
* 2. Listen to the update from {@link LocalBluetoothManager}
|
||||
*/
|
||||
public class BluetoothSwitchPreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
public static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth_switch";
|
||||
|
||||
private LocalBluetoothManager mBluetoothManager;
|
||||
private SwitchPreference mBtPreference;
|
||||
private BluetoothEnabler mBluetoothEnabler;
|
||||
private RestrictionUtils mRestrictionUtils;
|
||||
@VisibleForTesting
|
||||
LocalBluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
public BluetoothSwitchPreferenceController(Context context) {
|
||||
this(context, Utils.getLocalBtManager(context), new RestrictionUtils());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public BluetoothSwitchPreferenceController(Context context,
|
||||
LocalBluetoothManager bluetoothManager, RestrictionUtils restrictionUtils) {
|
||||
super(context, KEY_TOGGLE_BLUETOOTH);
|
||||
mBluetoothManager = bluetoothManager;
|
||||
mRestrictionUtils = restrictionUtils;
|
||||
|
||||
if (mBluetoothManager != null) {
|
||||
mBluetoothAdapter = mBluetoothManager.getBluetoothAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mBtPreference = (SwitchPreference) screen.findPreference(KEY_TOGGLE_BLUETOOTH);
|
||||
mBluetoothEnabler = new BluetoothEnabler(mContext,
|
||||
new SwitchController(mBtPreference),
|
||||
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(), mBluetoothManager,
|
||||
MetricsEvent.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE,
|
||||
mRestrictionUtils);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mBluetoothAdapter != null ? AVAILABLE : DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mBluetoothEnabler.resume(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mBluetoothEnabler.pause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mBluetoothAdapter != null ? mBluetoothAdapter.isEnabled() : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChecked(boolean isChecked) {
|
||||
if (mBluetoothAdapter != null) {
|
||||
mBluetoothAdapter.setBluetoothEnabled(isChecked);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Control the switch inside {@link SwitchPreference}
|
||||
*/
|
||||
@VisibleForTesting
|
||||
class SwitchController extends SwitchWidgetController implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
private SwitchPreference mSwitchPreference;
|
||||
|
||||
public SwitchController(SwitchPreference switchPreference) {
|
||||
mSwitchPreference = switchPreference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTitle(boolean isChecked) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startListening() {
|
||||
mSwitchPreference.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListening() {
|
||||
mSwitchPreference.setOnPreferenceChangeListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChecked(boolean checked) {
|
||||
mSwitchPreference.setChecked(checked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mSwitchPreference.isChecked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
mSwitchPreference.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (mListener != null) {
|
||||
return mListener.onSwitchToggled((Boolean) newValue);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisabledByAdmin(RestrictedLockUtils.EnforcedAdmin admin) {
|
||||
mBtPreference.setEnabled(admin == null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -24,6 +24,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.bluetooth.BluetoothFilesPreferenceController;
|
||||
import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
|
||||
import com.android.settings.bluetooth.BluetoothSwitchPreferenceController;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.deviceinfo.UsbBackend;
|
||||
@@ -83,10 +84,8 @@ public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment
|
||||
mUsbPrefController = new UsbModePreferenceController(context, new UsbBackend(context));
|
||||
lifecycle.addObserver(mUsbPrefController);
|
||||
controllers.add(mUsbPrefController);
|
||||
final BluetoothMasterSwitchPreferenceController bluetoothPreferenceController =
|
||||
new BluetoothMasterSwitchPreferenceController(
|
||||
context, Utils.getLocalBtManager(context), this,
|
||||
(SettingsActivity) getActivity());
|
||||
final BluetoothSwitchPreferenceController bluetoothPreferenceController =
|
||||
new BluetoothSwitchPreferenceController(context);
|
||||
lifecycle.addObserver(bluetoothPreferenceController);
|
||||
controllers.add(bluetoothPreferenceController);
|
||||
|
||||
|
@@ -19,6 +19,7 @@ import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
|
||||
import com.android.settings.bluetooth.ConnectedBluetoothDeviceUpdater;
|
||||
@@ -42,26 +43,31 @@ public class ConnectedDeviceGroupController extends AbstractPreferenceController
|
||||
@VisibleForTesting
|
||||
PreferenceGroup mPreferenceGroup;
|
||||
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||
private ConnectedUsbDeviceUpdater mConnectedUsbDeviceUpdater;
|
||||
|
||||
public ConnectedDeviceGroupController(DashboardFragment fragment, Lifecycle lifecycle) {
|
||||
super(fragment.getContext());
|
||||
init(lifecycle, new ConnectedBluetoothDeviceUpdater(fragment, this));
|
||||
init(lifecycle, new ConnectedBluetoothDeviceUpdater(fragment, this),
|
||||
new ConnectedUsbDeviceUpdater(fragment.getContext(), this));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ConnectedDeviceGroupController(DashboardFragment fragment, Lifecycle lifecycle,
|
||||
BluetoothDeviceUpdater bluetoothDeviceUpdater) {
|
||||
BluetoothDeviceUpdater bluetoothDeviceUpdater,
|
||||
ConnectedUsbDeviceUpdater connectedUsbDeviceUpdater) {
|
||||
super(fragment.getContext());
|
||||
init(lifecycle, bluetoothDeviceUpdater);
|
||||
init(lifecycle, bluetoothDeviceUpdater, connectedUsbDeviceUpdater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mBluetoothDeviceUpdater.registerCallback();
|
||||
mConnectedUsbDeviceUpdater.registerCallback();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mConnectedUsbDeviceUpdater.unregisterCallback();
|
||||
mBluetoothDeviceUpdater.unregisterCallback();
|
||||
}
|
||||
|
||||
@@ -70,8 +76,10 @@ public class ConnectedDeviceGroupController extends AbstractPreferenceController
|
||||
super.displayPreference(screen);
|
||||
mPreferenceGroup = (PreferenceGroup) screen.findPreference(KEY);
|
||||
mPreferenceGroup.setVisible(false);
|
||||
|
||||
mBluetoothDeviceUpdater.setPrefContext(screen.getContext());
|
||||
mBluetoothDeviceUpdater.forceUpdate();
|
||||
mConnectedUsbDeviceUpdater.initUsbPreference(screen.getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,10 +108,12 @@ public class ConnectedDeviceGroupController extends AbstractPreferenceController
|
||||
}
|
||||
}
|
||||
|
||||
private void init(Lifecycle lifecycle, BluetoothDeviceUpdater bluetoothDeviceUpdater) {
|
||||
private void init(Lifecycle lifecycle, BluetoothDeviceUpdater bluetoothDeviceUpdater,
|
||||
ConnectedUsbDeviceUpdater connectedUsbDeviceUpdater) {
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
|
||||
mConnectedUsbDeviceUpdater = connectedUsbDeviceUpdater;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.connecteddevice;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.deviceinfo.UsbBackend;
|
||||
import com.android.settings.deviceinfo.UsbModeChooserActivity;
|
||||
import com.android.settings.widget.GearPreference;
|
||||
|
||||
/**
|
||||
* Controller to maintain connected usb device
|
||||
*/
|
||||
public class ConnectedUsbDeviceUpdater {
|
||||
private Context mContext;
|
||||
private UsbBackend mUsbBackend;
|
||||
private DevicePreferenceCallback mDevicePreferenceCallback;
|
||||
@VisibleForTesting
|
||||
GearPreference mUsbPreference;
|
||||
@VisibleForTesting
|
||||
UsbConnectionBroadcastReceiver mUsbReceiver;
|
||||
|
||||
private UsbConnectionBroadcastReceiver.UsbConnectionListener mUsbConnectionListener =
|
||||
(connected) -> {
|
||||
if (connected) {
|
||||
mUsbPreference.setSummary(
|
||||
UsbModePreferenceController.getSummary(mUsbBackend.getCurrentMode()));
|
||||
mDevicePreferenceCallback.onDeviceAdded(mUsbPreference);
|
||||
} else {
|
||||
mDevicePreferenceCallback.onDeviceRemoved(mUsbPreference);
|
||||
}
|
||||
};
|
||||
|
||||
public ConnectedUsbDeviceUpdater(Context context,
|
||||
DevicePreferenceCallback devicePreferenceCallback) {
|
||||
this(context, devicePreferenceCallback, new UsbBackend(context));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ConnectedUsbDeviceUpdater(Context context, DevicePreferenceCallback devicePreferenceCallback,
|
||||
UsbBackend usbBackend) {
|
||||
mContext = context;
|
||||
mDevicePreferenceCallback = devicePreferenceCallback;
|
||||
mUsbBackend = usbBackend;
|
||||
mUsbReceiver = new UsbConnectionBroadcastReceiver(context, mUsbConnectionListener);
|
||||
}
|
||||
|
||||
public void registerCallback() {
|
||||
// This method could handle multiple register
|
||||
mUsbReceiver.register();
|
||||
}
|
||||
|
||||
public void unregisterCallback() {
|
||||
mUsbReceiver.unregister();
|
||||
}
|
||||
|
||||
public void initUsbPreference(Context context) {
|
||||
mUsbPreference = new GearPreference(context, null /* AttributeSet */);
|
||||
mUsbPreference.setTitle(R.string.usb_pref);
|
||||
mUsbPreference.setIcon(R.drawable.ic_usb);
|
||||
mUsbPreference.setSelectable(false);
|
||||
mUsbPreference.setOnGearClickListener((GearPreference p) -> {
|
||||
final Intent intent = new Intent(mContext, UsbModeChooserActivity.class);
|
||||
mContext.startActivity(intent);
|
||||
});
|
||||
|
||||
forceUpdate();
|
||||
}
|
||||
|
||||
private void forceUpdate() {
|
||||
// Register so we can get the connection state from sticky intent.
|
||||
//TODO(b/70336520): Use an API to get data instead of sticky intent
|
||||
mUsbReceiver.register();
|
||||
mUsbConnectionListener.onUsbConnectionChanged(mUsbReceiver.isConnected());
|
||||
}
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.connecteddevice;
|
||||
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.hardware.usb.UsbManager;
|
||||
|
||||
/**
|
||||
* Receiver to receive usb update and use {@link UsbConnectionListener} to invoke callback
|
||||
*/
|
||||
public class UsbConnectionBroadcastReceiver extends BroadcastReceiver {
|
||||
private Context mContext;
|
||||
private UsbConnectionListener mUsbConnectionListener;
|
||||
private boolean mListeningToUsbEvents;
|
||||
private boolean mConnected;
|
||||
|
||||
public UsbConnectionBroadcastReceiver(Context context,
|
||||
UsbConnectionListener usbConnectionListener) {
|
||||
mContext = context;
|
||||
mUsbConnectionListener = usbConnectionListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mConnected = intent != null
|
||||
&& intent.getExtras().getBoolean(UsbManager.USB_CONNECTED);
|
||||
if (mUsbConnectionListener != null) {
|
||||
mUsbConnectionListener.onUsbConnectionChanged(mConnected);
|
||||
}
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if (!mListeningToUsbEvents) {
|
||||
final IntentFilter intentFilter = new IntentFilter(UsbManager.ACTION_USB_STATE);
|
||||
final Intent intent = mContext.registerReceiver(this, intentFilter);
|
||||
mConnected = intent != null
|
||||
&& intent.getExtras().getBoolean(UsbManager.USB_CONNECTED);
|
||||
mListeningToUsbEvents = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
if (mListeningToUsbEvents) {
|
||||
mContext.unregisterReceiver(this);
|
||||
mListeningToUsbEvents = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return mConnected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when usb connection is changed.
|
||||
*/
|
||||
interface UsbConnectionListener {
|
||||
void onUsbConnectionChanged(boolean connected);
|
||||
}
|
||||
}
|
@@ -15,17 +15,12 @@
|
||||
*/
|
||||
package com.android.settings.connecteddevice;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.deviceinfo.UsbBackend;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
@@ -44,19 +39,21 @@ public class UsbModePreferenceController extends AbstractPreferenceController
|
||||
public UsbModePreferenceController(Context context, UsbBackend usbBackend) {
|
||||
super(context);
|
||||
mUsbBackend = usbBackend;
|
||||
mUsbReceiver = new UsbConnectionBroadcastReceiver();
|
||||
mUsbReceiver = new UsbConnectionBroadcastReceiver(mContext, (connected) -> {
|
||||
updateSummary(mUsbPreference);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mUsbPreference = screen.findPreference(KEY_USB_MODE);
|
||||
updataSummary(mUsbPreference);
|
||||
updateSummary(mUsbPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
updataSummary(preference);
|
||||
updateSummary(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,8 +76,7 @@ public class UsbModePreferenceController extends AbstractPreferenceController
|
||||
mUsbReceiver.register();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getSummary(int mode) {
|
||||
public static int getSummary(int mode) {
|
||||
switch (mode) {
|
||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_NONE:
|
||||
return R.string.usb_summary_charging_only;
|
||||
@@ -96,11 +92,11 @@ public class UsbModePreferenceController extends AbstractPreferenceController
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void updataSummary(Preference preference) {
|
||||
updataSummary(preference, mUsbBackend.getCurrentMode());
|
||||
private void updateSummary(Preference preference) {
|
||||
updateSummary(preference, mUsbBackend.getCurrentMode());
|
||||
}
|
||||
|
||||
private void updataSummary(Preference preference, int mode) {
|
||||
private void updateSummary(Preference preference, int mode) {
|
||||
if (preference != null) {
|
||||
if (mUsbReceiver.isConnected()) {
|
||||
preference.setEnabled(true);
|
||||
@@ -112,40 +108,4 @@ public class UsbModePreferenceController extends AbstractPreferenceController
|
||||
}
|
||||
}
|
||||
|
||||
private class UsbConnectionBroadcastReceiver extends BroadcastReceiver {
|
||||
private boolean mListeningToUsbEvents;
|
||||
private boolean mConnected;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
boolean connected = intent != null
|
||||
&& intent.getExtras().getBoolean(UsbManager.USB_CONNECTED);
|
||||
if (connected != mConnected) {
|
||||
mConnected = connected;
|
||||
updataSummary(mUsbPreference);
|
||||
}
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if (!mListeningToUsbEvents) {
|
||||
IntentFilter intentFilter = new IntentFilter(UsbManager.ACTION_USB_STATE);
|
||||
Intent intent = mContext.registerReceiver(this, intentFilter);
|
||||
mConnected = intent != null
|
||||
&& intent.getExtras().getBoolean(UsbManager.USB_CONNECTED);
|
||||
mListeningToUsbEvents = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
if (mListeningToUsbEvents) {
|
||||
mContext.unregisterReceiver(this);
|
||||
mListeningToUsbEvents = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return mConnected;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user