Skip to content

Commit 8036358

Browse files
committed
getContext should not be used as it is introduced in API 23
Override getContext function to return activtiy context to avoid similar crash in the future. It works in our case as our fragments are always added into an activtiy. The proper fix should be using support v4 PreferenceFragment, but given that we are going to release the testdpc soon, I prefer to have this temp fix first. Bug: 27491077 Change-Id: Ifebdd7217282d8c55207cd719dc1a970c374d41f
1 parent 633ef38 commit 8036358

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

app/src/main/java/com/afwsamples/testdpc/common/ProfileOrParentFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ protected final boolean isManagedProfileInstance() {
141141
return mProfileOwner && !isParentProfileInstance();
142142
}
143143

144+
@Override
145+
public Context getContext() {
146+
return (Context) getActivity();
147+
}
148+
144149
@Override
145150
public void onCreate(Bundle savedInstanceState) {
146151
super.onCreate(savedInstanceState);

app/src/main/java/com/afwsamples/testdpc/policy/PolicyManagementFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,4 +2071,9 @@ private void reboot() {
20712071
abstract class ManageLockTaskListCallback {
20722072
public abstract void onPositiveButtonClicked(String[] lockTaskArray);
20732073
}
2074+
2075+
@Override
2076+
public Context getContext() {
2077+
return (Context) getActivity();
2078+
}
20742079
}

app/src/main/java/com/afwsamples/testdpc/profilepolicy/ProfilePolicyManagementFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,9 @@ private void disableIncompatibleManagementOptionsByApiLevel() {
401401
}
402402
}
403403
}
404+
405+
@Override
406+
public Context getContext() {
407+
return (Context) getActivity();
408+
}
404409
}

0 commit comments

Comments
 (0)