Merge changes from topic "oct28b"
* changes:
BroadcastQueue: skip ANRs when assuming success.
BroadcastQueue: better state transition logging.
BroadcastQueue: return reasons from skip policy.
diff --git a/Android.bp b/Android.bp
index 0315c12..0a14565 100644
--- a/Android.bp
+++ b/Android.bp
@@ -214,6 +214,7 @@
"android.hardware.radio-V1.5-java",
"android.hardware.radio-V1.6-java",
"android.hardware.radio.data-V1-java",
+ "android.hardware.radio.ims-V1-java",
"android.hardware.radio.messaging-V1-java",
"android.hardware.radio.modem-V1-java",
"android.hardware.radio.network-V2-java",
diff --git a/apex/jobscheduler/framework/java/android/app/tare/EconomyManager.java b/apex/jobscheduler/framework/java/android/app/tare/EconomyManager.java
index 299ad66..4a3a6d9 100644
--- a/apex/jobscheduler/framework/java/android/app/tare/EconomyManager.java
+++ b/apex/jobscheduler/framework/java/android/app/tare/EconomyManager.java
@@ -113,7 +113,9 @@
/** @hide */
public static final String KEY_AM_INITIAL_CONSUMPTION_LIMIT = "am_initial_consumption_limit";
/** @hide */
- public static final String KEY_AM_HARD_CONSUMPTION_LIMIT = "am_hard_consumption_limit";
+ public static final String KEY_AM_MIN_CONSUMPTION_LIMIT = "am_minimum_consumption_limit";
+ /** @hide */
+ public static final String KEY_AM_MAX_CONSUMPTION_LIMIT = "am_maximum_consumption_limit";
// TODO: Add AlarmManager modifier keys
/** @hide */
public static final String KEY_AM_REWARD_TOP_ACTIVITY_INSTANT =
@@ -242,7 +244,9 @@
/** @hide */
public static final String KEY_JS_INITIAL_CONSUMPTION_LIMIT = "js_initial_consumption_limit";
/** @hide */
- public static final String KEY_JS_HARD_CONSUMPTION_LIMIT = "js_hard_consumption_limit";
+ public static final String KEY_JS_MIN_CONSUMPTION_LIMIT = "js_minimum_consumption_limit";
+ /** @hide */
+ public static final String KEY_JS_MAX_CONSUMPTION_LIMIT = "js_maximum_consumption_limit";
// TODO: Add JobScheduler modifier keys
/** @hide */
public static final String KEY_JS_REWARD_APP_INSTALL_INSTANT =
@@ -371,7 +375,9 @@
/** @hide */
public static final long DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT_CAKES = arcToCake(2880);
/** @hide */
- public static final long DEFAULT_AM_HARD_CONSUMPTION_LIMIT_CAKES = arcToCake(15_000);
+ public static final long DEFAULT_AM_MIN_CONSUMPTION_LIMIT_CAKES = arcToCake(1440);
+ /** @hide */
+ public static final long DEFAULT_AM_MAX_CONSUMPTION_LIMIT_CAKES = arcToCake(15_000);
// TODO: add AlarmManager modifier default values
/** @hide */
public static final long DEFAULT_AM_REWARD_TOP_ACTIVITY_INSTANT_CAKES = arcToCake(0);
@@ -478,8 +484,10 @@
/** @hide */
public static final long DEFAULT_JS_INITIAL_CONSUMPTION_LIMIT_CAKES = arcToCake(29_000);
/** @hide */
- // TODO: set hard limit based on device type (phone vs tablet vs etc) + battery size
- public static final long DEFAULT_JS_HARD_CONSUMPTION_LIMIT_CAKES = arcToCake(250_000);
+ public static final long DEFAULT_JS_MIN_CONSUMPTION_LIMIT_CAKES = arcToCake(17_000);
+ /** @hide */
+ // TODO: set maximum limit based on device type (phone vs tablet vs etc) + battery size
+ public static final long DEFAULT_JS_MAX_CONSUMPTION_LIMIT_CAKES = arcToCake(250_000);
// TODO: add JobScheduler modifier default values
/** @hide */
public static final long DEFAULT_JS_REWARD_APP_INSTALL_INSTANT_CAKES = arcToCake(408);
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
index 6375d0d..f659dbf 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
@@ -432,6 +432,7 @@
break;
case Constants.KEY_MIN_LINEAR_BACKOFF_TIME_MS:
case Constants.KEY_MIN_EXP_BACKOFF_TIME_MS:
+ case Constants.KEY_SYSTEM_STOP_TO_FAILURE_RATIO:
mConstants.updateBackoffConstantsLocked();
break;
case Constants.KEY_CONN_CONGESTION_DELAY_FRAC:
@@ -509,6 +510,8 @@
private static final String KEY_MIN_LINEAR_BACKOFF_TIME_MS = "min_linear_backoff_time_ms";
private static final String KEY_MIN_EXP_BACKOFF_TIME_MS = "min_exp_backoff_time_ms";
+ private static final String KEY_SYSTEM_STOP_TO_FAILURE_RATIO =
+ "system_stop_to_failure_ratio";
private static final String KEY_CONN_CONGESTION_DELAY_FRAC = "conn_congestion_delay_frac";
private static final String KEY_CONN_PREFETCH_RELAX_FRAC = "conn_prefetch_relax_frac";
private static final String KEY_CONN_USE_CELL_SIGNAL_STRENGTH =
@@ -540,6 +543,7 @@
private static final float DEFAULT_MODERATE_USE_FACTOR = .5f;
private static final long DEFAULT_MIN_LINEAR_BACKOFF_TIME_MS = JobInfo.MIN_BACKOFF_MILLIS;
private static final long DEFAULT_MIN_EXP_BACKOFF_TIME_MS = JobInfo.MIN_BACKOFF_MILLIS;
+ private static final int DEFAULT_SYSTEM_STOP_TO_FAILURE_RATIO = 3;
private static final float DEFAULT_CONN_CONGESTION_DELAY_FRAC = 0.5f;
private static final float DEFAULT_CONN_PREFETCH_RELAX_FRAC = 0.5f;
private static final boolean DEFAULT_CONN_USE_CELL_SIGNAL_STRENGTH = true;
@@ -589,6 +593,11 @@
* The minimum backoff time to allow for exponential backoff.
*/
long MIN_EXP_BACKOFF_TIME_MS = DEFAULT_MIN_EXP_BACKOFF_TIME_MS;
+ /**
+ * The ratio to use to convert number of times a job was stopped by JobScheduler to an
+ * incremental failure in the backoff policy calculation.
+ */
+ int SYSTEM_STOP_TO_FAILURE_RATIO = DEFAULT_SYSTEM_STOP_TO_FAILURE_RATIO;
/**
* The fraction of a job's running window that must pass before we
@@ -700,6 +709,9 @@
MIN_EXP_BACKOFF_TIME_MS = DeviceConfig.getLong(DeviceConfig.NAMESPACE_JOB_SCHEDULER,
KEY_MIN_EXP_BACKOFF_TIME_MS,
DEFAULT_MIN_EXP_BACKOFF_TIME_MS);
+ SYSTEM_STOP_TO_FAILURE_RATIO = DeviceConfig.getInt(DeviceConfig.NAMESPACE_JOB_SCHEDULER,
+ KEY_SYSTEM_STOP_TO_FAILURE_RATIO,
+ DEFAULT_SYSTEM_STOP_TO_FAILURE_RATIO);
}
private void updateConnectivityConstantsLocked() {
@@ -797,6 +809,7 @@
pw.print(KEY_MIN_LINEAR_BACKOFF_TIME_MS, MIN_LINEAR_BACKOFF_TIME_MS).println();
pw.print(KEY_MIN_EXP_BACKOFF_TIME_MS, MIN_EXP_BACKOFF_TIME_MS).println();
+ pw.print(KEY_SYSTEM_STOP_TO_FAILURE_RATIO, SYSTEM_STOP_TO_FAILURE_RATIO).println();
pw.print(KEY_CONN_CONGESTION_DELAY_FRAC, CONN_CONGESTION_DELAY_FRAC).println();
pw.print(KEY_CONN_PREFETCH_RELAX_FRAC, CONN_PREFETCH_RELAX_FRAC).println();
pw.print(KEY_CONN_USE_CELL_SIGNAL_STRENGTH, CONN_USE_CELL_SIGNAL_STRENGTH).println();
@@ -1277,7 +1290,7 @@
jobStatus.getJob().isPrefetch(),
jobStatus.getJob().getPriority(),
jobStatus.getEffectivePriority(),
- jobStatus.getNumFailures());
+ jobStatus.getNumPreviousAttempts());
// If the job is immediately ready to run, then we can just immediately
// put it in the pending list and try to schedule it. This is especially
@@ -1476,7 +1489,7 @@
cancelled.getJob().isPrefetch(),
cancelled.getJob().getPriority(),
cancelled.getEffectivePriority(),
- cancelled.getNumFailures());
+ cancelled.getNumPreviousAttempts());
}
// If this is a replacement, bring in the new version of the job
if (incomingJob != null) {
@@ -1903,7 +1916,7 @@
* Reschedules the given job based on the job's backoff policy. It doesn't make sense to
* specify an override deadline on a failed job (the failed job will run even though it's not
* ready), so we reschedule it with {@link JobStatus#NO_LATEST_RUNTIME}, but specify that any
- * ready job with {@link JobStatus#getNumFailures()} > 0 will be executed.
+ * ready job with {@link JobStatus#getNumPreviousAttempts()} > 0 will be executed.
*
* @param failureToReschedule Provided job status that we will reschedule.
* @return A newly instantiated JobStatus with the same constraints as the last job except
@@ -1911,12 +1924,24 @@
* @see #maybeQueueReadyJobsForExecutionLocked
*/
@VisibleForTesting
- JobStatus getRescheduleJobForFailureLocked(JobStatus failureToReschedule) {
+ JobStatus getRescheduleJobForFailureLocked(JobStatus failureToReschedule,
+ int internalStopReason) {
final long elapsedNowMillis = sElapsedRealtimeClock.millis();
final JobInfo job = failureToReschedule.getJob();
final long initialBackoffMillis = job.getInitialBackoffMillis();
- final int backoffAttempts = failureToReschedule.getNumFailures() + 1;
+ int numFailures = failureToReschedule.getNumFailures();
+ int numSystemStops = failureToReschedule.getNumSystemStops();
+ // We should back off slowly if JobScheduler keeps stopping the job,
+ // but back off immediately if the issue appeared to be the app's fault.
+ if (internalStopReason == JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH
+ || internalStopReason == JobParameters.INTERNAL_STOP_REASON_TIMEOUT) {
+ numFailures++;
+ } else {
+ numSystemStops++;
+ }
+ final int backoffAttempts = Math.max(1,
+ numFailures + numSystemStops / mConstants.SYSTEM_STOP_TO_FAILURE_RATIO);
long delayMillis;
switch (job.getBackoffPolicy()) {
@@ -1943,7 +1968,7 @@
Math.min(delayMillis, JobInfo.MAX_BACKOFF_DELAY_MILLIS);
JobStatus newJob = new JobStatus(failureToReschedule,
elapsedNowMillis + delayMillis,
- JobStatus.NO_LATEST_RUNTIME, backoffAttempts,
+ JobStatus.NO_LATEST_RUNTIME, numFailures, numSystemStops,
failureToReschedule.getLastSuccessfulRunTime(), sSystemClock.millis());
if (job.isPeriodic()) {
newJob.setOriginalLatestRunTimeElapsed(
@@ -2034,7 +2059,7 @@
+ newLatestRuntimeElapsed);
return new JobStatus(periodicToReschedule,
elapsedNow + period - flex, elapsedNow + period,
- 0 /* backoffAttempt */,
+ 0 /* numFailures */, 0 /* numSystemStops */,
sSystemClock.millis() /* lastSuccessfulRunTime */,
periodicToReschedule.getLastFailedRunTime());
}
@@ -2049,7 +2074,7 @@
}
return new JobStatus(periodicToReschedule,
newEarliestRunTimeElapsed, newLatestRuntimeElapsed,
- 0 /* backoffAttempt */,
+ 0 /* numFailures */, 0 /* numSystemStops */,
sSystemClock.millis() /* lastSuccessfulRunTime */,
periodicToReschedule.getLastFailedRunTime());
}
@@ -2093,7 +2118,7 @@
// job so we can transfer any appropriate state over from the previous job when
// we stop it.
final JobStatus rescheduledJob = needsReschedule
- ? getRescheduleJobForFailureLocked(jobStatus) : null;
+ ? getRescheduleJobForFailureLocked(jobStatus, debugStopReason) : null;
if (rescheduledJob != null
&& (debugStopReason == JobParameters.INTERNAL_STOP_REASON_TIMEOUT
|| debugStopReason == JobParameters.INTERNAL_STOP_REASON_PREEMPT)) {
@@ -2427,7 +2452,7 @@
shouldForceBatchJob =
mPrefetchController.getNextEstimatedLaunchTimeLocked(job)
> relativelySoonCutoffTime;
- } else if (job.getNumFailures() > 0) {
+ } else if (job.getNumPreviousAttempts() > 0) {
shouldForceBatchJob = false;
} else {
final long nowElapsed = sElapsedRealtimeClock.millis();
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java b/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java
index d6456f0..9e3f19d 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobServiceContext.java
@@ -363,7 +363,7 @@
job.getJob().isPrefetch(),
job.getJob().getPriority(),
job.getEffectivePriority(),
- job.getNumFailures());
+ job.getNumPreviousAttempts());
if (Trace.isTagEnabled(Trace.TRACE_TAG_SYSTEM_SERVER)) {
// Use the context's ID to distinguish traces since there'll only be one job
// running per context.
@@ -1032,7 +1032,7 @@
completedJob.getJob().isPrefetch(),
completedJob.getJob().getPriority(),
completedJob.getEffectivePriority(),
- completedJob.getNumFailures());
+ completedJob.getNumPreviousAttempts());
if (Trace.isTagEnabled(Trace.TRACE_TAG_SYSTEM_SERVER)) {
Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_SYSTEM_SERVER, "JobScheduler",
completedJob.getTag(), getId());
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobStore.java b/apex/jobscheduler/service/java/com/android/server/job/JobStore.java
index 22b0968..df8f729 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobStore.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobStore.java
@@ -194,7 +194,7 @@
convertRtcBoundsToElapsed(utcTimes, elapsedNow);
JobStatus newJob = new JobStatus(job,
elapsedRuntimes.first, elapsedRuntimes.second,
- 0, job.getLastSuccessfulRunTime(), job.getLastFailedRunTime());
+ 0, 0, job.getLastSuccessfulRunTime(), job.getLastFailedRunTime());
newJob.prepareLocked();
toAdd.add(newJob);
toRemove.add(job);
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/FlexibilityController.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/FlexibilityController.java
index 547f94ba..0eb9336 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/FlexibilityController.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/FlexibilityController.java
@@ -342,10 +342,10 @@
// There is no deadline and no estimated launch time.
return NO_LIFECYCLE_END;
}
- if (js.getNumFailures() > 1) {
- // Number of failures will not equal one as per restriction in JobStatus constructor.
+ // Increase the flex deadline for jobs rescheduled more than once.
+ if (js.getNumPreviousAttempts() > 1) {
return earliest + Math.min(
- (long) Math.scalb(mRescheduledJobDeadline, js.getNumFailures() - 2),
+ (long) Math.scalb(mRescheduledJobDeadline, js.getNumPreviousAttempts() - 2),
mMaxRescheduledDeadline);
}
return js.getLatestRunTimeElapsed() == JobStatus.NO_LATEST_RUNTIME
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java
index de602a8..f9fb0d0 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/JobStatus.java
@@ -241,10 +241,22 @@
*/
private long mOriginalLatestRunTimeElapsedMillis;
- /** How many times this job has failed, used to compute back-off. */
+ /**
+ * How many times this job has failed to complete on its own
+ * (via {@link android.app.job.JobService#jobFinished(JobParameters, boolean)} or because of
+ * a timeout).
+ * This count doesn't include most times JobScheduler decided to stop the job
+ * (via {@link android.app.job.JobService#onStopJob(JobParameters)}.
+ */
private final int numFailures;
/**
+ * The number of times JobScheduler has forced this job to stop due to reasons mostly outside
+ * of the app's control.
+ */
+ private final int mNumSystemStops;
+
+ /**
* Which app standby bucket this job's app is in. Updated when the app is moved to a
* different bucket.
*/
@@ -488,6 +500,8 @@
* @param tag A string associated with the job for debugging/logging purposes.
* @param numFailures Count of how many times this job has requested a reschedule because
* its work was not yet finished.
+ * @param numSystemStops Count of how many times JobScheduler has forced this job to stop due to
+ * factors mostly out of the app's control.
* @param earliestRunTimeElapsedMillis Milestone: earliest point in time at which the job
* is to be considered runnable
* @param latestRunTimeElapsedMillis Milestone: point in time at which the job will be
@@ -497,7 +511,7 @@
* @param internalFlags Non-API property flags about this job
*/
private JobStatus(JobInfo job, int callingUid, String sourcePackageName,
- int sourceUserId, int standbyBucket, String tag, int numFailures,
+ int sourceUserId, int standbyBucket, String tag, int numFailures, int numSystemStops,
long earliestRunTimeElapsedMillis, long latestRunTimeElapsedMillis,
long lastSuccessfulRunTime, long lastFailedRunTime, int internalFlags,
int dynamicConstraints) {
@@ -535,6 +549,7 @@
this.latestRunTimeElapsedMillis = latestRunTimeElapsedMillis;
this.mOriginalLatestRunTimeElapsedMillis = latestRunTimeElapsedMillis;
this.numFailures = numFailures;
+ mNumSystemStops = numSystemStops;
int requiredConstraints = job.getConstraintFlags();
if (job.getRequiredNetwork() != null) {
@@ -576,7 +591,7 @@
// Otherwise, every consecutive reschedule increases a jobs' flexibility deadline.
if (!isRequestedExpeditedJob()
&& satisfiesMinWindowException
- && numFailures != 1
+ && (numFailures + numSystemStops) != 1
&& lacksSomeFlexibleConstraints) {
mNumRequiredFlexibleConstraints =
NUM_SYSTEM_WIDE_FLEXIBLE_CONSTRAINTS + (mPreferUnmetered ? 1 : 0);
@@ -626,7 +641,7 @@
this(jobStatus.getJob(), jobStatus.getUid(),
jobStatus.getSourcePackageName(), jobStatus.getSourceUserId(),
jobStatus.getStandbyBucket(),
- jobStatus.getSourceTag(), jobStatus.getNumFailures(),
+ jobStatus.getSourceTag(), jobStatus.getNumFailures(), jobStatus.getNumSystemStops(),
jobStatus.getEarliestRunTime(), jobStatus.getLatestRunTimeElapsed(),
jobStatus.getLastSuccessfulRunTime(), jobStatus.getLastFailedRunTime(),
jobStatus.getInternalFlags(), jobStatus.mDynamicConstraints);
@@ -654,7 +669,7 @@
int innerFlags, int dynamicConstraints) {
this(job, callingUid, sourcePkgName, sourceUserId,
standbyBucket,
- sourceTag, 0,
+ sourceTag, /* numFailures */ 0, /* numSystemStops */ 0,
earliestRunTimeElapsedMillis, latestRunTimeElapsedMillis,
lastSuccessfulRunTime, lastFailedRunTime, innerFlags, dynamicConstraints);
@@ -673,12 +688,13 @@
/** Create a new job to be rescheduled with the provided parameters. */
public JobStatus(JobStatus rescheduling,
long newEarliestRuntimeElapsedMillis,
- long newLatestRuntimeElapsedMillis, int backoffAttempt,
+ long newLatestRuntimeElapsedMillis, int numFailures, int numSystemStops,
long lastSuccessfulRunTime, long lastFailedRunTime) {
this(rescheduling.job, rescheduling.getUid(),
rescheduling.getSourcePackageName(), rescheduling.getSourceUserId(),
rescheduling.getStandbyBucket(),
- rescheduling.getSourceTag(), backoffAttempt, newEarliestRuntimeElapsedMillis,
+ rescheduling.getSourceTag(), numFailures, numSystemStops,
+ newEarliestRuntimeElapsedMillis,
newLatestRuntimeElapsedMillis,
lastSuccessfulRunTime, lastFailedRunTime, rescheduling.getInternalFlags(),
rescheduling.mDynamicConstraints);
@@ -715,7 +731,7 @@
int standbyBucket = JobSchedulerService.standbyBucketForPackage(jobPackage,
sourceUserId, elapsedNow);
return new JobStatus(job, callingUid, sourcePkg, sourceUserId,
- standbyBucket, tag, 0,
+ standbyBucket, tag, /* numFailures */ 0, /* numSystemStops */ 0,
earliestRunTimeElapsedMillis, latestRunTimeElapsedMillis,
0 /* lastSuccessfulRunTime */, 0 /* lastFailedRunTime */,
/*innerFlags=*/ 0, /* dynamicConstraints */ 0);
@@ -868,10 +884,27 @@
pw.print(job.getId());
}
+ /**
+ * Returns the number of times the job stopped previously for reasons that appeared to be within
+ * the app's control.
+ */
public int getNumFailures() {
return numFailures;
}
+ /**
+ * Returns the number of times the system stopped a previous execution of this job for reasons
+ * that were likely outside the app's control.
+ */
+ public int getNumSystemStops() {
+ return mNumSystemStops;
+ }
+
+ /** Returns the total number of times we've attempted to run this job in the past. */
+ public int getNumPreviousAttempts() {
+ return numFailures + mNumSystemStops;
+ }
+
public ComponentName getServiceComponent() {
return job.getService();
}
@@ -1857,6 +1890,10 @@
sb.append(" failures=");
sb.append(numFailures);
}
+ if (mNumSystemStops != 0) {
+ sb.append(" system stops=");
+ sb.append(mNumSystemStops);
+ }
if (isReady()) {
sb.append(" READY");
} else {
@@ -2382,6 +2419,9 @@
if (numFailures != 0) {
pw.print("Num failures: "); pw.println(numFailures);
}
+ if (mNumSystemStops != 0) {
+ pw.print("Num system stops: "); pw.println(mNumSystemStops);
+ }
if (mLastSuccessfulRunTime != 0) {
pw.print("Last successful run: ");
pw.println(formatTime(mLastSuccessfulRunTime));
@@ -2579,7 +2619,7 @@
proto.write(JobStatusDumpProto.ORIGINAL_LATEST_RUNTIME_ELAPSED,
mOriginalLatestRunTimeElapsedMillis);
- proto.write(JobStatusDumpProto.NUM_FAILURES, numFailures);
+ proto.write(JobStatusDumpProto.NUM_FAILURES, numFailures + mNumSystemStops);
proto.write(JobStatusDumpProto.LAST_SUCCESSFUL_RUN_TIME, mLastSuccessfulRunTime);
proto.write(JobStatusDumpProto.LAST_FAILED_RUN_TIME, mLastFailedRunTime);
diff --git a/apex/jobscheduler/service/java/com/android/server/tare/AlarmManagerEconomicPolicy.java b/apex/jobscheduler/service/java/com/android/server/tare/AlarmManagerEconomicPolicy.java
index b426f16..46338fa 100644
--- a/apex/jobscheduler/service/java/com/android/server/tare/AlarmManagerEconomicPolicy.java
+++ b/apex/jobscheduler/service/java/com/android/server/tare/AlarmManagerEconomicPolicy.java
@@ -33,9 +33,10 @@
import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP_CAKES;
-import static android.app.tare.EconomyManager.DEFAULT_AM_HARD_CONSUMPTION_LIMIT_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT_CAKES;
+import static android.app.tare.EconomyManager.DEFAULT_AM_MAX_CONSUMPTION_LIMIT_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_AM_MAX_SATIATED_BALANCE_CAKES;
+import static android.app.tare.EconomyManager.DEFAULT_AM_MIN_CONSUMPTION_LIMIT_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_AM_MIN_SATIATED_BALANCE_EXEMPTED_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_AM_MIN_SATIATED_BALANCE_OTHER_APP_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT_CAKES;
@@ -71,9 +72,10 @@
import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP;
import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE;
import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP;
-import static android.app.tare.EconomyManager.KEY_AM_HARD_CONSUMPTION_LIMIT;
import static android.app.tare.EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT;
+import static android.app.tare.EconomyManager.KEY_AM_MAX_CONSUMPTION_LIMIT;
import static android.app.tare.EconomyManager.KEY_AM_MAX_SATIATED_BALANCE;
+import static android.app.tare.EconomyManager.KEY_AM_MIN_CONSUMPTION_LIMIT;
import static android.app.tare.EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED;
import static android.app.tare.EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP;
import static android.app.tare.EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT;
@@ -146,7 +148,8 @@
private long mMinSatiatedBalanceOther;
private long mMaxSatiatedBalance;
private long mInitialSatiatedConsumptionLimit;
- private long mHardSatiatedConsumptionLimit;
+ private long mMinSatiatedConsumptionLimit;
+ private long mMaxSatiatedConsumptionLimit;
private final KeyValueListParser mParser = new KeyValueListParser(',');
private final Injector mInjector;
@@ -199,8 +202,13 @@
}
@Override
- long getHardSatiatedConsumptionLimit() {
- return mHardSatiatedConsumptionLimit;
+ long getMinSatiatedConsumptionLimit() {
+ return mMinSatiatedConsumptionLimit;
+ }
+
+ @Override
+ long getMaxSatiatedConsumptionLimit() {
+ return mMaxSatiatedConsumptionLimit;
}
@NonNull
@@ -240,12 +248,15 @@
mMaxSatiatedBalance = getConstantAsCake(mParser, properties,
KEY_AM_MAX_SATIATED_BALANCE, DEFAULT_AM_MAX_SATIATED_BALANCE_CAKES,
Math.max(arcToCake(1), mMinSatiatedBalanceExempted));
+ mMinSatiatedConsumptionLimit = getConstantAsCake(mParser, properties,
+ KEY_AM_MIN_CONSUMPTION_LIMIT, DEFAULT_AM_MIN_CONSUMPTION_LIMIT_CAKES,
+ arcToCake(1));
mInitialSatiatedConsumptionLimit = getConstantAsCake(mParser, properties,
- KEY_AM_INITIAL_CONSUMPTION_LIMIT, DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT_CAKES,
- arcToCake(1));
- mHardSatiatedConsumptionLimit = getConstantAsCake(mParser, properties,
- KEY_AM_HARD_CONSUMPTION_LIMIT, DEFAULT_AM_HARD_CONSUMPTION_LIMIT_CAKES,
- mInitialSatiatedConsumptionLimit);
+ KEY_AM_INITIAL_CONSUMPTION_LIMIT, DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT_CAKES,
+ mMinSatiatedConsumptionLimit);
+ mMaxSatiatedConsumptionLimit = getConstantAsCake(mParser, properties,
+ KEY_AM_MAX_CONSUMPTION_LIMIT, DEFAULT_AM_MAX_CONSUMPTION_LIMIT_CAKES,
+ mInitialSatiatedConsumptionLimit);
final long exactAllowWhileIdleWakeupBasePrice = getConstantAsCake(mParser, properties,
KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE,
@@ -396,9 +407,11 @@
pw.decreaseIndent();
pw.print("Max satiated balance", cakeToString(mMaxSatiatedBalance)).println();
pw.print("Consumption limits: [");
+ pw.print(cakeToString(mMinSatiatedConsumptionLimit));
+ pw.print(", ");
pw.print(cakeToString(mInitialSatiatedConsumptionLimit));
pw.print(", ");
- pw.print(cakeToString(mHardSatiatedConsumptionLimit));
+ pw.print(cakeToString(mMaxSatiatedConsumptionLimit));
pw.println("]");
pw.println();
diff --git a/apex/jobscheduler/service/java/com/android/server/tare/CompleteEconomicPolicy.java b/apex/jobscheduler/service/java/com/android/server/tare/CompleteEconomicPolicy.java
index 66f7c35..7a96076 100644
--- a/apex/jobscheduler/service/java/com/android/server/tare/CompleteEconomicPolicy.java
+++ b/apex/jobscheduler/service/java/com/android/server/tare/CompleteEconomicPolicy.java
@@ -43,7 +43,8 @@
private int mEnabledEconomicPolicyIds = 0;
private int[] mCostModifiers = EmptyArray.INT;
private long mInitialConsumptionLimit;
- private long mHardConsumptionLimit;
+ private long mMinConsumptionLimit;
+ private long mMaxConsumptionLimit;
CompleteEconomicPolicy(@NonNull InternalResourceService irs) {
this(irs, new CompleteInjector());
@@ -100,14 +101,17 @@
private void updateLimits() {
long initialConsumptionLimit = 0;
- long hardConsumptionLimit = 0;
+ long minConsumptionLimit = 0;
+ long maxConsumptionLimit = 0;
for (int i = 0; i < mEnabledEconomicPolicies.size(); ++i) {
final EconomicPolicy economicPolicy = mEnabledEconomicPolicies.valueAt(i);
initialConsumptionLimit += economicPolicy.getInitialSatiatedConsumptionLimit();
- hardConsumptionLimit += economicPolicy.getHardSatiatedConsumptionLimit();
+ minConsumptionLimit += economicPolicy.getMinSatiatedConsumptionLimit();
+ maxConsumptionLimit += economicPolicy.getMaxSatiatedConsumptionLimit();
}
mInitialConsumptionLimit = initialConsumptionLimit;
- mHardConsumptionLimit = hardConsumptionLimit;
+ mMinConsumptionLimit = minConsumptionLimit;
+ mMaxConsumptionLimit = maxConsumptionLimit;
}
@Override
@@ -134,8 +138,13 @@
}
@Override
- long getHardSatiatedConsumptionLimit() {
- return mHardConsumptionLimit;
+ long getMinSatiatedConsumptionLimit() {
+ return mMinConsumptionLimit;
+ }
+
+ @Override
+ long getMaxSatiatedConsumptionLimit() {
+ return mMaxConsumptionLimit;
}
@NonNull
diff --git a/apex/jobscheduler/service/java/com/android/server/tare/EconomicPolicy.java b/apex/jobscheduler/service/java/com/android/server/tare/EconomicPolicy.java
index 008dcb8..b52f6f1 100644
--- a/apex/jobscheduler/service/java/com/android/server/tare/EconomicPolicy.java
+++ b/apex/jobscheduler/service/java/com/android/server/tare/EconomicPolicy.java
@@ -232,15 +232,21 @@
* Returns the maximum number of cakes that should be consumed during a full 100% discharge
* cycle. This is the initial limit. The system may choose to increase the limit over time,
* but the increased limit should never exceed the value returned from
- * {@link #getHardSatiatedConsumptionLimit()}.
+ * {@link #getMaxSatiatedConsumptionLimit()}.
*/
abstract long getInitialSatiatedConsumptionLimit();
/**
- * Returns the maximum number of cakes that should be consumed during a full 100% discharge
- * cycle. This is the hard limit that should never be exceeded.
+ * Returns the minimum number of cakes that should be available for consumption during a full
+ * 100% discharge cycle.
*/
- abstract long getHardSatiatedConsumptionLimit();
+ abstract long getMinSatiatedConsumptionLimit();
+
+ /**
+ * Returns the maximum number of cakes that should be available for consumption during a full
+ * 100% discharge cycle.
+ */
+ abstract long getMaxSatiatedConsumptionLimit();
/** Return the set of modifiers that should apply to this policy's costs. */
@NonNull
diff --git a/apex/jobscheduler/service/java/com/android/server/tare/InternalResourceService.java b/apex/jobscheduler/service/java/com/android/server/tare/InternalResourceService.java
index dd0a194..581a545 100644
--- a/apex/jobscheduler/service/java/com/android/server/tare/InternalResourceService.java
+++ b/apex/jobscheduler/service/java/com/android/server/tare/InternalResourceService.java
@@ -670,7 +670,7 @@
final long shortfall = (mCurrentBatteryLevel - QUANTITATIVE_EASING_BATTERY_THRESHOLD)
* currentConsumptionLimit / 100;
final long newConsumptionLimit = Math.min(currentConsumptionLimit + shortfall,
- mCompleteEconomicPolicy.getHardSatiatedConsumptionLimit());
+ mCompleteEconomicPolicy.getMaxSatiatedConsumptionLimit());
if (newConsumptionLimit != currentConsumptionLimit) {
Slog.i(TAG, "Increasing consumption limit from " + cakeToString(currentConsumptionLimit)
+ " to " + cakeToString(newConsumptionLimit));
@@ -720,12 +720,12 @@
// The stock is too low. We're doing pretty well. We can increase the stock slightly
// to let apps do more work in the background.
newConsumptionLimit = Math.min((long) (currentConsumptionLimit * 1.01),
- mCompleteEconomicPolicy.getHardSatiatedConsumptionLimit());
+ mCompleteEconomicPolicy.getMaxSatiatedConsumptionLimit());
} else if (percentageOfTarget < 100) {
// The stock is too high IMO. We're below the target. Decrease the stock to reduce
// background work.
newConsumptionLimit = Math.max((long) (currentConsumptionLimit * .98),
- mCompleteEconomicPolicy.getInitialSatiatedConsumptionLimit());
+ mCompleteEconomicPolicy.getMinSatiatedConsumptionLimit());
} else {
// The stock is just right.
return;
@@ -957,9 +957,9 @@
} else {
mScribe.loadFromDiskLocked();
if (mScribe.getSatiatedConsumptionLimitLocked()
- < mCompleteEconomicPolicy.getInitialSatiatedConsumptionLimit()
+ < mCompleteEconomicPolicy.getMinSatiatedConsumptionLimit()
|| mScribe.getSatiatedConsumptionLimitLocked()
- > mCompleteEconomicPolicy.getHardSatiatedConsumptionLimit()) {
+ > mCompleteEconomicPolicy.getMaxSatiatedConsumptionLimit()) {
// Reset the consumption limit since several factors may have changed.
mScribe.setConsumptionLimitLocked(
mCompleteEconomicPolicy.getInitialSatiatedConsumptionLimit());
@@ -1442,17 +1442,16 @@
private void updateEconomicPolicy() {
synchronized (mLock) {
- final long initialLimit =
- mCompleteEconomicPolicy.getInitialSatiatedConsumptionLimit();
- final long hardLimit = mCompleteEconomicPolicy.getHardSatiatedConsumptionLimit();
+ final long minLimit = mCompleteEconomicPolicy.getMinSatiatedConsumptionLimit();
+ final long maxLimit = mCompleteEconomicPolicy.getMaxSatiatedConsumptionLimit();
final int oldEnabledPolicies = mCompleteEconomicPolicy.getEnabledPolicyIds();
mCompleteEconomicPolicy.tearDown();
mCompleteEconomicPolicy = new CompleteEconomicPolicy(InternalResourceService.this);
if (mIsEnabled && mBootPhase >= PHASE_THIRD_PARTY_APPS_CAN_START) {
mCompleteEconomicPolicy.setup(getAllDeviceConfigProperties());
- if (initialLimit != mCompleteEconomicPolicy.getInitialSatiatedConsumptionLimit()
- || hardLimit
- != mCompleteEconomicPolicy.getHardSatiatedConsumptionLimit()) {
+ if (minLimit != mCompleteEconomicPolicy.getMinSatiatedConsumptionLimit()
+ || maxLimit
+ != mCompleteEconomicPolicy.getMaxSatiatedConsumptionLimit()) {
// Reset the consumption limit since several factors may have changed.
mScribe.setConsumptionLimitLocked(
mCompleteEconomicPolicy.getInitialSatiatedConsumptionLimit());
diff --git a/apex/jobscheduler/service/java/com/android/server/tare/JobSchedulerEconomicPolicy.java b/apex/jobscheduler/service/java/com/android/server/tare/JobSchedulerEconomicPolicy.java
index 71c6d09..7cf459c 100644
--- a/apex/jobscheduler/service/java/com/android/server/tare/JobSchedulerEconomicPolicy.java
+++ b/apex/jobscheduler/service/java/com/android/server/tare/JobSchedulerEconomicPolicy.java
@@ -38,9 +38,10 @@
import static android.app.tare.EconomyManager.DEFAULT_JS_ACTION_JOB_MIN_START_CTP_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_JS_ACTION_JOB_TIMEOUT_PENALTY_BASE_PRICE_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_JS_ACTION_JOB_TIMEOUT_PENALTY_CTP_CAKES;
-import static android.app.tare.EconomyManager.DEFAULT_JS_HARD_CONSUMPTION_LIMIT_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_JS_INITIAL_CONSUMPTION_LIMIT_CAKES;
+import static android.app.tare.EconomyManager.DEFAULT_JS_MAX_CONSUMPTION_LIMIT_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_JS_MAX_SATIATED_BALANCE_CAKES;
+import static android.app.tare.EconomyManager.DEFAULT_JS_MIN_CONSUMPTION_LIMIT_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_JS_MIN_SATIATED_BALANCE_EXEMPTED_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_JS_MIN_SATIATED_BALANCE_INCREMENT_APP_UPDATER_CAKES;
import static android.app.tare.EconomyManager.DEFAULT_JS_MIN_SATIATED_BALANCE_OTHER_APP_CAKES;
@@ -84,9 +85,10 @@
import static android.app.tare.EconomyManager.KEY_JS_ACTION_JOB_MIN_START_CTP;
import static android.app.tare.EconomyManager.KEY_JS_ACTION_JOB_TIMEOUT_PENALTY_BASE_PRICE;
import static android.app.tare.EconomyManager.KEY_JS_ACTION_JOB_TIMEOUT_PENALTY_CTP;
-import static android.app.tare.EconomyManager.KEY_JS_HARD_CONSUMPTION_LIMIT;
import static android.app.tare.EconomyManager.KEY_JS_INITIAL_CONSUMPTION_LIMIT;
+import static android.app.tare.EconomyManager.KEY_JS_MAX_CONSUMPTION_LIMIT;
import static android.app.tare.EconomyManager.KEY_JS_MAX_SATIATED_BALANCE;
+import static android.app.tare.EconomyManager.KEY_JS_MIN_CONSUMPTION_LIMIT;
import static android.app.tare.EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_EXEMPTED;
import static android.app.tare.EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_INCREMENT_APP_UPDATER;
import static android.app.tare.EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_OTHER_APP;
@@ -159,7 +161,8 @@
private long mMinSatiatedBalanceIncrementalAppUpdater;
private long mMaxSatiatedBalance;
private long mInitialSatiatedConsumptionLimit;
- private long mHardSatiatedConsumptionLimit;
+ private long mMinSatiatedConsumptionLimit;
+ private long mMaxSatiatedConsumptionLimit;
private final KeyValueListParser mParser = new KeyValueListParser(',');
private final Injector mInjector;
@@ -216,8 +219,13 @@
}
@Override
- long getHardSatiatedConsumptionLimit() {
- return mHardSatiatedConsumptionLimit;
+ long getMinSatiatedConsumptionLimit() {
+ return mMinSatiatedConsumptionLimit;
+ }
+
+ @Override
+ long getMaxSatiatedConsumptionLimit() {
+ return mMaxSatiatedConsumptionLimit;
}
@NonNull
@@ -260,12 +268,15 @@
mMaxSatiatedBalance = getConstantAsCake(mParser, properties,
KEY_JS_MAX_SATIATED_BALANCE, DEFAULT_JS_MAX_SATIATED_BALANCE_CAKES,
Math.max(arcToCake(1), mMinSatiatedBalanceExempted));
+ mMinSatiatedConsumptionLimit = getConstantAsCake(mParser, properties,
+ KEY_JS_MIN_CONSUMPTION_LIMIT, DEFAULT_JS_MIN_CONSUMPTION_LIMIT_CAKES,
+ arcToCake(1));
mInitialSatiatedConsumptionLimit = getConstantAsCake(mParser, properties,
- KEY_JS_INITIAL_CONSUMPTION_LIMIT, DEFAULT_JS_INITIAL_CONSUMPTION_LIMIT_CAKES,
- arcToCake(1));
- mHardSatiatedConsumptionLimit = getConstantAsCake(mParser, properties,
- KEY_JS_HARD_CONSUMPTION_LIMIT, DEFAULT_JS_HARD_CONSUMPTION_LIMIT_CAKES,
- mInitialSatiatedConsumptionLimit);
+ KEY_JS_INITIAL_CONSUMPTION_LIMIT, DEFAULT_JS_INITIAL_CONSUMPTION_LIMIT_CAKES,
+ mMinSatiatedConsumptionLimit);
+ mMaxSatiatedConsumptionLimit = getConstantAsCake(mParser, properties,
+ KEY_JS_MAX_CONSUMPTION_LIMIT, DEFAULT_JS_MAX_CONSUMPTION_LIMIT_CAKES,
+ mInitialSatiatedConsumptionLimit);
mActions.put(ACTION_JOB_MAX_START, new Action(ACTION_JOB_MAX_START,
getConstantAsCake(mParser, properties,
@@ -420,9 +431,11 @@
pw.decreaseIndent();
pw.print("Max satiated balance", cakeToString(mMaxSatiatedBalance)).println();
pw.print("Consumption limits: [");
+ pw.print(cakeToString(mMinSatiatedConsumptionLimit));
+ pw.print(", ");
pw.print(cakeToString(mInitialSatiatedConsumptionLimit));
pw.print(", ");
- pw.print(cakeToString(mHardSatiatedConsumptionLimit));
+ pw.print(cakeToString(mMaxSatiatedConsumptionLimit));
pw.println("]");
pw.println();
diff --git a/core/api/current.txt b/core/api/current.txt
index 218d7bd..2049d91 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -7457,6 +7457,7 @@
method public long getMaximumTimeToLock(@Nullable android.content.ComponentName);
method @NonNull public java.util.List<java.lang.String> getMeteredDataDisabledPackages(@NonNull android.content.ComponentName);
method public int getMinimumRequiredWifiSecurityLevel();
+ method public int getMtePolicy();
method @RequiresPermission(value=android.Manifest.permission.READ_NEARBY_STREAMING_POLICY, conditional=true) public int getNearbyAppStreamingPolicy();
method @RequiresPermission(value=android.Manifest.permission.READ_NEARBY_STREAMING_POLICY, conditional=true) public int getNearbyNotificationStreamingPolicy();
method @Deprecated @ColorInt public int getOrganizationColor(@NonNull android.content.ComponentName);
@@ -7605,6 +7606,7 @@
method public void setMaximumTimeToLock(@NonNull android.content.ComponentName, long);
method @NonNull public java.util.List<java.lang.String> setMeteredDataDisabledPackages(@NonNull android.content.ComponentName, @NonNull java.util.List<java.lang.String>);
method public void setMinimumRequiredWifiSecurityLevel(int);
+ method public void setMtePolicy(int);
method public void setNearbyAppStreamingPolicy(int);
method public void setNearbyNotificationStreamingPolicy(int);
method public void setNetworkLoggingEnabled(@Nullable android.content.ComponentName, boolean);
@@ -7788,6 +7790,9 @@
field public static final int LOCK_TASK_FEATURE_SYSTEM_INFO = 1; // 0x1
field public static final int MAKE_USER_EPHEMERAL = 2; // 0x2
field public static final String MIME_TYPE_PROVISIONING_NFC = "application/com.android.managedprovisioning";
+ field public static final int MTE_DISABLED = 2; // 0x2
+ field public static final int MTE_ENABLED = 1; // 0x1
+ field public static final int MTE_NOT_CONTROLLED_BY_POLICY = 0; // 0x0
field public static final int NEARBY_STREAMING_DISABLED = 1; // 0x1
field public static final int NEARBY_STREAMING_ENABLED = 2; // 0x2
field public static final int NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY = 0; // 0x0
@@ -41586,7 +41591,7 @@
field public static final String KEY_CARRIER_CONFIG_APPLIED_BOOL = "carrier_config_applied_bool";
field public static final String KEY_CARRIER_CONFIG_VERSION_STRING = "carrier_config_version_string";
field public static final String KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL = "carrier_cross_sim_ims_available_bool";
- field public static final String KEY_CARRIER_DATA_CALL_PERMANENT_FAILURE_STRINGS = "carrier_data_call_permanent_failure_strings";
+ field @Deprecated public static final String KEY_CARRIER_DATA_CALL_PERMANENT_FAILURE_STRINGS = "carrier_data_call_permanent_failure_strings";
field public static final String KEY_CARRIER_DEFAULT_ACTIONS_ON_DCFAILURE_STRING_ARRAY = "carrier_default_actions_on_dcfailure_string_array";
field public static final String KEY_CARRIER_DEFAULT_ACTIONS_ON_DEFAULT_NETWORK_AVAILABLE = "carrier_default_actions_on_default_network_available_string_array";
field public static final String KEY_CARRIER_DEFAULT_ACTIONS_ON_REDIRECTION_STRING_ARRAY = "carrier_default_actions_on_redirection_string_array";
@@ -41723,6 +41728,7 @@
field public static final String KEY_MMS_MMS_READ_REPORT_ENABLED_BOOL = "enableMMSReadReports";
field public static final String KEY_MMS_MULTIPART_SMS_ENABLED_BOOL = "enableMultipartSMS";
field public static final String KEY_MMS_NAI_SUFFIX_STRING = "naiSuffix";
+ field public static final String KEY_MMS_NETWORK_RELEASE_TIMEOUT_MILLIS_INT = "mms_network_release_timeout_millis_int";
field public static final String KEY_MMS_NOTIFY_WAP_MMSC_ENABLED_BOOL = "enabledNotifyWapMMSC";
field public static final String KEY_MMS_RECIPIENT_LIMIT_INT = "recipientLimit";
field public static final String KEY_MMS_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES_BOOL = "sendMultipartSmsAsSeparateMessages";
@@ -43411,14 +43417,18 @@
field public static final int RESULT_RECEIVE_WHILE_ENCRYPTED = 504; // 0x1f8
field public static final int RESULT_REMOTE_EXCEPTION = 31; // 0x1f
field public static final int RESULT_REQUEST_NOT_SUPPORTED = 24; // 0x18
+ field public static final int RESULT_RIL_ABORTED = 137; // 0x89
field public static final int RESULT_RIL_ACCESS_BARRED = 122; // 0x7a
field public static final int RESULT_RIL_BLOCKED_DUE_TO_CALL = 123; // 0x7b
field public static final int RESULT_RIL_CANCELLED = 119; // 0x77
+ field public static final int RESULT_RIL_DEVICE_IN_USE = 136; // 0x88
field public static final int RESULT_RIL_ENCODING_ERR = 109; // 0x6d
field public static final int RESULT_RIL_GENERIC_ERROR = 124; // 0x7c
field public static final int RESULT_RIL_INTERNAL_ERR = 113; // 0x71
field public static final int RESULT_RIL_INVALID_ARGUMENTS = 104; // 0x68
field public static final int RESULT_RIL_INVALID_MODEM_STATE = 115; // 0x73
+ field public static final int RESULT_RIL_INVALID_RESPONSE = 125; // 0x7d
+ field public static final int RESULT_RIL_INVALID_SIM_STATE = 130; // 0x82
field public static final int RESULT_RIL_INVALID_SMSC_ADDRESS = 110; // 0x6e
field public static final int RESULT_RIL_INVALID_SMS_FORMAT = 107; // 0x6b
field public static final int RESULT_RIL_INVALID_STATE = 103; // 0x67
@@ -43427,14 +43437,23 @@
field public static final int RESULT_RIL_NETWORK_NOT_READY = 116; // 0x74
field public static final int RESULT_RIL_NETWORK_REJECT = 102; // 0x66
field public static final int RESULT_RIL_NO_MEMORY = 105; // 0x69
+ field public static final int RESULT_RIL_NO_NETWORK_FOUND = 135; // 0x87
field public static final int RESULT_RIL_NO_RESOURCES = 118; // 0x76
+ field public static final int RESULT_RIL_NO_SMS_TO_ACK = 131; // 0x83
+ field public static final int RESULT_RIL_NO_SUBSCRIPTION = 134; // 0x86
field public static final int RESULT_RIL_OPERATION_NOT_ALLOWED = 117; // 0x75
field public static final int RESULT_RIL_RADIO_NOT_AVAILABLE = 100; // 0x64
field public static final int RESULT_RIL_REQUEST_NOT_SUPPORTED = 114; // 0x72
field public static final int RESULT_RIL_REQUEST_RATE_LIMITED = 106; // 0x6a
field public static final int RESULT_RIL_SIMULTANEOUS_SMS_AND_CALL_NOT_ALLOWED = 121; // 0x79
field public static final int RESULT_RIL_SIM_ABSENT = 120; // 0x78
+ field public static final int RESULT_RIL_SIM_BUSY = 132; // 0x84
+ field public static final int RESULT_RIL_SIM_ERROR = 129; // 0x81
+ field public static final int RESULT_RIL_SIM_FULL = 133; // 0x85
+ field public static final int RESULT_RIL_SIM_PIN2 = 126; // 0x7e
+ field public static final int RESULT_RIL_SIM_PUK2 = 127; // 0x7f
field public static final int RESULT_RIL_SMS_SEND_FAIL_RETRY = 101; // 0x65
+ field public static final int RESULT_RIL_SUBSCRIPTION_NOT_AVAILABLE = 128; // 0x80
field public static final int RESULT_RIL_SYSTEM_ERR = 108; // 0x6c
field public static final int RESULT_SMS_BLOCKED_DURING_EMERGENCY = 29; // 0x1d
field public static final int RESULT_SMS_SEND_RETRY_FAILED = 30; // 0x1e
@@ -48552,6 +48571,12 @@
field public static final int VERTICAL_GRAVITY_MASK = 112; // 0x70
}
+ public class HandwritingDelegateConfiguration {
+ ctor public HandwritingDelegateConfiguration(@IdRes int, @NonNull Runnable);
+ method public int getDelegatorViewId();
+ method @NonNull public Runnable getInitiationCallback();
+ }
+
public class HapticFeedbackConstants {
field public static final int CLOCK_TICK = 4; // 0x4
field public static final int CONFIRM = 16; // 0x10
@@ -49569,16 +49594,13 @@
}
public final class PixelCopy {
- method @NonNull public static android.view.PixelCopy.Request ofSurface(@NonNull android.view.Surface, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.view.PixelCopy.CopyResult>);
- method @NonNull public static android.view.PixelCopy.Request ofSurface(@NonNull android.view.SurfaceView, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.view.PixelCopy.CopyResult>);
- method @NonNull public static android.view.PixelCopy.Request ofWindow(@NonNull android.view.Window, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.view.PixelCopy.CopyResult>);
- method @NonNull public static android.view.PixelCopy.Request ofWindow(@NonNull android.view.View, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.view.PixelCopy.CopyResult>);
method public static void request(@NonNull android.view.SurfaceView, @NonNull android.graphics.Bitmap, @NonNull android.view.PixelCopy.OnPixelCopyFinishedListener, @NonNull android.os.Handler);
method public static void request(@NonNull android.view.SurfaceView, @Nullable android.graphics.Rect, @NonNull android.graphics.Bitmap, @NonNull android.view.PixelCopy.OnPixelCopyFinishedListener, @NonNull android.os.Handler);
method public static void request(@NonNull android.view.Surface, @NonNull android.graphics.Bitmap, @NonNull android.view.PixelCopy.OnPixelCopyFinishedListener, @NonNull android.os.Handler);
method public static void request(@NonNull android.view.Surface, @Nullable android.graphics.Rect, @NonNull android.graphics.Bitmap, @NonNull android.view.PixelCopy.OnPixelCopyFinishedListener, @NonNull android.os.Handler);
method public static void request(@NonNull android.view.Window, @NonNull android.graphics.Bitmap, @NonNull android.view.PixelCopy.OnPixelCopyFinishedListener, @NonNull android.os.Handler);
method public static void request(@NonNull android.view.Window, @Nullable android.graphics.Rect, @NonNull android.graphics.Bitmap, @NonNull android.view.PixelCopy.OnPixelCopyFinishedListener, @NonNull android.os.Handler);
+ method public static void request(@NonNull android.view.PixelCopy.Request);
field public static final int ERROR_DESTINATION_INVALID = 5; // 0x5
field public static final int ERROR_SOURCE_INVALID = 4; // 0x4
field public static final int ERROR_SOURCE_NO_DATA = 3; // 0x3
@@ -49587,19 +49609,28 @@
field public static final int SUCCESS = 0; // 0x0
}
- public static final class PixelCopy.CopyResult {
- method @NonNull public android.graphics.Bitmap getBitmap();
- method public int getStatus();
- }
-
public static interface PixelCopy.OnPixelCopyFinishedListener {
method public void onPixelCopyFinished(int);
}
public static final class PixelCopy.Request {
- method public void request();
- method @NonNull public android.view.PixelCopy.Request setDestinationBitmap(@Nullable android.graphics.Bitmap);
- method @NonNull public android.view.PixelCopy.Request setSourceRect(@Nullable android.graphics.Rect);
+ method @Nullable public android.graphics.Bitmap getDestinationBitmap();
+ method @Nullable public android.graphics.Rect getSourceRect();
+ method @NonNull public static android.view.PixelCopy.Request.Builder ofSurface(@NonNull android.view.Surface, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.view.PixelCopy.Result>);
+ method @NonNull public static android.view.PixelCopy.Request.Builder ofSurface(@NonNull android.view.SurfaceView, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.view.PixelCopy.Result>);
+ method @NonNull public static android.view.PixelCopy.Request.Builder ofWindow(@NonNull android.view.Window, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.view.PixelCopy.Result>);
+ method @NonNull public static android.view.PixelCopy.Request.Builder ofWindow(@NonNull android.view.View, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.view.PixelCopy.Result>);
+ }
+
+ public static final class PixelCopy.Request.Builder {
+ method @NonNull public android.view.PixelCopy.Request build();
+ method @NonNull public android.view.PixelCopy.Request.Builder setDestinationBitmap(@Nullable android.graphics.Bitmap);
+ method @NonNull public android.view.PixelCopy.Request.Builder setSourceRect(@Nullable android.graphics.Rect);
+ }
+
+ public static final class PixelCopy.Result {
+ method @NonNull public android.graphics.Bitmap getBitmap();
+ method public int getStatus();
}
public final class PointerIcon implements android.os.Parcelable {
@@ -50162,6 +50193,7 @@
method public float getHandwritingBoundsOffsetLeft();
method public float getHandwritingBoundsOffsetRight();
method public float getHandwritingBoundsOffsetTop();
+ method @Nullable public android.view.HandwritingDelegateConfiguration getHandwritingDelegateConfiguration();
method public final boolean getHasOverlappingRendering();
method public final int getHeight();
method public void getHitRect(android.graphics.Rect);
@@ -50528,6 +50560,7 @@
method public void setForegroundTintList(@Nullable android.content.res.ColorStateList);
method public void setForegroundTintMode(@Nullable android.graphics.PorterDuff.Mode);
method public void setHandwritingBoundsOffsets(float, float, float, float);
+ method public void setHandwritingDelegateConfiguration(@Nullable android.view.HandwritingDelegateConfiguration);
method public void setHapticFeedbackEnabled(boolean);
method public void setHasTransientState(boolean);
method public void setHorizontalFadingEdgeEnabled(boolean);
diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt
index 88efcce..ce18745 100644
--- a/core/api/module-lib-current.txt
+++ b/core/api/module-lib-current.txt
@@ -340,10 +340,6 @@
method public boolean shouldBypassCache(@NonNull Q);
}
- public interface Parcelable {
- method public default int getStability();
- }
-
public class Process {
method public static final int getAppUidForSdkSandboxUid(int);
method public static final boolean isSdkSandboxUid(int);
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index a382ecf..fdb5e07 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -9670,6 +9670,7 @@
}
public interface Parcelable {
+ method public default int getStability();
field public static final int PARCELABLE_STABILITY_LOCAL = 0; // 0x0
field public static final int PARCELABLE_STABILITY_VINTF = 1; // 0x1
}
@@ -9678,7 +9679,6 @@
ctor public ParcelableHolder(int);
method public int describeContents();
method @Nullable public <T extends android.os.Parcelable> T getParcelable(@NonNull Class<T>);
- method public int getStability();
method public void readFromParcel(@NonNull android.os.Parcel);
method public void setParcelable(@Nullable android.os.Parcelable);
method public void writeToParcel(@NonNull android.os.Parcel, int);
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index ef74a3e..6e87134 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -419,7 +419,7 @@
}
public final class SyncNotedAppOp implements android.os.Parcelable {
- ctor public SyncNotedAppOp(int, @IntRange(from=0L) int, @Nullable String, @NonNull String);
+ ctor public SyncNotedAppOp(int, @IntRange(from=0L) int, @Nullable String, @Nullable String);
}
public class TaskInfo {
diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java
index 4b1b0a2..308e996 100644
--- a/core/java/android/app/ActivityManagerInternal.java
+++ b/core/java/android/app/ActivityManagerInternal.java
@@ -389,6 +389,10 @@
*/
public abstract boolean isAppStartModeDisabled(int uid, String packageName);
+ /**
+ * Returns the ids of the current user and all of its profiles (if any), regardless of the
+ * running state of the profiles.
+ */
public abstract int[] getCurrentProfileIds();
public abstract UserInfo getCurrentUser();
public abstract void ensureNotSpecialUser(@UserIdInt int userId);
diff --git a/core/java/android/app/SyncNotedAppOp.java b/core/java/android/app/SyncNotedAppOp.java
index f156b30..f674e88 100644
--- a/core/java/android/app/SyncNotedAppOp.java
+++ b/core/java/android/app/SyncNotedAppOp.java
@@ -56,7 +56,7 @@
* The package this op applies to
* @hide
*/
- private final @NonNull String mPackageName;
+ private final @Nullable String mPackageName;
/**
* Native code relies on parcel ordering, do not change
@@ -64,7 +64,7 @@
*/
@TestApi
public SyncNotedAppOp(int opMode, @IntRange(from = 0L) int opCode,
- @Nullable String attributionTag, @NonNull String packageName) {
+ @Nullable String attributionTag, @Nullable String packageName) {
this.mOpCode = opCode;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mOpCode,
@@ -101,7 +101,7 @@
* @hide
*/
public SyncNotedAppOp(@IntRange(from = 0L) int opCode, @Nullable String attributionTag,
- @NonNull String packageName) {
+ @Nullable String packageName) {
this(AppOpsManager.MODE_IGNORED, opCode, attributionTag, packageName);
}
@@ -152,7 +152,7 @@
* @hide
*/
@DataClass.Generated.Member
- public @NonNull String getPackageName() {
+ public @Nullable String getPackageName() {
return mPackageName;
}
@@ -211,11 +211,12 @@
byte flg = 0;
if (mAttributionTag != null) flg |= 0x4;
+ if (mPackageName != null) flg |= 0x8;
dest.writeByte(flg);
dest.writeInt(mOpMode);
dest.writeInt(mOpCode);
if (mAttributionTag != null) dest.writeString(mAttributionTag);
- dest.writeString(mPackageName);
+ if (mPackageName != null) dest.writeString(mPackageName);
}
@Override
@@ -233,7 +234,7 @@
int opMode = in.readInt();
int opCode = in.readInt();
String attributionTag = (flg & 0x4) == 0 ? null : in.readString();
- String packageName = in.readString();
+ String packageName = (flg & 0x8) == 0 ? null : in.readString();
this.mOpMode = opMode;
this.mOpCode = opCode;
@@ -243,8 +244,6 @@
"to", AppOpsManager._NUM_OP - 1);
this.mAttributionTag = attributionTag;
this.mPackageName = packageName;
- com.android.internal.util.AnnotationValidations.validate(
- NonNull.class, null, mPackageName);
// onConstructed(); // You can define this method to get a callback
}
@@ -264,10 +263,10 @@
};
@DataClass.Generated(
- time = 1643320427700L,
+ time = 1667247337573L,
codegenVersion = "1.0.23",
sourceFile = "frameworks/base/core/java/android/app/SyncNotedAppOp.java",
- inputSignatures = "private final int mOpMode\nprivate final @android.annotation.IntRange int mOpCode\nprivate final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate final @android.annotation.NonNull java.lang.String mPackageName\npublic @android.annotation.NonNull java.lang.String getOp()\npublic int getOpMode()\nprivate java.lang.String opCodeToString()\nclass SyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genConstructor=false, genToString=true)")
+ inputSignatures = "private final int mOpMode\nprivate final @android.annotation.IntRange int mOpCode\nprivate final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate final @android.annotation.Nullable java.lang.String mPackageName\npublic @android.annotation.NonNull java.lang.String getOp()\npublic int getOpMode()\nprivate java.lang.String opCodeToString()\nclass SyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genConstructor=false, genToString=true)")
@Deprecated
private void __metadata() {}
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index de19687..f4cee5a 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -3864,6 +3864,56 @@
public static final String EXTRA_RESOURCE_IDS =
"android.app.extra.RESOURCE_IDS";
+ /** Allow the user to choose whether to enable MTE on the device. */
+ public static final int MTE_NOT_CONTROLLED_BY_POLICY = 0;
+
+ /**
+ * Require that MTE be enabled on the device, if supported. Can be set by a device owner or a
+ * profile owner of an organization-owned managed profile.
+ */
+ public static final int MTE_ENABLED = 1;
+
+ /** Require that MTE be disabled on the device. Can be set by a device owner. */
+ public static final int MTE_DISABLED = 2;
+
+ /** @hide */
+ @IntDef(
+ prefix = {"MTE_"},
+ value = {MTE_ENABLED, MTE_DISABLED, MTE_NOT_CONTROLLED_BY_POLICY})
+ @Retention(RetentionPolicy.SOURCE)
+ public static @interface MtePolicy {}
+
+ /**
+ * Set MTE policy for device. MTE_ENABLED does not necessarily enable MTE if set on a device
+ * that does not support MTE.
+ *
+ * The default policy is MTE_NOT_CONTROLLED_BY_POLICY.
+ *
+ * Memory Tagging Extension (MTE) is a CPU extension that allows to protect against certain
+ * classes of security problems at a small runtime performance cost overhead.
+ *
+ * @param policy the policy to be set
+ */
+ public void setMtePolicy(@MtePolicy int policy) {
+ // TODO(b/244290023): implement
+ // This is SecurityException to temporarily make ParentProfileTest happy.
+ // This is not used.
+ throw new SecurityException("not implemented");
+ }
+
+ /**
+ * Get currently set MTE policy. This is not necessarily the same as the state of MTE on the
+ * device, as the device might not support MTE.
+ *
+ * @return the currently set policy
+ */
+ public @MtePolicy int getMtePolicy() {
+ // TODO(b/244290023): implement
+ // This is SecurityException to temporarily make ParentProfileTest happy.
+ // This is not used.
+ throw new SecurityException("not implemented");
+ }
+
/**
* This object is a single place to tack on invalidation and disable calls. All
* binder caches in this class derive from this Config, so all can be invalidated or
diff --git a/core/java/android/credentials/Credential.java b/core/java/android/credentials/Credential.java
index fed2592..db89170 100644
--- a/core/java/android/credentials/Credential.java
+++ b/core/java/android/credentials/Credential.java
@@ -36,7 +36,8 @@
*
* @hide
*/
- @NonNull public static final String TYPE_PASSWORD = "android.credentials.TYPE_PASSWORD";
+ @NonNull public static final String TYPE_PASSWORD_CREDENTIAL =
+ "android.credentials.TYPE_PASSWORD_CREDENTIAL";
/**
* The credential type.
diff --git a/core/java/android/hardware/usb/UsbDeviceConnection.java b/core/java/android/hardware/usb/UsbDeviceConnection.java
index 60d8cac..7c2e518 100644
--- a/core/java/android/hardware/usb/UsbDeviceConnection.java
+++ b/core/java/android/hardware/usb/UsbDeviceConnection.java
@@ -108,6 +108,34 @@
}
/**
+ * This is meant to be called by UsbRequest's queue() in order to synchronize on
+ * UsbDeviceConnection's mLock to prevent the connection being closed while queueing.
+ */
+ /* package */ boolean queueRequest(UsbRequest request, ByteBuffer buffer, int length) {
+ synchronized (mLock) {
+ if (!isOpen()) {
+ return false;
+ }
+
+ return request.queueIfConnectionOpen(buffer, length);
+ }
+ }
+
+ /**
+ * This is meant to be called by UsbRequest's queue() in order to synchronize on
+ * UsbDeviceConnection's mLock to prevent the connection being closed while queueing.
+ */
+ /* package */ boolean queueRequest(UsbRequest request, @Nullable ByteBuffer buffer) {
+ synchronized (mLock) {
+ if (!isOpen()) {
+ return false;
+ }
+
+ return request.queueIfConnectionOpen(buffer);
+ }
+ }
+
+ /**
* Releases all system resources related to the device.
* Once the object is closed it cannot be used again.
* The client must call {@link UsbManager#openDevice} again
diff --git a/core/java/android/hardware/usb/UsbRequest.java b/core/java/android/hardware/usb/UsbRequest.java
index 6ac5e8d..beb0f8d 100644
--- a/core/java/android/hardware/usb/UsbRequest.java
+++ b/core/java/android/hardware/usb/UsbRequest.java
@@ -113,11 +113,13 @@
* Releases all resources related to this request.
*/
public void close() {
- if (mNativeContext != 0) {
- mEndpoint = null;
- mConnection = null;
- native_close();
- mCloseGuard.close();
+ synchronized (mLock) {
+ if (mNativeContext != 0) {
+ mEndpoint = null;
+ mConnection = null;
+ native_close();
+ mCloseGuard.close();
+ }
}
}
@@ -191,10 +193,32 @@
*/
@Deprecated
public boolean queue(ByteBuffer buffer, int length) {
+ UsbDeviceConnection connection = mConnection;
+ if (connection == null) {
+ // The expected exception by CTS Verifier - USB Device test
+ throw new NullPointerException("invalid connection");
+ }
+
+ // Calling into the underlying UsbDeviceConnection to synchronize on its lock, to prevent
+ // the connection being closed while queueing.
+ return connection.queueRequest(this, buffer, length);
+ }
+
+ /**
+ * This is meant to be called from UsbDeviceConnection after synchronizing using the lock over
+ * there, to prevent the connection being closed while queueing.
+ */
+ /* package */ boolean queueIfConnectionOpen(ByteBuffer buffer, int length) {
+ UsbDeviceConnection connection = mConnection;
+ if (connection == null || !connection.isOpen()) {
+ // The expected exception by CTS Verifier - USB Device test
+ throw new NullPointerException("invalid connection");
+ }
+
boolean out = (mEndpoint.getDirection() == UsbConstants.USB_DIR_OUT);
boolean result;
- if (mConnection.getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P
+ if (connection.getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P
&& length > MAX_USBFS_BUFFER_SIZE) {
length = MAX_USBFS_BUFFER_SIZE;
}
@@ -243,6 +267,28 @@
* @return true if the queueing operation succeeded
*/
public boolean queue(@Nullable ByteBuffer buffer) {
+ UsbDeviceConnection connection = mConnection;
+ if (connection == null) {
+ // The expected exception by CTS Verifier - USB Device test
+ throw new IllegalStateException("invalid connection");
+ }
+
+ // Calling into the underlying UsbDeviceConnection to synchronize on its lock, to prevent
+ // the connection being closed while queueing.
+ return connection.queueRequest(this, buffer);
+ }
+
+ /**
+ * This is meant to be called from UsbDeviceConnection after synchronizing using the lock over
+ * there, to prevent the connection being closed while queueing.
+ */
+ /* package */ boolean queueIfConnectionOpen(@Nullable ByteBuffer buffer) {
+ UsbDeviceConnection connection = mConnection;
+ if (connection == null || !connection.isOpen()) {
+ // The expected exception by CTS Verifier - USB Device test
+ throw new IllegalStateException("invalid connection");
+ }
+
// Request need to be initialized
Preconditions.checkState(mNativeContext != 0, "request is not initialized");
@@ -260,7 +306,7 @@
mIsUsingNewQueue = true;
wasQueued = native_queue(null, 0, 0);
} else {
- if (mConnection.getContext().getApplicationInfo().targetSdkVersion
+ if (connection.getContext().getApplicationInfo().targetSdkVersion
< Build.VERSION_CODES.P) {
// Can only send/receive MAX_USBFS_BUFFER_SIZE bytes at once
Preconditions.checkArgumentInRange(buffer.remaining(), 0, MAX_USBFS_BUFFER_SIZE,
@@ -363,11 +409,12 @@
* @return true if cancelling succeeded
*/
public boolean cancel() {
- if (mConnection == null) {
+ UsbDeviceConnection connection = mConnection;
+ if (connection == null) {
return false;
}
- return mConnection.cancelRequest(this);
+ return connection.cancelRequest(this);
}
/**
@@ -382,7 +429,8 @@
* @return true if cancelling succeeded.
*/
/* package */ boolean cancelIfOpen() {
- if (mNativeContext == 0 || (mConnection != null && !mConnection.isOpen())) {
+ UsbDeviceConnection connection = mConnection;
+ if (mNativeContext == 0 || (connection != null && !connection.isOpen())) {
Log.w(TAG,
"Detected attempt to cancel a request on a connection which isn't open");
return false;
diff --git a/core/java/android/inputmethodservice/IRemoteInputConnectionInvoker.java b/core/java/android/inputmethodservice/IRemoteInputConnectionInvoker.java
index 4f09bee..49123aa 100644
--- a/core/java/android/inputmethodservice/IRemoteInputConnectionInvoker.java
+++ b/core/java/android/inputmethodservice/IRemoteInputConnectionInvoker.java
@@ -26,18 +26,12 @@
import android.view.KeyEvent;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
-import android.view.inputmethod.DeleteGesture;
-import android.view.inputmethod.DeleteRangeGesture;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.HandwritingGesture;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputContentInfo;
-import android.view.inputmethod.InsertGesture;
-import android.view.inputmethod.JoinOrSplitGesture;
-import android.view.inputmethod.RemoveSpaceGesture;
-import android.view.inputmethod.SelectGesture;
-import android.view.inputmethod.SelectRangeGesture;
+import android.view.inputmethod.ParcelableHandwritingGesture;
import android.view.inputmethod.SurroundingText;
import android.view.inputmethod.TextAttribute;
@@ -637,50 +631,19 @@
}
/**
- * Invokes one of {@link IRemoteInputConnection#performHandwritingSelectGesture},
- * {@link IRemoteInputConnection#performHandwritingSelectRangeGesture},
- * {@link IRemoteInputConnection#performHandwritingDeleteGesture},
- * {@link IRemoteInputConnection#performHandwritingDeleteRangeGesture},
- * {@link IRemoteInputConnection#performHandwritingInsertGesture},
- * {@link IRemoteInputConnection#performHandwritingRemoveSpaceGesture},
- * {@link IRemoteInputConnection#performHandwritingJoinOrSplitGesture}.
+ * Invokes {@link IRemoteInputConnection#performHandwritingGesture(
+ * InputConnectionCommandHeader, ParcelableHandwritingGesture, ResultReceiver)}.
*/
@AnyThread
- public void performHandwritingGesture(
- @NonNull HandwritingGesture gesture, @Nullable @CallbackExecutor Executor executor,
- @Nullable IntConsumer consumer) {
-
+ public void performHandwritingGesture(@NonNull ParcelableHandwritingGesture gesture,
+ @Nullable @CallbackExecutor Executor executor, @Nullable IntConsumer consumer) {
ResultReceiver resultReceiver = null;
if (consumer != null) {
Objects.requireNonNull(executor);
resultReceiver = new IntResultReceiver(executor, consumer);
}
try {
- if (gesture instanceof SelectGesture) {
- mConnection.performHandwritingSelectGesture(
- createHeader(), (SelectGesture) gesture, resultReceiver);
- } else if (gesture instanceof SelectRangeGesture) {
- mConnection.performHandwritingSelectRangeGesture(
- createHeader(), (SelectRangeGesture) gesture, resultReceiver);
- } else if (gesture instanceof InsertGesture) {
- mConnection.performHandwritingInsertGesture(
- createHeader(), (InsertGesture) gesture, resultReceiver);
- } else if (gesture instanceof DeleteGesture) {
- mConnection.performHandwritingDeleteGesture(
- createHeader(), (DeleteGesture) gesture, resultReceiver);
- } else if (gesture instanceof DeleteRangeGesture) {
- mConnection.performHandwritingDeleteRangeGesture(
- createHeader(), (DeleteRangeGesture) gesture, resultReceiver);
- } else if (gesture instanceof RemoveSpaceGesture) {
- mConnection.performHandwritingRemoveSpaceGesture(
- createHeader(), (RemoveSpaceGesture) gesture, resultReceiver);
- } else if (gesture instanceof JoinOrSplitGesture) {
- mConnection.performHandwritingJoinOrSplitGesture(
- createHeader(), (JoinOrSplitGesture) gesture, resultReceiver);
- } else if (consumer != null && executor != null) {
- executor.execute(()
- -> consumer.accept(InputConnection.HANDWRITING_GESTURE_RESULT_UNSUPPORTED));
- }
+ mConnection.performHandwritingGesture(createHeader(), gesture, resultReceiver);
} catch (RemoteException e) {
if (consumer != null && executor != null) {
executor.execute(() -> consumer.accept(
diff --git a/core/java/android/inputmethodservice/RemoteInputConnection.java b/core/java/android/inputmethodservice/RemoteInputConnection.java
index 09e86c4..7d8dd5e 100644
--- a/core/java/android/inputmethodservice/RemoteInputConnection.java
+++ b/core/java/android/inputmethodservice/RemoteInputConnection.java
@@ -32,6 +32,7 @@
import android.view.inputmethod.HandwritingGesture;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputContentInfo;
+import android.view.inputmethod.ParcelableHandwritingGesture;
import android.view.inputmethod.SurroundingText;
import android.view.inputmethod.TextAttribute;
@@ -418,7 +419,8 @@
public void performHandwritingGesture(
@NonNull HandwritingGesture gesture, @Nullable @CallbackExecutor Executor executor,
@Nullable IntConsumer consumer) {
- mInvoker.performHandwritingGesture(gesture, executor, consumer);
+ mInvoker.performHandwritingGesture(ParcelableHandwritingGesture.of(gesture), executor,
+ consumer);
}
@AnyThread
diff --git a/core/java/android/os/Parcelable.java b/core/java/android/os/Parcelable.java
index 8a80457..a2b0486 100644
--- a/core/java/android/os/Parcelable.java
+++ b/core/java/android/os/Parcelable.java
@@ -188,7 +188,7 @@
* @return true if this parcelable is stable.
* @hide
*/
- @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
+ @SystemApi(client = SystemApi.Client.PRIVILEGED_APPS)
default @Stability int getStability() {
return PARCELABLE_STABILITY_LOCAL;
}
diff --git a/core/java/android/service/credentials/CredentialEntry.java b/core/java/android/service/credentials/CredentialEntry.java
index a3fa979..1d4ac25 100644
--- a/core/java/android/service/credentials/CredentialEntry.java
+++ b/core/java/android/service/credentials/CredentialEntry.java
@@ -172,9 +172,11 @@
* {@code credential}, or the {@code pendingIntent}.
*/
public @NonNull Builder setPendingIntent(@Nullable PendingIntent pendingIntent) {
- Preconditions.checkState(pendingIntent != null && mCredential != null,
- "credential is already set. Cannot set both the pendingIntent "
- + "and the credential");
+ if (pendingIntent != null) {
+ Preconditions.checkState(mCredential != null,
+ "credential is already set. Cannot set both the pendingIntent "
+ + "and the credential");
+ }
mPendingIntent = pendingIntent;
return this;
}
@@ -186,9 +188,11 @@
* the {@code pendingIntent}, or the {@code credential}.
*/
public @NonNull Builder setCredential(@Nullable Credential credential) {
- Preconditions.checkState(credential != null && mPendingIntent != null,
- "pendingIntent is already set. Cannot set both the "
- + "pendingIntent and the credential");
+ if (credential != null) {
+ Preconditions.checkState(mPendingIntent != null,
+ "pendingIntent is already set. Cannot set both the "
+ + "pendingIntent and the credential");
+ }
mCredential = credential;
return this;
}
diff --git a/core/java/android/service/credentials/SaveEntry.java b/core/java/android/service/credentials/SaveEntry.java
index abe51d4..55ff6ff 100644
--- a/core/java/android/service/credentials/SaveEntry.java
+++ b/core/java/android/service/credentials/SaveEntry.java
@@ -17,17 +17,11 @@
package android.service.credentials;
import android.annotation.NonNull;
-import android.annotation.Nullable;
import android.app.PendingIntent;
import android.app.slice.Slice;
-import android.credentials.Credential;
import android.os.Parcel;
import android.os.Parcelable;
-import com.android.internal.util.Preconditions;
-
-import java.util.Objects;
-
/**
* An entry to be shown on the UI. This entry represents where the credential to be created will
* be stored. Examples include user's account, family group etc.
@@ -36,13 +30,11 @@
*/
public final class SaveEntry implements Parcelable {
private final @NonNull Slice mSlice;
- private final @Nullable PendingIntent mPendingIntent;
- private final @Nullable Credential mCredential;
+ private final @NonNull PendingIntent mPendingIntent;
private SaveEntry(@NonNull Parcel in) {
mSlice = in.readTypedObject(Slice.CREATOR);
mPendingIntent = in.readTypedObject(PendingIntent.CREATOR);
- mCredential = in.readTypedObject(Credential.CREATOR);
}
public static final @NonNull Creator<SaveEntry> CREATOR = new Creator<SaveEntry>() {
@@ -66,18 +58,23 @@
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeTypedObject(mSlice, flags);
dest.writeTypedObject(mPendingIntent, flags);
- dest.writeTypedObject(mCredential, flags);
}
- /* package-private */ SaveEntry(
+ /**
+ * Constructs a save entry to be displayed on the UI.
+ *
+ * @param slice the display content to be displayed on the UI, along with this entry
+ * @param pendingIntent the intent to be invoked when the user selects this entry
+ */
+ public SaveEntry(
@NonNull Slice slice,
- @Nullable PendingIntent pendingIntent,
- @Nullable Credential credential) {
+ @NonNull PendingIntent pendingIntent) {
this.mSlice = slice;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mSlice);
this.mPendingIntent = pendingIntent;
- this.mCredential = credential;
+ com.android.internal.util.AnnotationValidations.validate(
+ NonNull.class, null, mPendingIntent);
}
/** Returns the content to be displayed with this save entry on the UI. */
@@ -86,76 +83,7 @@
}
/** Returns the pendingIntent to be invoked when this save entry on the UI is selectcd. */
- public @Nullable PendingIntent getPendingIntent() {
+ public @NonNull PendingIntent getPendingIntent() {
return mPendingIntent;
}
-
- /** Returns the credential produced by the {@link CreateCredentialRequest}. */
- public @Nullable Credential getCredential() {
- return mCredential;
- }
-
- /**
- * A builder for {@link SaveEntry}.
- */
- public static final class Builder {
-
- private @NonNull Slice mSlice;
- private @Nullable PendingIntent mPendingIntent;
- private @Nullable Credential mCredential;
-
- /**
- * Builds the instance.
- * @param slice the content to be displayed with this save entry
- *
- * @throws NullPointerException If {@code slice} is null.
- */
- public Builder(@NonNull Slice slice) {
- mSlice = Objects.requireNonNull(slice, "slice must not be null");
- }
-
- /**
- * Sets the pendingIntent to be invoked when this entry is selected by the user.
- *
- * @throws IllegalStateException If {@code credential} is already set. Must only set either
- * {@code credential}, or the {@code pendingIntent}.
- */
- public @NonNull Builder setPendingIntent(@Nullable PendingIntent pendingIntent) {
- Preconditions.checkState(pendingIntent != null
- && mCredential != null, "credential is already set. Must only set "
- + "either the pendingIntent or the credential");
- mPendingIntent = pendingIntent;
- return this;
- }
-
- /**
- * Sets the credential to be returned when this entry is selected by the user.
- *
- * @throws IllegalStateException If {@code pendingIntent} is already set. Must only
- * set either the {@code pendingIntent}, or {@code credential}.
- */
- public @NonNull Builder setCredential(@Nullable Credential credential) {
- Preconditions.checkState(credential != null && mPendingIntent != null,
- "pendingIntent is already set. Must only set either the credential "
- + "or the pendingIntent");
- mCredential = credential;
- return this;
- }
-
- /**
- * Builds the instance.
- *
- * @throws IllegalStateException if both {@code pendingIntent} and {@code credential}
- * are null.
- */
- public @NonNull SaveEntry build() {
- Preconditions.checkState(mPendingIntent == null && mCredential == null,
- "pendingIntent and credential both must not be null. Must set "
- + "either the pendingIntnet or the credential");
- return new SaveEntry(
- mSlice,
- mPendingIntent,
- mCredential);
- }
- }
}
diff --git a/core/java/android/util/FeatureFlagUtils.java b/core/java/android/util/FeatureFlagUtils.java
index d1f05ec..7b6a6d2 100644
--- a/core/java/android/util/FeatureFlagUtils.java
+++ b/core/java/android/util/FeatureFlagUtils.java
@@ -103,6 +103,25 @@
public static final String SETTINGS_NEW_KEYBOARD_UI = "settings_new_keyboard_ui";
/**
+ * Enable new shortcut list UI
+ * @hide
+ */
+ public static final String SETTINGS_NEW_KEYBOARD_SHORTCUT = "settings_new_keyboard_shortcut";
+
+ /**
+ * Enable new modifier key settings UI
+ * @hide
+ */
+ public static final String SETTINGS_NEW_KEYBOARD_MODIFIER_KEY =
+ "settings_new_keyboard_modifier_key";
+
+ /**
+ * Enable new trackpad settings UI
+ * @hide
+ */
+ public static final String SETTINGS_NEW_KEYBOARD_TRACKPAD = "settings_new_keyboard_trackpad";
+
+ /**
* Enable the new pages which is implemented with SPA.
* @hide
*/
@@ -143,6 +162,9 @@
DEFAULT_FLAGS.put(SETTINGS_HIDE_SECOND_LAYER_PAGE_NAVIGATE_UP_BUTTON_IN_TWO_PANE, "true");
DEFAULT_FLAGS.put(SETTINGS_AUTO_TEXT_WRAPPING, "false");
DEFAULT_FLAGS.put(SETTINGS_NEW_KEYBOARD_UI, "false");
+ DEFAULT_FLAGS.put(SETTINGS_NEW_KEYBOARD_SHORTCUT, "false");
+ DEFAULT_FLAGS.put(SETTINGS_NEW_KEYBOARD_MODIFIER_KEY, "false");
+ DEFAULT_FLAGS.put(SETTINGS_NEW_KEYBOARD_TRACKPAD, "false");
DEFAULT_FLAGS.put(SETTINGS_ENABLE_SPA, "false");
DEFAULT_FLAGS.put(SETTINGS_ADB_METRICS_WRITER, "false");
}
@@ -158,6 +180,9 @@
PERSISTENT_FLAGS.add(SETTINGS_HIDE_SECOND_LAYER_PAGE_NAVIGATE_UP_BUTTON_IN_TWO_PANE);
PERSISTENT_FLAGS.add(SETTINGS_AUTO_TEXT_WRAPPING);
PERSISTENT_FLAGS.add(SETTINGS_NEW_KEYBOARD_UI);
+ PERSISTENT_FLAGS.add(SETTINGS_NEW_KEYBOARD_SHORTCUT);
+ PERSISTENT_FLAGS.add(SETTINGS_NEW_KEYBOARD_MODIFIER_KEY);
+ PERSISTENT_FLAGS.add(SETTINGS_NEW_KEYBOARD_TRACKPAD);
}
/**
diff --git a/core/java/android/view/HandwritingDelegateConfiguration.java b/core/java/android/view/HandwritingDelegateConfiguration.java
new file mode 100644
index 0000000..524bb4c
--- /dev/null
+++ b/core/java/android/view/HandwritingDelegateConfiguration.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view;
+
+import android.annotation.IdRes;
+import android.annotation.NonNull;
+
+/**
+ * Configuration for a view to act as a handwriting initiation delegate. This allows handwriting
+ * mode for a delegator editor view to be initiated by stylus movement on the delegate view.
+ *
+ * <p>If a stylus {@link MotionEvent} occurs within the delegate view's bounds, the callback
+ * returned by {@link #getInitiationCallback()} will be called. The callback implementation is
+ * expected to show and focus the delegator editor view. If a view with identifier matching {@link
+ * #getDelegatorViewId()} creates an input connection while the same stylus {@link MotionEvent}
+ * sequence is ongoing, handwriting mode will be initiated for that view.
+ *
+ * <p>A common use case is a custom view which looks like a text editor but does not actually
+ * support text editing itself, and clicking on the custom view causes an EditText to be shown. To
+ * support handwriting initiation in this case, {@link View#setHandwritingDelegateConfiguration} can
+ * be called on the custom view to configure it as a delegate, and set the EditText as the delegator
+ * by passing the EditText's identifier as the {@code delegatorViewId}. The {@code
+ * initiationCallback} implementation is typically the same as the click listener implementation
+ * which shows the EditText.
+ */
+public class HandwritingDelegateConfiguration {
+ @IdRes private final int mDelegatorViewId;
+ @NonNull private final Runnable mInitiationCallback;
+
+ /**
+ * Constructs a HandwritingDelegateConfiguration instance.
+ *
+ * @param delegatorViewId identifier of the delegator editor view for which handwriting mode
+ * should be initiated
+ * @param initiationCallback callback called when a stylus {@link MotionEvent} occurs within
+ * this view's bounds
+ */
+ public HandwritingDelegateConfiguration(
+ @IdRes int delegatorViewId, @NonNull Runnable initiationCallback) {
+ mDelegatorViewId = delegatorViewId;
+ mInitiationCallback = initiationCallback;
+ }
+
+ /**
+ * Returns the identifier of the delegator editor view for which handwriting mode should be
+ * initiated.
+ */
+ public int getDelegatorViewId() {
+ return mDelegatorViewId;
+ }
+
+ /**
+ * Returns the callback which should be called when a stylus {@link MotionEvent} occurs within
+ * the delegate view's bounds.
+ */
+ @NonNull
+ public Runnable getInitiationCallback() {
+ return mInitiationCallback;
+ }
+}
diff --git a/core/java/android/view/HandwritingInitiator.java b/core/java/android/view/HandwritingInitiator.java
index a0a07b3..2e4073e 100644
--- a/core/java/android/view/HandwritingInitiator.java
+++ b/core/java/android/view/HandwritingInitiator.java
@@ -16,6 +16,7 @@
package android.view;
+import android.annotation.IdRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Rect;
@@ -161,6 +162,15 @@
if (candidateView != null) {
if (candidateView == getConnectedView()) {
startHandwriting(candidateView);
+ } else if (candidateView.getHandwritingDelegateConfiguration() != null) {
+ mState.mDelegatorViewId =
+ candidateView
+ .getHandwritingDelegateConfiguration()
+ .getDelegatorViewId();
+ candidateView
+ .getHandwritingDelegateConfiguration()
+ .getInitiationCallback()
+ .run();
} else {
if (candidateView.getRevealOnFocusHint()) {
candidateView.setRevealOnFocusHint(false);
@@ -259,8 +269,10 @@
}
final Rect handwritingArea = getViewHandwritingArea(connectedView);
- if (isInHandwritingArea(handwritingArea, mState.mStylusDownX,
- mState.mStylusDownY, connectedView)) {
+ if ((mState.mDelegatorViewId != View.NO_ID
+ && mState.mDelegatorViewId == connectedView.getId())
+ || isInHandwritingArea(
+ handwritingArea, mState.mStylusDownX, mState.mStylusDownY, connectedView)) {
startHandwriting(connectedView);
} else {
mState.mShouldInitHandwriting = false;
@@ -287,6 +299,11 @@
if (!view.isAutoHandwritingEnabled()) {
return false;
}
+ // The view may be a handwriting initiation delegate, in which case it is not the editor
+ // view for which handwriting would be started. However, in almost all cases, the return
+ // values of View#isStylusHandwritingAvailable will be the same for the delegate view and
+ // the delegator editor view. So the delegate view can be used to decide whether handwriting
+ // should be triggered.
return view.isStylusHandwritingAvailable();
}
@@ -473,6 +490,13 @@
* built InputConnection.
*/
private boolean mExceedHandwritingSlop;
+ /**
+ * If the current ongoing stylus MotionEvent sequence started over a handwriting initiation
+ * delegate view, then this is the view identifier of the corresponding delegator view. If
+ * the delegator view creates an input connection while the MotionEvent sequence is still
+ * ongoing, then handwriting mode will be initiated for the delegator view.
+ */
+ @IdRes private int mDelegatorViewId = View.NO_ID;
/** The pointer id of the stylus pointer that is being tracked. */
private final int mStylusPointerId;
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 7b6ebf7..49d9e67 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -5063,6 +5063,13 @@
private boolean mHoveringTouchDelegate = false;
/**
+ * Configuration for this view to act as a handwriting initiation delegate. This allows
+ * handwriting mode for a delegator editor view to be initiated by stylus movement on this
+ * delegate view.
+ */
+ private HandwritingDelegateConfiguration mHandwritingDelegateConfiguration;
+
+ /**
* Solid color to use as a background when creating the drawing cache. Enables
* the cache to use 16 bit bitmaps instead of 32 bit.
*/
@@ -12255,6 +12262,30 @@
}
/**
+ * Configures this view to act as a handwriting initiation delegate. This allows handwriting
+ * mode for a delegator editor view to be initiated by stylus movement on this delegate view.
+ *
+ * <p>If {@code null} is passed, this view will no longer act as a handwriting initiation
+ * delegate.
+ */
+ public void setHandwritingDelegateConfiguration(
+ @Nullable HandwritingDelegateConfiguration configuration) {
+ mHandwritingDelegateConfiguration = configuration;
+ if (configuration != null) {
+ setHandwritingArea(new Rect(0, 0, getWidth(), getHeight()));
+ }
+ }
+
+ /**
+ * If this view has been configured as a handwriting initiation delegate, returns the delegate
+ * configuration.
+ */
+ @Nullable
+ public HandwritingDelegateConfiguration getHandwritingDelegateConfiguration() {
+ return mHandwritingDelegateConfiguration;
+ }
+
+ /**
* Gets the coordinates of this view in the coordinate space of the
* {@link Surface} that contains the view.
*
@@ -24205,7 +24236,7 @@
}
}
rebuildOutline();
- if (onCheckIsTextEditor()) {
+ if (onCheckIsTextEditor() || mHandwritingDelegateConfiguration != null) {
setHandwritingArea(new Rect(0, 0, newWidth, newHeight));
}
}
diff --git a/core/java/android/view/inputmethod/ParcelableHandwritingGesture.aidl b/core/java/android/view/inputmethod/ParcelableHandwritingGesture.aidl
new file mode 100644
index 0000000..ffadf82
--- /dev/null
+++ b/core/java/android/view/inputmethod/ParcelableHandwritingGesture.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.inputmethod;
+
+parcelable ParcelableHandwritingGesture;
diff --git a/core/java/android/view/inputmethod/ParcelableHandwritingGesture.java b/core/java/android/view/inputmethod/ParcelableHandwritingGesture.java
new file mode 100644
index 0000000..e4066fc
--- /dev/null
+++ b/core/java/android/view/inputmethod/ParcelableHandwritingGesture.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.inputmethod;
+
+import android.annotation.NonNull;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.Objects;
+
+/**
+ * A generic container of parcelable {@link HandwritingGesture}.
+ *
+ * @hide
+ */
+public final class ParcelableHandwritingGesture implements Parcelable {
+ @NonNull
+ private final HandwritingGesture mGesture;
+ @NonNull
+ private final Parcelable mGestureAsParcelable;
+
+ private ParcelableHandwritingGesture(@NonNull HandwritingGesture gesture) {
+ mGesture = gesture;
+ // For fail-fast.
+ mGestureAsParcelable = (Parcelable) gesture;
+ }
+
+ /**
+ * Creates {@link ParcelableHandwritingGesture} from {@link HandwritingGesture}, which also
+ * implements {@link Parcelable}.
+ *
+ * @param gesture {@link HandwritingGesture} object to be stored.
+ * @return {@link ParcelableHandwritingGesture} to be stored in {@link Parcel}.
+ */
+ @NonNull
+ public static ParcelableHandwritingGesture of(@NonNull HandwritingGesture gesture) {
+ return new ParcelableHandwritingGesture(Objects.requireNonNull(gesture));
+ }
+
+ /**
+ * @return {@link HandwritingGesture} object stored in this container.
+ */
+ @NonNull
+ public HandwritingGesture get() {
+ return mGesture;
+ }
+
+ private static HandwritingGesture createFromParcelInternal(
+ @HandwritingGesture.GestureType int gestureType, @NonNull Parcel parcel) {
+ switch (gestureType) {
+ case HandwritingGesture.GESTURE_TYPE_NONE:
+ throw new UnsupportedOperationException("GESTURE_TYPE_NONE is not supported");
+ case HandwritingGesture.GESTURE_TYPE_SELECT:
+ return SelectGesture.CREATOR.createFromParcel(parcel);
+ case HandwritingGesture.GESTURE_TYPE_SELECT_RANGE:
+ return SelectRangeGesture.CREATOR.createFromParcel(parcel);
+ case HandwritingGesture.GESTURE_TYPE_INSERT:
+ return InsertGesture.CREATOR.createFromParcel(parcel);
+ case HandwritingGesture.GESTURE_TYPE_DELETE:
+ return DeleteGesture.CREATOR.createFromParcel(parcel);
+ case HandwritingGesture.GESTURE_TYPE_DELETE_RANGE:
+ return DeleteRangeGesture.CREATOR.createFromParcel(parcel);
+ case HandwritingGesture.GESTURE_TYPE_JOIN_OR_SPLIT:
+ return JoinOrSplitGesture.CREATOR.createFromParcel(parcel);
+ case HandwritingGesture.GESTURE_TYPE_REMOVE_SPACE:
+ return RemoveSpaceGesture.CREATOR.createFromParcel(parcel);
+ default:
+ throw new UnsupportedOperationException("Unknown type=" + gestureType);
+ }
+ }
+
+ public static final Creator<ParcelableHandwritingGesture> CREATOR = new Parcelable.Creator<>() {
+ @Override
+ public ParcelableHandwritingGesture createFromParcel(Parcel in) {
+ final int gestureType = in.readInt();
+ return new ParcelableHandwritingGesture(createFromParcelInternal(gestureType, in));
+ }
+
+ @Override
+ public ParcelableHandwritingGesture[] newArray(int size) {
+ return new ParcelableHandwritingGesture[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return mGestureAsParcelable.describeContents();
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeInt(mGesture.getGestureType());
+ mGestureAsParcelable.writeToParcel(dest, flags);
+ }
+}
diff --git a/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java b/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java
index f2b7099..e8e7f3a 100644
--- a/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java
+++ b/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java
@@ -982,62 +982,9 @@
@Dispatching(cancellable = true)
@Override
- public void performHandwritingSelectGesture(
- InputConnectionCommandHeader header, SelectGesture gesture,
+ public void performHandwritingGesture(
+ InputConnectionCommandHeader header, ParcelableHandwritingGesture gestureContainer,
ResultReceiver resultReceiver) {
- performHandwritingGestureInternal(header, gesture, resultReceiver);
- }
-
- @Dispatching(cancellable = true)
- @Override
- public void performHandwritingSelectRangeGesture(
- InputConnectionCommandHeader header, SelectRangeGesture gesture,
- ResultReceiver resultReceiver) {
- performHandwritingGestureInternal(header, gesture, resultReceiver);
- }
-
- @Dispatching(cancellable = true)
- @Override
- public void performHandwritingInsertGesture(
- InputConnectionCommandHeader header, InsertGesture gesture,
- ResultReceiver resultReceiver) {
- performHandwritingGestureInternal(header, gesture, resultReceiver);
- }
-
- @Dispatching(cancellable = true)
- @Override
- public void performHandwritingDeleteGesture(
- InputConnectionCommandHeader header, DeleteGesture gesture,
- ResultReceiver resultReceiver) {
- performHandwritingGestureInternal(header, gesture, resultReceiver);
- }
-
- @Dispatching(cancellable = true)
- @Override
- public void performHandwritingDeleteRangeGesture(
- InputConnectionCommandHeader header, DeleteRangeGesture gesture,
- ResultReceiver resultReceiver) {
- performHandwritingGestureInternal(header, gesture, resultReceiver);
- }
-
- @Dispatching(cancellable = true)
- @Override
- public void performHandwritingRemoveSpaceGesture(
- InputConnectionCommandHeader header, RemoveSpaceGesture gesture,
- ResultReceiver resultReceiver) {
- performHandwritingGestureInternal(header, gesture, resultReceiver);
- }
-
- @Dispatching(cancellable = true)
- @Override
- public void performHandwritingJoinOrSplitGesture(
- InputConnectionCommandHeader header, JoinOrSplitGesture gesture,
- ResultReceiver resultReceiver) {
- performHandwritingGestureInternal(header, gesture, resultReceiver);
- }
-
- private <T extends HandwritingGesture> void performHandwritingGestureInternal(
- InputConnectionCommandHeader header, T gesture, ResultReceiver resultReceiver) {
dispatchWithTracing("performHandwritingGesture", () -> {
if (header.mSessionId != mCurrentSessionId.get()) {
if (resultReceiver != null) {
@@ -1059,7 +1006,7 @@
// TODO(210039666): implement Cleaner to return HANDWRITING_GESTURE_RESULT_UNKNOWN if
// editor doesn't return any type.
ic.performHandwritingGesture(
- gesture,
+ gestureContainer.get(),
resultReceiver != null ? Runnable::run : null,
resultReceiver != null
? (resultCode) -> resultReceiver.send(resultCode, null /* resultData */)
diff --git a/core/java/com/android/internal/inputmethod/IRemoteInputConnection.aidl b/core/java/com/android/internal/inputmethod/IRemoteInputConnection.aidl
index ea5c9a3..f38cac7 100644
--- a/core/java/com/android/internal/inputmethod/IRemoteInputConnection.aidl
+++ b/core/java/com/android/internal/inputmethod/IRemoteInputConnection.aidl
@@ -21,15 +21,9 @@
import android.view.KeyEvent;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
-import android.view.inputmethod.DeleteGesture;
-import android.view.inputmethod.DeleteRangeGesture;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputContentInfo;
-import android.view.inputmethod.InsertGesture;
-import android.view.inputmethod.JoinOrSplitGesture;
-import android.view.inputmethod.RemoveSpaceGesture;
-import android.view.inputmethod.SelectGesture;
-import android.view.inputmethod.SelectRangeGesture;
+import android.view.inputmethod.ParcelableHandwritingGesture;
import android.view.inputmethod.TextAttribute;
import com.android.internal.infra.AndroidFuture;
@@ -94,26 +88,8 @@
void performPrivateCommand(in InputConnectionCommandHeader header, String action,
in Bundle data);
- void performHandwritingSelectGesture(in InputConnectionCommandHeader header,
- in SelectGesture gesture, in ResultReceiver resultReceiver);
-
- void performHandwritingSelectRangeGesture(in InputConnectionCommandHeader header,
- in SelectRangeGesture gesture, in ResultReceiver resultReceiver);
-
- void performHandwritingInsertGesture(in InputConnectionCommandHeader header,
- in InsertGesture gesture, in ResultReceiver resultReceiver);
-
- void performHandwritingDeleteGesture(in InputConnectionCommandHeader header,
- in DeleteGesture gesture, in ResultReceiver resultReceiver);
-
- void performHandwritingDeleteRangeGesture(in InputConnectionCommandHeader header,
- in DeleteRangeGesture gesture, in ResultReceiver resultReceiver);
-
- void performHandwritingRemoveSpaceGesture(in InputConnectionCommandHeader header,
- in RemoveSpaceGesture gesture, in ResultReceiver resultReceiver);
-
- void performHandwritingJoinOrSplitGesture(in InputConnectionCommandHeader header,
- in JoinOrSplitGesture gesture, in ResultReceiver resultReceiver);
+ void performHandwritingGesture(in InputConnectionCommandHeader header,
+ in ParcelableHandwritingGesture gesture, in ResultReceiver resultReceiver);
void setComposingRegion(in InputConnectionCommandHeader header, int start, int end);
diff --git a/core/proto/android/server/activitymanagerservice.proto b/core/proto/android/server/activitymanagerservice.proto
index 9e4f63c..4650000 100644
--- a/core/proto/android/server/activitymanagerservice.proto
+++ b/core/proto/android/server/activitymanagerservice.proto
@@ -978,6 +978,11 @@
}
repeated UserProfile user_profile_group_ids = 4;
repeated int32 visible_users_array = 5;
+
+ // current_user contains the id of the current user, while current_profiles contains the ids of
+ // both the current user and its profiles (if any)
+ optional int32 current_user = 6;
+ repeated int32 current_profiles = 7;
}
// sync with com.android.server.am.AppTimeTracker.java
diff --git a/core/tests/coretests/src/android/view/inputmethod/ParcelableHandwritingGestureTest.java b/core/tests/coretests/src/android/view/inputmethod/ParcelableHandwritingGestureTest.java
new file mode 100644
index 0000000..79aeaa3
--- /dev/null
+++ b/core/tests/coretests/src/android/view/inputmethod/ParcelableHandwritingGestureTest.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.inputmethod;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+import android.annotation.NonNull;
+import android.graphics.PointF;
+import android.graphics.RectF;
+import android.os.Parcel;
+import android.platform.test.annotations.Presubmit;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@Presubmit
+@RunWith(AndroidJUnit4.class)
+public class ParcelableHandwritingGestureTest {
+
+ @Test
+ public void testCreationFailWithNullPointerException() {
+ assertThrows(NullPointerException.class, () -> ParcelableHandwritingGesture.of(null));
+ }
+
+ @Test
+ public void testInvalidTypeHeader() {
+ Parcel parcel = null;
+ try {
+ parcel = Parcel.obtain();
+ // GESTURE_TYPE_NONE is not a supported header.
+ parcel.writeInt(HandwritingGesture.GESTURE_TYPE_NONE);
+ final Parcel initializedParcel = parcel;
+ assertThrows(UnsupportedOperationException.class,
+ () -> ParcelableHandwritingGesture.CREATOR.createFromParcel(initializedParcel));
+ } finally {
+ if (parcel != null) {
+ parcel.recycle();
+ }
+ }
+ }
+
+ @Test
+ public void testSelectGesture() {
+ verifyEqualityAfterUnparcel(new SelectGesture.Builder()
+ .setGranularity(HandwritingGesture.GRANULARITY_WORD)
+ .setSelectionArea(new RectF(1, 2, 3, 4))
+ .setFallbackText("")
+ .build());
+ }
+
+ @Test
+ public void testSelectRangeGesture() {
+ verifyEqualityAfterUnparcel(new SelectRangeGesture.Builder()
+ .setGranularity(HandwritingGesture.GRANULARITY_WORD)
+ .setSelectionStartArea(new RectF(1, 2, 3, 4))
+ .setSelectionEndArea(new RectF(5, 6, 7, 8))
+ .setFallbackText("")
+ .build());
+ }
+
+ @Test
+ public void testInsertGestureGesture() {
+ verifyEqualityAfterUnparcel(new InsertGesture.Builder()
+ .setTextToInsert("text")
+ .setInsertionPoint(new PointF(1, 1)).setFallbackText("")
+ .build());
+ }
+
+ @Test
+ public void testDeleteGestureGesture() {
+ verifyEqualityAfterUnparcel(new DeleteGesture.Builder()
+ .setGranularity(HandwritingGesture.GRANULARITY_WORD)
+ .setDeletionArea(new RectF(1, 2, 3, 4))
+ .setFallbackText("")
+ .build());
+ }
+
+ @Test
+ public void testDeleteRangeGestureGesture() {
+ verifyEqualityAfterUnparcel(new DeleteRangeGesture.Builder()
+ .setGranularity(HandwritingGesture.GRANULARITY_WORD)
+ .setDeletionStartArea(new RectF(1, 2, 3, 4))
+ .setDeletionEndArea(new RectF(5, 6, 7, 8))
+ .setFallbackText("")
+ .build());
+ }
+
+ @Test
+ public void testRemoveSpaceGestureGesture() {
+ verifyEqualityAfterUnparcel(new RemoveSpaceGesture.Builder()
+ .setPoints(new PointF(1f, 2f), new PointF(3f, 4f))
+ .setFallbackText("")
+ .build());
+ }
+
+ @Test
+ public void testJoinOrSplitGestureGesture() {
+ verifyEqualityAfterUnparcel(new JoinOrSplitGesture.Builder()
+ .setJoinOrSplitPoint(new PointF(1f, 2f))
+ .setFallbackText("")
+ .build());
+ }
+
+ static void verifyEqualityAfterUnparcel(@NonNull HandwritingGesture gesture) {
+ assertEquals(gesture, cloneViaParcel(ParcelableHandwritingGesture.of(gesture)).get());
+ }
+
+ private static ParcelableHandwritingGesture cloneViaParcel(
+ @NonNull ParcelableHandwritingGesture original) {
+ Parcel parcel = null;
+ try {
+ parcel = Parcel.obtain();
+ original.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ return ParcelableHandwritingGesture.CREATOR.createFromParcel(parcel);
+ } finally {
+ if (parcel != null) {
+ parcel.recycle();
+ }
+ }
+ }
+}
diff --git a/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java b/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java
index d4a6632..95aa5d0 100644
--- a/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java
+++ b/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java
@@ -32,6 +32,7 @@
import android.content.Context;
import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
+import android.view.HandwritingDelegateConfiguration;
import android.view.HandwritingInitiator;
import android.view.InputDevice;
import android.view.MotionEvent;
@@ -208,6 +209,30 @@
}
@Test
+ public void onTouchEvent_startHandwriting_delegate() {
+ int delegatorViewId = 234;
+ View delegatorView = new View(mContext);
+ delegatorView.setId(delegatorViewId);
+
+ mTestView.setHandwritingDelegateConfiguration(
+ new HandwritingDelegateConfiguration(
+ delegatorViewId,
+ () -> mHandwritingInitiator.onInputConnectionCreated(delegatorView)));
+
+ final int x1 = (sHwArea.left + sHwArea.right) / 2;
+ final int y1 = (sHwArea.top + sHwArea.bottom) / 2;
+ MotionEvent stylusEvent1 = createStylusEvent(ACTION_DOWN, x1, y1, 0);
+ mHandwritingInitiator.onTouchEvent(stylusEvent1);
+
+ final int x2 = x1 + mHandwritingSlop * 2;
+ final int y2 = y1;
+ MotionEvent stylusEvent2 = createStylusEvent(ACTION_MOVE, x2, y2, 0);
+ mHandwritingInitiator.onTouchEvent(stylusEvent2);
+
+ verify(mHandwritingInitiator, times(1)).startHandwriting(delegatorView);
+ }
+
+ @Test
public void onTouchEvent_notStartHandwriting_whenHandwritingNotAvailable() {
final Rect rect = new Rect(600, 600, 900, 900);
final View testView = createView(rect, true /* autoHandwritingEnabled */,
diff --git a/core/tests/coretests/src/com/android/internal/security/OWNERS b/core/tests/coretests/src/com/android/internal/security/OWNERS
new file mode 100644
index 0000000..4f4d8d7
--- /dev/null
+++ b/core/tests/coretests/src/com/android/internal/security/OWNERS
@@ -0,0 +1,3 @@
+# Bug component: 36824
+
+per-file VerityUtilsTest.java = file:platform/system/security:/fsverity/OWNERS
diff --git a/graphics/java/android/view/PixelCopy.java b/graphics/java/android/view/PixelCopy.java
index 0f82c8f..889edb3 100644
--- a/graphics/java/android/view/PixelCopy.java
+++ b/graphics/java/android/view/PixelCopy.java
@@ -311,11 +311,11 @@
/**
* Contains the result of a PixelCopy request
*/
- public static final class CopyResult {
+ public static final class Result {
private int mStatus;
private Bitmap mBitmap;
- private CopyResult(@CopyResultStatus int status, Bitmap bitmap) {
+ private Result(@CopyResultStatus int status, Bitmap bitmap) {
mStatus = status;
mBitmap = bitmap;
}
@@ -335,8 +335,8 @@
/**
* If the PixelCopy {@link Request} was given a destination bitmap with
- * {@link Request#setDestinationBitmap(Bitmap)} then the returned bitmap will be the same
- * as the one given. If no destination bitmap was provided, then this
+ * {@link Request.Builder#setDestinationBitmap(Bitmap)} then the returned bitmap will be
+ * the same as the one given. If no destination bitmap was provided, then this
* will contain the automatically allocated Bitmap to hold the result.
*
* @return the Bitmap the copy request was stored in.
@@ -349,66 +349,199 @@
}
/**
- * A builder to create the complete PixelCopy request, which is then executed by calling
- * {@link #request()}
+ * Represents a PixelCopy request.
+ *
+ * To create a copy request, use either of the PixelCopy.Request.ofWindow or
+ * PixelCopy.Request.ofSurface factories to create a {@link Request.Builder} for the
+ * given source content. After setting any optional parameters, such as
+ * {@link Builder#setSourceRect(Rect)}, build the request with {@link Builder#build()} and
+ * then execute it with {@link PixelCopy#request(Request)}
*/
public static final class Request {
+ private final Surface mSource;
+ private final Consumer<Result> mListener;
+ private final Executor mListenerThread;
+ private final Rect mSourceInsets;
+ private Rect mSrcRect;
+ private Bitmap mDest;
+
private Request(Surface source, Rect sourceInsets, Executor listenerThread,
- Consumer<CopyResult> listener) {
+ Consumer<Result> listener) {
this.mSource = source;
this.mSourceInsets = sourceInsets;
this.mListenerThread = listenerThread;
this.mListener = listener;
}
- private final Surface mSource;
- private final Consumer<CopyResult> mListener;
- private final Executor mListenerThread;
- private final Rect mSourceInsets;
- private Rect mSrcRect;
- private Bitmap mDest;
-
/**
- * Sets the region of the source to copy from. By default, the entire source is copied to
- * the output. If only a subset of the source is necessary to be copied, specifying a
- * srcRect will improve performance by reducing
- * the amount of data being copied.
- *
- * @param srcRect The area of the source to read from. Null or empty will be treated to
- * mean the entire source
- * @return this
+ * A builder to create the complete PixelCopy request, which is then executed by calling
+ * {@link #request(Request)} with the built request returned from {@link #build()}
*/
- public @NonNull Request setSourceRect(@Nullable Rect srcRect) {
- this.mSrcRect = srcRect;
- return this;
- }
+ public static final class Builder {
+ private Request mRequest;
- /**
- * Specifies the output bitmap in which to store the result. By default, a Bitmap of format
- * {@link android.graphics.Bitmap.Config#ARGB_8888} with a width & height matching that
- * of the {@link #setSourceRect(Rect) source area} will be created to place the result.
- *
- * @param destination The bitmap to store the result, or null to have a bitmap
- * automatically created of the appropriate size. If not null, must not
- * be {@link Bitmap#isRecycled() recycled} and must be
- * {@link Bitmap#isMutable() mutable}.
- * @return this
- */
- public @NonNull Request setDestinationBitmap(@Nullable Bitmap destination) {
- if (destination != null) {
- validateBitmapDest(destination);
+ private Builder(Request request) {
+ mRequest = request;
}
- this.mDest = destination;
- return this;
+
+ private void requireNotBuilt() {
+ if (mRequest == null) {
+ throw new IllegalStateException("build() already called on this builder");
+ }
+ }
+
+ /**
+ * Sets the region of the source to copy from. By default, the entire source is copied
+ * to the output. If only a subset of the source is necessary to be copied, specifying
+ * a srcRect will improve performance by reducing
+ * the amount of data being copied.
+ *
+ * @param srcRect The area of the source to read from. Null or empty will be treated to
+ * mean the entire source
+ * @return this
+ */
+ public @NonNull Builder setSourceRect(@Nullable Rect srcRect) {
+ requireNotBuilt();
+ mRequest.mSrcRect = srcRect;
+ return this;
+ }
+
+ /**
+ * Specifies the output bitmap in which to store the result. By default, a Bitmap of
+ * format {@link android.graphics.Bitmap.Config#ARGB_8888} with a width & height
+ * matching that of the {@link #setSourceRect(Rect) source area} will be created to
+ * place the result.
+ *
+ * @param destination The bitmap to store the result, or null to have a bitmap
+ * automatically created of the appropriate size. If not null, must
+ * not be {@link Bitmap#isRecycled() recycled} and must be
+ * {@link Bitmap#isMutable() mutable}.
+ * @return this
+ */
+ public @NonNull Builder setDestinationBitmap(@Nullable Bitmap destination) {
+ requireNotBuilt();
+ if (destination != null) {
+ validateBitmapDest(destination);
+ }
+ mRequest.mDest = destination;
+ return this;
+ }
+
+ /**
+ * @return The built {@link PixelCopy.Request}
+ */
+ public @NonNull Request build() {
+ requireNotBuilt();
+ Request ret = mRequest;
+ mRequest = null;
+ return ret;
+ }
}
/**
- * Executes the request.
+ * Creates a PixelCopy request for the given {@link Window}
+ * @param source The Window to copy from
+ * @param callbackExecutor The executor to run the callback on
+ * @param listener The callback for when the copy request is completed
+ * @return A {@link Builder} builder to set the optional params & execute the request
+ */
+ public static @NonNull Builder ofWindow(@NonNull Window source,
+ @NonNull Executor callbackExecutor,
+ @NonNull Consumer<Result> listener) {
+ final Rect insets = new Rect();
+ final Surface surface = sourceForWindow(source, insets);
+ return new Builder(new Request(surface, insets, callbackExecutor, listener));
+ }
+
+ /**
+ * Creates a PixelCopy request for the {@link Window} that the given {@link View} is
+ * attached to.
+ *
+ * Note that this copy request is not cropped to the area the View occupies by default. If
+ * that behavior is desired, use {@link View#getLocationInWindow(int[])} combined with
+ * {@link Builder#setSourceRect(Rect)} to set a crop area to restrict the copy operation.
+ *
+ * @param source A View that {@link View#isAttachedToWindow() is attached} to a window that
+ * will be used to retrieve the window to copy from.
+ * @param callbackExecutor The executor to run the callback on
+ * @param listener The callback for when the copy request is completed
+ * @return A {@link Builder} builder to set the optional params & execute the request
+ */
+ public static @NonNull Builder ofWindow(@NonNull View source,
+ @NonNull Executor callbackExecutor,
+ @NonNull Consumer<Result> listener) {
+ if (source == null || !source.isAttachedToWindow()) {
+ throw new IllegalArgumentException(
+ "View must not be null & must be attached to window");
+ }
+ final Rect insets = new Rect();
+ Surface surface = null;
+ final ViewRootImpl root = source.getViewRootImpl();
+ if (root != null) {
+ surface = root.mSurface;
+ insets.set(root.mWindowAttributes.surfaceInsets);
+ }
+ if (surface == null || !surface.isValid()) {
+ throw new IllegalArgumentException(
+ "Window doesn't have a backing surface!");
+ }
+ return new Builder(new Request(surface, insets, callbackExecutor, listener));
+ }
+
+ /**
+ * Creates a PixelCopy request for the given {@link Surface}
+ *
+ * @param source The Surface to copy from. Must be {@link Surface#isValid() valid}.
+ * @param callbackExecutor The executor to run the callback on
+ * @param listener The callback for when the copy request is completed
+ * @return A {@link Builder} builder to set the optional params & execute the request
+ */
+ public static @NonNull Builder ofSurface(@NonNull Surface source,
+ @NonNull Executor callbackExecutor,
+ @NonNull Consumer<Result> listener) {
+ if (source == null || !source.isValid()) {
+ throw new IllegalArgumentException("Source must not be null & must be valid");
+ }
+ return new Builder(new Request(source, null, callbackExecutor, listener));
+ }
+
+ /**
+ * Creates a PixelCopy request for the {@link Surface} belonging to the
+ * given {@link SurfaceView}
+ *
+ * @param source The SurfaceView to copy from. The backing surface must be
+ * {@link Surface#isValid() valid}
+ * @param callbackExecutor The executor to run the callback on
+ * @param listener The callback for when the copy request is completed
+ * @return A {@link Builder} builder to set the optional params & execute the request
+ */
+ public static @NonNull Builder ofSurface(@NonNull SurfaceView source,
+ @NonNull Executor callbackExecutor,
+ @NonNull Consumer<Result> listener) {
+ return ofSurface(source.getHolder().getSurface(), callbackExecutor, listener);
+ }
+
+ /**
+ * @return The destination bitmap as set by {@link Builder#setDestinationBitmap(Bitmap)}
+ */
+ public @Nullable Bitmap getDestinationBitmap() {
+ return mDest;
+ }
+
+ /**
+ * @return The source rect to copy from as set by {@link Builder#setSourceRect(Rect)}
+ */
+ public @Nullable Rect getSourceRect() {
+ return mSrcRect;
+ }
+
+ /**
+ * @hide
*/
public void request() {
if (!mSource.isValid()) {
mListenerThread.execute(() -> mListener.accept(
- new CopyResult(ERROR_SOURCE_INVALID, null)));
+ new Result(ERROR_SOURCE_INVALID, null)));
return;
}
HardwareRenderer.copySurfaceInto(mSource, new HardwareRenderer.CopyRequest(
@@ -416,93 +549,18 @@
@Override
public void onCopyFinished(int result) {
mListenerThread.execute(() -> mListener.accept(
- new CopyResult(result, mDestinationBitmap)));
+ new Result(result, mDestinationBitmap)));
}
});
}
}
/**
- * Creates a PixelCopy request for the given {@link Window}
- * @param source The Window to copy from
- * @param callbackExecutor The executor to run the callback on
- * @param listener The callback for when the copy request is completed
- * @return A {@link Request} builder to set the optional params & execute the request
+ * Executes the pixel copy request
+ * @param request The request to execute
*/
- public static @NonNull Request ofWindow(@NonNull Window source,
- @NonNull Executor callbackExecutor,
- @NonNull Consumer<CopyResult> listener) {
- final Rect insets = new Rect();
- final Surface surface = sourceForWindow(source, insets);
- return new Request(surface, insets, callbackExecutor, listener);
- }
-
- /**
- * Creates a PixelCopy request for the {@link Window} that the given {@link View} is
- * attached to.
- *
- * Note that this copy request is not cropped to the area the View occupies by default. If that
- * behavior is desired, use {@link View#getLocationInWindow(int[])} combined with
- * {@link Request#setSourceRect(Rect)} to set a crop area to restrict the copy operation.
- *
- * @param source A View that {@link View#isAttachedToWindow() is attached} to a window that
- * will be used to retrieve the window to copy from.
- * @param callbackExecutor The executor to run the callback on
- * @param listener The callback for when the copy request is completed
- * @return A {@link Request} builder to set the optional params & execute the request
- */
- public static @NonNull Request ofWindow(@NonNull View source,
- @NonNull Executor callbackExecutor,
- @NonNull Consumer<CopyResult> listener) {
- if (source == null || !source.isAttachedToWindow()) {
- throw new IllegalArgumentException(
- "View must not be null & must be attached to window");
- }
- final Rect insets = new Rect();
- Surface surface = null;
- final ViewRootImpl root = source.getViewRootImpl();
- if (root != null) {
- surface = root.mSurface;
- insets.set(root.mWindowAttributes.surfaceInsets);
- }
- if (surface == null || !surface.isValid()) {
- throw new IllegalArgumentException(
- "Window doesn't have a backing surface!");
- }
- return new Request(surface, insets, callbackExecutor, listener);
- }
-
- /**
- * Creates a PixelCopy request for the given {@link Surface}
- *
- * @param source The Surface to copy from. Must be {@link Surface#isValid() valid}.
- * @param callbackExecutor The executor to run the callback on
- * @param listener The callback for when the copy request is completed
- * @return A {@link Request} builder to set the optional params & execute the request
- */
- public static @NonNull Request ofSurface(@NonNull Surface source,
- @NonNull Executor callbackExecutor,
- @NonNull Consumer<CopyResult> listener) {
- if (source == null || !source.isValid()) {
- throw new IllegalArgumentException("Source must not be null & must be valid");
- }
- return new Request(source, null, callbackExecutor, listener);
- }
-
- /**
- * Creates a PixelCopy request for the {@link Surface} belonging to the
- * given {@link SurfaceView}
- *
- * @param source The SurfaceView to copy from. The backing surface must be
- * {@link Surface#isValid() valid}
- * @param callbackExecutor The executor to run the callback on
- * @param listener The callback for when the copy request is completed
- * @return A {@link Request} builder to set the optional params & execute the request
- */
- public static @NonNull Request ofSurface(@NonNull SurfaceView source,
- @NonNull Executor callbackExecutor,
- @NonNull Consumer<CopyResult> listener) {
- return ofSurface(source.getHolder().getSurface(), callbackExecutor, listener);
+ public static void request(@NonNull Request request) {
+ request.request();
}
private PixelCopy() {}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
index 2b36b4c..85bad17 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java
@@ -335,6 +335,7 @@
final ActivityManager.RunningTaskInfo taskInfo = mPipOrganizer.getTaskInfo();
if (taskInfo != null) {
startExpandAnimation(taskInfo, mPipOrganizer.getSurfaceControl(),
+ mPipBoundsState.getBounds(), mPipBoundsState.getBounds(),
new Rect(mExitDestinationBounds), Surface.ROTATION_0);
}
mExitDestinationBounds.setEmpty();
@@ -475,6 +476,20 @@
taskInfo);
return;
}
+
+ // When exiting PiP, the PiP leash may be an Activity of a multi-windowing Task, for which
+ // case it may not be in the screen coordinate.
+ // Reparent the pip leash to the root with max layer so that we can animate it outside of
+ // parent crop, and make sure it is not covered by other windows.
+ final SurfaceControl pipLeash = pipChange.getLeash();
+ startTransaction.reparent(pipLeash, info.getRootLeash());
+ startTransaction.setLayer(pipLeash, Integer.MAX_VALUE);
+ // Note: because of this, the bounds to animate should be translated to the root coordinate.
+ final Point offset = info.getRootOffset();
+ final Rect currentBounds = mPipBoundsState.getBounds();
+ currentBounds.offset(-offset.x, -offset.y);
+ startTransaction.setPosition(pipLeash, currentBounds.left, currentBounds.top);
+
mFinishCallback = (wct, wctCB) -> {
mPipOrganizer.onExitPipFinished(taskInfo);
finishCallback.onTransitionFinished(wct, wctCB);
@@ -496,18 +511,17 @@
if (displayRotationChange != null) {
// Exiting PIP to fullscreen with orientation change.
startExpandAndRotationAnimation(info, startTransaction, finishTransaction,
- displayRotationChange, taskInfo, pipChange);
+ displayRotationChange, taskInfo, pipChange, offset);
return;
}
}
// Set the initial frame as scaling the end to the start.
final Rect destinationBounds = new Rect(pipChange.getEndAbsBounds());
- final Point offset = pipChange.getEndRelOffset();
destinationBounds.offset(-offset.x, -offset.y);
- startTransaction.setWindowCrop(pipChange.getLeash(), destinationBounds);
- mSurfaceTransactionHelper.scale(startTransaction, pipChange.getLeash(),
- destinationBounds, mPipBoundsState.getBounds());
+ startTransaction.setWindowCrop(pipLeash, destinationBounds);
+ mSurfaceTransactionHelper.scale(startTransaction, pipLeash, destinationBounds,
+ currentBounds);
startTransaction.apply();
// Check if it is fixed rotation.
@@ -532,19 +546,21 @@
y = destinationBounds.bottom;
}
mSurfaceTransactionHelper.rotateAndScaleWithCrop(finishTransaction,
- pipChange.getLeash(), endBounds, endBounds, new Rect(), degree, x, y,
+ pipLeash, endBounds, endBounds, new Rect(), degree, x, y,
true /* isExpanding */, rotationDelta == ROTATION_270 /* clockwise */);
} else {
rotationDelta = Surface.ROTATION_0;
}
- startExpandAnimation(taskInfo, pipChange.getLeash(), destinationBounds, rotationDelta);
+ startExpandAnimation(taskInfo, pipLeash, currentBounds, currentBounds, destinationBounds,
+ rotationDelta);
}
private void startExpandAndRotationAnimation(@NonNull TransitionInfo info,
@NonNull SurfaceControl.Transaction startTransaction,
@NonNull SurfaceControl.Transaction finishTransaction,
@NonNull TransitionInfo.Change displayRotationChange,
- @NonNull TaskInfo taskInfo, @NonNull TransitionInfo.Change pipChange) {
+ @NonNull TaskInfo taskInfo, @NonNull TransitionInfo.Change pipChange,
+ @NonNull Point offset) {
final int rotateDelta = deltaRotation(displayRotationChange.getStartRotation(),
displayRotationChange.getEndRotation());
@@ -556,7 +572,6 @@
final Rect startBounds = new Rect(pipChange.getStartAbsBounds());
rotateBounds(startBounds, displayRotationChange.getStartAbsBounds(), rotateDelta);
final Rect endBounds = new Rect(pipChange.getEndAbsBounds());
- final Point offset = pipChange.getEndRelOffset();
startBounds.offset(-offset.x, -offset.y);
endBounds.offset(-offset.x, -offset.y);
@@ -592,11 +607,12 @@
}
private void startExpandAnimation(final TaskInfo taskInfo, final SurfaceControl leash,
- final Rect destinationBounds, final int rotationDelta) {
+ final Rect baseBounds, final Rect startBounds, final Rect endBounds,
+ final int rotationDelta) {
final PipAnimationController.PipTransitionAnimator animator =
- mPipAnimationController.getAnimator(taskInfo, leash, mPipBoundsState.getBounds(),
- mPipBoundsState.getBounds(), destinationBounds, null,
- TRANSITION_DIRECTION_LEAVE_PIP, 0 /* startingAngle */, rotationDelta);
+ mPipAnimationController.getAnimator(taskInfo, leash, baseBounds, startBounds,
+ endBounds, null /* sourceHintRect */, TRANSITION_DIRECTION_LEAVE_PIP,
+ 0 /* startingAngle */, rotationDelta);
animator.setTransitionDirection(TRANSITION_DIRECTION_LEAVE_PIP)
.setPipAnimationCallback(mPipAnimationCallback)
.setDuration(mEnterExitAnimationDuration)
diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/splitscreen/SwitchAppByDoubleTapDivider.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/splitscreen/SwitchAppByDoubleTapDivider.kt
index 73159c9..ad7a531 100644
--- a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/splitscreen/SwitchAppByDoubleTapDivider.kt
+++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/splitscreen/SwitchAppByDoubleTapDivider.kt
@@ -145,15 +145,19 @@
// robust enough to get the correct end state.
}
+ @Presubmit
@Test
fun splitScreenDividerKeepVisible() = testSpec.layerKeepVisible(SPLIT_SCREEN_DIVIDER_COMPONENT)
+ @Presubmit
@Test
fun primaryAppLayerIsVisibleAtEnd() = testSpec.layerIsVisibleAtEnd(primaryApp)
+ @Presubmit
@Test
fun secondaryAppLayerIsVisibleAtEnd() = testSpec.layerIsVisibleAtEnd(secondaryApp)
+ @Presubmit
@Test
fun primaryAppBoundsIsVisibleAtEnd() = testSpec.splitAppLayerBoundsIsVisibleAtEnd(
primaryApp,
@@ -161,6 +165,7 @@
portraitPosTop = true
)
+ @Presubmit
@Test
fun secondaryAppBoundsIsVisibleAtEnd() = testSpec.splitAppLayerBoundsIsVisibleAtEnd(
secondaryApp,
@@ -168,9 +173,11 @@
portraitPosTop = false
)
+ @Presubmit
@Test
fun primaryAppWindowIsVisibleAtEnd() = testSpec.appWindowIsVisibleAtEnd(primaryApp)
+ @Presubmit
@Test
fun secondaryAppWindowIsVisibleAtEnd() = testSpec.appWindowIsVisibleAtEnd(secondaryApp)
diff --git a/media/java/android/media/MediaRouter2.java b/media/java/android/media/MediaRouter2.java
index 26cb9f8..b4b908d 100644
--- a/media/java/android/media/MediaRouter2.java
+++ b/media/java/android/media/MediaRouter2.java
@@ -104,8 +104,8 @@
private final String mPackageName;
/**
- * Stores the latest copy of all routes received from {@link MediaRouter2ServiceImpl}, without
- * any filtering, sorting, or deduplication.
+ * Stores the latest copy of all routes received from the system server, without any filtering,
+ * sorting, or deduplication.
*
* <p>Uses {@link MediaRoute2Info#getId()} to set each entry's key.
*/
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt b/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt
index 56fb1a9..0988cba 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/CredentialManagerRepo.kt
@@ -36,7 +36,7 @@
import com.android.credentialmanager.createflow.RequestDisplayInfo
import com.android.credentialmanager.getflow.GetCredentialUiState
import com.android.credentialmanager.getflow.GetScreenState
-import com.android.credentialmanager.jetpack.CredentialEntryUi.Companion.TYPE_PUBLIC_KEY_CREDENTIAL
+import com.android.credentialmanager.jetpack.provider.CredentialEntryUi.Companion.TYPE_PUBLIC_KEY_CREDENTIAL
// Consider repo per screen, similar to view model?
class CredentialManagerRepo(
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreatePasskeyComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreatePasskeyComponents.kt
index 8e30208..aeea46a 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreatePasskeyComponents.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreatePasskeyComponents.kt
@@ -39,8 +39,8 @@
import androidx.compose.ui.unit.dp
import androidx.core.graphics.drawable.toBitmap
import com.android.credentialmanager.R
-import com.android.credentialmanager.jetpack.CredentialEntryUi.Companion.TYPE_PASSWORD_CREDENTIAL
-import com.android.credentialmanager.jetpack.CredentialEntryUi.Companion.TYPE_PUBLIC_KEY_CREDENTIAL
+import com.android.credentialmanager.jetpack.provider.CredentialEntryUi.Companion.TYPE_PASSWORD_CREDENTIAL
+import com.android.credentialmanager.jetpack.provider.CredentialEntryUi.Companion.TYPE_PUBLIC_KEY_CREDENTIAL
import com.android.credentialmanager.ui.theme.Grey100
import com.android.credentialmanager.ui.theme.Shapes
import com.android.credentialmanager.ui.theme.Typography
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreateCredentialRequest.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreateCredentialRequest.kt
new file mode 100644
index 0000000..7e7dbde
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreateCredentialRequest.kt
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.credentials.Credential
+import android.os.Bundle
+
+/**
+ * Base request class for registering a credential.
+ *
+ * @property type the credential type
+ * @property data the request data in the [Bundle] format
+ * @property requireSystemProvider true if must only be fulfilled by a system provider and false
+ * otherwise
+ */
+open class CreateCredentialRequest(
+ val type: String,
+ val data: Bundle,
+ val requireSystemProvider: Boolean,
+) {
+ companion object {
+ @JvmStatic
+ fun createFrom(from: android.credentials.CreateCredentialRequest): CreateCredentialRequest {
+ return try {
+ when (from.type) {
+ Credential.TYPE_PASSWORD_CREDENTIAL ->
+ CreatePasswordRequest.createFrom(from.data)
+ PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL ->
+ CreatePublicKeyCredentialBaseRequest.createFrom(from.data)
+ else ->
+ CreateCredentialRequest(from.type, from.data, from.requireSystemProvider())
+ }
+ } catch (e: FrameworkClassParsingException) {
+ CreateCredentialRequest(from.type, from.data, from.requireSystemProvider())
+ }
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePasswordRequest.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePasswordRequest.kt
new file mode 100644
index 0000000..f0da9f9
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePasswordRequest.kt
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.credentials.Credential
+import android.os.Bundle
+
+/**
+ * A request to save the user password credential with their password provider.
+ *
+ * @property id the user id associated with the password
+ * @property password the password
+ * @throws NullPointerException If [id] is null
+ * @throws NullPointerException If [password] is null
+ * @throws IllegalArgumentException If [password] is empty
+ */
+class CreatePasswordRequest constructor(
+ val id: String,
+ val password: String,
+) : CreateCredentialRequest(
+ Credential.TYPE_PASSWORD_CREDENTIAL,
+ toBundle(id, password),
+ false,
+) {
+
+ init {
+ require(password.isNotEmpty()) { "password should not be empty" }
+ }
+
+ companion object {
+ const val BUNDLE_KEY_ID = "androidx.credentials.BUNDLE_KEY_ID"
+ const val BUNDLE_KEY_PASSWORD = "androidx.credentials.BUNDLE_KEY_PASSWORD"
+
+ @JvmStatic
+ internal fun toBundle(id: String, password: String): Bundle {
+ val bundle = Bundle()
+ bundle.putString(BUNDLE_KEY_ID, id)
+ bundle.putString(BUNDLE_KEY_PASSWORD, password)
+ return bundle
+ }
+
+ @JvmStatic
+ fun createFrom(data: Bundle): CreatePasswordRequest {
+ try {
+ val id = data.getString(BUNDLE_KEY_ID)
+ val password = data.getString(BUNDLE_KEY_PASSWORD)
+ return CreatePasswordRequest(id!!, password!!)
+ } catch (e: Exception) {
+ throw FrameworkClassParsingException()
+ }
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePublicKeyCredentialBaseRequest.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePublicKeyCredentialBaseRequest.kt
new file mode 100644
index 0000000..26d61f9
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePublicKeyCredentialBaseRequest.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.os.Bundle
+
+/**
+ * Base request class for registering a public key credential.
+ *
+ * @property requestJson The request in JSON format
+ * @throws NullPointerException If [requestJson] is null. This is handled by the Kotlin runtime
+ * @throws IllegalArgumentException If [requestJson] is empty
+ *
+ * @hide
+ */
+abstract class CreatePublicKeyCredentialBaseRequest constructor(
+ val requestJson: String,
+ type: String,
+ data: Bundle,
+ requireSystemProvider: Boolean,
+) : CreateCredentialRequest(type, data, requireSystemProvider) {
+
+ init {
+ require(requestJson.isNotEmpty()) { "request json must not be empty" }
+ }
+
+ companion object {
+ const val BUNDLE_KEY_REQUEST_JSON = "androidx.credentials.BUNDLE_KEY_REQUEST_JSON"
+ const val BUNDLE_KEY_SUBTYPE = "androidx.credentials.BUNDLE_KEY_SUBTYPE"
+
+ @JvmStatic
+ fun createFrom(data: Bundle): CreatePublicKeyCredentialBaseRequest {
+ return when (data.getString(BUNDLE_KEY_SUBTYPE)) {
+ CreatePublicKeyCredentialRequest
+ .BUNDLE_VALUE_SUBTYPE_CREATE_PUBLIC_KEY_CREDENTIAL_REQUEST ->
+ CreatePublicKeyCredentialRequestPrivileged.createFrom(data)
+ CreatePublicKeyCredentialRequestPrivileged
+ .BUNDLE_VALUE_SUBTYPE_CREATE_PUBLIC_KEY_CREDENTIAL_REQUEST_PRIVILEGED ->
+ CreatePublicKeyCredentialRequestPrivileged.createFrom(data)
+ else -> throw FrameworkClassParsingException()
+ }
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePublicKeyCredentialRequest.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePublicKeyCredentialRequest.kt
new file mode 100644
index 0000000..2eda90b
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePublicKeyCredentialRequest.kt
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.os.Bundle
+
+/**
+ * A request to register a passkey from the user's public key credential provider.
+ *
+ * @property requestJson the request in JSON format
+ * @property allowHybrid defines whether hybrid credentials are allowed to fulfill this request,
+ * true by default
+ * @throws NullPointerException If [requestJson] or [allowHybrid] is null. This is handled by the
+ * Kotlin runtime
+ * @throws IllegalArgumentException If [requestJson] is empty
+ *
+ * @hide
+ */
+class CreatePublicKeyCredentialRequest @JvmOverloads constructor(
+ requestJson: String,
+ @get:JvmName("allowHybrid")
+ val allowHybrid: Boolean = true
+) : CreatePublicKeyCredentialBaseRequest(
+ requestJson,
+ PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL,
+ toBundle(requestJson, allowHybrid),
+ false,
+) {
+ companion object {
+ const val BUNDLE_KEY_ALLOW_HYBRID = "androidx.credentials.BUNDLE_KEY_ALLOW_HYBRID"
+ const val BUNDLE_VALUE_SUBTYPE_CREATE_PUBLIC_KEY_CREDENTIAL_REQUEST =
+ "androidx.credentials.BUNDLE_VALUE_SUBTYPE_CREATE_PUBLIC_KEY_CREDENTIAL_REQUEST"
+
+ @JvmStatic
+ internal fun toBundle(requestJson: String, allowHybrid: Boolean): Bundle {
+ val bundle = Bundle()
+ bundle.putString(BUNDLE_KEY_SUBTYPE,
+ BUNDLE_VALUE_SUBTYPE_CREATE_PUBLIC_KEY_CREDENTIAL_REQUEST)
+ bundle.putString(BUNDLE_KEY_REQUEST_JSON, requestJson)
+ bundle.putBoolean(BUNDLE_KEY_ALLOW_HYBRID, allowHybrid)
+ return bundle
+ }
+
+ @JvmStatic
+ fun createFrom(data: Bundle): CreatePublicKeyCredentialRequest {
+ try {
+ val requestJson = data.getString(BUNDLE_KEY_REQUEST_JSON)
+ val allowHybrid = data.get(BUNDLE_KEY_ALLOW_HYBRID)
+ return CreatePublicKeyCredentialRequest(requestJson!!, (allowHybrid!!) as Boolean)
+ } catch (e: Exception) {
+ throw FrameworkClassParsingException()
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePublicKeyCredentialRequestPrivileged.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePublicKeyCredentialRequestPrivileged.kt
new file mode 100644
index 0000000..36324f8
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/CreatePublicKeyCredentialRequestPrivileged.kt
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.os.Bundle
+
+/**
+ * A privileged request to register a passkey from the user’s public key credential provider, where
+ * the caller can modify the rp. Only callers with privileged permission, e.g. user’s default
+ * brower, caBLE, can use this.
+ *
+ * @property requestJson the privileged request in JSON format
+ * @property allowHybrid defines whether hybrid credentials are allowed to fulfill this request,
+ * true by default
+ * @property rp the expected true RP ID which will override the one in the [requestJson]
+ * @property clientDataHash a hash that is used to verify the [rp] Identity
+ * @throws NullPointerException If any of [allowHybrid], [requestJson], [rp], or [clientDataHash] is
+ * null. This is handled by the Kotlin runtime
+ * @throws IllegalArgumentException If any of [requestJson], [rp], or [clientDataHash] is empty
+ *
+ * @hide
+ */
+class CreatePublicKeyCredentialRequestPrivileged @JvmOverloads constructor(
+ requestJson: String,
+ val rp: String,
+ val clientDataHash: String,
+ @get:JvmName("allowHybrid")
+ val allowHybrid: Boolean = true
+) : CreatePublicKeyCredentialBaseRequest(
+ requestJson,
+ PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL,
+ toBundle(requestJson, rp, clientDataHash, allowHybrid),
+ false,
+) {
+
+ init {
+ require(rp.isNotEmpty()) { "rp must not be empty" }
+ require(clientDataHash.isNotEmpty()) { "clientDataHash must not be empty" }
+ }
+
+ /** A builder for [CreatePublicKeyCredentialRequestPrivileged]. */
+ class Builder(var requestJson: String, var rp: String, var clientDataHash: String) {
+
+ private var allowHybrid: Boolean = true
+
+ /**
+ * Sets the privileged request in JSON format.
+ */
+ fun setRequestJson(requestJson: String): Builder {
+ this.requestJson = requestJson
+ return this
+ }
+
+ /**
+ * Sets whether hybrid credentials are allowed to fulfill this request, true by default.
+ */
+ fun setAllowHybrid(allowHybrid: Boolean): Builder {
+ this.allowHybrid = allowHybrid
+ return this
+ }
+
+ /**
+ * Sets the expected true RP ID which will override the one in the [requestJson].
+ */
+ fun setRp(rp: String): Builder {
+ this.rp = rp
+ return this
+ }
+
+ /**
+ * Sets a hash that is used to verify the [rp] Identity.
+ */
+ fun setClientDataHash(clientDataHash: String): Builder {
+ this.clientDataHash = clientDataHash
+ return this
+ }
+
+ /** Builds a [CreatePublicKeyCredentialRequestPrivileged]. */
+ fun build(): CreatePublicKeyCredentialRequestPrivileged {
+ return CreatePublicKeyCredentialRequestPrivileged(this.requestJson,
+ this.rp, this.clientDataHash, this.allowHybrid)
+ }
+ }
+
+ companion object {
+ const val BUNDLE_KEY_RP = "androidx.credentials.BUNDLE_KEY_RP"
+ const val BUNDLE_KEY_CLIENT_DATA_HASH =
+ "androidx.credentials.BUNDLE_KEY_CLIENT_DATA_HASH"
+ const val BUNDLE_KEY_ALLOW_HYBRID = "androidx.credentials.BUNDLE_KEY_ALLOW_HYBRID"
+ const val BUNDLE_VALUE_SUBTYPE_CREATE_PUBLIC_KEY_CREDENTIAL_REQUEST_PRIVILEGED =
+ "androidx.credentials.BUNDLE_VALUE_SUBTYPE_CREATE_PUBLIC_KEY_CREDENTIAL_REQUEST_" +
+ "PRIVILEGED"
+
+ @JvmStatic
+ internal fun toBundle(
+ requestJson: String,
+ rp: String,
+ clientDataHash: String,
+ allowHybrid: Boolean
+ ): Bundle {
+ val bundle = Bundle()
+ bundle.putString(BUNDLE_KEY_SUBTYPE,
+ BUNDLE_VALUE_SUBTYPE_CREATE_PUBLIC_KEY_CREDENTIAL_REQUEST_PRIVILEGED)
+ bundle.putString(BUNDLE_KEY_REQUEST_JSON, requestJson)
+ bundle.putString(BUNDLE_KEY_RP, rp)
+ bundle.putString(BUNDLE_KEY_CLIENT_DATA_HASH, clientDataHash)
+ bundle.putBoolean(BUNDLE_KEY_ALLOW_HYBRID, allowHybrid)
+ return bundle
+ }
+
+ @JvmStatic
+ fun createFrom(data: Bundle): CreatePublicKeyCredentialRequestPrivileged {
+ try {
+ val requestJson = data.getString(BUNDLE_KEY_REQUEST_JSON)
+ val rp = data.getString(BUNDLE_KEY_RP)
+ val clientDataHash = data.getString(BUNDLE_KEY_CLIENT_DATA_HASH)
+ val allowHybrid = data.get(BUNDLE_KEY_ALLOW_HYBRID)
+ return CreatePublicKeyCredentialRequestPrivileged(
+ requestJson!!,
+ rp!!,
+ clientDataHash!!,
+ (allowHybrid!!) as Boolean,
+ )
+ } catch (e: Exception) {
+ throw FrameworkClassParsingException()
+ }
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/Credential.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/Credential.kt
new file mode 100644
index 0000000..ee08e9e
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/Credential.kt
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.os.Bundle
+
+/**
+ * Base class for a credential with which the user consented to authenticate to the app.
+ *
+ * @property type the credential type
+ * @property data the credential data in the [Bundle] format.
+ */
+open class Credential(val type: String, val data: Bundle)
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/FrameworkClassParsingException.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/FrameworkClassParsingException.kt
new file mode 100644
index 0000000..497c272
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/FrameworkClassParsingException.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+/**
+ * Internal exception used to indicate a parsing error while converting from a framework type to
+ * a jetpack type.
+ *
+ * @hide
+ */
+internal class FrameworkClassParsingException : Exception()
\ No newline at end of file
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetCredentialOption.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetCredentialOption.kt
new file mode 100644
index 0000000..eb65241
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetCredentialOption.kt
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.credentials.Credential
+import android.os.Bundle
+
+/**
+ * Base request class for getting a registered credential.
+ *
+ * @property type the credential type
+ * @property data the request data in the [Bundle] format
+ * @property requireSystemProvider true if must only be fulfilled by a system provider and false
+ * otherwise
+ */
+open class GetCredentialOption(
+ val type: String,
+ val data: Bundle,
+ val requireSystemProvider: Boolean,
+) {
+ companion object {
+ @JvmStatic
+ fun createFrom(from: android.credentials.GetCredentialOption): GetCredentialOption {
+ return try {
+ when (from.type) {
+ Credential.TYPE_PASSWORD_CREDENTIAL ->
+ GetPasswordOption.createFrom(from.data)
+ PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL ->
+ GetPublicKeyCredentialBaseOption.createFrom(from.data)
+ else ->
+ GetCredentialOption(from.type, from.data, from.requireSystemProvider())
+ }
+ } catch (e: FrameworkClassParsingException) {
+ GetCredentialOption(from.type, from.data, from.requireSystemProvider())
+ }
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetCredentialRequest.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetCredentialRequest.kt
new file mode 100644
index 0000000..7f9256e
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetCredentialRequest.kt
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+/**
+ * Encapsulates a request to get a user credential.
+ *
+ * @property getCredentialOptions the list of [GetCredentialOption] from which the user can choose
+ * one to authenticate to the app
+ * @throws IllegalArgumentException If [getCredentialOptions] is empty
+ */
+class GetCredentialRequest constructor(
+ val getCredentialOptions: List<GetCredentialOption>,
+) {
+
+ init {
+ require(getCredentialOptions.isNotEmpty()) { "credentialRequests should not be empty" }
+ }
+
+ /** A builder for [GetCredentialRequest]. */
+ class Builder {
+ private var getCredentialOptions: MutableList<GetCredentialOption> = mutableListOf()
+
+ /** Adds a specific type of [GetCredentialOption]. */
+ fun addGetCredentialOption(getCredentialOption: GetCredentialOption): Builder {
+ getCredentialOptions.add(getCredentialOption)
+ return this
+ }
+
+ /** Sets the list of [GetCredentialOption]. */
+ fun setGetCredentialOptions(getCredentialOptions: List<GetCredentialOption>): Builder {
+ this.getCredentialOptions = getCredentialOptions.toMutableList()
+ return this
+ }
+
+ /**
+ * Builds a [GetCredentialRequest].
+ *
+ * @throws IllegalArgumentException If [getCredentialOptions] is empty
+ */
+ fun build(): GetCredentialRequest {
+ return GetCredentialRequest(getCredentialOptions.toList())
+ }
+ }
+
+ companion object {
+ @JvmStatic
+ fun createFrom(from: android.credentials.GetCredentialRequest): GetCredentialRequest {
+ return GetCredentialRequest(
+ from.getCredentialOptions.map {GetCredentialOption.createFrom(it)}
+ )
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPasswordOption.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPasswordOption.kt
new file mode 100644
index 0000000..2facad1
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPasswordOption.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.credentials.Credential
+import android.os.Bundle
+
+/** A request to retrieve the user's saved application password from their password provider. */
+class GetPasswordOption : GetCredentialOption(
+ Credential.TYPE_PASSWORD_CREDENTIAL,
+ Bundle(),
+ false,
+) {
+ companion object {
+ @JvmStatic
+ fun createFrom(data: Bundle): GetPasswordOption {
+ return GetPasswordOption()
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPublicKeyCredentialBaseOption.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPublicKeyCredentialBaseOption.kt
new file mode 100644
index 0000000..9b51b30
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPublicKeyCredentialBaseOption.kt
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.os.Bundle
+
+/**
+ * Base request class for getting a registered public key credential.
+ *
+ * @property requestJson the request in JSON format
+ * @throws NullPointerException If [requestJson] is null - auto handled by the
+ * Kotlin runtime
+ * @throws IllegalArgumentException If [requestJson] is empty
+ *
+ * @hide
+ */
+abstract class GetPublicKeyCredentialBaseOption constructor(
+ val requestJson: String,
+ type: String,
+ data: Bundle,
+ requireSystemProvider: Boolean,
+) : GetCredentialOption(type, data, requireSystemProvider) {
+
+ init {
+ require(requestJson.isNotEmpty()) { "request json must not be empty" }
+ }
+
+ companion object {
+ const val BUNDLE_KEY_REQUEST_JSON = "androidx.credentials.BUNDLE_KEY_REQUEST_JSON"
+ const val BUNDLE_KEY_SUBTYPE = "androidx.credentials.BUNDLE_KEY_SUBTYPE"
+
+ @JvmStatic
+ fun createFrom(data: Bundle): GetPublicKeyCredentialBaseOption {
+ return when (data.getString(BUNDLE_KEY_SUBTYPE)) {
+ GetPublicKeyCredentialOption
+ .BUNDLE_VALUE_SUBTYPE_GET_PUBLIC_KEY_CREDENTIAL_OPTION ->
+ GetPublicKeyCredentialOption.createFrom(data)
+ GetPublicKeyCredentialOptionPrivileged
+ .BUNDLE_VALUE_SUBTYPE_GET_PUBLIC_KEY_CREDENTIAL_OPTION_PRIVILEGED ->
+ GetPublicKeyCredentialOptionPrivileged.createFrom(data)
+ else -> throw FrameworkClassParsingException()
+ }
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPublicKeyCredentialOption.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPublicKeyCredentialOption.kt
new file mode 100644
index 0000000..6f13c17
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPublicKeyCredentialOption.kt
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.os.Bundle
+
+/**
+ * A request to get passkeys from the user's public key credential provider.
+ *
+ * @property requestJson the request in JSON format
+ * @property allowHybrid defines whether hybrid credentials are allowed to fulfill this request,
+ * true by default
+ * @throws NullPointerException If [requestJson] or [allowHybrid] is null. It is handled by the
+ * Kotlin runtime
+ * @throws IllegalArgumentException If [requestJson] is empty
+ *
+ * @hide
+ */
+class GetPublicKeyCredentialOption @JvmOverloads constructor(
+ requestJson: String,
+ @get:JvmName("allowHybrid")
+ val allowHybrid: Boolean = true,
+) : GetPublicKeyCredentialBaseOption(
+ requestJson,
+ PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL,
+ toBundle(requestJson, allowHybrid),
+ false
+) {
+ companion object {
+ const val BUNDLE_KEY_ALLOW_HYBRID = "androidx.credentials.BUNDLE_KEY_ALLOW_HYBRID"
+ const val BUNDLE_VALUE_SUBTYPE_GET_PUBLIC_KEY_CREDENTIAL_OPTION =
+ "androidx.credentials.BUNDLE_VALUE_SUBTYPE_GET_PUBLIC_KEY_CREDENTIAL_OPTION"
+
+ @JvmStatic
+ internal fun toBundle(requestJson: String, allowHybrid: Boolean): Bundle {
+ val bundle = Bundle()
+ bundle.putString(BUNDLE_KEY_REQUEST_JSON, requestJson)
+ bundle.putBoolean(BUNDLE_KEY_ALLOW_HYBRID, allowHybrid)
+ return bundle
+ }
+
+ @JvmStatic
+ fun createFrom(data: Bundle): GetPublicKeyCredentialOption {
+ try {
+ val requestJson = data.getString(BUNDLE_KEY_REQUEST_JSON)
+ val allowHybrid = data.get(BUNDLE_KEY_ALLOW_HYBRID)
+ return GetPublicKeyCredentialOption(requestJson!!, (allowHybrid!!) as Boolean)
+ } catch (e: Exception) {
+ throw FrameworkClassParsingException()
+ }
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPublicKeyCredentialOptionPrivileged.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPublicKeyCredentialOptionPrivileged.kt
new file mode 100644
index 0000000..79c62a1
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/GetPublicKeyCredentialOptionPrivileged.kt
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.os.Bundle
+
+/**
+ * A privileged request to get passkeys from the user's public key credential provider. The caller
+ * can modify the RP. Only callers with privileged permission (e.g. user's public browser or caBLE)
+ * can use this.
+ *
+ * @property requestJson the privileged request in JSON format
+ * @property allowHybrid defines whether hybrid credentials are allowed to fulfill this request,
+ * true by default
+ * @property rp the expected true RP ID which will override the one in the [requestJson]
+ * @property clientDataHash a hash that is used to verify the [rp] Identity
+ * @throws NullPointerException If any of [allowHybrid], [requestJson], [rp], or [clientDataHash]
+ * is null. This is handled by the Kotlin runtime
+ * @throws IllegalArgumentException If any of [requestJson], [rp], or [clientDataHash] is empty
+ *
+ * @hide
+ */
+class GetPublicKeyCredentialOptionPrivileged @JvmOverloads constructor(
+ requestJson: String,
+ val rp: String,
+ val clientDataHash: String,
+ @get:JvmName("allowHybrid")
+ val allowHybrid: Boolean = true
+) : GetPublicKeyCredentialBaseOption(
+ requestJson,
+ PublicKeyCredential.TYPE_PUBLIC_KEY_CREDENTIAL,
+ toBundle(requestJson, rp, clientDataHash, allowHybrid),
+ false,
+) {
+
+ init {
+ require(rp.isNotEmpty()) { "rp must not be empty" }
+ require(clientDataHash.isNotEmpty()) { "clientDataHash must not be empty" }
+ }
+
+ /** A builder for [GetPublicKeyCredentialOptionPrivileged]. */
+ class Builder(var requestJson: String, var rp: String, var clientDataHash: String) {
+
+ private var allowHybrid: Boolean = true
+
+ /**
+ * Sets the privileged request in JSON format.
+ */
+ fun setRequestJson(requestJson: String): Builder {
+ this.requestJson = requestJson
+ return this
+ }
+
+ /**
+ * Sets whether hybrid credentials are allowed to fulfill this request, true by default.
+ */
+ fun setAllowHybrid(allowHybrid: Boolean): Builder {
+ this.allowHybrid = allowHybrid
+ return this
+ }
+
+ /**
+ * Sets the expected true RP ID which will override the one in the [requestJson].
+ */
+ fun setRp(rp: String): Builder {
+ this.rp = rp
+ return this
+ }
+
+ /**
+ * Sets a hash that is used to verify the [rp] Identity.
+ */
+ fun setClientDataHash(clientDataHash: String): Builder {
+ this.clientDataHash = clientDataHash
+ return this
+ }
+
+ /** Builds a [GetPublicKeyCredentialOptionPrivileged]. */
+ fun build(): GetPublicKeyCredentialOptionPrivileged {
+ return GetPublicKeyCredentialOptionPrivileged(this.requestJson,
+ this.rp, this.clientDataHash, this.allowHybrid)
+ }
+ }
+
+ companion object {
+ const val BUNDLE_KEY_RP = "androidx.credentials.BUNDLE_KEY_RP"
+ const val BUNDLE_KEY_CLIENT_DATA_HASH =
+ "androidx.credentials.BUNDLE_KEY_CLIENT_DATA_HASH"
+ const val BUNDLE_KEY_ALLOW_HYBRID = "androidx.credentials.BUNDLE_KEY_ALLOW_HYBRID"
+ const val BUNDLE_VALUE_SUBTYPE_GET_PUBLIC_KEY_CREDENTIAL_OPTION_PRIVILEGED =
+ "androidx.credentials.BUNDLE_VALUE_SUBTYPE_GET_PUBLIC_KEY_CREDENTIAL_OPTION" +
+ "_PRIVILEGED"
+
+ @JvmStatic
+ internal fun toBundle(
+ requestJson: String,
+ rp: String,
+ clientDataHash: String,
+ allowHybrid: Boolean
+ ): Bundle {
+ val bundle = Bundle()
+ bundle.putString(BUNDLE_KEY_REQUEST_JSON, requestJson)
+ bundle.putString(BUNDLE_KEY_RP, rp)
+ bundle.putString(BUNDLE_KEY_CLIENT_DATA_HASH, clientDataHash)
+ bundle.putBoolean(BUNDLE_KEY_ALLOW_HYBRID, allowHybrid)
+ return bundle
+ }
+
+ @JvmStatic
+ fun createFrom(data: Bundle): GetPublicKeyCredentialOptionPrivileged {
+ try {
+ val requestJson = data.getString(BUNDLE_KEY_REQUEST_JSON)
+ val rp = data.getString(BUNDLE_KEY_RP)
+ val clientDataHash = data.getString(BUNDLE_KEY_CLIENT_DATA_HASH)
+ val allowHybrid = data.get(BUNDLE_KEY_ALLOW_HYBRID)
+ return GetPublicKeyCredentialOptionPrivileged(
+ requestJson!!,
+ rp!!,
+ clientDataHash!!,
+ (allowHybrid!!) as Boolean,
+ )
+ } catch (e: Exception) {
+ throw FrameworkClassParsingException()
+ }
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/PublicKeyCredential.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/PublicKeyCredential.kt
new file mode 100644
index 0000000..b45a63b
--- /dev/null
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/developer/PublicKeyCredential.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.credentialmanager.jetpack.developer
+
+import android.os.Bundle
+
+/**
+ * Represents the user's passkey credential granted by the user for app sign-in.
+ *
+ * @property authenticationResponseJson the public key credential authentication response in
+ * JSON format that follows the standard webauthn json format shown at
+ * [this w3c link](https://w3c.github.io/webauthn/#dictdef-authenticationresponsejson)
+ * @throws NullPointerException If [authenticationResponseJson] is null. This is handled by the
+ * kotlin runtime
+ * @throws IllegalArgumentException If [authenticationResponseJson] is empty
+ *
+ * @hide
+ */
+class PublicKeyCredential constructor(
+ val authenticationResponseJson: String
+) : Credential(
+ TYPE_PUBLIC_KEY_CREDENTIAL,
+ toBundle(authenticationResponseJson)
+) {
+
+ init {
+ require(authenticationResponseJson.isNotEmpty()) {
+ "authentication response JSON must not be empty" }
+ }
+ companion object {
+ /** The type value for public key credential related operations. */
+ const val TYPE_PUBLIC_KEY_CREDENTIAL: String =
+ "androidx.credentials.TYPE_PUBLIC_KEY_CREDENTIAL"
+ const val BUNDLE_KEY_AUTHENTICATION_RESPONSE_JSON =
+ "androidx.credentials.BUNDLE_KEY_AUTHENTICATION_RESPONSE_JSON"
+
+ @JvmStatic
+ internal fun toBundle(authenticationResponseJson: String): Bundle {
+ val bundle = Bundle()
+ bundle.putString(BUNDLE_KEY_AUTHENTICATION_RESPONSE_JSON, authenticationResponseJson)
+ return bundle
+ }
+ }
+}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/ActionUi.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/ActionUi.kt
similarity index 96%
rename from packages/CredentialManager/src/com/android/credentialmanager/jetpack/ActionUi.kt
rename to packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/ActionUi.kt
index d4341b4..1e639fe 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/ActionUi.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/ActionUi.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.credentialmanager.jetpack
+package com.android.credentialmanager.jetpack.provider
import android.app.slice.Slice
import android.credentials.ui.Entry
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/CredentialEntryUi.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt
similarity index 96%
rename from packages/CredentialManager/src/com/android/credentialmanager/jetpack/CredentialEntryUi.kt
rename to packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt
index d6f1b5f..12ab436 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/CredentialEntryUi.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/CredentialEntryUi.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.credentialmanager.jetpack
+package com.android.credentialmanager.jetpack.provider
import android.app.slice.Slice
import android.graphics.drawable.Icon
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/PasskeyCredentialEntryUi.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/PasskeyCredentialEntryUi.kt
similarity index 97%
rename from packages/CredentialManager/src/com/android/credentialmanager/jetpack/PasskeyCredentialEntryUi.kt
rename to packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/PasskeyCredentialEntryUi.kt
index bb3b206..c5dbe66 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/PasskeyCredentialEntryUi.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/PasskeyCredentialEntryUi.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.credentialmanager.jetpack
+package com.android.credentialmanager.jetpack.provider
import android.app.slice.Slice
import android.credentials.ui.Entry
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/PasswordCredentialEntryUi.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/PasswordCredentialEntryUi.kt
similarity index 97%
rename from packages/CredentialManager/src/com/android/credentialmanager/jetpack/PasswordCredentialEntryUi.kt
rename to packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/PasswordCredentialEntryUi.kt
index 7311b70..5049503 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/PasswordCredentialEntryUi.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/PasswordCredentialEntryUi.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.credentialmanager.jetpack
+package com.android.credentialmanager.jetpack.provider
import android.app.slice.Slice
import android.credentials.ui.Entry
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/SaveEntryUi.kt b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt
similarity index 97%
rename from packages/CredentialManager/src/com/android/credentialmanager/jetpack/SaveEntryUi.kt
rename to packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt
index fad3309..b260cf6 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/jetpack/SaveEntryUi.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/jetpack/provider/SaveEntryUi.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.credentialmanager.jetpack
+package com.android.credentialmanager.jetpack.provider
import android.app.slice.Slice
import android.credentials.ui.Entry
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GalleryApplication.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GalleryApplication.kt
index 36b58ad..dfbf244 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GalleryApplication.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GalleryApplication.kt
@@ -22,6 +22,6 @@
class GalleryApplication : Application() {
override fun onCreate() {
super.onCreate()
- SpaEnvironmentFactory.reset(GallerySpaEnvironment)
+ SpaEnvironmentFactory.reset(GallerySpaEnvironment(this))
}
}
\ No newline at end of file
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GallerySpaEnvironment.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GallerySpaEnvironment.kt
index 4af2589..92f4fe4 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GallerySpaEnvironment.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/GallerySpaEnvironment.kt
@@ -16,6 +16,7 @@
package com.android.settingslib.spa.gallery
+import android.content.Context
import com.android.settingslib.spa.framework.common.LocalLogger
import com.android.settingslib.spa.framework.common.SettingsPageProviderRepository
import com.android.settingslib.spa.framework.common.SpaEnvironment
@@ -49,7 +50,7 @@
// Add your SPPs
}
-object GallerySpaEnvironment : SpaEnvironment() {
+class GallerySpaEnvironment(context: Context) : SpaEnvironment(context) {
override val pageProviderRepository = lazy {
SettingsPageProviderRepository(
allPageProviders = listOf(
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/home/HomePage.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/home/HomePage.kt
index 7fd49db..83e3f78 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/home/HomePage.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/home/HomePage.kt
@@ -22,6 +22,7 @@
import androidx.compose.ui.tooling.preview.Preview
import com.android.settingslib.spa.framework.common.SettingsEntry
import com.android.settingslib.spa.framework.common.SettingsPageProvider
+import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
import com.android.settingslib.spa.framework.common.createSettingsPage
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.gallery.R
@@ -76,6 +77,7 @@
@Preview(showBackground = true)
@Composable
private fun HomeScreenPreview() {
+ SpaEnvironmentFactory.resetForPreview()
SettingsTheme {
HomePageProvider.Page(null)
}
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/ArgumentPage.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/ArgumentPage.kt
index 8207310..60ff362 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/ArgumentPage.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/page/ArgumentPage.kt
@@ -23,6 +23,7 @@
import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
import com.android.settingslib.spa.framework.common.SettingsPage
import com.android.settingslib.spa.framework.common.SettingsPageProvider
+import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
import com.android.settingslib.spa.framework.common.createSettingsPage
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.gallery.SettingsPageProviderEnum
@@ -115,6 +116,7 @@
@Preview(showBackground = true)
@Composable
private fun ArgumentPagePreview() {
+ SpaEnvironmentFactory.resetForPreview()
SettingsTheme {
ArgumentPageProvider.Page(
ArgumentPageModel.buildArgument(stringParam = "foo", intParam = 0)
diff --git a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/PreferencePage.kt b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/PreferencePage.kt
index fa8d51c..2c2782b 100644
--- a/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/PreferencePage.kt
+++ b/packages/SettingsLib/Spa/gallery/src/com/android/settingslib/spa/gallery/preference/PreferencePage.kt
@@ -217,6 +217,7 @@
@Preview(showBackground = true)
@Composable
private fun PreferencePagePreview() {
+ SpaEnvironmentFactory.resetForPreview()
SettingsTheme {
PreferencePageProvider.Page(null)
}
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaEnvironment.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaEnvironment.kt
index 5baee4f..6073425 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaEnvironment.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/common/SpaEnvironment.kt
@@ -17,7 +17,10 @@
package com.android.settingslib.spa.framework.common
import android.app.Activity
+import android.content.Context
import android.util.Log
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.platform.LocalContext
private const val TAG = "SpaEnvironment"
@@ -29,6 +32,20 @@
Log.d(TAG, "reset")
}
+ @Composable
+ fun resetForPreview() {
+ val context = LocalContext.current
+ spaEnvironment = object : SpaEnvironment(context) {
+ override val pageProviderRepository = lazy {
+ SettingsPageProviderRepository(
+ allPageProviders = emptyList(),
+ rootPages = emptyList()
+ )
+ }
+ }
+ Log.d(TAG, "resetForPreview")
+ }
+
val instance: SpaEnvironment
get() {
if (spaEnvironment == null)
@@ -37,11 +54,13 @@
}
}
-abstract class SpaEnvironment {
+abstract class SpaEnvironment(context: Context) {
abstract val pageProviderRepository: Lazy<SettingsPageProviderRepository>
val entryRepository = lazy { SettingsEntryRepository(pageProviderRepository.value) }
+ val appContext: Context = context.applicationContext
+
open val browseActivityClass: Class<out Activity>? = null
open val entryProviderAuthorities: String? = null
diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/util/EntryHighlight.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/util/EntryHighlight.kt
index d09aec9..e26bdf7 100644
--- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/util/EntryHighlight.kt
+++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/util/EntryHighlight.kt
@@ -36,14 +36,15 @@
@Composable
internal fun EntryHighlight(UiLayoutFn: @Composable () -> Unit) {
val entryData = LocalEntryDataProvider.current
- var isHighlighted by rememberSaveable { mutableStateOf(false) }
+ val entryIsHighlighted = rememberSaveable { entryData.isHighlighted }
+ var localHighlighted by rememberSaveable { mutableStateOf(false) }
SideEffect {
- isHighlighted = entryData.isHighlighted
+ localHighlighted = entryIsHighlighted
}
val backgroundColor by animateColorAsState(
targetValue = when {
- isHighlighted -> MaterialTheme.colorScheme.surfaceVariant
+ localHighlighted -> MaterialTheme.colorScheme.surfaceVariant
else -> SettingsTheme.colorScheme.background
},
animationSpec = repeatable(
diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/PackageManagerExt.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/PackageManagerExt.kt
new file mode 100644
index 0000000..2b2f11c
--- /dev/null
+++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/PackageManagerExt.kt
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settingslib.spaprivileged.model.app
+
+import android.content.Intent
+import android.content.pm.ActivityInfo
+import android.content.pm.ApplicationInfo
+import android.content.pm.PackageManager
+import android.content.pm.PackageManager.ResolveInfoFlags
+
+/**
+ * Checks if a package is system module.
+ */
+fun PackageManager.isSystemModule(packageName: String): Boolean = try {
+ getModuleInfo(packageName, 0)
+ true
+} catch (_: PackageManager.NameNotFoundException) {
+ // Expected, not system module
+ false
+}
+
+/**
+ * Resolves the activity to start for a given application and action.
+ */
+fun PackageManager.resolveActionForApp(
+ app: ApplicationInfo,
+ action: String,
+ flags: Int = 0,
+): ActivityInfo? {
+ val intent = Intent(action).apply {
+ `package` = app.packageName
+ }
+ return resolveActivityAsUser(intent, ResolveInfoFlags.of(flags.toLong()), app.userId)
+ ?.activityInfo
+}
diff --git a/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/PackageManagerExtTest.kt b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/PackageManagerExtTest.kt
new file mode 100644
index 0000000..4207490
--- /dev/null
+++ b/packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/PackageManagerExtTest.kt
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settingslib.spaprivileged.model.app
+
+import android.content.ComponentName
+import android.content.pm.ActivityInfo
+import android.content.pm.ApplicationInfo
+import android.content.pm.ModuleInfo
+import android.content.pm.PackageManager
+import android.content.pm.PackageManager.NameNotFoundException
+import android.content.pm.PackageManager.ResolveInfoFlags
+import android.content.pm.ResolveInfo
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.google.common.truth.Truth.assertThat
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentCaptor
+import org.mockito.Mock
+import org.mockito.Mockito.any
+import org.mockito.Mockito.eq
+import org.mockito.Mockito.verify
+import org.mockito.junit.MockitoJUnit
+import org.mockito.junit.MockitoRule
+import org.mockito.Mockito.`when` as whenever
+
+@RunWith(AndroidJUnit4::class)
+class PackageManagerExtTest {
+ @JvmField
+ @Rule
+ val mockito: MockitoRule = MockitoJUnit.rule()
+
+ @Mock
+ private lateinit var packageManager: PackageManager
+
+ private fun mockResolveActivityAsUser(resolveInfo: ResolveInfo?) {
+ whenever(
+ packageManager.resolveActivityAsUser(any(), any<ResolveInfoFlags>(), eq(APP.userId))
+ ).thenReturn(resolveInfo)
+ }
+
+ @Test
+ fun isSystemModule_whenSystemModule_returnTrue() {
+ whenever(packageManager.getModuleInfo(PACKAGE_NAME, 0)).thenReturn(ModuleInfo())
+
+ val isSystemModule = packageManager.isSystemModule(PACKAGE_NAME)
+
+ assertThat(isSystemModule).isTrue()
+ }
+
+ @Test
+ fun isSystemModule_whenNotSystemModule_returnFalse() {
+ whenever(packageManager.getModuleInfo(PACKAGE_NAME, 0)).thenThrow(NameNotFoundException())
+
+ val isSystemModule = packageManager.isSystemModule(PACKAGE_NAME)
+
+ assertThat(isSystemModule).isFalse()
+ }
+
+ @Test
+ fun resolveActionForApp_noResolveInfo() {
+ mockResolveActivityAsUser(null)
+
+ val activityInfo = packageManager.resolveActionForApp(APP, ACTION)
+
+ assertThat(activityInfo).isNull()
+ }
+
+ @Test
+ fun resolveActionForApp_noActivityInfo() {
+ mockResolveActivityAsUser(ResolveInfo())
+
+ val activityInfo = packageManager.resolveActionForApp(APP, ACTION)
+
+ assertThat(activityInfo).isNull()
+ }
+
+ @Test
+ fun resolveActionForApp_hasActivityInfo() {
+ mockResolveActivityAsUser(ResolveInfo().apply {
+ activityInfo = ActivityInfo().apply {
+ packageName = PACKAGE_NAME
+ name = ACTIVITY_NAME
+ }
+ })
+
+ val activityInfo = packageManager.resolveActionForApp(APP, ACTION)!!
+
+ assertThat(activityInfo.componentName).isEqualTo(ComponentName(PACKAGE_NAME, ACTIVITY_NAME))
+ }
+
+ @Test
+ fun resolveActionForApp_withFlags() {
+ packageManager.resolveActionForApp(
+ app = APP,
+ action = ACTION,
+ flags = PackageManager.GET_META_DATA,
+ )
+
+ val flagsCaptor = ArgumentCaptor.forClass(ResolveInfoFlags::class.java)
+ verify(packageManager).resolveActivityAsUser(any(), flagsCaptor.capture(), eq(APP.userId))
+ assertThat(flagsCaptor.value.value).isEqualTo(PackageManager.GET_META_DATA.toLong())
+ }
+
+ private companion object {
+ const val PACKAGE_NAME = "package.name"
+ const val ACTIVITY_NAME = "ActivityName"
+ const val ACTION = "action"
+ const val UID = 123
+ val APP = ApplicationInfo().apply {
+ packageName = PACKAGE_NAME
+ uid = UID
+ }
+ }
+}
diff --git a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkDatabase.java b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkDatabase.java
index c1ee7ad..ca457b0 100644
--- a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkDatabase.java
+++ b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/MobileNetworkDatabase.java
@@ -20,6 +20,7 @@
import android.util.Log;
import java.util.List;
+import java.util.Objects;
import androidx.lifecycle.LiveData;
import androidx.room.Database;
@@ -39,17 +40,27 @@
public abstract MobileNetworkInfoDao mMobileNetworkInfoDao();
+ private static MobileNetworkDatabase sInstance;
+ private static final Object sLOCK = new Object();
+
+
/**
* Create the MobileNetworkDatabase.
*
* @param context The context.
* @return The MobileNetworkDatabase.
*/
- public static MobileNetworkDatabase createDatabase(Context context) {
- return Room.inMemoryDatabaseBuilder(context, MobileNetworkDatabase.class)
- .fallbackToDestructiveMigration()
- .enableMultiInstanceInvalidation()
- .build();
+ public static MobileNetworkDatabase getInstance(Context context) {
+ synchronized (sLOCK) {
+ if (Objects.isNull(sInstance)) {
+ Log.d(TAG, "createDatabase.");
+ sInstance = Room.inMemoryDatabaseBuilder(context, MobileNetworkDatabase.class)
+ .fallbackToDestructiveMigration()
+ .enableMultiInstanceInvalidation()
+ .build();
+ }
+ }
+ return sInstance;
}
/**
@@ -93,7 +104,7 @@
* Query the subscription info by the subscription ID from the SubscriptionInfoEntity
* table.
*/
- public LiveData<SubscriptionInfoEntity> querySubInfoById(String id) {
+ public SubscriptionInfoEntity querySubInfoById(String id) {
return mSubscriptionInfoDao().querySubInfoById(id);
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/SubscriptionInfoDao.java b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/SubscriptionInfoDao.java
index 4596637..e835125 100644
--- a/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/SubscriptionInfoDao.java
+++ b/packages/SettingsLib/src/com/android/settingslib/mobile/dataservice/SubscriptionInfoDao.java
@@ -37,7 +37,7 @@
@Query("SELECT * FROM " + DataServiceUtils.SubscriptionInfoData.TABLE_NAME + " WHERE "
+ DataServiceUtils.SubscriptionInfoData.COLUMN_ID + " = :subId")
- LiveData<SubscriptionInfoEntity> querySubInfoById(String subId);
+ SubscriptionInfoEntity querySubInfoById(String subId);
@Query("SELECT * FROM " + DataServiceUtils.SubscriptionInfoData.TABLE_NAME + " WHERE "
+ DataServiceUtils.SubscriptionInfoData.COLUMN_IS_ACTIVE_SUBSCRIPTION_ID
diff --git a/packages/SettingsLib/src/com/android/settingslib/qrcode/OWNERS b/packages/SettingsLib/src/com/android/settingslib/qrcode/OWNERS
new file mode 100644
index 0000000..61c73fb
--- /dev/null
+++ b/packages/SettingsLib/src/com/android/settingslib/qrcode/OWNERS
@@ -0,0 +1,8 @@
+# Default reviewers for this and subdirectories.
+bonianchen@google.com
+changbetty@google.com
+goldmanj@google.com
+wengsu@google.com
+zoeychen@google.com
+
+# Emergency approvers in case the above are not available
diff --git a/packages/SystemUI/ktfmt_includes.txt b/packages/SystemUI/ktfmt_includes.txt
index 0f037e4..06ea381 100644
--- a/packages/SystemUI/ktfmt_includes.txt
+++ b/packages/SystemUI/ktfmt_includes.txt
@@ -27,8 +27,6 @@
-packages/SystemUI/shared/src/com/android/systemui/shared/clocks/AnimatableClockView.kt
-packages/SystemUI/shared/src/com/android/systemui/shared/clocks/ClockRegistry.kt
-packages/SystemUI/shared/src/com/android/systemui/shared/clocks/DefaultClockProvider.kt
--packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionDarkness.kt
--packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt
-packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButtonPositionCalculator.kt
-packages/SystemUI/shared/src/com/android/systemui/shared/system/UncaughtExceptionPreHandlerManager.kt
-packages/SystemUI/shared/src/com/android/systemui/shared/system/smartspace/SmartspaceState.kt
@@ -683,8 +681,6 @@
-packages/SystemUI/tests/src/com/android/systemui/shared/animation/UnfoldConstantTranslateAnimatorTest.kt
-packages/SystemUI/tests/src/com/android/systemui/shared/animation/UnfoldMoveFromCenterAnimatorTest.kt
-packages/SystemUI/tests/src/com/android/systemui/shared/clocks/ClockRegistryTest.kt
--packages/SystemUI/tests/src/com/android/systemui/shared/navigationbar/RegionSamplingHelperTest.kt
--packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplingInstanceTest.kt
-packages/SystemUI/tests/src/com/android/systemui/shared/rotation/RotationButtonControllerTest.kt
-packages/SystemUI/tests/src/com/android/systemui/shared/system/UncaughtExceptionPreHandlerTest.kt
-packages/SystemUI/tests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt
diff --git a/packages/SystemUI/res/layout/user_switcher_fullscreen.xml b/packages/SystemUI/res/layout/user_switcher_fullscreen.xml
index c2c79cb..78884ff 100644
--- a/packages/SystemUI/res/layout/user_switcher_fullscreen.xml
+++ b/packages/SystemUI/res/layout/user_switcher_fullscreen.xml
@@ -14,58 +14,84 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<com.android.systemui.user.UserSwitcherRootView
+<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:id="@+id/user_switcher_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_marginVertical="40dp"
- android:layout_marginHorizontal="60dp">
+ android:orientation="vertical">
- <androidx.constraintlayout.helper.widget.Flow
- android:id="@+id/flow"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:flow_horizontalBias="0.5"
- app:flow_verticalAlign="center"
- app:flow_wrapMode="chain"
- app:flow_horizontalGap="@dimen/user_switcher_fullscreen_horizontal_gap"
- app:flow_verticalGap="44dp"
- app:flow_horizontalStyle="packed"/>
+ <ScrollView
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:fillViewport="true">
- <TextView
- android:id="@+id/cancel"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:gravity="center"
- app:layout_constraintHeight_min="48dp"
- app:layout_constraintEnd_toStartOf="@+id/add"
- app:layout_constraintBottom_toBottomOf="parent"
- android:paddingHorizontal="@dimen/user_switcher_fullscreen_button_padding"
- android:textSize="@dimen/user_switcher_fullscreen_button_text_size"
- android:textColor="?androidprv:attr/colorAccentPrimary"
- android:text="@string/cancel" />
+ <com.android.systemui.user.UserSwitcherRootView
+ android:id="@+id/user_switcher_grid_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="40dp"
+ android:paddingHorizontal="60dp">
- <TextView
- android:id="@+id/add"
- style="@style/Widget.Dialog.Button.BorderButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:gravity="center"
- android:paddingHorizontal="@dimen/user_switcher_fullscreen_button_padding"
- android:text="@string/add"
- android:textColor="?androidprv:attr/colorAccentPrimary"
- android:textSize="@dimen/user_switcher_fullscreen_button_text_size"
- android:visibility="gone"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHeight_min="48dp" />
-</com.android.systemui.user.UserSwitcherRootView>
+ <androidx.constraintlayout.helper.widget.Flow
+ android:id="@+id/flow"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:flow_horizontalBias="0.5"
+ app:flow_verticalAlign="center"
+ app:flow_wrapMode="chain"
+ app:flow_horizontalGap="@dimen/user_switcher_fullscreen_horizontal_gap"
+ app:flow_verticalGap="44dp"
+ app:flow_horizontalStyle="packed"/>
+ </com.android.systemui.user.UserSwitcherRootView>
+
+ </ScrollView>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="96dp"
+ android:orientation="horizontal"
+ android:gravity="center_vertical|end"
+ android:paddingEnd="48dp">
+
+ <TextView
+ android:id="@+id/cancel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:minHeight="48dp"
+ android:paddingHorizontal="@dimen/user_switcher_fullscreen_button_padding"
+ android:textSize="@dimen/user_switcher_fullscreen_button_text_size"
+ android:textColor="?androidprv:attr/colorAccentPrimary"
+ android:text="@string/cancel" />
+
+ <Space
+ android:layout_width="24dp"
+ android:layout_height="0dp"
+ />
+
+ <TextView
+ android:id="@+id/add"
+ style="@style/Widget.Dialog.Button.BorderButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:paddingHorizontal="@dimen/user_switcher_fullscreen_button_padding"
+ android:text="@string/add"
+ android:textColor="?androidprv:attr/colorAccentPrimary"
+ android:textSize="@dimen/user_switcher_fullscreen_button_text_size"
+ android:visibility="gone"
+ android:minHeight="48dp" />
+
+ </LinearLayout>
+
+</LinearLayout>
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt
similarity index 74%
rename from packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt
rename to packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt
index cd4b999..0ee813b 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt
@@ -24,15 +24,13 @@
import java.io.PrintWriter
import java.util.concurrent.Executor
-/**
- * Class for instance of RegionSamplingHelper
- */
-open class RegionSamplingInstance(
- sampledView: View?,
- mainExecutor: Executor?,
- bgExecutor: Executor?,
- regionSamplingEnabled: Boolean,
- updateFun: UpdateColorCallback
+/** Class for instance of RegionSamplingHelper */
+open class RegionSampler(
+ sampledView: View?,
+ mainExecutor: Executor?,
+ bgExecutor: Executor?,
+ regionSamplingEnabled: Boolean,
+ updateFun: UpdateColorCallback
) {
private var regionDarkness = RegionDarkness.DEFAULT
private var samplingBounds = Rect()
@@ -40,23 +38,13 @@
@VisibleForTesting var regionSampler: RegionSamplingHelper? = null
private var lightForegroundColor = Color.WHITE
private var darkForegroundColor = Color.BLACK
- /**
- * Interface for method to be passed into RegionSamplingHelper
- */
- @FunctionalInterface
- interface UpdateColorCallback {
- /**
- * Method to update the foreground colors after clock darkness changed.
- */
- fun updateColors()
- }
@VisibleForTesting
open fun createRegionSamplingHelper(
- sampledView: View,
- callback: SamplingCallback,
- mainExecutor: Executor?,
- bgExecutor: Executor?
+ sampledView: View,
+ callback: SamplingCallback,
+ mainExecutor: Executor?,
+ bgExecutor: Executor?
): RegionSamplingHelper {
return RegionSamplingHelper(sampledView, callback, mainExecutor, bgExecutor)
}
@@ -77,7 +65,7 @@
*
* @return the determined foreground color
*/
- fun currentForegroundColor(): Int{
+ fun currentForegroundColor(): Int {
return if (regionDarkness.isDark) {
lightForegroundColor
} else {
@@ -97,41 +85,37 @@
return regionDarkness
}
- /**
- * Start region sampler
- */
+ /** Start region sampler */
fun startRegionSampler() {
regionSampler?.start(samplingBounds)
}
- /**
- * Stop region sampler
- */
+ /** Stop region sampler */
fun stopRegionSampler() {
regionSampler?.stop()
}
- /**
- * Dump region sampler
- */
+ /** Dump region sampler */
fun dump(pw: PrintWriter) {
regionSampler?.dump(pw)
}
init {
if (regionSamplingEnabled && sampledView != null) {
- regionSampler = createRegionSamplingHelper(sampledView,
+ regionSampler =
+ createRegionSamplingHelper(
+ sampledView,
object : SamplingCallback {
override fun onRegionDarknessChanged(isRegionDark: Boolean) {
regionDarkness = convertToClockDarkness(isRegionDark)
- updateFun.updateColors()
+ updateFun()
}
/**
- * The method getLocationOnScreen is used to obtain the view coordinates
- * relative to its left and top edges on the device screen.
- * Directly accessing the X and Y coordinates of the view returns the
- * location relative to its parent view instead.
- */
+ * The method getLocationOnScreen is used to obtain the view coordinates
+ * relative to its left and top edges on the device screen. Directly
+ * accessing the X and Y coordinates of the view returns the location
+ * relative to its parent view instead.
+ */
override fun getSampledRegion(sampledView: View): Rect {
val screenLocation = tmpScreenLocation
sampledView.getLocationOnScreen(screenLocation)
@@ -147,8 +131,13 @@
override fun isSamplingEnabled(): Boolean {
return regionSamplingEnabled
}
- }, mainExecutor, bgExecutor)
+ },
+ mainExecutor,
+ bgExecutor
+ )
}
regionSampler?.setWindowVisible(true)
}
}
+
+typealias UpdateColorCallback = () -> Unit
diff --git a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt
index 40a96b0..71e0446 100644
--- a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt
+++ b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt
@@ -38,21 +38,21 @@
import com.android.systemui.log.dagger.KeyguardClockLog
import com.android.systemui.plugins.ClockController
import com.android.systemui.plugins.log.LogBuffer
-import com.android.systemui.shared.regionsampling.RegionSamplingInstance
+import com.android.systemui.shared.regionsampling.RegionSampler
import com.android.systemui.statusbar.policy.BatteryController
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback
import com.android.systemui.statusbar.policy.ConfigurationController
-import java.io.PrintWriter
-import java.util.Locale
-import java.util.TimeZone
-import java.util.concurrent.Executor
-import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
+import java.io.PrintWriter
+import java.util.Locale
+import java.util.TimeZone
+import java.util.concurrent.Executor
+import javax.inject.Inject
/**
* Controller for a Clock provided by the registry and used on the keyguard. Instantiated by
@@ -69,14 +69,17 @@
private val context: Context,
@Main private val mainExecutor: Executor,
@Background private val bgExecutor: Executor,
- @KeyguardClockLog private val logBuffer: LogBuffer,
+ @KeyguardClockLog private val logBuffer: LogBuffer?,
private val featureFlags: FeatureFlags
) {
var clock: ClockController? = null
set(value) {
field = value
if (value != null) {
- value.setLogBuffer(logBuffer)
+ if (logBuffer != null) {
+ value.setLogBuffer(logBuffer)
+ }
+
value.initialize(resources, dozeAmount, 0f)
updateRegionSamplers(value)
}
@@ -139,21 +142,17 @@
bgExecutor: Executor?,
regionSamplingEnabled: Boolean,
updateColors: () -> Unit
- ): RegionSamplingInstance {
- return RegionSamplingInstance(
+ ): RegionSampler {
+ return RegionSampler(
sampledView,
mainExecutor,
bgExecutor,
regionSamplingEnabled,
- object : RegionSamplingInstance.UpdateColorCallback {
- override fun updateColors() {
- updateColors()
- }
- })
+ updateFun = { updateColors() } )
}
- var smallRegionSampler: RegionSamplingInstance? = null
- var largeRegionSampler: RegionSamplingInstance? = null
+ var smallRegionSampler: RegionSampler? = null
+ var largeRegionSampler: RegionSampler? = null
private var smallClockIsDark = true
private var largeClockIsDark = true
@@ -161,6 +160,7 @@
private val configListener = object : ConfigurationController.ConfigurationListener {
override fun onThemeChanged() {
clock?.events?.onColorPaletteChanged(resources)
+ updateColors()
}
override fun onDensityOrFontScaleChanged() {
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
index d9f44cd..47ee71e 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
@@ -43,6 +43,7 @@
import com.android.systemui.dagger.GlobalRootComponent;
import com.android.systemui.dagger.SysUIComponent;
import com.android.systemui.dump.DumpManager;
+import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.util.NotificationChannels;
import java.util.Comparator;
@@ -137,7 +138,7 @@
if (mServicesStarted) {
final int N = mServices.length;
for (int i = 0; i < N; i++) {
- mServices[i].onBootCompleted();
+ notifyBootCompleted(mServices[i]);
}
}
}
@@ -256,7 +257,7 @@
for (i = 0; i < mServices.length; i++) {
if (mBootCompleteCache.isBootComplete()) {
- mServices[i].onBootCompleted();
+ notifyBootCompleted(mServices[i]);
}
mDumpManager.registerDumpable(mServices[i].getClass().getName(), mServices[i]);
@@ -267,7 +268,13 @@
mServicesStarted = true;
}
- private void timeInitialization(String clsName, Runnable init, TimingsTraceLog log,
+ private static void notifyBootCompleted(CoreStartable coreStartable) {
+ Trace.beginSection(coreStartable.getClass().getSimpleName() + ".onBootCompleted()");
+ coreStartable.onBootCompleted();
+ Trace.endSection();
+ }
+
+ private static void timeInitialization(String clsName, Runnable init, TimingsTraceLog log,
String metricsPrefix) {
long ti = System.currentTimeMillis();
log.traceBegin(metricsPrefix + " " + clsName);
@@ -281,11 +288,13 @@
}
}
- private CoreStartable startAdditionalStartable(String clsName) {
+ private static CoreStartable startAdditionalStartable(String clsName) {
CoreStartable startable;
if (DEBUG) Log.d(TAG, "loading: " + clsName);
try {
+ Trace.beginSection(clsName + ".newInstance()");
startable = (CoreStartable) Class.forName(clsName).newInstance();
+ Trace.endSection();
} catch (ClassNotFoundException
| IllegalAccessException
| InstantiationException ex) {
@@ -295,14 +304,19 @@
return startStartable(startable);
}
- private CoreStartable startStartable(String clsName, Provider<CoreStartable> provider) {
+ private static CoreStartable startStartable(String clsName, Provider<CoreStartable> provider) {
if (DEBUG) Log.d(TAG, "loading: " + clsName);
- return startStartable(provider.get());
+ Trace.beginSection("Provider<" + clsName + ">.get()");
+ CoreStartable startable = provider.get();
+ Trace.endSection();
+ return startStartable(startable);
}
- private CoreStartable startStartable(CoreStartable startable) {
+ private static CoreStartable startStartable(CoreStartable startable) {
if (DEBUG) Log.d(TAG, "running: " + startable);
+ Trace.beginSection(startable.getClass().getSimpleName() + ".start()");
startable.start();
+ Trace.endSection();
return startable;
}
@@ -340,11 +354,18 @@
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (mServicesStarted) {
- mSysUIComponent.getConfigurationController().onConfigurationChanged(newConfig);
+ ConfigurationController configController = mSysUIComponent.getConfigurationController();
+ Trace.beginSection(
+ configController.getClass().getSimpleName() + ".onConfigurationChanged()");
+ configController.onConfigurationChanged(newConfig);
+ Trace.endSection();
int len = mServices.length;
for (int i = 0; i < len; i++) {
if (mServices[i] != null) {
+ Trace.beginSection(
+ mServices[i].getClass().getSimpleName() + ".onConfigurationChanged()");
mServices[i].onConfigurationChanged(newConfig);
+ Trace.endSection();
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/models/player/MediaData.kt b/packages/SystemUI/src/com/android/systemui/media/controls/models/player/MediaData.kt
index ed649b1..f006442 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/models/player/MediaData.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/models/player/MediaData.kt
@@ -181,6 +181,7 @@
return enabled == other.enabled &&
name == other.name &&
intent == other.intent &&
- id == other.id
+ id == other.id &&
+ showBroadcastButton == other.showBroadcastButton
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
index 1c0f057..2aa7064 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
@@ -4729,8 +4729,6 @@
private void startOpening(MotionEvent event) {
updatePanelExpansionAndVisibility();
- // Reset at start so haptic can be triggered as soon as panel starts to open.
- mHasVibratedOnOpen = false;
//TODO: keyguard opens QS a different way; log that too?
// Log the position of the swipe that opened the panel
@@ -5035,7 +5033,7 @@
}
public boolean isFullyExpanded() {
- return mExpandedHeight >= getMaxPanelHeight();
+ return mExpandedHeight >= getMaxPanelTransitionDistance();
}
public boolean isFullyCollapsed() {
@@ -6214,6 +6212,10 @@
}
break;
case MotionEvent.ACTION_MOVE:
+ if (isFullyCollapsed()) {
+ // If panel is fully collapsed, reset haptic effect before adding movement.
+ mHasVibratedOnOpen = false;
+ }
addMovement(event);
if (!isFullyCollapsed()) {
maybeVibrateOnOpening(true /* openingWithTouch */);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt
index fc984618..5873837 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt
@@ -48,7 +48,8 @@
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.settings.UserTracker
-import com.android.systemui.shared.regionsampling.RegionSamplingInstance
+import com.android.systemui.shared.regionsampling.RegionSampler
+import com.android.systemui.shared.regionsampling.UpdateColorCallback
import com.android.systemui.statusbar.phone.KeyguardBypassController
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.statusbar.policy.DeviceProvisionedController
@@ -90,8 +91,8 @@
// Smartspace can be used on multiple displays, such as when the user casts their screen
private var smartspaceViews = mutableSetOf<SmartspaceView>()
- private var regionSamplingInstances =
- mutableMapOf<SmartspaceView, RegionSamplingInstance>()
+ private var regionSamplers =
+ mutableMapOf<SmartspaceView, RegionSampler>()
private val regionSamplingEnabled =
featureFlags.isEnabled(Flags.REGION_SAMPLING)
@@ -101,27 +102,23 @@
private var showSensitiveContentForManagedUser = false
private var managedUserHandle: UserHandle? = null
- private val updateFun = object : RegionSamplingInstance.UpdateColorCallback {
- override fun updateColors() {
- updateTextColorFromRegionSampler()
- }
- }
+ private val updateFun: UpdateColorCallback = { updateTextColorFromRegionSampler() }
// TODO: Move logic into SmartspaceView
var stateChangeListener = object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) {
smartspaceViews.add(v as SmartspaceView)
- var regionSamplingInstance = RegionSamplingInstance(
+ var regionSampler = RegionSampler(
v,
uiExecutor,
bgExecutor,
regionSamplingEnabled,
updateFun
)
- initializeTextColors(regionSamplingInstance)
- regionSamplingInstance.startRegionSampler()
- regionSamplingInstances.put(v, regionSamplingInstance)
+ initializeTextColors(regionSampler)
+ regionSampler.startRegionSampler()
+ regionSamplers.put(v, regionSampler)
connectSession()
updateTextColorFromWallpaper()
@@ -131,9 +128,9 @@
override fun onViewDetachedFromWindow(v: View) {
smartspaceViews.remove(v as SmartspaceView)
- var regionSamplingInstance = regionSamplingInstances.getValue(v)
- regionSamplingInstance.stopRegionSampler()
- regionSamplingInstances.remove(v)
+ var regionSampler = regionSamplers.getValue(v)
+ regionSampler.stopRegionSampler()
+ regionSamplers.remove(v)
if (smartspaceViews.isEmpty()) {
disconnect()
@@ -363,19 +360,19 @@
}
}
- private fun initializeTextColors(regionSamplingInstance: RegionSamplingInstance) {
+ private fun initializeTextColors(regionSampler: RegionSampler) {
val lightThemeContext = ContextThemeWrapper(context, R.style.Theme_SystemUI_LightWallpaper)
val darkColor = Utils.getColorAttrDefaultColor(lightThemeContext, R.attr.wallpaperTextColor)
val darkThemeContext = ContextThemeWrapper(context, R.style.Theme_SystemUI)
val lightColor = Utils.getColorAttrDefaultColor(darkThemeContext, R.attr.wallpaperTextColor)
- regionSamplingInstance.setForegroundColors(lightColor, darkColor)
+ regionSampler.setForegroundColors(lightColor, darkColor)
}
private fun updateTextColorFromRegionSampler() {
smartspaceViews.forEach {
- val textColor = regionSamplingInstances.getValue(it).currentForegroundColor()
+ val textColor = regionSamplers.getValue(it).currentForegroundColor()
it.setPrimaryTextColor(textColor)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt b/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt
index b16dc54..6a23260 100644
--- a/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/data/repository/UserRepository.kt
@@ -62,6 +62,7 @@
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch
+import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
/**
@@ -136,7 +137,7 @@
private val isNewImpl: Boolean
get() = !featureFlags.isEnabled(Flags.USER_INTERACTOR_AND_REPO_USE_CONTROLLER)
- private val _userSwitcherSettings = MutableStateFlow<UserSwitcherSettingsModel?>(null)
+ private val _userSwitcherSettings = MutableStateFlow(runBlocking { getSettings() })
override val userSwitcherSettings: Flow<UserSwitcherSettingsModel> =
_userSwitcherSettings.asStateFlow().filterNotNull()
@@ -235,7 +236,7 @@
}
override fun isSimpleUserSwitcher(): Boolean {
- return checkNotNull(_userSwitcherSettings.value?.isSimpleUserSwitcher)
+ return _userSwitcherSettings.value.isSimpleUserSwitcher
}
private fun observeSelectedUser() {
diff --git a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/GuestUserInteractor.kt b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/GuestUserInteractor.kt
index 07e5cf9..f9d14cd 100644
--- a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/GuestUserInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/GuestUserInteractor.kt
@@ -208,7 +208,12 @@
if (newGuestId == UserHandle.USER_NULL) {
Log.e(TAG, "Could not create new guest, switching back to system user")
switchUser(UserHandle.USER_SYSTEM)
- withContext(backgroundDispatcher) { manager.removeUser(currentUser.id) }
+ withContext(backgroundDispatcher) {
+ manager.removeUserWhenPossible(
+ UserHandle.of(currentUser.id),
+ /* overrideDevicePolicy= */ false
+ )
+ }
try {
WindowManagerGlobal.getWindowManagerService().lockNow(/* options= */ null)
} catch (e: RemoteException) {
@@ -222,13 +227,21 @@
switchUser(newGuestId)
- withContext(backgroundDispatcher) { manager.removeUser(currentUser.id) }
+ withContext(backgroundDispatcher) {
+ manager.removeUserWhenPossible(
+ UserHandle.of(currentUser.id),
+ /* overrideDevicePolicy= */ false
+ )
+ }
} else {
if (repository.isGuestUserAutoCreated) {
repository.isGuestUserResetting = true
}
switchUser(targetUserId)
- manager.removeUser(currentUser.id)
+ manager.removeUserWhenPossible(
+ UserHandle.of(currentUser.id),
+ /* overrideDevicePolicy= */ false
+ )
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/user/ui/binder/UserSwitcherViewBinder.kt b/packages/SystemUI/src/com/android/systemui/user/ui/binder/UserSwitcherViewBinder.kt
index 968af59..ad09ee3 100644
--- a/packages/SystemUI/src/com/android/systemui/user/ui/binder/UserSwitcherViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/user/ui/binder/UserSwitcherViewBinder.kt
@@ -61,14 +61,15 @@
falsingCollector: FalsingCollector,
onFinish: () -> Unit,
) {
- val rootView: UserSwitcherRootView = view.requireViewById(R.id.user_switcher_root)
- val flowWidget: FlowWidget = view.requireViewById(R.id.flow)
+ val gridContainerView: UserSwitcherRootView =
+ view.requireViewById(R.id.user_switcher_grid_container)
+ val flowWidget: FlowWidget = gridContainerView.requireViewById(R.id.flow)
val addButton: View = view.requireViewById(R.id.add)
val cancelButton: View = view.requireViewById(R.id.cancel)
val popupMenuAdapter = MenuAdapter(layoutInflater)
var popupMenu: UserSwitcherPopupMenu? = null
- rootView.touchHandler =
+ gridContainerView.touchHandler =
object : Gefingerpoken {
override fun onTouchEvent(ev: MotionEvent?): Boolean {
falsingCollector.onTouchEvent(ev)
@@ -134,7 +135,7 @@
val viewPool =
view.children.filter { it.tag == USER_VIEW_TAG }.toMutableList()
viewPool.forEach {
- view.removeView(it)
+ gridContainerView.removeView(it)
flowWidget.removeView(it)
}
users.forEach { userViewModel ->
@@ -152,7 +153,7 @@
inflatedView
}
userView.id = View.generateViewId()
- view.addView(userView)
+ gridContainerView.addView(userView)
flowWidget.addView(userView)
UserViewBinder.bind(
view = userView,
diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java b/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java
index 44f6d03..ad97ef4 100644
--- a/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java
+++ b/packages/SystemUI/src/com/android/systemui/wallpapers/ImageWallpaper.java
@@ -31,6 +31,7 @@
import android.os.HandlerThread;
import android.os.SystemClock;
import android.os.Trace;
+import android.os.UserHandle;
import android.service.wallpaper.WallpaperService;
import android.util.ArraySet;
import android.util.Log;
@@ -598,7 +599,6 @@
getDisplayContext().getSystemService(DisplayManager.class)
.unregisterDisplayListener(this);
mWallpaperLocalColorExtractor.cleanUp();
- unloadBitmap();
}
@Override
@@ -676,9 +676,14 @@
void drawFrameOnCanvas(Bitmap bitmap) {
Trace.beginSection("ImageWallpaper.CanvasEngine#drawFrame");
Surface surface = mSurfaceHolder.getSurface();
- Canvas canvas = mWideColorGamut
- ? surface.lockHardwareWideColorGamutCanvas()
- : surface.lockHardwareCanvas();
+ Canvas canvas = null;
+ try {
+ canvas = mWideColorGamut
+ ? surface.lockHardwareWideColorGamutCanvas()
+ : surface.lockHardwareCanvas();
+ } catch (IllegalStateException e) {
+ Log.w(TAG, "Unable to lock canvas", e);
+ }
if (canvas != null) {
Rect dest = mSurfaceHolder.getSurfaceFrame();
try {
@@ -709,17 +714,6 @@
}
}
- private void unloadBitmap() {
- mBackgroundExecutor.execute(this::unloadBitmapSynchronized);
- }
-
- private void unloadBitmapSynchronized() {
- synchronized (mLock) {
- mBitmapUsages = 0;
- unloadBitmapInternal();
- }
- }
-
private void unloadBitmapInternal() {
Trace.beginSection("ImageWallpaper.CanvasEngine#unloadBitmap");
if (mBitmap != null) {
@@ -738,7 +732,7 @@
boolean loadSuccess = false;
Bitmap bitmap;
try {
- bitmap = mWallpaperManager.getBitmap(false);
+ bitmap = mWallpaperManager.getBitmapAsUser(UserHandle.USER_CURRENT, false);
if (bitmap != null
&& bitmap.getByteCount() > RecordingCanvas.MAX_BITMAP_SIZE) {
throw new RuntimeException("Wallpaper is too large to draw!");
@@ -757,7 +751,7 @@
}
try {
- bitmap = mWallpaperManager.getBitmap(false);
+ bitmap = mWallpaperManager.getBitmapAsUser(UserHandle.USER_CURRENT, false);
} catch (RuntimeException | OutOfMemoryError e) {
Log.w(TAG, "Unable to load default wallpaper!", e);
bitmap = null;
@@ -770,9 +764,6 @@
Log.e(TAG, "Attempt to load a recycled bitmap");
} else if (mBitmap == bitmap) {
Log.e(TAG, "Loaded a bitmap that was already loaded");
- } else if (bitmap.getWidth() < 1 || bitmap.getHeight() < 1) {
- Log.e(TAG, "Attempt to load an invalid wallpaper of length "
- + bitmap.getWidth() + "x" + bitmap.getHeight());
} else {
// at this point, loading is done correctly.
loadSuccess = true;
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt
index 1c3656d..52b6b38 100644
--- a/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/keyguard/ClockEventControllerTest.kt
@@ -65,7 +65,6 @@
class ClockEventControllerTest : SysuiTestCase() {
@JvmField @Rule val mockito = MockitoJUnit.rule()
- @Mock private lateinit var keyguardInteractor: KeyguardInteractor
@Mock private lateinit var broadcastDispatcher: BroadcastDispatcher
@Mock private lateinit var batteryController: BatteryController
@Mock private lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java
index ac4dd49..89c5e59 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java
@@ -1680,6 +1680,15 @@
inOrder.verify(mNotificationStackScrollLayoutController).onExpansionStopped();
}
+ @Test
+ public void inUnlockedSplitShade_transitioningMaxTransitionDistance_makesShadeFullyExpanded() {
+ mStatusBarStateController.setState(SHADE);
+ enableSplitShade(true);
+ int transitionDistance = mNotificationPanelViewController.getMaxPanelTransitionDistance();
+ mNotificationPanelViewController.setExpandedHeight(transitionDistance);
+ assertThat(mNotificationPanelViewController.isFullyExpanded()).isTrue();
+ }
+
private static MotionEvent createMotionEvent(int x, int y, int action) {
return MotionEvent.obtain(
/* downTime= */ 0, /* eventTime= */ 0, action, x, y, /* metaState= */ 0);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplingInstanceTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplerTest.kt
similarity index 64%
rename from packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplingInstanceTest.kt
rename to packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplerTest.kt
index 09d51f6..5a62cc1 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplingInstanceTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplerTest.kt
@@ -21,61 +21,55 @@
@RunWith(AndroidTestingRunner::class)
@SmallTest
-class RegionSamplingInstanceTest : SysuiTestCase() {
+class RegionSamplerTest : SysuiTestCase() {
- @JvmField @Rule
- val mockito = MockitoJUnit.rule()
+ @JvmField @Rule val mockito = MockitoJUnit.rule()
@Mock private lateinit var sampledView: View
@Mock private lateinit var mainExecutor: Executor
@Mock private lateinit var bgExecutor: Executor
@Mock private lateinit var regionSampler: RegionSamplingHelper
- @Mock private lateinit var updateFun: RegionSamplingInstance.UpdateColorCallback
@Mock private lateinit var pw: PrintWriter
@Mock private lateinit var callback: RegionSamplingHelper.SamplingCallback
- private lateinit var regionSamplingInstance: RegionSamplingInstance
+ private lateinit var mRegionSampler: RegionSampler
+ private var updateFun: UpdateColorCallback = {}
@Before
fun setUp() {
whenever(sampledView.isAttachedToWindow).thenReturn(true)
- whenever(regionSampler.callback).thenReturn(this@RegionSamplingInstanceTest.callback)
+ whenever(regionSampler.callback).thenReturn(this@RegionSamplerTest.callback)
- regionSamplingInstance = object : RegionSamplingInstance(
- sampledView,
- mainExecutor,
- bgExecutor,
- true,
- updateFun
- ) {
- override fun createRegionSamplingHelper(
+ mRegionSampler =
+ object : RegionSampler(sampledView, mainExecutor, bgExecutor, true, updateFun) {
+ override fun createRegionSamplingHelper(
sampledView: View,
callback: RegionSamplingHelper.SamplingCallback,
mainExecutor: Executor?,
bgExecutor: Executor?
- ): RegionSamplingHelper {
- return this@RegionSamplingInstanceTest.regionSampler
+ ): RegionSamplingHelper {
+ return this@RegionSamplerTest.regionSampler
+ }
}
- }
}
@Test
fun testStartRegionSampler() {
- regionSamplingInstance.startRegionSampler()
+ mRegionSampler.startRegionSampler()
verify(regionSampler).start(Rect(0, 0, 0, 0))
}
@Test
fun testStopRegionSampler() {
- regionSamplingInstance.stopRegionSampler()
+ mRegionSampler.stopRegionSampler()
verify(regionSampler).stop()
}
@Test
fun testDump() {
- regionSamplingInstance.dump(pw)
+ mRegionSampler.dump(pw)
verify(regionSampler).dump(pw)
}
@@ -91,23 +85,18 @@
@Test
fun testFlagFalse() {
- regionSamplingInstance = object : RegionSamplingInstance(
- sampledView,
- mainExecutor,
- bgExecutor,
- false,
- updateFun
- ) {
- override fun createRegionSamplingHelper(
+ mRegionSampler =
+ object : RegionSampler(sampledView, mainExecutor, bgExecutor, false, updateFun) {
+ override fun createRegionSamplingHelper(
sampledView: View,
callback: RegionSamplingHelper.SamplingCallback,
mainExecutor: Executor?,
bgExecutor: Executor?
- ): RegionSamplingHelper {
- return this@RegionSamplingInstanceTest.regionSampler
+ ): RegionSamplingHelper {
+ return this@RegionSamplerTest.regionSampler
+ }
}
- }
- Assert.assertEquals(regionSamplingInstance.regionSampler, null)
+ Assert.assertEquals(mRegionSampler.regionSampler, null)
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDifferTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDifferTest.java
deleted file mode 100644
index ab71264..0000000
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDifferTest.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * 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.statusbar.notification.collection.render;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import android.content.Context;
-import android.testing.AndroidTestingRunner;
-import android.view.View;
-import android.widget.FrameLayout;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.test.filters.SmallTest;
-
-import com.android.systemui.SysuiTestCase;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-import java.util.List;
-
-@SmallTest
-@RunWith(AndroidTestingRunner.class)
-public class ShadeViewDifferTest extends SysuiTestCase {
- private ShadeViewDiffer mDiffer;
-
- private FakeController mRootController = new FakeController(mContext, "RootController");
- private FakeController mController1 = new FakeController(mContext, "Controller1");
- private FakeController mController2 = new FakeController(mContext, "Controller2");
- private FakeController mController3 = new FakeController(mContext, "Controller3");
- private FakeController mController4 = new FakeController(mContext, "Controller4");
- private FakeController mController5 = new FakeController(mContext, "Controller5");
- private FakeController mController6 = new FakeController(mContext, "Controller6");
- private FakeController mController7 = new FakeController(mContext, "Controller7");
-
- @Mock
- ShadeViewDifferLogger mLogger;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- mDiffer = new ShadeViewDiffer(mRootController, mLogger);
- }
-
- @Test
- public void testAddInitialViews() {
- // WHEN a spec is applied to an empty root
- // THEN the final tree matches the spec
- applySpecAndCheck(
- node(mController1),
- node(mController2,
- node(mController3),
- node(mController4)
- ),
- node(mController5)
- );
- }
-
- @Test
- public void testDetachViews() {
- // GIVEN a preexisting tree of controllers
- applySpecAndCheck(
- node(mController1),
- node(mController2,
- node(mController3),
- node(mController4)
- ),
- node(mController5)
- );
-
- // WHEN the new spec removes nodes
- // THEN the final tree matches the spec
- applySpecAndCheck(
- node(mController5)
- );
- }
-
- @Test
- public void testReparentChildren() {
- // GIVEN a preexisting tree of controllers
- applySpecAndCheck(
- node(mController1),
- node(mController2,
- node(mController3),
- node(mController4)
- ),
- node(mController5)
- );
-
- // WHEN the parents of the controllers are all shuffled around
- // THEN the final tree matches the spec
- applySpecAndCheck(
- node(mController1),
- node(mController4),
- node(mController3,
- node(mController2)
- )
- );
- }
-
- @Test
- public void testReorderChildren() {
- // GIVEN a preexisting tree of controllers
- applySpecAndCheck(
- node(mController1),
- node(mController2),
- node(mController3),
- node(mController4)
- );
-
- // WHEN the children change order
- // THEN the final tree matches the spec
- applySpecAndCheck(
- node(mController3),
- node(mController2),
- node(mController4),
- node(mController1)
- );
- }
-
- @Test
- public void testRemovedGroupsAreBrokenApart() {
- // GIVEN a preexisting tree with a group
- applySpecAndCheck(
- node(mController1),
- node(mController2,
- node(mController3),
- node(mController4),
- node(mController5)
- )
- );
-
- // WHEN the new spec removes the entire group
- applySpecAndCheck(
- node(mController1)
- );
-
- // THEN the group children are no longer attached to their parent
- assertNull(mController3.getView().getParent());
- assertNull(mController4.getView().getParent());
- assertNull(mController5.getView().getParent());
- }
-
- @Test
- public void testUnmanagedViews() {
- // GIVEN a preexisting tree of controllers
- applySpecAndCheck(
- node(mController1),
- node(mController2,
- node(mController3),
- node(mController4)
- ),
- node(mController5)
- );
-
- // GIVEN some additional unmanaged views attached to the tree
- View unmanagedView1 = new View(mContext);
- View unmanagedView2 = new View(mContext);
-
- mRootController.getView().addView(unmanagedView1, 1);
- mController2.getView().addView(unmanagedView2, 0);
-
- // WHEN a new spec is applied with additional nodes
- // THEN the final tree matches the spec
- applySpecAndCheck(
- node(mController1),
- node(mController2,
- node(mController3),
- node(mController4),
- node(mController6)
- ),
- node(mController5),
- node(mController7)
- );
-
- // THEN the unmanaged views have been pushed to the end of their parents
- assertEquals(unmanagedView1, mRootController.view.getChildAt(4));
- assertEquals(unmanagedView2, mController2.view.getChildAt(3));
- }
-
- private void applySpecAndCheck(NodeSpec spec) {
- mDiffer.applySpec(spec);
- checkMatchesSpec(spec);
- }
-
- private void applySpecAndCheck(SpecBuilder... children) {
- applySpecAndCheck(node(mRootController, children).build());
- }
-
- private void checkMatchesSpec(NodeSpec spec) {
- final NodeController parent = spec.getController();
- final List<NodeSpec> children = spec.getChildren();
-
- for (int i = 0; i < children.size(); i++) {
- NodeSpec childSpec = children.get(i);
- View view = parent.getChildAt(i);
-
- assertEquals(
- "Child " + i + " of parent " + parent.getNodeLabel() + " should be "
- + childSpec.getController().getNodeLabel() + " but is instead "
- + (view != null ? mDiffer.getViewLabel(view) : "null"),
- view,
- childSpec.getController().getView());
-
- if (!childSpec.getChildren().isEmpty()) {
- checkMatchesSpec(childSpec);
- }
- }
- }
-
- private static class FakeController implements NodeController {
-
- public final FrameLayout view;
- private final String mLabel;
-
- FakeController(Context context, String label) {
- view = new FrameLayout(context);
- mLabel = label;
- }
-
- @NonNull
- @Override
- public String getNodeLabel() {
- return mLabel;
- }
-
- @NonNull
- @Override
- public FrameLayout getView() {
- return view;
- }
-
- @Override
- public int getChildCount() {
- return view.getChildCount();
- }
-
- @Override
- public View getChildAt(int index) {
- return view.getChildAt(index);
- }
-
- @Override
- public void addChildAt(@NonNull NodeController child, int index) {
- view.addView(child.getView(), index);
- }
-
- @Override
- public void moveChildTo(@NonNull NodeController child, int index) {
- view.removeView(child.getView());
- view.addView(child.getView(), index);
- }
-
- @Override
- public void removeChild(@NonNull NodeController child, boolean isTransfer) {
- view.removeView(child.getView());
- }
-
- @Override
- public void onViewAdded() {
- }
-
- @Override
- public void onViewMoved() {
- }
-
- @Override
- public void onViewRemoved() {
- }
- }
-
- private static class SpecBuilder {
- private final NodeController mController;
- private final SpecBuilder[] mChildren;
-
- SpecBuilder(NodeController controller, SpecBuilder... children) {
- mController = controller;
- mChildren = children;
- }
-
- public NodeSpec build() {
- return build(null);
- }
-
- public NodeSpec build(@Nullable NodeSpec parent) {
- final NodeSpecImpl spec = new NodeSpecImpl(parent, mController);
- for (SpecBuilder childBuilder : mChildren) {
- spec.getChildren().add(childBuilder.build(spec));
- }
- return spec;
- }
- }
-
- private static SpecBuilder node(NodeController controller, SpecBuilder... children) {
- return new SpecBuilder(controller, children);
- }
-}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDifferTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDifferTest.kt
new file mode 100644
index 0000000..15cf17d
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDifferTest.kt
@@ -0,0 +1,234 @@
+/*
+ * 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.statusbar.notification.collection.render
+
+import android.content.Context
+import android.testing.AndroidTestingRunner
+import android.view.View
+import android.widget.FrameLayout
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.util.mockito.mock
+import org.junit.Assert
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@SmallTest
+@RunWith(AndroidTestingRunner::class)
+class ShadeViewDifferTest : SysuiTestCase() {
+ private lateinit var differ: ShadeViewDiffer
+ private val rootController = FakeController(mContext, "RootController")
+ private val controller1 = FakeController(mContext, "Controller1")
+ private val controller2 = FakeController(mContext, "Controller2")
+ private val controller3 = FakeController(mContext, "Controller3")
+ private val controller4 = FakeController(mContext, "Controller4")
+ private val controller5 = FakeController(mContext, "Controller5")
+ private val controller6 = FakeController(mContext, "Controller6")
+ private val controller7 = FakeController(mContext, "Controller7")
+ private val logger: ShadeViewDifferLogger = mock()
+
+ @Before
+ fun setUp() {
+ differ = ShadeViewDiffer(rootController, logger)
+ }
+
+ @Test
+ fun testAddInitialViews() {
+ // WHEN a spec is applied to an empty root
+ // THEN the final tree matches the spec
+ applySpecAndCheck(
+ node(controller1),
+ node(controller2, node(controller3), node(controller4)),
+ node(controller5)
+ )
+ }
+
+ @Test
+ fun testDetachViews() {
+ // GIVEN a preexisting tree of controllers
+ applySpecAndCheck(
+ node(controller1),
+ node(controller2, node(controller3), node(controller4)),
+ node(controller5)
+ )
+
+ // WHEN the new spec removes nodes
+ // THEN the final tree matches the spec
+ applySpecAndCheck(node(controller5))
+ }
+
+ @Test
+ fun testReparentChildren() {
+ // GIVEN a preexisting tree of controllers
+ applySpecAndCheck(
+ node(controller1),
+ node(controller2, node(controller3), node(controller4)),
+ node(controller5)
+ )
+
+ // WHEN the parents of the controllers are all shuffled around
+ // THEN the final tree matches the spec
+ applySpecAndCheck(
+ node(controller1),
+ node(controller4),
+ node(controller3, node(controller2))
+ )
+ }
+
+ @Test
+ fun testReorderChildren() {
+ // GIVEN a preexisting tree of controllers
+ applySpecAndCheck(
+ node(controller1),
+ node(controller2),
+ node(controller3),
+ node(controller4)
+ )
+
+ // WHEN the children change order
+ // THEN the final tree matches the spec
+ applySpecAndCheck(
+ node(controller3),
+ node(controller2),
+ node(controller4),
+ node(controller1)
+ )
+ }
+
+ @Test
+ fun testRemovedGroupsAreBrokenApart() {
+ // GIVEN a preexisting tree with a group
+ applySpecAndCheck(
+ node(controller1),
+ node(controller2, node(controller3), node(controller4), node(controller5))
+ )
+
+ // WHEN the new spec removes the entire group
+ applySpecAndCheck(node(controller1))
+
+ // THEN the group children are no longer attached to their parent
+ Assert.assertNull(controller3.view.parent)
+ Assert.assertNull(controller4.view.parent)
+ Assert.assertNull(controller5.view.parent)
+ }
+
+ @Test
+ fun testUnmanagedViews() {
+ // GIVEN a preexisting tree of controllers
+ applySpecAndCheck(
+ node(controller1),
+ node(controller2, node(controller3), node(controller4)),
+ node(controller5)
+ )
+
+ // GIVEN some additional unmanaged views attached to the tree
+ val unmanagedView1 = View(mContext)
+ val unmanagedView2 = View(mContext)
+ rootController.view.addView(unmanagedView1, 1)
+ controller2.view.addView(unmanagedView2, 0)
+
+ // WHEN a new spec is applied with additional nodes
+ // THEN the final tree matches the spec
+ applySpecAndCheck(
+ node(controller1),
+ node(controller2, node(controller3), node(controller4), node(controller6)),
+ node(controller5),
+ node(controller7)
+ )
+
+ // THEN the unmanaged views have been pushed to the end of their parents
+ Assert.assertEquals(unmanagedView1, rootController.view.getChildAt(4))
+ Assert.assertEquals(unmanagedView2, controller2.view.getChildAt(3))
+ }
+
+ private fun applySpecAndCheck(spec: NodeSpec) {
+ differ.applySpec(spec)
+ checkMatchesSpec(spec)
+ }
+
+ private fun applySpecAndCheck(vararg children: SpecBuilder) {
+ applySpecAndCheck(node(rootController, *children).build())
+ }
+
+ private fun checkMatchesSpec(spec: NodeSpec) {
+ val parent = spec.controller
+ val children = spec.children
+ for (i in children.indices) {
+ val childSpec = children[i]
+ val view = parent.getChildAt(i)
+ Assert.assertEquals(
+ "Child $i of parent ${parent.nodeLabel} " +
+ "should be ${childSpec.controller.nodeLabel} " +
+ "but instead " +
+ view?.let(differ::getViewLabel),
+ view,
+ childSpec.controller.view
+ )
+ if (childSpec.children.isNotEmpty()) {
+ checkMatchesSpec(childSpec)
+ }
+ }
+ }
+
+ private class FakeController(context: Context, label: String) : NodeController {
+ override val view: FrameLayout = FrameLayout(context)
+ override val nodeLabel: String = label
+ override fun getChildCount(): Int = view.childCount
+
+ override fun getChildAt(index: Int): View? {
+ return view.getChildAt(index)
+ }
+
+ override fun addChildAt(child: NodeController, index: Int) {
+ view.addView(child.view, index)
+ }
+
+ override fun moveChildTo(child: NodeController, index: Int) {
+ view.removeView(child.view)
+ view.addView(child.view, index)
+ }
+
+ override fun removeChild(child: NodeController, isTransfer: Boolean) {
+ view.removeView(child.view)
+ }
+
+ override fun onViewAdded() {}
+ override fun onViewMoved() {}
+ override fun onViewRemoved() {}
+ }
+
+ private class SpecBuilder(
+ private val mController: NodeController,
+ private val children: Array<out SpecBuilder>
+ ) {
+
+ @JvmOverloads
+ fun build(parent: NodeSpec? = null): NodeSpec {
+ val spec = NodeSpecImpl(parent, mController)
+ for (childBuilder in children) {
+ spec.children.add(childBuilder.build(spec))
+ }
+ return spec
+ }
+ }
+
+ companion object {
+ private fun node(controller: NodeController, vararg children: SpecBuilder): SpecBuilder {
+ return SpecBuilder(controller, children)
+ }
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/GuestUserInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/GuestUserInteractorTest.kt
index 120bf79..e496521 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/GuestUserInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/user/domain/interactor/GuestUserInteractorTest.kt
@@ -219,6 +219,7 @@
repository.setUserInfos(listOf(NON_GUEST_USER_INFO, EPHEMERAL_GUEST_USER_INFO))
repository.setSelectedUserInfo(EPHEMERAL_GUEST_USER_INFO)
val targetUserId = NON_GUEST_USER_INFO.id
+ val ephemeralGuestUserHandle = UserHandle.of(EPHEMERAL_GUEST_USER_INFO.id)
underTest.exit(
guestUserId = GUEST_USER_INFO.id,
@@ -230,7 +231,7 @@
)
verify(manager).markGuestForDeletion(EPHEMERAL_GUEST_USER_INFO.id)
- verify(manager).removeUser(EPHEMERAL_GUEST_USER_INFO.id)
+ verify(manager).removeUserWhenPossible(ephemeralGuestUserHandle, false)
verify(switchUser).invoke(targetUserId)
}
@@ -240,6 +241,7 @@
whenever(manager.markGuestForDeletion(anyInt())).thenReturn(true)
repository.setSelectedUserInfo(GUEST_USER_INFO)
val targetUserId = NON_GUEST_USER_INFO.id
+ val guestUserHandle = UserHandle.of(GUEST_USER_INFO.id)
underTest.exit(
guestUserId = GUEST_USER_INFO.id,
@@ -251,7 +253,7 @@
)
verify(manager).markGuestForDeletion(GUEST_USER_INFO.id)
- verify(manager).removeUser(GUEST_USER_INFO.id)
+ verify(manager).removeUserWhenPossible(guestUserHandle, false)
verify(switchUser).invoke(targetUserId)
}
@@ -296,6 +298,7 @@
repository.setSelectedUserInfo(GUEST_USER_INFO)
val targetUserId = NON_GUEST_USER_INFO.id
+ val guestUserHandle = UserHandle.of(GUEST_USER_INFO.id)
underTest.remove(
guestUserId = GUEST_USER_INFO.id,
targetUserId = targetUserId,
@@ -305,7 +308,7 @@
)
verify(manager).markGuestForDeletion(GUEST_USER_INFO.id)
- verify(manager).removeUser(GUEST_USER_INFO.id)
+ verify(manager).removeUserWhenPossible(guestUserHandle, false)
verify(switchUser).invoke(targetUserId)
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java
index c254358..379bb28 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/ImageWallpaperTest.java
@@ -26,8 +26,8 @@
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -44,6 +44,7 @@
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManagerGlobal;
import android.os.Handler;
+import android.os.UserHandle;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.Display;
@@ -135,9 +136,10 @@
when(mWallpaperBitmap.getHeight()).thenReturn(mBitmapHeight);
// set up wallpaper manager
- when(mWallpaperManager.peekBitmapDimensions()).thenReturn(
- new Rect(0, 0, mBitmapWidth, mBitmapHeight));
- when(mWallpaperManager.getBitmap(false)).thenReturn(mWallpaperBitmap);
+ when(mWallpaperManager.peekBitmapDimensions())
+ .thenReturn(new Rect(0, 0, mBitmapWidth, mBitmapHeight));
+ when(mWallpaperManager.getBitmapAsUser(eq(UserHandle.USER_CURRENT), anyBoolean()))
+ .thenReturn(mWallpaperBitmap);
when(mMockContext.getSystemService(WallpaperManager.class)).thenReturn(mWallpaperManager);
// set up surface
@@ -286,9 +288,6 @@
testMinSurfaceHelper(8, 8);
testMinSurfaceHelper(100, 2000);
testMinSurfaceHelper(200, 1);
- testMinSurfaceHelper(0, 1);
- testMinSurfaceHelper(1, 0);
- testMinSurfaceHelper(0, 0);
}
private void testMinSurfaceHelper(int bitmapWidth, int bitmapHeight) {
@@ -307,28 +306,6 @@
}
@Test
- public void testZeroBitmap() {
- // test that a frame is never drawn with a 0 bitmap
- testZeroBitmapHelper(0, 1);
- testZeroBitmapHelper(1, 0);
- testZeroBitmapHelper(0, 0);
- }
-
- private void testZeroBitmapHelper(int bitmapWidth, int bitmapHeight) {
-
- clearInvocations(mSurfaceHolder);
- setBitmapDimensions(bitmapWidth, bitmapHeight);
-
- ImageWallpaper imageWallpaper = createImageWallpaperCanvas();
- ImageWallpaper.CanvasEngine engine =
- (ImageWallpaper.CanvasEngine) imageWallpaper.onCreateEngine();
- ImageWallpaper.CanvasEngine spyEngine = spy(engine);
- spyEngine.onCreate(mSurfaceHolder);
- spyEngine.onSurfaceRedrawNeeded(mSurfaceHolder);
- verify(spyEngine, never()).drawFrameOnCanvas(any());
- }
-
- @Test
public void testLoadDrawAndUnloadBitmap() {
setBitmapDimensions(LOW_BMP_WIDTH, LOW_BMP_HEIGHT);
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index f865b8a..c954957 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -470,6 +470,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiFunction;
public class ActivityManagerService extends IActivityManager.Stub
@@ -3457,13 +3458,13 @@
}
/**
- * @param firstPidOffsets Optional, when it's set, it receives the start/end offset
+ * @param firstPidEndOffset Optional, when it's set, it receives the start/end offset
* of the very first pid to be dumped.
*/
/* package */ static File dumpStackTraces(ArrayList<Integer> firstPids,
ProcessCpuTracker processCpuTracker, SparseArray<Boolean> lastPids,
ArrayList<Integer> nativePids, StringWriter logExceptionCreatingFile,
- long[] firstPidOffsets, String subject, String criticalEventSection,
+ AtomicLong firstPidEndOffset, String subject, String criticalEventSection,
AnrLatencyTracker latencyTracker) {
try {
if (latencyTracker != null) {
@@ -3536,15 +3537,10 @@
+ (criticalEventSection != null ? criticalEventSection : ""));
}
- Pair<Long, Long> offsets = dumpStackTraces(
+ long firstPidEndPos = dumpStackTraces(
tracesFile.getAbsolutePath(), firstPids, nativePids, extraPids, latencyTracker);
- if (firstPidOffsets != null) {
- if (offsets == null) {
- firstPidOffsets[0] = firstPidOffsets[1] = -1;
- } else {
- firstPidOffsets[0] = offsets.first; // Start offset to the ANR trace file
- firstPidOffsets[1] = offsets.second; // End offset to the ANR trace file
- }
+ if (firstPidEndOffset != null) {
+ firstPidEndOffset.set(firstPidEndPos);
}
return tracesFile;
@@ -3663,9 +3659,9 @@
/**
- * @return The start/end offset of the trace of the very first PID
+ * @return The end offset of the trace of the very first PID
*/
- public static Pair<Long, Long> dumpStackTraces(String tracesFile,
+ public static long dumpStackTraces(String tracesFile,
ArrayList<Integer> firstPids, ArrayList<Integer> nativePids,
ArrayList<Integer> extraPids, AnrLatencyTracker latencyTracker) {
@@ -3681,7 +3677,6 @@
// As applications are usually interested with the ANR stack traces, but we can't share with
// them the stack traces other than their own stacks. So after the very first PID is
// dumped, remember the current file size.
- long firstPidStart = -1;
long firstPidEnd = -1;
// First collect all of the stacks of the most important pids.
@@ -3694,11 +3689,6 @@
final int pid = firstPids.get(i);
// We don't copy ANR traces from the system_server intentionally.
final boolean firstPid = i == 0 && MY_PID != pid;
- File tf = null;
- if (firstPid) {
- tf = new File(tracesFile);
- firstPidStart = tf.exists() ? tf.length() : 0;
- }
if (latencyTracker != null) {
latencyTracker.dumpingPidStarted(pid);
}
@@ -3714,11 +3704,11 @@
if (remainingTime <= 0) {
Slog.e(TAG, "Aborting stack trace dump (current firstPid=" + pid
+ "); deadline exceeded.");
- return firstPidStart >= 0 ? new Pair<>(firstPidStart, firstPidEnd) : null;
+ return firstPidEnd;
}
if (firstPid) {
- firstPidEnd = tf.length();
+ firstPidEnd = new File(tracesFile).length();
// Full latency dump
if (latencyTracker != null) {
appendtoANRFile(tracesFile,
@@ -3757,7 +3747,7 @@
if (remainingTime <= 0) {
Slog.e(TAG, "Aborting stack trace dump (current native pid=" + pid +
"); deadline exceeded.");
- return firstPidStart >= 0 ? new Pair<>(firstPidStart, firstPidEnd) : null;
+ return firstPidEnd;
}
if (DEBUG_ANR) {
@@ -3787,7 +3777,7 @@
if (remainingTime <= 0) {
Slog.e(TAG, "Aborting stack trace dump (current extra pid=" + pid +
"); deadline exceeded.");
- return firstPidStart >= 0 ? new Pair<>(firstPidStart, firstPidEnd) : null;
+ return firstPidEnd;
}
if (DEBUG_ANR) {
@@ -3802,7 +3792,7 @@
appendtoANRFile(tracesFile, "----- dumping ended at " + SystemClock.uptimeMillis() + "\n");
Slog.i(TAG, "Done dumping");
- return firstPidStart >= 0 ? new Pair<>(firstPidStart, firstPidEnd) : null;
+ return firstPidEnd;
}
@Override
@@ -16773,7 +16763,6 @@
mAtmInternal.onUserStopped(userId);
// Clean up various services by removing the user
mBatteryStatsService.onUserRemoved(userId);
- mUserController.onUserRemoved(userId);
}
@Override
diff --git a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java
index e956fb0..95cefea 100644
--- a/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java
+++ b/services/core/java/com/android/server/am/BroadcastQueueModernImpl.java
@@ -404,21 +404,24 @@
queue.runningTraceTrackName = TAG + ".mRunning[" + queueIndex + "]";
queue.runningOomAdjusted = queue.isPendingManifest();
+ // If already warm, we can make OOM adjust request immediately;
+ // otherwise we need to wait until process becomes warm
+ if (processWarm) {
+ notifyStartedRunning(queue);
+ updateOomAdj |= queue.runningOomAdjusted;
+ }
+
// If we're already warm, schedule next pending broadcast now;
// otherwise we'll wait for the cold start to circle back around
queue.makeActiveNextPending();
if (processWarm) {
queue.traceProcessRunningBegin();
- notifyStartedRunning(queue);
scheduleReceiverWarmLocked(queue);
} else {
queue.traceProcessStartingBegin();
scheduleReceiverColdLocked(queue);
}
- // Only kick off an OOM adjustment pass if needed
- updateOomAdj |= queue.runningOomAdjusted;
-
// Move to considering next runnable queue
queue = nextQueue;
}
@@ -456,9 +459,13 @@
// now; dispatch its next broadcast and clear the slot
mRunningColdStart = null;
+ // Now that we're running warm, we can finally request that OOM
+ // adjust we've been waiting for
+ notifyStartedRunning(queue);
+ mService.updateOomAdjPendingTargetsLocked(OOM_ADJ_REASON_START_RECEIVER);
+
queue.traceProcessEnd();
queue.traceProcessRunningBegin();
- notifyStartedRunning(queue);
scheduleReceiverWarmLocked(queue);
// We might be willing to kick off another cold start
@@ -811,9 +818,9 @@
* ordered broadcast; assumes the sender is still a warm process.
*/
private void scheduleResultTo(@NonNull BroadcastRecord r) {
- if ((r.resultToApp == null) || (r.resultTo == null)) return;
+ if (r.resultTo == null) return;
final ProcessRecord app = r.resultToApp;
- final IApplicationThread thread = app.getOnewayThread();
+ final IApplicationThread thread = (app != null) ? app.getOnewayThread() : null;
if (thread != null) {
mService.mOomAdjuster.mCachedAppOptimizer.unfreezeTemporarily(
app, OOM_ADJ_REASON_FINISH_RECEIVER);
diff --git a/services/core/java/com/android/server/am/PendingIntentRecord.java b/services/core/java/com/android/server/am/PendingIntentRecord.java
index 740efbc..14a1697 100644
--- a/services/core/java/com/android/server/am/PendingIntentRecord.java
+++ b/services/core/java/com/android/server/am/PendingIntentRecord.java
@@ -490,6 +490,11 @@
final IApplicationThread finishedReceiverThread = caller;
boolean sendFinish = finishedReceiver != null;
+ if ((finishedReceiver != null) && (finishedReceiverThread == null)) {
+ Slog.w(TAG, "Sending of " + intent + " from " + Binder.getCallingUid()
+ + " requested resultTo without an IApplicationThread!", new Throwable());
+ }
+
int userId = key.userId;
if (userId == UserHandle.USER_CURRENT) {
userId = controller.mUserController.getCurrentOrTargetUserId();
diff --git a/services/core/java/com/android/server/am/ProcessErrorStateRecord.java b/services/core/java/com/android/server/am/ProcessErrorStateRecord.java
index 71d39964..f461f3d 100644
--- a/services/core/java/com/android/server/am/ProcessErrorStateRecord.java
+++ b/services/core/java/com/android/server/am/ProcessErrorStateRecord.java
@@ -62,6 +62,8 @@
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.UUID;
+import java.util.concurrent.atomic.AtomicLong;
+
/**
* The error state of the process, such as if it's crashing/ANR etc.
*/
@@ -458,10 +460,10 @@
// avoid spending 1/2 second collecting stats to rank lastPids.
StringWriter tracesFileException = new StringWriter();
// To hold the start and end offset to the ANR trace file respectively.
- final long[] offsets = new long[2];
+ final AtomicLong firstPidEndOffset = new AtomicLong(-1);
File tracesFile = ActivityManagerService.dumpStackTraces(firstPids,
isSilentAnr ? null : processCpuTracker, isSilentAnr ? null : lastPids,
- nativePids, tracesFileException, offsets, annotation, criticalEventLog,
+ nativePids, tracesFileException, firstPidEndOffset, annotation, criticalEventLog,
latencyTracker);
if (isMonitorCpuUsage()) {
@@ -478,10 +480,14 @@
if (tracesFile == null) {
// There is no trace file, so dump (only) the alleged culprit's threads to the log
Process.sendSignal(pid, Process.SIGNAL_QUIT);
- } else if (offsets[1] > 0) {
+ } else if (firstPidEndOffset.get() > 0) {
// We've dumped into the trace file successfully
+ // We pass the start and end offsets of the first section of
+ // the ANR file (the headers and first process dump)
+ final long startOffset = 0L;
+ final long endOffset = firstPidEndOffset.get();
mService.mProcessList.mAppExitInfoTracker.scheduleLogAnrTrace(
- pid, mApp.uid, mApp.getPackageList(), tracesFile, offsets[0], offsets[1]);
+ pid, mApp.uid, mApp.getPackageList(), tracesFile, startOffset, endOffset);
}
// Check if package is still being loaded
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index dcc7a8e..82d239f 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -120,6 +120,7 @@
import com.android.server.SystemServiceManager;
import com.android.server.am.UserState.KeyEvictedCallback;
import com.android.server.pm.UserManagerInternal;
+import com.android.server.pm.UserManagerInternal.UserLifecycleListener;
import com.android.server.pm.UserManagerService;
import com.android.server.utils.Slogf;
import com.android.server.utils.TimingsTraceAndSlog;
@@ -320,8 +321,12 @@
@GuardedBy("mLock")
private int[] mStartedUserArray = new int[] { 0 };
- // If there are multiple profiles for the current user, their ids are here
- // Currently only the primary user can have managed profiles
+ /**
+ * Contains the current user and its profiles (if any).
+ *
+ * <p><b>NOTE: </b>it lists all profiles, regardless of their running state (i.e., they're in
+ * this list even if not running).
+ */
@GuardedBy("mLock")
private int[] mCurrentProfileIds = new int[] {};
@@ -436,6 +441,18 @@
@GuardedBy("mLock")
private final SparseBooleanArray mVisibleUsers = new SparseBooleanArray();
+ private final UserLifecycleListener mUserLifecycleListener = new UserLifecycleListener() {
+ @Override
+ public void onUserCreated(UserInfo user, Object token) {
+ onUserAdded(user);
+ }
+
+ @Override
+ public void onUserRemoved(UserInfo user) {
+ UserController.this.onUserRemoved(user.id);
+ }
+ };
+
UserController(ActivityManagerService service) {
this(new Injector(service));
}
@@ -1667,7 +1684,7 @@
userSwitchUiEnabled = mUserSwitchUiEnabled;
}
mInjector.updateUserConfiguration();
- updateCurrentProfileIds();
+ updateProfileRelatedCaches();
mInjector.getWindowManager().setCurrentUser(userId);
mInjector.reportCurWakefulnessUsageEvent();
// Once the internal notion of the active user has switched, we lock the device
@@ -1681,7 +1698,7 @@
}
} else {
final Integer currentUserIdInt = mCurrentUserId;
- updateCurrentProfileIds();
+ updateProfileRelatedCaches();
synchronized (mLock) {
mUserLru.remove(currentUserIdInt);
mUserLru.add(currentUserIdInt);
@@ -2526,7 +2543,8 @@
Slogf.d(TAG, "onSystemReady()");
}
- updateCurrentProfileIds();
+ mInjector.getUserManagerInternal().addUserLifecycleListener(mUserLifecycleListener);
+ updateProfileRelatedCaches();
mInjector.reportCurWakefulnessUsageEvent();
}
@@ -2551,13 +2569,13 @@
}
/**
- * Refreshes the list of users related to the current user when either a
- * user switch happens or when a new related user is started in the
- * background.
+ * Refreshes the internal caches related to user profiles.
+ *
+ * <p>It's called every time a user is started.
*/
- private void updateCurrentProfileIds() {
+ private void updateProfileRelatedCaches() {
final List<UserInfo> profiles = mInjector.getUserManager().getProfiles(getCurrentUserId(),
- false /* enabledOnly */);
+ /* enabledOnly= */ false);
int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null
for (int i = 0; i < currentProfileIds.length; i++) {
currentProfileIds[i] = profiles.get(i).id;
@@ -2824,6 +2842,18 @@
}
}
+ private void onUserAdded(UserInfo user) {
+ if (!user.isProfile()) {
+ return;
+ }
+ synchronized (mLock) {
+ if (user.profileGroupId == mCurrentUserId) {
+ mCurrentProfileIds = ArrayUtils.appendInt(mCurrentProfileIds, user.id);
+ }
+ mUserProfileGroupIds.put(user.id, user.profileGroupId);
+ }
+ }
+
void onUserRemoved(@UserIdInt int userId) {
synchronized (mLock) {
int size = mUserProfileGroupIds.size();
@@ -2938,6 +2968,10 @@
for (int i = 0; i < mVisibleUsers.size(); i++) {
proto.write(UserControllerProto.VISIBLE_USERS_ARRAY, mVisibleUsers.keyAt(i));
}
+ proto.write(UserControllerProto.CURRENT_USER, mCurrentUserId);
+ for (int i = 0; i < mCurrentProfileIds.length; i++) {
+ proto.write(UserControllerProto.CURRENT_PROFILES, mCurrentProfileIds[i]);
+ }
proto.end(token);
}
}
@@ -2975,6 +3009,7 @@
pw.println(mUserProfileGroupIds.valueAt(i));
}
}
+ pw.println(" mCurrentProfileIds:" + Arrays.toString(mCurrentProfileIds));
pw.println(" mCurrentUserId:" + mCurrentUserId);
pw.println(" mTargetUserId:" + mTargetUserId);
pw.println(" mLastActiveUsers:" + mLastActiveUsers);
diff --git a/services/core/java/com/android/server/display/DisplayDeviceConfig.java b/services/core/java/com/android/server/display/DisplayDeviceConfig.java
index a3b1a42..523a2dc 100644
--- a/services/core/java/com/android/server/display/DisplayDeviceConfig.java
+++ b/services/core/java/com/android/server/display/DisplayDeviceConfig.java
@@ -699,7 +699,6 @@
*/
public float getNitsFromBacklight(float backlight) {
if (mBacklightToNitsSpline == null) {
- Slog.wtf(TAG, "requesting nits when no mapping exists.");
return NITS_INVALID;
}
backlight = Math.max(backlight, mBacklightMinimum);
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 9cb8f43..0eaa5e4 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -144,6 +144,7 @@
import android.window.ImeOnBackInvokedDispatcher;
import com.android.internal.annotations.GuardedBy;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.content.PackageMonitor;
import com.android.internal.infra.AndroidFuture;
import com.android.internal.inputmethod.DirectBootAwareness;
@@ -1592,8 +1593,13 @@
private final InputMethodManagerService mService;
public Lifecycle(Context context) {
+ this(context, new InputMethodManagerService(context));
+ }
+
+ public Lifecycle(
+ Context context, @NonNull InputMethodManagerService inputMethodManagerService) {
super(context);
- mService = new InputMethodManagerService(context);
+ mService = inputMethodManagerService;
}
@Override
@@ -1668,12 +1674,25 @@
}
public InputMethodManagerService(Context context) {
+ this(context, null, null);
+ }
+
+ @VisibleForTesting
+ InputMethodManagerService(
+ Context context,
+ @Nullable ServiceThread serviceThreadForTesting,
+ @Nullable InputMethodBindingController bindingControllerForTesting) {
mContext = context;
mRes = context.getResources();
// TODO(b/196206770): Disallow I/O on this thread. Currently it's needed for loading
// additional subtypes in switchUserOnHandlerLocked().
- final ServiceThread thread = new ServiceThread(
- HANDLER_THREAD_NAME, Process.THREAD_PRIORITY_FOREGROUND, true /* allowIo */);
+ final ServiceThread thread =
+ serviceThreadForTesting != null
+ ? serviceThreadForTesting
+ : new ServiceThread(
+ HANDLER_THREAD_NAME,
+ Process.THREAD_PRIORITY_FOREGROUND,
+ true /* allowIo */);
thread.start();
mHandler = Handler.createAsync(thread.getLooper(), this);
// Note: SettingsObserver doesn't register observers in its constructor.
@@ -1701,10 +1720,13 @@
updateCurrentProfileIds();
AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, userId);
- mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked(
- mSettings, context);
+ mSwitchingController =
+ InputMethodSubtypeSwitchingController.createInstanceLocked(mSettings, context);
mMenuController = new InputMethodMenuController(this);
- mBindingController = new InputMethodBindingController(this);
+ mBindingController =
+ bindingControllerForTesting != null
+ ? bindingControllerForTesting
+ : new InputMethodBindingController(this);
mAutofillController = new AutofillSuggestionsController(this);
mPreventImeStartupUnlessTextEditor = mRes.getBoolean(
com.android.internal.R.bool.config_preventImeStartupUnlessTextEditor);
@@ -3673,6 +3695,7 @@
// UI for input.
if (isTextEditor && editorInfo != null
&& shouldRestoreImeVisibility(windowToken, softInputMode)) {
+ if (DEBUG) Slog.v(TAG, "Will show input to restore visibility");
res = startInputUncheckedLocked(cs, inputContext, remoteAccessibilityInputConnection,
editorInfo, startInputFlags, startInputReason, unverifiedTargetSdkVersion,
imeDispatcher);
@@ -3719,11 +3742,17 @@
imeDispatcher);
didStart = true;
}
- showCurrentInputLocked(windowToken, InputMethodManager.SHOW_IMPLICIT, null,
+ showCurrentInputLocked(
+ windowToken,
+ InputMethodManager.SHOW_IMPLICIT,
+ null,
SoftInputShowHideReason.SHOW_AUTO_EDITOR_FORWARD_NAV);
}
break;
case LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
+ if (DEBUG) {
+ Slog.v(TAG, "Window asks to keep the input in whatever state it was last in");
+ }
// Do nothing.
break;
case LayoutParams.SOFT_INPUT_STATE_HIDDEN:
@@ -3794,6 +3823,7 @@
// To maintain compatibility, we are now hiding the IME when we don't have
// an editor upon refocusing a window.
if (startInputByWinGainedFocus) {
+ if (DEBUG) Slog.v(TAG, "Same window without editor will hide input");
hideCurrentInputLocked(mCurFocusedWindow, 0, null,
SoftInputShowHideReason.HIDE_SAME_WINDOW_FOCUSED_WITHOUT_EDITOR);
}
@@ -3807,6 +3837,7 @@
// 1) SOFT_INPUT_STATE_UNCHANGED state without an editor
// 2) SOFT_INPUT_STATE_VISIBLE state without an editor
// 3) SOFT_INPUT_STATE_ALWAYS_VISIBLE state without an editor
+ if (DEBUG) Slog.v(TAG, "Window without editor will hide input");
hideCurrentInputLocked(mCurFocusedWindow, 0, null,
SoftInputShowHideReason.HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR);
}
diff --git a/services/core/java/com/android/server/pm/AppsFilterImpl.java b/services/core/java/com/android/server/pm/AppsFilterImpl.java
index 4c21195..e3a2fb2 100644
--- a/services/core/java/com/android/server/pm/AppsFilterImpl.java
+++ b/services/core/java/com/android/server/pm/AppsFilterImpl.java
@@ -22,6 +22,15 @@
import static android.provider.DeviceConfig.NAMESPACE_PACKAGE_MANAGER_SERVICE;
import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIVATE;
+import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_BUILD_REPORTED;
+import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_BUILD_REPORTED__EVENT_TYPE__BOOT;
+import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_BUILD_REPORTED__EVENT_TYPE__USER_CREATED;
+import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_BUILD_REPORTED__EVENT_TYPE__USER_DELETED;
+import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED;
+import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED__EVENT_TYPE__COMPAT_CHANGED;
+import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED__EVENT_TYPE__PACKAGE_ADDED;
+import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED__EVENT_TYPE__PACKAGE_DELETED;
+import static com.android.internal.util.FrameworkStatsLog.PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED__EVENT_TYPE__PACKAGE_REPLACED;
import static com.android.server.pm.AppsFilterUtils.canQueryAsInstaller;
import static com.android.server.pm.AppsFilterUtils.canQueryViaComponents;
import static com.android.server.pm.AppsFilterUtils.canQueryViaPackage;
@@ -36,6 +45,7 @@
import android.content.pm.SigningDetails;
import android.content.pm.UserInfo;
import android.os.Handler;
+import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
@@ -49,6 +59,7 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
+import com.android.internal.util.FrameworkStatsLog;
import com.android.server.FgThread;
import com.android.server.compat.CompatChange;
import com.android.server.om.OverlayReferenceMapper;
@@ -351,8 +362,15 @@
if (pkg == null) {
return;
}
+ final long currentTimeUs = SystemClock.currentTimeMicro();
updateEnabledState(pkg);
mAppsFilter.updateShouldFilterCacheForPackage(snapshot, packageName);
+ mAppsFilter.logCacheUpdated(
+ PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED__EVENT_TYPE__COMPAT_CHANGED,
+ SystemClock.currentTimeMicro() - currentTimeUs,
+ snapshot.getUserInfos().length,
+ snapshot.getPackageStates().size(),
+ pkg.getUid());
}
private void updateEnabledState(@NonNull AndroidPackage pkg) {
@@ -465,7 +483,8 @@
mOverlayReferenceMapper.rebuildIfDeferred();
mFeatureConfig.onSystemReady();
- updateEntireShouldFilterCacheAsync(pmInternal);
+ updateEntireShouldFilterCacheAsync(pmInternal,
+ PACKAGE_MANAGER_APPS_FILTER_CACHE_BUILD_REPORTED__EVENT_TYPE__BOOT);
}
/**
@@ -476,13 +495,17 @@
*/
public void addPackage(Computer snapshot, PackageStateInternal newPkgSetting,
boolean isReplace) {
+ final long currentTimeUs = SystemClock.currentTimeMicro();
+ final int logType = isReplace
+ ? PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED__EVENT_TYPE__PACKAGE_REPLACED
+ : PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED__EVENT_TYPE__PACKAGE_ADDED;
if (DEBUG_TRACING) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "filter.addPackage");
}
try {
if (isReplace) {
// let's first remove any prior rules for this package
- removePackage(snapshot, newPkgSetting, true /*isReplace*/);
+ removePackageInternal(snapshot, newPkgSetting, true /*isReplace*/);
}
final ArrayMap<String, ? extends PackageStateInternal> settings =
snapshot.getPackageStates();
@@ -508,6 +531,8 @@
}
}
}
+ logCacheUpdated(logType, SystemClock.currentTimeMicro() - currentTimeUs,
+ users.length, settings.size(), newPkgSetting.getAppId());
} else {
invalidateCache("addPackage: " + newPkgSetting.getPackageName());
}
@@ -757,18 +782,19 @@
}
}
- private void updateEntireShouldFilterCacheAsync(PackageManagerInternal pmInternal) {
- updateEntireShouldFilterCacheAsync(pmInternal, CACHE_REBUILD_DELAY_MIN_MS);
+ private void updateEntireShouldFilterCacheAsync(PackageManagerInternal pmInternal, int reason) {
+ updateEntireShouldFilterCacheAsync(pmInternal, CACHE_REBUILD_DELAY_MIN_MS, reason);
}
private void updateEntireShouldFilterCacheAsync(PackageManagerInternal pmInternal,
- long delayMs) {
+ long delayMs, int reason) {
mBackgroundHandler.postDelayed(() -> {
if (!mCacheValid.compareAndSet(CACHE_INVALID, CACHE_VALID)) {
// Cache is already valid.
return;
}
+ final long currentTimeUs = SystemClock.currentTimeMicro();
final ArrayMap<String, AndroidPackage> packagesCache = new ArrayMap<>();
final UserInfo[][] usersRef = new UserInfo[1][];
final Computer snapshot = (Computer) pmInternal.snapshot();
@@ -787,11 +813,13 @@
updateEntireShouldFilterCacheInner(snapshot, settings, usersRef[0], USER_ALL);
onChanged();
+ logCacheRebuilt(reason, SystemClock.currentTimeMicro() - currentTimeUs,
+ users.length, settings.size());
if (!mCacheValid.compareAndSet(CACHE_VALID, CACHE_VALID)) {
Slog.i(TAG, "Cache invalidated while building, retrying.");
updateEntireShouldFilterCacheAsync(pmInternal,
- Math.min(delayMs * 2, CACHE_REBUILD_DELAY_MAX_MS));
+ Math.min(delayMs * 2, CACHE_REBUILD_DELAY_MAX_MS), reason);
return;
}
@@ -803,15 +831,27 @@
if (!mCacheReady) {
return;
}
+ final long currentTimeUs = SystemClock.currentTimeMicro();
updateEntireShouldFilterCache(snapshot, newUserId);
+ logCacheRebuilt(
+ PACKAGE_MANAGER_APPS_FILTER_CACHE_BUILD_REPORTED__EVENT_TYPE__USER_CREATED,
+ SystemClock.currentTimeMicro() - currentTimeUs,
+ snapshot.getUserInfos().length,
+ snapshot.getPackageStates().size());
}
- public void onUserDeleted(@UserIdInt int userId) {
+ public void onUserDeleted(Computer snapshot, @UserIdInt int userId) {
if (!mCacheReady) {
return;
}
+ final long currentTimeUs = SystemClock.currentTimeMicro();
removeShouldFilterCacheForUser(userId);
onChanged();
+ logCacheRebuilt(
+ PACKAGE_MANAGER_APPS_FILTER_CACHE_BUILD_REPORTED__EVENT_TYPE__USER_DELETED,
+ SystemClock.currentTimeMicro() - currentTimeUs,
+ snapshot.getUserInfos().length,
+ snapshot.getPackageStates().size());
}
private void updateShouldFilterCacheForPackage(Computer snapshot,
@@ -988,10 +1028,26 @@
/**
* Removes a package for consideration when filtering visibility between apps.
*
+ * @param setting the setting of the package being removed.
+ */
+ public void removePackage(Computer snapshot, PackageStateInternal setting) {
+ final long currentTimeUs = SystemClock.currentTimeMicro();
+ removePackageInternal(snapshot, setting, false /* isReplace */);
+ logCacheUpdated(
+ PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED__EVENT_TYPE__PACKAGE_DELETED,
+ SystemClock.currentTimeMicro() - currentTimeUs,
+ snapshot.getUserInfos().length,
+ snapshot.getPackageStates().size(),
+ setting.getAppId());
+ }
+
+ /**
+ * Removes a package for consideration when filtering visibility between apps.
+ *
* @param setting the setting of the package being removed.
* @param isReplace if the package is being replaced.
*/
- public void removePackage(Computer snapshot, PackageStateInternal setting,
+ private void removePackageInternal(Computer snapshot, PackageStateInternal setting,
boolean isReplace) {
final ArraySet<String> additionalChangedPackages;
final ArrayMap<String, ? extends PackageStateInternal> settings =
@@ -1174,4 +1230,18 @@
}
}
}
+
+ private void logCacheRebuilt(int eventId, long latency, int userCount, int packageCount) {
+ FrameworkStatsLog.write(PACKAGE_MANAGER_APPS_FILTER_CACHE_BUILD_REPORTED,
+ eventId, latency, userCount, packageCount, mShouldFilterCache.size());
+ }
+
+ private void logCacheUpdated(int eventId, long latency, int userCount, int packageCount,
+ int appId) {
+ if (!mCacheReady) {
+ return;
+ }
+ FrameworkStatsLog.write(PACKAGE_MANAGER_APPS_FILTER_CACHE_UPDATE_REPORTED,
+ eventId, appId, latency, userCount, packageCount, mShouldFilterCache.size());
+ }
}
diff --git a/services/core/java/com/android/server/pm/BackgroundDexOptService.java b/services/core/java/com/android/server/pm/BackgroundDexOptService.java
index e7412c5..d856d54 100644
--- a/services/core/java/com/android/server/pm/BackgroundDexOptService.java
+++ b/services/core/java/com/android/server/pm/BackgroundDexOptService.java
@@ -410,7 +410,7 @@
job.jobFinished(params, !completed);
} else {
// Periodic job
- job.jobFinished(params, true);
+ job.jobFinished(params, false /* reschedule */);
}
markDexOptCompleted();
}
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index dfbe68a..23cf262 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -1147,7 +1147,7 @@
var done = SystemClock.currentTimeMicro();
if (mSnapshotStatistics != null) {
- mSnapshotStatistics.rebuild(now, done, hits);
+ mSnapshotStatistics.rebuild(now, done, hits, newSnapshot.getPackageStates().size());
}
return newSnapshot;
}
@@ -4220,7 +4220,7 @@
mSettings.removeUserLPw(userId);
mPendingBroadcasts.remove(userId);
mDeletePackageHelper.removeUnusedPackagesLPw(userManager, userId);
- mAppsFilter.onUserDeleted(userId);
+ mAppsFilter.onUserDeleted(snapshotComputer(), userId);
}
mInstantAppRegistry.onUserRemoved(userId);
}
diff --git a/services/core/java/com/android/server/pm/RemovePackageHelper.java b/services/core/java/com/android/server/pm/RemovePackageHelper.java
index bbc4fde..7e93673 100644
--- a/services/core/java/com/android/server/pm/RemovePackageHelper.java
+++ b/services/core/java/com/android/server/pm/RemovePackageHelper.java
@@ -308,7 +308,7 @@
mPm.mSettings.getKeySetManagerService().removeAppKeySetDataLPw(packageName);
final Computer snapshot = mPm.snapshotComputer();
mPm.mAppsFilter.removePackage(snapshot,
- snapshot.getPackageStateInternal(packageName), false /* isReplace */);
+ snapshot.getPackageStateInternal(packageName));
removedAppId = mPm.mSettings.removePackageLPw(packageName);
if (outInfo != null) {
outInfo.mRemovedAppId = removedAppId;
diff --git a/services/core/java/com/android/server/pm/SnapshotStatistics.java b/services/core/java/com/android/server/pm/SnapshotStatistics.java
index 2cfc894..e04a1e5 100644
--- a/services/core/java/com/android/server/pm/SnapshotStatistics.java
+++ b/services/core/java/com/android/server/pm/SnapshotStatistics.java
@@ -24,11 +24,13 @@
import android.text.TextUtils;
import com.android.internal.annotations.GuardedBy;
+import com.android.internal.util.FrameworkStatsLog;
import com.android.server.EventLogTags;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
+import java.util.concurrent.TimeUnit;
/**
* This class records statistics about PackageManagerService snapshots. It maintains two sets of
@@ -59,9 +61,9 @@
public static final int SNAPSHOT_TICK_INTERVAL_MS = 60 * 1000;
/**
- * The number of ticks for long statistics. This is one week.
+ * The interval of the snapshot statistics logging.
*/
- public static final int SNAPSHOT_LONG_TICKS = 7 * 24 * 60;
+ private static final long SNAPSHOT_LOG_INTERVAL_US = TimeUnit.DAYS.toMicros(1);
/**
* The number snapshot event logs that can be generated in a single logging interval.
@@ -93,6 +95,28 @@
public static final int SNAPSHOT_SHORT_LIFETIME = 5;
/**
+ * Buckets to represent a range of the rebuild latency for the histogram of
+ * snapshot rebuild latency.
+ */
+ private static final int REBUILD_LATENCY_BUCKET_LESS_THAN_1_MILLIS = 1;
+ private static final int REBUILD_LATENCY_BUCKET_LESS_THAN_2_MILLIS = 2;
+ private static final int REBUILD_LATENCY_BUCKET_LESS_THAN_5_MILLIS = 5;
+ private static final int REBUILD_LATENCY_BUCKET_LESS_THAN_10_MILLIS = 10;
+ private static final int REBUILD_LATENCY_BUCKET_LESS_THAN_20_MILLIS = 20;
+ private static final int REBUILD_LATENCY_BUCKET_LESS_THAN_50_MILLIS = 50;
+ private static final int REBUILD_LATENCY_BUCKET_LESS_THAN_100_MILLIS = 100;
+
+ /**
+ * Buckets to represent a range of the reuse count for the histogram of
+ * snapshot reuse counts.
+ */
+ private static final int REUSE_COUNT_BUCKET_LESS_THAN_1 = 1;
+ private static final int REUSE_COUNT_BUCKET_LESS_THAN_10 = 10;
+ private static final int REUSE_COUNT_BUCKET_LESS_THAN_100 = 100;
+ private static final int REUSE_COUNT_BUCKET_LESS_THAN_1000 = 1000;
+ private static final int REUSE_COUNT_BUCKET_LESS_THAN_10000 = 10000;
+
+ /**
* The lock to control access to this object.
*/
private final Object mLock = new Object();
@@ -113,11 +137,6 @@
private int mEventsReported = 0;
/**
- * The tick counter. At the default tick interval, this wraps every 4000 years or so.
- */
- private int mTicks = 0;
-
- /**
* The handler used for the periodic ticks.
*/
private Handler mHandler = null;
@@ -139,8 +158,6 @@
// The number of bins
private int mCount;
- // The mapping of low integers to bins
- private int[] mBinMap;
// The maximum mapped value. Values at or above this are mapped to the
// top bin.
private int mMaxBin;
@@ -158,16 +175,6 @@
mCount = mUserKey.length + 1;
// The maximum value is one more than the last one in the map.
mMaxBin = mUserKey[mUserKey.length - 1] + 1;
- mBinMap = new int[mMaxBin + 1];
-
- int j = 0;
- for (int i = 0; i < mUserKey.length; i++) {
- while (j <= mUserKey[i]) {
- mBinMap[j] = i;
- j++;
- }
- }
- mBinMap[mMaxBin] = mUserKey.length;
}
/**
@@ -175,9 +182,14 @@
*/
public int getBin(int x) {
if (x >= 0 && x < mMaxBin) {
- return mBinMap[x];
+ for (int i = 0; i < mUserKey.length; i++) {
+ if (x <= mUserKey[i]) {
+ return i;
+ }
+ }
+ return 0; // should not happen
} else if (x >= mMaxBin) {
- return mBinMap[mMaxBin];
+ return mUserKey.length;
} else {
// x is negative. The bin will not be used.
return 0;
@@ -263,6 +275,11 @@
public int mMaxBuildTimeUs = 0;
/**
+ * The maximum used count since the last log.
+ */
+ public int mMaxUsedCount = 0;
+
+ /**
* Record the rebuild. The parameters are the length of time it took to build the
* latest snapshot, and the number of times the _previous_ snapshot was used. A
* negative value for used signals an invalid value, which is the case the first
@@ -279,7 +296,6 @@
}
mTotalTimeUs += duration;
- boolean reportIt = false;
if (big) {
mBigBuilds++;
@@ -290,6 +306,9 @@
if (mMaxBuildTimeUs < duration) {
mMaxBuildTimeUs = duration;
}
+ if (mMaxUsedCount < used) {
+ mMaxUsedCount = used;
+ }
}
private Stats(long now) {
@@ -313,6 +332,7 @@
mShortLived = orig.mShortLived;
mTotalTimeUs = orig.mTotalTimeUs;
mMaxBuildTimeUs = orig.mMaxBuildTimeUs;
+ mMaxUsedCount = orig.mMaxUsedCount;
}
/**
@@ -443,18 +463,19 @@
}
/**
- * Report the object via an event. Presumably the record indicates an anomalous
- * incident.
+ * Report the snapshot statistics to FrameworkStatsLog.
*/
- private void report() {
- EventLogTags.writePmSnapshotStats(
- mTotalBuilds, mTotalUsed, mBigBuilds, mShortLived,
- mMaxBuildTimeUs / US_IN_MS, mTotalTimeUs / US_IN_MS);
+ private void logSnapshotStatistics(int packageCount) {
+ final long avgLatencyUs = (mTotalBuilds == 0 ? 0 : mTotalTimeUs / mTotalBuilds);
+ final int avgUsedCount = (mTotalBuilds == 0 ? 0 : mTotalUsed / mTotalBuilds);
+ FrameworkStatsLog.write(
+ FrameworkStatsLog.PACKAGE_MANAGER_SNAPSHOT_REPORTED, mTimes, mUsed,
+ mMaxBuildTimeUs, mMaxUsedCount, avgLatencyUs, avgUsedCount, packageCount);
}
}
/**
- * Long statistics. These roll over approximately every week.
+ * Long statistics. These roll over approximately one day.
*/
private Stats[] mLong;
@@ -464,10 +485,14 @@
private Stats[] mShort;
/**
- * The time of the last build. This can be used to compute the length of time a
- * snapshot existed before being replaced.
+ * The time of last logging to the FrameworkStatsLog.
*/
- private long mLastBuildTime = 0;
+ private long mLastLogTimeUs;
+
+ /**
+ * The number of packages on the device.
+ */
+ private int mPackageCount;
/**
* Create a snapshot object. Initialize the bin levels. The last bin catches
@@ -475,8 +500,20 @@
*/
public SnapshotStatistics() {
// Create the bin thresholds. The time bins are in units of us.
- mTimeBins = new BinMap(new int[] { 1, 2, 5, 10, 20, 50, 100 });
- mUseBins = new BinMap(new int[] { 1, 2, 5, 10, 20, 50, 100 });
+ mTimeBins = new BinMap(new int[] {
+ REBUILD_LATENCY_BUCKET_LESS_THAN_1_MILLIS,
+ REBUILD_LATENCY_BUCKET_LESS_THAN_2_MILLIS,
+ REBUILD_LATENCY_BUCKET_LESS_THAN_5_MILLIS,
+ REBUILD_LATENCY_BUCKET_LESS_THAN_10_MILLIS,
+ REBUILD_LATENCY_BUCKET_LESS_THAN_20_MILLIS,
+ REBUILD_LATENCY_BUCKET_LESS_THAN_50_MILLIS,
+ REBUILD_LATENCY_BUCKET_LESS_THAN_100_MILLIS });
+ mUseBins = new BinMap(new int[] {
+ REUSE_COUNT_BUCKET_LESS_THAN_1,
+ REUSE_COUNT_BUCKET_LESS_THAN_10,
+ REUSE_COUNT_BUCKET_LESS_THAN_100,
+ REUSE_COUNT_BUCKET_LESS_THAN_1000,
+ REUSE_COUNT_BUCKET_LESS_THAN_10000 });
// Create the raw statistics
final long now = SystemClock.currentTimeMicro();
@@ -484,6 +521,7 @@
mLong[0] = new Stats(now);
mShort = new Stats[10];
mShort[0] = new Stats(now);
+ mLastLogTimeUs = now;
// Create the message handler for ticks and start the ticker.
mHandler = new Handler(Looper.getMainLooper()) {
@@ -516,13 +554,14 @@
* @param now The time at which the snapshot rebuild began, in ns.
* @param done The time at which the snapshot rebuild completed, in ns.
* @param hits The number of times the previous snapshot was used.
+ * @param packageCount The number of packages on the device.
*/
- public final void rebuild(long now, long done, int hits) {
+ public final void rebuild(long now, long done, int hits, int packageCount) {
// The duration has a span of about 2000s
final int duration = (int) (done - now);
boolean reportEvent = false;
synchronized (mLock) {
- mLastBuildTime = now;
+ mPackageCount = packageCount;
final int timeBin = mTimeBins.getBin(duration / 1000);
final int useBin = mUseBins.getBin(hits);
@@ -570,10 +609,12 @@
private void tick() {
synchronized (mLock) {
long now = SystemClock.currentTimeMicro();
- mTicks++;
- if (mTicks % SNAPSHOT_LONG_TICKS == 0) {
+ if (now - mLastLogTimeUs > SNAPSHOT_LOG_INTERVAL_US) {
shift(mLong, now);
+ mLastLogTimeUs = now;
+ mLong[mLong.length - 1].logSnapshotStatistics(mPackageCount);
}
+
shift(mShort, now);
mEventsReported = 0;
}
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index ecc43f7..b153a85 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -1316,7 +1316,7 @@
mAppSwitchesState = APP_SWITCH_ALLOW;
}
}
- return pir.sendInner(0, fillInIntent, resolvedType, allowlistToken, null, null,
+ return pir.sendInner(caller, 0, fillInIntent, resolvedType, allowlistToken, null, null,
resultTo, resultWho, requestCode, flagsMask, flagsValues, bOptions);
}
diff --git a/services/tests/InputMethodSystemServerTests/Android.bp b/services/tests/InputMethodSystemServerTests/Android.bp
new file mode 100644
index 0000000..939fb6a
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/Android.bp
@@ -0,0 +1,62 @@
+// Copyright (C) 2022 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "frameworks_base_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["frameworks_base_license"],
+}
+
+android_test {
+ name: "FrameworksInputMethodSystemServerTests",
+ defaults: [
+ "modules-utils-testable-device-config-defaults",
+ ],
+
+ srcs: [
+ "src/**/*.java",
+ ],
+
+ static_libs: [
+ "androidx.test.core",
+ "androidx.test.runner",
+ "androidx.test.espresso.core",
+ "androidx.test.espresso.contrib",
+ "androidx.test.ext.truth",
+ "frameworks-base-testutils",
+ "mockito-target-extended-minus-junit4",
+ "platform-test-annotations",
+ "services.core",
+ "servicestests-core-utils",
+ "servicestests-utils-mockito-extended",
+ "truth-prebuilt",
+ ],
+
+ libs: [
+ "android.test.mock",
+ "android.test.base",
+ "android.test.runner",
+ ],
+
+ certificate: "platform",
+ platform_apis: true,
+ test_suites: ["device-tests"],
+
+ optimize: {
+ enabled: false,
+ },
+}
diff --git a/services/tests/InputMethodSystemServerTests/AndroidManifest.xml b/services/tests/InputMethodSystemServerTests/AndroidManifest.xml
new file mode 100644
index 0000000..12e7cfc
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/AndroidManifest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.frameworks.inputmethodtests">
+
+ <uses-sdk android:targetSdkVersion="31" />
+
+ <!-- Permissions required for granting and logging -->
+ <uses-permission android:name="android.permission.LOG_COMPAT_CHANGE"/>
+ <uses-permission android:name="android.permission.READ_COMPAT_CHANGE_CONFIG"/>
+ <uses-permission android:name="android.permission.OVERRIDE_COMPAT_CHANGE_CONFIG"/>
+ <uses-permission android:name="android.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD"/>
+
+ <!-- Permissions for reading system info -->
+ <uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
+ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
+
+ <application android:testOnly="true"
+ android:debuggable="true">
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation
+ android:name="androidx.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.frameworks.inputmethodtests"
+ android:label="Frameworks InputMethod System Service Tests" />
+
+</manifest>
diff --git a/services/tests/InputMethodSystemServerTests/AndroidTest.xml b/services/tests/InputMethodSystemServerTests/AndroidTest.xml
new file mode 100644
index 0000000..92be780
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/AndroidTest.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<configuration description="Runs Frameworks InputMethod System Services Tests.">
+ <option name="test-suite-tag" value="apct" />
+ <option name="test-suite-tag" value="apct-instrumentation" />
+
+ <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true" />
+ <option name="install-arg" value="-t" />
+ <option name="test-file-name" value="FrameworksInputMethodSystemServerTests.apk" />
+ </target_preparer>
+
+ <option name="test-tag" value="FrameworksInputMethodSystemServerTests" />
+
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+ <option name="package" value="com.android.frameworks.inputmethodtests" />
+ <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
+ <option name="hidden-api-checks" value="false"/>
+ </test>
+
+ <!-- Collect the files in the dump directory for debugging -->
+ <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
+ <option name="directory-keys" value="/sdcard/FrameworksInputMethodSystemServerTests/" />
+ <option name="collect-on-run-ended-only" value="true" />
+ </metrics_collector>
+</configuration>
diff --git a/services/tests/InputMethodSystemServerTests/OWNERS b/services/tests/InputMethodSystemServerTests/OWNERS
new file mode 100644
index 0000000..1f2c036
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/OWNERS
@@ -0,0 +1 @@
+include /services/core/java/com/android/server/inputmethod/OWNERS
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java
new file mode 100644
index 0000000..3fbc400
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java
@@ -0,0 +1,259 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.inputmethod;
+
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.ActivityManagerInternal;
+import android.content.Context;
+import android.content.pm.PackageManagerInternal;
+import android.hardware.display.DisplayManagerInternal;
+import android.hardware.input.IInputManager;
+import android.hardware.input.InputManager;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.view.inputmethod.EditorInfo;
+import android.window.ImeOnBackInvokedDispatcher;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.internal.compat.IPlatformCompat;
+import com.android.internal.inputmethod.IInputMethod;
+import com.android.internal.inputmethod.IInputMethodClient;
+import com.android.internal.inputmethod.IRemoteAccessibilityInputConnection;
+import com.android.internal.inputmethod.IRemoteInputConnection;
+import com.android.internal.inputmethod.InputBindResult;
+import com.android.internal.view.IInputMethodManager;
+import com.android.server.LocalServices;
+import com.android.server.ServiceThread;
+import com.android.server.SystemServerInitThreadPool;
+import com.android.server.SystemService;
+import com.android.server.input.InputManagerInternal;
+import com.android.server.pm.UserManagerInternal;
+import com.android.server.wm.WindowManagerInternal;
+
+import org.junit.After;
+import org.junit.Before;
+import org.mockito.Mock;
+import org.mockito.MockitoSession;
+import org.mockito.quality.Strictness;
+
+/** Base class for testing {@link InputMethodManagerService}. */
+public class InputMethodManagerServiceTestBase {
+ protected static final String TEST_SELECTED_IME_ID = "test.ime";
+ protected static final String TEST_EDITOR_PKG_NAME = "test.editor";
+ protected static final String TEST_FOCUSED_WINDOW_NAME = "test.editor/activity";
+ protected static final WindowManagerInternal.ImeTargetInfo TEST_IME_TARGET_INFO =
+ new WindowManagerInternal.ImeTargetInfo(
+ TEST_FOCUSED_WINDOW_NAME,
+ TEST_FOCUSED_WINDOW_NAME,
+ TEST_FOCUSED_WINDOW_NAME,
+ TEST_FOCUSED_WINDOW_NAME,
+ TEST_FOCUSED_WINDOW_NAME);
+ protected static final InputBindResult SUCCESS_WAITING_IME_BINDING_RESULT =
+ new InputBindResult(
+ InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING,
+ null,
+ null,
+ null,
+ "0",
+ 0,
+ null,
+ false);
+
+ @Mock protected WindowManagerInternal mMockWindowManagerInternal;
+ @Mock protected ActivityManagerInternal mMockActivityManagerInternal;
+ @Mock protected PackageManagerInternal mMockPackageManagerInternal;
+ @Mock protected InputManagerInternal mMockInputManagerInternal;
+ @Mock protected DisplayManagerInternal mMockDisplayManagerInternal;
+ @Mock protected UserManagerInternal mMockUserManagerInternal;
+ @Mock protected InputMethodBindingController mMockInputMethodBindingController;
+ @Mock protected IInputMethodClient mMockInputMethodClient;
+ @Mock protected IBinder mWindowToken;
+ @Mock protected IRemoteInputConnection mMockRemoteInputConnection;
+ @Mock protected IRemoteAccessibilityInputConnection mMockRemoteAccessibilityInputConnection;
+ @Mock protected ImeOnBackInvokedDispatcher mMockImeOnBackInvokedDispatcher;
+ @Mock protected IInputMethodManager.Stub mMockIInputMethodManager;
+ @Mock protected IPlatformCompat.Stub mMockIPlatformCompat;
+ @Mock protected IInputMethod mMockInputMethod;
+ @Mock protected IBinder mMockInputMethodBinder;
+ @Mock protected IInputManager mMockIInputManager;
+
+ protected Context mContext;
+ protected MockitoSession mMockingSession;
+ protected int mTargetSdkVersion;
+ protected int mCallingUserId;
+ protected EditorInfo mEditorInfo;
+ protected IInputMethodInvoker mMockInputMethodInvoker;
+ protected InputMethodManagerService mInputMethodManagerService;
+ protected ServiceThread mServiceThread;
+
+ @Before
+ public void setUp() throws RemoteException {
+ mMockingSession =
+ mockitoSession()
+ .initMocks(this)
+ .strictness(Strictness.LENIENT)
+ .mockStatic(LocalServices.class)
+ .mockStatic(ServiceManager.class)
+ .mockStatic(SystemServerInitThreadPool.class)
+ .startMocking();
+
+ mContext = InstrumentationRegistry.getInstrumentation().getContext();
+ spyOn(mContext);
+
+ mTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
+ mCallingUserId = UserHandle.getCallingUserId();
+ mEditorInfo = new EditorInfo();
+ mEditorInfo.packageName = TEST_EDITOR_PKG_NAME;
+
+ // Injecting and mocking local services.
+ doReturn(mMockWindowManagerInternal)
+ .when(() -> LocalServices.getService(WindowManagerInternal.class));
+ doReturn(mMockActivityManagerInternal)
+ .when(() -> LocalServices.getService(ActivityManagerInternal.class));
+ doReturn(mMockPackageManagerInternal)
+ .when(() -> LocalServices.getService(PackageManagerInternal.class));
+ doReturn(mMockInputManagerInternal)
+ .when(() -> LocalServices.getService(InputManagerInternal.class));
+ doReturn(mMockDisplayManagerInternal)
+ .when(() -> LocalServices.getService(DisplayManagerInternal.class));
+ doReturn(mMockUserManagerInternal)
+ .when(() -> LocalServices.getService(UserManagerInternal.class));
+ doReturn(mMockIInputMethodManager)
+ .when(() -> ServiceManager.getServiceOrThrow(Context.INPUT_METHOD_SERVICE));
+ doReturn(mMockIPlatformCompat)
+ .when(() -> ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
+
+ // Stubbing out context related methods to avoid the system holding strong references to
+ // InputMethodManagerService.
+ doNothing().when(mContext).enforceCallingPermission(anyString(), anyString());
+ doNothing().when(mContext).sendBroadcastAsUser(any(), any());
+ doReturn(null).when(mContext).registerReceiver(any(), any());
+ doReturn(null)
+ .when(mContext)
+ .registerReceiverAsUser(any(), any(), any(), anyString(), any(), anyInt());
+
+ // Injecting and mocked InputMethodBindingController and InputMethod.
+ mMockInputMethodInvoker = IInputMethodInvoker.create(mMockInputMethod);
+ InputManager.resetInstance(mMockIInputManager);
+ synchronized (ImfLock.class) {
+ when(mMockInputMethodBindingController.getCurMethod())
+ .thenReturn(mMockInputMethodInvoker);
+ when(mMockInputMethodBindingController.bindCurrentMethod())
+ .thenReturn(SUCCESS_WAITING_IME_BINDING_RESULT);
+ doNothing().when(mMockInputMethodBindingController).unbindCurrentMethod();
+ when(mMockInputMethodBindingController.getSelectedMethodId())
+ .thenReturn(TEST_SELECTED_IME_ID);
+ }
+
+ // Shuffling around all other initialization to make the test runnable.
+ when(mMockIInputManager.getInputDeviceIds()).thenReturn(new int[0]);
+ when(mMockIInputMethodManager.isImeTraceEnabled()).thenReturn(false);
+ when(mMockIPlatformCompat.isChangeEnabledByUid(anyLong(), anyInt())).thenReturn(true);
+ when(mMockUserManagerInternal.isUserRunning(anyInt())).thenReturn(true);
+ when(mMockUserManagerInternal.getProfileIds(anyInt(), anyBoolean()))
+ .thenReturn(new int[] {0});
+ when(mMockActivityManagerInternal.isSystemReady()).thenReturn(true);
+ when(mMockPackageManagerInternal.getPackageUid(anyString(), anyLong(), anyInt()))
+ .thenReturn(Binder.getCallingUid());
+ when(mMockWindowManagerInternal.onToggleImeRequested(anyBoolean(), any(), any(), anyInt()))
+ .thenReturn(TEST_IME_TARGET_INFO);
+ when(mMockInputMethodClient.asBinder()).thenReturn(mMockInputMethodBinder);
+
+ // Used by lazy initializing draw IMS nav bar at InputMethodManagerService#systemRunning(),
+ // which is ok to be mocked out for now.
+ doReturn(null).when(() -> SystemServerInitThreadPool.submit(any(), anyString()));
+
+ mServiceThread =
+ new ServiceThread(
+ "TestServiceThread",
+ Process.THREAD_PRIORITY_FOREGROUND, /* allowIo */
+ false);
+ mInputMethodManagerService =
+ new InputMethodManagerService(
+ mContext, mServiceThread, mMockInputMethodBindingController);
+
+ // Start a InputMethodManagerService.Lifecycle to publish and manage the lifecycle of
+ // InputMethodManagerService, which is closer to the real situation.
+ InputMethodManagerService.Lifecycle lifecycle =
+ new InputMethodManagerService.Lifecycle(mContext, mInputMethodManagerService);
+
+ // Public local InputMethodManagerService.
+ lifecycle.onStart();
+ try {
+ // After this boot phase, services can broadcast Intents.
+ lifecycle.onBootPhase(SystemService.PHASE_ACTIVITY_MANAGER_READY);
+ } catch (SecurityException e) {
+ // Security exception to permission denial is expected in test, mocking out to ensure
+ // InputMethodManagerService as system ready state.
+ if (!e.getMessage().contains("Permission Denial: not allowed to send broadcast")) {
+ throw e;
+ }
+ }
+
+ // Call InputMethodManagerService#addClient() as a preparation to start interacting with it.
+ mInputMethodManagerService.addClient(mMockInputMethodClient, mMockRemoteInputConnection, 0);
+ }
+
+ @After
+ public void tearDown() {
+ if (mServiceThread != null) {
+ mServiceThread.quitSafely();
+ }
+
+ if (mMockingSession != null) {
+ mMockingSession.finishMocking();
+ }
+ }
+
+ protected void verifyShowSoftInput(boolean setVisible, boolean showSoftInput)
+ throws RemoteException {
+ synchronized (ImfLock.class) {
+ verify(mMockInputMethodBindingController, times(setVisible ? 1 : 0))
+ .setCurrentMethodVisible();
+ }
+ verify(mMockInputMethod, times(showSoftInput ? 1 : 0))
+ .showSoftInput(any(), anyInt(), any());
+ }
+
+ protected void verifyHideSoftInput(boolean setNotVisible, boolean hideSoftInput)
+ throws RemoteException {
+ synchronized (ImfLock.class) {
+ verify(mMockInputMethodBindingController, times(setNotVisible ? 1 : 0))
+ .setCurrentMethodNotVisible();
+ }
+ verify(mMockInputMethod, times(hideSoftInput ? 1 : 0))
+ .hideSoftInput(any(), anyInt(), any());
+ }
+}
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceWindowGainedFocusTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceWindowGainedFocusTest.java
new file mode 100644
index 0000000..ffa2729
--- /dev/null
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceWindowGainedFocusTest.java
@@ -0,0 +1,266 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.inputmethod;
+
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.when;
+
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.inputmethod.EditorInfo;
+import android.window.ImeOnBackInvokedDispatcher;
+
+import com.android.internal.inputmethod.IInputMethodClient;
+import com.android.internal.inputmethod.IRemoteAccessibilityInputConnection;
+import com.android.internal.inputmethod.IRemoteInputConnection;
+import com.android.internal.inputmethod.InputBindResult;
+import com.android.internal.inputmethod.InputMethodDebug;
+import com.android.internal.inputmethod.StartInputFlags;
+import com.android.internal.inputmethod.StartInputReason;
+import com.android.server.wm.WindowManagerInternal;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Test the behavior of {@link InputMethodManagerService#startInputOrWindowGainedFocus(int,
+ * IInputMethodClient, IBinder, int, int, int, EditorInfo, IRemoteInputConnection,
+ * IRemoteAccessibilityInputConnection, int, int, ImeOnBackInvokedDispatcher)}.
+ */
+@RunWith(Parameterized.class)
+public class InputMethodManagerServiceWindowGainedFocusTest
+ extends InputMethodManagerServiceTestBase {
+ private static final String TAG = "IMMSWindowGainedFocusTest";
+
+ private static final int[] SOFT_INPUT_STATE_FLAGS =
+ new int[] {
+ SOFT_INPUT_STATE_UNSPECIFIED,
+ SOFT_INPUT_STATE_UNCHANGED,
+ SOFT_INPUT_STATE_HIDDEN,
+ SOFT_INPUT_STATE_ALWAYS_HIDDEN,
+ SOFT_INPUT_STATE_VISIBLE,
+ SOFT_INPUT_STATE_ALWAYS_VISIBLE
+ };
+ private static final int[] SOFT_INPUT_ADJUST_FLAGS =
+ new int[] {
+ SOFT_INPUT_ADJUST_UNSPECIFIED,
+ SOFT_INPUT_ADJUST_RESIZE,
+ SOFT_INPUT_ADJUST_PAN,
+ SOFT_INPUT_ADJUST_NOTHING
+ };
+ private static final int DEFAULT_SOFT_INPUT_FLAG =
+ StartInputFlags.VIEW_HAS_FOCUS | StartInputFlags.IS_TEXT_EDITOR;
+
+ @Parameterized.Parameters(name = "softInputState={0}, softInputAdjustment={1}")
+ public static List<Object[]> softInputModeConfigs() {
+ ArrayList<Object[]> params = new ArrayList<>();
+ for (int softInputState : SOFT_INPUT_STATE_FLAGS) {
+ for (int softInputAdjust : SOFT_INPUT_ADJUST_FLAGS) {
+ params.add(new Object[] {softInputState, softInputAdjust});
+ }
+ }
+ return params;
+ }
+
+ private final int mSoftInputState;
+ private final int mSoftInputAdjustment;
+
+ public InputMethodManagerServiceWindowGainedFocusTest(
+ int softInputState, int softInputAdjustment) {
+ mSoftInputState = softInputState;
+ mSoftInputAdjustment = softInputAdjustment;
+ }
+
+ @Test
+ public void startInputOrWindowGainedFocus_forwardNavigation() throws RemoteException {
+ mockHasImeFocusAndRestoreImeVisibility(false /* restoreImeVisibility */);
+
+ assertThat(
+ startInputOrWindowGainedFocus(
+ DEFAULT_SOFT_INPUT_FLAG, true /* forwardNavigation */))
+ .isEqualTo(SUCCESS_WAITING_IME_BINDING_RESULT);
+
+ switch (mSoftInputState) {
+ case SOFT_INPUT_STATE_UNSPECIFIED:
+ boolean showSoftInput = mSoftInputAdjustment == SOFT_INPUT_ADJUST_RESIZE;
+ verifyShowSoftInput(
+ showSoftInput /* setVisible */, showSoftInput /* showSoftInput */);
+ // Soft input was hidden by default, so it doesn't need to call
+ // {@code IMS#hideSoftInput()}.
+ verifyHideSoftInput(!showSoftInput /* setNotVisible */, false /* hideSoftInput */);
+ break;
+ case SOFT_INPUT_STATE_VISIBLE:
+ case SOFT_INPUT_STATE_ALWAYS_VISIBLE:
+ verifyShowSoftInput(true /* setVisible */, true /* showSoftInput */);
+ verifyHideSoftInput(false /* setNotVisible */, false /* hideSoftInput */);
+ break;
+ case SOFT_INPUT_STATE_UNCHANGED: // Do nothing
+ verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
+ verifyHideSoftInput(false /* setNotVisible */, false /* hideSoftInput */);
+ break;
+ case SOFT_INPUT_STATE_HIDDEN:
+ case SOFT_INPUT_STATE_ALWAYS_HIDDEN:
+ verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
+ // Soft input was hidden by default, so it doesn't need to call
+ // {@code IMS#hideSoftInput()}.
+ verifyHideSoftInput(true /* setNotVisible */, false /* hideSoftInput */);
+ break;
+ default:
+ throw new IllegalStateException(
+ "Unhandled soft input mode: "
+ + InputMethodDebug.softInputModeToString(mSoftInputState));
+ }
+ }
+
+ @Test
+ public void startInputOrWindowGainedFocus_notForwardNavigation() throws RemoteException {
+ mockHasImeFocusAndRestoreImeVisibility(false /* restoreImeVisibility */);
+
+ assertThat(
+ startInputOrWindowGainedFocus(
+ DEFAULT_SOFT_INPUT_FLAG, false /* forwardNavigation */))
+ .isEqualTo(SUCCESS_WAITING_IME_BINDING_RESULT);
+
+ switch (mSoftInputState) {
+ case SOFT_INPUT_STATE_UNSPECIFIED:
+ boolean hideSoftInput = mSoftInputAdjustment != SOFT_INPUT_ADJUST_RESIZE;
+ verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
+ // Soft input was hidden by default, so it doesn't need to call
+ // {@code IMS#hideSoftInput()}.
+ verifyHideSoftInput(hideSoftInput /* setNotVisible */, false /* hideSoftInput */);
+ break;
+ case SOFT_INPUT_STATE_VISIBLE:
+ case SOFT_INPUT_STATE_HIDDEN:
+ case SOFT_INPUT_STATE_UNCHANGED: // Do nothing
+ verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
+ verifyHideSoftInput(false /* setNotVisible */, false /* hideSoftInput */);
+ break;
+ case SOFT_INPUT_STATE_ALWAYS_VISIBLE:
+ verifyShowSoftInput(true /* setVisible */, true /* showSoftInput */);
+ verifyHideSoftInput(false /* setNotVisible */, false /* hideSoftInput */);
+ break;
+ case SOFT_INPUT_STATE_ALWAYS_HIDDEN:
+ verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
+ // Soft input was hidden by default, so it doesn't need to call
+ // {@code IMS#hideSoftInput()}.
+ verifyHideSoftInput(true /* setNotVisible */, false /* hideSoftInput */);
+ break;
+ default:
+ throw new IllegalStateException(
+ "Unhandled soft input mode: "
+ + InputMethodDebug.softInputModeToString(mSoftInputState));
+ }
+ }
+
+ @Test
+ public void startInputOrWindowGainedFocus_userNotRunning() throws RemoteException {
+ when(mMockUserManagerInternal.isUserRunning(anyInt())).thenReturn(false);
+
+ assertThat(
+ startInputOrWindowGainedFocus(
+ DEFAULT_SOFT_INPUT_FLAG, true /* forwardNavigation */))
+ .isEqualTo(InputBindResult.INVALID_USER);
+ verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
+ verifyHideSoftInput(false /* setNotVisible */, false /* hideSoftInput */);
+ }
+
+ @Test
+ public void startInputOrWindowGainedFocus_invalidFocusStatus() throws RemoteException {
+ int[] invalidImeClientFocus =
+ new int[] {
+ WindowManagerInternal.ImeClientFocusResult.NOT_IME_TARGET_WINDOW,
+ WindowManagerInternal.ImeClientFocusResult.DISPLAY_ID_MISMATCH,
+ WindowManagerInternal.ImeClientFocusResult.INVALID_DISPLAY_ID
+ };
+ InputBindResult[] inputBingResult =
+ new InputBindResult[] {
+ InputBindResult.NOT_IME_TARGET_WINDOW,
+ InputBindResult.DISPLAY_ID_MISMATCH,
+ InputBindResult.INVALID_DISPLAY_ID
+ };
+
+ for (int i = 0; i < invalidImeClientFocus.length; i++) {
+ when(mMockWindowManagerInternal.hasInputMethodClientFocus(
+ any(), anyInt(), anyInt(), anyInt()))
+ .thenReturn(invalidImeClientFocus[i]);
+
+ assertThat(
+ startInputOrWindowGainedFocus(
+ DEFAULT_SOFT_INPUT_FLAG, true /* forwardNavigation */))
+ .isEqualTo(inputBingResult[i]);
+ verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
+ verifyHideSoftInput(false /* setNotVisible */, false /* hideSoftInput */);
+ }
+ }
+
+ private InputBindResult startInputOrWindowGainedFocus(
+ int startInputFlag, boolean forwardNavigation) {
+ int softInputMode = mSoftInputState | mSoftInputAdjustment;
+ if (forwardNavigation) {
+ softInputMode |= SOFT_INPUT_IS_FORWARD_NAVIGATION;
+ }
+
+ Log.i(
+ TAG,
+ "startInputOrWindowGainedFocus() softInputStateFlag="
+ + InputMethodDebug.softInputModeToString(mSoftInputState)
+ + ", softInputAdjustFlag="
+ + InputMethodDebug.softInputModeToString(mSoftInputAdjustment));
+
+ return mInputMethodManagerService.startInputOrWindowGainedFocus(
+ StartInputReason.WINDOW_FOCUS_GAIN /* startInputReason */,
+ mMockInputMethodClient /* client */,
+ mWindowToken /* windowToken */,
+ startInputFlag /* startInputFlags */,
+ softInputMode /* softInputMode */,
+ 0 /* windowFlags */,
+ mEditorInfo /* editorInfo */,
+ mMockRemoteInputConnection /* inputConnection */,
+ mMockRemoteAccessibilityInputConnection /* remoteAccessibilityInputConnection */,
+ mTargetSdkVersion /* unverifiedTargetSdkVersion */,
+ mCallingUserId /* userId */,
+ mMockImeOnBackInvokedDispatcher /* imeDispatcher */);
+ }
+
+ private void mockHasImeFocusAndRestoreImeVisibility(boolean restoreImeVisibility) {
+ when(mMockWindowManagerInternal.hasInputMethodClientFocus(
+ any(), anyInt(), anyInt(), anyInt()))
+ .thenReturn(WindowManagerInternal.ImeClientFocusResult.HAS_IME_FOCUS);
+ when(mMockWindowManagerInternal.shouldRestoreImeVisibility(any()))
+ .thenReturn(restoreImeVisibility);
+ }
+}
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java
index 1753fc7..fc737d0 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/JobSchedulerServiceTest.java
@@ -41,6 +41,7 @@
import android.app.IActivityManager;
import android.app.UiModeManager;
import android.app.job.JobInfo;
+import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.usage.UsageStatsManagerInternal;
import android.content.ComponentName;
@@ -235,6 +236,59 @@
mService.getMinJobExecutionGuaranteeMs(jobDef));
}
+
+ /**
+ * Confirm that {@link JobSchedulerService#getRescheduleJobForFailureLocked(JobStatus, int)}
+ * returns a job with the correct delay and deadline constraints.
+ */
+ @Test
+ public void testGetRescheduleJobForFailure() {
+ final long nowElapsed = sElapsedRealtimeClock.millis();
+ final long initialBackoffMs = MINUTE_IN_MILLIS;
+ mService.mConstants.SYSTEM_STOP_TO_FAILURE_RATIO = 3;
+
+ JobStatus originalJob = createJobStatus("testGetRescheduleJobForFailure",
+ createJobInfo()
+ .setBackoffCriteria(initialBackoffMs, JobInfo.BACKOFF_POLICY_LINEAR));
+ assertEquals(JobStatus.NO_EARLIEST_RUNTIME, originalJob.getEarliestRunTime());
+ assertEquals(JobStatus.NO_LATEST_RUNTIME, originalJob.getLatestRunTimeElapsed());
+
+ // failure = 0, systemStop = 1
+ JobStatus rescheduledJob = mService.getRescheduleJobForFailureLocked(originalJob,
+ JobParameters.INTERNAL_STOP_REASON_DEVICE_THERMAL);
+ assertEquals(nowElapsed + initialBackoffMs, rescheduledJob.getEarliestRunTime());
+ assertEquals(JobStatus.NO_LATEST_RUNTIME, rescheduledJob.getLatestRunTimeElapsed());
+
+ // failure = 0, systemStop = 2
+ rescheduledJob = mService.getRescheduleJobForFailureLocked(rescheduledJob,
+ JobParameters.INTERNAL_STOP_REASON_PREEMPT);
+ // failure = 0, systemStop = 3
+ rescheduledJob = mService.getRescheduleJobForFailureLocked(rescheduledJob,
+ JobParameters.INTERNAL_STOP_REASON_CONSTRAINTS_NOT_SATISFIED);
+ assertEquals(nowElapsed + initialBackoffMs, rescheduledJob.getEarliestRunTime());
+ assertEquals(JobStatus.NO_LATEST_RUNTIME, rescheduledJob.getLatestRunTimeElapsed());
+
+ // failure = 0, systemStop = 2 * SYSTEM_STOP_TO_FAILURE_RATIO
+ for (int i = 0; i < mService.mConstants.SYSTEM_STOP_TO_FAILURE_RATIO; ++i) {
+ rescheduledJob = mService.getRescheduleJobForFailureLocked(rescheduledJob,
+ JobParameters.INTERNAL_STOP_REASON_RTC_UPDATED);
+ }
+ assertEquals(nowElapsed + 2 * initialBackoffMs, rescheduledJob.getEarliestRunTime());
+ assertEquals(JobStatus.NO_LATEST_RUNTIME, rescheduledJob.getLatestRunTimeElapsed());
+
+ // failure = 1, systemStop = 2 * SYSTEM_STOP_TO_FAILURE_RATIO
+ rescheduledJob = mService.getRescheduleJobForFailureLocked(rescheduledJob,
+ JobParameters.INTERNAL_STOP_REASON_TIMEOUT);
+ assertEquals(nowElapsed + 3 * initialBackoffMs, rescheduledJob.getEarliestRunTime());
+ assertEquals(JobStatus.NO_LATEST_RUNTIME, rescheduledJob.getLatestRunTimeElapsed());
+
+ // failure = 2, systemStop = 2 * SYSTEM_STOP_TO_FAILURE_RATIO
+ rescheduledJob = mService.getRescheduleJobForFailureLocked(rescheduledJob,
+ JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH);
+ assertEquals(nowElapsed + 4 * initialBackoffMs, rescheduledJob.getEarliestRunTime());
+ assertEquals(JobStatus.NO_LATEST_RUNTIME, rescheduledJob.getLatestRunTimeElapsed());
+ }
+
/**
* Confirm that {@link JobSchedulerService#getRescheduleJobForPeriodic(JobStatus)} returns a job
* with the correct delay and deadline constraints if the periodic job is scheduled with the
@@ -544,14 +598,16 @@
final long nextWindowEndTime = now + 2 * HOUR_IN_MILLIS;
JobStatus job = createJobStatus("testGetRescheduleJobForPeriodic_insideWindow_failedJob",
createJobInfo().setPeriodic(HOUR_IN_MILLIS));
- JobStatus failedJob = mService.getRescheduleJobForFailureLocked(job);
+ JobStatus failedJob = mService.getRescheduleJobForFailureLocked(job,
+ JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH);
JobStatus rescheduledJob = mService.getRescheduleJobForPeriodic(failedJob);
assertEquals(nextWindowStartTime, rescheduledJob.getEarliestRunTime());
assertEquals(nextWindowEndTime, rescheduledJob.getLatestRunTimeElapsed());
advanceElapsedClock(5 * MINUTE_IN_MILLIS); // now + 5 minutes
- failedJob = mService.getRescheduleJobForFailureLocked(job);
+ failedJob = mService.getRescheduleJobForFailureLocked(job,
+ JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH);
advanceElapsedClock(5 * MINUTE_IN_MILLIS); // now + 10 minutes
rescheduledJob = mService.getRescheduleJobForPeriodic(failedJob);
@@ -559,7 +615,8 @@
assertEquals(nextWindowEndTime, rescheduledJob.getLatestRunTimeElapsed());
advanceElapsedClock(35 * MINUTE_IN_MILLIS); // now + 45 minutes
- failedJob = mService.getRescheduleJobForFailureLocked(job);
+ failedJob = mService.getRescheduleJobForFailureLocked(job,
+ JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH);
advanceElapsedClock(10 * MINUTE_IN_MILLIS); // now + 55 minutes
rescheduledJob = mService.getRescheduleJobForPeriodic(failedJob);
@@ -569,7 +626,8 @@
assertEquals(nextWindowEndTime, rescheduledJob.getLatestRunTimeElapsed());
advanceElapsedClock(2 * MINUTE_IN_MILLIS); // now + 57 minutes
- failedJob = mService.getRescheduleJobForFailureLocked(job);
+ failedJob = mService.getRescheduleJobForFailureLocked(job,
+ JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH);
advanceElapsedClock(2 * MINUTE_IN_MILLIS); // now + 59 minutes
rescheduledJob = mService.getRescheduleJobForPeriodic(failedJob);
@@ -665,7 +723,8 @@
public void testGetRescheduleJobForPeriodic_outsideWindow_failedJob() {
JobStatus job = createJobStatus("testGetRescheduleJobForPeriodic_outsideWindow_failedJob",
createJobInfo().setPeriodic(HOUR_IN_MILLIS));
- JobStatus failedJob = mService.getRescheduleJobForFailureLocked(job);
+ JobStatus failedJob = mService.getRescheduleJobForFailureLocked(job,
+ JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH);
long now = sElapsedRealtimeClock.millis();
long nextWindowStartTime = now + HOUR_IN_MILLIS;
long nextWindowEndTime = now + 2 * HOUR_IN_MILLIS;
@@ -701,7 +760,8 @@
JobStatus job = createJobStatus(
"testGetRescheduleJobForPeriodic_outsideWindow_flex_failedJob",
createJobInfo().setPeriodic(HOUR_IN_MILLIS, 30 * MINUTE_IN_MILLIS));
- JobStatus failedJob = mService.getRescheduleJobForFailureLocked(job);
+ JobStatus failedJob = mService.getRescheduleJobForFailureLocked(job,
+ JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH);
// First window starts 30 minutes from now.
advanceElapsedClock(30 * MINUTE_IN_MILLIS);
long now = sElapsedRealtimeClock.millis();
@@ -742,7 +802,8 @@
JobStatus job = createJobStatus(
"testGetRescheduleJobForPeriodic_outsideWindow_flex_failedJob_longPeriod",
createJobInfo().setPeriodic(7 * DAY_IN_MILLIS, 9 * HOUR_IN_MILLIS));
- JobStatus failedJob = mService.getRescheduleJobForFailureLocked(job);
+ JobStatus failedJob = mService.getRescheduleJobForFailureLocked(job,
+ JobParameters.INTERNAL_STOP_REASON_SUCCESSFUL_FINISH);
// First window starts 6.625 days from now.
advanceElapsedClock(6 * DAY_IN_MILLIS + 15 * HOUR_IN_MILLIS);
long now = sElapsedRealtimeClock.millis();
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/FlexibilityControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/FlexibilityControllerTest.java
index 674e500..3bee687 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/controllers/FlexibilityControllerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/FlexibilityControllerTest.java
@@ -489,19 +489,22 @@
JobInfo.Builder jb = createJob(0).setOverrideDeadline(1000L);
JobStatus js = createJobStatus("time", jb);
js = new JobStatus(
- js, FROZEN_TIME, NO_LATEST_RUNTIME, /* numFailures */ 2, FROZEN_TIME, FROZEN_TIME);
+ js, FROZEN_TIME, NO_LATEST_RUNTIME, /* numFailures */ 2, /* numSystemStops */ 0,
+ FROZEN_TIME, FROZEN_TIME);
assertEquals(mFcConfig.RESCHEDULED_JOB_DEADLINE_MS,
mFlexibilityController.getLifeCycleEndElapsedLocked(js, 0));
js = new JobStatus(
- js, FROZEN_TIME, NO_LATEST_RUNTIME, /* numFailures */ 3, FROZEN_TIME, FROZEN_TIME);
+ js, FROZEN_TIME, NO_LATEST_RUNTIME, /* numFailures */ 2, /* numSystemStops */ 1,
+ FROZEN_TIME, FROZEN_TIME);
assertEquals(2 * mFcConfig.RESCHEDULED_JOB_DEADLINE_MS,
mFlexibilityController.getLifeCycleEndElapsedLocked(js, 0));
js = new JobStatus(
- js, FROZEN_TIME, NO_LATEST_RUNTIME, /* numFailures */ 10, FROZEN_TIME, FROZEN_TIME);
+ js, FROZEN_TIME, NO_LATEST_RUNTIME, /* numFailures */ 0, /* numSystemStops */ 10,
+ FROZEN_TIME, FROZEN_TIME);
assertEquals(mFcConfig.MAX_RESCHEDULED_DEADLINE_MS,
mFlexibilityController.getLifeCycleEndElapsedLocked(js, 0));
}
@@ -637,7 +640,12 @@
JobInfo.Builder jb = createJob(0);
JobStatus js = createJobStatus("time", jb);
js = new JobStatus(
- js, FROZEN_TIME, NO_LATEST_RUNTIME, /* numFailures */ 1, FROZEN_TIME, FROZEN_TIME);
+ js, FROZEN_TIME, NO_LATEST_RUNTIME, /* numFailures */ 1, /* numSystemStops */ 0,
+ FROZEN_TIME, FROZEN_TIME);
+ assertFalse(js.hasFlexibilityConstraint());
+ js = new JobStatus(
+ js, FROZEN_TIME, NO_LATEST_RUNTIME, /* numFailures */ 0, /* numSystemStops */ 1,
+ FROZEN_TIME, FROZEN_TIME);
assertFalse(js.hasFlexibilityConstraint());
}
diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/JobStatusTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/JobStatusTest.java
index 149ae0b..7f522b0 100644
--- a/services/tests/mockingservicestests/src/com/android/server/job/controllers/JobStatusTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/JobStatusTest.java
@@ -248,20 +248,32 @@
// Less than 2 failures, priority shouldn't be affected.
assertEquals(JobInfo.PRIORITY_MAX, job.getEffectivePriority());
- int backoffAttempt = 1;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ int numFailures = 1;
+ int numSystemStops = 0;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_MAX, job.getEffectivePriority());
// 2+ failures, priority should be lowered as much as possible.
- backoffAttempt = 2;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 2;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_HIGH, job.getEffectivePriority());
- backoffAttempt = 5;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 5;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_HIGH, job.getEffectivePriority());
- backoffAttempt = 8;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 8;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_HIGH, job.getEffectivePriority());
+
+ // System stops shouldn't factor in the downgrade.
+ numSystemStops = 10;
+ numFailures = 0;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
+ assertEquals(JobInfo.PRIORITY_MAX, job.getEffectivePriority());
}
@Test
@@ -274,33 +286,48 @@
// Less than 2 failures, priority shouldn't be affected.
assertEquals(JobInfo.PRIORITY_HIGH, job.getEffectivePriority());
- int backoffAttempt = 1;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ int numFailures = 1;
+ int numSystemStops = 0;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_HIGH, job.getEffectivePriority());
// Failures in [2,4), priority should be lowered slightly.
- backoffAttempt = 2;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 2;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_DEFAULT, job.getEffectivePriority());
- backoffAttempt = 3;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 3;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_DEFAULT, job.getEffectivePriority());
// Failures in [4,6), priority should be lowered more.
- backoffAttempt = 4;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 4;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_LOW, job.getEffectivePriority());
- backoffAttempt = 5;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 5;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_LOW, job.getEffectivePriority());
// 6+ failures, priority should be lowered as much as possible.
- backoffAttempt = 6;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 6;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_MIN, job.getEffectivePriority());
- backoffAttempt = 12;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 12;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_MIN, job.getEffectivePriority());
+
+ // System stops shouldn't factor in the downgrade.
+ numSystemStops = 10;
+ numFailures = 0;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
+ assertEquals(JobInfo.PRIORITY_HIGH, job.getEffectivePriority());
}
/**
@@ -317,23 +344,36 @@
// Less than 6 failures, priority shouldn't be affected.
assertEquals(JobInfo.PRIORITY_LOW, job.getEffectivePriority());
- int backoffAttempt = 1;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ int numFailures = 1;
+ int numSystemStops = 0;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_LOW, job.getEffectivePriority());
- backoffAttempt = 4;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 4;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_LOW, job.getEffectivePriority());
- backoffAttempt = 5;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 5;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_LOW, job.getEffectivePriority());
// 6+ failures, priority should be lowered as much as possible.
- backoffAttempt = 6;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 6;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_MIN, job.getEffectivePriority());
- backoffAttempt = 12;
- job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, backoffAttempt, 0, 0);
+ numFailures = 12;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
assertEquals(JobInfo.PRIORITY_MIN, job.getEffectivePriority());
+
+ // System stops shouldn't factor in the downgrade.
+ numSystemStops = 10;
+ numFailures = 0;
+ job = new JobStatus(job, NO_EARLIEST_RUNTIME, NO_LATEST_RUNTIME, numFailures,
+ numSystemStops, 0, 0);
+ assertEquals(JobInfo.PRIORITY_LOW, job.getEffectivePriority());
}
/**
diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/BackgroundDexOptServiceUnitTest.java b/services/tests/mockingservicestests/src/com/android/server/pm/BackgroundDexOptServiceUnitTest.java
index 47f449c..1be7e2e 100644
--- a/services/tests/mockingservicestests/src/com/android/server/pm/BackgroundDexOptServiceUnitTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/pm/BackgroundDexOptServiceUnitTest.java
@@ -223,7 +223,7 @@
/* expectedReschedule= */ false, /* expectedStatus= */ STATUS_OK,
/* totalJobFinishedWithParams= */ 1, /* expectedSkippedPackage= */ null);
runFullJob(mJobServiceForIdle, mJobParametersForIdle,
- /* expectedReschedule= */ true, /* expectedStatus= */ STATUS_OK,
+ /* expectedReschedule= */ false, /* expectedStatus= */ STATUS_OK,
/* totalJobFinishedWithParams= */ 1, /* expectedSkippedPackage= */ null);
}
@@ -241,7 +241,7 @@
assertThat(getFailedPackageNamesSecondary()).isEmpty();
runFullJob(mJobServiceForIdle, mJobParametersForIdle,
- /* expectedReschedule= */ true, /* expectedStatus= */ STATUS_OK,
+ /* expectedReschedule= */ false, /* expectedStatus= */ STATUS_OK,
/* totalJobFinishedWithParams= */ 1, /* expectedSkippedPackage= */ PACKAGE_AAA);
assertThat(getFailedPackageNamesPrimary()).containsExactly(PACKAGE_AAA);
@@ -256,7 +256,7 @@
mDexOptResultForPackageAAA = PackageDexOptimizer.DEX_OPT_PERFORMED;
runFullJob(mJobServiceForIdle, mJobParametersForIdle,
- /* expectedReschedule= */ true, /* expectedStatus= */ STATUS_OK,
+ /* expectedReschedule= */ false, /* expectedStatus= */ STATUS_OK,
/* totalJobFinishedWithParams= */ 2, /* expectedSkippedPackage= */ null);
assertThat(getFailedPackageNamesPrimary()).isEmpty();
@@ -393,7 +393,7 @@
mCancelThread.join(TEST_WAIT_TIMEOUT_MS);
// Always reschedule for periodic job
- verify(mJobServiceForIdle).jobFinished(mJobParametersForIdle, true);
+ verify(mJobServiceForIdle).jobFinished(mJobParametersForIdle, false);
verifyLastControlDexOptBlockingCall(false);
}
@@ -421,7 +421,7 @@
mCancelThread.join(TEST_WAIT_TIMEOUT_MS);
// Always reschedule for periodic job
- verify(mJobServiceForIdle).jobFinished(mJobParametersForIdle, true);
+ verify(mJobServiceForIdle).jobFinished(mJobParametersForIdle, false);
verify(mDexOptHelper, never()).controlDexOptBlocking(true);
}
diff --git a/services/tests/mockingservicestests/src/com/android/server/tare/AgentTrendCalculatorTest.java b/services/tests/mockingservicestests/src/com/android/server/tare/AgentTrendCalculatorTest.java
index 2fac31e..d477cb6 100644
--- a/services/tests/mockingservicestests/src/com/android/server/tare/AgentTrendCalculatorTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/tare/AgentTrendCalculatorTest.java
@@ -73,7 +73,12 @@
}
@Override
- long getHardSatiatedConsumptionLimit() {
+ long getMinSatiatedConsumptionLimit() {
+ return 0;
+ }
+
+ @Override
+ long getMaxSatiatedConsumptionLimit() {
return 0;
}
diff --git a/services/tests/mockingservicestests/src/com/android/server/tare/AlarmManagerEconomicPolicyTest.java b/services/tests/mockingservicestests/src/com/android/server/tare/AlarmManagerEconomicPolicyTest.java
index fb3e8f2..84a61c7 100644
--- a/services/tests/mockingservicestests/src/com/android/server/tare/AlarmManagerEconomicPolicyTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/tare/AlarmManagerEconomicPolicyTest.java
@@ -132,8 +132,10 @@
public void testDefaults() {
assertEquals(EconomyManager.DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT_CAKES,
mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(EconomyManager.DEFAULT_AM_HARD_CONSUMPTION_LIMIT_CAKES,
- mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(EconomyManager.DEFAULT_AM_MIN_CONSUMPTION_LIMIT_CAKES,
+ mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(EconomyManager.DEFAULT_AM_MAX_CONSUMPTION_LIMIT_CAKES,
+ mEconomicPolicy.getMaxSatiatedConsumptionLimit());
final String pkgRestricted = "com.pkg.restricted";
when(mIrs.isPackageRestricted(anyInt(), eq(pkgRestricted))).thenReturn(true);
assertEquals(0, mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
@@ -150,13 +152,15 @@
@Test
public void testConstantsUpdating_ValidValues() {
setDeviceConfigCakes(EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT, arcToCake(5));
- setDeviceConfigCakes(EconomyManager.KEY_AM_HARD_CONSUMPTION_LIMIT, arcToCake(25));
+ setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_CONSUMPTION_LIMIT, arcToCake(3));
+ setDeviceConfigCakes(EconomyManager.KEY_AM_MAX_CONSUMPTION_LIMIT, arcToCake(25));
setDeviceConfigCakes(EconomyManager.KEY_AM_MAX_SATIATED_BALANCE, arcToCake(10));
setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED, arcToCake(9));
setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP, arcToCake(7));
assertEquals(arcToCake(5), mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(arcToCake(25), mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(arcToCake(3), mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(arcToCake(25), mEconomicPolicy.getMaxSatiatedConsumptionLimit());
final String pkgRestricted = "com.pkg.restricted";
when(mIrs.isPackageRestricted(anyInt(), eq(pkgRestricted))).thenReturn(true);
assertEquals(arcToCake(0), mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
@@ -171,13 +175,15 @@
public void testConstantsUpdating_InvalidValues() {
// Test negatives.
setDeviceConfigCakes(EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT, arcToCake(-5));
- setDeviceConfigCakes(EconomyManager.KEY_AM_HARD_CONSUMPTION_LIMIT, arcToCake(-5));
+ setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_CONSUMPTION_LIMIT, arcToCake(-5));
+ setDeviceConfigCakes(EconomyManager.KEY_AM_MAX_CONSUMPTION_LIMIT, arcToCake(-5));
setDeviceConfigCakes(EconomyManager.KEY_AM_MAX_SATIATED_BALANCE, arcToCake(-1));
setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED, arcToCake(-2));
setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP, arcToCake(-3));
assertEquals(arcToCake(1), mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(arcToCake(1), mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(arcToCake(1), mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(arcToCake(1), mEconomicPolicy.getMaxSatiatedConsumptionLimit());
final String pkgRestricted = "com.pkg.restricted";
when(mIrs.isPackageRestricted(anyInt(), eq(pkgRestricted))).thenReturn(true);
assertEquals(arcToCake(0), mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
@@ -188,14 +194,16 @@
assertEquals(arcToCake(0), mEconomicPolicy.getMinSatiatedBalance(0, "com.any.other.app"));
// Test min+max reversed.
- setDeviceConfigCakes(EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT, arcToCake(5));
- setDeviceConfigCakes(EconomyManager.KEY_AM_HARD_CONSUMPTION_LIMIT, arcToCake(3));
+ setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_CONSUMPTION_LIMIT, arcToCake(5));
+ setDeviceConfigCakes(EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT, arcToCake(4));
+ setDeviceConfigCakes(EconomyManager.KEY_AM_MAX_CONSUMPTION_LIMIT, arcToCake(3));
setDeviceConfigCakes(EconomyManager.KEY_AM_MAX_SATIATED_BALANCE, arcToCake(10));
setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED, arcToCake(11));
setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP, arcToCake(13));
assertEquals(arcToCake(5), mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(arcToCake(5), mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(arcToCake(5), mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(arcToCake(5), mEconomicPolicy.getMaxSatiatedConsumptionLimit());
assertEquals(arcToCake(0), mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
assertEquals(arcToCake(13), mEconomicPolicy.getMaxSatiatedBalance(0, "com.any.other.app"));
assertEquals(arcToCake(13), mEconomicPolicy.getMinSatiatedBalance(0, pkgExempted));
diff --git a/services/tests/mockingservicestests/src/com/android/server/tare/CompleteEconomicPolicyTest.java b/services/tests/mockingservicestests/src/com/android/server/tare/CompleteEconomicPolicyTest.java
index 6da4ab7..cad608f 100644
--- a/services/tests/mockingservicestests/src/com/android/server/tare/CompleteEconomicPolicyTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/tare/CompleteEconomicPolicyTest.java
@@ -155,9 +155,12 @@
assertEquals(EconomyManager.DEFAULT_JS_INITIAL_CONSUMPTION_LIMIT_CAKES
+ EconomyManager.DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT_CAKES,
mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(EconomyManager.DEFAULT_JS_HARD_CONSUMPTION_LIMIT_CAKES
- + EconomyManager.DEFAULT_AM_HARD_CONSUMPTION_LIMIT_CAKES,
- mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(EconomyManager.DEFAULT_JS_MIN_CONSUMPTION_LIMIT_CAKES
+ + EconomyManager.DEFAULT_AM_MIN_CONSUMPTION_LIMIT_CAKES,
+ mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(EconomyManager.DEFAULT_JS_MAX_CONSUMPTION_LIMIT_CAKES
+ + EconomyManager.DEFAULT_AM_MAX_CONSUMPTION_LIMIT_CAKES,
+ mEconomicPolicy.getMaxSatiatedConsumptionLimit());
final String pkgRestricted = "com.pkg.restricted";
when(mIrs.isPackageRestricted(anyInt(), eq(pkgRestricted))).thenReturn(true);
assertEquals(0, mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
@@ -178,8 +181,10 @@
public void testConstantsUpdated() {
setDeviceConfigCakes(EconomyManager.KEY_JS_INITIAL_CONSUMPTION_LIMIT, arcToCake(4));
setDeviceConfigCakes(EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT, arcToCake(6));
- setDeviceConfigCakes(EconomyManager.KEY_JS_HARD_CONSUMPTION_LIMIT, arcToCake(24));
- setDeviceConfigCakes(EconomyManager.KEY_AM_HARD_CONSUMPTION_LIMIT, arcToCake(26));
+ setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_CONSUMPTION_LIMIT, arcToCake(2));
+ setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_CONSUMPTION_LIMIT, arcToCake(3));
+ setDeviceConfigCakes(EconomyManager.KEY_JS_MAX_CONSUMPTION_LIMIT, arcToCake(24));
+ setDeviceConfigCakes(EconomyManager.KEY_AM_MAX_CONSUMPTION_LIMIT, arcToCake(26));
setDeviceConfigCakes(EconomyManager.KEY_JS_MAX_SATIATED_BALANCE, arcToCake(9));
setDeviceConfigCakes(EconomyManager.KEY_AM_MAX_SATIATED_BALANCE, arcToCake(11));
setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_EXEMPTED, arcToCake(8));
@@ -188,7 +193,8 @@
setDeviceConfigCakes(EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP, arcToCake(2));
assertEquals(arcToCake(10), mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(arcToCake(50), mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(arcToCake(5), mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(arcToCake(50), mEconomicPolicy.getMaxSatiatedConsumptionLimit());
final String pkgRestricted = "com.pkg.restricted";
when(mIrs.isPackageRestricted(anyInt(), eq(pkgRestricted))).thenReturn(true);
assertEquals(arcToCake(0), mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
@@ -206,8 +212,10 @@
setDeviceConfigBoolean(EconomyManager.KEY_ENABLE_POLICY_JOB_SCHEDULER, false);
assertEquals(EconomyManager.DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT_CAKES,
mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(EconomyManager.DEFAULT_AM_HARD_CONSUMPTION_LIMIT_CAKES,
- mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(EconomyManager.DEFAULT_AM_MIN_CONSUMPTION_LIMIT_CAKES,
+ mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(EconomyManager.DEFAULT_AM_MAX_CONSUMPTION_LIMIT_CAKES,
+ mEconomicPolicy.getMaxSatiatedConsumptionLimit());
final String pkgRestricted = "com.pkg.restricted";
when(mIrs.isPackageRestricted(anyInt(), eq(pkgRestricted))).thenReturn(true);
assertEquals(0, mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
@@ -229,8 +237,10 @@
setDeviceConfigBoolean(EconomyManager.KEY_ENABLE_POLICY_JOB_SCHEDULER, true);
assertEquals(EconomyManager.DEFAULT_JS_INITIAL_CONSUMPTION_LIMIT_CAKES,
mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(EconomyManager.DEFAULT_JS_HARD_CONSUMPTION_LIMIT_CAKES,
- mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(EconomyManager.DEFAULT_JS_MIN_CONSUMPTION_LIMIT_CAKES,
+ mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(EconomyManager.DEFAULT_JS_MAX_CONSUMPTION_LIMIT_CAKES,
+ mEconomicPolicy.getMaxSatiatedConsumptionLimit());
when(mIrs.isPackageRestricted(anyInt(), eq(pkgRestricted))).thenReturn(true);
assertEquals(0, mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
assertEquals(EconomyManager.DEFAULT_JS_MAX_SATIATED_BALANCE_CAKES,
diff --git a/services/tests/mockingservicestests/src/com/android/server/tare/JobSchedulerEconomicPolicyTest.java b/services/tests/mockingservicestests/src/com/android/server/tare/JobSchedulerEconomicPolicyTest.java
index b7bbcd75..ebf760c 100644
--- a/services/tests/mockingservicestests/src/com/android/server/tare/JobSchedulerEconomicPolicyTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/tare/JobSchedulerEconomicPolicyTest.java
@@ -132,8 +132,10 @@
public void testDefaults() {
assertEquals(EconomyManager.DEFAULT_JS_INITIAL_CONSUMPTION_LIMIT_CAKES,
mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(EconomyManager.DEFAULT_JS_HARD_CONSUMPTION_LIMIT_CAKES,
- mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(EconomyManager.DEFAULT_JS_MIN_CONSUMPTION_LIMIT_CAKES,
+ mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(EconomyManager.DEFAULT_JS_MAX_CONSUMPTION_LIMIT_CAKES,
+ mEconomicPolicy.getMaxSatiatedConsumptionLimit());
final String pkgRestricted = "com.pkg.restricted";
when(mIrs.isPackageRestricted(anyInt(), eq(pkgRestricted))).thenReturn(true);
@@ -171,7 +173,8 @@
@Test
public void testConstantsUpdating_ValidValues() {
setDeviceConfigCakes(EconomyManager.KEY_JS_INITIAL_CONSUMPTION_LIMIT, arcToCake(5));
- setDeviceConfigCakes(EconomyManager.KEY_JS_HARD_CONSUMPTION_LIMIT, arcToCake(25));
+ setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_CONSUMPTION_LIMIT, arcToCake(2));
+ setDeviceConfigCakes(EconomyManager.KEY_JS_MAX_CONSUMPTION_LIMIT, arcToCake(25));
setDeviceConfigCakes(EconomyManager.KEY_JS_MAX_SATIATED_BALANCE, arcToCake(10));
setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_EXEMPTED, arcToCake(6));
setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_OTHER_APP, arcToCake(4));
@@ -179,7 +182,8 @@
arcToCake(1));
assertEquals(arcToCake(5), mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(arcToCake(25), mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(arcToCake(2), mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(arcToCake(25), mEconomicPolicy.getMaxSatiatedConsumptionLimit());
final String pkgRestricted = "com.pkg.restricted";
when(mIrs.isPackageRestricted(anyInt(), eq(pkgRestricted))).thenReturn(true);
assertEquals(arcToCake(0), mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
@@ -198,7 +202,8 @@
public void testConstantsUpdating_InvalidValues() {
// Test negatives.
setDeviceConfigCakes(EconomyManager.KEY_JS_INITIAL_CONSUMPTION_LIMIT, arcToCake(-5));
- setDeviceConfigCakes(EconomyManager.KEY_JS_HARD_CONSUMPTION_LIMIT, arcToCake(-5));
+ setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_CONSUMPTION_LIMIT, arcToCake(-5));
+ setDeviceConfigCakes(EconomyManager.KEY_JS_MAX_CONSUMPTION_LIMIT, arcToCake(-5));
setDeviceConfigCakes(EconomyManager.KEY_JS_MAX_SATIATED_BALANCE, arcToCake(-1));
setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_EXEMPTED, arcToCake(-2));
setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_OTHER_APP, arcToCake(-3));
@@ -206,7 +211,8 @@
arcToCake(-4));
assertEquals(arcToCake(1), mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(arcToCake(1), mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(arcToCake(1), mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(arcToCake(1), mEconomicPolicy.getMaxSatiatedConsumptionLimit());
final String pkgRestricted = "com.pkg.restricted";
when(mIrs.isPackageRestricted(anyInt(), eq(pkgRestricted))).thenReturn(true);
assertEquals(arcToCake(0), mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
@@ -221,14 +227,16 @@
mEconomicPolicy.getMinSatiatedBalance(0, pkgUpdater));
// Test min+max reversed.
- setDeviceConfigCakes(EconomyManager.KEY_JS_INITIAL_CONSUMPTION_LIMIT, arcToCake(5));
- setDeviceConfigCakes(EconomyManager.KEY_JS_HARD_CONSUMPTION_LIMIT, arcToCake(3));
+ setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_CONSUMPTION_LIMIT, arcToCake(5));
+ setDeviceConfigCakes(EconomyManager.KEY_JS_INITIAL_CONSUMPTION_LIMIT, arcToCake(4));
+ setDeviceConfigCakes(EconomyManager.KEY_JS_MAX_CONSUMPTION_LIMIT, arcToCake(3));
setDeviceConfigCakes(EconomyManager.KEY_JS_MAX_SATIATED_BALANCE, arcToCake(10));
setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_EXEMPTED, arcToCake(11));
setDeviceConfigCakes(EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_OTHER_APP, arcToCake(13));
assertEquals(arcToCake(5), mEconomicPolicy.getInitialSatiatedConsumptionLimit());
- assertEquals(arcToCake(5), mEconomicPolicy.getHardSatiatedConsumptionLimit());
+ assertEquals(arcToCake(5), mEconomicPolicy.getMinSatiatedConsumptionLimit());
+ assertEquals(arcToCake(5), mEconomicPolicy.getMaxSatiatedConsumptionLimit());
assertEquals(arcToCake(0), mEconomicPolicy.getMaxSatiatedBalance(0, pkgRestricted));
assertEquals(arcToCake(13), mEconomicPolicy.getMaxSatiatedBalance(0, "com.any.other.app"));
assertEquals(arcToCake(13), mEconomicPolicy.getMinSatiatedBalance(0, pkgExempted));
diff --git a/services/tests/servicestests/src/com/android/server/pm/AppsFilterImplTest.java b/services/tests/servicestests/src/com/android/server/pm/AppsFilterImplTest.java
index c321639..1a8ef9e 100644
--- a/services/tests/servicestests/src/com/android/server/pm/AppsFilterImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/AppsFilterImplTest.java
@@ -387,7 +387,7 @@
// delete user
when(mSnapshot.getUserInfos()).thenReturn(USER_INFO_LIST);
- appsFilter.onUserDeleted(ADDED_USER);
+ appsFilter.onUserDeleted(mSnapshot, ADDED_USER);
for (int subjectUserId : USER_ARRAY) {
for (int otherUserId : USER_ARRAY) {
@@ -925,7 +925,7 @@
assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_OVERLAY_APPID,
overlaySetting, actorSetting, SYSTEM_USER));
- appsFilter.removePackage(mSnapshot, targetSetting, false /* isReplace */);
+ appsFilter.removePackage(mSnapshot, targetSetting);
// Actor loses visibility to the overlay via removal of the target
assertTrue(appsFilter.shouldFilterApplication(mSnapshot, DUMMY_ACTOR_APPID, actorSetting,
@@ -1267,7 +1267,7 @@
watcher.verifyNoChangeReported("get");
// remove a package
- appsFilter.removePackage(mSnapshot, seesNothing, false /* isReplace */);
+ appsFilter.removePackage(mSnapshot, seesNothing);
watcher.verifyChangeReported("removePackage");
}
@@ -1337,7 +1337,7 @@
target.getPackageName()));
// New changes don't affect the snapshot
- appsFilter.removePackage(mSnapshot, target, false);
+ appsFilter.removePackage(mSnapshot, target);
assertTrue(
appsFilter.shouldFilterApplication(mSnapshot, DUMMY_CALLING_APPID, instrumentation,
target,
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index d314a65..2c7867c 100644
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -1147,8 +1147,12 @@
"carrier_data_call_apn_retry_after_disconnect_long";
/**
- * Data call setup permanent failure causes by the carrier
+ * Data call setup permanent failure causes by the carrier.
+ *
+ * @deprecated This API key was added in mistake and is not used anymore by the telephony data
+ * frameworks.
*/
+ @Deprecated
public static final String KEY_CARRIER_DATA_CALL_PERMANENT_FAILURE_STRINGS =
"carrier_data_call_permanent_failure_strings";
@@ -2103,6 +2107,16 @@
* is immediately closed (disabling keep-alive).
*/
public static final String KEY_MMS_CLOSE_CONNECTION_BOOL = "mmsCloseConnection";
+ /**
+ * Waiting time in milliseconds used before releasing an MMS data call. Not tearing down an MMS
+ * data connection immediately helps to reduce the message delivering latency if messaging
+ * continues between all parties in the conversation since the same data connection can be
+ * reused for further messages.
+ *
+ * This timer will control how long the data call will be kept alive before being torn down.
+ */
+ public static final String KEY_MMS_NETWORK_RELEASE_TIMEOUT_MILLIS_INT =
+ "mms_network_release_timeout_millis_int";
/**
* The flatten {@link android.content.ComponentName componentName} of the activity that can
@@ -8436,7 +8450,8 @@
*
* The syntax of the retry rule:
* 1. Retry based on {@link NetworkCapabilities}. Note that only APN-type network capabilities
- * are supported.
+ * are supported. If the capabilities are not specified, then the retry rule only applies
+ * to the current failed APN used in setup data call request.
* "capabilities=[netCaps1|netCaps2|...], [retry_interval=n1|n2|n3|n4...], [maximum_retries=n]"
*
* 2. Retry based on {@link DataFailCause}
@@ -8447,15 +8462,16 @@
* "capabilities=[netCaps1|netCaps2|...], fail_causes=[cause1|cause2|cause3|...],
* [retry_interval=n1|n2|n3|n4...], [maximum_retries=n]"
*
+ * 4. Permanent fail causes (no timer-based retry) on the current failed APN. Retry interval
+ * is specified for retrying the next available APN.
+ * "permanent_fail_causes=8|27|28|29|30|32|33|35|50|51|111|-5|-6|65537|65538|-3|65543|65547|
+ * 2252|2253|2254, retry_interval=2500"
+ *
* For example,
* "capabilities=eims, retry_interval=1000, maximum_retries=20" means if the attached
* network request is emergency, then retry data network setup every 1 second for up to 20
* times.
*
- * "fail_causes=8|27|28|29|30|32|33|35|50|51|111|-5|-6|65537|65538|-3|2253|2254
- * , maximum_retries=0" means for those fail causes, never retry with timers. Note that
- * when environment changes, retry can still happen.
- *
* "capabilities=internet|enterprise|dun|ims|fota, retry_interval=2500|3000|"
* "5000|10000|15000|20000|40000|60000|120000|240000|600000|1200000|1800000"
* "1800000, maximum_retries=20" means for those capabilities, retry happens in 2.5s, 3s, 5s,
@@ -9069,6 +9085,7 @@
sDefaults.putInt(KEY_MMS_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD_INT, -1);
sDefaults.putInt(KEY_MMS_SMS_TO_MMS_TEXT_THRESHOLD_INT, -1);
sDefaults.putInt(KEY_MMS_SUBJECT_MAX_LENGTH_INT, 40);
+ sDefaults.putInt(KEY_MMS_NETWORK_RELEASE_TIMEOUT_MILLIS_INT, 5 * 1000);
sDefaults.putString(KEY_MMS_EMAIL_GATEWAY_NUMBER_STRING, "");
sDefaults.putString(KEY_MMS_HTTP_PARAMS_STRING, "");
sDefaults.putString(KEY_MMS_NAI_SUFFIX_STRING, "");
@@ -9432,8 +9449,13 @@
sDefaults.putStringArray(
KEY_TELEPHONY_DATA_SETUP_RETRY_RULES_STRING_ARRAY, new String[] {
"capabilities=eims, retry_interval=1000, maximum_retries=20",
- "fail_causes=8|27|28|29|30|32|33|35|50|51|111|-5|-6|65537|65538|-3|2252|"
- + "2253|2254, maximum_retries=0", // No retry for those causes
+ // Permanent fail causes. When setup data call fails with the following
+ // fail causes, telephony data frameworks will stop timer-based retry on
+ // the failed APN until power cycle, APM, or some special events. Note that
+ // even timer-based retry is not performed, condition-based (RAT changes,
+ // registration state changes) retry can still happen.
+ "permanent_fail_causes=8|27|28|29|30|32|33|35|50|51|111|-5|-6|65537|65538|"
+ + "-3|65543|65547|2252|2253|2254, retry_interval=2500",
"capabilities=mms|supl|cbs, retry_interval=2000",
"capabilities=internet|enterprise|dun|ims|fota, retry_interval=2500|3000|"
+ "5000|10000|15000|20000|40000|60000|120000|240000|"
diff --git a/telephony/java/android/telephony/SmsManager.java b/telephony/java/android/telephony/SmsManager.java
index d670e55..1f301c1 100644
--- a/telephony/java/android/telephony/SmsManager.java
+++ b/telephony/java/android/telephony/SmsManager.java
@@ -2268,7 +2268,21 @@
RESULT_RIL_SIM_ABSENT,
RESULT_RIL_SIMULTANEOUS_SMS_AND_CALL_NOT_ALLOWED,
RESULT_RIL_ACCESS_BARRED,
- RESULT_RIL_BLOCKED_DUE_TO_CALL
+ RESULT_RIL_BLOCKED_DUE_TO_CALL,
+ RESULT_RIL_GENERIC_ERROR,
+ RESULT_RIL_INVALID_RESPONSE,
+ RESULT_RIL_SIM_PIN2,
+ RESULT_RIL_SIM_PUK2,
+ RESULT_RIL_SUBSCRIPTION_NOT_AVAILABLE,
+ RESULT_RIL_SIM_ERROR,
+ RESULT_RIL_INVALID_SIM_STATE,
+ RESULT_RIL_NO_SMS_TO_ACK,
+ RESULT_RIL_SIM_BUSY,
+ RESULT_RIL_SIM_FULL,
+ RESULT_RIL_NO_SUBSCRIPTION,
+ RESULT_RIL_NO_NETWORK_FOUND,
+ RESULT_RIL_DEVICE_IN_USE,
+ RESULT_RIL_ABORTED
})
@Retention(RetentionPolicy.SOURCE)
public @interface Result {}
@@ -2534,7 +2548,7 @@
public static final int RESULT_RIL_SIM_ABSENT = 120;
/**
- * 1X voice and SMS are not allowed simulteneously.
+ * 1X voice and SMS are not allowed simultaneously.
*/
public static final int RESULT_RIL_SIMULTANEOUS_SMS_AND_CALL_NOT_ALLOWED = 121;
@@ -2553,6 +2567,73 @@
*/
public static final int RESULT_RIL_GENERIC_ERROR = 124;
+ /**
+ * A RIL internal error when one of the RIL layers receives an unrecognized response from a
+ * lower layer.
+ */
+ public static final int RESULT_RIL_INVALID_RESPONSE = 125;
+
+ /**
+ * Operation requires SIM PIN2 to be entered
+ */
+ public static final int RESULT_RIL_SIM_PIN2 = 126;
+
+ /**
+ * Operation requires SIM PUK2 to be entered
+ */
+ public static final int RESULT_RIL_SIM_PUK2 = 127;
+
+ /**
+ * Fail to find CDMA subscription from specified location
+ */
+ public static final int RESULT_RIL_SUBSCRIPTION_NOT_AVAILABLE = 128;
+
+ /**
+ * Received error from SIM card
+ */
+ public static final int RESULT_RIL_SIM_ERROR = 129;
+
+ /**
+ * Cannot process the request in current SIM state
+ */
+ public static final int RESULT_RIL_INVALID_SIM_STATE = 130;
+
+ /**
+ * ACK received when there is no SMS to ack
+ */
+ public static final int RESULT_RIL_NO_SMS_TO_ACK = 131;
+
+ /**
+ * SIM is busy
+ */
+ public static final int RESULT_RIL_SIM_BUSY = 132;
+
+ /**
+ * The target EF is full
+ */
+ public static final int RESULT_RIL_SIM_FULL = 133;
+
+ /**
+ * Device does not have subscription
+ */
+ public static final int RESULT_RIL_NO_SUBSCRIPTION = 134;
+
+ /**
+ * Network cannot be found
+ */
+ public static final int RESULT_RIL_NO_NETWORK_FOUND = 135;
+
+ /**
+ * Operation cannot be performed because the device is currently in use
+ */
+ public static final int RESULT_RIL_DEVICE_IN_USE = 136;
+
+ /**
+ * Operation aborted
+ */
+ public static final int RESULT_RIL_ABORTED = 137;
+
+
// SMS receiving results sent as a "result" extra in {@link Intents.SMS_REJECTED_ACTION}
/**
diff --git a/telephony/java/com/android/internal/telephony/RILConstants.java b/telephony/java/com/android/internal/telephony/RILConstants.java
index 9892671..9f612e6 100644
--- a/telephony/java/com/android/internal/telephony/RILConstants.java
+++ b/telephony/java/com/android/internal/telephony/RILConstants.java
@@ -536,6 +536,12 @@
int RIL_REQUEST_TRIGGER_EMERGENCY_NETWORK_SCAN = 230;
int RIL_REQUEST_CANCEL_EMERGENCY_NETWORK_SCAN = 231;
int RIL_REQUEST_EXIT_EMERGENCY_MODE = 232;
+ int RIL_REQUEST_SET_SRVCC_CALL_INFO = 233;
+ int RIL_REQUEST_UPDATE_IMS_REGISTRATION_INFO = 234;
+ int RIL_REQUEST_START_IMS_TRAFFIC = 235;
+ int RIL_REQUEST_STOP_IMS_TRAFFIC = 236;
+ int RIL_REQUEST_SEND_ANBR_QUERY = 237;
+ int RIL_REQUEST_TRIGGER_EPS_FALLBACK = 238;
/* Responses begin */
int RIL_RESPONSE_ACKNOWLEDGEMENT = 800;
@@ -607,4 +613,7 @@
int RIL_UNSOL_REGISTRATION_FAILED = 1104;
int RIL_UNSOL_BARRING_INFO_CHANGED = 1105;
int RIL_UNSOL_EMERGENCY_NETWORK_SCAN_RESULT = 1106;
+ int RIL_UNSOL_TRIGGER_IMS_DEREGISTRATION = 1107;
+ int RIL_UNSOL_CONNECTION_SETUP_FAILURE = 1108;
+ int RIL_UNSOL_NOTIFY_ANBR = 1109;
}
diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppAfterCameraTest_ShellTransit.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppAfterCameraTest_ShellTransit.kt
index 0837c00..5686965 100644
--- a/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppAfterCameraTest_ShellTransit.kt
+++ b/tests/FlickerTests/src/com/android/server/wm/flicker/launch/OpenAppAfterCameraTest_ShellTransit.kt
@@ -44,7 +44,7 @@
OpenAppAfterCameraTest(testSpec) {
@Before
override fun before() {
- Assume.assumeFalse(isShellTransitionsEnabled)
+ Assume.assumeTrue(isShellTransitionsEnabled)
}
@FlakyTest