Loading android/app/src/com/android/bluetooth/Utils.java +68 −21 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.Manifest; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.app.AppGlobals; import android.app.AppOpsManager; import android.app.BroadcastOptions; import android.bluetooth.BluetoothAdapter; Loading @@ -53,12 +54,15 @@ import android.os.Bundle; import android.os.ParcelUuid; import android.os.PowerExemptionManager; import android.os.Process; import android.os.RemoteException; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; import android.provider.Telephony; import android.util.Log; import com.android.bluetooth.btservice.ProfileService; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; Loading Loading @@ -406,6 +410,20 @@ public final class Utils { "Need DUMP permission"); } public static AttributionSource getCallingAttributionSource() { int callingUid = Binder.getCallingUid(); if (callingUid == android.os.Process.ROOT_UID) { callingUid = android.os.Process.SYSTEM_UID; } try { return new AttributionSource(callingUid, AppGlobals.getPackageManager().getPackagesForUid(callingUid)[0], null); } catch (RemoteException e) { throw new IllegalStateException("Failed to resolve AttributionSource", e); } } @SuppressLint("AndroidFrameworkRequiresPermission") private static boolean checkPermissionForPreflight(Context context, String permission) { final int result = PermissionChecker.checkCallingOrSelfPermissionForPreflight( context, permission); Loading @@ -422,6 +440,7 @@ public final class Utils { } } @SuppressLint("AndroidFrameworkRequiresPermission") private static boolean checkPermissionForDataDelivery(Context context, String permission, AttributionSource attributionSource, String message) { final int result = PermissionChecker.checkPermissionForDataDeliveryFromDataSource( Loading @@ -448,6 +467,7 @@ public final class Utils { * * <p>Should be used in situations where the app op should not be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static boolean checkConnectPermissionForPreflight(Context context) { return checkPermissionForPreflight(context, BLUETOOTH_CONNECT); Loading @@ -461,6 +481,7 @@ public final class Utils { * <p>Should be used in situations where data will be delivered and hence the app op should * be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static boolean checkConnectPermissionForDataDelivery( Context context, AttributionSource attributionSource, String message) { Loading @@ -474,6 +495,7 @@ public final class Utils { * * <p>Should be used in situations where the app op should not be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN) public static boolean checkScanPermissionForPreflight(Context context) { return checkPermissionForPreflight(context, BLUETOOTH_SCAN); Loading @@ -486,6 +508,7 @@ public final class Utils { * <p>Should be used in situations where data will be delivered and hence the app op should * be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN) public static boolean checkScanPermissionForDataDelivery( Context context, AttributionSource attributionSource, String message) { Loading @@ -500,6 +523,7 @@ public final class Utils { * <p> * Should be used in situations where the app op should not be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADVERTISE) public static boolean checkAdvertisePermissionForPreflight(Context context) { return checkPermissionForPreflight(context, BLUETOOTH_ADVERTISE); Loading @@ -513,6 +537,7 @@ public final class Utils { * Should be used in situations where data will be delivered and hence the * app op should be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADVERTISE) public static boolean checkAdvertisePermissionForDataDelivery( Context context, AttributionSource attributionSource, String message) { Loading Loading @@ -553,23 +578,7 @@ public final class Utils { return false; } public static boolean callerIsSystemOrActiveUser(String tag, String method) { if (!checkCaller()) { Log.w(TAG, method + "() - Not allowed for non-active user and non-system user"); return false; } return true; } public static boolean callerIsSystemOrActiveOrManagedUser(Context context, String tag, String method) { if (!checkCallerAllowManagedProfiles(context)) { Log.w(TAG, method + "() - Not allowed for non-active user and non-system and non-managed user"); return false; } return true; } public static boolean checkCaller() { public static boolean checkCallerIsSystemOrActiveUser() { int callingUser = UserHandle.getCallingUserId(); int callingUid = Binder.getCallingUid(); return (sForegroundUserId == callingUser) Loading @@ -577,9 +586,21 @@ public final class Utils { || (UserHandle.getAppId(Process.SYSTEM_UID) == UserHandle.getAppId(callingUid)); } public static boolean checkCallerAllowManagedProfiles(Context mContext) { if (mContext == null) { return checkCaller(); public static boolean checkCallerIsSystemOrActiveUser(String tag) { final boolean res = checkCallerIsSystemOrActiveUser(); if (!res) { Log.w(TAG, tag + " - Not allowed for non-active user and non-system user"); } return res; } public static boolean callerIsSystemOrActiveUser(String tag, String method) { return checkCallerIsSystemOrActiveUser(tag + "." + method + "()"); } public static boolean checkCallerIsSystemOrActiveOrManagedUser(Context context) { if (context == null) { return checkCallerIsSystemOrActiveUser(); } int callingUser = UserHandle.getCallingUserId(); int callingUid = Binder.getCallingUid(); Loading @@ -587,7 +608,7 @@ public final class Utils { // Use the Bluetooth process identity when making call to get parent user long ident = Binder.clearCallingIdentity(); try { UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); UserInfo ui = um.getProfileParent(callingUser); int parentUser = (ui != null) ? ui.id : UserHandle.USER_NULL; Loading @@ -603,6 +624,32 @@ public final class Utils { } } public static boolean checkCallerIsSystemOrActiveOrManagedUser(Context context, String tag) { final boolean res = checkCallerIsSystemOrActiveOrManagedUser(context); if (!res) { Log.w(TAG, tag + " - Not allowed for" + " non-active user and non-system and non-managed user"); } return res; } public static boolean callerIsSystemOrActiveOrManagedUser(Context context, String tag, String method) { return checkCallerIsSystemOrActiveOrManagedUser(context, tag + "." + method + "()"); } public static boolean checkServiceAvailable(ProfileService service, String tag) { if (service == null) { Log.w(TAG, tag + " - Not present"); return false; } if (!service.isAvailable()) { Log.w(TAG, tag + " - Not available"); return false; } return true; } /** * Checks whether location is off and must be on for us to perform some operation */ Loading android/app/src/com/android/bluetooth/a2dp/A2dpNativeInterface.java +0 −1 Original line number Diff line number Diff line Loading @@ -205,7 +205,6 @@ public class A2dpNativeInterface { sendMessageToService(event); } @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) private boolean isMandatoryCodecPreferred(byte[] address) { A2dpService service = A2dpService.getA2dpService(); if (service != null) { Loading Loading
android/app/src/com/android/bluetooth/Utils.java +68 −21 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.Manifest; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.app.AppGlobals; import android.app.AppOpsManager; import android.app.BroadcastOptions; import android.bluetooth.BluetoothAdapter; Loading @@ -53,12 +54,15 @@ import android.os.Bundle; import android.os.ParcelUuid; import android.os.PowerExemptionManager; import android.os.Process; import android.os.RemoteException; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; import android.provider.Telephony; import android.util.Log; import com.android.bluetooth.btservice.ProfileService; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; Loading Loading @@ -406,6 +410,20 @@ public final class Utils { "Need DUMP permission"); } public static AttributionSource getCallingAttributionSource() { int callingUid = Binder.getCallingUid(); if (callingUid == android.os.Process.ROOT_UID) { callingUid = android.os.Process.SYSTEM_UID; } try { return new AttributionSource(callingUid, AppGlobals.getPackageManager().getPackagesForUid(callingUid)[0], null); } catch (RemoteException e) { throw new IllegalStateException("Failed to resolve AttributionSource", e); } } @SuppressLint("AndroidFrameworkRequiresPermission") private static boolean checkPermissionForPreflight(Context context, String permission) { final int result = PermissionChecker.checkCallingOrSelfPermissionForPreflight( context, permission); Loading @@ -422,6 +440,7 @@ public final class Utils { } } @SuppressLint("AndroidFrameworkRequiresPermission") private static boolean checkPermissionForDataDelivery(Context context, String permission, AttributionSource attributionSource, String message) { final int result = PermissionChecker.checkPermissionForDataDeliveryFromDataSource( Loading @@ -448,6 +467,7 @@ public final class Utils { * * <p>Should be used in situations where the app op should not be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static boolean checkConnectPermissionForPreflight(Context context) { return checkPermissionForPreflight(context, BLUETOOTH_CONNECT); Loading @@ -461,6 +481,7 @@ public final class Utils { * <p>Should be used in situations where data will be delivered and hence the app op should * be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static boolean checkConnectPermissionForDataDelivery( Context context, AttributionSource attributionSource, String message) { Loading @@ -474,6 +495,7 @@ public final class Utils { * * <p>Should be used in situations where the app op should not be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN) public static boolean checkScanPermissionForPreflight(Context context) { return checkPermissionForPreflight(context, BLUETOOTH_SCAN); Loading @@ -486,6 +508,7 @@ public final class Utils { * <p>Should be used in situations where data will be delivered and hence the app op should * be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN) public static boolean checkScanPermissionForDataDelivery( Context context, AttributionSource attributionSource, String message) { Loading @@ -500,6 +523,7 @@ public final class Utils { * <p> * Should be used in situations where the app op should not be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADVERTISE) public static boolean checkAdvertisePermissionForPreflight(Context context) { return checkPermissionForPreflight(context, BLUETOOTH_ADVERTISE); Loading @@ -513,6 +537,7 @@ public final class Utils { * Should be used in situations where data will be delivered and hence the * app op should be noted. */ @SuppressLint("AndroidFrameworkRequiresPermission") @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADVERTISE) public static boolean checkAdvertisePermissionForDataDelivery( Context context, AttributionSource attributionSource, String message) { Loading Loading @@ -553,23 +578,7 @@ public final class Utils { return false; } public static boolean callerIsSystemOrActiveUser(String tag, String method) { if (!checkCaller()) { Log.w(TAG, method + "() - Not allowed for non-active user and non-system user"); return false; } return true; } public static boolean callerIsSystemOrActiveOrManagedUser(Context context, String tag, String method) { if (!checkCallerAllowManagedProfiles(context)) { Log.w(TAG, method + "() - Not allowed for non-active user and non-system and non-managed user"); return false; } return true; } public static boolean checkCaller() { public static boolean checkCallerIsSystemOrActiveUser() { int callingUser = UserHandle.getCallingUserId(); int callingUid = Binder.getCallingUid(); return (sForegroundUserId == callingUser) Loading @@ -577,9 +586,21 @@ public final class Utils { || (UserHandle.getAppId(Process.SYSTEM_UID) == UserHandle.getAppId(callingUid)); } public static boolean checkCallerAllowManagedProfiles(Context mContext) { if (mContext == null) { return checkCaller(); public static boolean checkCallerIsSystemOrActiveUser(String tag) { final boolean res = checkCallerIsSystemOrActiveUser(); if (!res) { Log.w(TAG, tag + " - Not allowed for non-active user and non-system user"); } return res; } public static boolean callerIsSystemOrActiveUser(String tag, String method) { return checkCallerIsSystemOrActiveUser(tag + "." + method + "()"); } public static boolean checkCallerIsSystemOrActiveOrManagedUser(Context context) { if (context == null) { return checkCallerIsSystemOrActiveUser(); } int callingUser = UserHandle.getCallingUserId(); int callingUid = Binder.getCallingUid(); Loading @@ -587,7 +608,7 @@ public final class Utils { // Use the Bluetooth process identity when making call to get parent user long ident = Binder.clearCallingIdentity(); try { UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE); UserInfo ui = um.getProfileParent(callingUser); int parentUser = (ui != null) ? ui.id : UserHandle.USER_NULL; Loading @@ -603,6 +624,32 @@ public final class Utils { } } public static boolean checkCallerIsSystemOrActiveOrManagedUser(Context context, String tag) { final boolean res = checkCallerIsSystemOrActiveOrManagedUser(context); if (!res) { Log.w(TAG, tag + " - Not allowed for" + " non-active user and non-system and non-managed user"); } return res; } public static boolean callerIsSystemOrActiveOrManagedUser(Context context, String tag, String method) { return checkCallerIsSystemOrActiveOrManagedUser(context, tag + "." + method + "()"); } public static boolean checkServiceAvailable(ProfileService service, String tag) { if (service == null) { Log.w(TAG, tag + " - Not present"); return false; } if (!service.isAvailable()) { Log.w(TAG, tag + " - Not available"); return false; } return true; } /** * Checks whether location is off and must be on for us to perform some operation */ Loading
android/app/src/com/android/bluetooth/a2dp/A2dpNativeInterface.java +0 −1 Original line number Diff line number Diff line Loading @@ -205,7 +205,6 @@ public class A2dpNativeInterface { sendMessageToService(event); } @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) private boolean isMandatoryCodecPreferred(byte[] address) { A2dpService service = A2dpService.getA2dpService(); if (service != null) { Loading