diff --git a/java/ql/src/experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.java b/java/ql/src/experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.java new file mode 100644 index 000000000000..d05700dd2a4b --- /dev/null +++ b/java/ql/src/experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.java @@ -0,0 +1,83 @@ +public class UnsafeAndroidAccess extends Activity { + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.webview); + + // BAD: Have both JavaScript and cross-origin resource access enabled in webview while + // taking remote user inputs + { + WebView wv = (WebView) findViewById(R.id.my_webview); + WebSettings webSettings = wv.getSettings(); + + webSettings.setJavaScriptEnabled(true); + webSettings.setAllowUniversalAccessFromFileURLs(true); + + wv.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + view.loadUrl(url); + return true; + } + }); + + String thisUrl = getIntent().getExtras().getString("url"); // dangerous remote input from the intent's Bundle of extras + wv.loadUrl(thisUrl); + } + + // BAD: Have both JavaScript and cross-origin resource access enabled in webview while + // taking remote user inputs + { + WebView wv = (WebView) findViewById(R.id.my_webview); + WebSettings webSettings = wv.getSettings(); + + webSettings.setJavaScriptEnabled(true); + webSettings.setAllowUniversalAccessFromFileURLs(true); + + wv.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + view.loadUrl(url); + return true; + } + }); + + String thisUrl = getIntent().getStringExtra("url"); //dangerous remote input from intent extra + wv.loadUrl(thisUrl); + } + + // GOOD: Have JavaScript and cross-origin resource access disabled by default on modern Android (Jellybean+) while taking remote user inputs + { + WebView wv = (WebView) findViewById(-1); + WebSettings webSettings = wv.getSettings(); + + wv.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + view.loadUrl(url); + return true; + } + }); + + String thisUrl = getIntent().getExtras().getString("url"); // remote input + wv.loadUrl(thisUrl); + } + + // GOOD: Have JavaScript enabled in webview but remote user input is not allowed + { + WebView wv = (WebView) findViewById(-1); + WebSettings webSettings = wv.getSettings(); + + webSettings.setJavaScriptEnabled(true); + + wv.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + view.loadUrl(url); + return true; + } + }); + + wv.loadUrl("https://www.mycorp.com"); + } + } +} \ No newline at end of file diff --git a/java/ql/src/experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.qhelp b/java/ql/src/experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.qhelp new file mode 100644 index 000000000000..3ac8ec67e595 --- /dev/null +++ b/java/ql/src/experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.qhelp @@ -0,0 +1,31 @@ + + + + +

Android WebViews that allow loading URLs controlled by external inputs and whose JavaScript interface is enabled are potentially vulnerable to cross-site scripting and sensitive resource disclosure attacks.

+

A WebView whose WebSettings object has setAllowFileAccessFromFileURLs(true) or setAllowUniversalAccessFromFileURLs(true) called must not load any untrusted web content.

+

Enabling these settings allows malicious scripts loaded in a file:// context to launch cross-site scripting attacks, either accessing arbitrary local files including WebView cookies, session tokens, private app data or even credentials used on arbitrary web sites.

+

This query detects the following two scenarios:

+
    +
  1. Vulnerability introduced by WebViews with JavaScript enabled and remote inputs allowed.
  2. +
  3. A more severe vulnerability when allowing cross-origin resource access is also enabled. The setting was deprecated in API level 30 (Android 11), but most devices are still affected, especially given that some Android phones are updated slowly or no longer updated at all.
  4. +
+
+ + +

Only allow trusted web content to be displayed in WebViews when JavaScript is enabled. Disallow cross-origin resource access in WebSetting to reduce the attack surface.

+
+ + +

The following example shows both 'BAD' and 'GOOD' configurations. In the 'BAD' configuration, setting is enabled and JavaScript is enabled while URLs are loaded from externally controlled inputs. In the 'GOOD' configuration, JavaScript is disabled or only trusted web content is allowed to be loaded.

+ +
+ + +
  • + CWE-749 + Fixing a File-based XSS Vulnerability + OWASP - Testing WebView Protocol Handlers (MSTG-PLATFORM-5 and MSTG-PLATFORM-6) +
  • +
    +
    \ No newline at end of file diff --git a/java/ql/src/experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.ql b/java/ql/src/experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.ql new file mode 100644 index 000000000000..74e6c060c984 --- /dev/null +++ b/java/ql/src/experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.ql @@ -0,0 +1,146 @@ +/** + * @name Unsafe resource fetching in Android webview + * @description JavaScript rendered inside WebViews can access any protected application file and web resource from any origin + * @kind path-problem + * @tags security + * external/cwe/cwe-749 + * external/cwe/cwe-079 + */ + +import java +import semmle.code.java.frameworks.android.Intent +import semmle.code.java.frameworks.android.WebView +import semmle.code.java.dataflow.FlowSources + +/** + * Methods allowing any-local-file and cross-origin access in the WebSettings class + */ +class CrossOriginAccessMethod extends Method { + CrossOriginAccessMethod() { + this.getDeclaringType() instanceof TypeWebSettings and + ( + this.hasName("setAllowUniversalAccessFromFileURLs") or + this.hasName("setAllowFileAccessFromFileURLs") + ) + } +} + +/** + * `setJavaScriptEnabled` method for the webview + */ +class AllowJavaScriptMethod extends Method { + AllowJavaScriptMethod() { + this.getDeclaringType() instanceof TypeWebSettings and + this.hasName("setJavaScriptEnabled") + } +} + +/** + * Holds if a call to `v.setJavaScriptEnabled(true)` exists + */ +predicate isJSEnabled(Variable v) { + exists(MethodAccess jsa | + v.getAnAccess() = jsa.getQualifier() and + jsa.getMethod() instanceof AllowJavaScriptMethod and + jsa.getArgument(0).(BooleanLiteral).getBooleanValue() = true + ) +} + +/** + * Fetch URL method call on the `android.webkit.WebView` object + */ +class FetchResourceMethodAccess extends MethodAccess { + FetchResourceMethodAccess() { + this.getMethod().getDeclaringType() instanceof TypeWebView and + this.getMethod().hasName(["loadUrl", "postUrl"]) + } +} + +/** + * Method access to external inputs of `android.content.Intent` object + */ +class IntentGetExtraMethodAccess extends MethodAccess { + IntentGetExtraMethodAccess() { + this.getMethod().getName().regexpMatch("get\\w+Extra") and + this.getMethod().getDeclaringType() instanceof TypeIntent + or + this.getMethod().getName().regexpMatch("get\\w+") and + this.getQualifier().(MethodAccess).getMethod().hasName("getExtras") and + this.getQualifier().(MethodAccess).getMethod().getDeclaringType() instanceof TypeIntent + } +} + +/** + * Source of fetching URLs from intent extras + */ +class UntrustedResourceSource extends DataFlow::ExprNode { + UntrustedResourceSource() { this.asExpr() instanceof IntentGetExtraMethodAccess } +} + +/** + * Holds if `ma` loads URL `sink` + */ +predicate fetchResource(FetchResourceMethodAccess ma, Expr sink) { sink = ma.getArgument(0) } + +/** + * A URL argument to a `loadUrl` or `postUrl` call, considered as a sink. + */ +class UrlResourceSink extends DataFlow::ExprNode { + UrlResourceSink() { fetchResource(_, this.getExpr()) } + + /** Gets the fetch method that fetches this sink URL. */ + FetchResourceMethodAccess getMethodAccess() { fetchResource(result, this.getExpr()) } + + /** + * Holds if cross-origin access is enabled for this resource fetch. + * + * Specifically this looks for code like + * `webView.getSettings().setAllow[File|Universal]AccessFromFileURLs(true);` + */ + predicate crossOriginAccessEnabled() { + exists(MethodAccess ma, MethodAccess getSettingsMa | + ma.getMethod() instanceof CrossOriginAccessMethod and + ma.getArgument(0).(BooleanLiteral).getBooleanValue() = true and + ma.getQualifier().(VarAccess).getVariable().getAnAssignedValue() = getSettingsMa and + getSettingsMa.getMethod() instanceof WebViewGetSettingsMethod and + getSettingsMa.getQualifier().(VarAccess).getVariable().getAnAccess() = + getMethodAccess().getQualifier() + ) + } + + /** + * Returns a description of this vulnerability, assuming Javascript is enabled and + * the fetched URL is attacker-controlled. + */ + string getSinkType() { + if crossOriginAccessEnabled() + then result = "user input vulnerable to cross-origin and sensitive resource disclosure attacks" + else result = "user input vulnerable to XSS attacks" + } +} + +/** + * Taint configuration tracking flow from untrusted inputs to `loadUrl` or `postUrl` calls. + */ +class FetchUntrustedResourceConfiguration extends TaintTracking::Configuration { + FetchUntrustedResourceConfiguration() { this = "FetchUntrustedResourceConfiguration" } + + override predicate isSource(DataFlow::Node source) { source instanceof UntrustedResourceSource } + + override predicate isSink(DataFlow::Node sink) { + sink instanceof UrlResourceSink and + exists(VarAccess webviewVa, MethodAccess getSettingsMa, Variable v | + sink.(UrlResourceSink).getMethodAccess().getQualifier() = webviewVa and + getSettingsMa.getMethod() instanceof WebViewGetSettingsMethod and + webviewVa.getVariable().getAnAccess() = getSettingsMa.getQualifier() and + v.getAnAssignedValue() = getSettingsMa and + isJSEnabled(v) + ) + } +} + +from DataFlow::PathNode source, DataFlow::PathNode sink, FetchUntrustedResourceConfiguration conf +where conf.hasFlowPath(source, sink) +select sink.getNode().(UrlResourceSink).getMethodAccess(), source, sink, + "Unsafe resource fetching in Android webview due to $@.", source.getNode(), + sink.getNode().(UrlResourceSink).getSinkType() diff --git a/java/ql/test/experimental/query-tests/security/CWE-749/UnsafeAndroidAccess.expected b/java/ql/test/experimental/query-tests/security/CWE-749/UnsafeAndroidAccess.expected new file mode 100644 index 000000000000..800af691785f --- /dev/null +++ b/java/ql/test/experimental/query-tests/security/CWE-749/UnsafeAndroidAccess.expected @@ -0,0 +1,3 @@ +| UnsafeAndroidAccess.java:30:3:30:21 | loadUrl(...) | UnsafeAndroidAccess.java:29:20:29:59 | getString(...) : String | UnsafeAndroidAccess.java:30:14:30:20 | thisUrl | Unsafe resource fetching in Android webview due to $@. | UnsafeAndroidAccess.java:29:20:29:59 | getString(...) | user input vulnerable to cross-origin and sensitive resource disclosure attacks | +| UnsafeAndroidAccess.java:53:3:53:21 | loadUrl(...) | UnsafeAndroidAccess.java:52:20:52:52 | getStringExtra(...) : String | UnsafeAndroidAccess.java:53:14:53:20 | thisUrl | Unsafe resource fetching in Android webview due to $@. | UnsafeAndroidAccess.java:52:20:52:52 | getStringExtra(...) | user input vulnerable to cross-origin and sensitive resource disclosure attacks | +| UnsafeAndroidAccess.java:95:3:95:21 | loadUrl(...) | UnsafeAndroidAccess.java:94:20:94:52 | getStringExtra(...) : String | UnsafeAndroidAccess.java:95:14:95:20 | thisUrl | Unsafe resource fetching in Android webview due to $@. | UnsafeAndroidAccess.java:94:20:94:52 | getStringExtra(...) | user input vulnerable to XSS attacks | diff --git a/java/ql/test/experimental/query-tests/security/CWE-749/UnsafeAndroidAccess.java b/java/ql/test/experimental/query-tests/security/CWE-749/UnsafeAndroidAccess.java new file mode 100644 index 000000000000..8a929120bf89 --- /dev/null +++ b/java/ql/test/experimental/query-tests/security/CWE-749/UnsafeAndroidAccess.java @@ -0,0 +1,119 @@ +import android.app.Activity; + +import android.os.Bundle; + +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +public class UnsafeAndroidAccess extends Activity { + //Test onCreate with both JavaScript and cross-origin resource access enabled while taking remote user inputs from bundle extras + public void testOnCreate1(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(-1); + + WebView wv = (WebView) findViewById(-1); + WebSettings webSettings = wv.getSettings(); + + webSettings.setJavaScriptEnabled(true); + webSettings.setAllowFileAccessFromFileURLs(true); + + wv.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + view.loadUrl(url); + return true; + } + }); + + String thisUrl = getIntent().getExtras().getString("url"); + wv.loadUrl(thisUrl); + } + + //Test onCreate with both JavaScript and cross-origin resource access enabled while taking remote user inputs from string extra + public void testOnCreate2(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(-1); + + WebView wv = (WebView) findViewById(-1); + WebSettings webSettings = wv.getSettings(); + + webSettings.setJavaScriptEnabled(true); + webSettings.setAllowFileAccessFromFileURLs(true); + + wv.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + view.loadUrl(url); + return true; + } + }); + + String thisUrl = getIntent().getStringExtra("url"); + wv.loadUrl(thisUrl); + } + + //Test onCreate with both JavaScript and cross-origin resource access disabled by default while taking remote user inputs + public void testOnCreate3(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(-1); + + WebView wv = (WebView) findViewById(-1); + WebSettings webSettings = wv.getSettings(); + + wv.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + view.loadUrl(url); + return true; + } + }); + + String thisUrl = getIntent().getStringExtra("url"); + wv.loadUrl(thisUrl); + } + + //Test onCreate with JavaScript enabled but cross-origin resource access disabled while taking remote user inputs + public void testOnCreate4(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(-1); + + WebView wv = (WebView) findViewById(-1); + WebSettings webSettings = wv.getSettings(); + + webSettings.setJavaScriptEnabled(true); + + wv.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + view.loadUrl(url); + return true; + } + }); + + String thisUrl = getIntent().getStringExtra("url"); + wv.loadUrl(thisUrl); + } + + //Test onCreate with both JavaScript and cross-origin resource access enabled while not taking remote user inputs + public void testOnCreate5(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(-1); + + WebView wv = (WebView) findViewById(-1); + WebSettings webSettings = wv.getSettings(); + + webSettings.setJavaScriptEnabled(true); + webSettings.setAllowFileAccessFromFileURLs(true); + + wv.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + view.loadUrl(url); + return true; + } + }); + + wv.loadUrl("https://www.mycorp.com"); + } +} \ No newline at end of file diff --git a/java/ql/test/experimental/query-tests/security/CWE-749/UnsafeAndroidAccess.qlref b/java/ql/test/experimental/query-tests/security/CWE-749/UnsafeAndroidAccess.qlref new file mode 100644 index 000000000000..abaed120e991 --- /dev/null +++ b/java/ql/test/experimental/query-tests/security/CWE-749/UnsafeAndroidAccess.qlref @@ -0,0 +1 @@ +experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.ql \ No newline at end of file diff --git a/java/ql/test/experimental/query-tests/security/CWE-749/options b/java/ql/test/experimental/query-tests/security/CWE-749/options new file mode 100644 index 000000000000..43e25f608b67 --- /dev/null +++ b/java/ql/test/experimental/query-tests/security/CWE-749/options @@ -0,0 +1 @@ +// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../stubs/google-android-9.0.0 diff --git a/java/ql/test/stubs/google-android-9.0.0/android/app/Activity.java b/java/ql/test/stubs/google-android-9.0.0/android/app/Activity.java new file mode 100644 index 000000000000..19a2662b96cf --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/app/Activity.java @@ -0,0 +1,1144 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.app; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; + +/** + * An activity is a single, focused thing that the user can do. Almost all + * activities interact with the user, so the Activity class takes care of + * creating a window for you in which you can place your UI with + * {@link #setContentView}. While activities are often presented to the user as + * full-screen windows, they can also be used in other ways: as floating windows + * (via a theme with {@link android.R.attr#windowIsFloating} set) or embedded + * inside of another activity (using {@link ActivityGroup}). + * + * There are two methods almost all subclasses of Activity will implement: + * + * + * + *

    + * To be of use with {@link android.content.Context#startActivity + * Context.startActivity()}, all activity classes must have a corresponding + * {@link android.R.styleable#AndroidManifestActivity <activity>} + * declaration in their package's AndroidManifest.xml. + *

    + * + *

    + * Topics covered here: + *

      + *
    1. Fragments + *
    2. Activity Lifecycle + *
    3. Configuration Changes + *
    4. Starting Activities and Getting Results + *
    5. Saving Persistent State + *
    6. Permissions + *
    7. Process Lifecycle + *
    + * + *
    + *

    Developer Guides

    + *

    + * The Activity class is an important part of an application's overall + * lifecycle, and the way activities are launched and put together is a + * fundamental part of the platform's application model. For a detailed + * perspective on the structure of an Android application and how activities + * behave, please read the + * Application + * Fundamentals and + * Tasks and Back + * Stack developer guides. + *

    + * + *

    + * You can also find a detailed discussion about how to create activities in the + * Activities developer + * guide. + *

    + *
    + * + * + *

    Fragments

    + * + *

    + * The {@link android.support.v4.app.FragmentActivity} subclass can make use of + * the {@link android.support.v4.app.Fragment} class to better modularize their + * code, build more sophisticated user interfaces for larger screens, and help + * scale their application between small and large screens. + *

    + * + *

    + * For more information about using fragments, read the + * Fragments developer + * guide. + *

    + * + * + *

    Activity Lifecycle

    + * + *

    + * Activities in the system are managed as an activity stack. When a + * new activity is started, it is placed on the top of the stack and becomes the + * running activity -- the previous activity always remains below it in the + * stack, and will not come to the foreground again until the new activity + * exits. + *

    + * + *

    + * An activity has essentially four states: + *

    + * + * + *

    + * The following diagram shows the important state paths of an Activity. The + * square rectangles represent callback methods you can implement to perform + * operations when the Activity moves between states. The colored ovals are + * major states the Activity can be in. + *

    + * + *

    + * State diagram for an
+ * Android Activity Lifecycle. + *

    + * + *

    + * There are three key loops you may be interested in monitoring within your + * activity: + * + *

    + * + *

    + * The entire lifecycle of an activity is defined by the following Activity + * methods. All of these are hooks that you can override to do appropriate work + * when the activity changes state. All activities will implement + * {@link android.app.Activity#onCreate} to do their initial setup; many will + * also implement {@link android.app.Activity#onPause} to commit changes to data + * and otherwise prepare to stop interacting with the user. You should always + * call up to your superclass when implementing these methods. + *

    + * + *

    + * + *
    + * public class Activity extends ApplicationContext {
    + *     protected void onCreate(Bundle savedInstanceState);
    + *
    + *     protected void onStart();
    + *
    + *     protected void onRestart();
    + *
    + *     protected void onResume();
    + *
    + *     protected void onPause();
    + *
    + *     protected void onStop();
    + *
    + *     protected void onDestroy();
    + * }
    + * 
    + * + *

    + * In general the movement through an activity's lifecycle looks like this: + *

    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    MethodDescriptionKillable?Next
    {@link android.app.Activity#onCreate + * onCreate()}Called when the activity is first created. This is where you should do + * all of your normal static set up: create views, bind data to lists, etc. This + * method also provides you with a Bundle containing the activity's previously + * frozen state, if there was one. + *

    + * Always followed by onStart().

    NoonStart()
        {@link android.app.Activity#onRestart + * onRestart()}Called after your activity has been stopped, prior to it being started + * again. + *

    + * Always followed by onStart()

    NoonStart()
    {@link android.app.Activity#onStart + * onStart()}Called when the activity is becoming visible to the user. + *

    + * Followed by onResume() if the activity comes to the foreground, + * or onStop() if it becomes hidden.

    NoonResume() or onStop()
        {@link android.app.Activity#onResume + * onResume()}Called when the activity will start interacting with the user. At this + * point your activity is at the top of the activity stack, with user input + * going to it. + *

    + * Always followed by onPause().

    NoonPause()
    {@link android.app.Activity#onPause + * onPause()}Called when the system is about to start resuming a previous activity. + * This is typically used to commit unsaved changes to persistent data, stop + * animations and other things that may be consuming CPU, etc. Implementations + * of this method must be very quick because the next activity will not be + * resumed until this method returns. + *

    + * Followed by either onResume() if the activity returns back to + * the front, or onStop() if it becomes invisible to the user.

    Pre-{@link android.os.Build.VERSION_CODES#HONEYCOMB}onResume() or
    + * onStop()
    {@link android.app.Activity#onStop + * onStop()}Called when the activity is no longer visible to the user, because + * another activity has been resumed and is covering this one. This may happen + * either because a new activity is being started, an existing one is being + * brought in front of this one, or this one is being destroyed. + *

    + * Followed by either onRestart() if this activity is coming back + * to interact with the user, or onDestroy() if this activity is + * going away.

    YesonRestart() or
    + * onDestroy()
    {@link android.app.Activity#onDestroy + * onDestroy()}The final call you receive before your activity is destroyed. This can + * happen either because the activity is finishing (someone called + * {@link Activity#finish} on it, or because the system is temporarily + * destroying this instance of the activity to save space. You can distinguish + * between these two scenarios with the {@link Activity#isFinishing} + * method.Yesnothing
    + * + *

    + * Note the "Killable" column in the above table -- for those methods that are + * marked as being killable, after that method returns the process hosting the + * activity may be killed by the system at any time without another + * line of its code being executed. Because of this, you should use the + * {@link #onPause} method to write any persistent data (such as user edits) to + * storage. In addition, the method {@link #onSaveInstanceState(Bundle)} is + * called before placing the activity in such a background state, allowing you + * to save away any dynamic instance state in your activity into the given + * Bundle, to be later received in {@link #onCreate} if the activity needs to be + * re-created. See the Process Lifecycle section + * for more information on how the lifecycle of a process is tied to the + * activities it is hosting. Note that it is important to save persistent data + * in {@link #onPause} instead of {@link #onSaveInstanceState} because the + * latter is not part of the lifecycle callbacks, so will not be called in every + * situation as described in its documentation. + *

    + * + *

    + * Be aware that these semantics will change slightly between applications + * targeting platforms starting with + * {@link android.os.Build.VERSION_CODES#HONEYCOMB} vs. those targeting prior + * platforms. Starting with Honeycomb, an application is not in the killable + * state until its {@link #onStop} has returned. This impacts when + * {@link #onSaveInstanceState(Bundle)} may be called (it may be safely called + * after {@link #onPause()}) and allows an application to safely wait until + * {@link #onStop()} to save persistent state. + *

    + * + *

    + * For applications targeting platforms starting with + * {@link android.os.Build.VERSION_CODES#P} {@link #onSaveInstanceState(Bundle)} + * will always be called after {@link #onStop}, so an application may safely + * perform fragment transactions in {@link #onStop} and will be able to save + * persistent state later. + *

    + * + *

    + * For those methods that are not marked as being killable, the activity's + * process will not be killed by the system starting from the time the method is + * called and continuing after it returns. Thus an activity is in the killable + * state, for example, between after onPause() to the start of + * onResume(). + *

    + * + * + *

    Configuration Changes

    + * + *

    + * If the configuration of the device (as defined by the {@link Configuration + * Resources.Configuration} class) changes, then anything displaying a user + * interface will need to update to match that configuration. Because Activity + * is the primary mechanism for interacting with the user, it includes special + * support for handling configuration changes. + *

    + * + *

    + * Unless you specify otherwise, a configuration change (such as a change in + * screen orientation, language, input devices, etc) will cause your current + * activity to be destroyed, going through the normal activity + * lifecycle process of {@link #onPause}, {@link #onStop}, and + * {@link #onDestroy} as appropriate. If the activity had been in the foreground + * or visible to the user, once {@link #onDestroy} is called in that instance + * then a new instance of the activity will be created, with whatever + * savedInstanceState the previous instance had generated from + * {@link #onSaveInstanceState}. + *

    + * + *

    + * This is done because any application resource, including layout files, can + * change based on any configuration value. Thus the only safe way to handle a + * configuration change is to re-retrieve all resources, including layouts, + * drawables, and strings. Because activities must already know how to save + * their state and re-create themselves from that state, this is a convenient + * way to have an activity restart itself with a new configuration. + *

    + * + *

    + * In some special cases, you may want to bypass restarting of your activity + * based on one or more types of configuration changes. This is done with the + * {@link android.R.attr#configChanges android:configChanges} attribute in its + * manifest. For any types of configuration changes you say that you handle + * there, you will receive a call to your current activity's + * {@link #onConfigurationChanged} method instead of being restarted. If a + * configuration change involves any that you do not handle, however, the + * activity will still be restarted and {@link #onConfigurationChanged} will not + * be called. + *

    + * + * + *

    Starting Activities and Getting Results

    + * + *

    + * The {@link android.app.Activity#startActivity} method is used to start a new + * activity, which will be placed at the top of the activity stack. It takes a + * single argument, an {@link android.content.Intent Intent}, which describes + * the activity to be executed. + *

    + * + *

    + * Sometimes you want to get a result back from an activity when it ends. For + * example, you may start an activity that lets the user pick a person in a list + * of contacts; when it ends, it returns the person that was selected. To do + * this, you call the + * {@link android.app.Activity#startActivityForResult(Intent, int)} version with + * a second integer parameter identifying the call. The result will come back + * through your {@link android.app.Activity#onActivityResult} method. + *

    + * + *

    + * When an activity exits, it can call + * {@link android.app.Activity#setResult(int)} to return data back to its + * parent. It must always supply a result code, which can be the standard + * results RESULT_CANCELED, RESULT_OK, or any custom values starting at + * RESULT_FIRST_USER. In addition, it can optionally return back an Intent + * containing any additional data it wants. All of this information appears back + * on the parent's Activity.onActivityResult(), along with the + * integer identifier it originally supplied. + *

    + * + *

    + * If a child activity fails for any reason (such as crashing), the parent + * activity will receive a result with the code RESULT_CANCELED. + *

    + * + *
    + * public class MyActivity extends Activity {
    + *     ...
    + *
    + *     static final int PICK_CONTACT_REQUEST = 0;
    + *
    + *     public boolean onKeyDown(int keyCode, KeyEvent event) {
    + *         if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
    + *             // When the user center presses, let them pick a contact.
    + *             startActivityForResult(
    + *                 new Intent(Intent.ACTION_PICK,
    + *                 new Uri("content://contacts")),
    + *                 PICK_CONTACT_REQUEST);
    + *            return true;
    + *         }
    + *         return false;
    + *     }
    + *
    + *     protected void onActivityResult(int requestCode, int resultCode,
    + *             Intent data) {
    + *         if (requestCode == PICK_CONTACT_REQUEST) {
    + *             if (resultCode == RESULT_OK) {
    + *                 // A contact was picked.  Here we will just display it
    + *                 // to the user.
    + *                 startActivity(new Intent(Intent.ACTION_VIEW, data));
    + *             }
    + *         }
    + *     }
    + * }
    + * 
    + * + * + *

    Saving Persistent State

    + * + *

    + * There are generally two kinds of persistent state than an activity will deal + * with: shared document-like data (typically stored in a SQLite database using + * a {@linkplain android.content.ContentProvider content provider}) and internal + * state such as user preferences. + *

    + * + *

    + * For content provider data, we suggest that activities use a "edit in place" + * user model. That is, any edits a user makes are effectively made immediately + * without requiring an additional confirmation step. Supporting this model is + * generally a simple matter of following two rules: + *

    + * + * + * + *

    + * This model is designed to prevent data loss when a user is navigating between + * activities, and allows the system to safely kill an activity (because system + * resources are needed somewhere else) at any time after it has been paused. + * Note this implies that the user pressing BACK from your activity does + * not mean "cancel" -- it means to leave the activity with its current + * contents saved away. Canceling edits in an activity must be provided through + * some other mechanism, such as an explicit "revert" or "undo" option. + *

    + * + *

    + * See the {@linkplain android.content.ContentProvider content package} for more + * information about content providers. These are a key aspect of how different + * activities invoke and propagate data between themselves. + *

    + * + *

    + * The Activity class also provides an API for managing internal persistent + * state associated with an activity. This can be used, for example, to remember + * the user's preferred initial display in a calendar (day view or week view) or + * the user's default home page in a web browser. + *

    + * + *

    + * Activity persistent state is managed with the method {@link #getPreferences}, + * allowing you to retrieve and modify a set of name/value pairs associated with + * the activity. To use preferences that are shared across multiple application + * components (activities, receivers, services, providers), you can use the + * underlying {@link Context#getSharedPreferences + * Context.getSharedPreferences()} method to retrieve a preferences object + * stored under a specific name. (Note that it is not possible to share settings + * data across application packages -- for that you will need a content + * provider.) + *

    + * + *

    + * Here is an excerpt from a calendar activity that stores the user's preferred + * view mode in its persistent settings: + *

    + * + *
    + * public class CalendarActivity extends Activity {
    + *     ...
    + *
    + *     static final int DAY_VIEW_MODE = 0;
    + *     static final int WEEK_VIEW_MODE = 1;
    + *
    + *     private SharedPreferences mPrefs;
    + *     private int mCurViewMode;
    + *
    + *     protected void onCreate(Bundle savedInstanceState) {
    + *         super.onCreate(savedInstanceState);
    + *
    + *         SharedPreferences mPrefs = getSharedPreferences();
    + *         mCurViewMode = mPrefs.getInt("view_mode", DAY_VIEW_MODE);
    + *     }
    + *
    + *     protected void onPause() {
    + *         super.onPause();
    + *
    + *         SharedPreferences.Editor ed = mPrefs.edit();
    + *         ed.putInt("view_mode", mCurViewMode);
    + *         ed.commit();
    + *     }
    + * }
    + * 
    + * + * + *

    Permissions

    + * + *

    + * The ability to start a particular Activity can be enforced when it is + * declared in its manifest's {@link android.R.styleable#AndroidManifestActivity + * <activity>} tag. By doing so, other applications will need to declare a + * corresponding {@link android.R.styleable#AndroidManifestUsesPermission + * <uses-permission>} element in their own manifest to be able to start + * that activity. + * + *

    + * When starting an Activity you can set + * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION + * Intent.FLAG_GRANT_READ_URI_PERMISSION} and/or + * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION + * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} on the Intent. This will grant the + * Activity access to the specific URIs in the Intent. Access will remain until + * the Activity has finished (it will remain across the hosting process being + * killed and other temporary destruction). As of + * {@link android.os.Build.VERSION_CODES#GINGERBREAD}, if the Activity was + * already created and a new Intent is being delivered to + * {@link #onNewIntent(Intent)}, any newly granted URI permissions will be added + * to the existing ones it holds. + * + *

    + * See the Security and + * Permissions document for more information on permissions and security in + * general. + * + * + *

    Process Lifecycle

    + * + *

    + * The Android system attempts to keep an application process around for as long + * as possible, but eventually will need to remove old processes when memory + * runs low. As described in Activity + * Lifecycle, the decision about which process to remove is intimately tied + * to the state of the user's interaction with it. In general, there are four + * states a process can be in based on the activities running in it, listed here + * in order of importance. The system will kill less important processes (the + * last ones) before it resorts to killing more important processes (the first + * ones). + * + *

      + *
    1. + *

      + * The foreground activity (the activity at the top of the screen that + * the user is currently interacting with) is considered the most important. Its + * process will only be killed as a last resort, if it uses more memory than is + * available on the device. Generally at this point the device has reached a + * memory paging state, so this is required in order to keep the user interface + * responsive. + *

    2. + *

      + * A visible activity (an activity that is visible to the user but not in + * the foreground, such as one sitting behind a foreground dialog) is considered + * extremely important and will not be killed unless that is required to keep + * the foreground activity running. + *

    3. + *

      + * A background activity (an activity that is not visible to the user and + * has been paused) is no longer critical, so the system may safely kill its + * process to reclaim memory for other foreground or visible processes. If its + * process needs to be killed, when the user navigates back to the activity + * (making it visible on the screen again), its {@link #onCreate} method will be + * called with the savedInstanceState it had previously supplied in + * {@link #onSaveInstanceState} so that it can restart itself in the same state + * as the user last left it. + *

    4. + *

      + * An empty process is one hosting no activities or other application + * components (such as {@link Service} or + * {@link android.content.BroadcastReceiver} classes). These are killed very + * quickly by the system as memory becomes low. For this reason, any background + * operation you do outside of an activity must be executed in the context of an + * activity BroadcastReceiver or Service to ensure that the system knows it + * needs to keep your process around. + *

    + * + *

    + * Sometimes an Activity may need to do a long-running operation that exists + * independently of the activity lifecycle itself. An example may be a camera + * application that allows you to upload a picture to a web site. The upload may + * take a long time, and the application should allow the user to leave the + * application while it is executing. To accomplish this, your Activity should + * start a {@link Service} in which the upload takes place. This allows the + * system to properly prioritize your process (considering it to be more + * important than other non-visible applications) for the duration of the + * upload, independent of whether the original activity is paused, stopped, or + * finished. + */ +public class Activity { + /** Return the intent that started this activity. */ + public Intent getIntent() { + return null; + } + + /** + * Change the intent returned by {@link #getIntent}. This holds a reference to + * the given intent; it does not copy it. Often used in conjunction with + * {@link #onNewIntent}. + * + * @param newIntent The new Intent object to return from getIntent + * + * @see #getIntent + * @see #onNewIntent + */ + public void setIntent(Intent newIntent) { + } + + /** + * Called when the activity is starting. This is where most initialization + * should go: calling {@link #setContentView(int)} to inflate the activity's UI, + * using {@link #findViewById} to programmatically interact with widgets in the + * UI, calling + * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} + * to retrieve cursors for data being displayed, etc. + * + *

    + * You can call {@link #finish} from within this function, in which case + * onDestroy() will be immediately called after {@link #onCreate} without any of + * the rest of the activity lifecycle ({@link #onStart}, {@link #onResume}, + * {@link #onPause}, etc) executing. + * + *

    + * Derived classes must call through to the super class's implementation of + * this method. If they do not, an exception will be thrown. + *

    + * + * @param savedInstanceState If the activity is being re-initialized after + * previously being shut down then this Bundle + * contains the data it most recently supplied in + * {@link #onSaveInstanceState}. Note: Otherwise + * it is null. + * + * @see #onStart + * @see #onSaveInstanceState + * @see #onRestoreInstanceState + * @see #onPostCreate + */ + protected void onCreate(Bundle savedInstanceState) { + } + + /** + * This method is called after {@link #onStart} when the activity is being + * re-initialized from a previously saved state, given here in + * savedInstanceState. Most implementations will simply use + * {@link #onCreate} to restore their state, but it is sometimes convenient to + * do it here after all of the initialization has been done or to allow + * subclasses to decide whether to use your default implementation. The default + * implementation of this method performs a restore of any view state that had + * previously been frozen by {@link #onSaveInstanceState}. + * + *

    + * This method is called between {@link #onStart} and {@link #onPostCreate}. + * + * @param savedInstanceState the data most recently supplied in + * {@link #onSaveInstanceState}. + * + * @see #onCreate + * @see #onPostCreate + * @see #onResume + * @see #onSaveInstanceState + */ + protected void onRestoreInstanceState(Bundle savedInstanceState) { + } + + /** + * Called when activity start-up is complete (after {@link #onStart} and + * {@link #onRestoreInstanceState} have been called). Applications will + * generally not implement this method; it is intended for system classes to do + * final initialization after application code has run. + * + *

    + * Derived classes must call through to the super class's implementation of + * this method. If they do not, an exception will be thrown. + *

    + * + * @param savedInstanceState If the activity is being re-initialized after + * previously being shut down then this Bundle + * contains the data it most recently supplied in + * {@link #onSaveInstanceState}. Note: Otherwise + * it is null. + * @see #onCreate + */ + protected void onPostCreate(Bundle savedInstanceState) { + } + + /** + * Called after {@link #onCreate} — or after {@link #onRestart} when the + * activity had been stopped, but is now again being displayed to the user. It + * will be followed by {@link #onResume}. + * + *

    + * Derived classes must call through to the super class's implementation of + * this method. If they do not, an exception will be thrown. + *

    + * + * @see #onCreate + * @see #onStop + * @see #onResume + */ + protected void onStart() { + } + + /** + * Called after {@link #onRestoreInstanceState}, {@link #onRestart}, or + * {@link #onPause}, for your activity to start interacting with the user. This + * is a good place to begin animations, open exclusive-access devices (such as + * the camera), etc. + * + *

    + * Keep in mind that onResume is not the best indicator that your activity is + * visible to the user; a system window such as the keyguard may be in front. + * Use {@link #onWindowFocusChanged} to know for certain that your activity is + * visible to the user (for example, to resume a game). + * + *

    + * Derived classes must call through to the super class's implementation of + * this method. If they do not, an exception will be thrown. + *

    + * + * @see #onRestoreInstanceState + * @see #onRestart + * @see #onPostResume + * @see #onPause + */ + protected void onResume() { + } + + /** + * Called when activity resume is complete (after {@link #onResume} has been + * called). Applications will generally not implement this method; it is + * intended for system classes to do final setup after application resume code + * has run. + * + *

    + * Derived classes must call through to the super class's implementation of + * this method. If they do not, an exception will be thrown. + *

    + * + * @see #onResume + */ + protected void onPostResume() { + } + + /** + * This is called for activities that set launchMode to "singleTop" in their + * package, or if a client used the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP} flag + * when calling {@link #startActivity}. In either case, when the activity is + * re-launched while at the top of the activity stack instead of a new instance + * of the activity being started, onNewIntent() will be called on the existing + * instance with the Intent that was used to re-launch it. + * + *

    + * An activity will always be paused before receiving a new intent, so you can + * count on {@link #onResume} being called after this method. + * + *

    + * Note that {@link #getIntent} still returns the original Intent. You can use + * {@link #setIntent} to update it to this new Intent. + * + * @param intent The new intent that was started for the activity. + * + * @see #getIntent + * @see #setIntent + * @see #onResume + */ + protected void onNewIntent(Intent intent) { + } + + /** + * Called to retrieve per-instance state from an activity before being killed so + * that the state can be restored in {@link #onCreate} or + * {@link #onRestoreInstanceState} (the {@link Bundle} populated by this method + * will be passed to both). + * + *

    + * This method is called before an activity may be killed so that when it comes + * back some time in the future it can restore its state. For example, if + * activity B is launched in front of activity A, and at some point activity A + * is killed to reclaim resources, activity A will have a chance to save the + * current state of its user interface via this method so that when the user + * returns to activity A, the state of the user interface can be restored via + * {@link #onCreate} or {@link #onRestoreInstanceState}. + * + *

    + * Do not confuse this method with activity lifecycle callbacks such as + * {@link #onPause}, which is always called when an activity is being placed in + * the background or on its way to destruction, or {@link #onStop} which is + * called before destruction. One example of when {@link #onPause} and + * {@link #onStop} is called and not this method is when a user navigates back + * from activity B to activity A: there is no need to call + * {@link #onSaveInstanceState} on B because that particular instance will never + * be restored, so the system avoids calling it. An example when + * {@link #onPause} is called and not {@link #onSaveInstanceState} is when + * activity B is launched in front of activity A: the system may avoid calling + * {@link #onSaveInstanceState} on activity A if it isn't killed during the + * lifetime of B since the state of the user interface of A will stay intact. + * + *

    + * The default implementation takes care of most of the UI per-instance state + * for you by calling {@link android.view.View#onSaveInstanceState()} on each + * view in the hierarchy that has an id, and by saving the id of the currently + * focused view (all of which is restored by the default implementation of + * {@link #onRestoreInstanceState}). If you override this method to save + * additional information not captured by each individual view, you will likely + * want to call through to the default implementation, otherwise be prepared to + * save all of the state of each view yourself. + * + *

    + * If called, this method will occur after {@link #onStop} for applications + * targeting platforms starting with {@link android.os.Build.VERSION_CODES#P}. + * For applications targeting earlier platform versions this method will occur + * before {@link #onStop} and there are no guarantees about whether it will + * occur before or after {@link #onPause}. + * + * @param outState Bundle in which to place your saved state. + * + * @see #onCreate + * @see #onRestoreInstanceState + * @see #onPause + */ + protected void onSaveInstanceState(Bundle outState) { + } + + /** + * Called as part of the activity lifecycle when an activity is going into the + * background, but has not (yet) been killed. The counterpart to + * {@link #onResume}. + * + *

    + * When activity B is launched in front of activity A, this callback will be + * invoked on A. B will not be created until A's {@link #onPause} returns, so be + * sure to not do anything lengthy here. + * + *

    + * This callback is mostly used for saving any persistent state the activity is + * editing, to present a "edit in place" model to the user and making sure + * nothing is lost if there are not enough resources to start the new activity + * without first killing this one. This is also a good place to do things like + * stop animations and other things that consume a noticeable amount of CPU in + * order to make the switch to the next activity as fast as possible, or to + * close resources that are exclusive access such as the camera. + * + *

    + * In situations where the system needs more memory it may kill paused processes + * to reclaim resources. Because of this, you should be sure that all of your + * state is saved by the time you return from this function. In general + * {@link #onSaveInstanceState} is used to save per-instance state in the + * activity and this method is used to store global persistent data (in content + * providers, files, etc.) + * + *

    + * After receiving this call you will usually receive a following call to + * {@link #onStop} (after the next activity has been resumed and displayed), + * however in some cases there will be a direct call back to {@link #onResume} + * without going through the stopped state. + * + *

    + * Derived classes must call through to the super class's implementation of + * this method. If they do not, an exception will be thrown. + *

    + * + * @see #onResume + * @see #onSaveInstanceState + * @see #onStop + */ + protected void onPause() { + } + + /** + * Called when you are no longer visible to the user. You will next receive + * either {@link #onRestart}, {@link #onDestroy}, or nothing, depending on later + * user activity. + * + *

    + * Derived classes must call through to the super class's implementation of + * this method. If they do not, an exception will be thrown. + *

    + * + * @see #onRestart + * @see #onResume + * @see #onSaveInstanceState + * @see #onDestroy + */ + protected void onStop() { + } + + /** + * Perform any final cleanup before an activity is destroyed. This can happen + * either because the activity is finishing (someone called {@link #finish} on + * it, or because the system is temporarily destroying this instance of the + * activity to save space. You can distinguish between these two scenarios with + * the {@link #isFinishing} method. + * + *

    + * Note: do not count on this method being called as a place for saving + * data! For example, if an activity is editing data in a content provider, + * those edits should be committed in either {@link #onPause} or + * {@link #onSaveInstanceState}, not here. This method is usually + * implemented to free resources like threads that are associated with an + * activity, so that a destroyed activity does not leave such things around + * while the rest of its application is still running. There are situations + * where the system will simply kill the activity's hosting process without + * calling this method (or any others) in it, so it should not be used to do + * things that are intended to remain around after the process goes away. + * + *

    + * Derived classes must call through to the super class's implementation of + * this method. If they do not, an exception will be thrown. + *

    + * + * @see #onPause + * @see #onStop + * @see #finish + * @see #isFinishing + */ + protected void onDestroy() { + } + + /** + * Finds a view that was identified by the {@code android:id} XML attribute that + * was processed in {@link #onCreate}. + *

    + * Note: In most cases -- depending on compiler support -- the + * resulting view is automatically cast to the target class type. If the target + * class type is unconstrained, an explicit cast may be necessary. + * + * @param id the ID to search for + * @return a view with given ID if found, or {@code null} otherwise + * @see View#findViewById(int) + * @see Activity#requireViewById(int) + */ + public T findViewById(int id) { + } + + /** + * Set the activity content from a layout resource. The resource will be + * inflated, adding all top-level views to the activity. + * + * @param layoutResID Resource ID to be inflated. + * + * @see #setContentView(android.view.View) + * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) + */ + public void setContentView(int layoutResID) { + } + + /** + * Set the activity content to an explicit view. This view is placed directly + * into the activity's view hierarchy. It can itself be a complex view + * hierarchy. When calling this method, the layout parameters of the specified + * view are ignored. Both the width and the height of the view are set by + * default to {@link ViewGroup.LayoutParams#MATCH_PARENT}. To use your own + * layout parameters, invoke + * {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)} + * instead. + * + * @param view The desired content to display. + * + * @see #setContentView(int) + * @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams) + */ + public void setContentView(View view) { + } + + /** + * Same as calling {@link #startActivityForResult(Intent, int, Bundle)} with no + * options. + * + * @param intent The intent to start. + * @param requestCode If >= 0, this code will be returned in onActivityResult() + * when the activity exits. + * + * @throws android.content.ActivityNotFoundException + * + * @see #startActivity + */ + public void startActivityForResult(Intent intent, int requestCode) { + } + + /** + * Same as {@link #startActivity(Intent, Bundle)} with no options specified. + * + * @param intent The intent to start. + * + * @throws android.content.ActivityNotFoundException + * + * @see #startActivity(Intent, Bundle) + * @see #startActivityForResult + */ + public void startActivity(Intent intent) { + } + + /** + * Launch a new activity. You will not receive any information about when the + * activity exits. This implementation overrides the base version, providing + * information about the activity performing the launch. Because of this + * additional information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag + * is not required; if not specified, the new activity will be added to the task + * of the caller. + * + *

    + * This method throws {@link android.content.ActivityNotFoundException} if there + * was no Activity found to run the given Intent. + * + * @param intent The intent to start. + * @param options Additional options for how the Activity should be started. See + * {@link android.content.Context#startActivity(Intent, Bundle)} + * Context.startActivity(Intent, Bundle)} for more details. + * + * @throws android.content.ActivityNotFoundException + * + * @see #startActivity(Intent) + * @see #startActivityForResult + */ + public void startActivity(Intent intent, Bundle options) { + } + + /** + * Same as {@link #startActivities(Intent[], Bundle)} with no options specified. + * + * @param intents The intents to start. + * + * @throws android.content.ActivityNotFoundException + * + * @see #startActivities(Intent[], Bundle) + * @see #startActivityForResult + */ + public void startActivities(Intent[] intents) { + } + + /** + * Launch a new activity. You will not receive any information about when the + * activity exits. This implementation overrides the base version, providing + * information about the activity performing the launch. Because of this + * additional information, the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag + * is not required; if not specified, the new activity will be added to the task + * of the caller. + * + *

    + * This method throws {@link android.content.ActivityNotFoundException} if there + * was no Activity found to run the given Intent. + * + * @param intents The intents to start. + * @param options Additional options for how the Activity should be started. See + * {@link android.content.Context#startActivity(Intent, Bundle)} + * Context.startActivity(Intent, Bundle)} for more details. + * + * @throws android.content.ActivityNotFoundException + * + * @see #startActivities(Intent[]) + * @see #startActivityForResult + */ + public void startActivities(Intent[] intents, Bundle options) { + } +} \ No newline at end of file diff --git a/java/ql/test/stubs/google-android-9.0.0/android/content/Context.java b/java/ql/test/stubs/google-android-9.0.0/android/content/Context.java new file mode 100644 index 000000000000..8c528a58e412 --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/content/Context.java @@ -0,0 +1,816 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.content; + +import java.io.File; +import android.os.Bundle; + +/** + * Interface to global information about an application environment. This is an + * abstract class whose implementation is provided by the Android system. It + * allows access to application-specific resources and classes, as well as + * up-calls for application-level operations such as launching activities, + * broadcasting and receiving intents, etc. + */ +public abstract class Context { + /** + * Return the context of the single, global Application object of the current + * process. This generally should only be used if you need a Context whose + * lifecycle is separate from the current context, that is tied to the lifetime + * of the process rather than the current component. + * + *

    + * Consider for example how this interacts with + * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}: + *

    + */ + public abstract Context getApplicationContext(); + + /** + * Returns the absolute path on the filesystem where a file created with + * {@link #openFileOutput} is stored. + *

    + * The returned path may change over time if the calling app is moved to an + * adopted storage device, so only relative paths should be persisted. + * + * @param name The name of the file for which you would like to get its path. + * + * @return An absolute path to the given file. + * + * @see #openFileOutput + * @see #getFilesDir + * @see #getDir + */ + public abstract File getFileStreamPath(String name); + + /** + * Returns the absolute path on the filesystem where a file created with + * {@link #getSharedPreferences(String, int)} is stored. + *

    + * The returned path may change over time if the calling app is moved to an + * adopted storage device, so only relative paths should be persisted. + * + * @param name The name of the shared preferences for which you would like to + * get a path. + * @return An absolute path to the given file. + * @see #getSharedPreferences(String, int) + * @removed + */ + public abstract File getSharedPreferencesPath(String name); + + /** + * Returns the absolute path to the directory on the filesystem where all + * private files belonging to this app are stored. Apps should not use this path + * directly; they should instead use {@link #getFilesDir()}, + * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage APIs + * on this class. + *

    + * The returned path may change over time if the calling app is moved to an + * adopted storage device, so only relative paths should be persisted. + *

    + * No additional permissions are required for the calling app to read or write + * files under the returned path. + * + * @see ApplicationInfo#dataDir + */ + public abstract File getDataDir(); + + /** + * Returns the absolute path to the directory on the filesystem where files + * created with {@link #openFileOutput} are stored. + *

    + * The returned path may change over time if the calling app is moved to an + * adopted storage device, so only relative paths should be persisted. + *

    + * No additional permissions are required for the calling app to read or write + * files under the returned path. + * + * @return The path of the directory holding application files. + * @see #openFileOutput + * @see #getFileStreamPath + * @see #getDir + */ + public abstract File getFilesDir(); + + /** + * Returns the absolute path to the directory on the filesystem similar to + * {@link #getFilesDir()}. The difference is that files placed under this + * directory will be excluded from automatic backup to remote storage. See + * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion of + * the automatic backup mechanism in Android. + *

    + * The returned path may change over time if the calling app is moved to an + * adopted storage device, so only relative paths should be persisted. + *

    + * No additional permissions are required for the calling app to read or write + * files under the returned path. + * + * @return The path of the directory holding application files that will not be + * automatically backed up to remote storage. + * @see #openFileOutput + * @see #getFileStreamPath + * @see #getDir + * @see android.app.backup.BackupAgent + */ + public abstract File getNoBackupFilesDir(); + + /** + * Returns the absolute path to the directory on the primary shared/external + * storage device where the application can place persistent files it owns. + * These files are internal to the applications, and not typically visible to + * the user as media. + *

    + * This is like {@link #getFilesDir()} in that these files will be deleted when + * the application is uninstalled, however there are some important differences: + *

    + *

    + * If a shared storage device is emulated (as determined by + * {@link Environment#isExternalStorageEmulated(File)}), it's contents are + * backed by a private user data partition, which means there is little benefit + * to storing data here instead of the private directories returned by + * {@link #getFilesDir()}, etc. + *

    + * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions are + * required to read or write to the returned path; it's always accessible to the + * calling app. This only applies to paths generated for package name of the + * calling application. To access paths belonging to other packages, + * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or + * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required. + *

    + * On devices with multiple users (as described by {@link UserManager}), each + * user has their own isolated shared storage. Applications only have access to + * the shared storage for the user they're running as. + *

    + * The returned path may change over time if different shared storage media is + * inserted, so only relative paths should be persisted. + *

    + * Here is an example of typical code to manipulate a file in an application's + * shared storage: + *

    + * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java + * private_file} + *

    + * If you supply a non-null type to this function, the returned file + * will be a path to a sub-directory of the given type. Though these files are + * not automatically scanned by the media scanner, you can explicitly add them + * to the media database with + * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener) + * MediaScannerConnection.scanFile}. Note that this is not the same as + * {@link android.os.Environment#getExternalStoragePublicDirectory + * Environment.getExternalStoragePublicDirectory()}, which provides directories + * of media shared by all applications. The directories returned here are owned + * by the application, and their contents will be removed when the application + * is uninstalled. Unlike + * {@link android.os.Environment#getExternalStoragePublicDirectory + * Environment.getExternalStoragePublicDirectory()}, the directory returned here + * will be automatically created for you. + *

    + * Here is an example of typical code to manipulate a picture in an + * application's shared storage and add it to the media database: + *

    + * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java + * private_picture} + * + * @param type The type of files directory to return. May be {@code null} for + * the root of the files directory or one of the following constants + * for a subdirectory: + * {@link android.os.Environment#DIRECTORY_MUSIC}, + * {@link android.os.Environment#DIRECTORY_PODCASTS}, + * {@link android.os.Environment#DIRECTORY_RINGTONES}, + * {@link android.os.Environment#DIRECTORY_ALARMS}, + * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS}, + * {@link android.os.Environment#DIRECTORY_PICTURES}, or + * {@link android.os.Environment#DIRECTORY_MOVIES}. + * @return the absolute path to application-specific directory. May return + * {@code null} if shared storage is not currently available. + * @see #getFilesDir + * @see #getExternalFilesDirs(String) + * @see Environment#getExternalStorageState(File) + * @see Environment#isExternalStorageEmulated(File) + * @see Environment#isExternalStorageRemovable(File) + */ + public abstract File getExternalFilesDir(String type); + + /** + * Returns absolute paths to application-specific directories on all + * shared/external storage devices where the application can place persistent + * files it owns. These files are internal to the application, and not typically + * visible to the user as media. + *

    + * This is like {@link #getFilesDir()} in that these files will be deleted when + * the application is uninstalled, however there are some important differences: + *

    + *

    + * If a shared storage device is emulated (as determined by + * {@link Environment#isExternalStorageEmulated(File)}), it's contents are + * backed by a private user data partition, which means there is little benefit + * to storing data here instead of the private directories returned by + * {@link #getFilesDir()}, etc. + *

    + * Shared storage devices returned here are considered a stable part of the + * device, including physical media slots under a protective cover. The returned + * paths do not include transient devices, such as USB flash drives connected to + * handheld devices. + *

    + * An application may store data on any or all of the returned devices. For + * example, an app may choose to store large files on the device with the most + * available space, as measured by {@link StatFs}. + *

    + * No additional permissions are required for the calling app to read or write + * files under the returned path. Write access outside of these paths on + * secondary external storage devices is not available. + *

    + * The returned path may change over time if different shared storage media is + * inserted, so only relative paths should be persisted. + * + * @param type The type of files directory to return. May be {@code null} for + * the root of the files directory or one of the following constants + * for a subdirectory: + * {@link android.os.Environment#DIRECTORY_MUSIC}, + * {@link android.os.Environment#DIRECTORY_PODCASTS}, + * {@link android.os.Environment#DIRECTORY_RINGTONES}, + * {@link android.os.Environment#DIRECTORY_ALARMS}, + * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS}, + * {@link android.os.Environment#DIRECTORY_PICTURES}, or + * {@link android.os.Environment#DIRECTORY_MOVIES}. + * @return the absolute paths to application-specific directories. Some + * individual paths may be {@code null} if that shared storage is not + * currently available. The first path returned is the same as + * {@link #getExternalFilesDir(String)}. + * @see #getExternalFilesDir(String) + * @see Environment#getExternalStorageState(File) + * @see Environment#isExternalStorageEmulated(File) + * @see Environment#isExternalStorageRemovable(File) + */ + public abstract File[] getExternalFilesDirs(String type); + + /** + * Return the primary shared/external storage directory where this application's + * OBB files (if there are any) can be found. Note if the application does not + * have any OBB files, this directory may not exist. + *

    + * This is like {@link #getFilesDir()} in that these files will be deleted when + * the application is uninstalled, however there are some important differences: + *

    + *

    + * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions are + * required to read or write to the path that this method returns. However, + * starting from {@link android.os.Build.VERSION_CODES#M}, to read the OBB + * expansion files, you must declare the + * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the + * app manifest and ask for permission at runtime as follows: + *

    + *

    + * {@code } + *

    + *

    + * Starting from {@link android.os.Build.VERSION_CODES#N}, + * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission is not + * required, so don't ask for this permission at runtime. To handle both cases, + * your app must first try to read the OBB file, and if it fails, you must + * request {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission + * at runtime. + *

    + * + *

    + * The following code snippet shows how to do this: + *

    + * + *
    +     * File obb = new File(obb_filename);
    +     * boolean open_failed = false;
    +     *
    +     * try {
    +     *     BufferedReader br = new BufferedReader(new FileReader(obb));
    +     *     open_failed = false;
    +     *     ReadObbFile(br);
    +     * } catch (IOException e) {
    +     *     open_failed = true;
    +     * }
    +     *
    +     * if (open_failed) {
    +     *     // request READ_EXTERNAL_STORAGE permission before reading OBB file
    +     *     ReadObbFileWithPermission();
    +     * }
    +     * 
    + * + * On devices with multiple users (as described by {@link UserManager}), + * multiple users may share the same OBB storage location. Applications should + * ensure that multiple instances running under different users don't interfere + * with each other. + * + * @return the absolute path to application-specific directory. May return + * {@code null} if shared storage is not currently available. + * @see #getObbDirs() + * @see Environment#getExternalStorageState(File) + * @see Environment#isExternalStorageEmulated(File) + * @see Environment#isExternalStorageRemovable(File) + */ + public abstract File getObbDir(); + + /** + * Returns absolute paths to application-specific directories on all + * shared/external storage devices where the application's OBB files (if there + * are any) can be found. Note if the application does not have any OBB files, + * these directories may not exist. + *

    + * This is like {@link #getFilesDir()} in that these files will be deleted when + * the application is uninstalled, however there are some important differences: + *

    + *

    + * Shared storage devices returned here are considered a stable part of the + * device, including physical media slots under a protective cover. The returned + * paths do not include transient devices, such as USB flash drives connected to + * handheld devices. + *

    + * An application may store data on any or all of the returned devices. For + * example, an app may choose to store large files on the device with the most + * available space, as measured by {@link StatFs}. + *

    + * No additional permissions are required for the calling app to read or write + * files under the returned path. Write access outside of these paths on + * secondary external storage devices is not available. + * + * @return the absolute paths to application-specific directories. Some + * individual paths may be {@code null} if that shared storage is not + * currently available. The first path returned is the same as + * {@link #getObbDir()} + * @see #getObbDir() + * @see Environment#getExternalStorageState(File) + * @see Environment#isExternalStorageEmulated(File) + * @see Environment#isExternalStorageRemovable(File) + */ + public abstract File[] getObbDirs(); + + /** + * Returns the absolute path to the application specific cache directory on the + * filesystem. + *

    + * The system will automatically delete files in this directory as disk space is + * needed elsewhere on the device. The system will always delete older files + * first, as reported by {@link File#lastModified()}. If desired, you can exert + * more control over how files are deleted using + * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and + * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}. + *

    + * Apps are strongly encouraged to keep their usage of cache space below the + * quota returned by {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. + * If your app goes above this quota, your cached files will be some of the + * first to be deleted when additional disk space is needed. Conversely, if your + * app stays under this quota, your cached files will be some of the last to be + * deleted when additional disk space is needed. + *

    + * Note that your cache quota will change over time depending on how frequently + * the user interacts with your app, and depending on how much system-wide disk + * space is used. + *

    + * The returned path may change over time if the calling app is moved to an + * adopted storage device, so only relative paths should be persisted. + *

    + * Apps require no extra permissions to read or write to the returned path, + * since this path lives in their private storage. + * + * @return The path of the directory holding application cache files. + * @see #openFileOutput + * @see #getFileStreamPath + * @see #getDir + * @see #getExternalCacheDir + */ + public abstract File getCacheDir(); + + /** + * Returns the absolute path to the application specific cache directory on the + * filesystem designed for storing cached code. + *

    + * The system will delete any files stored in this location both when your + * specific application is upgraded, and when the entire platform is upgraded. + *

    + * This location is optimal for storing compiled or optimized code generated by + * your application at runtime. + *

    + * The returned path may change over time if the calling app is moved to an + * adopted storage device, so only relative paths should be persisted. + *

    + * Apps require no extra permissions to read or write to the returned path, + * since this path lives in their private storage. + * + * @return The path of the directory holding application code cache files. + */ + public abstract File getCodeCacheDir(); + + /** + * Returns absolute path to application-specific directory on the primary + * shared/external storage device where the application can place cache files it + * owns. These files are internal to the application, and not typically visible + * to the user as media. + *

    + * This is like {@link #getCacheDir()} in that these files will be deleted when + * the application is uninstalled, however there are some important differences: + *

    + *

    + * If a shared storage device is emulated (as determined by + * {@link Environment#isExternalStorageEmulated(File)}), its contents are backed + * by a private user data partition, which means there is little benefit to + * storing data here instead of the private directory returned by + * {@link #getCacheDir()}. + *

    + * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions are + * required to read or write to the returned path; it's always accessible to the + * calling app. This only applies to paths generated for package name of the + * calling application. To access paths belonging to other packages, + * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or + * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required. + *

    + * On devices with multiple users (as described by {@link UserManager}), each + * user has their own isolated shared storage. Applications only have access to + * the shared storage for the user they're running as. + *

    + * The returned path may change over time if different shared storage media is + * inserted, so only relative paths should be persisted. + * + * @return the absolute path to application-specific directory. May return + * {@code null} if shared storage is not currently available. + * @see #getCacheDir + * @see #getExternalCacheDirs() + * @see Environment#getExternalStorageState(File) + * @see Environment#isExternalStorageEmulated(File) + * @see Environment#isExternalStorageRemovable(File) + */ + public abstract File getExternalCacheDir(); + + /** + * Returns absolute path to application-specific directory in the preloaded + * cache. + *

    + * Files stored in the cache directory can be deleted when the device runs low + * on storage. There is no guarantee when these files will be deleted. + * + * @hide + */ + public abstract File getPreloadsFileCache(); + + /** + * Returns absolute paths to application-specific directories on all + * shared/external storage devices where the application can place cache files + * it owns. These files are internal to the application, and not typically + * visible to the user as media. + *

    + * This is like {@link #getCacheDir()} in that these files will be deleted when + * the application is uninstalled, however there are some important differences: + *

    + *

    + * If a shared storage device is emulated (as determined by + * {@link Environment#isExternalStorageEmulated(File)}), it's contents are + * backed by a private user data partition, which means there is little benefit + * to storing data here instead of the private directory returned by + * {@link #getCacheDir()}. + *

    + * Shared storage devices returned here are considered a stable part of the + * device, including physical media slots under a protective cover. The returned + * paths do not include transient devices, such as USB flash drives connected to + * handheld devices. + *

    + * An application may store data on any or all of the returned devices. For + * example, an app may choose to store large files on the device with the most + * available space, as measured by {@link StatFs}. + *

    + * No additional permissions are required for the calling app to read or write + * files under the returned path. Write access outside of these paths on + * secondary external storage devices is not available. + *

    + * The returned paths may change over time if different shared storage media is + * inserted, so only relative paths should be persisted. + * + * @return the absolute paths to application-specific directories. Some + * individual paths may be {@code null} if that shared storage is not + * currently available. The first path returned is the same as + * {@link #getExternalCacheDir()}. + * @see #getExternalCacheDir() + * @see Environment#getExternalStorageState(File) + * @see Environment#isExternalStorageEmulated(File) + * @see Environment#isExternalStorageRemovable(File) + */ + public abstract File[] getExternalCacheDirs(); + + /** + * Returns absolute paths to application-specific directories on all + * shared/external storage devices where the application can place media files. + * These files are scanned and made available to other apps through + * {@link MediaStore}. + *

    + * This is like {@link #getExternalFilesDirs} in that these files will be + * deleted when the application is uninstalled, however there are some important + * differences: + *

    + *

    + * Shared storage devices returned here are considered a stable part of the + * device, including physical media slots under a protective cover. The returned + * paths do not include transient devices, such as USB flash drives connected to + * handheld devices. + *

    + * An application may store data on any or all of the returned devices. For + * example, an app may choose to store large files on the device with the most + * available space, as measured by {@link StatFs}. + *

    + * No additional permissions are required for the calling app to read or write + * files under the returned path. Write access outside of these paths on + * secondary external storage devices is not available. + *

    + * The returned paths may change over time if different shared storage media is + * inserted, so only relative paths should be persisted. + * + * @return the absolute paths to application-specific directories. Some + * individual paths may be {@code null} if that shared storage is not + * currently available. + * @see Environment#getExternalStorageState(File) + * @see Environment#isExternalStorageEmulated(File) + * @see Environment#isExternalStorageRemovable(File) + */ + public abstract File[] getExternalMediaDirs(); + + /** + * Returns an array of strings naming the private files associated with this + * Context's application package. + * + * @return Array of strings naming the private files. + * + * @see #openFileInput + * @see #openFileOutput + * @see #deleteFile + */ + public abstract String[] fileList(); + + /** + * Retrieve, creating if needed, a new directory in which the application can + * place its own custom data files. You can use the returned File object to + * create and access files in this directory. Note that files created through a + * File object will only be accessible by your own application; you can only set + * the mode of the entire directory, not of individual files. + *

    + * The returned path may change over time if the calling app is moved to an + * adopted storage device, so only relative paths should be persisted. + *

    + * Apps require no extra permissions to read or write to the returned path, + * since this path lives in their private storage. + * + * @param name Name of the directory to retrieve. This is a directory that is + * created as part of your application data. + * @param mode Operating mode. + * + * @return A {@link File} object for the requested directory. The directory will + * have been created if it does not already exist. + * + * @see #openFileOutput(String, int) + */ + public abstract File getDir(String name, int mode); + + /** + * Same as {@link #startActivity(Intent, Bundle)} with no options specified. + * + * @param intent The description of the activity to start. + * + * @throws ActivityNotFoundException   ` + * @see #startActivity(Intent, Bundle) + * @see PackageManager#resolveActivity + */ + public abstract void startActivity(Intent intent); + + /** + * Launch a new activity. You will not receive any information about when the + * activity exits. + * + *

    + * Note that if this method is being called from outside of an + * {@link android.app.Activity} Context, then the Intent must include the + * {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because, without + * being started from an existing Activity, there is no existing task in which + * to place the new activity and thus it needs to be placed in its own separate + * task. + * + *

    + * This method throws {@link ActivityNotFoundException} if there was no Activity + * found to run the given Intent. + * + * @param intent The description of the activity to start. + * @param options Additional options for how the Activity should be started. May + * be null if there are no options. See + * {@link android.app.ActivityOptions} for how to build the + * Bundle supplied here; there are no supported definitions for + * building it manually. + * + * @throws ActivityNotFoundException   + * + * @see #startActivity(Intent) + * @see PackageManager#resolveActivity + */ + public abstract void startActivity(Intent intent, Bundle options); + + /** + * Identifies whether this Context instance will be able to process calls to + * {@link #startActivityForResult(String, Intent, int, Bundle)}. + * + * @hide + */ + public boolean canStartActivityForResult() { + return false; + } + + /** + * Same as {@link #startActivities(Intent[], Bundle)} with no options specified. + * + * @param intents An array of Intents to be started. + * + * @throws ActivityNotFoundException   + * + * @see #startActivities(Intent[], Bundle) + * @see PackageManager#resolveActivity + */ + public abstract void startActivities(Intent[] intents); + + /** + * Launch multiple new activities. This is generally the same as calling + * {@link #startActivity(Intent)} for the first Intent in the array, that + * activity during its creation calling {@link #startActivity(Intent)} for the + * second entry, etc. Note that unlike that approach, generally none of the + * activities except the last in the array will be created at this point, but + * rather will be created when the user first visits them (due to pressing back + * from the activity on top). + * + *

    + * This method throws {@link ActivityNotFoundException} if there was no Activity + * found for any given Intent. In this case the state of the activity + * stack is undefined (some Intents in the list may be on it, some not), so you + * probably want to avoid such situations. + * + * @param intents An array of Intents to be started. + * @param options Additional options for how the Activity should be started. See + * {@link android.content.Context#startActivity(Intent, Bundle)} + * Context.startActivity(Intent, Bundle)} for more details. + * + * @throws ActivityNotFoundException   + * + * @see #startActivities(Intent[]) + * @see PackageManager#resolveActivity + */ + public abstract void startActivities(Intent[] intents, Bundle options); + + /** + * Broadcast the given intent to all interested BroadcastReceivers. This call is + * asynchronous; it returns immediately, and you will continue executing while + * the receivers are run. No results are propagated from receivers and receivers + * can not abort the broadcast. If you want to allow receivers to propagate + * results or abort the broadcast, you must send an ordered broadcast using + * {@link #sendOrderedBroadcast(Intent, String)}. + * + *

    + * See {@link BroadcastReceiver} for more information on Intent broadcasts. + * + * @param intent The Intent to broadcast; all receivers matching this Intent + * will receive the broadcast. + * + * @see android.content.BroadcastReceiver + * @see #registerReceiver + * @see #sendBroadcast(Intent, String) + * @see #sendOrderedBroadcast(Intent, String) + * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, + * String, Bundle) + */ + public abstract void sendBroadcast(Intent intent); + + /** + * Broadcast the given intent to all interested BroadcastReceivers, allowing an + * optional required permission to be enforced. This call is asynchronous; it + * returns immediately, and you will continue executing while the receivers are + * run. No results are propagated from receivers and receivers can not abort the + * broadcast. If you want to allow receivers to propagate results or abort the + * broadcast, you must send an ordered broadcast using + * {@link #sendOrderedBroadcast(Intent, String)}. + * + *

    + * See {@link BroadcastReceiver} for more information on Intent broadcasts. + * + * @param intent The Intent to broadcast; all receivers matching + * this Intent will receive the broadcast. + * @param receiverPermission (optional) String naming a permission that a + * receiver must hold in order to receive your + * broadcast. If null, no permission is required. + * + * @see android.content.BroadcastReceiver + * @see #registerReceiver + * @see #sendBroadcast(Intent) + * @see #sendOrderedBroadcast(Intent, String) + * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, + * String, Bundle) + */ + public abstract void sendBroadcast(Intent intent, String receiverPermission); + + /** + * Like {@link #sendBroadcast(Intent, String)}, but also allows specification of + * an associated app op as per {@link android.app.AppOpsManager}. + * + * @hide + */ + public abstract void sendBroadcast(Intent intent, String receiverPermission, int appOp); +} \ No newline at end of file diff --git a/java/ql/test/stubs/google-android-9.0.0/android/content/Intent.java b/java/ql/test/stubs/google-android-9.0.0/android/content/Intent.java new file mode 100644 index 000000000000..e3ef6277dbad --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/content/Intent.java @@ -0,0 +1,1999 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.content; + +import android.net.Uri; +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Serializable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Objects; +import java.util.Set; + +/** + * An intent is an abstract description of an operation to be performed. It can + * be used with {@link Context#startActivity(Intent) startActivity} to launch an + * {@link android.app.Activity}, + * {@link android.content.Context#sendBroadcast(Intent) broadcastIntent} to send + * it to any interested {@link BroadcastReceiver BroadcastReceiver} components, + * and {@link android.content.Context#startService} or + * {@link android.content.Context#bindService} to communicate with a background + * {@link android.app.Service}. + * + *

    + * An Intent provides a facility for performing late runtime binding between the + * code in different applications. Its most significant use is in the launching + * of activities, where it can be thought of as the glue between activities. It + * is basically a passive data structure holding an abstract description of an + * action to be performed. + *

    + * + *
    + *

    Developer Guides

    + *

    + * For information about how to create and resolve intents, read the + * Intents and + * Intent Filters developer guide. + *

    + *
    + * + * + *

    Intent Structure

    + *

    + * The primary pieces of information in an intent are: + *

    + * + * + * + * + *

    + * Some examples of action/data pairs are: + *

    + * + * + * + *

    + * In addition to these primary attributes, there are a number of secondary + * attributes that you can also include with an intent: + *

    + * + * + * + *

    + * Here are some examples of other operations you can specify as intents using + * these additional parameters: + *

    + * + * + * + *

    + * There are a variety of standard Intent action and category constants defined + * in the Intent class, but applications can also define their own. These + * strings use Java-style scoping, to ensure they are unique -- for example, the + * standard {@link #ACTION_VIEW} is called "android.intent.action.VIEW". + *

    + * + *

    + * Put together, the set of actions, data types, categories, and extra data + * defines a language for the system allowing for the expression of phrases such + * as "call john smith's cell". As applications are added to the system, they + * can extend this language by adding new actions, types, and categories, or + * they can modify the behavior of existing phrases by supplying their own + * activities that handle them. + *

    + * + * + *

    Intent Resolution

    + * + *

    + * There are two primary forms of intents you will use. + * + *

    + * + *

    + * When using implicit intents, given such an arbitrary intent we need to know + * what to do with it. This is handled by the process of Intent + * resolution, which maps an Intent to an {@link android.app.Activity}, + * {@link BroadcastReceiver}, or {@link android.app.Service} (or sometimes two + * or more activities/receivers) that can handle it. + *

    + * + *

    + * The intent resolution mechanism basically revolves around matching an Intent + * against all of the <intent-filter> descriptions in the installed + * application packages. (Plus, in the case of broadcasts, any + * {@link BroadcastReceiver} objects explicitly registered with + * {@link Context#registerReceiver}.) More details on this can be found in the + * documentation on the {@link IntentFilter} class. + *

    + * + *

    + * There are three pieces of information in the Intent that are used for + * resolution: the action, type, and category. Using this information, a query + * is done on the {@link PackageManager} for a component that can handle the + * intent. The appropriate component is determined based on the intent + * information supplied in the AndroidManifest.xml file as follows: + *

    + * + * + * + *

    + * For example, consider the Note Pad sample application that allows a user to + * browse through a list of notes data and view details about individual items. + * Text in italics indicates places where you would replace a name with one + * specific to your own package. + *

    + * + *
    + *  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    + *       package="com.android.notepad">
    + *     <application android:icon="@drawable/app_notes"
    + *             android:label="@string/app_name">
    + *
    + *         <provider class=".NotePadProvider"
    + *                 android:authorities="com.google.provider.NotePad" />
    + *
    + *         <activity class=".NotesList" android:label="@string/title_notes_list">
    + *             <intent-filter>
    + *                 <action android:name="android.intent.action.MAIN" />
    + *                 <category android:name="android.intent.category.LAUNCHER" />
    + *             </intent-filter>
    + *             <intent-filter>
    + *                 <action android:name="android.intent.action.VIEW" />
    + *                 <action android:name="android.intent.action.EDIT" />
    + *                 <action android:name="android.intent.action.PICK" />
    + *                 <category android:name="android.intent.category.DEFAULT" />
    + *                 <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
    + *             </intent-filter>
    + *             <intent-filter>
    + *                 <action android:name="android.intent.action.GET_CONTENT" />
    + *                 <category android:name="android.intent.category.DEFAULT" />
    + *                 <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
    + *             </intent-filter>
    + *         </activity>
    + *
    + *         <activity class=".NoteEditor" android:label="@string/title_note">
    + *             <intent-filter android:label="@string/resolve_edit">
    + *                 <action android:name="android.intent.action.VIEW" />
    + *                 <action android:name="android.intent.action.EDIT" />
    + *                 <category android:name="android.intent.category.DEFAULT" />
    + *                 <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
    + *             </intent-filter>
    + *
    + *             <intent-filter>
    + *                 <action android:name="android.intent.action.INSERT" />
    + *                 <category android:name="android.intent.category.DEFAULT" />
    + *                 <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
    + *             </intent-filter>
    + *
    + *         </activity>
    + *
    + *         <activity class=".TitleEditor" android:label="@string/title_edit_title"
    + *                 android:theme="@android:style/Theme.Dialog">
    + *             <intent-filter android:label="@string/resolve_title">
    + *                 <action android:name="com.android.notepad.action.EDIT_TITLE" />
    + *                 <category android:name="android.intent.category.DEFAULT" />
    + *                 <category android:name="android.intent.category.ALTERNATIVE" />
    + *                 <category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
    + *                 <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
    + *             </intent-filter>
    + *         </activity>
    + *
    + *     </application>
    + * </manifest>
    + * 
    + * + *

    + * The first activity, com.android.notepad.NotesList, serves as our + * main entry into the app. It can do three things as described by its three + * intent templates: + *

      + *
    1. + * + *
      + * <intent-filter>
      + *     <action android:name="{@link #ACTION_MAIN android.intent.action.MAIN}" />
      + *     <category android:name="{@link #CATEGORY_LAUNCHER android.intent.category.LAUNCHER}" />
      + * </intent-filter>
      + * 
      + *

      + * This provides a top-level entry into the NotePad application: the standard + * MAIN action is a main entry point (not requiring any other information in the + * Intent), and the LAUNCHER category says that this entry point should be + * listed in the application launcher. + *

      + *
    2. + * + *
      + * <intent-filter>
      + *     <action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" />
      + *     <action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" />
      + *     <action android:name="{@link #ACTION_PICK android.intent.action.PICK}" />
      + *     <category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" />
      + *     <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
      + * </intent-filter>
      + * 
      + *

      + * This declares the things that the activity can do on a directory of notes. + * The type being supported is given with the <type> tag, where + * vnd.android.cursor.dir/vnd.google.note is a URI from which a + * Cursor of zero or more items (vnd.android.cursor.dir) can be + * retrieved which holds our note pad data (vnd.google.note). The + * activity allows the user to view or edit the directory of data (via the VIEW + * and EDIT actions), or to pick a particular note and return it to the caller + * (via the PICK action). Note also the DEFAULT category supplied here: this is + * required for the {@link Context#startActivity Context.startActivity} + * method to resolve your activity when its component name is not explicitly + * specified. + *

      + *
    3. + * + *
      + * <intent-filter>
      + *     <action android:name="{@link #ACTION_GET_CONTENT android.intent.action.GET_CONTENT}" />
      + *     <category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" />
      + *     <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
      + * </intent-filter>
      + * 
      + *

      + * This filter describes the ability to return to the caller a note selected by + * the user without needing to know where it came from. The data type + * vnd.android.cursor.item/vnd.google.note is a URI from which a + * Cursor of exactly one (vnd.android.cursor.item) item can be + * retrieved which contains our note pad data (vnd.google.note). + * The GET_CONTENT action is similar to the PICK action, where the activity will + * return to its caller a piece of data selected by the user. Here, however, the + * caller specifies the type of data they desire instead of the type of data the + * user will be picking from. + *

      + *
    + * + *

    + * Given these capabilities, the following intents will resolve to the NotesList + * activity: + *

    + * + * + * + *

    + * The second activity, com.android.notepad.NoteEditor, shows the + * user a single note entry and allows them to edit it. It can do two things as + * described by its two intent templates: + *

      + *
    1. + * + *
      + * <intent-filter android:label="@string/resolve_edit">
      + *     <action android:name="{@link #ACTION_VIEW android.intent.action.VIEW}" />
      + *     <action android:name="{@link #ACTION_EDIT android.intent.action.EDIT}" />
      + *     <category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" />
      + *     <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
      + * </intent-filter>
      + * 
      + *

      + * The first, primary, purpose of this activity is to let the user interact with + * a single note, as decribed by the MIME type + * vnd.android.cursor.item/vnd.google.note. The activity can either + * VIEW a note or allow the user to EDIT it. Again we support the DEFAULT + * category to allow the activity to be launched without explicitly specifying + * its component. + *

      + *
    2. + * + *
      + * <intent-filter>
      + *     <action android:name="{@link #ACTION_INSERT android.intent.action.INSERT}" />
      + *     <category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" />
      + *     <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
      + * </intent-filter>
      + * 
      + *

      + * The secondary use of this activity is to insert a new note entry into an + * existing directory of notes. This is used when the user creates a new note: + * the INSERT action is executed on the directory of notes, causing this + * activity to run and have the user create the new note data which it then adds + * to the content provider. + *

      + *
    + * + *

    + * Given these capabilities, the following intents will resolve to the + * NoteEditor activity: + *

    + * + * + * + *

    + * The last activity, com.android.notepad.TitleEditor, allows the + * user to edit the title of a note. This could be implemented as a class that + * the application directly invokes (by explicitly setting its component in the + * Intent), but here we show a way you can publish alternative operations on + * existing data: + *

    + * + *
    + * <intent-filter android:label="@string/resolve_title">
    + *     <action android:name="com.android.notepad.action.EDIT_TITLE" />
    + *     <category android:name="{@link #CATEGORY_DEFAULT android.intent.category.DEFAULT}" />
    + *     <category android:name="{@link #CATEGORY_ALTERNATIVE android.intent.category.ALTERNATIVE}" />
    + *     <category android:name="{@link #CATEGORY_SELECTED_ALTERNATIVE android.intent.category.SELECTED_ALTERNATIVE}" />
    + *     <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
    + * </intent-filter>
    + * 
    + * + *

    + * In the single intent template here, we have created our own private action + * called com.android.notepad.action.EDIT_TITLE which means to edit + * the title of a note. It must be invoked on a specific note (data type + * vnd.android.cursor.item/vnd.google.note) like the previous view + * and edit actions, but here displays and edits the title contained in the note + * data. + * + *

    + * In addition to supporting the default category as usual, our title editor + * also supports two other standard categories: ALTERNATIVE and + * SELECTED_ALTERNATIVE. Implementing these categories allows others to find the + * special action it provides without directly knowing about it, through the + * {@link android.content.pm.PackageManager#queryIntentActivityOptions} method, + * or more often to build dynamic menu items with + * {@link android.view.Menu#addIntentOptions}. Note that in the intent template + * here was also supply an explicit name for the template (via + * android:label="@string/resolve_title") to better control what + * the user sees when presented with this activity as an alternative action to + * the data they are viewing. + * + *

    + * Given these capabilities, the following intent will resolve to the + * TitleEditor activity: + *

    + * + * + * + *

    Standard Activity Actions

    + * + *

    + * These are the current standard actions that Intent defines for launching + * activities (usually through {@link Context#startActivity}. The most + * important, and by far most frequently used, are {@link #ACTION_MAIN} and + * {@link #ACTION_EDIT}. + * + *

    + * + *

    Standard Broadcast Actions

    + * + *

    + * These are the current standard actions that Intent defines for receiving + * broadcasts (usually through {@link Context#registerReceiver} or a + * <receiver> tag in a manifest). + * + *

    + * + *

    Standard Categories

    + * + *

    + * These are the current standard categories that can be used to further clarify + * an Intent via {@link #addCategory}. + * + *

    + * + *

    Standard Extra Data

    + * + *

    + * These are the current standard fields that can be used as extra data via + * {@link #putExtra}. + * + *

    + * + *

    Flags

    + * + *

    + * These are the possible flags that can be used in the Intent via + * {@link #setFlags} and {@link #addFlags}. See {@link #setFlags} for a list of + * all possible flags. + */ +public class Intent implements Parcelable, Cloneable { + + /** + * Create an empty intent. + */ + public Intent() { + } + + /** + * Copy constructor. + */ + public Intent(Intent o) { + } + + /** + * Create an intent with a given action. All other fields (data, type, class) + * are null. Note that the action must be in a namespace because + * Intents are used globally in the system -- for example the system VIEW action + * is android.intent.action.VIEW; an application's custom action would be + * something like com.google.app.myapp.CUSTOM_ACTION. + * + * @param action The Intent action, such as ACTION_VIEW. + */ + public Intent(String action) { + } + + /** + * Create an intent with a given action and for a given data url. Note that the + * action must be in a namespace because Intents are used globally in + * the system -- for example the system VIEW action is + * android.intent.action.VIEW; an application's custom action would be something + * like com.google.app.myapp.CUSTOM_ACTION. + * + *

    + * Note: scheme and host name matching in the Android framework is + * case-sensitive, unlike the formal RFC. As a result, you should always ensure + * that you write your Uri with these elements using lower case letters, and + * normalize any Uris you receive from outside of Android to ensure the scheme + * and host is lower case. + *

    + * + * @param action The Intent action, such as ACTION_VIEW. + * @param uri The Intent data URI. + */ + public Intent(String action, Uri uri) { + } + + /** + * Create an intent for a specific component. All other fields (action, data, + * type, class) are null, though they can be modified later with explicit calls. + * This provides a convenient way to create an intent that is intended to + * execute a hard-coded class name, rather than relying on the system to find an + * appropriate class for you; see {@link #setComponent} for more information on + * the repercussions of this. + * + * @param packageContext A Context of the application package implementing this + * class. + * @param cls The component class that is to be used for the intent. + * + * @see #setClass + * @see #setComponent + * @see #Intent(String, android.net.Uri , Context, Class) + */ + public Intent(Context packageContext, Class cls) { + } + + /** + * Create an intent for a specific component with a specified action and data. + * This is equivalent to using {@link #Intent(String, android.net.Uri)} to + * construct the Intent and then calling {@link #setClass} to set its class. + * + *

    + * Note: scheme and host name matching in the Android framework is + * case-sensitive, unlike the formal RFC. As a result, you should always ensure + * that you write your Uri with these elements using lower case letters, and + * normalize any Uris you receive from outside of Android to ensure the scheme + * and host is lower case. + *

    + * + * @param action The Intent action, such as ACTION_VIEW. + * @param uri The Intent data URI. + * @param packageContext A Context of the application package implementing this + * class. + * @param cls The component class that is to be used for the intent. + * + * @see #Intent(String, android.net.Uri) + * @see #Intent(Context, Class) + * @see #setClass + * @see #setComponent + */ + public Intent(String action, Uri uri, Context packageContext, Class cls) { + } + + /** + * Call {@link #parseUri} with 0 flags. + * + * @deprecated Use {@link #parseUri} instead. + */ + @Deprecated + public static Intent getIntent(String uri) { + } + + /** + * Create an intent from a URI. This URI may encode the action, category, and + * other intent fields, if it was returned by {@link #toUri}. If the Intent was + * not generate by toUri(), its data will be the entire URI and its action will + * be ACTION_VIEW. + * + *

    + * The URI given here must not be relative -- that is, it must include the + * scheme and full path. + * + * @param uri The URI to turn into an Intent. + * @param flags Additional processing flags. + * + * @return Intent The newly created Intent object. + * + * @throws URISyntaxException Throws URISyntaxError if the basic URI syntax it + * bad (as parsed by the Uri class) or the Intent + * data within the URI is invalid. + * + * @see #toUri + */ + public static Intent parseUri(String uri, int flags) { + } + + /** + * Retrieve the general action to be performed, such as {@link #ACTION_VIEW}. + * The action describes the general way the rest of the information in the + * intent should be interpreted -- most importantly, what to do with the data + * returned by {@link #getData}. + * + * @return The action of this intent or null if none is specified. + * + * @see #setAction + */ + public String getAction() { + return null; + } + + /** + * Retrieve data this intent is operating on. This URI specifies the name of the + * data; often it uses the content: scheme, specifying data in a content + * provider. Other schemes may be handled by specific activities, such as http: + * by the web browser. + * + * @return The URI of the data this intent is targeting or null. + * + * @see #getScheme + * @see #setData + */ + public Uri getData() { + return null; + } + + /** + * The same as {@link #getData()}, but returns the URI as an encoded String. + */ + public String getDataString() { + return null; + } + + /** + * Return the scheme portion of the intent's data. If the data is null or does + * not include a scheme, null is returned. Otherwise, the scheme prefix without + * the final ':' is returned, i.e. "http". + * + *

    + * This is the same as calling getData().getScheme() (and checking for null + * data). + * + * @return The scheme of this intent. + * + * @see #getData + */ + public String getScheme() { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if + * none was found. + * + * @deprecated + * @hide + */ + @Deprecated + public Object getExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param defaultValue the value to be returned if no value of the desired type + * is stored with the given name. + * + * @return the value of an item previously added with putExtra(), or the default + * value if none was found. + * + * @see #putExtra(String, boolean) + */ + public boolean getBooleanExtra(String name, boolean defaultValue) { + return false; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param defaultValue the value to be returned if no value of the desired type + * is stored with the given name. + * + * @return the value of an item previously added with putExtra(), or the default + * value if none was found. + * + * @see #putExtra(String, byte) + */ + public byte getByteExtra(String name, byte defaultValue) { + return -1; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param defaultValue the value to be returned if no value of the desired type + * is stored with the given name. + * + * @return the value of an item previously added with putExtra(), or the default + * value if none was found. + * + * @see #putExtra(String, short) + */ + public short getShortExtra(String name, short defaultValue) { + return -1; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param defaultValue the value to be returned if no value of the desired type + * is stored with the given name. + * + * @return the value of an item previously added with putExtra(), or the default + * value if none was found. + * + * @see #putExtra(String, char) + */ + public char getCharExtra(String name, char defaultValue) { + return 'a'; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param defaultValue the value to be returned if no value of the desired type + * is stored with the given name. + * + * @return the value of an item previously added with putExtra(), or the default + * value if none was found. + * + * @see #putExtra(String, int) + */ + public int getIntExtra(String name, int defaultValue) { + return -1; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param defaultValue the value to be returned if no value of the desired type + * is stored with the given name. + * + * @return the value of an item previously added with putExtra(), or the default + * value if none was found. + * + * @see #putExtra(String, long) + */ + public long getLongExtra(String name, long defaultValue) { + return -1; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param defaultValue the value to be returned if no value of the desired type + * is stored with the given name. + * + * @return the value of an item previously added with putExtra(), or the default + * value if no such item is present + * + * @see #putExtra(String, float) + */ + public float getFloatExtra(String name, float defaultValue) { + return -1; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param defaultValue the value to be returned if no value of the desired type + * is stored with the given name. + * + * @return the value of an item previously added with putExtra(), or the default + * value if none was found. + * + * @see #putExtra(String, double) + */ + public double getDoubleExtra(String name, double defaultValue) { + return -1; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * String value was found. + * + * @see #putExtra(String, String) + */ + public String getStringExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * CharSequence value was found. + * + * @see #putExtra(String, CharSequence) + */ + public CharSequence getCharSequenceExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * Parcelable value was found. + * + * @see #putExtra(String, Parcelable) + */ + public T getParcelableExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * Parcelable[] value was found. + * + * @see #putExtra(String, Parcelable[]) + */ + public Parcelable[] getParcelableArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with + * putParcelableArrayListExtra(), or null if no ArrayList + * value was found. + * + * @see #putParcelableArrayListExtra(String, ArrayList) + */ + public ArrayList getParcelableArrayListExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * Serializable value was found. + * + * @see #putExtra(String, Serializable) + */ + public Serializable getSerializableExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with + * putIntegerArrayListExtra(), or null if no ArrayList value + * was found. + * + * @see #putIntegerArrayListExtra(String, ArrayList) + */ + public ArrayList getIntegerArrayListExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putStringArrayListExtra(), + * or null if no ArrayList value was found. + * + * @see #putStringArrayListExtra(String, ArrayList) + */ + public ArrayList getStringArrayListExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with + * putCharSequenceArrayListExtra, or null if no ArrayList + * value was found. + * + * @see #putCharSequenceArrayListExtra(String, ArrayList) + */ + public ArrayList getCharSequenceArrayListExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * boolean array value was found. + * + * @see #putExtra(String, boolean[]) + */ + public boolean[] getBooleanArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * byte array value was found. + * + * @see #putExtra(String, byte[]) + */ + public byte[] getByteArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * short array value was found. + * + * @see #putExtra(String, short[]) + */ + public short[] getShortArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * char array value was found. + * + * @see #putExtra(String, char[]) + */ + public char[] getCharArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * int array value was found. + * + * @see #putExtra(String, int[]) + */ + public int[] getIntArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * long array value was found. + * + * @see #putExtra(String, long[]) + */ + public long[] getLongArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * float array value was found. + * + * @see #putExtra(String, float[]) + */ + public float[] getFloatArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * double array value was found. + * + * @see #putExtra(String, double[]) + */ + public double[] getDoubleArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * String array value was found. + * + * @see #putExtra(String, String[]) + */ + public String[] getStringArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * CharSequence array value was found. + * + * @see #putExtra(String, CharSequence[]) + */ + public CharSequence[] getCharSequenceArrayExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * + * @return the value of an item previously added with putExtra(), or null if no + * Bundle value was found. + * + * @see #putExtra(String, Bundle) + */ + public Bundle getBundleExtra(String name) { + return null; + } + + /** + * Retrieve extended data from the intent. + * + * @param name The name of the desired item. + * @param defaultValue The default value to return in case no item is associated + * with the key 'name' + * + * @return the value of an item previously added with putExtra(), or + * defaultValue if none was found. + * + * @see #putExtra + * + * @deprecated + * @hide + */ + @Deprecated + public Object getExtra(String name, Object defaultValue) { + return null; + } + + /** + * Retrieves a map of extended data from the intent. + * + * @return the map of all extras previously added with putExtra(), or null if + * none have been added. + */ + public Bundle getExtras() { + return null; + } + + /** + * Filter extras to only basic types. + * + * @hide + */ + public void removeUnsafeExtras() { + } + + /** + * Set the general action to be performed. + * + * @param action An action name, such as ACTION_VIEW. Application-specific + * actions should be prefixed with the vendor's package name. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #getAction + */ + public Intent setAction(String action) { + return null; + } + + /** + * Set the data this intent is operating on. This method automatically clears + * any type that was previously set by {@link #setType} or + * {@link #setTypeAndNormalize}. + * + *

    + * Note: scheme matching in the Android framework is case-sensitive, unlike + * the formal RFC. As a result, you should always write your Uri with a lower + * case scheme, or use {@link Uri#normalizeScheme} or + * {@link #setDataAndNormalize} to ensure that the scheme is converted to lower + * case. + * + * @param data The Uri of the data this intent is now targeting. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #getData + * @see #setDataAndNormalize + * @see android.net.Uri#normalizeScheme() + */ + public Intent setData(Uri data) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The boolean data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getBooleanExtra(String, boolean) + */ + public Intent putExtra(String name, boolean value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The byte data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getByteExtra(String, byte) + */ + public Intent putExtra(String name, byte value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The char data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getCharExtra(String, char) + */ + public Intent putExtra(String name, char value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The short data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getShortExtra(String, short) + */ + public Intent putExtra(String name, short value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The integer data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getIntExtra(String, int) + */ + public Intent putExtra(String name, int value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The long data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getLongExtra(String, long) + */ + public Intent putExtra(String name, long value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The float data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getFloatExtra(String, float) + */ + public Intent putExtra(String name, float value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The double data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getDoubleExtra(String, double) + */ + public Intent putExtra(String name, double value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The String data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getStringExtra(String) + */ + public Intent putExtra(String name, String value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The CharSequence data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getCharSequenceExtra(String) + */ + public Intent putExtra(String name, CharSequence value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The Parcelable data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getParcelableExtra(String) + */ + public Intent putExtra(String name, Parcelable value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The Parcelable[] data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getParcelableArrayExtra(String) + */ + public Intent putExtra(String name, Parcelable[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The ArrayList data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getParcelableArrayListExtra(String) + */ + public Intent putParcelableArrayListExtra(String name, ArrayList value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The ArrayList data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getIntegerArrayListExtra(String) + */ + public Intent putIntegerArrayListExtra(String name, ArrayList value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The ArrayList data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getStringArrayListExtra(String) + */ + public Intent putStringArrayListExtra(String name, ArrayList value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The ArrayList data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getCharSequenceArrayListExtra(String) + */ + public Intent putCharSequenceArrayListExtra(String name, ArrayList value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The Serializable data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getSerializableExtra(String) + */ + public Intent putExtra(String name, Serializable value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The boolean array data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getBooleanArrayExtra(String) + */ + public Intent putExtra(String name, boolean[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The byte array data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getByteArrayExtra(String) + */ + public Intent putExtra(String name, byte[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The short array data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getShortArrayExtra(String) + */ + public Intent putExtra(String name, short[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The char array data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getCharArrayExtra(String) + */ + public Intent putExtra(String name, char[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The int array data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getIntArrayExtra(String) + */ + public Intent putExtra(String name, int[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The byte array data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getLongArrayExtra(String) + */ + public Intent putExtra(String name, long[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The float array data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getFloatArrayExtra(String) + */ + public Intent putExtra(String name, float[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The double array data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getDoubleArrayExtra(String) + */ + public Intent putExtra(String name, double[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The String array data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getStringArrayExtra(String) + */ + public Intent putExtra(String name, String[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The CharSequence array data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getCharSequenceArrayExtra(String) + */ + public Intent putExtra(String name, CharSequence[] value) { + return null; + } + + /** + * Add extended data to the intent. The name must include a package prefix, for + * example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param name The name of the extra data, with package prefix. + * @param value The Bundle data value. + * + * @return Returns the same Intent object, for chaining multiple calls into a + * single statement. + * + * @see #putExtras + * @see #removeExtra + * @see #getBundleExtra(String) + */ + public Intent putExtra(String name, Bundle value) { + return null; + } + + /** + * Copy all extras in 'src' in to this intent. + * + * @param src Contains the extras to copy. + * + * @see #putExtra + */ + public Intent putExtras(Intent src) { + return null; + } + + /** + * Add a set of extended data to the intent. The keys must include a package + * prefix, for example the app com.android.contacts would use names like + * "com.android.contacts.ShowAll". + * + * @param extras The Bundle of extras to add to this intent. + * + * @see #putExtra + * @see #removeExtra + */ + public Intent putExtras(Bundle extras) { + return null; + } + + /** + * Completely replace the extras in the Intent with the extras in the given + * Intent. + * + * @param src The exact extras contained in this Intent are copied into the + * target intent, replacing any that were previously there. + */ + public Intent replaceExtras(Intent src) { + return null; + } + + /** + * Completely replace the extras in the Intent with the given Bundle of extras. + * + * @param extras The new set of extras in the Intent, or null to erase all + * extras. + */ + public Intent replaceExtras(Bundle extras) { + return null; + } + + /** + * Remove extended data from the intent. + * + * @see #putExtra + */ + public void removeExtra(String name) { + } + + public void writeToParcel(Parcel out, int flags) { + } + + public void readFromParcel(Parcel in) { + } +} \ No newline at end of file diff --git a/java/ql/test/stubs/google-android-9.0.0/android/net/Uri.java b/java/ql/test/stubs/google-android-9.0.0/android/net/Uri.java new file mode 100644 index 000000000000..d5352f0f7eae --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/net/Uri.java @@ -0,0 +1,544 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.net; + +import android.content.Intent; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.io.File; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Locale; +import java.util.Objects; +import java.util.RandomAccess; +import java.util.Set; + +/** + * Immutable URI reference. A URI reference includes a URI and a fragment, the + * component of the URI following a '#'. Builds and parses URI references which + * conform to RFC 2396. + * + *

    + * In the interest of performance, this class performs little to no validation. + * Behavior is undefined for invalid input. This class is very forgiving--in the + * face of invalid input, it will return garbage rather than throw an exception + * unless otherwise specified. + */ +public abstract class Uri implements Parcelable, Comparable { + /* + * This class aims to do as little up front work as possible. To accomplish + * that, we vary the implementation depending on what the user passes in. For + * example, we have one implementation if the user passes in a URI string + * (StringUri) and another if the user passes in the individual components + * (OpaqueUri). Concurrency notes*: Like any truly immutable object, this class + * is safe for concurrent use. This class uses a caching pattern in some places + * where it doesn't use volatile or synchronized. This is safe to do with ints + * because getting or setting an int is atomic. It's safe to do with a String + * because the internal fields are final and the memory model guarantees other + * threads won't see a partially initialized instance. We are not guaranteed + * that some threads will immediately see changes from other threads on certain + * platforms, but we don't mind if those threads reconstruct the cached result. + * As a result, we get thread safe caching with no concurrency overhead, which + * means the most common case, access from a single thread, is as fast as + * possible. From the Java Language spec.: "17.5 Final Field Semantics ... when + * the object is seen by another thread, that thread will always see the + * correctly constructed version of that object's final fields. It will also see + * versions of any object or array referenced by those final fields that are at + * least as up-to-date as the final fields are." In that same vein, all + * non-transient fields within Uri implementations should be final and immutable + * so as to ensure true immutability for clients even when they don't use proper + * concurrency control. For reference, from RFC 2396: "4.3. Parsing a URI + * Reference A URI reference is typically parsed according to the four main + * components and fragment identifier in order to determine what components are + * present and whether the reference is relative or absolute. The individual + * components are then parsed for their subparts and, if not opaque, to verify + * their validity. Although the BNF defines what is allowed in each component, + * it is ambiguous in terms of differentiating between an authority component + * and a path component that begins with two slash characters. The greedy + * algorithm is used for disambiguation: the left-most matching rule soaks up as + * much of the URI reference string as it is capable of matching. In other + * words, the authority component wins." The "four main components" of a + * hierarchical URI consist of ://? + */ + + /** + * NOTE: EMPTY accesses this field during its own initialization, so this field + * *must* be initialized first, or else EMPTY will see a null value! + * + * Placeholder for strings which haven't been cached. This enables us to cache + * null. We intentionally create a new String instance so we can compare its + * identity and there is no chance we will confuse it with user data. + */ + + /** + * Returns true if this URI is hierarchical like "http://google.com". Absolute + * URIs are hierarchical if the scheme-specific part starts with a '/'. Relative + * URIs are always hierarchical. + */ + public abstract boolean isHierarchical(); + + /** + * Returns true if this URI is opaque like "mailto:nobody@google.com". The + * scheme-specific part of an opaque URI cannot start with a '/'. + */ + public boolean isOpaque() { + return false; + } + + /** + * Returns true if this URI is relative, i.e. if it doesn't contain an + * explicit scheme. + * + * @return true if this URI is relative, false if it's absolute + */ + public abstract boolean isRelative(); + + /** + * Returns true if this URI is absolute, i.e. if it contains an explicit + * scheme. + * + * @return true if this URI is absolute, false if it's relative + */ + public boolean isAbsolute() { + return !isRelative(); + } + + /** + * Gets the scheme of this URI. Example: "http" + * + * @return the scheme or null if this is a relative URI + */ + public abstract String getScheme(); + + /** + * Gets the scheme-specific part of this URI, i.e. everything between the + * scheme separator ':' and the fragment separator '#'. If this is a relative + * URI, this method returns the entire URI. Decodes escaped octets. + * + *

    + * Example: "//www.google.com/search?q=android" + * + * @return the decoded scheme-specific-part + */ + public abstract String getSchemeSpecificPart(); + + /** + * Gets the scheme-specific part of this URI, i.e. everything between the + * scheme separator ':' and the fragment separator '#'. If this is a relative + * URI, this method returns the entire URI. Leaves escaped octets intact. + * + *

    + * Example: "//www.google.com/search?q=android" + * + * @return the decoded scheme-specific-part + */ + public abstract String getEncodedSchemeSpecificPart(); + + /** + * Gets the decoded authority part of this URI. For server addresses, the + * authority is structured as follows: + * {@code [ userinfo '@' ] host [ ':' port ]} + * + *

    + * Examples: "google.com", "bob@google.com:80" + * + * @return the authority for this URI or null if not present + */ + public abstract String getAuthority(); + + /** + * Gets the encoded authority part of this URI. For server addresses, the + * authority is structured as follows: + * {@code [ userinfo '@' ] host [ ':' port ]} + * + *

    + * Examples: "google.com", "bob@google.com:80" + * + * @return the authority for this URI or null if not present + */ + public abstract String getEncodedAuthority(); + + /** + * Gets the decoded user information from the authority. For example, if the + * authority is "nobody@google.com", this method will return "nobody". + * + * @return the user info for this URI or null if not present + */ + public abstract String getUserInfo(); + + /** + * Gets the encoded user information from the authority. For example, if the + * authority is "nobody@google.com", this method will return "nobody". + * + * @return the user info for this URI or null if not present + */ + public abstract String getEncodedUserInfo(); + + /** + * Gets the encoded host from the authority for this URI. For example, if the + * authority is "bob@google.com", this method will return "google.com". + * + * @return the host for this URI or null if not present + */ + public abstract String getHost(); + + /** + * Gets the port from the authority for this URI. For example, if the authority + * is "google.com:80", this method will return 80. + * + * @return the port for this URI or -1 if invalid or not present + */ + public abstract int getPort(); + + /** + * Gets the decoded path. + * + * @return the decoded path, or null if this is not a hierarchical URI (like + * "mailto:nobody@google.com") or the URI is invalid + */ + public abstract String getPath(); + + /** + * Gets the encoded path. + * + * @return the encoded path, or null if this is not a hierarchical URI (like + * "mailto:nobody@google.com") or the URI is invalid + */ + public abstract String getEncodedPath(); + + /** + * Gets the decoded query component from this URI. The query comes after the + * query separator ('?') and before the fragment separator ('#'). This method + * would return "q=android" for "http://www.google.com/search?q=android". + * + * @return the decoded query or null if there isn't one + */ + public abstract String getQuery(); + + /** + * Gets the encoded query component from this URI. The query comes after the + * query separator ('?') and before the fragment separator ('#'). This method + * would return "q=android" for "http://www.google.com/search?q=android". + * + * @return the encoded query or null if there isn't one + */ + public abstract String getEncodedQuery(); + + /** + * Gets the decoded fragment part of this URI, everything after the '#'. + * + * @return the decoded fragment or null if there isn't one + */ + public abstract String getFragment(); + + /** + * Gets the encoded fragment part of this URI, everything after the '#'. + * + * @return the encoded fragment or null if there isn't one + */ + public abstract String getEncodedFragment(); + + /** + * Gets the decoded path segments. + * + * @return decoded path segments, each without a leading or trailing '/' + */ + public abstract List getPathSegments(); + + /** + * Gets the decoded last segment in the path. + * + * @return the decoded last segment or null if the path is empty + */ + public abstract String getLastPathSegment(); + + /** + * Compares this Uri to another object for equality. Returns true if the encoded + * string representations of this Uri and the given Uri are equal. Case counts. + * Paths are not normalized. If one Uri specifies a default port explicitly and + * the other leaves it implicit, they will not be considered equal. + */ + public boolean equals(Object o) { + return false; + } + + /** + * Hashes the encoded string represention of this Uri consistently with + * {@link #equals(Object)}. + */ + public int hashCode() { + return -1; + } + + /** + * Compares the string representation of this Uri with that of another. + */ + public int compareTo(Uri other) { + return -1; + } + + /** + * Returns the encoded string representation of this URI. Example: + * "http://google.com/" + */ + public abstract String toString(); + + /** + * Return a string representation of the URI that is safe to print to logs and + * other places where PII should be avoided. + * + * @hide + */ + public String toSafeString() { + return null; + } + + /** + * Creates a Uri which parses the given encoded URI string. + * + * @param uriString an RFC 2396-compliant, encoded URI + * @throws NullPointerException if uriString is null + * @return Uri for this given uri string + */ + public static Uri parse(String uriString) { + return null; + } + + /** + * Creates a Uri from a file. The URI has the form "file://". + * Encodes path characters with the exception of '/'. + * + *

    + * Example: "file:///tmp/android.txt" + * + * @throws NullPointerException if file is null + * @return a Uri for the given file + */ + public static Uri fromFile(File file) { + return null; + } + + /** + * Creates an opaque Uri from the given components. Encodes the ssp which means + * this method cannot be used to create hierarchical URIs. + * + * @param scheme of the URI + * @param ssp scheme-specific-part, everything between the scheme separator + * (':') and the fragment separator ('#'), which will get + * encoded + * @param fragment fragment, everything after the '#', null if undefined, will + * get encoded + * + * @throws NullPointerException if scheme or ssp is null + * @return Uri composed of the given scheme, ssp, and fragment + * + * @see Builder if you don't want the ssp and fragment to be encoded + */ + public static Uri fromParts(String scheme, String ssp, String fragment) { + return null; + } + + /** + * Returns a set of the unique names of all query parameters. Iterating over the + * set will return the names in order of their first occurrence. + * + * @throws UnsupportedOperationException if this isn't a hierarchical URI + * + * @return a set of decoded names + */ + public Set getQueryParameterNames() { + return null; + } + + /** + * Searches the query string for parameter values with the given key. + * + * @param key which will be encoded + * + * @throws UnsupportedOperationException if this isn't a hierarchical URI + * @throws NullPointerException if key is null + * @return a list of decoded values + */ + public List getQueryParameters(String key) { + return null; + } + + /** + * Searches the query string for the first value with the given key. + * + *

    + * Warning: Prior to Jelly Bean, this decoded the '+' character + * as '+' rather than ' '. + * + * @param key which will be encoded + * @throws UnsupportedOperationException if this isn't a hierarchical URI + * @throws NullPointerException if key is null + * @return the decoded value or null if no parameter is found + */ + public String getQueryParameter(String key) { + return null; + } + + /** + * Searches the query string for the first value with the given key and + * interprets it as a boolean value. "false" and "0" are interpreted as + * false, everything else is interpreted as true. + * + * @param key which will be decoded + * @param defaultValue the default value to return if there is no query + * parameter for key + * @return the boolean interpretation of the query parameter key + */ + public boolean getBooleanQueryParameter(String key, boolean defaultValue) { + return false; + } + + /** + * Return an equivalent URI with a lowercase scheme component. This aligns the + * Uri with Android best practices for intent filtering. + * + *

    + * For example, "HTTP://www.android.com" becomes "http://www.android.com" + * + *

    + * All URIs received from outside Android (such as user input, or external + * sources like Bluetooth, NFC, or the Internet) should be normalized before + * they are used to create an Intent. + * + *

    + * This method does not validate bad URI's, or 'fix' poorly formatted + * URI's - so do not use it for input validation. A Uri will always be returned, + * even if the Uri is badly formatted to begin with and a scheme component + * cannot be found. + * + * @return normalized Uri (never null) + * @see android.content.Intent#setData + * @see android.content.Intent#setDataAndNormalize + */ + public Uri normalizeScheme() { + return null; + } + + /** + * Writes a Uri to a Parcel. + * + * @param out parcel to write to + * @param uri to write, can be null + */ + public static void writeToParcel(Parcel out, Uri uri) { + } + + /** + * Encodes characters in the given string as '%'-escaped octets using the UTF-8 + * scheme. Leaves letters ("A-Z", "a-z"), numbers ("0-9"), and unreserved + * characters ("_-!.~'()*") intact. Encodes all other characters. + * + * @param s string to encode + * @return an encoded version of s suitable for use as a URI component, or null + * if s is null + */ + public static String encode(String s) { + return null; + } + + /** + * Encodes characters in the given string as '%'-escaped octets using the UTF-8 + * scheme. Leaves letters ("A-Z", "a-z"), numbers ("0-9"), and unreserved + * characters ("_-!.~'()*") intact. Encodes all other characters with the + * exception of those specified in the allow argument. + * + * @param s string to encode + * @param allow set of additional characters to allow in the encoded form, null + * if no characters should be skipped + * @return an encoded version of s suitable for use as a URI component, or null + * if s is null + */ + public static String encode(String s, String allow) { + return null; + } + + /** + * Decodes '%'-escaped octets in the given string using the UTF-8 scheme. + * Replaces invalid octets with the unicode replacement character ("\\uFFFD"). + * + * @param s encoded string to decode + * @return the given string with escaped octets decoded, or null if s is null + */ + public static String decode(String s) { + return null; + } + + /** + * Creates a new Uri by appending an already-encoded path segment to a base Uri. + * + * @param baseUri Uri to append path segment to + * @param pathSegment encoded path segment to append + * @return a new Uri based on baseUri with the given segment appended to the + * path + * @throws NullPointerException if baseUri is null + */ + public static Uri withAppendedPath(Uri baseUri, String pathSegment) { + return null; + } + + /** + * If this {@link Uri} is {@code file://}, then resolve and return its canonical + * path. Also fixes legacy emulated storage paths so they are usable across user + * boundaries. Should always be called from the app process before sending + * elsewhere. + * + * @hide + */ + public Uri getCanonicalUri() { + return null; + } + + /** + * If this is a {@code file://} Uri, it will be reported to {@link StrictMode}. + * + * @hide + */ + public void checkFileUriExposed(String location) { + } + + /** + * If this is a {@code content://} Uri without access flags, it will be reported + * to {@link StrictMode}. + * + * @hide + */ + public void checkContentUriWithoutPermission(String location, int flags) { + } + + /** + * Test if this is a path prefix match against the given Uri. Verifies that + * scheme, authority, and atomic path segments match. + * + * @hide + */ + public boolean isPathPrefixMatch(Uri prefix) { + return false; + } +} diff --git a/java/ql/test/stubs/google-android-9.0.0/android/os/BaseBundle.java b/java/ql/test/stubs/google-android-9.0.0/android/os/BaseBundle.java new file mode 100644 index 000000000000..617ec97ae8ce --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/os/BaseBundle.java @@ -0,0 +1,677 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.os; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Set; + +/** + * A mapping from String keys to values of various types. In most cases, you + * should work directly with either the {@link Bundle} or + * {@link PersistableBundle} subclass. + */ +public class BaseBundle { + /** + * Constructs a new, empty Bundle that uses a specific ClassLoader for + * instantiating Parcelable and Serializable objects. + * + * @param loader An explicit ClassLoader to use when instantiating objects + * inside of the Bundle. + * @param capacity Initial size of the ArrayMap. + */ + BaseBundle(ClassLoader loader, int capacity) { + } + + /** + * Constructs a new, empty Bundle. + */ + BaseBundle() { + } + + /** + * Constructs a Bundle whose data is stored as a Parcel. The data will be + * unparcelled on first contact, using the assigned ClassLoader. + * + * @param parcelledData a Parcel containing a Bundle + */ + BaseBundle(Parcel parcelledData) { + } + + BaseBundle(Parcel parcelledData, int length) { + } + + /** + * Constructs a new, empty Bundle that uses a specific ClassLoader for + * instantiating Parcelable and Serializable objects. + * + * @param loader An explicit ClassLoader to use when instantiating objects + * inside of the Bundle. + */ + BaseBundle(ClassLoader loader) { + } + + /** + * Constructs a new, empty Bundle sized to hold the given number of elements. + * The Bundle will grow as needed. + * + * @param capacity the initial capacity of the Bundle + */ + BaseBundle(int capacity) { + } + + /** + * Constructs a Bundle containing a copy of the mappings from the given Bundle. + * + * @param b a Bundle to be copied. + */ + BaseBundle(BaseBundle b) { + } + + /** + * Special constructor that does not initialize the bundle. + */ + BaseBundle(boolean doInit) { + } + + /** + * TODO: optimize this later (getting just the value part of a Bundle with a + * single pair) once Bundle.forPair() above is implemented with a special + * single-value Map implementation/serialization. + * + * Note: value in single-pair Bundle may be null. + * + * @hide + */ + public String getPairValue() { + } + + /** + * Changes the ClassLoader this Bundle uses when instantiating objects. + * + * @param loader An explicit ClassLoader to use when instantiating objects + * inside of the Bundle. + */ + void setClassLoader(ClassLoader loader) { + } + + /** + * Return the ClassLoader currently associated with this Bundle. + */ + ClassLoader getClassLoader() { + return null; + } + + /** + * @hide + */ + public boolean isParcelled() { + return false; + } + + /** + * @hide + */ + public boolean isEmptyParcel() { + return false; + } + + /** + * Inserts an ArrayList value into the mapping of this Bundle, + * replacing any existing value for the given key. Either key or value may be + * null. + * + * @param key a String, or null + * @param value an ArrayList object, or null + */ + void putCharSequenceArrayList(String key, ArrayList value) { + } + + /** + * Inserts a Serializable value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a Serializable object, or null + */ + void putSerializable(String key, Serializable value) { + } + + /** + * Inserts a boolean array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a boolean array object, or null + */ + public void putBooleanArray(String key, boolean[] value) { + } + + /** + * Inserts a byte array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a byte array object, or null + */ + void putByteArray(String key, byte[] value) { + } + + /** + * Inserts a short array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a short array object, or null + */ + void putShortArray(String key, short[] value) { + } + + /** + * Inserts a char array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a char array object, or null + */ + void putCharArray(String key, char[] value) { + } + + /** + * Inserts an int array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value an int array object, or null + */ + public void putIntArray(String key, int[] value) { + } + + /** + * Inserts a long array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a long array object, or null + */ + public void putLongArray(String key, long[] value) { + } + + /** + * Inserts a float array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a float array object, or null + */ + void putFloatArray(String key, float[] value) { + } + + /** + * Inserts a double array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a double array object, or null + */ + public void putDoubleArray(String key, double[] value) { + } + + /** + * Inserts a String array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a String array object, or null + */ + public void putStringArray(String key, String[] value) { + } + + /** + * Inserts a CharSequence array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a CharSequence array object, or null + */ + void putCharSequenceArray(String key, CharSequence[] value) { + } + + /** + * Returns the value associated with the given key, or false if no mapping of + * the desired type exists for the given key. + * + * @param key a String + * @return a boolean value + */ + public boolean getBoolean(String key) { + return false; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a boolean value + */ + public boolean getBoolean(String key, boolean defaultValue) { + return false; + } + + /** + * Returns the value associated with the given key, or (byte) 0 if no mapping of + * the desired type exists for the given key. + * + * @param key a String + * @return a byte value + */ + byte getByte(String key) { + return -1; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a byte value + */ + Byte getByte(String key, byte defaultValue) { + return -1; + } + + /** + * Returns the value associated with the given key, or (char) 0 if no mapping of + * the desired type exists for the given key. + * + * @param key a String + * @return a char value + */ + char getChar(String key) { + return 'a'; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a char value + */ + char getChar(String key, char defaultValue) { + return 'a'; + } + + /** + * Returns the value associated with the given key, or (short) 0 if no mapping + * of the desired type exists for the given key. + * + * @param key a String + * @return a short value + */ + short getShort(String key) { + return -1; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a short value + */ + short getShort(String key, short defaultValue) { + return -1; + } + + /** + * Returns the value associated with the given key, or 0 if no mapping of the + * desired type exists for the given key. + * + * @param key a String + * @return an int value + */ + public int getInt(String key) { + return -1; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return an int value + */ + public int getInt(String key, int defaultValue) { + return -1; + } + + /** + * Returns the value associated with the given key, or 0L if no mapping of the + * desired type exists for the given key. + * + * @param key a String + * @return a long value + */ + public long getLong(String key) { + return -1; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a long value + */ + public long getLong(String key, long defaultValue) { + return -1; + } + + /** + * Returns the value associated with the given key, or 0.0f if no mapping of the + * desired type exists for the given key. + * + * @param key a String + * @return a float value + */ + float getFloat(String key) { + return -1; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a float value + */ + float getFloat(String key, float defaultValue) { + return -1; + } + + /** + * Returns the value associated with the given key, or 0.0 if no mapping of the + * desired type exists for the given key. + * + * @param key a String + * @return a double value + */ + public double getDouble(String key) { + return -1; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a double value + */ + public double getDouble(String key, double defaultValue) { + return -1; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a String value, or null + */ + public String getString(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key or if a null value is + * explicitly associated with the given key. + * + * @param key a String, or null + * @param defaultValue Value to return if key does not exist or if a null value + * is associated with the given key. + * @return the String value associated with the given key, or defaultValue if no + * valid String object is currently mapped to that key. + */ + public String getString(String key, String defaultValue) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a CharSequence value, or null + */ + CharSequence getCharSequence(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key or if a null value is + * explicitly associated with the given key. + * + * @param key a String, or null + * @param defaultValue Value to return if key does not exist or if a null value + * is associated with the given key. + * @return the CharSequence value associated with the given key, or defaultValue + * if no valid CharSequence object is currently mapped to that key. + */ + CharSequence getCharSequence(String key, CharSequence defaultValue) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a Serializable value, or null + */ + Serializable getSerializable(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + ArrayList getIntegerArrayList(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + ArrayList getStringArrayList(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + ArrayList getCharSequenceArrayList(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a boolean[] value, or null + */ + public boolean[] getBooleanArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a byte[] value, or null + */ + byte[] getByteArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a short[] value, or null + */ + short[] getShortArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a char[] value, or null + */ + char[] getCharArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return an int[] value, or null + */ + public int[] getIntArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a long[] value, or null + */ + public long[] getLongArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a float[] value, or null + */ + float[] getFloatArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a double[] value, or null + */ + public double[] getDoubleArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a String[] value, or null + */ + public String[] getStringArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a CharSequence[] value, or null + */ + CharSequence[] getCharSequenceArray(String key) { + return null; + } + + /** + * Writes the Bundle contents to a Parcel, typically in order for it to be + * passed through an IBinder connection. + * + * @param parcel The parcel to copy this bundle to. + */ + void writeToParcelInner(Parcel parcel, int flags) { + } + + /** + * Reads the Parcel contents into this Bundle, typically in order for it to be + * passed through an IBinder connection. + * + * @param parcel The parcel to overwrite this bundle from. + */ + void readFromParcelInner(Parcel parcel) { + } + +} diff --git a/java/ql/test/stubs/google-android-9.0.0/android/os/Bundle.java b/java/ql/test/stubs/google-android-9.0.0/android/os/Bundle.java new file mode 100644 index 000000000000..6c074780ee42 --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/os/Bundle.java @@ -0,0 +1,499 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.os; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * A mapping from String keys to various {@link Parcelable} values. + * + * @see PersistableBundle + */ +public final class Bundle extends BaseBundle implements Cloneable, Parcelable { + + /** + * Constructs a new, empty Bundle. + */ + public Bundle() { + super(); + } + + /** + * Removes all elements from the mapping of this Bundle. + */ + public void clear() { + } + + /** + * Removes any entry with the given key from the mapping of this Bundle. + * + * @param key a String key + */ + public void remove(String key) { + } + + /** + * Inserts all mappings from the given Bundle into this Bundle. + * + * @param bundle a Bundle + */ + public void putAll(Bundle bundle) { + } + + /** + * Return the size of {@link #mParcelledData} in bytes if available, otherwise + * {@code 0}. + * + * @hide + */ + public int getSize() { + return -1; + } + + /** + * Inserts a byte value into the mapping of this Bundle, replacing any existing + * value for the given key. + * + * @param key a String, or null + * @param value a byte + */ + public void putByte(String key, byte value) { + } + + /** + * Inserts a char value into the mapping of this Bundle, replacing any existing + * value for the given key. + * + * @param key a String, or null + * @param value a char + */ + public void putChar(String key, char value) { + } + + /** + * Inserts a short value into the mapping of this Bundle, replacing any existing + * value for the given key. + * + * @param key a String, or null + * @param value a short + */ + public void putShort(String key, short value) { + } + + /** + * Inserts a float value into the mapping of this Bundle, replacing any existing + * value for the given key. + * + * @param key a String, or null + * @param value a float + */ + public void putFloat(String key, float value) { + } + + /** + * Inserts a CharSequence value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a CharSequence, or null + */ + public void putCharSequence(String key, CharSequence value) { + } + + /** + * Inserts an ArrayList value into the mapping of this Bundle, + * replacing any existing value for the given key. Either key or value may be + * null. + * + * @param key a String, or null + * @param value an ArrayList object, or null + */ + public void putIntegerArrayList(String key, ArrayList value) { + } + + /** + * Inserts an ArrayList value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value an ArrayList object, or null + */ + public void putStringArrayList(String key, ArrayList value) { + } + + /** + * Inserts an ArrayList value into the mapping of this Bundle, + * replacing any existing value for the given key. Either key or value may be + * null. + * + * @param key a String, or null + * @param value an ArrayList object, or null + */ + public void putCharSequenceArrayList(String key, ArrayList value) { + } + + /** + * Inserts a Serializable value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a Serializable object, or null + */ + public void putSerializable(String key, Serializable value) { + } + + /** + * Inserts a byte array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a byte array object, or null + */ + public void putByteArray(String key, byte[] value) { + } + + /** + * Inserts a short array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a short array object, or null + */ + public void putShortArray(String key, short[] value) { + } + + /** + * Inserts a char array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a char array object, or null + */ + public void putCharArray(String key, char[] value) { + } + + /** + * Inserts a float array value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a float array object, or null + */ + public void putFloatArray(String key, float[] value) { + } + + /** + * Inserts a CharSequence array value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a CharSequence array object, or null + */ + public void putCharSequenceArray(String key, CharSequence[] value) { + } + + /** + * Inserts a Bundle value into the mapping of this Bundle, replacing any + * existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a Bundle object, or null + */ + public void putBundle(String key, Bundle value) { + } + + /** + * Returns the value associated with the given key, or (byte) 0 if no mapping of + * the desired type exists for the given key. + * + * @param key a String + * @return a byte value + */ + public byte getByte(String key) { + return -1; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a byte value + */ + public Byte getByte(String key, byte defaultValue) { + return -1; + } + + /** + * Returns the value associated with the given key, or (char) 0 if no mapping of + * the desired type exists for the given key. + * + * @param key a String + * @return a char value + */ + public char getChar(String key) { + return 'a'; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a char value + */ + public char getChar(String key, char defaultValue) { + return 'a'; + } + + /** + * Returns the value associated with the given key, or (short) 0 if no mapping + * of the desired type exists for the given key. + * + * @param key a String + * @return a short value + */ + public short getShort(String key) { + return -1; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a short value + */ + public short getShort(String key, short defaultValue) { + return -1; + } + + /** + * Returns the value associated with the given key, or 0.0f if no mapping of the + * desired type exists for the given key. + * + * @param key a String + * @return a float value + */ + public float getFloat(String key) { + return -1; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key. + * + * @param key a String + * @param defaultValue Value to return if key does not exist + * @return a float value + */ + public float getFloat(String key, float defaultValue) { + return -1; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a CharSequence value, or null + */ + public CharSequence getCharSequence(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or defaultValue if no + * mapping of the desired type exists for the given key or if a null value is + * explicitly associatd with the given key. + * + * @param key a String, or null + * @param defaultValue Value to return if key does not exist or if a null value + * is associated with the given key. + * @return the CharSequence value associated with the given key, or defaultValue + * if no valid CharSequence object is currently mapped to that key. + */ + public CharSequence getCharSequence(String key, CharSequence defaultValue) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a Bundle value, or null + */ + public Bundle getBundle(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + public ArrayList getParcelableArrayList(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a Serializable value, or null + */ + public Serializable getSerializable(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + public ArrayList getIntegerArrayList(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + public ArrayList getStringArrayList(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return an ArrayList value, or null + */ + public ArrayList getCharSequenceArrayList(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a byte[] value, or null + */ + public byte[] getByteArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a short[] value, or null + */ + public short[] getShortArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a char[] value, or null + */ + public char[] getCharArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a float[] value, or null + */ + public float[] getFloatArray(String key) { + return null; + } + + /** + * Returns the value associated with the given key, or null if no mapping of the + * desired type exists for the given key or a null value is explicitly + * associated with the key. + * + * @param key a String, or null + * @return a CharSequence[] value, or null + */ + public CharSequence[] getCharSequenceArray(String key) { + return null; + } + + /** + * Writes the Bundle contents to a Parcel, typically in order for it to be + * passed through an IBinder connection. + * + * @param parcel The parcel to copy this bundle to. + */ + public void writeToParcel(Parcel parcel, int flags) { + } + + /** + * Reads the Parcel contents into this Bundle, typically in order for it to be + * passed through an IBinder connection. + * + * @param parcel The parcel to overwrite this bundle from. + */ + public void readFromParcel(Parcel parcel) { + } + + public synchronized String toString() { + return null; + } + + /** + * @hide + */ + public synchronized String toShortString() { + return null; + } +} \ No newline at end of file diff --git a/java/ql/test/stubs/google-android-9.0.0/android/os/Parcel.java b/java/ql/test/stubs/google-android-9.0.0/android/os/Parcel.java new file mode 100644 index 000000000000..2670e258e4fa --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/os/Parcel.java @@ -0,0 +1,669 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.os; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileDescriptor; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamClass; +import java.io.Serializable; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public final class Parcel { + + /** + * Retrieve a new Parcel object from the pool. + */ + public static Parcel obtain() { + return null; + } + + /** + * Write a byte array into the parcel at the current {@link #dataPosition}, + * growing {@link #dataCapacity} if needed. + * + * @param b Bytes to place into the parcel. + */ + public final void writeByteArray(byte[] b) { + } + + /** + * Write a byte array into the parcel at the current {@link #dataPosition}, + * growing {@link #dataCapacity} if needed. + * + * @param b Bytes to place into the parcel. + * @param offset Index of first byte to be written. + * @param len Number of bytes to write. + */ + public final void writeByteArray(byte[] b, int offset, int len) { + } + + /** + * Write a blob of data into the parcel at the current {@link #dataPosition}, + * growing {@link #dataCapacity} if needed. + * + * @param b Bytes to place into the parcel. {@hide} {@SystemApi} + */ + public final void writeBlob(byte[] b) { + } + + /** + * Write a blob of data into the parcel at the current {@link #dataPosition}, + * growing {@link #dataCapacity} if needed. + * + * @param b Bytes to place into the parcel. + * @param offset Index of first byte to be written. + * @param len Number of bytes to write. {@hide} {@SystemApi} + */ + public final void writeBlob(byte[] b, int offset, int len) { + } + + /** + * Write an integer value into the parcel at the current dataPosition(), growing + * dataCapacity() if needed. + */ + public final void writeInt(int val) { + } + + /** + * Write a long integer value into the parcel at the current dataPosition(), + * growing dataCapacity() if needed. + */ + public final void writeLong(long val) { + } + + /** + * Write a floating point value into the parcel at the current dataPosition(), + * growing dataCapacity() if needed. + */ + public final void writeFloat(float val) { + } + + /** + * Write a double precision floating point value into the parcel at the current + * dataPosition(), growing dataCapacity() if needed. + */ + public final void writeDouble(double val) { + } + + /** + * Write a string value into the parcel at the current dataPosition(), growing + * dataCapacity() if needed. + */ + public final void writeString(String val) { + } + + /** + * Write a string without going though a {@link ReadWriteHelper}. Subclasses of + * {@link ReadWriteHelper} must use this method instead of {@link #writeString} + * to avoid infinity recursive calls. + * + * @hide + */ + public void writeStringNoHelper(String val) { + } + + /** @hide */ + public final void writeBoolean(boolean val) { + } + + /** + * Write a CharSequence value into the parcel at the current dataPosition(), + * growing dataCapacity() if needed. + * + * @hide + */ + public final void writeCharSequence(CharSequence val) { + } + + /** + * Write a byte value into the parcel at the current dataPosition(), growing + * dataCapacity() if needed. + */ + public final void writeByte(byte val) { + } + + /** + * Please use {@link #writeBundle} instead. Flattens a Map into the parcel at + * the current dataPosition(), growing dataCapacity() if needed. The Map keys + * must be String objects. The Map values are written using {@link #writeValue} + * and must follow the specification there. + * + *

    + * It is strongly recommended to use {@link #writeBundle} instead of this + * method, since the Bundle class provides a type-safe API that allows you to + * avoid mysterious type errors at the point of marshalling. + */ + public final void writeMap(Map val) { + } + + /** + * Flatten a Bundle into the parcel at the current dataPosition(), growing + * dataCapacity() if needed. + */ + public final void writeBundle(Bundle val) { + } + + /** + * Flatten a List into the parcel at the current dataPosition(), growing + * dataCapacity() if needed. The List values are written using + * {@link #writeValue} and must follow the specification there. + */ + public final void writeList(List val) { + } + + /** + * Flatten an Object array into the parcel at the current dataPosition(), + * growing dataCapacity() if needed. The array values are written using + * {@link #writeValue} and must follow the specification there. + */ + public final void writeArray(Object[] val) { + } + + public final void writeBooleanArray(boolean[] val) { + } + + public final boolean[] createBooleanArray() { + return null; + } + + public final void readBooleanArray(boolean[] val) { + } + + public final void writeCharArray(char[] val) { + } + + public final char[] createCharArray() { + return null; + } + + public final void readCharArray(char[] val) { + } + + public final void writeIntArray(int[] val) { + } + + public final int[] createIntArray() { + return null; + } + + public final void readIntArray(int[] val) { + } + + public final void writeLongArray(long[] val) { + } + + public final long[] createLongArray() { + return null; + } + + public final void readLongArray(long[] val) { + } + + public final void writeFloatArray(float[] val) { + } + + public final float[] createFloatArray() { + } + + public final void readFloatArray(float[] val) { + } + + public final void writeDoubleArray(double[] val) { + } + + public final double[] createDoubleArray() { + return null; + } + + public final void readDoubleArray(double[] val) { + } + + public final void writeStringArray(String[] val) { + } + + public final String[] createStringArray() { + return null; + } + + public final void readStringArray(String[] val) { + } + + /** + * @hide + */ + public final void writeCharSequenceArray(CharSequence[] val) { + } + + /** + * @hide + */ + public final void writeCharSequenceList(ArrayList val) { + } + + /** + * Flatten a List containing String objects into the parcel, at the current + * dataPosition() and growing dataCapacity() if needed. They can later be + * retrieved with {@link #createStringArrayList} or {@link #readStringList}. + * + * @param val The list of strings to be written. + * + * @see #createStringArrayList + * @see #readStringList + */ + public final void writeStringList(List val) { + } + + /** + * Flatten a generic object in to a parcel. The given Object value may currently + * be one of the following types: + * + *

    + * + *

    + * {@link Parcelable} objects are written with {@link Parcelable#writeToParcel} + * using contextual flags of 0. When serializing objects containing + * {@link ParcelFileDescriptor}s, this may result in file descriptor leaks when + * they are returned from Binder calls (where + * {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE} should be used). + *

    + */ + public final void writeValue(Object v) { + } + + /** + * Flatten the name of the class of the Parcelable and its contents into the + * parcel. + * + * @param p The Parcelable object to be written. + * @param parcelableFlags Contextual flags as per + * {@link Parcelable#writeToParcel(Parcel, int) + * Parcelable.writeToParcel()}. + */ + public final void writeParcelable(Parcelable p, int parcelableFlags) { + } + + /** @hide */ + public final void writeParcelableCreator(Parcelable p) { + } + + /** + * Write a generic serializable object in to a Parcel. It is strongly + * recommended that this method be avoided, since the serialization overhead is + * extremely large, and this approach will be much slower than using the other + * approaches to writing data in to a Parcel. + */ + public final void writeSerializable(Serializable s) { + } + + /** + * Special function for writing an exception result at the header of a parcel, + * to be used when returning an exception from a transaction. Note that this + * currently only supports a few exception types; any other exception will be + * re-thrown by this function as a RuntimeException (to be caught by the + * system's last-resort exception handling when dispatching a transaction). + * + *

    + * The supported exception types are: + *

    + * + * @param e The Exception to be written. + * + * @see #writeNoException + * @see #readException + */ + public final void writeException(Exception e) { + } + + /** + * Special function for writing information at the front of the Parcel + * indicating that no exception occurred. + * + * @see #writeException + * @see #readException + */ + public final void writeNoException() { + } + + /** + * Special function for reading an exception result from the header of a parcel, + * to be used after receiving the result of a transaction. This will throw the + * exception for you if it had been written to the Parcel, otherwise return and + * let you read the normal result data from the Parcel. + * + * @see #writeException + * @see #writeNoException + */ + public final void readException() { + } + + /** + * Parses the header of a Binder call's response Parcel and returns the + * exception code. Deals with lite or fat headers. In the common successful + * case, this header is generally zero. In less common cases, it's a small + * negative number and will be followed by an error string. + * + * This exists purely for android.database.DatabaseUtils and insulating it from + * having to handle fat headers as returned by e.g. StrictMode-induced RPC + * responses. + * + * @hide + */ + public final int readExceptionCode() { + return -1; + } + + /** + * Throw an exception with the given message. Not intended for use outside the + * Parcel class. + * + * @param code Used to determine which exception class to throw. + * @param msg The exception message. + */ + public final void readException(int code, String msg) { + } + + /** + * Read an integer value from the parcel at the current dataPosition(). + */ + public final int readInt() { + return -1; + } + + /** + * Read a long integer value from the parcel at the current dataPosition(). + */ + public final long readLong() { + return -1; + } + + /** + * Read a floating point value from the parcel at the current dataPosition(). + */ + public final float readFloat() { + return -1; + } + + /** + * Read a double precision floating point value from the parcel at the current + * dataPosition(). + */ + public final double readDouble() { + return -1; + } + + /** + * Read a string value from the parcel at the current dataPosition(). + */ + public final String readString() { + return null; + } + + /** @hide */ + public final boolean readBoolean() { + return false; + } + + /** + * Read a CharSequence value from the parcel at the current dataPosition(). + * + * @hide + */ + public final CharSequence readCharSequence() { + return null; + } + + /** + * Read a byte value from the parcel at the current dataPosition(). + */ + public final byte readByte() { + return -1; + } + + /** + * Please use {@link #readBundle(ClassLoader)} instead (whose data must have + * been written with {@link #writeBundle}. Read into an existing Map object from + * the parcel at the current dataPosition(). + */ + public final void readMap(Map outVal, ClassLoader loader) { + } + + /** + * Read into an existing List object from the parcel at the current + * dataPosition(), using the given class loader to load any enclosed + * Parcelables. If it is null, the default class loader is used. + */ + public final void readList(List outVal, ClassLoader loader) { + } + + /** + * Please use {@link #readBundle(ClassLoader)} instead (whose data must have + * been written with {@link #writeBundle}. Read and return a new HashMap object + * from the parcel at the current dataPosition(), using the given class loader + * to load any enclosed Parcelables. Returns null if the previously written map + * object was null. + */ + public final HashMap readHashMap(ClassLoader loader) { + return null; + } + + /** + * Read and return a new Bundle object from the parcel at the current + * dataPosition(). Returns null if the previously written Bundle object was + * null. + */ + public final Bundle readBundle() { + return null; + } + + /** + * Read and return a new Bundle object from the parcel at the current + * dataPosition(), using the given class loader to initialize the class loader + * of the Bundle for later retrieval of Parcelable objects. Returns null if the + * previously written Bundle object was null. + */ + public final Bundle readBundle(ClassLoader loader) { + return null; + } + + /** + * Read and return a byte[] object from the parcel. + */ + public final byte[] createByteArray() { + return null; + } + + /** + * Read a byte[] object from the parcel and copy it into the given byte array. + */ + public final void readByteArray(byte[] val) { + } + + /** + * Read a blob of data from the parcel and return it as a byte array. + * {@hide} {@SystemApi} + */ + public final byte[] readBlob() { + return null; + } + + /** + * Read and return a String[] object from the parcel. {@hide} + */ + public final String[] readStringArray() { + return null; + } + + /** + * Read and return a CharSequence[] object from the parcel. {@hide} + */ + public final CharSequence[] readCharSequenceArray() { + return null; + } + + /** + * Read and return an ArrayList<CharSequence> object from the parcel. + * {@hide} + */ + public final ArrayList readCharSequenceList() { + return null; + } + + /** + * Read and return a new ArrayList object from the parcel at the current + * dataPosition(). Returns null if the previously written list object was null. + * The given class loader will be used to load any enclosed Parcelables. + */ + public final ArrayList readArrayList(ClassLoader loader) { + return null; + } + + /** + * Read and return a new Object array from the parcel at the current + * dataPosition(). Returns null if the previously written array was null. The + * given class loader will be used to load any enclosed Parcelables. + */ + public final Object[] readArray(ClassLoader loader) { + return null; + } + + /** + * Read and return a new ArrayList containing String objects from the parcel + * that was written with {@link #writeStringList} at the current dataPosition(). + * Returns null if the previously written list object was null. + * + * @return A newly created ArrayList containing strings with the same data as + * those that were previously written. + * + * @see #writeStringList + */ + public final ArrayList createStringArrayList() { + return null; + } + + /** + * Read into the given List items String objects that were written with + * {@link #writeStringList} at the current dataPosition(). + * + * @see #writeStringList + */ + public final void readStringList(List list) { + } + + /** + * Read a typed object from a parcel. The given class loader will be used to + * load any enclosed Parcelables. If it is null, the default class loader will + * be used. + */ + public final Object readValue(ClassLoader loader) { + return null; + } + + /** + * Read and return a new Parcelable from the parcel. The given class loader will + * be used to load any enclosed Parcelables. If it is null, the default class + * loader will be used. + * + * @param loader A ClassLoader from which to instantiate the Parcelable object, + * or null for the default class loader. + * @return Returns the newly created Parcelable, or null if a null object has + * been written. + * @throws BadParcelableException Throws BadParcelableException if there was an + * error trying to instantiate the Parcelable. + */ + public final T readParcelable(ClassLoader loader) { + return null; + } + + /** + * Read and return a new Parcelable array from the parcel. The given class + * loader will be used to load any enclosed Parcelables. + * + * @return the Parcelable array, or null if the array is null + */ + public final Parcelable[] readParcelableArray(ClassLoader loader) { + return null; + } + + /** @hide */ + public final T[] readParcelableArray(ClassLoader loader, Class clazz) { + return null; + } + + /** + * Read and return a new Serializable object from the parcel. + * + * @return the Serializable object, or null if the Serializable name wasn't + * found in the parcel. + */ + public final Serializable readSerializable() { + return null; + } + + private final Serializable readSerializable(final ClassLoader loader) { + return null; + } +} diff --git a/java/ql/test/stubs/google-android-9.0.0/android/os/Parcelable.java b/java/ql/test/stubs/google-android-9.0.0/android/os/Parcelable.java new file mode 100644 index 000000000000..ba9942dbb79c --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/os/Parcelable.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.os; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Interface for classes whose instances can be written to and restored from a + * {@link Parcel}. Classes implementing the Parcelable interface must also have + * a non-null static field called CREATOR of a type that implements + * the {@link Parcelable.Creator} interface. + * + *

    + * A typical implementation of Parcelable is: + *

    + * + *
    + * public class MyParcelable implements Parcelable {
    + *     private int mData;
    + *
    + *     public int describeContents() {
    + *         return 0;
    + *     }
    + *
    + *     public void writeToParcel(Parcel out, int flags) {
    + *         out.writeInt(mData);
    + *     }
    + *
    + *     public static final Parcelable.Creator<MyParcelable> CREATOR = new Parcelable.Creator<MyParcelable>() {
    + *         public MyParcelable createFromParcel(Parcel in) {
    + *             return new MyParcelable(in);
    + *         }
    + *
    + *         public MyParcelable[] newArray(int size) {
    + *             return new MyParcelable[size];
    + *         }
    + *     };
    + * 
    + *     private MyParcelable(Parcel in) {
    + *         mData = in.readInt();
    + *     }
    + * }
    + * 
    + */ +public interface Parcelable { + /** + * Flatten this object in to a Parcel. + * + * @param dest The Parcel in which the object should be written. + * @param flags Additional flags about how the object should be written. May be + * 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}. + */ + public void writeToParcel(Parcel dest, int flags); + + /** + * Specialization of {@link Creator} that allows you to receive the ClassLoader + * the object is being created in. + */ + public interface ClassLoaderCreator { + /** + * Create a new instance of the Parcelable class, instantiating it from the + * given Parcel whose data had previously been written by + * {@link Parcelable#writeToParcel Parcelable.writeToParcel()} and using the + * given ClassLoader. + * + * @param source The Parcel to read the object's data from. + * @param loader The ClassLoader that this object is being created in. + * @return Returns a new instance of the Parcelable class. + */ + public T createFromParcel(Parcel source, ClassLoader loader); + } +} \ No newline at end of file diff --git a/java/ql/test/stubs/google-android-9.0.0/android/view/View.java b/java/ql/test/stubs/google-android-9.0.0/android/view/View.java new file mode 100644 index 000000000000..6940772eb6ed --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/view/View.java @@ -0,0 +1,682 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.view; + +import android.content.Context; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** + *

    + * This class represents the basic building block for user interface components. A View + * occupies a rectangular area on the screen and is responsible for drawing and + * event handling. View is the base class for widgets, which are + * used to create interactive UI components (buttons, text fields, etc.). The + * {@link android.view.ViewGroup} subclass is the base class for layouts, which + * are invisible containers that hold other Views (or other ViewGroups) and define + * their layout properties. + *

    + * + *
    + *

    Developer Guides

    + *

    For information about using this class to develop your application's user interface, + * read the User Interface developer guide. + *

    + * + * + *

    Using Views

    + *

    + * All of the views in a window are arranged in a single tree. You can add views + * either from code or by specifying a tree of views in one or more XML layout + * files. There are many specialized subclasses of views that act as controls or + * are capable of displaying text, images, or other content. + *

    + *

    + * Once you have created a tree of views, there are typically a few types of + * common operations you may wish to perform: + *

      + *
    • Set properties: for example setting the text of a + * {@link android.widget.TextView}. The available properties and the methods + * that set them will vary among the different subclasses of views. Note that + * properties that are known at build time can be set in the XML layout + * files.
    • + *
    • Set focus: The framework will handle moving focus in + * response to user input. To force focus to a specific view, call + * {@link #requestFocus}.
    • + *
    • Set up listeners: Views allow clients to set listeners + * that will be notified when something interesting happens to the view. For + * example, all views will let you set a listener to be notified when the view + * gains or loses focus. You can register such a listener using + * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. + * Other view subclasses offer more specialized listeners. For example, a Button + * exposes a listener to notify clients when the button is clicked.
    • + *
    • Set visibility: You can hide or show views using + * {@link #setVisibility(int)}.
    • + *
    + *

    + *

    + * Note: The Android framework is responsible for measuring, laying out and + * drawing views. You should not call methods that perform these actions on + * views yourself unless you are actually implementing a + * {@link android.view.ViewGroup}. + *

    + * + * + *

    Implementing a Custom View

    + * + *

    + * To implement a custom view, you will usually begin by providing overrides for + * some of the standard methods that the framework calls on all views. You do + * not need to override all of these methods. In fact, you can start by just + * overriding {@link #onDraw(android.graphics.Canvas)}. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Category Methods Description
    CreationConstructorsThere is a form of the constructor that are called when the view + * is created from code and a form that is called when the view is + * inflated from a layout file. The second form should parse and apply + * any attributes defined in the layout file. + *
    {@link #onFinishInflate()}Called after a view and all of its children has been inflated + * from XML.
    Layout{@link #onMeasure(int, int)}Called to determine the size requirements for this view and all + * of its children. + *
    {@link #onLayout(boolean, int, int, int, int)}Called when this view should assign a size and position to all + * of its children. + *
    {@link #onSizeChanged(int, int, int, int)}Called when the size of this view has changed. + *
    Drawing{@link #onDraw(android.graphics.Canvas)}Called when the view should render its content. + *
    Event processing{@link #onKeyDown(int, KeyEvent)}Called when a new hardware key event occurs. + *
    {@link #onKeyUp(int, KeyEvent)}Called when a hardware key up event occurs. + *
    {@link #onTrackballEvent(MotionEvent)}Called when a trackball motion event occurs. + *
    {@link #onTouchEvent(MotionEvent)}Called when a touch screen motion event occurs. + *
    Focus{@link #onFocusChanged(boolean, int, android.graphics.Rect)}Called when the view gains or loses focus. + *
    {@link #onWindowFocusChanged(boolean)}Called when the window containing the view gains or loses focus. + *
    Attaching{@link #onAttachedToWindow()}Called when the view is attached to a window. + *
    {@link #onDetachedFromWindow}Called when the view is detached from its window. + *
    {@link #onWindowVisibilityChanged(int)}Called when the visibility of the window containing the view + * has changed. + *
    + *

    + * + * + *

    IDs

    + * Views may have an integer id associated with them. These ids are typically + * assigned in the layout XML files, and are used to find specific views within + * the view tree. A common pattern is to: + *
      + *
    • Define a Button in the layout file and assign it a unique ID. + *
      + * <Button
      + *     android:id="@+id/my_button"
      + *     android:layout_width="wrap_content"
      + *     android:layout_height="wrap_content"
      + *     android:text="@string/my_button_text"/>
      + * 
    • + *
    • From the onCreate method of an Activity, find the Button + *
      + *      Button myButton = findViewById(R.id.my_button);
      + * 
    • + *
    + *

    + * View IDs need not be unique throughout the tree, but it is good practice to + * ensure that they are at least unique within the part of the tree you are + * searching. + *

    + * + * + *

    Position

    + *

    + * The geometry of a view is that of a rectangle. A view has a location, + * expressed as a pair of left and top coordinates, and + * two dimensions, expressed as a width and a height. The unit for location + * and dimensions is the pixel. + *

    + * + *

    + * It is possible to retrieve the location of a view by invoking the methods + * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, + * coordinate of the rectangle representing the view. The latter returns the + * top, or Y, coordinate of the rectangle representing the view. These methods + * both return the location of the view relative to its parent. For instance, + * when getLeft() returns 20, that means the view is located 20 pixels to the + * right of the left edge of its direct parent. + *

    + * + *

    + * In addition, several convenience methods are offered to avoid unnecessary + * computations, namely {@link #getRight()} and {@link #getBottom()}. + * These methods return the coordinates of the right and bottom edges of the + * rectangle representing the view. For instance, calling {@link #getRight()} + * is similar to the following computation: getLeft() + getWidth() + * (see Size for more information about the width.) + *

    + * + * + *

    Size, padding and margins

    + *

    + * The size of a view is expressed with a width and a height. A view actually + * possess two pairs of width and height values. + *

    + * + *

    + * The first pair is known as measured width and + * measured height. These dimensions define how big a view wants to be + * within its parent (see Layout for more details.) The + * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} + * and {@link #getMeasuredHeight()}. + *

    + * + *

    + * The second pair is simply known as width and height, or + * sometimes drawing width and drawing height. These + * dimensions define the actual size of the view on screen, at drawing time and + * after layout. These values may, but do not have to, be different from the + * measured width and height. The width and height can be obtained by calling + * {@link #getWidth()} and {@link #getHeight()}. + *

    + * + *

    + * To measure its dimensions, a view takes into account its padding. The padding + * is expressed in pixels for the left, top, right and bottom parts of the view. + * Padding can be used to offset the content of the view by a specific amount of + * pixels. For instance, a left padding of 2 will push the view's content by + * 2 pixels to the right of the left edge. Padding can be set using the + * {@link #setPadding(int, int, int, int)} or {@link #setPaddingRelative(int, int, int, int)} + * method and queried by calling {@link #getPaddingLeft()}, {@link #getPaddingTop()}, + * {@link #getPaddingRight()}, {@link #getPaddingBottom()}, {@link #getPaddingStart()}, + * {@link #getPaddingEnd()}. + *

    + * + *

    + * Even though a view can define a padding, it does not provide any support for + * margins. However, view groups provide such a support. Refer to + * {@link android.view.ViewGroup} and + * {@link android.view.ViewGroup.MarginLayoutParams} for further information. + *

    + * + * + *

    Layout

    + *

    + * Layout is a two pass process: a measure pass and a layout pass. The measuring + * pass is implemented in {@link #measure(int, int)} and is a top-down traversal + * of the view tree. Each view pushes dimension specifications down the tree + * during the recursion. At the end of the measure pass, every view has stored + * its measurements. The second pass happens in + * {@link #layout(int,int,int,int)} and is also top-down. During + * this pass each parent is responsible for positioning all of its children + * using the sizes computed in the measure pass. + *

    + * + *

    + * When a view's measure() method returns, its {@link #getMeasuredWidth()} and + * {@link #getMeasuredHeight()} values must be set, along with those for all of + * that view's descendants. A view's measured width and measured height values + * must respect the constraints imposed by the view's parents. This guarantees + * that at the end of the measure pass, all parents accept all of their + * children's measurements. A parent view may call measure() more than once on + * its children. For example, the parent may measure each child once with + * unspecified dimensions to find out how big they want to be, then call + * measure() on them again with actual numbers if the sum of all the children's + * unconstrained sizes is too big or too small. + *

    + * + *

    + * The measure pass uses two classes to communicate dimensions. The + * {@link MeasureSpec} class is used by views to tell their parents how they + * want to be measured and positioned. The base LayoutParams class just + * describes how big the view wants to be for both width and height. For each + * dimension, it can specify one of: + *

      + *
    • an exact number + *
    • MATCH_PARENT, which means the view wants to be as big as its parent + * (minus padding) + *
    • WRAP_CONTENT, which means that the view wants to be just big enough to + * enclose its content (plus padding). + *
    + * There are subclasses of LayoutParams for different subclasses of ViewGroup. + * For example, AbsoluteLayout has its own subclass of LayoutParams which adds + * an X and Y value. + *

    + * + *

    + * MeasureSpecs are used to push requirements down the tree from parent to + * child. A MeasureSpec can be in one of three modes: + *

      + *
    • UNSPECIFIED: This is used by a parent to determine the desired dimension + * of a child view. For example, a LinearLayout may call measure() on its child + * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how + * tall the child view wants to be given a width of 240 pixels. + *
    • EXACTLY: This is used by the parent to impose an exact size on the + * child. The child must use this size, and guarantee that all of its + * descendants will fit within this size. + *
    • AT_MOST: This is used by the parent to impose a maximum size on the + * child. The child must guarantee that it and all of its descendants will fit + * within this size. + *
    + *

    + * + *

    + * To initiate a layout, call {@link #requestLayout}. This method is typically + * called by a view on itself when it believes that is can no longer fit within + * its current bounds. + *

    + * + * + *

    Drawing

    + *

    + * Drawing is handled by walking the tree and recording the drawing commands of + * any View that needs to update. After this, the drawing commands of the + * entire tree are issued to screen, clipped to the newly damaged area. + *

    + * + *

    + * The tree is largely recorded and drawn in order, with parents drawn before + * (i.e., behind) their children, with siblings drawn in the order they appear + * in the tree. If you set a background drawable for a View, then the View will + * draw it before calling back to its onDraw() method. The child + * drawing order can be overridden with + * {@link ViewGroup#setChildrenDrawingOrderEnabled(boolean) custom child drawing order} + * in a ViewGroup, and with {@link #setZ(float)} custom Z values} set on Views. + *

    + * + *

    + * To force a view to draw, call {@link #invalidate()}. + *

    + * + * + *

    Event Handling and Threading

    + *

    + * The basic cycle of a view is as follows: + *

      + *
    1. An event comes in and is dispatched to the appropriate view. The view + * handles the event and notifies any listeners.
    2. + *
    3. If in the course of processing the event, the view's bounds may need + * to be changed, the view will call {@link #requestLayout()}.
    4. + *
    5. Similarly, if in the course of processing the event the view's appearance + * may need to be changed, the view will call {@link #invalidate()}.
    6. + *
    7. If either {@link #requestLayout()} or {@link #invalidate()} were called, + * the framework will take care of measuring, laying out, and drawing the tree + * as appropriate.
    8. + *
    + *

    + * + *

    Note: The entire view tree is single threaded. You must always be on + * the UI thread when calling any method on any view. + * If you are doing work on other threads and want to update the state of a view + * from that thread, you should use a {@link Handler}. + *

    + * + * + *

    Focus Handling

    + *

    + * The framework will handle routine focus movement in response to user input. + * This includes changing the focus as views are removed or hidden, or as new + * views become available. Views indicate their willingness to take focus + * through the {@link #isFocusable} method. To change whether a view can take + * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) + * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} + * and can change this via {@link #setFocusableInTouchMode(boolean)}. + *

    + *

    + * Focus movement is based on an algorithm which finds the nearest neighbor in a + * given direction. In rare cases, the default algorithm may not match the + * intended behavior of the developer. In these situations, you can provide + * explicit overrides by using these XML attributes in the layout file: + *

    + * nextFocusDown
    + * nextFocusLeft
    + * nextFocusRight
    + * nextFocusUp
    + * 
    + *

    + * + * + *

    + * To get a particular view to take focus, call {@link #requestFocus()}. + *

    + * + * + *

    Touch Mode

    + *

    + * When a user is navigating a user interface via directional keys such as a D-pad, it is + * necessary to give focus to actionable items such as buttons so the user can see + * what will take input. If the device has touch capabilities, however, and the user + * begins interacting with the interface by touching it, it is no longer necessary to + * always highlight, or give focus to, a particular view. This motivates a mode + * for interaction named 'touch mode'. + *

    + *

    + * For a touch capable device, once the user touches the screen, the device + * will enter touch mode. From this point onward, only views for which + * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. + * Other views that are touchable, like buttons, will not take focus when touched; they will + * only fire the on click listeners. + *

    + *

    + * Any time a user hits a directional key, such as a D-pad direction, the view device will + * exit touch mode, and find a view to take focus, so that the user may resume interacting + * with the user interface without touching the screen again. + *

    + *

    + * The touch mode state is maintained across {@link android.app.Activity}s. Call + * {@link #isInTouchMode} to see whether the device is currently in touch mode. + *

    + * + * + *

    Scrolling

    + *

    + * The framework provides basic support for views that wish to internally + * scroll their content. This includes keeping track of the X and Y scroll + * offset as well as mechanisms for drawing scrollbars. See + * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and + * {@link #awakenScrollBars()} for more details. + *

    + * + * + *

    Tags

    + *

    + * Unlike IDs, tags are not used to identify views. Tags are essentially an + * extra piece of information that can be associated with a view. They are most + * often used as a convenience to store data related to views in the views + * themselves rather than by putting them in a separate structure. + *

    + *

    + * Tags may be specified with character sequence values in layout XML as either + * a single tag using the {@link android.R.styleable#View_tag android:tag} + * attribute or multiple tags using the {@code } child element: + *

    + *     <View ...
    + *           android:tag="@string/mytag_value" />
    + *     <View ...>
    + *         <tag android:id="@+id/mytag"
    + *              android:value="@string/mytag_value" />
    + *     </View>
    + * 
    + *

    + *

    + * Tags may also be specified with arbitrary objects from code using + * {@link #setTag(Object)} or {@link #setTag(int, Object)}. + *

    + * + * + *

    Themes

    + *

    + * By default, Views are created using the theme of the Context object supplied + * to their constructor; however, a different theme may be specified by using + * the {@link android.R.styleable#View_theme android:theme} attribute in layout + * XML or by passing a {@link ContextThemeWrapper} to the constructor from + * code. + *

    + *

    + * When the {@link android.R.styleable#View_theme android:theme} attribute is + * used in XML, the specified theme is applied on top of the inflation + * context's theme (see {@link LayoutInflater}) and used for the view itself as + * well as any child elements. + *

    + *

    + * In the following example, both views will be created using the Material dark + * color scheme; however, because an overlay theme is used which only defines a + * subset of attributes, the value of + * {@link android.R.styleable#Theme_colorAccent android:colorAccent} defined on + * the inflation context's theme (e.g. the Activity theme) will be preserved. + *

    + *     <LinearLayout
    + *             ...
    + *             android:theme="@android:theme/ThemeOverlay.Material.Dark">
    + *         <View ...>
    + *     </LinearLayout>
    + * 
    + *

    + * + * + *

    Properties

    + *

    + * The View class exposes an {@link #ALPHA} property, as well as several transform-related + * properties, such as {@link #TRANSLATION_X} and {@link #TRANSLATION_Y}. These properties are + * available both in the {@link Property} form as well as in similarly-named setter/getter + * methods (such as {@link #setAlpha(float)} for {@link #ALPHA}). These properties can + * be used to set persistent state associated with these rendering-related properties on the view. + * The properties and methods can also be used in conjunction with + * {@link android.animation.Animator Animator}-based animations, described more in the + * Animation section. + *

    + * + * + *

    Animation

    + *

    + * Starting with Android 3.0, the preferred way of animating views is to use the + * {@link android.animation} package APIs. These {@link android.animation.Animator Animator}-based + * classes change actual properties of the View object, such as {@link #setAlpha(float) alpha} and + * {@link #setTranslationX(float) translationX}. This behavior is contrasted to that of the pre-3.0 + * {@link android.view.animation.Animation Animation}-based classes, which instead animate only + * how the view is drawn on the display. In particular, the {@link ViewPropertyAnimator} class + * makes animating these View properties particularly easy and efficient. + *

    + *

    + * Alternatively, you can use the pre-3.0 animation classes to animate how Views are rendered. + * You can attach an {@link Animation} object to a view using + * {@link #setAnimation(Animation)} or + * {@link #startAnimation(Animation)}. The animation can alter the scale, + * rotation, translation and alpha of a view over time. If the animation is + * attached to a view that has children, the animation will affect the entire + * subtree rooted by that node. When an animation is started, the framework will + * take care of redrawing the appropriate views until the animation completes. + *

    + * + * + *

    Security

    + *

    + * Sometimes it is essential that an application be able to verify that an action + * is being performed with the full knowledge and consent of the user, such as + * granting a permission request, making a purchase or clicking on an advertisement. + * Unfortunately, a malicious application could try to spoof the user into + * performing these actions, unaware, by concealing the intended purpose of the view. + * As a remedy, the framework offers a touch filtering mechanism that can be used to + * improve the security of views that provide access to sensitive functionality. + *

    + * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the + * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework + * will discard touches that are received whenever the view's window is obscured by + * another visible window. As a result, the view will not receive touches whenever a + * toast, dialog or other window appears above the view's window. + *

    + * For more fine-grained control over security, consider overriding the + * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own + * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. + *

    + * + * @attr ref android.R.styleable#View_accessibilityHeading + * @attr ref android.R.styleable#View_alpha + * @attr ref android.R.styleable#View_background + * @attr ref android.R.styleable#View_clickable + * @attr ref android.R.styleable#View_contentDescription + * @attr ref android.R.styleable#View_drawingCacheQuality + * @attr ref android.R.styleable#View_duplicateParentState + * @attr ref android.R.styleable#View_id + * @attr ref android.R.styleable#View_requiresFadingEdge + * @attr ref android.R.styleable#View_fadeScrollbars + * @attr ref android.R.styleable#View_fadingEdgeLength + * @attr ref android.R.styleable#View_filterTouchesWhenObscured + * @attr ref android.R.styleable#View_fitsSystemWindows + * @attr ref android.R.styleable#View_isScrollContainer + * @attr ref android.R.styleable#View_focusable + * @attr ref android.R.styleable#View_focusableInTouchMode + * @attr ref android.R.styleable#View_focusedByDefault + * @attr ref android.R.styleable#View_hapticFeedbackEnabled + * @attr ref android.R.styleable#View_keepScreenOn + * @attr ref android.R.styleable#View_keyboardNavigationCluster + * @attr ref android.R.styleable#View_layerType + * @attr ref android.R.styleable#View_layoutDirection + * @attr ref android.R.styleable#View_longClickable + * @attr ref android.R.styleable#View_minHeight + * @attr ref android.R.styleable#View_minWidth + * @attr ref android.R.styleable#View_nextClusterForward + * @attr ref android.R.styleable#View_nextFocusDown + * @attr ref android.R.styleable#View_nextFocusLeft + * @attr ref android.R.styleable#View_nextFocusRight + * @attr ref android.R.styleable#View_nextFocusUp + * @attr ref android.R.styleable#View_onClick + * @attr ref android.R.styleable#View_outlineSpotShadowColor + * @attr ref android.R.styleable#View_outlineAmbientShadowColor + * @attr ref android.R.styleable#View_padding + * @attr ref android.R.styleable#View_paddingHorizontal + * @attr ref android.R.styleable#View_paddingVertical + * @attr ref android.R.styleable#View_paddingBottom + * @attr ref android.R.styleable#View_paddingLeft + * @attr ref android.R.styleable#View_paddingRight + * @attr ref android.R.styleable#View_paddingTop + * @attr ref android.R.styleable#View_paddingStart + * @attr ref android.R.styleable#View_paddingEnd + * @attr ref android.R.styleable#View_saveEnabled + * @attr ref android.R.styleable#View_rotation + * @attr ref android.R.styleable#View_rotationX + * @attr ref android.R.styleable#View_rotationY + * @attr ref android.R.styleable#View_scaleX + * @attr ref android.R.styleable#View_scaleY + * @attr ref android.R.styleable#View_scrollX + * @attr ref android.R.styleable#View_scrollY + * @attr ref android.R.styleable#View_scrollbarSize + * @attr ref android.R.styleable#View_scrollbarStyle + * @attr ref android.R.styleable#View_scrollbars + * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade + * @attr ref android.R.styleable#View_scrollbarFadeDuration + * @attr ref android.R.styleable#View_scrollbarTrackHorizontal + * @attr ref android.R.styleable#View_scrollbarThumbHorizontal + * @attr ref android.R.styleable#View_scrollbarThumbVertical + * @attr ref android.R.styleable#View_scrollbarTrackVertical + * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack + * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack + * @attr ref android.R.styleable#View_stateListAnimator + * @attr ref android.R.styleable#View_transitionName + * @attr ref android.R.styleable#View_soundEffectsEnabled + * @attr ref android.R.styleable#View_tag + * @attr ref android.R.styleable#View_textAlignment + * @attr ref android.R.styleable#View_textDirection + * @attr ref android.R.styleable#View_transformPivotX + * @attr ref android.R.styleable#View_transformPivotY + * @attr ref android.R.styleable#View_translationX + * @attr ref android.R.styleable#View_translationY + * @attr ref android.R.styleable#View_translationZ + * @attr ref android.R.styleable#View_visibility + * @attr ref android.R.styleable#View_theme + * + * @see android.view.ViewGroup + */ +public class View { + + /** + * Simple constructor to use when creating a view from code. + * + * @param context The Context the view is running in, through which it can + * access the current theme, resources, etc. + */ + public View(Context context) { + } + + + + + + + + + +} \ No newline at end of file diff --git a/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebResourceRequest.java b/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebResourceRequest.java new file mode 100644 index 000000000000..9732ca67ae0f --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebResourceRequest.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.webkit; + +import android.net.Uri; +import java.util.Map; + +/** + * Encompasses parameters to the {@link WebViewClient#shouldInterceptRequest} + * method. + */ +public interface WebResourceRequest { + /** + * Gets the URL for which the resource request was made. + * + * @return the URL for which the resource request was made. + */ + Uri getUrl(); + + /** + * Gets whether the request was made for the main frame. + * + * @return whether the request was made for the main frame. Will be + * {@code false} for iframes, for example. + */ + boolean isForMainFrame(); + + /** + * Gets whether the request was a result of a server-side redirect. + * + * @return whether the request was a result of a server-side redirect. + */ + boolean isRedirect(); + + /** + * Gets whether a gesture (such as a click) was associated with the request. For + * security reasons in certain situations this method may return {@code false} + * even though the sequence of events which caused the request to be created was + * initiated by a user gesture. + * + * @return whether a gesture was associated with the request. + */ + boolean hasGesture(); + + /** + * Gets the method associated with the request, for example "GET". + * + * @return the method associated with the request. + */ + String getMethod(); + + /** + * Gets the headers associated with the request. These are represented as a + * mapping of header name to header value. + * + * @return the headers associated with the request. + */ + Map getRequestHeaders(); +} \ No newline at end of file diff --git a/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebResourceResponse.java b/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebResourceResponse.java new file mode 100644 index 000000000000..0df042650462 --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebResourceResponse.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.webkit; + +import java.io.InputStream; +import java.io.StringBufferInputStream; +import java.util.Map; + +/** + * Encapsulates a resource response. Applications can return an instance of this + * class from {@link WebViewClient#shouldInterceptRequest} to provide a custom + * response when the WebView requests a particular resource. + */ +public class WebResourceResponse { + /** + * Constructs a resource response with the given MIME type, encoding, and input + * stream. Callers must implement {@link InputStream#read(byte[]) + * InputStream.read(byte[])} for the input stream. + * + * @param mimeType the resource response's MIME type, for example text/html + * @param encoding the resource response's encoding + * @param data the input stream that provides the resource response's data. + * Must not be a StringBufferInputStream. + */ + public WebResourceResponse(String mimeType, String encoding, InputStream data) { + } + + /** + * Constructs a resource response with the given parameters. Callers must + * implement {@link InputStream#read(byte[]) InputStream.read(byte[])} for the + * input stream. + * + * @param mimeType the resource response's MIME type, for example + * text/html + * @param encoding the resource response's encoding + * @param statusCode the status code needs to be in the ranges [100, 299], + * [400, 599]. Causing a redirect by specifying a 3xx + * code is not supported. + * @param reasonPhrase the phrase describing the status code, for example + * "OK". Must be non-empty. + * @param responseHeaders the resource response's headers represented as a + * mapping of header name -> header value. + * @param data the input stream that provides the resource response's + * data. Must not be a StringBufferInputStream. + */ + public WebResourceResponse(String mimeType, String encoding, int statusCode, String reasonPhrase, + Map responseHeaders, InputStream data) { + } + + /** + * Sets the resource response's MIME type, for example "text/html". + * + * @param mimeType The resource response's MIME type + */ + public void setMimeType(String mimeType) { + } + + /** + * Gets the resource response's MIME type. + * + * @return The resource response's MIME type + */ + public String getMimeType() { + return null; + } + + /** + * Sets the resource response's encoding, for example "UTF-8". This is + * used to decode the data from the input stream. + * + * @param encoding The resource response's encoding + */ + public void setEncoding(String encoding) { + } + + /** + * Gets the resource response's encoding. + * + * @return The resource response's encoding + */ + public String getEncoding() { + return null; + } + + /** + * Sets the resource response's status code and reason phrase. + * + * @param statusCode the status code needs to be in the ranges [100, 299], + * [400, 599]. Causing a redirect by specifying a 3xx code + * is not supported. + * @param reasonPhrase the phrase describing the status code, for example "OK". + * Must be non-empty. + */ + public void setStatusCodeAndReasonPhrase(int statusCode, String reasonPhrase) { + } + + /** + * Gets the resource response's status code. + * + * @return The resource response's status code. + */ + public int getStatusCode() { + return -1; + } + + /** + * Gets the description of the resource response's status code. + * + * @return The description of the resource response's status code. + */ + public String getReasonPhrase() { + return null; + } + + /** + * Sets the headers for the resource response. + * + * @param headers Mapping of header name -> header value. + */ + public void setResponseHeaders(Map headers) { + } + + /** + * Gets the headers for the resource response. + * + * @return The headers for the resource response. + */ + public Map getResponseHeaders() { + return null; + } + + /** + * Sets the input stream that provides the resource response's data. Callers + * must implement {@link InputStream#read(byte[]) InputStream.read(byte[])}. + * + * @param data the input stream that provides the resource response's data. Must + * not be a StringBufferInputStream. + */ + public void setData(InputStream data) { + } + + /** + * Gets the input stream that provides the resource response's data. + * + * @return The input stream that provides the resource response's data + */ + public InputStream getData() { + return null; + } + + /** + * The internal version of the constructor that doesn't perform arguments + * checks. + * + * @hide + */ + public WebResourceResponse(boolean immutable, String mimeType, String encoding, int statusCode, String reasonPhrase, + Map responseHeaders, InputStream data) { + } + +} \ No newline at end of file diff --git a/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebSettings.java b/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebSettings.java new file mode 100644 index 000000000000..e6a7d5d70508 --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebSettings.java @@ -0,0 +1,1382 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.webkit; + +import android.content.Context; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Manages settings state for a WebView. When a WebView is first created, it + * obtains a set of default settings. These default settings will be returned + * from any getter call. A {@code WebSettings} object obtained from + * {@link WebView#getSettings()} is tied to the life of the WebView. If a + * WebView has been destroyed, any method call on {@code WebSettings} will throw + * an {@link IllegalStateException}. + */ +// This is an abstract base class: concrete WebViewProviders must +// create a class derived from this, and return an instance of it in the +// WebViewProvider.getWebSettingsProvider() method implementation. +public abstract class WebSettings { + /** + * Enum for controlling the layout of html. + *
      + *
    • {@code NORMAL} means no rendering changes. This is the recommended choice + * for maximum compatibility across different platforms and Android + * versions.
    • + *
    • {@code SINGLE_COLUMN} moves all content into one column that is the width + * of the view.
    • + *
    • {@code NARROW_COLUMNS} makes all columns no wider than the screen if + * possible. Only use this for API levels prior to + * {@link android.os.Build.VERSION_CODES#KITKAT}.
    • + *
    • {@code TEXT_AUTOSIZING} boosts font size of paragraphs based on + * heuristics to make the text readable when viewing a wide-viewport layout in + * the overview mode. It is recommended to enable zoom support + * {@link #setSupportZoom} when using this mode. Supported from API level + * {@link android.os.Build.VERSION_CODES#KITKAT}
    • + *
    + */ + // XXX: These must match LayoutAlgorithm in Settings.h in WebCore. + public enum LayoutAlgorithm { + NORMAL, + /** + * @deprecated This algorithm is now obsolete. + */ + @Deprecated + SINGLE_COLUMN, + /** + * @deprecated This algorithm is now obsolete. + */ + @Deprecated + NARROW_COLUMNS, TEXT_AUTOSIZING + } + + /** + * Enum for specifying the text size. + *
      + *
    • SMALLEST is 50%
    • + *
    • SMALLER is 75%
    • + *
    • NORMAL is 100%
    • + *
    • LARGER is 150%
    • + *
    • LARGEST is 200%
    • + *
    + * + * @deprecated Use {@link WebSettings#setTextZoom(int)} and + * {@link WebSettings#getTextZoom()} instead. + */ + @Deprecated + public enum TextSize { + SMALLEST(50), SMALLER(75), NORMAL(100), LARGER(150), LARGEST(200); + + TextSize(int size) { + value = size; + } + + int value; + } + + /** + * Enum for specifying the WebView's desired density. + *
      + *
    • {@code FAR} makes 100% looking like in 240dpi
    • + *
    • {@code MEDIUM} makes 100% looking like in 160dpi
    • + *
    • {@code CLOSE} makes 100% looking like in 120dpi
    • + *
    + */ + public enum ZoomDensity { + FAR(150), // 240dpi + MEDIUM(100), // 160dpi + CLOSE(75); // 120dpi + + ZoomDensity(int size) { + value = size; + } + + /** + * @hide Only for use by WebViewProvider implementations + */ + public int getValue() { + return value; + } + + int value; + } + + public @interface CacheMode { + } + + /** + * Default cache usage mode. If the navigation type doesn't impose any specific + * behavior, use cached resources when they are available and not expired, + * otherwise load resources from the network. Use with {@link #setCacheMode}. + */ + public static final int LOAD_DEFAULT = -1; + /** + * Normal cache usage mode. Use with {@link #setCacheMode}. + * + * @deprecated This value is obsolete, as from API level + * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and onwards it + * has the same effect as {@link #LOAD_DEFAULT}. + */ + @Deprecated + public static final int LOAD_NORMAL = 0; + /** + * Use cached resources when they are available, even if they have expired. + * Otherwise load resources from the network. Use with {@link #setCacheMode}. + */ + public static final int LOAD_CACHE_ELSE_NETWORK = 1; + /** + * Don't use the cache, load from the network. Use with {@link #setCacheMode}. + */ + public static final int LOAD_NO_CACHE = 2; + /** + * Don't use the network, load from the cache. Use with {@link #setCacheMode}. + */ + public static final int LOAD_CACHE_ONLY = 3; + + public enum RenderPriority { + NORMAL, HIGH, LOW + } + + /** + * The plugin state effects how plugins are treated on a page. ON means that any + * object will be loaded even if a plugin does not exist to handle the content. + * ON_DEMAND means that if there is a plugin installed that can handle the + * content, a placeholder is shown until the user clicks on the placeholder. + * Once clicked, the plugin will be enabled on the page. OFF means that all + * plugins will be turned off and any fallback content will be used. + */ + public enum PluginState { + ON, ON_DEMAND, OFF + } + + /** + * Used with {@link #setMixedContentMode} + * + * In this mode, the WebView will allow a secure origin to load content from any + * other origin, even if that origin is insecure. This is the least secure mode + * of operation for the WebView, and where possible apps should not set this + * mode. + */ + public static final int MIXED_CONTENT_ALWAYS_ALLOW = 0; + /** + * Used with {@link #setMixedContentMode} + * + * In this mode, the WebView will not allow a secure origin to load content from + * an insecure origin. This is the preferred and most secure mode of operation + * for the WebView and apps are strongly advised to use this mode. + */ + public static final int MIXED_CONTENT_NEVER_ALLOW = 1; + /** + * Used with {@link #setMixedContentMode} + * + * In this mode, the WebView will attempt to be compatible with the approach of + * a modern web browser with regard to mixed content. Some insecure content may + * be allowed to be loaded by a secure origin and other types of content will be + * blocked. The types of content are allowed or blocked may change release to + * release and are not explicitly defined. + * + * This mode is intended to be used by apps that are not in control of the + * content that they render but desire to operate in a reasonably secure + * environment. For highest security, apps are recommended to use + * {@link #MIXED_CONTENT_NEVER_ALLOW}. + */ + public static final int MIXED_CONTENT_COMPATIBILITY_MODE = 2; + + /** + * Enables dumping the pages navigation cache to a text file. The default is + * {@code false}. + * + * @deprecated This method is now obsolete. + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} + */ + @Deprecated + public abstract void setNavDump(boolean enabled); + + /** + * Gets whether dumping the navigation cache is enabled. + * + * @return whether dumping the navigation cache is enabled + * @see #setNavDump + * @deprecated This method is now obsolete. + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} + */ + @Deprecated + public abstract boolean getNavDump(); + + /** + * Sets whether the WebView should support zooming using its on-screen zoom + * controls and gestures. The particular zoom mechanisms that should be used can + * be set with {@link #setBuiltInZoomControls}. This setting does not affect + * zooming performed using the {@link WebView#zoomIn()} and + * {@link WebView#zoomOut()} methods. The default is {@code true}. + * + * @param support whether the WebView should support zoom + */ + public abstract void setSupportZoom(boolean support); + + /** + * Gets whether the WebView supports zoom. + * + * @return {@code true} if the WebView supports zoom + * @see #setSupportZoom + */ + public abstract boolean supportZoom(); + + /** + * Sets whether the WebView requires a user gesture to play media. The default + * is {@code true}. + * + * @param require whether the WebView requires a user gesture to play media + */ + public abstract void setMediaPlaybackRequiresUserGesture(boolean require); + + /** + * Gets whether the WebView requires a user gesture to play media. + * + * @return {@code true} if the WebView requires a user gesture to play media + * @see #setMediaPlaybackRequiresUserGesture + */ + public abstract boolean getMediaPlaybackRequiresUserGesture(); + + /** + * Sets whether the WebView should use its built-in zoom mechanisms. The + * built-in zoom mechanisms comprise on-screen zoom controls, which are + * displayed over the WebView's content, and the use of a pinch gesture to + * control zooming. Whether or not these on-screen controls are displayed can be + * set with {@link #setDisplayZoomControls}. The default is {@code false}. + *

    + * The built-in mechanisms are the only currently supported zoom mechanisms, so + * it is recommended that this setting is always enabled. + * + * @param enabled whether the WebView should use its built-in zoom mechanisms + */ + // This method was intended to select between the built-in zoom mechanisms + // and the separate zoom controls. The latter were obtained using + // {@link WebView#getZoomControls}, which is now hidden. + public abstract void setBuiltInZoomControls(boolean enabled); + + /** + * Gets whether the zoom mechanisms built into WebView are being used. + * + * @return {@code true} if the zoom mechanisms built into WebView are being used + * @see #setBuiltInZoomControls + */ + public abstract boolean getBuiltInZoomControls(); + + /** + * Sets whether the WebView should display on-screen zoom controls when using + * the built-in zoom mechanisms. See {@link #setBuiltInZoomControls}. The + * default is {@code true}. + * + * @param enabled whether the WebView should display on-screen zoom controls + */ + public abstract void setDisplayZoomControls(boolean enabled); + + /** + * Gets whether the WebView displays on-screen zoom controls when using the + * built-in zoom mechanisms. + * + * @return {@code true} if the WebView displays on-screen zoom controls when + * using the built-in zoom mechanisms + * @see #setDisplayZoomControls + */ + public abstract boolean getDisplayZoomControls(); + + /** + * Enables or disables file access within WebView. File access is enabled by + * default. Note that this enables or disables file system access only. Assets + * and resources are still accessible using file:///android_asset and + * file:///android_res. + */ + public abstract void setAllowFileAccess(boolean allow); + + /** + * Gets whether this WebView supports file access. + * + * @see #setAllowFileAccess + */ + public abstract boolean getAllowFileAccess(); + + /** + * Enables or disables content URL access within WebView. Content URL access + * allows WebView to load content from a content provider installed in the + * system. The default is enabled. + */ + public abstract void setAllowContentAccess(boolean allow); + + /** + * Gets whether this WebView supports content URL access. + * + * @see #setAllowContentAccess + */ + public abstract boolean getAllowContentAccess(); + + /** + * Sets whether the WebView loads pages in overview mode, that is, zooms out the + * content to fit on screen by width. This setting is taken into account when + * the content width is greater than the width of the WebView control, for + * example, when {@link #getUseWideViewPort} is enabled. The default is + * {@code false}. + */ + public abstract void setLoadWithOverviewMode(boolean overview); + + /** + * Gets whether this WebView loads pages in overview mode. + * + * @return whether this WebView loads pages in overview mode + * @see #setLoadWithOverviewMode + */ + public abstract boolean getLoadWithOverviewMode(); + + /** + * Sets whether the WebView will enable smooth transition while panning or + * zooming or while the window hosting the WebView does not have focus. If it is + * {@code true}, WebView will choose a solution to maximize the performance. + * e.g. the WebView's content may not be updated during the transition. If it is + * false, WebView will keep its fidelity. The default value is {@code false}. + * + * @deprecated This method is now obsolete, and will become a no-op in future. + */ + @Deprecated + public abstract void setEnableSmoothTransition(boolean enable); + + /** + * Gets whether the WebView enables smooth transition while panning or zooming. + * + * @see #setEnableSmoothTransition + * + * @deprecated This method is now obsolete, and will become a no-op in future. + */ + @Deprecated + public abstract boolean enableSmoothTransition(); + + /** + * Sets whether the WebView uses its background for over scroll background. If + * {@code true}, it will use the WebView's background. If {@code false}, it will + * use an internal pattern. Default is {@code true}. + * + * @deprecated This method is now obsolete. + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} + */ + @Deprecated + public abstract void setUseWebViewBackgroundForOverscrollBackground(boolean view); + + /** + * Gets whether this WebView uses WebView's background instead of internal + * pattern for over scroll background. + * + * @see #setUseWebViewBackgroundForOverscrollBackground + * @deprecated This method is now obsolete. + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} + */ + @Deprecated + public abstract boolean getUseWebViewBackgroundForOverscrollBackground(); + + /** + * Sets whether the WebView should save form data. In Android O, the platform + * has implemented a fully functional Autofill feature to store form data. + * Therefore, the Webview form data save feature is disabled. + * + * Note that the feature will continue to be supported on older versions of + * Android as before. + * + * This function does not have any effect. + */ + @Deprecated + public abstract void setSaveFormData(boolean save); + + /** + * Gets whether the WebView saves form data. + * + * @return whether the WebView saves form data + * @see #setSaveFormData + */ + @Deprecated + public abstract boolean getSaveFormData(); + + /** + * Sets whether the WebView should save passwords. The default is {@code true}. + * + * @deprecated Saving passwords in WebView will not be supported in future + * versions. + */ + @Deprecated + public abstract void setSavePassword(boolean save); + + /** + * Gets whether the WebView saves passwords. + * + * @return whether the WebView saves passwords + * @see #setSavePassword + * @deprecated Saving passwords in WebView will not be supported in future + * versions. + */ + @Deprecated + public abstract boolean getSavePassword(); + + /** + * Sets the text zoom of the page in percent. The default is 100. + * + * @param textZoom the text zoom in percent + */ + public abstract void setTextZoom(int textZoom); + + /** + * Gets the text zoom of the page in percent. + * + * @return the text zoom of the page in percent + * @see #setTextZoom + */ + public abstract int getTextZoom(); + + /** + * Sets policy for third party cookies. Developers should access this via + * {@link CookieManager#setShouldAcceptThirdPartyCookies}. + * + * @hide Internal API. + */ + public abstract void setAcceptThirdPartyCookies(boolean accept); + + /** + * Gets policy for third party cookies. Developers should access this via + * {@link CookieManager#getShouldAcceptThirdPartyCookies}. + * + * @hide Internal API + */ + public abstract boolean getAcceptThirdPartyCookies(); + + /** + * Sets the text size of the page. The default is {@link TextSize#NORMAL}. + * + * @param t the text size as a {@link TextSize} value + * @deprecated Use {@link #setTextZoom} instead. + */ + @Deprecated + public synchronized void setTextSize(TextSize t) { + setTextZoom(t.value); + } + + /** + * Gets the text size of the page. If the text size was previously specified in + * percent using {@link #setTextZoom}, this will return the closest matching + * {@link TextSize}. + * + * @return the text size as a {@link TextSize} value + * @see #setTextSize + * @deprecated Use {@link #getTextZoom} instead. + */ + @Deprecated + public synchronized TextSize getTextSize() { + return null; + } + + /** + * Sets the default zoom density of the page. This must be called from the UI + * thread. The default is {@link ZoomDensity#MEDIUM}. + * + * This setting is not recommended for use in new applications. If the WebView + * is utilized to display mobile-oriented pages, the desired effect can be + * achieved by adjusting 'width' and 'initial-scale' attributes of page's 'meta + * viewport' tag. For pages lacking the tag, + * {@link android.webkit.WebView#setInitialScale} and + * {@link #setUseWideViewPort} can be used. + * + * @param zoom the zoom density + * @deprecated This method is no longer supported, see the function + * documentation for recommended alternatives. + */ + @Deprecated + public abstract void setDefaultZoom(ZoomDensity zoom); + + /** + * Gets the default zoom density of the page. This should be called from the UI + * thread. + * + * This setting is not recommended for use in new applications. + * + * @return the zoom density + * @see #setDefaultZoom + * @deprecated Will only return the default value. + */ + @Deprecated + public abstract ZoomDensity getDefaultZoom(); + + /** + * Enables using light touches to make a selection and activate mouseovers. + * + * @deprecated From {@link android.os.Build.VERSION_CODES#JELLY_BEAN} this + * setting is obsolete and has no effect. + */ + @Deprecated + public abstract void setLightTouchEnabled(boolean enabled); + + /** + * Gets whether light touches are enabled. + * + * @see #setLightTouchEnabled + * @deprecated This setting is obsolete. + */ + @Deprecated + public abstract boolean getLightTouchEnabled(); + + /** + * Controlled a rendering optimization that is no longer present. Setting it now + * has no effect. + * + * @deprecated This setting now has no effect. + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} + */ + @Deprecated + public void setUseDoubleTree(boolean use) { + // Specified to do nothing, so no need for derived classes to override. + } + + /** + * Controlled a rendering optimization that is no longer present. Setting it now + * has no effect. + * + * @deprecated This setting now has no effect. + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} + */ + @Deprecated + public boolean getUseDoubleTree() { + // Returns false unconditionally, so no need for derived classes to override. + return false; + } + + /** + * Sets the user-agent string using an integer code. + *

      + *
    • 0 means the WebView should use an Android user-agent string
    • + *
    • 1 means the WebView should use a desktop user-agent string
    • + *
    + * Other values are ignored. The default is an Android user-agent string, i.e. + * code value 0. + * + * @param ua the integer code for the user-agent string + * @deprecated Please use {@link #setUserAgentString} instead. + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} + */ + @Deprecated + public abstract void setUserAgent(int ua); + + /** + * Gets the user-agent as an integer code. + *
      + *
    • -1 means the WebView is using a custom user-agent string set with + * {@link #setUserAgentString}
    • + *
    • 0 means the WebView should use an Android user-agent string
    • + *
    • 1 means the WebView should use a desktop user-agent string
    • + *
    + * + * @return the integer code for the user-agent string + * @see #setUserAgent + * @deprecated Please use {@link #getUserAgentString} instead. + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} + */ + @Deprecated + public abstract int getUserAgent(); + + /** + * Sets whether the WebView should enable support for the "viewport" + * HTML meta tag or should use a wide viewport. When the value of the setting is + * {@code false}, the layout width is always set to the width of the WebView + * control in device-independent (CSS) pixels. When the value is {@code true} + * and the page contains the viewport meta tag, the value of the width specified + * in the tag is used. If the page does not contain the tag or does not provide + * a width, then a wide viewport will be used. + * + * @param use whether to enable support for the viewport meta tag + */ + public abstract void setUseWideViewPort(boolean use); + + /** + * Gets whether the WebView supports the "viewport" HTML meta tag or + * will use a wide viewport. + * + * @return {@code true} if the WebView supports the viewport meta tag + * @see #setUseWideViewPort + */ + public abstract boolean getUseWideViewPort(); + + /** + * Sets whether the WebView whether supports multiple windows. If set to true, + * {@link WebChromeClient#onCreateWindow} must be implemented by the host + * application. The default is {@code false}. + * + * @param support whether to support multiple windows + */ + public abstract void setSupportMultipleWindows(boolean support); + + /** + * Gets whether the WebView supports multiple windows. + * + * @return {@code true} if the WebView supports multiple windows + * @see #setSupportMultipleWindows + */ + public abstract boolean supportMultipleWindows(); + + /** + * Sets the underlying layout algorithm. This will cause a re-layout of the + * WebView. The default is {@link LayoutAlgorithm#NARROW_COLUMNS}. + * + * @param l the layout algorithm to use, as a {@link LayoutAlgorithm} value + */ + public abstract void setLayoutAlgorithm(LayoutAlgorithm l); + + /** + * Gets the current layout algorithm. + * + * @return the layout algorithm in use, as a {@link LayoutAlgorithm} value + * @see #setLayoutAlgorithm + */ + public abstract LayoutAlgorithm getLayoutAlgorithm(); + + /** + * Sets the standard font family name. The default is "sans-serif". + * + * @param font a font family name + */ + public abstract void setStandardFontFamily(String font); + + /** + * Gets the standard font family name. + * + * @return the standard font family name as a string + * @see #setStandardFontFamily + */ + public abstract String getStandardFontFamily(); + + /** + * Sets the fixed font family name. The default is "monospace". + * + * @param font a font family name + */ + public abstract void setFixedFontFamily(String font); + + /** + * Gets the fixed font family name. + * + * @return the fixed font family name as a string + * @see #setFixedFontFamily + */ + public abstract String getFixedFontFamily(); + + /** + * Sets the sans-serif font family name. The default is "sans-serif". + * + * @param font a font family name + */ + public abstract void setSansSerifFontFamily(String font); + + /** + * Gets the sans-serif font family name. + * + * @return the sans-serif font family name as a string + * @see #setSansSerifFontFamily + */ + public abstract String getSansSerifFontFamily(); + + /** + * Sets the serif font family name. The default is "sans-serif". + * + * @param font a font family name + */ + public abstract void setSerifFontFamily(String font); + + /** + * Gets the serif font family name. The default is "serif". + * + * @return the serif font family name as a string + * @see #setSerifFontFamily + */ + public abstract String getSerifFontFamily(); + + /** + * Sets the cursive font family name. The default is "cursive". + * + * @param font a font family name + */ + public abstract void setCursiveFontFamily(String font); + + /** + * Gets the cursive font family name. + * + * @return the cursive font family name as a string + * @see #setCursiveFontFamily + */ + public abstract String getCursiveFontFamily(); + + /** + * Sets the fantasy font family name. The default is "fantasy". + * + * @param font a font family name + */ + public abstract void setFantasyFontFamily(String font); + + /** + * Gets the fantasy font family name. + * + * @return the fantasy font family name as a string + * @see #setFantasyFontFamily + */ + public abstract String getFantasyFontFamily(); + + /** + * Sets the minimum font size. The default is 8. + * + * @param size a non-negative integer between 1 and 72. Any number outside the + * specified range will be pinned. + */ + public abstract void setMinimumFontSize(int size); + + /** + * Gets the minimum font size. + * + * @return a non-negative integer between 1 and 72 + * @see #setMinimumFontSize + */ + public abstract int getMinimumFontSize(); + + /** + * Sets the minimum logical font size. The default is 8. + * + * @param size a non-negative integer between 1 and 72. Any number outside the + * specified range will be pinned. + */ + public abstract void setMinimumLogicalFontSize(int size); + + /** + * Gets the minimum logical font size. + * + * @return a non-negative integer between 1 and 72 + * @see #setMinimumLogicalFontSize + */ + public abstract int getMinimumLogicalFontSize(); + + /** + * Sets the default font size. The default is 16. + * + * @param size a non-negative integer between 1 and 72. Any number outside the + * specified range will be pinned. + */ + public abstract void setDefaultFontSize(int size); + + /** + * Gets the default font size. + * + * @return a non-negative integer between 1 and 72 + * @see #setDefaultFontSize + */ + public abstract int getDefaultFontSize(); + + /** + * Sets the default fixed font size. The default is 16. + * + * @param size a non-negative integer between 1 and 72. Any number outside the + * specified range will be pinned. + */ + public abstract void setDefaultFixedFontSize(int size); + + /** + * Gets the default fixed font size. + * + * @return a non-negative integer between 1 and 72 + * @see #setDefaultFixedFontSize + */ + public abstract int getDefaultFixedFontSize(); + + /** + * Sets whether the WebView should load image resources. Note that this method + * controls loading of all images, including those embedded using the data URI + * scheme. Use {@link #setBlockNetworkImage} to control loading only of images + * specified using network URI schemes. Note that if the value of this setting + * is changed from {@code false} to {@code true}, all images resources + * referenced by content currently displayed by the WebView are loaded + * automatically. The default is {@code true}. + * + * @param flag whether the WebView should load image resources + */ + public abstract void setLoadsImagesAutomatically(boolean flag); + + /** + * Gets whether the WebView loads image resources. This includes images embedded + * using the data URI scheme. + * + * @return {@code true} if the WebView loads image resources + * @see #setLoadsImagesAutomatically + */ + public abstract boolean getLoadsImagesAutomatically(); + + /** + * Sets whether the WebView should not load image resources from the network + * (resources accessed via http and https URI schemes). Note that this method + * has no effect unless {@link #getLoadsImagesAutomatically} returns + * {@code true}. Also note that disabling all network loads using + * {@link #setBlockNetworkLoads} will also prevent network images from loading, + * even if this flag is set to false. When the value of this setting is changed + * from {@code true} to {@code false}, network images resources referenced by + * content currently displayed by the WebView are fetched automatically. The + * default is {@code false}. + * + * @param flag whether the WebView should not load image resources from the + * network + * @see #setBlockNetworkLoads + */ + public abstract void setBlockNetworkImage(boolean flag); + + /** + * Gets whether the WebView does not load image resources from the network. + * + * @return {@code true} if the WebView does not load image resources from the + * network + * @see #setBlockNetworkImage + */ + public abstract boolean getBlockNetworkImage(); + + /** + * Sets whether the WebView should not load resources from the network. Use + * {@link #setBlockNetworkImage} to only avoid loading image resources. Note + * that if the value of this setting is changed from {@code true} to + * {@code false}, network resources referenced by content currently displayed by + * the WebView are not fetched until {@link android.webkit.WebView#reload} is + * called. If the application does not have the + * {@link android.Manifest.permission#INTERNET} permission, attempts to set a + * value of {@code false} will cause a {@link java.lang.SecurityException} to be + * thrown. The default value is {@code false} if the application has the + * {@link android.Manifest.permission#INTERNET} permission, otherwise it is + * {@code true}. + * + * @param flag {@code true} means block network loads by the WebView + * @see android.webkit.WebView#reload + */ + public abstract void setBlockNetworkLoads(boolean flag); + + /** + * Gets whether the WebView does not load any resources from the network. + * + * @return {@code true} if the WebView does not load any resources from the + * network + * @see #setBlockNetworkLoads + */ + public abstract boolean getBlockNetworkLoads(); + + /** + * Tells the WebView to enable JavaScript execution. The default is + * {@code false}. + * + * @param flag {@code true} if the WebView should execute JavaScript + */ + public abstract void setJavaScriptEnabled(boolean flag); + + /** + * Sets whether JavaScript running in the context of a file scheme URL should be + * allowed to access content from any origin. This includes access to content + * from other file scheme URLs. See {@link #setAllowFileAccessFromFileURLs}. To + * enable the most restrictive, and therefore secure policy, this setting should + * be disabled. Note that this setting affects only JavaScript access to file + * scheme resources. Other access to such resources, for example, from image + * HTML elements, is unaffected. To prevent possible violation of same domain + * policy when targeting + * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and earlier, + * you should explicitly set this value to {@code false}. + *

    + * The default value is {@code true} for apps targeting + * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and below, and + * {@code false} when targeting + * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} and above. + * + * @param flag whether JavaScript running in the context of a file scheme URL + * should be allowed to access content from any origin + */ + public abstract void setAllowUniversalAccessFromFileURLs(boolean flag); + + /** + * Sets whether JavaScript running in the context of a file scheme URL should be + * allowed to access content from other file scheme URLs. To enable the most + * restrictive, and therefore secure, policy this setting should be disabled. + * Note that the value of this setting is ignored if the value of + * {@link #getAllowUniversalAccessFromFileURLs} is {@code true}. Note too, that + * this setting affects only JavaScript access to file scheme resources. Other + * access to such resources, for example, from image HTML elements, is + * unaffected. To prevent possible violation of same domain policy when + * targeting {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and + * earlier, you should explicitly set this value to {@code false}. + *

    + * The default value is {@code true} for apps targeting + * {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1} and below, and + * {@code false} when targeting + * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} and above. + * + * @param flag whether JavaScript running in the context of a file scheme URL + * should be allowed to access content from other file scheme URLs + */ + public abstract void setAllowFileAccessFromFileURLs(boolean flag); + + /** + * Sets whether the WebView should enable plugins. The default is {@code false}. + * + * @param flag {@code true} if plugins should be enabled + * @deprecated This method has been deprecated in favor of + * {@link #setPluginState} + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} + */ + @Deprecated + public abstract void setPluginsEnabled(boolean flag); + + /** + * Tells the WebView to enable, disable, or have plugins on demand. On demand + * mode means that if a plugin exists that can handle the embedded content, a + * placeholder icon will be shown instead of the plugin. When the placeholder is + * clicked, the plugin will be enabled. The default is {@link PluginState#OFF}. + * + * @param state a PluginState value + * @deprecated Plugins will not be supported in future, and should not be used. + */ + @Deprecated + public abstract void setPluginState(PluginState state); + + /** + * Sets a custom path to plugins used by the WebView. This method is obsolete + * since each plugin is now loaded from its own package. + * + * @param pluginsPath a String path to the directory containing plugins + * @deprecated This method is no longer used as plugins are loaded from their + * own APK via the system's package manager. + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} + */ + @Deprecated + public void setPluginsPath(String pluginsPath) { + // Specified to do nothing, so no need for derived classes to override. + } + + /** + * Sets the path to where database storage API databases should be saved. In + * order for the database storage API to function correctly, this method must be + * called with a path to which the application can write. This method should + * only be called once: repeated calls are ignored. + * + * @param databasePath a path to the directory where databases should be saved. + * @deprecated Database paths are managed by the implementation and calling this + * method will have no effect. + */ + @Deprecated + public abstract void setDatabasePath(String databasePath); + + /** + * Sets the path where the Geolocation databases should be saved. In order for + * Geolocation permissions and cached positions to be persisted, this method + * must be called with a path to which the application can write. + * + * @param databasePath a path to the directory where databases should be saved. + * @deprecated Geolocation database are managed by the implementation and + * calling this method will have no effect. + */ + @Deprecated + public abstract void setGeolocationDatabasePath(String databasePath); + + /** + * Sets whether the Application Caches API should be enabled. The default is + * {@code false}. Note that in order for the Application Caches API to be + * enabled, a valid database path must also be supplied to + * {@link #setAppCachePath}. + * + * @param flag {@code true} if the WebView should enable Application Caches + */ + public abstract void setAppCacheEnabled(boolean flag); + + /** + * Sets the path to the Application Caches files. In order for the Application + * Caches API to be enabled, this method must be called with a path to which the + * application can write. This method should only be called once: repeated calls + * are ignored. + * + * @param appCachePath a String path to the directory containing Application + * Caches files. + * @see #setAppCacheEnabled + */ + public abstract void setAppCachePath(String appCachePath); + + /** + * Sets the maximum size for the Application Cache content. The passed size will + * be rounded to the nearest value that the database can support, so this should + * be viewed as a guide, not a hard limit. Setting the size to a value less than + * current database size does not cause the database to be trimmed. The default + * size is {@link Long#MAX_VALUE}. It is recommended to leave the maximum size + * set to the default value. + * + * @param appCacheMaxSize the maximum size in bytes + * @deprecated In future quota will be managed automatically. + */ + @Deprecated + public abstract void setAppCacheMaxSize(long appCacheMaxSize); + + /** + * Sets whether the database storage API is enabled. The default value is false. + * See also {@link #setDatabasePath} for how to correctly set up the database + * storage API. + * + * This setting is global in effect, across all WebView instances in a process. + * Note you should only modify this setting prior to making any WebView + * page load within a given process, as the WebView implementation may ignore + * changes to this setting after that point. + * + * @param flag {@code true} if the WebView should use the database storage API + */ + public abstract void setDatabaseEnabled(boolean flag); + + /** + * Sets whether the DOM storage API is enabled. The default value is + * {@code false}. + * + * @param flag {@code true} if the WebView should use the DOM storage API + */ + public abstract void setDomStorageEnabled(boolean flag); + + /** + * Gets whether the DOM Storage APIs are enabled. + * + * @return {@code true} if the DOM Storage APIs are enabled + * @see #setDomStorageEnabled + */ + public abstract boolean getDomStorageEnabled(); + + /** + * Gets the path to where database storage API databases are saved. + * + * @return the String path to the database storage API databases + * @see #setDatabasePath + * @deprecated Database paths are managed by the implementation this method is + * obsolete. + */ + @Deprecated + public abstract String getDatabasePath(); + + /** + * Gets whether the database storage API is enabled. + * + * @return {@code true} if the database storage API is enabled + * @see #setDatabaseEnabled + */ + public abstract boolean getDatabaseEnabled(); + + /** + * Sets whether Geolocation is enabled. The default is {@code true}. + *

    + * Please note that in order for the Geolocation API to be usable by a page in + * the WebView, the following requirements must be met: + *

      + *
    • an application must have permission to access the device location, see + * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}, + * {@link android.Manifest.permission#ACCESS_FINE_LOCATION}; + *
    • an application must provide an implementation of the + * {@link WebChromeClient#onGeolocationPermissionsShowPrompt} callback to + * receive notifications that a page is requesting access to location via the + * JavaScript Geolocation API. + *
    + *

    + * + * @param flag whether Geolocation should be enabled + */ + public abstract void setGeolocationEnabled(boolean flag); + + /** + * Gets whether JavaScript is enabled. + * + * @return {@code true} if JavaScript is enabled + * @see #setJavaScriptEnabled + */ + public abstract boolean getJavaScriptEnabled(); + + /** + * Gets whether JavaScript running in the context of a file scheme URL can + * access content from any origin. This includes access to content from other + * file scheme URLs. + * + * @return whether JavaScript running in the context of a file scheme URL can + * access content from any origin + * @see #setAllowUniversalAccessFromFileURLs + */ + public abstract boolean getAllowUniversalAccessFromFileURLs(); + + /** + * Gets whether JavaScript running in the context of a file scheme URL can + * access content from other file scheme URLs. + * + * @return whether JavaScript running in the context of a file scheme URL can + * access content from other file scheme URLs + * @see #setAllowFileAccessFromFileURLs + */ + public abstract boolean getAllowFileAccessFromFileURLs(); + + /** + * Gets whether plugins are enabled. + * + * @return {@code true} if plugins are enabled + * @see #setPluginsEnabled + * @deprecated This method has been replaced by {@link #getPluginState} + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} + */ + @Deprecated + public abstract boolean getPluginsEnabled(); + + /** + * Gets the current state regarding whether plugins are enabled. + * + * @return the plugin state as a {@link PluginState} value + * @see #setPluginState + * @deprecated Plugins will not be supported in future, and should not be used. + */ + @Deprecated + public abstract PluginState getPluginState(); + + /** + * Gets the directory that contains the plugin libraries. This method is + * obsolete since each plugin is now loaded from its own package. + * + * @return an empty string + * @deprecated This method is no longer used as plugins are loaded from their + * own APK via the system's package manager. + * @hide Since API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2} + */ + @Deprecated + public String getPluginsPath() { + // Unconditionally returns empty string, so no need for derived classes to + // override. + return ""; + } + + /** + * Tells JavaScript to open windows automatically. This applies to the + * JavaScript function {@code window.open()}. The default is {@code false}. + * + * @param flag {@code true} if JavaScript can open windows automatically + */ + public abstract void setJavaScriptCanOpenWindowsAutomatically(boolean flag); + + /** + * Gets whether JavaScript can open windows automatically. + * + * @return {@code true} if JavaScript can open windows automatically during + * {@code window.open()} + * @see #setJavaScriptCanOpenWindowsAutomatically + */ + public abstract boolean getJavaScriptCanOpenWindowsAutomatically(); + + /** + * Sets the default text encoding name to use when decoding html pages. The + * default is "UTF-8". + * + * @param encoding the text encoding name + */ + public abstract void setDefaultTextEncodingName(String encoding); + + /** + * Gets the default text encoding name. + * + * @return the default text encoding name as a string + * @see #setDefaultTextEncodingName + */ + public abstract String getDefaultTextEncodingName(); + + /** + * Sets the WebView's user-agent string. If the string is {@code null} or empty, + * the system default value will be used. + * + * Note that starting from {@link android.os.Build.VERSION_CODES#KITKAT} Android + * version, changing the user-agent while loading a web page causes WebView to + * initiate loading once again. + * + * @param ua new user-agent string + */ + public abstract void setUserAgentString(String ua); + + /** + * Gets the WebView's user-agent string. + * + * @return the WebView's user-agent string + * @see #setUserAgentString + */ + public abstract String getUserAgentString(); + + /** + * Returns the default User-Agent used by a WebView. An instance of WebView + * could use a different User-Agent if a call is made to + * {@link WebSettings#setUserAgentString(String)}. + * + * @param context a Context object used to access application assets + */ + public static String getDefaultUserAgent(Context context) { + return null; + } + + /** + * Tells the WebView whether it needs to set a node to have focus when + * {@link WebView#requestFocus(int, android.graphics.Rect)} is called. The + * default value is {@code true}. + * + * @param flag whether the WebView needs to set a node + */ + public abstract void setNeedInitialFocus(boolean flag); + + /** + * Sets the priority of the Render thread. Unlike the other settings, this one + * only needs to be called once per process. The default value is + * {@link RenderPriority#NORMAL}. + * + * @param priority the priority + * @deprecated It is not recommended to adjust thread priorities, and this will + * not be supported in future versions. + */ + @Deprecated + public abstract void setRenderPriority(RenderPriority priority); + + /** + * Overrides the way the cache is used. The way the cache is used is based on + * the navigation type. For a normal page load, the cache is checked and content + * is re-validated as needed. When navigating back, content is not revalidated, + * instead the content is just retrieved from the cache. This method allows the + * client to override this behavior by specifying one of {@link #LOAD_DEFAULT}, + * {@link #LOAD_CACHE_ELSE_NETWORK}, {@link #LOAD_NO_CACHE} or + * {@link #LOAD_CACHE_ONLY}. The default value is {@link #LOAD_DEFAULT}. + * + * @param mode the mode to use + */ + public abstract void setCacheMode(@CacheMode int mode); + + /** + * Gets the current setting for overriding the cache mode. + * + * @return the current setting for overriding the cache mode + * @see #setCacheMode + */ + public abstract int getCacheMode(); + + /** + * Configures the WebView's behavior when a secure origin attempts to load a + * resource from an insecure origin. + * + * By default, apps that target {@link android.os.Build.VERSION_CODES#KITKAT} or + * below default to {@link #MIXED_CONTENT_ALWAYS_ALLOW}. Apps targeting + * {@link android.os.Build.VERSION_CODES#LOLLIPOP} default to + * {@link #MIXED_CONTENT_NEVER_ALLOW}. + * + * The preferred and most secure mode of operation for the WebView is + * {@link #MIXED_CONTENT_NEVER_ALLOW} and use of + * {@link #MIXED_CONTENT_ALWAYS_ALLOW} is strongly discouraged. + * + * @param mode The mixed content mode to use. One of + * {@link #MIXED_CONTENT_NEVER_ALLOW}, + * {@link #MIXED_CONTENT_ALWAYS_ALLOW} or + * {@link #MIXED_CONTENT_COMPATIBILITY_MODE}. + */ + public abstract void setMixedContentMode(int mode); + + /** + * Gets the current behavior of the WebView with regard to loading insecure + * content from a secure origin. + * + * @return The current setting, one of {@link #MIXED_CONTENT_NEVER_ALLOW}, + * {@link #MIXED_CONTENT_ALWAYS_ALLOW} or + * {@link #MIXED_CONTENT_COMPATIBILITY_MODE}. + */ + public abstract int getMixedContentMode(); + + /** + * Sets whether to use a video overlay for embedded encrypted video. In API + * levels prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, encrypted + * video can only be rendered directly on a secure video surface, so it had been + * a hard problem to play encrypted video in HTML. When this flag is on, WebView + * can play encrypted video (MSE/EME) by using a video overlay (aka + * hole-punching) for videos embedded using HTML <video> tag.
    + * Caution: This setting is intended for use only in a narrow set of + * circumstances and apps should only enable it if they require playback of + * encrypted video content. It will impose the following limitations on the + * WebView: + *

      + *
    • Only one video overlay can be played at a time. + *
    • Changes made to position or dimensions of a video element may be + * propagated to the corresponding video overlay with a noticeable delay. + *
    • The video overlay is not visible to web APIs and as such may not interact + * with script or styling. For example, CSS styles applied to the <video> + * tag may be ignored. + *
    + * This is not an exhaustive set of constraints and it may vary with new + * versions of the WebView. + * + * @hide + */ + public abstract void setVideoOverlayForEmbeddedEncryptedVideoEnabled(boolean flag); + + /** + * Gets whether a video overlay will be used for embedded encrypted video. + * + * @return {@code true} if WebView uses a video overlay for embedded encrypted + * video. + * @see #setVideoOverlayForEmbeddedEncryptedVideoEnabled + * @hide + */ + public abstract boolean getVideoOverlayForEmbeddedEncryptedVideoEnabled(); + + /** + * Sets whether this WebView should raster tiles when it is offscreen but + * attached to a window. Turning this on can avoid rendering artifacts when + * animating an offscreen WebView on-screen. Offscreen WebViews in this mode use + * more memory. The default value is false.
    + * Please follow these guidelines to limit memory usage: + *
      + *
    • WebView size should be not be larger than the device screen size. + *
    • Limit use of this mode to a small number of WebViews. Use it for visible + * WebViews and WebViews about to be animated to visible. + *
    + */ + public abstract void setOffscreenPreRaster(boolean enabled); + + /** + * Gets whether this WebView should raster tiles when it is offscreen but + * attached to a window. + * + * @return {@code true} if this WebView will raster tiles when it is offscreen + * but attached to a window. + */ + public abstract boolean getOffscreenPreRaster(); + + /** + * Sets whether Safe Browsing is enabled. Safe Browsing allows WebView to + * protect against malware and phishing attacks by verifying the links. + * + *

    + * Safe Browsing can be disabled for all WebViews using a manifest tag (read + * general Safe + * Browsing info). The manifest tag has a lower precedence than this API. + * + *

    + * Safe Browsing is enabled by default for devices which support it. + * + * @param enabled Whether Safe Browsing is enabled. + */ + public abstract void setSafeBrowsingEnabled(boolean enabled); + + /** + * Gets whether Safe Browsing is enabled. See {@link #setSafeBrowsingEnabled}. + * + * @return {@code true} if Safe Browsing is enabled and {@code false} otherwise. + */ + public abstract boolean getSafeBrowsingEnabled(); +} diff --git a/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebView.java b/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebView.java new file mode 100644 index 000000000000..1b377ad3e178 --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebView.java @@ -0,0 +1,602 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.webkit; + +import android.content.Context; +import android.content.Intent; + +import java.io.File; +import java.util.List; +import java.util.Map; + +/** + *

    + * A View that displays web pages. This class is the basis upon which you can + * roll your own web browser or simply display some online content within your + * Activity. It uses the WebKit rendering engine to display web pages and + * includes methods to navigate forward and backward through a history, zoom in + * and out, perform text searches and more. + * + *

    + * Note that, in order for your Activity to access the Internet and load web + * pages in a WebView, you must add the {@code INTERNET} permissions to your + * Android Manifest file: + * + *

    + * {@code }
    + * 
    + * + *

    + * This must be a child of the {@code } + * element. + * + *

    + * For more information, read + * Building Web Apps in + * WebView. + * + *

    Basic usage

    + * + *

    + * By default, a WebView provides no browser-like widgets, does not enable + * JavaScript and web page errors are ignored. If your goal is only to display + * some HTML as a part of your UI, this is probably fine; the user won't need to + * interact with the web page beyond reading it, and the web page won't need to + * interact with the user. If you actually want a full-blown web browser, then + * you probably want to invoke the Browser application with a URL Intent rather + * than show it with a WebView. For example: + * + *

    + * Uri uri = Uri.parse("https://www.example.com");
    + * Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    + * startActivity(intent);
    + * 
    + *

    + * See {@link android.content.Intent} for more information. + * + *

    + * To provide a WebView in your own Activity, include a {@code } in + * your layout, or set the entire Activity window as a WebView during + * {@link android.app.Activity#onCreate(Bundle) onCreate()}: + * + *

    + * WebView webview = new WebView(this);
    + * setContentView(webview);
    + * 
    + * + *

    + * Then load the desired web page: + * + *

    + * // Simplest usage: note that an exception will NOT be thrown
    + * // if there is an error loading this page (see below).
    + * webview.loadUrl("https://example.com/");
    + *
    + * // OR, you can also load from an HTML string:
    + * String summary = "<html><body>You scored <b>192</b> points.</body></html>";
    + * webview.loadData(summary, "text/html", null);
    + * // ... although note that there are restrictions on what this HTML can do.
    + * // See {@link #loadData(String,String,String)} and {@link
    + * #loadDataWithBaseURL(String,String,String,String,String)} for more info.
    + * // Also see {@link #loadData(String,String,String)} for information on encoding special
    + * // characters.
    + * 
    + * + *

    + * A WebView has several customization points where you can add your own + * behavior. These are: + * + *

      + *
    • Creating and setting a {@link android.webkit.WebChromeClient} subclass. + * This class is called when something that might impact a browser UI happens, + * for instance, progress updates and JavaScript alerts are sent here (see + * Debugging + * Tasks).
    • + *
    • Creating and setting a {@link android.webkit.WebViewClient} subclass. It + * will be called when things happen that impact the rendering of the content, + * eg, errors or form submissions. You can also intercept URL loading here (via + * {@link android.webkit.WebViewClient#shouldOverrideUrlLoading(WebView,String) + * shouldOverrideUrlLoading()}).
    • + *
    • Modifying the {@link android.webkit.WebSettings}, such as enabling + * JavaScript with + * {@link android.webkit.WebSettings#setJavaScriptEnabled(boolean) + * setJavaScriptEnabled()}.
    • + *
    • Injecting Java objects into the WebView using the + * {@link android.webkit.WebView#addJavascriptInterface} method. This method + * allows you to inject Java objects into a page's JavaScript context, so that + * they can be accessed by JavaScript in the page.
    • + *
    + * + *

    + * Here's a more complicated example, showing error handling, settings, and + * progress notification: + * + *

    + * // Let's display the progress in the activity title bar, like the
    + * // browser app does.
    + * getWindow().requestFeature(Window.FEATURE_PROGRESS);
    + *
    + * webview.getSettings().setJavaScriptEnabled(true);
    + *
    + * final Activity activity = this;
    + * webview.setWebChromeClient(new WebChromeClient() {
    + *     public void onProgressChanged(WebView view, int progress) {
    + *         // Activities and WebViews measure progress with different scales.
    + *         // The progress meter will automatically disappear when we reach 100%
    + *         activity.setProgress(progress * 1000);
    + *     }
    + * });
    + * webview.setWebViewClient(new WebViewClient() {
    + *     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    + *         Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
    + *     }
    + * });
    + *
    + * webview.loadUrl("https://developer.android.com/");
    + * 
    + * + *

    Zoom

    + * + *

    + * To enable the built-in zoom, set {@link #getSettings() + * WebSettings}.{@link WebSettings#setBuiltInZoomControls(boolean)} (introduced + * in API level {@link android.os.Build.VERSION_CODES#CUPCAKE}). + * + *

    + * Note: Using zoom if either the height or width is set to + * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} may lead to + * undefined behavior and should be avoided. + * + *

    Cookie and window management

    + * + *

    + * For obvious security reasons, your application has its own cache, cookie + * store etc.—it does not share the Browser application's data. + * + *

    + * By default, requests by the HTML to open new windows are ignored. This is + * {@code true} whether they be opened by JavaScript or by the target attribute + * on a link. You can customize your {@link WebChromeClient} to provide your own + * behavior for opening multiple windows, and render them in whatever manner you + * want. + * + *

    + * The standard behavior for an Activity is to be destroyed and recreated when + * the device orientation or any other configuration changes. This will cause + * the WebView to reload the current page. If you don't want that, you can set + * your Activity to handle the {@code orientation} and {@code keyboardHidden} + * changes, and then just leave the WebView alone. It'll automatically re-orient + * itself as appropriate. Read + * Handling + * Runtime Changes for more information about how to handle configuration + * changes during runtime. + * + * + *

    Building web pages to support different screen densities

    + * + *

    + * The screen density of a device is based on the screen resolution. A screen + * with low density has fewer available pixels per inch, where a screen with + * high density has more — sometimes significantly more — pixels per + * inch. The density of a screen is important because, other things being equal, + * a UI element (such as a button) whose height and width are defined in terms + * of screen pixels will appear larger on the lower density screen and smaller + * on the higher density screen. For simplicity, Android collapses all actual + * screen densities into three generalized densities: high, medium, and low. + *

    + * By default, WebView scales a web page so that it is drawn at a size that + * matches the default appearance on a medium density screen. So, it applies + * 1.5x scaling on a high density screen (because its pixels are smaller) and + * 0.75x scaling on a low density screen (because its pixels are bigger). + * Starting with API level {@link android.os.Build.VERSION_CODES#ECLAIR}, + * WebView supports DOM, CSS, and meta tag features to help you (as a web + * developer) target screens with different screen densities. + *

    + * Here's a summary of the features you can use to handle different screen + * densities: + *

      + *
    • The {@code window.devicePixelRatio} DOM property. The value of this + * property specifies the default scaling factor used for the current device. + * For example, if the value of {@code + * window.devicePixelRatio} is "1.0", then the device is considered a medium + * density (mdpi) device and default scaling is not applied to the web page; if + * the value is "1.5", then the device is considered a high density device + * (hdpi) and the page content is scaled 1.5x; if the value is "0.75", then the + * device is considered a low density device (ldpi) and the content is scaled + * 0.75x.
    • + *
    • The {@code -webkit-device-pixel-ratio} CSS media query. Use this to + * specify the screen densities for which this style sheet is to be used. The + * corresponding value should be either "0.75", "1", or "1.5", to indicate that + * the styles are for devices with low density, medium density, or high density + * screens, respectively. For example: + * + *
      + * <link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" />
      + * 
      + *

      + * The {@code hdpi.css} stylesheet is only used for devices with a screen pixel + * ratio of 1.5, which is the high density pixel ratio.

    • + *
    + * + *

    HTML5 Video support

    + * + *

    + * In order to support inline HTML5 video in your application you need to have + * hardware acceleration turned on. + * + *

    Full screen support

    + * + *

    + * In order to support full screen — for video or other HTML content + * — you need to set a {@link android.webkit.WebChromeClient} and + * implement both + * {@link WebChromeClient#onShowCustomView(View, WebChromeClient.CustomViewCallback)} + * and {@link WebChromeClient#onHideCustomView()}. If the implementation of + * either of these two methods is missing then the web contents will not be + * allowed to enter full screen. Optionally you can implement + * {@link WebChromeClient#getVideoLoadingProgressView()} to customize the View + * displayed whilst a video is loading. + * + *

    HTML5 Geolocation API support

    + * + *

    + * For applications targeting Android N and later releases (API level > + * {@link android.os.Build.VERSION_CODES#M}) the geolocation api is only + * supported on secure origins such as https. For such applications requests to + * geolocation api on non-secure origins are automatically denied without + * invoking the corresponding + * {@link WebChromeClient#onGeolocationPermissionsShowPrompt(String, GeolocationPermissions.Callback)} + * method. + * + *

    Layout size

    + *

    + * It is recommended to set the WebView layout height to a fixed value or to + * {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT} instead of using + * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT}. When using + * {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT} for the height none + * of the WebView's parents should use a + * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} layout height since + * that could result in incorrect sizing of the views. + * + *

    + * Setting the WebView's height to + * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} enables the + * following behaviors: + *

      + *
    • The HTML body layout height is set to a fixed value. This means that + * elements with a height relative to the HTML body may not be sized correctly. + *
    • + *
    • For applications targeting {@link android.os.Build.VERSION_CODES#KITKAT} + * and earlier SDKs the HTML viewport meta tag will be ignored in order to + * preserve backwards compatibility.
    • + *
    + * + *

    + * Using a layout width of + * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} is not supported. If + * such a width is used the WebView will attempt to use the width of the parent + * instead. + * + *

    Metrics

    + * + *

    + * WebView may upload anonymous diagnostic data to Google when the user has + * consented. This data helps Google improve WebView. Data is collected on a + * per-app basis for each app which has instantiated a WebView. An individual + * app can opt out of this feature by putting the following tag in its + * manifest's {@code } element: + * + *

    + * <manifest>
    + *     <application>
    + *         ...
    + *         <meta-data android:name="android.webkit.WebView.MetricsOptOut"
    + *             android:value="true" />
    + *     </application>
    + * </manifest>
    + * 
    + *

    + * Data will only be uploaded for a given app if the user has consented AND the + * app has not opted out. + * + *

    Safe Browsing

    + * + *

    + * With Safe Browsing, WebView will block malicious URLs and present a warning + * UI to the user to allow them to navigate back safely or proceed to the + * malicious page. + *

    + * Safe Browsing is enabled by default on devices which support it. If your app + * needs to disable Safe Browsing for all WebViews, it can do so in the + * manifest's {@code } element: + *

    + * + *

    + * <manifest>
    + *     <application>
    + *         ...
    + *         <meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"
    + *             android:value="false" />
    + *     </application>
    + * </manifest>
    + * 
    + * + *

    + * Otherwise, see {@link WebSettings#setSafeBrowsingEnabled}. + * + */ +// Implementation notes. +// The WebView is a thin API class that delegates its public API to a backend +// WebViewProvider +// class instance. WebView extends {@link AbsoluteLayout} for backward +// compatibility reasons. +// Methods are delegated to the provider implementation: all public API methods +// introduced in this +// file are fully delegated, whereas public and protected methods from the View +// base classes are +// only delegated where a specific need exists for them to do so. +public class WebView { + + /** + * Constructs a new WebView with an Activity Context object. + * + *

    + * Note: WebView should always be instantiated with an Activity Context. + * If instantiated with an Application Context, WebView will be unable to + * provide several features, such as JavaScript dialogs and autofill. + * + * @param context an Activity Context to access application assets + */ + public WebView(Context context) { + } + + /** + * Loads the given URL with the specified additional HTTP headers. + *

    + * Also see compatibility note on {@link #evaluateJavascript}. + * + * @param url the URL of the resource to load + * @param additionalHttpHeaders the additional headers to be used in the HTTP + * request for this URL, specified as a map from + * name to value. Note that if this map contains + * any of the headers that are set by default by + * this WebView, such as those controlling caching, + * accept types or the User-Agent, their values may + * be overridden by this WebView's defaults. + */ + public void loadUrl(String url, Map additionalHttpHeaders) { + } + + /** + * Loads the given URL. + *

    + * Also see compatibility note on {@link #evaluateJavascript}. + * + * @param url the URL of the resource to load + */ + public void loadUrl(String url) { + } + + /** + * Loads the URL with postData using "POST" method into this WebView. If url is + * not a network URL, it will be loaded with {@link #loadUrl(String)} instead, + * ignoring the postData param. + * + * @param url the URL of the resource to load + * @param postData the data will be passed to "POST" request, which must be be + * "application/x-www-form-urlencoded" encoded. + */ + public void postUrl(String url, byte[] postData) { + } + + /** + * Loads the given data into this WebView using a 'data' scheme URL. + *

    + * Note that JavaScript's same origin policy means that script running in a page + * loaded using this method will be unable to access content loaded using any + * scheme other than 'data', including 'http(s)'. To avoid this restriction, use + * {@link #loadDataWithBaseURL(String,String,String,String,String) + * loadDataWithBaseURL()} with an appropriate base URL. + *

    + * The {@code encoding} parameter specifies whether the data is base64 or URL + * encoded. If the data is base64 encoded, the value of the encoding parameter + * must be 'base64'. HTML can be encoded with + * {@link android.util.Base64#encodeToString(byte[],int)} like so: + * + *

    +     * String unencodedHtml = "<html><body>'%28' is the code for '('</body></html>";
    +     * String encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(), Base64.NO_PADDING);
    +     * webView.loadData(encodedHtml, "text/html", "base64");
    +     * 
    + *

    + * For all other values of {@code encoding} (including {@code null}) it is + * assumed that the data uses ASCII encoding for octets inside the range of safe + * URL characters and use the standard %xx hex encoding of URLs for octets + * outside that range. See + * RFC 3986 for + * more information. + *

    + * The {@code mimeType} parameter specifies the format of the data. If WebView + * can't handle the specified MIME type, it will download the data. If + * {@code null}, defaults to 'text/html'. + *

    + * The 'data' scheme URL formed by this method uses the default US-ASCII + * charset. If you need to set a different charset, you should form a 'data' + * scheme URL which explicitly specifies a charset parameter in the mediatype + * portion of the URL and call {@link #loadUrl(String)} instead. Note that the + * charset obtained from the mediatype portion of a data URL always overrides + * that specified in the HTML or XML document itself. + *

    + * Content loaded using this method will have a {@code window.origin} value of + * {@code "null"}. This must not be considered to be a trusted origin by the + * application or by any JavaScript code running inside the WebView (for + * example, event sources in DOM event handlers or web messages), because + * malicious content can also create frames with a null origin. If you need to + * identify the main frame's origin in a trustworthy way, you should use + * {@link #loadDataWithBaseURL(String,String,String,String,String) + * loadDataWithBaseURL()} with a valid HTTP or HTTPS base URL to set the origin. + * + * @param data a String of data in the given encoding + * @param mimeType the MIME type of the data, e.g. 'text/html'. + * @param encoding the encoding of the data + */ + public void loadData(String data, String mimeType, String encoding) { + } + + /** + * Loads the given data into this WebView, using baseUrl as the base URL for the + * content. The base URL is used both to resolve relative URLs and when applying + * JavaScript's same origin policy. The historyUrl is used for the history + * entry. + *

    + * The {@code mimeType} parameter specifies the format of the data. If WebView + * can't handle the specified MIME type, it will download the data. If + * {@code null}, defaults to 'text/html'. + *

    + * Note that content specified in this way can access local device files (via + * 'file' scheme URLs) only if baseUrl specifies a scheme other than 'http', + * 'https', 'ftp', 'ftps', 'about' or 'javascript'. + *

    + * If the base URL uses the data scheme, this method is equivalent to calling + * {@link #loadData(String,String,String) loadData()} and the historyUrl is + * ignored, and the data will be treated as part of a data: URL. If the base URL + * uses any other scheme, then the data will be loaded into the WebView as a + * plain string (i.e. not part of a data URL) and any URL-encoded entities in + * the string will not be decoded. + *

    + * Note that the baseUrl is sent in the 'Referer' HTTP header when requesting + * subresources (images, etc.) of the page loaded using this method. + *

    + * If a valid HTTP or HTTPS base URL is not specified in {@code baseUrl}, then + * content loaded using this method will have a {@code window.origin} value of + * {@code "null"}. This must not be considered to be a trusted origin by the + * application or by any JavaScript code running inside the WebView (for + * example, event sources in DOM event handlers or web messages), because + * malicious content can also create frames with a null origin. If you need to + * identify the main frame's origin in a trustworthy way, you should use a valid + * HTTP or HTTPS base URL to set the origin. + * + * @param baseUrl the URL to use as the page's base URL. If {@code null} + * defaults to 'about:blank'. + * @param data a String of data in the given encoding + * @param mimeType the MIME type of the data, e.g. 'text/html'. + * @param encoding the encoding of the data + * @param historyUrl the URL to use as the history entry. If {@code null} + * defaults to 'about:blank'. If non-null, this must be a + * valid URL. + */ + public void loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl) { + } + + /** + * Sets the WebViewClient that will receive various notifications and + * requests. This will replace the current handler. + * + * @param client an implementation of WebViewClient + * @see #getWebViewClient + */ + public void setWebViewClient(WebViewClient client) { + } + /** + * Gets the WebViewClient. + * + * @return the WebViewClient, or a default client if not yet set + * @see #setWebViewClient + */ + public WebViewClient getWebViewClient() { + return null; + } + + /** + * Injects the supplied Java object into this WebView. The object is + * injected into the JavaScript context of the main frame, using the + * supplied name. This allows the Java object's methods to be + * accessed from JavaScript. For applications targeted to API + * level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} + * and above, only public methods that are annotated with + * {@link android.webkit.JavascriptInterface} can be accessed from JavaScript. + * For applications targeted to API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or below, + * all public methods (including the inherited ones) can be accessed, see the + * important security note below for implications. + *

    Note that injected objects will not appear in JavaScript until the page is next + * (re)loaded. JavaScript should be enabled before injecting the object. For example: + *

    +     * class JsObject {
    +     *    {@literal @}JavascriptInterface
    +     *    public String toString() { return "injectedObject"; }
    +     * }
    +     * webview.getSettings().setJavaScriptEnabled(true);
    +     * webView.addJavascriptInterface(new JsObject(), "injectedObject");
    +     * webView.loadData("", "text/html", null);
    +     * webView.loadUrl("javascript:alert(injectedObject.toString())");
    + *

    + * IMPORTANT: + *

      + *
    • This method can be used to allow JavaScript to control the host + * application. This is a powerful feature, but also presents a security + * risk for apps targeting {@link android.os.Build.VERSION_CODES#JELLY_BEAN} or earlier. + * Apps that target a version later than {@link android.os.Build.VERSION_CODES#JELLY_BEAN} + * are still vulnerable if the app runs on a device running Android earlier than 4.2. + * The most secure way to use this method is to target {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} + * and to ensure the method is called only when running on Android 4.2 or later. + * With these older versions, JavaScript could use reflection to access an + * injected object's public fields. Use of this method in a WebView + * containing untrusted content could allow an attacker to manipulate the + * host application in unintended ways, executing Java code with the + * permissions of the host application. Use extreme care when using this + * method in a WebView which could contain untrusted content.
    • + *
    • JavaScript interacts with Java object on a private, background + * thread of this WebView. Care is therefore required to maintain thread + * safety. + *
    • + *
    • The Java object's fields are not accessible.
    • + *
    • For applications targeted to API level {@link android.os.Build.VERSION_CODES#LOLLIPOP} + * and above, methods of injected Java objects are enumerable from + * JavaScript.
    • + *
    + * + * @param object the Java object to inject into this WebView's JavaScript + * context. {@code null} values are ignored. + * @param name the name used to expose the object in JavaScript + */ + public void addJavascriptInterface(Object object, String name) { + } + /** + * Removes a previously injected Java object from this WebView. Note that + * the removal will not be reflected in JavaScript until the page is next + * (re)loaded. See {@link #addJavascriptInterface}. + * + * @param name the name used to expose the object in JavaScript + */ + public void removeJavascriptInterface(String name) { + } + + /** + * Gets the WebSettings object used to control the settings for this + * WebView. + * + * @return a WebSettings object that can be used to control this WebView's + * settings + */ + public WebSettings getSettings() { + return null; + } + + + +} diff --git a/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebViewClient.java b/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebViewClient.java new file mode 100644 index 000000000000..4b1bd58498b8 --- /dev/null +++ b/java/ql/test/stubs/google-android-9.0.0/android/webkit/WebViewClient.java @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.webkit; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class WebViewClient { + /** + * Give the host application a chance to take over the control when a new url is + * about to be loaded in the current WebView. If WebViewClient is not provided, + * by default WebView will ask Activity Manager to choose the proper handler for + * the url. If WebViewClient is provided, return {@code true} means the host + * application handles the url, while return {@code false} means the current + * WebView handles the url. This method is not called for requests using the + * POST "method". + * + * @param view The WebView that is initiating the callback. + * @param url The url to be loaded. + * @return {@code true} if the host application wants to leave the current + * WebView and handle the url itself, otherwise return {@code false}. + * @deprecated Use {@link #shouldOverrideUrlLoading(WebView, WebResourceRequest) + * shouldOverrideUrlLoading(WebView, WebResourceRequest)} instead. + */ + @Deprecated + public boolean shouldOverrideUrlLoading(WebView view, String url) { + return false; + } + + /** + * Give the host application a chance to take over the control when a new url is + * about to be loaded in the current WebView. If WebViewClient is not provided, + * by default WebView will ask Activity Manager to choose the proper handler for + * the url. If WebViewClient is provided, return {@code true} means the host + * application handles the url, while return {@code false} means the current + * WebView handles the url. + * + *

    + * Notes: + *

      + *
    • This method is not called for requests using the POST + * "method".
    • + *
    • This method is also called for subframes with non-http schemes, thus it + * is strongly disadvised to unconditionally call + * {@link WebView#loadUrl(String)} with the request's url from inside the method + * and then return {@code true}, as this will make WebView to attempt loading a + * non-http url, and thus fail.
    • + *
    + * + * @param view The WebView that is initiating the callback. + * @param request Object containing the details of the request. + * @return {@code true} if the host application wants to leave the current + * WebView and handle the url itself, otherwise return {@code false}. + */ + public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { + return false; + } + + /** + * Notify the host application that a page has finished loading. This method is + * called only for main frame. When onPageFinished() is called, the rendering + * picture may not be updated yet. To get the notification for the new Picture, + * use {@link WebView.PictureListener#onNewPicture}. + * + * @param view The WebView that is initiating the callback. + * @param url The url of the page. + */ + public void onPageFinished(WebView view, String url) { + } + + /** + * Notify the host application that the WebView will load the resource specified + * by the given url. + * + * @param view The WebView that is initiating the callback. + * @param url The url of the resource the WebView will load. + */ + public void onLoadResource(WebView view, String url) { + } + + /** + * Notify the host application that {@link android.webkit.WebView} content left + * over from previous page navigations will no longer be drawn. + * + *

    + * This callback can be used to determine the point at which it is safe to make + * a recycled {@link android.webkit.WebView} visible, ensuring that no stale + * content is shown. It is called at the earliest point at which it can be + * guaranteed that {@link WebView#onDraw} will no longer draw any content from + * previous navigations. The next draw will display either the + * {@link WebView#setBackgroundColor background color} of the {@link WebView}, + * or some of the contents of the newly loaded page. + * + *

    + * This method is called when the body of the HTTP response has started loading, + * is reflected in the DOM, and will be visible in subsequent draws. This + * callback occurs early in the document loading process, and as such you should + * expect that linked resources (for example, CSS and images) may not be + * available. + * + *

    + * For more fine-grained notification of visual state updates, see + * {@link WebView#postVisualStateCallback}. + * + *

    + * Please note that all the conditions and recommendations applicable to + * {@link WebView#postVisualStateCallback} also apply to this API. + * + *

    + * This callback is only called for main frame navigations. + * + * @param view The {@link android.webkit.WebView} for which the navigation + * occurred. + * @param url The URL corresponding to the page navigation that triggered this + * callback. + */ + public void onPageCommitVisible(WebView view, String url) { + } + + /** + * Notify the host application of a resource request and allow the application + * to return the data. If the return value is {@code null}, the WebView will + * continue to load the resource as usual. Otherwise, the return response and + * data will be used. + * + *

    + * This callback is invoked for a variety of URL schemes (e.g., + * {@code http(s):}, {@code + * data:}, {@code file:}, etc.), not only those schemes which send requests over + * the network. This is not called for {@code javascript:} URLs, {@code blob:} + * URLs, or for assets accessed via {@code file:///android_asset/} or + * {@code file:///android_res/} URLs. + * + *

    + * In the case of redirects, this is only called for the initial resource URL, + * not any subsequent redirect URLs. + * + *

    + * Note: This method is called on a thread other than the UI thread so + * clients should exercise caution when accessing private data or the view + * system. + * + *

    + * Note: When Safe Browsing is enabled, these URLs still undergo Safe + * Browsing checks. If this is undesired, whitelist the URL with + * {@link WebView#setSafeBrowsingWhitelist} or ignore the warning with + * {@link #onSafeBrowsingHit}. + * + * @param view The {@link android.webkit.WebView} that is requesting the + * resource. + * @param url The raw url of the resource. + * @return A {@link android.webkit.WebResourceResponse} containing the response + * information or {@code null} if the WebView should load the resource + * itself. + * @deprecated Use {@link #shouldInterceptRequest(WebView, WebResourceRequest) + * shouldInterceptRequest(WebView, WebResourceRequest)} instead. + */ + @Deprecated + public WebResourceResponse shouldInterceptRequest(WebView view, String url) { + return null; + } + + /** + * Notify the host application of a resource request and allow the application + * to return the data. If the return value is {@code null}, the WebView will + * continue to load the resource as usual. Otherwise, the return response and + * data will be used. + * + *

    + * This callback is invoked for a variety of URL schemes (e.g., + * {@code http(s):}, {@code + * data:}, {@code file:}, etc.), not only those schemes which send requests over + * the network. This is not called for {@code javascript:} URLs, {@code blob:} + * URLs, or for assets accessed via {@code file:///android_asset/} or + * {@code file:///android_res/} URLs. + * + *

    + * In the case of redirects, this is only called for the initial resource URL, + * not any subsequent redirect URLs. + * + *

    + * Note: This method is called on a thread other than the UI thread so + * clients should exercise caution when accessing private data or the view + * system. + * + *

    + * Note: When Safe Browsing is enabled, these URLs still undergo Safe + * Browsing checks. If this is undesired, whitelist the URL with + * {@link WebView#setSafeBrowsingWhitelist} or ignore the warning with + * {@link #onSafeBrowsingHit}. + * + * @param view The {@link android.webkit.WebView} that is requesting the + * resource. + * @param request Object containing the details of the request. + * @return A {@link android.webkit.WebResourceResponse} containing the response + * information or {@code null} if the WebView should load the resource + * itself. + */ + public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { + return null; + } + + /** + * Report an error to the host application. These errors are unrecoverable (i.e. + * the main resource is unavailable). The {@code errorCode} parameter + * corresponds to one of the {@code ERROR_*} constants. + * + * @param view The WebView that is initiating the callback. + * @param errorCode The error code corresponding to an ERROR_* value. + * @param description A String describing the error. + * @param failingUrl The url that failed to load. + * @deprecated Use + * {@link #onReceivedError(WebView, WebResourceRequest, WebResourceError) + * onReceivedError(WebView, WebResourceRequest, WebResourceError)} + * instead. + */ + @Deprecated + public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { + } + +}