Skip to content

Commit 5379158

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "More mult-user API work." into jb-mr1-dev
2 parents ec0feef + 7d19e02 commit 5379158

File tree

25 files changed

+531
-163
lines changed

25 files changed

+531
-163
lines changed

api/current.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5075,6 +5075,7 @@ package android.content {
50755075
public class ContentProviderClient {
50765076
method public android.content.ContentProviderResult[] applyBatch(java.util.ArrayList<android.content.ContentProviderOperation>) throws android.content.OperationApplicationException, android.os.RemoteException;
50775077
method public int bulkInsert(android.net.Uri, android.content.ContentValues[]) throws android.os.RemoteException;
5078+
method public android.os.Bundle call(java.lang.String, java.lang.String, android.os.Bundle) throws android.os.RemoteException;
50785079
method public int delete(android.net.Uri, java.lang.String, java.lang.String[]) throws android.os.RemoteException;
50795080
method public android.content.ContentProvider getLocalContentProvider();
50805081
method public java.lang.String[] getStreamTypes(android.net.Uri, java.lang.String) throws android.os.RemoteException;
@@ -5319,9 +5320,10 @@ package android.content {
53195320
method public abstract void revokeUriPermission(android.net.Uri, int);
53205321
method public abstract void sendBroadcast(android.content.Intent);
53215322
method public abstract void sendBroadcast(android.content.Intent, java.lang.String);
5322-
method public void sendBroadcastToUser(android.content.Intent, int);
5323+
method public abstract void sendBroadcastToUser(android.content.Intent, int);
53235324
method public abstract void sendOrderedBroadcast(android.content.Intent, java.lang.String);
53245325
method public abstract void sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
5326+
method public abstract void sendOrderedBroadcastToUser(android.content.Intent, int, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
53255327
method public abstract void sendStickyBroadcast(android.content.Intent);
53265328
method public abstract void sendStickyOrderedBroadcast(android.content.Intent, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
53275329
method public abstract void setTheme(int);
@@ -5453,8 +5455,10 @@ package android.content {
54535455
method public void revokeUriPermission(android.net.Uri, int);
54545456
method public void sendBroadcast(android.content.Intent);
54555457
method public void sendBroadcast(android.content.Intent, java.lang.String);
5458+
method public void sendBroadcastToUser(android.content.Intent, int);
54565459
method public void sendOrderedBroadcast(android.content.Intent, java.lang.String);
54575460
method public void sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
5461+
method public void sendOrderedBroadcastToUser(android.content.Intent, int, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
54585462
method public void sendStickyBroadcast(android.content.Intent);
54595463
method public void sendStickyOrderedBroadcast(android.content.Intent, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
54605464
method public void setTheme(int);
@@ -6235,6 +6239,7 @@ package android.content.pm {
62356239
field public static final int FLAG_HARDWARE_ACCELERATED = 512; // 0x200
62366240
field public static final int FLAG_MULTIPROCESS = 1; // 0x1
62376241
field public static final int FLAG_NO_HISTORY = 128; // 0x80
6242+
field public static final int FLAG_SINGLE_USER = 1073741824; // 0x40000000
62386243
field public static final int FLAG_STATE_NOT_NEEDED = 16; // 0x10
62396244
field public static final int LAUNCH_MULTIPLE = 0; // 0x0
62406245
field public static final int LAUNCH_SINGLE_INSTANCE = 3; // 0x3
@@ -6657,7 +6662,9 @@ package android.content.pm {
66576662
ctor public ProviderInfo(android.content.pm.ProviderInfo);
66586663
method public int describeContents();
66596664
field public static final android.os.Parcelable.Creator CREATOR;
6665+
field public static final int FLAG_SINGLE_USER = 1073741824; // 0x40000000
66606666
field public java.lang.String authority;
6667+
field public int flags;
66616668
field public boolean grantUriPermissions;
66626669
field public int initOrder;
66636670
field public deprecated boolean isSyncable;
@@ -6703,7 +6710,7 @@ package android.content.pm {
67036710
method public void dump(android.util.Printer, java.lang.String);
67046711
field public static final android.os.Parcelable.Creator CREATOR;
67056712
field public static final int FLAG_ISOLATED_PROCESS = 2; // 0x2
6706-
field public static final int FLAG_SINGLE_USER = 4; // 0x4
6713+
field public static final int FLAG_SINGLE_USER = 1073741824; // 0x40000000
67076714
field public static final int FLAG_STOP_WITH_TASK = 1; // 0x1
67086715
field public int flags;
67096716
field public java.lang.String permission;
@@ -16248,6 +16255,7 @@ package android.os {
1624816255
method public static final int myPid();
1624916256
method public static final int myTid();
1625016257
method public static final int myUid();
16258+
method public static final int myUserHandle();
1625116259
method public static final void sendSignal(int, int);
1625216260
method public static final void setThreadPriority(int, int) throws java.lang.IllegalArgumentException, java.lang.SecurityException;
1625316261
method public static final void setThreadPriority(int) throws java.lang.IllegalArgumentException, java.lang.SecurityException;
@@ -21143,8 +21151,10 @@ package android.test.mock {
2114321151
method public void revokeUriPermission(android.net.Uri, int);
2114421152
method public void sendBroadcast(android.content.Intent);
2114521153
method public void sendBroadcast(android.content.Intent, java.lang.String);
21154+
method public void sendBroadcastToUser(android.content.Intent, int);
2114621155
method public void sendOrderedBroadcast(android.content.Intent, java.lang.String);
2114721156
method public void sendOrderedBroadcast(android.content.Intent, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
21157+
method public void sendOrderedBroadcastToUser(android.content.Intent, int, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
2114821158
method public void sendStickyBroadcast(android.content.Intent);
2114921159
method public void sendStickyOrderedBroadcast(android.content.Intent, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle);
2115021160
method public void setTheme(int);

core/java/android/app/ActivityManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,18 @@ public static int checkComponentPermission(String permission, int uid,
18401840
return PackageManager.PERMISSION_DENIED;
18411841
}
18421842

1843+
/** @hide */
1844+
public static int checkUidPermission(String permission, int uid) {
1845+
try {
1846+
return AppGlobals.getPackageManager()
1847+
.checkUidPermission(permission, uid);
1848+
} catch (RemoteException e) {
1849+
// Should never happen, but if it does... deny!
1850+
Slog.e(TAG, "PackageManager is dead?!?", e);
1851+
}
1852+
return PackageManager.PERMISSION_DENIED;
1853+
}
1854+
18431855
/**
18441856
* Returns the usage statistics of each installed package.
18451857
*

core/java/android/app/ContextImpl.java

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -966,18 +966,6 @@ public void sendBroadcast(Intent intent) {
966966
}
967967
}
968968

969-
@Override
970-
public void sendBroadcastToUser(Intent intent, int userId) {
971-
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
972-
try {
973-
intent.setAllowFds(false);
974-
ActivityManagerNative.getDefault().broadcastIntent(mMainThread.getApplicationThread(),
975-
intent, resolvedType, null, Activity.RESULT_OK, null, null, null, false, false,
976-
userId);
977-
} catch (RemoteException e) {
978-
}
979-
}
980-
981969
@Override
982970
public void sendBroadcast(Intent intent, String receiverPermission) {
983971
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
@@ -1038,6 +1026,50 @@ resultReceiver, getOuterContext(), scheduler,
10381026
}
10391027
}
10401028

1029+
@Override
1030+
public void sendBroadcastToUser(Intent intent, int userHandle) {
1031+
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
1032+
try {
1033+
intent.setAllowFds(false);
1034+
ActivityManagerNative.getDefault().broadcastIntent(mMainThread.getApplicationThread(),
1035+
intent, resolvedType, null, Activity.RESULT_OK, null, null, null, false, false,
1036+
userHandle);
1037+
} catch (RemoteException e) {
1038+
}
1039+
}
1040+
1041+
@Override
1042+
public void sendOrderedBroadcastToUser(Intent intent, int userHandle,
1043+
BroadcastReceiver resultReceiver, Handler scheduler,
1044+
int initialCode, String initialData, Bundle initialExtras) {
1045+
IIntentReceiver rd = null;
1046+
if (resultReceiver != null) {
1047+
if (mPackageInfo != null) {
1048+
if (scheduler == null) {
1049+
scheduler = mMainThread.getHandler();
1050+
}
1051+
rd = mPackageInfo.getReceiverDispatcher(
1052+
resultReceiver, getOuterContext(), scheduler,
1053+
mMainThread.getInstrumentation(), false);
1054+
} else {
1055+
if (scheduler == null) {
1056+
scheduler = mMainThread.getHandler();
1057+
}
1058+
rd = new LoadedApk.ReceiverDispatcher(
1059+
resultReceiver, getOuterContext(), scheduler, null, false).getIIntentReceiver();
1060+
}
1061+
}
1062+
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
1063+
try {
1064+
intent.setAllowFds(false);
1065+
ActivityManagerNative.getDefault().broadcastIntent(
1066+
mMainThread.getApplicationThread(), intent, resolvedType, rd,
1067+
initialCode, initialData, initialExtras, null,
1068+
true, false, userHandle);
1069+
} catch (RemoteException e) {
1070+
}
1071+
}
1072+
10411073
@Override
10421074
public void sendStickyBroadcast(Intent intent) {
10431075
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
@@ -1197,7 +1229,7 @@ public boolean bindService(Intent service, ServiceConnection conn,
11971229

11981230
/** @hide */
11991231
@Override
1200-
public boolean bindService(Intent service, ServiceConnection conn, int flags, int userId) {
1232+
public boolean bindService(Intent service, ServiceConnection conn, int flags, int userHandle) {
12011233
IServiceConnection sd;
12021234
if (conn == null) {
12031235
throw new IllegalArgumentException("connection is null");
@@ -1219,7 +1251,7 @@ public boolean bindService(Intent service, ServiceConnection conn, int flags, in
12191251
int res = ActivityManagerNative.getDefault().bindService(
12201252
mMainThread.getApplicationThread(), getActivityToken(),
12211253
service, service.resolveTypeIfNeeded(getContentResolver()),
1222-
sd, flags, userId);
1254+
sd, flags, userHandle);
12231255
if (res < 0) {
12241256
throw new SecurityException(
12251257
"Not allowed to bind to service " + service);

core/java/android/content/ContentProviderClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,19 @@ public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> op
231231
}
232232
}
233233

234+
/** See {@link ContentProvider#call(String, String, Bundle)} */
235+
public Bundle call(String method, String arg, Bundle extras)
236+
throws RemoteException {
237+
try {
238+
return mContentProvider.call(method, arg, extras);
239+
} catch (DeadObjectException e) {
240+
if (!mStable) {
241+
mContentResolver.unstableProviderDied(mContentProvider);
242+
}
243+
throw e;
244+
}
245+
}
246+
234247
/**
235248
* Call this to indicate to the system that the associated {@link ContentProvider} is no
236249
* longer needed by this {@link ContentProviderClient}.

core/java/android/content/Context.java

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -987,18 +987,6 @@ public abstract void startIntentSender(IntentSender intent,
987987
*/
988988
public abstract void sendBroadcast(Intent intent);
989989

990-
/**
991-
* Same as #sendBroadcast(Intent intent), but for a specific user. This broadcast
992-
* can only be sent to receivers that are part of the calling application. It
993-
* requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
994-
* permission.
995-
* @param intent the intent to broadcast
996-
* @param userId user to send the intent to
997-
*/
998-
public void sendBroadcastToUser(Intent intent, int userId) {
999-
throw new RuntimeException("Not implemented. Must override in a subclass.");
1000-
}
1001-
1002990
/**
1003991
* Broadcast the given intent to all interested BroadcastReceivers, allowing
1004992
* an optional required permission to be enforced. This
@@ -1096,6 +1084,48 @@ public abstract void sendOrderedBroadcast(Intent intent,
10961084
Handler scheduler, int initialCode, String initialData,
10971085
Bundle initialExtras);
10981086

1087+
/**
1088+
* Same as {@link #sendBroadcast(Intent)}, but for a specific user. This broadcast
1089+
* can only be sent to receivers that are part of the calling application. It
1090+
* requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
1091+
* permission.
1092+
* @param intent The intent to broadcast
1093+
* @param userHandle User to send the intent to.
1094+
* @see #sendBroadcast(Intent)
1095+
*/
1096+
public abstract void sendBroadcastToUser(Intent intent, int userHandle);
1097+
1098+
/**
1099+
* Same as
1100+
* {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)},
1101+
* but for a specific user. This broadcast
1102+
* can only be sent to receivers that are part of the calling application. It
1103+
* requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
1104+
* permission.
1105+
*
1106+
* <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1107+
*
1108+
* @param intent The Intent to broadcast; all receivers matching this
1109+
* Intent will receive the broadcast.
1110+
* @param userHandle User to send the intent to.
1111+
* @param resultReceiver Your own BroadcastReceiver to treat as the final
1112+
* receiver of the broadcast.
1113+
* @param scheduler A custom Handler with which to schedule the
1114+
* resultReceiver callback; if null it will be
1115+
* scheduled in the Context's main thread.
1116+
* @param initialCode An initial value for the result code. Often
1117+
* Activity.RESULT_OK.
1118+
* @param initialData An initial value for the result data. Often
1119+
* null.
1120+
* @param initialExtras An initial value for the result extras. Often
1121+
* null.
1122+
*
1123+
* @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1124+
*/
1125+
public abstract void sendOrderedBroadcastToUser(Intent intent, int userHandle,
1126+
BroadcastReceiver resultReceiver, Handler scheduler,
1127+
int initialCode, String initialData, Bundle initialExtras);
1128+
10991129
/**
11001130
* Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
11011131
* Intent you are sending stays around after the broadcast is complete,
@@ -1403,11 +1433,11 @@ public abstract boolean bindService(Intent service, ServiceConnection conn,
14031433
int flags);
14041434

14051435
/**
1406-
* Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userId
1436+
* Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
14071437
* argument for use by system server and other multi-user aware code.
14081438
* @hide
14091439
*/
1410-
public boolean bindService(Intent service, ServiceConnection conn, int flags, int userId) {
1440+
public boolean bindService(Intent service, ServiceConnection conn, int flags, int userHandle) {
14111441
throw new RuntimeException("Not implemented. Must override in a subclass.");
14121442
}
14131443

core/java/android/content/ContextWrapper.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,6 @@ public void sendBroadcast(Intent intent) {
312312
mBase.sendBroadcast(intent);
313313
}
314314

315-
@Override
316-
public void sendBroadcastToUser(Intent intent, int userId) {
317-
mBase.sendBroadcastToUser(intent, userId);
318-
}
319-
320315
@Override
321316
public void sendBroadcast(Intent intent, String receiverPermission) {
322317
mBase.sendBroadcast(intent, receiverPermission);
@@ -338,6 +333,19 @@ public void sendOrderedBroadcast(
338333
initialData, initialExtras);
339334
}
340335

336+
@Override
337+
public void sendBroadcastToUser(Intent intent, int userHandle) {
338+
mBase.sendBroadcastToUser(intent, userHandle);
339+
}
340+
341+
@Override
342+
public void sendOrderedBroadcastToUser(Intent intent, int userHandle,
343+
BroadcastReceiver resultReceiver, Handler scheduler,
344+
int initialCode, String initialData, Bundle initialExtras) {
345+
mBase.sendOrderedBroadcastToUser(intent, userHandle, resultReceiver,
346+
scheduler, initialCode, initialData, initialExtras);
347+
}
348+
341349
@Override
342350
public void sendStickyBroadcast(Intent intent) {
343351
mBase.sendStickyBroadcast(intent);
@@ -395,8 +403,8 @@ public boolean bindService(Intent service, ServiceConnection conn,
395403

396404
/** @hide */
397405
@Override
398-
public boolean bindService(Intent service, ServiceConnection conn, int flags, int userId) {
399-
return mBase.bindService(service, conn, flags, userId);
406+
public boolean bindService(Intent service, ServiceConnection conn, int flags, int userHandle) {
407+
return mBase.bindService(service, conn, flags, userHandle);
400408
}
401409

402410
@Override

core/java/android/content/pm/ActivityInfo.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ public class ActivityInfo extends ComponentInfo
171171
* {@see android.app.Notification#FLAG_HIGH_PRIORITY}
172172
*/
173173
public static final int FLAG_IMMERSIVE = 0x0400;
174+
/**
175+
* Bit in {@link #flags}: If set, a single instance of the receiver will
176+
* run for all users on the device. Set from the
177+
* {@link android.R.attr#singleUser} attribute. Note that this flag is
178+
* only relevent for ActivityInfo structures that are describiner receiver
179+
* components; it is not applied to activities.
180+
*/
181+
public static final int FLAG_SINGLE_USER = 0x40000000;
174182
/**
175183
* Options that have been set in the activity declaration in the
176184
* manifest.
@@ -181,7 +189,7 @@ public class ActivityInfo extends ComponentInfo
181189
* {@link #FLAG_STATE_NOT_NEEDED}, {@link #FLAG_EXCLUDE_FROM_RECENTS},
182190
* {@link #FLAG_ALLOW_TASK_REPARENTING}, {@link #FLAG_NO_HISTORY},
183191
* {@link #FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS},
184-
* {@link #FLAG_HARDWARE_ACCELERATED}
192+
* {@link #FLAG_HARDWARE_ACCELERATED}, {@link #FLAG_SINGLE_USER}.
185193
*/
186194
public int flags;
187195

0 commit comments

Comments
 (0)