Android-x86
Fork

  • R/O
  • HTTP
  • SSH
  • HTTPS

packages-apps-Bluetooth: コミット

packages/apps/Bluetooth


コミットメタ情報

リビジョンd28d2ec2145778c23a9ca09763089e353817cd54 (tree)
日時2017-04-22 05:41:52
作者android-build-team Robot <android-build-team-robot@goog...>
コミッターandroid-build-team Robot

ログメッセージ

Merge cherrypicks of [2007123, 2089669, 2072002, 2094113, 1989895, 2094094, 2017568, 2054111, 2054025, 2074928, 2066476, 2092431, 2053944, 2095243, 2092549, 2065088, 2007730, 2008313, 2053983, 2025333, 2094716, 2026590, 2059276, 2089422, 2080090] into nyc-mr2-pixel-monthly-release

Change-Id: I97aaec17443e66c586b65a2c2921e7ed13e64c83

変更サマリ

差分

--- a/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiver.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiver.java
@@ -59,7 +59,7 @@ public class BluetoothOppHandoverReceiver extends BroadcastReceiver {
5959 Thread t = new Thread(new Runnable() {
6060 public void run() {
6161 BluetoothOppManager.getInstance(context).saveSendingFileInfo(finalType,
62- finalUris, true);
62+ finalUris, true /* isHandover */, true /* fromExternal */);
6363 BluetoothOppManager.getInstance(context).startTransfer(device);
6464 }
6565 });
--- a/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppLauncherActivity.java
@@ -112,7 +112,8 @@ public class BluetoothOppLauncherActivity extends Activity {
112112 Thread t = new Thread(new Runnable() {
113113 public void run() {
114114 BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this)
115- .saveSendingFileInfo(type,stream.toString(), false);
115+ .saveSendingFileInfo(type,stream.toString(),
116+ false /* isHandover */, true /* fromExternal */);
116117 //Done getting file info..Launch device picker and finish this activity
117118 launchDevicePicker();
118119 finish();
@@ -128,7 +129,8 @@ public class BluetoothOppLauncherActivity extends Activity {
128129 Thread t = new Thread(new Runnable() {
129130 public void run() {
130131 BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this)
131- .saveSendingFileInfo(type,fileUri.toString(), false);
132+ .saveSendingFileInfo(type,fileUri.toString(),
133+ false /* isHandover */, false /* fromExternal */);
132134 //Done getting file info..Launch device picker
133135 //and finish this activity
134136 launchDevicePicker();
@@ -156,7 +158,8 @@ public class BluetoothOppLauncherActivity extends Activity {
156158 Thread t = new Thread(new Runnable() {
157159 public void run() {
158160 BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this)
159- .saveSendingFileInfo(mimeType,uris, false);
161+ .saveSendingFileInfo(mimeType,uris,
162+ false /* isHandover */, true /* fromExternal */);
160163 //Done getting file info..Launch device picker
161164 //and finish this activity
162165 launchDevicePicker();
--- a/src/com/android/bluetooth/opp/BluetoothOppManager.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppManager.java
@@ -246,28 +246,32 @@ public class BluetoothOppManager {
246246 if (V) Log.v(TAG, "Application data stored to SharedPreference! ");
247247 }
248248
249- public void saveSendingFileInfo(String mimeType, String uriString, boolean isHandover) {
249+ public void saveSendingFileInfo(String mimeType, String uriString, boolean isHandover,
250+ boolean fromExternal) {
250251 synchronized (BluetoothOppManager.this) {
251252 mMultipleFlag = false;
252253 mMimeTypeOfSendingFile = mimeType;
253254 mUriOfSendingFile = uriString;
254255 mIsHandoverInitiated = isHandover;
255256 Uri uri = Uri.parse(uriString);
256- BluetoothOppUtility.putSendFileInfo(uri,
257- BluetoothOppSendFileInfo.generateFileInfo(mContext, uri, mimeType));
257+ BluetoothOppUtility.putSendFileInfo(
258+ uri, BluetoothOppSendFileInfo.generateFileInfo(
259+ mContext, uri, mimeType, fromExternal));
258260 storeApplicationData();
259261 }
260262 }
261263
262- public void saveSendingFileInfo(String mimeType, ArrayList<Uri> uris, boolean isHandover) {
264+ public void saveSendingFileInfo(String mimeType, ArrayList<Uri> uris, boolean isHandover,
265+ boolean fromExternal) {
263266 synchronized (BluetoothOppManager.this) {
264267 mMultipleFlag = true;
265268 mMimeTypeOfSendingFiles = mimeType;
266269 mUrisOfSendingFiles = uris;
267270 mIsHandoverInitiated = isHandover;
268271 for (Uri uri : uris) {
269- BluetoothOppUtility.putSendFileInfo(uri,
270- BluetoothOppSendFileInfo.generateFileInfo(mContext, uri, mimeType));
272+ BluetoothOppUtility.putSendFileInfo(
273+ uri, BluetoothOppSendFileInfo.generateFileInfo(
274+ mContext, uri, mimeType, fromExternal));
271275 }
272276 storeApplicationData();
273277 }
--- a/src/com/android/bluetooth/opp/BluetoothOppSendFileInfo.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppSendFileInfo.java
@@ -39,6 +39,7 @@ import android.database.Cursor;
3939 import android.database.sqlite.SQLiteException;
4040 import android.net.Uri;
4141 import android.provider.OpenableColumns;
42+import android.util.EventLog;
4243 import android.util.Log;
4344
4445 import java.io.File;
@@ -97,8 +98,8 @@ public class BluetoothOppSendFileInfo {
9798 mStatus = status;
9899 }
99100
100- public static BluetoothOppSendFileInfo generateFileInfo(Context context, Uri uri,
101- String type) {
101+ public static BluetoothOppSendFileInfo generateFileInfo(
102+ Context context, Uri uri, String type, boolean fromExternal) {
102103 ContentResolver contentResolver = context.getContentResolver();
103104 String scheme = uri.getScheme();
104105 String fileName = null;
@@ -140,6 +141,16 @@ public class BluetoothOppSendFileInfo {
140141 fileName = uri.getLastPathSegment();
141142 }
142143 } else if ("file".equals(scheme)) {
144+ if (uri.getPath() == null) {
145+ Log.e(TAG, "Invalid URI path: " + uri);
146+ return SEND_FILE_INFO_ERROR;
147+ }
148+ if (fromExternal && !BluetoothOppUtility.isInExternalStorageDir(uri)) {
149+ EventLog.writeEvent(0x534e4554, "35310991", -1, uri.getPath());
150+ Log.e(TAG,
151+ "File based URI not in Environment.getExternalStorageDirectory() is not allowed.");
152+ return SEND_FILE_INFO_ERROR;
153+ }
143154 fileName = uri.getLastPathSegment();
144155 contentType = type;
145156 File f = new File(uri.getPath());
--- a/src/com/android/bluetooth/opp/BluetoothOppUtility.java
+++ b/src/com/android/bluetooth/opp/BluetoothOppUtility.java
@@ -39,6 +39,7 @@ import com.google.android.collect.Lists;
3939 import android.bluetooth.BluetoothAdapter;
4040 import android.bluetooth.BluetoothDevice;
4141 import android.net.Uri;
42+import android.content.ContentResolver;
4243 import android.content.ContentValues;
4344 import android.content.Context;
4445 import android.content.ActivityNotFoundException;
@@ -46,6 +47,7 @@ import android.content.Intent;
4647 import android.content.pm.PackageManager;
4748 import android.content.pm.ResolveInfo;
4849 import android.database.Cursor;
50+import android.os.Environment;
4951 import android.util.Log;
5052
5153 import java.io.File;
@@ -66,6 +68,10 @@ public class BluetoothOppUtility {
6668 private static final ConcurrentHashMap<Uri, BluetoothOppSendFileInfo> sSendFileMap
6769 = new ConcurrentHashMap<Uri, BluetoothOppSendFileInfo>();
6870
71+ public static boolean isBluetoothShareUri(Uri uri) {
72+ return uri.toString().startsWith(BluetoothShare.CONTENT_URI.toString());
73+ }
74+
6975 public static BluetoothOppTransferInfo queryRecord(Context context, Uri uri) {
7076 BluetoothOppTransferInfo info = new BluetoothOppTransferInfo();
7177 Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
@@ -176,6 +182,11 @@ public class BluetoothOppUtility {
176182 return;
177183 }
178184
185+ if (!isBluetoothShareUri(uri)) {
186+ Log.e(TAG, "Trying to open a file that wasn't transfered over Bluetooth");
187+ return;
188+ }
189+
179190 File f = new File(fileName);
180191 if (!f.exists()) {
181192 Intent in = new Intent(context, BluetoothOppBtErrorActivity.class);
@@ -206,17 +217,8 @@ public class BluetoothOppUtility {
206217 .queryIntentActivities(activityIntent,
207218 PackageManager.MATCH_DEFAULT_ONLY);
208219
209- // Grant permissions for any app that can handle a file to access it
210- for (ResolveInfo resolveInfo : resInfoList) {
211- String packageName = resolveInfo.activityInfo.packageName;
212- context.grantUriPermission(packageName, path,
213- Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
214- Intent.FLAG_GRANT_READ_URI_PERMISSION);
215- }
216-
217220 activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
218- activityIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
219- activityIntent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
221+ activityIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
220222
221223 try {
222224 if (V) Log.d(TAG, "ACTION_VIEW intent sent out: " + path + " / " + mimetype);
@@ -353,4 +355,40 @@ public class BluetoothOppUtility {
353355 }
354356 }
355357 }
358+
359+ /**
360+ * Checks if the URI is in Environment.getExternalStorageDirectory() as it
361+ * is the only directory that is possibly readable by both the sender and
362+ * the Bluetooth process.
363+ */
364+ static boolean isInExternalStorageDir(Uri uri) {
365+ if (!ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
366+ Log.e(TAG, "Not a file URI: " + uri);
367+ return false;
368+ }
369+ final File file = new File(uri.getCanonicalUri().getPath());
370+ return isSameOrSubDirectory(Environment.getExternalStorageDirectory(), file);
371+ }
372+
373+ /**
374+ * Checks, whether the child directory is the same as, or a sub-directory of the base
375+ * directory. Neither base nor child should be null.
376+ */
377+ static boolean isSameOrSubDirectory(File base, File child) {
378+ try {
379+ base = base.getCanonicalFile();
380+ child = child.getCanonicalFile();
381+ File parentFile = child;
382+ while (parentFile != null) {
383+ if (base.equals(parentFile)) {
384+ return true;
385+ }
386+ parentFile = parentFile.getParentFile();
387+ }
388+ return false;
389+ } catch (IOException ex) {
390+ Log.e(TAG, "Error while accessing file", ex);
391+ return false;
392+ }
393+ }
356394 }
旧リポジトリブラウザで表示