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

Commit 4ef09fd4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add themed icons." into qt-r1-dev

parents 262a2fcb ac1c3107
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@
    <item>@*android:drawable/ic_wifi_signal_3</item>
    <item>@*android:drawable/ic_wifi_signal_4</item>
    <item>@*android:drawable/perm_group_activity_recognition</item>
    <item>@*android:drawable/perm_group_aural</item>
    <item>@*android:drawable/perm_group_calendar</item>
    <item>@*android:drawable/perm_group_call_log</item>
    <item>@*android:drawable/perm_group_camera</item>
+192 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

package com.android.systemui;

import static junit.framework.Assert.fail;

import static org.junit.Assert.assertEquals;

import android.annotation.DrawableRes;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.text.TextUtils;
import android.util.TypedValue;

import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.util.XmlUtils;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

@RunWith(AndroidJUnit4.class)
@MediumTest
public class IconPackOverlayTest extends SysuiTestCase {

    private static final String[] ICON_PACK_OVERLAY_PACKAGES = {
            "com.android.theme.icon_pack.circular.systemui",
            "com.android.theme.icon_pack.rounded.systemui",
            "com.android.theme.icon_pack.filled.systemui",
    };

    private static final int[] VECTOR_ATTRIBUTES = {
            android.R.attr.tint,
            android.R.attr.height,
            android.R.attr.width,
            android.R.attr.alpha,
            android.R.attr.autoMirrored,
    };

    private final TypedValue mTargetTypedValue = new TypedValue();
    private final TypedValue mOverlayTypedValue = new TypedValue();

    private Resources mResources;
    private TypedArray mOverlayableIcons;

    @Before
    public void setup() {
        mResources = mContext.getResources();
        mOverlayableIcons = mResources.obtainTypedArray(R.array.overlayable_icons);
    }

    @After
    public void teardown() {
        mOverlayableIcons.recycle();
    }

    /**
     * Ensure that all icons contained in overlayable_icons_test.xml exist in all 3 overlay icon
     * packs for systemui. This test fails if you remove or rename an overlaid icon. If so,
     * make the same change to the corresponding drawables in {@link #ICON_PACK_OVERLAY_PACKAGES}.
     */
    @Test
    public void testIconPack_containAllOverlayedIcons() {
        StringBuilder errors = new StringBuilder();

        for (String overlayPackage : ICON_PACK_OVERLAY_PACKAGES) {
            Resources overlayResources;
            try {
                overlayResources = mContext.getPackageManager()
                        .getResourcesForApplication(overlayPackage);
            } catch (PackageManager.NameNotFoundException e) {
                continue; // No need to test overlay resources if apk is not on the system.
            }

            for (int i = 0; i < mOverlayableIcons.length(); i++) {
                int sysuiRid = mOverlayableIcons.getResourceId(i, 0);
                String sysuiResourceName = mResources.getResourceName(sysuiRid);
                String overlayResourceName = sysuiResourceName
                        .replace(mContext.getPackageName(), overlayPackage);
                if (overlayResources.getIdentifier(overlayResourceName, null, null)
                        == Resources.ID_NULL) {
                    errors.append(String.format("[%s] is not contained in overlay package [%s]",
                            overlayResourceName, overlayPackage));
                }
            }
        }

        if (!TextUtils.isEmpty(errors)) {
            fail(errors.toString());
        }
    }

    /**
     * Ensures that all overlay icons have the same values for {@link #VECTOR_ATTRIBUTES} as the
     * underlying drawable in systemui. To fix this test, make the attribute change to all of the
     * corresponding drawables in {@link #ICON_PACK_OVERLAY_PACKAGES}.
     */
    @Test
    public void testIconPacks_haveEqualVectorDrawableAttributes() {
        StringBuilder errors = new StringBuilder();

        for (String overlayPackage : ICON_PACK_OVERLAY_PACKAGES) {
            Resources overlayResources;
            try {
                overlayResources = mContext.getPackageManager()
                        .getResourcesForApplication(overlayPackage);
            } catch (PackageManager.NameNotFoundException e) {
                continue; // No need to test overlay resources if apk is not on the system.
            }

            for (int i = 0; i < mOverlayableIcons.length(); i++) {
                int sysuiRid = mOverlayableIcons.getResourceId(i, 0);
                String sysuiResourceName = mResources.getResourceName(sysuiRid);
                TypedArray sysuiAttrs = getAVDAttributes(mResources, sysuiRid);
                if (sysuiAttrs == null) {
                    errors.append(String.format("[%s] does not exist or is not a valid AVD.",
                            sysuiResourceName));
                    continue;
                }

                String overlayResourceName = sysuiResourceName
                        .replace(mContext.getPackageName(), overlayPackage);
                int overlayRid = overlayResources.getIdentifier(overlayResourceName, null, null);
                TypedArray overlayAttrs = getAVDAttributes(overlayResources, overlayRid);
                if (overlayAttrs == null) {
                    errors.append(String.format("[%s] does not exist or is not a valid AVD.",
                            overlayResourceName));
                    continue;
                }

                if (!attributesEquals(sysuiAttrs, overlayAttrs)) {
                    errors.append(String.format("[%s] AVD attributes do not match [%s]\n",
                            sysuiResourceName, overlayResourceName));
                }
                sysuiAttrs.recycle();
                overlayAttrs.recycle();
            }
        }

        if (!TextUtils.isEmpty(errors)) {
            fail(errors.toString());
        }
    }

    private TypedArray getAVDAttributes(Resources resources, @DrawableRes int rid) {
        try {
            XmlResourceParser parser = resources.getXml(rid);
            XmlUtils.nextElement(parser);
            return resources.obtainAttributes(parser, VECTOR_ATTRIBUTES);
        } catch (XmlPullParserException | IOException  | Resources.NotFoundException e) {
            return null;
        }
    }

    private boolean attributesEquals(TypedArray target, TypedArray overlay) {
        assertEquals(target.length(), overlay.length());
        for (int i = 0; i < target.length(); i++) {
            target.getValue(i, mTargetTypedValue);
            overlay.getValue(i, mOverlayTypedValue);
            if (!attributesEquals(mTargetTypedValue, mOverlayTypedValue)) {
                return false;
            }
        }
        return true;
    }

    private boolean attributesEquals(TypedValue target, TypedValue overlay) {
        return target.type == overlay.type && target.data == overlay.data;
    }
}
+40 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
   Copyright (C) 2019 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="24dp"
    android:tint="?android:attr/colorControlNormal"
    android:viewportHeight="24"
    android:viewportWidth="24"
    android:width="24dp" >
    <group
        android:translateX="2.000000"
        android:translateY="2.000000" >
        <path
            android:fillColor="@android:color/white"
            android:fillType="evenOdd"
            android:pathData="M12.64,3 L12.64,8.82352941 C12.2536,8.5 11.772,8.29411765 11.24,8.29411765 C10.0024,8.29411765 9,9.34705882 9,10.6470588 C9,11.9470588 10.0024,13 11.24,13 C12.4776,13 13.48,11.9470588 13.48,10.6470588 L13.48,5.00157166 L15.02,5.00157166 C15.5576,5.00157166 16,4.53686577 16,3.97215989 L16,3 L12.64,3 Z"
            android:strokeWidth="1" />
        <path
            android:fillColor="@android:color/white"
            android:pathData="M20,2 C20,0.9 19.1,0 18,0 L6,0 C4.9,0 4,0.9 4,2 L4,14 C4,15.1 4.9,16 6,16 L18,16 C19.1,16 20,15.1 20,14 L20,2 Z M18.5,14 C18.5,14.28 18.28,14.5 18,14.5 L6,14.5 C5.72,14.5 5.5,14.28 5.5,14 L5.5,2 C5.5,1.72 5.72,1.5 6,1.5 L18,1.5 C18.28,1.5 18.5,1.72 18.5,2 L18.5,14 Z"
            android:strokeWidth="1" />
        <path
            android:fillColor="@android:color/white"
            android:pathData="M0.5,4.75 L0.5,16.75 C0.5,18.27 1.73,19.5 3.25,19.5 L15.25,19.5 C15.66,19.5 16,19.16 16,18.75 C16,18.34 15.66,18 15.25,18 L3.25,18 C2.56,18 2,17.44 2,16.75 L2,4.75 C2,4.34 1.66,4 1.25,4 C0.84,4 0.5,4.34 0.5,4.75 Z"
            android:strokeWidth="1" />
    </group>
</vector>
 No newline at end of file
+37 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
   Copyright (C) 2019 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="24dp"
    android:tint="?android:attr/colorControlNormal"
    android:viewportHeight="24"
    android:viewportWidth="24"
    android:width="24dp" >
    <group
        android:translateX="1.000000"
        android:translateY="2.000000" >
        <path
            android:fillColor="@android:color/white"
            android:fillType="evenOdd"
            android:pathData="M11,18.5 C6.313,18.5 2.5,14.687 2.5,10 C2.5,8.182 3.078,6.498 4.055,5.114 L15.887,16.945 C14.503,17.922 12.818,18.5 11,18.5 M20.031,18.969 L2.032,0.971 C1.739,0.678 1.264,0.678 0.971,0.971 C0.678,1.264 0.678,1.738 0.971,2.031 L2.983,4.043 C1.742,5.707 1,7.765 1,10 C1,15.522 5.477,20 11,20 C13.236,20 15.293,19.258 16.957,18.017 L18.971,20.029 C19.117,20.176 19.309,20.249 19.501,20.249 C19.693,20.249 19.885,20.176 20.031,20.029 C20.324,19.736 20.324,19.262 20.031,18.969"
            android:strokeWidth="1" />
        <path
            android:fillColor="@android:color/white"
            android:fillType="evenOdd"
            android:pathData="M11,1.5 C15.687,1.5 19.5,5.313 19.5,10 C19.5,11.782 18.946,13.436 18.006,14.804 L19.078,15.877 C20.281,14.226 21,12.199 21,10 C21,4.478 16.522,0 11,0 C8.801,0 6.774,0.719 5.124,1.922 L6.196,2.994 C7.564,2.054 9.218,1.5 11,1.5"
            android:strokeWidth="1" />
    </group>
</vector>
 No newline at end of file
+37 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
   Copyright (C) 2019 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:height="24dp"
    android:tint="?android:attr/colorControlNormal"
    android:viewportHeight="24"
    android:viewportWidth="24"
    android:width="24dp" >
    <group
        android:translateX="2.000000"
        android:translateY="2.000000" >
        <path
            android:fillColor="@android:color/white"
            android:fillType="evenOdd"
            android:pathData="M12.25,0.2637 L12.25,1.8127 C15.847,2.8017 18.5,6.0927 18.5,9.9997 C18.5,14.6867 14.687,18.4997 10,18.4997 C5.313,18.4997 1.5,14.6867 1.5,9.9997 C1.5,6.0927 4.153,2.8017 7.75,1.8127 L7.75,0.2637 C3.312,1.2847 0,5.2517 0,9.9997 C0,15.5227 4.477,19.9997 10,19.9997 C15.523,19.9997 20,15.5227 20,9.9997 C20,5.2517 16.687,1.2847 12.25,0.2637"
            android:strokeWidth="1" />
        <path
            android:fillColor="@android:color/white"
            android:fillType="evenOdd"
            android:pathData="M15.0303,9.9697 C14.7373,9.6767 14.2623,9.6767 13.9693,9.9697 L10.7503,13.1897 L10.7503,0.7387 C10.7503,0.3307 10.4143,-0.0003 10.0003,-0.0003 C9.5863,-0.0003 9.2503,0.3307 9.2503,0.7387 L9.2503,13.1897 L6.0303,9.9697 C5.7373,9.6767 5.2623,9.6767 4.9693,9.9697 C4.6763,10.2627 4.6763,10.7377 4.9693,11.0307 L10.0003,16.0607 L15.0303,11.0307 C15.3233,10.7377 15.3233,10.2627 15.0303,9.9697"
            android:strokeWidth="1" />
    </group>
</vector>
 No newline at end of file
Loading