|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.content.Context
android.content.ContextWrapper
android.test.IsolatedContext
public class IsolatedContext
A mock context which prevents its users from talking to the rest of the device while stubbing enough methods to satify code that tries to talk to other packages.
| Field Summary |
|---|
| Constructor Summary | |
|---|---|
IsolatedContext(ContentResolver resolver,
Context targetContext)
|
|
| Method Summary | |
|---|---|
boolean |
bindService(Intent service,
ServiceConnection conn,
int flags)
Connect to an application service, creating it if needed. |
int |
checkUriPermission(Uri uri,
int pid,
int uid,
int modeFlags)
Determine whether a particular process and user ID has been granted permission to access a specific URI. |
int |
checkUriPermission(Uri uri,
String readPermission,
String writePermission,
int pid,
int uid,
int modeFlags)
Check both a Uri and normal permission. |
List<Intent> |
getAndClearBroadcastIntents()
Returns the list of intents that were broadcast since the last call to this method. |
ContentResolver |
getContentResolver()
Return a ContentResolver instance for your application's package. |
Object |
getSystemService(String name)
Return the handle to a system-level service by name. |
Intent |
registerReceiver(BroadcastReceiver receiver,
IntentFilter filter)
Register an BroadcastReceiver to be run in the main activity thread. |
void |
sendBroadcast(Intent intent)
Broadcast the given intent to all interested BroadcastReceivers. |
void |
sendOrderedBroadcast(Intent intent,
String receiverPermission)
Broadcast the given intent to all interested BroadcastReceivers, delivering them one at a time to allow more preferred receivers to consume the broadcast before it is delivered to less preferred receivers. |
| Methods inherited from class android.content.Context |
|---|
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public IsolatedContext(ContentResolver resolver,
Context targetContext)
| Method Detail |
|---|
public List<Intent> getAndClearBroadcastIntents()
public ContentResolver getContentResolver()
Context
getContentResolver in class ContextWrapper
public boolean bindService(Intent service,
ServiceConnection conn,
int flags)
ContextThis function will throw SecurityException if you do not
have permission to bind to the given service.
Note: this method can not be called from an
BroadcastReceiver component. A pattern you can use to
communicate from an BroadcastReceiver to a Service is to call
Context.startService(android.content.Intent) with the arguments containing the command to be
sent, with the service calling its
Service.stopSelf(int) method when done executing
that command. See the API demo App/Service/Service Start Arguments
Controller for an illustration of this. It is okay, however, to use
this method from an BroadcastReceiver that has been registered with
Context.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter), since the lifetime of this BroadcastReceiver
is tied to another object (the one that registered it).
bindService in class ContextWrapperservice - Identifies the service to connect to. The Intent may
specify either an explicit component name, or a logical
description (action, category, etc) to match an
IntentFilter published by a service.conn - Receives information as the service is started and stopped.flags - Operation options for the binding. May be 0 or
Context.BIND_AUTO_CREATE.
Context.unbindService(android.content.ServiceConnection),
Context.startService(android.content.Intent),
Context.BIND_AUTO_CREATE
public Intent registerReceiver(BroadcastReceiver receiver,
IntentFilter filter)
ContextThe system may broadcast Intents that are "sticky" -- these stay around after the broadcast as finished, to be sent to any later registrations. If your IntentFilter matches one of these sticky Intents, that Intent will be returned by this function and sent to your receiver as if it had just been broadcast.
There may be multiple sticky Intents that match filter, in which case each of these will be sent to receiver. In this case, only one of these can be returned directly by the function; which of these that is returned is arbitrarily decided by the system.
If you know the Intent your are registering for is sticky, you can supply null for your receiver. In this case, no receiver is registered -- the function simply returns the sticky Intent that matches filter. In the case of multiple matches, the same rules as described above apply.
See BroadcastReceiver for more information on Intent broadcasts.
Note: this method can not be called from an
BroadcastReceiver component. It is okay, however, to use
this method from another BroadcastReceiver that has itself been registered with
Context.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter), since the lifetime of such an BroadcastReceiver
is tied to another object (the one that registered it).
registerReceiver in class ContextWrapperreceiver - The BroadcastReceiver to handle the broadcast.filter - Selects the Intent broadcasts to be received.
Context.registerReceiver(BroadcastReceiver, IntentFilter, String, Handler),
Context.sendBroadcast(android.content.Intent),
Context.unregisterReceiver(android.content.BroadcastReceiver)public void sendBroadcast(Intent intent)
ContextContext.sendOrderedBroadcast(Intent, String).
See BroadcastReceiver for more information on Intent broadcasts.
sendBroadcast in class ContextWrapperintent - The Intent to broadcast; all receivers matching this
Intent will receive the broadcast.BroadcastReceiver,
Context.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter),
Context.sendBroadcast(Intent, String),
Context.sendOrderedBroadcast(Intent, String),
Context.sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
public void sendOrderedBroadcast(Intent intent,
String receiverPermission)
ContextSee BroadcastReceiver for more information on Intent broadcasts.
sendOrderedBroadcast in class ContextWrapperintent - The Intent to broadcast; all receivers matching this
Intent will receive the broadcast.receiverPermission - (optional) String naming a permissions that
a receiver must hold in order to receive your broadcast.
If null, no permission is required.BroadcastReceiver,
Context.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter),
Context.sendBroadcast(Intent),
Context.sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
public int checkUriPermission(Uri uri,
String readPermission,
String writePermission,
int pid,
int uid,
int modeFlags)
ContextContext.checkPermission(java.lang.String, int, int) and Context.checkUriPermission(android.net.Uri, int, int, int) in one
call.
checkUriPermission in class ContextWrapperuri - The Uri whose permission is to be checked, or null to not
do this check.readPermission - The permission that provides overall read access,
or null to not do this check.writePermission - The permission that provides overall write
acess, or null to not do this check.pid - The process ID being checked against. Must be > 0.uid - The user ID being checked against. A uid of 0 is the root
user, which will pass every permission check.modeFlags - The type of access to grant. May be one or both of
Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION.
PackageManager.PERMISSION_GRANTED if the caller
is allowed to access that uri or holds one of the given permissions, or
PackageManager.PERMISSION_DENIED if it is not.
public int checkUriPermission(Uri uri,
int pid,
int uid,
int modeFlags)
Context
checkUriPermission in class ContextWrapperuri - The uri that is being checked.pid - The process ID being checked against. Must be > 0.uid - The user ID being checked against. A uid of 0 is the root
user, which will pass every permission check.modeFlags - The type of access to grant. May be one or both of
Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION.
PackageManager.PERMISSION_GRANTED if the given
pid/uid is allowed to access that uri, or
PackageManager.PERMISSION_DENIED if it is not.Context.checkCallingUriPermission(android.net.Uri, int)public Object getSystemService(String name)
ContextContext.WINDOW_SERVICE ("window")
WindowManager.
Context.LAYOUT_INFLATER_SERVICE ("layout_inflater")
LayoutInflater for inflating layout resources
in this context.
Context.ACTIVITY_SERVICE ("activity")
ActivityManager for interacting with the
global activity state of the system.
Context.POWER_SERVICE ("power")
PowerManager for controlling power
management.
Context.ALARM_SERVICE ("alarm")
AlarmManager for receiving intents at the
time of your choosing.
Context.NOTIFICATION_SERVICE ("notification")
NotificationManager for informing the user
of background events.
Context.KEYGUARD_SERVICE ("keyguard")
KeyguardManager for controlling keyguard.
Context.LOCATION_SERVICE ("location")
LocationManager for controlling location
(e.g., GPS) updates.
Context.SEARCH_SERVICE ("search")
SearchManager for handling search.
Context.VIBRATOR_SERVICE ("vibrator")
Vibrator for interacting with the vibrator
hardware.
Context.CONNECTIVITY_SERVICE ("connection")
ConnectivityManager for
handling management of network connections.
Context.WIFI_SERVICE ("wifi")
WifiManager for management of
Wi-Fi connectivity.
Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.)
getSystemService in class ContextWrappername - The name of the desired service.
Context.WINDOW_SERVICE,
WindowManager,
Context.LAYOUT_INFLATER_SERVICE,
LayoutInflater,
Context.ACTIVITY_SERVICE,
ActivityManager,
Context.POWER_SERVICE,
PowerManager,
Context.ALARM_SERVICE,
AlarmManager,
Context.NOTIFICATION_SERVICE,
NotificationManager,
Context.KEYGUARD_SERVICE,
KeyguardManager,
Context.LOCATION_SERVICE,
LocationManager,
Context.SEARCH_SERVICE,
SearchManager,
Context.SENSOR_SERVICE,
SensorManager,
Context.VIBRATOR_SERVICE,
Vibrator,
Context.CONNECTIVITY_SERVICE,
ConnectivityManager,
Context.WIFI_SERVICE,
WifiManager,
Context.AUDIO_SERVICE,
AudioManager,
Context.TELEPHONY_SERVICE,
android.internal.TelephonyManager
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||