use of android.app.Application in project robospice by stephanenicolas.
the class LruCacheObjectPersisterTest method setUp.
@Override
public void setUp() throws CacheCreationException {
testPersister = new LruCacheStringObjectPersister(TEST_LRU_CACHE_SIZE);
Application application = (Application) getContext().getApplicationContext();
testPersisterWithFallback = new LruCacheStringObjectPersister(new InFileStringObjectPersister(application), TEST_LRU_CACHE_SIZE);
}
use of android.app.Application in project AndroidChromium by JackyAndroid.
the class Tab method swapContentViewCore.
/**
* Called to swap out the current view with the one passed in.
*
* @param newContentViewCore The content view that should be swapped into the tab.
* @param deleteOldNativeWebContents Whether to delete the native web
* contents of old view.
* @param didStartLoad Whether
* WebContentsObserver::DidStartProvisionalLoadForFrame() has
* already been called.
* @param didFinishLoad Whether WebContentsObserver::DidFinishLoad() has
* already been called.
*/
public void swapContentViewCore(ContentViewCore newContentViewCore, boolean deleteOldNativeWebContents, boolean didStartLoad, boolean didFinishLoad) {
int originalWidth = 0;
int originalHeight = 0;
if (mContentViewCore != null) {
originalWidth = mContentViewCore.getViewportWidthPix();
originalHeight = mContentViewCore.getViewportHeightPix();
mContentViewCore.onHide();
}
Rect bounds = new Rect();
if (originalWidth == 0 && originalHeight == 0) {
bounds = ExternalPrerenderHandler.estimateContentSize((Application) getApplicationContext(), false);
originalWidth = bounds.right - bounds.left;
originalHeight = bounds.bottom - bounds.top;
}
destroyContentViewCore(deleteOldNativeWebContents);
NativePage previousNativePage = mNativePage;
mNativePage = null;
// Size of the new ContentViewCore is zero at this point. If we don't call onSizeChanged(),
// next onShow() call would send a resize message with the current ContentViewCore size
// (zero) to the renderer process, although the new size will be set soon.
// However, this size fluttering may confuse Blink and rendered result can be broken
// (see http://crbug.com/340987).
newContentViewCore.onSizeChanged(originalWidth, originalHeight, 0, 0);
if (!bounds.isEmpty()) {
newContentViewCore.onPhysicalBackingSizeChanged(bounds.right, bounds.bottom);
}
newContentViewCore.onShow();
setContentViewCore(newContentViewCore);
mContentViewCore.attachImeAdapter();
// See crbug.com/537671
if (!mContentViewCore.getWebContents().getLastCommittedUrl().equals("")) {
ChildProcessLauncher.determinedVisibility(mContentViewCore.getCurrentRenderProcessId());
}
destroyNativePageInternal(previousNativePage);
for (TabObserver observer : mObservers) {
observer.onWebContentsSwapped(this, didStartLoad, didFinishLoad);
}
}
use of android.app.Application in project android_frameworks_base by AOSPA.
the class WebViewFactory method getWebViewContextAndSetProvider.
private static Context getWebViewContextAndSetProvider() {
Application initialApplication = AppGlobals.getInitialApplication();
try {
WebViewProviderResponse response = null;
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewUpdateService.waitForAndGetProvider()");
try {
response = getUpdateService().waitForAndGetProvider();
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
if (response.status != LIBLOAD_SUCCESS && response.status != LIBLOAD_FAILED_WAITING_FOR_RELRO) {
throw new MissingWebViewPackageException("Failed to load WebView provider: " + getWebViewPreparationErrorReason(response.status));
}
// Register to be killed before fetching package info - so that we will be
// killed if the package info goes out-of-date.
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "ActivityManager.addPackageDependency()");
try {
ActivityManagerNative.getDefault().addPackageDependency(response.packageInfo.packageName);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
// Fetch package info and verify it against the chosen package
PackageInfo newPackageInfo = null;
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "PackageManager.getPackageInfo()");
try {
newPackageInfo = initialApplication.getPackageManager().getPackageInfo(response.packageInfo.packageName, PackageManager.GET_SHARED_LIBRARY_FILES | PackageManager.MATCH_DEBUG_TRIAGED_MISSING | // installed for the current user
PackageManager.MATCH_UNINSTALLED_PACKAGES | // Fetch signatures for verification
PackageManager.GET_SIGNATURES | // Get meta-data for meta data flag verification
PackageManager.GET_META_DATA);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
// Validate the newly fetched package info, throws MissingWebViewPackageException on
// failure
verifyPackageInfo(response.packageInfo, newPackageInfo);
Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "initialApplication.createApplicationContext");
try {
// Construct an app context to load the Java code into the current app.
Context webViewContext = initialApplication.createApplicationContext(newPackageInfo.applicationInfo, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
sPackageInfo = newPackageInfo;
return webViewContext;
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
}
} catch (RemoteException | PackageManager.NameNotFoundException e) {
throw new MissingWebViewPackageException("Failed to load WebView provider: " + e);
}
}
use of android.app.Application in project android_frameworks_base by AOSPA.
the class FalsingLog method wtf.
public static synchronized void wtf(String tag, String s, Throwable here) {
if (!ENABLED) {
return;
}
e(tag, s);
Application application = ActivityThread.currentApplication();
String fileMessage = "";
if (Build.IS_DEBUGGABLE && application != null) {
File f = new File(application.getDataDir(), "falsing-" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + ".txt");
PrintWriter pw = null;
try {
pw = new PrintWriter(f);
dump(pw);
pw.close();
fileMessage = "Log written to " + f.getAbsolutePath();
} catch (IOException e) {
Log.e(TAG, "Unable to write falsing log", e);
} finally {
if (pw != null) {
pw.close();
}
}
} else {
Log.e(TAG, "Unable to write log, build must be debuggable.");
}
Log.wtf(TAG, tag + " " + s + "; " + fileMessage, here);
}
use of android.app.Application in project android_frameworks_base by AOSPA.
the class HtmlToSpannedConverter method withinParagraph.
private static void withinParagraph(StringBuilder out, Spanned text, int start, int end) {
int next;
for (int i = start; i < end; i = next) {
next = text.nextSpanTransition(i, end, CharacterStyle.class);
CharacterStyle[] style = text.getSpans(i, next, CharacterStyle.class);
for (int j = 0; j < style.length; j++) {
if (style[j] instanceof StyleSpan) {
int s = ((StyleSpan) style[j]).getStyle();
if ((s & Typeface.BOLD) != 0) {
out.append("<b>");
}
if ((s & Typeface.ITALIC) != 0) {
out.append("<i>");
}
}
if (style[j] instanceof TypefaceSpan) {
String s = ((TypefaceSpan) style[j]).getFamily();
if ("monospace".equals(s)) {
out.append("<tt>");
}
}
if (style[j] instanceof SuperscriptSpan) {
out.append("<sup>");
}
if (style[j] instanceof SubscriptSpan) {
out.append("<sub>");
}
if (style[j] instanceof UnderlineSpan) {
out.append("<u>");
}
if (style[j] instanceof StrikethroughSpan) {
out.append("<span style=\"text-decoration:line-through;\">");
}
if (style[j] instanceof URLSpan) {
out.append("<a href=\"");
out.append(((URLSpan) style[j]).getURL());
out.append("\">");
}
if (style[j] instanceof ImageSpan) {
out.append("<img src=\"");
out.append(((ImageSpan) style[j]).getSource());
out.append("\">");
// Don't output the dummy character underlying the image.
i = next;
}
if (style[j] instanceof AbsoluteSizeSpan) {
AbsoluteSizeSpan s = ((AbsoluteSizeSpan) style[j]);
float sizeDip = s.getSize();
if (!s.getDip()) {
Application application = ActivityThread.currentApplication();
sizeDip /= application.getResources().getDisplayMetrics().density;
}
// px in CSS is the equivalance of dip in Android
out.append(String.format("<span style=\"font-size:%.0fpx\";>", sizeDip));
}
if (style[j] instanceof RelativeSizeSpan) {
float sizeEm = ((RelativeSizeSpan) style[j]).getSizeChange();
out.append(String.format("<span style=\"font-size:%.2fem;\">", sizeEm));
}
if (style[j] instanceof ForegroundColorSpan) {
int color = ((ForegroundColorSpan) style[j]).getForegroundColor();
out.append(String.format("<span style=\"color:#%06X;\">", 0xFFFFFF & color));
}
if (style[j] instanceof BackgroundColorSpan) {
int color = ((BackgroundColorSpan) style[j]).getBackgroundColor();
out.append(String.format("<span style=\"background-color:#%06X;\">", 0xFFFFFF & color));
}
}
withinStyle(out, text, i, next);
for (int j = style.length - 1; j >= 0; j--) {
if (style[j] instanceof BackgroundColorSpan) {
out.append("</span>");
}
if (style[j] instanceof ForegroundColorSpan) {
out.append("</span>");
}
if (style[j] instanceof RelativeSizeSpan) {
out.append("</span>");
}
if (style[j] instanceof AbsoluteSizeSpan) {
out.append("</span>");
}
if (style[j] instanceof URLSpan) {
out.append("</a>");
}
if (style[j] instanceof StrikethroughSpan) {
out.append("</span>");
}
if (style[j] instanceof UnderlineSpan) {
out.append("</u>");
}
if (style[j] instanceof SubscriptSpan) {
out.append("</sub>");
}
if (style[j] instanceof SuperscriptSpan) {
out.append("</sup>");
}
if (style[j] instanceof TypefaceSpan) {
String s = ((TypefaceSpan) style[j]).getFamily();
if (s.equals("monospace")) {
out.append("</tt>");
}
}
if (style[j] instanceof StyleSpan) {
int s = ((StyleSpan) style[j]).getStyle();
if ((s & Typeface.BOLD) != 0) {
out.append("</b>");
}
if ((s & Typeface.ITALIC) != 0) {
out.append("</i>");
}
}
}
}
}
Aggregations