Add module version in About settings.

Change-Id: I2474d05ee96e3dd29fe012fe77450c91775fdf1d
Fixes: 122615240
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2019-01-16 12:39:57 -08:00
parent 00020f6605
commit 380e92c54c
5 changed files with 181 additions and 0 deletions

View File

@@ -51,6 +51,18 @@
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:textColor="?android:attr/colorAccent"/> 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 <TextView
style="@style/device_info_dialog_label" style="@style/device_info_dialog_label"
android:id="@+id/baseband_version_label" android:id="@+id/baseband_version_label"

View File

@@ -2897,6 +2897,8 @@
<string name="kernel_version">Kernel version</string> <string name="kernel_version">Kernel version</string>
<!-- About phone screen, setting option name [CHAR LIMIT=40] --> <!-- About phone screen, setting option name [CHAR LIMIT=40] -->
<string name="build_number">Build number</string> <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. --> <!-- About phone screen, show when a value of some status item is unavailable. -->
<string name="device_info_not_available">Not available</string> <string name="device_info_not_available">Not available</string>

View File

@@ -90,5 +90,6 @@ public class FirmwareVersionDialogFragment extends InstrumentedDialogFragment {
new BasebandVersionDialogController(this).initialize(); new BasebandVersionDialogController(this).initialize();
new KernelVersionDialogController(this).initialize(); new KernelVersionDialogController(this).initialize();
new BuildNumberDialogController(this).initialize(); new BuildNumberDialogController(this).initialize();
new ModuleVersionDialogController(this).initialize();
} }
} }

View File

@@ -0,0 +1,65 @@
/*
* 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);
}
}

View File

@@ -0,0 +1,101 @@
/*
* 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);
}
}