• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 
17 package com.android.packageinstaller.permission.service;
18 
19 import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
20 import static android.provider.SearchIndexablesContract.RawData.COLUMN_INTENT_ACTION;
21 import static android.provider.SearchIndexablesContract.RawData.COLUMN_KEY;
22 import static android.provider.SearchIndexablesContract.RawData.COLUMN_KEYWORDS;
23 import static android.provider.SearchIndexablesContract.RawData.COLUMN_RANK;
24 import static android.provider.SearchIndexablesContract.RawData.COLUMN_TITLE;
25 
26 import android.content.Context;
27 import android.content.pm.PackageManager;
28 import android.database.Cursor;
29 import android.database.MatrixCursor;
30 import android.util.Log;
31 
32 import com.android.packageinstaller.permission.utils.Utils;
33 import com.android.permissioncontroller.R;
34 
35 import java.util.List;
36 
37 /**
38  * {@link android.provider.SearchIndexablesProvider} for permissions.
39  */
40 public class PermissionSearchIndexablesProvider extends BaseSearchIndexablesProvider {
41     private static final String LOG_TAG = PermissionSearchIndexablesProvider.class.getSimpleName();
42 
43     public static final String ACTION_MANAGE_PERMISSION_APPS =
44             "com.android.permissioncontroller.settingssearch.action.MANAGE_PERMISSION_APPS";
45     public static final String ACTION_REVIEW_PERMISSION_USAGE =
46             "com.android.permissioncontroller.settingssearch.action.REVIEW_PERMISSION_USAGE";
47 
48     @Override
queryRawData(String[] projection)49     public Cursor queryRawData(String[] projection) {
50         Context context = getContext();
51         PackageManager pm = context.getPackageManager();
52 
53         List<String> permissionGroupNames = Utils.getPlatformPermissionGroups();
54         MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS);
55 
56         int numPermissionGroups = permissionGroupNames.size();
57         for (int i = 0; i < numPermissionGroups; i++) {
58             String groupName = permissionGroupNames.get(i);
59 
60             CharSequence label = getPermissionGroupLabel(groupName, pm);
61 
62             cursor.newRow().add(COLUMN_RANK, 0)
63                     .add(COLUMN_TITLE, label)
64                     .add(COLUMN_KEYWORDS, label + ", " + context.getString(
65                             R.string.permission_search_keyword))
66                     .add(COLUMN_KEY, createRawDataKey(groupName, context))
67                     .add(COLUMN_INTENT_ACTION, ACTION_MANAGE_PERMISSION_APPS);
68         }
69 
70         cursor.newRow().add(COLUMN_RANK, 0)
71                 .add(COLUMN_TITLE, context.getString(R.string.permission_usage_title))
72                 .add(COLUMN_KEYWORDS, context.getString(R.string.permission_search_keyword))
73                 .add(COLUMN_KEY, createRawDataKey("permissions usage", context))
74                 .add(COLUMN_INTENT_ACTION, ACTION_REVIEW_PERMISSION_USAGE);
75 
76         return cursor;
77     }
78 
getPermissionGroupLabel(String groupName, PackageManager pm)79     private CharSequence getPermissionGroupLabel(String groupName, PackageManager pm) {
80         try {
81             return pm.getPermissionGroupInfo(groupName, 0).loadLabel(pm);
82         } catch (PackageManager.NameNotFoundException e) {
83             Log.w(LOG_TAG, "Cannot find group label for " + groupName, e);
84         }
85         return null;
86     }
87 }
88