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;
|
package com.android.settings.applications;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -45,6 +46,8 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
|||||||
private Preference mAppDomainURLsPreference;
|
private Preference mAppDomainURLsPreference;
|
||||||
private Preference mHighPowerPreference;
|
private Preference mHighPowerPreference;
|
||||||
|
|
||||||
|
private BroadcastReceiver mPermissionReceiver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
@@ -63,6 +66,15 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
|||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
if (mPermissionReceiver != null) {
|
||||||
|
getContext().unregisterReceiver(mPermissionReceiver);
|
||||||
|
mPermissionReceiver = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateUI() {
|
private void updateUI() {
|
||||||
ArrayList<AppEntry> allApps = mSession.getAllApps();
|
ArrayList<AppEntry> allApps = mSession.getAllApps();
|
||||||
|
|
||||||
@@ -79,7 +91,12 @@ 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);
|
|
||||||
|
if (mPermissionReceiver != null) {
|
||||||
|
getContext().unregisterReceiver(mPermissionReceiver);
|
||||||
|
}
|
||||||
|
mPermissionReceiver = PermissionsSummaryHelper.getAppWithPermissionsCounts(getContext(),
|
||||||
|
mPermissionCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -133,6 +150,7 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
|||||||
if (getActivity() == null) {
|
if (getActivity() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mPermissionReceiver = null;
|
||||||
if (counts != null) {
|
if (counts != null) {
|
||||||
mAppPermsPreference.setSummary(getContext().getString(
|
mAppPermsPreference.setSummary(getContext().getString(
|
||||||
R.string.app_permissions_summary, counts[0], counts[1]));
|
R.string.app_permissions_summary, counts[0], counts[1]));
|
||||||
|
@@ -157,6 +157,8 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
protected ProcStatsData mStatsManager;
|
protected ProcStatsData mStatsManager;
|
||||||
protected ProcStatsPackageEntry mStats;
|
protected ProcStatsPackageEntry mStats;
|
||||||
|
|
||||||
|
private BroadcastReceiver mPermissionReceiver;
|
||||||
|
|
||||||
private boolean handleDisableable(Button button) {
|
private boolean handleDisableable(Button button) {
|
||||||
boolean disableable = false;
|
boolean disableable = false;
|
||||||
// Try to prevent the user from bricking their phone
|
// Try to prevent the user from bricking their phone
|
||||||
@@ -312,6 +314,10 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
TrafficStats.closeQuietly(mStatsSession);
|
TrafficStats.closeQuietly(mStatsSession);
|
||||||
|
if (mPermissionReceiver != null) {
|
||||||
|
getContext().unregisterReceiver(mPermissionReceiver);
|
||||||
|
mPermissionReceiver = null;
|
||||||
|
}
|
||||||
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
@@ -489,8 +495,11 @@ 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));
|
||||||
PermissionsSummaryHelper.getPermissionSummary(getContext(), mPackageName,
|
if (mPermissionReceiver != null) {
|
||||||
mPermissionCallback);
|
getContext().unregisterReceiver(mPermissionReceiver);
|
||||||
|
}
|
||||||
|
mPermissionReceiver = PermissionsSummaryHelper.getPermissionSummary(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,
|
||||||
@@ -941,6 +950,10 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
= new PermissionsResultCallback() {
|
= new PermissionsResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onPermissionSummaryResult(int[] counts, CharSequence[] groupLabels) {
|
public void onPermissionSummaryResult(int[] counts, CharSequence[] groupLabels) {
|
||||||
|
if (getActivity() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mPermissionReceiver = null;
|
||||||
final Resources res = getResources();
|
final Resources res = getResources();
|
||||||
CharSequence summary = null;
|
CharSequence summary = null;
|
||||||
boolean enabled = false;
|
boolean enabled = false;
|
||||||
|
@@ -27,21 +27,21 @@ public class PermissionsSummaryHelper {
|
|||||||
private static final String ACTION_APP_COUNT_RESPONSE
|
private static final String ACTION_APP_COUNT_RESPONSE
|
||||||
= "com.android.settings.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) {
|
PermissionsResultCallback callback) {
|
||||||
Intent request = new Intent(Intent.ACTION_GET_PERMISSIONS_COUNT);
|
Intent request = new Intent(Intent.ACTION_GET_PERMISSIONS_COUNT);
|
||||||
request.putExtra(Intent.EXTRA_PACKAGE_NAME, pkg);
|
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) {
|
PermissionsResultCallback callback) {
|
||||||
Intent request = new Intent(Intent.ACTION_GET_PERMISSIONS_COUNT);
|
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,
|
private static BroadcastReceiver sendPermissionRequest(Context context, String action,
|
||||||
final PermissionsResultCallback callback) {
|
Intent request, final PermissionsResultCallback callback) {
|
||||||
BroadcastReceiver receiver = new BroadcastReceiver() {
|
BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@@ -59,6 +59,7 @@ public class PermissionsSummaryHelper {
|
|||||||
request.putExtra(Intent.EXTRA_GET_PERMISSIONS_RESPONSE_INTENT, action);
|
request.putExtra(Intent.EXTRA_GET_PERMISSIONS_RESPONSE_INTENT, action);
|
||||||
request.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
request.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||||
context.sendBroadcast(request);
|
context.sendBroadcast(request);
|
||||||
|
return receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface PermissionsResultCallback {
|
public interface PermissionsResultCallback {
|
||||||
|
Reference in New Issue
Block a user