Convert android version dialog into a full screen UI
Bug: 112427717 Test: robotests Change-Id: I09c4130c4284670278fa7cab8a21641c663bb365
This commit is contained in:
@@ -1,103 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2017 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.
|
||||
-->
|
||||
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/sim_content_padding">
|
||||
|
||||
<TextView
|
||||
style="@style/device_info_dialog_label"
|
||||
android:id="@+id/firmware_version_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/firmware_version"/>
|
||||
<TextView
|
||||
style="@style/device_info_dialog_value"
|
||||
android:id="@+id/firmware_version_value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
style="@style/device_info_dialog_label"
|
||||
android:id="@+id/security_patch_level_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/security_patch"/>
|
||||
<TextView
|
||||
style="@style/device_info_dialog_value"
|
||||
android:id="@+id/security_patch_level_value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/baseband_version"/>
|
||||
<TextView
|
||||
style="@style/device_info_dialog_value"
|
||||
android:id="@+id/baseband_version_value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
style="@style/device_info_dialog_label"
|
||||
android:id="@+id/kernel_version_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/kernel_version"/>
|
||||
<TextView
|
||||
style="@style/device_info_dialog_value"
|
||||
android:id="@+id/kernel_version_value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
style="@style/device_info_dialog_label"
|
||||
android:id="@+id/build_number_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/build_number"/>
|
||||
<TextView
|
||||
style="@style/device_info_dialog_value"
|
||||
android:id="@+id/build_number_value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
@@ -2927,8 +2927,6 @@
|
||||
|
||||
<!-- About phone screen, status item label [CHAR LIMIT=40] -->
|
||||
<string name="firmware_version">Android version</string>
|
||||
<!-- About phone screen, dialog title for showing device software information such as android version, security patch level, etc [CHAR LIMIT=60] -->
|
||||
<string name="firmware_title">Android</string>
|
||||
<!-- About phone screen, status item label [CHAR LIMIT=60] -->
|
||||
<string name="security_patch">Android security patch level</string>
|
||||
<!-- About phone screen, status item label [CHAR LIMIT=40] -->
|
||||
|
73
res/xml/firmware_version.xml
Normal file
73
res/xml/firmware_version.xml
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="firmware_version_screen"
|
||||
android:title="@string/firmware_version"
|
||||
settings:keywords="@string/keywords_android_version">
|
||||
|
||||
<!-- Android version -->
|
||||
<Preference
|
||||
android:key="os_firmware_version"
|
||||
android:title="@string/firmware_version"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:enableCopying="true"
|
||||
settings:allowDynamicSummaryInSlice="true"
|
||||
settings:controller="com.android.settings.deviceinfo.firmwareversion.FirmwareVersionDetailPreferenceController"/>
|
||||
|
||||
<!-- Security patch -->
|
||||
<Preference
|
||||
android:key="security_key"
|
||||
android:title="@string/security_patch"
|
||||
settings:enableCopying="true"
|
||||
settings:controller="com.android.settings.deviceinfo.firmwareversion.SecurityPatchLevelPreferenceController"/>
|
||||
|
||||
<!-- Mainline module version -->
|
||||
<Preference
|
||||
android:key="module_version"
|
||||
android:title="@string/module_version"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:enableCopying="true"
|
||||
settings:controller="com.android.settings.deviceinfo.firmwareversion.MainlineModuleVersionPreferenceController"/>
|
||||
|
||||
<!-- Baseband -->
|
||||
<Preference
|
||||
android:key="base_band"
|
||||
android:title="@string/baseband_version"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:enableCopying="true"
|
||||
settings:controller="com.android.settings.deviceinfo.firmwareversion.BasebandVersionPreferenceController"/>
|
||||
|
||||
<!-- Kernel -->
|
||||
<Preference
|
||||
android:key="kernel_version"
|
||||
android:title="@string/kernel_version"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:enableCopying="true"
|
||||
settings:controller="com.android.settings.deviceinfo.firmwareversion.KernelVersionPreferenceController"/>
|
||||
|
||||
<!-- Build -->
|
||||
<Preference
|
||||
android:key="os_build_number"
|
||||
android:title="@string/build_number"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:enableCopying="true"
|
||||
settings:controller="com.android.settings.deviceinfo.firmwareversion.SimpleBuildNumberPreferenceController"/>
|
||||
|
||||
</PreferenceScreen>
|
@@ -121,11 +121,10 @@
|
||||
android:key="firmware_version"
|
||||
android:order="32"
|
||||
android:title="@string/firmware_version"
|
||||
settings:keywords="@string/keywords_android_version"
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:allowDynamicSummaryInSlice="true"
|
||||
settings:controller=
|
||||
"com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceController"/>
|
||||
android:fragment="com.android.settings.deviceinfo.firmwareversion.FirmwareVersionSettings"
|
||||
settings:controller="com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceController"/>
|
||||
|
||||
<!--IP address -->
|
||||
<Preference
|
||||
|
@@ -49,9 +49,9 @@ import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminSe
|
||||
import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureDetails;
|
||||
import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureSettings;
|
||||
import com.android.settings.applications.specialaccess.vrlistener.VrListenerSettings;
|
||||
import com.android.settings.backup.UserBackupSettingsActivity;
|
||||
import com.android.settings.backup.PrivacySettings;
|
||||
import com.android.settings.backup.ToggleBackupSettingFragment;
|
||||
import com.android.settings.backup.UserBackupSettingsActivity;
|
||||
import com.android.settings.biometrics.face.FaceSettings;
|
||||
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
|
||||
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
|
||||
@@ -68,6 +68,7 @@ import com.android.settings.deviceinfo.PublicVolumeSettings;
|
||||
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
||||
import com.android.settings.deviceinfo.StorageSettings;
|
||||
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
|
||||
import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionSettings;
|
||||
import com.android.settings.display.NightDisplaySettings;
|
||||
import com.android.settings.dream.DreamSettings;
|
||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
@@ -165,6 +166,7 @@ public class SettingsGateway {
|
||||
DisplaySettings.class.getName(),
|
||||
MyDeviceInfoFragment.class.getName(),
|
||||
ManageApplications.class.getName(),
|
||||
FirmwareVersionSettings.class.getName(),
|
||||
ManageAssist.class.getName(),
|
||||
ProcessStatsUi.class.getName(),
|
||||
NotificationStation.class.getName(),
|
||||
|
@@ -77,7 +77,6 @@ public class MyDeviceInfoFragment extends DashboardFragment
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
use(FirmwareVersionPreferenceController.class).setHost(this /* parent */);
|
||||
use(DeviceModelPreferenceController.class).setHost(this /* parent */);
|
||||
use(ImeiInfoPreferenceController.class).setHost(this /* parent */);
|
||||
use(DeviceNamePreferenceController.class).setHost(this /* parent */);
|
||||
|
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.os.SystemProperties;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
public class BasebandVersionDialogController {
|
||||
|
||||
@VisibleForTesting
|
||||
static final int BASEBAND_VERSION_LABEL_ID = R.id.baseband_version_label;
|
||||
@VisibleForTesting
|
||||
static final int BASEBAND_VERSION_VALUE_ID = R.id.baseband_version_value;
|
||||
@VisibleForTesting
|
||||
static final String BASEBAND_PROPERTY = "gsm.version.baseband";
|
||||
|
||||
private final FirmwareVersionDialogFragment mDialog;
|
||||
|
||||
public BasebandVersionDialogController(FirmwareVersionDialogFragment dialog) {
|
||||
mDialog = dialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the baseband version field of the dialog.
|
||||
*/
|
||||
public void initialize() {
|
||||
final Context context = mDialog.getContext();
|
||||
if (Utils.isWifiOnly(context)) {
|
||||
mDialog.removeSettingFromScreen(BASEBAND_VERSION_LABEL_ID);
|
||||
mDialog.removeSettingFromScreen(BASEBAND_VERSION_VALUE_ID);
|
||||
return;
|
||||
}
|
||||
|
||||
mDialog.setText(BASEBAND_VERSION_VALUE_ID, SystemProperties.get(BASEBAND_PROPERTY,
|
||||
context.getString(R.string.device_info_default)));
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.os.SystemProperties;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class BasebandVersionPreferenceController extends BasePreferenceController {
|
||||
|
||||
@VisibleForTesting
|
||||
static final String BASEBAND_PROPERTY = "gsm.version.baseband";
|
||||
|
||||
public BasebandVersionPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return !Utils.isWifiOnly(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return SystemProperties.get(BASEBAND_PROPERTY,
|
||||
mContext.getString(R.string.device_info_default));
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* 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.
|
||||
@@ -22,42 +22,61 @@ import android.os.Build;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.slices.Copyable;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
|
||||
public class FirmwareVersionDialogController implements View.OnClickListener {
|
||||
public class FirmwareVersionDetailPreferenceController extends BasePreferenceController implements
|
||||
Copyable {
|
||||
|
||||
private static final String TAG = "firmwareDialogCtrl";
|
||||
private static final int DELAY_TIMER_MILLIS = 500;
|
||||
private static final int ACTIVITY_TRIGGER_COUNT = 3;
|
||||
|
||||
@VisibleForTesting
|
||||
static final int FIRMWARE_VERSION_VALUE_ID = R.id.firmware_version_value;
|
||||
@VisibleForTesting
|
||||
static final int FIRMWARE_VERSION_LABEL_ID = R.id.firmware_version_label;
|
||||
|
||||
private final FirmwareVersionDialogFragment mDialog;
|
||||
private final Context mContext;
|
||||
private final UserManager mUserManager;
|
||||
private final long[] mHits = new long[ACTIVITY_TRIGGER_COUNT];
|
||||
|
||||
private RestrictedLockUtils.EnforcedAdmin mFunDisallowedAdmin;
|
||||
private boolean mFunDisallowedBySystem;
|
||||
|
||||
public FirmwareVersionDialogController(FirmwareVersionDialogFragment dialog) {
|
||||
mDialog = dialog;
|
||||
mContext = dialog.getContext();
|
||||
public FirmwareVersionDetailPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
initializeAdminPermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return Build.VERSION.RELEASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||
return false;
|
||||
}
|
||||
if (Utils.isMonkeyRunning()) {
|
||||
return false;
|
||||
}
|
||||
arrayCopy();
|
||||
mHits[mHits.length - 1] = SystemClock.uptimeMillis();
|
||||
if (mHits[0] >= (SystemClock.uptimeMillis() - DELAY_TIMER_MILLIS)) {
|
||||
@@ -67,7 +86,7 @@ public class FirmwareVersionDialogController implements View.OnClickListener {
|
||||
mFunDisallowedAdmin);
|
||||
}
|
||||
Log.d(TAG, "Sorry, no fun for you!");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
final Intent intent = new Intent(Intent.ACTION_MAIN)
|
||||
@@ -79,21 +98,7 @@ public class FirmwareVersionDialogController implements View.OnClickListener {
|
||||
Log.e(TAG, "Unable to start activity " + intent.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the Android version field in the dialog and registers click listeners.
|
||||
*/
|
||||
public void initialize() {
|
||||
initializeAdminPermissions();
|
||||
registerClickListeners();
|
||||
|
||||
mDialog.setText(FIRMWARE_VERSION_VALUE_ID, Build.VERSION.RELEASE);
|
||||
}
|
||||
|
||||
private void registerClickListeners() {
|
||||
mDialog.registerClickListener(FIRMWARE_VERSION_LABEL_ID, this /* listener */);
|
||||
mDialog.registerClickListener(FIRMWARE_VERSION_VALUE_ID, this /* listener */);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,4 +116,10 @@ public class FirmwareVersionDialogController implements View.OnClickListener {
|
||||
mFunDisallowedBySystem = RestrictedLockUtilsInternal.hasBaseUserRestriction(
|
||||
mContext, UserManager.DISALLOW_FUN, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Copyable.setCopyContent(mContext, getSummary(),
|
||||
mContext.getText(R.string.firmware_version));
|
||||
}
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
|
||||
public class FirmwareVersionDialogFragment extends InstrumentedDialogFragment {
|
||||
|
||||
private static final String TAG = "firmwareVersionDialog";
|
||||
|
||||
private View mRootView;
|
||||
|
||||
public static void show(Fragment host) {
|
||||
final FragmentManager manager = host.getChildFragmentManager();
|
||||
if (manager.findFragmentByTag(TAG) == null) {
|
||||
final FirmwareVersionDialogFragment dialog = new FirmwareVersionDialogFragment();
|
||||
dialog.show(manager, TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DIALOG_FIRMWARE_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.firmware_title)
|
||||
.setPositiveButton(android.R.string.ok, null /* listener */);
|
||||
|
||||
mRootView = LayoutInflater.from(getActivity()).inflate(
|
||||
R.layout.dialog_firmware_version, null /* parent */);
|
||||
|
||||
initializeControllers();
|
||||
|
||||
return builder.setView(mRootView).create();
|
||||
}
|
||||
|
||||
public void setText(int viewId, CharSequence text) {
|
||||
final TextView view = mRootView.findViewById(viewId);
|
||||
if (view != null) {
|
||||
view.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSettingFromScreen(int viewId) {
|
||||
final View view = mRootView.findViewById(viewId);
|
||||
if (view != null) {
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerClickListener(int viewId, View.OnClickListener listener) {
|
||||
final View view = mRootView.findViewById(viewId);
|
||||
if (view != null) {
|
||||
view.setOnClickListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeControllers() {
|
||||
new FirmwareVersionDialogController(this).initialize();
|
||||
new SecurityPatchLevelDialogController(this).initialize();
|
||||
new BasebandVersionDialogController(this).initialize();
|
||||
new KernelVersionDialogController(this).initialize();
|
||||
new BuildNumberDialogController(this).initialize();
|
||||
new ModuleVersionDialogController(this).initialize();
|
||||
}
|
||||
}
|
@@ -18,56 +18,22 @@ package com.android.settings.deviceinfo.firmwareversion;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.slices.Copyable;
|
||||
|
||||
public class FirmwareVersionPreferenceController extends BasePreferenceController implements
|
||||
Copyable {
|
||||
|
||||
private Fragment mFragment;
|
||||
public class FirmwareVersionPreferenceController extends BasePreferenceController {
|
||||
|
||||
public FirmwareVersionPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
public void setHost(Fragment fragment) {
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return Build.VERSION.RELEASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (!TextUtils.equals(preference.getKey(), mPreferenceKey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FirmwareVersionDialogFragment.show(mFragment);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Copyable.setCopyContent(mContext, getSummary(),
|
||||
mContext.getText(R.string.firmware_version));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
public class FirmwareVersionSettings extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.firmware_version;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return "FirmwareVersionSettings";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DIALOG_FIRMWARE_VERSION;
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
|
||||
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.firmware_version;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* 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.
|
||||
@@ -16,27 +16,24 @@
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.DeviceInfoUtils;
|
||||
|
||||
public class KernelVersionDialogController {
|
||||
public class KernelVersionPreferenceController extends BasePreferenceController {
|
||||
|
||||
@VisibleForTesting
|
||||
static int KERNEL_VERSION_VALUE_ID = R.id.kernel_version_value;
|
||||
|
||||
private final FirmwareVersionDialogFragment mDialog;
|
||||
|
||||
public KernelVersionDialogController(FirmwareVersionDialogFragment dialog) {
|
||||
mDialog = dialog;
|
||||
public KernelVersionPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates kernel version to the dialog.
|
||||
*/
|
||||
public void initialize() {
|
||||
mDialog.setText(KERNEL_VERSION_VALUE_ID,
|
||||
DeviceInfoUtils.getFormattedKernelVersion(mDialog.getContext()));
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return DeviceInfoUtils.getFormattedKernelVersion(mContext);
|
||||
}
|
||||
}
|
@@ -22,51 +22,51 @@ import android.text.TextUtils;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.FeatureFlags;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
public class ModuleVersionDialogController {
|
||||
public class MainlineModuleVersionPreferenceController extends BasePreferenceController {
|
||||
|
||||
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();
|
||||
private String mModuleVersion;
|
||||
|
||||
public MainlineModuleVersionPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mPackageManager = mContext.getPackageManager();
|
||||
initModules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the mainline module version field of the dialog.
|
||||
*/
|
||||
public void initialize() {
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (!FeatureFlagUtils.isEnabled(mContext, FeatureFlags.MAINLINE_MODULE)) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
return !TextUtils.isEmpty(mModuleVersion) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
private void initModules() {
|
||||
if (!FeatureFlagUtils.isEnabled(mContext, FeatureFlags.MAINLINE_MODULE)) {
|
||||
mDialog.removeSettingFromScreen(MODULE_VERSION_LABEL_ID);
|
||||
mDialog.removeSettingFromScreen(MODULE_VERSION_VALUE_ID);
|
||||
return;
|
||||
}
|
||||
final String moduleProvider = mContext.getString(
|
||||
com.android.internal.R.string.config_defaultModuleMetadataProvider);
|
||||
com.android.internal.R.string.config_defaultModuleMetadataProvider);
|
||||
if (!TextUtils.isEmpty(moduleProvider)) {
|
||||
try {
|
||||
mDialog.setText(MODULE_VERSION_VALUE_ID,
|
||||
mPackageManager.getPackageInfo(moduleProvider, 0 /* flags */).versionName);
|
||||
mModuleVersion =
|
||||
mPackageManager.getPackageInfo(moduleProvider, 0 /* flags */).versionName;
|
||||
return;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e(TAG, "Failed to get mainline version.", e);
|
||||
mModuleVersion = null;
|
||||
}
|
||||
}
|
||||
mDialog.removeSettingFromScreen(MODULE_VERSION_LABEL_ID);
|
||||
mDialog.removeSettingFromScreen(MODULE_VERSION_VALUE_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mModuleVersion;
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* 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.
|
||||
@@ -22,66 +22,54 @@ import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.DeviceInfoUtils;
|
||||
|
||||
public class SecurityPatchLevelDialogController implements View.OnClickListener {
|
||||
public class SecurityPatchLevelPreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "SecurityPatchCtrl";
|
||||
private static final Uri INTENT_URI_DATA = Uri.parse(
|
||||
"https://source.android.com/security/bulletin/");
|
||||
|
||||
@VisibleForTesting
|
||||
static final int SECURITY_PATCH_VALUE_ID = R.id.security_patch_level_value;
|
||||
@VisibleForTesting
|
||||
static final int SECURITY_PATCH_LABEL_ID = R.id.security_patch_level_label;
|
||||
|
||||
private final FirmwareVersionDialogFragment mDialog;
|
||||
private final Context mContext;
|
||||
private final PackageManager mPackageManager;
|
||||
private final String mCurrentPatch;
|
||||
|
||||
public SecurityPatchLevelDialogController(FirmwareVersionDialogFragment dialog) {
|
||||
mDialog = dialog;
|
||||
mContext = dialog.getContext();
|
||||
public SecurityPatchLevelPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mPackageManager = mContext.getPackageManager();
|
||||
mCurrentPatch = DeviceInfoUtils.getSecurityPatch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public int getAvailabilityStatus() {
|
||||
return !TextUtils.isEmpty(mCurrentPatch)
|
||||
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mCurrentPatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setData(INTENT_URI_DATA);
|
||||
if (mPackageManager.queryIntentActivities(intent, 0).isEmpty()) {
|
||||
// Don't send out the intent to stop crash
|
||||
Log.w(TAG, "Stop click action on " + SECURITY_PATCH_VALUE_ID + ": "
|
||||
+ "queryIntentActivities() returns empty");
|
||||
return;
|
||||
Log.w(TAG, "queryIntentActivities() returns empty");
|
||||
return true;
|
||||
}
|
||||
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the security patch level field in the dialog and registers click listeners.
|
||||
*/
|
||||
public void initialize() {
|
||||
if (TextUtils.isEmpty(mCurrentPatch)) {
|
||||
mDialog.removeSettingFromScreen(SECURITY_PATCH_LABEL_ID);
|
||||
mDialog.removeSettingFromScreen(SECURITY_PATCH_VALUE_ID);
|
||||
return;
|
||||
}
|
||||
registerListeners();
|
||||
mDialog.setText(SECURITY_PATCH_VALUE_ID, mCurrentPatch);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
mDialog.registerClickListener(SECURITY_PATCH_LABEL_ID, this /* listener */);
|
||||
mDialog.registerClickListener(SECURITY_PATCH_VALUE_ID, this /* listener */);
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* 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.
|
||||
@@ -16,29 +16,26 @@
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.text.BidiFormatter;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import com.android.settings.R;
|
||||
public class SimpleBuildNumberPreferenceController extends BasePreferenceController {
|
||||
|
||||
public class BuildNumberDialogController {
|
||||
|
||||
@VisibleForTesting
|
||||
static final int BUILD_NUMBER_VALUE_ID = R.id.build_number_value;
|
||||
|
||||
private final FirmwareVersionDialogFragment mDialog;
|
||||
|
||||
public BuildNumberDialogController(FirmwareVersionDialogFragment dialog) {
|
||||
mDialog = dialog;
|
||||
public SimpleBuildNumberPreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the build number to the dialog.
|
||||
*/
|
||||
public void initialize() {
|
||||
mDialog.setText(BUILD_NUMBER_VALUE_ID,
|
||||
BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY));
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY);
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* 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.
|
||||
@@ -16,15 +16,12 @@
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion;
|
||||
|
||||
import static com.android.settings.deviceinfo.firmwareversion.BasebandVersionDialogController
|
||||
.BASEBAND_PROPERTY;
|
||||
import static com.android.settings.deviceinfo.firmwareversion.BasebandVersionDialogController
|
||||
.BASEBAND_VERSION_LABEL_ID;
|
||||
import static com.android.settings.deviceinfo.firmwareversion.BasebandVersionDialogController
|
||||
.BASEBAND_VERSION_VALUE_ID;
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
import static com.android.settings.deviceinfo.firmwareversion.BasebandVersionPreferenceController.BASEBAND_PROPERTY;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.shadow.api.Shadow.extract;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -36,7 +33,6 @@ import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||
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;
|
||||
@@ -44,44 +40,35 @@ import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowConnectivityManager.class)
|
||||
public class BasebandVersionDialogControllerTest {
|
||||
|
||||
@Mock
|
||||
private FirmwareVersionDialogFragment mDialog;
|
||||
public class BasebandVersionPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private BasebandVersionDialogController mController;
|
||||
private BasebandVersionPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
when(mDialog.getContext()).thenReturn(mContext);
|
||||
mController = new BasebandVersionDialogController(mDialog);
|
||||
mController = new BasebandVersionPreferenceController(mContext, "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_wifiOnly_shouldRemoveSettingFromDialog() {
|
||||
ShadowConnectivityManager connectivityManager =
|
||||
public void getAvailability_wifiOnly_unavailable() {
|
||||
final ShadowConnectivityManager connectivityManager =
|
||||
extract(mContext.getSystemService(ConnectivityManager.class));
|
||||
connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, false);
|
||||
|
||||
mController.initialize();
|
||||
|
||||
verify(mDialog).removeSettingFromScreen(BASEBAND_VERSION_LABEL_ID);
|
||||
verify(mDialog).removeSettingFromScreen(BASEBAND_VERSION_VALUE_ID);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_hasMobile_shouldSetDialogTextToBasebandVersion() {
|
||||
public void getAvailability_hasMobile_available() {
|
||||
final String text = "test";
|
||||
SystemProperties.set(BASEBAND_PROPERTY, text);
|
||||
ShadowConnectivityManager connectivityManager =
|
||||
extract(mContext.getSystemService(ConnectivityManager.class));
|
||||
connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, true);
|
||||
|
||||
mController.initialize();
|
||||
|
||||
verify(mDialog).setText(BASEBAND_VERSION_VALUE_ID, text);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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 com.android.settings.deviceinfo.firmwareversion.BuildNumberDialogController
|
||||
.BUILD_NUMBER_VALUE_ID;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.BidiFormatter;
|
||||
|
||||
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;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BuildNumberDialogControllerTest {
|
||||
|
||||
@Mock
|
||||
private FirmwareVersionDialogFragment mDialog;
|
||||
|
||||
private BuildNumberDialogController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new BuildNumberDialogController(mDialog);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_shouldUpdateBuildNumberToDialog() {
|
||||
mController.initialize();
|
||||
|
||||
verify(mDialog)
|
||||
.setText(BUILD_NUMBER_VALUE_ID, BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY));
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* 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.
|
||||
@@ -16,13 +16,9 @@
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion;
|
||||
|
||||
import static com.android.settings.deviceinfo.firmwareversion.FirmwareVersionDialogController
|
||||
.FIRMWARE_VERSION_LABEL_ID;
|
||||
import static com.android.settings.deviceinfo.firmwareversion.FirmwareVersionDialogController
|
||||
.FIRMWARE_VERSION_VALUE_ID;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -32,7 +28,8 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.UserManager;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -44,36 +41,30 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class FirmwareVersionDialogControllerTest {
|
||||
public class FirmwareVersionDetailPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private FirmwareVersionDialogFragment mDialog;
|
||||
@Mock
|
||||
private View mView;
|
||||
|
||||
private Preference mPreference;
|
||||
private Context mContext;
|
||||
private FirmwareVersionDialogController mController;
|
||||
private FirmwareVersionDetailPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mDialog.getContext()).thenReturn(mContext);
|
||||
mController = spy(new FirmwareVersionDialogController(mDialog));
|
||||
mController = spy(new TestController(mContext, "key"));
|
||||
|
||||
ReflectionHelpers.setField(mController, "mUserManager", mUserManager);
|
||||
doNothing().when(mController).arrayCopy();
|
||||
doNothing().when(mController).initializeAdminPermissions();
|
||||
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_shouldRegisterListenersAndSetBuildVersion() {
|
||||
mController.initialize();
|
||||
|
||||
verify(mDialog).registerClickListener(eq(FIRMWARE_VERSION_VALUE_ID), any());
|
||||
verify(mDialog).registerClickListener(eq(FIRMWARE_VERSION_LABEL_ID), any());
|
||||
verify(mDialog).setText(FIRMWARE_VERSION_VALUE_ID, Build.VERSION.RELEASE);
|
||||
public void getSummary_shouldGetBuildVersion() {
|
||||
assertThat(mController.getSummary()).isEqualTo(Build.VERSION.RELEASE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +73,7 @@ public class FirmwareVersionDialogControllerTest {
|
||||
hits[0] = Long.MAX_VALUE;
|
||||
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_FUN)).thenReturn(true);
|
||||
|
||||
mController.onClick(mView);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mContext, never()).startActivity(any());
|
||||
}
|
||||
@@ -93,8 +84,19 @@ public class FirmwareVersionDialogControllerTest {
|
||||
hits[0] = Long.MAX_VALUE;
|
||||
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_FUN)).thenReturn(false);
|
||||
|
||||
mController.onClick(mView);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mContext).startActivity(any());
|
||||
}
|
||||
|
||||
private static class TestController extends FirmwareVersionDetailPreferenceController {
|
||||
|
||||
public TestController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
void initializeAdminPermissions() {
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* 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.
|
||||
@@ -16,42 +16,29 @@
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion;
|
||||
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import org.junit.After;
|
||||
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;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class FirmwareVersionPreferenceControllerTest {
|
||||
|
||||
private static final String KEY = "firmware_version";
|
||||
|
||||
@Mock
|
||||
private Fragment mFragment;
|
||||
|
||||
private Preference mPreference;
|
||||
private PreferenceScreen mScreen;
|
||||
private FirmwareVersionPreferenceController mController;
|
||||
@@ -62,22 +49,16 @@ public class FirmwareVersionPreferenceControllerTest {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final PreferenceManager preferenceManager = new PreferenceManager(context);
|
||||
mController = new FirmwareVersionPreferenceController(context, KEY);
|
||||
mController.setHost(mFragment);
|
||||
mPreference = new Preference(context);
|
||||
mPreference.setKey(KEY);
|
||||
mScreen = preferenceManager.createPreferenceScreen(context);
|
||||
mScreen.addPreference(mPreference);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowFirmwareVersionDialogFragment.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void firmwareVersion_shouldAlwaysBeShown() {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,55 +67,4 @@ public class FirmwareVersionPreferenceControllerTest {
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo(Build.VERSION.RELEASE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowFirmwareVersionDialogFragment.class)
|
||||
public void handlePreferenceTreeClick_samePreferenceKey_shouldStartDialogFragment() {
|
||||
final boolean result = mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(ShadowFirmwareVersionDialogFragment.isShowing).isTrue();
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_unknownPreferenceKey_shouldDoNothingAndReturnFalse() {
|
||||
mPreference.setKey("foobar");
|
||||
|
||||
final boolean result = mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(ShadowFirmwareVersionDialogFragment.isShowing).isFalse();
|
||||
assertThat(result).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceable_shouldBeTrue() {
|
||||
assertThat(mController.isSliceable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copy_shouldCopyVersionNumberToClipboard() {
|
||||
mController.copy();
|
||||
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(
|
||||
CLIPBOARD_SERVICE);
|
||||
final CharSequence data = clipboard.getPrimaryClip().getItemAt(0).getText();
|
||||
assertThat(data.toString()).isEqualTo(Build.VERSION.RELEASE);
|
||||
}
|
||||
|
||||
@Implements(FirmwareVersionDialogFragment.class)
|
||||
public static class ShadowFirmwareVersionDialogFragment {
|
||||
|
||||
private static boolean isShowing = false;
|
||||
|
||||
@Implementation
|
||||
public static void show(Fragment fragemnt) {
|
||||
isShowing = true;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
isShowing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* 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.
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion;
|
||||
|
||||
import static com.android.settings.deviceinfo.firmwareversion.KernelVersionDialogController
|
||||
.KERNEL_VERSION_VALUE_ID;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -29,33 +25,27 @@ import com.android.settingslib.DeviceInfoUtils;
|
||||
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 KernelVersionDialogControllerTest {
|
||||
public class KernelVersionPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private FirmwareVersionDialogFragment mDialog;
|
||||
|
||||
private Context mContext;
|
||||
private KernelVersionDialogController mController;
|
||||
private KernelVersionPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
when(mDialog.getContext()).thenReturn(mContext);
|
||||
mController = new KernelVersionDialogController(mDialog);
|
||||
mController = new KernelVersionPreferenceController(mContext, "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_shouldUpdateKernelVersionToDialog() {
|
||||
mController.initialize();
|
||||
|
||||
verify(mDialog)
|
||||
.setText(KERNEL_VERSION_VALUE_ID, DeviceInfoUtils.getFormattedKernelVersion(mContext));
|
||||
public void getSummary_shouldGetKernalVersion() {
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
DeviceInfoUtils.getFormattedKernelVersion(mContext));
|
||||
}
|
||||
}
|
@@ -16,10 +16,14 @@
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
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;
|
||||
@@ -38,78 +42,75 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ModuleVersionDialogControllerTest {
|
||||
public class MainlineModuleVersionPreferenceControllerTest {
|
||||
|
||||
@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);
|
||||
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.MAINLINE_MODULE, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_featureDisabled_shouldRemoveSettingFromDialog() {
|
||||
public void getAvailabilityStatus_featureDisabled_unavailable() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.MAINLINE_MODULE, false);
|
||||
|
||||
mController.initialize();
|
||||
final MainlineModuleVersionPreferenceController controller =
|
||||
new MainlineModuleVersionPreferenceController(mContext, "key");
|
||||
|
||||
verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_LABEL_ID);
|
||||
verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_VALUE_ID);
|
||||
assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_noMainlineModuleProvider_shouldRemoveSettingFromDialog() {
|
||||
public void getAvailabilityStatus_noMainlineModuleProvider_unavailable() {
|
||||
when(mContext.getString(
|
||||
com.android.internal.R.string.config_defaultModuleMetadataProvider)).thenReturn(null);
|
||||
com.android.internal.R.string.config_defaultModuleMetadataProvider)).thenReturn(
|
||||
null);
|
||||
|
||||
mController.initialize();
|
||||
final MainlineModuleVersionPreferenceController controller =
|
||||
new MainlineModuleVersionPreferenceController(mContext, "key");
|
||||
|
||||
verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_LABEL_ID);
|
||||
verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_VALUE_ID);
|
||||
assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_noMainlineModulePackageInfo_shouldRemoveSettingFromDialog()
|
||||
throws PackageManager.NameNotFoundException {
|
||||
public void getAvailabilityStatus_noMainlineModulePackageInfo_unavailable() throws Exception {
|
||||
|
||||
final String provider = "test.provider";
|
||||
when(mContext.getString(
|
||||
com.android.internal.R.string.config_defaultModuleMetadataProvider))
|
||||
.thenReturn(provider);
|
||||
com.android.internal.R.string.config_defaultModuleMetadataProvider))
|
||||
.thenReturn(provider);
|
||||
when(mPackageManager.getPackageInfo(eq(provider), anyInt()))
|
||||
.thenThrow(new PackageManager.NameNotFoundException());
|
||||
.thenThrow(new PackageManager.NameNotFoundException());
|
||||
|
||||
mController.initialize();
|
||||
final MainlineModuleVersionPreferenceController controller =
|
||||
new MainlineModuleVersionPreferenceController(mContext, "key");
|
||||
|
||||
verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_LABEL_ID);
|
||||
verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_VALUE_ID);
|
||||
assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_hasMainlineModulePackageInfo_shouldshouldSetDialogTextToMainlineVersion()
|
||||
throws PackageManager.NameNotFoundException {
|
||||
public void getAvailabilityStatus_hasMainlineModulePackageInfo_available() throws Exception {
|
||||
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);
|
||||
com.android.internal.R.string.config_defaultModuleMetadataProvider))
|
||||
.thenReturn(provider);
|
||||
when(mPackageManager.getPackageInfo(eq(provider), anyInt())).thenReturn(info);
|
||||
|
||||
mController.initialize();
|
||||
final MainlineModuleVersionPreferenceController controller =
|
||||
new MainlineModuleVersionPreferenceController(mContext, "key");
|
||||
|
||||
verify(mDialog).setText(mController.MODULE_VERSION_VALUE_ID, version);
|
||||
assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* 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.
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package com.android.settings.deviceinfo.firmwareversion;
|
||||
|
||||
import static com.android.settings.deviceinfo.firmwareversion.SecurityPatchLevelDialogController
|
||||
.SECURITY_PATCH_LABEL_ID;
|
||||
import static com.android.settings.deviceinfo.firmwareversion.SecurityPatchLevelDialogController
|
||||
.SECURITY_PATCH_VALUE_ID;
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -33,7 +32,8 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -47,55 +47,47 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
import java.util.Collections;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SecurityPatchLevelDialogControllerTest {
|
||||
public class SecurityPatchLevelPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private FirmwareVersionDialogFragment mDialog;
|
||||
@Mock
|
||||
private View mView;
|
||||
|
||||
private Context mContext;
|
||||
private SecurityPatchLevelDialogController mController;
|
||||
private SecurityPatchLevelPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(Robolectric.setupActivity(Activity.class));
|
||||
when(mDialog.getContext()).thenReturn(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_noPatchInfo_shouldRemoveSettingFromDialog() {
|
||||
public void getAvailabilityStatus_noPatchInfo_unavailable() {
|
||||
ReflectionHelpers.setStaticField(Build.VERSION.class, "SECURITY_PATCH", "");
|
||||
mController = new SecurityPatchLevelDialogController(mDialog);
|
||||
mController = new SecurityPatchLevelPreferenceController(mContext, "key");
|
||||
|
||||
mController.initialize();
|
||||
|
||||
verify(mDialog).removeSettingFromScreen(SECURITY_PATCH_VALUE_ID);
|
||||
verify(mDialog).removeSettingFromScreen(SECURITY_PATCH_LABEL_ID);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initialize_patchInfoAvailable_shouldRegisterListeners() {
|
||||
public void getAvailabilityStatus_hasPatchInfo_available() {
|
||||
ReflectionHelpers.setStaticField(Build.VERSION.class, "SECURITY_PATCH", "foobar");
|
||||
mController = new SecurityPatchLevelDialogController(mDialog);
|
||||
mController = new SecurityPatchLevelPreferenceController(mContext, "key");
|
||||
|
||||
mController.initialize();
|
||||
|
||||
verify(mDialog).registerClickListener(eq(SECURITY_PATCH_LABEL_ID), any());
|
||||
verify(mDialog).registerClickListener(eq(SECURITY_PATCH_VALUE_ID), any());
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_noActivityIntent_shouldDoNothing() {
|
||||
when(mPackageManager.queryIntentActivities(any(), anyInt()))
|
||||
.thenReturn(Collections.emptyList());
|
||||
mController = new SecurityPatchLevelDialogController(mDialog);
|
||||
mController = new SecurityPatchLevelPreferenceController(mContext, "key");
|
||||
ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
|
||||
|
||||
mController.onClick(mView);
|
||||
final Preference pref = new Preference(mContext);
|
||||
pref.setKey(mController.getPreferenceKey());
|
||||
|
||||
mController.handlePreferenceTreeClick(pref);
|
||||
|
||||
verify(mContext, never()).startActivity(any());
|
||||
}
|
||||
@@ -104,10 +96,14 @@ public class SecurityPatchLevelDialogControllerTest {
|
||||
public void onClick_activityIntentFound_shouldStartActivity() {
|
||||
when(mPackageManager.queryIntentActivities(any(), anyInt()))
|
||||
.thenReturn(Collections.singletonList(null));
|
||||
mController = new SecurityPatchLevelDialogController(mDialog);
|
||||
|
||||
mController = new SecurityPatchLevelPreferenceController(mContext, "key");
|
||||
ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
|
||||
|
||||
mController.onClick(mView);
|
||||
final Preference pref = new Preference(mContext);
|
||||
pref.setKey(mController.getPreferenceKey());
|
||||
|
||||
mController.handlePreferenceTreeClick(pref);
|
||||
|
||||
verify(mContext).startActivity(any());
|
||||
}
|
Reference in New Issue
Block a user