1 /* 2 * Copyright (c) 2016, 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.android.car.media.localmediaplayer; 17 18 import android.content.ContentResolver; 19 import android.content.Context; 20 import android.content.pm.PackageManager; 21 import android.content.res.Resources; 22 import android.net.Uri; 23 24 public class Utils { 25 static final String[] PERMISSIONS = { 26 android.Manifest.permission.READ_EXTERNAL_STORAGE 27 }; 28 29 static Uri getUriForResource(Context context, int id) { 30 Resources res = context.getResources(); 31 return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE 32 + "://" + res.getResourcePackageName(id) 33 + "/" + res.getResourceTypeName(id) 34 + "/" + res.getResourceEntryName(id)); 35 } 36 37 static boolean hasRequiredPermissions(Context context) { 38 for (String permission : PERMISSIONS) { 39 if (context.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { 40 return false; 41 } 42 } 43 return true; 44 } 45 } 46