Handle rotation (or refresh) before callback is received
Make sure we unregister the old receiver
Bug: 22160603
Change-Id: I798ca07dd65711caa4d3295b7ad811ca2fc69c1d
diff --git a/src/com/android/settings/applications/AdvancedAppSettings.java b/src/com/android/settings/applications/AdvancedAppSettings.java
index 47a0098..7df269e 100644
--- a/src/com/android/settings/applications/AdvancedAppSettings.java
+++ b/src/com/android/settings/applications/AdvancedAppSettings.java
@@ -15,6 +15,7 @@
*/
package com.android.settings.applications;
+import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
@@ -45,6 +46,8 @@
private Preference mAppDomainURLsPreference;
private Preference mHighPowerPreference;
+ private BroadcastReceiver mPermissionReceiver;
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -63,6 +66,15 @@
updateUI();
}
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (mPermissionReceiver != null) {
+ getContext().unregisterReceiver(mPermissionReceiver);
+ mPermissionReceiver = null;
+ }
+ }
+
private void updateUI() {
ArrayList<AppEntry> allApps = mSession.getAllApps();
@@ -79,7 +91,12 @@
int highPowerCount = PowerWhitelistBackend.getInstance().getWhitelistSize();
mHighPowerPreference.setSummary(getResources().getQuantityString(R.plurals.high_power_count,
highPowerCount, highPowerCount));
- PermissionsSummaryHelper.getAppWithPermissionsCounts(getContext(), mPermissionCallback);
+
+ if (mPermissionReceiver != null) {
+ getContext().unregisterReceiver(mPermissionReceiver);
+ }
+ mPermissionReceiver = PermissionsSummaryHelper.getAppWithPermissionsCounts(getContext(),
+ mPermissionCallback);
}
@Override
@@ -133,6 +150,7 @@
if (getActivity() == null) {
return;
}
+ mPermissionReceiver = null;
if (counts != null) {
mAppPermsPreference.setSummary(getContext().getString(
R.string.app_permissions_summary, counts[0], counts[1]));
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index a275743..842660b 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -157,6 +157,8 @@
protected ProcStatsData mStatsManager;
protected ProcStatsPackageEntry mStats;
+ private BroadcastReceiver mPermissionReceiver;
+
private boolean handleDisableable(Button button) {
boolean disableable = false;
// Try to prevent the user from bricking their phone
@@ -312,6 +314,10 @@
@Override
public void onDestroy() {
TrafficStats.closeQuietly(mStatsSession);
+ if (mPermissionReceiver != null) {
+ getContext().unregisterReceiver(mPermissionReceiver);
+ mPermissionReceiver = null;
+ }
super.onDestroy();
}
@@ -489,8 +495,11 @@
// Update the preference summaries.
Activity context = getActivity();
mStoragePreference.setSummary(AppStorageSettings.getSummary(mAppEntry, context));
- PermissionsSummaryHelper.getPermissionSummary(getContext(), mPackageName,
- mPermissionCallback);
+ if (mPermissionReceiver != null) {
+ getContext().unregisterReceiver(mPermissionReceiver);
+ }
+ mPermissionReceiver = PermissionsSummaryHelper.getPermissionSummary(getContext(),
+ mPackageName, mPermissionCallback);
mLaunchPreference.setSummary(Utils.getLaunchByDeafaultSummary(mAppEntry, mUsbManager,
mPm, context));
mNotificationPreference.setSummary(getNotificationSummary(mAppEntry, context,
@@ -941,6 +950,10 @@
= new PermissionsResultCallback() {
@Override
public void onPermissionSummaryResult(int[] counts, CharSequence[] groupLabels) {
+ if (getActivity() == null) {
+ return;
+ }
+ mPermissionReceiver = null;
final Resources res = getResources();
CharSequence summary = null;
boolean enabled = false;
diff --git a/src/com/android/settings/applications/PermissionsSummaryHelper.java b/src/com/android/settings/applications/PermissionsSummaryHelper.java
index 1b384ea..859e446 100644
--- a/src/com/android/settings/applications/PermissionsSummaryHelper.java
+++ b/src/com/android/settings/applications/PermissionsSummaryHelper.java
@@ -27,21 +27,21 @@
private static final String ACTION_APP_COUNT_RESPONSE
= "com.android.settings.APP_COUNT_RESPONSE";
- public static void getPermissionSummary(Context context, String pkg,
+ public static BroadcastReceiver getPermissionSummary(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);
+ return sendPermissionRequest(context, ACTION_PERM_COUNT_RESPONSE, request, callback);
}
- public static void getAppWithPermissionsCounts(Context context,
+ public static BroadcastReceiver getAppWithPermissionsCounts(Context context,
PermissionsResultCallback callback) {
Intent request = new Intent(Intent.ACTION_GET_PERMISSIONS_COUNT);
- sendPermissionRequest(context, ACTION_APP_COUNT_RESPONSE, request, callback);
+ return sendPermissionRequest(context, ACTION_APP_COUNT_RESPONSE, request, callback);
}
- private static void sendPermissionRequest(Context context, String action, Intent request,
- final PermissionsResultCallback callback) {
+ private static BroadcastReceiver sendPermissionRequest(Context context, String action,
+ Intent request, final PermissionsResultCallback callback) {
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -59,6 +59,7 @@
request.putExtra(Intent.EXTRA_GET_PERMISSIONS_RESPONSE_INTENT, action);
request.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
context.sendBroadcast(request);
+ return receiver;
}
public interface PermissionsResultCallback {