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

Commit 8a7102c1 authored by Sarp Misoglu's avatar Sarp Misoglu
Browse files

Fix debug logging in the backup service

The existing DEBUG and DEBUG_SCHEDULING had been set to true (maybe
accidentally?) for 8+ years. Whereas MORE_DEBUG is false as expected. In
this CL we:

1) Remove existing DEBUG and DEBUG_SCHEDULING checks. This is a no-op.
2) Rename MORE_DEBUG to DEBUG. Also no-op.
3) Make any Log.v log that isn't guarded by if(DEBUG) a Log.d instead.
   Log.v logs should always be guarded by a default false constant so
   the compiler strips out the Strings from the binary.

Test: n/a
Flag: EXEMPT no-op refactor
Change-Id: I117f7fe04da1a62c3ad42d71b080fed6454f73af
parent 2a5d587f
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -16,7 +16,7 @@


package com.android.server.backup;
package com.android.server.backup;


import static com.android.server.backup.BackupManagerService.MORE_DEBUG;
import static com.android.server.backup.BackupManagerService.DEBUG;
import static com.android.server.backup.BackupManagerService.TAG;
import static com.android.server.backup.BackupManagerService.TAG;


import android.annotation.Nullable;
import android.annotation.Nullable;
@@ -302,7 +302,7 @@ public class BackupAgentConnectionManager {
                // that the package being backed up doesn't get stuck in restricted mode until the
                // that the package being backed up doesn't get stuck in restricted mode until the
                // backup time-out elapses.
                // backup time-out elapses.
                for (int token : mOperationStorage.operationTokensForPackage(packageName)) {
                for (int token : mOperationStorage.operationTokensForPackage(packageName)) {
                    if (MORE_DEBUG) {
                    if (DEBUG) {
                        Slog.d(TAG,
                        Slog.d(TAG,
                                mUserIdMsg + "agentDisconnected: will handleCancel(all) for token:"
                                mUserIdMsg + "agentDisconnected: will handleCancel(all) for token:"
                                        + Integer.toHexString(token));
                                        + Integer.toHexString(token));
+16 −48
Original line number Original line Diff line number Diff line
@@ -16,8 +16,6 @@


package com.android.server.backup;
package com.android.server.backup;


import static com.android.server.backup.BackupManagerService.DEBUG_SCHEDULING;

import android.app.AlarmManager;
import android.app.AlarmManager;
import android.app.job.JobInfo;
import android.app.job.JobInfo;
import android.content.ContentResolver;
import android.content.ContentResolver;
@@ -168,85 +166,55 @@ public class BackupManagerConstants extends KeyValueSettingObserver {
    // group the calls of these methods in a block syncrhonized on
    // group the calls of these methods in a block syncrhonized on
    // a reference of this object.
    // a reference of this object.
    public synchronized long getKeyValueBackupIntervalMilliseconds() {
    public synchronized long getKeyValueBackupIntervalMilliseconds() {
        if (DEBUG_SCHEDULING) {
        Slog.d(TAG, "getKeyValueBackupIntervalMilliseconds(...) returns "
            Slog.v(
                    TAG,
                    "getKeyValueBackupIntervalMilliseconds(...) returns "
                + mKeyValueBackupIntervalMilliseconds);
                + mKeyValueBackupIntervalMilliseconds);
        }
        return mKeyValueBackupIntervalMilliseconds;
        return mKeyValueBackupIntervalMilliseconds;
    }
    }


    public synchronized long getKeyValueBackupFuzzMilliseconds() {
    public synchronized long getKeyValueBackupFuzzMilliseconds() {
        if (DEBUG_SCHEDULING) {
        Slog.d(TAG, "getKeyValueBackupFuzzMilliseconds(...) returns "
            Slog.v(
                    TAG,
                    "getKeyValueBackupFuzzMilliseconds(...) returns "
                + mKeyValueBackupFuzzMilliseconds);
                + mKeyValueBackupFuzzMilliseconds);
        }
        return mKeyValueBackupFuzzMilliseconds;
        return mKeyValueBackupFuzzMilliseconds;
    }
    }


    public synchronized boolean getKeyValueBackupRequireCharging() {
    public synchronized boolean getKeyValueBackupRequireCharging() {
        if (DEBUG_SCHEDULING) {
        Slog.d(TAG,
            Slog.v(
                "getKeyValueBackupRequireCharging(...) returns " + mKeyValueBackupRequireCharging);
                    TAG,
                    "getKeyValueBackupRequireCharging(...) returns "
                            + mKeyValueBackupRequireCharging);
        }
        return mKeyValueBackupRequireCharging;
        return mKeyValueBackupRequireCharging;
    }
    }


    public synchronized int getKeyValueBackupRequiredNetworkType() {
    public synchronized int getKeyValueBackupRequiredNetworkType() {
        if (DEBUG_SCHEDULING) {
        Slog.d(TAG, "getKeyValueBackupRequiredNetworkType(...) returns "
            Slog.v(
                    TAG,
                    "getKeyValueBackupRequiredNetworkType(...) returns "
                + mKeyValueBackupRequiredNetworkType);
                + mKeyValueBackupRequiredNetworkType);
        }
        return mKeyValueBackupRequiredNetworkType;
        return mKeyValueBackupRequiredNetworkType;
    }
    }


    public synchronized long getFullBackupIntervalMilliseconds() {
    public synchronized long getFullBackupIntervalMilliseconds() {
        if (DEBUG_SCHEDULING) {
        Slog.d(TAG, "getFullBackupIntervalMilliseconds(...) returns "
            Slog.v(
                    TAG,
                    "getFullBackupIntervalMilliseconds(...) returns "
                + mFullBackupIntervalMilliseconds);
                + mFullBackupIntervalMilliseconds);
        }
        return mFullBackupIntervalMilliseconds;
        return mFullBackupIntervalMilliseconds;
    }
    }


    public synchronized boolean getFullBackupRequireCharging() {
    public synchronized boolean getFullBackupRequireCharging() {
        if (DEBUG_SCHEDULING) {
        Slog.d(TAG, "getFullBackupRequireCharging(...) returns " + mFullBackupRequireCharging);
            Slog.v(TAG, "getFullBackupRequireCharging(...) returns " + mFullBackupRequireCharging);
        }
        return mFullBackupRequireCharging;
        return mFullBackupRequireCharging;
    }
    }


    public synchronized int getFullBackupRequiredNetworkType() {
    public synchronized int getFullBackupRequiredNetworkType() {
        if (DEBUG_SCHEDULING) {
        Slog.d(TAG,
            Slog.v(
                "getFullBackupRequiredNetworkType(...) returns " + mFullBackupRequiredNetworkType);
                    TAG,
                    "getFullBackupRequiredNetworkType(...) returns "
                            + mFullBackupRequiredNetworkType);
        }
        return mFullBackupRequiredNetworkType;
        return mFullBackupRequiredNetworkType;
    }
    }


    /** Returns an array of package names that should be notified whenever a backup finishes. */
    /** Returns an array of package names that should be notified whenever a backup finishes. */
    public synchronized String[] getBackupFinishedNotificationReceivers() {
    public synchronized String[] getBackupFinishedNotificationReceivers() {
        if (DEBUG_SCHEDULING) {
        Slog.d(TAG, "getBackupFinishedNotificationReceivers(...) returns " + TextUtils.join(", ",
            Slog.v(
                mBackupFinishedNotificationReceivers));
                    TAG,
                    "getBackupFinishedNotificationReceivers(...) returns "
                            + TextUtils.join(", ", mBackupFinishedNotificationReceivers));
        }
        return mBackupFinishedNotificationReceivers;
        return mBackupFinishedNotificationReceivers;
    }
    }


    public synchronized long getWakelockTimeoutMillis() {
    public synchronized long getWakelockTimeoutMillis() {
        Slog.v(TAG, "wakelock timeout: " + mWakelockTimeoutMillis);
        Slog.d(TAG, "wakelock timeout: " + mWakelockTimeoutMillis);
        return mWakelockTimeoutMillis;
        return mWakelockTimeoutMillis;
    }
    }
}
}
+2 −6
Original line number Original line Diff line number Diff line
@@ -94,9 +94,7 @@ import java.util.Set;
 */
 */
public class BackupManagerService extends IBackupManager.Stub implements BackupManagerInternal {
public class BackupManagerService extends IBackupManager.Stub implements BackupManagerInternal {
    public static final String TAG = "BackupManagerService";
    public static final String TAG = "BackupManagerService";
    public static final boolean DEBUG = true;
    public static final boolean DEBUG = false;
    public static final boolean MORE_DEBUG = false;
    public static final boolean DEBUG_SCHEDULING = true;


    @VisibleForTesting
    @VisibleForTesting
    static final String DUMP_RUNNING_USERS_MESSAGE = "Backup Manager is running for users:";
    static final String DUMP_RUNNING_USERS_MESSAGE = "Backup Manager is running for users:";
@@ -187,10 +185,8 @@ public class BackupManagerService extends IBackupManager.Stub implements BackupM
                mUserRemovedReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
                mUserRemovedReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
        UserHandle mainUser = getUserManager().getMainUser();
        UserHandle mainUser = getUserManager().getMainUser();
        mDefaultBackupUserId = mainUser == null ? UserHandle.USER_SYSTEM : mainUser.getIdentifier();
        mDefaultBackupUserId = mainUser == null ? UserHandle.USER_SYSTEM : mainUser.getIdentifier();
        if (DEBUG) {
        Slog.d(TAG, "Default backup user id = " + mDefaultBackupUserId);
        Slog.d(TAG, "Default backup user id = " + mDefaultBackupUserId);
    }
    }
    }


    @VisibleForTesting
    @VisibleForTesting
    Handler getBackupHandler() {
    Handler getBackupHandler() {
+4 −12
Original line number Original line Diff line number Diff line
@@ -180,9 +180,7 @@ public class KeyValueAdbBackupEngine {
                Slog.e(TAG, "Key-value backup failed on package " + packageName);
                Slog.e(TAG, "Key-value backup failed on package " + packageName);
                return false;
                return false;
            }
            }
            if (DEBUG) {
            Slog.i(TAG, "Key-value backup success for package " + packageName);
            Slog.i(TAG, "Key-value backup success for package " + packageName);
            }
            return true;
            return true;
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Slog.e(TAG, "Error invoking agent for backup on " + packageName + ". " + e);
            Slog.e(TAG, "Error invoking agent for backup on " + packageName + ". " + e);
@@ -210,9 +208,7 @@ public class KeyValueAdbBackupEngine {
                AppMetadataBackupWriter writer =
                AppMetadataBackupWriter writer =
                        new AppMetadataBackupWriter(output, mPackageManager);
                        new AppMetadataBackupWriter(output, mPackageManager);


                if (DEBUG) {
                Slog.d(TAG, "Writing manifest for " + mPackage.packageName);
                Slog.d(TAG, "Writing manifest for " + mPackage.packageName);
                }


                writer.backupManifest(
                writer.backupManifest(
                        mPackage,
                        mPackage,
@@ -223,9 +219,7 @@ public class KeyValueAdbBackupEngine {
                        /* withApk */ false);
                        /* withApk */ false);
                mManifestFile.delete();
                mManifestFile.delete();


                if (DEBUG) {
                Slog.d(TAG, "Writing key-value package payload" + mPackage.packageName);
                Slog.d(TAG, "Writing key-value package payload" + mPackage.packageName);
                }
                FullBackup.backupToTar(mPackage.packageName, FullBackup.KEY_VALUE_DATA_TOKEN, null,
                FullBackup.backupToTar(mPackage.packageName, FullBackup.KEY_VALUE_DATA_TOKEN, null,
                        mDataDir.getAbsolutePath(),
                        mDataDir.getAbsolutePath(),
                        mBackupDataName.getAbsolutePath(),
                        mBackupDataName.getAbsolutePath(),
@@ -283,10 +277,8 @@ public class KeyValueAdbBackupEngine {
            if (!mBackupManagerService.waitUntilOperationComplete(token)) {
            if (!mBackupManagerService.waitUntilOperationComplete(token)) {
                Slog.e(TAG, "Full backup failed on package " + mCurrentPackage.packageName);
                Slog.e(TAG, "Full backup failed on package " + mCurrentPackage.packageName);
            } else {
            } else {
                if (DEBUG) {
                Slog.d(TAG, "Full package backup success: " + mCurrentPackage.packageName);
                Slog.d(TAG, "Full package backup success: " + mCurrentPackage.packageName);
            }
            }
            }
        } catch (IOException e) {
        } catch (IOException e) {
            Slog.e(TAG, "Error backing up " + mCurrentPackage.packageName + ": " + e);
            Slog.e(TAG, "Error backing up " + mCurrentPackage.packageName + ": " + e);
        } finally {
        } finally {
+1 −3
Original line number Original line Diff line number Diff line
@@ -89,10 +89,8 @@ public class KeyValueAdbRestoreEngine implements Runnable {
            ParcelFileDescriptor newState = ParcelFileDescriptor.open(newStateName,
            ParcelFileDescriptor newState = ParcelFileDescriptor.open(newStateName,
                    MODE_READ_WRITE | MODE_CREATE | MODE_TRUNCATE);
                    MODE_READ_WRITE | MODE_CREATE | MODE_TRUNCATE);


            if (DEBUG) {
            Slog.i(TAG, "Starting restore of package " + pkg + " for version code "
            Slog.i(TAG, "Starting restore of package " + pkg + " for version code "
                        + info.version);
                        + info.version);
            }
            agent.doRestore(backupData, info.version, newState, mToken,
            agent.doRestore(backupData, info.version, newState, mToken,
                    mBackupManagerService.getBackupManagerBinder());
                    mBackupManagerService.getBackupManagerBinder());
        } catch (IOException e) {
        } catch (IOException e) {
Loading