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

Commit 4f6e5cab authored by Jack He's avatar Jack He
Browse files

Update deprecated Notification builder to new API

* Replace Notification.setLastEventInfo() and various variable
  assignments with the corresponding Notification.Builder API calls.
* Explicitly choose theme for getColor() using Context.getTheme() as
  previous getColor() method is deprecated as well.

Bug: 31218737
Test: TestTracker/63162/3975
Change-Id: I696cb7f07b50b04551e56c3b4a02fea87f23589c
parent 6b30601d
Loading
Loading
Loading
Loading
+38 −34
Original line number Original line Diff line number Diff line
@@ -352,9 +352,6 @@ class BluetoothOppNotification {
    }
    }


    private void updateCompletedNotification() {
    private void updateCompletedNotification() {
        String title;
        String unsuccess_caption;
        String caption;
        long timeStamp = 0;
        long timeStamp = 0;
        int outboundSuccNumber = 0;
        int outboundSuccNumber = 0;
        int outboundFailNumber = 0;
        int outboundFailNumber = 0;
@@ -362,7 +359,6 @@ class BluetoothOppNotification {
        int inboundNum;
        int inboundNum;
        int inboundSuccNumber = 0;
        int inboundSuccNumber = 0;
        int inboundFailNumber = 0;
        int inboundFailNumber = 0;
        Intent intent;


        // If there is active transfer, no need to update complete transfer
        // If there is active transfer, no need to update complete transfer
        // notification
        // notification
@@ -409,24 +405,28 @@ class BluetoothOppNotification {
        outboundNum = outboundSuccNumber + outboundFailNumber;
        outboundNum = outboundSuccNumber + outboundFailNumber;
        // create the outbound notification
        // create the outbound notification
        if (outboundNum > 0) {
        if (outboundNum > 0) {
            Notification outNoti = new Notification();
            String unsuccess_caption = mContext.getResources().getQuantityString(
            outNoti.icon = android.R.drawable.stat_sys_upload_done;
            title = mContext.getString(R.string.outbound_noti_title);
            unsuccess_caption = mContext.getResources().getQuantityString(
                    R.plurals.noti_caption_unsuccessful, outboundFailNumber, outboundFailNumber);
                    R.plurals.noti_caption_unsuccessful, outboundFailNumber, outboundFailNumber);
            caption = mContext.getResources().getQuantityString(
            String caption = mContext.getResources().getQuantityString(
                    R.plurals.noti_caption_success, outboundSuccNumber, outboundSuccNumber,
                    R.plurals.noti_caption_success, outboundSuccNumber, outboundSuccNumber,
                    unsuccess_caption);
                    unsuccess_caption);
            intent = new Intent(Constants.ACTION_OPEN_OUTBOUND_TRANSFER);
            Intent content_intent = new Intent(Constants.ACTION_OPEN_OUTBOUND_TRANSFER)
            intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
                    .setClassName(Constants.THIS_PACKAGE_NAME,
            outNoti.color = mContext.getResources().getColor(
                            BluetoothOppReceiver.class.getName());
                    com.android.internal.R.color.system_notification_accent_color);
            Intent delete_intent = new Intent(Constants.ACTION_COMPLETE_HIDE)
            outNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
                    .setClassName(Constants.THIS_PACKAGE_NAME,
                    mContext, 0, intent, 0));
                            BluetoothOppReceiver.class.getName());
            intent = new Intent(Constants.ACTION_COMPLETE_HIDE);
            Notification outNoti = new Notification.Builder(mContext)
            intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
                    .setContentTitle(mContext.getString(R.string.outbound_noti_title))
            outNoti.deleteIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
                    .setContentText(caption)
            outNoti.when = timeStamp;
                    .setSmallIcon(android.R.drawable.stat_sys_upload_done)
                    .setColor(mContext.getResources().getColor(
                            com.android.internal.R.color.system_notification_accent_color,
                            mContext.getTheme()))
                    .setContentIntent(PendingIntent.getBroadcast(mContext, 0, content_intent, 0))
                    .setDeleteIntent(PendingIntent.getBroadcast(mContext, 0, delete_intent, 0))
                    .setWhen(timeStamp)
                    .build();
            mNotificationMgr.notify(NOTIFICATION_ID_OUTBOUND, outNoti);
            mNotificationMgr.notify(NOTIFICATION_ID_OUTBOUND, outNoti);
        } else {
        } else {
            if (mNotificationMgr != null) {
            if (mNotificationMgr != null) {
@@ -461,24 +461,28 @@ class BluetoothOppNotification {
        inboundNum = inboundSuccNumber + inboundFailNumber;
        inboundNum = inboundSuccNumber + inboundFailNumber;
        // create the inbound notification
        // create the inbound notification
        if (inboundNum > 0) {
        if (inboundNum > 0) {
            Notification inNoti = new Notification();
            String unsuccess_caption = mContext.getResources().getQuantityString(
            inNoti.icon = android.R.drawable.stat_sys_download_done;
            title = mContext.getString(R.string.inbound_noti_title);
            unsuccess_caption = mContext.getResources().getQuantityString(
                    R.plurals.noti_caption_unsuccessful, inboundFailNumber, inboundFailNumber);
                    R.plurals.noti_caption_unsuccessful, inboundFailNumber, inboundFailNumber);
            caption = mContext.getResources().getQuantityString(
            String caption = mContext.getResources().getQuantityString(
                    R.plurals.noti_caption_success, inboundSuccNumber, inboundSuccNumber,
                    R.plurals.noti_caption_success, inboundSuccNumber, inboundSuccNumber,
                    unsuccess_caption);
                    unsuccess_caption);
            intent = new Intent(Constants.ACTION_OPEN_INBOUND_TRANSFER);
            Intent content_intent = new Intent(Constants.ACTION_OPEN_INBOUND_TRANSFER)
            intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
                    .setClassName(Constants.THIS_PACKAGE_NAME,
            inNoti.color = mContext.getResources().getColor(
                            BluetoothOppReceiver.class.getName());
                    com.android.internal.R.color.system_notification_accent_color);
            Intent delete_intent = new Intent(Constants.ACTION_COMPLETE_HIDE)
            inNoti.setLatestEventInfo(mContext, title, caption, PendingIntent.getBroadcast(
                    .setClassName(Constants.THIS_PACKAGE_NAME,
                    mContext, 0, intent, 0));
                            BluetoothOppReceiver.class.getName());
            intent = new Intent(Constants.ACTION_COMPLETE_HIDE);
            Notification inNoti = new Notification.Builder(mContext)
            intent.setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());
                    .setContentTitle(mContext.getString(R.string.inbound_noti_title))
            inNoti.deleteIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
                    .setContentText(caption)
            inNoti.when = timeStamp;
                    .setSmallIcon(android.R.drawable.stat_sys_download_done)
                    .setColor(mContext.getResources().getColor(
                            com.android.internal.R.color.system_notification_accent_color,
                            mContext.getTheme()))
                    .setContentIntent(PendingIntent.getBroadcast(mContext, 0, content_intent, 0))
                    .setDeleteIntent(PendingIntent.getBroadcast(mContext, 0, delete_intent, 0))
                    .setWhen(timeStamp)
                    .build();
            mNotificationMgr.notify(NOTIFICATION_ID_INBOUND, inNoti);
            mNotificationMgr.notify(NOTIFICATION_ID_INBOUND, inNoti);
        } else {
        } else {
            if (mNotificationMgr != null) {
            if (mNotificationMgr != null) {
+16 −14
Original line number Original line Diff line number Diff line
@@ -777,23 +777,25 @@ public class BluetoothPbapService extends Service {
        Intent deleteIntent = new Intent();
        Intent deleteIntent = new Intent();
        deleteIntent.setClass(this, BluetoothPbapReceiver.class);
        deleteIntent.setClass(this, BluetoothPbapReceiver.class);


        Notification notification = null;
        String name = getRemoteDeviceName();
        String name = getRemoteDeviceName();


        if (action.equals(AUTH_CHALL_ACTION)) {
        if (action.equals(AUTH_CHALL_ACTION)) {
            deleteIntent.setAction(AUTH_CANCELLED_ACTION);
            Notification notification = new Notification.Builder(this)
            notification = new Notification(android.R.drawable.stat_sys_data_bluetooth,
                    .setWhen(System.currentTimeMillis())
                getString(R.string.auth_notif_ticker), System.currentTimeMillis());
                    .setContentTitle(getString(R.string.auth_notif_title))
            notification.color = getResources().getColor(
                    .setContentText(getString(R.string.auth_notif_message, name))
                    com.android.internal.R.color.system_notification_accent_color);
                    .setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
            notification.setLatestEventInfo(this, getString(R.string.auth_notif_title),
                    .setTicker(getString(R.string.auth_notif_ticker))
                    getString(R.string.auth_notif_message, name), PendingIntent
                    .setColor(getResources().getColor(
                            .getActivity(this, 0, clickIntent, 0));
                            com.android.internal.R.color.system_notification_accent_color,

                            this.getTheme()))
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
                    .setFlag(Notification.FLAG_AUTO_CANCEL, true)
            notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
                    .setFlag(Notification.FLAG_ONLY_ALERT_ONCE, true)
            notification.defaults = Notification.DEFAULT_SOUND;
                    .setDefaults(Notification.DEFAULT_SOUND)
            notification.deleteIntent = PendingIntent.getBroadcast(this, 0, deleteIntent, 0);
                    .setContentIntent(PendingIntent.getActivity(this, 0, clickIntent, 0))
                    .setDeleteIntent(PendingIntent.getBroadcast(this, 0,
                            deleteIntent.setAction(AUTH_CANCELLED_ACTION), 0))
                    .build();
            nm.notify(NOTIFICATION_ID_AUTH, notification);
            nm.notify(NOTIFICATION_ID_AUTH, notification);
        }
        }
    }
    }