Use SystemUpdateManager to provide system update info.
Change-Id: I38b631cda8aa63e478c74625eba3d18f9a5723bd Fixes: 36874007 Test: robotests
This commit is contained in:
@@ -8343,8 +8343,10 @@
|
|||||||
<!-- Backup disabled summary [CHAR LIMIT=NONE] -->
|
<!-- Backup disabled summary [CHAR LIMIT=NONE] -->
|
||||||
<string name="backup_disabled">Back up disabled</string>
|
<string name="backup_disabled">Back up disabled</string>
|
||||||
|
|
||||||
<!-- Summary of device info page [CHAR LIMIT=NONE] -->
|
<!-- Summary of Android version info [CHAR LIMIT=NONE] -->
|
||||||
<string name="about_summary">Updated to Android <xliff:g id="version" example="6.0">%1$s</xliff:g></string>
|
<string name="android_version_summary">Updated to Android <xliff:g id="version" example="6.0">%1$s</xliff:g></string>
|
||||||
|
<!-- Summary of Android version info (when there is a pending upgrade available) [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="android_version_pending_update_summary">Update available</string>
|
||||||
|
|
||||||
<!-- Title for dialog displayed when user clicks on a setting locked by an admin [CHAR LIMIT=30] -->
|
<!-- Title for dialog displayed when user clicks on a setting locked by an admin [CHAR LIMIT=30] -->
|
||||||
<string name="disabled_by_policy_title">Action not allowed</string>
|
<string name="disabled_by_policy_title">Action not allowed</string>
|
||||||
|
@@ -55,7 +55,7 @@
|
|||||||
android:summary="@string/summary_placeholder"
|
android:summary="@string/summary_placeholder"
|
||||||
android:icon="@drawable/ic_system_update"
|
android:icon="@drawable/ic_system_update"
|
||||||
android:order="-30"
|
android:order="-30"
|
||||||
settings:controller="com.android.settings.deviceinfo.SystemUpdatePreferenceController">
|
settings:controller="com.android.settings.system.SystemUpdatePreferenceController">
|
||||||
<intent android:action="android.settings.SYSTEM_UPDATE_SETTINGS" />
|
<intent android:action="android.settings.SYSTEM_UPDATE_SETTINGS" />
|
||||||
</Preference>
|
</Preference>
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
android:key="additional_system_update_settings"
|
android:key="additional_system_update_settings"
|
||||||
android:title="@string/additional_system_update_settings_list_item_title"
|
android:title="@string/additional_system_update_settings_list_item_title"
|
||||||
android:order="-31"
|
android:order="-31"
|
||||||
settings:controller="com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController">
|
settings:controller="com.android.settings.system.AdditionalSystemUpdatePreferenceController">
|
||||||
<intent android:action="android.intent.action.MAIN"
|
<intent android:action="android.intent.action.MAIN"
|
||||||
android:targetPackage="@string/additional_system_update"
|
android:targetPackage="@string/additional_system_update"
|
||||||
android:targetClass="@string/additional_system_update_menu" />
|
android:targetClass="@string/additional_system_update_menu" />
|
||||||
|
@@ -13,13 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.android.settings.deviceinfo;
|
package com.android.settings.system;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
|
|
||||||
public class AdditionalSystemUpdatePreferenceController extends BasePreferenceController {
|
public class AdditionalSystemUpdatePreferenceController extends BasePreferenceController {
|
||||||
|
|
@@ -26,8 +26,6 @@ import com.android.internal.logging.nano.MetricsProto;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.backup.BackupSettingsActivityPreferenceController;
|
import com.android.settings.backup.BackupSettingsActivityPreferenceController;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
|
|
||||||
import com.android.settings.deviceinfo.SystemUpdatePreferenceController;
|
|
||||||
import com.android.settings.gestures.GesturesSettingPreferenceController;
|
import com.android.settings.gestures.GesturesSettingPreferenceController;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
|
@@ -13,14 +13,17 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.android.settings.deviceinfo;
|
package com.android.settings.system;
|
||||||
|
|
||||||
import static android.content.Context.CARRIER_CONFIG_SERVICE;
|
import static android.content.Context.CARRIER_CONFIG_SERVICE;
|
||||||
|
import static android.content.Context.SYSTEM_UPDATE_SERVICE;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
|
import android.os.SystemUpdateManager;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
@@ -39,10 +42,12 @@ public class SystemUpdatePreferenceController extends BasePreferenceController {
|
|||||||
private static final String KEY_SYSTEM_UPDATE_SETTINGS = "system_update_settings";
|
private static final String KEY_SYSTEM_UPDATE_SETTINGS = "system_update_settings";
|
||||||
|
|
||||||
private final UserManager mUm;
|
private final UserManager mUm;
|
||||||
|
private final SystemUpdateManager mUpdateManager;
|
||||||
|
|
||||||
public SystemUpdatePreferenceController(Context context) {
|
public SystemUpdatePreferenceController(Context context) {
|
||||||
super(context, KEY_SYSTEM_UPDATE_SETTINGS);
|
super(context, KEY_SYSTEM_UPDATE_SETTINGS);
|
||||||
mUm = UserManager.get(context);
|
mUm = UserManager.get(context);
|
||||||
|
mUpdateManager = (SystemUpdateManager) context.getSystemService(SYSTEM_UPDATE_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -84,7 +89,27 @@ public class SystemUpdatePreferenceController extends BasePreferenceController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSummary() {
|
public String getSummary() {
|
||||||
return mContext.getString(R.string.about_summary, Build.VERSION.RELEASE);
|
final Bundle updateInfo = mUpdateManager.retrieveSystemUpdateInfo();
|
||||||
|
String summary = mContext.getString(R.string.android_version_summary,
|
||||||
|
Build.VERSION.RELEASE);
|
||||||
|
switch (updateInfo.getInt(SystemUpdateManager.KEY_STATUS)) {
|
||||||
|
case SystemUpdateManager.STATUS_WAITING_DOWNLOAD:
|
||||||
|
case SystemUpdateManager.STATUS_IN_PROGRESS:
|
||||||
|
case SystemUpdateManager.STATUS_WAITING_INSTALL:
|
||||||
|
case SystemUpdateManager.STATUS_WAITING_REBOOT:
|
||||||
|
summary = mContext.getString(R.string.android_version_pending_update_summary);
|
||||||
|
break;
|
||||||
|
case SystemUpdateManager.STATUS_UNKNOWN:
|
||||||
|
Log.d(TAG, "Update statue unknown");
|
||||||
|
// fall through to next branch
|
||||||
|
case SystemUpdateManager.STATUS_IDLE:
|
||||||
|
final String version = updateInfo.getString(SystemUpdateManager.KEY_TITLE);
|
||||||
|
if (!TextUtils.isEmpty(version)) {
|
||||||
|
summary = mContext.getString(R.string.android_version_summary, version);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
37
tests/robotests/src/android/os/SystemUpdateManager.java
Normal file
37
tests/robotests/src/android/os/SystemUpdateManager.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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 android.os;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duplicate class for platform SystemUpdateManager to get around Robolectric sdk problem.
|
||||||
|
*/
|
||||||
|
public class SystemUpdateManager {
|
||||||
|
|
||||||
|
public static final String KEY_STATUS = "status";
|
||||||
|
public static final String KEY_TITLE = "title";
|
||||||
|
|
||||||
|
public static final int STATUS_UNKNOWN = 0;
|
||||||
|
public static final int STATUS_IDLE = 1;
|
||||||
|
public static final int STATUS_WAITING_DOWNLOAD = 2;
|
||||||
|
public static final int STATUS_IN_PROGRESS = 3;
|
||||||
|
public static final int STATUS_WAITING_INSTALL = 4;
|
||||||
|
public static final int STATUS_WAITING_REBOOT = 5;
|
||||||
|
|
||||||
|
public Bundle retrieveSystemUpdateInfo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@@ -13,20 +13,18 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.android.settings.deviceinfo;
|
package com.android.settings.system;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
@@ -13,17 +13,20 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.android.settings.deviceinfo;
|
package com.android.settings.system;
|
||||||
|
|
||||||
|
import static android.os.SystemUpdateManager.KEY_STATUS;
|
||||||
|
import static android.os.SystemUpdateManager.KEY_TITLE;
|
||||||
|
import static android.os.SystemUpdateManager.STATUS_IDLE;
|
||||||
|
import static android.os.SystemUpdateManager.STATUS_UNKNOWN;
|
||||||
|
import static android.os.SystemUpdateManager.STATUS_WAITING_DOWNLOAD;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.UserManager;
|
import android.os.Bundle;
|
||||||
|
import android.os.SystemUpdateManager;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
@@ -55,6 +58,8 @@ public class SystemUpdatePreferenceControllerTest {
|
|||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
@Mock
|
||||||
|
private SystemUpdateManager mSystemUpdateManager;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private SystemUpdatePreferenceController mController;
|
private SystemUpdatePreferenceController mController;
|
||||||
@@ -64,7 +69,8 @@ public class SystemUpdatePreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
|
ShadowApplication.getInstance().setSystemService(Context.SYSTEM_UPDATE_SERVICE,
|
||||||
|
mSystemUpdateManager);
|
||||||
mController = new SystemUpdatePreferenceController(mContext);
|
mController = new SystemUpdatePreferenceController(mContext);
|
||||||
mPreference = new Preference(RuntimeEnvironment.application);
|
mPreference = new Preference(RuntimeEnvironment.application);
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
@@ -118,11 +124,41 @@ public class SystemUpdatePreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_shouldSetToAndroidVersion() {
|
public void updateState_systemUpdateStatusUnknown_shouldSetToAndroidVersion() {
|
||||||
|
final Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt(KEY_STATUS, STATUS_UNKNOWN);
|
||||||
|
when(mSystemUpdateManager.retrieveSystemUpdateInfo()).thenReturn(bundle);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertThat(mPreference.getSummary())
|
assertThat(mPreference.getSummary()).isEqualTo(
|
||||||
.isEqualTo(RuntimeEnvironment.application.getString(R.string.about_summary,
|
mContext.getString(R.string.android_version_summary, Build.VERSION.RELEASE));
|
||||||
Build.VERSION.RELEASE));
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_systemUpdateStatusIdle_shouldSetToAndroidVersion() {
|
||||||
|
final String testReleaseName = "ANDROID TEST VERSION";
|
||||||
|
|
||||||
|
final Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt(KEY_STATUS, STATUS_IDLE);
|
||||||
|
bundle.putString(KEY_TITLE, testReleaseName);
|
||||||
|
when(mSystemUpdateManager.retrieveSystemUpdateInfo()).thenReturn(bundle);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo(
|
||||||
|
mContext.getString(R.string.android_version_summary, testReleaseName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_systemUpdateInProgress_shouldSetToUpdatePending() {
|
||||||
|
final Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt(KEY_STATUS, STATUS_WAITING_DOWNLOAD);
|
||||||
|
when(mSystemUpdateManager.retrieveSystemUpdateInfo()).thenReturn(bundle);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo(
|
||||||
|
mContext.getString(R.string.android_version_pending_update_summary));
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user