Suppress warnings from AppOpsManager#checkPackage()
AppOpsManager#checkPackage() is the recommended API to check whether a given package belongs to a certain UID or not. You can check whether a SecurityException is thrown or not to get the answer. However, if the given package does not belong to the UID specified, the app developer not only sees SecurityException but also sees the warning in messages like below, which is a bit spammy and may actually confuse QA team. W AppOps : Bad call: specified package com.android under uid 12345 but it is really -1 W AppOps : java.lang.RuntimeException: here W AppOps : at com.android.server.AppOpsService.getOpsRawLocked(AppOpsService.java:1330) W AppOps : at com.android.server.AppOpsService.checkPackage(AppOpsService.java:1049) W AppOps : at com.android.internal.app.IAppOpsService$Stub.onTransact(IAppOpsService.java:169) W AppOps : at android.os.Binder.execTransact(Binder.java:696) With this CL, AppOpsManager#checkPackage() no longer triggers the above warnings in logcat. Hopefully app developers do log something in logcat if the package name / UID mismatch is actually unexpected. This CL should have no semantic behavior change anyway. Fixes: 67745316 Test: Locally verified by making the following API call. context.getSystemService(AppOpsManager.class) .checkPackage(12345, "com.android") While it still throws SecurityException, warning messages are no longer shown in the logcat. Change-Id: Ic7af4ef84ad9e7ae5c0fbaa9cd1343f5443e8603
Loading
Please register or sign in to comment