diff options
35 files changed, 473 insertions, 92 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index ec1e665dbdb1..3a6fc590648e 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -49292,7 +49292,7 @@ package android.view { method @NonNull public android.view.SurfaceControl.Transaction setDataSpace(@NonNull android.view.SurfaceControl, int); method @NonNull public android.view.SurfaceControl.Transaction setFrameRate(@NonNull android.view.SurfaceControl, @FloatRange(from=0.0) float, int); method @NonNull public android.view.SurfaceControl.Transaction setFrameRate(@NonNull android.view.SurfaceControl, @FloatRange(from=0.0) float, int, int); - method @NonNull public android.view.SurfaceControl.Transaction setGeometry(@NonNull android.view.SurfaceControl, @Nullable android.graphics.Rect, @Nullable android.graphics.Rect, int); + method @Deprecated @NonNull public android.view.SurfaceControl.Transaction setGeometry(@NonNull android.view.SurfaceControl, @Nullable android.graphics.Rect, @Nullable android.graphics.Rect, int); method @NonNull public android.view.SurfaceControl.Transaction setLayer(@NonNull android.view.SurfaceControl, @IntRange(from=java.lang.Integer.MIN_VALUE, to=java.lang.Integer.MAX_VALUE) int); method @NonNull public android.view.SurfaceControl.Transaction setOpaque(@NonNull android.view.SurfaceControl, boolean); method @NonNull public android.view.SurfaceControl.Transaction setPosition(@NonNull android.view.SurfaceControl, float, float); diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 98cef95885bd..632af2315bcd 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -3094,6 +3094,10 @@ public final class SurfaceControl implements Parcelable { * @param destFrame The destination rectangle in parent space. Or null for the source frame. * @param orientation The buffer rotation * @return This transaction object. + * @deprecated Use {@link #setCrop(SurfaceControl, Rect)}, + * {@link #setBufferTransform(SurfaceControl, int)}, + * {@link #setPosition(SurfaceControl, float, float)} and + * {@link #setScale(SurfaceControl, float, float)} instead. */ @NonNull public Transaction setGeometry(@NonNull SurfaceControl sc, @Nullable Rect sourceCrop, diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 286b502791c8..34a13868f4d7 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -14173,7 +14173,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, && isAccessibilityPane()) { // If the pane isn't visible, content changed events are sufficient unless we're // reporting that the view just disappeared - if ((getVisibility() == VISIBLE) + if ((isAggregatedVisible()) || (changeType == AccessibilityEvent.CONTENT_CHANGE_TYPE_PANE_DISAPPEARED)) { final AccessibilityEvent event = AccessibilityEvent.obtain(); onInitializeAccessibilityEvent(event); diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 3dfb4a5a084a..c207af53fab7 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -12774,7 +12774,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener /** * Called when a context menu option for the text view is selected. Currently * this will be one of {@link android.R.id#selectAll}, {@link android.R.id#cut}, - * {@link android.R.id#copy}, {@link android.R.id#paste} or {@link android.R.id#shareText}. + * {@link android.R.id#copy}, {@link android.R.id#paste}, + * {@link android.R.id#pasteAsPlainText} (starting at API level 23) or + * {@link android.R.id#shareText}. * * @return true if the context menu item action was performed. */ @@ -12965,6 +12967,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * method. The default actions can also be removed from the menu using * {@link android.view.Menu#removeItem(int)} and passing {@link android.R.id#selectAll}, * {@link android.R.id#cut}, {@link android.R.id#copy}, {@link android.R.id#paste}, + * {@link android.R.id#pasteAsPlainText} (starting at API level 23), * {@link android.R.id#replaceText} or {@link android.R.id#shareText} ids as parameters. * * <p>Returning false from @@ -13003,7 +13006,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * {@link android.view.ActionMode.Callback#onPrepareActionMode(android.view.ActionMode, * android.view.Menu)} method. The default actions can also be removed from the menu using * {@link android.view.Menu#removeItem(int)} and passing {@link android.R.id#selectAll}, - * {@link android.R.id#paste} or {@link android.R.id#replaceText} ids as parameters.</p> + * {@link android.R.id#paste}, {@link android.R.id#pasteAsPlainText} (starting at API + * level 23) or {@link android.R.id#replaceText} ids as parameters.</p> * * <p>Returning false from * {@link android.view.ActionMode.Callback#onCreateActionMode(android.view.ActionMode, diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index d4c03e412fcb..80317b8f5305 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -6912,6 +6912,10 @@ android:permission="android.permission.BIND_JOB_SERVICE"> </service> + <service android:name="com.android.server.appsearch.contactsindexer.ContactsIndexerMaintenanceService" + android:permission="android.permission.BIND_JOB_SERVICE"> + </service> + <service android:name="com.android.server.pm.PackageManagerShellCommandDataLoader" android:exported="false"> <intent-filter> diff --git a/packages/CompanionDeviceManager/Android.bp b/packages/CompanionDeviceManager/Android.bp index 6ded16371e8a..9f5bfd40e7e3 100644 --- a/packages/CompanionDeviceManager/Android.bp +++ b/packages/CompanionDeviceManager/Android.bp @@ -34,6 +34,7 @@ license { android_app { name: "CompanionDeviceManager", defaults: ["platform_app_defaults"], + certificate: "platform", srcs: ["src/**/*.java"], static_libs: [ diff --git a/packages/CompanionDeviceManager/AndroidManifest.xml b/packages/CompanionDeviceManager/AndroidManifest.xml index 06f2d9d0f0c8..8b5d214f7a10 100644 --- a/packages/CompanionDeviceManager/AndroidManifest.xml +++ b/packages/CompanionDeviceManager/AndroidManifest.xml @@ -31,6 +31,7 @@ <uses-permission android:name="android.permission.RADIO_SCAN_WITHOUT_LOCATION"/> <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> <uses-permission android:name="android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS"/> + <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/> <application android:allowClearUserData="true" diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java index b51d3103caec..a6a8fcf9af62 100644 --- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java +++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceActivity.java @@ -37,6 +37,7 @@ import android.companion.AssociationRequest; import android.companion.CompanionDeviceManager; import android.companion.IAssociationRequestCallback; import android.content.Intent; +import android.content.pm.PackageManager; import android.net.MacAddress; import android.os.Bundle; import android.os.Handler; @@ -71,6 +72,9 @@ public class CompanionDeviceActivity extends AppCompatActivity { private static final String EXTRA_ASSOCIATION_REQUEST = "association_request"; private static final String EXTRA_RESULT_RECEIVER = "result_receiver"; + // Activity result: Internal Error. + private static final int RESULT_INTERNAL_ERROR = 2; + // AssociationRequestsProcessor -> UI private static final int RESULT_CODE_ASSOCIATION_CREATED = 0; private static final String EXTRA_ASSOCIATION = "association"; @@ -191,6 +195,20 @@ public class CompanionDeviceActivity extends AppCompatActivity { private void initUI() { if (DEBUG) Log.d(TAG, "initUI(), request=" + mRequest); + final String packageName = mRequest.getPackageName(); + final int userId = mRequest.getUserId(); + final CharSequence appLabel; + + try { + appLabel = getApplicationLabel(this, packageName, userId); + } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, "Package u" + userId + "/" + packageName + " not found."); + + CompanionDeviceDiscoveryService.stop(this); + setResultAndFinish(null, RESULT_INTERNAL_ERROR); + return; + } + setContentView(R.layout.activity_confirmation); mTitle = findViewById(R.id.title); @@ -203,8 +221,6 @@ public class CompanionDeviceActivity extends AppCompatActivity { mButtonAllow.setOnClickListener(this::onPositiveButtonClick); findViewById(R.id.btn_negative).setOnClickListener(this::onNegativeButtonClick); - final CharSequence appLabel = getApplicationLabel(this, mRequest.getPackageName()); - if (mRequest.isSelfManaged()) { initUiForSelfManagedAssociation(appLabel); } else if (mRequest.isSingleDevice()) { @@ -257,7 +273,7 @@ public class CompanionDeviceActivity extends AppCompatActivity { if (DEBUG) Log.i(TAG, "onAssociationCreated(), association=" + association); // Don't need to notify the app, CdmService has already done that. Just finish. - setResultAndFinish(association); + setResultAndFinish(association, RESULT_OK); } private void cancel(boolean discoveryTimeout) { @@ -284,10 +300,10 @@ public class CompanionDeviceActivity extends AppCompatActivity { } // ... then set result and finish ("sending" onActivityResult()). - setResultAndFinish(null); + setResultAndFinish(null, RESULT_CANCELED); } - private void setResultAndFinish(@Nullable AssociationInfo association) { + private void setResultAndFinish(@Nullable AssociationInfo association, int resultCode) { if (DEBUG) Log.i(TAG, "setResultAndFinish(), association=" + association); final Intent data = new Intent(); @@ -297,7 +313,7 @@ public class CompanionDeviceActivity extends AppCompatActivity { data.putExtra(CompanionDeviceManager.EXTRA_DEVICE, mSelectedDevice.getDevice()); } } - setResult(association != null ? RESULT_OK : RESULT_CANCELED, data); + setResult(resultCode, data); finish(); } diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/Utils.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/Utils.java index eab421e48446..e3e563d56e8a 100644 --- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/Utils.java +++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/Utils.java @@ -50,14 +50,13 @@ class Utils { } static @NonNull CharSequence getApplicationLabel( - @NonNull Context context, @NonNull String packageName) { + @NonNull Context context, @NonNull String packageName, int userId) + throws PackageManager.NameNotFoundException { final PackageManager packageManager = context.getPackageManager(); - final ApplicationInfo appInfo; - try { - appInfo = packageManager.getApplicationInfo(packageName, 0); - } catch (PackageManager.NameNotFoundException e) { - throw new RuntimeException(e); - } + + final ApplicationInfo appInfo = packageManager.getApplicationInfoAsUser( + packageName, PackageManager.ApplicationInfoFlags.of(0), userId); + return packageManager.getApplicationLabel(appInfo); } diff --git a/packages/SettingsLib/src/com/android/settingslib/devicestate/AndroidSecureSettings.java b/packages/SettingsLib/src/com/android/settingslib/devicestate/AndroidSecureSettings.java new file mode 100644 index 000000000000..8aee576c3d04 --- /dev/null +++ b/packages/SettingsLib/src/com/android/settingslib/devicestate/AndroidSecureSettings.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2022 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.devicestate; + +import android.content.ContentResolver; +import android.database.ContentObserver; +import android.provider.Settings; + +/** + * Implementation of {@link SecureSettings} that uses Android's {@link Settings.Secure} + * implementation. + */ +class AndroidSecureSettings implements SecureSettings { + + private final ContentResolver mContentResolver; + + AndroidSecureSettings(ContentResolver contentResolver) { + mContentResolver = contentResolver; + } + + @Override + public void putStringForUser(String name, String value, int userHandle) { + Settings.Secure.putStringForUser(mContentResolver, name, value, userHandle); + } + + @Override + public String getStringForUser(String name, int userHandle) { + return Settings.Secure.getStringForUser(mContentResolver, name, userHandle); + } + + @Override + public void registerContentObserver(String name, boolean notifyForDescendants, + ContentObserver observer, int userHandle) { + mContentResolver.registerContentObserver( + Settings.Secure.getUriFor(name), + notifyForDescendants, + observer, + userHandle); + } +} diff --git a/packages/SettingsLib/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManager.java b/packages/SettingsLib/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManager.java index afd3626ab889..961fab32fc2c 100644 --- a/packages/SettingsLib/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManager.java @@ -24,6 +24,7 @@ import android.content.ContentResolver; import android.content.Context; import android.database.ContentObserver; import android.os.Handler; +import android.os.Looper; import android.os.UserHandle; import android.provider.Settings; import android.text.TextUtils; @@ -47,28 +48,33 @@ public final class DeviceStateRotationLockSettingsManager { private static DeviceStateRotationLockSettingsManager sSingleton; - private final ContentResolver mContentResolver; private final String[] mDeviceStateRotationLockDefaults; - private final Handler mMainHandler = Handler.getMain(); + private final Handler mMainHandler = new Handler(Looper.getMainLooper()); private final Set<DeviceStateRotationLockSettingsListener> mListeners = new HashSet<>(); + private final SecureSettings mSecureSettings; private SparseIntArray mDeviceStateRotationLockSettings; private SparseIntArray mDeviceStateRotationLockFallbackSettings; + private String mLastSettingValue; - private DeviceStateRotationLockSettingsManager(Context context) { - mContentResolver = context.getContentResolver(); + @VisibleForTesting + DeviceStateRotationLockSettingsManager(Context context, SecureSettings secureSettings) { + this.mSecureSettings = secureSettings; mDeviceStateRotationLockDefaults = context.getResources() .getStringArray(R.array.config_perDeviceStateRotationLockDefaults); loadDefaults(); initializeInMemoryMap(); - listenForSettingsChange(context); + listenForSettingsChange(); } /** Returns a singleton instance of this class */ public static synchronized DeviceStateRotationLockSettingsManager getInstance(Context context) { if (sSingleton == null) { + Context applicationContext = context.getApplicationContext(); + ContentResolver contentResolver = applicationContext.getContentResolver(); + SecureSettings secureSettings = new AndroidSecureSettings(contentResolver); sSingleton = - new DeviceStateRotationLockSettingsManager(context.getApplicationContext()); + new DeviceStateRotationLockSettingsManager(applicationContext, secureSettings); } return sSingleton; } @@ -81,11 +87,11 @@ public final class DeviceStateRotationLockSettingsManager { > 0; } - private void listenForSettingsChange(Context context) { - context.getContentResolver() + private void listenForSettingsChange() { + mSecureSettings .registerContentObserver( - Settings.Secure.getUriFor(Settings.Secure.DEVICE_STATE_ROTATION_LOCK), - /* notifyForDescendents= */ false, //NOTYPO + Settings.Secure.DEVICE_STATE_ROTATION_LOCK, + /* notifyForDescendants= */ false, new ContentObserver(mMainHandler) { @Override public void onChange(boolean selfChange) { @@ -182,8 +188,7 @@ public final class DeviceStateRotationLockSettingsManager { private void initializeInMemoryMap() { String serializedSetting = - Settings.Secure.getStringForUser( - mContentResolver, + mSecureSettings.getStringForUser( Settings.Secure.DEVICE_STATE_ROTATION_LOCK, UserHandle.USER_CURRENT); if (TextUtils.isEmpty(serializedSetting)) { @@ -222,11 +227,7 @@ public final class DeviceStateRotationLockSettingsManager { private void persistSettings() { if (mDeviceStateRotationLockSettings.size() == 0) { - Settings.Secure.putStringForUser( - mContentResolver, - Settings.Secure.DEVICE_STATE_ROTATION_LOCK, - /* value= */ "", - UserHandle.USER_CURRENT); + persistSettingIfChanged(/* newSettingValue= */ ""); return; } @@ -243,10 +244,17 @@ public final class DeviceStateRotationLockSettingsManager { .append(SEPARATOR_REGEX) .append(mDeviceStateRotationLockSettings.valueAt(i)); } - Settings.Secure.putStringForUser( - mContentResolver, + persistSettingIfChanged(stringBuilder.toString()); + } + + private void persistSettingIfChanged(String newSettingValue) { + if (TextUtils.equals(mLastSettingValue, newSettingValue)) { + return; + } + mLastSettingValue = newSettingValue; + mSecureSettings.putStringForUser( Settings.Secure.DEVICE_STATE_ROTATION_LOCK, - stringBuilder.toString(), + /* value= */ newSettingValue, UserHandle.USER_CURRENT); } diff --git a/packages/SettingsLib/src/com/android/settingslib/devicestate/SecureSettings.java b/packages/SettingsLib/src/com/android/settingslib/devicestate/SecureSettings.java new file mode 100644 index 000000000000..10528739b2b0 --- /dev/null +++ b/packages/SettingsLib/src/com/android/settingslib/devicestate/SecureSettings.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2022 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.devicestate; + +import android.database.ContentObserver; + +/** Minimal wrapper interface around {@link android.provider.Settings.Secure} for easier testing. */ +interface SecureSettings { + + void putStringForUser(String name, String value, int userHandle); + + String getStringForUser(String name, int userHandle); + + void registerContentObserver(String name, boolean notifyForDescendants, + ContentObserver settingsObserver, int userHandle); +} diff --git a/packages/SettingsLib/src/com/android/settingslib/users/AvatarPickerActivity.java b/packages/SettingsLib/src/com/android/settingslib/users/AvatarPickerActivity.java index 93be66ad4882..1e1dfae9f7ac 100644 --- a/packages/SettingsLib/src/com/android/settingslib/users/AvatarPickerActivity.java +++ b/packages/SettingsLib/src/com/android/settingslib/users/AvatarPickerActivity.java @@ -81,6 +81,7 @@ public class AvatarPickerActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setTheme(R.style.SudThemeGlifV3_DayNight); ThemeHelper.trySetDynamicColor(this); setContentView(R.layout.avatar_picker); setUpButtons(); diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java new file mode 100644 index 000000000000..1a45384bc768 --- /dev/null +++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2022 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.devicestate; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.content.res.Resources; +import android.database.ContentObserver; +import android.os.UserHandle; +import android.provider.Settings; + +import androidx.test.InstrumentationRegistry; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class DeviceStateRotationLockSettingsManagerTest { + + @Mock private Context mMockContext; + @Mock private Resources mMockResources; + + private DeviceStateRotationLockSettingsManager mManager; + private int mNumSettingsChanges = 0; + private final ContentObserver mContentObserver = new ContentObserver(null) { + @Override + public void onChange(boolean selfChange) { + mNumSettingsChanges++; + } + }; + private final FakeSecureSettings mFakeSecureSettings = new FakeSecureSettings(); + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + Context context = InstrumentationRegistry.getTargetContext(); + when(mMockContext.getApplicationContext()).thenReturn(mMockContext); + when(mMockContext.getResources()).thenReturn(mMockResources); + when(mMockContext.getContentResolver()).thenReturn(context.getContentResolver()); + mFakeSecureSettings.registerContentObserver( + Settings.Secure.DEVICE_STATE_ROTATION_LOCK, + /* notifyForDescendents= */ false, //NOTYPO + mContentObserver, + UserHandle.USER_CURRENT); + mManager = new DeviceStateRotationLockSettingsManager(context, mFakeSecureSettings); + } + + @Test + public void initialization_settingsAreChangedOnce() { + assertThat(mNumSettingsChanges).isEqualTo(1); + } + + @Test + public void updateSetting_multipleTimes_sameValue_settingsAreChangedOnlyOnce() { + mNumSettingsChanges = 0; + + mManager.updateSetting(/* deviceState= */ 1, /* rotationLocked= */ true); + mManager.updateSetting(/* deviceState= */ 1, /* rotationLocked= */ true); + mManager.updateSetting(/* deviceState= */ 1, /* rotationLocked= */ true); + + assertThat(mNumSettingsChanges).isEqualTo(1); + } + + @Test + public void updateSetting_multipleTimes_differentValues_settingsAreChangedMultipleTimes() { + mNumSettingsChanges = 0; + + mManager.updateSetting(/* deviceState= */ 1, /* rotationLocked= */ true); + mManager.updateSetting(/* deviceState= */ 1, /* rotationLocked= */ false); + mManager.updateSetting(/* deviceState= */ 1, /* rotationLocked= */ true); + + assertThat(mNumSettingsChanges).isEqualTo(3); + } +} diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/FakeSecureSettings.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/FakeSecureSettings.java new file mode 100644 index 000000000000..91baa68a1c49 --- /dev/null +++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/FakeSecureSettings.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2022 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.devicestate; + +import android.database.ContentObserver; +import android.util.Pair; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; + +import java.util.HashMap; +import java.util.Map; + +/** Fake implementation of {@link SecureSettings} that stores everything in memory. */ +class FakeSecureSettings implements SecureSettings { + + private final Map<SettingsKey, String> mValues = new HashMap<>(); + private final Multimap<SettingsKey, ContentObserver> mContentObservers = HashMultimap.create(); + + @Override + public void putStringForUser(String name, String value, int userHandle) { + SettingsKey settingsKey = new SettingsKey(userHandle, name); + mValues.put(settingsKey, value); + for (ContentObserver observer : mContentObservers.get(settingsKey)) { + observer.onChange(/* selfChange= */ false); + } + } + + @Override + public String getStringForUser(String name, int userHandle) { + return mValues.getOrDefault(new SettingsKey(userHandle, name), ""); + } + + @Override + public void registerContentObserver(String name, boolean notifyForDescendants, + ContentObserver settingsObserver, int userHandle) { + mContentObservers.put(new SettingsKey(userHandle, name), settingsObserver); + } + + private static class SettingsKey extends Pair<Integer, String> { + + SettingsKey(Integer userHandle, String settingName) { + super(userHandle, settingName); + } + } +} diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/OWNERS b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/OWNERS new file mode 100644 index 000000000000..98f41234feb1 --- /dev/null +++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/OWNERS @@ -0,0 +1,3 @@ +# Default reviewers for this and subdirectories. +alexflo@google.com +chrisgollner@google.com diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt index c3f6a5d18b74..0da60f0b3d66 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/ActivityLaunchAnimator.kt @@ -298,6 +298,9 @@ class ActivityLaunchAnimator( * * Important: The view must be attached to a [ViewGroup] when calling this function and * during the animation. For safety, this method will return null when it is not. + * + * Note: The background of [view] should be a (rounded) rectangle so that it can be + * properly animated. */ @JvmStatic fun fromView(view: View, cujType: Int? = null): Controller? { diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt index a3c5649e3fec..50178f470fd8 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt @@ -79,6 +79,9 @@ class DialogLaunchAnimator @JvmOverloads constructor( * If [animateBackgroundBoundsChange] is true, then the background of the dialog will be * animated when the dialog bounds change. * + * Note: The background of [view] should be a (rounded) rectangle so that it can be properly + * animated. + * * Caveats: When calling this function and [dialog] is not a fullscreen dialog, then it will be * made fullscreen and 2 views will be inserted between the dialog DecorView and its children. */ @@ -153,6 +156,9 @@ class DialogLaunchAnimator @JvmOverloads constructor( * activity started, when the dialog to app animation is done (or when it is cancelled). If this * method returns null, then the dialog won't be dismissed. * + * Note: The background of [view] should be a (rounded) rectangle so that it can be properly + * animated. + * * @param view any view inside the dialog to animate. */ @JvmOverloads diff --git a/packages/SystemUI/res/drawable/qs_footer_action_circle.xml b/packages/SystemUI/res/drawable/qs_footer_action_circle.xml index d057f5f32dc4..31a8c3bc2397 100644 --- a/packages/SystemUI/res/drawable/qs_footer_action_circle.xml +++ b/packages/SystemUI/res/drawable/qs_footer_action_circle.xml @@ -19,13 +19,17 @@ <ripple android:color="?android:attr/colorControlHighlight"> <item android:id="@android:id/mask"> - <shape android:shape="oval"> + <!-- We make this shape a rounded rectangle instead of a oval so that it can animate --> + <!-- properly into an app/dialog. --> + <shape android:shape="rectangle"> <solid android:color="@android:color/white"/> + <corners android:radius="@dimen/qs_footer_action_corner_radius"/> </shape> </item> <item> - <shape android:shape="oval"> + <shape android:shape="rectangle"> <solid android:color="?attr/offStateColor"/> + <corners android:radius="@dimen/qs_footer_action_corner_radius"/> </shape> </item> diff --git a/packages/SystemUI/res/drawable/qs_footer_action_circle_color.xml b/packages/SystemUI/res/drawable/qs_footer_action_circle_color.xml index 944061cc8e70..021a85f6a244 100644 --- a/packages/SystemUI/res/drawable/qs_footer_action_circle_color.xml +++ b/packages/SystemUI/res/drawable/qs_footer_action_circle_color.xml @@ -19,13 +19,17 @@ <ripple android:color="?android:attr/colorControlHighlight"> <item android:id="@android:id/mask"> - <shape android:shape="oval"> + <!-- We make this shape a rounded rectangle instead of a oval so that it can animate --> + <!-- properly into an app/dialog. --> + <shape android:shape="rectangle"> <solid android:color="@android:color/white"/> + <corners android:radius="@dimen/qs_footer_action_corner_radius"/> </shape> </item> <item> - <shape android:shape="oval"> + <shape android:shape="rectangle"> <solid android:color="?android:attr/colorAccent"/> + <corners android:radius="@dimen/qs_footer_action_corner_radius"/> </shape> </item> diff --git a/services/core/java/com/android/server/audio/BtHelper.java b/services/core/java/com/android/server/audio/BtHelper.java index 3491cd59ebb7..49a935ebadc9 100644 --- a/services/core/java/com/android/server/audio/BtHelper.java +++ b/services/core/java/com/android/server/audio/BtHelper.java @@ -479,6 +479,8 @@ public class BtHelper { } if (profile == BluetoothProfile.A2DP) { mA2dp = (BluetoothA2dp) proxy; + } else if (profile == BluetoothProfile.HEARING_AID) { + mHearingAid = (BluetoothHearingAid) proxy; } else if (profile == BluetoothProfile.LE_AUDIO) { mLeAudio = (BluetoothLeAudio) proxy; } diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java index 96391ac62530..074d891a9974 100644 --- a/services/core/java/com/android/server/media/MediaSessionRecord.java +++ b/services/core/java/com/android/server/media/MediaSessionRecord.java @@ -647,18 +647,17 @@ public class MediaSessionRecord implements IBinder.DeathRecipient, MediaSessionR if (mDestroyed) { return; } - toSend = new ArrayList<>(); - if (mQueue != null) { - toSend.ensureCapacity(mQueue.size()); - toSend.addAll(mQueue); - } + toSend = mQueue == null ? null : new ArrayList<>(mQueue); } Collection<ISessionControllerCallbackHolder> deadCallbackHolders = null; for (ISessionControllerCallbackHolder holder : mControllerCallbackHolders) { - ParceledListSlice<QueueItem> parcelableQueue = new ParceledListSlice<>(toSend); - // Limit the size of initial Parcel to prevent binder buffer overflow - // as onQueueChanged is an async binder call. - parcelableQueue.setInlineCountLimit(1); + ParceledListSlice<QueueItem> parcelableQueue = null; + if (toSend != null) { + parcelableQueue = new ParceledListSlice<>(toSend); + // Limit the size of initial Parcel to prevent binder buffer overflow + // as onQueueChanged is an async binder call. + parcelableQueue.setInlineCountLimit(1); + } try { holder.mCallback.onQueueChanged(parcelableQueue); diff --git a/services/core/java/com/android/server/pm/InstallPackageHelper.java b/services/core/java/com/android/server/pm/InstallPackageHelper.java index c09c904ff931..db0b0c58b046 100644 --- a/services/core/java/com/android/server/pm/InstallPackageHelper.java +++ b/services/core/java/com/android/server/pm/InstallPackageHelper.java @@ -183,7 +183,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -1596,18 +1595,16 @@ final class InstallPackageHelper { parsedPackage.setRestrictUpdateHash(oldPackage.getRestrictUpdateHash()); } - // Check for shared user id changes - if (!Objects.equals(oldPackage.getSharedUserId(), - parsedPackage.getSharedUserId()) - // Don't mark as invalid if the app is trying to - // leave a sharedUserId - && parsedPackage.getSharedUserId() != null) { + // APK should not change its sharedUserId declarations + final var oldSharedUid = oldPackage.getSharedUserId() != null + ? oldPackage.getSharedUserId() : "<nothing>"; + final var newSharedUid = parsedPackage.getSharedUserId() != null + ? parsedPackage.getSharedUserId() : "<nothing>"; + if (!oldSharedUid.equals(newSharedUid)) { throw new PrepareFailure(INSTALL_FAILED_UID_CHANGED, "Package " + parsedPackage.getPackageName() + " shared user changed from " - + (oldPackage.getSharedUserId() != null - ? oldPackage.getSharedUserId() : "<nothing>") - + " to " + parsedPackage.getSharedUserId()); + + oldSharedUid + " to " + newSharedUid); } // In case of rollback, remember per-user/profile install state @@ -3696,10 +3693,13 @@ final class InstallPackageHelper { } disabledPkgSetting = mPm.mSettings.getDisabledSystemPkgLPr( parsedPackage.getPackageName()); - sharedUserSetting = (parsedPackage.getSharedUserId() != null) - ? mPm.mSettings.getSharedUserLPw(parsedPackage.getSharedUserId(), - 0 /*pkgFlags*/, 0 /*pkgPrivateFlags*/, true) - : null; + if (parsedPackage.getSharedUserId() != null && !parsedPackage.isLeavingSharedUid()) { + sharedUserSetting = mPm.mSettings.getSharedUserLPw( + parsedPackage.getSharedUserId(), + 0 /*pkgFlags*/, 0 /*pkgPrivateFlags*/, true /*create*/); + } else { + sharedUserSetting = null; + } if (DEBUG_PACKAGE_SCANNING && (parseFlags & ParsingPackageUtils.PARSE_CHATTY) != 0 && sharedUserSetting != null) { diff --git a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackage.java b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackage.java index cdc2b1245b1e..f6f9faf98c40 100644 --- a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackage.java +++ b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackage.java @@ -290,6 +290,9 @@ public interface ParsingPackage extends ParsingPackageRead { /** @see R#styleable.AndroidManifest_inheritKeyStoreKeys */ ParsingPackage setInheritKeyStoreKeys(boolean inheritKeyStoreKeys); + /** @see R#styleable.AndroidManifest_sharedUserMaxSdkVersion */ + ParsingPackage setLeavingSharedUid(boolean leavingSharedUid); + ParsingPackage setLabelRes(int labelRes); ParsingPackage setLargestWidthLimitDp(int largestWidthLimitDp); diff --git a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageImpl.java b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageImpl.java index 177eaca8e06f..67670272ef8b 100644 --- a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageImpl.java +++ b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageImpl.java @@ -549,6 +549,7 @@ public class ParsingPackageImpl implements ParsingPackage, ParsingPackageHidden, private static final long SDK_LIBRARY = 1L << 49; private static final long INHERIT_KEYSTORE_KEYS = 1L << 50; private static final long ENABLE_ON_BACK_INVOKED_CALLBACK = 1L << 51; + private static final long LEAVING_SHARED_UID = 1L << 52; } private ParsingPackageImpl setBoolean(@Booleans.Values long flag, boolean value) { @@ -2403,6 +2404,11 @@ public class ParsingPackageImpl implements ParsingPackage, ParsingPackageHidden, } @Override + public boolean isLeavingSharedUid() { + return getBoolean(Booleans.LEAVING_SHARED_UID); + } + + @Override public ParsingPackageImpl setBaseRevisionCode(int value) { baseRevisionCode = value; return this; @@ -2551,6 +2557,11 @@ public class ParsingPackageImpl implements ParsingPackage, ParsingPackageHidden, } @Override + public ParsingPackageImpl setLeavingSharedUid(boolean value) { + return setBoolean(Booleans.LEAVING_SHARED_UID, value); + } + + @Override public ParsingPackageImpl setLabelRes(int value) { labelRes = value; return this; diff --git a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageRead.java b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageRead.java index 428374fa21a8..50033f652bfd 100644 --- a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageRead.java +++ b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageRead.java @@ -360,4 +360,11 @@ public interface ParsingPackageRead extends PkgWithoutStateAppInfo, PkgWithoutSt * @see R.styleable.AndroidManifestApplication_enableOnBackInvokedCallback */ boolean isOnBackInvokedCallbackEnabled(); + + /** + * Returns true if R.styleable#AndroidManifest_sharedUserMaxSdkVersion is set to a value + * smaller than the current SDK version. + * @see R.styleable#AndroidManifest_sharedUserMaxSdkVersion + */ + boolean isLeavingSharedUid(); } diff --git a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageUtils.java b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageUtils.java index f30daa930e6c..ed1ab01e1d12 100644 --- a/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageUtils.java +++ b/services/core/java/com/android/server/pm/pkg/parsing/ParsingPackageUtils.java @@ -1032,11 +1032,6 @@ public class ParsingPackageUtils { private static ParseResult<ParsingPackage> parseSharedUser(ParseInput input, ParsingPackage pkg, TypedArray sa) { - int maxSdkVersion = anInteger(0, R.styleable.AndroidManifest_sharedUserMaxSdkVersion, sa); - if ((maxSdkVersion != 0) && maxSdkVersion < Build.VERSION.RESOURCES_SDK_INT) { - return input.success(pkg); - } - String str = nonConfigString(0, R.styleable.AndroidManifest_sharedUserId, sa); if (TextUtils.isEmpty(str)) { return input.success(pkg); @@ -1052,7 +1047,11 @@ public class ParsingPackageUtils { } } + int maxSdkVersion = anInteger(0, R.styleable.AndroidManifest_sharedUserMaxSdkVersion, sa); + boolean leaving = (maxSdkVersion != 0) && (maxSdkVersion < Build.VERSION.RESOURCES_SDK_INT); + return input.success(pkg + .setLeavingSharedUid(leaving) .setSharedUserId(str.intern()) .setSharedUserLabel(resId(R.styleable.AndroidManifest_sharedUserLabel, sa))); } diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index ffa1a601d41b..98c74f8ad81d 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -5149,10 +5149,13 @@ class Task extends TaskFragment { // Ensure that we do not trigger entering PiP an activity on the root pinned task return false; } + final boolean isTransient = opts != null && opts.getTransientLaunch(); final Task targetRootTask = toFrontTask != null ? toFrontTask.getRootTask() : toFrontActivity.getRootTask(); - if (targetRootTask != null && targetRootTask.isActivityTypeAssistant()) { - // Ensure the task/activity being brought forward is not the assistant + if (targetRootTask != null && (targetRootTask.isActivityTypeAssistant() || isTransient)) { + // Ensure the task/activity being brought forward is not the assistant and is not + // transient. In the case of transient-launch, we want to wait until the end of the + // transition and only allow switch if the transient launch was committed. return false; } return true; diff --git a/services/core/java/com/android/server/wm/Transition.java b/services/core/java/com/android/server/wm/Transition.java index 0b965c37a2ba..3a3103e752ad 100644 --- a/services/core/java/com/android/server/wm/Transition.java +++ b/services/core/java/com/android/server/wm/Transition.java @@ -459,9 +459,19 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe // activity in a bad state. if (!visibleAtTransitionEnd && !ar.isVisibleRequested()) { boolean commitVisibility = true; - if (ar.getDeferHidingClient() && ar.getTask() != null) { + if (ar.isVisible() && ar.getTask() != null) { if (ar.pictureInPictureArgs != null && ar.pictureInPictureArgs.isAutoEnterEnabled()) { + if (mTransientLaunches != null) { + for (int j = 0; j < mTransientLaunches.size(); ++j) { + if (mTransientLaunches.valueAt(j).isVisibleRequested()) { + // force enable pip-on-task-switch now that we've committed + // to actually launching to the transient activity. + ar.supportsEnterPipOnTaskSwitch = true; + break; + } + } + } mController.mAtm.enterPictureInPictureMode(ar, ar.pictureInPictureArgs); // Avoid commit visibility to false here, or else we will get a sudden // "flash" / surface going invisible for a split second. diff --git a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/parsing/parcelling/AndroidPackageTest.kt b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/parsing/parcelling/AndroidPackageTest.kt index cd2d0fce6691..83ccabf03935 100644 --- a/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/parsing/parcelling/AndroidPackageTest.kt +++ b/services/tests/PackageManagerServiceTests/unit/src/com/android/server/pm/test/parsing/parcelling/AndroidPackageTest.kt @@ -238,6 +238,7 @@ class AndroidPackageTest : ParcelableComponentTest(AndroidPackage::class, Packag AndroidPackage::isVendor, AndroidPackage::isVisibleToInstantApps, AndroidPackage::isVmSafeMode, + AndroidPackage::isLeavingSharedUid, AndroidPackage::isResetEnabledSettingsOnAppDataCleared, AndroidPackage::getMaxAspectRatio, AndroidPackage::getMinAspectRatio, diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index f57c32c959d9..0394a546388d 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -4189,7 +4189,8 @@ public class TelephonyManager { * {@link UiccSlotMapping} which consist of both physical slot index and port index. * Logical slot is the slot that is seen by modem. Physical slot is the actual physical slot. * Port index is the index (enumerated value) for the associated port available on the SIM. - * Each physical slot can have multiple ports if multi-enabled profile(MEP) is supported. + * Each physical slot can have multiple ports if + * {@link PackageManager#FEATURE_TELEPHONY_EUICC_MEP} is supported. * * Example: no. of logical slots 1 and physical slots 2 do not support MEP, each physical slot * has one port: @@ -4285,11 +4286,11 @@ public class TelephonyManager { /** * Get the mapping from logical slots to physical sim slots and port indexes. Initially the * logical slot index was mapped to physical slot index, but with support for multi-enabled - * profile(MEP) logical slot is now mapped to port index. + * profile(MEP){@link PackageManager#FEATURE_TELEPHONY_EUICC_MEP},logical slot is now mapped to + * port index. * * @return a collection of {@link UiccSlotMapping} which indicates the mapping from logical * slots to ports and physical slots. - * * @hide */ @SystemApi diff --git a/telephony/java/android/telephony/UiccCardInfo.java b/telephony/java/android/telephony/UiccCardInfo.java index 30ca1627953f..3843a6240b43 100644 --- a/telephony/java/android/telephony/UiccCardInfo.java +++ b/telephony/java/android/telephony/UiccCardInfo.java @@ -17,6 +17,7 @@ package android.telephony; import android.annotation.NonNull; import android.annotation.Nullable; +import android.content.pm.PackageManager; import android.os.Parcel; import android.os.Parcelable; @@ -147,9 +148,10 @@ public final class UiccCardInfo implements Parcelable { * Note that this field may be omitted if the caller does not have the correct permissions * (see {@link TelephonyManager#getUiccCardsInfo()}). * - * @deprecated with support for MEP(multiple enabled profile), a SIM card can have more than one - * ICCID active at the same time.Instead use {@link UiccPortInfo#getIccId()} to retrieve ICCID. - * To find {@link UiccPortInfo} use {@link UiccCardInfo#getPorts()} + * @deprecated with support for MEP(multiple enabled profile) + * {@link PackageManager#FEATURE_TELEPHONY_EUICC_MEP}, a SIM card can have more than one + * ICCID active at the same time. Instead use {@link UiccPortInfo#getIccId()} to retrieve ICCID. + * To find {@link UiccPortInfo} use {@link UiccCardInfo#getPorts()}. * * @throws UnsupportedOperationException if the calling app's target SDK is T and beyond. */ @@ -192,11 +194,11 @@ public final class UiccCardInfo implements Parcelable { } /* - * Whether the UICC card supports multiple enable profile(MEP) + * Whether the UICC card supports multiple enabled profile(MEP) * UICCs are generally MEP disabled, there can be only one active profile on the physical * sim card. * - * @return {@code true} if the eUICC is supporting multiple enabled profile(MEP). + * @return {@code true} if the UICC is supporting multiple enabled profile(MEP). */ public boolean isMultipleEnabledProfilesSupported() { return mIsMultipleEnabledProfilesSupported; @@ -205,6 +207,9 @@ public final class UiccCardInfo implements Parcelable { /** * Get information regarding port, ICCID and its active status. * + * For device which support {@link PackageManager#FEATURE_TELEPHONY_EUICC_MEP}, it should return + * more than one {@link UiccPortInfo} object if the card is eUICC. + * * @return Collection of {@link UiccPortInfo} */ public @NonNull Collection<UiccPortInfo> getPorts() { diff --git a/telephony/java/android/telephony/UiccPortInfo.java b/telephony/java/android/telephony/UiccPortInfo.java index d1838c0b91f4..6fb0470d6225 100644 --- a/telephony/java/android/telephony/UiccPortInfo.java +++ b/telephony/java/android/telephony/UiccPortInfo.java @@ -29,7 +29,9 @@ import java.util.Objects; * Per GSMA SGP.22 V3.0, a port is a logical entity to which an active UICC profile can be bound on * a UICC card. If UICC supports 2 ports, then the port index is numbered 0,1. * Each port index is unique within an UICC, but not necessarily unique across UICC’s. - * For UICC's does not support MEP(Multi-enabled profile), just return the default port index 0. + * For UICC's does not support MEP(Multi-enabled profile) + * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY_EUICC_MEP}, just return the default + * port index 0. */ public final class UiccPortInfo implements Parcelable{ private final String mIccId; diff --git a/telephony/java/android/telephony/UiccSlotInfo.java b/telephony/java/android/telephony/UiccSlotInfo.java index 17f34db4e44a..17ce45063d41 100644 --- a/telephony/java/android/telephony/UiccSlotInfo.java +++ b/telephony/java/android/telephony/UiccSlotInfo.java @@ -19,6 +19,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; +import android.content.pm.PackageManager; import android.os.Parcel; import android.os.Parcelable; @@ -225,6 +226,9 @@ public class UiccSlotInfo implements Parcelable { /** * Get Information regarding port, iccid and its active status. * + * For device which support {@link PackageManager#FEATURE_TELEPHONY_EUICC_MEP}, it should return + * more than one {@link UiccPortInfo} object if the card is eUICC. + * * @return Collection of {@link UiccPortInfo} */ public @NonNull Collection<UiccPortInfo> getPorts() { diff --git a/telephony/java/android/telephony/euicc/EuiccManager.java b/telephony/java/android/telephony/euicc/EuiccManager.java index b6ae53017f64..4820d332de0f 100644 --- a/telephony/java/android/telephony/euicc/EuiccManager.java +++ b/telephony/java/android/telephony/euicc/EuiccManager.java @@ -37,6 +37,7 @@ import android.os.RemoteException; import android.telephony.SubscriptionInfo; import android.telephony.TelephonyFrameworkInitializer; import android.telephony.TelephonyManager; +import android.telephony.UiccCardInfo; import android.telephony.euicc.EuiccCardManager.ResetOption; import android.util.Log; @@ -931,6 +932,21 @@ public class EuiccManager { * intent to prompt the user to accept the download. The caller should also be authorized to * manage the subscription to be downloaded. * + * <p>If device support {@link PackageManager#FEATURE_TELEPHONY_EUICC_MEP} and + * switchAfterDownload is {@code true}, the subscription will be enabled on an esim port based + * on the following selection rules: + * <ul> + * <li>In SS(Single SIM) mode, if the embedded slot already has an active port, then download + * and enable the subscription on this port. + * <li>In SS mode, if the embedded slot is not active, then try to download and enable the + * subscription on the default port 0 of eUICC. + * <li>In DSDS mode, find first available port to download and enable the subscription. + * (see {@link #isSimPortAvailable(int)}) + *</ul> + * If there is no available port, an {@link #EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR} + * will be returned in the callback intent to prompt the user to disable an already-active + * subscription. + * * @param subscription the subscription to download. * @param switchAfterDownload if true, the profile will be activated upon successful download. * @param callbackIntent a PendingIntent to launch when the operation completes. @@ -1141,14 +1157,25 @@ public class EuiccManager { * intent to prompt the user to accept the download. The caller should also be authorized to * manage the subscription to be enabled. * - * <p> From Android T, devices might support MEP(Multiple Enabled Profiles), the subscription - * can be installed on different port from the eUICC. Calling apps with carrier privilege - * (see {@link TelephonyManager#hasCarrierPrivileges}) over the currently active subscriptions - * can use {@link #switchToSubscription(int, int, PendingIntent)} to specify which port to - * enable the subscription. Otherwise, use this API to enable the subscription on the eUICC - * and the platform will internally resolve a port. If there is no available port, - * an {@link #EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR} might be returned in the callback - * intent to prompt the user to disable an already-active subscription. + * <p> From Android T, devices might support {@link PackageManager#FEATURE_TELEPHONY_EUICC_MEP}, + * the subscription can be installed on different port from the eUICC. Calling apps with + * carrier privilege (see {@link TelephonyManager#hasCarrierPrivileges}) over the currently + * active subscriptions can use {@link #switchToSubscription(int, int, PendingIntent)} to + * specify which port to enable the subscription. Otherwise, use this API to enable the + * subscription on the eUICC and the platform will internally resolve a port based on following + * rules: + * <ul> + * <li>always use the default port 0 is eUICC does not support MEP. + * <li>In SS(Single SIM) mode, if the embedded slot already has an active port, then enable + * the subscription on this port. + * <li>In SS mode, if the embedded slot is not active, then try to enable the subscription on + * the default port 0 of eUICC. + * <li>In DSDS mode, find first available port to enable the subscription. + * (see {@link #isSimPortAvailable(int)}) + *</ul> + * If there is no available port, an {@link #EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR} + * will be returned in the callback intent to prompt the user to disable an already-active + * subscription. * * @param subscriptionId the ID of the subscription to enable. May be * {@link android.telephony.SubscriptionManager#INVALID_SUBSCRIPTION_ID} to deactivate the @@ -1197,7 +1224,15 @@ public class EuiccManager { * * <p> If the caller is passing invalid port index, * an {@link #EMBEDDED_SUBSCRIPTION_RESULT_ERROR} with detailed error code - * {@link #ERROR_INVALID_PORT} will be returned. + * {@link #ERROR_INVALID_PORT} will be returned. The port index is invalid if one of the + * following requirements is met: + * <ul> + * <li>index is beyond the range of {@link UiccCardInfo#getPorts()}. + * <li>In SS(Single SIM) mode, the embedded slot already has an active port with different + * port index. + * <li>In DSDS mode, if the psim slot is active and the embedded slot already has an active + * empty port with different port index. + * </ul> * * <p> Depending on the target port and permission check, * an {@link #EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR} might be returned to the callback @@ -1522,8 +1557,8 @@ public class EuiccManager { /** * Returns whether the passing portIndex is available. - * A port is available if it has no profiles enabled on it or calling app has carrier privilege - * over the profile installed on the selected port. + * A port is available if it is active without enabled profile on it or + * calling app has carrier privilege over the profile installed on the selected port. * Always returns false if the cardId is a physical card. * * @param portIndex is an enumeration of the ports available on the UICC. |