From 67e067fff4e4ef1eb54f9c238dbf07312434a07e Mon Sep 17 00:00:00 2001 From: Svet Ganov Date: Sat, 16 May 2015 22:59:38 -0700 Subject: Hide platform platform legacy permissions behind a menu option - settings. bug:21195624 Change-Id: Ib1dcfe2a15685c36e2a59e0921ea74d46ec9738c --- res/xml/advanced_apps.xml | 1 - .../settings/applications/AdvancedAppSettings.java | 34 +--- .../settings/applications/ManagePermissions.java | 192 --------------------- 3 files changed, 8 insertions(+), 219 deletions(-) delete mode 100644 src/com/android/settings/applications/ManagePermissions.java diff --git a/res/xml/advanced_apps.xml b/res/xml/advanced_apps.xml index 323dca19b..1e2d51653 100644 --- a/res/xml/advanced_apps.xml +++ b/res/xml/advanced_apps.xml @@ -36,7 +36,6 @@ diff --git a/src/com/android/settings/applications/AdvancedAppSettings.java b/src/com/android/settings/applications/AdvancedAppSettings.java index 268bc5baf..0d2f206e6 100644 --- a/src/com/android/settings/applications/AdvancedAppSettings.java +++ b/src/com/android/settings/applications/AdvancedAppSettings.java @@ -15,11 +15,10 @@ */ package com.android.settings.applications; -import android.app.Activity; +import android.content.Intent; import android.content.pm.ApplicationInfo; import android.os.Bundle; import android.preference.Preference; -import android.util.Log; import com.android.internal.logging.MetricsLogger; import com.android.settings.R; @@ -27,36 +26,34 @@ import com.android.settings.SettingsPreferenceFragment; import com.android.settings.applications.ApplicationsState.AppEntry; import com.android.settings.applications.ApplicationsState.Session; import com.android.settings.fuelgauge.PowerWhitelistBackend; -import com.android.settingslib.applications.PermissionsInfo; import java.util.ArrayList; public class AdvancedAppSettings extends SettingsPreferenceFragment implements - ApplicationsState.Callbacks, PermissionsInfo.Callback { + ApplicationsState.Callbacks { static final String TAG = "AdvancedAppSettings"; - static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final String KEY_APP_PERM = "manage_perms"; private static final String KEY_APP_DOMAIN_URLS = "domain_urls"; private static final String KEY_HIGH_POWER_APPS = "high_power_apps"; - private ApplicationsState mApplicationsState; private Session mSession; - private Preference mAppPermsPreference; private Preference mAppDomainURLsPreference; private Preference mHighPowerPreference; - private PermissionsInfo mPermissionsInfo; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); addPreferencesFromResource(R.xml.advanced_apps); - mApplicationsState = ApplicationsState.getInstance(getActivity().getApplication()); - mSession = mApplicationsState.newSession(this); + Preference permissions = getPreferenceScreen().findPreference(KEY_APP_PERM); + permissions.setIntent(new Intent(Intent.ACTION_MANAGE_PERMISSIONS)); + + ApplicationsState applicationsState = ApplicationsState.getInstance( + getActivity().getApplication()); + mSession = applicationsState.newSession(this); - mAppPermsPreference = findPreference(KEY_APP_PERM); mAppDomainURLsPreference = findPreference(KEY_APP_DOMAIN_URLS); mHighPowerPreference = findPreference(KEY_HIGH_POWER_APPS); updateUI(); @@ -85,12 +82,6 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements return MetricsLogger.APPLICATIONS_ADVANCED; } - @Override - public void onResume() { - super.onResume(); - mPermissionsInfo = new PermissionsInfo(getActivity(), this); - } - @Override public void onRunningStateChanged(boolean running) { // No-op. @@ -130,13 +121,4 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements public void onLoadEntriesCompleted() { // No-op. } - - @Override - public void onPermissionLoadComplete() { - Activity activity = getActivity(); - if (activity == null) return; -// mAppPermsPreference.setSummary(activity.getString(R.string.app_permissions_summary, -// mPermissionsInfo.getRuntimePermAppsGrantedCount(), -// mPermissionsInfo.getRuntimePermAppsCount())); - } } diff --git a/src/com/android/settings/applications/ManagePermissions.java b/src/com/android/settings/applications/ManagePermissions.java deleted file mode 100644 index 35356e540..000000000 --- a/src/com/android/settings/applications/ManagePermissions.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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.app.Activity; -import android.app.FragmentTransaction; -import android.content.ActivityNotFoundException; -import android.content.Context; -import android.content.Intent; -import android.content.res.Resources; -import android.content.res.Resources.Theme; -import android.os.Bundle; -import android.preference.Preference; -import android.preference.Preference.OnPreferenceClickListener; -import android.preference.PreferenceScreen; -import android.util.Log; -import android.view.View; - -import com.android.internal.logging.MetricsLogger; -import com.android.settings.AppHeader; -import com.android.settings.R; -import com.android.settings.SettingsPreferenceFragment; -import com.android.settingslib.applications.PermissionsInfo; -import com.android.settingslib.applications.PermissionsInfo.PermissionGroup; - -import java.util.List; - -public class ManagePermissions extends SettingsPreferenceFragment - implements PermissionsInfo.Callback { - - private static final String TAG = "ManagePermissions"; - - private static final String OS_PKG = "android"; - - private PermissionsInfo mPermissionsInfo; - - private PreferenceScreen mExtraScreen; - - @Override - public void onResume() { - super.onResume(); - - mPermissionsInfo = new PermissionsInfo(getActivity(), this); - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - showLoadingWhenEmpty(); - } - - private void refreshUi() { - Activity activity = getActivity(); - PreferenceScreen screen = getPreferenceScreen(); - if (screen == null) { - screen = getPreferenceManager().createPreferenceScreen(activity); - setPreferenceScreen(screen); - } else { - screen.removeAll(); - if (mExtraScreen != null) { - mExtraScreen.removeAll(); - } - } - final int count = screen.getPreferenceCount(); - if (count == 0) { - final Preference extraScreenPreference = new Preference(activity); - extraScreenPreference.setIcon(R.drawable.ic_toc); - extraScreenPreference.setTitle(R.string.additional_permissions); - List groups = mPermissionsInfo.getGroups(); - for (PermissionGroup group : groups) { - if (group.possibleApps.size() == 0) continue; - PermissionPreference pref = new PermissionPreference(activity, group); - pref.refreshUi(); - if (group.packageName.equals(OS_PKG)) { - screen.addPreference(pref); - } else { - if (mExtraScreen == null) { - mExtraScreen = getPreferenceManager().createPreferenceScreen(activity); - } - mExtraScreen.addPreference(pref); - } - } - if (mExtraScreen != null) { - extraScreenPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - AdditionalPermissionsFragment frag = new AdditionalPermissionsFragment(); - frag.setTargetFragment(ManagePermissions.this, 0); - FragmentTransaction ft = getFragmentManager().beginTransaction(); - ft.replace(R.id.main_content, frag); - ft.addToBackStack("AdditionalPerms"); - ft.commit(); - return true; - } - }); - extraScreenPreference.setSummary(getString(R.string.additional_permissions_more, - mExtraScreen.getPreferenceCount())); - screen.addPreference(extraScreenPreference); - } - } else { - updatePrefs(screen); - if (mExtraScreen != null) { - updatePrefs(mExtraScreen); - } - } - } - - private void updatePrefs(PreferenceScreen screen) { - for (int i = 0; i < screen.getPreferenceCount(); i++) { - Preference pref = screen.getPreference(i); - if (pref instanceof PermissionPreference) { - ((PermissionPreference) pref).refreshUi(); - } - } - } - - @Override - public void onPermissionLoadComplete() { - refreshUi(); - } - - @Override - protected int getMetricsCategory() { - return MetricsLogger.MANAGE_PERMISSIONS; - } - - private class PermissionPreference extends Preference implements OnPreferenceClickListener { - private final PermissionGroup mGroup; - - public PermissionPreference(Context context, PermissionGroup group) { - super(context); - setOnPreferenceClickListener(this); - mGroup = group; - } - - public void refreshUi() { - setTitle(mGroup.label); - setIcon(mGroup.icon); -// setSummary(getContext().getString(R.string.app_permissions_group_summary, -// mGroup.grantedApps.size(), mGroup.possibleApps.size())); - } - - @Override - public boolean onPreferenceClick(Preference preference) { - Intent i = new Intent(Intent.ACTION_MANAGE_PERMISSION_APPS) - .putExtra(Intent.EXTRA_PERMISSION_NAME, mGroup.name); - try { - getActivity().startActivity(i); - } catch (ActivityNotFoundException e) { - Log.w(TAG, "No app to handle " + i.getAction()); - } - return true; - } - } - - public static class AdditionalPermissionsFragment extends SettingsPreferenceFragment { - @Override - public void onCreate(Bundle icicle) { - super.onCreate(icicle); - setPreferenceScreen(((ManagePermissions) getTargetFragment()).mExtraScreen); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - Resources resources = getResources(); - Theme theme = getActivity().getTheme(); - AppHeader.createAppHeader(this, resources.getDrawable(R.drawable.ic_toc, theme), - getString(R.string.additional_permissions), null, android.R.color.white); - } - - @Override - protected int getMetricsCategory() { - return MetricsLogger.MANAGE_PERMISSIONS; - } - } - -} -- cgit v1.2.3