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

Commit 64f2c9b7 authored by Hemant Gupta's avatar Hemant Gupta Committed by Myles Watson
Browse files

OPP: Replace deprecated API(s) with new API.

Remove unnecessary variable/functions and avoid using
deprecated API(s).

Test: OPP functionality (Tx/Rx) works fine without issues.

Bug: 35013632
Change-Id: Ice9314d599d0c0f4d7cc0e1ed70c7e87fa41e937
parent c4890e78
Loading
Loading
Loading
Loading
+0 −19
Original line number Diff line number Diff line
@@ -129,25 +129,6 @@ public class BluetoothOppBatch {
        }
    }

    /**
     * Delete one share from the batch. Not used now.
     */
    /*It should only be called under requirement that cancel one single share, but not to
     * cancel the whole batch. Currently we assume "cancel" is to cancel whole batch.
     */
    public void deleteShare(BluetoothOppShareInfo info) {
        if (info.mStatus == BluetoothShare.STATUS_RUNNING) {
            info.mStatus = BluetoothShare.STATUS_CANCELED;
            if (info.mDirection == BluetoothShare.DIRECTION_INBOUND && info.mFilename != null) {
                new File(info.mFilename).delete();
            }
        }

        if (mListener != null) {
            mListener.onShareDeleted(info.mId);
        }
    }

    /**
     * Cancel the whole batch.
     */
+7 −9
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import java.util.ArrayList;
public class BluetoothOppHandoverReceiver extends BroadcastReceiver {
    public static final String TAG ="BluetoothOppHandoverReceiver";
    private static final boolean D = Constants.DEBUG;
    private static final boolean V = Constants.VERBOSE;

    @Override
    public void onReceive(Context context, Intent intent) {
@@ -36,15 +35,14 @@ public class BluetoothOppHandoverReceiver extends BroadcastReceiver {

        if (action.equals(Constants.ACTION_HANDOVER_SEND) ||
               action.equals(Constants.ACTION_HANDOVER_SEND_MULTIPLE)) {

            BluetoothDevice device =
            final BluetoothDevice device =
                    (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            if (device == null) {
                if (D) Log.d(TAG, "No device attached to handover intent.");
                return;
            }

            String mimeType = intent.getType();
            final String mimeType = intent.getType();
            ArrayList<Uri> uris = new ArrayList<Uri>();
            if (action.equals(Constants.ACTION_HANDOVER_SEND)) {
                Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM);
@@ -54,13 +52,13 @@ public class BluetoothOppHandoverReceiver extends BroadcastReceiver {
            }

            if (mimeType != null && uris != null && !uris.isEmpty()) {
                final String finalType = mimeType;
                final Context finalContext = context;
                final ArrayList<Uri> finalUris = uris;
                Thread t = new Thread(new Runnable() {
                    public void run() {
                        BluetoothOppManager.getInstance(context).saveSendingFileInfo(finalType,
                            finalUris, true);
                        BluetoothOppManager.getInstance(context).startTransfer(device);
                        BluetoothOppManager.getInstance(finalContext)
                                .saveSendingFileInfo(mimeType, finalUris, true);
                        BluetoothOppManager.getInstance(finalContext).startTransfer(device);
                    }
                });
                t.start();
+9 −8
Original line number Diff line number Diff line
@@ -215,15 +215,15 @@ public class BluetoothOppLauncherActivity extends Activity {
        final ContentResolver resolver = this.getContentResolver();

        // Check if airplane mode is on
        final boolean isAirplaneModeOn = Settings.System.getInt(resolver,
                Settings.System.AIRPLANE_MODE_ON, 0) == 1;
        final boolean isAirplaneModeOn =
                Settings.System.getInt(resolver, Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
        if (!isAirplaneModeOn) {
            return true;
        }

        // Check if airplane mode matters
        final String airplaneModeRadios = Settings.System.getString(resolver,
                Settings.System.AIRPLANE_MODE_RADIOS);
        final String airplaneModeRadios =
                Settings.System.getString(resolver, Settings.Global.AIRPLANE_MODE_RADIOS);
        final boolean isAirplaneSensitive = airplaneModeRadios == null ? true :
                airplaneModeRadios.contains(Settings.System.RADIO_BLUETOOTH);
        if (!isAirplaneSensitive) {
@@ -231,10 +231,11 @@ public class BluetoothOppLauncherActivity extends Activity {
        }

        // Check if Bluetooth may be enabled in airplane mode
        final String airplaneModeToggleableRadios = Settings.System.getString(resolver,
                Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
        final boolean isAirplaneToggleable = airplaneModeToggleableRadios == null ? false :
                airplaneModeToggleableRadios.contains(Settings.System.RADIO_BLUETOOTH);
        final String airplaneModeToggleableRadios = Settings.System.getString(
                resolver, Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
        final boolean isAirplaneToggleable = airplaneModeToggleableRadios == null
                ? false
                : airplaneModeToggleableRadios.contains(Settings.Global.RADIO_BLUETOOTH);
        if (isAirplaneToggleable) {
            return true;
        }
+62 −41
Original line number Diff line number Diff line
@@ -34,8 +34,10 @@ package com.android.bluetooth.opp;

import com.android.bluetooth.R;

import android.content.ContentResolver;
import android.content.Context;
import android.app.Notification;
import android.app.Notification.Action;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
@@ -105,6 +107,7 @@ class BluetoothOppNotification {

    private int mActiveNotificationId = 0;

    private ContentResolver mContentResolver = null;
    /**
     * This inner class is used to describe some properties for one transfer.
     */
@@ -137,6 +140,8 @@ class BluetoothOppNotification {
        mNotificationMgr = (NotificationManager)mContext
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotifications = new HashMap<String, NotificationItem>();
        // Get Content Resolver object one time
        mContentResolver = mContext.getContentResolver();
    }

    /**
@@ -212,8 +217,8 @@ class BluetoothOppNotification {

    private void updateActiveNotification() {
        // Active transfers
        Cursor cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
                WHERE_RUNNING, null, BluetoothShare._ID);
        Cursor cursor = mContentResolver.query(
                BluetoothShare.CONTENT_URI, null, WHERE_RUNNING, null, BluetoothShare._ID);
        if (cursor == null) {
            return;
        }
@@ -317,9 +322,10 @@ class BluetoothOppNotification {
            // TODO: split description into two rows with filename in second row
            Notification.Builder b = new Notification.Builder(mContext);
            b.setColor(mContext.getResources().getColor(
                    com.android.internal.R.color.system_notification_accent_color));
                    com.android.internal.R.color.system_notification_accent_color,
                    mContext.getTheme()));
            b.setContentTitle(item.description);
            b.setContentInfo(
            b.setSubText(
                    BluetoothOppUtility.formatProgressText(item.totalTotal, item.totalCurrent));
            if (item.totalTotal != 0) {
                if (V) Log.v(TAG, "mCurrentBytes: " + item.totalCurrent +
@@ -345,7 +351,7 @@ class BluetoothOppNotification {
            intent.setDataAndNormalize(Uri.parse(BluetoothShare.CONTENT_URI + "/" + item.id));

            b.setContentIntent(PendingIntent.getBroadcast(mContext, 0, intent, 0));
            mNotificationMgr.notify(item.id, b.getNotification());
            mNotificationMgr.notify(item.id, b.build());

            mActiveNotificationId = item.id;
        }
@@ -377,7 +383,7 @@ class BluetoothOppNotification {
        }

        // Creating outbound notification
        Cursor cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
        Cursor cursor = mContentResolver.query(BluetoothShare.CONTENT_URI, null,
                WHERE_COMPLETED_OUTBOUND, null, BluetoothShare.TIMESTAMP + " DESC");
        if (cursor == null) {
            return;
@@ -436,8 +442,8 @@ class BluetoothOppNotification {
        }

        // Creating inbound notification
        cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
                WHERE_COMPLETED_INBOUND, null, BluetoothShare.TIMESTAMP + " DESC");
        cursor = mContentResolver.query(BluetoothShare.CONTENT_URI, null, WHERE_COMPLETED_INBOUND,
                null, BluetoothShare.TIMESTAMP + " DESC");
        if (cursor == null) {
            return;
        }
@@ -493,8 +499,8 @@ class BluetoothOppNotification {
    }

    private void updateIncomingFileConfirmNotification() {
        Cursor cursor = mContext.getContentResolver().query(BluetoothShare.CONTENT_URI, null,
                WHERE_CONFIRM_PENDING, null, BluetoothShare._ID);
        Cursor cursor = mContentResolver.query(
                BluetoothShare.CONTENT_URI, null, WHERE_CONFIRM_PENDING, null, BluetoothShare._ID);

        if (cursor == null) {
            return;
@@ -506,29 +512,44 @@ class BluetoothOppNotification {
          Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + info.mID);
          Intent baseIntent = new Intent().setDataAndNormalize(contentUri)
              .setClassName(Constants.THIS_PACKAGE_NAME, BluetoothOppReceiver.class.getName());

          Notification n = new Notification.Builder(mContext)
          Notification.Action actionDecline =
                  new Notification.Action
                          .Builder(R.drawable.ic_decline,
                                  mContext.getText(R.string.incoming_file_confirm_cancel),
                                  PendingIntent.getBroadcast(mContext, 0,
                                          new Intent(baseIntent)
                                                  .setAction(Constants.ACTION_DECLINE),
                                          0))
                          .build();
          Notification.Action actionAccept =
                  new Notification.Action
                          .Builder(R.drawable.ic_accept,
                                  mContext.getText(R.string.incoming_file_confirm_ok),
                                  PendingIntent.getBroadcast(mContext, 0,
                                          new Intent(baseIntent).setAction(Constants.ACTION_ACCEPT),
                                          0))
                          .build();
          Notification n =
                  new Notification.Builder(mContext)
                          .setOnlyAlertOnce(true)
                          .setOngoing(true)
                          .setVibrate(new long[] {200})
                          .setWhen(info.mTimeStamp)
                          .setDefaults(Notification.DEFAULT_SOUND)
                          .setPriority(Notification.PRIORITY_HIGH)
              .addAction(R.drawable.ic_decline,
                  mContext.getText(R.string.incoming_file_confirm_cancel),
                      PendingIntent.getBroadcast(mContext, 0,
                          new Intent(baseIntent).setAction(Constants.ACTION_DECLINE), 0))
              .addAction(R.drawable.ic_accept,
                  mContext.getText(R.string.incoming_file_confirm_ok),
                      PendingIntent.getBroadcast(mContext, 0,
                          new Intent(baseIntent).setAction(Constants.ACTION_ACCEPT), 0))
                          .addAction(actionDecline)
                          .addAction(actionAccept)
                          .setContentIntent(PendingIntent.getBroadcast(mContext, 0,
                  new Intent(baseIntent).setAction(Constants.ACTION_INCOMING_FILE_CONFIRM), 0))
                                  new Intent(baseIntent)
                                          .setAction(Constants.ACTION_INCOMING_FILE_CONFIRM),
                                  0))
                          .setDeleteIntent(PendingIntent.getBroadcast(mContext, 0,
                                  new Intent(baseIntent).setAction(Constants.ACTION_HIDE), 0))
                          .setColor(mContext.getResources().getColor(
                  com.android.internal.R.color.system_notification_accent_color))
              .setContentTitle(mContext.getText(R.string.incoming_file_confirm_Notification_title))
                                  com.android.internal.R.color.system_notification_accent_color,
                                  mContext.getTheme()))
                          .setContentTitle(mContext.getText(
                                  R.string.incoming_file_confirm_Notification_title))
                          .setContentText(info.mFileName)
                          .setStyle(new Notification.BigTextStyle().bigText(mContext.getString(
                                  R.string.incoming_file_confirm_Notification_content,
+0 −1
Original line number Diff line number Diff line
@@ -240,7 +240,6 @@ public final class BluetoothOppProvider extends ContentProvider {
        }
        Integer dir = values.getAsInteger(BluetoothShare.DIRECTION);
        Integer con = values.getAsInteger(BluetoothShare.USER_CONFIRMATION);
        String address = values.getAsString(BluetoothShare.DESTINATION);

        if (values.getAsInteger(BluetoothShare.DIRECTION) == null) {
            dir = BluetoothShare.DIRECTION_OUTBOUND;
Loading