Merge "Handle rotation (or refresh) before callback is received" into mnc-dev
This commit is contained in:
@@ -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 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
||||
private Preference mAppDomainURLsPreference;
|
||||
private Preference mHighPowerPreference;
|
||||
|
||||
private BroadcastReceiver mPermissionReceiver;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -63,6 +66,15 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
||||
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 @@ 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);
|
||||
|
||||
if (mPermissionReceiver != null) {
|
||||
getContext().unregisterReceiver(mPermissionReceiver);
|
||||
}
|
||||
mPermissionReceiver = PermissionsSummaryHelper.getAppWithPermissionsCounts(getContext(),
|
||||
mPermissionCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,6 +150,7 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
mPermissionReceiver = null;
|
||||
if (counts != null) {
|
||||
mAppPermsPreference.setSummary(getContext().getString(
|
||||
R.string.app_permissions_summary, counts[0], counts[1]));
|
||||
|
@@ -157,6 +157,8 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
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 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
TrafficStats.closeQuietly(mStatsSession);
|
||||
if (mPermissionReceiver != null) {
|
||||
getContext().unregisterReceiver(mPermissionReceiver);
|
||||
mPermissionReceiver = null;
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
@@ -489,8 +495,11 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
// 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 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
= 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;
|
||||
|
@@ -27,21 +27,21 @@ public class PermissionsSummaryHelper {
|
||||
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 @@ public class PermissionsSummaryHelper {
|
||||
request.putExtra(Intent.EXTRA_GET_PERMISSIONS_RESPONSE_INTENT, action);
|
||||
request.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||
context.sendBroadcast(request);
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public interface PermissionsResultCallback {
|
||||
|
Reference in New Issue
Block a user