Respect default browser of the user by hnljp · Pull Request #379 · openid/AppAuth-Android · GitHub
Skip to content

Respect default browser of the user#379

Merged
iainmcgin merged 8 commits into
openid:masterfrom
hnljp:default-browser
Aug 7, 2018
Merged

Respect default browser of the user#379
iainmcgin merged 8 commits into
openid:masterfrom
hnljp:default-browser

Conversation

@hnljp

@hnljp hnljp commented Jul 20, 2018

Copy link
Copy Markdown
Contributor

a possible default browser of the user is respected.

fixes: #372

split from #369

Signed-off-by: Henning Nielsen Lund henning.n.lund@jp.dk

a possible default browser of the user is respected.

fixes: openid#372

split from openid#369

Signed-off-by: Henning Nielsen Lund <henning.n.lund@jp.dk>
@codecov-io

codecov-io commented Jul 20, 2018

Copy link
Copy Markdown

@hnljp

hnljp commented Jul 20, 2018

Copy link
Copy Markdown
Contributor Author

As stated in #369

I have tried to look more into it.
The problem is that the PackageManager.MATCH_ALL flag is making the result unsorted.
https://developer.android.com/reference/android/content/pm/PackageManager#MATCH_ALL
But the problem is that removing MATCH_ALL, will make queryIntentActivities only return the default browser on Android >= 7.0.

Looking at the code generating the list returned by queryIntentActivities:
https://android.googlesource.com/platform/frameworks/base.git/+/master/services/core/java/com/android/server/pm/PackageManagerService.java#7801
That is using the list generated as "an unsorted list":
https://android.googlesource.com/platform/frameworks/base.git/+/master/services/core/java/com/android/server/pm/PackageManagerService.java#7731
That is why there is a need to get the package name of the default browser and the list using MATCH_ALL is needed, in case the default browser is not compatible with Custom Tabs.

@hnljp

hnljp commented Jul 20, 2018

Copy link
Copy Markdown
Contributor Author

Fixes #368

Add support for custom tabs in Firefox. Support for custom tabs was added to stable Firefox in version 57.0

Fixes: openid#368
Signed-off-by: Henning Nielsen Lund <henning.n.lund@jp.dk>

@iainmcgin iainmcgin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! If you can address the review comments, in particular the need for tests, I can merge this change.

if (VERSION.SDK_INT >= VERSION_CODES.M) {
queryFlag |= PackageManager.MATCH_ALL;
}
ResolveInfo resolvedDefaultActivity =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a brief comment here describing the issue, e.g.

When requesting all matching activities for an intent from the package manager, the user's preferred browser is not guaranteed to be at the head of this list. Therefore, the preferred browser must be separately determined and the resultant list of browsers reordered to restored this desired property.


if (hasWarmupService(pm, info.activityInfo.packageName)) {
browsers.add(new BrowserDescriptor(packageInfo, true));
BrowserDescriptor customTabBrowserDescriptor =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add tests to BrowserSelectorTest that demonstrate:

  • If the user has no default browser, the order of the returned browsers matches the order of matching intents returned by queryIntentActivities. This case is likely already covered by the existing tests, but it will help to make that more explicit.
  • If the user has a default browser, with custom tab support, the two entries for that browser are at the start of the list, with the custom tab descriptor first.
  • If the user has a default browser, without custom tab support, that one entry for that browser is at the start of the list.

The code looks correct to me, but I just want to make sure that the changes are appropriately covered by tests so that future changes don't result in regressions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests have now been added.

hnljp added 6 commits July 27, 2018 23:33
a possible default browser of the user is respected.

fixes: openid#372

split from openid#369

Signed-off-by: Henning Nielsen Lund <henning.n.lund@jp.dk>
openid#379 (comment)
Signed-off-by: Henning Nielsen Lund <henning.n.lund@jp.dk>
Add tests for when a default browser is set.

Signed-off-by: Henning Nielsen Lund <henning.n.lund@jp.dk>
The test is now also checking if the BrowserDesriptors are added in the correct order, by checking useCustomTab.

Signed-off-by: Henning Nielsen Lund <henning.n.lund@jp.dk>
Now also check if there is no browser supporting custom tabs, but a browser is set as the default browser, so it should be returned.

Signed-off-by: Henning Nielsen Lund <henning.n.lund@jp.dk>
@hnljp

hnljp commented Aug 4, 2018

Copy link
Copy Markdown
Contributor Author

@iainmcgin iainmcgin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your patience, and for the addition of the tests.

@iainmcgin iainmcgin merged commit a42f28a into openid:master Aug 7, 2018
@hnljp hnljp deleted the default-browser branch August 7, 2018 19:14
athilahs added a commit to Skyscanner/AppAuth-Android that referenced this pull request Aug 17, 2020
* Minor README fixes (openid#351)

Thanks to @celphy for spotting these mistakes.

* Add WeWork to AUTHORS

WeWork, as my employer, is now the copyright owner for my
contributions to AppAuth.

* Dependency version bump

* Handle CustomTabsSession.newSession failures

Fixes openid#315.

* Enable Java 8 language features

* Do not automatically pass scope on token exchange request

Fixes openid#297.

* Do not override tab title setting

Fixes openid#358.

* Firefox customtabs (openid#378)

Add support for custom tabs in Firefox. Support for custom tabs was added to stable Firefox in version 57.0

Fixes: openid#368
Signed-off-by: Henning Nielsen Lund <henning.n.lund@jp.dk>

* Respect default browser of the user (openid#379)

Correctly orders the user's preferred browser to the start of the returned list.

* Custom Tabs was first added in Samsung Internet 4.0 (openid#383)

At the moment all versions of the Samsung Internet Browser is set to support Custom Tabs. Support for Custom Tabs was first added in version 4.0.

fixes: openid#382

* add getBrowserDescriptor() (openid#388)

Make it possible to get the BrowserDescriptor used by AuthorizationService.

fixes: openid#387
Signed-off-by: Henning Nielsen Lund <henning.n.lund@jp.dk>

* Android gradle plugin version bump

* Implement ID Token validation according to OIDC spec (openid#385)

Validate ID Tokens (if any) on TokenResponses according to http://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation

* Add Øyvind to the contributors list

* Update CONTRIBUTORS with email (openid#397)

* Use CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION in BrowserSelector. (openid#411)

* This helps with the jetification. I produced an artifact locally,
  and wrote a sample app using:

  ```gradle
  implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
  implementation 'androidx.browser:browser:1.0.0-rc02'
  ```

  to make sure that the app works.

Fixes: openid#395

* Issue openid#402: fixes NPE in case input stream is null (openid#414)

* Fix spelling mistake

* Update link to custom tabs documentation

* Fix typo in README.md (openid#455)

* Fix `Using access tokens` snippet in the readme (openid#510)

The snippet code in the `Using access tokens` section didn't follow java code formatting.

* Use capitalized form for "Bearer" token type

While this is case-insensitive, some provider implementations do not correctly handle the lower case form.

* Migrate to AndroidX & Update dependencies (openid#508)

* gradle update to 5.4.1

* gradle plugin update to 3.5.3

* minor bintray update

* bump compile sdk to 29

- this requires bumping build tools to 29
- also updating the gradlewrapper (again, fully) to 5.4.1

* Migrate to AndroidX

This required changes to checkstyle & javadocs gradle files
(perhaps because of jetifier? not sure tbh)
Also mockito now can mock all final classes

* Fix compiler warning

* update travis build tools to 29.0.2 to align with build.gradle

* update travis android sdk version to 29 to align with build.gradle

* Android11 support (openid#558)

- Migrated from the deprecated Android Support libraries to the newest versions of the AndroidX libraries.
- The Android gradle plugin is updated to the current 4.0.0.
- Glide is updated to the current 4.11.0, and 4.1x.x is needed for AndroidX support.
- limit the allowed queries to only fullbrowsers - openid#554 .
- Add support for CATEGORY_APP_BROWSER.
- Update dependencies

* Deprecate whitelist and blacklist (openid#555)

* Replace BrowserBlacklist with BrowserDenyList and BrowserWhitelist with BrowserAllowList

* Add xmlpull library dependency for tests because some of the unit tests fail without it.

* Override constructors and add a deprecation migration test

* Update library version to 0.8.0-skyscanner

* Fix build after upgrading gradle plugin (as result of syncing up with openid repo)

Co-authored-by: Iain McGinniss <iainmcgin@gmail.com>
Co-authored-by: Iain McGinniss <iain.mcginniss@wework.com>
Co-authored-by: Henning Lund <40355805+hnljp@users.noreply.github.com>
Co-authored-by: Øyvind Robertsen <oyvindrobertsen@gmail.com>
Co-authored-by: Rahul Ravikumar <tikurahul@users.noreply.github.com>
Co-authored-by: Thomas Rebouillon <thomas.rebouillon@gmail.com>
Co-authored-by: Mark Kowalski <mark.kowalski86@googlemail.com>
Co-authored-by: Ahmad El-Melegy <ahmad.melegy@gmail.com>
Co-authored-by: Paul Blundell <blundell.app.dev@gmail.com>
Co-authored-by: Jon F Hancock <jonfhancock@gmail.com>
Co-authored-by: Athila Santos <athilahs>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default browser should be chosen, if compatible

5 participants