Refactor Bluetooth settings for readability and performance.

Major refactoring of Bluetooth settings classes.
- Moved all functionality from LocalBluetoothManager into new
  LocalBluetoothAdapter and LocalBluetoothPreferences, and into
  existing classes.
- Refactored functionality from BluetoothEventRedirector into new
  BluetoothEventManager class, deleting the original version. New
  version uses a HashMap from action Strings to implementers of the
  BluetoothEventManager.Handler interface.
- Created new BluetoothDiscoveryReceiver to update shared preferences
  timestamp for Bluetooth discovery start/finish. This is the only event
  handling we need to do when the settings app is not visible, so it has
  its own receiver entry in AndroidManifest.xml. Edits are written using
  QueuedWork.singleThreadExecutor(), which BroadcastReceiver knows about
  and will wait for completion, eliminating the need for PendingResult.
- Miscellaneous cleanups to code style and logic for readability.
- Pulled some large switch statement code blocks into new methods.
- Changed all Bluetooth state references to the new BluetoothProfile
  constants.
- Changed use of deprecated Notification constructor in
  BluetoothPairingRequest to use Notification.Builder.
- Moved Utf8ByteLengthFilter helper function from BluetoothNamePreference
  into its own class, and moved test cases into the same package.
- Moved all LocalBluetoothProfileManager functionality related to
  specific profiles into new top-level classes (A2dpProfile, etc.), all
  implementing the LocalBluetoothProfile interface.
- Moved all UI-related methods from CachedBluetoothDevice into the class
  that uses the method, or into the static Utils class for shared methods.

Change-Id: I6d49b7f4ae0c7d7dcf62551ee40b51ecb5fe4f47
This commit is contained in:
Jake Hamby
2011-02-07 18:21:25 -08:00
parent 2adae4e274
commit 436b29e68e
44 changed files with 3536 additions and 3041 deletions

View File

@@ -28,7 +28,7 @@ import android.content.Intent;
import android.os.PowerManager;
import android.util.Log;
public class DockEventReceiver extends BroadcastReceiver {
public final class DockEventReceiver extends BroadcastReceiver {
private static final boolean DEBUG = DockService.DEBUG;
@@ -39,11 +39,9 @@ public class DockEventReceiver extends BroadcastReceiver {
private static final int EXTRA_INVALID = -1234;
private static final Object mStartingServiceSync = new Object();
private static final Object sStartingServiceSync = new Object();
private static final long WAKELOCK_TIMEOUT = 5000;
private static PowerManager.WakeLock mStartingService;
private static PowerManager.WakeLock sStartingService;
@Override
public void onReceive(Context context, Intent intent) {
@@ -75,7 +73,7 @@ public class DockEventReceiver extends BroadcastReceiver {
beginStartingService(context, i);
break;
default:
if (DEBUG) Log.e(TAG, "Unknown state");
Log.e(TAG, "Unknown state: " + state);
break;
}
} else if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction()) ||
@@ -118,15 +116,15 @@ public class DockEventReceiver extends BroadcastReceiver {
* Start the service to process the current event notifications, acquiring
* the wake lock before returning to ensure that the service will run.
*/
public static void beginStartingService(Context context, Intent intent) {
synchronized (mStartingServiceSync) {
if (mStartingService == null) {
private static void beginStartingService(Context context, Intent intent) {
synchronized (sStartingServiceSync) {
if (sStartingService == null) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mStartingService = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
sStartingService = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"StartingDockService");
}
mStartingService.acquire(WAKELOCK_TIMEOUT);
sStartingService.acquire();
if (context.startService(intent) == null) {
Log.e(TAG, "Can't start DockService");
@@ -139,10 +137,13 @@ public class DockEventReceiver extends BroadcastReceiver {
* releasing the wake lock if the service is now stopping.
*/
public static void finishStartingService(Service service, int startId) {
synchronized (mStartingServiceSync) {
if (mStartingService != null) {
if (DEBUG) Log.d(TAG, "stopSelf id = "+ startId);
service.stopSelfResult(startId);
synchronized (sStartingServiceSync) {
if (sStartingService != null) {
if (DEBUG) Log.d(TAG, "stopSelf id = " + startId);
if (service.stopSelfResult(startId)) {
Log.d(TAG, "finishStartingService: stopping service");
sStartingService.release();
}
}
}
}