return getKey().equals(mSelectedKey);
}
- public void setChecked(boolean checked) {
+ public void setChecked() {
mSelectedKey = getKey();
}
pref.setSelectable(selectable);
if (selectable) {
if ((mSelectedKey != null) && mSelectedKey.equals(key)) {
- pref.setChecked(true);
+ pref.setChecked();
}
apnList.addPreference(pref);
} else {
}
};
- private class BandListItem {
+ static private class BandListItem {
private int mBandMode = Phone.BM_UNSPECIFIED;
public BandListItem(int bm) {
*/
private final String tenthsToFixedString(int x) {
int tens = x / 10;
- return new String("" + tens + "." + (x - 10*tens));
+ return Integer.toString(tens) + "." + (x - 10 * tens);
}
/**
private String mLastInputMethodId;
private String mLastTickedInputMethodId;
- private String mRootDirectory;
-
static public String getInputMethodIdFromKey(String key) {
return key;
}
public void onGetStatsCompleted(PackageStats pStats, boolean pSucceeded) {
AppInfo appInfo = null;
Bundle data = new Bundle();
- data.putString(ATTR_PKG_NAME, pStats.packageName);
- if(pSucceeded && pStats != null) {
- if (localLOGV) Log.i(TAG, "onGetStatsCompleted::"+pStats.packageName+", ("+
- pStats.cacheSize+","+
- pStats.codeSize+", "+pStats.dataSize);
- data.putParcelable(ATTR_APP_PKG_STATS, pStats);
- } else {
+ if (pStats != null) {
+ data.putString(ATTR_PKG_NAME, pStats.packageName);
+ if(pSucceeded) {
+ if (localLOGV) Log.i(TAG, "onGetStatsCompleted::"+pStats.packageName+", ("+
+ pStats.cacheSize+","+
+ pStats.codeSize+", "+pStats.dataSize);
+ data.putParcelable(ATTR_APP_PKG_STATS, pStats);
+ }
+ }
+
+ if(!pSucceeded || pStats == null) {
Log.w(TAG, "Invalid package stats from PackageManager");
}
+
//post message to Handler
Message msg = mHandler.obtainMessage(mMsgId, data);
msg.setData(data);
// internal structure used to track added and deleted packages when
// the activity has focus
- class AddRemoveInfo {
+ static class AddRemoveInfo {
String pkgName;
boolean add;
public AddRemoveInfo(String pPkgName, boolean pAdd) {
}
};
- private class OemCommands {
+ static private class OemCommands {
- public final int OEM_QXDM_SDLOG_DEFAULT_FILE_SIZE = 32;
- public final int OEM_QXDM_SDLOG_DEFAULT_MASK = 0;
- public final int OEM_QXDM_SDLOG_DEFAULT_MAX_INDEX = 8;
+ public static final int OEM_QXDM_SDLOG_DEFAULT_FILE_SIZE = 32;
+ public static final int OEM_QXDM_SDLOG_DEFAULT_MASK = 0;
+ public static final int OEM_QXDM_SDLOG_DEFAULT_MAX_INDEX = 8;
- final int SIZE_OF_INT = 4;
- final int OEM_FEATURE_ENABLE = 1;
- final int OEM_FEATURE_DISABLE = 0;
- final int OEM_SIMPE_FEAUTURE_LEN = 1;
+ static final int SIZE_OF_INT = 4;
+ static final int OEM_FEATURE_ENABLE = 1;
+ static final int OEM_FEATURE_DISABLE = 0;
+ static final int OEM_SIMPE_FEAUTURE_LEN = 1;
- final int OEM_QXDM_SDLOG_FUNCTAG = 0x00010000;
- final int OEM_QXDM_SDLOG_LEN = 4;
- final int OEM_PS_AUTO_ATTACH_FUNCTAG = 0x00020000;
- final int OEM_CIPHERING_FUNCTAG = 0x00020001;
+ static final int OEM_QXDM_SDLOG_FUNCTAG = 0x00010000;
+ static final int OEM_QXDM_SDLOG_LEN = 4;
+ static final int OEM_PS_AUTO_ATTACH_FUNCTAG = 0x00020000;
+ static final int OEM_CIPHERING_FUNCTAG = 0x00020001;
/**
* The OEM interface to store QXDM to SD.
private void displayQxdmEnableResult() {
String status = mQxdmLogEnabled ? "Start QXDM Log" : "Stop QXDM Log";
- DialogInterface mProgressPanel = new AlertDialog.
- Builder(this).setMessage(status).show();
+ new AlertDialog.Builder(this).setMessage(status).show();
mHandler.postDelayed(
new Runnable() {
} catch (RemoteException ex) {
}
- String scanVolume = null; // this no longer exists: SystemProperties.get(MediaScanner.CURRENT_VOLUME_PROPERTY, "");
- boolean scanning = "external".equals(scanVolume);
-
- if (scanning) {
- setLayout(mScanningLayout);
- } else {
- String status = Environment.getExternalStorageState();
- boolean readOnly = false;
-
- if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
- status = Environment.MEDIA_MOUNTED;
- readOnly = true;
- }
+ String status = Environment.getExternalStorageState();
+ boolean readOnly = false;
+
+ if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
+ status = Environment.MEDIA_MOUNTED;
+ readOnly = true;
+ }
- if (status.equals(Environment.MEDIA_MOUNTED)) {
- try {
- File path = Environment.getExternalStorageDirectory();
- StatFs stat = new StatFs(path.getPath());
- long blockSize = stat.getBlockSize();
- long totalBlocks = stat.getBlockCount();
- long availableBlocks = stat.getAvailableBlocks();
-
- mTotalSize.setText(formatSize(totalBlocks * blockSize));
- mUsedSize.setText(formatSize((totalBlocks - availableBlocks) * blockSize));
- mAvailableSize.setText(formatSize(availableBlocks * blockSize));
- } catch (IllegalArgumentException e) {
- // this can occur if the SD card is removed, but we haven't received the
- // ACTION_MEDIA_REMOVED Intent yet.
- status = Environment.MEDIA_REMOVED;
- }
-
- mReadOnlyStatus.setVisibility(readOnly ? View.VISIBLE : View.GONE);
- setLayout(mMountedLayout);
- } else if (status.equals(Environment.MEDIA_UNMOUNTED)) {
- setLayout(mUnmountedLayout);
- } else if (status.equals(Environment.MEDIA_REMOVED)) {
- setLayout(mRemovedLayout);
- } else if (status.equals(Environment.MEDIA_SHARED)) {
- setLayout(mSharedLayout);
- } else if (status.equals(Environment.MEDIA_BAD_REMOVAL)) {
- setLayout(mBadRemovalLayout);
+ if (status.equals(Environment.MEDIA_MOUNTED)) {
+ try {
+ File path = Environment.getExternalStorageDirectory();
+ StatFs stat = new StatFs(path.getPath());
+ long blockSize = stat.getBlockSize();
+ long totalBlocks = stat.getBlockCount();
+ long availableBlocks = stat.getAvailableBlocks();
+
+ mTotalSize.setText(formatSize(totalBlocks * blockSize));
+ mUsedSize.setText(formatSize((totalBlocks - availableBlocks) * blockSize));
+ mAvailableSize.setText(formatSize(availableBlocks * blockSize));
+ } catch (IllegalArgumentException e) {
+ // this can occur if the SD card is removed, but we haven't received the
+ // ACTION_MEDIA_REMOVED Intent yet.
+ status = Environment.MEDIA_REMOVED;
}
+
+ mReadOnlyStatus.setVisibility(readOnly ? View.VISIBLE : View.GONE);
+ setLayout(mMountedLayout);
+ } else if (status.equals(Environment.MEDIA_UNMOUNTED)) {
+ setLayout(mUnmountedLayout);
+ } else if (status.equals(Environment.MEDIA_REMOVED)) {
+ setLayout(mRemovedLayout);
+ } else if (status.equals(Environment.MEDIA_SHARED)) {
+ setLayout(mSharedLayout);
+ } else if (status.equals(Environment.MEDIA_BAD_REMOVAL)) {
+ setLayout(mBadRemovalLayout);
}
}
}
};
-
- private int mStatus;
private IMountService mMountService;
private CheckBox mMassStorage;
holder.launchCount.setText(String.valueOf(pkgStats.launchCount));
holder.usageTime.setText(String.valueOf(pkgStats.usageTime)+" ms");
} else {
- Log.w(TAG, "No usage stats info for package:"+pkgStats.packageName);
+ Log.w(TAG, "No usage stats info for package:" + position);
}
return convertView;
}
try {
XmlResourceParser xrp = getResources().getXml(R.xml.timezones);
while (xrp.next() != XmlResourceParser.START_TAG)
- ;
+ continue;
xrp.next();
while (xrp.getEventType() != XmlResourceParser.END_TAG) {
while (xrp.getEventType() != XmlResourceParser.START_TAG) {
*/
public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChangeListener {
private static final String TAG = "BluetoothDiscoverableEnabler";
-
+
private static final String SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT =
"debug.bt.discoverable_time";
- private static final int DISCOVERABLE_TIMEOUT = 120;
+ private static final int DISCOVERABLE_TIMEOUT = 120;
private static final String SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP =
"discoverable_end_timestamp";
-
+
private final Context mContext;
private final Handler mUiHandler;
private final CheckBoxPreference mCheckBoxPreference;
-
+
private final LocalBluetoothManager mLocalManager;
-
+
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
private final Runnable mUpdateCountdownSummaryRunnable = new Runnable() {
public void run() {
- updateCountdownSummary();
- }
+ updateCountdownSummary();
+ }
};
public BluetoothDiscoverableEnabler(Context context, CheckBoxPreference checkBoxPreference) {
mContext = context;
mUiHandler = new Handler();
mCheckBoxPreference = checkBoxPreference;
-
+
checkBoxPreference.setPersistent(false);
-
+
mLocalManager = LocalBluetoothManager.getInstance(context);
if (mLocalManager == null) {
// Bluetooth not supported
IntentFilter filter = new IntentFilter(BluetoothIntent.SCAN_MODE_CHANGED_ACTION);
mContext.registerReceiver(mReceiver, filter);
mCheckBoxPreference.setOnPreferenceChangeListener(this);
-
+
handleModeChanged(mLocalManager.getBluetoothManager().getScanMode());
}
-
+
public void pause() {
if (mLocalManager == null) {
return;
}
-
+
mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
mCheckBoxPreference.setOnPreferenceChangeListener(null);
mContext.unregisterReceiver(mReceiver);
}
-
+
public boolean onPreferenceChange(Preference preference, Object value) {
// Turn on/off BT discoverability
setEnabled((Boolean) value);
-
+
return true;
}
-
+
private void setEnabled(final boolean enable) {
BluetoothDevice manager = mLocalManager.getBluetoothManager();
-
+
if (enable) {
int timeout = getDiscoverableTimeout();
long endTimestamp = System.currentTimeMillis() + timeout * 1000;
persistDiscoverableEndTimestamp(endTimestamp);
-
+
manager.setScanMode(BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
} else {
manager.setScanMode(BluetoothDevice.SCAN_MODE_CONNECTABLE);
if (timeout <= 0) {
timeout = DISCOVERABLE_TIMEOUT;
}
-
+
return timeout;
}
editor.putLong(SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP, endTimestamp);
editor.commit();
}
-
+
private void handleModeChanged(int mode) {
if (mode == BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
mCheckBoxPreference.setChecked(true);
updateCountdownSummary();
-
+
} else {
mCheckBoxPreference.setChecked(false);
}
}
-
+
private void updateCountdownSummary() {
int mode = mLocalManager.getBluetoothManager().getScanMode();
if (mode != BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
return;
}
-
+
long currentTimestamp = System.currentTimeMillis();
long endTimestamp = mLocalManager.getSharedPreferences().getLong(
SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP, 0);
-
+
if (currentTimestamp > endTimestamp) {
// We're still in discoverable mode, but maybe there isn't a timeout.
mCheckBoxPreference.setSummaryOn(null);
return;
}
-
+
String formattedTimeLeft = String.valueOf((endTimestamp - currentTimestamp) / 1000);
-
+
mCheckBoxPreference.setSummaryOn(
mContext.getResources().getString(R.string.bluetooth_is_discoverable,
formattedTimeLeft));
-
+
synchronized (this) {
mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
mUiHandler.postDelayed(mUpdateCountdownSummaryRunnable, 1000);
}
}
-
-
+
+
}
package com.android.settings.bluetooth;
import android.bluetooth.BluetoothA2dp;
+import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothError;
import android.bluetooth.BluetoothHeadset;
public class BluetoothEventRedirector {
private static final String TAG = "BluetoothEventRedirector";
private static final boolean V = LocalBluetoothManager.V;
-
+
private LocalBluetoothManager mManager;
-
+
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (V) {
Log.v(TAG, "Received " + intent.getAction());
}
-
+
String action = intent.getAction();
String address = intent.getStringExtra(BluetoothIntent.ADDRESS);
-
+
if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) {
int state = intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE,
BluetoothError.ERROR);
mManager.setBluetoothStateInt(state);
} else if (action.equals(BluetoothIntent.DISCOVERY_STARTED_ACTION)) {
mManager.onScanningStateChanged(true);
-
+
} else if (action.equals(BluetoothIntent.DISCOVERY_COMPLETED_ACTION)) {
mManager.onScanningStateChanged(false);
-
+
} else if (action.equals(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION)) {
short rssi = intent.getShortExtra(BluetoothIntent.RSSI, Short.MIN_VALUE);
- mManager.getLocalDeviceManager().onDeviceAppeared(address, rssi);
-
+ int btClass = intent.getIntExtra(BluetoothIntent.CLASS, BluetoothClass.ERROR);
+ String name = intent.getStringExtra(BluetoothIntent.NAME);
+ mManager.getLocalDeviceManager().onDeviceAppeared(address, rssi, btClass, name);
+
} else if (action.equals(BluetoothIntent.REMOTE_DEVICE_DISAPPEARED_ACTION)) {
mManager.getLocalDeviceManager().onDeviceDisappeared(address);
-
+
} else if (action.equals(BluetoothIntent.REMOTE_NAME_UPDATED_ACTION)) {
mManager.getLocalDeviceManager().onDeviceNameUpdated(address);
-
+
} else if (action.equals(BluetoothIntent.BOND_STATE_CHANGED_ACTION)) {
int bondState = intent.getIntExtra(BluetoothIntent.BOND_STATE,
BluetoothError.ERROR);
mManager.getLocalDeviceManager().onBondingError(address, reason);
}
}
-
+
} else if (action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION)) {
int newState = intent.getIntExtra(BluetoothIntent.HEADSET_STATE, 0);
int oldState = intent.getIntExtra(BluetoothIntent.HEADSET_PREVIOUS_STATE, 0);
} else if (action.equals(BluetoothIntent.REMOTE_DEVICE_CLASS_UPDATED_ACTION)) {
mManager.getLocalDeviceManager().onBtClassChanged(address);
-
+
}
}
};
public void start() {
IntentFilter filter = new IntentFilter();
-
+
// Bluetooth on/off broadcasts
filter.addAction(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
-
+
// Discovery broadcasts
filter.addAction(BluetoothIntent.DISCOVERY_STARTED_ACTION);
filter.addAction(BluetoothIntent.DISCOVERY_COMPLETED_ACTION);
filter.addAction(BluetoothIntent.REMOTE_DEVICE_DISAPPEARED_ACTION);
filter.addAction(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION);
filter.addAction(BluetoothIntent.REMOTE_NAME_UPDATED_ACTION);
-
+
// Pairing broadcasts
filter.addAction(BluetoothIntent.BOND_STATE_CHANGED_ACTION);
-
+
// Fine-grained state broadcasts
filter.addAction(BluetoothA2dp.SINK_STATE_CHANGED_ACTION);
filter.addAction(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION);
filter.addAction(BluetoothIntent.REMOTE_DEVICE_CLASS_UPDATED_ACTION);
-
+
mManager.getContext().registerReceiver(mBroadcastReceiver, filter);
}
-
+
public void stop() {
- mManager.getContext().unregisterReceiver(mBroadcastReceiver);
+ mManager.getContext().unregisterReceiver(mBroadcastReceiver);
}
}
CONNECT, DISCONNECT,
}
- class BluetoothJob {
+ static class BluetoothJob {
final BluetoothCommand command; // CONNECT, DISCONNECT
final LocalBluetoothDevice device;
final Profile profile; // HEADSET, A2DP, etc
this.profile = profile;
this.timeSent = 0;
}
-
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
}
}
}
-
+
private boolean pruneQueue(BluetoothJob job) {
boolean removedStaleItems = false;
long now = System.currentTimeMillis();
private boolean processCommand(BluetoothJob job) {
boolean successful = false;
if (job.timeSent == 0) {
- job.timeSent = System.currentTimeMillis();
+ job.timeSent = System.currentTimeMillis();
switch (job.command) {
case CONNECT:
successful = connectInt(job.device, job.profile);
}
};
- AlertDialog ad = new AlertDialog.Builder(context)
+ new AlertDialog.Builder(context)
.setTitle(getName())
.setMessage(message)
.setPositiveButton(android.R.string.ok, disconnectListener)
// Reset the only-show-one-error-dialog tracking variable
mIsConnectingErrorPossible = true;
- Context context = mLocalManager.getContext();
boolean hasAtLeastOnePreferredProfile = false;
for (Profile profile : mProfiles) {
LocalBluetoothProfileManager profileManager =
// Reset the only-show-one-error-dialog tracking variable
mIsConnectingErrorPossible = true;
- Context context = mLocalManager.getContext();
for (Profile profile : mProfiles) {
LocalBluetoothProfileManager profileManager =
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
public void unpair() {
synchronized (workQueue) {
// Remove any pending commands for this device
- boolean processNow = false;
+ boolean processNow = false;
Iterator<BluetoothJob> it = workQueue.iterator();
while (it.hasNext()) {
BluetoothJob job = it.next();
}
private void fillData() {
- BluetoothDevice manager = mLocalManager.getBluetoothManager();
-
fetchName();
fetchBtClass();
return mName;
}
+ public void setName(String name) {
+ if (!mName.equals(name)) {
+ if (TextUtils.isEmpty(name)) {
+ mName = mAddress;
+ } else {
+ mName = name;
+ }
+ dispatchAttributesChanged();
+ }
+ }
+
public void refreshName() {
fetchName();
dispatchAttributesChanged();
dispatchAttributesChanged();
}
+ public void setBtClass(int btClass) {
+ if (mBtClass != btClass && btClass != BluetoothClass.ERROR) {
+ mBtClass = btClass;
+ LocalBluetoothProfileManager.fill(mBtClass, mProfiles);
+ dispatchAttributesChanged();
+ }
+ }
+
public int getSummary() {
// TODO: clean up
int oneOffSummary = getOneOffSummary();
break;
case CONTEXT_ITEM_UNPAIR:
- mLocalManager.getBluetoothManager().disconnectRemoteDeviceAcl(mAddress);
unpair();
break;
final LocalBluetoothManager mLocalManager;
final List<Callback> mCallbacks;
-
+
final List<LocalBluetoothDevice> mDevices = new ArrayList<LocalBluetoothDevice>();
public LocalBluetoothDeviceManager(LocalBluetoothManager localManager) {
BluetoothDevice manager = mLocalManager.getBluetoothManager();
String[] bondedAddresses = manager.listBonds();
if (bondedAddresses == null) return false;
-
+
boolean deviceAdded = false;
for (String address : bondedAddresses) {
LocalBluetoothDevice device = findDevice(address);
deviceAdded = true;
}
}
-
+
return deviceAdded;
}
-
+
public synchronized List<LocalBluetoothDevice> getDevicesCopy() {
return new ArrayList<LocalBluetoothDevice>(mDevices);
}
-
+
void onBluetoothStateChanged(boolean enabled) {
if (enabled) {
readPairedDevices();
}
}
- public synchronized void onDeviceAppeared(String address, short rssi) {
+ public synchronized void onDeviceAppeared(String address, short rssi, int btClass,
+ String name) {
boolean deviceAdded = false;
-
+
LocalBluetoothDevice device = findDevice(address);
if (device == null) {
device = new LocalBluetoothDevice(mLocalManager.getContext(), address);
mDevices.add(device);
deviceAdded = true;
}
-
+
device.setRssi(rssi);
+ device.setBtClass(btClass);
+ device.setName(name);
device.setVisible(true);
-
+
if (deviceAdded) {
dispatchDeviceAdded(device);
}
}
-
+
public synchronized void onDeviceDisappeared(String address) {
LocalBluetoothDevice device = findDevice(address);
if (device == null) return;
-
+
device.setVisible(false);
checkForDeviceRemoval(device);
}
-
+
private void checkForDeviceRemoval(LocalBluetoothDevice device) {
if (device.getBondState() == BluetoothDevice.BOND_NOT_BONDED &&
!device.isVisible()) {
// If device isn't paired, remove it altogether
mDevices.remove(device);
dispatchDeviceDeleted(device);
- }
+ }
}
-
+
public synchronized void onDeviceNameUpdated(String address) {
LocalBluetoothDevice device = findDevice(address);
if (device != null) {
}
public synchronized LocalBluetoothDevice findDevice(String address) {
-
+
for (int i = mDevices.size() - 1; i >= 0; i--) {
LocalBluetoothDevice device = mDevices.get(i);
-
+
if (device.getAddress().equals(address)) {
return device;
}
}
-
+
return null;
}
-
+
/**
* Attempts to get the name of a remote device, otherwise returns the address.
- *
+ *
* @param address The address.
* @return The name, or if unavailable, the address.
*/
LocalBluetoothDevice device = findDevice(address);
return device != null ? device.getName() : address;
}
-
+
private void dispatchDeviceAdded(LocalBluetoothDevice device) {
synchronized (mCallbacks) {
for (Callback callback : mCallbacks) {
callback.onDeviceAdded(device);
}
}
-
+
// TODO: divider between prev paired/connected and scanned
}
-
+
private void dispatchDeviceDeleted(LocalBluetoothDevice device) {
synchronized (mCallbacks) {
for (Callback callback : mCallbacks) {
/**
* Called when there is a bonding error.
- *
+ *
* @param address The address of the remote device.
* @param reason The reason, one of the error reasons from
* BluetoothDevice.UNBOND_REASON_*
}
mLocalManager.showError(address, R.string.bluetooth_error_title, errorMsg);
}
-
+
public synchronized void onProfileStateChanged(String address, Profile profile,
int newProfileState) {
LocalBluetoothDevice device = findDevice(address);
device.onProfileStateChanged(profile, newProfileState);
device.refresh();
}
-
+
public synchronized void onConnectingError(String address) {
LocalBluetoothDevice device = findDevice(address);
if (device == null) return;
-
+
/*
* Go through the device's delegate so we don't spam the user with
* errors connecting to different profiles, and instead make sure the
*/
device.showConnectingError();
}
-
+
public synchronized void onScanningStateChanged(boolean started) {
if (!started) return;
-
+
// If starting a new scan, clear old visibility
for (int i = mDevices.size() - 1; i >= 0; i--) {
LocalBluetoothDevice device = mDevices.get(i);
checkForDeviceRemoval(device);
}
}
-
+
public synchronized void onBtClassChanged(String address) {
LocalBluetoothDevice device = findDevice(address);
if (device != null) {
public class LocalBluetoothManager {
private static final String TAG = "LocalBluetoothManager";
static final boolean V = Config.LOGV;
- static final boolean D = Config.LOGD && false;
-
+ static final boolean D = Config.LOGD;
+
private static final String SHARED_PREFERENCES_NAME = "bluetooth_settings";
-
+
private static LocalBluetoothManager INSTANCE;
/** Used when obtaining a reference to the singleton instance. */
private static Object INSTANCE_LOCK = new Object();
private boolean mInitialized;
-
+
private Context mContext;
/** If a BT-related activity is in the foreground, this will be it. */
private Activity mForegroundActivity;
private LocalBluetoothDeviceManager mLocalDeviceManager;
private BluetoothEventRedirector mEventRedirector;
private BluetoothA2dp mBluetoothA2dp;
-
+
private int mState = BluetoothError.ERROR;
private List<Callback> mCallbacks = new ArrayList<Callback>();
-
+
private static final int SCAN_EXPIRATION_MS = 5 * 60 * 1000; // 5 mins
private long mLastScan;
-
+
public static LocalBluetoothManager getInstance(Context context) {
synchronized (INSTANCE_LOCK) {
if (INSTANCE == null) {
INSTANCE = new LocalBluetoothManager();
}
-
+
if (!INSTANCE.init(context)) {
return null;
}
-
+
return INSTANCE;
}
}
private boolean init(Context context) {
if (mInitialized) return true;
mInitialized = true;
-
+
// This will be around as long as this process is
mContext = context.getApplicationContext();
-
+
mManager = (BluetoothDevice) context.getSystemService(Context.BLUETOOTH_SERVICE);
if (mManager == null) {
return false;
}
-
+
mLocalDeviceManager = new LocalBluetoothDeviceManager(this);
mEventRedirector = new BluetoothEventRedirector(this);
return true;
}
-
+
public BluetoothDevice getBluetoothManager() {
return mManager;
}
-
+
public Context getContext() {
return mContext;
}
public Activity getForegroundActivity() {
return mForegroundActivity;
}
-
+
public void setForegroundActivity(Activity activity) {
if (mErrorDialog != null) {
mErrorDialog.dismiss();
}
mForegroundActivity = activity;
}
-
+
public SharedPreferences getSharedPreferences() {
return mContext.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
}
-
+
public LocalBluetoothDeviceManager getLocalDeviceManager() {
return mLocalDeviceManager;
}
-
+
List<Callback> getCallbacks() {
return mCallbacks;
}
-
+
public void registerCallback(Callback callback) {
synchronized (mCallbacks) {
mCallbacks.add(callback);
}
}
-
+
public void unregisterCallback(Callback callback) {
synchronized (mCallbacks) {
mCallbacks.remove(callback);
}
}
-
+
public void startScanning(boolean force) {
if (mManager.isDiscovering()) {
/*
* Note: we only call the callbacks, not the same path as if the
* scanning state had really changed (in that case the device
* manager would clear its list of unpaired scanned devices).
- */
+ */
dispatchScanningStateChanged(true);
} else {
if (!force) {
}
}
}
-
- if (mManager.startDiscovery(true)) {
+
+ if (mManager.startDiscovery()) {
mLastScan = System.currentTimeMillis();
}
}
}
-
+
public int getBluetoothState() {
-
+
if (mState == BluetoothError.ERROR) {
syncBluetoothState();
}
-
+
return mState;
}
-
+
void setBluetoothStateInt(int state) {
mState = state;
if (state == BluetoothDevice.BLUETOOTH_STATE_ON ||
mLocalDeviceManager.onBluetoothStateChanged(state == BluetoothDevice.BLUETOOTH_STATE_ON);
}
}
-
+
private void syncBluetoothState() {
int bluetoothState;
boolean wasSetStateSuccessful = enabled
? mManager.enable()
: mManager.disable();
-
+
if (wasSetStateSuccessful) {
setBluetoothStateInt(enabled
? BluetoothDevice.BLUETOOTH_STATE_TURNING_ON
"setBluetoothEnabled call, manager didn't return success for enabled: "
+ enabled);
}
-
+
syncBluetoothState();
}
}
-
+
/**
* @param started True if scanning started, false if scanning finished.
*/
mLocalDeviceManager.onScanningStateChanged(started);
dispatchScanningStateChanged(started);
}
-
+
private void dispatchScanningStateChanged(boolean started) {
synchronized (mCallbacks) {
for (Callback callback : mCallbacks) {
.setPositiveButton(android.R.string.ok, null)
.show();
} else {
- // Fallback on a toast
+ // Fallback on a toast
Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
}
}
void onDeviceAdded(LocalBluetoothDevice device);
void onDeviceDeleted(LocalBluetoothDevice device);
}
-
+
}
void updateTimes() {
long at = SystemClock.uptimeMillis() / 1000;
long ut = SystemClock.elapsedRealtime() / 1000;
- long st = ut - at;
if (ut == 0) {
ut = 1;
Log.w(TAG, "Result from bookmark picker does not have an intent.");
return;
}
-
- String title = data.getStringExtra(BookmarkPicker.EXTRA_TITLE);
+
char shortcut = data.getCharExtra(BookmarkPicker.EXTRA_SHORTCUT, (char) 0);
updateShortcut(shortcut, data);
}
private void updatePasswordCaption(String security) {
-
- if (mPasswordText != null && security != null
- && security.equals(AccessPointState.WEP)) {
- mPasswordText.setText(R.string.please_type_hex_key);
- } else {
- mPasswordText.setText(R.string.please_type_passphrase);
+ if (mPasswordText != null) {
+ if (security != null && security.equals(AccessPointState.WEP)) {
+ mPasswordText.setText(R.string.please_type_hex_key);
+ } else {
+ mPasswordText.setText(R.string.please_type_passphrase);
+ }
}
}
// Signal strength indicator
private static final int UI_SIGNAL_LEVELS = 4;
- private WifiSettings mWifiSettings;
-
private AccessPointState mState;
public AccessPointPreference(WifiSettings wifiSettings, AccessPointState state) {
super(wifiSettings, null);
- mWifiSettings = wifiSettings;
mState = state;
setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
try {
int numChannels = Integer.parseInt((String) newValue);
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
- if (!wifiManager.setNumAllowedChannels(numChannels)) {
+ if (!wifiManager.setNumAllowedChannels(numChannels, true)) {
Toast.makeText(this, R.string.wifi_setting_num_channels_error,
Toast.LENGTH_SHORT).show();
}
* We pass null for security since we have a network ID (i.e., it's
* not a wildcard), and rely on it matching.
*/
- return findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), ssid, null);
+ synchronized (this) {
+ return findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), ssid, null);
+ }
} else {
return null;
}
* We pass null for security since we have a network ID (i.e., it's
* not a wildcard), and rely on it matching.
*/
- ap = findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), wifiInfo
- .getSSID(), null);
+ synchronized (this) {
+ ap = findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), wifiInfo
+ .getSSID(), null);
+ }
}
if (ap != null) {
}
mDialog = dialog;
- dialog.setOnDismissListener(this);
if (dialog != null) {
+ dialog.setOnDismissListener(this);
dialog.show();
}
}