| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
| 6 | 6 |
| 7 import android.content.pm.ApplicationInfo; | 7 import android.content.pm.ApplicationInfo; |
| 8 import android.content.pm.PackageManager; | 8 import android.content.pm.PackageManager; |
| 9 import android.content.res.Resources; | 9 import android.content.res.Resources; |
| 10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 /** | 23 /** |
| 24 * Contains methods for extracting meta data from WebAPK. | 24 * Contains methods for extracting meta data from WebAPK. |
| 25 */ | 25 */ |
| 26 public class WebApkMetaDataUtils { | 26 public class WebApkMetaDataUtils { |
| 27 /** | 27 /** |
| 28 * Populates {@link WebappInfo} with meta data extracted from WebAPK's Andro
id Manifest. | 28 * Populates {@link WebappInfo} with meta data extracted from WebAPK's Andro
id Manifest. |
| 29 * @param webApkPackageName Package name of the WebAPK to extract meta data
from. | 29 * @param webApkPackageName Package name of the WebAPK to extract meta data
from. |
| 30 * @param url WebAPK start URL. | 30 * @param url WebAPK start URL. |
| 31 * @param source {@link ShortcutSource} that the WebAPK was opened from. | 31 * @param source {@link ShortcutSource} that the WebAPK was opened from. |
| 32 */ | 32 */ |
| 33 public static WebappInfo extractWebappInfoFromWebApk( | 33 public static WebApkInfo extractWebappInfoFromWebApk( |
| 34 String webApkPackageName, String url, int source) { | 34 String webApkPackageName, String url, int source) { |
| 35 WebApkMetaData metaData = extractMetaDataFromWebApk(webApkPackageName); | 35 WebApkMetaData metaData = extractMetaDataFromWebApk(webApkPackageName); |
| 36 if (metaData == null) return null; | 36 if (metaData == null) return null; |
| 37 | 37 |
| 38 PackageManager packageManager = ContextUtils.getApplicationContext().get
PackageManager(); | 38 PackageManager packageManager = ContextUtils.getApplicationContext().get
PackageManager(); |
| 39 Resources resources; | 39 Resources resources; |
| 40 try { | 40 try { |
| 41 resources = packageManager.getResourcesForApplication(webApkPackageN
ame); | 41 resources = packageManager.getResourcesForApplication(webApkPackageN
ame); |
| 42 } catch (PackageManager.NameNotFoundException e) { | 42 } catch (PackageManager.NameNotFoundException e) { |
| 43 return null; | 43 return null; |
| 44 } | 44 } |
| 45 Bitmap icon = BitmapFactory.decodeResource(resources, metaData.iconId); | 45 Bitmap icon = BitmapFactory.decodeResource(resources, metaData.iconId); |
| 46 String encodedIcon = ShortcutHelper.encodeBitmapAsString(icon); | 46 String encodedIcon = ShortcutHelper.encodeBitmapAsString(icon); |
| 47 | 47 |
| 48 return WebappInfo.create(WebApkConstants.WEBAPK_ID_PREFIX + webApkPackag
eName, url, | 48 return WebApkInfo.create(WebApkConstants.WEBAPK_ID_PREFIX + webApkPackag
eName, url, |
| 49 metaData.scope, encodedIcon, metaData.name, metaData.shortName, | 49 metaData.scope, encodedIcon, metaData.name, metaData.shortName, |
| 50 metaData.displayMode, metaData.orientation, source, metaData.the
meColor, | 50 metaData.displayMode, metaData.orientation, source, metaData.the
meColor, |
| 51 metaData.backgroundColor, TextUtils.isEmpty(metaData.iconUrl), w
ebApkPackageName); | 51 metaData.backgroundColor, TextUtils.isEmpty(metaData.iconUrl), w
ebApkPackageName); |
| 52 } | 52 } |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * Populates {@link WebApkMetaData} with meta data extracted from WebAPK's A
ndroid Manifest. | 55 * Populates {@link WebApkMetaData} with meta data extracted from WebAPK's A
ndroid Manifest. |
| 56 * @param webApkPackageName Package name of the WebAPK to extract meta data
from. | 56 * @param webApkPackageName Package name of the WebAPK to extract meta data
from. |
| 57 */ | 57 */ |
| 58 public static WebApkMetaData extractMetaDataFromWebApk(String webApkPackageN
ame) { | 58 public static WebApkMetaData extractMetaDataFromWebApk(String webApkPackageN
ame) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 return ScreenOrientationValues.PORTRAIT; | 183 return ScreenOrientationValues.PORTRAIT; |
| 184 } else if (orientation.equals("portrait-primary")) { | 184 } else if (orientation.equals("portrait-primary")) { |
| 185 return ScreenOrientationValues.PORTRAIT_PRIMARY; | 185 return ScreenOrientationValues.PORTRAIT_PRIMARY; |
| 186 } else if (orientation.equals("portrait-secondary")) { | 186 } else if (orientation.equals("portrait-secondary")) { |
| 187 return ScreenOrientationValues.PORTRAIT_SECONDARY; | 187 return ScreenOrientationValues.PORTRAIT_SECONDARY; |
| 188 } else { | 188 } else { |
| 189 return ScreenOrientationValues.DEFAULT; | 189 return ScreenOrientationValues.DEFAULT; |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 } | 192 } |
| OLD | NEW |