Merge "Revert "[DO NOT MERGE] Handle config override via settings correctly"" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f61e5f2410
@@ -108,12 +108,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* must be called with the mInMemoryLock, xxxDMLocked suffix means the method
|
* must be called with the mInMemoryLock, xxxDMLocked suffix means the method
|
||||||
* must be called with the mOnDiskLock and mInMemoryLock locks acquired in that
|
* must be called with the mOnDiskLock and mInMemoryLock locks acquired in that
|
||||||
* exact order.
|
* exact order.
|
||||||
* <p>
|
|
||||||
* INITIALIZATION: We can initialize persistence only after the system is ready
|
|
||||||
* as we need to check the optional configuration override from the settings
|
|
||||||
* database which is not initialized at the time the app ops service is created.
|
|
||||||
* This means that all entry points that touch persistence should be short
|
|
||||||
* circuited via isPersistenceInitialized() check.
|
|
||||||
*/
|
*/
|
||||||
// TODO (bug:122218838): Make sure we handle start of epoch time
|
// TODO (bug:122218838): Make sure we handle start of epoch time
|
||||||
// TODO (bug:122218838): Validate changed time is handled correctly
|
// TODO (bug:122218838): Validate changed time is handled correctly
|
||||||
@@ -183,33 +177,14 @@ final class HistoricalRegistry {
|
|||||||
|
|
||||||
// Object managing persistence (read/write)
|
// Object managing persistence (read/write)
|
||||||
@GuardedBy("mOnDiskLock")
|
@GuardedBy("mOnDiskLock")
|
||||||
private Persistence mPersistence;
|
private Persistence mPersistence = new Persistence(mBaseSnapshotInterval,
|
||||||
|
mIntervalCompressionMultiplier);
|
||||||
|
|
||||||
HistoricalRegistry(@NonNull Object lock) {
|
HistoricalRegistry(@NonNull Object lock) {
|
||||||
mInMemoryLock = lock;
|
mInMemoryLock = lock;
|
||||||
}
|
if (mMode != AppOpsManager.HISTORICAL_MODE_DISABLED) {
|
||||||
|
synchronized (mOnDiskLock) {
|
||||||
void systemReady(@NonNull ContentResolver resolver) {
|
synchronized (mInMemoryLock) {
|
||||||
final Uri uri = Settings.Global.getUriFor(Settings.Global.APPOP_HISTORY_PARAMETERS);
|
|
||||||
resolver.registerContentObserver(uri, false, new ContentObserver(
|
|
||||||
FgThread.getHandler()) {
|
|
||||||
@Override
|
|
||||||
public void onChange(boolean selfChange) {
|
|
||||||
updateParametersFromSetting(resolver);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
updateParametersFromSetting(resolver);
|
|
||||||
|
|
||||||
synchronized (mOnDiskLock) {
|
|
||||||
synchronized (mInMemoryLock) {
|
|
||||||
if (mMode != AppOpsManager.HISTORICAL_MODE_DISABLED) {
|
|
||||||
// Can be uninitialized if there is no config in the settings table.
|
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
|
||||||
mPersistence = new Persistence(mBaseSnapshotInterval,
|
|
||||||
mIntervalCompressionMultiplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
// When starting always adjust history to now.
|
// When starting always adjust history to now.
|
||||||
final long lastPersistTimeMills =
|
final long lastPersistTimeMills =
|
||||||
mPersistence.getLastPersistTimeMillisDLocked();
|
mPersistence.getLastPersistTimeMillisDLocked();
|
||||||
@@ -222,8 +197,16 @@ final class HistoricalRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPersistenceInitializedMLocked() {
|
void systemReady(@NonNull ContentResolver resolver) {
|
||||||
return mPersistence != null;
|
updateParametersFromSetting(resolver);
|
||||||
|
final Uri uri = Settings.Global.getUriFor(Settings.Global.APPOP_HISTORY_PARAMETERS);
|
||||||
|
resolver.registerContentObserver(uri, false, new ContentObserver(
|
||||||
|
FgThread.getHandler()) {
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
updateParametersFromSetting(resolver);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateParametersFromSetting(@NonNull ContentResolver resolver) {
|
private void updateParametersFromSetting(@NonNull ContentResolver resolver) {
|
||||||
@@ -291,11 +274,6 @@ final class HistoricalRegistry {
|
|||||||
makeRelativeToEpochStart(currentOps, nowMillis);
|
makeRelativeToEpochStart(currentOps, nowMillis);
|
||||||
currentOps.accept(visitor);
|
currentOps.accept(visitor);
|
||||||
|
|
||||||
if(isPersistenceInitializedMLocked()) {
|
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<HistoricalOps> ops = mPersistence.readHistoryDLocked();
|
final List<HistoricalOps> ops = mPersistence.readHistoryDLocked();
|
||||||
if (ops != null) {
|
if (ops != null) {
|
||||||
// TODO (bug:122218838): Make sure this is properly dumped
|
// TODO (bug:122218838): Make sure this is properly dumped
|
||||||
@@ -324,21 +302,12 @@ final class HistoricalRegistry {
|
|||||||
void getHistoricalOpsFromDiskRaw(int uid, @NonNull String packageName,
|
void getHistoricalOpsFromDiskRaw(int uid, @NonNull String packageName,
|
||||||
@Nullable String[] opNames, long beginTimeMillis, long endTimeMillis,
|
@Nullable String[] opNames, long beginTimeMillis, long endTimeMillis,
|
||||||
@OpFlags int flags, @NonNull RemoteCallback callback) {
|
@OpFlags int flags, @NonNull RemoteCallback callback) {
|
||||||
synchronized (mOnDiskLock) {
|
final HistoricalOps result = new HistoricalOps(beginTimeMillis, endTimeMillis);
|
||||||
synchronized (mInMemoryLock) {
|
mPersistence.collectHistoricalOpsDLocked(result, uid, packageName, opNames,
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
beginTimeMillis, endTimeMillis, flags);
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
final Bundle payload = new Bundle();
|
||||||
callback.sendResult(new Bundle());
|
payload.putParcelable(AppOpsManager.KEY_HISTORICAL_OPS, result);
|
||||||
return;
|
callback.sendResult(payload);
|
||||||
}
|
|
||||||
final HistoricalOps result = new HistoricalOps(beginTimeMillis, endTimeMillis);
|
|
||||||
mPersistence.collectHistoricalOpsDLocked(result, uid, packageName, opNames,
|
|
||||||
beginTimeMillis, endTimeMillis, flags);
|
|
||||||
final Bundle payload = new Bundle();
|
|
||||||
payload.putParcelable(AppOpsManager.KEY_HISTORICAL_OPS, result);
|
|
||||||
callback.sendResult(payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void getHistoricalOps(int uid, @NonNull String packageName,
|
void getHistoricalOps(int uid, @NonNull String packageName,
|
||||||
@@ -362,12 +331,6 @@ final class HistoricalRegistry {
|
|||||||
boolean collectOpsFromDisk;
|
boolean collectOpsFromDisk;
|
||||||
|
|
||||||
synchronized (mInMemoryLock) {
|
synchronized (mInMemoryLock) {
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
|
||||||
callback.sendResult(new Bundle());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentOps = getUpdatedPendingHistoricalOpsMLocked(currentTimeMillis);
|
currentOps = getUpdatedPendingHistoricalOpsMLocked(currentTimeMillis);
|
||||||
if (!(inMemoryAdjBeginTimeMillis >= currentOps.getEndTimeMillis()
|
if (!(inMemoryAdjBeginTimeMillis >= currentOps.getEndTimeMillis()
|
||||||
|| inMemoryAdjEndTimeMillis <= currentOps.getBeginTimeMillis())) {
|
|| inMemoryAdjEndTimeMillis <= currentOps.getBeginTimeMillis())) {
|
||||||
@@ -411,10 +374,6 @@ final class HistoricalRegistry {
|
|||||||
@UidState int uidState, @OpFlags int flags) {
|
@UidState int uidState, @OpFlags int flags) {
|
||||||
synchronized (mInMemoryLock) {
|
synchronized (mInMemoryLock) {
|
||||||
if (mMode == AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
|
if (mMode == AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getUpdatedPendingHistoricalOpsMLocked(System.currentTimeMillis())
|
getUpdatedPendingHistoricalOpsMLocked(System.currentTimeMillis())
|
||||||
.increaseAccessCount(op, uid, packageName, uidState, flags, 1);
|
.increaseAccessCount(op, uid, packageName, uidState, flags, 1);
|
||||||
}
|
}
|
||||||
@@ -425,10 +384,6 @@ final class HistoricalRegistry {
|
|||||||
@UidState int uidState, @OpFlags int flags) {
|
@UidState int uidState, @OpFlags int flags) {
|
||||||
synchronized (mInMemoryLock) {
|
synchronized (mInMemoryLock) {
|
||||||
if (mMode == AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
|
if (mMode == AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getUpdatedPendingHistoricalOpsMLocked(System.currentTimeMillis())
|
getUpdatedPendingHistoricalOpsMLocked(System.currentTimeMillis())
|
||||||
.increaseRejectCount(op, uid, packageName, uidState, flags, 1);
|
.increaseRejectCount(op, uid, packageName, uidState, flags, 1);
|
||||||
}
|
}
|
||||||
@@ -439,10 +394,6 @@ final class HistoricalRegistry {
|
|||||||
@UidState int uidState, @OpFlags int flags, long increment) {
|
@UidState int uidState, @OpFlags int flags, long increment) {
|
||||||
synchronized (mInMemoryLock) {
|
synchronized (mInMemoryLock) {
|
||||||
if (mMode == AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
|
if (mMode == AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getUpdatedPendingHistoricalOpsMLocked(System.currentTimeMillis())
|
getUpdatedPendingHistoricalOpsMLocked(System.currentTimeMillis())
|
||||||
.increaseAccessDuration(op, uid, packageName, uidState, flags, increment);
|
.increaseAccessDuration(op, uid, packageName, uidState, flags, increment);
|
||||||
}
|
}
|
||||||
@@ -453,8 +404,6 @@ final class HistoricalRegistry {
|
|||||||
long baseSnapshotInterval, long intervalCompressionMultiplier) {
|
long baseSnapshotInterval, long intervalCompressionMultiplier) {
|
||||||
synchronized (mOnDiskLock) {
|
synchronized (mOnDiskLock) {
|
||||||
synchronized (mInMemoryLock) {
|
synchronized (mInMemoryLock) {
|
||||||
// NOTE: We allow this call if persistence is not initialized as
|
|
||||||
// it is a part of the persistence initialization process.
|
|
||||||
boolean resampleHistory = false;
|
boolean resampleHistory = false;
|
||||||
Slog.i(LOG_TAG, "New history parameters: mode:"
|
Slog.i(LOG_TAG, "New history parameters: mode:"
|
||||||
+ AppOpsManager.historicalModeToString(mMode) + " baseSnapshotInterval:"
|
+ AppOpsManager.historicalModeToString(mMode) + " baseSnapshotInterval:"
|
||||||
@@ -463,7 +412,7 @@ final class HistoricalRegistry {
|
|||||||
if (mMode != mode) {
|
if (mMode != mode) {
|
||||||
mMode = mode;
|
mMode = mode;
|
||||||
if (mMode == AppOpsManager.HISTORICAL_MODE_DISABLED) {
|
if (mMode == AppOpsManager.HISTORICAL_MODE_DISABLED) {
|
||||||
clearHistoryOnDiskDLocked();
|
clearHistoryOnDiskLocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mBaseSnapshotInterval != baseSnapshotInterval) {
|
if (mBaseSnapshotInterval != baseSnapshotInterval) {
|
||||||
@@ -484,10 +433,6 @@ final class HistoricalRegistry {
|
|||||||
void offsetHistory(long offsetMillis) {
|
void offsetHistory(long offsetMillis) {
|
||||||
synchronized (mOnDiskLock) {
|
synchronized (mOnDiskLock) {
|
||||||
synchronized (mInMemoryLock) {
|
synchronized (mInMemoryLock) {
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final List<HistoricalOps> history = mPersistence.readHistoryDLocked();
|
final List<HistoricalOps> history = mPersistence.readHistoryDLocked();
|
||||||
clearHistory();
|
clearHistory();
|
||||||
if (history != null) {
|
if (history != null) {
|
||||||
@@ -508,10 +453,6 @@ final class HistoricalRegistry {
|
|||||||
void addHistoricalOps(HistoricalOps ops) {
|
void addHistoricalOps(HistoricalOps ops) {
|
||||||
final List<HistoricalOps> pendingWrites;
|
final List<HistoricalOps> pendingWrites;
|
||||||
synchronized (mInMemoryLock) {
|
synchronized (mInMemoryLock) {
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// The history files start from mBaseSnapshotInterval - take this into account.
|
// The history files start from mBaseSnapshotInterval - take this into account.
|
||||||
ops.offsetBeginAndEndTime(mBaseSnapshotInterval);
|
ops.offsetBeginAndEndTime(mBaseSnapshotInterval);
|
||||||
mPendingWrites.offerFirst(ops);
|
mPendingWrites.offerFirst(ops);
|
||||||
@@ -527,10 +468,6 @@ final class HistoricalRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void resetHistoryParameters() {
|
void resetHistoryParameters() {
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setHistoryParameters(DEFAULT_MODE, DEFAULT_SNAPSHOT_INTERVAL_MILLIS,
|
setHistoryParameters(DEFAULT_MODE, DEFAULT_SNAPSHOT_INTERVAL_MILLIS,
|
||||||
DEFAULT_COMPRESSION_STEP);
|
DEFAULT_COMPRESSION_STEP);
|
||||||
}
|
}
|
||||||
@@ -538,10 +475,6 @@ final class HistoricalRegistry {
|
|||||||
void clearHistory(int uid, String packageName) {
|
void clearHistory(int uid, String packageName) {
|
||||||
synchronized (mOnDiskLock) {
|
synchronized (mOnDiskLock) {
|
||||||
synchronized (mInMemoryLock) {
|
synchronized (mInMemoryLock) {
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mMode != AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
|
if (mMode != AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -560,17 +493,11 @@ final class HistoricalRegistry {
|
|||||||
|
|
||||||
void clearHistory() {
|
void clearHistory() {
|
||||||
synchronized (mOnDiskLock) {
|
synchronized (mOnDiskLock) {
|
||||||
synchronized (mInMemoryLock) {
|
clearHistoryOnDiskLocked();
|
||||||
if (!isPersistenceInitializedMLocked()) {
|
|
||||||
Slog.e(LOG_TAG, "Interaction before persistence initialized");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
clearHistoryOnDiskDLocked();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearHistoryOnDiskDLocked() {
|
private void clearHistoryOnDiskLocked() {
|
||||||
BackgroundThread.getHandler().removeMessages(MSG_WRITE_PENDING_HISTORY);
|
BackgroundThread.getHandler().removeMessages(MSG_WRITE_PENDING_HISTORY);
|
||||||
synchronized (mInMemoryLock) {
|
synchronized (mInMemoryLock) {
|
||||||
mCurrentHistoricalOps = null;
|
mCurrentHistoricalOps = null;
|
||||||
@@ -791,27 +718,13 @@ final class HistoricalRegistry {
|
|||||||
baseDir = mHistoricalAppOpsDir.startRead();
|
baseDir = mHistoricalAppOpsDir.startRead();
|
||||||
final File[] files = baseDir.listFiles();
|
final File[] files = baseDir.listFiles();
|
||||||
if (files != null && files.length > 0) {
|
if (files != null && files.length > 0) {
|
||||||
File shortestFile = null;
|
final Set<File> historyFiles = new ArraySet<>();
|
||||||
for (File candidate : files) {
|
Collections.addAll(historyFiles, files);
|
||||||
final String candidateName = candidate.getName();
|
for (int i = 0;; i++) {
|
||||||
if (!candidateName.endsWith(HISTORY_FILE_SUFFIX)) {
|
final File file = generateFile(baseDir, i);
|
||||||
continue;
|
if (historyFiles.contains(file)) {
|
||||||
|
return file.lastModified();
|
||||||
}
|
}
|
||||||
if (shortestFile == null) {
|
|
||||||
shortestFile = candidate;
|
|
||||||
} else if (candidateName.length() < shortestFile.getName().length()) {
|
|
||||||
shortestFile = candidate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (shortestFile == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
final String shortestNameNoExtension = shortestFile.getName()
|
|
||||||
.replace(HISTORY_FILE_SUFFIX, "");
|
|
||||||
try {
|
|
||||||
return Long.parseLong(shortestNameNoExtension);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mHistoricalAppOpsDir.finishRead();
|
mHistoricalAppOpsDir.finishRead();
|
||||||
|
|||||||
Reference in New Issue
Block a user