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

Commit 380e92c5 authored by Doris Ling's avatar Doris Ling
Browse files

Add module version in About settings.

Change-Id: I2474d05ee96e3dd29fe012fe77450c91775fdf1d
Fixes: 122615240
Test: make RunSettingsRoboTests
parent 00020f66
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -51,6 +51,18 @@
            android:background="?android:attr/selectableItemBackground"
            android:textColor="?android:attr/colorAccent"/>

        <TextView
            style="@style/device_info_dialog_label"
            android:id="@+id/module_version_label"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/module_version"/>
        <TextView
            style="@style/device_info_dialog_value"
            android:id="@+id/module_version_value"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <TextView
            style="@style/device_info_dialog_label"
            android:id="@+id/baseband_version_label"
+2 −0
Original line number Diff line number Diff line
@@ -2897,6 +2897,8 @@
    <string name="kernel_version">Kernel version</string>
    <!-- About phone screen,  setting option name  [CHAR LIMIT=40] -->
    <string name="build_number">Build number</string>
    <!-- About phone screen,  mainline module versions  [CHAR LIMIT=40] -->
    <string name="module_version">Mainline module versions</string>
    <!-- About phone screen, show when a value of some status item is unavailable. -->
    <string name="device_info_not_available">Not available</string>
+1 −0
Original line number Diff line number Diff line
@@ -90,5 +90,6 @@ public class FirmwareVersionDialogFragment extends InstrumentedDialogFragment {
        new BasebandVersionDialogController(this).initialize();
        new KernelVersionDialogController(this).initialize();
        new BuildNumberDialogController(this).initialize();
        new ModuleVersionDialogController(this).initialize();
    }
}
+65 −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.deviceinfo.firmwareversion;

import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import android.util.Log;

import com.android.settings.R;

import androidx.annotation.VisibleForTesting;

public class ModuleVersionDialogController {

    private static final String TAG = "MainlineModuleControl";

    @VisibleForTesting
    static final int MODULE_VERSION_LABEL_ID = R.id.module_version_label;
    @VisibleForTesting
    static final int MODULE_VERSION_VALUE_ID = R.id.module_version_value;

    private final FirmwareVersionDialogFragment mDialog;
    private final Context mContext;
    private final PackageManager mPackageManager;

    public ModuleVersionDialogController(FirmwareVersionDialogFragment dialog) {
        mDialog = dialog;
        mContext = mDialog.getContext();
        mPackageManager = mContext.getPackageManager();
    }

    /**
     * Updates the mainline module version field of the dialog.
     */
    public void initialize() {
        final String moduleProvider = mContext.getString(
            com.android.internal.R.string.config_defaultModuleMetadataProvider);
        if (!TextUtils.isEmpty(moduleProvider)) {
            try {
                mDialog.setText(MODULE_VERSION_VALUE_ID,
                    mPackageManager.getPackageInfo(moduleProvider, 0 /* flags */).versionName);
                return;
            } catch (PackageManager.NameNotFoundException e) {
                Log.e(TAG, "Failed to get mainline version.", e);
            }
        }
        mDialog.removeSettingFromScreen(MODULE_VERSION_LABEL_ID);
        mDialog.removeSettingFromScreen(MODULE_VERSION_VALUE_ID);
    }
}
+101 −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.deviceinfo.firmwareversion;

import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

@RunWith(RobolectricTestRunner.class)
public class ModuleVersionDialogControllerTest {

    @Mock
    private FirmwareVersionDialogFragment mDialog;
    @Mock
    private PackageManager mPackageManager;

    private Context mContext;
    private ModuleVersionDialogController mController;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        mContext = spy(RuntimeEnvironment.application);
        when(mDialog.getContext()).thenReturn(mContext);
        when(mContext.getPackageManager()).thenReturn(mPackageManager);
        mController = new ModuleVersionDialogController(mDialog);
    }

    @Test
    public void initialize_noMainlineModuleProvider_shouldRemoveSettingFromDialog() {
        when(mContext.getString(
            com.android.internal.R.string.config_defaultModuleMetadataProvider)).thenReturn(null);

        mController.initialize();

        verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_LABEL_ID);
        verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_VALUE_ID);
    }

    @Test
    public void initialize_noMainlineModulePackageInfo_shouldRemoveSettingFromDialog()
            throws PackageManager.NameNotFoundException {
        final String provider = "test.provider";
        when(mContext.getString(
            com.android.internal.R.string.config_defaultModuleMetadataProvider))
            .thenReturn(provider);
        when(mPackageManager.getPackageInfo(eq(provider), anyInt()))
            .thenThrow(new PackageManager.NameNotFoundException());

        mController.initialize();

        verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_LABEL_ID);
        verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_VALUE_ID);
    }

    @Test
    public void initialize_hasMainlineModulePackageInfo_shouldshouldSetDialogTextToMainlineVersion()
            throws PackageManager.NameNotFoundException {
        final String provider = "test.provider";
        final String version = "test version 123";
        final PackageInfo info = new PackageInfo();
        info.versionName = version;
        when(mContext.getString(
            com.android.internal.R.string.config_defaultModuleMetadataProvider))
            .thenReturn(provider);
        when(mPackageManager.getPackageInfo(eq(provider), anyInt())).thenReturn(info);

        mController.initialize();

        verify(mDialog).setText(mController.MODULE_VERSION_VALUE_ID, version);
    }

}