originallgb / keepassdroid

Automatically exported from code.google.com/p/keepassdroid
0 stars 0 forks source link

Intent filter doesn't work for file paths with a "." #262

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm one of the developers of the Dropbox app for Android. After some updates, 
we and several of our users noticed that KeePassDroid stopped showing up as an 
app to open .kdb files. I traced it down to not working when the file path 
contains a period other than before the file extension (i.e., 
file://mnt/sdcard/my.folder/passwords.kdb).

It seems that matching on host="*" in the manifest doesn't seem to act the way 
we'd expect, and that extra period adds a host to the file:// URI which that 
rule doesn't match. Removing the host check fixes the issue and shouldn't 
affect the intent filter in any other way (since the * was meant to imply 
"match everything", which is exactly what removing that rule altogether does).

I'm attaching the patch with the aforementioned fix.

Original issue reported on code.google.com by emailfor...@gmail.com on 21 Dec 2011 at 3:23

GoogleCodeExporter commented 8 years ago
I think the host tag is a red herring. The pathPattern is ignored unless both a 
host and scheme are specified:

http://developer.android.com/guide/topics/manifest/data-element.html

If I apply your fix, then KeePassDroid will try to launch for every filename 
you click on in Dropbox, regardless of whether it ends in .kdb or .kdbx.

It seems to me like that the dot special character fails to match literal dots.

If I change the intent-filter to look like this:

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="file" />
                <data android:mimeType="*/*" />
                <data android:host="*" />
                <data android:pathPattern=".*\\.kdb" />
                <data android:pathPattern=".*\\..*\\.kdb" />
            </intent-filter>

It will now match paths with a single dot in the path.

I'll consider adding this as a workaround to allow some arbitrary number of 
dots in a path.

This behavior isn't documented. It's probably worth filing a bug against the 
android project for this.

Original comment by bpel...@gmail.com on 22 Dec 2011 at 5:22

GoogleCodeExporter commented 8 years ago
Issue 245 has been merged into this issue.

Original comment by bpel...@gmail.com on 22 Dec 2011 at 5:22

GoogleCodeExporter commented 8 years ago
I read the source code for the PatternMatch class that android uses to 
interpret these strings:

https://github.com/android/platform_frameworks_base/blob/master/core/java/androi
d/os/PatternMatcher.java

Unfortunately, the * operator is not greedy like you would expect if this was a 
regular expression. The . in my initial pattern will match all characters until 
it sees a dot, then it will stop.

I haven't thought about this too hard, but I think this means it's not possible 
to write a pattern that can match any string that ends in .kdb or .kdbx. I can 
only write patterns that match an arbitrary number of dots in the path.

Original comment by bpel...@gmail.com on 22 Dec 2011 at 5:43

GoogleCodeExporter commented 8 years ago
You're totally right. Sorry about that, I should have dug a little deeper into 
it before pointing my finger in the wrong direction.

I peeked at the Android source as well and I agree with what you said. Maybe 
this is their intention (they call it a PATTERN_SIMPLE_GLOB), but I'll try 
filing a bug anyway. Either way, it won't help anyone for a while.

One workaround, although not great, is to get rid of the dot and match ".*kdb". 
Another is what you mentioned, adding a bunch of pathPatterns up to an 
arbitrary number of dots.

Either way, I'd appreciate if you could get an update out that addresses this 
in any way. We're about to push an update ourselves that will introduce some 
dots to our file paths (due to "com.dropbox.android") and we've already had a 
few users run into this from our forum build.

Original comment by emailfor...@gmail.com on 22 Dec 2011 at 5:57

GoogleCodeExporter commented 8 years ago
Unfortunately getting rid of the dot in the match introduces the more troubling 
problem of failing to match paths with multiple k's in them.

They really botched the implementation of this pattern matcher.

I'll put in a workaround. Maybe 10 dots is enough?

Original comment by bpel...@gmail.com on 22 Dec 2011 at 6:07

GoogleCodeExporter commented 8 years ago
I should stop suggesting things when I'm tired :\ You're right again, and 10 
sounds pretty reasonable to me. I think this mostly comes up from dots in 
filenames (I can't imagine most people have more than 2) and dots in package 
names when apps put their data in Android/data/[package], which also is usually 
limited to 2-3 dots.

Original comment by emailfor...@gmail.com on 22 Dec 2011 at 6:24

GoogleCodeExporter commented 8 years ago
Fixed in 1.9.6.

Original comment by bpel...@gmail.com on 22 Dec 2011 at 6:42

GoogleCodeExporter commented 8 years ago
Hi all,
What is the exact fix for this issue ? Do we need to add multiple dots in path 
pattern as per our need ? 

Original comment by yogeshla...@gmail.com on 2 Sep 2013 at 9:21

GoogleCodeExporter commented 8 years ago
Does anyone know what the fix is other than doing the multiple patterns and 
repeating until I'm tired like this:

   <data android:pathPattern=".*\\.kdb" />
   <data android:pathPattern=".*\\..*\\.kdb" />

Original comment by casol...@gmail.com on 15 Apr 2014 at 9:17