Merge "Revert "Clean up hiden notifications on Keyguard handling"" into lmp-dev
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index a94bc41..860512b 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/java/android/bluetooth/BluetoothDevice.java
@@ -760,7 +760,38 @@
return false;
}
try {
- return sService.createBond(this);
+ return sService.createBond(this, TRANSPORT_AUTO);
+ } catch (RemoteException e) {Log.e(TAG, "", e);}
+ return false;
+ }
+
+ /**
+ * Start the bonding (pairing) process with the remote device using the
+ * specified transport.
+ *
+ * <p>This is an asynchronous call, it will return immediately. Register
+ * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
+ * the bonding process completes, and its result.
+ * <p>Android system services will handle the necessary user interactions
+ * to confirm and complete the bonding process.
+ * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
+ *
+ * @param transport The transport to use for the pairing procedure.
+ * @return false on immediate error, true if bonding will begin
+ * @throws IllegalArgumentException if an invalid transport was specified
+ * @hide
+ */
+ public boolean createBond(int transport) {
+ if (sService == null) {
+ Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
+ return false;
+ }
+ if (TRANSPORT_AUTO > transport || transport > TRANSPORT_LE)
+ {
+ throw new IllegalArgumentException(transport + " is not a valid Bluetooth transport");
+ }
+ try {
+ return sService.createBond(this, transport);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
diff --git a/core/java/android/bluetooth/IBluetooth.aidl b/core/java/android/bluetooth/IBluetooth.aidl
index ca55803..19c600c 100644
--- a/core/java/android/bluetooth/IBluetooth.aidl
+++ b/core/java/android/bluetooth/IBluetooth.aidl
@@ -55,7 +55,7 @@
int getProfileConnectionState(int profile);
BluetoothDevice[] getBondedDevices();
- boolean createBond(in BluetoothDevice device);
+ boolean createBond(in BluetoothDevice device, in int transport);
boolean cancelBondProcess(in BluetoothDevice device);
boolean removeBond(in BluetoothDevice device);
int getBondState(in BluetoothDevice device);
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index be9782f..5f6fb6e 100644
--- a/core/java/android/content/ContentProvider.java
+++ b/core/java/android/content/ContentProvider.java
@@ -17,6 +17,7 @@
package android.content;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
+import static android.Manifest.permission.INTERACT_ACROSS_USERS;
import android.app.AppOpsManager;
import android.content.pm.PathPermission;
@@ -192,11 +193,12 @@
public Cursor query(String callingPkg, Uri uri, String[] projection,
String selection, String[] selectionArgs, String sortOrder,
ICancellationSignal cancellationSignal) {
+ getAndEnforceUserId(uri);
+ uri = getUriWithoutUserId(uri);
if (enforceReadPermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
return rejectQuery(uri, projection, selection, selectionArgs, sortOrder,
CancellationSignal.fromTransport(cancellationSignal));
}
- uri = getUriWithoutUserId(uri);
final String original = setCallingPackage(callingPkg);
try {
return ContentProvider.this.query(
@@ -209,17 +211,18 @@
@Override
public String getType(Uri uri) {
+ getAndEnforceUserId(uri);
uri = getUriWithoutUserId(uri);
return ContentProvider.this.getType(uri);
}
@Override
public Uri insert(String callingPkg, Uri uri, ContentValues initialValues) {
+ int userId = getAndEnforceUserId(uri);
+ uri = getUriWithoutUserId(uri);
if (enforceWritePermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
return rejectInsert(uri, initialValues);
}
- int userId = getUserIdFromUri(uri);
- uri = getUriWithoutUserId(uri);
final String original = setCallingPackage(callingPkg);
try {
return maybeAddUserId(ContentProvider.this.insert(uri, initialValues), userId);
@@ -230,10 +233,11 @@
@Override
public int bulkInsert(String callingPkg, Uri uri, ContentValues[] initialValues) {
+ getAndEnforceUserId(uri);
+ uri = getUriWithoutUserId(uri);
if (enforceWritePermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
return 0;
}
- uri = getUriWithoutUserId(uri);
final String original = setCallingPackage(callingPkg);
try {
return ContentProvider.this.bulkInsert(uri, initialValues);
@@ -250,7 +254,12 @@
final int[] userIds = new int[numOperations];
for (int i = 0; i < numOperations; i++) {
ContentProviderOperation operation = operations.get(i);
- userIds[i] = getUserIdFromUri(operation.getUri());
+ userIds[i] = getAndEnforceUserId(operation.getUri());
+ if (userIds[i] != UserHandle.USER_CURRENT) {
+ // Removing the user id from the uri.
+ operation = new ContentProviderOperation(operation, true);
+ operations.set(i, operation);
+ }
if (operation.isReadOperation()) {
if (enforceReadPermission(callingPkg, operation.getUri())
!= AppOpsManager.MODE_ALLOWED) {
@@ -263,11 +272,6 @@
throw new OperationApplicationException("App op not allowed", 0);
}
}
- if (userIds[i] != UserHandle.USER_CURRENT) {
- // Removing the user id from the uri.
- operation = new ContentProviderOperation(operation, true);
- }
- operations.set(i, operation);
}
final String original = setCallingPackage(callingPkg);
try {
@@ -286,10 +290,11 @@
@Override
public int delete(String callingPkg, Uri uri, String selection, String[] selectionArgs) {
+ getAndEnforceUserId(uri);
+ uri = getUriWithoutUserId(uri);
if (enforceWritePermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
return 0;
}
- uri = getUriWithoutUserId(uri);
final String original = setCallingPackage(callingPkg);
try {
return ContentProvider.this.delete(uri, selection, selectionArgs);
@@ -301,10 +306,11 @@
@Override
public int update(String callingPkg, Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
+ getAndEnforceUserId(uri);
+ uri = getUriWithoutUserId(uri);
if (enforceWritePermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
return 0;
}
- uri = getUriWithoutUserId(uri);
final String original = setCallingPackage(callingPkg);
try {
return ContentProvider.this.update(uri, values, selection, selectionArgs);
@@ -317,8 +323,9 @@
public ParcelFileDescriptor openFile(
String callingPkg, Uri uri, String mode, ICancellationSignal cancellationSignal)
throws FileNotFoundException {
- enforceFilePermission(callingPkg, uri, mode);
+ getAndEnforceUserId(uri);
uri = getUriWithoutUserId(uri);
+ enforceFilePermission(callingPkg, uri, mode);
final String original = setCallingPackage(callingPkg);
try {
return ContentProvider.this.openFile(
@@ -332,8 +339,9 @@
public AssetFileDescriptor openAssetFile(
String callingPkg, Uri uri, String mode, ICancellationSignal cancellationSignal)
throws FileNotFoundException {
- enforceFilePermission(callingPkg, uri, mode);
+ getAndEnforceUserId(uri);
uri = getUriWithoutUserId(uri);
+ enforceFilePermission(callingPkg, uri, mode);
final String original = setCallingPackage(callingPkg);
try {
return ContentProvider.this.openAssetFile(
@@ -355,6 +363,7 @@
@Override
public String[] getStreamTypes(Uri uri, String mimeTypeFilter) {
+ getAndEnforceUserId(uri);
uri = getUriWithoutUserId(uri);
return ContentProvider.this.getStreamTypes(uri, mimeTypeFilter);
}
@@ -362,8 +371,9 @@
@Override
public AssetFileDescriptor openTypedAssetFile(String callingPkg, Uri uri, String mimeType,
Bundle opts, ICancellationSignal cancellationSignal) throws FileNotFoundException {
- enforceFilePermission(callingPkg, uri, "r");
+ getAndEnforceUserId(uri);
uri = getUriWithoutUserId(uri);
+ enforceFilePermission(callingPkg, uri, "r");
final String original = setCallingPackage(callingPkg);
try {
return ContentProvider.this.openTypedAssetFile(
@@ -380,11 +390,11 @@
@Override
public Uri canonicalize(String callingPkg, Uri uri) {
+ int userId = getAndEnforceUserId(uri);
+ uri = getUriWithoutUserId(uri);
if (enforceReadPermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
return null;
}
- int userId = getUserIdFromUri(uri);
- uri = getUriWithoutUserId(uri);
final String original = setCallingPackage(callingPkg);
try {
return maybeAddUserId(ContentProvider.this.canonicalize(uri), userId);
@@ -395,11 +405,11 @@
@Override
public Uri uncanonicalize(String callingPkg, Uri uri) {
+ int userId = getAndEnforceUserId(uri);
+ uri = getUriWithoutUserId(uri);
if (enforceReadPermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
return null;
}
- int userId = getUserIdFromUri(uri);
- uri = getUriWithoutUserId(uri);
final String original = setCallingPackage(callingPkg);
try {
return maybeAddUserId(ContentProvider.this.uncanonicalize(uri), userId);
@@ -438,6 +448,12 @@
}
}
+ boolean checkUser(int pid, int uid, Context context) {
+ return UserHandle.getUserId(uid) == context.getUserId()
+ || context.checkPermission(INTERACT_ACROSS_USERS, pid, uid)
+ == PERMISSION_GRANTED;
+ }
+
/** {@hide} */
protected void enforceReadPermissionInner(Uri uri) throws SecurityException {
final Context context = getContext();
@@ -449,7 +465,7 @@
return;
}
- if (mExported) {
+ if (mExported && checkUser(pid, uid, context)) {
final String componentPerm = getReadPermission();
if (componentPerm != null) {
if (context.checkPermission(componentPerm, pid, uid) == PERMISSION_GRANTED) {
@@ -511,7 +527,7 @@
return;
}
- if (mExported) {
+ if (mExported && checkUser(pid, uid, context)) {
final String componentPerm = getWritePermission();
if (componentPerm != null) {
if (context.checkPermission(componentPerm, pid, uid) == PERMISSION_GRANTED) {
@@ -1711,11 +1727,20 @@
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
writer.println("nothing to dump");
}
+ /** @hide */
+ private int getAndEnforceUserId(Uri uri) {
+ int userId = getUserIdFromUri(uri, UserHandle.USER_CURRENT);
+ if (userId != UserHandle.USER_CURRENT && userId != mContext.getUserId()) {
+ throw new SecurityException("trying to query a ContentProvider in user "
+ + mContext.getUserId() + "with a uri belonging to user " + userId);
+ }
+ return userId;
+ }
/** @hide */
public static int getUserIdFromAuthority(String auth, int defaultUserId) {
if (auth == null) return defaultUserId;
- int end = auth.indexOf('@');
+ int end = auth.lastIndexOf('@');
if (end == -1) return defaultUserId;
String userIdString = auth.substring(0, end);
try {
@@ -1750,7 +1775,7 @@
*/
public static String getAuthorityWithoutUserId(String auth) {
if (auth == null) return null;
- int end = auth.indexOf('@');
+ int end = auth.lastIndexOf('@');
return auth.substring(end+1);
}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 275185a..29fd984 100755
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -6325,7 +6325,10 @@
if (DEBUG_URI_PERMISSION) Slog.v(TAG,
"checkHoldingPermissionsLocked: uri=" + grantUri + " uid=" + uid);
if (UserHandle.getUserId(uid) != grantUri.sourceUserId) {
- return false;
+ if (ActivityManager.checkComponentPermission(INTERACT_ACROSS_USERS, uid, -1, true)
+ != PERMISSION_GRANTED) {
+ return false;
+ }
}
return checkHoldingPermissionsInternalLocked(pm, pi, grantUri, uid, modeFlags, true);
}
diff --git a/services/print/java/com/android/server/print/PrintManagerService.java b/services/print/java/com/android/server/print/PrintManagerService.java
index 0575a5e9..7400dde 100644
--- a/services/print/java/com/android/server/print/PrintManagerService.java
+++ b/services/print/java/com/android/server/print/PrintManagerService.java
@@ -734,7 +734,7 @@
}
if (mContext.checkCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL)
!= PackageManager.PERMISSION_GRANTED
- || mContext.checkCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS)
+ && mContext.checkCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS)
!= PackageManager.PERMISSION_GRANTED) {
if (userId == UserHandle.USER_CURRENT_OR_SELF) {
return callingUserId;
@@ -746,8 +746,7 @@
if (userId == UserHandle.USER_CURRENT || userId == UserHandle.USER_CURRENT_OR_SELF) {
return mCurrentUserId;
}
- throw new IllegalArgumentException("Calling user can be changed to only "
- + "UserHandle.USER_CURRENT or UserHandle.USER_CURRENT_OR_SELF.");
+ return userId;
}
private String resolveCallingPackageNameEnforcingSecurity(String packageName) {