Add permission summaries back in
Use broadcasts to ask the PackageInstaller about the number of granted permissions. Bug: 21078474 Change-Id: I91d88d145a803f5f6c3f3163ba1f4500d39b1943
This commit is contained in:
@@ -25,6 +25,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.applications.ApplicationsState.AppEntry;
|
import com.android.settings.applications.ApplicationsState.AppEntry;
|
||||||
import com.android.settings.applications.ApplicationsState.Session;
|
import com.android.settings.applications.ApplicationsState.Session;
|
||||||
|
import com.android.settings.applications.PermissionsSummaryHelper.PermissionsResultCallback;
|
||||||
import com.android.settings.fuelgauge.PowerWhitelistBackend;
|
import com.android.settings.fuelgauge.PowerWhitelistBackend;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -39,6 +40,7 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
|||||||
private static final String KEY_HIGH_POWER_APPS = "high_power_apps";
|
private static final String KEY_HIGH_POWER_APPS = "high_power_apps";
|
||||||
|
|
||||||
private Session mSession;
|
private Session mSession;
|
||||||
|
private Preference mAppPermsPreference;
|
||||||
private Preference mAppDomainURLsPreference;
|
private Preference mAppDomainURLsPreference;
|
||||||
private Preference mHighPowerPreference;
|
private Preference mHighPowerPreference;
|
||||||
|
|
||||||
@@ -54,6 +56,7 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
|||||||
getActivity().getApplication());
|
getActivity().getApplication());
|
||||||
mSession = applicationsState.newSession(this);
|
mSession = applicationsState.newSession(this);
|
||||||
|
|
||||||
|
mAppPermsPreference = findPreference(KEY_APP_PERM);
|
||||||
mAppDomainURLsPreference = findPreference(KEY_APP_DOMAIN_URLS);
|
mAppDomainURLsPreference = findPreference(KEY_APP_DOMAIN_URLS);
|
||||||
mHighPowerPreference = findPreference(KEY_HIGH_POWER_APPS);
|
mHighPowerPreference = findPreference(KEY_HIGH_POWER_APPS);
|
||||||
updateUI();
|
updateUI();
|
||||||
@@ -75,6 +78,7 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
|||||||
int highPowerCount = PowerWhitelistBackend.getInstance().getWhitelistSize();
|
int highPowerCount = PowerWhitelistBackend.getInstance().getWhitelistSize();
|
||||||
mHighPowerPreference.setSummary(getResources().getQuantityString(R.plurals.high_power_count,
|
mHighPowerPreference.setSummary(getResources().getQuantityString(R.plurals.high_power_count,
|
||||||
highPowerCount, highPowerCount));
|
highPowerCount, highPowerCount));
|
||||||
|
PermissionsSummaryHelper.getAppWithPermissionsCounts(getContext(), mPermissionCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -121,4 +125,19 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
|||||||
public void onLoadEntriesCompleted() {
|
public void onLoadEntriesCompleted() {
|
||||||
// No-op.
|
// No-op.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final PermissionsResultCallback mPermissionCallback = new PermissionsResultCallback() {
|
||||||
|
@Override
|
||||||
|
public void onPermissionCountResult(int[] result) {
|
||||||
|
if (getActivity() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (result != null) {
|
||||||
|
mAppPermsPreference.setSummary(getContext().getString(
|
||||||
|
R.string.app_permissions_summary, result[0], result[1]));
|
||||||
|
} else {
|
||||||
|
mAppPermsPreference.setSummary(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@@ -45,7 +45,6 @@ import android.os.ServiceManager;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -66,6 +65,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.applications.ApplicationsState.AppEntry;
|
import com.android.settings.applications.ApplicationsState.AppEntry;
|
||||||
|
import com.android.settings.applications.PermissionsSummaryHelper.PermissionsResultCallback;
|
||||||
import com.android.settings.fuelgauge.BatteryEntry;
|
import com.android.settings.fuelgauge.BatteryEntry;
|
||||||
import com.android.settings.fuelgauge.PowerUsageDetail;
|
import com.android.settings.fuelgauge.PowerUsageDetail;
|
||||||
import com.android.settings.net.ChartData;
|
import com.android.settings.net.ChartData;
|
||||||
@@ -461,7 +461,8 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
// Update the preference summaries.
|
// Update the preference summaries.
|
||||||
Activity context = getActivity();
|
Activity context = getActivity();
|
||||||
mStoragePreference.setSummary(AppStorageSettings.getSummary(mAppEntry, context));
|
mStoragePreference.setSummary(AppStorageSettings.getSummary(mAppEntry, context));
|
||||||
// mPermissionsPreference.setSummary(AppPermissionSettings.getSummary(mAppEntry, context));
|
PermissionsSummaryHelper.getPermissionCounts(getContext(), mPackageName,
|
||||||
|
mPermissionCallback);
|
||||||
mLaunchPreference.setSummary(Utils.getLaunchByDeafaultSummary(mAppEntry, mUsbManager,
|
mLaunchPreference.setSummary(Utils.getLaunchByDeafaultSummary(mAppEntry, mUsbManager,
|
||||||
mPm, context));
|
mPm, context));
|
||||||
mNotificationPreference.setSummary(getNotificationSummary(mAppEntry, context,
|
mNotificationPreference.setSummary(getNotificationSummary(mAppEntry, context,
|
||||||
@@ -832,6 +833,21 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
updateForceStopButton(getResultCode() != Activity.RESULT_CANCELED);
|
updateForceStopButton(getResultCode() != Activity.RESULT_CANCELED);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final PermissionsResultCallback mPermissionCallback = new PermissionsResultCallback() {
|
||||||
|
@Override
|
||||||
|
public void onPermissionCountResult(int[] result) {
|
||||||
|
if (getActivity() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (result != null) {
|
||||||
|
mPermissionsPreference.setSummary(getResources().getQuantityString(
|
||||||
|
R.plurals.runtime_permissions_summary, result[1], result[0], result[1]));
|
||||||
|
} else {
|
||||||
|
mPermissionsPreference.setSummary(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user