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

Commit 468e40e9 authored by Yanting Yang's avatar Yanting Yang Committed by android-build-merger
Browse files

Merge "Support new regulatory label for location" into qt-dev am: 28736bee

am: c453af3f

Change-Id: Iba9e810217cc4eee6c791eda6e3c100a851e9aa5
parents f67401a4 c453af3f
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -119,7 +119,8 @@ public class RegulatoryInfoDisplayActivity extends Activity implements
        }
    }

    private int getResourceId() {
    @VisibleForTesting
    int getResourceId() {
        // Use regulatory_info by default.
        int resId = getResources().getIdentifier(
                REGULATORY_INFO_RESOURCE, "drawable", getPackageName());
@@ -134,6 +135,18 @@ public class RegulatoryInfoDisplayActivity extends Activity implements
                resId = id;
            }
        }

        // When hardware coo property exists, use regulatory_info_<sku>_<coo> resource if valid.
        final String coo = getCoo();
        if (!TextUtils.isEmpty(coo) && !TextUtils.isEmpty(sku)) {
            final String regulatory_info_coo_res =
                    REGULATORY_INFO_RESOURCE + "_" + sku.toLowerCase() + "_" + coo.toLowerCase();
            final int id = getResources().getIdentifier(
                    regulatory_info_coo_res, "drawable", getPackageName());
            if (id != 0) {
                resId = id;
            }
        }
        return resId;
    }

@@ -142,13 +155,15 @@ public class RegulatoryInfoDisplayActivity extends Activity implements
        finish();   // close the activity
    }

    @VisibleForTesting
    public static String getSku() {
    private String getCoo() {
        return SystemProperties.get("ro.boot.hardware.coo", "");
    }

    private String getSku() {
        return SystemProperties.get("ro.boot.hardware.sku", "");
    }

    @VisibleForTesting
    public static String getRegulatoryInfoImageFileName() {
    private String getRegulatoryInfoImageFileName() {
        final String sku = getSku();
        if (TextUtils.isEmpty(sku)) {
            return DEFAULT_REGULATORY_INFO_FILEPATH;
+159 B
Loading image diff...
+159 B
Loading image diff...
+159 B
Loading image diff...
+83 −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.settings;

import static com.google.common.truth.Truth.assertThat;

import android.os.SystemProperties;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;


@RunWith(RobolectricTestRunner.class)
public class RegulatoryInfoDisplayActivityTest {

    private static final String SKU_PROP_KEY = "ro.boot.hardware.sku";
    private static final String COO_PROP_KEY = "ro.boot.hardware.coo";

    private RegulatoryInfoDisplayActivity mRegulatoryInfoDisplayActivity;

    @Before
    public void setUp() {
        mRegulatoryInfoDisplayActivity = Robolectric.buildActivity(
                RegulatoryInfoDisplayActivity.class).create().get();
    }

    @Test
    public void getResourceId_noSkuProperty_shouldReturnDefaultLabel() {
        SystemProperties.set(SKU_PROP_KEY, "");

        final int expectedResId = getResourceId("regulatory_info");
        assertThat(mRegulatoryInfoDisplayActivity.getResourceId()).isEqualTo(expectedResId);
    }

    @Test
    public void getResourceId_noCooProperty_shouldReturnSkuLabel() {
        SystemProperties.set(SKU_PROP_KEY, "sku");
        SystemProperties.set(COO_PROP_KEY, "");

        final int expectedResId = getResourceId("regulatory_info_sku");
        assertThat(mRegulatoryInfoDisplayActivity.getResourceId()).isEqualTo(expectedResId);
    }

    @Test
    public void getResourceId_hasSkuAndCooProperties_shouldReturnCooLabel() {
        SystemProperties.set(SKU_PROP_KEY, "sku1");
        SystemProperties.set(COO_PROP_KEY, "coo");

        final int expectedResId = getResourceId("regulatory_info_sku1_coo");
        assertThat(mRegulatoryInfoDisplayActivity.getResourceId()).isEqualTo(expectedResId);
    }

    @Test
    public void getResourceId_noCorrespondingCooLabel_shouldReturnSkuLabel() {
        SystemProperties.set(SKU_PROP_KEY, "sku");
        SystemProperties.set(COO_PROP_KEY, "unknown");

        final int expectedResId = getResourceId("regulatory_info_sku");
        assertThat(mRegulatoryInfoDisplayActivity.getResourceId()).isEqualTo(expectedResId);
    }

    private int getResourceId(String resourceName) {
        return mRegulatoryInfoDisplayActivity.getResources().getIdentifier(resourceName, "drawable",
                mRegulatoryInfoDisplayActivity.getPackageName());
    }
}