| /* |
| * Copyright (C) 2022 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.bedstead.nene.roles; |
| |
| import static com.android.bedstead.nene.permissions.CommonPermissions.BYPASS_ROLE_QUALIFICATION; |
| import static com.android.bedstead.nene.utils.Versions.T; |
| |
| import android.annotation.TargetApi; |
| import android.app.role.RoleManager; |
| import android.content.Context; |
| import android.os.Build; |
| |
| import com.android.bedstead.nene.TestApis; |
| import com.android.bedstead.nene.annotations.Experimental; |
| import com.android.bedstead.nene.permissions.PermissionContext; |
| import com.android.bedstead.nene.utils.Versions; |
| |
| /** Test APIs related to roles. */ |
| @TargetApi(Build.VERSION_CODES.TIRAMISU) |
| public class Roles { |
| public static final Roles sInstance = new Roles(); |
| |
| private static final Context sContext = TestApis.context().instrumentedContext(); |
| |
| private Roles() {} |
| |
| /** |
| * @see RoleManager#setBypassingRoleQualification(boolean) |
| */ |
| @Experimental |
| public void setBypassingRoleQualification(boolean bypassingRoleQualification) { |
| if (!Versions.meetsMinimumSdkVersionRequirement(T)) { |
| return; |
| } |
| try (PermissionContext p = TestApis.permissions().withPermission( |
| BYPASS_ROLE_QUALIFICATION)) { |
| sContext.getSystemService(RoleManager.class) |
| .setBypassingRoleQualification(bypassingRoleQualification); |
| } |
| } |
| } |