diff options
19 files changed, 796 insertions, 78 deletions
diff --git a/api/current.txt b/api/current.txt index a4ffb6a37d83..f105bb8be094 100644 --- a/api/current.txt +++ b/api/current.txt @@ -24754,6 +24754,7 @@ package android.media { field public static final java.lang.String MIMETYPE_AUDIO_AMR_NB = "audio/3gpp"; field public static final java.lang.String MIMETYPE_AUDIO_AMR_WB = "audio/amr-wb"; field public static final java.lang.String MIMETYPE_AUDIO_EAC3 = "audio/eac3"; + field public static final java.lang.String MIMETYPE_AUDIO_EAC3_JOC = "audio/eac3-joc"; field public static final java.lang.String MIMETYPE_AUDIO_FLAC = "audio/flac"; field public static final java.lang.String MIMETYPE_AUDIO_G711_ALAW = "audio/g711-alaw"; field public static final java.lang.String MIMETYPE_AUDIO_G711_MLAW = "audio/g711-mlaw"; diff --git a/core/java/android/annotation/UnsupportedAppUsage.java b/core/java/android/annotation/UnsupportedAppUsage.java index 65e3f25f8fb6..ac3daaf638ad 100644 --- a/core/java/android/annotation/UnsupportedAppUsage.java +++ b/core/java/android/annotation/UnsupportedAppUsage.java @@ -26,16 +26,32 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; /** - * Indicates that a class member, that is not part of the SDK, is used by apps. - * Since the member is not part of the SDK, such use is not supported. + * Indicates that this non-SDK interface is used by apps. A non-SDK interface is a + * class member (field or method) that is not part of the public SDK. Since the + * member is not part of the SDK, usage by apps is not supported. * - * <p>This annotation acts as a heads up that changing a given method or field + * <h2>If you are an Android App developer</h2> + * + * This annotation indicates that you may be able to access the member, but that + * this access is discouraged and not supported by Android. If there is a value + * for {@link #maxTargetSdk()} on the annotation, access will be restricted based + * on the {@code targetSdkVersion} value set in your manifest. + * + * <p>Fields and methods annotated with this are likely to be restricted, changed + * or removed in future Android releases. If you rely on these members for + * functionality that is not otherwise supported by Android, consider filing a + * <a href="http://g.co/dev/appcompat">feature request</a>. + * + * <h2>If you are an Android OS developer</h2> + * + * This annotation acts as a heads up that changing a given method or field * may affect apps, potentially breaking them when the next Android version is * released. In some cases, for members that are heavily used, this annotation * may imply restrictions on changes to the member. * * <p>This annotation also results in access to the member being permitted by the - * runtime, with a warning being generated in debug builds. + * runtime, with a warning being generated in debug builds. Which apps can access + * the member is determined by the value of {@link #maxTargetSdk()}. * * <p>For more details, see go/UnsupportedAppUsage. * diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index de6afcbad9a6..9380695f39c4 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -12852,6 +12852,13 @@ public final class Settings { public static final String HIDDEN_API_POLICY = "hidden_api_policy"; /** + * Current version of signed configuration applied. + * + * @hide + */ + public static final String SIGNED_CONFIG_VERSION = "signed_config_version"; + + /** * Timeout for a single {@link android.media.soundtrigger.SoundTriggerDetectionService} * operation (in ms). * diff --git a/core/proto/android/stats/devicepolicy/device_policy_enums.proto b/core/proto/android/stats/devicepolicy/device_policy_enums.proto index 5726d9ab0466..c7a6b68fbc00 100644 --- a/core/proto/android/stats/devicepolicy/device_policy_enums.proto +++ b/core/proto/android/stats/devicepolicy/device_policy_enums.proto @@ -51,7 +51,7 @@ enum EventId { SET_ALWAYS_ON_VPN_PACKAGE = 26; SET_PERMITTED_INPUT_METHODS = 27; SET_PERMITTED_ACCESSIBILITY_SERVICES = 28; - SET_SCREEN_CAPTURE_DISABLE = 29; + SET_SCREEN_CAPTURE_DISABLED = 29; SET_CAMERA_DISABLED = 30; QUERY_SUMMARY_FOR_USER = 31; QUERY_SUMMARY = 32; @@ -64,7 +64,7 @@ enum EventId { SET_ORGANIZATION_COLOR = 39; SET_PROFILE_NAME = 40; SET_USER_ICON = 41; - SET_DEVICE_OWNER_LOCKSCREEN_INFO = 42; + SET_DEVICE_OWNER_LOCK_SCREEN_INFO = 42; SET_SHORT_SUPPORT_MESSAGE = 43; SET_LONG_SUPPORT_MESSAGE = 44; SET_CROSS_PROFILE_CONTACTS_SEARCH_DISABLED = 45; @@ -139,4 +139,6 @@ enum EventId { SET_GLOBAL_SETTING = 111; PM_IS_INSTALLER_DEVICE_OWNER_OR_AFFILIATED_PROFILE_OWNER = 112; PM_UNINSTALL = 113; + WIFI_SERVICE_ADD_NETWORK_SUGGESTIONS = 114; + WIFI_SERVICE_ADD_OR_UPDATE_NETWORK = 115; } diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java index 49a7555c2ac4..3a37fb627b26 100644 --- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java +++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java @@ -415,6 +415,7 @@ public class SettingsBackupTest { Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, Settings.Global.SHOW_RESTART_IN_CRASH_DIALOG, Settings.Global.SHOW_TEMPERATURE_WARNING, + Settings.Global.SIGNED_CONFIG_VERSION, Settings.Global.SMART_SELECTION_UPDATE_CONTENT_URL, Settings.Global.SMART_SELECTION_UPDATE_METADATA_URL, Settings.Global.SMS_ACCESS_RESTRICTION_ENABLED, diff --git a/media/java/android/media/MediaCodecInfo.java b/media/java/android/media/MediaCodecInfo.java index 95e3df2fd7c5..902582905b0e 100644 --- a/media/java/android/media/MediaCodecInfo.java +++ b/media/java/android/media/MediaCodecInfo.java @@ -1135,6 +1135,10 @@ public final class MediaCodecInfo { maxChannels = 6; } else if (mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_EAC3)) { maxChannels = 16; + } else if (mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_EAC3_JOC)) { + sampleRates = new int[] { 48000 }; + bitRates = Range.create(32000, 6144000); + maxChannels = 16; } else if (mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_AC4)) { sampleRates = new int[] { 44100, 48000, 96000, 192000 }; bitRates = Range.create(16000, 2688000); diff --git a/media/java/android/media/MediaFormat.java b/media/java/android/media/MediaFormat.java index b62108f1f4e7..594a22457cc3 100644 --- a/media/java/android/media/MediaFormat.java +++ b/media/java/android/media/MediaFormat.java @@ -147,6 +147,7 @@ public final class MediaFormat { public static final String MIMETYPE_AUDIO_MSGSM = "audio/gsm"; public static final String MIMETYPE_AUDIO_AC3 = "audio/ac3"; public static final String MIMETYPE_AUDIO_EAC3 = "audio/eac3"; + public static final String MIMETYPE_AUDIO_EAC3_JOC = "audio/eac3-joc"; public static final String MIMETYPE_AUDIO_AC4 = "audio/ac4"; public static final String MIMETYPE_AUDIO_SCRAMBLED = "audio/scrambled"; diff --git a/packages/SettingsLib/Android.bp b/packages/SettingsLib/Android.bp index cc17b25d9a40..0126e7e59915 100644 --- a/packages/SettingsLib/Android.bp +++ b/packages/SettingsLib/Android.bp @@ -18,6 +18,7 @@ android_library { "SettingsLibSettingsSpinner", "SettingsLayoutPreference", "ActionButtonsPreference", + "SettingsLibEntityHeaderWidgets", ], // ANDROIDMK TRANSLATION ERROR: unsupported assignment to LOCAL_SHARED_JAVA_LIBRARIES diff --git a/packages/SettingsLib/EntityHeaderWidgets/Android.bp b/packages/SettingsLib/EntityHeaderWidgets/Android.bp new file mode 100644 index 000000000000..3ca4ecd33ce4 --- /dev/null +++ b/packages/SettingsLib/EntityHeaderWidgets/Android.bp @@ -0,0 +1,14 @@ +android_library { + name: "SettingsLibEntityHeaderWidgets", + + srcs: ["src/**/*.java"], + resource_dirs: ["res"], + + static_libs: [ + "androidx.annotation_annotation", + "SettingsLibAppPreference" + ], + + sdk_version: "system_current", + min_sdk_version: "21", +} diff --git a/packages/SettingsLib/EntityHeaderWidgets/AndroidManifest.xml b/packages/SettingsLib/EntityHeaderWidgets/AndroidManifest.xml new file mode 100644 index 000000000000..4b9f1ab8d6cc --- /dev/null +++ b/packages/SettingsLib/EntityHeaderWidgets/AndroidManifest.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. + --> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.settingslib.widget"> + + <uses-sdk android:minSdkVersion="21" /> + +</manifest> diff --git a/packages/SettingsLib/EntityHeaderWidgets/res/layout/app_entities_header.xml b/packages/SettingsLib/EntityHeaderWidgets/res/layout/app_entities_header.xml new file mode 100644 index 000000000000..9f30eda242f6 --- /dev/null +++ b/packages/SettingsLib/EntityHeaderWidgets/res/layout/app_entities_header.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. + --> + +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/app_entities_header" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingStart="24dp" + android:paddingEnd="8dp" + android:gravity="center" + android:orientation="vertical"> + + <TextView + android:id="@+id/header_title" + android:layout_width="wrap_content" + android:layout_height="48dp" + android:gravity="center" + android:textAppearance="@style/AppEntitiesHeader.Text.HeaderTitle"/> + + <LinearLayout + android:id="@+id/all_apps_view" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:gravity="center"> + + <include + android:id="@+id/app1_view" + layout="@layout/app_view"/> + + <include + android:id="@+id/app2_view" + layout="@layout/app_view"/> + + <include + android:id="@+id/app3_view" + layout="@layout/app_view"/> + + </LinearLayout> + + <Button + android:id="@+id/header_details" + style="@*android:style/Widget.DeviceDefault.Button.Borderless.Colored" + android:layout_width="wrap_content" + android:layout_height="48dp" + android:gravity="center"/> + +</LinearLayout> diff --git a/packages/SettingsLib/EntityHeaderWidgets/res/layout/app_view.xml b/packages/SettingsLib/EntityHeaderWidgets/res/layout/app_view.xml new file mode 100644 index 000000000000..fcafa3140955 --- /dev/null +++ b/packages/SettingsLib/EntityHeaderWidgets/res/layout/app_view.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. + --> + +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:layout_marginEnd="16dp" + android:gravity="center" + android:orientation="vertical"> + + <ImageView + android:id="@+id/app_icon" + android:layout_width="@dimen/secondary_app_icon_size" + android:layout_height="@dimen/secondary_app_icon_size" + android:layout_marginBottom="12dp"/> + + <TextView + android:id="@+id/app_title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginBottom="2dp" + android:singleLine="true" + android:ellipsize="marquee" + android:textAppearance="@style/AppEntitiesHeader.Text.Title"/> + + <TextView + android:id="@+id/app_summary" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:singleLine="true" + android:ellipsize="marquee" + android:textAppearance="@style/AppEntitiesHeader.Text.Summary"/> + +</LinearLayout>
\ No newline at end of file diff --git a/packages/SettingsLib/EntityHeaderWidgets/res/values/styles.xml b/packages/SettingsLib/EntityHeaderWidgets/res/values/styles.xml new file mode 100644 index 000000000000..0eefd4bff97f --- /dev/null +++ b/packages/SettingsLib/EntityHeaderWidgets/res/values/styles.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. + --> + +<resources> + <style name="AppEntitiesHeader.Text" + parent="@android:style/TextAppearance.Material.Subhead"> + <item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item> + <item name="android:textColor">?android:attr/textColorPrimary</item> + </style> + + <style name="AppEntitiesHeader.Text.HeaderTitle"> + <item name="android:textSize">14sp</item> + </style> + + <style name="AppEntitiesHeader.Text.Title"> + <item name="android:textSize">16sp</item> + </style> + + <style name="AppEntitiesHeader.Text.Summary" + parent="@android:style/TextAppearance.Material.Body1"> + <item name="android:textColor">?android:attr/textColorSecondary</item> + <item name="android:textSize">14sp</item> + </style> +</resources>
\ No newline at end of file diff --git a/packages/SettingsLib/EntityHeaderWidgets/src/com/android/settingslib/widget/AppEntitiesHeaderController.java b/packages/SettingsLib/EntityHeaderWidgets/src/com/android/settingslib/widget/AppEntitiesHeaderController.java new file mode 100644 index 000000000000..8ccf89fc38b0 --- /dev/null +++ b/packages/SettingsLib/EntityHeaderWidgets/src/com/android/settingslib/widget/AppEntitiesHeaderController.java @@ -0,0 +1,267 @@ +/* + * 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 com.android.settingslib.widget; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.drawable.Drawable; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.annotation.VisibleForTesting; + +/** + * This is used to initialize view which was inflated + * from {@link R.xml.app_entities_header.xml}. + * + * <p>The view looks like below. + * + * <pre> + * -------------------------------------------------------------- + * | Header title | + * -------------------------------------------------------------- + * | App1 icon | App2 icon | App3 icon | + * | App1 title | App2 title | App3 title | + * | App1 summary | App2 summary | App3 summary | + * |------------------------------------------------------------- + * | Header details | + * -------------------------------------------------------------- + * </pre> + * + * <p>How to use AppEntitiesHeaderController? + * + * <p>1. Add a {@link LayoutPreference} in layout XML file. + * <pre> + * <com.android.settingslib.widget.LayoutPreference + * android:key="app_entities_header" + * android:layout="@layout/app_entities_header"/> + * </pre> + * + * <p>2. Use AppEntitiesHeaderController to call below methods, then you can initialize + * view of <code>app_entities_header</code>. + * + * <pre> + * + * View headerView = ((LayoutPreference) screen.findPreference("app_entities_header")) + * .findViewById(R.id.app_entities_header); + * + * AppEntitiesHeaderController.newInstance(context, headerView) + * .setHeaderTitleRes(R.string.xxxxx) + * .setHeaderDetailsRes(R.string.xxxxx) + * .setHeaderDetailsClickListener(onClickListener) + * .setAppEntity(0, icon, "app title", "app summary") + * .setAppEntity(1, icon, "app title", "app summary") + * .setAppEntity(2, icon, "app title", "app summary") + * .apply(); + * </pre> + */ +public class AppEntitiesHeaderController { + + private static final String TAG = "AppEntitiesHeaderCtl"; + + @VisibleForTesting + static final int MAXIMUM_APPS = 3; + + private final Context mContext; + private final TextView mHeaderTitleView; + private final Button mHeaderDetailsView; + + private final AppEntity[] mAppEntities; + private final View[] mAppEntityViews; + private final ImageView[] mAppIconViews; + private final TextView[] mAppTitleViews; + private final TextView[] mAppSummaryViews; + + private int mHeaderTitleRes; + private int mHeaderDetailsRes; + private View.OnClickListener mDetailsOnClickListener; + + /** + * Creates a new instance of the controller. + * + * @param context the Context the view is running in + * @param appEntitiesHeaderView view was inflated from <code>app_entities_header</code> + */ + public static AppEntitiesHeaderController newInstance(@NonNull Context context, + @NonNull View appEntitiesHeaderView) { + return new AppEntitiesHeaderController(context, appEntitiesHeaderView); + } + + private AppEntitiesHeaderController(Context context, View appEntitiesHeaderView) { + mContext = context; + mHeaderTitleView = appEntitiesHeaderView.findViewById(R.id.header_title); + mHeaderDetailsView = appEntitiesHeaderView.findViewById(R.id.header_details); + + mAppEntities = new AppEntity[MAXIMUM_APPS]; + mAppIconViews = new ImageView[MAXIMUM_APPS]; + mAppTitleViews = new TextView[MAXIMUM_APPS]; + mAppSummaryViews = new TextView[MAXIMUM_APPS]; + + mAppEntityViews = new View[]{ + appEntitiesHeaderView.findViewById(R.id.app1_view), + appEntitiesHeaderView.findViewById(R.id.app2_view), + appEntitiesHeaderView.findViewById(R.id.app3_view) + }; + + // Initialize view in advance, so we won't take too much time to do it when controller is + // binding view. + for (int index = 0; index < MAXIMUM_APPS; index++) { + final View appView = mAppEntityViews[index]; + mAppIconViews[index] = (ImageView) appView.findViewById(R.id.app_icon); + mAppTitleViews[index] = (TextView) appView.findViewById(R.id.app_title); + mAppSummaryViews[index] = (TextView) appView.findViewById(R.id.app_summary); + } + } + + /** + * Set the text resource for app entities header title. + */ + public AppEntitiesHeaderController setHeaderTitleRes(@StringRes int titleRes) { + mHeaderTitleRes = titleRes; + return this; + } + + /** + * Set the text resource for app entities header details. + */ + public AppEntitiesHeaderController setHeaderDetailsRes(@StringRes int detailsRes) { + mHeaderDetailsRes = detailsRes; + return this; + } + + /** + * Register a callback to be invoked when header details view is clicked. + */ + public AppEntitiesHeaderController setHeaderDetailsClickListener( + @Nullable View.OnClickListener clickListener) { + mDetailsOnClickListener = clickListener; + return this; + } + + /** + * Set an app entity at a specified position view. + * + * @param index the index at which the specified view is to be inserted + * @param icon the icon of app entity + * @param titleRes the title of app entity + * @param summaryRes the summary of app entity + * @return this {@code AppEntitiesHeaderController} object + */ + public AppEntitiesHeaderController setAppEntity(int index, @NonNull Drawable icon, + @Nullable CharSequence titleRes, @Nullable CharSequence summaryRes) { + final AppEntity appEntity = new AppEntity(icon, titleRes, summaryRes); + mAppEntities[index] = appEntity; + return this; + } + + /** + * Remove an app entity at a specified position view. + * + * @param index the index at which the specified view is to be removed + * @return this {@code AppEntitiesHeaderController} object + */ + public AppEntitiesHeaderController removeAppEntity(int index) { + mAppEntities[index] = null; + return this; + } + + /** + * Clear all app entities in app entities header. + * + * @return this {@code AppEntitiesHeaderController} object + */ + public AppEntitiesHeaderController clearAllAppEntities() { + for (int index = 0; index < MAXIMUM_APPS; index++) { + removeAppEntity(index); + } + return this; + } + + /** + * Done mutating app entities header, rebinds everything. + */ + public void apply() { + bindHeaderTitleView(); + bindHeaderDetailsView(); + + // Rebind all apps view + for (int index = 0; index < MAXIMUM_APPS; index++) { + bindAppEntityView(index); + } + } + + private void bindHeaderTitleView() { + CharSequence titleText = ""; + try { + titleText = mContext.getText(mHeaderTitleRes); + } catch (Resources.NotFoundException e) { + Log.e(TAG, "Resource of header title can't not be found!", e); + } + mHeaderTitleView.setText(titleText); + mHeaderTitleView.setVisibility( + TextUtils.isEmpty(titleText) ? View.GONE : View.VISIBLE); + } + + private void bindHeaderDetailsView() { + CharSequence detailsText = ""; + try { + detailsText = mContext.getText(mHeaderDetailsRes); + } catch (Resources.NotFoundException e) { + Log.e(TAG, "Resource of header details can't not be found!", e); + } + mHeaderDetailsView.setText(detailsText); + mHeaderDetailsView.setVisibility( + TextUtils.isEmpty(detailsText) ? View.GONE : View.VISIBLE); + mHeaderDetailsView.setOnClickListener(mDetailsOnClickListener); + } + + private void bindAppEntityView(int index) { + final AppEntity appEntity = mAppEntities[index]; + mAppEntityViews[index].setVisibility(appEntity != null ? View.VISIBLE : View.GONE); + + if (appEntity != null) { + mAppIconViews[index].setImageDrawable(appEntity.icon); + + mAppTitleViews[index].setVisibility( + TextUtils.isEmpty(appEntity.title) ? View.INVISIBLE : View.VISIBLE); + mAppTitleViews[index].setText(appEntity.title); + + mAppSummaryViews[index].setVisibility( + TextUtils.isEmpty(appEntity.summary) ? View.INVISIBLE : View.VISIBLE); + mAppSummaryViews[index].setText(appEntity.summary); + } + } + + private static class AppEntity { + public final Drawable icon; + public final CharSequence title; + public final CharSequence summary; + + AppEntity(Drawable appIcon, CharSequence appTitle, CharSequence appSummary) { + icon = appIcon; + title = appTitle; + summary = appSummary; + } + } +} diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/AppEntitiesHeaderControllerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/AppEntitiesHeaderControllerTest.java new file mode 100644 index 000000000000..c3bc8da89685 --- /dev/null +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/AppEntitiesHeaderControllerTest.java @@ -0,0 +1,181 @@ +/* + * 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 com.android.settingslib.widget; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; + +@RunWith(RobolectricTestRunner.class) +public class AppEntitiesHeaderControllerTest { + + private static final CharSequence TITLE = "APP_TITLE"; + private static final CharSequence SUMMARY = "APP_SUMMARY"; + + @Rule + public final ExpectedException thrown = ExpectedException.none(); + + private Context mContext; + private Drawable mIcon; + private View mAppEntitiesHeaderView; + private AppEntitiesHeaderController mController; + + @Before + public void setUp() { + mContext = RuntimeEnvironment.application; + mAppEntitiesHeaderView = LayoutInflater.from(mContext).inflate( + R.layout.app_entities_header, null /* root */); + mIcon = mContext.getDrawable(R.drawable.ic_menu); + mController = AppEntitiesHeaderController.newInstance(mContext, + mAppEntitiesHeaderView); + } + + @Test + public void assert_amountOfMaximumAppsAreThree() { + assertThat(AppEntitiesHeaderController.MAXIMUM_APPS).isEqualTo(3); + } + + @Test + public void setHeaderTitleRes_setTextRes_shouldSetToTitleView() { + mController.setHeaderTitleRes(R.string.expand_button_title).apply(); + final TextView view = mAppEntitiesHeaderView.findViewById(R.id.header_title); + + assertThat(view.getText()).isEqualTo(mContext.getText(R.string.expand_button_title)); + } + + @Test + public void setHeaderDetailsRes_setTextRes_shouldSetToDetailsView() { + mController.setHeaderDetailsRes(R.string.expand_button_title).apply(); + final TextView view = mAppEntitiesHeaderView.findViewById(R.id.header_details); + + assertThat(view.getText()).isEqualTo(mContext.getText(R.string.expand_button_title)); + } + + @Test + public void setHeaderDetailsClickListener_setClickListener_detailsViewAttachClickListener() { + mController.setHeaderDetailsClickListener(v -> { + }).apply(); + final TextView view = mAppEntitiesHeaderView.findViewById(R.id.header_details); + + assertThat(view.hasOnClickListeners()).isTrue(); + } + + @Test + public void setAppEntity_indexLessThanZero_shouldThrowArrayIndexOutOfBoundsException() { + thrown.expect(ArrayIndexOutOfBoundsException.class); + + mController.setAppEntity(-1, mIcon, TITLE, SUMMARY); + } + + @Test + public void asetAppEntity_indexGreaterThanMaximum_shouldThrowArrayIndexOutOfBoundsException() { + thrown.expect(ArrayIndexOutOfBoundsException.class); + + mController.setAppEntity(AppEntitiesHeaderController.MAXIMUM_APPS + 1, mIcon, TITLE, + SUMMARY); + } + + @Test + public void setAppEntity_addAppToIndex0_shouldShowAppView1() { + mController.setAppEntity(0, mIcon, TITLE, SUMMARY).apply(); + final View app1View = mAppEntitiesHeaderView.findViewById(R.id.app1_view); + final ImageView appIconView = app1View.findViewById(R.id.app_icon); + final TextView appTitle = app1View.findViewById(R.id.app_title); + final TextView appSummary = app1View.findViewById(R.id.app_summary); + + assertThat(app1View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(appIconView.getDrawable()).isNotNull(); + assertThat(appTitle.getText()).isEqualTo(TITLE); + assertThat(appSummary.getText()).isEqualTo(SUMMARY); + } + + @Test + public void setAppEntity_addAppToIndex1_shouldShowAppView2() { + mController.setAppEntity(1, mIcon, TITLE, SUMMARY).apply(); + final View app2View = mAppEntitiesHeaderView.findViewById(R.id.app2_view); + final ImageView appIconView = app2View.findViewById(R.id.app_icon); + final TextView appTitle = app2View.findViewById(R.id.app_title); + final TextView appSummary = app2View.findViewById(R.id.app_summary); + + assertThat(app2View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(appIconView.getDrawable()).isNotNull(); + assertThat(appTitle.getText()).isEqualTo(TITLE); + assertThat(appSummary.getText()).isEqualTo(SUMMARY); + } + + @Test + public void setAppEntity_addAppToIndex2_shouldShowAppView3() { + mController.setAppEntity(2, mIcon, TITLE, SUMMARY).apply(); + final View app3View = mAppEntitiesHeaderView.findViewById(R.id.app3_view); + final ImageView appIconView = app3View.findViewById(R.id.app_icon); + final TextView appTitle = app3View.findViewById(R.id.app_title); + final TextView appSummary = app3View.findViewById(R.id.app_summary); + + assertThat(app3View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(appIconView.getDrawable()).isNotNull(); + assertThat(appTitle.getText()).isEqualTo(TITLE); + assertThat(appSummary.getText()).isEqualTo(SUMMARY); + } + + @Test + public void removeAppEntity_removeIndex0_shouldNotShowAppView1() { + mController.setAppEntity(0, mIcon, TITLE, SUMMARY) + .setAppEntity(1, mIcon, TITLE, SUMMARY).apply(); + final View app1View = mAppEntitiesHeaderView.findViewById(R.id.app1_view); + final View app2View = mAppEntitiesHeaderView.findViewById(R.id.app2_view); + + assertThat(app1View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(app2View.getVisibility()).isEqualTo(View.VISIBLE); + + mController.removeAppEntity(0).apply(); + + assertThat(app1View.getVisibility()).isEqualTo(View.GONE); + assertThat(app2View.getVisibility()).isEqualTo(View.VISIBLE); + } + + @Test + public void clearAllAppEntities_shouldNotShowAllAppViews() { + mController.setAppEntity(0, mIcon, TITLE, SUMMARY) + .setAppEntity(1, mIcon, TITLE, SUMMARY) + .setAppEntity(2, mIcon, TITLE, SUMMARY).apply(); + final View app1View = mAppEntitiesHeaderView.findViewById(R.id.app1_view); + final View app2View = mAppEntitiesHeaderView.findViewById(R.id.app2_view); + final View app3View = mAppEntitiesHeaderView.findViewById(R.id.app3_view); + + assertThat(app1View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(app2View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(app3View.getVisibility()).isEqualTo(View.VISIBLE); + + mController.clearAllAppEntities().apply(); + assertThat(app1View.getVisibility()).isEqualTo(View.GONE); + assertThat(app2View.getVisibility()).isEqualTo(View.GONE); + assertThat(app3View.getVisibility()).isEqualTo(View.GONE); + } +} diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 14503f9d7379..eda9fe15fe36 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -902,6 +902,7 @@ public class ConnectivityService extends IConnectivityManager.Stub // Listen to package add and removal events for all users. intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED); + intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); intentFilter.addDataScheme("package"); mContext.registerReceiverAsUser( @@ -4203,12 +4204,46 @@ public class ConnectivityService extends IConnectivityManager.Stub mPermissionMonitor.onPackageAdded(packageName, uid); } - private void onPackageRemoved(String packageName, int uid) { + private void onPackageReplaced(String packageName, int uid) { + if (TextUtils.isEmpty(packageName) || uid < 0) { + Slog.wtf(TAG, "Invalid package in onPackageReplaced: " + packageName + " | " + uid); + return; + } + final int userId = UserHandle.getUserId(uid); + synchronized (mVpns) { + final Vpn vpn = mVpns.get(userId); + if (vpn == null) { + return; + } + // Legacy always-on VPN won't be affected since the package name is not set. + if (TextUtils.equals(vpn.getAlwaysOnPackage(), packageName)) { + Slog.d(TAG, "Restarting always-on VPN package " + packageName + " for user " + + userId); + vpn.startAlwaysOnVpn(); + } + } + } + + private void onPackageRemoved(String packageName, int uid, boolean isReplacing) { if (TextUtils.isEmpty(packageName) || uid < 0) { Slog.wtf(TAG, "Invalid package in onPackageRemoved: " + packageName + " | " + uid); return; } mPermissionMonitor.onPackageRemoved(uid); + + final int userId = UserHandle.getUserId(uid); + synchronized (mVpns) { + final Vpn vpn = mVpns.get(userId); + if (vpn == null) { + return; + } + // Legacy always-on VPN won't be affected since the package name is not set. + if (TextUtils.equals(vpn.getAlwaysOnPackage(), packageName) && !isReplacing) { + Slog.d(TAG, "Removing always-on VPN package " + packageName + " for user " + + userId); + vpn.setAlwaysOnPackage(null, false); + } + } } private void onUserUnlocked(int userId) { @@ -4245,8 +4280,12 @@ public class ConnectivityService extends IConnectivityManager.Stub onUserUnlocked(userId); } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)) { onPackageAdded(packageName, uid); + } else if (Intent.ACTION_PACKAGE_REPLACED.equals(action)) { + onPackageReplaced(packageName, uid); } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) { - onPackageRemoved(packageName, uid); + final boolean isReplacing = intent.getBooleanExtra( + Intent.EXTRA_REPLACING, false); + onPackageRemoved(packageName, uid, isReplacing); } } }; diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java index b7ed2f9bd473..602aedbc2d00 100644 --- a/services/core/java/com/android/server/connectivity/Vpn.java +++ b/services/core/java/com/android/server/connectivity/Vpn.java @@ -206,45 +206,6 @@ public class Vpn { // Handle of the user initiating VPN. private final int mUserHandle; - // Listen to package removal and change events (update/uninstall) for this user - private final BroadcastReceiver mPackageIntentReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - final Uri data = intent.getData(); - final String packageName = data == null ? null : data.getSchemeSpecificPart(); - if (packageName == null) { - return; - } - - synchronized (Vpn.this) { - // Avoid race where always-on package has been unset - if (!packageName.equals(getAlwaysOnPackage())) { - return; - } - - final String action = intent.getAction(); - Log.i(TAG, "Received broadcast " + action + " for always-on VPN package " - + packageName + " in user " + mUserHandle); - - switch(action) { - case Intent.ACTION_PACKAGE_REPLACED: - // Start vpn after app upgrade - startAlwaysOnVpn(); - break; - case Intent.ACTION_PACKAGE_REMOVED: - final boolean isPackageRemoved = !intent.getBooleanExtra( - Intent.EXTRA_REPLACING, false); - if (isPackageRemoved) { - setAlwaysOnPackage(null, false); - } - break; - } - } - } - }; - - private boolean mIsPackageIntentReceiverRegistered = false; - public Vpn(Looper looper, Context context, INetworkManagementService netService, @UserIdInt int userHandle) { this(looper, context, netService, userHandle, new SystemServices(context)); @@ -500,7 +461,6 @@ public class Vpn { // Prepare this app. The notification will update as a side-effect of updateState(). prepareInternal(packageName); } - maybeRegisterPackageChangeReceiverLocked(packageName); setVpnForcedLocked(mLockdown); return true; } @@ -509,31 +469,6 @@ public class Vpn { return packageName == null || VpnConfig.LEGACY_VPN.equals(packageName); } - private void unregisterPackageChangeReceiverLocked() { - if (mIsPackageIntentReceiverRegistered) { - mContext.unregisterReceiver(mPackageIntentReceiver); - mIsPackageIntentReceiverRegistered = false; - } - } - - private void maybeRegisterPackageChangeReceiverLocked(String packageName) { - // Unregister IntentFilter listening for previous always-on package change - unregisterPackageChangeReceiverLocked(); - - if (!isNullOrLegacyVpn(packageName)) { - mIsPackageIntentReceiverRegistered = true; - - IntentFilter intentFilter = new IntentFilter(); - // Protected intent can only be sent by system. No permission required in register. - intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); - intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); - intentFilter.addDataScheme("package"); - intentFilter.addDataSchemeSpecificPart(packageName, PatternMatcher.PATTERN_LITERAL); - mContext.registerReceiverAsUser( - mPackageIntentReceiver, UserHandle.of(mUserHandle), intentFilter, null, null); - } - } - /** * @return the package name of the VPN controller responsible for always-on VPN, * or {@code null} if none is set or always-on VPN is controlled through @@ -1302,7 +1237,6 @@ public class Vpn { setLockdown(false); mAlwaysOn = false; - unregisterPackageChangeReceiverLocked(); // Quit any active connections agentDisconnect(); } diff --git a/services/core/java/com/android/server/signedconfig/SignedConfigApplicator.java b/services/core/java/com/android/server/signedconfig/SignedConfigApplicator.java index 7ce071faab04..2312f5f0a2a2 100644 --- a/services/core/java/com/android/server/signedconfig/SignedConfigApplicator.java +++ b/services/core/java/com/android/server/signedconfig/SignedConfigApplicator.java @@ -17,12 +17,86 @@ package com.android.server.signedconfig; import android.content.Context; +import android.os.Build; +import android.provider.Settings; +import android.util.ArraySet; +import android.util.Slog; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.Set; class SignedConfigApplicator { - static void applyConfig(Context context, String config, String signature) { - //TODO verify signature - //TODO parse & apply config + private static final String TAG = "SignedConfig"; + + private static final Set<String> ALLOWED_KEYS = Collections.unmodifiableSet(new ArraySet<>( + Arrays.asList( + Settings.Global.HIDDEN_API_POLICY, + Settings.Global.HIDDEN_API_BLACKLIST_EXEMPTIONS + ))); + + private final Context mContext; + private final String mSourcePackage; + + SignedConfigApplicator(Context context, String sourcePackage) { + mContext = context; + mSourcePackage = sourcePackage; } + private boolean checkSignature(String data, String signature) { + Slog.w(TAG, "SIGNATURE CHECK NOT IMPLEMENTED YET!"); + return false; + } + + private int getCurrentConfigVersion() { + return Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.SIGNED_CONFIG_VERSION, 0); + } + + private void updateCurrentConfig(int version, Map<String, String> values) { + for (Map.Entry<String, String> e: values.entrySet()) { + Settings.Global.putString( + mContext.getContentResolver(), + e.getKey(), + e.getValue()); + } + Settings.Global.putInt( + mContext.getContentResolver(), Settings.Global.SIGNED_CONFIG_VERSION, version); + } + + + void applyConfig(String configStr, String signature) { + if (!checkSignature(configStr, signature)) { + Slog.e(TAG, "Signature check on signed configuration in package " + mSourcePackage + + " failed; ignoring"); + return; + } + SignedConfig config; + try { + config = SignedConfig.parse(configStr, ALLOWED_KEYS); + } catch (InvalidConfigException e) { + Slog.e(TAG, "Failed to parse config from package " + mSourcePackage, e); + return; + } + int currentVersion = getCurrentConfigVersion(); + if (currentVersion >= config.version) { + Slog.i(TAG, "Config from package " + mSourcePackage + " is older than existing: " + + config.version + "<=" + currentVersion); + return; + } + // We have new config! + Slog.i(TAG, "Got new signed config from package " + mSourcePackage + ": version " + + config.version + " replacing existing version " + currentVersion); + SignedConfig.PerSdkConfig matchedConfig = + config.getMatchingConfig(Build.VERSION.SDK_INT); + if (matchedConfig == null) { + Slog.i(TAG, "Config is not applicable to current SDK version; ignoring"); + return; + } + + Slog.i(TAG, "Updating signed config to version " + config.version); + updateCurrentConfig(config.version, matchedConfig.values); + } } diff --git a/services/core/java/com/android/server/signedconfig/SignedConfigService.java b/services/core/java/com/android/server/signedconfig/SignedConfigService.java index 148568628397..be1d41dd392b 100644 --- a/services/core/java/com/android/server/signedconfig/SignedConfigService.java +++ b/services/core/java/com/android/server/signedconfig/SignedConfigService.java @@ -85,7 +85,8 @@ public class SignedConfigService { Slog.d(TAG, "Got signed config: " + config); Slog.d(TAG, "Got config signature: " + signature); } - SignedConfigApplicator.applyConfig(mContext, config, signature); + new SignedConfigApplicator(mContext, packageName).applyConfig( + config, signature); } else { if (DBG) Slog.d(TAG, "Package has no config/signature."); } |