1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.snippet.wifi.aware; 17 18 import android.content.Context; 19 import android.content.pm.PackageManager; 20 21 /** 22 * Utility class for checking permissions. 23 */ 24 public final class PermissionUtils { 25 /** 26 * Check if the app has the required permissions. 27 * 28 * @param context The context of the app. 29 * @param permissions The permissions to check. 30 */ checkPermissions(Context context, String... permissions)31 public static void checkPermissions(Context context, String... permissions) { 32 for (String permission : permissions) { 33 if (context.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { 34 throw new SecurityException( 35 "Permission denied (missing " + permission + " permission)"); 36 } 37 } 38 } 39 } 40