diff --git a/src/com/android/settings/applications/AdvancedAppSettings.java b/src/com/android/settings/applications/AdvancedAppSettings.java index 0d2f206e662..f407cb15801 100644 --- a/src/com/android/settings/applications/AdvancedAppSettings.java +++ b/src/com/android/settings/applications/AdvancedAppSettings.java @@ -25,6 +25,7 @@ import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.applications.ApplicationsState.AppEntry; import com.android.settings.applications.ApplicationsState.Session; +import com.android.settings.applications.PermissionsSummaryHelper.PermissionsResultCallback; import com.android.settings.fuelgauge.PowerWhitelistBackend; 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 Session mSession; + private Preference mAppPermsPreference; private Preference mAppDomainURLsPreference; private Preference mHighPowerPreference; @@ -54,6 +56,7 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements getActivity().getApplication()); mSession = applicationsState.newSession(this); + mAppPermsPreference = findPreference(KEY_APP_PERM); mAppDomainURLsPreference = findPreference(KEY_APP_DOMAIN_URLS); mHighPowerPreference = findPreference(KEY_HIGH_POWER_APPS); updateUI(); @@ -75,6 +78,7 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements int highPowerCount = PowerWhitelistBackend.getInstance().getWhitelistSize(); mHighPowerPreference.setSummary(getResources().getQuantityString(R.plurals.high_power_count, highPowerCount, highPowerCount)); + PermissionsSummaryHelper.getAppWithPermissionsCounts(getContext(), mPermissionCallback); } @Override @@ -121,4 +125,19 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements public void onLoadEntriesCompleted() { // 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); + } + } + }; } diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java index e625a979b0c..73f9c7dd2dd 100755 --- a/src/com/android/settings/applications/InstalledAppDetails.java +++ b/src/com/android/settings/applications/InstalledAppDetails.java @@ -45,7 +45,6 @@ import android.os.ServiceManager; import android.os.UserHandle; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; -import android.provider.Settings; import android.text.format.DateUtils; import android.text.format.Formatter; import android.util.Log; @@ -66,6 +65,7 @@ import com.android.settings.R; import com.android.settings.SettingsActivity; import com.android.settings.Utils; 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.PowerUsageDetail; import com.android.settings.net.ChartData; @@ -461,7 +461,8 @@ public class InstalledAppDetails extends AppInfoBase // Update the preference summaries. Activity context = getActivity(); mStoragePreference.setSummary(AppStorageSettings.getSummary(mAppEntry, context)); -// mPermissionsPreference.setSummary(AppPermissionSettings.getSummary(mAppEntry, context)); + PermissionsSummaryHelper.getPermissionCounts(getContext(), mPackageName, + mPermissionCallback); mLaunchPreference.setSummary(Utils.getLaunchByDeafaultSummary(mAppEntry, mUsbManager, mPm, context)); mNotificationPreference.setSummary(getNotificationSummary(mAppEntry, context, @@ -832,6 +833,21 @@ public class InstalledAppDetails extends AppInfoBase 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); + } + } + }; } diff --git a/src/com/android/settings/applications/PermissionsSummaryHelper.java b/src/com/android/settings/applications/PermissionsSummaryHelper.java new file mode 100644 index 00000000000..e4ecd531412 --- /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); + } +}