Use broadcasts to ask the PackageInstaller about the number of granted permissions. Bug: 21078474 Change-Id: I91d88d145a803f5f6c3f3163ba1f4500d39b1943
63 lines
2.6 KiB
Java
63 lines
2.6 KiB
Java
/*
|
|
* 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);
|
|
}
|
|
}
|