Skip to content

Commit 309aa3e

Browse files
Adnan BegovicPRJosh
authored andcommitted
Settings: Fix inflate exception on search. Dynamically replace nested fragment.
When PrivacyGuard is opened, the parent fragment would inflate the layout which contained a nested fragment. This is bad behavior. Since we couldn't keep track of the fragments lifecycle, the fragment we instantiated during inflation would cause an inflate exception if and when we toggled the search view within the current context. Mitigate the crash by programmatically replacing the fragment after instantiating it once. AndroidRuntime E FATAL EXCEPTION: main E Process: com.android.settings, PID: 12372 E android.view.InflateException: Binary XML file line SlimRoms#21: Error inflating class fragment E at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763) E at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) E at android.view.LayoutInflater.inflate(LayoutInflater.java:504) ... E Caused by: java.lang.IllegalArgumentException: Binary XML file line SlimRoms#21: Duplicate id 0x7f1001a2, tag nul l, or parent id 0xffffffff with another fragment for com.android.settings.privacyguard.PrivacyGuardPrefs E at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2120) E at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:177) E at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733) E ... 25 more Change-Id: I6820ad7d35814f150eedf91140e21c0b8e23322b
1 parent 354d52c commit 309aa3e

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

res/layout/privacy_guard_manager.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
android:orientation="vertical"
1919
android:layout_width="match_parent"
2020
android:layout_height="match_parent">
21-
<fragment
21+
<FrameLayout
2222
android:id="@+id/privacy_guard_prefs"
23-
android:name="com.android.settings.privacyguard.PrivacyGuardPrefs"
2423
android:layout_width="match_parent"
2524
android:layout_height="wrap_content" />
2625
<View

src/com/android/settings/privacyguard/PrivacyGuardManager.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.android.settings.privacyguard;
1818

19+
import android.app.FragmentTransaction;
1920
import android.view.animation.AnimationUtils;
2021
import android.app.Activity;
2122
import android.app.AlertDialog;
@@ -84,6 +85,9 @@ public class PrivacyGuardManager extends Fragment
8485
private final static String LAST_LIST_POS = "last_list_pos";
8586
private final static String LAST_LIST_OFFSET = "last_list_offset";
8687

88+
// Privacy Guard Fragment
89+
private final static String PRIVACY_GUARD_FRAGMENT_TAG = "privacy_guard_fragment";
90+
8791
// holder for package data passed into the adapter
8892
public static final class AppInfo {
8993
String title;
@@ -96,21 +100,17 @@ public static final class AppInfo {
96100
@Override
97101
public View onCreateView(LayoutInflater inflater, ViewGroup container,
98102
Bundle savedInstanceState) {
99-
100103
mActivity = getActivity();
101104
mAppOps = (AppOpsManager)getActivity().getSystemService(Context.APP_OPS_SERVICE);
102105

103-
return inflater.inflate(R.layout.privacy_guard_manager, container, false);
104-
}
106+
View hostView = inflater.inflate(R.layout.privacy_guard_manager, container, false);
105107

106-
@Override
107-
public void onDestroyView() {
108-
super.onDestroyView();
109-
FragmentManager fm = getFragmentManager();
110-
Fragment f = fm.findFragmentById(R.id.privacy_guard_prefs);
111-
if (f != null && !fm.isDestroyed()) {
112-
fm.beginTransaction().remove(f).commit();
113-
}
108+
Fragment privacyGuardPrefs = PrivacyGuardPrefs.newInstance();
109+
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
110+
fragmentTransaction.replace(R.id.privacy_guard_prefs, privacyGuardPrefs,
111+
PRIVACY_GUARD_FRAGMENT_TAG);
112+
fragmentTransaction.commit();
113+
return hostView;
114114
}
115115

116116
@Override

src/com/android/settings/privacyguard/PrivacyGuardPrefs.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616

1717
package com.android.settings.privacyguard;
1818

19-
import android.app.Activity;
20-
import android.content.Context;
2119
import android.os.Bundle;
2220
import android.preference.Preference;
2321
import android.preference.Preference.OnPreferenceChangeListener;
24-
import android.preference.PreferenceScreen;
2522
import android.preference.SwitchPreference;
2623
import android.provider.Settings;
27-
import android.provider.Settings.SettingNotFoundException;
2824
import android.view.LayoutInflater;
2925
import android.view.View;
3026
import android.view.ViewGroup;
@@ -44,12 +40,16 @@ public class PrivacyGuardPrefs extends SettingsPreferenceFragment implements
4440

4541
private SwitchPreference mPrivacyGuardDefault;
4642

43+
public static PrivacyGuardPrefs newInstance() {
44+
PrivacyGuardPrefs privacyGuardFragment = new PrivacyGuardPrefs();
45+
return privacyGuardFragment;
46+
}
47+
4748
@Override
4849
public void onCreate(Bundle savedInstanceState) {
4950
super.onCreate(savedInstanceState);
5051

5152
addPreferencesFromResource(R.xml.privacy_guard_prefs);
52-
PreferenceScreen prefSet = getPreferenceScreen();
5353

5454
mPrivacyGuardDefault = (SwitchPreference) findPreference(KEY_PRIVACY_GUARD_DEFAULT);
5555
mPrivacyGuardDefault.setOnPreferenceChangeListener(this);

0 commit comments

Comments
 (0)