Block the disable option for WebView Default package

Test: atest ApplicationFeatureProviderImplTest

Bug: 308907090

Change-Id: I21785975b965b04895849d2df71fa2f2b4cb4b2d
This commit is contained in:
Ziad Youssef
2023-12-12 14:57:26 +00:00
parent 11df0d4c17
commit e41e5444e9
4 changed files with 73 additions and 1 deletions

View File

@@ -22,11 +22,14 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.util.Log;
import android.webkit.IWebViewUpdateService;
import android.webkit.UserPackage;
import android.webkit.WebViewFactory;
import android.webkit.WebViewProviderInfo;
import android.widget.Toast;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -104,5 +107,24 @@ public class WebViewUpdateServiceWrapper {
toast.show();
}
/**
* Fetch the package name of the default WebView provider.
*/
@Nullable
public String getDefaultWebViewPackageName() {
try {
IWebViewUpdateService service = WebViewFactory.getUpdateService();
if (service != null) {
WebViewProviderInfo provider = service.getDefaultWebViewPackage();
if (provider != null) {
return provider.packageName;
}
}
} catch (RemoteException e) {
Log.e(TAG, "RemoteException when trying to fetch default WebView package Name", e);
}
return null;
}
static final int PACKAGE_FLAGS = PackageManager.MATCH_ANY_USER;
}