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; 20 import android.compat.annotation.UnsupportedAppUsage; 21 import android.os.RemoteException; 22 23 /** 24 * @hide 25 */ 26 @SystemApi 27 public final class WebViewUpdateService { 28 29 @UnsupportedAppUsage WebViewUpdateService()30 private WebViewUpdateService () {} 31 32 /** 33 * Fetch all packages that could potentially implement WebView. 34 */ getAllWebViewPackages()35 public static WebViewProviderInfo[] getAllWebViewPackages() { 36 if (Flags.updateServiceIpcWrapper()) { 37 WebViewUpdateManager manager = WebViewUpdateManager.getInstance(); 38 if (manager == null) { 39 return new WebViewProviderInfo[0]; 40 } 41 return manager.getAllWebViewPackages(); 42 } else { 43 IWebViewUpdateService service = getUpdateService(); 44 if (service == null) { 45 return new WebViewProviderInfo[0]; 46 } 47 try { 48 return service.getAllWebViewPackages(); 49 } catch (RemoteException e) { 50 throw e.rethrowFromSystemServer(); 51 } 52 } 53 } 54 55 /** 56 * Fetch all packages that could potentially implement WebView and are currently valid. 57 */ getValidWebViewPackages()58 public static WebViewProviderInfo[] getValidWebViewPackages() { 59 if (Flags.updateServiceIpcWrapper()) { 60 WebViewUpdateManager manager = WebViewUpdateManager.getInstance(); 61 if (manager == null) { 62 return new WebViewProviderInfo[0]; 63 } 64 return manager.getValidWebViewPackages(); 65 } else { 66 IWebViewUpdateService service = getUpdateService(); 67 if (service == null) { 68 return new WebViewProviderInfo[0]; 69 } 70 try { 71 return service.getValidWebViewPackages(); 72 } catch (RemoteException e) { 73 throw e.rethrowFromSystemServer(); 74 } 75 } 76 } 77 78 /** 79 * Used by DevelopmentSetting to get the name of the WebView provider currently in use. 80 */ getCurrentWebViewPackageName()81 public static String getCurrentWebViewPackageName() { 82 if (Flags.updateServiceIpcWrapper()) { 83 WebViewUpdateManager manager = WebViewUpdateManager.getInstance(); 84 if (manager == null) { 85 return null; 86 } 87 return manager.getCurrentWebViewPackageName(); 88 } else { 89 IWebViewUpdateService service = getUpdateService(); 90 if (service == null) { 91 return null; 92 } 93 try { 94 return service.getCurrentWebViewPackageName(); 95 } catch (RemoteException e) { 96 throw e.rethrowFromSystemServer(); 97 } 98 } 99 } 100 getUpdateService()101 private static IWebViewUpdateService getUpdateService() { 102 return WebViewFactory.getUpdateService(); 103 } 104 } 105