/*
* Copyright (c) 2008-2009, Motorola, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of the Motorola, Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.android.bluetooth.opp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevicePicker;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.CharArrayBuffer;
import android.database.ContentObserver;
import android.database.Cursor;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
import android.os.Binder;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.sysprop.BluetoothProperties;
import android.util.Log;
import com.android.bluetooth.BluetoothObexTransport;
import com.android.bluetooth.IObexConnectionHandler;
import com.android.bluetooth.ObexServerSockets;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.sdp.SdpManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.obex.ObexTransport;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
/**
* Performs the background Bluetooth OPP transfer. It also starts thread to
* accept incoming OPP connection.
*/
public class BluetoothOppService extends ProfileService implements IObexConnectionHandler {
private static final boolean D = Constants.DEBUG;
private static final boolean V = Constants.VERBOSE;
/**
* Owned providers and activities
*/
private static final String OPP_PROVIDER =
BluetoothOppProvider.class.getCanonicalName();
private static final String OPP_FILE_PROVIDER =
BluetoothOppFileProvider.class.getCanonicalName();
private static final String INCOMING_FILE_CONFIRM_ACTIVITY =
BluetoothOppIncomingFileConfirmActivity.class.getCanonicalName();
private static final String TRANSFER_ACTIVITY =
BluetoothOppTransferActivity.class.getCanonicalName();
private static final String TRANSFER_HISTORY_ACTIVITY =
BluetoothOppTransferHistory.class.getCanonicalName();
// Normally we would dynamically define and create these but they need to be manifest receivers
// because they rely on explicit intents. Explicit intents don't work with dynamic receivers.
private static final String OPP_RECEIVER =
BluetoothOppReceiver.class.getCanonicalName();
private static final String OPP_HANDOFF_RECEIVER =
BluetoothOppHandoverReceiver.class.getCanonicalName();
private static final byte[] SUPPORTED_OPP_FORMAT = {
0x01 /* vCard 2.1 */,
0x02 /* vCard 3.0 */,
0x03 /* vCal 1.0 */,
0x04 /* iCal 2.0 */,
(byte) 0xFF /* Any type of object */
};
private class BluetoothShareContentObserver extends ContentObserver {
BluetoothShareContentObserver() {
super(new Handler());
}
@Override
public void onChange(boolean selfChange) {
if (V) {
Log.v(TAG, "ContentObserver received notification");
}
updateFromProvider();
}
}
private static final String TAG = "BtOppService";
/** Observer to get notified when the content observer's data changes */
private BluetoothShareContentObserver mObserver;
/** Class to handle Notification Manager updates */
private BluetoothOppNotification mNotifier;
private boolean mPendingUpdate;
private UpdateThread mUpdateThread;
private boolean mUpdateThreadRunning;
private ArrayList<BluetoothOppShareInfo> mShares;
private ArrayList<BluetoothOppBatch> mBatches;
private BluetoothOppTransfer mTransfer;
private BluetoothOppTransfer mServerTransfer;
private int mBatchId;
/**
* Array used when extracting strings from content provider
*/
private CharArrayBuffer mOldChars;
/**
* Array used when extracting strings from content provider
*/
private CharArrayBuffer mNewChars;
private boolean mListenStarted;
private boolean mMediaScanInProgress;
private int mIncomingRetries;
private ObexTransport mPendingConnection;
private int mOppSdpHandle = -1;
boolean mAcceptNewConnections;
private AdapterService mAdapterService;
private static final String INVISIBLE =
BluetoothShare.VISIBILITY + "=" + BluetoothShare.VISIBILITY_HIDDEN;
private static final String WHERE_INBOUND_SUCCESS =
BluetoothShare.DIRECTION + "=" + BluetoothShare.DIRECTION_INBOUND + " AND "
+ BluetoothShare.STATUS + "=" + BluetoothShare.STATUS_SUCCESS + " AND "
+ INVISIBLE;
private static final String WHERE_CONFIRM_PENDING_INBOUND =
BluetoothShare.DIRECTION + "=" + BluetoothShare.DIRECTION_INBOUND + " AND "
+ BluetoothShare.USER_CONFIRMATION + "="
+ BluetoothShare.USER_CONFIRMATION_PENDING;
private static final String WHERE_INVISIBLE_UNCONFIRMED =
"(" + BluetoothShare.STATUS + " > " + BluetoothShare.STATUS_SUCCESS + " AND "
+ INVISIBLE + ") OR (" + WHERE_CONFIRM_PENDING_INBOUND + ")";
private static BluetoothOppService sBluetoothOppService;
/*
* TODO No support for queue incoming from multiple devices.
* Make an array list of server session to support receiving queue from
* multiple devices
*/
private BluetoothOppObexServerSession mServerSession;
public static boolean isEnabled() {
return BluetoothProperties.isProfileOppEnabled().orElse(false);
}
@Override
protected IProfileServiceBinder initBinder() {
return new OppBinder(this);
}
private static class OppBinder extends Binder implements IProfileServiceBinder {
OppBinder(BluetoothOppService service) {
}
@Ove
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Android 原生系统蓝牙接收是在通知栏显示和操作,但是部分定制设备比如大屏或者盒子设备是没有通知栏的。 如果要接收蓝牙文件就要自己接收蓝牙广播进行弹框提示,大概包括:确认接收,显示接收进度,确认取消/完成接收等弹框和实现,具体修改就要适配系统的蓝牙应用。 本文基于Android13 系统蓝牙应用Bluetooth文件传输Opp部分代码适配进行介绍。 也许你工作中不一定有这个需求,但是安卓屏显开发大概率是有这个需求的, 部分有兴趣的并且有系统源码编译运行条件的,可以尝试修改系统源码试试, 有需求的或者有兴趣的可以看看。
资源推荐
资源详情
资源评论
收起资源包目录
Bluetooth.zip (56个子文件)
Bluetooth
android
app
Android.bp 6KB
src
com
android
bluetooth
opp
BluetoothOppService.java.txt 55KB
BluetoothOppUtility.java.txt 23KB
BluetoothOppTransferHistory.java 13KB
BluetoothReceiverConfirmDialog.java 2KB
BluetoothOppTransferEntity.java 569B
BluetoothOppReceiver.java 15KB
BluetoothOppTransferActivity.java.txt 20KB
BluetoothOppUtility.java 22KB
BluetoothOppNotification.java 29KB
NotifyDialogManager.java 8KB
BluetoothOppTransferActivity.java 19KB
BluetoothOppObexServerSession.java.txt 25KB
BluetoothOppService.java 53KB
NotifyDialogManager.java.txt 8KB
BluetoothReceiverProgressDialog.java 14KB
BluetoothOppTransferProgressAdapter.java 3KB
BluetoothReceiverFinishDialog.java.txt 14KB
BluetoothOppTransferHistory.java.txt 3KB
BluetoothOppNotification.java.txt 29KB
Constants.java 12KB
BluetoothOppObexServerSession.java 24KB
BluetoothOppTransferEntity.java.txt 569B
BluetoothOppReceiver.java.txt 15KB
BluetoothReceiverConfirmDialog.java.txt 2KB
BluetoothReceiverFinishDialog.java 2KB
Constants.java.txt 13KB
BluetoothBaseUI.java 1KB
res
values-zh-rCN
strings.xml 15KB
mipmap-xxxhdpi
delivery_nor.png 5KB
success.png 1KB
fail.png 1KB
bt_share.png 15KB
delivery_pre.png 7KB
ic_narrow_pre.png 895B
ic_narrow_nor.png 950B
values
strings.xml 16KB
layout
bluetooth_progress_adapter.xml 2KB
bluetooth_receiver_finish_dialog.xml 1KB
bluetooth_receiver_confirm_dialog.xml 2KB
bluetooth_receiver_floating_button.xml 995B
bluetooth_progress_dialog_header.xml 2KB
bluetooth_receiver_progress_dialog.xml 8KB
drawable
receiver_progress_background.xml 628B
selector_hide_narror.xml 343B
bluetooth_dialog_cancel_background.xml 529B
shape_rectangle_count.xml 582B
shape_transfer_cancel.xml 533B
shape_rectangle_confirm.xml 193B
bluetooth_dialog_background.xml 219B
bluetooth_dialog_confirm_background.xml 527B
bluetooth_dialog_button_background.xml 507B
shape_rectangle_cancel.xml 533B
AndroidManifest.xml 28KB
0001-SKG-Bluetooth.patch 639KB
system
gd
hci
le_scanning_manager.cc 69KB
共 56 条
- 1
资源评论
峥嵘life
- 粉丝: 2533
- 资源: 114
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功