Merge "Cleanup of the PackageInstaller API - Settings" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c8d363e24c
@@ -123,66 +123,23 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
private final PermissionsResultCallback mPermissionCallback = new PermissionsResultCallback() {
|
private final PermissionsResultCallback mPermissionCallback = new PermissionsResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onPermissionSummaryResult(int[] counts, CharSequence[] groupLabels) {
|
public void onAppWithPermissionsCountsResult(int standardGrantedPermissionAppCount,
|
||||||
|
int standardUsedPermissionAppCount) {
|
||||||
if (getActivity() == null) {
|
if (getActivity() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mPermissionReceiver = null;
|
mPermissionReceiver = null;
|
||||||
if (counts != null) {
|
if (standardUsedPermissionAppCount != 0) {
|
||||||
mAppPermsPreference.setSummary(getContext().getString(
|
mAppPermsPreference.setSummary(getContext().getString(
|
||||||
R.string.app_permissions_summary, counts[0], counts[1]));
|
R.string.app_permissions_summary,
|
||||||
|
standardGrantedPermissionAppCount,
|
||||||
|
standardUsedPermissionAppCount));
|
||||||
} else {
|
} else {
|
||||||
mAppPermsPreference.setSummary(null);
|
mAppPermsPreference.setSummary(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private class CountAppsWithOverlayPermission extends
|
|
||||||
AsyncTask<AppStateOverlayBridge, Void, Integer> {
|
|
||||||
int numOfPackagesRequestedPermission = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Integer doInBackground(AppStateOverlayBridge... params) {
|
|
||||||
AppStateOverlayBridge overlayBridge = params[0];
|
|
||||||
numOfPackagesRequestedPermission = overlayBridge
|
|
||||||
.getNumberOfPackagesWithPermission();
|
|
||||||
return overlayBridge.getNumberOfPackagesCanDrawOverlay();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Integer result) {
|
|
||||||
// checks if fragment is still there before updating the preference object
|
|
||||||
if (isAdded()) {
|
|
||||||
mSystemAlertWindowPreference.setSummary(getContext().getString(
|
|
||||||
R.string.system_alert_window_summary, result,
|
|
||||||
numOfPackagesRequestedPermission));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CountAppsWithWriteSettingsPermission extends
|
|
||||||
AsyncTask<AppStateWriteSettingsBridge, Void, Integer> {
|
|
||||||
int numOfPackagesRequestedPermission = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Integer doInBackground(AppStateWriteSettingsBridge... params) {
|
|
||||||
AppStateWriteSettingsBridge writeSettingsBridge = params[0];
|
|
||||||
numOfPackagesRequestedPermission = writeSettingsBridge
|
|
||||||
.getNumberOfPackagesWithPermission();
|
|
||||||
return writeSettingsBridge.getNumberOfPackagesCanWriteSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Integer result) {
|
|
||||||
// checks if fragment is still there before updating the preference object
|
|
||||||
if (isAdded()) {
|
|
||||||
mWriteSettingsPreference.setSummary(getContext().getString(
|
|
||||||
R.string.write_settings_summary, result,
|
|
||||||
numOfPackagesRequestedPermission));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider() {
|
new BaseSearchIndexProvider() {
|
||||||
@Override
|
@Override
|
||||||
|
@@ -179,8 +179,6 @@ 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
|
||||||
@@ -356,11 +354,6 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,10 +557,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));
|
||||||
if (mPermissionReceiver != null) {
|
|
||||||
getContext().unregisterReceiver(mPermissionReceiver);
|
PermissionsSummaryHelper.getPermissionSummary(getContext(),
|
||||||
}
|
|
||||||
mPermissionReceiver = PermissionsSummaryHelper.getPermissionSummary(getContext(),
|
|
||||||
mPackageName, mPermissionCallback);
|
mPackageName, mPermissionCallback);
|
||||||
mLaunchPreference.setSummary(AppUtils.getLaunchByDefaultSummary(mAppEntry, mUsbManager,
|
mLaunchPreference.setSummary(AppUtils.getLaunchByDefaultSummary(mAppEntry, mUsbManager,
|
||||||
mPm, context));
|
mPm, context));
|
||||||
@@ -1187,27 +1178,25 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
private final PermissionsResultCallback mPermissionCallback
|
private final PermissionsResultCallback mPermissionCallback
|
||||||
= new PermissionsResultCallback() {
|
= new PermissionsResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onPermissionSummaryResult(int[] counts, CharSequence[] groupLabels) {
|
public void onPermissionSummaryResult(int standardGrantedPermissionCount,
|
||||||
|
int requestedPermissionCount, int additionalGrantedPermissionCount,
|
||||||
|
List<CharSequence> grantedGroupLabels) {
|
||||||
if (getActivity() == null) {
|
if (getActivity() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mPermissionReceiver = null;
|
|
||||||
final Resources res = getResources();
|
final Resources res = getResources();
|
||||||
CharSequence summary = null;
|
CharSequence summary = null;
|
||||||
if (counts != null) {
|
|
||||||
int totalCount = counts[1];
|
|
||||||
int additionalCounts = counts[2];
|
|
||||||
|
|
||||||
if (totalCount == 0) {
|
if (requestedPermissionCount == 0) {
|
||||||
summary = res.getString(
|
summary = res.getString(
|
||||||
R.string.runtime_permissions_summary_no_permissions_requested);
|
R.string.runtime_permissions_summary_no_permissions_requested);
|
||||||
} else {
|
} else {
|
||||||
final ArrayList<CharSequence> list = new ArrayList(Arrays.asList(groupLabels));
|
final ArrayList<CharSequence> list = new ArrayList<>(grantedGroupLabels);
|
||||||
if (additionalCounts > 0) {
|
if (additionalGrantedPermissionCount > 0) {
|
||||||
// N additional permissions.
|
// N additional permissions.
|
||||||
list.add(res.getQuantityString(
|
list.add(res.getQuantityString(
|
||||||
R.plurals.runtime_permissions_additional_count,
|
R.plurals.runtime_permissions_additional_count,
|
||||||
additionalCounts, additionalCounts));
|
additionalGrantedPermissionCount, additionalGrantedPermissionCount));
|
||||||
}
|
}
|
||||||
if (list.size() == 0) {
|
if (list.size() == 0) {
|
||||||
summary = res.getString(
|
summary = res.getString(
|
||||||
@@ -1216,7 +1205,6 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
summary = ListFormatter.getInstance().format(list);
|
summary = ListFormatter.getInstance().format(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
mPermissionsPreference.setSummary(summary);
|
mPermissionsPreference.setSummary(summary);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -15,54 +15,66 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.applications;
|
package com.android.settings.applications;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.annotation.NonNull;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.pm.permission.RuntimePermissionPresentationInfo;
|
||||||
import android.content.IntentFilter;
|
import android.content.pm.permission.RuntimePermissionPresenter;
|
||||||
|
|
||||||
|
import java.text.Collator;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PermissionsSummaryHelper {
|
public class PermissionsSummaryHelper {
|
||||||
|
|
||||||
private static final String ACTION_PERM_COUNT_RESPONSE
|
public static void getPermissionSummary(Context context, String pkg,
|
||||||
= "com.android.settings.PERM_COUNT_RESPONSE";
|
final PermissionsResultCallback callback) {
|
||||||
private static final String ACTION_APP_COUNT_RESPONSE
|
final RuntimePermissionPresenter presenter =
|
||||||
= "com.android.settings.APP_COUNT_RESPONSE";
|
RuntimePermissionPresenter.getInstance(context);
|
||||||
|
presenter.getAppPermissions(pkg, new RuntimePermissionPresenter.OnResultCallback() {
|
||||||
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);
|
|
||||||
return sendPermissionRequest(context, ACTION_PERM_COUNT_RESPONSE, request, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BroadcastReceiver getAppWithPermissionsCounts(Context context,
|
|
||||||
PermissionsResultCallback callback) {
|
|
||||||
Intent request = new Intent(Intent.ACTION_GET_PERMISSIONS_COUNT);
|
|
||||||
return sendPermissionRequest(context, ACTION_APP_COUNT_RESPONSE, request, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BroadcastReceiver sendPermissionRequest(Context context, String action,
|
|
||||||
Intent request, final PermissionsResultCallback callback) {
|
|
||||||
BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onGetAppPermissions(
|
||||||
int[] counts = intent.getIntArrayExtra(Intent.EXTRA_GET_PERMISSIONS_COUNT_RESULT);
|
@NonNull List<RuntimePermissionPresentationInfo> permissions) {
|
||||||
|
final int permissionCount = permissions.size();
|
||||||
|
|
||||||
CharSequence[] groups = intent.getCharSequenceArrayExtra(
|
int grantedStandardCount = 0;
|
||||||
Intent.EXTRA_GET_PERMISSIONS_GROUP_LIST_RESULT);
|
int grantedAdditionalCount = 0;
|
||||||
|
int requestedCount = 0;
|
||||||
|
List<CharSequence> grantedStandardLabels = new ArrayList<>();
|
||||||
|
|
||||||
callback.onPermissionSummaryResult(counts, groups);
|
for (int i = 0; i < permissionCount; i++) {
|
||||||
|
RuntimePermissionPresentationInfo permission = permissions.get(i);
|
||||||
context.unregisterReceiver(this);
|
requestedCount++;
|
||||||
|
if (permission.isGranted()) {
|
||||||
|
if (permission.isStandard()) {
|
||||||
|
grantedStandardLabels.add(permission.getLabel());
|
||||||
|
grantedStandardCount++;
|
||||||
|
} else {
|
||||||
|
grantedAdditionalCount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
context.registerReceiver(receiver, new IntentFilter(action));
|
|
||||||
request.putExtra(Intent.EXTRA_GET_PERMISSIONS_RESPONSE_INTENT, action);
|
|
||||||
request.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
|
||||||
context.sendBroadcast(request);
|
|
||||||
return receiver;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface PermissionsResultCallback {
|
Collator collator = Collator.getInstance();
|
||||||
void onPermissionSummaryResult(int[] counts, CharSequence[] groupLabels);
|
collator.setStrength(Collator.PRIMARY);
|
||||||
|
Collections.sort(grantedStandardLabels, collator);
|
||||||
|
|
||||||
|
callback.onPermissionSummaryResult(grantedStandardCount, requestedCount,
|
||||||
|
grantedAdditionalCount, grantedStandardLabels);
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class PermissionsResultCallback {
|
||||||
|
public void onAppWithPermissionsCountsResult(int standardGrantedPermissionAppCount,
|
||||||
|
int standardUsedPermissionAppCount) {
|
||||||
|
/* do nothing - stub */
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPermissionSummaryResult(int standardGrantedPermissionCount,
|
||||||
|
int requestedPermissionCount, int additionalGrantedPermissionCount,
|
||||||
|
List<CharSequence> grantedGroupLabels) {
|
||||||
|
/* do nothing - stub */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user