Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.webkit; |
| 18 | |
| 19 | import android.annotation.SystemApi; |
Mathew Inwood | 42afea2 | 2018-08-16 19:18:28 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 21 | import android.os.RemoteException; |
| 22 | |
| 23 | /** |
| 24 | * @hide |
| 25 | */ |
| 26 | @SystemApi |
| 27 | public final class WebViewUpdateService { |
| 28 | |
Mathew Inwood | 42afea2 | 2018-08-16 19:18:28 +0100 | [diff] [blame] | 29 | @UnsupportedAppUsage |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 30 | private WebViewUpdateService () {} |
| 31 | |
| 32 | /** |
| 33 | * Fetch all packages that could potentially implement WebView. |
| 34 | */ |
| 35 | public static WebViewProviderInfo[] getAllWebViewPackages() { |
Torne (Richard Coles) | ff937ac | 2017-10-02 17:09:32 -0400 | [diff] [blame] | 36 | IWebViewUpdateService service = getUpdateService(); |
| 37 | if (service == null) { |
| 38 | return new WebViewProviderInfo[0]; |
| 39 | } |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 40 | try { |
Torne (Richard Coles) | ff937ac | 2017-10-02 17:09:32 -0400 | [diff] [blame] | 41 | return service.getAllWebViewPackages(); |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 42 | } catch (RemoteException e) { |
Gustav Sennton | 17757f8 | 2016-05-04 15:25:46 +0100 | [diff] [blame] | 43 | throw e.rethrowFromSystemServer(); |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Fetch all packages that could potentially implement WebView and are currently valid. |
| 49 | */ |
| 50 | public static WebViewProviderInfo[] getValidWebViewPackages() { |
Torne (Richard Coles) | ff937ac | 2017-10-02 17:09:32 -0400 | [diff] [blame] | 51 | IWebViewUpdateService service = getUpdateService(); |
| 52 | if (service == null) { |
| 53 | return new WebViewProviderInfo[0]; |
| 54 | } |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 55 | try { |
Torne (Richard Coles) | ff937ac | 2017-10-02 17:09:32 -0400 | [diff] [blame] | 56 | return service.getValidWebViewPackages(); |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 57 | } catch (RemoteException e) { |
Gustav Sennton | 17757f8 | 2016-05-04 15:25:46 +0100 | [diff] [blame] | 58 | throw e.rethrowFromSystemServer(); |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Used by DevelopmentSetting to get the name of the WebView provider currently in use. |
| 64 | */ |
| 65 | public static String getCurrentWebViewPackageName() { |
Torne (Richard Coles) | ff937ac | 2017-10-02 17:09:32 -0400 | [diff] [blame] | 66 | IWebViewUpdateService service = getUpdateService(); |
| 67 | if (service == null) { |
| 68 | return null; |
| 69 | } |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 70 | try { |
Torne (Richard Coles) | ff937ac | 2017-10-02 17:09:32 -0400 | [diff] [blame] | 71 | return service.getCurrentWebViewPackageName(); |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 72 | } catch (RemoteException e) { |
Gustav Sennton | 17757f8 | 2016-05-04 15:25:46 +0100 | [diff] [blame] | 73 | throw e.rethrowFromSystemServer(); |
Gustav Sennton | 1c177d8 | 2016-03-29 20:43:11 +0100 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | private static IWebViewUpdateService getUpdateService() { |
| 78 | return WebViewFactory.getUpdateService(); |
| 79 | } |
| 80 | } |