Merge pull request #4483 from smowton/smowton/admin/droid-webview-pr-rebase

Rebase of #3706
This commit is contained in:
Chris Smowton
2020-10-19 09:29:04 +01:00
committed by GitHub
21 changed files with 9966 additions and 0 deletions

View File

@@ -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 |

View File

@@ -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");
}
}

View File

@@ -0,0 +1 @@
experimental/Security/CWE/CWE-749/UnsafeAndroidAccess.ql

View File

@@ -0,0 +1 @@
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../stubs/google-android-9.0.0

File diff suppressed because it is too large Load Diff

View File

@@ -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.
*
* <p>
* Consider for example how this interacts with
* {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
* <ul>
* <li>
* <p>
* If used from an Activity context, the receiver is being registered within
* that activity. This means that you are expected to unregister before the
* activity is done being destroyed; in fact if you do not do so, the framework
* will clean up your leaked registration as it removes the activity and log an
* error. Thus, if you use the Activity context to register a receiver that is
* static (global to the process, not associated with an Activity instance) then
* that registration will be removed on you at whatever point the activity you
* used is destroyed.
* <li>
* <p>
* If used from the Context returned here, the receiver is being registered with
* the global state associated with your application. Thus it will never be
* unregistered for you. This is necessary if the receiver is associated with
* static data, not a particular component. However using the ApplicationContext
* elsewhere can easily lead to serious leaks if you forget to unregister,
* unbind, etc.
* </ul>
*/
public abstract Context getApplicationContext();
/**
* Returns the absolute path on the filesystem where a file created with
* {@link #openFileOutput} is stored.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* This is like {@link #getFilesDir()} in that these files will be deleted when
* the application is uninstalled, however there are some important differences:
* <ul>
* <li>Shared storage may not always be available, since removable media can be
* ejected by the user. Media state can be checked using
* {@link Environment#getExternalStorageState(File)}.
* <li>There is no security enforced with these files. For example, any
* application holding
* {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to these
* files.
* </ul>
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* The returned path may change over time if different shared storage media is
* inserted, so only relative paths should be persisted.
* <p>
* Here is an example of typical code to manipulate a file in an application's
* shared storage:
* </p>
* {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
* private_file}
* <p>
* If you supply a non-null <var>type</var> 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.
* <p>
* Here is an example of typical code to manipulate a picture in an
* application's shared storage and add it to the media database:
* </p>
* {@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.
* <p>
* This is like {@link #getFilesDir()} in that these files will be deleted when
* the application is uninstalled, however there are some important differences:
* <ul>
* <li>Shared storage may not always be available, since removable media can be
* ejected by the user. Media state can be checked using
* {@link Environment#getExternalStorageState(File)}.
* <li>There is no security enforced with these files. For example, any
* application holding
* {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to these
* files.
* </ul>
* <p>
* 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.
* <p>
* 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.
* <p>
* 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}.
* <p>
* 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.
* <p>
* 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.
* <p>
* This is like {@link #getFilesDir()} in that these files will be deleted when
* the application is uninstalled, however there are some important differences:
* <ul>
* <li>Shared storage may not always be available, since removable media can be
* ejected by the user. Media state can be checked using
* {@link Environment#getExternalStorageState(File)}.
* <li>There is no security enforced with these files. For example, any
* application holding
* {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to these
* files.
* </ul>
* <p>
* 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:
* </p>
* <p>
* {@code <uses-permission android:name=
* "android.permission.READ_EXTERNAL_STORAGE"
* android:maxSdkVersion="23" />}
* </p>
* <p>
* 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.
* </p>
*
* <p>
* The following code snippet shows how to do this:
* </p>
*
* <pre>
* 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();
* }
* </pre>
*
* 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.
* <p>
* This is like {@link #getFilesDir()} in that these files will be deleted when
* the application is uninstalled, however there are some important differences:
* <ul>
* <li>Shared storage may not always be available, since removable media can be
* ejected by the user. Media state can be checked using
* {@link Environment#getExternalStorageState(File)}.
* <li>There is no security enforced with these files. For example, any
* application holding
* {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to these
* files.
* </ul>
* <p>
* 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.
* <p>
* 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}.
* <p>
* 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.
* <p>
* 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)}.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* The system will delete any files stored in this location both when your
* specific application is upgraded, and when the entire platform is upgraded.
* <p>
* This location is optimal for storing compiled or optimized code generated by
* your application at runtime.
* <p>
* 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.
* <p>
* 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.
* <p>
* This is like {@link #getCacheDir()} in that these files will be deleted when
* the application is uninstalled, however there are some important differences:
* <ul>
* <li>The platform does not always monitor the space available in shared
* storage, and thus may not automatically delete these files. Apps should
* always manage the maximum space used in this location. Currently the only
* time files here will be deleted by the platform is when running on
* {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
* {@link Environment#isExternalStorageEmulated(File)} returns true.
* <li>Shared storage may not always be available, since removable media can be
* ejected by the user. Media state can be checked using
* {@link Environment#getExternalStorageState(File)}.
* <li>There is no security enforced with these files. For example, any
* application holding
* {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to these
* files.
* </ul>
* <p>
* 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()}.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* This is like {@link #getCacheDir()} in that these files will be deleted when
* the application is uninstalled, however there are some important differences:
* <ul>
* <li>The platform does not always monitor the space available in shared
* storage, and thus may not automatically delete these files. Apps should
* always manage the maximum space used in this location. Currently the only
* time files here will be deleted by the platform is when running on
* {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
* {@link Environment#isExternalStorageEmulated(File)} returns true.
* <li>Shared storage may not always be available, since removable media can be
* ejected by the user. Media state can be checked using
* {@link Environment#getExternalStorageState(File)}.
* <li>There is no security enforced with these files. For example, any
* application holding
* {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to these
* files.
* </ul>
* <p>
* 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()}.
* <p>
* 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.
* <p>
* 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}.
* <p>
* 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.
* <p>
* 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}.
* <p>
* This is like {@link #getExternalFilesDirs} in that these files will be
* deleted when the application is uninstalled, however there are some important
* differences:
* <ul>
* <li>Shared storage may not always be available, since removable media can be
* ejected by the user. Media state can be checked using
* {@link Environment#getExternalStorageState(File)}.
* <li>There is no security enforced with these files. For example, any
* application holding
* {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to these
* files.
* </ul>
* <p>
* 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.
* <p>
* 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}.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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 &nbsp; `
* @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.
*
* <p>
* 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.
*
* <p>
* 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 &nbsp;
*
* @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 &nbsp;
*
* @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).
*
* <p>
* This method throws {@link ActivityNotFoundException} if there was no Activity
* found for <em>any</em> 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 &nbsp;
*
* @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)}.
*
* <p>
* 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)}.
*
* <p>
* 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);
}

File diff suppressed because it is too large Load Diff

View File

@@ -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 <a href="http://www.faqs.org/rfcs/rfc2396.html">RFC 2396</a>.
*
* <p>
* 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<Uri> {
/*
* 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 <scheme>://<authority><path>?<query>
*/
/**
* 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.&nbsp;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.&nbsp;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.&nbsp;everything between the
* scheme separator ':' and the fragment separator '#'. If this is a relative
* URI, this method returns the entire URI. Decodes escaped octets.
*
* <p>
* 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.&nbsp;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.
*
* <p>
* 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 ]}
*
* <p>
* 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 ]}
*
* <p>
* 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<String> 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://<absolute path>".
* Encodes path characters with the exception of '/'.
*
* <p>
* 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<String> 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<String> getQueryParameters(String key) {
return null;
}
/**
* Searches the query string for the first value with the given key.
*
* <p>
* <strong>Warning:</strong> 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
* <code>false</code>, everything else is interpreted as <code>true</code>.
*
* @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.
*
* <p>
* For example, "HTTP://www.android.com" becomes "http://www.android.com"
*
* <p>
* 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.
*
* <p class="note">
* This method does <em>not</em> 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;
}
}

View File

@@ -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<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 an ArrayList<CharSequence> object, or null
*/
void putCharSequenceArrayList(String key, ArrayList<CharSequence> 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<String> value, or null
*/
ArrayList<Integer> 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<String> value, or null
*/
ArrayList<String> 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<CharSequence> value, or null
*/
ArrayList<CharSequence> 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) {
}
}

View File

@@ -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<Integer> 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<Integer> object, or null
*/
public void putIntegerArrayList(String key, ArrayList<Integer> value) {
}
/**
* Inserts an ArrayList<String> 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<String> object, or null
*/
public void putStringArrayList(String key, ArrayList<String> value) {
}
/**
* Inserts an ArrayList<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 an ArrayList<CharSequence> object, or null
*/
public void putCharSequenceArrayList(String key, ArrayList<CharSequence> 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<T> value, or null
*/
public <T extends Parcelable> ArrayList<T> 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<String> value, or null
*/
public ArrayList<Integer> 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<String> value, or null
*/
public ArrayList<String> 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<CharSequence> value, or null
*/
public ArrayList<CharSequence> 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;
}
}

View File

@@ -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.
*
* <p>
* 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<CharSequence> 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<String> val) {
}
/**
* Flatten a generic object in to a parcel. The given Object value may currently
* be one of the following types:
*
* <ul>
* <li>null
* <li>String
* <li>Byte
* <li>Short
* <li>Integer
* <li>Long
* <li>Float
* <li>Double
* <li>Boolean
* <li>String[]
* <li>boolean[]
* <li>byte[]
* <li>int[]
* <li>long[]
* <li>Object[] (supporting objects of the same type defined here).
* <li>{@link Bundle}
* <li>Map (as supported by {@link #writeMap}).
* <li>Any object that implements the {@link Parcelable} protocol.
* <li>Parcelable[]
* <li>CharSequence (as supported by {@link TextUtils#writeToParcel}).
* <li>List (as supported by {@link #writeList}).
* <li>{@link SparseArray} (as supported by
* {@link #writeSparseArray(SparseArray)}).
* <li>{@link IBinder}
* <li>Any object that implements Serializable (but see
* {@link #writeSerializable} for caveats). Note that all of the previous types
* have relatively efficient implementations for writing to a Parcel; having to
* rely on the generic serialization approach is much less efficient and should
* be avoided whenever possible.
* </ul>
*
* <p class="caution">
* {@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).
* </p>
*/
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).
*
* <p>
* The supported exception types are:
* <ul>
* <li>{@link BadParcelableException}
* <li>{@link IllegalArgumentException}
* <li>{@link IllegalStateException}
* <li>{@link NullPointerException}
* <li>{@link SecurityException}
* <li>{@link UnsupportedOperationException}
* <li>{@link NetworkOnMainThreadException}
* </ul>
*
* @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&lt;CharSequence&gt; object from the parcel.
* {@hide}
*/
public final ArrayList<CharSequence> 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<String> 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<String> 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 extends Parcelable> 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 extends Parcelable> T[] readParcelableArray(ClassLoader loader, Class<T> 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;
}
}

View File

@@ -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 <code>CREATOR</code> of a type that implements
* the {@link Parcelable.Creator} interface.
*
* <p>
* A typical implementation of Parcelable is:
* </p>
*
* <pre>
* 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&lt;MyParcelable&gt; CREATOR = new Parcelable.Creator&lt;MyParcelable&gt;() {
* 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();
* }
* }
* </pre>
*/
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<T> {
/**
* 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);
}
}

View File

@@ -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;
/**
* <p>
* 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 <em>widgets</em>, which are
* used to create interactive UI components (buttons, text fields, etc.). The
* {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which
* are invisible containers that hold other Views (or other ViewGroups) and define
* their layout properties.
* </p>
*
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For information about using this class to develop your application's user interface,
* read the <a href="{@docRoot}guide/topics/ui/index.html">User Interface</a> developer guide.
* </div>
*
* <a name="Using"></a>
* <h3>Using Views</h3>
* <p>
* 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.
* </p>
* <p>
* Once you have created a tree of views, there are typically a few types of
* common operations you may wish to perform:
* <ul>
* <li><strong>Set properties:</strong> 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.</li>
* <li><strong>Set focus:</strong> The framework will handle moving focus in
* response to user input. To force focus to a specific view, call
* {@link #requestFocus}.</li>
* <li><strong>Set up listeners:</strong> 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.</li>
* <li><strong>Set visibility:</strong> You can hide or show views using
* {@link #setVisibility(int)}.</li>
* </ul>
* </p>
* <p><em>
* 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}.
* </em></p>
*
* <a name="Lifecycle"></a>
* <h3>Implementing a Custom View</h3>
*
* <p>
* 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)}.
* <table border="2" width="85%" align="center" cellpadding="5">
* <thead>
* <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr>
* </thead>
*
* <tbody>
* <tr>
* <td rowspan="2">Creation</td>
* <td>Constructors</td>
* <td>There 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.
* </td>
* </tr>
* <tr>
* <td><code>{@link #onFinishInflate()}</code></td>
* <td>Called after a view and all of its children has been inflated
* from XML.</td>
* </tr>
*
* <tr>
* <td rowspan="3">Layout</td>
* <td><code>{@link #onMeasure(int, int)}</code></td>
* <td>Called to determine the size requirements for this view and all
* of its children.
* </td>
* </tr>
* <tr>
* <td><code>{@link #onLayout(boolean, int, int, int, int)}</code></td>
* <td>Called when this view should assign a size and position to all
* of its children.
* </td>
* </tr>
* <tr>
* <td><code>{@link #onSizeChanged(int, int, int, int)}</code></td>
* <td>Called when the size of this view has changed.
* </td>
* </tr>
*
* <tr>
* <td>Drawing</td>
* <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td>
* <td>Called when the view should render its content.
* </td>
* </tr>
*
* <tr>
* <td rowspan="4">Event processing</td>
* <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td>
* <td>Called when a new hardware key event occurs.
* </td>
* </tr>
* <tr>
* <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td>
* <td>Called when a hardware key up event occurs.
* </td>
* </tr>
* <tr>
* <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td>
* <td>Called when a trackball motion event occurs.
* </td>
* </tr>
* <tr>
* <td><code>{@link #onTouchEvent(MotionEvent)}</code></td>
* <td>Called when a touch screen motion event occurs.
* </td>
* </tr>
*
* <tr>
* <td rowspan="2">Focus</td>
* <td><code>{@link #onFocusChanged(boolean, int, android.graphics.Rect)}</code></td>
* <td>Called when the view gains or loses focus.
* </td>
* </tr>
*
* <tr>
* <td><code>{@link #onWindowFocusChanged(boolean)}</code></td>
* <td>Called when the window containing the view gains or loses focus.
* </td>
* </tr>
*
* <tr>
* <td rowspan="3">Attaching</td>
* <td><code>{@link #onAttachedToWindow()}</code></td>
* <td>Called when the view is attached to a window.
* </td>
* </tr>
*
* <tr>
* <td><code>{@link #onDetachedFromWindow}</code></td>
* <td>Called when the view is detached from its window.
* </td>
* </tr>
*
* <tr>
* <td><code>{@link #onWindowVisibilityChanged(int)}</code></td>
* <td>Called when the visibility of the window containing the view
* has changed.
* </td>
* </tr>
* </tbody>
*
* </table>
* </p>
*
* <a name="IDs"></a>
* <h3>IDs</h3>
* 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:
* <ul>
* <li>Define a Button in the layout file and assign it a unique ID.
* <pre>
* &lt;Button
* android:id="@+id/my_button"
* android:layout_width="wrap_content"
* android:layout_height="wrap_content"
* android:text="@string/my_button_text"/&gt;
* </pre></li>
* <li>From the onCreate method of an Activity, find the Button
* <pre class="prettyprint">
* Button myButton = findViewById(R.id.my_button);
* </pre></li>
* </ul>
* <p>
* 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.
* </p>
*
* <a name="Position"></a>
* <h3>Position</h3>
* <p>
* The geometry of a view is that of a rectangle. A view has a location,
* expressed as a pair of <em>left</em> and <em>top</em> coordinates, and
* two dimensions, expressed as a width and a height. The unit for location
* and dimensions is the pixel.
* </p>
*
* <p>
* 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.
* </p>
*
* <p>
* 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: <code>getLeft() + getWidth()</code>
* (see <a href="#SizePaddingMargins">Size</a> for more information about the width.)
* </p>
*
* <a name="SizePaddingMargins"></a>
* <h3>Size, padding and margins</h3>
* <p>
* The size of a view is expressed with a width and a height. A view actually
* possess two pairs of width and height values.
* </p>
*
* <p>
* The first pair is known as <em>measured width</em> and
* <em>measured height</em>. These dimensions define how big a view wants to be
* within its parent (see <a href="#Layout">Layout</a> for more details.) The
* measured dimensions can be obtained by calling {@link #getMeasuredWidth()}
* and {@link #getMeasuredHeight()}.
* </p>
*
* <p>
* The second pair is simply known as <em>width</em> and <em>height</em>, or
* sometimes <em>drawing width</em> and <em>drawing height</em>. 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()}.
* </p>
*
* <p>
* 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()}.
* </p>
*
* <p>
* 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.
* </p>
*
* <a name="Layout"></a>
* <h3>Layout</h3>
* <p>
* 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.
* </p>
*
* <p>
* 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.
* </p>
*
* <p>
* 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:
* <ul>
* <li> an exact number
* <li>MATCH_PARENT, which means the view wants to be as big as its parent
* (minus padding)
* <li> WRAP_CONTENT, which means that the view wants to be just big enough to
* enclose its content (plus padding).
* </ul>
* 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.
* </p>
*
* <p>
* MeasureSpecs are used to push requirements down the tree from parent to
* child. A MeasureSpec can be in one of three modes:
* <ul>
* <li>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.
* <li>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.
* <li>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.
* </ul>
* </p>
*
* <p>
* 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.
* </p>
*
* <a name="Drawing"></a>
* <h3>Drawing</h3>
* <p>
* 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.
* </p>
*
* <p>
* 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 <code>onDraw()</code> 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.
* </p>
*
* <p>
* To force a view to draw, call {@link #invalidate()}.
* </p>
*
* <a name="EventHandlingThreading"></a>
* <h3>Event Handling and Threading</h3>
* <p>
* The basic cycle of a view is as follows:
* <ol>
* <li>An event comes in and is dispatched to the appropriate view. The view
* handles the event and notifies any listeners.</li>
* <li>If in the course of processing the event, the view's bounds may need
* to be changed, the view will call {@link #requestLayout()}.</li>
* <li>Similarly, if in the course of processing the event the view's appearance
* may need to be changed, the view will call {@link #invalidate()}.</li>
* <li>If either {@link #requestLayout()} or {@link #invalidate()} were called,
* the framework will take care of measuring, laying out, and drawing the tree
* as appropriate.</li>
* </ol>
* </p>
*
* <p><em>Note: The entire view tree is single threaded. You must always be on
* the UI thread when calling any method on any view.</em>
* 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}.
* </p>
*
* <a name="FocusHandling"></a>
* <h3>Focus Handling</h3>
* <p>
* 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)}.
* </p>
* <p>
* 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:
* <pre>
* nextFocusDown
* nextFocusLeft
* nextFocusRight
* nextFocusUp
* </pre>
* </p>
*
*
* <p>
* To get a particular view to take focus, call {@link #requestFocus()}.
* </p>
*
* <a name="TouchMode"></a>
* <h3>Touch Mode</h3>
* <p>
* 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'.
* </p>
* <p>
* 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.
* </p>
* <p>
* 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.
* </p>
* <p>
* 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.
* </p>
*
* <a name="Scrolling"></a>
* <h3>Scrolling</h3>
* <p>
* 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.
* </p>
*
* <a name="Tags"></a>
* <h3>Tags</h3>
* <p>
* 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.
* </p>
* <p>
* 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 <tag>} child element:
* <pre>
* &lt;View ...
* android:tag="@string/mytag_value" /&gt;
* &lt;View ...&gt;
* &lt;tag android:id="@+id/mytag"
* android:value="@string/mytag_value" /&gt;
* &lt;/View>
* </pre>
* </p>
* <p>
* Tags may also be specified with arbitrary objects from code using
* {@link #setTag(Object)} or {@link #setTag(int, Object)}.
* </p>
*
* <a name="Themes"></a>
* <h3>Themes</h3>
* <p>
* 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.
* </p>
* <p>
* 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.
* </p>
* <p>
* 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.
* <pre>
* &lt;LinearLayout
* ...
* android:theme="@android:theme/ThemeOverlay.Material.Dark"&gt;
* &lt;View ...&gt;
* &lt;/LinearLayout&gt;
* </pre>
* </p>
*
* <a name="Properties"></a>
* <h3>Properties</h3>
* <p>
* 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
* <a href="#Animation">Animation</a> section.
* </p>
*
* <a name="Animation"></a>
* <h3>Animation</h3>
* <p>
* 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.
* </p>
* <p>
* 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.
* </p>
*
* <a name="Security"></a>
* <h3>Security</h3>
* <p>
* 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.
* </p><p>
* 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.
* </p><p>
* 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}.
* </p>
*
* @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) {
}
}

View File

@@ -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<String, String> getRequestHeaders();
}

View File

@@ -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<String, String> responseHeaders, InputStream data) {
}
/**
* Sets the resource response's MIME type, for example &quot;text/html&quot;.
*
* @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 &quot;UTF-8&quot;. 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<String, String> headers) {
}
/**
* Gets the headers for the resource response.
*
* @return The headers for the resource response.
*/
public Map<String, String> 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<String, String> responseHeaders, InputStream data) {
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -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;
/**
* <p>
* 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.
*
* <p>
* 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:
*
* <pre>
* {@code <uses-permission android:name="android.permission.INTERNET" />}
* </pre>
*
* <p>
* This must be a child of the <a href="
* {@docRoot}guide/topics/manifest/manifest-element.html">{@code <manifest>}</a>
* element.
*
* <p>
* For more information, read
* <a href="{@docRoot}guide/webapps/webview.html">Building Web Apps in
* WebView</a>.
*
* <h3>Basic usage</h3>
*
* <p>
* 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:
*
* <pre>
* Uri uri = Uri.parse("https://www.example.com");
* Intent intent = new Intent(Intent.ACTION_VIEW, uri);
* startActivity(intent);
* </pre>
* <p>
* See {@link android.content.Intent} for more information.
*
* <p>
* To provide a WebView in your own Activity, include a {@code <WebView>} in
* your layout, or set the entire Activity window as a WebView during
* {@link android.app.Activity#onCreate(Bundle) onCreate()}:
*
* <pre class="prettyprint">
* WebView webview = new WebView(this);
* setContentView(webview);
* </pre>
*
* <p>
* Then load the desired web page:
*
* <pre>
* // 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 = "&lt;html>&lt;body>You scored &lt;b>192&lt;/b> points.&lt;/body>&lt;/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.
* </pre>
*
* <p>
* A WebView has several customization points where you can add your own
* behavior. These are:
*
* <ul>
* <li>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
* <a href="
* {@docRoot}guide/developing/debug-tasks.html#DebuggingWebPages">Debugging
* Tasks</a>).</li>
* <li>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()}).</li>
* <li>Modifying the {@link android.webkit.WebSettings}, such as enabling
* JavaScript with
* {@link android.webkit.WebSettings#setJavaScriptEnabled(boolean)
* setJavaScriptEnabled()}.</li>
* <li>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.</li>
* </ul>
*
* <p>
* Here's a more complicated example, showing error handling, settings, and
* progress notification:
*
* <pre class="prettyprint">
* // 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/");
* </pre>
*
* <h3>Zoom</h3>
*
* <p>
* 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}).
*
* <p class="note">
* <b>Note:</b> 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.
*
* <h3>Cookie and window management</h3>
*
* <p>
* For obvious security reasons, your application has its own cache, cookie
* store etc.&mdash;it does not share the Browser application's data.
*
* <p>
* 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.
*
* <p>
* 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
* <a href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling
* Runtime Changes</a> for more information about how to handle configuration
* changes during runtime.
*
*
* <h3>Building web pages to support different screen densities</h3>
*
* <p>
* 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 &mdash; sometimes significantly more &mdash; 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.
* <p>
* 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.
* <p>
* Here's a summary of the features you can use to handle different screen
* densities:
* <ul>
* <li>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.</li>
* <li>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:
*
* <pre>
* &lt;link rel="stylesheet" media="screen and (-webkit-device-pixel-ratio:1.5)" href="hdpi.css" /&gt;
* </pre>
* <p>
* 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.</li>
* </ul>
*
* <h3>HTML5 Video support</h3>
*
* <p>
* In order to support inline HTML5 video in your application you need to have
* hardware acceleration turned on.
*
* <h3>Full screen support</h3>
*
* <p>
* In order to support full screen &mdash; for video or other HTML content
* &mdash; 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.
*
* <h3>HTML5 Geolocation API support</h3>
*
* <p>
* 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.
*
* <h3>Layout size</h3>
* <p>
* 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.
*
* <p>
* Setting the WebView's height to
* {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} enables the
* following behaviors:
* <ul>
* <li>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.
* </li>
* <li>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.</li>
* </ul>
*
* <p>
* 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.
*
* <h3>Metrics</h3>
*
* <p>
* 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 <application>} element:
*
* <pre>
* &lt;manifest&gt;
* &lt;application&gt;
* ...
* &lt;meta-data android:name=&quot;android.webkit.WebView.MetricsOptOut&quot;
* android:value=&quot;true&quot; /&gt;
* &lt;/application&gt;
* &lt;/manifest&gt;
* </pre>
* <p>
* Data will only be uploaded for a given app if the user has consented AND the
* app has not opted out.
*
* <h3>Safe Browsing</h3>
*
* <p>
* 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.
* <p>
* 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 <application>} element:
* <p>
*
* <pre>
* &lt;manifest&gt;
* &lt;application&gt;
* ...
* &lt;meta-data android:name=&quot;android.webkit.WebView.EnableSafeBrowsing&quot;
* android:value=&quot;false&quot; /&gt;
* &lt;/application&gt;
* &lt;/manifest&gt;
* </pre>
*
* <p>
* 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.
*
* <p class="note">
* <b>Note:</b> 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.
* <p>
* 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<String, String> additionalHttpHeaders) {
}
/**
* Loads the given URL.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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:
*
* <pre>
* String unencodedHtml = "&lt;html&gt;&lt;body&gt;'%28' is the code for '('&lt;/body&gt;&lt;/html&gt;";
* String encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(), Base64.NO_PADDING);
* webView.loadData(encodedHtml, "text/html", "base64");
* </pre>
* <p>
* 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
* <a href="https://tools.ietf.org/html/rfc3986#section-2.2">RFC 3986</a> for
* more information.
* <p>
* 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'.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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'.
* <p>
* 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'.
* <p>
* 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.
* <p>
* Note that the baseUrl is sent in the 'Referer' HTTP header when requesting
* subresources (images, etc.) of the page loaded using this method.
* <p>
* 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.
* <p> 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:
* <pre>
* class JsObject {
* {@literal @}JavascriptInterface
* public String toString() { return "injectedObject"; }
* }
* webview.getSettings().setJavaScriptEnabled(true);
* webView.addJavascriptInterface(new JsObject(), "injectedObject");
* webView.loadData("<!DOCTYPE html><title></title>", "text/html", null);
* webView.loadUrl("javascript:alert(injectedObject.toString())");</pre>
* <p>
* <strong>IMPORTANT:</strong>
* <ul>
* <li> 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.</li>
* <li> JavaScript interacts with Java object on a private, background
* thread of this WebView. Care is therefore required to maintain thread
* safety.
* </li>
* <li> The Java object's fields are not accessible.</li>
* <li> For applications targeted to API level {@link android.os.Build.VERSION_CODES#LOLLIPOP}
* and above, methods of injected Java objects are enumerable from
* JavaScript.</li>
* </ul>
*
* @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;
}
}

View File

@@ -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.
*
* <p>
* Notes:
* <ul>
* <li>This method is not called for requests using the POST
* &quot;method&quot;.</li>
* <li>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.</li>
* </ul>
*
* @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.
*
* <p>
* 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.
*
* <p>
* 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.
*
* <p>
* For more fine-grained notification of visual state updates, see
* {@link WebView#postVisualStateCallback}.
*
* <p>
* Please note that all the conditions and recommendations applicable to
* {@link WebView#postVisualStateCallback} also apply to this API.
*
* <p>
* 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.
*
* <p>
* 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.
*
* <p>
* In the case of redirects, this is only called for the initial resource URL,
* not any subsequent redirect URLs.
*
* <p class="note">
* <b>Note:</b> 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.
*
* <p class="note">
* <b>Note:</b> 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.
*
* <p>
* 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.
*
* <p>
* In the case of redirects, this is only called for the initial resource URL,
* not any subsequent redirect URLs.
*
* <p class="note">
* <b>Note:</b> 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.
*
* <p class="note">
* <b>Note:</b> 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) {
}
}