• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Intent;
21 import android.content.pm.PackageManager;
22 import android.content.res.Resources;
23 import android.net.Uri;
24 
25 public class Utils {
26     static final String[] PERMISSIONS = {
27         android.Manifest.permission.READ_EXTERNAL_STORAGE
28     };
29 
30     static final String ERROR_RESOLUTION_ACTION_INTENT =
31             "android.media.extras.ERROR_RESOLUTION_ACTION_INTENT";
32 
33     static final String ERROR_RESOLUTION_ACTION_LABEL =
34             "android.media.extras.ERROR_RESOLUTION_ACTION_LABEL";
35 
getUriForResource(Context context, int id)36     static Uri getUriForResource(Context context, int id) {
37         Resources res = context.getResources();
38         return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
39                 + "://" + res.getResourcePackageName(id)
40                 + "/" + res.getResourceTypeName(id)
41                 + "/" + res.getResourceEntryName(id));
42     }
43 
hasRequiredPermissions(Context context)44     static boolean hasRequiredPermissions(Context context) {
45         for (String permission : PERMISSIONS) {
46             if (context.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
47                 return false;
48             }
49         }
50         return true;
51     }
52 }
53