Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0439854b authored by Robin Lee's avatar Robin Lee
Browse files

Fix two common NPEs, remove TV radio widget layout

TV layout:
 - Removed because the code specifically depends on a certain layout
   ID which was not in sync with the handheld layout ID. The custom
   layout wasn't adding any value anyway.

NPE 1 (ManagePermissionsFragment):
 - Using the wrong context in ManagePermissionsFragment. We get the
   right context and explicitly null-check it, but one line in the
   update function was going and getting its own context from
   somewhere else and this could be null.

NPE 2 (FooterPreference):
 - TV currently reuses handheld code. The reason this code runs into
   a NullPointerException on ATV and not mobile currently is that one
   uses a DeviceDefault theme and the other does not.

   Interestingly, the resource ID for the icon_frame ViewGroup is
   different depending on where the theme comes from! This is fixed in
   other classes in PermissionController already.

   See this commit in AndroidX from 2015 for an example (unfortunately
   original bug isn't documented):

   https://android.googlesource.com/platform/frameworks/support/+/3fadd62b614e4a69aefe920aac640bdb629e502e%5E%21/v7/preference/src/android/support/v7/preference/Preference.java

Fix: 160262096
Test: atest AutoRevokeTest # 5 tests, 4 pass, 1 fail (ki)
Test: atest CtsRoleTestCases # 55 tests, 43 pass, 12 skipped
Change-Id: Ia579144f308076804642728dcc1e103f4b645e7b
parent 6cb5fcd7
Loading
Loading
Loading
Loading
+0 −25
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>

<!--
  ~ Copyright (C) 2020 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.
  -->

<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:focusable="false"
    android:clickable="false" />
+1 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ public final class ManagePermissionsFragment extends SettingsWithHeader

        // Use this to speed up getting the info for all of the PermissionApps below.
        // Create a new one for each refresh to make sure it has fresh data.
        PmCache cache = new PmCache(getContext().getPackageManager());
        PmCache cache = new PmCache(context.getPackageManager());
        for (PermissionGroup group : groups) {
            boolean isSystemPermission = group.getDeclaringPackage().equals(OS_PKG);

+3 −2
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ public class RadioButtonPreference extends Preference {
    @Override
    public void onBindViewHolder(PreferenceViewHolder viewHolder) {
        super.onBindViewHolder(viewHolder);
        final RadioButton rb = (RadioButton) viewHolder.findViewById(android.R.id.checkbox);
        final RadioButton rb = (RadioButton) viewHolder.findViewById(R.id.radio_button);
        rb.setChecked(mIsChecked);
        mViewHolder = viewHolder;
    }
@@ -54,7 +54,8 @@ public class RadioButtonPreference extends Preference {
    public void setChecked(boolean isChecked) {
        mIsChecked = isChecked;
        if (mViewHolder != null) {
            ((RadioButton) mViewHolder.findViewById(android.R.id.checkbox)).setChecked(mIsChecked);
            ((RadioButton) mViewHolder.findViewById(R.id.radio_button))
                    .setChecked(mIsChecked);
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -79,6 +79,9 @@ public class FooterPreference extends Preference {
        holder.setDividerAllowedAbove(true);

        View iconFrame = holder.findViewById(R.id.icon_frame);
        if (iconFrame == null) {
            iconFrame = holder.findViewById(android.R.id.icon_frame);
        }
        LinearLayout.LayoutParams iconFrameLayoutParams = (LinearLayout.LayoutParams)
                iconFrame.getLayoutParams();
        iconFrameLayoutParams.gravity = Gravity.TOP;