forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AW: fetch flag overrides via ContentProvider
This CL completes the basic implementation of the flags UI. During startup, the embedded WebView implementation will check if the user has enabled developer mode, and if so, fetch the flag overrides from the service. This uses a ContentProvider instead of an aidl method on the service interface for the sake of a simple synchronous IPC. Although aidl itself supports synchronous IPC, the Android framework only supports binding to the service asynchronously. We require fully synchronous IPC so we can block startup while we fetch the flags. Now that we've settled on using a ContentProvider to plumb information from the developer UI to embedded WebViews, this changes "developer mode" to be defined by the ContentProvider's state rather than the Service's state, which has the side benefit of simplifying some of the Activity/Service code. We rely on PackageManager APIs to check if developer mode is enabled. The check itself should have very little impact to startup time, since PackageManager caches its state in RAM. I benchmarked this check (when developer mode is disabled) at 0ms on my Google Pixel 2 device. For simplicity, we do not care about performance when developer mode is enabled, as this is not the usual user experience. Bug: 981143 Test: Manual - toggle debug border flag, start WebView shell, see borders Test: Benchmark isDeveloperModeEnabled() with System.currentTimeMillis() Test: run_android_webview_junit_tests -f *ServiceNamesTest* Change-Id: I7cc67d1bdf8f0f2ce0fce714fb359160899354a7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1977828 Commit-Queue: Nate Fischer <ntfschr@chromium.org> Reviewed-by: Richard Coles <torne@chromium.org> Cr-Commit-Position: refs/heads/master@{#726993}
- Loading branch information
1 parent
606e604
commit 34df84d
Showing
12 changed files
with
202 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
android_webview/java/src/org/chromium/android_webview/common/FlagOverrideConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.android_webview.common; | ||
|
||
/** | ||
* Constants to facilitate communication with {@code FlagOverrideContentProvider}. | ||
*/ | ||
public final class FlagOverrideConstants { | ||
// Do not instantiate this class. | ||
private FlagOverrideConstants() {} | ||
|
||
public static final String URI_AUTHORITY_SUFFIX = ".FlagOverrideContentProvider"; | ||
public static final String URI_PATH = "/flag-overrides"; | ||
public static final String FLAG_NAME_COLUMN = "flagName"; | ||
public static final String FLAG_STATE_COLUMN = "flagState"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...nembedded/java/src/org/chromium/android_webview/services/FlagOverrideContentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
package org.chromium.android_webview.services; | ||
|
||
import android.content.ComponentName; | ||
import android.content.ContentProvider; | ||
import android.content.ContentValues; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.database.Cursor; | ||
import android.database.MatrixCursor; | ||
import android.net.Uri; | ||
|
||
import org.chromium.android_webview.common.FlagOverrideConstants; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* A {@link ContentProvider} to fetch the flag overrides, via the {@code query()} method. No special | ||
* permissions are required to access this ContentProvider, and it can be accessed by any context | ||
* (including the embedded WebView implementation). | ||
*/ | ||
public final class FlagOverrideContentProvider extends ContentProvider { | ||
@Override | ||
public boolean onCreate() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public int delete(Uri uri, String selection, String[] selectionArgs) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Uri insert(Uri uri, ContentValues values) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, | ||
String sortOrder) { | ||
if (FlagOverrideConstants.URI_PATH.equals(uri.getPath())) { | ||
Map<String, Boolean> flagOverrides = DeveloperUiService.getFlagOverrides(); | ||
final String[] columns = {FlagOverrideConstants.FLAG_NAME_COLUMN, | ||
FlagOverrideConstants.FLAG_STATE_COLUMN}; | ||
MatrixCursor cursor = new MatrixCursor(columns, flagOverrides.size()); | ||
for (Map.Entry<String, Boolean> entry : flagOverrides.entrySet()) { | ||
String flagName = entry.getKey(); | ||
boolean enabled = entry.getValue(); | ||
cursor.addRow(new Object[] {flagName, enabled ? 1 : 0}); | ||
} | ||
if (flagOverrides.isEmpty()) { | ||
disableDeveloperMode(); | ||
} | ||
return cursor; | ||
} | ||
return null; | ||
} | ||
|
||
private void disableDeveloperMode() { | ||
ComponentName flagOverrideContentProvider = | ||
new ComponentName(getContext(), FlagOverrideContentProvider.class.getName()); | ||
getContext().getPackageManager().setComponentEnabledSetting(flagOverrideContentProvider, | ||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); | ||
|
||
// Stop the service explicitly, in case it's running. NOOP if the service is not running. | ||
getContext().stopService(new Intent(getContext(), DeveloperUiService.class)); | ||
} | ||
|
||
@Override | ||
public String getType(Uri uri) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
Oops, something went wrong.