Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 145f98f5 authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

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
parent 93206ea5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@
                  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>
+1 −0
Original line number Diff line number Diff line
@@ -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>
+1 −2
Original line number Diff line number Diff line
@@ -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) {
+1 −2
Original line number Diff line number Diff line
@@ -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);
+19 −20
Original line number Diff line number Diff line
@@ -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);
    }