From e39def480fd2d1bcc3a89751dd492d4634c38194 Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Wed, 5 Aug 2015 23:32:54 -0700 Subject: MidiService: update listener with current status when registered This will give an app an opportunity to learn whether an input port is busy before the user tries to connect and then fails. Bug: 22825043 Change-Id: Ifede60f166dfe66ea15453044fce06f4a8452b18 Signed-off-by: Phil Burk (cherry picked from commit b2355940e3e697deeecd1b6511cd5094f9dc553a) --- media/java/android/media/midi/MidiManager.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'media') diff --git a/media/java/android/media/midi/MidiManager.java b/media/java/android/media/midi/MidiManager.java index 7197dc0..29863d4 100644 --- a/media/java/android/media/midi/MidiManager.java +++ b/media/java/android/media/midi/MidiManager.java @@ -169,6 +169,13 @@ public final class MidiManager { /** * Registers a callback to receive notifications when MIDI devices are added and removed. * + * The {@link DeviceCallback#onDeviceStatusChanged} method will be called immediately + * for any devices that have open ports. This allows applications to know which input + * ports are already in use and, therefore, unavailable. + * + * Applications should call {@link #getDevices} before registering the callback + * to get a list of devices already added. + * * @param callback a {@link DeviceCallback} for MIDI device notifications * @param handler The {@link android.os.Handler Handler} that will be used for delivering the * device notifications. If handler is null, then the thread used for the -- cgit v1.1 From afa038c07444fc16c2e77157195945162a9cc83e Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Fri, 21 Aug 2015 15:22:35 -0700 Subject: MidiManager: fix double BTLE callback Stop openBluetoothDevice() from calling its callback twice. Bug: 23218338 Change-Id: I2e738b22a124c0336c46bef05680a82ee1f59e79 Signed-off-by: Phil Burk (cherry picked from commit 0ca998d79fe95ded26ec4ff0a1e0a8dc4802684b) --- media/java/android/media/midi/MidiManager.java | 1 - 1 file changed, 1 deletion(-) (limited to 'media') diff --git a/media/java/android/media/midi/MidiManager.java b/media/java/android/media/midi/MidiManager.java index 7197dc0..e72bdb4 100644 --- a/media/java/android/media/midi/MidiManager.java +++ b/media/java/android/media/midi/MidiManager.java @@ -288,7 +288,6 @@ public final class MidiManager { // fetch MidiDeviceInfo from the server MidiDeviceInfo deviceInfo = server.getDeviceInfo(); device = new MidiDevice(deviceInfo, server, mService, mToken, deviceToken); - sendOpenDeviceResponse(device, listenerF, handlerF); } catch (RemoteException e) { Log.e(TAG, "remote exception in getDeviceInfo()"); } -- cgit v1.1 From 7688911b9f08d239245e4e2c8f6153894fce9671 Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Fri, 21 Aug 2015 15:39:10 -0700 Subject: MidiBluetoothService: add new device to HashMap The HashMap is being used but devices never added to the map. Bug: 23429459 Change-Id: I1da5305a56f5bd48e1c5d9345e721ea8dd2eed4e Signed-off-by: Phil Burk (cherry picked from commit e5f722e55c5708c2b48b8c9688c135e451225032) --- .../src/com/android/bluetoothmidiservice/BluetoothMidiService.java | 1 + 1 file changed, 1 insertion(+) (limited to 'media') diff --git a/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java b/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java index fbde2b4..1f81a05 100644 --- a/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java +++ b/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java @@ -46,6 +46,7 @@ public class BluetoothMidiService extends Service { device = mDeviceServerMap.get(bluetoothDevice); if (device == null) { device = new BluetoothMidiDevice(this, bluetoothDevice, this); + mDeviceServerMap.put(bluetoothDevice, device); } } return device.getBinder(); -- cgit v1.1 From af3e489c1ee3e1017d8aca53a1cf6c683b88ecc2 Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Tue, 22 Sep 2015 12:07:31 -0700 Subject: BluetoothMidiDevice: change write type to support JamStik Temporarily use a Request instead of a Command so that the JamStik will be properly enabled. Bug: 24207964 Change-Id: I3d11732958c46e6039405b5969d5af0db8032fb9 Signed-off-by: Phil Burk (cherry picked from commit 95129f50c68c734c5ebdf32ff6b8b9c63cc1ada7) --- .../com/android/bluetoothmidiservice/BluetoothMidiDevice.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'media') diff --git a/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiDevice.java b/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiDevice.java index e6d59e4..444705c 100644 --- a/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiDevice.java +++ b/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiDevice.java @@ -147,14 +147,22 @@ public final class BluetoothMidiDevice { // switch to receiving notifications after initial characteristic read mBluetoothGatt.setCharacteristicNotification(characteristic, true); + // Use writeType that requests acknowledgement. + // This improves compatibility with various BLE-MIDI devices. + int originalWriteType = characteristic.getWriteType(); + characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT); + BluetoothGattDescriptor descriptor = characteristic.getDescriptor( CLIENT_CHARACTERISTIC_CONFIG); if (descriptor != null) { descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); - mBluetoothGatt.writeDescriptor(descriptor); + boolean result = mBluetoothGatt.writeDescriptor(descriptor); + Log.d(TAG, "writeDescriptor returned " + result); } else { Log.e(TAG, "No CLIENT_CHARACTERISTIC_CONFIG for device " + mBluetoothDevice); } + + characteristic.setWriteType(originalWriteType); } @Override -- cgit v1.1 From c024de3c946c18e8e4799eb8d372fdec3146f8cf Mon Sep 17 00:00:00 2001 From: Ronghua Wu Date: Tue, 11 Aug 2015 13:33:49 -0700 Subject: media: ignore null InputStream Bug: 22854896 Change-Id: I20b9e28bbba6dec73538ee6937d337c2e2b971f4 --- media/java/android/media/MediaPlayer.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'media') diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java index 13b2878..2e82e2f 100644 --- a/media/java/android/media/MediaPlayer.java +++ b/media/java/android/media/MediaPlayer.java @@ -2243,10 +2243,14 @@ public class MediaPlayer implements SubtitleController.Listener final InputStream fIs = is; final MediaFormat fFormat = format; - // Ensure all input streams are closed. It is also a handy - // way to implement timeouts in the future. - synchronized(mOpenSubtitleSources) { - mOpenSubtitleSources.add(is); + if (is != null) { + // Ensure all input streams are closed. It is also a handy + // way to implement timeouts in the future. + synchronized(mOpenSubtitleSources) { + mOpenSubtitleSources.add(is); + } + } else { + Log.w(TAG, "addSubtitleSource called with null InputStream"); } // process each subtitle in its own thread -- cgit v1.1 From 977fe03b36a7783f9cee8497efe550a69b128473 Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Thu, 3 Sep 2015 14:37:03 -0700 Subject: BLE-MIDI: change binding for BluetoothMidiService Add a remote call addBluetoothDevice() using AIDL. This was needed because onBind() is only called once. Bug: 23219556 Bug: 23760886 Change-Id: Id7554ca55d596352d11dbd6ae3e403138a29c864 Signed-off-by: Phil Burk (cherry picked from commit 7cd06c0b9e087a555d2c5dd4cab5b7eac8497526) --- .../android/media/midi/IBluetoothMidiService.aidl | 26 ++++++++++++++++++++++ media/packages/BluetoothMidiService/Android.mk | 3 ++- .../BluetoothMidiService/AndroidManifest.xml | 2 +- .../bluetoothmidiservice/BluetoothMidiService.java | 23 ++++++++++++------- 4 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 media/java/android/media/midi/IBluetoothMidiService.aidl (limited to 'media') diff --git a/media/java/android/media/midi/IBluetoothMidiService.aidl b/media/java/android/media/midi/IBluetoothMidiService.aidl new file mode 100644 index 0000000..fe5566d --- /dev/null +++ b/media/java/android/media/midi/IBluetoothMidiService.aidl @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media.midi; + +import android.bluetooth.BluetoothDevice; +import android.os.IBinder; + +/** @hide */ +interface IBluetoothMidiService +{ + IBinder addBluetoothDevice(in BluetoothDevice bluetoothDevice); +} diff --git a/media/packages/BluetoothMidiService/Android.mk b/media/packages/BluetoothMidiService/Android.mk index 2c9c3c5..0565925 100644 --- a/media/packages/BluetoothMidiService/Android.mk +++ b/media/packages/BluetoothMidiService/Android.mk @@ -3,7 +3,8 @@ include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional -LOCAL_SRC_FILES := $(call all-subdir-java-files) +LOCAL_SRC_FILES += \ + $(call all-java-files-under,src) LOCAL_PACKAGE_NAME := BluetoothMidiService LOCAL_CERTIFICATE := platform diff --git a/media/packages/BluetoothMidiService/AndroidManifest.xml b/media/packages/BluetoothMidiService/AndroidManifest.xml index b0b389a..1cfd55d 100644 --- a/media/packages/BluetoothMidiService/AndroidManifest.xml +++ b/media/packages/BluetoothMidiService/AndroidManifest.xml @@ -8,7 +8,7 @@ - diff --git a/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java b/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java index 1f81a05..5541f9f 100644 --- a/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java +++ b/media/packages/BluetoothMidiService/src/com/android/bluetoothmidiservice/BluetoothMidiService.java @@ -19,6 +19,7 @@ package com.android.bluetoothmidiservice; import android.app.Service; import android.bluetooth.BluetoothDevice; import android.content.Intent; +import android.media.midi.IBluetoothMidiService; import android.media.midi.MidiManager; import android.os.IBinder; import android.util.Log; @@ -34,25 +35,31 @@ public class BluetoothMidiService extends Service { @Override public IBinder onBind(Intent intent) { - if (MidiManager.BLUETOOTH_MIDI_SERVICE_INTENT.equals(intent.getAction())) { - BluetoothDevice bluetoothDevice = (BluetoothDevice)intent.getParcelableExtra("device"); + // Return the interface + return mBinder; + } + + + private final IBluetoothMidiService.Stub mBinder = new IBluetoothMidiService.Stub() { + + public IBinder addBluetoothDevice(BluetoothDevice bluetoothDevice) { + BluetoothMidiDevice device; if (bluetoothDevice == null) { - Log.e(TAG, "no BluetoothDevice in onBind intent"); + Log.e(TAG, "no BluetoothDevice in addBluetoothDevice()"); return null; } - - BluetoothMidiDevice device; synchronized (mDeviceServerMap) { device = mDeviceServerMap.get(bluetoothDevice); if (device == null) { - device = new BluetoothMidiDevice(this, bluetoothDevice, this); + device = new BluetoothMidiDevice(BluetoothMidiService.this, + bluetoothDevice, BluetoothMidiService.this); mDeviceServerMap.put(bluetoothDevice, device); } } return device.getBinder(); } - return null; - } + + }; void deviceClosed(BluetoothDevice device) { synchronized (mDeviceServerMap) { -- cgit v1.1 From de612dc1d10d25e017ac911d0e7cca6709bdbb96 Mon Sep 17 00:00:00 2001 From: Wei Jia Date: Wed, 7 Oct 2015 15:38:12 -0700 Subject: MediaPlayer: remove obsolete function setPlaybackRate from comments. Bug: 24260668 Change-Id: I20733e52dbd2dab5eb10b4607a1c1aadb93a1332 (cherry picked from commit cd860ac06ca7a46e9638dd741ba731f066705eb5) --- media/java/android/media/MediaPlayer.java | 5 ----- 1 file changed, 5 deletions(-) (limited to 'media') diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java index 2e82e2f..587d494 100644 --- a/media/java/android/media/MediaPlayer.java +++ b/media/java/android/media/MediaPlayer.java @@ -479,11 +479,6 @@ import java.lang.ref.WeakReference; * {}

* This method can be called in any state and calling it does not change * the object state.

- * setPlaybackRate

- * any

- * {}

- * This method can be called in any state and calling it does not change - * the object state.

* setPlaybackParams

* any

* {}

-- cgit v1.1 From df252d6e0fc23462bdb0993a2f4acb033fe18f43 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Thu, 5 Nov 2015 16:44:52 -0800 Subject: Fix race condition when setting default ringtones If the device was powered off during first boot, after media scanner inserted some entries but before the default ringtone settings were set (or committed to disk), the default settings would not be set on subsequent boots. Bug: 18625739 Bug: 22349910 Change-Id: Iff07da59a9c6d53bf2950bd107ee74d02b7f48d6 --- media/java/android/media/MediaScanner.java | 89 ++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 28 deletions(-) (limited to 'media') diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java index 9ea6722..f36d640 100644 --- a/media/java/android/media/MediaScanner.java +++ b/media/java/android/media/MediaScanner.java @@ -20,6 +20,7 @@ import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; +import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; @@ -41,6 +42,7 @@ import android.provider.MediaStore.Files.FileColumns; import android.provider.MediaStore.Images; import android.provider.MediaStore.Video; import android.provider.Settings; +import android.provider.Settings.SettingNotFoundException; import android.sax.Element; import android.sax.ElementListener; import android.sax.RootElement; @@ -324,8 +326,6 @@ public class MediaScanner // used when scanning the image database so we know whether we have to prune // old thumbnail files private int mOriginalCount; - /** Whether the database had any entries in it before the scan started */ - private boolean mWasEmptyPriorToScan = false; /** Whether the scanner has set a default sound for the ringer ringtone. */ private boolean mDefaultRingtoneSet; /** Whether the scanner has set a default sound for the notification ringtone. */ @@ -535,6 +535,18 @@ public class MediaScanner if (mMtpObjectHandle != 0) { entry.mRowId = 0; } + + if ((!mDefaultNotificationSet && + doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename)) + || (!mDefaultRingtoneSet && + doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) + || (!mDefaultAlarmSet && + doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename))) { + Log.w(TAG, "forcing rescan of " + entry.mPath + + "since ringtone setting didn't finish"); + scanAlways = true; + } + // rescan for metadata if file was modified since last scan if (entry != null && (entry.mLastModifiedChanged || scanAlways)) { if (noMedia) { @@ -914,6 +926,26 @@ public class MediaScanner } Uri result = null; boolean needToSetSettings = false; + // Setting a flag in order not to use bulk insert for the file related with + // notifications, ringtones, and alarms, because the rowId of the inserted file is + // needed. + if (notifications && !mDefaultNotificationSet) { + if (TextUtils.isEmpty(mDefaultNotificationFilename) || + doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename)) { + needToSetSettings = true; + } + } else if (ringtones && !mDefaultRingtoneSet) { + if (TextUtils.isEmpty(mDefaultRingtoneFilename) || + doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) { + needToSetSettings = true; + } + } else if (alarms && !mDefaultAlarmSet) { + if (TextUtils.isEmpty(mDefaultAlarmAlertFilename) || + doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename)) { + needToSetSettings = true; + } + } + if (rowId == 0) { if (mMtpObjectHandle != 0) { values.put(MediaStore.MediaColumns.MEDIA_SCANNER_NEW_OBJECT_ID, mMtpObjectHandle); @@ -925,28 +957,6 @@ public class MediaScanner } values.put(Files.FileColumns.FORMAT, format); } - // Setting a flag in order not to use bulk insert for the file related with - // notifications, ringtones, and alarms, because the rowId of the inserted file is - // needed. - if (mWasEmptyPriorToScan) { - if (notifications && !mDefaultNotificationSet) { - if (TextUtils.isEmpty(mDefaultNotificationFilename) || - doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename)) { - needToSetSettings = true; - } - } else if (ringtones && !mDefaultRingtoneSet) { - if (TextUtils.isEmpty(mDefaultRingtoneFilename) || - doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) { - needToSetSettings = true; - } - } else if (alarms && !mDefaultAlarmSet) { - if (TextUtils.isEmpty(mDefaultAlarmAlertFilename) || - doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename)) { - needToSetSettings = true; - } - } - } - // New file, insert it. // Directories need to be inserted before the files they contain, so they // get priority when bulk inserting. @@ -1016,13 +1026,20 @@ public class MediaScanner private void setSettingIfNotSet(String settingName, Uri uri, long rowId) { + if(wasSettingAlreadySet(settingName)) { + return; + } + String existingSettingValue = Settings.System.getString(mContext.getContentResolver(), settingName); if (TextUtils.isEmpty(existingSettingValue)) { // Set the setting to the given URI - Settings.System.putString(mContext.getContentResolver(), settingName, + + ContentResolver cr = mContext.getContentResolver(); + Settings.System.putString(cr, settingName, ContentUris.withAppendedId(uri, rowId).toString()); + Settings.System.putInt(cr, settingSetIndicatorName(settingName), 1); } } @@ -1050,6 +1067,20 @@ public class MediaScanner }; // end of anonymous MediaScannerClient instance + private String settingSetIndicatorName(String base) { + return base + "_set"; + } + + private boolean wasSettingAlreadySet(String name) { + ContentResolver cr = mContext.getContentResolver(); + String indicatorName = settingSetIndicatorName(name); + try { + return Settings.System.getInt(cr, indicatorName) != 0; + } catch (SettingNotFoundException e) { + return false; + } + } + private void prescan(String filePath, boolean prescanFiles) throws RemoteException { Cursor c = null; String where = null; @@ -1071,6 +1102,10 @@ public class MediaScanner selectionArgs = new String[] { "" }; } + mDefaultRingtoneSet = wasSettingAlreadySet(Settings.System.RINGTONE); + mDefaultNotificationSet = wasSettingAlreadySet(Settings.System.NOTIFICATION_SOUND); + mDefaultAlarmSet = wasSettingAlreadySet(Settings.System.ALARM_ALERT); + // Tell the provider to not delete the file. // If the file is truly gone the delete is unnecessary, and we want to avoid // accidentally deleting files that are really there (this may happen if the @@ -1089,7 +1124,6 @@ public class MediaScanner // with CursorWindow positioning. long lastId = Long.MIN_VALUE; Uri limitUri = mFilesUri.buildUpon().appendQueryParameter("limit", "1000").build(); - mWasEmptyPriorToScan = true; while (true) { selectionArgs[0] = "" + lastId; @@ -1108,7 +1142,6 @@ public class MediaScanner if (num == 0) { break; } - mWasEmptyPriorToScan = false; while (c.moveToNext()) { long rowId = c.getLong(FILES_PRESCAN_ID_COLUMN_INDEX); String path = c.getString(FILES_PRESCAN_PATH_COLUMN_INDEX); @@ -1260,7 +1293,7 @@ public class MediaScanner } } - private void postscan(String[] directories) throws RemoteException { + private void postscan(final String[] directories) throws RemoteException { // handle playlists last, after we know what media files are on the storage. if (mProcessPlaylists) { -- cgit v1.1 From 4d70bd7a928903b35c92619437c70bc382587b71 Mon Sep 17 00:00:00 2001 From: Ian Pedowitz Date: Wed, 11 Nov 2015 21:38:04 +0000 Subject: Revert "Fix race condition when setting default ringtones" This reverts commit f2cb9341ff864e6d9cc6797857665b2281643a74. Change-Id: I151972052aea47bf8c6823eb8bbf8161c5a7a4f0 --- media/java/android/media/MediaScanner.java | 89 ++++++++++-------------------- 1 file changed, 28 insertions(+), 61 deletions(-) (limited to 'media') diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java index f36d640..9ea6722 100644 --- a/media/java/android/media/MediaScanner.java +++ b/media/java/android/media/MediaScanner.java @@ -20,7 +20,6 @@ import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; -import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; @@ -42,7 +41,6 @@ import android.provider.MediaStore.Files.FileColumns; import android.provider.MediaStore.Images; import android.provider.MediaStore.Video; import android.provider.Settings; -import android.provider.Settings.SettingNotFoundException; import android.sax.Element; import android.sax.ElementListener; import android.sax.RootElement; @@ -326,6 +324,8 @@ public class MediaScanner // used when scanning the image database so we know whether we have to prune // old thumbnail files private int mOriginalCount; + /** Whether the database had any entries in it before the scan started */ + private boolean mWasEmptyPriorToScan = false; /** Whether the scanner has set a default sound for the ringer ringtone. */ private boolean mDefaultRingtoneSet; /** Whether the scanner has set a default sound for the notification ringtone. */ @@ -535,18 +535,6 @@ public class MediaScanner if (mMtpObjectHandle != 0) { entry.mRowId = 0; } - - if ((!mDefaultNotificationSet && - doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename)) - || (!mDefaultRingtoneSet && - doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) - || (!mDefaultAlarmSet && - doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename))) { - Log.w(TAG, "forcing rescan of " + entry.mPath + - "since ringtone setting didn't finish"); - scanAlways = true; - } - // rescan for metadata if file was modified since last scan if (entry != null && (entry.mLastModifiedChanged || scanAlways)) { if (noMedia) { @@ -926,26 +914,6 @@ public class MediaScanner } Uri result = null; boolean needToSetSettings = false; - // Setting a flag in order not to use bulk insert for the file related with - // notifications, ringtones, and alarms, because the rowId of the inserted file is - // needed. - if (notifications && !mDefaultNotificationSet) { - if (TextUtils.isEmpty(mDefaultNotificationFilename) || - doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename)) { - needToSetSettings = true; - } - } else if (ringtones && !mDefaultRingtoneSet) { - if (TextUtils.isEmpty(mDefaultRingtoneFilename) || - doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) { - needToSetSettings = true; - } - } else if (alarms && !mDefaultAlarmSet) { - if (TextUtils.isEmpty(mDefaultAlarmAlertFilename) || - doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename)) { - needToSetSettings = true; - } - } - if (rowId == 0) { if (mMtpObjectHandle != 0) { values.put(MediaStore.MediaColumns.MEDIA_SCANNER_NEW_OBJECT_ID, mMtpObjectHandle); @@ -957,6 +925,28 @@ public class MediaScanner } values.put(Files.FileColumns.FORMAT, format); } + // Setting a flag in order not to use bulk insert for the file related with + // notifications, ringtones, and alarms, because the rowId of the inserted file is + // needed. + if (mWasEmptyPriorToScan) { + if (notifications && !mDefaultNotificationSet) { + if (TextUtils.isEmpty(mDefaultNotificationFilename) || + doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename)) { + needToSetSettings = true; + } + } else if (ringtones && !mDefaultRingtoneSet) { + if (TextUtils.isEmpty(mDefaultRingtoneFilename) || + doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) { + needToSetSettings = true; + } + } else if (alarms && !mDefaultAlarmSet) { + if (TextUtils.isEmpty(mDefaultAlarmAlertFilename) || + doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename)) { + needToSetSettings = true; + } + } + } + // New file, insert it. // Directories need to be inserted before the files they contain, so they // get priority when bulk inserting. @@ -1026,20 +1016,13 @@ public class MediaScanner private void setSettingIfNotSet(String settingName, Uri uri, long rowId) { - if(wasSettingAlreadySet(settingName)) { - return; - } - String existingSettingValue = Settings.System.getString(mContext.getContentResolver(), settingName); if (TextUtils.isEmpty(existingSettingValue)) { // Set the setting to the given URI - - ContentResolver cr = mContext.getContentResolver(); - Settings.System.putString(cr, settingName, + Settings.System.putString(mContext.getContentResolver(), settingName, ContentUris.withAppendedId(uri, rowId).toString()); - Settings.System.putInt(cr, settingSetIndicatorName(settingName), 1); } } @@ -1067,20 +1050,6 @@ public class MediaScanner }; // end of anonymous MediaScannerClient instance - private String settingSetIndicatorName(String base) { - return base + "_set"; - } - - private boolean wasSettingAlreadySet(String name) { - ContentResolver cr = mContext.getContentResolver(); - String indicatorName = settingSetIndicatorName(name); - try { - return Settings.System.getInt(cr, indicatorName) != 0; - } catch (SettingNotFoundException e) { - return false; - } - } - private void prescan(String filePath, boolean prescanFiles) throws RemoteException { Cursor c = null; String where = null; @@ -1102,10 +1071,6 @@ public class MediaScanner selectionArgs = new String[] { "" }; } - mDefaultRingtoneSet = wasSettingAlreadySet(Settings.System.RINGTONE); - mDefaultNotificationSet = wasSettingAlreadySet(Settings.System.NOTIFICATION_SOUND); - mDefaultAlarmSet = wasSettingAlreadySet(Settings.System.ALARM_ALERT); - // Tell the provider to not delete the file. // If the file is truly gone the delete is unnecessary, and we want to avoid // accidentally deleting files that are really there (this may happen if the @@ -1124,6 +1089,7 @@ public class MediaScanner // with CursorWindow positioning. long lastId = Long.MIN_VALUE; Uri limitUri = mFilesUri.buildUpon().appendQueryParameter("limit", "1000").build(); + mWasEmptyPriorToScan = true; while (true) { selectionArgs[0] = "" + lastId; @@ -1142,6 +1108,7 @@ public class MediaScanner if (num == 0) { break; } + mWasEmptyPriorToScan = false; while (c.moveToNext()) { long rowId = c.getLong(FILES_PRESCAN_ID_COLUMN_INDEX); String path = c.getString(FILES_PRESCAN_PATH_COLUMN_INDEX); @@ -1293,7 +1260,7 @@ public class MediaScanner } } - private void postscan(final String[] directories) throws RemoteException { + private void postscan(String[] directories) throws RemoteException { // handle playlists last, after we know what media files are on the storage. if (mProcessPlaylists) { -- cgit v1.1