OSDN Git Service

Fix pbap and opp running bluetooth in phone process problems.
authorJaikumar Ganesh <jaikumar@google.com>
Wed, 24 Mar 2010 17:36:06 +0000 (10:36 -0700)
committerJaikumar Ganesh <jaikumar@google.com>
Wed, 24 Mar 2010 17:43:06 +0000 (10:43 -0700)
1. Use the right context instead of application context.
2. Make PbapActivity run in the same process as PbapService as they
   share state.

Change-Id: Ib50c63c271dd8b30108f22734c47ee8645cd4839

AndroidManifest.xml
AndroidManifest_test.xml
src/com/android/bluetooth/opp/BluetoothOppManager.java
src/com/android/bluetooth/opp/BluetoothOppPreference.java
src/com/android/bluetooth/pbap/BluetoothPbapService.java

index c78e971..fabdf02 100644 (file)
                   android:configChanges="orientation|keyboardHidden">
         </activity>
         <activity android:name=".pbap.BluetoothPbapActivity"
+            android:process="@string/process"
             android:excludeFromRecents="true"
             android:theme="@*android:style/Theme.Dialog.Alert">
             <intent-filter>
index 593682c..de55b5f 100644 (file)
@@ -84,6 +84,7 @@
             </intent-filter>
         </activity>
         <activity android:name=".pbap.BluetoothPbapActivity"
+            android:process="@string/process"
             android:label=" "
             android:theme="@*android:style/Theme.Dialog.Alert">
             <intent-filter>
index 2dd0acb..73411d9 100644 (file)
@@ -127,8 +127,7 @@ public class BluetoothOppManager {
             return true;
         mInitialized = true;
 
-        // This will be around as long as this process is
-        mContext = context.getApplicationContext();
+        mContext = context;
 
         mAdapter = BluetoothAdapter.getDefaultAdapter();
         if (mAdapter == null) {
index 3a83cb3..7874222 100644 (file)
@@ -83,8 +83,7 @@ public class BluetoothOppPreference {
             return true;
         mInitialized = true;
 
-        // This will be around as long as this process is
-        mContext = context.getApplicationContext();
+        mContext = context;
 
         mNamePreference = mContext.getSharedPreferences(Constants.BLUETOOTHOPP_NAME_PREFERENCE,
                 Context.MODE_PRIVATE);
index 26ac61a..e0a705f 100644 (file)
@@ -617,57 +617,56 @@ public class BluetoothPbapService extends Service {
     }
 
     private void createPbapNotification(String action) {
-        Context context = getApplicationContext();
 
-        NotificationManager nm = (NotificationManager)context
-                .getSystemService(Context.NOTIFICATION_SERVICE);
+        NotificationManager nm = (NotificationManager)
+            getSystemService(Context.NOTIFICATION_SERVICE);
 
         // Create an intent triggered by clicking on the status icon.
         Intent clickIntent = new Intent();
-        clickIntent.setClass(context, BluetoothPbapActivity.class);
+        clickIntent.setClass(this, BluetoothPbapActivity.class);
         clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         clickIntent.setAction(action);
 
         // Create an intent triggered by clicking on the
         // "Clear All Notifications" button
         Intent deleteIntent = new Intent();
-        deleteIntent.setClass(context, BluetoothPbapReceiver.class);
+        deleteIntent.setClass(this, BluetoothPbapReceiver.class);
 
         Notification notification = null;
         String name = getRemoteDeviceName();
+
         if (action.equals(ACCESS_REQUEST_ACTION)) {
             deleteIntent.setAction(ACCESS_DISALLOWED_ACTION);
-            notification = new Notification(android.R.drawable.stat_sys_data_bluetooth, context
-                    .getString(R.string.pbap_notif_ticker), System.currentTimeMillis());
-            notification.setLatestEventInfo(context, context.getString(R.string.pbap_notif_title),
-                    context.getString(R.string.pbap_notif_message, name), PendingIntent
-                            .getActivity(context, 0, clickIntent, 0));
+            notification = new Notification(android.R.drawable.stat_sys_data_bluetooth,
+                getString(R.string.pbap_notif_ticker), System.currentTimeMillis());
+            notification.setLatestEventInfo(this, getString(R.string.pbap_notif_title),
+                    getString(R.string.pbap_notif_message, name), PendingIntent
+                            .getActivity(this, 0, clickIntent, 0));
 
             notification.flags |= Notification.FLAG_AUTO_CANCEL;
             notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
             notification.defaults = Notification.DEFAULT_SOUND;
-            notification.deleteIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, 0);
+            notification.deleteIntent = PendingIntent.getBroadcast(this, 0, deleteIntent, 0);
             nm.notify(NOTIFICATION_ID_ACCESS, notification);
         } else if (action.equals(AUTH_CHALL_ACTION)) {
             deleteIntent.setAction(AUTH_CANCELLED_ACTION);
-            notification = new Notification(android.R.drawable.stat_sys_data_bluetooth, context
-                    .getString(R.string.auth_notif_ticker), System.currentTimeMillis());
-            notification.setLatestEventInfo(context, context.getString(R.string.auth_notif_title),
-                    context.getString(R.string.auth_notif_message, name), PendingIntent
-                            .getActivity(context, 0, clickIntent, 0));
+            notification = new Notification(android.R.drawable.stat_sys_data_bluetooth,
+                getString(R.string.auth_notif_ticker), System.currentTimeMillis());
+            notification.setLatestEventInfo(this, getString(R.string.auth_notif_title),
+                    getString(R.string.auth_notif_message, name), PendingIntent
+                            .getActivity(this, 0, clickIntent, 0));
 
             notification.flags |= Notification.FLAG_AUTO_CANCEL;
             notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
             notification.defaults = Notification.DEFAULT_SOUND;
-            notification.deleteIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, 0);
+            notification.deleteIntent = PendingIntent.getBroadcast(this, 0, deleteIntent, 0);
             nm.notify(NOTIFICATION_ID_AUTH, notification);
         }
     }
 
     private void removePbapNotification(int id) {
-        Context context = getApplicationContext();
-        NotificationManager nm = (NotificationManager)context
-                .getSystemService(Context.NOTIFICATION_SERVICE);
+        NotificationManager nm = (NotificationManager)
+            getSystemService(Context.NOTIFICATION_SERVICE);
         nm.cancel(id);
     }