summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/applications/AppOpsSummary.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/applications/AppOpsSummary.java')
-rw-r--r--src/com/android/settings/applications/AppOpsSummary.java71
1 files changed, 42 insertions, 29 deletions
diff --git a/src/com/android/settings/applications/AppOpsSummary.java b/src/com/android/settings/applications/AppOpsSummary.java
index be153de..4ec390d 100644
--- a/src/com/android/settings/applications/AppOpsSummary.java
+++ b/src/com/android/settings/applications/AppOpsSummary.java
@@ -26,11 +26,13 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.content.SharedPreferences;
+import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceFrameLayout;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
+import android.util.Pair;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -61,36 +63,35 @@ public class AppOpsSummary extends InstrumentedFragment {
private Activity mActivity;
private SharedPreferences mPreferences;
- CharSequence[] mPageNames;
-
- int mCurPos;
-
@Override
protected int getMetricsCategory() {
return MetricsLogger.APP_OPS_SUMMARY;
}
- class MyPagerAdapter extends FragmentPagerAdapter implements ViewPager.OnPageChangeListener {
- private AppOpsState.OpsTemplate[] mPageTemplates;
+ static class MyPagerAdapter extends FragmentPagerAdapter
+ implements ViewPager.OnPageChangeListener {
+ private List<Pair<CharSequence, AppOpsState.OpsTemplate>> mPageData;
+ private int mCurPos;
- public MyPagerAdapter(FragmentManager fm, AppOpsState.OpsTemplate[] templates) {
+ public MyPagerAdapter(FragmentManager fm,
+ List<Pair<CharSequence, AppOpsState.OpsTemplate>> data) {
super(fm);
- mPageTemplates = templates;
+ mPageData = data;
}
@Override
public Fragment getItem(int position) {
- return new AppOpsCategory(mPageTemplates[position]);
+ return new AppOpsCategory(mPageData.get(position).second);
}
@Override
public int getCount() {
- return mPageTemplates.length;
+ return mPageData.size();
}
@Override
public CharSequence getPageTitle(int position) {
- return mPageNames[position];
+ return mPageData.get(position).first;
}
@Override
@@ -132,21 +133,25 @@ public class AppOpsSummary extends InstrumentedFragment {
mContentContainer = container;
mRootView = rootView;
- mPageNames = getResources().getTextArray(R.array.app_ops_categories_cm);
+ CharSequence[] pageNames = getResources().getTextArray(R.array.app_ops_categories_cm);
+ AppOpsState.OpsTemplate[] templates = AppOpsState.ALL_TEMPLATES;
+ assert(pageNames.length == templates.length);
- int defaultTab = -1;
+ int specificTab = -1;
Bundle bundle = getArguments();
if (bundle != null) {
- defaultTab = Arrays.asList(mPageNames).indexOf(bundle.getString("appops_tab", ""));
+ specificTab = Arrays.asList(pageNames).indexOf(bundle.getString("appops_tab", ""));
+ }
+
+ List<Pair<CharSequence, AppOpsState.OpsTemplate>> pageData = new ArrayList<>();
+ for (int i = 0; i < pageNames.length; i++) {
+ pageData.add(Pair.create(pageNames[i], templates[i]));
}
+ filterPageData(pageData, specificTab);
mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
- mAdapter = new MyPagerAdapter(getChildFragmentManager(),
- filterTemplates(AppOpsState.ALL_TEMPLATES));
+ mAdapter = new MyPagerAdapter(getChildFragmentManager(), pageData);
mViewPager.setAdapter(mAdapter);
- if (defaultTab >= 0) {
- mViewPager.setCurrentItem(defaultTab);
- }
mViewPager.setOnPageChangeListener(mAdapter);
PagerTabStrip tabs = (PagerTabStrip) rootView.findViewById(R.id.tabs);
@@ -169,16 +174,19 @@ public class AppOpsSummary extends InstrumentedFragment {
return rootView;
}
- private AppOpsState.OpsTemplate[] filterTemplates(AppOpsState.OpsTemplate[] templates) {
- List<AppOpsState.OpsTemplate> validTemplates = new ArrayList(templates.length);
- for (AppOpsState.OpsTemplate template : templates) {
- if (template == AppOpsState.SU_TEMPLATE
- && !DevelopmentSettings.isRootForAppsEnabled()) {
- continue;
+ private void filterPageData(List<Pair<CharSequence, AppOpsState.OpsTemplate>> data, int tab) {
+ if (tab >= 0 && tab < data.size()) {
+ Pair<CharSequence, AppOpsState.OpsTemplate> item = data.get(tab);
+ data.clear();
+ data.add(item);
+ } else if (!DevelopmentSettings.isRootForAppsEnabled()) {
+ for (Pair<CharSequence, AppOpsState.OpsTemplate> item : data) {
+ if (item.second == AppOpsState.SU_TEMPLATE) {
+ data.remove(item);
+ return;
+ }
}
- validTemplates.add(template);
}
- return validTemplates.toArray(new AppOpsState.OpsTemplate[0]);
}
private boolean shouldShowUserApps() {
@@ -186,7 +194,8 @@ public class AppOpsSummary extends InstrumentedFragment {
}
private boolean shouldShowSystemApps() {
- return mPreferences.getBoolean("show_system_apps", true);
+ return mPreferences.getBoolean("show_system_apps", true) &&
+ mActivity.getResources().getBoolean(R.bool.config_showBuiltInAppsForPG);
}
@Override
@@ -204,7 +213,11 @@ public class AppOpsSummary extends InstrumentedFragment {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.appops_manager, menu);
menu.findItem(R.id.show_user_apps).setChecked(shouldShowUserApps());
- menu.findItem(R.id.show_system_apps).setChecked(shouldShowSystemApps());
+ if (!mActivity.getResources().getBoolean(R.bool.config_showBuiltInAppsForPG)) {
+ menu.removeItem(R.id.show_system_apps);
+ } else {
+ menu.findItem(R.id.show_system_apps).setChecked(shouldShowSystemApps());
+ }
}
private void resetCounters() {