| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.webkit; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.app.ActivityThread; |
| 23 |
import android.app.Application; |
| 24 |
import android.app.ResourcesManager; |
| 25 |
import android.compat.annotation.UnsupportedAppUsage; |
| 26 |
import android.content.Context; |
| 27 |
import android.content.pm.ApplicationInfo; |
| 28 |
import android.content.res.Resources; |
| 29 |
import android.graphics.Canvas; |
| 30 |
import android.graphics.RecordingCanvas; |
| 31 |
import android.os.RemoteException; |
| 32 |
import android.os.SystemProperties; |
| 33 |
import android.os.Trace; |
| 34 |
import android.util.SparseArray; |
| 35 |
import android.view.View; |
| 36 |
import android.view.ViewRootImpl; |
| 37 |
|
| 38 |
import com.android.internal.util.ArrayUtils; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
@SystemApi |
| 47 |
public final class WebViewDelegate { |
| 48 |
|
| 49 |
@UnsupportedAppUsage |
| 50 |
WebViewDelegate() { } |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public interface OnTraceEnabledChangeListener { |
| 56 |
void onTraceEnabledChange(boolean enabled); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public void setOnTraceEnabledChangeListener(final OnTraceEnabledChangeListener listener) { |
| 64 |
SystemProperties.addChangeCallback(new Runnable() { |
| 65 |
@Override |
| 66 |
public void run() { |
| 67 |
listener.onTraceEnabledChange(isTraceTagEnabled()); |
| 68 |
} |
| 69 |
}); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public boolean isTraceTagEnabled() { |
| 76 |
return Trace.isTagEnabled(Trace.TRACE_TAG_WEBVIEW); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
@Deprecated |
| 84 |
public boolean canInvokeDrawGlFunctor(View containerView) { |
| 85 |
throw new UnsupportedOperationException(); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
@Deprecated |
| 93 |
public void invokeDrawGlFunctor(View containerView, long nativeDrawGLFunctor, |
| 94 |
boolean waitForCompletion) { |
| 95 |
throw new UnsupportedOperationException(); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
@Deprecated |
| 103 |
public void callDrawGlFunction(Canvas canvas, long nativeDrawGLFunctor) { |
| 104 |
throw new UnsupportedOperationException(); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
@Deprecated |
| 112 |
public void callDrawGlFunction(@NonNull Canvas canvas, long nativeDrawGLFunctor, |
| 113 |
@Nullable Runnable releasedRunnable) { |
| 114 |
throw new UnsupportedOperationException(); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public void drawWebViewFunctor(@NonNull Canvas canvas, int functor) { |
| 123 |
if (!(canvas instanceof RecordingCanvas)) { |
| 124 |
|
| 125 |
throw new IllegalArgumentException(canvas.getClass().getName() |
| 126 |
+ " is not a RecordingCanvas canvas"); |
| 127 |
} |
| 128 |
((RecordingCanvas) canvas).drawWebViewFunctor(functor); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
@Deprecated |
| 139 |
public void detachDrawGlFunctor(View containerView, long nativeDrawGLFunctor) { |
| 140 |
ViewRootImpl viewRootImpl = containerView.getViewRootImpl(); |
| 141 |
if (nativeDrawGLFunctor != 0 && viewRootImpl != null) { |
| 142 |
viewRootImpl.detachFunctor(nativeDrawGLFunctor); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public int getPackageId(Resources resources, String packageName) { |
| 150 |
SparseArray<String> packageIdentifiers = |
| 151 |
resources.getAssets().getAssignedPackageIdentifiers(); |
| 152 |
for (int i = 0; i < packageIdentifiers.size(); i++) { |
| 153 |
final String name = packageIdentifiers.valueAt(i); |
| 154 |
|
| 155 |
if (packageName.equals(name)) { |
| 156 |
return packageIdentifiers.keyAt(i); |
| 157 |
} |
| 158 |
} |
| 159 |
throw new RuntimeException("Package not found: " + packageName); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public Application getApplication() { |
| 166 |
return ActivityThread.currentApplication(); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
public String getErrorString(Context context, int errorCode) { |
| 173 |
return LegacyErrorStrings.getString(errorCode, context); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
public void addWebViewAssetPath(Context context) { |
| 180 |
final String[] newAssetPaths = |
| 181 |
WebViewFactory.getLoadedPackageInfo().applicationInfo.getAllApkPaths(); |
| 182 |
final ApplicationInfo appInfo = context.getApplicationInfo(); |
| 183 |
|
| 184 |
|
| 185 |
String[] newLibAssets = appInfo.sharedLibraryFiles; |
| 186 |
for (String newAssetPath : newAssetPaths) { |
| 187 |
newLibAssets = ArrayUtils.appendElement(String.class, newLibAssets, newAssetPath); |
| 188 |
} |
| 189 |
|
| 190 |
if (newLibAssets != appInfo.sharedLibraryFiles) { |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
appInfo.sharedLibraryFiles = newLibAssets; |
| 197 |
|
| 198 |
|
| 199 |
ResourcesManager.getInstance().appendLibAssetsForMainAssetPath( |
| 200 |
appInfo.getBaseResourcePath(), newAssetPaths); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
public boolean isMultiProcessEnabled() { |
| 208 |
try { |
| 209 |
return WebViewFactory.getUpdateService().isMultiProcessEnabled(); |
| 210 |
} catch (RemoteException e) { |
| 211 |
throw e.rethrowFromSystemServer(); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
public String getDataDirectorySuffix() { |
| 219 |
return WebViewFactory.getDataDirectorySuffix(); |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
@NonNull |
| 228 |
public WebViewFactory.StartupTimestamps getStartupTimestamps() { |
| 229 |
return WebViewFactory.getStartupTimestamps(); |
| 230 |
} |
| 231 |
} |