OSDN Git Service

OPP: Replace deprecated API(s) with new API.
authorHemant Gupta <hemantg@codeaurora.org>
Mon, 6 Feb 2017 09:51:21 +0000 (15:21 +0530)
committerMyles Watson <mylesgw@google.com>
Wed, 22 Mar 2017 13:40:07 +0000 (13:40 +0000)
Remove unnecessary variable/functions and avoid using
deprecated API(s).

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

Bug: 35013632
Change-Id: Ice9314d599d0c0f4d7cc0e1ed70c7e87fa41e937

src/com/android/bluetooth/opp/BluetoothOppBatch.java
src/com/android/bluetooth/opp/BluetoothOppHandoverReceiver.java
src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java
src/com/android/bluetooth/opp/BluetoothOppNotification.java
src/com/android/bluetooth/opp/BluetoothOppProvider.java
src/com/android/bluetooth/opp/BluetoothOppReceiveFileInfo.java
src/com/android/bluetooth/opp/BluetoothOppReceiver.java
src/com/android/bluetooth/opp/BluetoothOppSendFileInfo.java
src/com/android/bluetooth/opp/BluetoothOppTransfer.java

index 08701c4..a74d100 100644 (file)
@@ -130,25 +130,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.
      */
     /* 1) If the batch is running, stop the transfer
index 3553d34..a239d6d 100644 (file)
@@ -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 =
-                    (BluetoothDevice)intent.getParcelableExtra(BluetoothDevice.EXTRA_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();
index 56b27d8..af04471 100644 (file)
@@ -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;
         }
index 85c5884..ef103cc 100644 (file)
@@ -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,10 +322,11 @@ 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(
-                BluetoothOppUtility.formatProgressText(item.totalTotal, item.totalCurrent));
+            b.setSubText(
+                    BluetoothOppUtility.formatProgressText(item.totalTotal, item.totalCurrent));
             if (item.totalTotal != 0) {
                 if (V) Log.v(TAG, "mCurrentBytes: " + item.totalCurrent +
                     " mTotalBytes: " + item.totalTotal + " (" +
@@ -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,36 +512,51 @@ 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)
-              .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))
-              .setContentIntent(PendingIntent.getBroadcast(mContext, 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))
-              .setContentText(info.mFileName)
-              .setStyle(new Notification.BigTextStyle().bigText(mContext.getString(
-                  R.string.incoming_file_confirm_Notification_content,
-                  info.mDeviceName, info.mFileName)))
-              .setContentInfo(Formatter.formatFileSize(mContext, info.mTotalBytes))
-              .setSmallIcon(R.drawable.bt_incomming_file_notification)
-              .build();
+          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(actionDecline)
+                          .addAction(actionAccept)
+                          .setContentIntent(PendingIntent.getBroadcast(mContext, 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,
+                                  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,
+                                  info.mDeviceName, info.mFileName)))
+                          .setContentInfo(Formatter.formatFileSize(mContext, info.mTotalBytes))
+                          .setSmallIcon(R.drawable.bt_incomming_file_notification)
+                          .build();
           mNotificationMgr.notify(info.mID, n);
         }
         cursor.close();
index c4e489e..c3ea704 100644 (file)
@@ -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;
index 8529e4d..02e01f5 100644 (file)
@@ -136,7 +136,7 @@ public class BluetoothOppReceiveFileInfo {
          * the file. Put a bit of margin (in case creating the file grows the
          * system by a few blocks).
          */
-        if (stat.getBlockSize() * ((long)stat.getAvailableBlocks() - 4) < length) {
+        if (stat.getBlockSizeLong() * (stat.getAvailableBlocksLong() - 4) < length) {
             if (D) Log.d(Constants.TAG, "Receive File aborted - not enough free space");
             return new BluetoothOppReceiveFileInfo(BluetoothShare.STATUS_ERROR_SDCARD_FULL);
         }
index 480bec3..cab2c40 100644 (file)
@@ -169,8 +169,6 @@ public class BluetoothOppReceiver extends BroadcastReceiver {
                     null);
             if (cursor != null) {
                 if (cursor.moveToFirst()) {
-                    int statusColumn = cursor.getColumnIndexOrThrow(BluetoothShare.STATUS);
-                    int status = cursor.getInt(statusColumn);
                     int visibilityColumn = cursor.getColumnIndexOrThrow(BluetoothShare.VISIBILITY);
                     int visibility = cursor.getInt(visibilityColumn);
                     int userConfirmationColumn = cursor
index 3321bda..d154f6b 100644 (file)
@@ -55,7 +55,6 @@ public class BluetoothOppSendFileInfo {
 
     private static final boolean D = Constants.DEBUG;
 
-    private static final boolean V = Constants.VERBOSE;
 
     /** Reusable SendFileInfo for error status. */
     static final BluetoothOppSendFileInfo SEND_FILE_INFO_ERROR = new BluetoothOppSendFileInfo(
index 10a7662..39fc10a 100644 (file)
@@ -84,8 +84,6 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch
 
     private static final int CONNECT_RETRY_TIME = 100;
 
-    private static final short OPUSH_UUID16 = 0x1105;
-
     private static final String SOCKET_LINK_KEY_ERROR = "Invalid exchange";
 
     private Context mContext;