diff --git a/res/values/strings.xml b/res/values/strings.xml index 3e211b44d49..4cf03dd1cc8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -8345,8 +8345,10 @@ Back up disabled - - Updated to Android %1$s + + Updated to Android %1$s + + Update available Action not allowed diff --git a/res/xml/system_dashboard_fragment.xml b/res/xml/system_dashboard_fragment.xml index 73aab4bdd81..d8459dd3c9f 100644 --- a/res/xml/system_dashboard_fragment.xml +++ b/res/xml/system_dashboard_fragment.xml @@ -55,7 +55,7 @@ android:summary="@string/summary_placeholder" android:icon="@drawable/ic_system_update" android:order="-30" - settings:controller="com.android.settings.deviceinfo.SystemUpdatePreferenceController"> + settings:controller="com.android.settings.system.SystemUpdatePreferenceController"> @@ -63,7 +63,7 @@ android:key="additional_system_update_settings" android:title="@string/additional_system_update_settings_list_item_title" android:order="-31" - settings:controller="com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController"> + settings:controller="com.android.settings.system.AdditionalSystemUpdatePreferenceController"> diff --git a/src/com/android/settings/deviceinfo/AdditionalSystemUpdatePreferenceController.java b/src/com/android/settings/system/AdditionalSystemUpdatePreferenceController.java similarity index 88% rename from src/com/android/settings/deviceinfo/AdditionalSystemUpdatePreferenceController.java rename to src/com/android/settings/system/AdditionalSystemUpdatePreferenceController.java index f91ed4e69a5..1fbf83574ec 100644 --- a/src/com/android/settings/deviceinfo/AdditionalSystemUpdatePreferenceController.java +++ b/src/com/android/settings/system/AdditionalSystemUpdatePreferenceController.java @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.settings.deviceinfo; +package com.android.settings.system; import android.content.Context; import com.android.settings.core.BasePreferenceController; -import com.android.settings.core.PreferenceControllerMixin; -import com.android.settingslib.core.AbstractPreferenceController; public class AdditionalSystemUpdatePreferenceController extends BasePreferenceController { diff --git a/src/com/android/settings/system/SystemDashboardFragment.java b/src/com/android/settings/system/SystemDashboardFragment.java index 88cafb042cc..deabf543b3a 100644 --- a/src/com/android/settings/system/SystemDashboardFragment.java +++ b/src/com/android/settings/system/SystemDashboardFragment.java @@ -26,8 +26,6 @@ import com.android.internal.logging.nano.MetricsProto; import com.android.settings.R; import com.android.settings.backup.BackupSettingsActivityPreferenceController; 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.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; diff --git a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java b/src/com/android/settings/system/SystemUpdatePreferenceController.java similarity index 73% rename from src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java rename to src/com/android/settings/system/SystemUpdatePreferenceController.java index 28062756104..20f43ef0865 100644 --- a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java +++ b/src/com/android/settings/system/SystemUpdatePreferenceController.java @@ -13,14 +13,17 @@ * See the License for the specific language governing permissions and * 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.SYSTEM_UPDATE_SERVICE; import android.content.Context; import android.content.Intent; import android.os.Build; +import android.os.Bundle; import android.os.PersistableBundle; +import android.os.SystemUpdateManager; import android.os.UserManager; import android.support.v7.preference.Preference; 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 final UserManager mUm; + private final SystemUpdateManager mUpdateManager; public SystemUpdatePreferenceController(Context context) { super(context, KEY_SYSTEM_UPDATE_SETTINGS); mUm = UserManager.get(context); + mUpdateManager = (SystemUpdateManager) context.getSystemService(SYSTEM_UPDATE_SERVICE); } @Override @@ -84,7 +89,27 @@ public class SystemUpdatePreferenceController extends BasePreferenceController { @Override 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; } /** diff --git a/tests/robotests/src/android/os/SystemUpdateManager.java b/tests/robotests/src/android/os/SystemUpdateManager.java new file mode 100644 index 00000000000..f81df3600ba --- /dev/null +++ b/tests/robotests/src/android/os/SystemUpdateManager.java @@ -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; + } +} diff --git a/tests/robotests/src/com/android/settings/deviceinfo/AdditionalSystemUpdatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/system/AdditionalSystemUpdatePreferenceControllerTest.java similarity index 94% rename from tests/robotests/src/com/android/settings/deviceinfo/AdditionalSystemUpdatePreferenceControllerTest.java rename to tests/robotests/src/com/android/settings/system/AdditionalSystemUpdatePreferenceControllerTest.java index e5708ba607f..43f48c08f05 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/AdditionalSystemUpdatePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/system/AdditionalSystemUpdatePreferenceControllerTest.java @@ -13,20 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.settings.deviceinfo; +package com.android.settings.system; import static com.google.common.truth.Truth.assertThat; import android.content.Context; -import com.android.settings.R; import com.android.settings.TestConfig; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; diff --git a/tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/system/SystemUpdatePreferenceControllerTest.java similarity index 64% rename from tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java rename to tests/robotests/src/com/android/settings/system/SystemUpdatePreferenceControllerTest.java index b5b84da78a3..95a18a11a51 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/system/SystemUpdatePreferenceControllerTest.java @@ -13,17 +13,20 @@ * See the License for the specific language governing permissions and * 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 org.mockito.Answers.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.content.Context; 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.PreferenceScreen; @@ -55,6 +58,8 @@ public class SystemUpdatePreferenceControllerTest { @Mock private PreferenceScreen mScreen; + @Mock + private SystemUpdateManager mSystemUpdateManager; private Context mContext; private SystemUpdatePreferenceController mController; @@ -64,7 +69,8 @@ public class SystemUpdatePreferenceControllerTest { public void setUp() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; - + ShadowApplication.getInstance().setSystemService(Context.SYSTEM_UPDATE_SERVICE, + mSystemUpdateManager); mController = new SystemUpdatePreferenceController(mContext); mPreference = new Preference(RuntimeEnvironment.application); mPreference.setKey(mController.getPreferenceKey()); @@ -118,11 +124,41 @@ public class SystemUpdatePreferenceControllerTest { } @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); - assertThat(mPreference.getSummary()) - .isEqualTo(RuntimeEnvironment.application.getString(R.string.about_summary, - Build.VERSION.RELEASE)); + assertThat(mPreference.getSummary()).isEqualTo( + mContext.getString(R.string.android_version_summary, 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)); } } \ No newline at end of file