summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/timezonedetector/TimeZoneDetector.java2
-rw-r--r--services/core/java/com/android/server/pm/OtaDexoptService.java11
-rw-r--r--services/core/java/com/android/server/pm/PackageInstallerService.java11
-rw-r--r--services/core/java/com/android/server/pm/StagingManager.java15
-rw-r--r--services/core/java/com/android/server/timedetector/TimeDetectorService.java5
-rw-r--r--services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java13
-rw-r--r--services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java7
-rw-r--r--services/core/java/com/android/server/timezonedetector/ArrayMapWithHistory.java2
-rw-r--r--services/core/java/com/android/server/timezonedetector/Dumpable.java13
-rw-r--r--services/core/java/com/android/server/timezonedetector/ReferenceWithHistory.java3
-rw-r--r--services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternal.java2
-rw-r--r--services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternalImpl.java2
-rw-r--r--services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java9
-rw-r--r--services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategy.java14
-rw-r--r--services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java9
-rw-r--r--services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java7
-rw-r--r--services/tests/servicestests/src/com/android/server/timezonedetector/FakeTimeZoneDetectorStrategy.java (renamed from services/tests/servicestests/src/com/android/server/timezonedetector/StubbedTimeZoneDetectorStrategy.java)7
-rw-r--r--services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorInternalImplTest.java8
-rw-r--r--services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java37
-rw-r--r--services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java119
-rw-r--r--tests/StagedInstallTest/src/com/android/tests/stagedinstallinternal/host/StagedInstallInternalTest.java13
21 files changed, 162 insertions, 147 deletions
diff --git a/core/java/android/app/timezonedetector/TimeZoneDetector.java b/core/java/android/app/timezonedetector/TimeZoneDetector.java
index 786acba94ef4..621ef526aacf 100644
--- a/core/java/android/app/timezonedetector/TimeZoneDetector.java
+++ b/core/java/android/app/timezonedetector/TimeZoneDetector.java
@@ -29,7 +29,7 @@ import android.content.Context;
@SystemService(Context.TIME_ZONE_DETECTOR_SERVICE)
public interface TimeZoneDetector {
- /**
+ /**
* Returns the current user's time zone capabilities. See {@link TimeZoneCapabilities}.
*/
@RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
diff --git a/services/core/java/com/android/server/pm/OtaDexoptService.java b/services/core/java/com/android/server/pm/OtaDexoptService.java
index 2df4a920d5c2..eddab76de5ee 100644
--- a/services/core/java/com/android/server/pm/OtaDexoptService.java
+++ b/services/core/java/com/android/server/pm/OtaDexoptService.java
@@ -18,6 +18,7 @@ package com.android.server.pm;
import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
import static com.android.server.pm.InstructionSets.getDexCodeInstructionSets;
+import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
import android.annotation.Nullable;
import android.content.Context;
@@ -42,10 +43,9 @@ import java.io.FileDescriptor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.TimeUnit;
+import java.util.function.Predicate;
/**
* A service for A/B OTA dexopting.
@@ -123,15 +123,20 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
}
final List<PackageSetting> important;
final List<PackageSetting> others;
+ Predicate<PackageSetting> isPlatformPackage = pkgSetting ->
+ PLATFORM_PACKAGE_NAME.equals(pkgSetting.pkg.getPackageName());
synchronized (mPackageManagerService.mLock) {
// Important: the packages we need to run with ab-ota compiler-reason.
important = PackageManagerServiceUtils.getPackagesForDexopt(
mPackageManagerService.mSettings.mPackages.values(), mPackageManagerService,
DEBUG_DEXOPT);
+ // Remove Platform Package from A/B OTA b/160735835.
+ important.removeIf(isPlatformPackage);
// Others: we should optimize this with the (first-)boot compiler-reason.
others = new ArrayList<>(mPackageManagerService.mSettings.mPackages.values());
others.removeAll(important);
others.removeIf(PackageManagerServiceUtils.REMOVE_IF_NULL_PKG);
+ others.removeIf(isPlatformPackage);
// Pre-size the array list by over-allocating by a factor of 1.5.
mDexoptCommands = new ArrayList<>(3 * mPackageManagerService.mPackages.size() / 2);
@@ -147,7 +152,7 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
throw new IllegalStateException("Found a core app that's not important");
}
mDexoptCommands.addAll(generatePackageDexopts(pkgSetting.pkg, pkgSetting,
- PackageManagerService.REASON_FIRST_BOOT));
+ PackageManagerService.REASON_FIRST_BOOT));
}
completeSize = mDexoptCommands.size();
diff --git a/services/core/java/com/android/server/pm/PackageInstallerService.java b/services/core/java/com/android/server/pm/PackageInstallerService.java
index 07f756771326..ddc5e14bfeb3 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerService.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerService.java
@@ -869,7 +869,16 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
@Override
public ParceledListSlice<SessionInfo> getStagedSessions() {
- return mStagingManager.getSessions(Binder.getCallingUid());
+ final List<SessionInfo> result = new ArrayList<>();
+ synchronized (mSessions) {
+ for (int i = 0; i < mSessions.size(); i++) {
+ final PackageInstallerSession session = mSessions.valueAt(i);
+ if (session.isStaged() && !session.isDestroyed()) {
+ result.add(session.generateInfoForCaller(false, Binder.getCallingUid()));
+ }
+ }
+ }
+ return new ParceledListSlice<>(result);
}
@Override
diff --git a/services/core/java/com/android/server/pm/StagingManager.java b/services/core/java/com/android/server/pm/StagingManager.java
index 53a3904ed8c1..14da9aa14470 100644
--- a/services/core/java/com/android/server/pm/StagingManager.java
+++ b/services/core/java/com/android/server/pm/StagingManager.java
@@ -38,7 +38,6 @@ import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageParser.PackageParserException;
import android.content.pm.PackageParser.SigningDetails;
import android.content.pm.PackageParser.SigningDetails.SignatureSchemeVersion;
-import android.content.pm.ParceledListSlice;
import android.content.pm.parsing.PackageInfoWithoutStateUtils;
import android.content.rollback.RollbackInfo;
import android.content.rollback.RollbackManager;
@@ -184,20 +183,6 @@ public class StagingManager {
mApexManager.markBootCompleted();
}
- ParceledListSlice<PackageInstaller.SessionInfo> getSessions(int callingUid) {
- final List<PackageInstaller.SessionInfo> result = new ArrayList<>();
- synchronized (mStagedSessions) {
- for (int i = 0; i < mStagedSessions.size(); i++) {
- final PackageInstallerSession stagedSession = mStagedSessions.valueAt(i);
- if (stagedSession.isDestroyed()) {
- continue;
- }
- result.add(stagedSession.generateInfoForCaller(false /*icon*/, callingUid));
- }
- }
- return new ParceledListSlice<>(result);
- }
-
/**
* Validates the signature used to sign the container of the new apex package
*
diff --git a/services/core/java/com/android/server/timedetector/TimeDetectorService.java b/services/core/java/com/android/server/timedetector/TimeDetectorService.java
index 32f8da8d4a77..3406bd99c883 100644
--- a/services/core/java/com/android/server/timedetector/TimeDetectorService.java
+++ b/services/core/java/com/android/server/timedetector/TimeDetectorService.java
@@ -28,6 +28,7 @@ import android.database.ContentObserver;
import android.os.Binder;
import android.os.Handler;
import android.provider.Settings;
+import android.util.IndentingPrintWriter;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.DumpUtils;
@@ -139,7 +140,9 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub {
@Nullable String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
- mTimeDetectorStrategy.dump(pw, args);
+ IndentingPrintWriter ipw = new IndentingPrintWriter(pw);
+ mTimeDetectorStrategy.dump(ipw, args);
+ ipw.flush();
}
private void enforceSuggestTelephonyTimePermission() {
diff --git a/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java b/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java
index 9a39d2418994..e943978cfc14 100644
--- a/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java
+++ b/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java
@@ -17,25 +17,25 @@
package com.android.server.timedetector;
import android.annotation.NonNull;
-import android.annotation.Nullable;
import android.app.timedetector.ManualTimeSuggestion;
import android.app.timedetector.NetworkTimeSuggestion;
import android.app.timedetector.TelephonyTimeSuggestion;
import android.os.TimestampedValue;
+import android.util.IndentingPrintWriter;
-import java.io.PrintWriter;
+import com.android.server.timezonedetector.Dumpable;
/**
* The interface for the class that implements the time detection algorithm used by the
* {@link TimeDetectorService}.
*
* <p>Most calls will be handled by a single thread but that is not true for all calls. For example
- * {@link #dump(PrintWriter, String[])}) may be called on a different thread so implementations must
- * handle thread safety.
+ * {@link #dump(IndentingPrintWriter, String[])}) may be called on a different thread so
+ * implementations must handle thread safety.
*
* @hide
*/
-public interface TimeDetectorStrategy {
+public interface TimeDetectorStrategy extends Dumpable {
/**
* The interface used by the strategy to interact with the surrounding service.
@@ -94,9 +94,6 @@ public interface TimeDetectorStrategy {
/** Handle the auto-time setting being toggled on or off. */
void handleAutoTimeDetectionChanged();
- /** Dump debug information. */
- void dump(@NonNull PrintWriter pw, @Nullable String[] args);
-
// Utility methods below are to be moved to a better home when one becomes more obvious.
/**
diff --git a/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java b/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java
index ceb548551635..fe0e82e66093 100644
--- a/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java
+++ b/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java
@@ -24,16 +24,15 @@ import android.app.timedetector.ManualTimeSuggestion;
import android.app.timedetector.NetworkTimeSuggestion;
import android.app.timedetector.TelephonyTimeSuggestion;
import android.os.TimestampedValue;
+import android.util.IndentingPrintWriter;
import android.util.LocalLog;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.IndentingPrintWriter;
import com.android.server.timezonedetector.ArrayMapWithHistory;
import com.android.server.timezonedetector.ReferenceWithHistory;
-import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -203,8 +202,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
}
@Override
- public synchronized void dump(@NonNull PrintWriter pw, @Nullable String[] args) {
- IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
+ public synchronized void dump(@NonNull IndentingPrintWriter ipw, @Nullable String[] args) {
ipw.println("TimeDetectorStrategy:");
ipw.increaseIndent(); // level 1
@@ -232,7 +230,6 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
ipw.decreaseIndent(); // level 2
ipw.decreaseIndent(); // level 1
- ipw.flush();
}
@GuardedBy("this")
diff --git a/services/core/java/com/android/server/timezonedetector/ArrayMapWithHistory.java b/services/core/java/com/android/server/timezonedetector/ArrayMapWithHistory.java
index 3274f0e1112f..d6fdddf4ee43 100644
--- a/services/core/java/com/android/server/timezonedetector/ArrayMapWithHistory.java
+++ b/services/core/java/com/android/server/timezonedetector/ArrayMapWithHistory.java
@@ -20,10 +20,10 @@ import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.util.ArrayMap;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.IndentingPrintWriter;
/**
* A partial decorator for {@link ArrayMap} that records historic values for each mapping for
diff --git a/services/core/java/com/android/server/timezonedetector/Dumpable.java b/services/core/java/com/android/server/timezonedetector/Dumpable.java
index 58a5a0b517f8..5603c38bd0ae 100644
--- a/services/core/java/com/android/server/timezonedetector/Dumpable.java
+++ b/services/core/java/com/android/server/timezonedetector/Dumpable.java
@@ -15,24 +15,27 @@
*/
package com.android.server.timezonedetector;
-import java.io.PrintWriter;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.util.IndentingPrintWriter;
/** An interface for components that can write their internal state to dumpsys logs. */
public interface Dumpable {
/** Dump internal state. */
- void dump(PrintWriter pw, String[] args);
+ void dump(@NonNull IndentingPrintWriter pw, @Nullable String[] args);
/**
* An interface that can be used expose when one component allows another to be registered so
* that it is dumped at the same time.
*/
- interface Dumpee {
+ interface Container {
/**
* Registers the supplied {@link Dumpable}. When the implementation is dumped
- * {@link Dumpable#dump(PrintWriter, String[])} should be called on the {@code dumpable}.
+ * {@link Dumpable#dump(IndentingPrintWriter, String[])} should be called on the
+ * {@code dumpable}.
*/
- void addDumpable(Dumpable dumpable);
+ void addDumpable(@NonNull Dumpable dumpable);
}
}
diff --git a/services/core/java/com/android/server/timezonedetector/ReferenceWithHistory.java b/services/core/java/com/android/server/timezonedetector/ReferenceWithHistory.java
index 165419a7a38b..b63df05ad7a1 100644
--- a/services/core/java/com/android/server/timezonedetector/ReferenceWithHistory.java
+++ b/services/core/java/com/android/server/timezonedetector/ReferenceWithHistory.java
@@ -19,8 +19,7 @@ package com.android.server.timezonedetector;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
-
-import com.android.internal.util.IndentingPrintWriter;
+import android.util.IndentingPrintWriter;
import java.util.ArrayDeque;
diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternal.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternal.java
index d833586dc2dd..3d9ec6475a8b 100644
--- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternal.java
+++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternal.java
@@ -24,7 +24,7 @@ import android.annotation.NonNull;
*
* @hide
*/
-public interface TimeZoneDetectorInternal extends Dumpable.Dumpee {
+public interface TimeZoneDetectorInternal extends Dumpable.Container {
/**
* Suggests the current time zone, determined using geolocation, to the detector. The
diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternalImpl.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternalImpl.java
index d8db1ba0eb43..4464f7d136e3 100644
--- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternalImpl.java
+++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternalImpl.java
@@ -49,7 +49,7 @@ public final class TimeZoneDetectorInternalImpl implements TimeZoneDetectorInter
}
@Override
- public void addDumpable(Dumpable dumpable) {
+ public void addDumpable(@NonNull Dumpable dumpable) {
mTimeZoneDetectorStrategy.addDumpable(dumpable);
}
diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java
index bb4f56d76943..d9415ce81636 100644
--- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java
+++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java
@@ -36,6 +36,7 @@ import android.os.ResultReceiver;
import android.os.ShellCallback;
import android.os.UserHandle;
import android.provider.Settings;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
@@ -118,7 +119,7 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub
Settings.Global.getUriFor(Settings.Global.AUTO_TIME_ZONE), true,
new ContentObserver(handler) {
public void onChange(boolean selfChange) {
- service.handleAutoTimeZoneDetectionChanged();
+ service.handleAutoTimeZoneConfigChanged();
}
});
return service;
@@ -272,12 +273,14 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub
@Nullable String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
- mTimeZoneDetectorStrategy.dump(pw, args);
+ IndentingPrintWriter ipw = new IndentingPrintWriter(pw);
+ mTimeZoneDetectorStrategy.dump(ipw, args);
+ ipw.flush();
}
/** Internal method for handling the auto time zone configuration being changed. */
@VisibleForTesting
- public void handleAutoTimeZoneDetectionChanged() {
+ public void handleAutoTimeZoneConfigChanged() {
mHandler.post(mTimeZoneDetectorStrategy::handleAutoTimeZoneConfigChanged);
}
diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategy.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategy.java
index 497ff3efc4b8..f947a6554412 100644
--- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategy.java
+++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategy.java
@@ -21,8 +21,7 @@ import android.app.timezonedetector.ManualTimeZoneSuggestion;
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
import android.app.timezonedetector.TimeZoneCapabilities;
import android.app.timezonedetector.TimeZoneConfiguration;
-
-import java.io.PrintWriter;
+import android.util.IndentingPrintWriter;
/**
* The interface for the class that implements the time detection algorithm used by the
@@ -32,12 +31,12 @@ import java.io.PrintWriter;
* and what to set it to.
*
* <p>Most calls will be handled by a single thread but that is not true for all calls. For example
- * {@link #dump(PrintWriter, String[])}) may be called on a different thread so implementations must
- * handle thread safety.
+ * {@link #dump(IndentingPrintWriter, String[])}) may be called on a different thread so
+ * implementations mustvhandle thread safety.
*
* @hide
*/
-public interface TimeZoneDetectorStrategy extends Dumpable.Dumpee {
+public interface TimeZoneDetectorStrategy extends Dumpable, Dumpable.Container {
/** A listener for strategy events. */
interface StrategyListener {
@@ -91,9 +90,4 @@ public interface TimeZoneDetectorStrategy extends Dumpable.Dumpee {
* Called when there has been a change to the automatic time zone detection configuration.
*/
void handleAutoTimeZoneConfigChanged();
-
- /**
- * Dumps internal state such as field values.
- */
- void dump(PrintWriter pw, String[] args);
}
diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java
index ab9a773d3b8c..9c36c3921e3e 100644
--- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java
+++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java
@@ -32,14 +32,13 @@ import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
import android.app.timezonedetector.TimeZoneCapabilities;
import android.app.timezonedetector.TimeZoneConfiguration;
import android.content.Context;
+import android.util.IndentingPrintWriter;
import android.util.LocalLog;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.IndentingPrintWriter;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -517,7 +516,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
}
@Override
- public synchronized void addDumpable(Dumpable dumpable) {
+ public synchronized void addDumpable(@NonNull Dumpable dumpable) {
mDumpables.add(dumpable);
}
@@ -525,8 +524,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
* Dumps internal state such as field values.
*/
@Override
- public synchronized void dump(PrintWriter pw, String[] args) {
- IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
+ public synchronized void dump(@NonNull IndentingPrintWriter ipw, @Nullable String[] args) {
ipw.println("TimeZoneDetectorStrategy:");
ipw.increaseIndent(); // level 1
@@ -549,7 +547,6 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
for (Dumpable dumpable : mDumpables) {
dumpable.dump(ipw, args);
}
- ipw.flush();
}
/**
diff --git a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java
index f0531f5166b9..9f59763cfa58 100644
--- a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java
@@ -35,6 +35,7 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.os.HandlerThread;
import android.os.TimestampedValue;
+import android.util.IndentingPrintWriter;
import androidx.test.runner.AndroidJUnit4;
@@ -46,6 +47,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.PrintWriter;
+import java.io.StringWriter;
@RunWith(AndroidJUnit4.class)
public class TimeDetectorServiceTest {
@@ -177,7 +179,8 @@ public class TimeDetectorServiceTest {
when(mMockContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP))
.thenReturn(PackageManager.PERMISSION_GRANTED);
- mTimeDetectorService.dump(null, null, null);
+ PrintWriter pw = new PrintWriter(new StringWriter());
+ mTimeDetectorService.dump(null, pw, null);
verify(mMockContext).checkCallingOrSelfPermission(eq(android.Manifest.permission.DUMP));
mStubbedTimeDetectorStrategy.verifyDumpCalled();
@@ -251,7 +254,7 @@ public class TimeDetectorServiceTest {
}
@Override
- public void dump(PrintWriter pw, String[] args) {
+ public void dump(IndentingPrintWriter pw, String[] args) {
mDumpCalled = true;
}
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/StubbedTimeZoneDetectorStrategy.java b/services/tests/servicestests/src/com/android/server/timezonedetector/FakeTimeZoneDetectorStrategy.java
index 43a6b8f3e314..dcf319058ca2 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/StubbedTimeZoneDetectorStrategy.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/FakeTimeZoneDetectorStrategy.java
@@ -25,10 +25,9 @@ import android.app.timezonedetector.ManualTimeZoneSuggestion;
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
import android.app.timezonedetector.TimeZoneCapabilities;
import android.app.timezonedetector.TimeZoneConfiguration;
+import android.util.IndentingPrintWriter;
-import java.io.PrintWriter;
-
-class StubbedTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
+class FakeTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
private StrategyListener mListener;
@@ -110,7 +109,7 @@ class StubbedTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
}
@Override
- public void dump(PrintWriter pw, String[] args) {
+ public void dump(IndentingPrintWriter pw, String[] args) {
mDumpCalled = true;
}
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorInternalImplTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorInternalImplTest.java
index 40ea3982df06..0e2c22756097 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorInternalImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorInternalImplTest.java
@@ -37,7 +37,7 @@ public class TimeZoneDetectorInternalImplTest {
private static final List<String> ARBITRARY_ZONE_IDS = Arrays.asList("TestZoneId");
private Context mMockContext;
- private StubbedTimeZoneDetectorStrategy mStubbedTimeZoneDetectorStrategy;
+ private FakeTimeZoneDetectorStrategy mFakeTimeZoneDetectorStrategy;
private TimeZoneDetectorInternalImpl mTimeZoneDetectorInternal;
private HandlerThread mHandlerThread;
@@ -53,10 +53,10 @@ public class TimeZoneDetectorInternalImplTest {
mHandlerThread.start();
mTestHandler = new TestHandler(mHandlerThread.getLooper());
- mStubbedTimeZoneDetectorStrategy = new StubbedTimeZoneDetectorStrategy();
+ mFakeTimeZoneDetectorStrategy = new FakeTimeZoneDetectorStrategy();
mTimeZoneDetectorInternal = new TimeZoneDetectorInternalImpl(
- mMockContext, mTestHandler, mStubbedTimeZoneDetectorStrategy);
+ mMockContext, mTestHandler, mFakeTimeZoneDetectorStrategy);
}
@After
@@ -72,7 +72,7 @@ public class TimeZoneDetectorInternalImplTest {
mTestHandler.assertTotalMessagesEnqueued(1);
mTestHandler.waitForMessagesToBeProcessed();
- mStubbedTimeZoneDetectorStrategy.verifySuggestGeolocationTimeZoneCalled(timeZoneSuggestion);
+ mFakeTimeZoneDetectorStrategy.verifySuggestGeolocationTimeZoneCalled(timeZoneSuggestion);
}
private static GeolocationTimeZoneSuggestion createGeolocationTimeZoneSuggestion() {
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java
index aa517ac0eea7..971d2e28b14e 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java
@@ -46,13 +46,16 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
@RunWith(AndroidJUnit4.class)
public class TimeZoneDetectorServiceTest {
private static final int ARBITRARY_USER_ID = 9999;
private Context mMockContext;
- private StubbedTimeZoneDetectorStrategy mStubbedTimeZoneDetectorStrategy;
+ private FakeTimeZoneDetectorStrategy mFakeTimeZoneDetectorStrategy;
private TimeZoneDetectorService mTimeZoneDetectorService;
private HandlerThread mHandlerThread;
@@ -68,10 +71,10 @@ public class TimeZoneDetectorServiceTest {
mHandlerThread.start();
mTestHandler = new TestHandler(mHandlerThread.getLooper());
- mStubbedTimeZoneDetectorStrategy = new StubbedTimeZoneDetectorStrategy();
+ mFakeTimeZoneDetectorStrategy = new FakeTimeZoneDetectorStrategy();
mTimeZoneDetectorService = new TimeZoneDetectorService(
- mMockContext, mTestHandler, mStubbedTimeZoneDetectorStrategy);
+ mMockContext, mTestHandler, mFakeTimeZoneDetectorStrategy);
}
@After
@@ -100,7 +103,7 @@ public class TimeZoneDetectorServiceTest {
doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
TimeZoneCapabilities capabilities = createTimeZoneCapabilities();
- mStubbedTimeZoneDetectorStrategy.initializeCapabilities(capabilities);
+ mFakeTimeZoneDetectorStrategy.initializeCapabilities(capabilities);
assertEquals(capabilities, mTimeZoneDetectorService.getCapabilities());
@@ -130,7 +133,7 @@ public class TimeZoneDetectorServiceTest {
TimeZoneConfiguration configuration =
createTimeZoneConfiguration(false /* autoDetectionEnabled */);
- mStubbedTimeZoneDetectorStrategy.initializeConfiguration(configuration);
+ mFakeTimeZoneDetectorStrategy.initializeConfiguration(configuration);
assertEquals(configuration, mTimeZoneDetectorService.getConfiguration());
@@ -161,7 +164,8 @@ public class TimeZoneDetectorServiceTest {
TimeZoneConfiguration autoDetectDisabledConfiguration =
createTimeZoneConfiguration(false /* autoDetectionEnabled */);
- mStubbedTimeZoneDetectorStrategy.initializeConfiguration(autoDetectDisabledConfiguration);
+
+ mFakeTimeZoneDetectorStrategy.initializeConfiguration(autoDetectDisabledConfiguration);
IBinder mockListenerBinder = mock(IBinder.class);
ITimeZoneConfigurationListener mockListener = mock(ITimeZoneConfigurationListener.class);
@@ -177,7 +181,7 @@ public class TimeZoneDetectorServiceTest {
// Simulate the configuration being changed and verify the mockListener was notified.
TimeZoneConfiguration autoDetectEnabledConfiguration =
createTimeZoneConfiguration(true /* autoDetectionEnabled */);
- mStubbedTimeZoneDetectorStrategy.updateConfiguration(
+ mFakeTimeZoneDetectorStrategy.updateConfiguration(
ARBITRARY_USER_ID, autoDetectEnabledConfiguration);
verify(mockListener).onChange(autoDetectEnabledConfiguration);
@@ -209,7 +213,7 @@ public class TimeZoneDetectorServiceTest {
assertEquals(expectedResult,
mTimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion));
- mStubbedTimeZoneDetectorStrategy.verifySuggestManualTimeZoneCalled(timeZoneSuggestion);
+ mFakeTimeZoneDetectorStrategy.verifySuggestManualTimeZoneCalled(timeZoneSuggestion);
verify(mMockContext).enforceCallingOrSelfPermission(
eq(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE),
@@ -261,7 +265,7 @@ public class TimeZoneDetectorServiceTest {
anyString());
mTestHandler.waitForMessagesToBeProcessed();
- mStubbedTimeZoneDetectorStrategy.verifySuggestTelephonyTimeZoneCalled(timeZoneSuggestion);
+ mFakeTimeZoneDetectorStrategy.verifySuggestTelephonyTimeZoneCalled(timeZoneSuggestion);
}
@Test
@@ -269,25 +273,26 @@ public class TimeZoneDetectorServiceTest {
when(mMockContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP))
.thenReturn(PackageManager.PERMISSION_GRANTED);
- mTimeZoneDetectorService.dump(null, null, null);
+ PrintWriter pw = new PrintWriter(new StringWriter());
+ mTimeZoneDetectorService.dump(null, pw, null);
verify(mMockContext).checkCallingOrSelfPermission(eq(android.Manifest.permission.DUMP));
- mStubbedTimeZoneDetectorStrategy.verifyDumpCalled();
+ mFakeTimeZoneDetectorStrategy.verifyDumpCalled();
}
@Test
public void testAutoTimeZoneDetectionChanged() throws Exception {
- mTimeZoneDetectorService.handleAutoTimeZoneDetectionChanged();
+ mTimeZoneDetectorService.handleAutoTimeZoneConfigChanged();
mTestHandler.assertTotalMessagesEnqueued(1);
mTestHandler.waitForMessagesToBeProcessed();
- mStubbedTimeZoneDetectorStrategy.verifyHandleAutoTimeZoneConfigChangedCalled();
+ mFakeTimeZoneDetectorStrategy.verifyHandleAutoTimeZoneConfigChangedCalled();
- mStubbedTimeZoneDetectorStrategy.resetCallTracking();
+ mFakeTimeZoneDetectorStrategy.resetCallTracking();
- mTimeZoneDetectorService.handleAutoTimeZoneDetectionChanged();
+ mTimeZoneDetectorService.handleAutoTimeZoneConfigChanged();
mTestHandler.assertTotalMessagesEnqueued(2);
mTestHandler.waitForMessagesToBeProcessed();
- mStubbedTimeZoneDetectorStrategy.verifyHandleAutoTimeZoneConfigChangedCalled();
+ mFakeTimeZoneDetectorStrategy.verifyHandleAutoTimeZoneConfigChangedCalled();
}
private static TimeZoneConfiguration createTimeZoneConfiguration(
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java
index 00a7caaa7254..68554451e43a 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java
@@ -48,13 +48,13 @@ import android.app.timezonedetector.TelephonyTimeZoneSuggestion.MatchType;
import android.app.timezonedetector.TelephonyTimeZoneSuggestion.Quality;
import android.app.timezonedetector.TimeZoneCapabilities;
import android.app.timezonedetector.TimeZoneConfiguration;
+import android.util.IndentingPrintWriter;
import com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.QualifiedTelephonyTimeZoneSuggestion;
import org.junit.Before;
import org.junit.Test;
-import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
@@ -119,7 +119,8 @@ public class TimeZoneDetectorStrategyImplTest {
@Test
public void testGetCapabilities() {
new Script()
- .initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
TimeZoneCapabilities expectedCapabilities = mFakeCallback.getCapabilities(USER_ID);
assertEquals(expectedCapabilities, mTimeZoneDetectorStrategy.getCapabilities(USER_ID));
}
@@ -127,17 +128,19 @@ public class TimeZoneDetectorStrategyImplTest {
@Test
public void testGetConfiguration() {
new Script()
- .initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
TimeZoneConfiguration expectedConfiguration = mFakeCallback.getConfiguration(USER_ID);
assertTrue(expectedConfiguration.isComplete());
assertEquals(expectedConfiguration, mTimeZoneDetectorStrategy.getConfiguration(USER_ID));
}
@Test
- public void testCapabilitiesTestInfra_owner() {
+ public void testCapabilitiesTestInfra_unrestricted() {
Script script = new Script();
- script.initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
+ script.initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
{
// Check the fake test infra is doing what is expected.
TimeZoneCapabilities capabilities = mFakeCallback.getCapabilities(USER_ID);
@@ -145,7 +148,8 @@ public class TimeZoneDetectorStrategyImplTest {
assertEquals(CAPABILITY_NOT_APPLICABLE, capabilities.getSuggestManualTimeZone());
}
- script.initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED);
+ script.initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED);
{
// Check the fake test infra is doing what is expected.
TimeZoneCapabilities capabilities = mFakeCallback.getCapabilities(USER_ID);
@@ -155,10 +159,11 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testCapabilitiesTestInfra_nonOwner() {
+ public void testCapabilitiesTestInfra_restricted() {
Script script = new Script();
- script.initializeUser(USER_ID, UserCase.NON_OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
+ script.initializeUser(USER_ID, UserCase.RESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
{
// Check the fake test infra is doing what is expected.
TimeZoneCapabilities capabilities = mFakeCallback.getCapabilities(USER_ID);
@@ -166,7 +171,7 @@ public class TimeZoneDetectorStrategyImplTest {
assertEquals(CAPABILITY_NOT_ALLOWED, capabilities.getSuggestManualTimeZone());
}
- script.initializeUser(USER_ID, UserCase.NON_OWNER,
+ script.initializeUser(USER_ID, UserCase.RESTRICTED,
CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED);
{
// Check the fake test infra is doing what is expected.
@@ -177,10 +182,10 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testCapabilitiesTestInfra_ownerAutoDetectNotSupported() {
+ public void testCapabilitiesTestInfra_autoDetectNotSupported() {
Script script = new Script();
- script.initializeUser(USER_ID, UserCase.OWNER_AUTO_DETECT_NOT_SUPPORTED,
+ script.initializeUser(USER_ID, UserCase.AUTO_DETECT_NOT_SUPPORTED,
CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
{
// Check the fake test infra is doing what is expected.
@@ -189,7 +194,7 @@ public class TimeZoneDetectorStrategyImplTest {
assertEquals(CAPABILITY_POSSESSED, capabilities.getSuggestManualTimeZone());
}
- script.initializeUser(USER_ID, UserCase.OWNER_AUTO_DETECT_NOT_SUPPORTED,
+ script.initializeUser(USER_ID, UserCase.AUTO_DETECT_NOT_SUPPORTED,
CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED);
{
// Check the fake test infra is doing what is expected.
@@ -200,9 +205,10 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testUpdateConfiguration_owner() {
+ public void testUpdateConfiguration_unrestricted() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
// Set the configuration with auto detection enabled.
script.simulateUpdateConfiguration(USER_ID, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
@@ -225,9 +231,9 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testUpdateConfiguration_nonOwner() {
+ public void testUpdateConfiguration_restricted() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.NON_OWNER,
+ .initializeUser(USER_ID, UserCase.RESTRICTED,
CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
// Try to update the configuration with auto detection disabled.
@@ -244,9 +250,9 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testUpdateConfiguration_ownerAutoDetectNotSupported() {
+ public void testUpdateConfiguration_autoDetectNotSupported() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER_AUTO_DETECT_NOT_SUPPORTED,
+ .initializeUser(USER_ID, UserCase.AUTO_DETECT_NOT_SUPPORTED,
CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
// Try to update the configuration with auto detection disabled.
@@ -269,7 +275,8 @@ public class TimeZoneDetectorStrategyImplTest {
TelephonyTimeZoneSuggestion slotIndex2TimeZoneSuggestion =
createEmptySlotIndex2Suggestion();
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED)
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
script.simulateTelephonyTimeZoneSuggestion(slotIndex1TimeZoneSuggestion)
@@ -311,7 +318,8 @@ public class TimeZoneDetectorStrategyImplTest {
QUALITY_SINGLE_ZONE, TELEPHONY_SCORE_HIGH);
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
// A low quality suggestions will not be taken: The device time zone setting is left
// uninitialized.
@@ -376,7 +384,8 @@ public class TimeZoneDetectorStrategyImplTest {
for (TelephonyTestCase testCase : TELEPHONY_TEST_CASES) {
// Start with the device in a known state.
- script.initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED)
+ script.initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
TelephonyTimeZoneSuggestion suggestion =
@@ -427,7 +436,8 @@ public class TimeZoneDetectorStrategyImplTest {
@Test
public void testTelephonySuggestionsSingleSlotId() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED)
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
for (TelephonyTestCase testCase : TELEPHONY_TEST_CASES) {
@@ -493,7 +503,8 @@ public class TimeZoneDetectorStrategyImplTest {
TELEPHONY_SCORE_NONE);
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED)
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID)
// Initialize the latest suggestions as empty so we don't need to worry about nulls
// below for the first loop.
@@ -579,7 +590,8 @@ public class TimeZoneDetectorStrategyImplTest {
@Test
public void testTelephonySuggestionTimeZoneDetectorStrategyDoesNotAssumeCurrentSetting() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED);
TelephonyTestCase testCase = newTelephonyTestCase(
MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET, QUALITY_SINGLE_ZONE, TELEPHONY_SCORE_HIGH);
@@ -613,9 +625,10 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testManualSuggestion_owner_simulateAutoTimeZoneEnabled() {
+ public void testManualSuggestion_unrestricted_simulateAutoTimeZoneEnabled() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED)
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
// Auto time zone detection is enabled so the manual suggestion should be ignored.
@@ -625,9 +638,9 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testManualSuggestion_nonOwner_simulateAutoTimeZoneEnabled() {
+ public void testManualSuggestion_restricted_simulateAutoTimeZoneEnabled() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.NON_OWNER,
+ .initializeUser(USER_ID, UserCase.RESTRICTED,
CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
@@ -638,9 +651,9 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testManualSuggestion_ownerAutoDetectNotSupported_simulateAutoTimeZoneEnabled() {
+ public void testManualSuggestion_autoDetectNotSupported_simulateAutoTimeZoneEnabled() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER_AUTO_DETECT_NOT_SUPPORTED,
+ .initializeUser(USER_ID, UserCase.AUTO_DETECT_NOT_SUPPORTED,
CONFIG_AUTO_TIME_ZONE_DETECTION_ENABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
@@ -652,9 +665,10 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testManualSuggestion_owner_autoTimeZoneDetectionDisabled() {
+ public void testManualSuggestion_unrestricted_autoTimeZoneDetectionDisabled() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER, CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED)
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
+ CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
// Auto time zone detection is disabled so the manual suggestion should be used.
@@ -665,13 +679,13 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testManualSuggestion_nonOwner_autoTimeZoneDetectionDisabled() {
+ public void testManualSuggestion_restricted_autoTimeZoneDetectionDisabled() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.NON_OWNER,
+ .initializeUser(USER_ID, UserCase.RESTRICTED,
CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
- // Only owners have the capability.
+ // Restricted users do not have the capability.
ManualTimeZoneSuggestion manualSuggestion = createManualSuggestion("Europe/Paris");
script.simulateManualTimeZoneSuggestion(
USER_ID, manualSuggestion, false /* expectedResult */)
@@ -679,13 +693,13 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testManualSuggestion_ownerAutoDetectNotSupported_autoTimeZoneDetectionDisabled() {
+ public void testManualSuggestion_autoDetectNotSupported_autoTimeZoneDetectionDisabled() {
Script script = new Script()
- .initializeUser(USER_ID, UserCase.OWNER_AUTO_DETECT_NOT_SUPPORTED,
+ .initializeUser(USER_ID, UserCase.AUTO_DETECT_NOT_SUPPORTED,
CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
- // Only owners have the capability.
+ // Unrestricted users have the capability.
ManualTimeZoneSuggestion manualSuggestion = createManualSuggestion("Europe/Paris");
script.simulateManualTimeZoneSuggestion(
USER_ID, manualSuggestion, true /* expectedResult */)
@@ -695,22 +709,22 @@ public class TimeZoneDetectorStrategyImplTest {
@Test
public void testAddDumpable() {
new Script()
- .initializeUser(USER_ID, UserCase.OWNER,
+ .initializeUser(USER_ID, UserCase.UNRESTRICTED,
CONFIG_AUTO_TIME_ZONE_DETECTION_DISABLED)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
AtomicBoolean dumpCalled = new AtomicBoolean(false);
class FakeDumpable implements Dumpable {
@Override
- public void dump(PrintWriter pw, String[] args) {
+ public void dump(IndentingPrintWriter pw, String[] args) {
dumpCalled.set(true);
}
}
mTimeZoneDetectorStrategy.addDumpable(new FakeDumpable());
- PrintWriter pw = new PrintWriter(new StringWriter());
+ IndentingPrintWriter ipw = new IndentingPrintWriter(new StringWriter());
String[] args = {"ArgOne", "ArgTwo"};
- mTimeZoneDetectorStrategy.dump(pw, args);
+ mTimeZoneDetectorStrategy.dump(ipw, args);
assertTrue(dumpCalled.get());
}
@@ -912,12 +926,15 @@ public class TimeZoneDetectorStrategyImplTest {
/** Simulated user test cases. */
enum UserCase {
- /** A catch-all for users that can set time zone config. */
- OWNER,
- /** A catch-all for users that can't set time zone config. */
- NON_OWNER,
- /** Owner, but auto tz detection is not supported on the device. */
- OWNER_AUTO_DETECT_NOT_SUPPORTED,
+ /** A catch-all for users that can set auto time zone config. */
+ UNRESTRICTED,
+ /** A catch-all for users that can't set auto time zone config. */
+ RESTRICTED,
+ /**
+ * Like {@link #UNRESTRICTED}, but auto tz detection is not
+ * supported on the device.
+ */
+ AUTO_DETECT_NOT_SUPPORTED,
}
/**
@@ -927,7 +944,7 @@ public class TimeZoneDetectorStrategyImplTest {
private static TimeZoneCapabilities createCapabilities(
int userId, UserCase userRole, TimeZoneConfiguration configuration) {
switch (userRole) {
- case OWNER: {
+ case UNRESTRICTED: {
int suggestManualTimeZoneCapability = configuration.isAutoDetectionEnabled()
? CAPABILITY_NOT_APPLICABLE : CAPABILITY_POSSESSED;
return new TimeZoneCapabilities.Builder(userId)
@@ -935,14 +952,14 @@ public class TimeZoneDetectorStrategyImplTest {
.setSuggestManualTimeZone(suggestManualTimeZoneCapability)
.build();
}
- case NON_OWNER: {
+ case RESTRICTED: {
return new TimeZoneCapabilities.Builder(userId)
.setConfigureAutoDetectionEnabled(CAPABILITY_NOT_ALLOWED)
.setSuggestManualTimeZone(CAPABILITY_NOT_ALLOWED)
.build();
}
- case OWNER_AUTO_DETECT_NOT_SUPPORTED: {
+ case AUTO_DETECT_NOT_SUPPORTED: {
return new TimeZoneCapabilities.Builder(userId)
.setConfigureAutoDetectionEnabled(CAPABILITY_NOT_SUPPORTED)
.setSuggestManualTimeZone(CAPABILITY_POSSESSED)
diff --git a/tests/StagedInstallTest/src/com/android/tests/stagedinstallinternal/host/StagedInstallInternalTest.java b/tests/StagedInstallTest/src/com/android/tests/stagedinstallinternal/host/StagedInstallInternalTest.java
index 530f885e62bf..e6ba8015e5b5 100644
--- a/tests/StagedInstallTest/src/com/android/tests/stagedinstallinternal/host/StagedInstallInternalTest.java
+++ b/tests/StagedInstallTest/src/com/android/tests/stagedinstallinternal/host/StagedInstallInternalTest.java
@@ -19,6 +19,7 @@ package com.android.tests.stagedinstallinternal.host;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import com.android.ddmlib.Log;
import com.android.tests.rollback.host.AbandonSessionsRule;
@@ -83,7 +84,7 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
private void restartSystemServer() throws Exception {
// Restart the system server
- long oldStartTime = getDevice().getProcessByName("system_server").getStartTime();
+ ProcessInfo oldPs = getDevice().getProcessByName("system_server");
getDevice().enableAdbRoot(); // Need root to restart system server
assertThat(getDevice().executeShellCommand("am restart")).contains("Restart the system");
@@ -91,18 +92,16 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
// Wait for new system server process to start
long start = System.currentTimeMillis();
- long newStartTime = oldStartTime;
while (System.currentTimeMillis() < start + SYSTEM_SERVER_TIMEOUT_MS) {
ProcessInfo newPs = getDevice().getProcessByName("system_server");
if (newPs != null) {
- newStartTime = newPs.getStartTime();
- if (newStartTime != oldStartTime) {
- break;
+ if (newPs.getPid() != oldPs.getPid()) {
+ getDevice().waitForDeviceAvailable();
+ return;
}
}
Thread.sleep(500);
}
- assertThat(newStartTime).isNotEqualTo(oldStartTime);
- getDevice().waitForDeviceAvailable();
+ fail("Timed out in restarting system server");
}
}