summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2016-09-05 09:14:26 +0200
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-09-09 11:54:55 -0700
commit8ebe1736d53e80b55f862ab73427cf0f295d0d37 (patch)
tree894348d218369ac1af5e00a92229348c88f8d551 /src/com/android
parent31be1080addd6860b16aef708c1052f8c7d3b663 (diff)
downloadpackages_apps_Settings-8ebe1736d53e80b55f862ab73427cf0f295d0d37.zip
packages_apps_Settings-8ebe1736d53e80b55f862ab73427cf0f295d0d37.tar.gz
packages_apps_Settings-8ebe1736d53e80b55f862ab73427cf0f295d0d37.tar.bz2
Fix AIOOBE with root access disabled.
Page title and template array lengths got out of sync if root access was disabled. Make sure this doesn't happen anymore by combining titles and templates into a single list prior to filtering. Change-Id: I069db9b9925887d6d80592eabe93b33abeaf0fe8 JIRA: CYAN-8028
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/settings/applications/AppOpsSummary.java63
1 files changed, 33 insertions, 30 deletions
diff --git a/src/com/android/settings/applications/AppOpsSummary.java b/src/com/android/settings/applications/AppOpsSummary.java
index faefb65..4ec390d 100644
--- a/src/com/android/settings/applications/AppOpsSummary.java
+++ b/src/com/android/settings/applications/AppOpsSummary.java
@@ -32,6 +32,7 @@ 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;
@@ -62,37 +63,35 @@ public class AppOpsSummary extends InstrumentedFragment {
private Activity mActivity;
private SharedPreferences mPreferences;
- CharSequence[] mPageNames;
-
- int mCurPos;
- int mPositionOffset;
-
@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[mPositionOffset + position]);
+ return new AppOpsCategory(mPageData.get(position).second);
}
@Override
public int getCount() {
- return mPageNames.length;
+ return mPageData.size();
}
@Override
public CharSequence getPageTitle(int position) {
- return mPageNames[position];
+ return mPageData.get(position).first;
}
@Override
@@ -134,23 +133,24 @@ public class AppOpsSummary extends InstrumentedFragment {
mContentContainer = container;
mRootView = rootView;
- mPageNames = getResources().getTextArray(R.array.app_ops_categories_cm);
-
- mPositionOffset = 0;
+ CharSequence[] pageNames = getResources().getTextArray(R.array.app_ops_categories_cm);
+ AppOpsState.OpsTemplate[] templates = AppOpsState.ALL_TEMPLATES;
+ assert(pageNames.length == templates.length);
int specificTab = -1;
Bundle bundle = getArguments();
if (bundle != null) {
- specificTab = Arrays.asList(mPageNames).indexOf(bundle.getString("appops_tab", ""));
- if (specificTab >= 0) {
- mPageNames = Arrays.copyOfRange(mPageNames, specificTab, specificTab + 1);
- mPositionOffset = specificTab;
- }
+ 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);
mViewPager.setOnPageChangeListener(mAdapter);
PagerTabStrip tabs = (PagerTabStrip) rootView.findViewById(R.id.tabs);
@@ -174,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() {