summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apex/jobscheduler/service/java/com/android/server/job/controllers/idle/DeviceIdlenessTracker.java120
-rw-r--r--apex/media/framework/java/android/media/MediaParser.java52
-rw-r--r--cmds/statsd/Android.bp2
-rw-r--r--cmds/statsd/src/StatsService.cpp16
-rw-r--r--cmds/statsd/src/StatsService.h20
-rw-r--r--cmds/statsd/src/atoms.proto81
-rw-r--r--cmds/statsd/src/utils/NamedLatch.cpp48
-rw-r--r--cmds/statsd/src/utils/NamedLatch.h58
-rw-r--r--cmds/statsd/tests/utils/NamedLatch_test.cpp96
-rw-r--r--core/java/android/app/AppOpsManager.java38
-rw-r--r--core/java/android/app/TEST_MAPPING4
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java22
-rw-r--r--core/java/android/app/admin/IDevicePolicyManager.aidl1
-rw-r--r--core/java/android/app/admin/PasswordMetrics.java2
-rw-r--r--core/java/android/content/pm/PackageManager.java17
-rw-r--r--core/java/android/net/UrlQuerySanitizer.java2
-rw-r--r--core/java/android/os/UserManager.java30
-rw-r--r--core/java/android/os/incremental/V4Signature.java28
-rw-r--r--core/java/android/service/dreams/DreamService.java44
-rw-r--r--core/java/android/service/notification/StatusBarNotification.java12
-rw-r--r--core/java/android/speech/RecognizerIntent.java4
-rw-r--r--core/java/android/view/SurfaceControl.java28
-rw-r--r--core/java/com/android/internal/app/SystemUserHomeActivity.java17
-rw-r--r--core/proto/android/server/jobscheduler.proto1
-rw-r--r--core/res/res/layout/system_user_home.xml44
-rw-r--r--core/res/res/values/symbols.xml1
-rw-r--r--location/java/android/location/LocationManager.java5
-rw-r--r--media/java/android/media/MediaRouter2.java51
-rw-r--r--media/tests/AudioPolicyTest/Android.bp17
-rw-r--r--media/tests/AudioPolicyTest/AndroidManifest.xml45
-rw-r--r--media/tests/AudioPolicyTest/AndroidTest.xml27
-rw-r--r--media/tests/AudioPolicyTest/res/layout/audiopolicytest.xml21
-rw-r--r--media/tests/AudioPolicyTest/res/values/strings.xml5
-rw-r--r--media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioManagerTest.java328
-rw-r--r--media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyTest.java38
-rw-r--r--media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioProductStrategyTest.java213
-rw-r--r--media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupCallbackHelper.java69
-rw-r--r--media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupChangeHandlerTest.java180
-rw-r--r--media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupTest.java131
-rw-r--r--media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumesTestBase.java146
-rw-r--r--packages/CarSystemUI/src/com/android/systemui/car/keyguard/CarKeyguardViewController.java7
-rw-r--r--packages/CarSystemUI/tests/src/com/android/systemui/car/keyguard/CarKeyguardViewControllerTest.java209
-rw-r--r--packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java22
-rw-r--r--packages/SystemUI/res/anim/control_state_list_animator.xml4
-rw-r--r--packages/SystemUI/res/drawable/control_background.xml3
-rw-r--r--packages/SystemUI/res/interpolator/control_state.xml22
-rw-r--r--packages/SystemUI/res/layout/photo_preview_overlay.xml19
-rw-r--r--packages/SystemUI/res/layout/status_bar_expanded.xml2
-rw-r--r--packages/SystemUI/res/values/dimens.xml1
-rwxr-xr-xpackages/SystemUI/scripts/update_statsd_lib.sh35
-rw-r--r--packages/SystemUI/src/com/android/systemui/ScreenDecorations.java27
-rw-r--r--packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt30
-rw-r--r--packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/ScreenRecordTile.java1
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java4
-rw-r--r--packages/SystemUI/src/com/android/systemui/util/magnetictarget/MagnetizedObject.kt34
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/util/magnetictarget/MagnetizedObjectTest.kt12
-rw-r--r--packages/Tethering/tests/integration/Android.bp56
-rw-r--r--packages/Tethering/tests/integration/AndroidManifest.xml1
-rw-r--r--packages/Tethering/tests/integration/AndroidManifest_coverage.xml29
-rw-r--r--packages/Tethering/tests/integration/AndroidTest_Coverage.xml12
-rw-r--r--packages/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java4
-rw-r--r--packages/Tethering/tests/unit/Android.bp46
-rw-r--r--read-snapshot.txt0
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java5
-rw-r--r--services/core/java/com/android/server/am/ProcessList.java50
-rw-r--r--services/core/java/com/android/server/am/UserController.java139
-rw-r--r--services/core/java/com/android/server/appop/TEST_MAPPING3
-rwxr-xr-xservices/core/java/com/android/server/audio/AudioService.java53
-rw-r--r--services/core/java/com/android/server/audio/AudioSystemAdapter.java69
-rw-r--r--services/core/java/com/android/server/audio/SystemServerAdapter.java90
-rw-r--r--services/core/java/com/android/server/display/DisplayPowerController.java5
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodManagerService.java3
-rw-r--r--services/core/java/com/android/server/location/AppOpsHelper.java4
-rw-r--r--services/core/java/com/android/server/location/LocationManagerService.java (renamed from services/core/java/com/android/server/LocationManagerService.java)36
-rw-r--r--services/core/java/com/android/server/location/LocationManagerServiceUtils.java (renamed from services/core/java/com/android/server/LocationManagerServiceUtils.java)6
-rw-r--r--services/core/java/com/android/server/location/LocationUsageLogger.java2
-rw-r--r--services/core/java/com/android/server/location/SettingsHelper.java4
-rw-r--r--services/core/java/com/android/server/location/UserInfoHelper.java4
-rw-r--r--services/core/java/com/android/server/location/gnss/GnssManagerService.java4
-rw-r--r--services/core/java/com/android/server/locksettings/LockSettingsService.java29
-rw-r--r--services/core/java/com/android/server/net/NetworkStatsService.java86
-rwxr-xr-xservices/core/java/com/android/server/notification/NotificationManagerService.java51
-rw-r--r--services/core/java/com/android/server/notification/NotificationRecord.java2
-rw-r--r--services/core/java/com/android/server/notification/PreferencesHelper.java34
-rw-r--r--services/core/java/com/android/server/notification/ShortcutHelper.java31
-rw-r--r--services/core/java/com/android/server/pm/BackgroundDexOptService.java7
-rw-r--r--services/core/java/com/android/server/pm/PackageDexOptimizer.java9
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerService.java54
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerServiceUtils.java75
-rw-r--r--services/core/java/com/android/server/pm/UserManagerService.java25
-rw-r--r--services/core/java/com/android/server/pm/dex/DexManager.java44
-rw-r--r--services/core/java/com/android/server/pm/dex/DexoptOptions.java13
-rw-r--r--services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerHw2Enforcer.java56
-rw-r--r--services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareLogging.java6
-rw-r--r--services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java80
-rw-r--r--services/core/java/com/android/server/wm/AccessibilityController.java47
-rw-r--r--services/core/java/com/android/server/wm/InsetsSourceProvider.java5
-rw-r--r--services/core/java/com/android/server/wm/WindowContainer.java8
-rw-r--r--services/core/java/com/android/server/wm/WindowManagerService.java13
-rw-r--r--services/core/java/com/android/server/wm/WindowState.java10
-rw-r--r--services/core/java/com/android/server/wm/WindowToken.java9
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java75
-rw-r--r--services/incremental/IncrementalService.cpp4
-rw-r--r--services/java/com/android/server/SystemServer.java1
-rw-r--r--services/tests/servicestests/AndroidManifest.xml1
-rw-r--r--services/tests/servicestests/src/com/android/server/audio/AudioDeviceBrokerTest.java2
-rw-r--r--services/tests/servicestests/src/com/android/server/audio/AudioServiceTest.java115
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java27
-rw-r--r--services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTests.java20
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/ArchiveTest.java143
-rwxr-xr-xservices/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java13
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java115
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/ShortcutHelperTest.java86
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java2
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java14
-rw-r--r--startop/iorap/functional_tests/Android.bp2
l---------startop/iorap/functional_tests/test_data/iorap_test_app_v1.apk1
l---------startop/iorap/functional_tests/test_data/iorap_test_app_v2.apk1
l---------startop/iorap/functional_tests/test_data/iorap_test_app_v3.apk1
-rw-r--r--telecomm/java/android/telecom/Conference.java20
-rwxr-xr-xtelecomm/java/android/telecom/ConnectionService.java5
-rwxr-xr-xtelephony/java/android/telephony/CarrierConfigManager.java21
-rw-r--r--telephony/java/android/telephony/TelephonyManager.java17
-rw-r--r--telephony/java/com/android/internal/telephony/ITelephony.aidl5
-rw-r--r--tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java1
-rw-r--r--tests/net/java/com/android/server/net/NetworkStatsServiceTest.java44
129 files changed, 4025 insertions, 543 deletions
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/DeviceIdlenessTracker.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/DeviceIdlenessTracker.java
index f74eb3b9a45f..e2c8f649fdb7 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/DeviceIdlenessTracker.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/idle/DeviceIdlenessTracker.java
@@ -19,10 +19,12 @@ package com.android.server.job.controllers.idle;
import static com.android.server.job.JobSchedulerService.sElapsedRealtimeClock;
import android.app.AlarmManager;
+import android.app.UiModeManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.os.PowerManager;
import android.util.Log;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
@@ -39,6 +41,7 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
|| Log.isLoggable(TAG, Log.DEBUG);
private AlarmManager mAlarm;
+ private PowerManager mPowerManager;
// After construction, mutations of idle/screen-on state will only happen
// on the main looper thread, either in onReceive() or in an alarm callback.
@@ -47,6 +50,7 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
private boolean mIdle;
private boolean mScreenOn;
private boolean mDockIdle;
+ private boolean mInCarMode;
private IdlenessListener mIdleListener;
private AlarmManager.OnAlarmListener mIdleAlarmListener = () -> {
@@ -59,6 +63,7 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
mIdle = false;
mScreenOn = true;
mDockIdle = false;
+ mInCarMode = false;
}
@Override
@@ -74,6 +79,7 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
mIdleWindowSlop = context.getResources().getInteger(
com.android.internal.R.integer.config_jobSchedulerIdleWindowSlop);
mAlarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ mPowerManager = context.getSystemService(PowerManager.class);
IntentFilter filter = new IntentFilter();
@@ -92,6 +98,10 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
filter.addAction(Intent.ACTION_DOCK_IDLE);
filter.addAction(Intent.ACTION_DOCK_ACTIVE);
+ // Car mode
+ filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE_PRIORITIZED);
+ filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE_PRIORITIZED);
+
context.registerReceiver(this, filter);
}
@@ -100,6 +110,8 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
pw.print(" mIdle: "); pw.println(mIdle);
pw.print(" mScreenOn: "); pw.println(mScreenOn);
pw.print(" mDockIdle: "); pw.println(mDockIdle);
+ pw.print(" mInCarMode: ");
+ pw.println(mInCarMode);
}
@Override
@@ -116,6 +128,9 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
proto.write(
StateControllerProto.IdleController.IdlenessTracker.DeviceIdlenessTracker.IS_DOCK_IDLE,
mDockIdle);
+ proto.write(
+ StateControllerProto.IdleController.IdlenessTracker.DeviceIdlenessTracker.IN_CAR_MODE,
+ mInCarMode);
proto.end(diToken);
proto.end(token);
@@ -124,63 +139,90 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
- if (action.equals(Intent.ACTION_SCREEN_ON)
- || action.equals(Intent.ACTION_DREAMING_STOPPED)
- || action.equals(Intent.ACTION_DOCK_ACTIVE)) {
- if (action.equals(Intent.ACTION_DOCK_ACTIVE)) {
+ if (DEBUG) {
+ Slog.v(TAG, "Received action: " + action);
+ }
+ switch (action) {
+ case Intent.ACTION_DOCK_ACTIVE:
if (!mScreenOn) {
// Ignore this intent during screen off
return;
- } else {
- mDockIdle = false;
}
- } else {
+ // Intentional fallthrough
+ case Intent.ACTION_DREAMING_STOPPED:
+ if (!mPowerManager.isInteractive()) {
+ // Ignore this intent if the device isn't interactive.
+ return;
+ }
+ // Intentional fallthrough
+ case Intent.ACTION_SCREEN_ON:
mScreenOn = true;
mDockIdle = false;
- }
- if (DEBUG) {
- Slog.v(TAG,"exiting idle : " + action);
- }
- //cancel the alarm
- mAlarm.cancel(mIdleAlarmListener);
- if (mIdle) {
- // possible transition to not-idle
- mIdle = false;
- mIdleListener.reportNewIdleState(mIdle);
- }
- } else if (action.equals(Intent.ACTION_SCREEN_OFF)
- || action.equals(Intent.ACTION_DREAMING_STARTED)
- || action.equals(Intent.ACTION_DOCK_IDLE)) {
- // when the screen goes off or dreaming starts or wireless charging dock in idle,
- // we schedule the alarm that will tell us when we have decided the device is
- // truly idle.
- if (action.equals(Intent.ACTION_DOCK_IDLE)) {
- if (!mScreenOn) {
- // Ignore this intent during screen off
- return;
+ if (DEBUG) {
+ Slog.v(TAG, "exiting idle");
+ }
+ cancelIdlenessCheck();
+ if (mIdle) {
+ mIdle = false;
+ mIdleListener.reportNewIdleState(mIdle);
+ }
+ break;
+ case Intent.ACTION_SCREEN_OFF:
+ case Intent.ACTION_DREAMING_STARTED:
+ case Intent.ACTION_DOCK_IDLE:
+ // when the screen goes off or dreaming starts or wireless charging dock in idle,
+ // we schedule the alarm that will tell us when we have decided the device is
+ // truly idle.
+ if (action.equals(Intent.ACTION_DOCK_IDLE)) {
+ if (!mScreenOn) {
+ // Ignore this intent during screen off
+ return;
+ } else {
+ mDockIdle = true;
+ }
} else {
- mDockIdle = true;
+ mScreenOn = false;
+ mDockIdle = false;
}
- } else {
- mScreenOn = false;
- mDockIdle = false;
- }
+ maybeScheduleIdlenessCheck(action);
+ break;
+ case UiModeManager.ACTION_ENTER_CAR_MODE_PRIORITIZED:
+ mInCarMode = true;
+ cancelIdlenessCheck();
+ if (mIdle) {
+ mIdle = false;
+ mIdleListener.reportNewIdleState(mIdle);
+ }
+ break;
+ case UiModeManager.ACTION_EXIT_CAR_MODE_PRIORITIZED:
+ mInCarMode = false;
+ maybeScheduleIdlenessCheck(action);
+ break;
+ case ActivityManagerService.ACTION_TRIGGER_IDLE:
+ handleIdleTrigger();
+ break;
+ }
+ }
+
+ private void maybeScheduleIdlenessCheck(String reason) {
+ if ((!mScreenOn || mDockIdle) && !mInCarMode) {
final long nowElapsed = sElapsedRealtimeClock.millis();
final long when = nowElapsed + mInactivityIdleThreshold;
if (DEBUG) {
- Slog.v(TAG, "Scheduling idle : " + action + " now:" + nowElapsed + " when="
- + when);
+ Slog.v(TAG, "Scheduling idle : " + reason + " now:" + nowElapsed + " when=" + when);
}
mAlarm.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP,
when, mIdleWindowSlop, "JS idleness", mIdleAlarmListener, null);
- } else if (action.equals(ActivityManagerService.ACTION_TRIGGER_IDLE)) {
- handleIdleTrigger();
}
}
+ private void cancelIdlenessCheck() {
+ mAlarm.cancel(mIdleAlarmListener);
+ }
+
private void handleIdleTrigger() {
// idle time starts now. Do not set mIdle if screen is on.
- if (!mIdle && (!mScreenOn || mDockIdle)) {
+ if (!mIdle && (!mScreenOn || mDockIdle) && !mInCarMode) {
if (DEBUG) {
Slog.v(TAG, "Idle trigger fired @ " + sElapsedRealtimeClock.millis());
}
@@ -189,7 +231,7 @@ public final class DeviceIdlenessTracker extends BroadcastReceiver implements Id
} else {
if (DEBUG) {
Slog.v(TAG, "TRIGGER_IDLE received but not changing state; idle="
- + mIdle + " screen=" + mScreenOn);
+ + mIdle + " screen=" + mScreenOn + " car=" + mInCarMode);
}
}
}
diff --git a/apex/media/framework/java/android/media/MediaParser.java b/apex/media/framework/java/android/media/MediaParser.java
index e533b7a7d6f3..073fddf8f615 100644
--- a/apex/media/framework/java/android/media/MediaParser.java
+++ b/apex/media/framework/java/android/media/MediaParser.java
@@ -51,6 +51,7 @@ import com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory;
import com.google.android.exoplayer2.extractor.ts.PsExtractor;
import com.google.android.exoplayer2.extractor.ts.TsExtractor;
import com.google.android.exoplayer2.extractor.wav.WavExtractor;
+import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.TransferListener;
@@ -60,7 +61,6 @@ import com.google.android.exoplayer2.video.ColorInfo;
import java.io.EOFException;
import java.io.IOException;
-import java.io.InterruptedIOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.ByteBuffer;
@@ -848,9 +848,9 @@ public final class MediaParser {
private final String[] mParserNamesPool;
private final PositionHolder mPositionHolder;
private final InputReadingDataSource mDataSource;
- private final ExtractorInputAdapter mScratchExtractorInputAdapter;
+ private final DataReaderAdapter mScratchDataReaderAdapter;
private final ParsableByteArrayAdapter mScratchParsableByteArrayAdapter;
- private String mExtractorName;
+ private String mParserName;
private Extractor mExtractor;
private ExtractorInput mExtractorInput;
private long mPendingSeekPosition;
@@ -924,7 +924,7 @@ public final class MediaParser {
@NonNull
@ParserName
public String getParserName() {
- return mExtractorName;
+ return mParserName;
}
/**
@@ -958,25 +958,21 @@ public final class MediaParser {
// TODO: Apply parameters when creating extractor instances.
if (mExtractor == null) {
- if (!mExtractorName.equals(PARSER_NAME_UNKNOWN)) {
- mExtractor = EXTRACTOR_FACTORIES_BY_NAME.get(mExtractorName).createInstance();
+ if (!mParserName.equals(PARSER_NAME_UNKNOWN)) {
+ mExtractor = createExtractor(mParserName);
mExtractor.init(new ExtractorOutputAdapter());
} else {
for (String parserName : mParserNamesPool) {
Extractor extractor = createExtractor(parserName);
try {
if (extractor.sniff(mExtractorInput)) {
- mExtractorName = parserName;
+ mParserName = parserName;
mExtractor = extractor;
mExtractor.init(new ExtractorOutputAdapter());
break;
}
} catch (EOFException e) {
// Do nothing.
- } catch (InterruptedException e) {
- // TODO: Remove this exception replacement once we update the ExoPlayer
- // version.
- throw new InterruptedIOException();
} finally {
mExtractorInput.resetPeekPosition();
}
@@ -999,9 +995,6 @@ public final class MediaParser {
result = mExtractor.read(mExtractorInput, mPositionHolder);
} catch (ParserException e) {
throw new ParsingException(e);
- } catch (InterruptedException e) {
- // TODO: Remove this exception replacement once we update the ExoPlayer version.
- throw new InterruptedIOException();
}
if (result == Extractor.RESULT_END_OF_INPUT) {
return false;
@@ -1051,11 +1044,11 @@ public final class MediaParser {
mParserParameters = new HashMap<>();
mOutputConsumer = outputConsumer;
mParserNamesPool = parserNamesPool;
- mExtractorName = sniff ? PARSER_NAME_UNKNOWN : parserNamesPool[0];
+ mParserName = sniff ? PARSER_NAME_UNKNOWN : parserNamesPool[0];
mPositionHolder = new PositionHolder();
mDataSource = new InputReadingDataSource();
removePendingSeek();
- mScratchExtractorInputAdapter = new ExtractorInputAdapter();
+ mScratchDataReaderAdapter = new DataReaderAdapter();
mScratchParsableByteArrayAdapter = new ParsableByteArrayAdapter();
}
@@ -1097,7 +1090,7 @@ public final class MediaParser {
getBooleanParameter(PARAMETER_MP4_IGNORE_EDIT_LISTS)
? Mp4Extractor.FLAG_WORKAROUND_IGNORE_EDIT_LISTS
: 0;
- return new Mp4Extractor();
+ return new Mp4Extractor(flags);
case PARSER_NAME_MP3:
flags |=
getBooleanParameter(PARAMETER_MP3_DISABLE_ID3)
@@ -1270,12 +1263,12 @@ public final class MediaParser {
}
@Override
- public int sampleData(ExtractorInput input, int length, boolean allowEndOfInput)
+ public int sampleData(DataReader input, int length, boolean allowEndOfInput)
throws IOException {
- mScratchExtractorInputAdapter.setExtractorInput(input, length);
- long positionBeforeReading = mScratchExtractorInputAdapter.getPosition();
- mOutputConsumer.onSampleDataFound(mTrackIndex, mScratchExtractorInputAdapter);
- return (int) (mScratchExtractorInputAdapter.getPosition() - positionBeforeReading);
+ mScratchDataReaderAdapter.setDataReader(input, length);
+ long positionBeforeReading = mScratchDataReaderAdapter.getPosition();
+ mOutputConsumer.onSampleDataFound(mTrackIndex, mScratchDataReaderAdapter);
+ return (int) (mScratchDataReaderAdapter.getPosition() - positionBeforeReading);
}
@Override
@@ -1297,14 +1290,14 @@ public final class MediaParser {
}
}
- private static final class ExtractorInputAdapter implements InputReader {
+ private static final class DataReaderAdapter implements InputReader {
- private ExtractorInput mExtractorInput;
+ private DataReader mDataReader;
private int mCurrentPosition;
private long mLength;
- public void setExtractorInput(ExtractorInput extractorInput, long length) {
- mExtractorInput = extractorInput;
+ public void setDataReader(DataReader dataReader, long length) {
+ mDataReader = dataReader;
mCurrentPosition = 0;
mLength = length;
}
@@ -1314,12 +1307,7 @@ public final class MediaParser {
@Override
public int read(byte[] buffer, int offset, int readLength) throws IOException {
int readBytes = 0;
- try {
- readBytes = mExtractorInput.read(buffer, offset, readLength);
- } catch (InterruptedException e) {
- // TODO: Remove this exception replacement once we update the ExoPlayer version.
- throw new InterruptedIOException();
- }
+ readBytes = mDataReader.read(buffer, offset, readLength);
mCurrentPosition += readBytes;
return readBytes;
}
diff --git a/cmds/statsd/Android.bp b/cmds/statsd/Android.bp
index b3579045b6a5..6e8ceb7cb367 100644
--- a/cmds/statsd/Android.bp
+++ b/cmds/statsd/Android.bp
@@ -104,6 +104,7 @@ cc_defaults {
"src/subscriber/IncidentdReporter.cpp",
"src/subscriber/SubscriberReporter.cpp",
"src/uid_data.proto",
+ "src/utils/NamedLatch.cpp",
],
local_include_dirs: [
@@ -361,6 +362,7 @@ cc_test {
"tests/StatsService_test.cpp",
"tests/storage/StorageManager_test.cpp",
"tests/UidMap_test.cpp",
+ "tests/utils/NamedLatch_test.cpp",
],
static_libs: [
diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp
index dd1d40083a6b..ae7a8d0d30cc 100644
--- a/cmds/statsd/src/StatsService.cpp
+++ b/cmds/statsd/src/StatsService.cpp
@@ -118,8 +118,9 @@ StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQ
}
})),
mEventQueue(queue),
- mStatsCompanionServiceDeathRecipient(AIBinder_DeathRecipient_new(
- StatsService::statsCompanionServiceDied)) {
+ mBootCompleteLatch({kBootCompleteTag, kUidMapReceivedTag, kAllPullersRegisteredTag}),
+ mStatsCompanionServiceDeathRecipient(
+ AIBinder_DeathRecipient_new(StatsService::statsCompanionServiceDied)) {
mUidMap = UidMap::getInstance();
mPullerManager = new StatsPullerManager();
StatsPuller::SetUidMap(mUidMap);
@@ -164,6 +165,12 @@ StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQ
std::thread pushedEventThread([this] { readLogs(); });
pushedEventThread.detach();
}
+
+ std::thread bootCompletedThread([this] {
+ mBootCompleteLatch.wait();
+ VLOG("In the boot completed thread");
+ });
+ bootCompletedThread.detach();
}
StatsService::~StatsService() {
@@ -939,6 +946,7 @@ Status StatsService::informAllUidData(const ScopedFileDescriptor& fd) {
packageNames,
installers);
+ mBootCompleteLatch.countDown(kUidMapReceivedTag);
VLOG("StatsService::informAllUidData UidData proto parsed successfully.");
return Status::ok();
}
@@ -1058,7 +1066,7 @@ Status StatsService::bootCompleted() {
ENFORCE_UID(AID_SYSTEM);
VLOG("StatsService::bootCompleted was called");
-
+ mBootCompleteLatch.countDown(kBootCompleteTag);
return Status::ok();
}
@@ -1227,7 +1235,7 @@ Status StatsService::allPullersFromBootRegistered() {
ENFORCE_UID(AID_SYSTEM);
VLOG("StatsService::allPullersFromBootRegistered was called");
-
+ mBootCompleteLatch.countDown(kAllPullersRegisteredTag);
return Status::ok();
}
diff --git a/cmds/statsd/src/StatsService.h b/cmds/statsd/src/StatsService.h
index 23d4c1bd199d..79324d89d8e8 100644
--- a/cmds/statsd/src/StatsService.h
+++ b/cmds/statsd/src/StatsService.h
@@ -17,7 +17,14 @@
#ifndef STATS_SERVICE_H
#define STATS_SERVICE_H
+#include <aidl/android/os/BnStatsd.h>
+#include <aidl/android/os/IPendingIntentRef.h>
+#include <aidl/android/os/IPullAtomCallback.h>
#include <gtest/gtest_prod.h>
+#include <utils/Looper.h>
+
+#include <mutex>
+
#include "StatsLogProcessor.h"
#include "anomaly/AlarmMonitor.h"
#include "config/ConfigManager.h"
@@ -26,13 +33,7 @@
#include "packages/UidMap.h"
#include "shell/ShellSubscriber.h"
#include "statscompanion_util.h"
-
-#include <aidl/android/os/BnStatsd.h>
-#include <aidl/android/os/IPendingIntentRef.h>
-#include <aidl/android/os/IPullAtomCallback.h>
-#include <utils/Looper.h>
-
-#include <mutex>
+#include "utils/NamedLatch.h"
using namespace android;
using namespace android::os;
@@ -385,6 +386,11 @@ private:
mutable mutex mShellSubscriberMutex;
std::shared_ptr<LogEventQueue> mEventQueue;
+ NamedLatch mBootCompleteLatch;
+ static const inline string kBootCompleteTag = "BOOT_COMPLETE";
+ static const inline string kUidMapReceivedTag = "UID_MAP";
+ static const inline string kAllPullersRegisteredTag = "PULLERS_REGISTERED";
+
ScopedAIBinder_DeathRecipient mStatsCompanionServiceDeathRecipient;
FRIEND_TEST(StatsLogProcessorTest, TestActivationsPersistAcrossSystemServerRestart);
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 1f090fda2ce7..b7ed6eb16013 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -421,6 +421,8 @@ message Atom {
TvSettingsUIInteracted tvsettings_ui_interacted = 261 [(module) = "tv_settings"];
LauncherStaticLayout launcher_snapshot = 262 [(module) = "sysui"];
PackageInstallerV2Reported package_installer_v2_reported = 263 [(module) = "framework"];
+ UserLifecycleJourneyReported user_lifecycle_journey_reported = 264 [(module) = "framework"];
+ UserLifecycleEventOccurred user_lifecycle_event_occurred = 265 [(module) = "framework"];
SdkExtensionStatus sdk_extension_status = 354;
}
@@ -9357,3 +9359,82 @@ message SettingSnapshot {
// Android user index. 0 for primary user, 10, 11 for secondary or profile user
optional int32 user_id = 7;
}
+
+/**
+ * An event logged to indicate that a user journey is about to be performed. This atom includes
+ * relevant information about the users involved in the journey. A UserLifecycleEventOccurred event
+ * will immediately follow this atom which will describe the event(s) and its state.
+ *
+ * Logged from:
+ * frameworks/base/services/core/java/com/android/server/am/UserController.java
+ * frameworks/base/services/core/java/com/android/server/pm/UserManagerService.java
+ */
+message UserLifecycleJourneyReported {
+ // An identifier to track a chain of user lifecycle events occurring (referenced in the
+ // UserLifecycleEventOccurred atom)
+ optional int64 session_id = 1;
+
+ // Indicates what type of user journey this session is related to
+ enum Journey {
+ UNKNOWN = 0; // Undefined user lifecycle journey
+ USER_SWITCH_UI = 1; // A user switch journey where a UI is shown
+ USER_SWITCH_FG = 2; // A user switch journey without a UI shown
+ USER_START = 3; // A user start journey
+ USER_CREATE = 4; // A user creation journey
+ }
+ optional Journey journey = 2;
+ // Which user the journey is originating from - could be -1 for certain phases (eg USER_CREATE)
+ // This integer is a UserIdInt (eg 0 for the system user, 10 for secondary/guest)
+ optional int32 origin_user = 3;
+ // Which user the journey is targeting
+ // This integer is a UserIdInt (eg 0 for the system user, 10 for secondary/guest)
+ optional int32 target_user = 4;
+
+ // What is the user type of the target user
+ // These should be in sync with USER_TYPE_* flags defined in UserManager.java
+ enum UserType {
+ TYPE_UNKNOWN = 0;
+ FULL_SYSTEM = 1;
+ FULL_SECONDARY = 2;
+ FULL_GUEST = 3;
+ FULL_DEMO = 4;
+ FULL_RESTRICTED = 5;
+ PROFILE_MANAGED = 6;
+ SYSTEM_HEADLESS = 7;
+ }
+ optional UserType user_type = 5;
+ // What are the flags attached to the target user
+ optional int32 user_flags = 6;
+}
+
+/**
+ * An event logged when a specific user lifecycle event is performed. These events should be
+ * correlated with a UserLifecycleJourneyReported atom via the session_id.
+ * Note: journeys can span over multiple events, hence some events may share a single session id.
+ *
+ * Logged from:
+ * frameworks/base/services/core/java/com/android/server/am/UserController.java
+ * frameworks/base/services/core/java/com/android/server/pm/UserManagerService.java
+ */
+message UserLifecycleEventOccurred {
+ // An id which links back to user details (reported in the UserLifecycleJourneyReported atom)
+ optional int64 session_id = 1;
+ // The target user for this event (same as target_user in the UserLifecycleJourneyReported atom)
+ // This integer is a UserIdInt (eg 0 for the system user, 10 for secondary/guest)
+ optional int32 user_id = 2;
+
+ enum Event {
+ UNKNOWN = 0; // Indicates that the associated user journey timed-out or resulted in an error
+ SWITCH_USER = 1; // Indicates that this is a user switch event
+ START_USER = 2; // Indicates that this is a user start event
+ CREATE_USER = 3; // Indicates that this is a user create event
+ }
+ optional Event event = 3;
+
+ enum State {
+ NONE = 0; // Indicates the associated event has no start/end defined
+ BEGIN = 1;
+ FINISH = 2;
+ }
+ optional State state = 4; // Represents the state of an event (beginning/ending)
+}
diff --git a/cmds/statsd/src/utils/NamedLatch.cpp b/cmds/statsd/src/utils/NamedLatch.cpp
new file mode 100644
index 000000000000..6e77977857cc
--- /dev/null
+++ b/cmds/statsd/src/utils/NamedLatch.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+#define DEBUG false // STOPSHIP if true
+
+#include "NamedLatch.h"
+
+using namespace std;
+
+namespace android {
+namespace os {
+namespace statsd {
+
+NamedLatch::NamedLatch(const set<string>& eventNames) : mRemainingEventNames(eventNames) {
+}
+
+void NamedLatch::countDown(const string& eventName) {
+ bool notify = false;
+ {
+ lock_guard<mutex> lg(mMutex);
+ mRemainingEventNames.erase(eventName);
+ notify = mRemainingEventNames.empty();
+ }
+ if (notify) {
+ mConditionVariable.notify_all();
+ }
+}
+
+void NamedLatch::wait() const {
+ unique_lock<mutex> unique_lk(mMutex);
+ mConditionVariable.wait(unique_lk, [this] { return mRemainingEventNames.empty(); });
+}
+
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/src/utils/NamedLatch.h b/cmds/statsd/src/utils/NamedLatch.h
new file mode 100644
index 000000000000..70238370f647
--- /dev/null
+++ b/cmds/statsd/src/utils/NamedLatch.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+#pragma once
+
+#include <gtest/gtest_prod.h>
+
+#include <condition_variable>
+#include <mutex>
+#include <set>
+
+namespace android {
+namespace os {
+namespace statsd {
+
+/**
+ * This class provides a threading primitive similar to a latch.
+ * The primary difference is that it waits for named events to occur instead of waiting for
+ * N threads to reach a certain point.
+ *
+ * It uses a condition variable under the hood.
+ */
+class NamedLatch {
+public:
+ explicit NamedLatch(const std::set<std::string>& eventNames);
+
+ NamedLatch(const NamedLatch&) = delete;
+ NamedLatch& operator=(const NamedLatch&) = delete;
+
+ // Mark a specific event as completed. If this event has called countDown already or if the
+ // event was not specified in the constructor, the function is a no-op.
+ void countDown(const std::string& eventName);
+
+ // Blocks the calling thread until all events in eventNames have called countDown.
+ void wait() const;
+
+private:
+ mutable std::mutex mMutex;
+ mutable std::condition_variable mConditionVariable;
+ std::set<std::string> mRemainingEventNames;
+
+ FRIEND_TEST(NamedLatchTest, TestCountDownCalledBySameEventName);
+};
+} // namespace statsd
+} // namespace os
+} // namespace android
diff --git a/cmds/statsd/tests/utils/NamedLatch_test.cpp b/cmds/statsd/tests/utils/NamedLatch_test.cpp
new file mode 100644
index 000000000000..de48a133823e
--- /dev/null
+++ b/cmds/statsd/tests/utils/NamedLatch_test.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+#include "utils/NamedLatch.h"
+
+#include <gtest/gtest.h>
+
+#include <chrono>
+#include <set>
+#include <thread>
+#include <vector>
+
+#ifdef __ANDROID__
+
+using namespace std;
+using std::this_thread::sleep_for;
+
+namespace android {
+namespace os {
+namespace statsd {
+
+TEST(NamedLatchTest, TestWait) {
+ int numEvents = 5;
+ string t1 = "t1", t2 = "t2", t3 = "t3", t4 = "t4", t5 = "t5";
+ set<string> eventNames = {t1, t2, t3, t4, t5};
+
+ NamedLatch latch(eventNames);
+ vector<thread> threads;
+ vector<bool> done(numEvents, false);
+
+ int i = 0;
+ for (const string& eventName : eventNames) {
+ threads.emplace_back([&done, &eventName, &latch, i] {
+ sleep_for(chrono::milliseconds(3));
+ done[i] = true;
+ latch.countDown(eventName);
+ });
+ i++;
+ }
+
+ latch.wait();
+
+ for (i = 0; i < numEvents; i++) {
+ EXPECT_EQ(done[i], 1);
+ }
+
+ for (i = 0; i < numEvents; i++) {
+ threads[i].join();
+ }
+}
+
+TEST(NamedLatchTest, TestNoWorkers) {
+ NamedLatch latch({});
+ latch.wait();
+ // Ensure that latch does not wait if no events need to countDown.
+}
+
+TEST(NamedLatchTest, TestCountDownCalledBySameEventName) {
+ string t1 = "t1", t2 = "t2";
+ set<string> eventNames = {t1, t2};
+
+ NamedLatch latch(eventNames);
+
+ thread waiterThread([&latch] { latch.wait(); });
+
+ latch.countDown(t1);
+ latch.countDown(t1);
+
+ // Ensure that the latch's remaining threads still has t2.
+ latch.mMutex.lock();
+ ASSERT_EQ(latch.mRemainingEventNames.size(), 1);
+ EXPECT_NE(latch.mRemainingEventNames.find(t2), latch.mRemainingEventNames.end());
+ latch.mMutex.unlock();
+
+ latch.countDown(t2);
+ waiterThread.join();
+}
+
+} // namespace statsd
+} // namespace os
+} // namespace android
+#else
+GTEST_LOG_(INFO) << "This test does nothing.\n";
+#endif
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index 3a708a6f699b..8e0d939487e3 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -2586,6 +2586,44 @@ public class AppOpsManager {
}
/**
+ * Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}.
+ *
+ * This is intended for use client side, when the receiver id must be created before the
+ * associated call is made to the system server. If using {@link PendingIntent} as the receiver,
+ * avoid using this method as it will include a pointless additional x-process call. Instead to
+ * prefer passing the PendingIntent to the system server, and then invoking
+ * {@link #toReceiverId(PendingIntent)} instead.
+ *
+ * @param obj the receiver in use
+ * @return a string representation of the receiver suitable for app ops use
+ * @hide
+ */
+ // TODO: this should probably be @SystemApi as well
+ public static @NonNull String toReceiverId(@NonNull Object obj) {
+ if (obj instanceof PendingIntent) {
+ return toReceiverId((PendingIntent) obj);
+ } else {
+ return obj.getClass().getName() + "@" + System.identityHashCode(obj);
+ }
+ }
+
+ /**
+ * Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}.
+ *
+ * This is intended for use server side, where ActivityManagerService can be referenced without
+ * an additional x-process call.
+ *
+ * @param pendingIntent the pendingIntent in use
+ * @return a string representation of the pending intent suitable for app ops use
+ * @see #toReceiverId(Object)
+ * @hide
+ */
+ // TODO: this should probably be @SystemApi as well
+ public static @NonNull String toReceiverId(@NonNull PendingIntent pendingIntent) {
+ return pendingIntent.getTag("");
+ }
+
+ /**
* When to not enforce {@link #setUserRestriction restrictions}.
*
* @hide
diff --git a/core/java/android/app/TEST_MAPPING b/core/java/android/app/TEST_MAPPING
index ab868604dfde..344a4d79b766 100644
--- a/core/java/android/app/TEST_MAPPING
+++ b/core/java/android/app/TEST_MAPPING
@@ -20,6 +20,10 @@
},
{
"file_patterns": ["(/|^)AppOpsManager.java"],
+ "name": "UidAtomTests:testAppOps"
+ },
+ {
+ "file_patterns": ["(/|^)AppOpsManager.java"],
"name": "FrameworksServicesTests",
"options": [
{
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index fb9adb730314..41e2dc0de4d6 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -3666,6 +3666,28 @@ public class DevicePolicyManager {
}
/**
+ * Returns whether the given user's credential will be sufficient for all password policy
+ * requirement, once the user's profile has switched to unified challenge.
+ *
+ * <p>This is different from {@link #isActivePasswordSufficient()} since once the profile
+ * switches to unified challenge, policies set explicitly on the profile will start to affect
+ * the parent user.
+ * @param userHandle the user whose password requirement will be checked
+ * @param profileUser the profile user whose lockscreen challenge will be unified.
+ * @hide
+ */
+ public boolean isPasswordSufficientAfterProfileUnification(int userHandle, int profileUser) {
+ if (mService != null) {
+ try {
+ return mService.isPasswordSufficientAfterProfileUnification(userHandle,
+ profileUser);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+ return false;
+ }
+ /**
* Retrieve the number of times the user has failed at entering a password since that last
* successful password entry.
* <p>
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 591a3f68eed0..d10153c11723 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -85,6 +85,7 @@ interface IDevicePolicyManager {
boolean isActivePasswordSufficient(int userHandle, boolean parent);
boolean isProfileActivePasswordSufficientForParent(int userHandle);
+ boolean isPasswordSufficientAfterProfileUnification(int userHandle, int profileUser);
int getPasswordComplexity(boolean parent);
boolean isUsingUnifiedPassword(in ComponentName admin);
int getCurrentFailedPasswordAttempts(int userHandle, boolean parent);
diff --git a/core/java/android/app/admin/PasswordMetrics.java b/core/java/android/app/admin/PasswordMetrics.java
index 86ebb47400c7..39e1f0dc2d2c 100644
--- a/core/java/android/app/admin/PasswordMetrics.java
+++ b/core/java/android/app/admin/PasswordMetrics.java
@@ -350,7 +350,7 @@ public final class PasswordMetrics implements Parcelable {
*
* TODO: move to PasswordPolicy
*/
- private void maxWith(PasswordMetrics other) {
+ public void maxWith(PasswordMetrics other) {
credType = Math.max(credType, other.credType);
if (credType != CREDENTIAL_TYPE_PASSWORD) {
return;
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 9ca2db970eb7..d36d583559a0 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -3158,6 +3158,23 @@ public abstract class PackageManager {
"android.content.pm.extra.VERIFICATION_LONG_VERSION_CODE";
/**
+ * Extra field name for the Merkle tree root hash of a package.
+ * <p>Passed to a package verifier both prior to verification and as a result
+ * of verification.
+ * <p>The value of the extra is a specially formatted list:
+ * {@code filename1:HASH_1;filename2:HASH_2;...;filenameN:HASH_N}
+ * <p>The extra must include an entry for every APK within an installation. If
+ * a hash is not physically present, a hash value of {@code 0} will be used.
+ * <p>The root hash is generated using SHA-256, no salt with a 4096 byte block
+ * size. See the description of the
+ * <a href="https://www.kernel.org/doc/html/latest/filesystems/fsverity.html#merkle-tree">fs-verity merkle-tree</a>
+ * for more details.
+ * @hide
+ */
+ public static final String EXTRA_VERIFICATION_ROOT_HASH =
+ "android.content.pm.extra.EXTRA_VERIFICATION_ROOT_HASH";
+
+ /**
* Extra field name for the ID of a intent filter pending verification.
* Passed to an intent filter verifier and is used to call back to
* {@link #verifyIntentFilter}
diff --git a/core/java/android/net/UrlQuerySanitizer.java b/core/java/android/net/UrlQuerySanitizer.java
index cf08b653d0f4..b1cf044e8173 100644
--- a/core/java/android/net/UrlQuerySanitizer.java
+++ b/core/java/android/net/UrlQuerySanitizer.java
@@ -306,7 +306,7 @@ public class UrlQuerySanitizer {
return null;
}
int length = value.length();
- if ((mFlags & SCRIPT_URL_OK) != 0) {
+ if ((mFlags & SCRIPT_URL_OK) == 0) {
if (length >= MIN_SCRIPT_PREFIX_LENGTH) {
String asLower = value.toLowerCase(Locale.ROOT);
if (asLower.startsWith(JAVASCRIPT_PREFIX) ||
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index 0f2060a36ac9..187274a837a0 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -57,6 +57,7 @@ import android.view.WindowManager.LayoutParams;
import com.android.internal.R;
import com.android.internal.os.RoSystemProperties;
+import com.android.internal.util.FrameworkStatsLog;
import java.io.IOException;
import java.lang.annotation.Retention;
@@ -1841,6 +1842,35 @@ public class UserManager {
}
/**
+ * Returns the enum defined in the statsd UserLifecycleJourneyReported atom corresponding to the
+ * user type.
+ * @hide
+ */
+ public static int getUserTypeForStatsd(@NonNull String userType) {
+ switch (userType) {
+ case USER_TYPE_FULL_SYSTEM:
+ return FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__USER_TYPE__FULL_SYSTEM;
+ case USER_TYPE_FULL_SECONDARY:
+ return FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__USER_TYPE__FULL_SECONDARY;
+ case USER_TYPE_FULL_GUEST:
+ return FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__USER_TYPE__FULL_GUEST;
+ case USER_TYPE_FULL_DEMO:
+ return FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__USER_TYPE__FULL_DEMO;
+ case USER_TYPE_FULL_RESTRICTED:
+ return FrameworkStatsLog
+ .USER_LIFECYCLE_JOURNEY_REPORTED__USER_TYPE__FULL_RESTRICTED;
+ case USER_TYPE_PROFILE_MANAGED:
+ return FrameworkStatsLog
+ .USER_LIFECYCLE_JOURNEY_REPORTED__USER_TYPE__PROFILE_MANAGED;
+ case USER_TYPE_SYSTEM_HEADLESS:
+ return FrameworkStatsLog
+ .USER_LIFECYCLE_JOURNEY_REPORTED__USER_TYPE__SYSTEM_HEADLESS;
+ default:
+ return FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__USER_TYPE__TYPE_UNKNOWN;
+ }
+ }
+
+ /**
* @hide
* @deprecated Use {@link #isRestrictedProfile()}
*/
diff --git a/core/java/android/os/incremental/V4Signature.java b/core/java/android/os/incremental/V4Signature.java
index 5cc73caa4f60..d35ce5b2c3f8 100644
--- a/core/java/android/os/incremental/V4Signature.java
+++ b/core/java/android/os/incremental/V4Signature.java
@@ -16,6 +16,8 @@
package android.os.incremental;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.os.ParcelFileDescriptor;
import java.io.ByteArrayInputStream;
@@ -45,8 +47,8 @@ public class V4Signature {
public static class HashingInfo {
public final int hashAlgorithm; // only 1 == SHA256 supported
public final byte log2BlockSize; // only 12 (block size 4096) supported now
- public final byte[] salt; // used exactly as in fs-verity, 32 bytes max
- public final byte[] rawRootHash; // salted digest of the first Merkle tree page
+ @Nullable public final byte[] salt; // used exactly as in fs-verity, 32 bytes max
+ @Nullable public final byte[] rawRootHash; // salted digest of the first Merkle tree page
HashingInfo(int hashAlgorithm, byte log2BlockSize, byte[] salt, byte[] rawRootHash) {
this.hashAlgorithm = hashAlgorithm;
@@ -58,7 +60,8 @@ public class V4Signature {
/**
* Constructs HashingInfo from byte array.
*/
- public static HashingInfo fromByteArray(byte[] bytes) throws IOException {
+ @NonNull
+ public static HashingInfo fromByteArray(@NonNull byte[] bytes) throws IOException {
ByteBuffer buffer = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
final int hashAlgorithm = buffer.getInt();
final byte log2BlockSize = buffer.get();
@@ -106,8 +109,18 @@ public class V4Signature {
}
public final int version; // Always 2 for now.
- public final byte[] hashingInfo;
- public final byte[] signingInfo; // Passed as-is to the kernel. Can be retrieved later.
+ /**
+ * Raw byte array containing the IncFS hashing data.
+ * @see HashingInfo#fromByteArray(byte[])
+ */
+ @Nullable public final byte[] hashingInfo;
+
+ /**
+ * Raw byte array containing the V4 signature data.
+ * <p>Passed as-is to the kernel. Can be retrieved later.
+ * @see SigningInfo#fromByteArray(byte[])
+ */
+ @Nullable public final byte[] signingInfo;
/**
* Construct a V4Signature from .idsig file.
@@ -121,7 +134,8 @@ public class V4Signature {
/**
* Construct a V4Signature from a byte array.
*/
- public static V4Signature readFrom(byte[] bytes) throws IOException {
+ @NonNull
+ public static V4Signature readFrom(@NonNull byte[] bytes) throws IOException {
try (InputStream stream = new ByteArrayInputStream(bytes)) {
return readFrom(stream);
}
@@ -169,7 +183,7 @@ public class V4Signature {
return this.version == SUPPORTED_VERSION;
}
- private V4Signature(int version, byte[] hashingInfo, byte[] signingInfo) {
+ private V4Signature(int version, @Nullable byte[] hashingInfo, @Nullable byte[] signingInfo) {
this.version = version;
this.hashingInfo = hashingInfo;
this.signingInfo = signingInfo;
diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java
index 3f0787350075..337027ef5bc9 100644
--- a/core/java/android/service/dreams/DreamService.java
+++ b/core/java/android/service/dreams/DreamService.java
@@ -182,7 +182,6 @@ public class DreamService extends Service implements Window.Callback {
private Window mWindow;
private Activity mActivity;
private boolean mInteractive;
- private boolean mLowProfile = true;
private boolean mFullscreen;
private boolean mScreenBright = true;
private boolean mStarted;
@@ -530,32 +529,6 @@ public class DreamService extends Service implements Window.Callback {
}
/**
- * Sets View.SYSTEM_UI_FLAG_LOW_PROFILE on the content view.
- *
- * @param lowProfile True to set View.SYSTEM_UI_FLAG_LOW_PROFILE
- * @hide There is no reason to have this -- dreams can set this flag
- * on their own content view, and from there can actually do the
- * correct interactions with it (seeing when it is cleared etc).
- */
- public void setLowProfile(boolean lowProfile) {
- if (mLowProfile != lowProfile) {
- mLowProfile = lowProfile;
- int flag = View.SYSTEM_UI_FLAG_LOW_PROFILE;
- applySystemUiVisibilityFlags(mLowProfile ? flag : 0, flag);
- }
- }
-
- /**
- * Returns whether or not this dream is in low profile mode. Defaults to true.
- *
- * @see #setLowProfile(boolean)
- * @hide
- */
- public boolean isLowProfile() {
- return getSystemUiVisibilityFlagValue(View.SYSTEM_UI_FLAG_LOW_PROFILE, mLowProfile);
- }
-
- /**
* Controls {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN}
* on the dream's window.
*
@@ -1094,10 +1067,6 @@ public class DreamService extends Service implements Window.Callback {
// along well. Dreams usually don't need such bars anyways, so disable them by default.
mWindow.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
- applySystemUiVisibilityFlags(
- (mLowProfile ? View.SYSTEM_UI_FLAG_LOW_PROFILE : 0),
- View.SYSTEM_UI_FLAG_LOW_PROFILE);
-
mWindow.getDecorView().addOnAttachStateChangeListener(
new View.OnAttachStateChangeListener() {
@Override
@@ -1126,18 +1095,6 @@ public class DreamService extends Service implements Window.Callback {
}
}
- private boolean getSystemUiVisibilityFlagValue(int flag, boolean defaultValue) {
- View v = mWindow == null ? null : mWindow.getDecorView();
- return v == null ? defaultValue : (v.getSystemUiVisibility() & flag) != 0;
- }
-
- private void applySystemUiVisibilityFlags(int flags, int mask) {
- View v = mWindow == null ? null : mWindow.getDecorView();
- if (v != null) {
- v.setSystemUiVisibility(applyFlags(v.getSystemUiVisibility(), flags, mask));
- }
- }
-
private int applyFlags(int oldFlags, int flags, int mask) {
return (oldFlags&~mask) | (flags&mask);
}
@@ -1163,7 +1120,6 @@ public class DreamService extends Service implements Window.Callback {
pw.println(" window: " + mWindow);
pw.print(" flags:");
if (isInteractive()) pw.print(" interactive");
- if (isLowProfile()) pw.print(" lowprofile");
if (isFullscreen()) pw.print(" fullscreen");
if (isScreenBright()) pw.print(" bright");
if (isWindowless()) pw.print(" windowless");
diff --git a/core/java/android/service/notification/StatusBarNotification.java b/core/java/android/service/notification/StatusBarNotification.java
index 21b83c660446..5c43f8f829b0 100644
--- a/core/java/android/service/notification/StatusBarNotification.java
+++ b/core/java/android/service/notification/StatusBarNotification.java
@@ -292,6 +292,18 @@ public class StatusBarNotification implements Parcelable {
return this.user.getIdentifier();
}
+ /**
+ * Like {@link #getUserId()} but handles special users.
+ * @hide
+ */
+ public int getNormalizedUserId() {
+ int userId = getUserId();
+ if (userId == UserHandle.USER_ALL) {
+ userId = UserHandle.USER_SYSTEM;
+ }
+ return userId;
+ }
+
/** The package that the notification belongs to. */
public String getPackageName() {
return pkg;
diff --git a/core/java/android/speech/RecognizerIntent.java b/core/java/android/speech/RecognizerIntent.java
index 362b94b83c3f..3b5a6d59e7e6 100644
--- a/core/java/android/speech/RecognizerIntent.java
+++ b/core/java/android/speech/RecognizerIntent.java
@@ -413,6 +413,10 @@ public class RecognizerIntent {
* {@link #ACTION_VOICE_SEARCH_HANDS_FREE}, {@link #ACTION_WEB_SEARCH} to indicate whether to
* only use an offline speech recognition engine. The default is false, meaning that either
* network or offline recognition engines may be used.
+ *
+ * <p>Depending on the recognizer implementation, these values may have
+ * no effect.</p>
+ *
*/
public static final String EXTRA_PREFER_OFFLINE = "android.speech.extra.PREFER_OFFLINE";
}
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index 1086774fc8ff..76ed37c51bfe 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -228,6 +228,7 @@ public final class SurfaceControl implements Parcelable {
*/
public long mNativeObject;
private long mNativeHandle;
+ private Throwable mReleaseStack = null;
// TODO: Move this to native.
private final Object mSizeLock = new Object();
@@ -426,11 +427,18 @@ public final class SurfaceControl implements Parcelable {
if (mNativeObject != 0) {
release();
}
- if (nativeObject != 0) {
+ if (nativeObject != 0) {
mCloseGuard.open("release");
}
mNativeObject = nativeObject;
mNativeHandle = mNativeObject != 0 ? nativeGetHandle(nativeObject) : 0;
+ if (mNativeObject == 0) {
+ if (Build.IS_DEBUGGABLE) {
+ mReleaseStack = new Throwable("assigned zero nativeObject here");
+ }
+ } else {
+ mReleaseStack = null;
+ }
}
/**
@@ -989,11 +997,22 @@ public final class SurfaceControl implements Parcelable {
nativeRelease(mNativeObject);
mNativeObject = 0;
mNativeHandle = 0;
+ if (Build.IS_DEBUGGABLE) {
+ mReleaseStack = new Throwable("released here");
+ }
mCloseGuard.close();
}
}
/**
+ * Returns the call stack that assigned mNativeObject to zero.
+ * @hide
+ */
+ public Throwable getReleaseStack() {
+ return mReleaseStack;
+ }
+
+ /**
* Disconnect any client still connected to the surface.
* @hide
*/
@@ -1004,8 +1023,11 @@ public final class SurfaceControl implements Parcelable {
}
private void checkNotReleased() {
- if (mNativeObject == 0) throw new NullPointerException(
- "mNativeObject is null. Have you called release() already?");
+ if (mNativeObject == 0) {
+ Log.wtf(TAG, "Invalid " + this + " caused by:", mReleaseStack);
+ throw new NullPointerException(
+ "mNativeObject of " + this + " is null. Have you called release() already?");
+ }
}
/**
diff --git a/core/java/com/android/internal/app/SystemUserHomeActivity.java b/core/java/com/android/internal/app/SystemUserHomeActivity.java
index 26fbf6f826a8..ee936a3f9abc 100644
--- a/core/java/com/android/internal/app/SystemUserHomeActivity.java
+++ b/core/java/com/android/internal/app/SystemUserHomeActivity.java
@@ -17,10 +17,27 @@
package com.android.internal.app;
import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.android.internal.R;
/**
* Placeholder home activity, which is always installed on the system user. At least one home
* activity must be present and enabled in order for the system to boot.
*/
public class SystemUserHomeActivity extends Activity {
+ private static final String TAG = "SystemUserHome";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Log.i(TAG, "onCreate");
+ setContentView(R.layout.system_user_home);
+ }
+
+ protected void onDestroy() {
+ super.onDestroy();
+ Log.i(TAG, "onDestroy");
+ }
}
diff --git a/core/proto/android/server/jobscheduler.proto b/core/proto/android/server/jobscheduler.proto
index bd1bae6d83fb..b678d627d48c 100644
--- a/core/proto/android/server/jobscheduler.proto
+++ b/core/proto/android/server/jobscheduler.proto
@@ -523,6 +523,7 @@ message StateControllerProto {
optional bool is_idle = 1;
optional bool is_screen_on = 2;
optional bool is_dock_idle = 3;
+ optional bool in_car_mode = 4;
}
oneof active_tracker {
diff --git a/core/res/res/layout/system_user_home.xml b/core/res/res/layout/system_user_home.xml
new file mode 100644
index 000000000000..8afa42338e36
--- /dev/null
+++ b/core/res/res/layout/system_user_home.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2020 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
+ -->
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#80000000"
+ android:forceHasOverlappingRendering="false">
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:layout_gravity="center"
+ android:layout_marginStart="16dp"
+ android:layout_marginEnd="16dp">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="20sp"
+ android:textColor="?android:attr/textColorPrimary"
+ android:text="Framework Fallback Home"/>
+ <ProgressBar
+ style="@android:style/Widget.Material.ProgressBar.Horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="12.75dp"
+ android:colorControlActivated="?android:attr/textColorPrimary"
+ android:indeterminate="true"/>
+ </LinearLayout>
+</FrameLayout>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 01d4e8c56249..717f326d0378 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1468,6 +1468,7 @@
<java-symbol type="layout" name="select_dialog" />
<java-symbol type="layout" name="simple_dropdown_hint" />
<java-symbol type="layout" name="status_bar_latest_event_content" />
+ <java-symbol type="layout" name="system_user_home" />
<java-symbol type="layout" name="text_edit_action_popup_text" />
<java-symbol type="layout" name="text_drag_thumbnail" />
<java-symbol type="layout" name="typing_filter" />
diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java
index d1b41dfccf63..9b4aebcd8aff 100644
--- a/location/java/android/location/LocationManager.java
+++ b/location/java/android/location/LocationManager.java
@@ -34,6 +34,7 @@ import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.AlarmManager;
+import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.app.PropertyInvalidatedCache;
import android.compat.Compatibility;
@@ -2561,7 +2562,7 @@ public class LocationManager {
}
public String getListenerId() {
- return mConsumer.getClass().getName() + "@" + System.identityHashCode(mConsumer);
+ return AppOpsManager.toReceiverId(mConsumer);
}
public synchronized void register(AlarmManager alarmManager,
@@ -2690,7 +2691,7 @@ public class LocationManager {
}
public String getListenerId() {
- return mListener.getClass().getName() + "@" + System.identityHashCode(mListener);
+ return AppOpsManager.toReceiverId(mListener);
}
public void register(@NonNull Executor executor) {
diff --git a/media/java/android/media/MediaRouter2.java b/media/java/android/media/MediaRouter2.java
index 25f6059c35de..bd8fb9602656 100644
--- a/media/java/android/media/MediaRouter2.java
+++ b/media/java/android/media/MediaRouter2.java
@@ -409,7 +409,7 @@ public final class MediaRouter2 {
// TODO: Check thread-safety
if (!mRoutes.containsKey(route.getId())) {
- notifyTransferFailed(route);
+ notifyTransferFailure(route);
return;
}
if (controller.getRoutingSessionInfo().getTransferableRoutes().contains(route.getId())) {
@@ -588,14 +588,14 @@ public final class MediaRouter2 {
if (sessionInfo == null) {
// TODO: We may need to distinguish between failure and rejection.
// One way can be introducing 'reason'.
- notifyTransferFailed(requestedRoute);
+ notifyTransferFailure(requestedRoute);
return;
} else if (!sessionInfo.getSelectedRoutes().contains(requestedRoute.getId())) {
Log.w(TAG, "The session does not contain the requested route. "
+ "(requestedRouteId=" + requestedRoute.getId()
+ ", actualRoutes=" + sessionInfo.getSelectedRoutes()
+ ")");
- notifyTransferFailed(requestedRoute);
+ notifyTransferFailure(requestedRoute);
return;
} else if (!TextUtils.equals(requestedRoute.getProviderId(),
sessionInfo.getProviderId())) {
@@ -603,7 +603,7 @@ public final class MediaRouter2 {
+ "(requested route's providerId=" + requestedRoute.getProviderId()
+ ", actual providerId=" + sessionInfo.getProviderId()
+ ")");
- notifyTransferFailed(requestedRoute);
+ notifyTransferFailure(requestedRoute);
return;
}
}
@@ -619,7 +619,7 @@ public final class MediaRouter2 {
}
}
//TODO: Determine oldController properly when transfer is launched by Output Switcher.
- notifyTransferred(matchingRequest != null ? matchingRequest.mController :
+ notifyTransfer(matchingRequest != null ? matchingRequest.mController :
getSystemController(), newController);
}
}
@@ -687,15 +687,7 @@ public final class MediaRouter2 {
return;
}
- boolean removed;
- synchronized (sRouterLock) {
- removed = mRoutingControllers.remove(uniqueSessionId, matchingController);
- }
-
- if (removed) {
- matchingController.release();
- notifyStopped(matchingController);
- }
+ matchingController.releaseInternal(/* shouldReleaseSession= */ false);
}
private List<MediaRoute2Info> filterRoutes(List<MediaRoute2Info> routes,
@@ -736,22 +728,21 @@ public final class MediaRouter2 {
}
}
- private void notifyTransferred(RoutingController oldController,
- RoutingController newController) {
+ private void notifyTransfer(RoutingController oldController, RoutingController newController) {
for (TransferCallbackRecord record: mTransferCallbackRecords) {
record.mExecutor.execute(
() -> record.mTransferCallback.onTransfer(oldController, newController));
}
}
- private void notifyTransferFailed(MediaRoute2Info route) {
+ private void notifyTransferFailure(MediaRoute2Info route) {
for (TransferCallbackRecord record: mTransferCallbackRecords) {
record.mExecutor.execute(
() -> record.mTransferCallback.onTransferFailure(route));
}
}
- private void notifyStopped(RoutingController controller) {
+ private void notifyStop(RoutingController controller) {
for (TransferCallbackRecord record: mTransferCallbackRecords) {
record.mExecutor.execute(
() -> record.mTransferCallback.onStop(controller));
@@ -1189,32 +1180,38 @@ public final class MediaRouter2 {
*/
// TODO: Add tests using {@link MediaRouter2Manager#getActiveSessions()}.
public void release() {
+ releaseInternal(/* shouldReleaseSession= */ true);
+ }
+
+ void releaseInternal(boolean shouldReleaseSession) {
synchronized (mControllerLock) {
if (mIsReleased) {
- Log.w(TAG, "release() called on released controller. Ignoring.");
+ Log.w(TAG, "releaseInternal() called on released controller. Ignoring.");
return;
}
mIsReleased = true;
}
MediaRouter2Stub stub;
- boolean removed;
synchronized (sRouterLock) {
- removed = mRoutingControllers.remove(getId(), this);
+ mRoutingControllers.remove(getId(), this);
stub = mStub;
}
- if (removed) {
- mHandler.post(() -> notifyStopped(RoutingController.this));
- }
-
- if (stub != null) {
+ if (shouldReleaseSession && stub != null) {
try {
mMediaRouterService.releaseSessionWithRouter2(stub, getId());
} catch (RemoteException ex) {
- Log.e(TAG, "Unable to notify of controller release", ex);
+ Log.e(TAG, "Unable to release session", ex);
}
}
+
+ if (Thread.currentThread() == mHandler.getLooper().getThread()) {
+ notifyStop(this);
+ } else {
+ mHandler.sendMessage(obtainMessage(MediaRouter2::notifyStop, MediaRouter2.this,
+ RoutingController.this));
+ }
}
@Override
diff --git a/media/tests/AudioPolicyTest/Android.bp b/media/tests/AudioPolicyTest/Android.bp
new file mode 100644
index 000000000000..ed3383752695
--- /dev/null
+++ b/media/tests/AudioPolicyTest/Android.bp
@@ -0,0 +1,17 @@
+android_test {
+ name: "audiopolicytest",
+ srcs: ["**/*.java"],
+ libs: [
+ "android.test.runner",
+ "android.test.base",
+ ],
+ static_libs: [
+ "mockito-target-minus-junit4",
+ "androidx.test.rules",
+ "android-ex-camera2",
+ "testng",
+ ],
+ platform_apis: true,
+ certificate: "platform",
+ resource_dirs: ["res"],
+}
diff --git a/media/tests/AudioPolicyTest/AndroidManifest.xml b/media/tests/AudioPolicyTest/AndroidManifest.xml
new file mode 100644
index 000000000000..adb058c82870
--- /dev/null
+++ b/media/tests/AudioPolicyTest/AndroidManifest.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 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.audiopolicytest">
+
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
+ <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
+ <uses-permission android:name="android.permission.MODIFY_AUDIO_ROUTING" />
+ <uses-permission android:name="android.permission.CHANGE_ACCESSIBILITY_VOLUME" />
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ <activity android:label="@string/app_name" android:name="AudioPolicyTest"
+ android:screenOrientation="landscape">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+
+ <!--instrumentation android:name=".AudioPolicyTestRunner"
+ android:targetPackage="com.android.audiopolicytest"
+ android:label="AudioManager policy oriented integration tests InstrumentationRunner">
+ </instrumentation-->
+
+ <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.audiopolicytest"
+ android:label="AudioManager policy oriented integration tests InstrumentationRunner">
+ </instrumentation>
+</manifest>
diff --git a/media/tests/AudioPolicyTest/AndroidTest.xml b/media/tests/AudioPolicyTest/AndroidTest.xml
new file mode 100644
index 000000000000..f3ca9a165d1b
--- /dev/null
+++ b/media/tests/AudioPolicyTest/AndroidTest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 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.
+-->
+<configuration description="Runs Media Framework Tests">
+ <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
+ <option name="test-file-name" value="audiopolicytest.apk" />
+ </target_preparer>
+
+ <option name="test-tag" value="AudioPolicyTest" />
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+ <option name="package" value="com.android.audiopolicytest" />
+ <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
+ <option name="hidden-api-checks" value="false"/>
+ </test>
+</configuration>
diff --git a/media/tests/AudioPolicyTest/res/layout/audiopolicytest.xml b/media/tests/AudioPolicyTest/res/layout/audiopolicytest.xml
new file mode 100644
index 000000000000..17fdba6f7c15
--- /dev/null
+++ b/media/tests/AudioPolicyTest/res/layout/audiopolicytest.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 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="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
+</LinearLayout>
diff --git a/media/tests/AudioPolicyTest/res/values/strings.xml b/media/tests/AudioPolicyTest/res/values/strings.xml
new file mode 100644
index 000000000000..036592770450
--- /dev/null
+++ b/media/tests/AudioPolicyTest/res/values/strings.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <!-- name of the app [CHAR LIMIT=25]-->
+ <string name="app_name">Audio Policy APIs Tests</string>
+</resources>
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioManagerTest.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioManagerTest.java
new file mode 100644
index 000000000000..1131c623e428
--- /dev/null
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioManagerTest.java
@@ -0,0 +1,328 @@
+/*
+ * Copyright (C) 2020 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.audiopolicytest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.testng.Assert.assertThrows;
+
+import android.media.AudioAttributes;
+import android.media.AudioManager;
+import android.media.AudioSystem;
+import android.media.audiopolicy.AudioProductStrategy;
+import android.media.audiopolicy.AudioVolumeGroup;
+import android.util.Log;
+
+import com.google.common.primitives.Ints;
+
+import java.util.List;
+
+public class AudioManagerTest extends AudioVolumesTestBase {
+ private static final String TAG = "AudioManagerTest";
+
+ //-----------------------------------------------------------------
+ // Test getAudioProductStrategies and validate strategies
+ //-----------------------------------------------------------------
+ public void testGetAndValidateProductStrategies() throws Exception {
+ List<AudioProductStrategy> audioProductStrategies =
+ mAudioManager.getAudioProductStrategies();
+ assertTrue(audioProductStrategies.size() > 0);
+
+ List<AudioVolumeGroup> audioVolumeGroups = mAudioManager.getAudioVolumeGroups();
+ assertTrue(audioVolumeGroups.size() > 0);
+
+ // Validate Audio Product Strategies
+ for (final AudioProductStrategy audioProductStrategy : audioProductStrategies) {
+ AudioAttributes attributes = audioProductStrategy.getAudioAttributes();
+ int strategyStreamType =
+ audioProductStrategy.getLegacyStreamTypeForAudioAttributes(attributes);
+
+ assertTrue("Strategy shall support the attributes retrieved from its getter API",
+ audioProductStrategy.supportsAudioAttributes(attributes));
+
+ int volumeGroupId =
+ audioProductStrategy.getVolumeGroupIdForAudioAttributes(attributes);
+
+ // A strategy must be associated to a volume group
+ assertNotEquals("strategy not assigned to any volume group",
+ volumeGroupId, AudioVolumeGroup.DEFAULT_VOLUME_GROUP);
+
+ // Valid Group ?
+ AudioVolumeGroup audioVolumeGroup = null;
+ for (final AudioVolumeGroup avg : audioVolumeGroups) {
+ if (avg.getId() == volumeGroupId) {
+ audioVolumeGroup = avg;
+ break;
+ }
+ }
+ assertNotNull("Volume Group not found", audioVolumeGroup);
+
+ // Cross check: the group shall have at least one aa / stream types following the
+ // considered strategy
+ boolean strategyAttributesSupported = false;
+ for (final AudioAttributes aa : audioVolumeGroup.getAudioAttributes()) {
+ if (audioProductStrategy.supportsAudioAttributes(aa)) {
+ strategyAttributesSupported = true;
+ break;
+ }
+ }
+ assertTrue("Volume Group and Strategy mismatching", strategyAttributesSupported);
+
+ // Some Product strategy may not have corresponding stream types as they intends
+ // to address volume setting per attributes to avoid adding new stream type
+ // and going on deprecating the stream type even for volume
+ if (strategyStreamType != AudioSystem.STREAM_DEFAULT) {
+ boolean strategStreamTypeSupported = false;
+ for (final int vgStreamType : audioVolumeGroup.getLegacyStreamTypes()) {
+ if (vgStreamType == strategyStreamType) {
+ strategStreamTypeSupported = true;
+ break;
+ }
+ }
+ assertTrue("Volume Group and Strategy mismatching", strategStreamTypeSupported);
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------
+ // Test getAudioVolumeGroups and validate volume groups
+ //-----------------------------------------------------------------
+
+ public void testGetAndValidateVolumeGroups() throws Exception {
+ List<AudioVolumeGroup> audioVolumeGroups = mAudioManager.getAudioVolumeGroups();
+ assertTrue(audioVolumeGroups.size() > 0);
+
+ List<AudioProductStrategy> audioProductStrategies =
+ mAudioManager.getAudioProductStrategies();
+ assertTrue(audioProductStrategies.size() > 0);
+
+ // Validate Audio Volume Groups, check all
+ for (final AudioVolumeGroup audioVolumeGroup : audioVolumeGroups) {
+ List<AudioAttributes> avgAttributes = audioVolumeGroup.getAudioAttributes();
+ int[] avgStreamTypes = audioVolumeGroup.getLegacyStreamTypes();
+
+ // for each volume group attributes, find the matching product strategy and ensure
+ // it is linked the considered volume group
+ for (final AudioAttributes aa : avgAttributes) {
+ if (aa.equals(sDefaultAttributes)) {
+ // Some volume groups may not have valid attributes, used for internal
+ // volume management like patch/rerouting
+ // so bailing out strategy retrieval from attributes
+ continue;
+ }
+ boolean isVolumeGroupAssociatedToStrategy = false;
+ for (final AudioProductStrategy strategy : audioProductStrategies) {
+ int groupId = strategy.getVolumeGroupIdForAudioAttributes(aa);
+ if (groupId != AudioVolumeGroup.DEFAULT_VOLUME_GROUP) {
+
+ assertEquals("Volume Group ID (" + audioVolumeGroup.toString()
+ + "), and Volume group ID associated to Strategy ("
+ + strategy.toString() + ") both supporting attributes "
+ + aa.toString() + " are mismatching",
+ audioVolumeGroup.getId(), groupId);
+ isVolumeGroupAssociatedToStrategy = true;
+ break;
+ }
+ }
+ assertTrue("Volume Group (" + audioVolumeGroup.toString()
+ + ") has no associated strategy for attributes " + aa.toString(),
+ isVolumeGroupAssociatedToStrategy);
+ }
+
+ // for each volume group stream type, find the matching product strategy and ensure
+ // it is linked the considered volume group
+ for (final int avgStreamType : avgStreamTypes) {
+ if (avgStreamType == AudioSystem.STREAM_DEFAULT) {
+ // Some Volume Groups may not have corresponding stream types as they
+ // intends to address volume setting per attributes to avoid adding new
+ // stream type and going on deprecating the stream type even for volume
+ // so bailing out strategy retrieval from stream type
+ continue;
+ }
+ boolean isVolumeGroupAssociatedToStrategy = false;
+ for (final AudioProductStrategy strategy : audioProductStrategies) {
+ Log.i(TAG, "strategy:" + strategy.toString());
+ int groupId = strategy.getVolumeGroupIdForLegacyStreamType(avgStreamType);
+ if (groupId != AudioVolumeGroup.DEFAULT_VOLUME_GROUP) {
+
+ assertEquals("Volume Group ID (" + audioVolumeGroup.toString()
+ + "), and Volume group ID associated to Strategy ("
+ + strategy.toString() + ") both supporting stream "
+ + AudioSystem.streamToString(avgStreamType) + "("
+ + avgStreamType + ") are mismatching",
+ audioVolumeGroup.getId(), groupId);
+ isVolumeGroupAssociatedToStrategy = true;
+ break;
+ }
+ }
+ assertTrue("Volume Group (" + audioVolumeGroup.toString()
+ + ") has no associated strategy for stream "
+ + AudioSystem.streamToString(avgStreamType) + "(" + avgStreamType + ")",
+ isVolumeGroupAssociatedToStrategy);
+ }
+ }
+ }
+
+ //-----------------------------------------------------------------
+ // Test Volume per Attributes setter/getters
+ //-----------------------------------------------------------------
+ public void testSetGetVolumePerAttributesWithInvalidAttributes() throws Exception {
+ AudioAttributes nullAttributes = null;
+
+ assertThrows(NullPointerException.class,
+ () -> mAudioManager.getMaxVolumeIndexForAttributes(nullAttributes));
+
+ assertThrows(NullPointerException.class,
+ () -> mAudioManager.getMinVolumeIndexForAttributes(nullAttributes));
+
+ assertThrows(NullPointerException.class,
+ () -> mAudioManager.getVolumeIndexForAttributes(nullAttributes));
+
+ assertThrows(NullPointerException.class,
+ () -> mAudioManager.setVolumeIndexForAttributes(
+ nullAttributes, 0 /*index*/, 0/*flags*/));
+ }
+
+ public void testSetGetVolumePerAttributes() throws Exception {
+ for (int usage : AudioAttributes.SDK_USAGES) {
+ if (usage == AudioAttributes.USAGE_UNKNOWN) {
+ continue;
+ }
+ AudioAttributes aaForUsage = new AudioAttributes.Builder().setUsage(usage).build();
+ int indexMin = 0;
+ int indexMax = 0;
+ int index = 0;
+ Exception ex = null;
+
+ try {
+ indexMax = mAudioManager.getMaxVolumeIndexForAttributes(aaForUsage);
+ } catch (Exception e) {
+ ex = e; // unexpected
+ }
+ assertNull("Exception was thrown for valid attributes", ex);
+ ex = null;
+ try {
+ indexMin = mAudioManager.getMinVolumeIndexForAttributes(aaForUsage);
+ } catch (Exception e) {
+ ex = e; // unexpected
+ }
+ assertNull("Exception was thrown for valid attributes", ex);
+ ex = null;
+ try {
+ index = mAudioManager.getVolumeIndexForAttributes(aaForUsage);
+ } catch (Exception e) {
+ ex = e; // unexpected
+ }
+ assertNull("Exception was thrown for valid attributes", ex);
+ ex = null;
+ try {
+ mAudioManager.setVolumeIndexForAttributes(aaForUsage, indexMin, 0/*flags*/);
+ } catch (Exception e) {
+ ex = e; // unexpected
+ }
+ assertNull("Exception was thrown for valid attributes", ex);
+
+ index = mAudioManager.getVolumeIndexForAttributes(aaForUsage);
+ assertEquals(index, indexMin);
+
+ mAudioManager.setVolumeIndexForAttributes(aaForUsage, indexMax, 0/*flags*/);
+ index = mAudioManager.getVolumeIndexForAttributes(aaForUsage);
+ assertEquals(index, indexMax);
+ }
+ }
+
+ //-----------------------------------------------------------------
+ // Test register/unregister VolumeGroupCallback
+ //-----------------------------------------------------------------
+ public void testVolumeGroupCallback() throws Exception {
+ List<AudioVolumeGroup> audioVolumeGroups = mAudioManager.getAudioVolumeGroups();
+ assertTrue(audioVolumeGroups.size() > 0);
+
+ AudioVolumeGroupCallbackHelper vgCbReceiver = new AudioVolumeGroupCallbackHelper();
+ mAudioManager.registerVolumeGroupCallback(mContext.getMainExecutor(), vgCbReceiver);
+
+ final List<Integer> publicStreams = Ints.asList(PUBLIC_STREAM_TYPES);
+ try {
+ // Validate Audio Volume Groups callback reception
+ for (final AudioVolumeGroup audioVolumeGroup : audioVolumeGroups) {
+ int volumeGroupId = audioVolumeGroup.getId();
+
+ // Set the receiver to filter only the current group callback
+ vgCbReceiver.setExpectedVolumeGroup(volumeGroupId);
+
+ List<AudioAttributes> avgAttributes = audioVolumeGroup.getAudioAttributes();
+ int[] avgStreamTypes = audioVolumeGroup.getLegacyStreamTypes();
+
+ int index = 0;
+ int indexMax = 0;
+ int indexMin = 0;
+
+ // Set the volume per attributes (if valid) and wait the callback
+ for (final AudioAttributes aa : avgAttributes) {
+ if (aa.equals(sDefaultAttributes)) {
+ // Some volume groups may not have valid attributes, used for internal
+ // volume management like patch/rerouting
+ // so bailing out strategy retrieval from attributes
+ continue;
+ }
+ index = mAudioManager.getVolumeIndexForAttributes(aa);
+ indexMax = mAudioManager.getMaxVolumeIndexForAttributes(aa);
+ indexMin = mAudioManager.getMinVolumeIndexForAttributes(aa);
+ index = incrementVolumeIndex(index, indexMin, indexMax);
+
+ vgCbReceiver.setExpectedVolumeGroup(volumeGroupId);
+ mAudioManager.setVolumeIndexForAttributes(aa, index, 0/*flags*/);
+ assertTrue(vgCbReceiver.waitForExpectedVolumeGroupChanged(
+ AudioVolumeGroupCallbackHelper.ASYNC_TIMEOUT_MS));
+
+ int readIndex = mAudioManager.getVolumeIndexForAttributes(aa);
+ assertEquals(readIndex, index);
+ }
+ // Set the volume per stream type (if valid) and wait the callback
+ for (final int avgStreamType : avgStreamTypes) {
+ if (avgStreamType == AudioSystem.STREAM_DEFAULT) {
+ // Some Volume Groups may not have corresponding stream types as they
+ // intends to address volume setting per attributes to avoid adding new
+ // stream type and going on deprecating the stream type even for volume
+ // so bailing out strategy retrieval from stream type
+ continue;
+ }
+ if (!publicStreams.contains(avgStreamType)
+ || avgStreamType == AudioManager.STREAM_ACCESSIBILITY) {
+ // Limit scope of test to public stream that do not require any
+ // permission (e.g. Changing ACCESSIBILITY is subject to permission).
+ continue;
+ }
+ index = mAudioManager.getStreamVolume(avgStreamType);
+ indexMax = mAudioManager.getStreamMaxVolume(avgStreamType);
+ indexMin = mAudioManager.getStreamMinVolumeInt(avgStreamType);
+ index = incrementVolumeIndex(index, indexMin, indexMax);
+
+ vgCbReceiver.setExpectedVolumeGroup(volumeGroupId);
+ mAudioManager.setStreamVolume(avgStreamType, index, 0/*flags*/);
+ assertTrue(vgCbReceiver.waitForExpectedVolumeGroupChanged(
+ AudioVolumeGroupCallbackHelper.ASYNC_TIMEOUT_MS));
+
+ int readIndex = mAudioManager.getStreamVolume(avgStreamType);
+ assertEquals(index, readIndex);
+ }
+ }
+ } finally {
+ mAudioManager.unregisterVolumeGroupCallback(vgCbReceiver);
+ }
+ }
+}
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyTest.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyTest.java
new file mode 100644
index 000000000000..e0c7b223a2e4
--- /dev/null
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioPolicyTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2020 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.audiopolicytest;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class AudioPolicyTest extends Activity {
+
+ public AudioPolicyTest() {
+ }
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ setContentView(R.layout.audiopolicytest);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+}
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioProductStrategyTest.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioProductStrategyTest.java
new file mode 100644
index 000000000000..c0f596b974e1
--- /dev/null
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioProductStrategyTest.java
@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2020 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.audiopolicytest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import android.media.AudioAttributes;
+import android.media.AudioSystem;
+import android.media.audiopolicy.AudioProductStrategy;
+import android.media.audiopolicy.AudioVolumeGroup;
+import android.util.Log;
+
+import java.util.List;
+
+public class AudioProductStrategyTest extends AudioVolumesTestBase {
+ private static final String TAG = "AudioProductStrategyTest";
+
+ //-----------------------------------------------------------------
+ // Test getAudioProductStrategies and validate strategies
+ //-----------------------------------------------------------------
+ public void testGetProductStrategies() throws Exception {
+ List<AudioProductStrategy> audioProductStrategies =
+ AudioProductStrategy.getAudioProductStrategies();
+
+ assertNotNull(audioProductStrategies);
+ assertTrue(audioProductStrategies.size() > 0);
+
+ for (final AudioProductStrategy aps : audioProductStrategies) {
+ assertTrue(aps.getId() >= 0);
+
+ AudioAttributes aa = aps.getAudioAttributes();
+ assertNotNull(aa);
+
+ // Ensure API consistency
+ assertTrue(aps.supportsAudioAttributes(aa));
+
+ int streamType = aps.getLegacyStreamTypeForAudioAttributes(aa);
+ if (streamType == AudioSystem.STREAM_DEFAULT) {
+ // bailing out test for volume group APIs consistency
+ continue;
+ }
+ final int volumeGroupFromStream = aps.getVolumeGroupIdForLegacyStreamType(streamType);
+ final int volumeGroupFromAttributes = aps.getVolumeGroupIdForAudioAttributes(aa);
+ assertNotEquals(volumeGroupFromStream, AudioVolumeGroup.DEFAULT_VOLUME_GROUP);
+ assertEquals(volumeGroupFromStream, volumeGroupFromAttributes);
+ }
+ }
+
+ //-----------------------------------------------------------------
+ // Test stream to/from attributes conversion
+ //-----------------------------------------------------------------
+ public void testAudioAttributesFromStreamTypes() throws Exception {
+ List<AudioProductStrategy> audioProductStrategies =
+ AudioProductStrategy.getAudioProductStrategies();
+
+ assertNotNull(audioProductStrategies);
+ assertTrue(audioProductStrategies.size() > 0);
+
+ for (final int streamType : PUBLIC_STREAM_TYPES) {
+ AudioAttributes aaFromStreamType =
+ AudioProductStrategy.getAudioAttributesForStrategyWithLegacyStreamType(
+ streamType);
+
+ // No strategy found for this stream type or no attributes defined for the strategy
+ // hosting this stream type; Bailing out the test, just ensure that any request
+ // for reciproque API with the unknown attributes would return default stream
+ // for volume control, aka STREAM_MUSIC.
+ if (aaFromStreamType.equals(sInvalidAttributes)) {
+ assertEquals(AudioSystem.STREAM_MUSIC,
+ AudioProductStrategy.getLegacyStreamTypeForStrategyWithAudioAttributes(
+ aaFromStreamType));
+ } else {
+ // Attributes are valid, i.e. a strategy was found supporting this stream type
+ // with valid attributes. Ensure reciproque works fine
+ int streamTypeFromAttributes =
+ AudioProductStrategy.getLegacyStreamTypeForStrategyWithAudioAttributes(
+ aaFromStreamType);
+ assertEquals("stream " + AudioSystem.streamToString(streamType) + "("
+ + streamType + ") expected to match attributes "
+ + aaFromStreamType.toString() + " got instead stream "
+ + AudioSystem.streamToString(streamTypeFromAttributes) + "("
+ + streamTypeFromAttributes + ") expected to match attributes ",
+ streamType, streamTypeFromAttributes);
+ }
+
+ // Now identify the strategy supporting this stream type, ensure uniqueness
+ boolean strategyFound = false;
+ for (final AudioProductStrategy aps : audioProductStrategies) {
+ AudioAttributes aaFromAps =
+ aps.getAudioAttributesForLegacyStreamType(streamType);
+
+ if (aaFromAps == null) {
+ // not this one...
+ continue;
+ }
+ // Got it!
+ assertFalse("Unique ProductStrategy shall match for a given stream type",
+ strategyFound);
+ strategyFound = true;
+
+ // Ensure getters aligned
+ assertEquals(aaFromStreamType, aaFromAps);
+ assertTrue(aps.supportsAudioAttributes(aaFromStreamType));
+
+ // Ensure reciproque works fine
+ assertEquals(streamType,
+ aps.getLegacyStreamTypeForAudioAttributes(aaFromStreamType));
+
+ // Ensure consistency of volume group getter API
+ final int volumeGroupFromStream =
+ aps.getVolumeGroupIdForLegacyStreamType(streamType);
+ final int volumeGroupFromAttributes =
+ aps.getVolumeGroupIdForAudioAttributes(aaFromStreamType);
+ assertNotEquals(volumeGroupFromStream, AudioVolumeGroup.DEFAULT_VOLUME_GROUP);
+ assertEquals(volumeGroupFromStream, volumeGroupFromAttributes);
+ }
+ if (!strategyFound) {
+ // No strategy found, ensure volume control is MUSIC
+ assertEquals(AudioSystem.STREAM_MUSIC,
+ AudioProductStrategy.getLegacyStreamTypeForStrategyWithAudioAttributes(
+ aaFromStreamType));
+ }
+ }
+ }
+
+ public void testAudioAttributesToStreamTypes() throws Exception {
+ List<AudioProductStrategy> audioProductStrategies =
+ AudioProductStrategy.getAudioProductStrategies();
+
+ assertNotNull(audioProductStrategies);
+ assertTrue(audioProductStrategies.size() > 0);
+
+ for (int usage : AudioAttributes.SDK_USAGES) {
+ AudioAttributes aaForUsage = new AudioAttributes.Builder().setUsage(usage).build();
+
+ int streamTypeFromUsage =
+ AudioProductStrategy.getLegacyStreamTypeForStrategyWithAudioAttributes(
+ aaForUsage);
+
+ // Cannot be undefined, always shall fall back on a valid stream type
+ // to be able to control the volume
+ assertNotEquals(streamTypeFromUsage, AudioSystem.STREAM_DEFAULT);
+
+ Log.w(TAG, "GUSTAVE aaForUsage=" + aaForUsage.toString());
+
+ // Now identify the strategy hosting these Audio Attributes and ensure informations
+ // matches.
+ // Now identify the strategy supporting this stream type, ensure uniqueness
+ boolean strategyFound = false;
+ for (final AudioProductStrategy aps : audioProductStrategies) {
+ if (!aps.supportsAudioAttributes(aaForUsage)) {
+ // Not this one
+ continue;
+ }
+ // Got it!
+ String msg = "Unique ProductStrategy shall match for a given audio attributes "
+ + aaForUsage.toString() + " already associated also matches with"
+ + aps.toString();
+ assertFalse(msg, strategyFound);
+ strategyFound = true;
+
+ // It may not return the expected stream type if the strategy does not have
+ // associated stream type.
+ // Behavior of member function getLegacyStreamTypeForAudioAttributes is
+ // different than getLegacyStreamTypeForStrategyWithAudioAttributes since it
+ // does not fallback on MUSIC stream type for volume operation
+ int streamTypeFromAps = aps.getLegacyStreamTypeForAudioAttributes(aaForUsage);
+ if (streamTypeFromAps == AudioSystem.STREAM_DEFAULT) {
+ // No stream type assigned to this strategy
+ // Expect static API to return default stream type for volume (aka MUSIC)
+ assertEquals("Strategy (" + aps.toString() + ") has no associated stream "
+ + ", must fallback on MUSIC stream as default",
+ streamTypeFromUsage, AudioSystem.STREAM_MUSIC);
+ } else {
+ assertEquals("Attributes " + aaForUsage.toString() + " associated to stream "
+ + AudioSystem.streamToString(streamTypeFromUsage)
+ + " are supported by strategy (" + aps.toString() + ") which reports "
+ + " these attributes are associated to stream "
+ + AudioSystem.streamToString(streamTypeFromAps),
+ streamTypeFromUsage, streamTypeFromAps);
+
+ // Ensure consistency of volume group getter API
+ int volumeGroupFromStream =
+ aps.getVolumeGroupIdForLegacyStreamType(streamTypeFromAps);
+ int volumeGroupFromAttributes =
+ aps.getVolumeGroupIdForAudioAttributes(aaForUsage);
+ assertNotEquals(
+ volumeGroupFromStream, AudioVolumeGroup.DEFAULT_VOLUME_GROUP);
+ assertEquals(volumeGroupFromStream, volumeGroupFromAttributes);
+ }
+ }
+ if (!strategyFound) {
+ // No strategy found for the given attributes, the expected stream must be MUSIC
+ assertEquals(streamTypeFromUsage, AudioSystem.STREAM_MUSIC);
+ }
+ }
+ }
+}
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupCallbackHelper.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupCallbackHelper.java
new file mode 100644
index 000000000000..0c1d52c57020
--- /dev/null
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupCallbackHelper.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2020 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.audiopolicytest;
+
+import static org.junit.Assert.assertNotNull;
+
+import android.media.AudioManager;
+import android.util.Log;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+
+final class AudioVolumeGroupCallbackHelper extends AudioManager.VolumeGroupCallback {
+ private static final String TAG = "AudioVolumeGroupCallbackHelper";
+ public static final long ASYNC_TIMEOUT_MS = 800;
+
+ private int mExpectedVolumeGroupId;
+
+ private CountDownLatch mVolumeGroupChanged = null;
+
+ void setExpectedVolumeGroup(int group) {
+ mVolumeGroupChanged = new CountDownLatch(1);
+ mExpectedVolumeGroupId = group;
+ }
+
+ @Override
+ public void onAudioVolumeGroupChanged(int group, int flags) {
+ if (group != mExpectedVolumeGroupId) {
+ return;
+ }
+ if (mVolumeGroupChanged == null) {
+ Log.wtf(TAG, "Received callback but object not initialized");
+ return;
+ }
+ if (mVolumeGroupChanged.getCount() <= 0) {
+ Log.i(TAG, "callback for group: " + group + " already received");
+ return;
+ }
+ mVolumeGroupChanged.countDown();
+ }
+
+ public boolean waitForExpectedVolumeGroupChanged(long timeOutMs) {
+ assertNotNull("Call first setExpectedVolumeGroup before waiting...", mVolumeGroupChanged);
+ boolean timeoutReached = false;
+ if (mVolumeGroupChanged.getCount() == 0) {
+ // done already...
+ return true;
+ }
+ try {
+ timeoutReached = !mVolumeGroupChanged.await(ASYNC_TIMEOUT_MS, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) { }
+ return !timeoutReached;
+ }
+}
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupChangeHandlerTest.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupChangeHandlerTest.java
new file mode 100644
index 000000000000..221f1f7fef17
--- /dev/null
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupChangeHandlerTest.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2020 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.audiopolicytest;
+
+import static org.junit.Assert.assertEquals;
+import static org.testng.Assert.assertThrows;
+
+import android.media.AudioAttributes;
+import android.media.AudioManager;
+import android.media.audiopolicy.AudioVolumeGroup;
+import android.media.audiopolicy.AudioVolumeGroupChangeHandler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AudioVolumeGroupChangeHandlerTest extends AudioVolumesTestBase {
+ private static final String TAG = "AudioVolumeGroupChangeHandlerTest";
+
+ public void testRegisterInvalidCallback() throws Exception {
+ final AudioVolumeGroupChangeHandler audioAudioVolumeGroupChangedHandler =
+ new AudioVolumeGroupChangeHandler();
+
+ audioAudioVolumeGroupChangedHandler.init();
+
+ assertThrows(NullPointerException.class, () -> {
+ AudioManager.VolumeGroupCallback nullCb = null;
+ audioAudioVolumeGroupChangedHandler.registerListener(nullCb);
+ });
+ }
+
+ public void testUnregisterInvalidCallback() throws Exception {
+ final AudioVolumeGroupChangeHandler audioAudioVolumeGroupChangedHandler =
+ new AudioVolumeGroupChangeHandler();
+
+ audioAudioVolumeGroupChangedHandler.init();
+
+ final AudioVolumeGroupCallbackHelper cb = new AudioVolumeGroupCallbackHelper();
+ audioAudioVolumeGroupChangedHandler.registerListener(cb);
+
+ assertThrows(NullPointerException.class, () -> {
+ AudioManager.VolumeGroupCallback nullCb = null;
+ audioAudioVolumeGroupChangedHandler.unregisterListener(nullCb);
+ });
+ audioAudioVolumeGroupChangedHandler.unregisterListener(cb);
+ }
+
+ public void testRegisterUnregisterCallback() throws Exception {
+ final AudioVolumeGroupChangeHandler audioAudioVolumeGroupChangedHandler =
+ new AudioVolumeGroupChangeHandler();
+
+ audioAudioVolumeGroupChangedHandler.init();
+ final AudioVolumeGroupCallbackHelper validCb = new AudioVolumeGroupCallbackHelper();
+
+ // Should not assert, otherwise test will fail
+ audioAudioVolumeGroupChangedHandler.registerListener(validCb);
+
+ // Should not assert, otherwise test will fail
+ audioAudioVolumeGroupChangedHandler.unregisterListener(validCb);
+ }
+
+ public void testCallbackReceived() throws Exception {
+ final AudioVolumeGroupChangeHandler audioAudioVolumeGroupChangedHandler =
+ new AudioVolumeGroupChangeHandler();
+
+ audioAudioVolumeGroupChangedHandler.init();
+
+ final AudioVolumeGroupCallbackHelper validCb = new AudioVolumeGroupCallbackHelper();
+ audioAudioVolumeGroupChangedHandler.registerListener(validCb);
+
+ List<AudioVolumeGroup> audioVolumeGroups = mAudioManager.getAudioVolumeGroups();
+ assertTrue(audioVolumeGroups.size() > 0);
+
+ try {
+ for (final AudioVolumeGroup audioVolumeGroup : audioVolumeGroups) {
+ int volumeGroupId = audioVolumeGroup.getId();
+
+ List<AudioAttributes> avgAttributes = audioVolumeGroup.getAudioAttributes();
+ // Set the volume per attributes (if valid) and wait the callback
+ if (avgAttributes.size() == 0 || avgAttributes.get(0).equals(sDefaultAttributes)) {
+ // Some volume groups may not have valid attributes, used for internal
+ // volume management like patch/rerouting
+ // so bailing out strategy retrieval from attributes
+ continue;
+ }
+ final AudioAttributes aa = avgAttributes.get(0);
+
+ int index = mAudioManager.getVolumeIndexForAttributes(aa);
+ int indexMax = mAudioManager.getMaxVolumeIndexForAttributes(aa);
+ int indexMin = mAudioManager.getMinVolumeIndexForAttributes(aa);
+
+ final int indexForAa = incrementVolumeIndex(index, indexMin, indexMax);
+
+ // Set the receiver to filter only the current group callback
+ validCb.setExpectedVolumeGroup(volumeGroupId);
+ mAudioManager.setVolumeIndexForAttributes(aa, indexForAa, 0/*flags*/);
+ assertTrue(validCb.waitForExpectedVolumeGroupChanged(
+ AudioVolumeGroupCallbackHelper.ASYNC_TIMEOUT_MS));
+
+ final int readIndex = mAudioManager.getVolumeIndexForAttributes(aa);
+ assertEquals(readIndex, indexForAa);
+ }
+ } finally {
+ audioAudioVolumeGroupChangedHandler.unregisterListener(validCb);
+ }
+ }
+
+ public void testMultipleCallbackReceived() throws Exception {
+
+ final AudioVolumeGroupChangeHandler audioAudioVolumeGroupChangedHandler =
+ new AudioVolumeGroupChangeHandler();
+
+ audioAudioVolumeGroupChangedHandler.init();
+
+ final int callbackCount = 10;
+ final List<AudioVolumeGroupCallbackHelper> validCbs =
+ new ArrayList<AudioVolumeGroupCallbackHelper>();
+ for (int i = 0; i < callbackCount; i++) {
+ validCbs.add(new AudioVolumeGroupCallbackHelper());
+ }
+ for (final AudioVolumeGroupCallbackHelper cb : validCbs) {
+ audioAudioVolumeGroupChangedHandler.registerListener(cb);
+ }
+
+ List<AudioVolumeGroup> audioVolumeGroups = mAudioManager.getAudioVolumeGroups();
+ assertTrue(audioVolumeGroups.size() > 0);
+
+ try {
+ for (final AudioVolumeGroup audioVolumeGroup : audioVolumeGroups) {
+ int volumeGroupId = audioVolumeGroup.getId();
+
+ List<AudioAttributes> avgAttributes = audioVolumeGroup.getAudioAttributes();
+ // Set the volume per attributes (if valid) and wait the callback
+ if (avgAttributes.size() == 0 || avgAttributes.get(0).equals(sDefaultAttributes)) {
+ // Some volume groups may not have valid attributes, used for internal
+ // volume management like patch/rerouting
+ // so bailing out strategy retrieval from attributes
+ continue;
+ }
+ AudioAttributes aa = avgAttributes.get(0);
+
+ int index = mAudioManager.getVolumeIndexForAttributes(aa);
+ int indexMax = mAudioManager.getMaxVolumeIndexForAttributes(aa);
+ int indexMin = mAudioManager.getMinVolumeIndexForAttributes(aa);
+
+ final int indexForAa = incrementVolumeIndex(index, indexMin, indexMax);
+
+ // Set the receiver to filter only the current group callback
+ for (final AudioVolumeGroupCallbackHelper cb : validCbs) {
+ cb.setExpectedVolumeGroup(volumeGroupId);
+ }
+ mAudioManager.setVolumeIndexForAttributes(aa, indexForAa, 0/*flags*/);
+
+ for (final AudioVolumeGroupCallbackHelper cb : validCbs) {
+ assertTrue(cb.waitForExpectedVolumeGroupChanged(
+ AudioVolumeGroupCallbackHelper.ASYNC_TIMEOUT_MS));
+ }
+ int readIndex = mAudioManager.getVolumeIndexForAttributes(aa);
+ assertEquals(readIndex, indexForAa);
+ }
+ } finally {
+ for (final AudioVolumeGroupCallbackHelper cb : validCbs) {
+ audioAudioVolumeGroupChangedHandler.unregisterListener(cb);
+ }
+ }
+ }
+}
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupTest.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupTest.java
new file mode 100644
index 000000000000..84b24b8fcab3
--- /dev/null
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumeGroupTest.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2020 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.audiopolicytest;
+
+import static org.junit.Assert.assertNotEquals;
+
+import android.media.AudioAttributes;
+import android.media.AudioSystem;
+import android.media.audiopolicy.AudioProductStrategy;
+import android.media.audiopolicy.AudioVolumeGroup;
+
+import java.util.List;
+
+public class AudioVolumeGroupTest extends AudioVolumesTestBase {
+ private static final String TAG = "AudioVolumeGroupTest";
+
+ //-----------------------------------------------------------------
+ // Test getAudioVolumeGroups and validate groud id
+ //-----------------------------------------------------------------
+ public void testGetVolumeGroupsFromNonServiceCaller() throws Exception {
+ // The transaction behind getAudioVolumeGroups will fail. Check is done at binder level
+ // with policy service. Error is not reported, the list is just empty.
+ // Request must come from service components
+ List<AudioVolumeGroup> audioVolumeGroup = AudioVolumeGroup.getAudioVolumeGroups();
+
+ assertNotNull(audioVolumeGroup);
+ assertEquals(audioVolumeGroup.size(), 0);
+ }
+
+ //-----------------------------------------------------------------
+ // Test getAudioVolumeGroups and validate groud id
+ //-----------------------------------------------------------------
+ public void testGetVolumeGroups() throws Exception {
+ // Through AudioManager, the transaction behind getAudioVolumeGroups will succeed
+ final List<AudioVolumeGroup> audioVolumeGroup = mAudioManager.getAudioVolumeGroups();
+ assertNotNull(audioVolumeGroup);
+ assertTrue(audioVolumeGroup.size() > 0);
+
+ final List<AudioProductStrategy> audioProductStrategies =
+ mAudioManager.getAudioProductStrategies();
+ assertTrue(audioProductStrategies.size() > 0);
+
+ for (final AudioVolumeGroup avg : audioVolumeGroup) {
+ int avgId = avg.getId();
+ assertNotEquals(avgId, AudioVolumeGroup.DEFAULT_VOLUME_GROUP);
+
+ List<AudioAttributes> avgAttributes = avg.getAudioAttributes();
+ assertNotNull(avgAttributes);
+
+ final int[] avgStreamTypes = avg.getLegacyStreamTypes();
+ assertNotNull(avgStreamTypes);
+
+ // for each volume group attributes, find the matching product strategy and ensure
+ // it is linked the considered volume group
+ for (final AudioAttributes aa : avgAttributes) {
+ if (aa.equals(sDefaultAttributes)) {
+ // Some volume groups may not have valid attributes, used for internal
+ // volume management like patch/rerouting
+ // so bailing out strategy retrieval from attributes
+ continue;
+ }
+ boolean isVolumeGroupAssociatedToStrategy = false;
+ for (final AudioProductStrategy aps : audioProductStrategies) {
+ int groupId = aps.getVolumeGroupIdForAudioAttributes(aa);
+ if (groupId != AudioVolumeGroup.DEFAULT_VOLUME_GROUP) {
+ // Note that Audio Product Strategies are priority ordered, and the
+ // the first one matching the AudioAttributes will be used to identify
+ // the volume group associated to the request.
+ assertTrue(aps.supportsAudioAttributes(aa));
+ assertEquals("Volume Group ID (" + avg.toString()
+ + "), and Volume group ID associated to Strategy ("
+ + aps.toString() + ") both supporting attributes "
+ + aa.toString() + " are mismatching",
+ avgId, groupId);
+ isVolumeGroupAssociatedToStrategy = true;
+ break;
+ }
+ }
+ assertTrue("Volume Group (" + avg.toString()
+ + ") has no associated strategy for attributes " + aa.toString(),
+ isVolumeGroupAssociatedToStrategy);
+ }
+
+ // for each volume group stream type, find the matching product strategy and ensure
+ // it is linked the considered volume group
+ for (final int avgStreamType : avgStreamTypes) {
+ if (avgStreamType == AudioSystem.STREAM_DEFAULT) {
+ // Some Volume Groups may not have corresponding stream types as they
+ // intends to address volume setting per attributes to avoid adding new
+ // stream type and going on deprecating the stream type even for volume
+ // so bailing out strategy retrieval from stream type
+ continue;
+ }
+ boolean isVolumeGroupAssociatedToStrategy = false;
+ for (final AudioProductStrategy aps : audioProductStrategies) {
+ int groupId = aps.getVolumeGroupIdForLegacyStreamType(avgStreamType);
+ if (groupId != AudioVolumeGroup.DEFAULT_VOLUME_GROUP) {
+
+ assertEquals("Volume Group ID (" + avg.toString()
+ + "), and Volume group ID associated to Strategy ("
+ + aps.toString() + ") both supporting stream "
+ + AudioSystem.streamToString(avgStreamType) + "("
+ + avgStreamType + ") are mismatching",
+ avgId, groupId);
+
+ isVolumeGroupAssociatedToStrategy = true;
+ break;
+ }
+ }
+ assertTrue("Volume Group (" + avg.toString()
+ + ") has no associated strategy for stream "
+ + AudioSystem.streamToString(avgStreamType) + "(" + avgStreamType + ")",
+ isVolumeGroupAssociatedToStrategy);
+ }
+ }
+ }
+}
diff --git a/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumesTestBase.java b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumesTestBase.java
new file mode 100644
index 000000000000..a17d65cf7376
--- /dev/null
+++ b/media/tests/AudioPolicyTest/src/com/android/audiopolicytest/AudioVolumesTestBase.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2020 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.audiopolicytest;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.media.AudioAttributes;
+import android.media.AudioManager;
+import android.media.audiopolicy.AudioProductStrategy;
+import android.media.audiopolicy.AudioVolumeGroup;
+import android.test.ActivityInstrumentationTestCase2;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class AudioVolumesTestBase extends ActivityInstrumentationTestCase2<AudioPolicyTest> {
+ public AudioManager mAudioManager;
+ Context mContext;
+ private Map<Integer, Integer> mOriginalStreamVolumes = new HashMap<>();
+ private Map<Integer, Integer> mOriginalVolumeGroupVolumes = new HashMap<>();
+
+ // Default matches the invalid (empty) attributes from native.
+ // The difference is the input source default which is not aligned between native and java
+ public static final AudioAttributes sDefaultAttributes =
+ AudioProductStrategy.sDefaultAttributes;
+
+ public static final AudioAttributes sInvalidAttributes = new AudioAttributes.Builder().build();
+
+ public final int[] PUBLIC_STREAM_TYPES = { AudioManager.STREAM_VOICE_CALL,
+ AudioManager.STREAM_SYSTEM, AudioManager.STREAM_RING, AudioManager.STREAM_MUSIC,
+ AudioManager.STREAM_ALARM, AudioManager.STREAM_NOTIFICATION,
+ AudioManager.STREAM_DTMF, AudioManager.STREAM_ACCESSIBILITY };
+
+ public AudioVolumesTestBase() {
+ super("com.android.audiopolicytest", AudioPolicyTest.class);
+ }
+
+ /**
+ * <p>Note: must be called with shell permission (MODIFY_AUDIO_ROUTING)
+ */
+ private void storeAllVolumes() {
+ List<AudioVolumeGroup> audioVolumeGroups = mAudioManager.getAudioVolumeGroups();
+ for (final AudioVolumeGroup avg : audioVolumeGroups) {
+ if (avg.getAudioAttributes().isEmpty()) {
+ // some volume group may not supports volume control per attributes
+ // like rerouting/patch since these groups are internal to audio policy manager
+ continue;
+ }
+ AudioAttributes avgAttributes = sDefaultAttributes;
+ for (final AudioAttributes aa : avg.getAudioAttributes()) {
+ if (!aa.equals(AudioProductStrategy.sDefaultAttributes)) {
+ avgAttributes = aa;
+ break;
+ }
+ }
+ if (avgAttributes.equals(sDefaultAttributes)) {
+ // This shall not happen, however, not purpose of this base class.
+ // so bailing out.
+ continue;
+ }
+ mOriginalVolumeGroupVolumes.put(
+ avg.getId(), mAudioManager.getVolumeIndexForAttributes(avgAttributes));
+ }
+ }
+
+ /**
+ * <p>Note: must be called with shell permission (MODIFY_AUDIO_ROUTING)
+ */
+ private void restoreAllVolumes() {
+ List<AudioVolumeGroup> audioVolumeGroups = mAudioManager.getAudioVolumeGroups();
+ for (Map.Entry<Integer, Integer> e : mOriginalVolumeGroupVolumes.entrySet()) {
+ for (final AudioVolumeGroup avg : audioVolumeGroups) {
+ if (avg.getId() == e.getKey()) {
+ assertTrue(!avg.getAudioAttributes().isEmpty());
+ AudioAttributes avgAttributes = sDefaultAttributes;
+ for (final AudioAttributes aa : avg.getAudioAttributes()) {
+ if (!aa.equals(AudioProductStrategy.sDefaultAttributes)) {
+ avgAttributes = aa;
+ break;
+ }
+ }
+ assertTrue(!avgAttributes.equals(sDefaultAttributes));
+ mAudioManager.setVolumeIndexForAttributes(
+ avgAttributes, e.getValue(), AudioManager.FLAG_ALLOW_RINGER_MODES);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mContext = getActivity();
+ mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
+
+ assertEquals(PackageManager.PERMISSION_GRANTED,
+ mContext.checkSelfPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING));
+
+ // Store the original volumes that that they can be recovered in tearDown().
+ mOriginalStreamVolumes.clear();
+ for (int streamType : PUBLIC_STREAM_TYPES) {
+ mOriginalStreamVolumes.put(streamType, mAudioManager.getStreamVolume(streamType));
+ }
+ // Store the original volume per attributes so that they can be recovered in tearDown()
+ mOriginalVolumeGroupVolumes.clear();
+ storeAllVolumes();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ // Recover the volume and the ringer mode that the test may have overwritten.
+ for (Map.Entry<Integer, Integer> e : mOriginalStreamVolumes.entrySet()) {
+ mAudioManager.setStreamVolume(e.getKey(), e.getValue(),
+ AudioManager.FLAG_ALLOW_RINGER_MODES);
+ }
+
+ // Recover the original volume per attributes
+ restoreAllVolumes();
+ }
+
+ public static int resetVolumeIndex(int indexMin, int indexMax) {
+ return (indexMax + indexMin) / 2;
+ }
+
+ public static int incrementVolumeIndex(int index, int indexMin, int indexMax) {
+ return (index + 1 > indexMax) ? resetVolumeIndex(indexMin, indexMax) : ++index;
+ }
+}
diff --git a/packages/CarSystemUI/src/com/android/systemui/car/keyguard/CarKeyguardViewController.java b/packages/CarSystemUI/src/com/android/systemui/car/keyguard/CarKeyguardViewController.java
index 1814fd0403d0..a4bb916b16ea 100644
--- a/packages/CarSystemUI/src/com/android/systemui/car/keyguard/CarKeyguardViewController.java
+++ b/packages/CarSystemUI/src/com/android/systemui/car/keyguard/CarKeyguardViewController.java
@@ -26,6 +26,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewRootImpl;
+import androidx.annotation.VisibleForTesting;
+
import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardViewController;
@@ -332,6 +334,11 @@ public class CarKeyguardViewController extends OverlayViewController implements
getLayout().setVisibility(View.INVISIBLE);
}
+ @VisibleForTesting
+ void setKeyguardBouncer(KeyguardBouncer keyguardBouncer) {
+ mBouncer = keyguardBouncer;
+ }
+
private void revealKeyguardIfBouncerPrepared() {
int reattemptDelayMillis = 50;
Runnable revealKeyguard = () -> {
diff --git a/packages/CarSystemUI/tests/src/com/android/systemui/car/keyguard/CarKeyguardViewControllerTest.java b/packages/CarSystemUI/tests/src/com/android/systemui/car/keyguard/CarKeyguardViewControllerTest.java
new file mode 100644
index 000000000000..d4cf6ccf4b9e
--- /dev/null
+++ b/packages/CarSystemUI/tests/src/com/android/systemui/car/keyguard/CarKeyguardViewControllerTest.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2020 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.systemui.car.keyguard;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.Handler;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.keyguard.KeyguardUpdateMonitor;
+import com.android.keyguard.ViewMediatorCallback;
+import com.android.systemui.R;
+import com.android.systemui.SysuiTestCase;
+import com.android.systemui.car.CarServiceProvider;
+import com.android.systemui.keyguard.DismissCallbackRegistry;
+import com.android.systemui.navigationbar.car.CarNavigationBarController;
+import com.android.systemui.plugins.FalsingManager;
+import com.android.systemui.statusbar.phone.BiometricUnlockController;
+import com.android.systemui.statusbar.phone.KeyguardBouncer;
+import com.android.systemui.statusbar.phone.KeyguardBypassController;
+import com.android.systemui.statusbar.policy.KeyguardStateController;
+import com.android.systemui.window.OverlayViewGlobalStateController;
+import com.android.systemui.window.SystemUIOverlayWindowController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class CarKeyguardViewControllerTest extends SysuiTestCase {
+
+ private TestableCarKeyguardViewController mCarKeyguardViewController;
+ private OverlayViewGlobalStateController mOverlayViewGlobalStateController;
+ private ViewGroup mBaseLayout;
+
+ @Mock
+ private KeyguardBouncer mBouncer;
+ @Mock
+ private CarNavigationBarController mCarNavigationBarController;
+ @Mock
+ private SystemUIOverlayWindowController mSystemUIOverlayWindowController;
+ @Mock
+ private CarKeyguardViewController.OnKeyguardCancelClickedListener mCancelClickedListener;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mOverlayViewGlobalStateController = new OverlayViewGlobalStateController(
+ mCarNavigationBarController, mSystemUIOverlayWindowController);
+ mBaseLayout = (ViewGroup) LayoutInflater.from(mContext).inflate(
+ R.layout.sysui_overlay_window, /* root= */ null);
+ when(mSystemUIOverlayWindowController.getBaseLayout()).thenReturn(mBaseLayout);
+
+ mCarKeyguardViewController = new TestableCarKeyguardViewController(
+ mContext,
+ Handler.getMain(),
+ mock(CarServiceProvider.class),
+ mOverlayViewGlobalStateController,
+ mock(KeyguardStateController.class),
+ mock(KeyguardUpdateMonitor.class),
+ mock(BiometricUnlockController.class),
+ mock(ViewMediatorCallback.class),
+ mock(CarNavigationBarController.class),
+ mock(LockPatternUtils.class),
+ mock(DismissCallbackRegistry.class),
+ mock(FalsingManager.class),
+ mock(KeyguardBypassController.class)
+ );
+ }
+
+ @Test
+ public void onShow_bouncerIsSecure_showsBouncerWithSecuritySelectionReset() {
+ when(mBouncer.isSecure()).thenReturn(true);
+ mCarKeyguardViewController.show(/* options= */ null);
+
+ verify(mBouncer).show(/* resetSecuritySelection= */ true);
+ }
+
+ @Test
+ public void onShow_bouncerIsSecure_keyguardIsVisible() {
+ when(mBouncer.isSecure()).thenReturn(true);
+ mCarKeyguardViewController.show(/* options= */ null);
+
+ assertThat(mBaseLayout.findViewById(R.id.keyguard_container).getVisibility()).isEqualTo(
+ View.VISIBLE);
+ }
+
+ @Test
+ public void onShow_bouncerNotSecure_hidesBouncerAndDestroysTheView() {
+ when(mBouncer.isSecure()).thenReturn(false);
+ mCarKeyguardViewController.show(/* options= */ null);
+
+ verify(mBouncer).hide(/* destroyView= */ true);
+ }
+
+ @Test
+ public void onShow_bouncerNotSecure_keyguardIsNotVisible() {
+ when(mBouncer.isSecure()).thenReturn(false);
+ mCarKeyguardViewController.show(/* options= */ null);
+
+ assertThat(mBaseLayout.findViewById(R.id.keyguard_container).getVisibility()).isEqualTo(
+ View.GONE);
+ }
+
+ @Test
+ public void onHide_keyguardShowing_hidesBouncerAndDestroysTheView() {
+ when(mBouncer.isSecure()).thenReturn(true);
+ mCarKeyguardViewController.show(/* options= */ null);
+ mCarKeyguardViewController.hide(/* startTime= */ 0, /* fadeoutDelay= */ 0);
+
+ verify(mBouncer).hide(/* destroyView= */ true);
+ }
+
+ @Test
+ public void onHide_keyguardNotShown_doesNotHideOrDestroyBouncer() {
+ mCarKeyguardViewController.hide(/* startTime= */ 0, /* fadeoutDelay= */ 0);
+
+ verify(mBouncer, never()).hide(anyBoolean());
+ }
+
+ @Test
+ public void onHide_KeyguardNotVisible() {
+ when(mBouncer.isSecure()).thenReturn(true);
+ mCarKeyguardViewController.show(/* options= */ null);
+ mCarKeyguardViewController.hide(/* startTime= */ 0, /* fadeoutDelay= */ 0);
+
+ assertThat(mBaseLayout.findViewById(R.id.keyguard_container).getVisibility()).isEqualTo(
+ View.GONE);
+ }
+
+ @Test
+ public void onCancelClicked_callsCancelClickedListener() {
+ when(mBouncer.isSecure()).thenReturn(true);
+ mCarKeyguardViewController.show(/* options= */ null);
+ mCarKeyguardViewController.registerOnKeyguardCancelClickedListener(mCancelClickedListener);
+ mCarKeyguardViewController.onCancelClicked();
+
+ verify(mCancelClickedListener).onCancelClicked();
+ }
+
+ @Test
+ public void onCancelClicked_hidesBouncerAndDestroysTheView() {
+ when(mBouncer.isSecure()).thenReturn(true);
+ mCarKeyguardViewController.show(/* options= */ null);
+ mCarKeyguardViewController.registerOnKeyguardCancelClickedListener(mCancelClickedListener);
+ mCarKeyguardViewController.onCancelClicked();
+
+ verify(mBouncer).hide(/* destroyView= */ true);
+ }
+
+ private class TestableCarKeyguardViewController extends CarKeyguardViewController {
+
+ TestableCarKeyguardViewController(Context context,
+ Handler mainHandler,
+ CarServiceProvider carServiceProvider,
+ OverlayViewGlobalStateController overlayViewGlobalStateController,
+ KeyguardStateController keyguardStateController,
+ KeyguardUpdateMonitor keyguardUpdateMonitor,
+ BiometricUnlockController biometricUnlockController,
+ ViewMediatorCallback viewMediatorCallback,
+ CarNavigationBarController carNavigationBarController,
+ LockPatternUtils lockPatternUtils,
+ DismissCallbackRegistry dismissCallbackRegistry,
+ FalsingManager falsingManager,
+ KeyguardBypassController keyguardBypassController) {
+ super(context, mainHandler, carServiceProvider, overlayViewGlobalStateController,
+ keyguardStateController, keyguardUpdateMonitor, biometricUnlockController,
+ viewMediatorCallback, carNavigationBarController, lockPatternUtils,
+ dismissCallbackRegistry, falsingManager, keyguardBypassController);
+ }
+
+ @Override
+ public void onFinishInflate() {
+ super.onFinishInflate();
+ setKeyguardBouncer(CarKeyguardViewControllerTest.this.mBouncer);
+ }
+ }
+
+}
diff --git a/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java b/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java
index fa2ec55bd81a..a77e34b4af1e 100644
--- a/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java
+++ b/packages/SettingsLib/RestrictedLockUtils/src/com/android/settingslib/RestrictedLockUtils.java
@@ -147,6 +147,28 @@ public class RestrictedLockUtils {
public EnforcedAdmin() {
}
+ /**
+ * Combines two {@link EnforcedAdmin} into one: if one of them is null, then just return
+ * the other. If both of them are the same, then return that. Otherwise return the symbolic
+ * {@link #MULTIPLE_ENFORCED_ADMIN}
+ */
+ public static EnforcedAdmin combine(EnforcedAdmin admin1, EnforcedAdmin admin2) {
+ if (admin1 == null) {
+ return admin2;
+ }
+ if (admin2 == null) {
+ return admin1;
+ }
+ if (admin1.equals(admin2)) {
+ return admin1;
+ }
+ if (!admin1.enforcedRestriction.equals(admin2.enforcedRestriction)) {
+ throw new IllegalArgumentException(
+ "Admins with different restriction cannot be combined");
+ }
+ return MULTIPLE_ENFORCED_ADMIN;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
diff --git a/packages/SystemUI/res/anim/control_state_list_animator.xml b/packages/SystemUI/res/anim/control_state_list_animator.xml
index 7940b8874ece..a20a9255f86f 100644
--- a/packages/SystemUI/res/anim/control_state_list_animator.xml
+++ b/packages/SystemUI/res/anim/control_state_list_animator.xml
@@ -18,11 +18,13 @@
<item android:state_pressed="true">
<set>
<objectAnimator
+ android:interpolator="@interpolator/control_state"
android:duration="50"
android:propertyName="scaleX"
android:valueTo="0.97"
android:valueType="floatType" />
<objectAnimator
+ android:interpolator="@interpolator/control_state"
android:duration="50"
android:propertyName="scaleY"
android:valueTo="0.97"
@@ -33,11 +35,13 @@
<item>
<set>
<objectAnimator
+ android:interpolator="@interpolator/control_state"
android:duration="250"
android:propertyName="scaleX"
android:valueTo="1"
android:valueType="floatType" />
<objectAnimator
+ android:interpolator="@interpolator/control_state"
android:duration="250"
android:propertyName="scaleY"
android:valueTo="1"
diff --git a/packages/SystemUI/res/drawable/control_background.xml b/packages/SystemUI/res/drawable/control_background.xml
index 29b4efa48fa1..cf298b70f3db 100644
--- a/packages/SystemUI/res/drawable/control_background.xml
+++ b/packages/SystemUI/res/drawable/control_background.xml
@@ -17,7 +17,8 @@
*/
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item>
+ <item
+ android:id="@+id/background">
<shape>
<solid android:color="@color/control_default_background" />
<corners android:radius="@dimen/control_corner_radius" />
diff --git a/packages/SystemUI/res/interpolator/control_state.xml b/packages/SystemUI/res/interpolator/control_state.xml
new file mode 100644
index 000000000000..66106d48d507
--- /dev/null
+++ b/packages/SystemUI/res/interpolator/control_state.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2020 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.
+ -->
+<pathInterpolator
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:controlX1="0"
+ android:controlY1="0"
+ android:controlX2="1"
+ android:controlY2="1"/>
diff --git a/packages/SystemUI/res/layout/photo_preview_overlay.xml b/packages/SystemUI/res/layout/photo_preview_overlay.xml
new file mode 100644
index 000000000000..9210996fb9c6
--- /dev/null
+++ b/packages/SystemUI/res/layout/photo_preview_overlay.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2020 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.
+ -->
+
+<!-- empty stub -->
+<merge /> \ No newline at end of file
diff --git a/packages/SystemUI/res/layout/status_bar_expanded.xml b/packages/SystemUI/res/layout/status_bar_expanded.xml
index 115b4a86b86d..1d4b98242519 100644
--- a/packages/SystemUI/res/layout/status_bar_expanded.xml
+++ b/packages/SystemUI/res/layout/status_bar_expanded.xml
@@ -66,6 +66,8 @@
<include layout="@layout/ambient_indication"
android:id="@+id/ambient_indication_container" />
+ <include layout="@layout/photo_preview_overlay" />
+
<ViewStub
android:id="@+id/keyguard_user_switcher"
android:layout="@layout/keyguard_user_switcher"
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index e7ef8ccf4eba..622e4ccef487 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -1252,6 +1252,7 @@
<dimen name="control_status_expanded">18sp</dimen>
<dimen name="control_base_item_margin">2dp</dimen>
<dimen name="control_status_padding">3dp</dimen>
+ <fraction name="controls_toggle_bg_intensity">5%</fraction>
<!-- Home Controls activity view detail panel-->
<dimen name="controls_activity_view_top_padding">25dp</dimen>
diff --git a/packages/SystemUI/scripts/update_statsd_lib.sh b/packages/SystemUI/scripts/update_statsd_lib.sh
new file mode 100755
index 000000000000..79b9497a5f3f
--- /dev/null
+++ b/packages/SystemUI/scripts/update_statsd_lib.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+NUM_ARGS=$#
+JAR_DESTINATION="$1/prebuilts/framework_intermediates/libs/systemui_statsd.jar"
+
+has_croot() {
+ declare -F croot > /dev/null
+ return $?
+}
+
+check_environment() {
+ if ! has_croot; then
+ echo "Run script in a shell that has had envsetup run. Run '. update_statsd_lib.sh' from scripts directory"
+ return 1
+ fi
+
+ if [ $NUM_ARGS -ne 1 ]; then
+ echo "Usage: . update_statsd_lib.sh PATH_TO_UNBUNDLED_LAUNCER e.g. . update_statsd_lib ~/src/ub-launcher3-master"
+ return 1
+ fi
+ return 0
+}
+
+main() {
+ if check_environment ; then
+ pushd .
+ croot
+ mma -j16 SystemUI-statsd
+ cp out/target/product/$TARGET_PRODUCT/obj/JAVA_LIBRARIES/SystemUI-statsd_intermediates/javalib.jar $JAR_DESTINATION
+ popd
+ fi
+}
+
+main
+
diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
index 8df3dd2ad845..922fb69b3fdc 100644
--- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
+++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
@@ -54,8 +54,10 @@ import android.graphics.Region;
import android.graphics.drawable.VectorDrawable;
import android.hardware.display.DisplayManager;
import android.os.Handler;
+import android.os.HandlerExecutor;
import android.os.HandlerThread;
import android.os.SystemProperties;
+import android.os.UserHandle;
import android.provider.Settings.Secure;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -298,13 +300,15 @@ public class ScreenDecorations extends SystemUI implements Tunable {
updateColorInversion(value);
}
};
+
+ mColorInversionSetting.setListening(true);
+ mColorInversionSetting.onChange(false);
}
- mColorInversionSetting.setListening(true);
- mColorInversionSetting.onChange(false);
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_USER_SWITCHED);
- mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter, mHandler);
+ mBroadcastDispatcher.registerReceiver(mUserSwitchIntentReceiver, filter,
+ new HandlerExecutor(mHandler), UserHandle.ALL);
mIsRegistered = true;
} else {
mMainHandler.post(() -> mTunerService.removeTunable(this));
@@ -313,7 +317,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
mColorInversionSetting.setListening(false);
}
- mBroadcastDispatcher.unregisterReceiver(mIntentReceiver);
+ mBroadcastDispatcher.unregisterReceiver(mUserSwitchIntentReceiver);
mIsRegistered = false;
}
}
@@ -503,17 +507,16 @@ public class ScreenDecorations extends SystemUI implements Tunable {
}
}
- private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
+ private final BroadcastReceiver mUserSwitchIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (action.equals(Intent.ACTION_USER_SWITCHED)) {
- int newUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
- ActivityManager.getCurrentUser());
- // update color inversion setting to the new user
- mColorInversionSetting.setUserId(newUserId);
- updateColorInversion(mColorInversionSetting.getValue());
+ int newUserId = ActivityManager.getCurrentUser();
+ if (DEBUG) {
+ Log.d(TAG, "UserSwitched newUserId=" + newUserId);
}
+ // update color inversion setting to the new user
+ mColorInversionSetting.setUserId(newUserId);
+ updateColorInversion(mColorInversionSetting.getValue());
}
};
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt
index 055adc6f6774..93e1bd444938 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt
@@ -66,7 +66,10 @@ class ControlViewHolder(
)
}
+ private val toggleBackgroundIntensity: Float = layout.context.resources
+ .getFraction(R.fraction.controls_toggle_bg_intensity, 1, 1)
private var stateAnimator: ValueAnimator? = null
+ private val baseLayer: GradientDrawable
val icon: ImageView = layout.requireViewById(R.id.icon)
val status: TextView = layout.requireViewById(R.id.status)
val title: TextView = layout.requireViewById(R.id.title)
@@ -85,6 +88,7 @@ class ControlViewHolder(
ld.mutate()
clipLayer = ld.findDrawableByLayerId(R.id.clip_layer) as ClipDrawable
clipLayer.alpha = ALPHA_DISABLED
+ baseLayer = ld.findDrawableByLayerId(R.id.background) as GradientDrawable
// needed for marquee to start
status.setSelected(true)
}
@@ -171,11 +175,12 @@ class ControlViewHolder(
val ri = RenderInfo.lookup(context, cws.componentName, deviceType, enabled, offset)
- val fg = context.getResources().getColorStateList(ri.foreground, context.getTheme())
- val (bg, newAlpha) = if (enabled) {
- Pair(ri.enabledBackground, ALPHA_ENABLED)
+ val fg = context.resources.getColorStateList(ri.foreground, context.theme)
+ val bg = context.resources.getColor(R.color.control_default_background, context.theme)
+ val (clip, newAlpha) = if (enabled) {
+ listOf(ri.enabledBackground, ALPHA_ENABLED)
} else {
- Pair(R.color.control_default_background, ALPHA_DISABLED)
+ listOf(R.color.control_default_background, ALPHA_DISABLED)
}
status.setTextColor(fg)
@@ -187,14 +192,22 @@ class ControlViewHolder(
}
(clipLayer.getDrawable() as GradientDrawable).apply {
- val newColor = context.resources.getColor(bg, context.theme)
+ val newClipColor = context.resources.getColor(clip, context.theme)
+ val newBaseColor = if (behavior is ToggleRangeBehavior) {
+ ColorUtils.blendARGB(bg, newClipColor, toggleBackgroundIntensity)
+ } else {
+ bg
+ }
stateAnimator?.cancel()
if (animated) {
- val oldColor = color?.defaultColor ?: newColor
+ val oldColor = color?.defaultColor ?: newClipColor
+ val oldBaseColor = baseLayer.color?.defaultColor ?: newBaseColor
stateAnimator = ValueAnimator.ofInt(clipLayer.alpha, newAlpha).apply {
addUpdateListener {
alpha = it.animatedValue as Int
- setColor(ColorUtils.blendARGB(oldColor, newColor, it.animatedFraction))
+ setColor(ColorUtils.blendARGB(oldColor, newClipColor, it.animatedFraction))
+ baseLayer.setColor(ColorUtils.blendARGB(oldBaseColor,
+ newBaseColor, it.animatedFraction))
}
addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
@@ -207,7 +220,8 @@ class ControlViewHolder(
}
} else {
alpha = newAlpha
- setColor(newColor)
+ setColor(newClipColor)
+ baseLayer.setColor(newBaseColor)
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
index e6af36b2c86b..2c080b8efc63 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
@@ -43,7 +43,6 @@ import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Color;
-import android.graphics.Insets;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.net.ConnectivityManager;
@@ -2178,8 +2177,10 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
ViewGroup root = (ViewGroup) mGlobalActionsLayout.getRootView();
root.setOnApplyWindowInsetsListener((v, windowInsets) -> {
if (mControlsUiController != null) {
- Insets insets = windowInsets.getInsets(WindowInsets.Type.all());
- root.setPadding(insets.left, insets.top, insets.right, insets.bottom);
+ root.setPadding(windowInsets.getStableInsetLeft(),
+ windowInsets.getStableInsetTop(),
+ windowInsets.getStableInsetRight(),
+ windowInsets.getStableInsetBottom());
}
return WindowInsets.CONSUMED;
});
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
index 350ce293a13f..79d2eddfaec4 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
@@ -266,6 +266,10 @@ public class PipTouchHandler {
mMagnetizedPip = mMotionHelper.getMagnetizedPip();
mMagneticTarget = mMagnetizedPip.addTarget(mTargetView, 0);
+
+ // Set the magnetic field radius equal to twice the size of the target.
+ mMagneticTarget.setMagneticFieldRadiusPx(targetSize * 2);
+
mMagnetizedPip.setPhysicsAnimatorUpdateListener(mMotionHelper.mResizePipUpdateListener);
mMagnetizedPip.setMagnetListener(new MagnetizedObject.MagnetListener() {
@Override
@@ -504,9 +508,6 @@ public class PipTouchHandler {
mTargetView.setTranslationY(mTargetViewContainer.getHeight());
mTargetViewContainer.setVisibility(View.VISIBLE);
- // Set the magnetic field radius to half of PIP's width.
- mMagneticTarget.setMagneticFieldRadiusPx(mMotionHelper.getBounds().width());
-
// Cancel in case we were in the middle of animating it out.
mMagneticTargetAnimator.cancel();
mMagneticTargetAnimator
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/ScreenRecordTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/ScreenRecordTile.java
index 666323766c12..9cee7e7ccba4 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/ScreenRecordTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/ScreenRecordTile.java
@@ -72,6 +72,7 @@ public class ScreenRecordTile extends QSTileImpl<QSTile.BooleanState>
state.value = isRecording || isStarting;
state.state = (isRecording || isStarting) ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
+ state.label = mContext.getString(R.string.quick_settings_screen_record_label);
if (isRecording) {
state.icon = ResourceIcon.get(R.drawable.ic_qs_screenrecord);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt
index 0d7715958995..25f1a974bc36 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt
@@ -250,7 +250,8 @@ class NotificationShadeDepthController @Inject constructor(
private fun updateShadeBlur() {
var newBlur = 0
val state = statusBarStateController.state
- if (state == StatusBarState.SHADE || state == StatusBarState.SHADE_LOCKED) {
+ if ((state == StatusBarState.SHADE || state == StatusBarState.SHADE_LOCKED) &&
+ !keyguardStateController.isKeyguardFadingAway) {
newBlur = blurUtils.blurRadiusOfRatio(shadeExpansion)
}
shadeSpring.animateTo(newBlur)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java
index f103bd01fc3f..7d422e3c15a2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java
@@ -312,7 +312,7 @@ public class EdgeBackGestureHandler implements DisplayListener,
WindowManagerGlobal.getWindowManagerService()
.unregisterSystemGestureExclusionListener(
mGestureExclusionListener, mDisplayId);
- } catch (RemoteException e) {
+ } catch (RemoteException | IllegalArgumentException e) {
Log.e(TAG, "Failed to unregister window manager callbacks", e);
}
@@ -326,7 +326,7 @@ public class EdgeBackGestureHandler implements DisplayListener,
WindowManagerGlobal.getWindowManagerService()
.registerSystemGestureExclusionListener(
mGestureExclusionListener, mDisplayId);
- } catch (RemoteException e) {
+ } catch (RemoteException | IllegalArgumentException e) {
Log.e(TAG, "Failed to register window manager callbacks", e);
}
diff --git a/packages/SystemUI/src/com/android/systemui/util/magnetictarget/MagnetizedObject.kt b/packages/SystemUI/src/com/android/systemui/util/magnetictarget/MagnetizedObject.kt
index f27bdbfbeda0..e905e6772074 100644
--- a/packages/SystemUI/src/com/android/systemui/util/magnetictarget/MagnetizedObject.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/magnetictarget/MagnetizedObject.kt
@@ -27,6 +27,7 @@ import android.provider.Settings
import android.view.MotionEvent
import android.view.VelocityTracker
import android.view.View
+import android.view.ViewConfiguration
import androidx.dynamicanimation.animation.DynamicAnimation
import androidx.dynamicanimation.animation.FloatPropertyCompat
import androidx.dynamicanimation.animation.SpringForce
@@ -146,6 +147,10 @@ abstract class MagnetizedObject<T : Any>(
private val velocityTracker: VelocityTracker = VelocityTracker.obtain()
private val vibrator: Vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
+ private var touchDown = PointF()
+ private var touchSlop = 0
+ private var movedBeyondSlop = false
+
/** Whether touch events are presently occurring within the magnetic field area of a target. */
val objectStuckToTarget: Boolean
get() = targetObjectIsStuckTo != null
@@ -324,15 +329,32 @@ abstract class MagnetizedObject<T : Any>(
// When a gesture begins, recalculate target views' positions on the screen in case they
// have changed. Also, clear state.
if (ev.action == MotionEvent.ACTION_DOWN) {
- updateTargetViewLocations()
+ updateTargetViews()
- // Clear the velocity tracker and assume we're not stuck to a target yet.
+ // Clear the velocity tracker and stuck target.
velocityTracker.clear()
targetObjectIsStuckTo = null
+
+ // Set the touch down coordinates and reset movedBeyondSlop.
+ touchDown.set(ev.rawX, ev.rawY)
+ movedBeyondSlop = false
}
+ // Always pass events to the VelocityTracker.
addMovement(ev)
+ // If we haven't yet moved beyond the slop distance, check if we have.
+ if (!movedBeyondSlop) {
+ val dragDistance = hypot(ev.rawX - touchDown.x, ev.rawY - touchDown.y)
+ if (dragDistance > touchSlop) {
+ // If we're beyond the slop distance, save that and continue.
+ movedBeyondSlop = true
+ } else {
+ // Otherwise, don't do anything yet.
+ return false
+ }
+ }
+
val targetObjectIsInMagneticFieldOf = associatedTargets.firstOrNull { target ->
val distanceFromTargetCenter = hypot(
ev.rawX - target.centerOnScreen.x,
@@ -559,8 +581,14 @@ abstract class MagnetizedObject<T : Any>(
}
/** Updates the locations on screen of all of the [associatedTargets]. */
- internal fun updateTargetViewLocations() {
+ internal fun updateTargetViews() {
associatedTargets.forEach { it.updateLocationOnScreen() }
+
+ // Update the touch slop, since the configuration may have changed.
+ if (associatedTargets.size > 0) {
+ touchSlop =
+ ViewConfiguration.get(associatedTargets[0].targetView.context).scaledTouchSlop
+ }
}
/**
diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/magnetictarget/MagnetizedObjectTest.kt b/packages/SystemUI/tests/src/com/android/systemui/util/magnetictarget/MagnetizedObjectTest.kt
index f6b7b74d4bfc..251ca9c8dcb2 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/util/magnetictarget/MagnetizedObjectTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/util/magnetictarget/MagnetizedObjectTest.kt
@@ -186,8 +186,8 @@ class MagnetizedObjectTest : SysuiTestCase() {
@Test
fun testMotionEventConsumption_downInMagneticField() {
- // We should consume DOWN events if they occur in the field.
- assertTrue(magnetizedObject.maybeConsumeMotionEvent(getMotionEvent(
+ // We should not consume DOWN events even if they occur in the field.
+ assertFalse(magnetizedObject.maybeConsumeMotionEvent(getMotionEvent(
x = targetCenterX, y = targetCenterY, action = MotionEvent.ACTION_DOWN)))
}
@@ -342,10 +342,14 @@ class MagnetizedObjectTest : SysuiTestCase() {
// Trigger the magnet animation, and block the test until it ends.
PhysicsAnimatorTestUtils.setAllAnimationsBlock(true)
magnetizedObject.maybeConsumeMotionEvent(getMotionEvent(
- x = targetCenterX,
- y = targetCenterY,
+ x = targetCenterX - 250,
+ y = targetCenterY - 250,
action = MotionEvent.ACTION_DOWN))
+ magnetizedObject.maybeConsumeMotionEvent(getMotionEvent(
+ x = targetCenterX,
+ y = targetCenterY))
+
// The object's (top-left) position should now position it centered over the target.
assertEquals(targetCenterX - objectSize / 2, objectX)
assertEquals(targetCenterY - objectSize / 2, objectY)
diff --git a/packages/Tethering/tests/integration/Android.bp b/packages/Tethering/tests/integration/Android.bp
index 620261b375d2..6b751afdf58b 100644
--- a/packages/Tethering/tests/integration/Android.bp
+++ b/packages/Tethering/tests/integration/Android.bp
@@ -13,19 +13,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-
-android_test {
- name: "TetheringIntegrationTests",
- certificate: "platform",
- platform_apis: true,
+java_defaults {
+ name: "TetheringIntegrationTestsDefaults",
srcs: [
"src/**/*.java",
"src/**/*.kt",
],
- test_suites: [
- "device-tests",
- "mts",
- ],
static_libs: [
"NetworkStackApiStableLib",
"androidx.test.rules",
@@ -44,4 +37,49 @@ android_test {
"libdexmakerjvmtiagent",
"libstaticjvmtiagent",
],
+ jarjar_rules: ":NetworkStackJarJarRules",
+}
+
+android_library {
+ name: "TetheringIntegrationTestsLib",
+ platform_apis: true,
+ defaults: ["TetheringIntegrationTestsDefaults"],
+ visibility: ["//cts/tests/tests/tethering"]
+}
+
+android_test {
+ name: "TetheringIntegrationTests",
+ platform_apis: true,
+ defaults: ["TetheringIntegrationTestsDefaults"],
+ test_suites: [
+ "device-tests",
+ "mts",
+ ],
+ compile_multilib: "both",
}
+
+// Special version of the tethering tests that includes all tests necessary for code coverage
+// purposes. This is currently the union of TetheringTests, TetheringIntegrationTests and
+// NetworkStackTests.
+android_test {
+ name: "TetheringCoverageTests",
+ certificate: "platform",
+ platform_apis: true,
+ test_suites: ["device-tests", "mts"],
+ test_config: "AndroidTest_Coverage.xml",
+ defaults: ["libnetworkstackutilsjni_deps"],
+ static_libs: [
+ "NetworkStackTestsLib",
+ "TetheringTestsLib",
+ "TetheringIntegrationTestsLib",
+ ],
+ jni_libs: [
+ // For mockito extended
+ "libdexmakerjvmtiagent",
+ "libstaticjvmtiagent",
+ // For NetworkStackUtils included in NetworkStackBase
+ "libnetworkstackutilsjni",
+ ],
+ compile_multilib: "both",
+ manifest: "AndroidManifest_coverage.xml",
+} \ No newline at end of file
diff --git a/packages/Tethering/tests/integration/AndroidManifest.xml b/packages/Tethering/tests/integration/AndroidManifest.xml
index 233ba40b5d35..fddfaad29f0f 100644
--- a/packages/Tethering/tests/integration/AndroidManifest.xml
+++ b/packages/Tethering/tests/integration/AndroidManifest.xml
@@ -17,7 +17,6 @@
package="com.android.networkstack.tethering.tests.integration">
<uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.TETHER_PRIVILEGED"/>
<application android:debuggable="true">
<uses-library android:name="android.test.runner" />
diff --git a/packages/Tethering/tests/integration/AndroidManifest_coverage.xml b/packages/Tethering/tests/integration/AndroidManifest_coverage.xml
new file mode 100644
index 000000000000..06de00d78558
--- /dev/null
+++ b/packages/Tethering/tests/integration/AndroidManifest_coverage.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 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"
+ xmlns:tools="http://schemas.android.com/tools"
+ package="com.android.networkstack.tethering.tests.coverage">
+
+ <application tools:replace="android:label"
+ android:debuggable="true"
+ android:label="Tethering coverage tests">
+ <uses-library android:name="android.test.runner" />
+ </application>
+ <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.networkstack.tethering.tests.coverage"
+ android:label="Tethering coverage tests">
+ </instrumentation>
+</manifest>
diff --git a/packages/Tethering/tests/integration/AndroidTest_Coverage.xml b/packages/Tethering/tests/integration/AndroidTest_Coverage.xml
new file mode 100644
index 000000000000..3def2099e45f
--- /dev/null
+++ b/packages/Tethering/tests/integration/AndroidTest_Coverage.xml
@@ -0,0 +1,12 @@
+<configuration description="Runs coverage tests for Tethering">
+ <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
+ <option name="test-file-name" value="TetheringCoverageTests.apk" />
+ </target_preparer>
+
+ <option name="test-tag" value="TetheringCoverageTests" />
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+ <option name="package" value="com.android.networkstack.tethering.tests.coverage" />
+ <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
+ <option name="hidden-api-checks" value="false"/>
+ </test>
+</configuration> \ No newline at end of file
diff --git a/packages/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java b/packages/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java
index b02bb23f9807..4bac9da9c3d2 100644
--- a/packages/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java
+++ b/packages/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java
@@ -18,6 +18,7 @@ package android.net;
import static android.Manifest.permission.MANAGE_TEST_NETWORKS;
import static android.Manifest.permission.NETWORK_SETTINGS;
+import static android.Manifest.permission.TETHER_PRIVILEGED;
import static android.net.TetheringManager.TETHERING_ETHERNET;
import static org.junit.Assert.assertEquals;
@@ -109,7 +110,8 @@ public class EthernetTetheringTest {
mTetheredInterfaceRequester = new TetheredInterfaceRequester(mHandler, mEm);
// Needed to create a TestNetworkInterface, to call requestTetheredInterface, and to receive
// tethered client callbacks.
- mUiAutomation.adoptShellPermissionIdentity(MANAGE_TEST_NETWORKS, NETWORK_SETTINGS);
+ mUiAutomation.adoptShellPermissionIdentity(
+ MANAGE_TEST_NETWORKS, NETWORK_SETTINGS, TETHER_PRIVILEGED);
}
private void cleanUp() throws Exception {
diff --git a/packages/Tethering/tests/unit/Android.bp b/packages/Tethering/tests/unit/Android.bp
index 59681e9eb56a..4849fd5d01f5 100644
--- a/packages/Tethering/tests/unit/Android.bp
+++ b/packages/Tethering/tests/unit/Android.bp
@@ -14,39 +14,33 @@
// limitations under the License.
//
-android_test {
- name: "TetheringTests",
- certificate: "platform",
+java_defaults {
+ name: "TetheringTestsDefaults",
srcs: [
"src/**/*.java",
"src/**/*.kt",
],
- test_suites: [
- "device-tests",
- "mts",
- ],
- compile_multilib: "both",
static_libs: [
+ "TetheringApiCurrentLib",
"androidx.test.rules",
"frameworks-base-testutils",
- "net-tests-utils",
"mockito-target-extended-minus-junit4",
- "TetheringApiCurrentLib",
+ "net-tests-utils",
"testables",
],
// TODO(b/147200698) change sdk_version to module-current and
// remove framework-minus-apex, ext, and framework-res
sdk_version: "core_platform",
libs: [
- "framework-minus-apex",
- "ext",
- "framework-res",
- "framework-wifi-stubs-module_libs_api",
- "framework-telephony-stubs",
"android.test.runner",
"android.test.base",
"android.test.mock",
+ "ext",
+ "framework-minus-apex",
+ "framework-res",
+ "framework-telephony-stubs",
"framework-tethering",
+ "framework-wifi-stubs-module_libs_api",
],
jni_libs: [
// For mockito extended
@@ -55,3 +49,25 @@ android_test {
],
jarjar_rules: "jarjar-rules.txt",
}
+
+// Library containing the unit tests. This is used by the coverage test target to pull in the
+// unit test code. It is not currently used by the tests themselves because all the build
+// configuration needed by the tests is in the TetheringTestsDefaults rule.
+android_library {
+ name: "TetheringTestsLib",
+ defaults: ["TetheringTestsDefaults"],
+ visibility: [
+ "//frameworks/base/packages/Tethering/tests/integration",
+ ]
+}
+
+android_test {
+ name: "TetheringTests",
+ certificate: "platform",
+ test_suites: [
+ "device-tests",
+ "mts",
+ ],
+ defaults: ["TetheringTestsDefaults"],
+ compile_multilib: "both",
+}
diff --git a/read-snapshot.txt b/read-snapshot.txt
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/read-snapshot.txt
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index e41ba0e1745d..2a9f503602ac 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -465,6 +465,8 @@ public class ActivityManagerService extends IActivityManager.Stub
static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
+ static final String SYSTEM_USER_HOME_NEEDED = "ro.system_user_home_needed";
+
public static final String ANR_TRACE_DIR = "/data/anr";
// Maximum number of receivers an app can register.
@@ -9592,7 +9594,8 @@ public class ActivityManagerService extends IActivityManager.Stub
// to handle home activity in this case.
if (UserManager.isSplitSystemUser() &&
Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.USER_SETUP_COMPLETE, 0) != 0) {
+ Settings.Secure.USER_SETUP_COMPLETE, 0) != 0
+ || SystemProperties.getBoolean(SYSTEM_USER_HOME_NEEDED, false)) {
t.traceBegin("enableHomeActivity");
ComponentName cName = new ComponentName(mContext, SystemUserHomeActivity.class);
try {
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
index 89fa02bbbd64..cce749d5a7ef 100644
--- a/services/core/java/com/android/server/am/ProcessList.java
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -1668,6 +1668,33 @@ public final class ProcessList {
return gidArray;
}
+ private boolean shouldEnableTaggedPointers(ProcessRecord app) {
+ // Ensure we have platform + kernel support for TBI.
+ if (!Zygote.nativeSupportsTaggedPointers()) {
+ return false;
+ }
+
+ // Check to ensure the app hasn't explicitly opted-out of TBI via. the manifest attribute.
+ if (!app.info.allowsNativeHeapPointerTagging()) {
+ return false;
+ }
+
+ // Check to see that the compat feature for TBI is enabled.
+ if (!mPlatformCompat.isChangeEnabled(NATIVE_HEAP_POINTER_TAGGING, app.info)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private int decideTaggingLevel(ProcessRecord app) {
+ if (shouldEnableTaggedPointers(app)) {
+ return Zygote.MEMORY_TAG_LEVEL_TBI;
+ }
+
+ return 0;
+ }
+
private int decideGwpAsanLevel(ProcessRecord app) {
// Look at the process attribute first.
if (app.processInfo != null
@@ -1856,15 +1883,6 @@ public final class ProcessList {
runtimeFlags |= Zygote.USE_APP_IMAGE_STARTUP_CACHE;
}
- if (Zygote.nativeSupportsTaggedPointers()) {
- // Enable heap pointer tagging if supported by the kernel, unless disabled by the
- // app manifest, target sdk level, or compat feature.
- if (app.info.allowsNativeHeapPointerTagging()
- && mPlatformCompat.isChangeEnabled(NATIVE_HEAP_POINTER_TAGGING, app.info)) {
- runtimeFlags |= Zygote.MEMORY_TAG_LEVEL_TBI;
- }
- }
-
runtimeFlags |= decideGwpAsanLevel(app);
String invokeWith = null;
@@ -1895,6 +1913,20 @@ public final class ProcessList {
app.setRequiredAbi(requiredAbi);
app.instructionSet = instructionSet;
+ // If instructionSet is non-null, this indicates that the system_server is spawning a
+ // process with an ISA that may be different from its own. System (kernel and hardware)
+ // compatililty for these features is checked in the decideTaggingLevel in the
+ // system_server process (not the child process). As TBI is only supported in aarch64,
+ // we can simply ensure that the new process is also aarch64. This prevents the mismatch
+ // where a 64-bit system server spawns a 32-bit child that thinks it should enable some
+ // tagging variant. Theoretically, a 32-bit system server could exist that spawns 64-bit
+ // processes, in which case the new process won't get any tagging. This is fine as we
+ // haven't seen this configuration in practice, and we can reasonable assume that if
+ // tagging is desired, the system server will be 64-bit.
+ if (instructionSet == null || instructionSet.equals("arm64")) {
+ runtimeFlags |= decideTaggingLevel(app);
+ }
+
// the per-user SELinux context must be set
if (TextUtils.isEmpty(app.info.seInfoUser)) {
Slog.wtf(ActivityManagerService.TAG, "SELinux tag not defined",
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index e02c6f9d5497..546025a2498f 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -40,6 +40,7 @@ import static com.android.server.am.UserState.STATE_RUNNING_LOCKED;
import static com.android.server.am.UserState.STATE_RUNNING_UNLOCKED;
import static com.android.server.am.UserState.STATE_RUNNING_UNLOCKING;
+import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
@@ -89,6 +90,7 @@ import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseIntArray;
+import android.util.SparseLongArray;
import android.util.proto.ProtoOutputStream;
import com.android.internal.R;
@@ -112,6 +114,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -162,6 +165,46 @@ class UserController implements Handler.Callback {
// TODO(b/149604218): STOPSHIP remove this constant and the logcat
private static final boolean TESTS_NEED_LOGCAT = true;
+ // Used for statsd logging with UserLifecycleJourneyReported + UserLifecycleEventOccurred atoms
+ private static final long INVALID_SESSION_ID = 0;
+
+ // The various user journeys, defined in the UserLifecycleJourneyReported atom for statsd
+ private static final int USER_JOURNEY_UNKNOWN =
+ FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__JOURNEY__UNKNOWN;
+ private static final int USER_JOURNEY_USER_SWITCH_FG =
+ FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__JOURNEY__USER_SWITCH_FG;
+ private static final int USER_JOURNEY_USER_SWITCH_UI =
+ FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__JOURNEY__USER_SWITCH_UI;
+ private static final int USER_JOURNEY_USER_START =
+ FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__JOURNEY__USER_START;
+ private static final int USER_JOURNEY_USER_CREATE =
+ FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__JOURNEY__USER_CREATE;
+ @IntDef(prefix = { "USER_JOURNEY" }, value = {
+ USER_JOURNEY_UNKNOWN,
+ USER_JOURNEY_USER_SWITCH_FG,
+ USER_JOURNEY_USER_SWITCH_UI,
+ USER_JOURNEY_USER_START,
+ USER_JOURNEY_USER_CREATE,
+ })
+ @interface UserJourney {}
+
+ // The various user lifecycle events, defined in the UserLifecycleEventOccurred atom for statsd
+ private static final int USER_LIFECYCLE_EVENT_UNKNOWN =
+ FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__EVENT__UNKNOWN;
+ private static final int USER_LIFECYCLE_EVENT_SWITCH_USER =
+ FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__EVENT__SWITCH_USER;
+ private static final int USER_LIFECYCLE_EVENT_START_USER =
+ FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__EVENT__START_USER;
+ private static final int USER_LIFECYCLE_EVENT_CREATE_USER =
+ FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__EVENT__CREATE_USER;
+ @IntDef(prefix = { "USER_LIFECYCLE_EVENT" }, value = {
+ USER_LIFECYCLE_EVENT_UNKNOWN,
+ USER_LIFECYCLE_EVENT_SWITCH_USER,
+ USER_LIFECYCLE_EVENT_START_USER,
+ USER_LIFECYCLE_EVENT_CREATE_USER,
+ })
+ @interface UserLifecycleEvent {}
+
/**
* Maximum number of users we allow to be running at a time, including system user.
*
@@ -270,6 +313,13 @@ class UserController implements Handler.Callback {
@GuardedBy("mLock")
private final ArrayList<Integer> mLastActiveUsers = new ArrayList<>();
+ /**
+ * A per-user, journey to session id map, used for statsd logging for the
+ * UserLifecycleJourneyReported and UserLifecycleEventOccurred atoms.
+ */
+ @GuardedBy("mUserJourneyToSessionIdMap")
+ private final SparseArray<SparseLongArray> mUserJourneyToSessionIdMap = new SparseArray<>();
+
UserController(ActivityManagerService service) {
this(new Injector(service));
}
@@ -2349,6 +2399,10 @@ class UserController implements Handler.Callback {
public boolean handleMessage(Message msg) {
switch (msg.what) {
case START_USER_SWITCH_FG_MSG:
+ logUserJourneyInfo(getUserInfo(getCurrentUserId()), getUserInfo(msg.arg1),
+ USER_JOURNEY_USER_SWITCH_FG);
+ logUserLifecycleEvent(msg.arg1, USER_JOURNEY_USER_SWITCH_FG,
+ USER_LIFECYCLE_EVENT_SWITCH_USER, true);
startUserInForeground(msg.arg1);
break;
case REPORT_USER_SWITCH_MSG:
@@ -2370,8 +2424,14 @@ class UserController implements Handler.Callback {
mInjector.batteryStatsServiceNoteEvent(
BatteryStats.HistoryItem.EVENT_USER_RUNNING_START,
Integer.toString(msg.arg1), msg.arg1);
+ logUserJourneyInfo(null, getUserInfo(msg.arg1), USER_JOURNEY_USER_START);
+ logUserLifecycleEvent(msg.arg1, USER_JOURNEY_USER_START,
+ USER_LIFECYCLE_EVENT_START_USER, true);
mInjector.getSystemServiceManager().startUser(TimingsTraceAndSlog.newAsyncLog(),
msg.arg1);
+ logUserLifecycleEvent(msg.arg1, USER_JOURNEY_USER_START,
+ USER_LIFECYCLE_EVENT_START_USER, false);
+ clearSessionId(msg.arg1, USER_JOURNEY_USER_START);
break;
case USER_UNLOCK_MSG:
final int userId = msg.arg1;
@@ -2400,17 +2460,94 @@ class UserController implements Handler.Callback {
break;
case REPORT_USER_SWITCH_COMPLETE_MSG:
dispatchUserSwitchComplete(msg.arg1);
+ final int currentJourney = mUserSwitchUiEnabled ? USER_JOURNEY_USER_SWITCH_UI
+ : USER_JOURNEY_USER_SWITCH_FG;
+ logUserLifecycleEvent(msg.arg1, currentJourney,
+ USER_LIFECYCLE_EVENT_SWITCH_USER, false);
+ clearSessionId(msg.arg1, currentJourney);
break;
case REPORT_LOCKED_BOOT_COMPLETE_MSG:
dispatchLockedBootComplete(msg.arg1);
break;
case START_USER_SWITCH_UI_MSG:
- showUserSwitchDialog((Pair<UserInfo, UserInfo>) msg.obj);
+ final Pair<UserInfo, UserInfo> fromToUserPair = (Pair<UserInfo, UserInfo>) msg.obj;
+ logUserJourneyInfo(fromToUserPair.first, fromToUserPair.second,
+ USER_JOURNEY_USER_SWITCH_UI);
+ logUserLifecycleEvent(fromToUserPair.second.id, USER_JOURNEY_USER_SWITCH_UI,
+ USER_LIFECYCLE_EVENT_SWITCH_USER, true);
+ showUserSwitchDialog(fromToUserPair);
break;
}
return false;
}
+ /**
+ * statsd helper method for logging the start of a user journey via a UserLifecycleEventOccurred
+ * atom given the originating and targeting users for the journey.
+ *
+ * Note: these info atoms are currently logged more than once per journey since there is no
+ * state associated with the user's ongoing journey - this will be updated in a later CL.
+ */
+ private void logUserJourneyInfo(UserInfo origin, UserInfo target, @UserJourney int journey) {
+ final long newSessionId = ThreadLocalRandom.current().nextLong(1, Long.MAX_VALUE);
+ synchronized (mUserJourneyToSessionIdMap) {
+ SparseLongArray userSessions = mUserJourneyToSessionIdMap.get(target.id);
+ if (userSessions == null) {
+ userSessions = new SparseLongArray();
+ mUserJourneyToSessionIdMap.put(target.id, userSessions);
+ }
+ final long oldSessionId = userSessions.get(journey);
+ if (oldSessionId != INVALID_SESSION_ID) {
+ // potentially an incomplete or timed-out session
+ FrameworkStatsLog.write(FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED,
+ oldSessionId, target.id, USER_LIFECYCLE_EVENT_UNKNOWN,
+ FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__STATE__NONE);
+ }
+ // update session id
+ userSessions.put(journey, newSessionId);
+ }
+
+ FrameworkStatsLog.write(FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED, newSessionId,
+ journey, origin != null ? origin.id : -1,
+ target.id, UserManager.getUserTypeForStatsd(target.userType), target.flags);
+ }
+
+ /**
+ * statsd helper method for logging the begin or finish of the given event for the
+ * UserLifecycleEventOccurred statsd atom.
+ * Note: This does not clear the user's journey session id - if this event represents the end of
+ * a particular journey, call {@link #clearSessionId} to indicate that the session is over.
+ */
+ private void logUserLifecycleEvent(@UserIdInt int userId, @UserJourney int journey,
+ @UserLifecycleEvent int event, boolean begin) {
+ final long sessionId;
+ synchronized (mUserJourneyToSessionIdMap) {
+ final SparseLongArray eventToSessionMap = mUserJourneyToSessionIdMap.get(userId);
+ if (eventToSessionMap == null || eventToSessionMap.size() == 0) {
+ return;
+ }
+ sessionId = eventToSessionMap.get(journey);
+ if (sessionId == INVALID_SESSION_ID) {
+ return;
+ }
+ }
+
+ FrameworkStatsLog.write(FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED, sessionId, userId,
+ event, begin ? FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__STATE__BEGIN
+ : FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__STATE__FINISH);
+ }
+
+ /**
+ * Clears the user's session id associated with the given UserJourney (for statsd).
+ */
+ private void clearSessionId(@UserIdInt int userId, @UserJourney int journey) {
+ synchronized (mUserJourneyToSessionIdMap) {
+ if (mUserJourneyToSessionIdMap.get(userId) != null) {
+ mUserJourneyToSessionIdMap.get(userId).delete(journey);
+ }
+ }
+ }
+
private static class UserProgressListener extends IProgressListener.Stub {
private volatile long mUnlockStarted;
@Override
diff --git a/services/core/java/com/android/server/appop/TEST_MAPPING b/services/core/java/com/android/server/appop/TEST_MAPPING
index 9c03a3606e6c..604b9f1ead6d 100644
--- a/services/core/java/com/android/server/appop/TEST_MAPPING
+++ b/services/core/java/com/android/server/appop/TEST_MAPPING
@@ -38,6 +38,9 @@
},
{
"name": "CtsAppTestCases:ActivityManagerApi29Test"
+ },
+ {
+ "name": "UidAtomTests:testAppOps"
}
]
}
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 387a2be41d3c..f840f2d359d5 100755
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -185,6 +185,9 @@ public class AudioService extends IAudioService.Stub
private static final String TAG = "AS.AudioService";
+ private final AudioSystemAdapter mAudioSystem;
+ private final SystemServerAdapter mSystemServer;
+
/** Debug audio mode */
protected static final boolean DEBUG_MODE = false;
@@ -649,10 +652,19 @@ public class AudioService extends IAudioService.Stub
/** @hide */
public AudioService(Context context) {
+ this(context, AudioSystemAdapter.getDefaultAdapter(),
+ SystemServerAdapter.getDefaultAdapter(context));
+ }
+
+ public AudioService(Context context, AudioSystemAdapter audioSystem,
+ SystemServerAdapter systemServer) {
mContext = context;
mContentResolver = context.getContentResolver();
mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
+ mAudioSystem = audioSystem;
+ mSystemServer = systemServer;
+
mPlatformType = AudioSystem.getPlatformType(context);
mIsSingleVolume = AudioSystem.isSingleVolume(context);
@@ -842,11 +854,13 @@ public class AudioService extends IAudioService.Stub
context.registerReceiverAsUser(mReceiver, UserHandle.ALL, intentFilter, null, null);
- LocalServices.addService(AudioManagerInternal.class, new AudioServiceInternal());
+ if (mSystemServer.isPrivileged()) {
+ LocalServices.addService(AudioManagerInternal.class, new AudioServiceInternal());
- mUserManagerInternal.addUserRestrictionsListener(mUserRestrictionsListener);
+ mUserManagerInternal.addUserRestrictionsListener(mUserRestrictionsListener);
- mRecordMonitor.initMonitor();
+ mRecordMonitor.initMonitor();
+ }
final float[] preScale = new float[3];
preScale[0] = mContext.getResources().getFraction(
@@ -935,7 +949,7 @@ public class AudioService extends IAudioService.Stub
onIndicateSystemReady();
- mMicMuteFromSystemCached = AudioSystem.isMicrophoneMuted();
+ mMicMuteFromSystemCached = mAudioSystem.isMicrophoneMuted();
setMicMuteFromSwitchInput();
}
@@ -1636,12 +1650,15 @@ public class AudioService extends IAudioService.Stub
}
if (currentImeUid != mCurrentImeUid || forceUpdate) {
- AudioSystem.setCurrentImeUid(currentImeUid);
+ mAudioSystem.setCurrentImeUid(currentImeUid);
mCurrentImeUid = currentImeUid;
}
}
private void readPersistedSettings() {
+ if (!mSystemServer.isPrivileged()) {
+ return;
+ }
final ContentResolver cr = mContentResolver;
int ringerModeFromSettings =
@@ -1712,6 +1729,9 @@ public class AudioService extends IAudioService.Stub
}
private void readUserRestrictions() {
+ if (!mSystemServer.isPrivileged()) {
+ return;
+ }
final int currentUser = getCurrentUserId();
// Check the current user restriction.
@@ -2782,6 +2802,9 @@ public class AudioService extends IAudioService.Stub
}
private void sendBroadcastToAll(Intent intent) {
+ if (!mSystemServer.isPrivileged()) {
+ return;
+ }
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
final long ident = Binder.clearCallingIdentity();
@@ -3174,12 +3197,12 @@ public class AudioService extends IAudioService.Stub
}
// only mute for the current user
if (getCurrentUserId() == userId || userId == android.os.Process.SYSTEM_UID) {
- final boolean currentMute = AudioSystem.isMicrophoneMuted();
+ final boolean currentMute = mAudioSystem.isMicrophoneMuted();
final long identity = Binder.clearCallingIdentity();
- final int ret = AudioSystem.muteMicrophone(muted);
+ final int ret = mAudioSystem.muteMicrophone(muted);
// update cache with the real state independently from what was set
- mMicMuteFromSystemCached = AudioSystem.isMicrophoneMuted();
+ mMicMuteFromSystemCached = mAudioSystem.isMicrophoneMuted();
if (ret != AudioSystem.AUDIO_STATUS_OK) {
Log.e(TAG, "Error changing mic mute state to " + muted + " current:"
+ mMicMuteFromSystemCached);
@@ -4518,6 +4541,9 @@ public class AudioService extends IAudioService.Stub
}
private void broadcastRingerMode(String action, int ringerMode) {
+ if (!mSystemServer.isPrivileged()) {
+ return;
+ }
// Send sticky broadcast
Intent broadcast = new Intent(action);
broadcast.putExtra(AudioManager.EXTRA_RINGER_MODE, ringerMode);
@@ -4527,6 +4553,9 @@ public class AudioService extends IAudioService.Stub
}
private void broadcastVibrateSetting(int vibrateType) {
+ if (!mSystemServer.isPrivileged()) {
+ return;
+ }
// Send broadcast
if (mActivityManagerInternal.isSystemReady()) {
Intent broadcast = new Intent(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
@@ -5258,6 +5287,9 @@ public class AudioService extends IAudioService.Stub
}
public int observeDevicesForStream_syncVSS(boolean checkOthers) {
+ if (!mSystemServer.isPrivileged()) {
+ return AudioSystem.DEVICE_NONE;
+ }
final int devices = AudioSystem.getDevicesForStream(mStreamType);
if (devices == mObservedDevices) {
return devices;
@@ -5998,10 +6030,7 @@ public class AudioService extends IAudioService.Stub
break;
case MSG_BROADCAST_MICROPHONE_MUTE:
- mContext.sendBroadcastAsUser(
- new Intent(AudioManager.ACTION_MICROPHONE_MUTE_CHANGED)
- .setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY),
- UserHandle.ALL);
+ mSystemServer.sendMicrophoneMuteChangedIntent();
break;
}
}
diff --git a/services/core/java/com/android/server/audio/AudioSystemAdapter.java b/services/core/java/com/android/server/audio/AudioSystemAdapter.java
index 9f8f9f8fddde..40c13904fbc9 100644
--- a/services/core/java/com/android/server/audio/AudioSystemAdapter.java
+++ b/services/core/java/com/android/server/audio/AudioSystemAdapter.java
@@ -40,10 +40,11 @@ public class AudioSystemAdapter {
/**
* Create an adapter for AudioSystem that always succeeds, and does nothing.
- * @return a no-op AudioSystem adapter
+ * Overridden methods can be configured
+ * @return a no-op AudioSystem adapter with configurable adapter
*/
- static final @NonNull AudioSystemAdapter getAlwaysOkAdapter() {
- return new AudioSystemOkAdapter();
+ static final @NonNull AudioSystemAdapter getConfigurableAdapter() {
+ return new AudioSystemConfigurableAdapter();
}
/**
@@ -113,10 +114,51 @@ public class AudioSystemAdapter {
return AudioSystem.setParameters(keyValuePairs);
}
+ /**
+ * Same as {@link AudioSystem#isMicrophoneMuted()}}
+ * Checks whether the microphone mute is on or off.
+ * @return true if microphone is muted, false if it's not
+ */
+ public boolean isMicrophoneMuted() {
+ return AudioSystem.isMicrophoneMuted();
+ }
+
+ /**
+ * Same as {@link AudioSystem#muteMicrophone(boolean)}
+ * Sets the microphone mute on or off.
+ *
+ * @param on set <var>true</var> to mute the microphone;
+ * <var>false</var> to turn mute off
+ * @return command completion status see AUDIO_STATUS_OK, see AUDIO_STATUS_ERROR
+ */
+ public int muteMicrophone(boolean on) {
+ return AudioSystem.muteMicrophone(on);
+ }
+
+ /**
+ * Same as {@link AudioSystem#setCurrentImeUid(int)}
+ * Communicate UID of current InputMethodService to audio policy service.
+ */
+ public int setCurrentImeUid(int uid) {
+ return AudioSystem.setCurrentImeUid(uid);
+ }
+
//--------------------------------------------------------------------
- protected static class AudioSystemOkAdapter extends AudioSystemAdapter {
+ protected static class AudioSystemConfigurableAdapter extends AudioSystemAdapter {
private static final String TAG = "ASA";
+ private boolean mIsMicMuted = false;
+ private boolean mMuteMicrophoneFails = false;
+
+ public void configureIsMicrophoneMuted(boolean muted) {
+ mIsMicMuted = muted;
+ }
+ public void configureMuteMicrophoneToFail(boolean fail) {
+ mMuteMicrophoneFails = fail;
+ }
+
+ //-----------------------------------------------------------------
+ // Overrides of AudioSystemAdapter
@Override
public int setDeviceConnectionState(int device, int state, String deviceAddress,
String deviceName, int codecFormat) {
@@ -152,5 +194,24 @@ public class AudioSystemAdapter {
public int setParameters(String keyValuePairs) {
return AudioSystem.AUDIO_STATUS_OK;
}
+
+ @Override
+ public boolean isMicrophoneMuted() {
+ return mIsMicMuted;
+ }
+
+ @Override
+ public int muteMicrophone(boolean on) {
+ if (mMuteMicrophoneFails) {
+ return AudioSystem.AUDIO_STATUS_ERROR;
+ }
+ mIsMicMuted = on;
+ return AudioSystem.AUDIO_STATUS_OK;
+ }
+
+ @Override
+ public int setCurrentImeUid(int uid) {
+ return AudioSystem.AUDIO_STATUS_OK;
+ }
}
}
diff --git a/services/core/java/com/android/server/audio/SystemServerAdapter.java b/services/core/java/com/android/server/audio/SystemServerAdapter.java
new file mode 100644
index 000000000000..509f6be76f17
--- /dev/null
+++ b/services/core/java/com/android/server/audio/SystemServerAdapter.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2020 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.server.audio;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.content.Context;
+import android.content.Intent;
+import android.media.AudioManager;
+import android.os.UserHandle;
+
+/**
+ * Provides an adapter to access functionality reserved to components running in system_server
+ * Functionality such as sending privileged broadcasts is to be accessed through the default
+ * adapter, whereas tests can inject a no-op adapter.
+ */
+public class SystemServerAdapter {
+
+ protected final Context mContext;
+
+ private SystemServerAdapter(@Nullable Context context) {
+ mContext = context;
+ }
+ /**
+ * Create a wrapper around privileged functionality.
+ * @return the adapter
+ */
+ static final @NonNull SystemServerAdapter getDefaultAdapter(Context context) {
+ return new SystemServerAdapter(context);
+ }
+
+ /**
+ * Create an adapter that does nothing.
+ * Use for running non-privileged tests, such as unit tests
+ * @return a no-op adapter
+ */
+ static final @NonNull SystemServerAdapter getNoOpAdapter() {
+ return new NoOpSystemServerAdapter();
+ }
+
+ /**
+ * @return true if this is supposed to be run in system_server, false otherwise (e.g. for a
+ * unit test)
+ */
+ public boolean isPrivileged() {
+ return true;
+ }
+
+ /**
+ * Broadcast ACTION_MICROPHONE_MUTE_CHANGED
+ */
+ public void sendMicrophoneMuteChangedIntent() {
+ mContext.sendBroadcastAsUser(
+ new Intent(AudioManager.ACTION_MICROPHONE_MUTE_CHANGED)
+ .setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY),
+ UserHandle.ALL);
+ }
+
+ //--------------------------------------------------------------------
+ protected static class NoOpSystemServerAdapter extends SystemServerAdapter {
+
+ NoOpSystemServerAdapter() {
+ super(null);
+ }
+
+ @Override
+ public boolean isPrivileged() {
+ return false;
+ }
+
+ @Override
+ public void sendMicrophoneMuteChangedIntent() {
+ // no-op
+ }
+ }
+}
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java
index 4687a5117343..48e30bf42c2d 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController.java
@@ -390,6 +390,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
private ObjectAnimator mColorFadeOffAnimator;
private RampAnimator<DisplayPowerState> mScreenBrightnessRampAnimator;
+ // The brightness synchronizer to allow changes in the int brightness value to be reflected in
+ // the float brightness value and vice versa.
+ @Nullable
+ private final BrightnessSynchronizer mBrightnessSynchronizer;
/**
* Creates the display power controller.
@@ -406,6 +410,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mWindowManagerPolicy = LocalServices.getService(WindowManagerPolicy.class);
mBlanker = blanker;
mContext = context;
+ mBrightnessSynchronizer = new BrightnessSynchronizer(context);
mDisplayDevice = displayDevice;
PowerManager pm = context.getSystemService(PowerManager.class);
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index e6cb37185d71..b949d6bcf2e2 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -784,6 +784,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
private static final AtomicInteger sSequenceNumber = new AtomicInteger(0);
private static final class Entry {
+ final int mSequenceNumber = sSequenceNumber.getAndIncrement();
final ClientState mClientState;
@SoftInputModeFlags
final int mFocusedWindowSoftInputMode;
@@ -831,7 +832,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
continue;
}
pw.print(prefix);
- pw.println("SoftInputShowHideHistory #" + sSequenceNumber.getAndIncrement() + ":");
+ pw.println("SoftInputShowHideHistory #" + entry.mSequenceNumber + ":");
pw.print(prefix);
pw.println(" time=" + dataFormat.format(new Date(entry.mWallTime))
diff --git a/services/core/java/com/android/server/location/AppOpsHelper.java b/services/core/java/com/android/server/location/AppOpsHelper.java
index cb64c50bf11d..c598fb1dbe26 100644
--- a/services/core/java/com/android/server/location/AppOpsHelper.java
+++ b/services/core/java/com/android/server/location/AppOpsHelper.java
@@ -19,8 +19,8 @@ package com.android.server.location;
import static android.app.AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION;
import static android.app.AppOpsManager.OP_MONITOR_LOCATION;
-import static com.android.server.LocationManagerService.D;
-import static com.android.server.LocationManagerService.TAG;
+import static com.android.server.location.LocationManagerService.D;
+import static com.android.server.location.LocationManagerService.TAG;
import android.annotation.Nullable;
import android.app.AppOpsManager;
diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/location/LocationManagerService.java
index 7f25de6b3470..4f8708a7599a 100644
--- a/services/core/java/com/android/server/LocationManagerService.java
+++ b/services/core/java/com/android/server/location/LocationManagerService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.server;
+package com.android.server.location;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
@@ -36,6 +36,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
+import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -91,27 +92,14 @@ import com.android.internal.location.ProviderRequest;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
-import com.android.server.location.AbstractLocationProvider;
+import com.android.server.FgThread;
+import com.android.server.LocalServices;
+import com.android.server.PendingIntentUtils;
+import com.android.server.SystemService;
import com.android.server.location.AbstractLocationProvider.State;
-import com.android.server.location.AppForegroundHelper;
-import com.android.server.location.AppOpsHelper;
-import com.android.server.location.CallerIdentity;
import com.android.server.location.CallerIdentity.PermissionLevel;
-import com.android.server.location.GeocoderProxy;
-import com.android.server.location.GeofenceManager;
-import com.android.server.location.GeofenceProxy;
-import com.android.server.location.HardwareActivityRecognitionProxy;
-import com.android.server.location.LocationFudger;
-import com.android.server.location.LocationProviderProxy;
-import com.android.server.location.LocationRequestStatistics;
import com.android.server.location.LocationRequestStatistics.PackageProviderKey;
import com.android.server.location.LocationRequestStatistics.PackageStatistics;
-import com.android.server.location.LocationUsageLogger;
-import com.android.server.location.MockProvider;
-import com.android.server.location.MockableLocationProvider;
-import com.android.server.location.PassiveProvider;
-import com.android.server.location.SettingsHelper;
-import com.android.server.location.UserInfoHelper;
import com.android.server.location.UserInfoHelper.UserListener;
import com.android.server.location.gnss.GnssManagerService;
import com.android.server.pm.permission.PermissionManagerServiceInternal;
@@ -1620,8 +1608,8 @@ public class LocationManagerService extends ILocationManager.Stub {
// For now, make sure callers have supplied an attribution tag for use with
// AppOpsManager. This might be relaxed in the future.
final List<WorkChain> workChains = workSource.getWorkChains();
- return workChains != null && !workChains.isEmpty() &&
- workChains.get(0).getAttributionTag() != null;
+ return workChains != null && !workChains.isEmpty()
+ && workChains.get(0).getAttributionTag() != null;
}
}
@@ -1840,6 +1828,9 @@ public class LocationManagerService extends ILocationManager.Stub {
if (request == null) {
request = DEFAULT_LOCATION_REQUEST;
}
+ if (listenerId == null && intent != null) {
+ listenerId = AppOpsManager.toReceiverId(intent);
+ }
CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, featureId,
listenerId);
@@ -2106,7 +2097,8 @@ public class LocationManagerService extends ILocationManager.Stub {
request = DEFAULT_LOCATION_REQUEST;
}
- CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, featureId);
+ CallerIdentity identity = CallerIdentity.fromBinder(mContext, packageName, featureId,
+ AppOpsManager.toReceiverId(intent));
identity.enforceLocationPermission();
Objects.requireNonNull(intent);
diff --git a/services/core/java/com/android/server/LocationManagerServiceUtils.java b/services/core/java/com/android/server/location/LocationManagerServiceUtils.java
index 9d0fe5e936bb..c33a70662cb5 100644
--- a/services/core/java/com/android/server/LocationManagerServiceUtils.java
+++ b/services/core/java/com/android/server/location/LocationManagerServiceUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2020 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.
@@ -14,15 +14,13 @@
* limitations under the License.
*/
-package com.android.server;
+package com.android.server.location;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.IBinder;
import android.os.RemoteException;
-import com.android.server.location.CallerIdentity;
-
import java.util.NoSuchElementException;
import java.util.function.Consumer;
diff --git a/services/core/java/com/android/server/location/LocationUsageLogger.java b/services/core/java/com/android/server/location/LocationUsageLogger.java
index 93e19df01cf3..b325deb786d6 100644
--- a/services/core/java/com/android/server/location/LocationUsageLogger.java
+++ b/services/core/java/com/android/server/location/LocationUsageLogger.java
@@ -16,7 +16,7 @@
package com.android.server.location;
-import static com.android.server.LocationManagerService.TAG;
+import static com.android.server.location.LocationManagerService.TAG;
import android.app.ActivityManager;
import android.location.Geofence;
diff --git a/services/core/java/com/android/server/location/SettingsHelper.java b/services/core/java/com/android/server/location/SettingsHelper.java
index 7ab258c29b46..cbb06b86a291 100644
--- a/services/core/java/com/android/server/location/SettingsHelper.java
+++ b/services/core/java/com/android/server/location/SettingsHelper.java
@@ -26,8 +26,8 @@ import static android.provider.Settings.Secure.LOCATION_COARSE_ACCURACY_M;
import static android.provider.Settings.Secure.LOCATION_MODE;
import static android.provider.Settings.Secure.LOCATION_MODE_OFF;
-import static com.android.server.LocationManagerService.D;
-import static com.android.server.LocationManagerService.TAG;
+import static com.android.server.location.LocationManagerService.D;
+import static com.android.server.location.LocationManagerService.TAG;
import android.app.ActivityManager;
import android.content.Context;
diff --git a/services/core/java/com/android/server/location/UserInfoHelper.java b/services/core/java/com/android/server/location/UserInfoHelper.java
index 28f3f476847b..a3dcc40bdf2d 100644
--- a/services/core/java/com/android/server/location/UserInfoHelper.java
+++ b/services/core/java/com/android/server/location/UserInfoHelper.java
@@ -18,8 +18,8 @@ package com.android.server.location;
import static android.os.UserManager.DISALLOW_SHARE_LOCATION;
-import static com.android.server.LocationManagerService.D;
-import static com.android.server.LocationManagerService.TAG;
+import static com.android.server.location.LocationManagerService.D;
+import static com.android.server.location.LocationManagerService.TAG;
import android.annotation.IntDef;
import android.annotation.Nullable;
diff --git a/services/core/java/com/android/server/location/gnss/GnssManagerService.java b/services/core/java/com/android/server/location/gnss/GnssManagerService.java
index 711f45cb7d28..3c509c380374 100644
--- a/services/core/java/com/android/server/location/gnss/GnssManagerService.java
+++ b/services/core/java/com/android/server/location/gnss/GnssManagerService.java
@@ -46,11 +46,11 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
-import com.android.server.LocationManagerServiceUtils.LinkedListener;
-import com.android.server.LocationManagerServiceUtils.LinkedListenerBase;
import com.android.server.location.AppForegroundHelper;
import com.android.server.location.AppOpsHelper;
import com.android.server.location.CallerIdentity;
+import com.android.server.location.LocationManagerServiceUtils.LinkedListener;
+import com.android.server.location.LocationManagerServiceUtils.LinkedListenerBase;
import com.android.server.location.LocationUsageLogger;
import com.android.server.location.RemoteListenerHelper;
import com.android.server.location.SettingsHelper;
diff --git a/services/core/java/com/android/server/locksettings/LockSettingsService.java b/services/core/java/com/android/server/locksettings/LockSettingsService.java
index 9297a43b04aa..7972f247b46d 100644
--- a/services/core/java/com/android/server/locksettings/LockSettingsService.java
+++ b/services/core/java/com/android/server/locksettings/LockSettingsService.java
@@ -366,10 +366,15 @@ public class LockSettingsService extends ILockSettings.Stub {
if (mStorage.hasChildProfileLock(managedUserId)) {
return;
}
- // Do not tie it to parent when parent does not have a screen lock
+ // If parent does not have a screen lock, simply clear credential from the managed profile,
+ // to maintain the invariant that unified profile should always have the same secure state
+ // as its parent.
final int parentId = mUserManager.getProfileParent(managedUserId).id;
- if (!isUserSecure(parentId)) {
- if (DEBUG) Slog.v(TAG, "Parent does not have a screen lock");
+ if (!isUserSecure(parentId) && !managedUserPassword.isNone()) {
+ if (DEBUG) Slog.v(TAG, "Parent does not have a screen lock but profile has one");
+
+ setLockCredentialInternal(LockscreenCredential.createNone(), managedUserPassword,
+ managedUserId, /* isLockTiedToParent= */ true);
return;
}
// Do not tie when the parent has no SID (but does have a screen lock).
@@ -3161,6 +3166,21 @@ public class LockSettingsService extends ILockSettings.Stub {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(timestamp));
}
+ private static String credentialTypeToString(int credentialType) {
+ switch (credentialType) {
+ case CREDENTIAL_TYPE_NONE:
+ return "None";
+ case CREDENTIAL_TYPE_PATTERN:
+ return "Pattern";
+ case CREDENTIAL_TYPE_PIN:
+ return "Pin";
+ case CREDENTIAL_TYPE_PASSWORD:
+ return "Password";
+ default:
+ return "Unknown " + credentialType;
+ }
+ }
+
@Override
protected void dump(FileDescriptor fd, PrintWriter printWriter, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, printWriter)) return;
@@ -3192,7 +3212,8 @@ public class LockSettingsService extends ILockSettings.Stub {
// It's OK to dump the password type since anyone with physical access can just
// observe it from the keyguard directly.
pw.println("Quality: " + getKeyguardStoredQuality(userId));
- pw.println("CredentialType: " + getCredentialTypeInternal(userId));
+ pw.println("CredentialType: " + credentialTypeToString(
+ getCredentialTypeInternal(userId)));
pw.println("SeparateChallenge: " + getSeparateProfileChallengeEnabledInternal(userId));
pw.println(String.format("Metrics: %s",
getUserPasswordMetrics(userId) != null ? "known" : "unknown"));
diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java
index d8264b36256d..f7d0d4ee16eb 100644
--- a/services/core/java/com/android/server/net/NetworkStatsService.java
+++ b/services/core/java/com/android/server/net/NetworkStatsService.java
@@ -46,7 +46,6 @@ import static android.net.NetworkStats.UID_ALL;
import static android.net.NetworkStatsHistory.FIELD_ALL;
import static android.net.NetworkTemplate.buildTemplateMobileWildcard;
import static android.net.NetworkTemplate.buildTemplateWifiWildcard;
-import static android.net.NetworkTemplate.getCollapsedRatType;
import static android.net.TrafficStats.KB_IN_BYTES;
import static android.net.TrafficStats.MB_IN_BYTES;
import static android.os.Trace.TRACE_TAG_NETWORK;
@@ -67,9 +66,6 @@ import static android.provider.Settings.Global.NETSTATS_UID_TAG_BUCKET_DURATION;
import static android.provider.Settings.Global.NETSTATS_UID_TAG_DELETE_AGE;
import static android.provider.Settings.Global.NETSTATS_UID_TAG_PERSIST_BYTES;
import static android.provider.Settings.Global.NETSTATS_UID_TAG_ROTATE_AGE;
-import static android.telephony.PhoneStateListener.LISTEN_NONE;
-import static android.telephony.PhoneStateListener.LISTEN_SERVICE_STATE;
-import static android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN;
import static android.text.format.DateUtils.DAY_IN_MILLIS;
import static android.text.format.DateUtils.HOUR_IN_MILLIS;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
@@ -133,9 +129,7 @@ import android.provider.Settings.Global;
import android.service.NetworkInterfaceProto;
import android.service.NetworkStatsServiceDumpProto;
import android.telephony.PhoneStateListener;
-import android.telephony.ServiceState;
import android.telephony.SubscriptionPlan;
-import android.telephony.TelephonyManager;
import android.text.format.DateUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -206,7 +200,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private final NetworkStatsFactory mStatsFactory;
private final AlarmManager mAlarmManager;
private final Clock mClock;
- private final TelephonyManager mTeleManager;
private final NetworkStatsSettings mSettings;
private final NetworkStatsObservers mStatsObservers;
@@ -352,6 +345,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
@NonNull
private final Dependencies mDeps;
+ @NonNull
+ private final NetworkStatsSubscriptionsMonitor mNetworkStatsSubscriptionsMonitor;
+
private static @NonNull File getDefaultSystemDir() {
return new File(Environment.getDataDirectory(), "system");
}
@@ -401,8 +397,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
PowerManager.WakeLock wakeLock =
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
- NetworkStatsService service = new NetworkStatsService(context, networkManager, alarmManager,
- wakeLock, getDefaultClock(), context.getSystemService(TelephonyManager.class),
+ final NetworkStatsService service = new NetworkStatsService(context, networkManager,
+ alarmManager, wakeLock, getDefaultClock(),
new DefaultNetworkStatsSettings(context), new NetworkStatsFactory(),
new NetworkStatsObservers(), getDefaultSystemDir(), getDefaultBaseDir(),
new Dependencies());
@@ -416,16 +412,15 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
@VisibleForTesting
NetworkStatsService(Context context, INetworkManagementService networkManager,
AlarmManager alarmManager, PowerManager.WakeLock wakeLock, Clock clock,
- TelephonyManager teleManager, NetworkStatsSettings settings,
- NetworkStatsFactory factory, NetworkStatsObservers statsObservers, File systemDir,
- File baseDir, @NonNull Dependencies deps) {
+ NetworkStatsSettings settings, NetworkStatsFactory factory,
+ NetworkStatsObservers statsObservers, File systemDir, File baseDir,
+ @NonNull Dependencies deps) {
mContext = Objects.requireNonNull(context, "missing Context");
mNetworkManager = Objects.requireNonNull(networkManager,
- "missing INetworkManagementService");
+ "missing INetworkManagementService");
mAlarmManager = Objects.requireNonNull(alarmManager, "missing AlarmManager");
mClock = Objects.requireNonNull(clock, "missing Clock");
mSettings = Objects.requireNonNull(settings, "missing NetworkStatsSettings");
- mTeleManager = Objects.requireNonNull(teleManager, "missing TelephonyManager");
mWakeLock = Objects.requireNonNull(wakeLock, "missing WakeLock");
mStatsFactory = Objects.requireNonNull(factory, "missing factory");
mStatsObservers = Objects.requireNonNull(statsObservers, "missing NetworkStatsObservers");
@@ -437,7 +432,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
final HandlerThread handlerThread = mDeps.makeHandlerThread();
handlerThread.start();
mHandler = new NetworkStatsHandler(handlerThread.getLooper());
- mPhoneListener = new NetworkTypeListener(new HandlerExecutor(mHandler));
+ mNetworkStatsSubscriptionsMonitor = deps.makeSubscriptionsMonitor(mContext,
+ new HandlerExecutor(mHandler), this);
}
/**
@@ -453,6 +449,19 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
public HandlerThread makeHandlerThread() {
return new HandlerThread(TAG);
}
+
+ /**
+ * Create a {@link NetworkStatsSubscriptionsMonitor}, can be used to monitor RAT change
+ * event in NetworkStatsService.
+ */
+ @NonNull
+ public NetworkStatsSubscriptionsMonitor makeSubscriptionsMonitor(@NonNull Context context,
+ @NonNull Executor executor, @NonNull NetworkStatsService service) {
+ // TODO: Update RatType passively in NSS, instead of querying into the monitor
+ // when forceUpdateIface.
+ return new NetworkStatsSubscriptionsMonitor(context, executor, (subscriberId, type) ->
+ service.handleOnCollapsedRatTypeChanged());
+ }
}
private void registerLocalService() {
@@ -517,11 +526,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, currentRealtime,
mSettings.getPollInterval(), pollIntent);
- // TODO: 1. listen to changes from all subscriptions.
- // 2. listen to settings changed to support dynamically enable/disable.
+ // TODO: listen to settings changed to support dynamically enable/disable.
// watch for networkType changes
if (!mSettings.getCombineSubtypeEnabled()) {
- mTeleManager.listen(mPhoneListener, LISTEN_SERVICE_STATE);
+ mNetworkStatsSubscriptionsMonitor.start();
}
registerGlobalAlert();
@@ -544,7 +552,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
mContext.unregisterReceiver(mUserReceiver);
mContext.unregisterReceiver(mShutdownReceiver);
- mTeleManager.listen(mPhoneListener, LISTEN_NONE);
+ if (!mSettings.getCombineSubtypeEnabled()) {
+ mNetworkStatsSubscriptionsMonitor.stop();
+ }
final long currentTime = mClock.millis();
@@ -1197,35 +1207,14 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
};
/**
- * Receiver that watches for {@link TelephonyManager} changes, such as
- * transitioning between Radio Access Technology(RAT) types.
+ * Handle collapsed RAT type changed event.
*/
- @NonNull
- private final NetworkTypeListener mPhoneListener;
-
- class NetworkTypeListener extends PhoneStateListener {
- private volatile int mLastCollapsedRatType = NETWORK_TYPE_UNKNOWN;
-
- NetworkTypeListener(@NonNull Executor executor) {
- super(executor);
- }
-
- @Override
- public void onServiceStateChanged(@NonNull ServiceState ss) {
- final int networkType = ss.getDataNetworkType();
- final int collapsedRatType = getCollapsedRatType(networkType);
- if (collapsedRatType == mLastCollapsedRatType) return;
-
- if (LOGD) {
- Log.d(TAG, "subtype changed for mobile: "
- + mLastCollapsedRatType + " -> " + collapsedRatType);
- }
- // Protect service from frequently updating. Remove pending messages if any.
- mHandler.removeMessages(MSG_UPDATE_IFACES);
- mLastCollapsedRatType = collapsedRatType;
- mHandler.sendMessageDelayed(
- mHandler.obtainMessage(MSG_UPDATE_IFACES), mSettings.getPollDelay());
- }
+ @VisibleForTesting
+ public void handleOnCollapsedRatTypeChanged() {
+ // Protect service from frequently updating. Remove pending messages if any.
+ mHandler.removeMessages(MSG_UPDATE_IFACES);
+ mHandler.sendMessageDelayed(
+ mHandler.obtainMessage(MSG_UPDATE_IFACES), mSettings.getPollDelay());
}
private void updateIfaces(
@@ -1352,8 +1341,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
return 0;
}
- // TODO: return different subType for different subscriptions.
- return mPhoneListener.mLastCollapsedRatType;
+ return mNetworkStatsSubscriptionsMonitor.getRatTypeForSubscriberId(state.subscriberId);
}
private static <K> NetworkIdentitySet findOrCreateNetworkIdentitySet(
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 54efe543a29f..8eb41adc1585 100755
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -108,6 +108,7 @@ import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
+import android.annotation.UserIdInt;
import android.annotation.WorkerThread;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
@@ -156,6 +157,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ParceledListSlice;
import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutServiceInternal;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.database.ContentObserver;
@@ -220,6 +222,7 @@ import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
+import android.util.SparseArrayMap;
import android.util.StatsEvent;
import android.util.Xml;
import android.util.proto.ProtoOutputStream;
@@ -291,6 +294,7 @@ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
@@ -528,13 +532,15 @@ public class NotificationManagerService extends SystemService {
private NotificationRecordLogger mNotificationRecordLogger;
private InstanceIdSequence mNotificationInstanceIdSequence;
- private static class Archive {
+ static class Archive {
+ final SparseArray<Boolean> mEnabled;
final int mBufferSize;
- final ArrayDeque<Pair<StatusBarNotification, Integer>> mBuffer;
+ final LinkedList<Pair<StatusBarNotification, Integer>> mBuffer;
public Archive(int size) {
mBufferSize = size;
- mBuffer = new ArrayDeque<>(mBufferSize);
+ mBuffer = new LinkedList<>();
+ mEnabled = new SparseArray<>();
}
public String toString() {
@@ -547,7 +553,10 @@ public class NotificationManagerService extends SystemService {
return sb.toString();
}
- public void record(StatusBarNotification nr, int reason) {
+ public void record(StatusBarNotification sbn, int reason) {
+ if (!mEnabled.get(sbn.getNormalizedUserId(), false)) {
+ return;
+ }
if (mBuffer.size() == mBufferSize) {
mBuffer.removeFirst();
}
@@ -555,7 +564,7 @@ public class NotificationManagerService extends SystemService {
// We don't want to store the heavy bits of the notification in the archive,
// but other clients in the system process might be using the object, so we
// store a (lightened) copy.
- mBuffer.addLast(new Pair<>(nr.cloneLight(), reason));
+ mBuffer.addLast(new Pair<>(sbn.cloneLight(), reason));
}
public Iterator<Pair<StatusBarNotification, Integer>> descendingIterator() {
@@ -577,6 +586,17 @@ public class NotificationManagerService extends SystemService {
return a.toArray(new StatusBarNotification[a.size()]);
}
+ public void updateHistoryEnabled(@UserIdInt int userId, boolean enabled) {
+ mEnabled.put(userId, enabled);
+
+ if (!enabled) {
+ for (int i = mBuffer.size() - 1; i >= 0; i--) {
+ if (userId == mBuffer.get(i).first.getNormalizedUserId()) {
+ mBuffer.remove(i);
+ }
+ }
+ }
+ }
}
void loadDefaultApprovedServices(int userId) {
@@ -1638,6 +1658,9 @@ public class NotificationManagerService extends SystemService {
= Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE);
private final Uri NOTIFICATION_RATE_LIMIT_URI
= Settings.Global.getUriFor(Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE);
+ private final Uri NOTIFICATION_HISTORY_ENABLED
+ = Settings.Secure.getUriFor(Settings.Secure.NOTIFICATION_HISTORY_ENABLED);
+
SettingsObserver(Handler handler) {
super(handler);
@@ -1653,10 +1676,12 @@ public class NotificationManagerService extends SystemService {
false, this, UserHandle.USER_ALL);
resolver.registerContentObserver(NOTIFICATION_BUBBLES_URI,
false, this, UserHandle.USER_ALL);
+ resolver.registerContentObserver(NOTIFICATION_HISTORY_ENABLED,
+ false, this, UserHandle.USER_ALL);
update(null);
}
- @Override public void onChange(boolean selfChange, Uri uri) {
+ @Override public void onChange(boolean selfChange, Uri uri, int userId) {
update(uri);
}
@@ -1681,6 +1706,14 @@ public class NotificationManagerService extends SystemService {
if (uri == null || NOTIFICATION_BUBBLES_URI.equals(uri)) {
mPreferencesHelper.updateBubblesEnabled();
}
+ if (uri == null || NOTIFICATION_HISTORY_ENABLED.equals(uri)) {
+ final IntArray userIds = mUserProfiles.getCurrentProfileIds();
+
+ for (int i = 0; i < userIds.size(); i++) {
+ mArchive.updateHistoryEnabled(userIds.get(i), Settings.Secure.getInt(resolver,
+ Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0) == 1);
+ }
+ }
}
}
@@ -1959,7 +1992,8 @@ public class NotificationManagerService extends SystemService {
mPackageManagerClient,
mRankingHandler,
mZenModeHelper,
- new NotificationChannelLoggerImpl());
+ new NotificationChannelLoggerImpl(),
+ mAppOps);
mRankingHelper = new RankingHelper(getContext(),
mRankingHandler,
mPreferencesHelper,
@@ -2300,7 +2334,8 @@ public class NotificationManagerService extends SystemService {
mRoleObserver.init();
LauncherApps launcherApps =
(LauncherApps) getContext().getSystemService(Context.LAUNCHER_APPS_SERVICE);
- mShortcutHelper = new ShortcutHelper(launcherApps, mShortcutListener);
+ mShortcutHelper = new ShortcutHelper(launcherApps, mShortcutListener, getLocalService(
+ ShortcutServiceInternal.class));
BubbleExtractor bubbsExtractor = mRankingHelper.findExtractor(BubbleExtractor.class);
if (bubbsExtractor != null) {
bubbsExtractor.setShortcutHelper(mShortcutHelper);
diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java
index 192df4139b37..2bbbffc203f4 100644
--- a/services/core/java/com/android/server/notification/NotificationRecord.java
+++ b/services/core/java/com/android/server/notification/NotificationRecord.java
@@ -590,6 +590,8 @@ public final class NotificationRecord {
pw.println(prefix + "snoozeCriteria=" + TextUtils.join(",", getSnoozeCriteria()));
}
pw.println(prefix + "mAdjustments=" + mAdjustments);
+ pw.println(prefix + "shortcut=" + notification.getShortcutId()
+ + " found valid? " + (mShortcutInfo != null));
}
@Override
diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java
index b3d373ffab3a..d432fc83b52a 100644
--- a/services/core/java/com/android/server/notification/PreferencesHelper.java
+++ b/services/core/java/com/android/server/notification/PreferencesHelper.java
@@ -16,7 +16,9 @@
package com.android.server.notification;
+import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
import static android.app.NotificationChannel.PLACEHOLDER_CONVERSATION_ID;
+import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL;
import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
@@ -30,6 +32,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
+import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
@@ -79,7 +82,9 @@ import java.util.concurrent.ConcurrentHashMap;
public class PreferencesHelper implements RankingConfig {
private static final String TAG = "NotificationPrefHelper";
- private static final int XML_VERSION = 1;
+ private static final int XML_VERSION = 2;
+ /** What version to check to do the upgrade for bubbles. */
+ private static final int XML_VERSION_BUBBLES_UPGRADE = 1;
private static final int UNKNOWN_UID = UserHandle.USER_NULL;
private static final String NON_BLOCKABLE_CHANNEL_DELIM = ":";
@@ -151,6 +156,7 @@ public class PreferencesHelper implements RankingConfig {
private final RankingHandler mRankingHandler;
private final ZenModeHelper mZenModeHelper;
private final NotificationChannelLogger mNotificationChannelLogger;
+ private final AppOpsManager mAppOps;
private SparseBooleanArray mBadgingEnabled;
private boolean mBubblesEnabledGlobally = DEFAULT_GLOBAL_ALLOW_BUBBLE;
@@ -167,12 +173,14 @@ public class PreferencesHelper implements RankingConfig {
}
public PreferencesHelper(Context context, PackageManager pm, RankingHandler rankingHandler,
- ZenModeHelper zenHelper, NotificationChannelLogger notificationChannelLogger) {
+ ZenModeHelper zenHelper, NotificationChannelLogger notificationChannelLogger,
+ AppOpsManager appOpsManager) {
mContext = context;
mZenModeHelper = zenHelper;
mRankingHandler = rankingHandler;
mPm = pm;
mNotificationChannelLogger = notificationChannelLogger;
+ mAppOps = appOpsManager;
// STOPSHIP (b/142218092) this should be removed before ship
if (!wasBadgingForcedTrue(context)) {
@@ -195,6 +203,15 @@ public class PreferencesHelper implements RankingConfig {
if (type != XmlPullParser.START_TAG) return;
String tag = parser.getName();
if (!TAG_RANKING.equals(tag)) return;
+
+ boolean upgradeForBubbles = false;
+ if (parser.getAttributeCount() > 0) {
+ String attribute = parser.getAttributeName(0);
+ if (ATT_VERSION.equals(attribute)) {
+ int xmlVersion = Integer.parseInt(parser.getAttributeValue(0));
+ upgradeForBubbles = xmlVersion == XML_VERSION_BUBBLES_UPGRADE;
+ }
+ }
synchronized (mPackagePreferences) {
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
tag = parser.getName();
@@ -220,6 +237,16 @@ public class PreferencesHelper implements RankingConfig {
}
}
boolean skipWarningLogged = false;
+ boolean hasSAWPermission = false;
+ if (upgradeForBubbles) {
+ hasSAWPermission = mAppOps.noteOpNoThrow(
+ OP_SYSTEM_ALERT_WINDOW, uid, name, null,
+ "check-notif-bubble") == AppOpsManager.MODE_ALLOWED;
+ }
+ int bubblePref = hasSAWPermission
+ ? BUBBLE_PREFERENCE_ALL
+ : XmlUtils.readIntAttribute(parser, ATT_ALLOW_BUBBLE,
+ DEFAULT_BUBBLE_PREFERENCE);
PackagePreferences r = getOrCreatePackagePreferencesLocked(
name, userId, uid,
@@ -231,8 +258,7 @@ public class PreferencesHelper implements RankingConfig {
parser, ATT_VISIBILITY, DEFAULT_VISIBILITY),
XmlUtils.readBooleanAttribute(
parser, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE),
- XmlUtils.readIntAttribute(
- parser, ATT_ALLOW_BUBBLE, DEFAULT_BUBBLE_PREFERENCE));
+ bubblePref);
r.importance = XmlUtils.readIntAttribute(
parser, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
r.priority = XmlUtils.readIntAttribute(
diff --git a/services/core/java/com/android/server/notification/ShortcutHelper.java b/services/core/java/com/android/server/notification/ShortcutHelper.java
index f1ce3a7d9f48..1d4843822931 100644
--- a/services/core/java/com/android/server/notification/ShortcutHelper.java
+++ b/services/core/java/com/android/server/notification/ShortcutHelper.java
@@ -21,11 +21,15 @@ import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED;
import android.annotation.NonNull;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.LauncherApps;
import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutServiceInternal;
import android.os.Binder;
import android.os.Handler;
import android.os.UserHandle;
+import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
@@ -38,6 +42,7 @@ import java.util.List;
* Helper for querying shortcuts.
*/
class ShortcutHelper {
+ private static final String TAG = "ShortcutHelper";
/**
* Listener to call when a shortcut we're tracking has been removed.
@@ -48,6 +53,8 @@ class ShortcutHelper {
private LauncherApps mLauncherAppsService;
private ShortcutListener mShortcutListener;
+ private ShortcutServiceInternal mShortcutServiceInternal;
+ private IntentFilter mSharingFilter;
// Key: packageName Value: <shortcutId, notifId>
private HashMap<String, HashMap<String, String>> mActiveShortcutBubbles = new HashMap<>();
@@ -111,9 +118,17 @@ class ShortcutHelper {
}
};
- ShortcutHelper(LauncherApps launcherApps, ShortcutListener listener) {
+ ShortcutHelper(LauncherApps launcherApps, ShortcutListener listener,
+ ShortcutServiceInternal shortcutServiceInternal) {
mLauncherAppsService = launcherApps;
mShortcutListener = listener;
+ mSharingFilter = new IntentFilter();
+ try {
+ mSharingFilter.addDataType("*/*");
+ } catch (IntentFilter.MalformedMimeTypeException e) {
+ Slog.e(TAG, "Bad mime type", e);
+ }
+ mShortcutServiceInternal = shortcutServiceInternal;
}
@VisibleForTesting
@@ -121,6 +136,11 @@ class ShortcutHelper {
mLauncherAppsService = launcherApps;
}
+ @VisibleForTesting
+ void setShortcutServiceInternal(ShortcutServiceInternal shortcutServiceInternal) {
+ mShortcutServiceInternal = shortcutServiceInternal;
+ }
+
/**
* Only returns shortcut info if it's found and if it's {@link ShortcutInfo#isLongLived()}.
*/
@@ -141,7 +161,14 @@ class ShortcutHelper {
ShortcutInfo info = shortcuts != null && shortcuts.size() > 0
? shortcuts.get(0)
: null;
- return info != null && info.isLongLived() ? info : null;
+ if (info == null || !info.isLongLived() || !info.isEnabled()) {
+ return null;
+ }
+ if (mShortcutServiceInternal.isSharingShortcut(user.getIdentifier(),
+ "android", packageName, shortcutId, user.getIdentifier(), mSharingFilter)) {
+ return info;
+ }
+ return null;
} finally {
Binder.restoreCallingIdentity(token);
}
diff --git a/services/core/java/com/android/server/pm/BackgroundDexOptService.java b/services/core/java/com/android/server/pm/BackgroundDexOptService.java
index dab4bfd4df5a..5415967c3bdc 100644
--- a/services/core/java/com/android/server/pm/BackgroundDexOptService.java
+++ b/services/core/java/com/android/server/pm/BackgroundDexOptService.java
@@ -17,6 +17,7 @@
package com.android.server.pm;
import static com.android.server.pm.PackageManagerService.DEBUG_DEXOPT;
+import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
import android.annotation.Nullable;
import android.app.job.JobInfo;
@@ -434,7 +435,7 @@ public class BackgroundDexOptService extends JobService {
| DexoptOptions.DEXOPT_DOWNGRADE;
long package_size_before = getPackageSize(pm, pkg);
- if (isForPrimaryDex) {
+ if (isForPrimaryDex || PLATFORM_PACKAGE_NAME.equals(pkg)) {
// This applies for system apps or if packages location is not a directory, i.e.
// monolithic install.
if (!pm.canHaveOatDir(pkg)) {
@@ -486,7 +487,9 @@ public class BackgroundDexOptService extends JobService {
| DexoptOptions.DEXOPT_BOOT_COMPLETE
| DexoptOptions.DEXOPT_IDLE_BACKGROUND_JOB;
- return isForPrimaryDex
+ // System server share the same code path as primary dex files.
+ // PackageManagerService will select the right optimization path for it.
+ return (isForPrimaryDex || PLATFORM_PACKAGE_NAME.equals(pkg))
? performDexOptPrimary(pm, pkg, reason, dexoptFlags)
: performDexOptSecondary(pm, pkg, reason, dexoptFlags);
}
diff --git a/services/core/java/com/android/server/pm/PackageDexOptimizer.java b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
index 65b7cf3eabd1..1951e7417b2c 100644
--- a/services/core/java/com/android/server/pm/PackageDexOptimizer.java
+++ b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
@@ -32,6 +32,7 @@ import static com.android.server.pm.Installer.DEXOPT_STORAGE_CE;
import static com.android.server.pm.Installer.DEXOPT_STORAGE_DE;
import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
import static com.android.server.pm.InstructionSets.getDexCodeInstructionSets;
+import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
import static com.android.server.pm.PackageManagerService.WATCHDOG_TIMEOUT;
import static com.android.server.pm.PackageManagerServiceCompilerMapping.getReasonName;
@@ -115,7 +116,9 @@ public class PackageDexOptimizer {
static boolean canOptimizePackage(AndroidPackage pkg) {
// We do not dexopt a package with no code.
- if (!pkg.isHasCode()) {
+ // Note that the system package is marked as having no code, however we can
+ // still optimize it via dexoptSystemServerPath.
+ if (!PLATFORM_PACKAGE_NAME.equals(pkg.getPackageName()) && !pkg.isHasCode()) {
return false;
}
@@ -132,6 +135,10 @@ public class PackageDexOptimizer {
int performDexOpt(AndroidPackage pkg, @NonNull PackageSetting pkgSetting,
String[] instructionSets, CompilerStats.PackageStats packageStats,
PackageDexUsage.PackageUseInfo packageUseInfo, DexoptOptions options) {
+ if (PLATFORM_PACKAGE_NAME.equals(pkg.getPackageName())) {
+ throw new IllegalArgumentException("System server dexopting should be done via "
+ + " DexManager and PackageDexOptimizer#dexoptSystemServerPath");
+ }
if (pkg.getUid() == -1) {
throw new IllegalArgumentException("Dexopt for " + pkg.getPackageName()
+ " has invalid uid.");
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 59ac603875e2..12ee2f55e87f 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -94,6 +94,7 @@ import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.content.pm.PackageManager.RESTRICTION_NONE;
import static android.content.pm.PackageManager.UNINSTALL_REASON_UNKNOWN;
+import static android.content.pm.PackageParser.SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V4;
import static android.content.pm.PackageParser.isApkFile;
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
import static android.os.incremental.IncrementalManager.isIncrementalPath;
@@ -1820,10 +1821,12 @@ public class PackageManagerService extends IPackageManager.Stub
state.setVerifierResponse(Binder.getCallingUid(),
PackageManager.VERIFICATION_ALLOW_WITHOUT_SUFFICIENT);
broadcastPackageVerified(verificationId, originUri,
- PackageManager.VERIFICATION_ALLOW, user);
+ PackageManager.VERIFICATION_ALLOW, null, args.mDataLoaderType,
+ user);
} else {
broadcastPackageVerified(verificationId, originUri,
- PackageManager.VERIFICATION_REJECT, user);
+ PackageManager.VERIFICATION_REJECT, null, args.mDataLoaderType,
+ user);
params.setReturnCode(
PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE);
state.setVerifierResponse(Binder.getCallingUid(),
@@ -1899,7 +1902,7 @@ public class PackageManagerService extends IPackageManager.Stub
if (state.isInstallAllowed()) {
broadcastPackageVerified(verificationId, originUri,
- response.code, args.getUser());
+ response.code, null, args.mDataLoaderType, args.getUser());
} else {
params.setReturnCode(
PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE);
@@ -13575,12 +13578,17 @@ public class PackageManagerService extends IPackageManager.Stub
}
private void broadcastPackageVerified(int verificationId, Uri packageUri,
- int verificationCode, UserHandle user) {
+ int verificationCode, @Nullable String rootHashString, int dataLoaderType,
+ UserHandle user) {
final Intent intent = new Intent(Intent.ACTION_PACKAGE_VERIFIED);
intent.setDataAndType(packageUri, PACKAGE_MIME_TYPE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(PackageManager.EXTRA_VERIFICATION_ID, verificationId);
intent.putExtra(PackageManager.EXTRA_VERIFICATION_RESULT, verificationCode);
+ if (rootHashString != null) {
+ intent.putExtra(PackageManager.EXTRA_VERIFICATION_ROOT_HASH, rootHashString);
+ }
+ intent.putExtra(PackageInstaller.EXTRA_DATA_LOADER_TYPE, dataLoaderType);
mContext.sendBroadcastAsUser(intent, user,
android.Manifest.permission.PACKAGE_VERIFICATION_AGENT);
@@ -14952,8 +14960,17 @@ public class PackageManagerService extends IPackageManager.Stub
verificationState.setRequiredVerifierUid(requiredUid);
final int installerUid =
verificationInfo == null ? -1 : verificationInfo.installerUid;
- if (!origin.existing && isVerificationEnabled(pkgLite, verifierUser.getIdentifier(),
- installFlags, installerUid)) {
+ final boolean isVerificationEnabled = isVerificationEnabled(
+ pkgLite, verifierUser.getIdentifier(), installFlags, installerUid);
+ final boolean isV4Signed =
+ (mArgs.signingDetails.signatureSchemeVersion == SIGNING_BLOCK_V4);
+ final boolean isIncrementalInstall =
+ (mArgs.mDataLoaderType == DataLoaderType.INCREMENTAL);
+ // NOTE: We purposefully skip verification for only incremental installs when there's
+ // a v4 signature block. Otherwise, proceed with verification as usual.
+ if (!origin.existing
+ && isVerificationEnabled
+ && (!isIncrementalInstall || !isV4Signed)) {
final Intent verification = new Intent(
Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
verification.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
@@ -16569,7 +16586,29 @@ public class PackageManagerService extends IPackageManager.Stub
}
executePostCommitSteps(commitRequest);
} finally {
- if (!success) {
+ if (success) {
+ for (InstallRequest request : requests) {
+ final InstallArgs args = request.args;
+ if (args.mDataLoaderType != DataLoaderType.INCREMENTAL) {
+ continue;
+ }
+ if (args.signingDetails.signatureSchemeVersion != SIGNING_BLOCK_V4) {
+ continue;
+ }
+ // For incremental installs, we bypass the verifier prior to install. Now
+ // that we know the package is valid, send a notice to the verifier with
+ // the root hash of the base.apk.
+ final String baseCodePath = request.installResult.pkg.getBaseCodePath();
+ final String[] splitCodePaths = request.installResult.pkg.getSplitCodePaths();
+ final Uri originUri = Uri.fromFile(args.origin.resolvedFile);
+ final int verificationId = mPendingVerificationToken++;
+ final String rootHashString = PackageManagerServiceUtils
+ .buildVerificationRootHashString(baseCodePath, splitCodePaths);
+ broadcastPackageVerified(verificationId, originUri,
+ PackageManager.VERIFICATION_ALLOW, rootHashString,
+ args.mDataLoaderType, args.getUser());
+ }
+ } else {
for (ScanResult result : preparedScans.values()) {
if (createdAppId.getOrDefault(result.request.parsedPackage.getPackageName(),
false)) {
@@ -16911,7 +16950,6 @@ public class PackageManagerService extends IPackageManager.Stub
if (args.signingDetails != PackageParser.SigningDetails.UNKNOWN) {
parsedPackage.setSigningDetails(args.signingDetails);
} else {
- // TODO(b/136132412): skip for Incremental installation
parsedPackage.setSigningDetails(
ParsingPackageUtils.collectCertificates(parsedPackage, false /* skipVerify */));
}
diff --git a/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java b/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java
index 91afd846a9c3..5c175a6ef847 100644
--- a/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java
+++ b/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java
@@ -32,7 +32,6 @@ import android.annotation.Nullable;
import android.app.AppGlobals;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfoLite;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
@@ -40,7 +39,6 @@ import android.content.pm.PackageParser;
import android.content.pm.PackageParser.PackageParserException;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
-import android.content.pm.parsing.ParsingPackageUtils;
import android.os.Build;
import android.os.Debug;
import android.os.Environment;
@@ -50,6 +48,9 @@ import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManagerInternal;
+import android.os.incremental.IncrementalManager;
+import android.os.incremental.V4Signature;
+import android.os.incremental.V4Signature.HashingInfo;
import android.service.pm.PackageServiceDumpProto;
import android.system.ErrnoException;
import android.system.Os;
@@ -62,6 +63,7 @@ import com.android.internal.content.NativeLibraryHelper;
import com.android.internal.content.PackageHelper;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.FastPrintWriter;
+import com.android.internal.util.HexDump;
import com.android.server.EventLogTags;
import com.android.server.pm.dex.DexManager;
import com.android.server.pm.dex.PackageDexUsage;
@@ -94,8 +96,6 @@ import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
import java.util.function.Predicate;
import java.util.zip.GZIPInputStream;
@@ -943,4 +943,71 @@ public class PackageManagerServiceUtils {
Os.chmod(currentDir.getAbsolutePath(), mode);
}
}
+
+ /**
+ * Returns a string that's compatible with the verification root hash extra.
+ * @see PackageManager#EXTRA_VERIFICATION_ROOT_HASH
+ */
+ @NonNull
+ public static String buildVerificationRootHashString(@NonNull String baseFilename,
+ @Nullable String[] splitFilenameArray) {
+ final StringBuilder sb = new StringBuilder();
+ final String baseFilePath =
+ baseFilename.substring(baseFilename.lastIndexOf(File.separator) + 1);
+ sb.append(baseFilePath).append(":");
+ final byte[] baseRootHash = getRootHash(baseFilename);
+ if (baseRootHash == null) {
+ sb.append("0");
+ } else {
+ sb.append(HexDump.toHexString(baseRootHash));
+ }
+ if (splitFilenameArray == null || splitFilenameArray.length == 0) {
+ return sb.toString();
+ }
+
+ for (int i = splitFilenameArray.length - 1; i >= 0; i--) {
+ final String splitFilename = splitFilenameArray[i];
+ final String splitFilePath =
+ splitFilename.substring(splitFilename.lastIndexOf(File.separator) + 1);
+ final byte[] splitRootHash = getRootHash(splitFilename);
+ sb.append(";").append(splitFilePath).append(":");
+ if (splitRootHash == null) {
+ sb.append("0");
+ } else {
+ sb.append(HexDump.toHexString(splitRootHash));
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns the root has for the given file.
+ * <p>Otherwise, returns {@code null} if the root hash could not be found or calculated.
+ * <p>NOTE: This currently only works on files stored on the incremental file system. The
+ * eventual goal is that this hash [among others] can be retrieved for any file.
+ */
+ @Nullable
+ private static byte[] getRootHash(String filename) {
+ try {
+ final byte[] baseFileSignature =
+ IncrementalManager.unsafeGetFileSignature(filename);
+ if (baseFileSignature == null) {
+ throw new IOException("File signature not present");
+ }
+ final V4Signature signature =
+ V4Signature.readFrom(baseFileSignature);
+ if (signature.hashingInfo == null) {
+ throw new IOException("Hashing info not present");
+ }
+ final HashingInfo hashInfo =
+ HashingInfo.fromByteArray(signature.hashingInfo);
+ if (ArrayUtils.isEmpty(hashInfo.rawRootHash)) {
+ throw new IOException("Root has not present");
+ }
+ return hashInfo.rawRootHash;
+ } catch (IOException ignore) {
+ Slog.e(TAG, "ERROR: could not load root hash from incremental install");
+ }
+ return null;
+ }
}
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index 323ffcfc2a1c..fc70af4e7bd4 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -103,6 +103,7 @@ import com.android.internal.logging.MetricsLogger;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils;
import com.android.internal.widget.LockPatternUtils;
@@ -137,6 +138,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
+import java.util.concurrent.ThreadLocalRandom;
/**
* Service for {@link UserManager}.
@@ -3244,16 +3246,39 @@ public class UserManagerService extends IUserManager.Stub {
@NonNull String userType, @UserInfoFlag int flags, @UserIdInt int parentId,
boolean preCreate, @Nullable String[] disallowedPackages)
throws UserManager.CheckedUserOperationException {
+ final int nextProbableUserId = getNextAvailableId();
final TimingsTraceAndSlog t = new TimingsTraceAndSlog();
t.traceBegin("createUser-" + flags);
+ final long sessionId = logUserCreateJourneyBegin(nextProbableUserId, userType, flags);
try {
return createUserInternalUncheckedNoTracing(name, userType, flags, parentId,
preCreate, disallowedPackages, t);
} finally {
+ logUserCreateJourneyFinish(sessionId, nextProbableUserId);
t.traceEnd();
}
}
+ private long logUserCreateJourneyBegin(@UserIdInt int userId, String userType,
+ @UserInfoFlag int flags) {
+ final long sessionId = ThreadLocalRandom.current().nextLong(1, Long.MAX_VALUE);
+ // log the journey atom with the user metadata
+ FrameworkStatsLog.write(FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED, sessionId,
+ FrameworkStatsLog.USER_LIFECYCLE_JOURNEY_REPORTED__JOURNEY__USER_CREATE,
+ /* origin_user= */ -1, userId, UserManager.getUserTypeForStatsd(userType), flags);
+ // log the event atom to indicate the event start
+ FrameworkStatsLog.write(FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED, sessionId, userId,
+ FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__EVENT__CREATE_USER,
+ FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__STATE__BEGIN);
+ return sessionId;
+ }
+
+ private void logUserCreateJourneyFinish(long sessionId, @UserIdInt int userId) {
+ FrameworkStatsLog.write(FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED, sessionId, userId,
+ FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__EVENT__CREATE_USER,
+ FrameworkStatsLog.USER_LIFECYCLE_EVENT_OCCURRED__STATE__FINISH);
+ }
+
private UserInfo createUserInternalUncheckedNoTracing(@Nullable String name,
@NonNull String userType, @UserInfoFlag int flags, @UserIdInt int parentId,
boolean preCreate, @Nullable String[] disallowedPackages,
diff --git a/services/core/java/com/android/server/pm/dex/DexManager.java b/services/core/java/com/android/server/pm/dex/DexManager.java
index 6dcf71e9fbf0..f7bf1d985786 100644
--- a/services/core/java/com/android/server/pm/dex/DexManager.java
+++ b/services/core/java/com/android/server/pm/dex/DexManager.java
@@ -79,6 +79,10 @@ public class DexManager {
private static final String PROPERTY_NAME_PM_DEXOPT_PRIV_APPS_OOB_LIST =
"pm.dexopt.priv-apps-oob-list";
+ // System server cannot load executable code outside system partitions.
+ // However it can load verification data - thus we pick the "verify" compiler filter.
+ private static final String SYSTEM_SERVER_COMPILER_FILTER = "verify";
+
private final Context mContext;
// Maps package name to code locations.
@@ -443,6 +447,14 @@ public class DexManager {
* because they don't need to be compiled)..
*/
public boolean dexoptSecondaryDex(DexoptOptions options) {
+ if (PLATFORM_PACKAGE_NAME.equals(options.getPackageName())) {
+ // We could easily redirect to #dexoptSystemServer in this case. But there should be
+ // no-one calling this method directly for system server.
+ // As such we prefer to abort in this case.
+ Slog.wtf(TAG, "System server jars should be optimized with dexoptSystemServer");
+ return false;
+ }
+
PackageDexOptimizer pdo = getPackageDexOptimizer(options);
String packageName = options.getPackageName();
PackageUseInfo useInfo = getPackageUseInfoOrDefault(packageName);
@@ -501,8 +513,17 @@ public class DexManager {
return PackageDexOptimizer.DEX_OPT_FAILED;
}
- PackageDexOptimizer pdo = getPackageDexOptimizer(options);
- String packageName = options.getPackageName();
+ // Override compiler filter for system server to the expected one.
+ //
+ // We could let the caller do this every time the invoke PackageManagerServer#dexopt.
+ // However, there are a few places were this will need to be done which creates
+ // redundancy and the danger of overlooking the config (and thus generating code that will
+ // waste storage and time).
+ DexoptOptions overriddenOptions = options.overrideCompilerFilter(
+ SYSTEM_SERVER_COMPILER_FILTER);
+
+ PackageDexOptimizer pdo = getPackageDexOptimizer(overriddenOptions);
+ String packageName = overriddenOptions.getPackageName();
PackageUseInfo useInfo = getPackageUseInfoOrDefault(packageName);
if (useInfo.getDexUseInfoMap().isEmpty()) {
if (DEBUG) {
@@ -527,7 +548,7 @@ public class DexManager {
continue;
}
- int newResult = pdo.dexoptSystemServerPath(dexPath, dexUseInfo, options);
+ int newResult = pdo.dexoptSystemServerPath(dexPath, dexUseInfo, overriddenOptions);
// The end result is:
// - FAILED if any path failed,
@@ -600,6 +621,23 @@ public class DexManager {
packageName, dexUseInfo.getOwnerUserId()) || updated;
continue;
}
+
+ // Special handle system server files.
+ // We don't need an installd call because we have permissions to check if the file
+ // exists.
+ if (PLATFORM_PACKAGE_NAME.equals(packageName)) {
+ if (!Files.exists(Paths.get(dexPath))) {
+ if (DEBUG) {
+ Slog.w(TAG, "A dex file previously loaded by System Server does not exist "
+ + " anymore: " + dexPath);
+ }
+ updated = mPackageDexUsage.removeUserPackage(
+ packageName, dexUseInfo.getOwnerUserId()) || updated;
+ }
+ continue;
+ }
+
+ // This is a regular application.
ApplicationInfo info = pkg.applicationInfo;
int flags = 0;
if (info.deviceProtectedDataDir != null &&
diff --git a/services/core/java/com/android/server/pm/dex/DexoptOptions.java b/services/core/java/com/android/server/pm/dex/DexoptOptions.java
index de3c9f28218d..b453c898ded8 100644
--- a/services/core/java/com/android/server/pm/dex/DexoptOptions.java
+++ b/services/core/java/com/android/server/pm/dex/DexoptOptions.java
@@ -166,4 +166,17 @@ public final class DexoptOptions {
public int getCompilationReason() {
return mCompilationReason;
}
+
+ /**
+ * Creates a new set of DexoptOptions which are the same with the exception of the compiler
+ * filter (set to the given value).
+ */
+ public DexoptOptions overrideCompilerFilter(String newCompilerFilter) {
+ return new DexoptOptions(
+ mPackageName,
+ mCompilationReason,
+ newCompilerFilter,
+ mSplitName,
+ mFlags);
+ }
}
diff --git a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerHw2Enforcer.java b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerHw2Enforcer.java
index 870d909fbbcc..a18b690f08cd 100644
--- a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerHw2Enforcer.java
+++ b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerHw2Enforcer.java
@@ -33,7 +33,7 @@ import java.util.Map;
* This is not necessarily a strict enforcement for the HAL contract, but a place to add checks for
* common HAL malfunctions, to help track them and assist in debugging.
*
- * The class is not thread-safe.
+ * The class is thread-safe.
*/
public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
static final String TAG = "SoundTriggerHw2Enforcer";
@@ -55,7 +55,9 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
public int loadSoundModel(ISoundTriggerHw.SoundModel soundModel, Callback callback,
int cookie) {
int handle = mUnderlying.loadSoundModel(soundModel, new CallbackEnforcer(callback), cookie);
- mModelStates.put(handle, false);
+ synchronized (mModelStates) {
+ mModelStates.put(handle, false);
+ }
return handle;
}
@@ -64,27 +66,35 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
int cookie) {
int handle = mUnderlying.loadPhraseSoundModel(soundModel, new CallbackEnforcer(callback),
cookie);
- mModelStates.put(handle, false);
+ synchronized (mModelStates) {
+ mModelStates.put(handle, false);
+ }
return handle;
}
@Override
public void unloadSoundModel(int modelHandle) {
mUnderlying.unloadSoundModel(modelHandle);
- mModelStates.remove(modelHandle);
+ synchronized (mModelStates) {
+ mModelStates.remove(modelHandle);
+ }
}
@Override
public void stopRecognition(int modelHandle) {
mUnderlying.stopRecognition(modelHandle);
- mModelStates.replace(modelHandle, false);
+ synchronized (mModelStates) {
+ mModelStates.replace(modelHandle, false);
+ }
}
@Override
public void stopAllRecognitions() {
mUnderlying.stopAllRecognitions();
- for (Map.Entry<Integer, Boolean> entry : mModelStates.entrySet()) {
- entry.setValue(false);
+ synchronized (mModelStates) {
+ for (Map.Entry<Integer, Boolean> entry : mModelStates.entrySet()) {
+ entry.setValue(false);
+ }
}
}
@@ -92,7 +102,9 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
public void startRecognition(int modelHandle, RecognitionConfig config, Callback callback,
int cookie) {
mUnderlying.startRecognition(modelHandle, config, new CallbackEnforcer(callback), cookie);
- mModelStates.replace(modelHandle, true);
+ synchronized (mModelStates) {
+ mModelStates.replace(modelHandle, true);
+ }
}
@Override
@@ -142,12 +154,14 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
public void recognitionCallback(ISoundTriggerHwCallback.RecognitionEvent event,
int cookie) {
int model = event.header.model;
- if (!mModelStates.getOrDefault(model, false)) {
- Log.wtfStack(TAG, "Unexpected recognition event for model: " + model);
- }
- if (event.header.status
- != android.media.soundtrigger_middleware.RecognitionStatus.FORCED) {
- mModelStates.replace(model, false);
+ synchronized (mModelStates) {
+ if (!mModelStates.getOrDefault(model, false)) {
+ Log.wtfStack(TAG, "Unexpected recognition event for model: " + model);
+ }
+ if (event.header.status
+ != android.media.soundtrigger_middleware.RecognitionStatus.FORCED) {
+ mModelStates.replace(model, false);
+ }
}
mUnderlying.recognitionCallback(event, cookie);
}
@@ -156,12 +170,14 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
public void phraseRecognitionCallback(ISoundTriggerHwCallback.PhraseRecognitionEvent event,
int cookie) {
int model = event.common.header.model;
- if (!mModelStates.getOrDefault(model, false)) {
- Log.wtfStack(TAG, "Unexpected recognition event for model: " + model);
- }
- if (event.common.header.status
- != android.media.soundtrigger_middleware.RecognitionStatus.FORCED) {
- mModelStates.replace(model, false);
+ synchronized (mModelStates) {
+ if (!mModelStates.getOrDefault(model, false)) {
+ Log.wtfStack(TAG, "Unexpected recognition event for model: " + model);
+ }
+ if (event.common.header.status
+ != android.media.soundtrigger_middleware.RecognitionStatus.FORCED) {
+ mModelStates.replace(model, false);
+ }
}
mUnderlying.phraseRecognitionCallback(event, cookie);
}
diff --git a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareLogging.java b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareLogging.java
index 04ba6bfeb4ee..8b6ed1ff5081 100644
--- a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareLogging.java
+++ b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareLogging.java
@@ -377,11 +377,7 @@ public class SoundTriggerMiddlewareLogging implements ISoundTriggerMiddlewareInt
}
private static void printObject(@NonNull StringBuilder builder, @Nullable Object obj) {
- if (obj instanceof Parcelable) {
- ObjectPrinter.print(builder, obj, true, 16);
- } else {
- builder.append(obj.toString());
- }
+ ObjectPrinter.print(builder, obj, true, 16);
}
private static String printObject(@Nullable Object obj) {
diff --git a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java
index 23259558eeb7..bae244179346 100644
--- a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java
+++ b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java
@@ -32,9 +32,9 @@ import android.media.soundtrigger_middleware.RecognitionEvent;
import android.media.soundtrigger_middleware.RecognitionStatus;
import android.media.soundtrigger_middleware.SoundModel;
import android.media.soundtrigger_middleware.SoundTriggerModuleDescriptor;
+import android.media.soundtrigger_middleware.SoundTriggerModuleProperties;
import android.media.soundtrigger_middleware.Status;
import android.os.IBinder;
-import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceSpecificException;
import android.util.Log;
@@ -108,17 +108,26 @@ import java.util.Set;
public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddlewareInternal, Dumpable {
private static final String TAG = "SoundTriggerMiddlewareValidation";
- private enum ModuleState {
+ private enum ModuleStatus {
ALIVE,
DETACHED,
DEAD
};
+ private class ModuleState {
+ final @NonNull SoundTriggerModuleProperties properties;
+ Set<ModuleService> sessions = new HashSet<>();
+
+ private ModuleState(@NonNull SoundTriggerModuleProperties properties) {
+ this.properties = properties;
+ }
+ }
+
private Boolean mCaptureState;
private final @NonNull ISoundTriggerMiddlewareInternal mDelegate;
private final @NonNull Context mContext;
- private Map<Integer, Set<ModuleService>> mModules;
+ private Map<Integer, ModuleState> mModules;
public SoundTriggerMiddlewareValidation(
@NonNull ISoundTriggerMiddlewareInternal delegate, @NonNull Context context) {
@@ -168,7 +177,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
SoundTriggerModuleDescriptor[] result = mDelegate.listModules();
mModules = new HashMap<>(result.length);
for (SoundTriggerModuleDescriptor desc : result) {
- mModules.put(desc.handle, new HashSet<>());
+ mModules.put(desc.handle, new ModuleState(desc.properties));
}
return result;
} catch (Exception e) {
@@ -278,18 +287,21 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
@Override
public void dump(PrintWriter pw) {
synchronized (this) {
- pw.printf("Capture state is %s\n", mCaptureState == null ? "uninitialized"
+ pw.printf("Capture state is %s\n\n", mCaptureState == null ? "uninitialized"
: (mCaptureState ? "active" : "inactive"));
if (mModules != null) {
for (int handle : mModules.keySet()) {
+ final ModuleState module = mModules.get(handle);
pw.println("=========================================");
- pw.printf("Active sessions for module %d", handle);
- pw.println();
+ pw.printf("Module %d\n%s\n", handle,
+ ObjectPrinter.print(module.properties, true, 16));
pw.println("=========================================");
- for (ModuleService session : mModules.get(handle)) {
+ for (ModuleService session : module.sessions) {
session.dump(pw);
}
}
+ } else {
+ pw.println("Modules have not yet been enumerated.");
}
}
pw.println();
@@ -297,11 +309,18 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
if (mDelegate instanceof Dumpable) {
((Dumpable) mDelegate).dump(pw);
}
-
}
/** State of a sound model. */
static class ModelState {
+ ModelState(SoundModel model) {
+ this.description = ObjectPrinter.print(model, true, 16);
+ }
+
+ ModelState(PhraseSoundModel model) {
+ this.description = ObjectPrinter.print(model, true, 16);
+ }
+
/** Activity state of a sound model. */
enum Activity {
/** Model is loaded, recognition is inactive. */
@@ -313,6 +332,9 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
/** Activity state. */
Activity activityState = Activity.LOADED;
+ /** Human-readable description of the model. */
+ final String description;
+
/**
* A map of known parameter support. A missing key means we don't know yet whether the
* parameter is supported. A null value means it is known to not be supported. A non-null
@@ -375,7 +397,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
private ISoundTriggerModule mDelegate;
private @NonNull Map<Integer, ModelState> mLoadedModels = new HashMap<>();
private final int mHandle;
- private ModuleState mState = ModuleState.ALIVE;
+ private ModuleStatus mState = ModuleStatus.ALIVE;
ModuleService(int handle, @NonNull ISoundTriggerCallback callback) {
mCallback = callback;
@@ -389,7 +411,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
void attach(@NonNull ISoundTriggerModule delegate) {
mDelegate = delegate;
- mModules.get(mHandle).add(this);
+ mModules.get(mHandle).sessions.add(this);
}
@Override
@@ -401,14 +423,14 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
- if (mState == ModuleState.DETACHED) {
+ if (mState == ModuleStatus.DETACHED) {
throw new IllegalStateException("Module has been detached.");
}
// From here on, every exception isn't client's fault.
try {
int handle = mDelegate.loadModel(model);
- mLoadedModels.put(handle, new ModelState());
+ mLoadedModels.put(handle, new ModelState(model));
return handle;
} catch (Exception e) {
throw handleException(e);
@@ -425,14 +447,14 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
- if (mState == ModuleState.DETACHED) {
+ if (mState == ModuleStatus.DETACHED) {
throw new IllegalStateException("Module has been detached.");
}
// From here on, every exception isn't client's fault.
try {
int handle = mDelegate.loadPhraseModel(model);
- mLoadedModels.put(handle, new ModelState());
+ mLoadedModels.put(handle, new ModelState(model));
return handle;
} catch (Exception e) {
throw handleException(e);
@@ -448,7 +470,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
- if (mState == ModuleState.DETACHED) {
+ if (mState == ModuleStatus.DETACHED) {
throw new IllegalStateException("Module has been detached.");
}
ModelState modelState = mLoadedModels.get(
@@ -481,7 +503,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
- if (mState == ModuleState.DETACHED) {
+ if (mState == ModuleStatus.DETACHED) {
throw new IllegalStateException("Module has been detached.");
}
ModelState modelState = mLoadedModels.get(
@@ -515,7 +537,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
- if (mState == ModuleState.DETACHED) {
+ if (mState == ModuleStatus.DETACHED) {
throw new IllegalStateException("Module has been detached.");
}
ModelState modelState = mLoadedModels.get(
@@ -544,7 +566,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
- if (mState == ModuleState.DETACHED) {
+ if (mState == ModuleStatus.DETACHED) {
throw new IllegalStateException("Module has been detached.");
}
ModelState modelState = mLoadedModels.get(
@@ -572,7 +594,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
- if (mState == ModuleState.DETACHED) {
+ if (mState == ModuleStatus.DETACHED) {
throw new IllegalStateException("Module has been detached.");
}
ModelState modelState = mLoadedModels.get(
@@ -600,7 +622,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
- if (mState == ModuleState.DETACHED) {
+ if (mState == ModuleStatus.DETACHED) {
throw new IllegalStateException("Module has been detached.");
}
ModelState modelState = mLoadedModels.get(
@@ -629,7 +651,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
- if (mState == ModuleState.DETACHED) {
+ if (mState == ModuleStatus.DETACHED) {
throw new IllegalStateException("Module has been detached.");
}
ModelState modelState = mLoadedModels.get(
@@ -658,10 +680,10 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
- if (mState == ModuleState.DETACHED) {
+ if (mState == ModuleStatus.DETACHED) {
throw new IllegalStateException("Module has already been detached.");
}
- if (mState == ModuleState.ALIVE && !mLoadedModels.isEmpty()) {
+ if (mState == ModuleStatus.ALIVE && !mLoadedModels.isEmpty()) {
throw new IllegalStateException("Cannot detach while models are loaded.");
}
@@ -683,16 +705,16 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
private void detachInternal() {
try {
mDelegate.detach();
- mState = ModuleState.DETACHED;
+ mState = ModuleStatus.DETACHED;
mCallback.asBinder().unlinkToDeath(this, 0);
- mModules.get(mHandle).remove(this);
+ mModules.get(mHandle).sessions.remove(this);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
void dump(PrintWriter pw) {
- if (mState == ModuleState.ALIVE) {
+ if (mState == ModuleStatus.ALIVE) {
pw.printf("Loaded models for session %s (handle, active)", toString());
pw.println();
pw.println("-------------------------------");
@@ -700,6 +722,8 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
pw.print(entry.getKey());
pw.print('\t');
pw.print(entry.getValue().activityState.name());
+ pw.print('\t');
+ pw.print(entry.getValue().description);
pw.println();
}
} else {
@@ -762,7 +786,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
public void onModuleDied() {
synchronized (SoundTriggerMiddlewareValidation.this) {
try {
- mState = ModuleState.DEAD;
+ mState = ModuleStatus.DEAD;
mCallback.onModuleDied();
} catch (RemoteException e) {
// Dead client will be handled by binderDied() - no need to handle here.
diff --git a/services/core/java/com/android/server/wm/AccessibilityController.java b/services/core/java/com/android/server/wm/AccessibilityController.java
index 75d6a090bd3d..4fe58433ddb6 100644
--- a/services/core/java/com/android/server/wm/AccessibilityController.java
+++ b/services/core/java/com/android/server/wm/AccessibilityController.java
@@ -674,6 +674,15 @@ final class AccessibilityController {
availableBounds.op(windowBounds, Region.Op.DIFFERENCE);
}
+ // If the navigation bar window doesn't have touchable region, count
+ // navigation bar insets into nonMagnifiedBounds. It happens when
+ // navigation mode is gestural.
+ if (isUntouchableNavigationBar(windowState, mTempRegion3)) {
+ final Rect navBarInsets = getNavBarInsets(mDisplayContent);
+ nonMagnifiedBounds.op(navBarInsets, Region.Op.UNION);
+ availableBounds.op(navBarInsets, Region.Op.DIFFERENCE);
+ }
+
// Count letterbox into nonMagnifiedBounds
if (windowState.isLetterboxedForDisplayCutoutLw()) {
Region letterboxBounds = getLetterboxBounds(windowState);
@@ -1091,6 +1100,24 @@ final class AccessibilityController {
}
}
+ static boolean isUntouchableNavigationBar(WindowState windowState,
+ Region touchableRegion) {
+ if (windowState.mAttrs.type != WindowManager.LayoutParams.TYPE_NAVIGATION_BAR) {
+ return false;
+ }
+
+ // Gets the touchable region.
+ windowState.getTouchableRegion(touchableRegion);
+
+ return touchableRegion.isEmpty();
+ }
+
+ static Rect getNavBarInsets(DisplayContent displayContent) {
+ final InsetsState insetsState =
+ displayContent.getInsetsStateController().getRawInsetsState();
+ return insetsState.getSource(ITYPE_NAVIGATION_BAR).getFrame();
+ }
+
/**
* This class encapsulates the functionality related to computing the windows
* reported for accessibility purposes. These windows are all windows a sighted
@@ -1205,16 +1232,12 @@ final class AccessibilityController {
updateUnaccountedSpace(windowState, regionInScreen, unaccountedSpace,
skipRemainingWindowsForTasks);
focusedWindowAdded |= windowState.isFocused();
- } else if (isUntouchableNavigationBar(windowState)) {
+ } else if (isUntouchableNavigationBar(windowState, mTempRegion1)) {
// If this widow is navigation bar without touchable region, accounting the
// region of navigation bar inset because all touch events from this region
// would be received by launcher, i.e. this region is a un-touchable one
// for the application.
- final InsetsState insetsState =
- dc.getInsetsStateController().getRawInsetsState();
- final Rect displayFrame =
- insetsState.getSource(ITYPE_NAVIGATION_BAR).getFrame();
- unaccountedSpace.op(displayFrame, unaccountedSpace,
+ unaccountedSpace.op(getNavBarInsets(dc), unaccountedSpace,
Region.Op.REVERSE_DIFFERENCE);
}
@@ -1294,18 +1317,6 @@ final class AccessibilityController {
return false;
}
- private boolean isUntouchableNavigationBar(WindowState windowState) {
- if (windowState.mAttrs.type != WindowManager.LayoutParams.TYPE_NAVIGATION_BAR) {
- return false;
- }
-
- // Gets the touchable region.
- Region touchableRegion = mTempRegion1;
- windowState.getTouchableRegion(touchableRegion);
-
- return touchableRegion.isEmpty();
- }
-
private void updateUnaccountedSpace(WindowState windowState, Region regionInScreen,
Region unaccountedSpace, HashSet<Integer> skipRemainingWindowsForTasks) {
if (windowState.mAttrs.type
diff --git a/services/core/java/com/android/server/wm/InsetsSourceProvider.java b/services/core/java/com/android/server/wm/InsetsSourceProvider.java
index cb0d8536fe72..1ca82ceeb570 100644
--- a/services/core/java/com/android/server/wm/InsetsSourceProvider.java
+++ b/services/core/java/com/android/server/wm/InsetsSourceProvider.java
@@ -266,7 +266,7 @@ class InsetsSourceProvider {
if (getSource().getType() == ITYPE_IME) {
setClientVisible(InsetsState.getDefaultVisibility(mSource.getType()));
}
- final Transaction t = mDisplayContent.getPendingTransaction();
+ final Transaction t = mDisplayContent.mWmService.mTransactionFactory.get();
mWin.startAnimation(t, mAdapter, !mClientVisible /* hidden */,
ANIMATION_TYPE_INSETS_CONTROL, null /* animationFinishedCallback */);
final SurfaceControl leash = mAdapter.mCapturedLeash;
@@ -281,6 +281,9 @@ class InsetsSourceProvider {
t.deferTransactionUntil(mWin.getSurfaceControl(), barrier, frameNumber);
t.deferTransactionUntil(leash, barrier, frameNumber);
}
+ // Applying the transaction here can prevent the client from applying its transaction sooner
+ // than us which makes us overwrite the client's operation to the leash.
+ t.apply();
mControlTarget = target;
mControl = new InsetsSourceControl(mSource.getType(), leash,
new Point(mWin.getWindowFrames().mFrame.left, mWin.getWindowFrames().mFrame.top));
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 7219164ad2f1..77530fb629bc 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -2304,14 +2304,18 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
}
}
+ void resetSurfacePositionForAnimationLeash(Transaction t) {
+ t.setPosition(mSurfaceControl, 0, 0);
+ mLastSurfacePosition.set(0, 0);
+ }
+
@Override
public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
mLastLayer = -1;
reassignLayer(t);
// Leash is now responsible for position, so set our position to 0.
- t.setPosition(mSurfaceControl, 0, 0);
- mLastSurfacePosition.set(0, 0);
+ resetSurfacePositionForAnimationLeash(t);
}
@Override
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index a488af7cdee0..84cc19d68a24 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -2445,8 +2445,17 @@ public class WindowManagerService extends IWindowManager.Stub
if (controls != null) {
final int length = Math.min(controls.length, outControls.length);
for (int i = 0; i < length; i++) {
- outControls[i] = win.isClientLocal()
- ? new InsetsSourceControl(controls[i]) : controls[i];
+ final InsetsSourceControl control = controls[i];
+
+ // Check if we are sending invalid leashes.
+ final SurfaceControl leash = control != null ? control.getLeash() : null;
+ if (leash != null && !leash.isValid()) {
+ Slog.wtf(TAG, leash + " is not valid before sending to " + win,
+ leash.getReleaseStack());
+ }
+
+ outControls[i] = win.isClientLocal() && control != null
+ ? new InsetsSourceControl(control) : control;
}
}
}
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 2e1b907e71bc..5f2e14f86c94 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -5250,16 +5250,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
}
@Override
- public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
- super.onAnimationLeashCreated(t, leash);
- }
-
- @Override
- public void onAnimationLeashLost(Transaction t) {
- super.onAnimationLeashLost(t);
- }
-
- @Override
@VisibleForTesting
void updateSurfacePosition(Transaction t) {
if (mSurfaceControl == null) {
diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java
index b4e770f24eaf..21c76874f5c0 100644
--- a/services/core/java/com/android/server/wm/WindowToken.java
+++ b/services/core/java/com/android/server/wm/WindowToken.java
@@ -632,6 +632,15 @@ class WindowToken extends WindowContainer<WindowState> {
}
}
+ @Override
+ void resetSurfacePositionForAnimationLeash(SurfaceControl.Transaction t) {
+ // Keep the transformed position to animate because the surface will show in different
+ // rotation than the animator of leash.
+ if (!isFixedRotationTransforming()) {
+ super.resetSurfacePositionForAnimationLeash(t);
+ }
+ }
+
/**
* Gives a chance to this {@link WindowToken} to adjust the {@link
* android.view.WindowManager.LayoutParams} of its windows.
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 1da074002456..2c0d4c0c9208 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -4733,33 +4733,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
if (!parent && isSeparateProfileChallengeEnabled(userHandle)) {
// If this user has a separate challenge, only return its restrictions.
return getUserDataUnchecked(userHandle).mAdminList;
- } else {
- // Return all admins for this user and the profiles that are visible from this
- // user that do not use a separate work challenge.
- ArrayList<ActiveAdmin> admins = new ArrayList<ActiveAdmin>();
- for (UserInfo userInfo : mUserManager.getProfiles(userHandle)) {
- DevicePolicyData policy = getUserData(userInfo.id);
- if (!userInfo.isManagedProfile()) {
- admins.addAll(policy.mAdminList);
- } else {
- // For managed profiles, we always include the policies set on the parent
- // profile. Additionally, we include the ones set on the managed profile
- // if no separate challenge is in place.
- boolean hasSeparateChallenge = isSeparateProfileChallengeEnabled(userInfo.id);
- final int N = policy.mAdminList.size();
- for (int i = 0; i < N; i++) {
- ActiveAdmin admin = policy.mAdminList.get(i);
- if (admin.hasParentActiveAdmin()) {
- admins.add(admin.getParentActiveAdmin());
- }
- if (!hasSeparateChallenge) {
- admins.add(admin);
- }
- }
- }
- }
- return admins;
}
+ // Either parent == true, or isSeparateProfileChallengeEnabled == false
+ // If parent is true, query the parent user of userHandle by definition,
+ // If isSeparateProfileChallengeEnabled is false, userHandle points to a managed profile
+ // with unified challenge so also need to query the parent user who owns the credential.
+ return getActiveAdminsForUserAndItsManagedProfilesLocked(getProfileParentId(userHandle),
+ (user) -> !mLockPatternUtils.isSeparateProfileChallengeEnabled(user.id));
}
/**
@@ -4777,6 +4757,19 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
if (isManagedProfile(userHandle)) {
return getUserDataUnchecked(userHandle).mAdminList;
}
+ return getActiveAdminsForUserAndItsManagedProfilesLocked(userHandle,
+ /* shouldIncludeProfileAdmins */ (user) -> false);
+ }
+
+ /**
+ * Returns the list of admins on the given user, as well as parent admins for each managed
+ * profile associated with the given user. Optionally also include the admin of each managed
+ * profile.
+ * <p> Should not be called on a profile user.
+ */
+ @GuardedBy("getLockObject()")
+ private List<ActiveAdmin> getActiveAdminsForUserAndItsManagedProfilesLocked(int userHandle,
+ Predicate<UserInfo> shouldIncludeProfileAdmins) {
ArrayList<ActiveAdmin> admins = new ArrayList<>();
mInjector.binderWithCleanCallingIdentity(() -> {
for (UserInfo userInfo : mUserManager.getProfiles(userHandle)) {
@@ -4784,12 +4777,14 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
if (userInfo.id == userHandle) {
admins.addAll(policy.mAdminList);
} else if (userInfo.isManagedProfile()) {
- // For managed profiles, policies set on the parent profile will be included
for (int i = 0; i < policy.mAdminList.size(); i++) {
ActiveAdmin admin = policy.mAdminList.get(i);
if (admin.hasParentActiveAdmin()) {
admins.add(admin.getParentActiveAdmin());
}
+ if (shouldIncludeProfileAdmins.test(userInfo)) {
+ admins.add(admin);
+ }
}
} else {
Slog.w(LOG_TAG, "Unknown user type: " + userInfo);
@@ -5366,6 +5361,32 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
}
+ @Override
+ public boolean isPasswordSufficientAfterProfileUnification(int userHandle, int profileUser) {
+ if (!mHasFeature) {
+ return true;
+ }
+ enforceFullCrossUsersPermission(userHandle);
+ enforceNotManagedProfile(userHandle, "check password sufficiency");
+ enforceUserUnlocked(userHandle);
+
+ synchronized (getLockObject()) {
+ PasswordMetrics metrics = mLockSettingsInternal.getUserPasswordMetrics(userHandle);
+
+ // Combine password policies across the user and its profiles. Profile admins are
+ // included if the profile is to be unified or currently has unified challenge
+ List<ActiveAdmin> admins = getActiveAdminsForUserAndItsManagedProfilesLocked(userHandle,
+ /* shouldIncludeProfileAdmins */ (user) -> user.id == profileUser
+ || !mLockPatternUtils.isSeparateProfileChallengeEnabled(user.id));
+ ArrayList<PasswordMetrics> adminMetrics = new ArrayList<>(admins.size());
+ for (ActiveAdmin admin : admins) {
+ adminMetrics.add(admin.mPasswordPolicy.getMinMetrics());
+ }
+ return PasswordMetrics.validatePasswordMetrics(PasswordMetrics.merge(adminMetrics),
+ PASSWORD_COMPLEXITY_NONE, false, metrics).isEmpty();
+ }
+ }
+
private boolean isActivePasswordSufficientForUserLocked(
boolean passwordValidAtLastCheckpoint, @Nullable PasswordMetrics metrics,
int userHandle, boolean parent) {
diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp
index 8d084cddf0de..c1f237f91b44 100644
--- a/services/incremental/IncrementalService.cpp
+++ b/services/incremental/IncrementalService.cpp
@@ -1333,13 +1333,13 @@ void IncrementalService::extractZipFile(const IfsMountPtr& ifs, ZipArchiveHandle
std::vector<IncFsDataBlock> instructions(numBlocks);
auto remainingData = std::span(libData.get(), entry.uncompressed_length);
for (int i = 0; i < numBlocks; i++) {
- const auto blockSize = std::min<uint16_t>(constants().blockSize, remainingData.size());
+ const auto blockSize = std::min<long>(constants().blockSize, remainingData.size());
instructions[i] = IncFsDataBlock{
.fileFd = writeFd.get(),
.pageIndex = static_cast<IncFsBlockIndex>(i),
.compression = INCFS_COMPRESSION_KIND_NONE,
.kind = INCFS_BLOCK_KIND_DATA,
- .dataSize = blockSize,
+ .dataSize = static_cast<uint32_t>(blockSize),
.data = reinterpret_cast<const char*>(remainingData.data()),
};
remainingData = remainingData.subspan(blockSize);
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index e2a247394a81..2c3e3df46e7c 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -112,6 +112,7 @@ import com.android.server.inputmethod.InputMethodSystemProperty;
import com.android.server.inputmethod.MultiClientInputMethodManagerService;
import com.android.server.integrity.AppIntegrityManagerService;
import com.android.server.lights.LightsService;
+import com.android.server.location.LocationManagerService;
import com.android.server.media.MediaResourceMonitorService;
import com.android.server.media.MediaRouterService;
import com.android.server.media.MediaSessionService;
diff --git a/services/tests/servicestests/AndroidManifest.xml b/services/tests/servicestests/AndroidManifest.xml
index 109c1191523b..270a3b50b934 100644
--- a/services/tests/servicestests/AndroidManifest.xml
+++ b/services/tests/servicestests/AndroidManifest.xml
@@ -78,6 +78,7 @@
<uses-permission android:name="android.permission.DUMP"/>
<uses-permission android:name="android.permission.READ_DREAM_STATE"/>
<uses-permission android:name="android.permission.WRITE_DREAM_STATE"/>
+ <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<!-- Uses API introduced in O (26) -->
<uses-sdk android:minSdkVersion="1"
diff --git a/services/tests/servicestests/src/com/android/server/audio/AudioDeviceBrokerTest.java b/services/tests/servicestests/src/com/android/server/audio/AudioDeviceBrokerTest.java
index 73a191dc78cc..22f8b9c8ae92 100644
--- a/services/tests/servicestests/src/com/android/server/audio/AudioDeviceBrokerTest.java
+++ b/services/tests/servicestests/src/com/android/server/audio/AudioDeviceBrokerTest.java
@@ -66,7 +66,7 @@ public class AudioDeviceBrokerTest {
mContext = InstrumentationRegistry.getTargetContext();
mMockAudioService = mock(AudioService.class);
- mSpyAudioSystem = spy(AudioSystemAdapter.getAlwaysOkAdapter());
+ mSpyAudioSystem = spy(AudioSystemAdapter.getConfigurableAdapter());
mSpyDevInventory = spy(new AudioDeviceInventory(mSpyAudioSystem));
mAudioDeviceBroker = new AudioDeviceBroker(mContext, mMockAudioService, mSpyDevInventory);
mSpyDevInventory.setDeviceBroker(mAudioDeviceBroker);
diff --git a/services/tests/servicestests/src/com/android/server/audio/AudioServiceTest.java b/services/tests/servicestests/src/com/android/server/audio/AudioServiceTest.java
new file mode 100644
index 000000000000..6185ae6d93f9
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/audio/AudioServiceTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2020 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.server.audio;
+
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.os.Looper;
+import android.os.UserHandle;
+import android.util.Log;
+
+import androidx.test.InstrumentationRegistry;
+import androidx.test.filters.MediumTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Spy;
+
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class AudioServiceTest {
+ private static final String TAG = "AudioServiceTest";
+
+ private static final int MAX_MESSAGE_HANDLING_DELAY_MS = 100;
+
+ private Context mContext;
+ private AudioSystemAdapter mAudioSystem;
+ @Spy private SystemServerAdapter mSpySystemServer;
+ // the class being unit-tested here
+ private AudioService mAudioService;
+
+ private static boolean sLooperPrepared = false;
+
+ @Before
+ public void setUp() throws Exception {
+ if (!sLooperPrepared) {
+ Looper.prepare();
+ sLooperPrepared = true;
+ }
+ mContext = InstrumentationRegistry.getTargetContext();
+ mAudioSystem = AudioSystemAdapter.getConfigurableAdapter();
+ mSpySystemServer = spy(SystemServerAdapter.getNoOpAdapter());
+ mAudioService = new AudioService(mContext, mAudioSystem, mSpySystemServer);
+ }
+
+ /**
+ * Test muting the mic reports the expected value, and the corresponding intent was fired
+ * @throws Exception
+ */
+ @Test
+ public void testMuteMicrophone() throws Exception {
+ Log.i(TAG, "running testMuteMicrophone");
+ Assert.assertNotNull(mAudioService);
+ final AudioSystemAdapter.AudioSystemConfigurableAdapter testAudioSystem =
+ (AudioSystemAdapter.AudioSystemConfigurableAdapter) mAudioSystem;
+ testAudioSystem.configureMuteMicrophoneToFail(false);
+ for (boolean muted : new boolean[] { true, false}) {
+ testAudioSystem.configureIsMicrophoneMuted(!muted);
+ mAudioService.setMicrophoneMute(muted, mContext.getOpPackageName(),
+ UserHandle.getCallingUserId());
+ Assert.assertEquals("mic mute reporting wrong value",
+ muted, mAudioService.isMicrophoneMuted());
+ // verify the intent for mic mute changed is supposed to be fired
+ Thread.sleep(MAX_MESSAGE_HANDLING_DELAY_MS);
+ verify(mSpySystemServer, times(1))
+ .sendMicrophoneMuteChangedIntent();
+ reset(mSpySystemServer);
+ }
+ }
+
+ /**
+ * Test muting the mic with simulated failure reports the expected value, and the corresponding
+ * intent was fired
+ * @throws Exception
+ */
+ @Test
+ public void testMuteMicrophoneWhenFail() throws Exception {
+ Log.i(TAG, "running testMuteMicrophoneWhenFail");
+ Assert.assertNotNull(mAudioService);
+ final AudioSystemAdapter.AudioSystemConfigurableAdapter testAudioSystem =
+ (AudioSystemAdapter.AudioSystemConfigurableAdapter) mAudioSystem;
+ testAudioSystem.configureMuteMicrophoneToFail(true);
+ for (boolean muted : new boolean[] { true, false}) {
+ testAudioSystem.configureIsMicrophoneMuted(!muted);
+ mAudioService.setMicrophoneMute(muted, mContext.getOpPackageName(),
+ UserHandle.getCallingUserId());
+ Assert.assertEquals("mic mute reporting wrong value",
+ !muted, mAudioService.isMicrophoneMuted());
+ // verify the intent for mic mute changed is supposed to be fired
+ Thread.sleep(MAX_MESSAGE_HANDLING_DELAY_MS);
+ verify(mSpySystemServer, times(1))
+ .sendMicrophoneMuteChangedIntent();
+ reset(mSpySystemServer);
+ }
+ }
+}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
index fe224ce058f4..4faed659f5df 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -4841,6 +4841,33 @@ public class DevicePolicyManagerTest extends DpmTestBase {
assertFalse(dpm.isActivePasswordSufficient());
}
+ public void testIsPasswordSufficientAfterProfileUnification() throws Exception {
+ final int managedProfileUserId = DpmMockContext.CALLER_USER_HANDLE;
+ final int managedProfileAdminUid =
+ UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
+ mContext.binder.callingUid = managedProfileAdminUid;
+
+ addManagedProfile(admin1, managedProfileAdminUid, admin1);
+ doReturn(true).when(getServices().lockPatternUtils)
+ .isSeparateProfileChallengeEnabled(managedProfileUserId);
+
+ dpm.setPasswordQuality(admin1, DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC);
+ parentDpm.setPasswordQuality(admin1, DevicePolicyManager.PASSWORD_QUALITY_NUMERIC);
+
+ when(getServices().lockSettingsInternal.getUserPasswordMetrics(UserHandle.USER_SYSTEM))
+ .thenReturn(computeForPassword("1234".getBytes()));
+
+ // Numeric password is compliant with current requirement (QUALITY_NUMERIC set explicitly
+ // on the parent admin)
+ assertTrue(dpm.isPasswordSufficientAfterProfileUnification(UserHandle.USER_SYSTEM,
+ UserHandle.USER_NULL));
+ // Numeric password is not compliant if profile is to be unified: the profile has a
+ // QUALITY_ALPHABETIC policy on itself which will be enforced on the password after
+ // unification.
+ assertFalse(dpm.isPasswordSufficientAfterProfileUnification(UserHandle.USER_SYSTEM,
+ managedProfileUserId));
+ }
+
private void setActivePasswordState(PasswordMetrics passwordMetrics)
throws Exception {
final int userHandle = UserHandle.getUserId(mContext.binder.callingUid);
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTests.java b/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTests.java
index 07d7830c9b0f..12b144f2b778 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTests.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/LockSettingsServiceTests.java
@@ -209,6 +209,26 @@ public class LockSettingsServiceTests extends BaseLockSettingsServiceTests {
}
@Test
+ public void testManagedProfileChallengeUnification_parentUserNoPassword() throws Exception {
+ // Start with a profile with unified challenge, parent user has not password
+ mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, false, null);
+ assertEquals(0, mGateKeeperService.getSecureUserId(MANAGED_PROFILE_USER_ID));
+ assertEquals(CREDENTIAL_TYPE_NONE, mService.getCredentialType(MANAGED_PROFILE_USER_ID));
+
+ // Set a separate challenge on the profile
+ assertTrue(mService.setLockCredential(
+ newPassword("12345678"), nonePassword(), MANAGED_PROFILE_USER_ID));
+ assertNotEquals(0, mGateKeeperService.getSecureUserId(MANAGED_PROFILE_USER_ID));
+ assertEquals(CREDENTIAL_TYPE_PASSWORD, mService.getCredentialType(MANAGED_PROFILE_USER_ID));
+
+ // Now unify again, profile should become passwordless again
+ mService.setSeparateProfileChallengeEnabled(MANAGED_PROFILE_USER_ID, false,
+ newPassword("12345678"));
+ assertEquals(0, mGateKeeperService.getSecureUserId(MANAGED_PROFILE_USER_ID));
+ assertEquals(CREDENTIAL_TYPE_NONE, mService.getCredentialType(MANAGED_PROFILE_USER_ID));
+ }
+
+ @Test
public void testSetLockCredential_forPrimaryUser_sendsCredentials() throws Exception {
assertTrue(mService.setLockCredential(
newPassword("password"),
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ArchiveTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ArchiveTest.java
new file mode 100644
index 000000000000..c69ef8d93282
--- /dev/null
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ArchiveTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2020 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.server.notification;
+
+import static android.os.UserHandle.USER_CURRENT;
+import static android.os.UserHandle.USER_SYSTEM;
+import static android.service.notification.NotificationListenerService.REASON_CANCEL;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Notification;
+import android.os.UserHandle;
+import android.service.notification.StatusBarNotification;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import com.android.server.UiServiceTestCase;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class ArchiveTest extends UiServiceTestCase {
+ private static final int SIZE = 5;
+
+ private NotificationManagerService.Archive mArchive;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mArchive = new NotificationManagerService.Archive(SIZE);
+ mArchive.updateHistoryEnabled(USER_SYSTEM, true);
+ mArchive.updateHistoryEnabled(USER_CURRENT, true);
+ }
+
+ private StatusBarNotification getNotification(String pkg, int id, UserHandle user) {
+ Notification n = new Notification.Builder(getContext(), "test")
+ .setContentTitle("A")
+ .setWhen(1205)
+ .build();
+ return new StatusBarNotification(
+ pkg, pkg, id, null, 0, 0, n, user, null, System.currentTimeMillis());
+ }
+
+
+ @Test
+ public void testRecordAndRead() {
+ List<String> expected = new ArrayList<>();
+ for (int i = 0; i < SIZE; i++) {
+ StatusBarNotification sbn = getNotification("pkg" + i, i,
+ UserHandle.of(i % 2 ==0 ? USER_SYSTEM : USER_CURRENT));
+ expected.add(sbn.getKey());
+ mArchive.record(sbn, REASON_CANCEL);
+ }
+
+ List<StatusBarNotification> actual = Arrays.asList(mArchive.getArray(SIZE, true));
+ assertThat(actual).hasSize(expected.size());
+ for (StatusBarNotification sbn : actual) {
+ assertThat(expected).contains(sbn.getKey());
+ }
+ }
+
+ @Test
+ public void testRecordAndRead_overLimit() {
+ List<String> expected = new ArrayList<>();
+ for (int i = 0; i < (SIZE * 2); i++) {
+ StatusBarNotification sbn = getNotification("pkg" + i, i, UserHandle.of(USER_SYSTEM));
+ mArchive.record(sbn, REASON_CANCEL);
+ if (i >= SIZE) {
+ expected.add(sbn.getKey());
+ }
+ }
+
+ List<StatusBarNotification> actual = Arrays.asList(mArchive.getArray((SIZE * 2), true));
+ assertThat(actual).hasSize(expected.size());
+ for (StatusBarNotification sbn : actual) {
+ assertThat(expected).contains(sbn.getKey());
+ }
+ }
+
+ @Test
+ public void testDoesNotRecordIfHistoryDisabled() {
+ mArchive.updateHistoryEnabled(USER_CURRENT, false);
+ List<String> expected = new ArrayList<>();
+ for (int i = 0; i < SIZE; i++) {
+ StatusBarNotification sbn = getNotification("pkg" + i, i,
+ UserHandle.of(i % 2 ==0 ? USER_SYSTEM : USER_CURRENT));
+ mArchive.record(sbn, REASON_CANCEL);
+ if (i % 2 ==0) {
+ expected.add(sbn.getKey());
+ }
+ }
+
+ List<StatusBarNotification> actual = Arrays.asList(mArchive.getArray(SIZE, true));
+ assertThat(actual).hasSize(expected.size());
+ for (StatusBarNotification sbn : actual) {
+ assertThat(expected).contains(sbn.getKey());
+ }
+ }
+
+ @Test
+ public void testRemovesEntriesWhenHistoryDisabled() {
+ mArchive.updateHistoryEnabled(USER_CURRENT, true);
+ List<String> expected = new ArrayList<>();
+ for (int i = 0; i < SIZE; i++) {
+ StatusBarNotification sbn = getNotification("pkg" + i, i,
+ UserHandle.of(i % 2 ==0 ? USER_SYSTEM : USER_CURRENT));
+ mArchive.record(sbn, REASON_CANCEL);
+ if (i % 2 ==0) {
+ expected.add(sbn.getKey());
+ }
+ }
+ mArchive.updateHistoryEnabled(USER_CURRENT, false);
+
+ List<StatusBarNotification> actual = Arrays.asList(mArchive.getArray(SIZE, true));
+ assertThat(actual).hasSize(expected.size());
+ for (StatusBarNotification sbn : actual) {
+ assertThat(expected).contains(sbn.getKey());
+ }
+ }
+}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 3cd0e92964ec..2d66aa51ee0f 100755
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -113,6 +113,7 @@ import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutServiceInternal;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Color;
@@ -234,6 +235,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
@Mock
private LauncherApps mLauncherApps;
@Mock
+ private ShortcutServiceInternal mShortcutServiceInternal;
+ @Mock
ActivityManager mActivityManager;
@Mock
Resources mResources;
@@ -466,6 +469,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
mShortcutHelper = mService.getShortcutHelper();
mShortcutHelper.setLauncherApps(mLauncherApps);
+ mShortcutHelper.setShortcutServiceInternal(mShortcutServiceInternal);
// Set the testable bubble extractor
RankingHelper rankingHelper = mService.getRankingHelper();
@@ -6088,8 +6092,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
List<ShortcutInfo> shortcutInfos = new ArrayList<>();
ShortcutInfo info = mock(ShortcutInfo.class);
when(info.isLongLived()).thenReturn(true);
+ when(info.isEnabled()).thenReturn(true);
shortcutInfos.add(info);
when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcutInfos);
+ when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
+ anyString(), anyInt(), any())).thenReturn(true);
// Test: Send the bubble notification
mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
@@ -6148,8 +6155,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
List<ShortcutInfo> shortcutInfos = new ArrayList<>();
ShortcutInfo info = mock(ShortcutInfo.class);
when(info.isLongLived()).thenReturn(true);
+ when(info.isEnabled()).thenReturn(true);
shortcutInfos.add(info);
when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcutInfos);
+ when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
+ anyString(), anyInt(), any())).thenReturn(true);
// Test: Send the bubble notification
mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
@@ -6492,7 +6502,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
ShortcutInfo si = mock(ShortcutInfo.class);
when(si.getShortLabel()).thenReturn("Hello");
when(si.isLongLived()).thenReturn(true);
+ when(si.isEnabled()).thenReturn(true);
when(mLauncherApps.getShortcuts(any(), any())).thenReturn(Arrays.asList(si));
+ when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
+ anyString(), anyInt(), any())).thenReturn(true);
List<ConversationChannelWrapper> conversations =
mBinderService.getConversationsForPackage(PKG_P, mUid).getList();
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
index 427237c4be0f..ac51750f23f8 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
@@ -15,6 +15,9 @@
*/
package com.android.server.notification;
+import static android.app.AppOpsManager.MODE_ALLOWED;
+import static android.app.AppOpsManager.MODE_DEFAULT;
+import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
import static android.app.NotificationChannel.CONVERSATION_CHANNEL_ID_FORMAT;
import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL;
import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE;
@@ -50,6 +53,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
@@ -132,6 +136,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
@Spy IContentProvider mTestIContentProvider = new MockIContentProvider();
@Mock Context mContext;
@Mock ZenModeHelper mMockZenModeHelper;
+ @Mock AppOpsManager mAppOpsManager;
private NotificationManager.Policy mTestNotificationPolicy;
@@ -187,7 +192,10 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0,
NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND, 0);
when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(),
+ anyString(), eq(null), anyString())).thenReturn(MODE_DEFAULT);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
resetZenModeHelper();
mAudioAttributes = new AudioAttributes.Builder()
@@ -1464,7 +1472,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0,
NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND, 0);
when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
assertFalse(mHelper.areChannelsBypassingDnd());
verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any());
resetZenModeHelper();
@@ -1475,7 +1484,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
// start notification policy off with mAreChannelsBypassingDnd = false
mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, 0, 0);
when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
assertFalse(mHelper.areChannelsBypassingDnd());
verify(mMockZenModeHelper, never()).setNotificationPolicy(any());
resetZenModeHelper();
@@ -2241,7 +2251,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
+ "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n"
+ "</package>\n"
+ "</ranking>\n";
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
loadByteArrayXml(preQXml.getBytes(), true, UserHandle.USER_SYSTEM);
assertEquals(PreferencesHelper.DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS,
@@ -2253,7 +2264,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mHelper.setHideSilentStatusIcons(!PreferencesHelper.DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS);
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
loadStreamXml(baos, false, UserHandle.USER_ALL);
assertEquals(!PreferencesHelper.DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS,
@@ -2349,7 +2361,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_UNSPECIFIED);
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
loadStreamXml(baos, false, UserHandle.USER_ALL);
assertNull(mHelper.getNotificationDelegate(PKG_O, UID_O));
@@ -2360,7 +2373,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mHelper.setNotificationDelegate(PKG_O, UID_O, "other", 53);
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
loadStreamXml(baos, false, UserHandle.USER_ALL);
assertEquals("other", mHelper.getNotificationDelegate(PKG_O, UID_O));
@@ -2372,7 +2386,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mHelper.revokeNotificationDelegate(PKG_O, UID_O);
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
loadStreamXml(baos, false, UserHandle.USER_ALL);
assertNull(mHelper.getNotificationDelegate(PKG_O, UID_O));
@@ -2384,7 +2399,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mHelper.toggleNotificationDelegate(PKG_O, UID_O, false);
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
loadStreamXml(baos, false, UserHandle.USER_ALL);
// appears disabled
@@ -2402,7 +2418,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mHelper.revokeNotificationDelegate(PKG_O, UID_O);
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
loadStreamXml(baos, false, UserHandle.USER_ALL);
// appears disabled
@@ -2417,14 +2434,71 @@ public class PreferencesHelperTest extends UiServiceTestCase {
@Test
public void testBubblePreference_defaults() throws Exception {
- assertEquals(mHelper.getBubblePreference(PKG_O, UID_O), BUBBLE_PREFERENCE_NONE);
+ assertEquals(BUBBLE_PREFERENCE_NONE, mHelper.getBubblePreference(PKG_O, UID_O));
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
loadStreamXml(baos, false, UserHandle.USER_ALL);
- assertEquals(mHelper.getBubblePreference(PKG_O, UID_O), BUBBLE_PREFERENCE_NONE);
+ assertEquals(BUBBLE_PREFERENCE_NONE, mHelper.getBubblePreference(PKG_O, UID_O));
+ assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O));
+ }
+
+ @Test
+ public void testBubblePreference_upgradeWithSAWPermission() throws Exception {
+ when(mAppOpsManager.noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(),
+ anyString(), eq(null), anyString())).thenReturn(MODE_ALLOWED);
+
+ final String xml = "<ranking version=\"1\">\n"
+ + "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\">\n"
+ + "<channel id=\"someId\" name=\"hi\""
+ + " importance=\"3\"/>"
+ + "</package>"
+ + "</ranking>";
+ XmlPullParser parser = Xml.newPullParser();
+ parser.setInput(new BufferedInputStream(new ByteArrayInputStream(xml.getBytes())),
+ null);
+ parser.nextTag();
+ mHelper.readXml(parser, false, UserHandle.USER_ALL);
+
+ assertEquals(BUBBLE_PREFERENCE_ALL, mHelper.getBubblePreference(PKG_O, UID_O));
+ assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O));
+ }
+
+ @Test
+ public void testBubblePreference_upgradeWithSAWThenUserOverride() throws Exception {
+ when(mAppOpsManager.noteOpNoThrow(eq(OP_SYSTEM_ALERT_WINDOW), anyInt(),
+ anyString(), eq(null), anyString())).thenReturn(MODE_ALLOWED);
+
+ final String xml = "<ranking version=\"1\">\n"
+ + "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\">\n"
+ + "<channel id=\"someId\" name=\"hi\""
+ + " importance=\"3\"/>"
+ + "</package>"
+ + "</ranking>";
+ XmlPullParser parser = Xml.newPullParser();
+ parser.setInput(new BufferedInputStream(new ByteArrayInputStream(xml.getBytes())),
+ null);
+ parser.nextTag();
+ mHelper.readXml(parser, false, UserHandle.USER_ALL);
+
+ assertEquals(BUBBLE_PREFERENCE_ALL, mHelper.getBubblePreference(PKG_O, UID_O));
assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O));
+
+ mHelper.setBubblesAllowed(PKG_O, UID_O, BUBBLE_PREFERENCE_SELECTED);
+ assertEquals(BUBBLE_PREFERENCE_SELECTED, mHelper.getBubblePreference(PKG_O, UID_O));
+ assertEquals(PreferencesHelper.LockableAppFields.USER_LOCKED_BUBBLE,
+ mHelper.getAppLockedFields(PKG_O, UID_O));
+
+ ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
+ loadStreamXml(baos, false, UserHandle.USER_ALL);
+
+ assertEquals(BUBBLE_PREFERENCE_SELECTED, mHelper.getBubblePreference(PKG_O, UID_O));
+ assertEquals(PreferencesHelper.LockableAppFields.USER_LOCKED_BUBBLE,
+ mHelper.getAppLockedFields(PKG_O, UID_O));
}
@Test
@@ -2435,7 +2509,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
mHelper.getAppLockedFields(PKG_O, UID_O));
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false, UserHandle.USER_ALL);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
loadStreamXml(baos, false, UserHandle.USER_ALL);
assertEquals(mHelper.getBubblePreference(PKG_O, UID_O), BUBBLE_PREFERENCE_NONE);
@@ -2949,7 +3024,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.REQUIRE_SHORTCUTS_FOR_CONVERSATIONS, 0);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
final String xml = "<ranking version=\"1\">\n"
+ "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\" >\n"
@@ -2969,7 +3045,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
public void testPlaceholderConversationId_shortcutRequired() throws Exception {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.REQUIRE_SHORTCUTS_FOR_CONVERSATIONS, 1);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
final String xml = "<ranking version=\"1\">\n"
+ "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\" >\n"
@@ -2989,7 +3066,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
public void testNormalConversationId_shortcutRequired() throws Exception {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.REQUIRE_SHORTCUTS_FOR_CONVERSATIONS, 1);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
final String xml = "<ranking version=\"1\">\n"
+ "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\" >\n"
@@ -3009,7 +3087,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
public void testNoConversationId_shortcutRequired() throws Exception {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.REQUIRE_SHORTCUTS_FOR_CONVERSATIONS, 1);
- mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger);
+ mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mLogger,
+ mAppOpsManager);
final String xml = "<ranking version=\"1\">\n"
+ "<package name=\"" + PKG_O + "\" uid=\"" + UID_O + "\" >\n"
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ShortcutHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ShortcutHelperTest.java
index 50fb9b425652..f7304bd0075b 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/ShortcutHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ShortcutHelperTest.java
@@ -16,7 +16,11 @@
package com.android.server.notification;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -25,6 +29,7 @@ import static org.mockito.Mockito.when;
import android.app.Notification;
import android.content.pm.LauncherApps;
import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutServiceInternal;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.test.suitebuilder.annotation.SmallTest;
@@ -58,6 +63,8 @@ public class ShortcutHelperTest extends UiServiceTestCase {
@Mock
ShortcutHelper.ShortcutListener mShortcutListener;
@Mock
+ ShortcutServiceInternal mShortcutServiceInternal;
+ @Mock
NotificationRecord mNr;
@Mock
Notification mNotif;
@@ -72,7 +79,8 @@ public class ShortcutHelperTest extends UiServiceTestCase {
public void setUp() {
MockitoAnnotations.initMocks(this);
- mShortcutHelper = new ShortcutHelper(mLauncherApps, mShortcutListener);
+ mShortcutHelper = new ShortcutHelper(
+ mLauncherApps, mShortcutListener, mShortcutServiceInternal);
when(mNr.getKey()).thenReturn(KEY);
when(mNr.getSbn()).thenReturn(mSbn);
when(mSbn.getPackageName()).thenReturn(PKG);
@@ -138,4 +146,80 @@ public class ShortcutHelperTest extends UiServiceTestCase {
callback.onShortcutsChanged(PKG, shortcutInfos, mock(UserHandle.class));
verify(mShortcutListener).onShortcutRemoved(mNr.getKey());
}
+
+ @Test
+ public void testGetValidShortcutInfo_noMatchingShortcut() {
+ when(mLauncherApps.getShortcuts(any(), any())).thenReturn(null);
+ when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
+ anyString(), anyInt(), any())).thenReturn(true);
+
+ assertThat(mShortcutHelper.getValidShortcutInfo("a", "p", UserHandle.SYSTEM)).isNull();
+ }
+
+ @Test
+ public void testGetValidShortcutInfo_nullShortcut() {
+ ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
+ shortcuts.add(null);
+ when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcuts);
+ when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
+ anyString(), anyInt(), any())).thenReturn(true);
+
+ assertThat(mShortcutHelper.getValidShortcutInfo("a", "p", UserHandle.SYSTEM)).isNull();
+ }
+
+ @Test
+ public void testGetValidShortcutInfo_notLongLived() {
+ ShortcutInfo si = mock(ShortcutInfo.class);
+ when(si.isLongLived()).thenReturn(false);
+ when(si.isEnabled()).thenReturn(true);
+ ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
+ shortcuts.add(si);
+ when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcuts);
+ when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
+ anyString(), anyInt(), any())).thenReturn(true);
+
+ assertThat(mShortcutHelper.getValidShortcutInfo("a", "p", UserHandle.SYSTEM)).isNull();
+ }
+
+ @Test
+ public void testGetValidShortcutInfo_notSharingShortcut() {
+ ShortcutInfo si = mock(ShortcutInfo.class);
+ when(si.isLongLived()).thenReturn(true);
+ when(si.isEnabled()).thenReturn(true);
+ ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
+ shortcuts.add(si);
+ when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcuts);
+ when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
+ anyString(), anyInt(), any())).thenReturn(false);
+
+ assertThat(mShortcutHelper.getValidShortcutInfo("a", "p", UserHandle.SYSTEM)).isNull();
+ }
+
+ @Test
+ public void testGetValidShortcutInfo_notEnabled() {
+ ShortcutInfo si = mock(ShortcutInfo.class);
+ when(si.isLongLived()).thenReturn(true);
+ when(si.isEnabled()).thenReturn(false);
+ ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
+ shortcuts.add(si);
+ when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcuts);
+ when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
+ anyString(), anyInt(), any())).thenReturn(true);
+
+ assertThat(mShortcutHelper.getValidShortcutInfo("a", "p", UserHandle.SYSTEM)).isNull();
+ }
+
+ @Test
+ public void testGetValidShortcutInfo_isValid() {
+ ShortcutInfo si = mock(ShortcutInfo.class);
+ when(si.isLongLived()).thenReturn(true);
+ when(si.isEnabled()).thenReturn(true);
+ ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
+ shortcuts.add(si);
+ when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcuts);
+ when(mShortcutServiceInternal.isSharingShortcut(anyInt(), anyString(), anyString(),
+ anyString(), anyInt(), any())).thenReturn(true);
+
+ assertThat(mShortcutHelper.getValidShortcutInfo("a", "p", UserHandle.SYSTEM)).isSameAs(si);
+ }
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
index bc66fa7ff48d..5bbb4d9e712c 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java
@@ -1324,7 +1324,7 @@ public class ActivityRecordTests extends ActivityTestsBase {
display.rotateInDifferentOrientationIfNeeded(mActivity);
display.mFixedRotationLaunchingApp = mActivity;
- displayRotation.updateRotationUnchecked(false /* forceUpdate */);
+ displayRotation.updateRotationUnchecked(true /* forceUpdate */);
assertTrue(displayRotation.isRotatingSeamlessly());
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
index 3f47b8722a39..3fd81b47c546 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
@@ -90,6 +90,7 @@ import android.view.ISystemGestureExclusionListener;
import android.view.IWindowManager;
import android.view.MotionEvent;
import android.view.Surface;
+import android.view.SurfaceControl.Transaction;
import android.view.ViewRootImpl;
import android.view.WindowManager;
import android.view.test.InsetsModeSession;
@@ -1040,6 +1041,12 @@ public class DisplayContentTests extends WindowTestsBase {
assertEquals(config90.orientation, app.getConfiguration().orientation);
assertEquals(config90.windowConfiguration.getBounds(), app.getBounds());
+ // Make wallaper laid out with the fixed rotation transform.
+ final WindowToken wallpaperToken = mWallpaperWindow.mToken;
+ wallpaperToken.linkFixedRotationTransform(app);
+ mWallpaperWindow.mLayoutNeeded = true;
+ performLayout(mDisplayContent);
+
// Force the negative offset to verify it can be updated.
mWallpaperWindow.mWinAnimator.mXOffset = mWallpaperWindow.mWinAnimator.mYOffset = -1;
assertTrue(mDisplayContent.mWallpaperController.updateWallpaperOffset(mWallpaperWindow,
@@ -1047,6 +1054,13 @@ public class DisplayContentTests extends WindowTestsBase {
assertThat(mWallpaperWindow.mWinAnimator.mXOffset).isGreaterThan(-1);
assertThat(mWallpaperWindow.mWinAnimator.mYOffset).isGreaterThan(-1);
+ // The wallpaper need to animate with transformed position, so its surface position should
+ // not be reset.
+ final Transaction t = wallpaperToken.getPendingTransaction();
+ spyOn(t);
+ mWallpaperWindow.mToken.onAnimationLeashCreated(t, null /* leash */);
+ verify(t, never()).setPosition(any(), eq(0), eq(0));
+
mDisplayContent.mAppTransition.notifyAppTransitionFinishedLocked(app.token);
// The animation in old rotation should be cancelled.
diff --git a/startop/iorap/functional_tests/Android.bp b/startop/iorap/functional_tests/Android.bp
index ad85f1430bdf..8a5bd34af653 100644
--- a/startop/iorap/functional_tests/Android.bp
+++ b/startop/iorap/functional_tests/Android.bp
@@ -15,7 +15,7 @@
android_test {
name: "iorap-functional-tests",
srcs: ["src/**/*.java"],
- data: ["test_data/*"],
+ data: [":iorap-functional-test-apps"],
static_libs: [
// Non-test dependencies
// library under test
diff --git a/startop/iorap/functional_tests/test_data/iorap_test_app_v1.apk b/startop/iorap/functional_tests/test_data/iorap_test_app_v1.apk
deleted file mode 120000
index 1c1a437f6a55..000000000000
--- a/startop/iorap/functional_tests/test_data/iorap_test_app_v1.apk
+++ /dev/null
@@ -1 +0,0 @@
-../../../../../../packages/modules/ArtPrebuilt/iorap/test/iorap_test_app_v1.apk \ No newline at end of file
diff --git a/startop/iorap/functional_tests/test_data/iorap_test_app_v2.apk b/startop/iorap/functional_tests/test_data/iorap_test_app_v2.apk
deleted file mode 120000
index 7cd41c48ba3a..000000000000
--- a/startop/iorap/functional_tests/test_data/iorap_test_app_v2.apk
+++ /dev/null
@@ -1 +0,0 @@
-../../../../../../packages/modules/ArtPrebuilt/iorap/test/iorap_test_app_v2.apk \ No newline at end of file
diff --git a/startop/iorap/functional_tests/test_data/iorap_test_app_v3.apk b/startop/iorap/functional_tests/test_data/iorap_test_app_v3.apk
deleted file mode 120000
index 7f4e996e57d0..000000000000
--- a/startop/iorap/functional_tests/test_data/iorap_test_app_v3.apk
+++ /dev/null
@@ -1 +0,0 @@
-../../../../../../packages/modules/ArtPrebuilt/iorap/test/iorap_test_app_v3.apk \ No newline at end of file
diff --git a/telecomm/java/android/telecom/Conference.java b/telecomm/java/android/telecom/Conference.java
index 4e14fd3d59a1..d9605522b3b0 100644
--- a/telecomm/java/android/telecom/Conference.java
+++ b/telecomm/java/android/telecom/Conference.java
@@ -106,6 +106,7 @@ public abstract class Conference extends Conferenceable {
private int mCallerDisplayNamePresentation;
private int mCallDirection;
private boolean mRingbackRequested = false;
+ private boolean mIsMultiparty = true;
private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
@Override
@@ -998,8 +999,8 @@ public abstract class Conference extends Conferenceable {
public void onExtrasChanged(Bundle extras) {}
/**
- * Set whether Telecom should treat this {@link Conference} as a conference call or if it
- * should treat it as a single-party call.
+ * Set whether Telecom should treat this {@link Conference} as a multiparty conference call or
+ * if it should treat it as a single-party call.
* This method is used as part of a workaround regarding IMS conference calls and user
* expectation. In IMS, once a conference is formed, the UE is connected to an IMS conference
* server. If all participants of the conference drop out of the conference except for one, the
@@ -1020,6 +1021,7 @@ public abstract class Conference extends Conferenceable {
@TestApi
@RequiresPermission(MODIFY_PHONE_STATE)
public void setConferenceState(boolean isConference) {
+ mIsMultiparty = isConference;
for (Listener l : mListeners) {
l.onConferenceStateChanged(this, isConference);
}
@@ -1043,6 +1045,20 @@ public abstract class Conference extends Conferenceable {
}
}
+ /**
+ * Determines if the {@link Conference} is considered "multiparty" or not. By default all
+ * conferences are considered multiparty. A multiparty conference is one where there are
+ * multiple conference participants (other than the host) in the conference.
+ * This is tied to {@link #setConferenceState(boolean)}, which is used for some use cases to
+ * have a conference appear as if it is a standalone call, in which case the conference will
+ * no longer be multiparty.
+ * @return {@code true} if conference is treated as a conference (i.e. it is multiparty),
+ * {@code false} if it should emulate a standalone call (i.e. not multiparty).
+ * @hide
+ */
+ public boolean isMultiparty() {
+ return mIsMultiparty;
+ }
/**
* Sets the address of this {@link Conference}. Used when {@link #setConferenceState(boolean)}
diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java
index 73296986d82e..1b60e4820ad0 100755
--- a/telecomm/java/android/telecom/ConnectionService.java
+++ b/telecomm/java/android/telecom/ConnectionService.java
@@ -2505,6 +2505,11 @@ public abstract class ConnectionService extends Service {
mAdapter.addConferenceCall(id, parcelableConference);
mAdapter.setVideoProvider(id, conference.getVideoProvider());
mAdapter.setVideoState(id, conference.getVideoState());
+ // In some instances a conference can start its life as a standalone call with just a
+ // single participant; ensure we signal to Telecom in this case.
+ if (!conference.isMultiparty()) {
+ mAdapter.setConferenceState(id, conference.isMultiparty());
+ }
// Go through any child calls and set the parent.
for (Connection connection : conference.getConnections()) {
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index 545c8a35058f..d2de19aaf89a 100755
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -505,6 +505,15 @@ public class CarrierConfigManager {
public static final String KEY_CARRIER_VT_AVAILABLE_BOOL = "carrier_vt_available_bool";
/**
+ * Flag specifying whether to show an alert dialog for 5G disable when the user disables VoLTE.
+ * By default this value is {@code false}.
+ *
+ * @hide
+ */
+ public static final String KEY_VOLTE_5G_LIMITED_ALERT_DIALOG_BOOL =
+ "volte_5g_limited_alert_dialog_bool";
+
+ /**
* Flag specifying whether the carrier wants to notify the user when a VT call has been handed
* over from WIFI to LTE.
* <p>
@@ -3084,6 +3093,16 @@ public class CarrierConfigManager {
public static final String KEY_UNMETERED_NR_NSA_SUB6_BOOL = "unmetered_nr_nsa_sub6_bool";
/**
+ * Whether NR (non-standalone) should be unmetered when the device is roaming.
+ * If false, then the values for {@link #KEY_UNMETERED_NR_NSA_BOOL},
+ * {@link #KEY_UNMETERED_NR_NSA_MMWAVE_BOOL}, {@link #KEY_UNMETERED_NR_NSA_SUB6_BOOL},
+ * and unmetered {@link SubscriptionPlan} will be ignored.
+ * @hide
+ */
+ public static final String KEY_UNMETERED_NR_NSA_WHEN_ROAMING_BOOL =
+ "unmetered_nr_nsa_when_roaming_bool";
+
+ /**
* Whether NR (standalone) should be unmetered for all frequencies.
* If either {@link #KEY_UNMETERED_NR_SA_MMWAVE_BOOL} or
* {@link #KEY_UNMETERED_NR_SA_SUB6_BOOL} are true, then this value will be ignored.
@@ -3703,6 +3722,7 @@ public class CarrierConfigManager {
sDefaults.putBoolean(KEY_CARRIER_SETTINGS_ENABLE_BOOL, false);
sDefaults.putBoolean(KEY_CARRIER_VOLTE_AVAILABLE_BOOL, false);
sDefaults.putBoolean(KEY_CARRIER_VT_AVAILABLE_BOOL, false);
+ sDefaults.putBoolean(KEY_VOLTE_5G_LIMITED_ALERT_DIALOG_BOOL, false);
sDefaults.putBoolean(KEY_NOTIFY_HANDOVER_VIDEO_FROM_WIFI_TO_LTE_BOOL, false);
sDefaults.putBoolean(KEY_ALLOW_MERGING_RTT_CALLS_BOOL, false);
sDefaults.putBoolean(KEY_NOTIFY_HANDOVER_VIDEO_FROM_LTE_TO_WIFI_BOOL, false);
@@ -4134,6 +4154,7 @@ public class CarrierConfigManager {
sDefaults.putBoolean(KEY_UNMETERED_NR_NSA_BOOL, false);
sDefaults.putBoolean(KEY_UNMETERED_NR_NSA_MMWAVE_BOOL, false);
sDefaults.putBoolean(KEY_UNMETERED_NR_NSA_SUB6_BOOL, false);
+ sDefaults.putBoolean(KEY_UNMETERED_NR_NSA_WHEN_ROAMING_BOOL, false);
sDefaults.putBoolean(KEY_UNMETERED_NR_SA_BOOL, false);
sDefaults.putBoolean(KEY_UNMETERED_NR_SA_MMWAVE_BOOL, false);
sDefaults.putBoolean(KEY_UNMETERED_NR_SA_SUB6_BOOL, false);
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index f623649fb25e..835ef59f9ef3 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -13250,4 +13250,21 @@ public class TelephonyManager {
public static void enableServiceHandleCaching() {
sServiceHandleCacheEnabled = true;
}
+
+ /**
+ * Whether device can connect to 5G network when two SIMs are active.
+ * @hide
+ * TODO b/153669716: remove or make system API.
+ */
+ public boolean canConnectTo5GInDsdsMode() {
+ ITelephony telephony = getITelephony();
+ if (telephony == null) return true;
+ try {
+ return telephony.canConnectTo5GInDsdsMode();
+ } catch (RemoteException ex) {
+ return true;
+ } catch (NullPointerException ex) {
+ return true;
+ }
+ }
}
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 43aeb19fe1bd..f5cd68f050a4 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -2268,4 +2268,9 @@ interface ITelephony {
* @return operatorinfo on success
*/
String getManualNetworkSelectionPlmn(int subId);
+
+ /**
+ * Whether device can connect to 5G network when two SIMs are active.
+ */
+ boolean canConnectTo5GInDsdsMode();
}
diff --git a/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java b/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java
index f4f610b1b280..fa292bd0d57a 100644
--- a/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java
+++ b/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java
@@ -100,7 +100,6 @@ public class DozeTestDream extends DreamService {
public void onAttachedToWindow() {
super.onAttachedToWindow();
setInteractive(false);
- setLowProfile(true);
setFullscreen(true);
setContentView(R.layout.dream);
setScreenBright(false);
diff --git a/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java b/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java
index 6e6331312eac..a1bb0d586916 100644
--- a/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java
+++ b/tests/net/java/com/android/server/net/NetworkStatsServiceTest.java
@@ -60,14 +60,13 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.annotation.NonNull;
-import android.annotation.Nullable;
import android.app.AlarmManager;
import android.app.usage.NetworkStatsManager;
import android.content.Context;
@@ -95,8 +94,6 @@ import android.os.Message;
import android.os.Messenger;
import android.os.PowerManager;
import android.os.SimpleClock;
-import android.telephony.PhoneStateListener;
-import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import androidx.test.InstrumentationRegistry;
@@ -109,7 +106,7 @@ import com.android.internal.util.test.BroadcastInterceptingContext;
import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config;
import com.android.testutils.HandlerUtilsKt;
-import com.android.testutils.TestableNetworkStatsProvider;
+import com.android.testutils.TestableNetworkStatsProviderBinder;
import libcore.io.IoUtils;
@@ -126,6 +123,7 @@ import java.io.File;
import java.time.Clock;
import java.time.ZoneOffset;
import java.util.Objects;
+import java.util.concurrent.Executor;
/**
* Tests for {@link NetworkStatsService}.
@@ -168,14 +166,13 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
private @Mock NetworkStatsSettings mSettings;
private @Mock IBinder mBinder;
private @Mock AlarmManager mAlarmManager;
- private @Mock TelephonyManager mTelephonyManager;
+ @Mock
+ private NetworkStatsSubscriptionsMonitor mNetworkStatsSubscriptionsMonitor;
private HandlerThread mHandlerThread;
private NetworkStatsService mService;
private INetworkStatsSession mSession;
private INetworkManagementEventObserver mNetworkObserver;
- @Nullable
- private PhoneStateListener mPhoneStateListener;
private final Clock mClock = new SimpleClock(ZoneOffset.UTC) {
@Override
@@ -203,8 +200,8 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
mHandlerThread = new HandlerThread("HandlerThread");
final NetworkStatsService.Dependencies deps = makeDependencies();
mService = new NetworkStatsService(mServiceContext, mNetManager, mAlarmManager, wakeLock,
- mClock, mTelephonyManager, mSettings,
- mStatsFactory, new NetworkStatsObservers(), mStatsDir, getBaseDir(mStatsDir), deps);
+ mClock, mSettings, mStatsFactory, new NetworkStatsObservers(), mStatsDir,
+ getBaseDir(mStatsDir), deps);
mElapsedRealtime = 0L;
@@ -224,12 +221,6 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
ArgumentCaptor.forClass(INetworkManagementEventObserver.class);
verify(mNetManager).registerObserver(networkObserver.capture());
mNetworkObserver = networkObserver.getValue();
-
- // Capture the phone state listener that created by service.
- final ArgumentCaptor<PhoneStateListener> phoneStateListenerCaptor =
- ArgumentCaptor.forClass(PhoneStateListener.class);
- verify(mTelephonyManager).listen(phoneStateListenerCaptor.capture(), anyInt());
- mPhoneStateListener = phoneStateListenerCaptor.getValue();
}
@NonNull
@@ -239,6 +230,14 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
public HandlerThread makeHandlerThread() {
return mHandlerThread;
}
+
+ @Override
+ public NetworkStatsSubscriptionsMonitor makeSubscriptionsMonitor(
+ @NonNull Context context, @NonNull Executor executor,
+ @NonNull NetworkStatsService service) {
+
+ return mNetworkStatsSubscriptionsMonitor;
+ }
};
}
@@ -678,10 +677,9 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
// TODO: support per IMSI state
private void setMobileRatTypeAndWaitForIdle(int ratType) {
- final ServiceState mockSs = mock(ServiceState.class);
- when(mockSs.getDataNetworkType()).thenReturn(ratType);
- mPhoneStateListener.onServiceStateChanged(mockSs);
-
+ when(mNetworkStatsSubscriptionsMonitor.getRatTypeForSubscriberId(anyString()))
+ .thenReturn(ratType);
+ mService.handleOnCollapsedRatTypeChanged();
HandlerUtilsKt.waitForIdle(mHandlerThread, WAIT_TIMEOUT);
}
@@ -1118,7 +1116,8 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
expectNetworkStatsUidDetail(buildEmptyStats());
// Register custom provider and retrieve callback.
- final TestableNetworkStatsProvider provider = new TestableNetworkStatsProvider();
+ final TestableNetworkStatsProviderBinder provider =
+ new TestableNetworkStatsProviderBinder();
final INetworkStatsProviderCallback cb =
mService.registerNetworkStatsProvider("TEST", provider);
assertNotNull(cb);
@@ -1176,7 +1175,8 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
mService.forceUpdateIfaces(NETWORKS_WIFI, states, getActiveIface(states), new VpnInfo[0]);
// Register custom provider and retrieve callback.
- final TestableNetworkStatsProvider provider = new TestableNetworkStatsProvider();
+ final TestableNetworkStatsProviderBinder provider =
+ new TestableNetworkStatsProviderBinder();
final INetworkStatsProviderCallback cb =
mService.registerNetworkStatsProvider("TEST", provider);
assertNotNull(cb);