Move permission enforcement to onCommand
Calling enforceCallingOrSelfPermission in the shell command constructor causes a hang when running GTS if the permission isn't granted. Bug: 191043641 Test: Run "cmd contexthub deny" and verify error is printed if not rooted Change-Id: I807adee4382310a201c34e31cd53fbb37574e851
This commit is contained in:
@@ -32,16 +32,18 @@ public class ContextHubShellCommand extends ShellCommand {
|
||||
|
||||
// Internal service impl -- must perform security checks before touching.
|
||||
private final ContextHubService mInternal;
|
||||
private final Context mContext;
|
||||
|
||||
public ContextHubShellCommand(Context context, ContextHubService service) {
|
||||
mInternal = service;
|
||||
|
||||
context.enforceCallingOrSelfPermission(
|
||||
android.Manifest.permission.ACCESS_CONTEXT_HUB, "ContextHubShellCommand");
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onCommand(String cmd) {
|
||||
mContext.enforceCallingOrSelfPermission(
|
||||
android.Manifest.permission.ACCESS_CONTEXT_HUB, "ContextHubShellCommand");
|
||||
|
||||
if ("deny".equals(cmd)) {
|
||||
return runDisableAuth();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user