diff options
Diffstat (limited to 'src/com/android/settings/applications/PermissionsSummaryHelper.java')
-rw-r--r-- | src/com/android/settings/applications/PermissionsSummaryHelper.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/com/android/settings/applications/PermissionsSummaryHelper.java b/src/com/android/settings/applications/PermissionsSummaryHelper.java new file mode 100644 index 0000000..e4ecd53 --- /dev/null +++ b/src/com/android/settings/applications/PermissionsSummaryHelper.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015 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.settings.applications; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; + +public class PermissionsSummaryHelper { + + private static final String ACTION_PERM_COUNT_RESPONSE + = "com.android.settings.PERM_COUNT_RESPONSE"; + private static final String ACTION_APP_COUNT_RESPONSE + = "com.android.settings.APP_COUNT_RESPONSE"; + + public static void getPermissionCounts(Context context, String pkg, + PermissionsResultCallback callback) { + Intent request = new Intent(Intent.ACTION_GET_PERMISSIONS_COUNT); + request.putExtra(Intent.EXTRA_PACKAGE_NAME, pkg); + sendPermissionRequest(context, ACTION_PERM_COUNT_RESPONSE, request, callback); + } + + public static void getAppWithPermissionsCounts(Context context, + PermissionsResultCallback callback) { + Intent request = new Intent(Intent.ACTION_GET_PERMISSIONS_COUNT); + sendPermissionRequest(context, ACTION_APP_COUNT_RESPONSE, request, callback); + } + + private static void sendPermissionRequest(Context context, String action, Intent request, + final PermissionsResultCallback callback) { + BroadcastReceiver receiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + int[] result = intent.getIntArrayExtra(Intent.EXTRA_GET_PERMISSIONS_COUNT_RESULT); + callback.onPermissionCountResult(result); + context.unregisterReceiver(this); + } + }; + context.registerReceiver(receiver, new IntentFilter(action)); + request.putExtra(Intent.EXTRA_GET_PERMISSIONS_RESPONSE_INTENT, action); + request.setFlags(Intent.FLAG_RECEIVER_FOREGROUND); + context.sendBroadcast(request); + } + + public interface PermissionsResultCallback { + void onPermissionCountResult(int[] result); + } +} |