Commit 6b1ce2d3 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

Expose app version when calling getInstalledRelatedApps

Bug: 1013568
Change-Id: I9d5cdcf2175cbdadeda5ac718ae0a9cf137c936b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1831870
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705078}
parent db32ed3b
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.installedapp; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.installedapp;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources; import android.content.res.Resources;
...@@ -160,11 +161,28 @@ public class InstalledAppProviderImpl implements InstalledAppProvider { ...@@ -160,11 +161,28 @@ public class InstalledAppProviderImpl implements InstalledAppProvider {
} }
} }
for (RelatedApplication installedApp : installedApps) {
setVersionInfo(installedApp);
}
RelatedApplication[] installedAppsArray = new RelatedApplication[installedApps.size()]; RelatedApplication[] installedAppsArray = new RelatedApplication[installedApps.size()];
installedApps.toArray(installedAppsArray); installedApps.toArray(installedAppsArray);
return Pair.create(installedAppsArray, delayMillis); return Pair.create(installedAppsArray, delayMillis);
} }
/**
* Sets the version information, if available, to |installedApp|.
* @param installedApp
*/
private void setVersionInfo(RelatedApplication installedApp) {
assert installedApp.id != null;
try {
PackageInfo info = mContext.getPackageManager().getPackageInfo(installedApp.id, 0);
installedApp.version = info.versionName;
} catch (NameNotFoundException e) {
}
}
/** /**
* Returns whether or not the app ID is for an instant app/instant app holdback. * Returns whether or not the app ID is for an instant app/instant app holdback.
*/ */
......
...@@ -11,6 +11,7 @@ import "third_party/blink/public/mojom/installedapp/related_application.mojom"; ...@@ -11,6 +11,7 @@ import "third_party/blink/public/mojom/installedapp/related_application.mojom";
interface InstalledAppProvider { interface InstalledAppProvider {
// Filters |related_apps|, keeping only those which are both installed on the // Filters |related_apps|, keeping only those which are both installed on the
// user's system, and related to the web origin of the requesting page. // user's system, and related to the web origin of the requesting page.
// Also appends the app version to the filtered apps.
FilterInstalledApps(array<RelatedApplication> related_apps) FilterInstalledApps(array<RelatedApplication> related_apps)
=> (array<RelatedApplication> installedApps); => (array<RelatedApplication> installedApps);
}; };
...@@ -13,4 +13,5 @@ struct RelatedApplication { ...@@ -13,4 +13,5 @@ struct RelatedApplication {
// WebRelatedApplication as well). // WebRelatedApplication as well).
string? url; string? url;
string? id; string? id;
string? version;
}; };
...@@ -100,6 +100,7 @@ void InstalledAppController::OnFilterInstalledApps( ...@@ -100,6 +100,7 @@ void InstalledAppController::OnFilterInstalledApps(
app->setPlatform(res->platform); app->setPlatform(res->platform);
app->setURL(res->url); app->setURL(res->url);
app->setId(res->id); app->setId(res->id);
app->setVersion(res->version);
applications.push_back(app); applications.push_back(app);
} }
callbacks->OnSuccess(applications); callbacks->OnSuccess(applications);
......
...@@ -9,4 +9,5 @@ dictionary RelatedApplication { ...@@ -9,4 +9,5 @@ dictionary RelatedApplication {
required USVString platform; required USVString platform;
USVString url; USVString url;
DOMString id; DOMString id;
DOMString version;
}; };
...@@ -12,8 +12,8 @@ installedapp_test((t, mock) => { ...@@ -12,8 +12,8 @@ installedapp_test((t, mock) => {
// list of related_applications from this page's manifest. The mock service // list of related_applications from this page's manifest. The mock service
// returns the empty list, implying that none are installed. // returns the empty list, implying that none are installed.
mock.pushExpectedCall( mock.pushExpectedCall(
[{platform: 'play', url: null, id: 'com.test'}, [{platform: 'play', url: null, id: 'com.test', version: null},
{platform: 'itunes', url: 'https://itunes.apple.com/', id: null}], {platform: 'itunes', url: 'https://itunes.apple.com/', id: null, version: null}],
[]); []);
return navigator.getInstalledRelatedApps().then(result => { return navigator.getInstalledRelatedApps().then(result => {
assert_array_relatedapplication_equals(result, []); assert_array_relatedapplication_equals(result, []);
...@@ -44,13 +44,13 @@ installedapp_test((t, mock) => { ...@@ -44,13 +44,13 @@ installedapp_test((t, mock) => {
mock.pushExpectedCall( mock.pushExpectedCall(
[{platform: 'play', url: null, id: 'com.test'}, [{platform: 'play', url: null, id: 'com.test'},
{platform: 'itunes', url: 'https://itunes.apple.com/', id: null}], {platform: 'itunes', url: 'https://itunes.apple.com/', id: null}],
[{platform: 'play', url: null, id: 'com.test'}, [{platform: 'play', url: null, id: 'com.test', version: '1.4.2'},
{platform: 'itunes', url: 'https://itunes.apple.com/', id: null}]); {platform: 'itunes', url: 'https://itunes.apple.com/', id: null, version: null}]);
return navigator.getInstalledRelatedApps().then(result => { return navigator.getInstalledRelatedApps().then(result => {
assert_array_relatedapplication_equals( assert_array_relatedapplication_equals(
result, result,
[{platform: 'play', id: 'com.test'}, [{platform: 'play', id: 'com.test', version: '1.4.2'},
{platform: 'itunes', url: 'https://itunes.apple.com/'}]); {platform: 'itunes', url: 'https://itunes.apple.com/'}]);
}); });
}, 'getInstalledRelatedApps with multiple related and installed apps'); }, 'getInstalledRelatedApps with multiple related and installed apps');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment