adb shell am broadcast -a android.btopp.intent.action.OPEN
提示如下错误,说明action处于保护状态
1 2 3 4 5 6 7 8 9 10 11
Broadcasting: Intent { act=android.btopp.intent.action.OPEN } java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.btopp.intent.action.OPEN from pid=26382, uid=2000 at android.os.Parcel.readException(Parcel.java:1683) at android.os.Parcel.readException(Parcel.java:1636) at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3507) at com.android.commands.am.Am.sendBroadcast(Am.java:772) at com.android.commands.am.Am.onRun(Am.java:404) at com.android.internal.os.BaseCommand.run(BaseCommand.java:51) at com.android.commands.am.Am.main(Am.java:121) at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:262)
/** * Exposes constants used to interact with the Bluetooth Share manager's content * provider. * @hide */ publicfinalclassBluetoothShareimplementsBaseColumns{ privateBluetoothShare(){ } /** * The permission to access the Bluetooth Share Manager */ publicstaticfinal String PERMISSION_ACCESS = "android.permission.ACCESS_BLUETOOTH_SHARE"; /** * The content:// URI for the data table in the provider */ publicstaticfinal Uri CONTENT_URI = Uri.parse("content://com.android.bluetooth.opp/btopp");
Don’t allow file attachment from /data through GET_CONTENT
Thirdparty can
attach private files from “/data/data/com.android.messaging/“
directory to the messaging app。
/* * Other application is trying to share a file via Bluetooth, * probably Pictures, videos, or vCards. The Intent should contain * an EXTRA_STREAM with the data to attach. */ if (action.equals(Intent.ACTION_SEND)) { // TODO: handle type == null case final String type = intent.getType(); final Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM); CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT); // If we get ACTION_SEND intent with EXTRA_STREAM, we'll use the // uri data; // If we get ACTION_SEND intent without EXTRA_STREAM, but with // EXTRA_TEXT, we will try send this TEXT out; Currently in // Browser, share one link goes to this case; if (stream != null && type != null) { if (V) Log.v(TAG, "Get ACTION_SEND intent: Uri = " + stream + "; mimetype = " + type); // Save type/stream, will be used when adding transfer // session to DB. Thread t = new Thread(new Runnable() { publicvoidrun(){ BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this) .saveSendingFileInfo(type,stream.toString(), false); //Done getting file info..Launch device picker and finish this activity launchDevicePicker(); finish(); } }); t.start(); return; } else { Log.w(TAG,"Error trying to do set text...File not created!"); finish(); return; } } else { Log.e(TAG, "type is null; or sending file URI is null"); finish(); return; } } elseif (action.equals(Intent.ACTION_SEND_MULTIPLE)) { final String mimeType = intent.getType(); final ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); if (mimeType != null && uris != null) { if (V) Log.v(TAG, "Get ACTION_SHARE_MULTIPLE intent: uris " + uris + "\n Type= " + mimeType); Thread t = new Thread(new Runnable() { publicvoidrun(){ BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this) .saveSendingFileInfo(mimeType,uris, false); //Done getting file info..Launch device picker //and finish this activity launchDevicePicker(); finish(); } }); t.start();
那么,传入蓝牙App私有数据试试!先寻找bluetooth所拥有的私有文件,
angler:/ # find /data -user bluetooth -exec ls -al {} ; 2> /dev/null
--------- beginning of crash 06-12 10:32:43.930 16171 16171 E AndroidRuntime: FATAL EXCEPTION: main 06-12 10:32:43.930 16171 16171 E AndroidRuntime: Process: ms509.com.testaospbluetoothopplauncher, PID: 16171 06-12 10:32:43.930 16171 16171 E AndroidRuntime: android.os.FileUriExposedException: file:///data/user_de/0/com.android.bluetooth/databases/btopp.db exposed beyond app through ClipData.Item.getUri() 06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799) 06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.net.Uri.checkFileUriExposed(Uri.java:2346) 06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832) 06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.content.Intent.prepareToLeaveProcess(Intent.java:8909) 06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.content.Intent.prepareToLeaveProcess(Intent.java:8894) 06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517) 06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:4224) 06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50) 06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79) 06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:4183)
} elseif (action.equals(Constants.ACTION_OPEN) || action.equals(Constants.ACTION_LIST)) { if (V) { if (action.equals(Constants.ACTION_OPEN)) { Log.v(TAG, "Receiver open for " + intent.getData()); } else { Log.v(TAG, "Receiver list for " + intent.getData()); } }
BluetoothOppTransferInfo transInfo = new BluetoothOppTransferInfo(); Uri uri = intent.getData(); //Intent可控! transInfo = BluetoothOppUtility.queryRecord(context, uri); if (transInfo == null) { Log.e(TAG, "Error: Can not get data from db"); return; }
if (transInfo.mDirection == BluetoothShare.DIRECTION_INBOUND && BluetoothShare.isStatusSuccess(transInfo.mStatus)) { // if received file successfully, open this file // transInfo可控! BluetoothOppUtility.openReceivedFile(context, transInfo.mFileName, transInfo.mFileType, transInfo.mTimeStamp, uri); BluetoothOppUtility.updateVisibilityToHidden(context, uri); } else { Intent in = new Intent(context, BluetoothOppTransferActivity.class); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); in.setDataAndNormalize(uri); context.startActivity(in); }
// 注意这段,授予任何app对该文件的读写权限 // Grant permissions for any app that can handle a file to access it for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; context.grantUriPermission(packageName, path, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); }