Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd78991b authored by David Chen's avatar David Chen
Browse files

Moves the settings changed logging for statsd.

Previously, we wrote a log entry regardless of permission checks, so
the logging could be misleading. Now we only send the log to statsd
after verifying that this setting mutation is valid.

Test: Flashed onto marlin-eng and verified stats-log as expected.
Bug: 73493944
Change-Id: I2a8b052aa8c380ffc5d15caec089fffcdc5823f4
parent 02a4219c
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -1098,7 +1098,7 @@ message PhoneSignalStrengthChanged {
/**
 * Logs that a setting was updated.
 * Logged from:
 *   frameworks/base/core/java/android/provider/Settings.java
 *   frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java
 * The tag and is_default allow resetting of settings to default values based on the specified
 * tag. See Settings#putString(ContentResolver, String, String, String, boolean) for more details.
 */
@@ -1124,8 +1124,14 @@ message SettingChanged {
    // True if this setting with tag should be resettable.
    optional bool is_default = 6;

    // The user ID associated. Defined in android/os/UserHandle.java
    // The associated user (for multi-user feature). Defined in android/os/UserHandle.java
    optional int32 user = 7;

    enum ChangeReason {
        UPDATED = 1; // Updated can be an insertion or an update.
        DELETED = 2;
    }
    optional ChangeReason reason = 8;
}

/**
+0 −5
Original line number Diff line number Diff line
@@ -83,7 +83,6 @@ import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.util.MemoryIntArray;
import android.util.StatsLog;
import android.view.textservice.TextServicesManager;

import com.android.internal.annotations.GuardedBy;
@@ -1914,11 +1913,7 @@ public final class Settings {
                    arg.putBoolean(CALL_METHOD_MAKE_DEFAULT_KEY, true);
                }
                IContentProvider cp = mProviderHolder.getProvider(cr);
                String prevValue = getStringForUser(cr, name, userHandle);
                cp.call(cr.getPackageName(), mCallSetCommand, name, arg);
                String newValue = getStringForUser(cr, name, userHandle);
                StatsLog.write(StatsLog.SETTING_CHANGED, name, value, newValue, prevValue, tag,
                        makeDefault, userHandle);
            } catch (RemoteException e) {
                Log.w(TAG, "Can't set key " + name + " in " + mUri, e);
                return false;
+8 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.util.AtomicFile;
import android.util.Base64;
import android.util.Slog;
import android.util.SparseIntArray;
import android.util.StatsLog;
import android.util.TimeUtils;
import android.util.Xml;
import android.util.proto.ProtoOutputStream;
@@ -386,6 +387,9 @@ final class SettingsState {
            mSettings.put(name, newState);
        }

        StatsLog.write(StatsLog.SETTING_CHANGED, name, value, newState.value, oldValue, tag,
            makeDefault, getUserIdFromKey(mKey), StatsLog.SETTING_CHANGED__REASON__UPDATED);

        addHistoricalOperationLocked(HISTORICAL_OPERATION_UPDATE, newState);

        updateMemoryUsagePerPackageLocked(packageName, oldValue, value,
@@ -410,6 +414,10 @@ final class SettingsState {

        Setting oldState = mSettings.remove(name);

        StatsLog.write(StatsLog.SETTING_CHANGED, name, /* value= */ "", /* newValue= */ "",
            oldState.value, /* tag */ "", false, getUserIdFromKey(mKey),
            StatsLog.SETTING_CHANGED__REASON__DELETED);

        updateMemoryUsagePerPackageLocked(oldState.packageName, oldState.value,
                null, oldState.defaultValue, null);