Skip to content

Commit 864411b

Browse files
committed
Updates to Android stub classes
1 parent 8da9b9d commit 864411b

File tree

4 files changed

+529
-0
lines changed

4 files changed

+529
-0
lines changed
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
/*
2+
* Copyright (C) 2006 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package android.content;
17+
18+
import android.os.Bundle;
19+
/**
20+
* Base class for code that will receive intents sent by sendBroadcast().
21+
*
22+
* <p>If you don't need to send broadcasts across applications, consider using
23+
* this class with {@link android.support.v4.content.LocalBroadcastManager} instead
24+
* of the more general facilities described below. This will give you a much
25+
* more efficient implementation (no cross-process communication needed) and allow
26+
* you to avoid thinking about any security issues related to other applications
27+
* being able to receive or send your broadcasts.
28+
*
29+
* <p>You can either dynamically register an instance of this class with
30+
* {@link Context#registerReceiver Context.registerReceiver()}
31+
* or statically publish an implementation through the
32+
* {@link android.R.styleable#AndroidManifestReceiver &lt;receiver&gt;}
33+
* tag in your <code>AndroidManifest.xml</code>.
34+
*
35+
* <p><em><strong>Note:</strong></em>
36+
* &nbsp;&nbsp;&nbsp;If registering a receiver in your
37+
* {@link android.app.Activity#onResume() Activity.onResume()}
38+
* implementation, you should unregister it in
39+
* {@link android.app.Activity#onPause() Activity.onPause()}.
40+
* (You won't receive intents when paused,
41+
* and this will cut down on unnecessary system overhead). Do not unregister in
42+
* {@link android.app.Activity#onSaveInstanceState(android.os.Bundle) Activity.onSaveInstanceState()},
43+
* because this won't be called if the user moves back in the history
44+
* stack.
45+
*
46+
* <p>There are two major classes of broadcasts that can be received:</p>
47+
* <ul>
48+
* <li> <b>Normal broadcasts</b> (sent with {@link Context#sendBroadcast(Intent)
49+
* Context.sendBroadcast}) are completely asynchronous. All receivers of the
50+
* broadcast are run in an undefined order, often at the same time. This is
51+
* more efficient, but means that receivers cannot use the result or abort
52+
* APIs included here.
53+
* <li> <b>Ordered broadcasts</b> (sent with {@link Context#sendOrderedBroadcast(Intent, String)
54+
* Context.sendOrderedBroadcast}) are delivered to one receiver at a time.
55+
* As each receiver executes in turn, it can propagate a result to the next
56+
* receiver, or it can completely abort the broadcast so that it won't be passed
57+
* to other receivers. The order receivers run in can be controlled with the
58+
* {@link android.R.styleable#AndroidManifestIntentFilter_priority
59+
* android:priority} attribute of the matching intent-filter; receivers with
60+
* the same priority will be run in an arbitrary order.
61+
* </ul>
62+
*
63+
* <p>Even in the case of normal broadcasts, the system may in some
64+
* situations revert to delivering the broadcast one receiver at a time. In
65+
* particular, for receivers that may require the creation of a process, only
66+
* one will be run at a time to avoid overloading the system with new processes.
67+
* In this situation, however, the non-ordered semantics hold: these receivers still
68+
* cannot return results or abort their broadcast.</p>
69+
*
70+
* <p>Note that, although the Intent class is used for sending and receiving
71+
* these broadcasts, the Intent broadcast mechanism here is completely separate
72+
* from Intents that are used to start Activities with
73+
* {@link Context#startActivity Context.startActivity()}.
74+
* There is no way for a BroadcastReceiver
75+
* to see or capture Intents used with startActivity(); likewise, when
76+
* you broadcast an Intent, you will never find or start an Activity.
77+
* These two operations are semantically very different: starting an
78+
* Activity with an Intent is a foreground operation that modifies what the
79+
* user is currently interacting with; broadcasting an Intent is a background
80+
* operation that the user is not normally aware of.
81+
*
82+
* <p>The BroadcastReceiver class (when launched as a component through
83+
* a manifest's {@link android.R.styleable#AndroidManifestReceiver &lt;receiver&gt;}
84+
* tag) is an important part of an
85+
* <a href="{@docRoot}guide/topics/fundamentals.html#lcycles">application's overall lifecycle</a>.</p>
86+
*
87+
* <p>Topics covered here:
88+
* <ol>
89+
* <li><a href="#Security">Security</a>
90+
* <li><a href="#ReceiverLifecycle">Receiver Lifecycle</a>
91+
* <li><a href="#ProcessLifecycle">Process Lifecycle</a>
92+
* </ol>
93+
*
94+
* <div class="special reference">
95+
* <h3>Developer Guides</h3>
96+
* <p>For information about how to use this class to receive and resolve intents, read the
97+
* <a href="{@docRoot}guide/topics/intents/intents-filters.html">Intents and Intent Filters</a>
98+
* developer guide.</p>
99+
* </div>
100+
*
101+
* <a name="Security"></a>
102+
* <h3>Security</h3>
103+
*
104+
* <p>Receivers used with the {@link Context} APIs are by their nature a
105+
* cross-application facility, so you must consider how other applications
106+
* may be able to abuse your use of them. Some things to consider are:
107+
*
108+
* <ul>
109+
* <li><p>The Intent namespace is global. Make sure that Intent action names and
110+
* other strings are written in a namespace you own, or else you may inadvertantly
111+
* conflict with other applications.
112+
* <li><p>When you use {@link Context#registerReceiver(BroadcastReceiver, IntentFilter)},
113+
* <em>any</em> application may send broadcasts to that registered receiver. You can
114+
* control who can send broadcasts to it through permissions described below.
115+
* <li><p>When you publish a receiver in your application's manifest and specify
116+
* intent-filters for it, any other application can send broadcasts to it regardless
117+
* of the filters you specify. To prevent others from sending to it, make it
118+
* unavailable to them with <code>android:exported="false"</code>.
119+
* <li><p>When you use {@link Context#sendBroadcast(Intent)} or related methods,
120+
* normally any other application can receive these broadcasts. You can control who
121+
* can receive such broadcasts through permissions described below. Alternatively,
122+
* starting with {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, you
123+
* can also safely restrict the broadcast to a single application with
124+
* {@link Intent#setPackage(String) Intent.setPackage}
125+
* </ul>
126+
*
127+
* <p>None of these issues exist when using
128+
* {@link android.support.v4.content.LocalBroadcastManager}, since intents
129+
* broadcast it never go outside of the current process.
130+
*
131+
* <p>Access permissions can be enforced by either the sender or receiver
132+
* of a broadcast.
133+
*
134+
* <p>To enforce a permission when sending, you supply a non-null
135+
* <var>permission</var> argument to
136+
* {@link Context#sendBroadcast(Intent, String)} or
137+
* {@link Context#sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, Bundle)}.
138+
* Only receivers who have been granted this permission
139+
* (by requesting it with the
140+
* {@link android.R.styleable#AndroidManifestUsesPermission &lt;uses-permission&gt;}
141+
* tag in their <code>AndroidManifest.xml</code>) will be able to receive
142+
* the broadcast.
143+
*
144+
* <p>To enforce a permission when receiving, you supply a non-null
145+
* <var>permission</var> when registering your receiver -- either when calling
146+
* {@link Context#registerReceiver(BroadcastReceiver, IntentFilter, String, android.os.Handler)}
147+
* or in the static
148+
* {@link android.R.styleable#AndroidManifestReceiver &lt;receiver&gt;}
149+
* tag in your <code>AndroidManifest.xml</code>. Only broadcasters who have
150+
* been granted this permission (by requesting it with the
151+
* {@link android.R.styleable#AndroidManifestUsesPermission &lt;uses-permission&gt;}
152+
* tag in their <code>AndroidManifest.xml</code>) will be able to send an
153+
* Intent to the receiver.
154+
*
155+
* <p>See the <a href="{@docRoot}guide/topics/security/security.html">Security and Permissions</a>
156+
* document for more information on permissions and security in general.
157+
*
158+
* <a name="ReceiverLifecycle"></a>
159+
* <h3>Receiver Lifecycle</h3>
160+
*
161+
* <p>A BroadcastReceiver object is only valid for the duration of the call
162+
* to {@link #onReceive}. Once your code returns from this function,
163+
* the system considers the object to be finished and no longer active.
164+
*
165+
* <p>This has important repercussions to what you can do in an
166+
* {@link #onReceive} implementation: anything that requires asynchronous
167+
* operation is not available, because you will need to return from the
168+
* function to handle the asynchronous operation, but at that point the
169+
* BroadcastReceiver is no longer active and thus the system is free to kill
170+
* its process before the asynchronous operation completes.
171+
*
172+
* <p>In particular, you may <i>not</i> show a dialog or bind to a service from
173+
* within a BroadcastReceiver. For the former, you should instead use the
174+
* {@link android.app.NotificationManager} API. For the latter, you can
175+
* use {@link android.content.Context#startService Context.startService()} to
176+
* send a command to the service.
177+
*
178+
* <a name="ProcessLifecycle"></a>
179+
* <h3>Process Lifecycle</h3>
180+
*
181+
* <p>A process that is currently executing a BroadcastReceiver (that is,
182+
* currently running the code in its {@link #onReceive} method) is
183+
* considered to be a foreground process and will be kept running by the
184+
* system except under cases of extreme memory pressure.
185+
*
186+
* <p>Once you return from onReceive(), the BroadcastReceiver is no longer
187+
* active, and its hosting process is only as important as any other application
188+
* components that are running in it. This is especially important because if
189+
* that process was only hosting the BroadcastReceiver (a common case for
190+
* applications that the user has never or not recently interacted with), then
191+
* upon returning from onReceive() the system will consider its process
192+
* to be empty and aggressively kill it so that resources are available for other
193+
* more important processes.
194+
*
195+
* <p>This means that for longer-running operations you will often use
196+
* a {@link android.app.Service} in conjunction with a BroadcastReceiver to keep
197+
* the containing process active for the entire time of your operation.
198+
*/
199+
public abstract class BroadcastReceiver {
200+
201+
/**
202+
* State for a result that is pending for a broadcast receiver. Returned
203+
* by {@link BroadcastReceiver#goAsync() goAsync()}
204+
* while in {@link BroadcastReceiver#onReceive BroadcastReceiver.onReceive()}.
205+
* This allows you to return from onReceive() without having the broadcast
206+
* terminate; you must call {@link #finish()} once you are done with the
207+
* broadcast. This allows you to process the broadcast off of the main
208+
* thread of your app.
209+
*
210+
* <p>Note on threading: the state inside of this class is not itself
211+
* thread-safe, however you can use it from any thread if you properly
212+
* sure that you do not have races. Typically this means you will hand
213+
* the entire object to another thread, which will be solely responsible
214+
* for setting any results and finally calling {@link #finish()}.
215+
*/
216+
217+
public BroadcastReceiver() {
218+
}
219+
/**
220+
* This method is called when the BroadcastReceiver is receiving an Intent
221+
* broadcast. During this time you can use the other methods on
222+
* BroadcastReceiver to view/modify the current result values. This method
223+
* is always called within the main thread of its process, unless you
224+
* explicitly asked for it to be scheduled on a different thread using
225+
* {@link android.content.Context#registerReceiver(BroadcastReceiver,
226+
* IntentFilter, String, android.os.Handler)}. When it runs on the main
227+
* thread you should
228+
* never perform long-running operations in it (there is a timeout of
229+
* 10 seconds that the system allows before considering the receiver to
230+
* be blocked and a candidate to be killed). You cannot launch a popup dialog
231+
* in your implementation of onReceive().
232+
*
233+
* <p><b>If this BroadcastReceiver was launched through a &lt;receiver&gt; tag,
234+
* then the object is no longer alive after returning from this
235+
* function.</b> This means you should not perform any operations that
236+
* return a result to you asynchronously -- in particular, for interacting
237+
* with services, you should use
238+
* {@link Context#startService(Intent)} instead of
239+
* {@link Context#bindService(Intent, ServiceConnection, int)}. If you wish
240+
* to interact with a service that is already running, you can use
241+
* {@link #peekService}.
242+
*
243+
* <p>The Intent filters used in {@link android.content.Context#registerReceiver}
244+
* and in application manifests are <em>not</em> guaranteed to be exclusive. They
245+
* are hints to the operating system about how to find suitable recipients. It is
246+
* possible for senders to force delivery to specific recipients, bypassing filter
247+
* resolution. For this reason, {@link #onReceive(Context, Intent) onReceive()}
248+
* implementations should respond only to known actions, ignoring any unexpected
249+
* Intents that they may receive.
250+
*
251+
* @param context The Context in which the receiver is running.
252+
* @param intent The Intent being received.
253+
*/
254+
public abstract void onReceive(Context context, Intent intent);
255+
}

java/ql/test/stubs/google-android-9.0.0/android/content/Context.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,4 +813,51 @@ public boolean canStartActivityForResult() {
813813
* @hide
814814
*/
815815
public abstract void sendBroadcast(Intent intent, String receiverPermission, int appOp);
816+
817+
/**
818+
* Broadcast the given intent to all interested BroadcastReceivers, allowing
819+
* an array of required permissions to be enforced. This call is asynchronous; it returns
820+
* immediately, and you will continue executing while the receivers are run. No results are
821+
* propagated from receivers and receivers can not abort the broadcast. If you want to allow
822+
* receivers to propagate results or abort the broadcast, you must send an ordered broadcast
823+
* using {@link #sendOrderedBroadcast(Intent, String)}.
824+
*
825+
* <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
826+
*
827+
* @param intent The Intent to broadcast; all receivers matching this
828+
* Intent will receive the broadcast.
829+
* @param receiverPermissions Array of names of permissions that a receiver must hold
830+
* in order to receive your broadcast.
831+
* If empty, no permissions are required.
832+
*
833+
* @see android.content.BroadcastReceiver
834+
* @see #registerReceiver
835+
* @see #sendBroadcast(Intent)
836+
* @see #sendOrderedBroadcast(Intent, String)
837+
* @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
838+
* @hide
839+
*/
840+
public abstract void sendBroadcastWithMultiplePermissions (Intent intent, String[] receiverPermissions);
841+
842+
/**
843+
* Broadcast the given intent to all interested BroadcastReceivers, delivering
844+
* them one at a time to allow more preferred receivers to consume the
845+
* broadcast before it is delivered to less preferred receivers. This
846+
* call is asynchronous; it returns immediately, and you will continue
847+
* executing while the receivers are run.
848+
*
849+
* <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
850+
*
851+
* @param intent The Intent to broadcast; all receivers matching this
852+
* Intent will receive the broadcast.
853+
* @param receiverPermission (optional) String naming a permissions that
854+
* a receiver must hold in order to receive your broadcast.
855+
* If null, no permission is required.
856+
*
857+
* @see android.content.BroadcastReceiver
858+
* @see #registerReceiver
859+
* @see #sendBroadcast(Intent)
860+
* @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
861+
*/
862+
public abstract void sendOrderedBroadcast(Intent intent, String receiverPermission);
816863
}

java/ql/test/stubs/google-android-9.0.0/android/content/Intent.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,4 +1996,77 @@ public void writeToParcel(Parcel out, int flags) {
19961996

19971997
public void readFromParcel(Parcel in) {
19981998
}
1999+
2000+
/**
2001+
* Retrieve the application package name this Intent is limited to. When
2002+
* resolving an Intent, if non-null this limits the resolution to only
2003+
* components in the given application package.
2004+
*
2005+
* @return The name of the application package for the Intent.
2006+
*
2007+
* @see #resolveActivity
2008+
* @see #setPackage
2009+
*/
2010+
public String getPackage() {
2011+
return null;
2012+
}
2013+
2014+
/**
2015+
* (Usually optional) Set an explicit application package name that limits
2016+
* the components this Intent will resolve to. If left to the default
2017+
* value of null, all components in all applications will considered.
2018+
* If non-null, the Intent can only match the components in the given
2019+
* application package.
2020+
*
2021+
* @param packageName The name of the application package to handle the
2022+
* intent, or null to allow any application package.
2023+
*
2024+
* @return Returns the same Intent object, for chaining multiple calls
2025+
* into a single statement.
2026+
*
2027+
* @see #getPackage
2028+
* @see #resolveActivity
2029+
*/
2030+
public Intent setPackage(String packageName) {
2031+
return null;
2032+
}
2033+
2034+
/**
2035+
* Convenience for calling {@link #setComponent} with an
2036+
* explicit class name.
2037+
*
2038+
* @param packageContext A Context of the application package implementing
2039+
* this class.
2040+
* @param className The name of a class inside of the application package
2041+
* that will be used as the component for this Intent.
2042+
*
2043+
* @return Returns the same Intent object, for chaining multiple calls
2044+
* into a single statement.
2045+
*
2046+
* @see #setComponent
2047+
* @see #setClass
2048+
*/
2049+
public Intent setClassName(Context packageContext, String className) {
2050+
return null;
2051+
}
2052+
2053+
/**
2054+
* Convenience for calling {@link #setComponent} with an
2055+
* explicit application package name and class name.
2056+
*
2057+
* @param packageName The name of the package implementing the desired
2058+
* component.
2059+
* @param className The name of a class inside of the application package
2060+
* that will be used as the component for this Intent.
2061+
*
2062+
* @return Returns the same Intent object, for chaining multiple calls
2063+
* into a single statement.
2064+
*
2065+
* @see #setComponent
2066+
* @see #setClass
2067+
*/
2068+
public Intent setClassName(String packageName, String className) {
2069+
return null;
2070+
}
2071+
19992072
}

0 commit comments

Comments
 (0)