Block the user from enabling or disabling webview fallback packages.
Now that we support webview fallback packages - packages that should be enabled if and only if no other webview packages are available - we need to ensure that the Settings UI consistently shows that these packages cannot be enabled or disabled (e.g. the 'Enable' and 'Disable' buttons for enabling/disabling them are greyed out). Also, remove the Dialog that lets a user enable a disabled webview package from the webview implementation Dev Setting. Instead show a Toast if the user has chosen an invalid package. Bug: 26375524, 26375860 Change-Id: I949083d3f7c83cd2e049dd2c5c15ec5ab880fe07
This commit is contained in:
@@ -821,13 +821,15 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
mBtHciSnoopLog.isChecked() ? 1 : 0);
|
mBtHciSnoopLog.isChecked() ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeWebViewProviderOptions(Object newValue) {
|
private boolean writeWebViewProviderOptions(Object newValue) {
|
||||||
try {
|
try {
|
||||||
mWebViewUpdateService.changeProviderAndSetting(
|
String updatedProvider = mWebViewUpdateService.changeProviderAndSetting(
|
||||||
newValue == null ? "" : newValue.toString());
|
newValue == null ? "" : newValue.toString());
|
||||||
updateWebViewProviderOptions();
|
updateWebViewProviderOptions();
|
||||||
|
return newValue != null && newValue.equals(updatedProvider);
|
||||||
} catch(RemoteException e) {
|
} catch(RemoteException e) {
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDebuggerOptions() {
|
private void writeDebuggerOptions() {
|
||||||
@@ -1933,18 +1935,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableAndSetWebViewPackage(String packageName) {
|
|
||||||
getActivity().getPackageManager().setApplicationEnabledSetting(packageName,
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
|
|
||||||
mWebViewProvider.setValue(packageName);
|
|
||||||
writeWebViewProviderOptions(packageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showEnableWebViewProviderAlert(final String packageName) {
|
|
||||||
EnableWebViewProviderDialogFragment.newInstance(packageName).show(
|
|
||||||
getChildFragmentManager(), EnableWebViewProviderDialogFragment.TAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
|
if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
|
||||||
@@ -1957,19 +1947,15 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
Log.e(TAG, "Tried to set a null WebView provider");
|
Log.e(TAG, "Tried to set a null WebView provider");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String newWebViewPackageName = (String) newValue;
|
if (writeWebViewProviderOptions(newValue)) {
|
||||||
if (isPackageEnabled(newWebViewPackageName)) {
|
|
||||||
writeWebViewProviderOptions(newValue);
|
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
// The user chose a package that became invalid since the list was last updated,
|
||||||
|
// show a Toast to explain the situation.
|
||||||
|
Toast toast = Toast.makeText(getActivity(),
|
||||||
|
R.string.select_webview_provider_toast_text, Toast.LENGTH_SHORT);
|
||||||
|
toast.show();
|
||||||
}
|
}
|
||||||
// Package is disabled or uninstalled, if it is simply disabled, check if the user wants
|
|
||||||
// to enable it
|
|
||||||
if (isPackageInstalled(getActivity(), newWebViewPackageName)) {
|
|
||||||
showEnableWebViewProviderAlert(newWebViewPackageName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Package has been uninstalled (could happen if the package was uninstalled between
|
|
||||||
// opening and closing the setting).
|
|
||||||
return false;
|
return false;
|
||||||
} else if (preference == mLogdSize) {
|
} else if (preference == mLogdSize) {
|
||||||
writeLogdSizeOption(newValue);
|
writeLogdSizeOption(newValue);
|
||||||
@@ -2128,36 +2114,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EnableWebViewProviderDialogFragment extends DialogFragment {
|
|
||||||
public static final String TAG = "EnableWebViewProviderDialogFragment";
|
|
||||||
private static final String PACKAGE_NAME_TAG = "packageName";
|
|
||||||
|
|
||||||
public static EnableWebViewProviderDialogFragment newInstance(String packageName) {
|
|
||||||
EnableWebViewProviderDialogFragment fragment
|
|
||||||
= new EnableWebViewProviderDialogFragment();
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putString(PACKAGE_NAME_TAG, packageName);
|
|
||||||
fragment.setArguments(args);
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
final String packageName = getArguments().getString(PACKAGE_NAME_TAG);
|
|
||||||
|
|
||||||
return new AlertDialog.Builder(getActivity())
|
|
||||||
.setMessage(R.string.select_webview_provider_confirmation_text)
|
|
||||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
((DevelopmentSettings)getParentFragment()).enableAndSetWebViewPackage(
|
|
||||||
packageName);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For Search.
|
* For Search.
|
||||||
|
@@ -61,6 +61,7 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.webkit.IWebViewUpdateService;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -254,6 +255,16 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
IWebViewUpdateService webviewUpdateService =
|
||||||
|
IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
|
||||||
|
if (webviewUpdateService.isFallbackPackage(mAppEntry.info.packageName)) {
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
mUninstallButton.setEnabled(enabled);
|
mUninstallButton.setEnabled(enabled);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
// Register listener
|
// Register listener
|
||||||
|
@@ -30,6 +30,7 @@ import android.os.Bundle;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.webkit.IWebViewUpdateService;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
@@ -46,6 +47,7 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
|
|||||||
private final PackageManager mPm;
|
private final PackageManager mPm;
|
||||||
private final IPackageManager mIPm;
|
private final IPackageManager mIPm;
|
||||||
private final INotificationManager mNm;
|
private final INotificationManager mNm;
|
||||||
|
private final IWebViewUpdateService mWvus;
|
||||||
private final NetworkPolicyManager mNpm;
|
private final NetworkPolicyManager mNpm;
|
||||||
private final AppOpsManager mAom;
|
private final AppOpsManager mAom;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@@ -58,6 +60,7 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
|
|||||||
mIPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
|
mIPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
|
||||||
mNm = INotificationManager.Stub.asInterface(
|
mNm = INotificationManager.Stub.asInterface(
|
||||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||||
|
mWvus = IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
|
||||||
mNpm = NetworkPolicyManager.from(context);
|
mNpm = NetworkPolicyManager.from(context);
|
||||||
mAom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
mAom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||||
}
|
}
|
||||||
@@ -118,7 +121,8 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
|
|||||||
}
|
}
|
||||||
if (!app.enabled) {
|
if (!app.enabled) {
|
||||||
if (mPm.getApplicationEnabledSetting(app.packageName)
|
if (mPm.getApplicationEnabledSetting(app.packageName)
|
||||||
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
|
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
|
||||||
|
&& !isNonEnableableFallback(app.packageName)) {
|
||||||
mPm.setApplicationEnabledSetting(app.packageName,
|
mPm.setApplicationEnabledSetting(app.packageName,
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
|
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
|
||||||
PackageManager.DONT_KILL_APP);
|
PackageManager.DONT_KILL_APP);
|
||||||
@@ -142,4 +146,12 @@ public class ResetAppsHelper implements DialogInterface.OnClickListener,
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isNonEnableableFallback(String packageName) {
|
||||||
|
try {
|
||||||
|
return mWvus.isFallbackPackage(packageName);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user