From: Jaikumar Ganesh Date: Wed, 24 Mar 2010 17:36:06 +0000 (-0700) Subject: Fix pbap and opp running bluetooth in phone process problems. X-Git-Tag: android-7.1.2_r17~1418 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=0bd5f7b5c36a60687ffe895368fd8df6df38acab;p=android-x86%2Fpackages-apps-Bluetooth.git Fix pbap and opp running bluetooth in phone process problems. 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 --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c78e9714..fabdf02b 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -108,6 +108,7 @@ android:configChanges="orientation|keyboardHidden"> diff --git a/AndroidManifest_test.xml b/AndroidManifest_test.xml index 593682cc..de55b5f4 100644 --- a/AndroidManifest_test.xml +++ b/AndroidManifest_test.xml @@ -84,6 +84,7 @@ diff --git a/src/com/android/bluetooth/opp/BluetoothOppManager.java b/src/com/android/bluetooth/opp/BluetoothOppManager.java index 2dd0acb8..73411d92 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppManager.java +++ b/src/com/android/bluetooth/opp/BluetoothOppManager.java @@ -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) { diff --git a/src/com/android/bluetooth/opp/BluetoothOppPreference.java b/src/com/android/bluetooth/opp/BluetoothOppPreference.java index 3a83cb35..78742229 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppPreference.java +++ b/src/com/android/bluetooth/opp/BluetoothOppPreference.java @@ -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); diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapService.java b/src/com/android/bluetooth/pbap/BluetoothPbapService.java index 26ac61a9..e0a705f0 100644 --- a/src/com/android/bluetooth/pbap/BluetoothPbapService.java +++ b/src/com/android/bluetooth/pbap/BluetoothPbapService.java @@ -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); }