Build 1.0_r1(from source)

android.test
Class IsolatedContext

java.lang.Object
  extended by android.content.Context
      extended by android.content.ContextWrapper
          extended by android.test.IsolatedContext

public class IsolatedContext
extends ContextWrapper

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
 
Fields inherited from class android.content.Context
ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BLUETOOTH_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MODE_APPEND, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NOTIFICATION_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, STATUS_BAR_SERVICE, TELEPHONY_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
 
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.ContextWrapper
attachBaseContext, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, clearWallpaper, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getAssets, getBaseContext, getCacheDir, getClassLoader, getDatabasePath, getDir, getFilesDir, getFileStreamPath, getMainLooper, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, openFileInput, openFileOutput, openOrCreateDatabase, peekWallpaper, registerReceiver, removeStickyBroadcast, revokeUriPermission, sendBroadcast, sendOrderedBroadcast, sendStickyBroadcast, setTheme, setWallpaper, setWallpaper, startActivity, startInstrumentation, startService, stopService, unbindService, unregisterReceiver
 
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

IsolatedContext

public IsolatedContext(ContentResolver resolver,
                       Context targetContext)
Method Detail

getAndClearBroadcastIntents

public List<Intent> getAndClearBroadcastIntents()
Returns the list of intents that were broadcast since the last call to this method.


getContentResolver

public ContentResolver getContentResolver()
Description copied from class: Context
Return a ContentResolver instance for your application's package.

Overrides:
getContentResolver in class ContextWrapper

bindService

public boolean bindService(Intent service,
                           ServiceConnection conn,
                           int flags)
Description copied from class: Context
Connect to an application service, creating it if needed. This defines a dependency between your application and the service. The given conn will receive the service object when its created and be told if it dies and restarts. The service will be considered required by the system only for as long as the calling context exists. For example, if this Context is an Activity that is stopped, the service will not be required to continue running until the Activity is resumed.

This 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).

Overrides:
bindService in class ContextWrapper
Parameters:
service - 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.
Returns:
If you have successfully bound to the service, true is returned; false is returned if the connection is not made so you will not receive the service object.
See Also:
Context.unbindService(android.content.ServiceConnection), Context.startService(android.content.Intent), Context.BIND_AUTO_CREATE

registerReceiver

public Intent registerReceiver(BroadcastReceiver receiver,
                               IntentFilter filter)
Description copied from class: Context
Register an BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.

The 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).

Overrides:
registerReceiver in class ContextWrapper
Parameters:
receiver - The BroadcastReceiver to handle the broadcast.
filter - Selects the Intent broadcasts to be received.
Returns:
The first sticky intent found that matches filter, or null if there are none.
See Also:
Context.registerReceiver(BroadcastReceiver, IntentFilter, String, Handler), Context.sendBroadcast(android.content.Intent), Context.unregisterReceiver(android.content.BroadcastReceiver)

sendBroadcast

public void sendBroadcast(Intent intent)
Description copied from class: Context
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 Context.sendOrderedBroadcast(Intent, String).

See BroadcastReceiver for more information on Intent broadcasts.

Overrides:
sendBroadcast in class ContextWrapper
Parameters:
intent - The Intent to broadcast; all receivers matching this Intent will receive the broadcast.
See Also:
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)

sendOrderedBroadcast

public void sendOrderedBroadcast(Intent intent,
                                 String receiverPermission)
Description copied from class: Context
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. This call is asynchronous; it returns immediately, and you will continue executing while the receivers are run.

See BroadcastReceiver for more information on Intent broadcasts.

Overrides:
sendOrderedBroadcast in class ContextWrapper
Parameters:
intent - 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.
See Also:
BroadcastReceiver, Context.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter), Context.sendBroadcast(Intent), Context.sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)

checkUriPermission

public int checkUriPermission(Uri uri,
                              String readPermission,
                              String writePermission,
                              int pid,
                              int uid,
                              int modeFlags)
Description copied from class: Context
Check both a Uri and normal permission. This allows you to perform both Context.checkPermission(java.lang.String, int, int) and Context.checkUriPermission(android.net.Uri, int, int, int) in one call.

Overrides:
checkUriPermission in class ContextWrapper
Parameters:
uri - 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.
Returns:
Returns 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.

checkUriPermission

public int checkUriPermission(Uri uri,
                              int pid,
                              int uid,
                              int modeFlags)
Description copied from class: Context
Determine whether a particular process and user ID has been granted permission to access a specific URI. This only checks for permissions that have been explicitly granted -- if the given process/uid has more general access to the URI's content provider then this check will always fail.

Overrides:
checkUriPermission in class ContextWrapper
Parameters:
uri - 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.
Returns:
Returns PackageManager.PERMISSION_GRANTED if the given pid/uid is allowed to access that uri, or PackageManager.PERMISSION_DENIED if it is not.
See Also:
Context.checkCallingUriPermission(android.net.Uri, int)

getSystemService

public Object getSystemService(String name)
Description copied from class: Context
Return the handle to a system-level service by name. The class of the returned object varies by the requested name. Currently available names are:
Context.WINDOW_SERVICE ("window")
The top-level window manager in which you can place custom windows. The returned object is a WindowManager.
Context.LAYOUT_INFLATER_SERVICE ("layout_inflater")
A LayoutInflater for inflating layout resources in this context.
Context.ACTIVITY_SERVICE ("activity")
A ActivityManager for interacting with the global activity state of the system.
Context.POWER_SERVICE ("power")
A PowerManager for controlling power management.
Context.ALARM_SERVICE ("alarm")
A AlarmManager for receiving intents at the time of your choosing.
Context.NOTIFICATION_SERVICE ("notification")
A NotificationManager for informing the user of background events.
Context.KEYGUARD_SERVICE ("keyguard")
A KeyguardManager for controlling keyguard.
Context.LOCATION_SERVICE ("location")
A LocationManager for controlling location (e.g., GPS) updates.
Context.SEARCH_SERVICE ("search")
A SearchManager for handling search.
Context.VIBRATOR_SERVICE ("vibrator")
A Vibrator for interacting with the vibrator hardware.
Context.CONNECTIVITY_SERVICE ("connection")
A ConnectivityManager for handling management of network connections.
Context.WIFI_SERVICE ("wifi")
A 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.)

Overrides:
getSystemService in class ContextWrapper
Parameters:
name - The name of the desired service.
Returns:
The service or null if the name does not exist.
See Also:
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)

Please submit a feedback, bug or feature