this.setstateelocked是什么异常

java.lang.Throwable
Start line: &
End line: &
Snippet Preview
Snippet HTML Code
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&package&java.&import&; The Throwable class is the superclass of all errors and
exceptions in the Java language. Only objects that are instances of this
class (or one of its subclasses) are thrown by the Java Virtual Machine or
can be thrown by the Java throw statement. Similarly, only
this class or one of its subclasses can be the argument type in a
catch clause.
Instances of two subclasses,
, are conventionally used to indicate
that exceptional situations have occurred. Typically, these instances
are freshly created in the context of the exceptional situation so
as to include relevant information (such as stack trace data).
A throwable contains a snapshot of the execution stack of its thread at
the time it was created. It can also contain a message string that gives
more information about the error. Finally, it can contain a cause:
another throwable that caused this throwable to get thrown.
facility is new in release 1.4.
It is also known as the chained
exception facility, as the cause can, itself, have a cause, and so on,
leading to a &chain& of exceptions, each caused by another.
One reason that a throwable may have a cause is that the class that
throws it is built atop a lower layered abstraction, and an operation on
the upper layer fails due to a failure in the lower layer.
It would be bad
design to let the throwable thrown by the lower layer propagate outward, as
it is generally unrelated to the abstraction provided by the upper layer.
Further, doing so would tie the API of the upper layer to the details of
its implementation, assuming the lower layer&s exception was a checked
exception.
Throwing a &wrapped exception& (i.e., an exception containing a
cause) allows the upper layer to communicate the details of the failure to
its caller without incurring either of these shortcomings.
It preserves
the flexibility to change the implementation of the upper layer without
changing its API (in particular, the set of exceptions thrown by its
A second reason that a throwable may have a cause is that the method
that throws it must conform to a general-purpose interface that does not
permit the method to throw the cause directly.
For example, suppose
a persistent collection conforms to the
Collection interface, and that its persistence is implemented atop
Suppose the internals of the add method
can throw an IOException.
The implementation
can communicate the details of the IOException to its caller
while conforming to the Collection interface by wrapping the
IOException in an appropriate unchecked exception.
specification for the persistent collection should indicate that it is
capable of throwing such exceptions.)
A cause can be associated with a throwable in two ways: via a
constructor that takes the cause as an argument, or via the
New throwable classes that
wish to allow causes to be associated with them should provide constructors
that take a cause and delegate (perhaps indirectly) to one of the
Throwable constructors that takes a cause.
For example:
lowLevelOp();
} catch (LowLevelException le) {
throw new HighLevelException(le);
// Chaining-aware constructor
Because the initCause method is public, it allows a cause to be
associated with any throwable, even a &legacy throwable& whose
implementation predates the addition of the exception chaining mechanism to
Throwable. For example:
lowLevelOp();
} catch (LowLevelException le) {
throw (HighLevelException)
new HighLevelException().initCause(le);
// Legacy constructor
Prior to release 1.4, there were many throwables that had their own
non-standard exception chaining mechanisms (
All of these throwables have been retrofitted to
use the standard exception chaining mechanism, while continuing to
implement their &legacy& chaining mechanisms for compatibility.
Further, as of release 1.4, many general purpose Throwable
classes (for example , ,
) have been retrofitted with constructors that take
This was not strictly necessary, due to the existence of the
initCause method, but it is more convenient and expressive to
delegate to a constructor that takes a cause.
By convention, class Throwable and its subclasses have two
constructors, one that takes no arguments and one that takes a
String argument that can be used to produce a detail message.
Further, those subclasses that might likely have a cause associated with
them should have two more constructors, one that takes a
Throwable (the cause), and one that takes a
String (the detail message) and a Throwable (the
Also introduced in release 1.4 is the
which allows programmatic access to the stack trace information that was
previously available only in text form, via the various forms of the
This information has been added to the
serialized representation of this class so getStackTrace
and printStackTrace will operate properly on a throwable that
was obtained by deserialization.
public&class&&implements&&{&&&&use serialVersionUID from JDK 1.0.2 for interoperability&&&&private&static&final&long&&=&-8047285L;&&&& Native code saves some indication of the stack backtrace in this slot.
&&&&private&transient&&;&&&& Specific details about the Throwable.
For example, for
FileNotFoundException, this contains the name of
the file that could not be found.
&&&&private&&;&&&& The throwable that caused this throwable to get thrown, or null if this
throwable was not caused by another throwable, or if the causative
throwable is unknown.
If this field is equal to this throwable itself,
it indicates that the cause of this throwable has not yet been
initialized.
&&&&private&&&=&this;&&&& The stack trace, as returned by .
&&&&private&[]&;&&&&&&&& Constructs a new throwable with null as its detail message.
The cause is not initialized, and may subsequently be initialized by a
method is called to initialize
the stack trace data in the newly created throwable.
&&&&public&()&{&&&&&&&&();&&&&}&&&& Constructs a new throwable with the specified detail message.
cause is not initialized, and may subsequently be initialized by
a call to .
method is called to initialize
the stack trace data in the newly created throwable.
&&&&public&(&message)&{&&&&&&&&();&&&&&&&&&=&message;&&&&}&&&& Constructs a new throwable with the specified detail message and
Note that the detail message associated with
cause is not automatically incorporated in
this throwable&s detail message.
method is called to initialize
the stack trace data in the newly created throwable.
&&&&public&(&message,&&cause)&{&&&&&&&&();&&&&&&&&&=&message;&&&&&&&&this.&=&cause;&&&&}&&&& Constructs a new throwable with the specified cause and a detail
message of (cause==null ? null : cause.toString()) (which
typically contains the class and detail message of cause).
This constructor is useful for throwables that are little more than
wrappers for other throwables (for example, ).
method is called to initialize
the stack trace data in the newly created throwable.
&&&&public&(&cause)&{&&&&&&&&();&&&&&&&&&=&(cause==null&?&null&:&cause.());&&&&&&&&this.&=&cause;&&&&}&&&& Returns the detail message string of this throwable.
&&&&public&&()&{&&&&&&&&return&;&&&&}&&&& Creates a localized description of this throwable.
Subclasses may override this method in order to produce a
locale-specific message.
For subclasses that do not override this
method, the default implementation returns the same result as
getMessage().
&&&&public&&()&{&&&&&&&&return&();&&&&}&&&& Returns the cause of this throwable or null if the
cause is nonexistent or unknown.
(The cause is the throwable that
caused this throwable to get thrown.)
This implementation returns the cause that was supplied via one of
the constructors requiring a Throwable, or that was set after
creation with the
While it is
typically unnecessary to override this method, a subclass can override
it to return a cause set by some other means.
This is appropriate for
a &legacy chained throwable& that predates the addition of chained
exceptions to Throwable.
Note that it is not
necessary to override any of the PrintStackTrace methods,
all of which invoke the getCause method to determine the
cause of a throwable.
&&&&public&&()&{&&&&&&&&return&(==this&?&null&:&);&&&&}&&&& Initializes the cause of this throwable to the specified value.
(The cause is the throwable that caused this throwable to get thrown.)
This method can be called at most once.
It is generally called from
within the constructor, or immediately after creating the
throwable.
If this throwable was created
with Throwable(java.lang.Throwable) or
Throwable(java.lang.String,java.lang.Throwable), this method cannot be called
even once.
&&&&public&synchronized&&(&cause)&{&&&&&&&&if&(this.&!=&this)&&&&&&&&&&&&throw&new&("Can't&overwrite&cause");&&&&&&&&if&(cause&==&this)&&&&&&&&&&&&throw&new&("Self-causation&not&permitted");&&&&&&&&this.&=&cause;&&&&&&&&return&this;&&&&}&&&& Returns a short description of this throwable.
The result is the concatenation of:
the name of the class of this object
&: & (a colon and a space)
the result of invoking this object&s
If getLocalizedMessage returns null, then just
the class name is returned.
&&&&public&&()&{&&&&&&&&&s&=&().();&&&&&&&&&message&=&();&&&&&&&&return&(message&!=&null)&?&(s&+&":&"&+&message)&:&s;&&&&}&&&& Prints this throwable and its backtrace to the
standard error stream. This method prints a stack trace for this
Throwable object on the error output stream that is
the value of the field System.err. The first line of
output contains the result of the
method for
this object.
Remaining lines represent data previously recorded by
the method . The format of this
information depends on the implementation, but the following
example may be regarded as typical:
java.lang.NullPointerException
at MyClass.mash(MyClass.java:9)
at MyClass.crunch(MyClass.java:6)
at MyClass.main(MyClass.java:3)
This example was produced by running the program:
class MyClass {
public static void main(String[] args) {
crunch(null);
static void crunch(int[] a) {
static void mash(int[] b) {
System.out.println(b[0]);
The backtrace for a throwable with an initialized, non-null cause
should generally include the backtrace for the cause.
The format
of this information depends on the implementation, but the following
example may be regarded as typical:
HighLevelException: MidLevelException: LowLevelException
at Junk.a(Junk.java:13)
at Junk.main(Junk.java:4)
Caused by: MidLevelException: LowLevelException
at Junk.c(Junk.java:23)
at Junk.b(Junk.java:17)
at Junk.a(Junk.java:11)
... 1 more
Caused by: LowLevelException
at Junk.e(Junk.java:30)
at Junk.d(Junk.java:27)
at Junk.c(Junk.java:21)
... 3 more
Note the presence of lines containing the characters &...&.
These lines indicate that the remainder of the stack trace for this
exception matches the indicated number of frames from the bottom of the
stack trace of the exception that was caused by this exception (the
&enclosing& exception).
This shorthand can greatly reduce the length
of the output in the common case where a wrapped exception is thrown
from same method as the &causative exception& is caught.
example was produced by running the program:
public class Junk {
public static void main(String args[]) {
} catch(HighLevelException e) {
e.printStackTrace();
static void a() throws HighLevelException {
} catch(MidLevelException e) {
throw new HighLevelException(e);
static void b() throws MidLevelException {
static void c() throws MidLevelException {
} catch(LowLevelException e) {
throw new MidLevelException(e);
static void d() throws LowLevelException {
static void e() throws LowLevelException {
throw new LowLevelException();
class HighLevelException extends Exception {
HighLevelException(Throwable cause) { super(cause); }
class MidLevelException extends Exception {
MidLevelException(Throwable cause)
{ super(cause); }
class LowLevelException extends Exception {
&&&&public&void&()&{&&&&&&&&(.);&&&&}&&&& Prints this throwable and its backtrace to the specified print stream.
&&&&public&void&(&s)&{&&&&&&&&synchronized&(s)&{&&&&&&&&&&&&s.(this);&&&&&&&&&&&&[]&trace&=&();&&&&&&&&&&&&for&(int&i=0;&i&&&trace.length;&i++)&&&&&&&&&&&&&&&&s.("\tat&"&+&trace[i]);&&&&&&&&&&&&&ourCause&=&();&&&&&&&&&&&&if&(ourCause&!=&null)&&&&&&&&&&&&&&&&ourCause.(s,&trace);&&&&&&&&}&&&&}&&&& Print our stack trace as a cause for the specified stack trace.
&&&&private&void&(&s,&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&[]&causedTrace)&&&&{&&&&&&&&&&&&&&&&&&&&&&&&[]&trace&=&();&&&&&&&&int&m&=&trace.length-1,&n&=&causedTrace.length-1;&&&&&&&&while&(m&>=&0&&&&n&>=0&&&&trace[m].(causedTrace[n]))&{&&&&&&&&&&&&m--;&n--;&&&&&&&&}&&&&&&&&int&framesInCommon&=&trace.length&-&1&-&m;&&&&&&&&s.("Caused&by:&"&+&this);&&&&&&&&for&(int&i=0;&i&&=&m;&i++)&&&&&&&&&&&&s.("\tat&"&+&trace[i]);&&&&&&&&if&(framesInCommon&!=&0)&&&&&&&&&&&&s.("\t...&"&+&framesInCommon&+&"&more");&&&&&&&&&&&&&&&&&ourCause&=&();&&&&&&&&if&(ourCause&!=&null)&&&&&&&&&&&&ourCause.(s,&trace);&&&&}&&&& Prints this throwable and its backtrace to the specified
print writer.
&&&&public&void&(&s)&{&&&&&&&&synchronized&(s)&{&&&&&&&&&&&&s.(this);&&&&&&&&&&&&[]&trace&=&();&&&&&&&&&&&&for&(int&i=0;&i&&&trace.length;&i++)&&&&&&&&&&&&&&&&s.("\tat&"&+&trace[i]);&&&&&&&&&&&&&ourCause&=&();&&&&&&&&&&&&if&(ourCause&!=&null)&&&&&&&&&&&&&&&&ourCause.(s,&trace);&&&&&&&&}&&&&}&&&& Print our stack trace as a cause for the specified stack trace.
&&&&private&void&(&s,&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&[]&causedTrace)&&&&{&&&&&&&&&&&&&&&&&&&&&&&&[]&trace&=&();&&&&&&&&int&m&=&trace.length-1,&n&=&causedTrace.length-1;&&&&&&&&while&(m&>=&0&&&&n&>=0&&&&trace[m].(causedTrace[n]))&{&&&&&&&&&&&&m--;&n--;&&&&&&&&}&&&&&&&&int&framesInCommon&=&trace.length&-&1&-&m;&&&&&&&&s.("Caused&by:&"&+&this);&&&&&&&&for&(int&i=0;&i&&=&m;&i++)&&&&&&&&&&&&s.("\tat&"&+&trace[i]);&&&&&&&&if&(framesInCommon&!=&0)&&&&&&&&&&&&s.("\t...&"&+&framesInCommon&+&"&more");&&&&&&&&&&&&&&&&&ourCause&=&();&&&&&&&&if&(ourCause&!=&null)&&&&&&&&&&&&ourCause.(s,&trace);&&&&}&&&& Fills in the execution stack trace. This method records within this
Throwable object information about the current state of
the stack frames for the current thread.
&&&&public&synchronized&native&&();&&&& Provides programmatic access to the stack trace information printed by
Returns an array of stack trace elements,
each representing one stack frame.
The zeroth element of the array
(assuming the array&s length is non-zero) represents the top of the
stack, which is the last method invocation in the sequence.
Typically,
this is the point at which this throwable was created and thrown.
The last element of the array (assuming the array&s length is non-zero)
represents the bottom of the stack, which is the first method invocation
in the sequence.
Some virtual machines may, under some circumstances, omit one
or more stack frames from the stack trace.
In the extreme case,
a virtual machine that has no stack trace information concerning
this throwable is permitted to return a zero-length array from this
Generally speaking, the array returned by this method will
contain one element for every frame that would be printed by
printStackTrace.
&&&&public&[]&()&{&&&&&&&&return&().();&&&&}&&&&private&synchronized&[]&()&{&&&&&&&&&&&&&&&&if&(&==&null)&{&&&&&&&&&&&&int&depth&=&();&&&&&&&&&&&&&=&new&[depth];&&&&&&&&&&&&for&(int&i=0;&i&&&depth;&i++)&&&&&&&&&&&&&&&&[i]&=&(i);&&&&&&&&}&&&&&&&&return&;&&&&}&&&& Sets the stack trace elements that will be returned by
and printed by
and related methods.
This method, which is designed for use by RPC frameworks and other
advanced systems, allows the client to override the default
stack trace that is either generated by
when a throwable is constructed or deserialized when a throwable is
read from a serialization stream.
&&&&public&void&([]&stackTrace)&{&&&&&&&&[]&defensiveCopy&=&stackTrace.();&&&&&&&&for&(int&i&=&0;&i&&&defensiveCopy.length;&i++)&&&&&&&&&&&&if&(defensiveCopy[i]&==&null)&&&&&&&&&&&&&&&&throw&new&("stackTrace["&+&i&+&"]");&&&&&&&&this.&=&defensiveCopy;&&&&}&&&& Returns the number of elements in the stack trace (or 0 if the stack
trace is unavailable).
&&&&private&native&int&();&&&& Returns the specified element of the stack trace.
&&&&private&native&&(int&index);&&&&private&synchronized&void&(..&s)&&&&&&&&throws&&&&&{&&&&&&&&();&&&&&&&&&&s.();&&&&}}
&java.lang
<div class="gae-status" id="gae-status-$java$root@jdk$openjdk@6-b14@java$lang@Throwable@()">
<div class="gae-status" id="gae-status-$java$root@jdk$openjdk@6-b14@java$lang@Throwable@(java.lang.String)">
<div class="gae-status" id="gae-status-$java$root@jdk$openjdk@6-b14@java$lang@Throwable@(java.lang.Throwable)">
<div class="gae-status" id="gae-status-$java$root@jdk$openjdk@6-b14@java$lang@Throwable@(java.lang.String,java.lang.Throwable)">
New to GrepCode? Check out ourJava Code Example android.content.pm.ServiceInfo
Java Code Examples for android.content.pm.ServiceInfo
The following are top voted examples for showing how to use
android.content.pm.ServiceInfo. These examples are extracted from open source projects.
You can vote up the examples you like and your votes will be used in our system to product
more good examples.
* Finds the meta-data XML containing the contacts configuration and
* reads the picture priority from that file.
/* package */ int resolvePhotoPriorityFromMetaData(String packageName) {
final PackageManager pm = mContext.getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SERVICES
| PackageManager.GET_META_DATA);
if (pi != null && pi.services != null) {
for (ServiceInfo si : pi.services) {
final XmlResourceParser parser = si.loadXmlMetaData(pm, METADATA_CONTACTS);
if (parser != null) {
return loadPhotoPriorityFromXml(mContext, parser);
} catch (NameNotFoundException e) {
Log.w(TAG, &Problem loading photo priorities: & + e.toString());
return DEFAULT_PRIORITY;
* Constructor.
* @param context The Context in which we are parsing the input method.
* @param service The ResolveInfo returned from the package manager about
* this input method's component.
public InputMethodInfo(Context context, ResolveInfo service)
throws XmlPullParserException, IOException {
mService =
ServiceInfo si = service.serviceI
mId = new ComponentName(si.packageName, si.name).flattenToShortString();
PackageManager pm = context.getPackageManager();
String settingsActivityComponent =
int isDefaultResId = 0;
XmlResourceParser parser =
parser = si.loadXmlMetaData(pm, InputMethod.SERVICE_META_DATA);
if (parser == null) {
throw new XmlPullParserException(&No &
+ InputMethod.SERVICE_META_DATA + & meta-data&);
AttributeSet attrs = Xml.asAttributeSet(parser);
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
String nodeName = parser.getName();
if (!&input-method&.equals(nodeName)) {
throw new XmlPullParserException(
&Meta-data does not start with input-method tag&);
TypedArray sa = context.getResources().obtainAttributes(attrs,
com.android.internal.R.styleable.InputMethod);
settingsActivityComponent = sa.getString(
com.android.internal.R.styleable.InputMethod_settingsActivity);
isDefaultResId = sa.getResourceId(
com.android.internal.R.styleable.InputMethod_isDefault, 0);
sa.recycle();
} finally {
if (parser != null) parser.close();
mSettingsActivityName = settingsActivityC
mIsDefaultResId = isDefaultResId;
* Returns the CONTACTS_STRUCTURE metadata (aka &contacts.xml&) in the given apk package.
* Unfortunately, there's no public way to determine which service defines a sync service for
* which account type, so this method looks through all services in the package, and just
* returns the first CONTACTS_STRUCTURE metadata defined in any of them.
* Returns {@code null} if the package has no CONTACTS_STRUCTURE metadata.
In this case
* the account type *will* be initialized with minimal configuration.
* On the other hand, if the package is not found, it throws a {@link NameNotFoundException},
* in which case the account type will *not* be initialized.
private XmlResourceParser loadContactsXml(Context context, String resPackageName)
throws NameNotFoundException {
final PackageManager pm = context.getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo(resPackageName,
PackageManager.GET_SERVICES|PackageManager.GET_META_DATA);
for (ServiceInfo serviceInfo : packageInfo.services) {
final XmlResourceParser parser = serviceInfo.loadXmlMetaData(pm,
METADATA_CONTACTS);
if (parser != null) {
// Package was found, but that doesn't contain the CONTACTS_STRUCTURE metadata.
* Constructor.
* @param context The Context in which we are parsing the input method.
* @param service The ResolveInfo returned from the package manager about
* this input method's component.
public InputMethodInfo(Context context, ResolveInfo service)
throws XmlPullParserException, IOException {
mService =
ServiceInfo si = service.serviceI
mId = new ComponentName(si.packageName, si.name).flattenToShortString();
PackageManager pm = context.getPackageManager();
String settingsActivityComponent =
int isDefaultResId = 0;
XmlResourceParser parser =
parser = si.loadXmlMetaData(pm, InputMethod.SERVICE_META_DATA);
if (parser == null) {
throw new XmlPullParserException(&No &
+ InputMethod.SERVICE_META_DATA + & meta-data&);
AttributeSet attrs = Xml.asAttributeSet(parser);
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
String nodeName = parser.getName();
if (!&input-method&.equals(nodeName)) {
throw new XmlPullParserException(
&Meta-data does not start with input-method tag&);
TypedArray sa = context.getResources().obtainAttributes(attrs,
com.android.internal.R.styleable.InputMethod);
settingsActivityComponent = sa.getString(
com.android.internal.R.styleable.InputMethod_settingsActivity);
isDefaultResId = sa.getResourceId(
com.android.internal.R.styleable.InputMethod_isDefault, 0);
sa.recycle();
} finally {
if (parser != null) parser.close();
mSettingsActivityName = settingsActivityC
mIsDefaultResId = isDefaultResId;
public final void scheduleCreateService(IBinder token, ServiceInfo info,
CompatibilityInfo compatInfo) throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
data.writeStrongBinder(token);
info.writeToParcel(data, 0);
compatInfo.writeToParcel(data, 0);
mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
IBinder.FLAG_ONEWAY);
data.recycle();
public final void scheduleCreateService(IBinder token, ServiceInfo info,
CompatibilityInfo compatInfo) throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
data.writeStrongBinder(token);
info.writeToParcel(data, 0);
compatInfo.writeToParcel(data, 0);
mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
IBinder.FLAG_ONEWAY);
data.recycle();
public final void scheduleCreateService(IBinder token, ServiceInfo info)
throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
data.writeStrongBinder(token);
info.writeToParcel(data, 0);
mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
IBinder.FLAG_ONEWAY);
data.recycle();
public final void scheduleCreateService(IBinder token, ServiceInfo info)
throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
data.writeStrongBinder(token);
info.writeToParcel(data, 0);
mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
IBinder.FLAG_ONEWAY);
data.recycle();
public final void scheduleCreateService(IBinder token, ServiceInfo info,
CompatibilityInfo compatInfo) throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
data.writeStrongBinder(token);
info.writeToParcel(data, 0);
compatInfo.writeToParcel(data, 0);
mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
IBinder.FLAG_ONEWAY);
data.recycle();
Example 10
public final void scheduleCreateService(IBinder token, ServiceInfo info)
throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
data.writeStrongBinder(token);
info.writeToParcel(data, 0);
mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
IBinder.FLAG_ONEWAY);
data.recycle();
Example 11
public final void scheduleCreateService(IBinder token, ServiceInfo info)
throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
data.writeStrongBinder(token);
info.writeToParcel(data, 0);
mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
IBinder.FLAG_ONEWAY);
data.recycle();
Example 12
public final void scheduleCreateService(IBinder token, ServiceInfo info,
CompatibilityInfo compatInfo, int processState) throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
data.writeStrongBinder(token);
info.writeToParcel(data, 0);
compatInfo.writeToParcel(data, 0);
data.writeInt(processState);
mRemote.transact(SCHEDULE_CREATE_SERVICE_TRANSACTION, data, null,
IBinder.FLAG_ONEWAY);
} catch (TransactionTooLargeException e) {
Log.e(&CREATE_SERVICE&, &Binder fail service=& + info);
data.recycle();
Example 13
private EngineInfo getEngineInfo(ResolveInfo resolve, PackageManager pm) {
ServiceInfo service = resolve.serviceI
if (service != null) {
EngineInfo engine = new EngineInfo();
// Using just the package name isn't great, since it disallows having
// multiple engines in the same package, but that's what the existing API does.
engine.name = service.packageN
CharSequence label = service.loadLabel(pm);
engine.label = TextUtils.isEmpty(label) ? engine.name : label.toString();
engine.icon = service.getIconResource();
engine.priority = resolve.
engine.system = isSystemEngine(service);
Example 14
private EngineInfo getEngineInfo(ResolveInfo resolve, PackageManager pm) {
ServiceInfo service = resolve.serviceI
if (service != null) {
EngineInfo engine = new EngineInfo();
// Using just the package name isn't great, since it disallows having
// multiple engines in the same package, but that's what the existing API does.
engine.name = service.packageN
CharSequence label = service.loadLabel(pm);
engine.label = TextUtils.isEmpty(label) ? engine.name : label.toString();
engine.icon = service.getIconResource();
engine.priority = resolve.
engine.system = isSystemEngine(service);
Example 15
public CharSequence getActiveDreamName() {
ComponentName cn = getActiveDream();
if (cn != null) {
PackageManager pm = mContext.getPackageManager();
ServiceInfo ri = pm.getServiceInfo(cn, 0);
if (ri != null) {
return ri.loadLabel(pm);
} catch (PackageManager.NameNotFoundException exc) {
// uninstalled?
Example 16
private String getSuppressorCaption(ComponentName suppressor) {
final PackageManager pm = mContext.getPackageManager();
final ServiceInfo info = pm.getServiceInfo(suppressor, 0);
if (info != null) {
final CharSequence seq = info.loadLabel(pm);
if (seq != null) {
final String str = seq.toString().trim();
if (str.length() & 0) {
} catch (Throwable e) {
Log.w(TAG, &Error loading suppressor caption&, e);
return suppressor.getPackageName();
Example 17
private EngineInfo getEngineInfo(ResolveInfo resolve, PackageManager pm) {
ServiceInfo service = resolve.serviceI
if (service != null) {
EngineInfo engine = new EngineInfo();
// Using just the package name isn't great, since it disallows having
// multiple engines in the same package, but that's what the existing API does.
engine.name = service.packageN
CharSequence label = service.loadLabel(pm);
engine.label = TextUtils.isEmpty(label) ? engine.name : label.toString();
engine.icon = service.getIconResource();
engine.priority = resolve.
engine.system = isSystemEngine(service);
Example 18
* Returns the localized name of the TTS engine with the specified package
* @param context The parent context.
* @param enginePackage The package name of the TTS engine.
* @return The localized name of the TTS engine.
static CharSequence getLabelForEngine(Context context, String enginePackage) {
if (enginePackage == null) {
final PackageManager pm = context.getPackageManager();
final Intent intent = new Intent(TextToSpeech.Engine.INTENT_ACTION_TTS_SERVICE);
intent.setPackage(enginePackage);
final List&ResolveInfo& resolveInfos =
pm.queryIntentServices(intent, PackageManager.MATCH_DEFAULT_ONLY);
if ((resolveInfos == null) || resolveInfos.isEmpty()) {
final ResolveInfo resolveInfo = resolveInfos.get(0);
final ServiceInfo serviceInfo = resolveInfo.serviceI
if (serviceInfo == null) {
return serviceInfo.loadLabel(pm);
Example 19
public CharSequence getActiveDreamName() {
ComponentName cn = getActiveDream();
if (cn != null) {
PackageManager pm = mContext.getPackageManager();
ServiceInfo ri = pm.getServiceInfo(cn, 0);
if (ri != null) {
return ri.loadLabel(pm);
} catch (PackageManager.NameNotFoundException exc) {
// uninstalled?
Example 20
private void populateServices() {
PackageManager pm = getPackageManager();
List&ResolveInfo& services = pm.queryIntentServices(
new Intent(RecognitionService.SERVICE_INTERFACE), 0);
String selectedService = mPrefs.getString(mKeyService, null);
int selectedIndex = 0;
CharSequence[] entries = new CharSequence[services.size()];
CharSequence[] entryValues = new CharSequence[services.size()];
int index = 0;
for (ResolveInfo ri : services) {
ServiceInfo si = ri.serviceI
if (si == null) {
Log.i(&serviceInfo == null&);
String pkg = si.packageN
String cls = si.
CharSequence label = si.loadLabel(pm);
mPkgToCls.put(pkg, cls);
Log.i(pkg + & :: & + label + & :: & + mPkgToCls.get(pkg));
entries[index] =
entryValues[index] =
if (pkg.equals(selectedService)) {
selectedIndex =
if (services.size() & 0) {
ListPreference list = (ListPreference) mSettingsFragment.findPreference(mKeyService);
list.setEntries(entries);
list.setEntryValues(entryValues);
list.setValueIndex(selectedIndex);
list.setSummary(list.getEntry());
populateLangs();
Example 21
private EngineInfo getEngineInfo(ResolveInfo resolve, PackageManager pm) {
ServiceInfo service = resolve.serviceI
if (service != null) {
EngineInfo engine = new EngineInfo();
// Using just the package name isn't great, since it disallows having
// multiple engines in the same package, but that's what the existing API does.
engine.name = service.packageN
CharSequence label = service.loadLabel(pm);
engine.label = TextUtils.isEmpty(label) ? engine.name : label.toString();
engine.icon = service.getIconResource();
engine.priority = resolve.
engine.system = isSystemEngine(service);
Example 22
public CharSequence getActiveDreamName() {
ComponentName cn = getActiveDream();
if (cn != null) {
PackageManager pm = mContext.getPackageManager();
ServiceInfo ri = pm.getServiceInfo(cn, 0);
if (ri != null) {
return ri.loadLabel(pm);
} catch (PackageManager.NameNotFoundException exc) {
// uninstalled?
Example 23
* Creates a new instance.
* @param resolveInfo The service resolve info.
* @param context Context for accessing resources.
* @throws XmlPullParserException If a XML parsing error occurs.
* @throws IOException If a XML parsing error occurs.
public AccessibilityServiceInfo(ResolveInfo resolveInfo, Context context)
throws XmlPullParserException, IOException {
ServiceInfo serviceInfo = resolveInfo.serviceI
mId = new ComponentName(serviceInfo.packageName, serviceInfo.name).flattenToShortString();
mResolveInfo = resolveI
XmlResourceParser parser =
PackageManager packageManager = context.getPackageManager();
parser = serviceInfo.loadXmlMetaData(packageManager,
AccessibilityService.SERVICE_META_DATA);
if (parser == null) {
int type = 0;
while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
type = parser.next();
String nodeName = parser.getName();
if (!TAG_ACCESSIBILITY_SERVICE.equals(nodeName)) {
throw new XmlPullParserException( &Meta-data does not start with&
+ TAG_ACCESSIBILITY_SERVICE + & tag&);
AttributeSet allAttributes = Xml.asAttributeSet(parser);
Resources resources = packageManager.getResourcesForApplication(
serviceInfo.applicationInfo);
TypedArray asAttributes = resources.obtainAttributes(allAttributes,
com.android.internal.R.styleable.AccessibilityService);
eventTypes = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityEventTypes,
String packageNamez = asAttributes.getString(
com.android.internal.R.styleable.AccessibilityService_packageNames);
if (packageNamez != null) {
packageNames = packageNamez.split(&(\\s)*,(\\s)*&);
feedbackType = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityFeedbackType,
notificationTimeout = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_notificationTimeout,
flags = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityFlags, 0);
mSettingsActivityName = asAttributes.getString(
com.android.internal.R.styleable.AccessibilityService_settingsActivity);
mCanRetrieveWindowContent = asAttributes.getBoolean(
com.android.internal.R.styleable.AccessibilityService_canRetrieveWindowContent,
TypedValue peekedValue = asAttributes.peekValue(
com.android.internal.R.styleable.AccessibilityService_description);
if (peekedValue != null) {
mDescriptionResId = peekedValue.resourceId;
CharSequence nonLocalizedDescription = peekedValue.coerceToString();
if (nonLocalizedDescription != null) {
mNonLocalizedDescription = nonLocalizedDescription.toString().trim();
asAttributes.recycle();
} catch (NameNotFoundException e) {
throw new XmlPullParserException( &Unable to create context for: &
+ serviceInfo.packageName);
} finally {
if (parser != null) {
parser.close();
Example 24
* Creates a new instance.
* @param resolveInfo The service resolve info.
* @param context Context for accessing resources.
* @throws XmlPullParserException If a XML parsing error occurs.
* @throws IOException If a XML parsing error occurs.
public AccessibilityServiceInfo(ResolveInfo resolveInfo, Context context)
throws XmlPullParserException, IOException {
ServiceInfo serviceInfo = resolveInfo.serviceI
mId = new ComponentName(serviceInfo.packageName, serviceInfo.name).flattenToShortString();
mResolveInfo = resolveI
XmlResourceParser parser =
PackageManager packageManager = context.getPackageManager();
parser = serviceInfo.loadXmlMetaData(packageManager,
AccessibilityService.SERVICE_META_DATA);
if (parser == null) {
int type = 0;
while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
type = parser.next();
String nodeName = parser.getName();
if (!TAG_ACCESSIBILITY_SERVICE.equals(nodeName)) {
throw new XmlPullParserException( &Meta-data does not start with&
+ TAG_ACCESSIBILITY_SERVICE + & tag&);
AttributeSet allAttributes = Xml.asAttributeSet(parser);
Resources resources = packageManager.getResourcesForApplication(
serviceInfo.applicationInfo);
TypedArray asAttributes = resources.obtainAttributes(allAttributes,
com.android.internal.R.styleable.AccessibilityService);
eventTypes = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityEventTypes,
String packageNamez = asAttributes.getString(
com.android.internal.R.styleable.AccessibilityService_packageNames);
if (packageNamez != null) {
packageNames = packageNamez.split(&(\\s)*,(\\s)*&);
feedbackType = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityFeedbackType,
notificationTimeout = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_notificationTimeout,
flags = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityFlags, 0);
mSettingsActivityName = asAttributes.getString(
com.android.internal.R.styleable.AccessibilityService_settingsActivity);
mCanRetrieveWindowContent = asAttributes.getBoolean(
com.android.internal.R.styleable.AccessibilityService_canRetrieveWindowContent,
TypedValue peekedValue = asAttributes.peekValue(
com.android.internal.R.styleable.AccessibilityService_description);
if (peekedValue != null) {
mDescriptionResId = peekedValue.resourceId;
CharSequence nonLocalizedDescription = peekedValue.coerceToString();
if (nonLocalizedDescription != null) {
mNonLocalizedDescription = nonLocalizedDescription.toString().trim();
asAttributes.recycle();
} catch (NameNotFoundException e) {
throw new XmlPullParserException( &Unable to create context for: &
+ serviceInfo.packageName);
} finally {
if (parser != null) {
parser.close();
Example 25
* Constructor.
* @param context The Context in which we are parsing the input method.
* @param service The ResolveInfo returned from the package manager about
* this input method's component.
public InputMethodInfo(Context context, ResolveInfo service)
throws XmlPullParserException, IOException {
mService =
ServiceInfo si = service.serviceI
mId = new ComponentName(si.packageName, si.name).flattenToShortString();
PackageManager pm = context.getPackageManager();
String settingsActivityComponent =
int isDefaultResId = 0;
XmlResourceParser parser =
parser = si.loadXmlMetaData(pm, InputMethod.SERVICE_META_DATA);
if (parser == null) {
throw new XmlPullParserException(&No &
+ InputMethod.SERVICE_META_DATA + & meta-data&);
Resources res = pm.getResourcesForApplication(si.applicationInfo);
AttributeSet attrs = Xml.asAttributeSet(parser);
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
String nodeName = parser.getName();
if (!&input-method&.equals(nodeName)) {
throw new XmlPullParserException(
&Meta-data does not start with input-method tag&);
TypedArray sa = res.obtainAttributes(attrs,
com.android.internal.R.styleable.InputMethod);
settingsActivityComponent = sa.getString(
com.android.internal.R.styleable.InputMethod_settingsActivity);
isDefaultResId = sa.getResourceId(
com.android.internal.R.styleable.InputMethod_isDefault, 0);
sa.recycle();
} catch (NameNotFoundException e) {
throw new XmlPullParserException(
&Unable to create context for: & + si.packageName);
} finally {
if (parser != null) parser.close();
mSettingsActivityName = settingsActivityC
mIsDefaultResId = isDefaultResId;
Example 26
* Creates a new instance.
* @param resolveInfo The service resolve info.
* @param context Context for accessing resources.
* @throws XmlPullParserException If a XML parsing error occurs.
* @throws IOException If a XML parsing error occurs.
public AccessibilityServiceInfo(ResolveInfo resolveInfo, Context context)
throws XmlPullParserException, IOException {
ServiceInfo serviceInfo = resolveInfo.serviceI
mId = new ComponentName(serviceInfo.packageName, serviceInfo.name).flattenToShortString();
mResolveInfo = resolveI
XmlResourceParser parser =
PackageManager packageManager = context.getPackageManager();
parser = serviceInfo.loadXmlMetaData(packageManager,
AccessibilityService.SERVICE_META_DATA);
if (parser == null) {
int type = 0;
while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
type = parser.next();
String nodeName = parser.getName();
if (!TAG_ACCESSIBILITY_SERVICE.equals(nodeName)) {
throw new XmlPullParserException( &Meta-data does not start with&
+ TAG_ACCESSIBILITY_SERVICE + & tag&);
AttributeSet allAttributes = Xml.asAttributeSet(parser);
Resources resources = packageManager.getResourcesForApplication(
serviceInfo.applicationInfo);
TypedArray asAttributes = resources.obtainAttributes(allAttributes,
com.android.internal.R.styleable.AccessibilityService);
eventTypes = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityEventTypes,
String packageNamez = asAttributes.getString(
com.android.internal.R.styleable.AccessibilityService_packageNames);
if (packageNamez != null) {
packageNames = packageNamez.split(&(\\s)*,(\\s)*&);
feedbackType = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityFeedbackType,
notificationTimeout = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_notificationTimeout,
flags = asAttributes.getInt(
com.android.internal.R.styleable.AccessibilityService_accessibilityFlags, 0);
mSettingsActivityName = asAttributes.getString(
com.android.internal.R.styleable.AccessibilityService_settingsActivity);
mCanRetrieveWindowContent = asAttributes.getBoolean(
com.android.internal.R.styleable.AccessibilityService_canRetrieveWindowContent,
mDescription = asAttributes.getString(
com.android.internal.R.styleable.AccessibilityService_description);
asAttributes.recycle();
} catch (NameNotFoundException e) {
throw new XmlPullParserException( &Unable to create context for: &
+ serviceInfo.packageName);
} finally {
if (parser != null) {
parser.close();
Example 27
private static TvInputInfo createTvInputInfo(Context context, ResolveInfo service, String id,
String parentId, int inputType, boolean isHardwareInput, int labelRes, String label,
Icon icon, Uri iconUri, boolean isConnectedToHdmiSwitch)
throws XmlPullParserException, IOException {
ServiceInfo si = service.serviceI
PackageManager pm = context.getPackageManager();
XmlResourceParser parser =
parser = si.loadXmlMetaData(pm, TvInputService.SERVICE_META_DATA);
if (parser == null) {
throw new XmlPullParserException(&No & + TvInputService.SERVICE_META_DATA
+ & meta-data for & + si.name);
Resources res = pm.getResourcesForApplication(si.applicationInfo);
AttributeSet attrs = Xml.asAttributeSet(parser);
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
String nodeName = parser.getName();
if (!XML_START_TAG_NAME.equals(nodeName)) {
throw new XmlPullParserException(
&Meta-data does not start with tv-input-service tag in & + si.name);
TvInputInfo input = new TvInputInfo(service, id, parentId, inputType, isHardwareInput);
TypedArray sa = res.obtainAttributes(attrs,
com.android.internal.R.styleable.TvInputService);
input.mSetupActivity = sa.getString(
com.android.internal.R.styleable.TvInputService_setupActivity);
if (DEBUG) {
Log.d(TAG, &Setup activity loaded. [& + input.mSetupActivity + &] for & + si.name);
if (inputType == TYPE_TUNER && TextUtils.isEmpty(input.mSetupActivity)) {
throw new XmlPullParserException(&Setup activity not found in & + si.name);
input.mSettingsActivity = sa.getString(
com.android.internal.R.styleable.TvInputService_settingsActivity);
if (DEBUG) {
Log.d(TAG, &Settings activity loaded. [& + input.mSettingsActivity + &] for &
+ si.name);
sa.recycle();
input.mLabelRes = labelR
input.mLabel =
input.mIcon =
input.mIconUri = iconU
input.mIsConnectedToHdmiSwitch = isConnectedToHdmiS
} catch (NameNotFoundException e) {
throw new XmlPullParserException(&Unable to create context for: & + si.packageName);
} finally {
if (parser != null) {
parser.close();}

我要回帖

更多关于 setstatelocked 安卓 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信