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

Commit e4162b21 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 9011

* changes:
  Allow zero-length lists in EventLog entries.   (I'm verifying that the consumers of EventLog -- logcat, checkin -- are OK with this.) Improve the error handling in RestoreSession.
parents ff1907f6 0084da56
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -124,10 +124,6 @@ public class EventLog {
                        "A List must have fewer than "
                        + Byte.MAX_VALUE + " items in it.");
            }
            if (items.length < 1) {
                throw new IllegalArgumentException(
                        "A List must have at least one item in it.");
            }
            for (int i = 0; i < items.length; i++) {
                final Object item = items[i];
                if (item == null) {
@@ -223,7 +219,7 @@ public class EventLog {
            case LIST:
                if (mBuffer.remaining() < 1) return null;
                int length = mBuffer.get();
                if (length <= 0) return null;
                if (length < 0) return null;
                Object[] array = new Object[length];
                for (int i = 0; i < length; ++i) {
                    array[i] = decodeObject();
+37 −29
Original line number Diff line number Diff line
@@ -803,7 +803,7 @@ class BackupManagerService extends IBackupManager.Stub {

    class ClearDataObserver extends IPackageDataObserver.Stub {
        public void onRemoveCompleted(String packageName, boolean succeeded)
                throws android.os.RemoteException {
                throws RemoteException {
            synchronized(mClearDataLock) {
                mClearingData = false;
                mClearDataLock.notifyAll();
@@ -1666,34 +1666,37 @@ class BackupManagerService extends IBackupManager.Stub {
        }

        // --- Binder interface ---
        public RestoreSet[] getAvailableRestoreSets() throws android.os.RemoteException {
        public synchronized RestoreSet[] getAvailableRestoreSets() {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
                    "getAvailableRestoreSets");

            try {
            synchronized(this) {
                if (mRestoreTransport == null) {
                    Log.w(TAG, "Null transport getting restore sets");
                } else if (mRestoreSets == null) { // valid transport; do the one-time fetch
                    return null;
                }
                if (mRestoreSets == null) { // valid transport; do the one-time fetch
                    mRestoreSets = mRestoreTransport.getAvailableRestoreSets();
                    if (mRestoreSets == null) EventLog.writeEvent(RESTORE_TRANSPORT_FAILURE_EVENT);
                }
                return mRestoreSets;
            }
            } catch (RuntimeException e) {
                Log.d(TAG, "getAvailableRestoreSets exception");
                e.printStackTrace();
                throw e;
            } catch (Exception e) {
                Log.e(TAG, "Error in getAvailableRestoreSets", e);
                return null;
            }
        }

        public int performRestore(long token, IRestoreObserver observer)
                throws android.os.RemoteException {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "performRestore");
        public synchronized int performRestore(long token, IRestoreObserver observer) {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
                    "performRestore");

            Log.d(TAG, "performRestore token=" + token + " observer=" + observer);
            if (DEBUG) Log.d(TAG, "performRestore token=" + token + " observer=" + observer);

            if (mRestoreTransport == null || mRestoreSets == null) {
                Log.e(TAG, "Ignoring performRestore() with no restore set");
                return -1;
            }

            if (mRestoreSets != null) {
            for (int i = 0; i < mRestoreSets.length; i++) {
                if (token == mRestoreSets[i].token) {
                    mWakelock.acquire();
@@ -1703,20 +1706,25 @@ class BackupManagerService extends IBackupManager.Stub {
                    return 0;
                }
            }
            } else {
                if (DEBUG) Log.v(TAG, "No current restore set, not doing restore");
            }
            return -1;
        }

        public void endRestoreSession() throws android.os.RemoteException {
        public synchronized void endRestoreSession() {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
                    "endRestoreSession");

            Log.d(TAG, "endRestoreSession");
            if (DEBUG) Log.d(TAG, "endRestoreSession");

            mRestoreTransport.finishRestore();
            synchronized (this) {
                try {
                    if (mRestoreTransport != null) mRestoreTransport.finishRestore();
                } catch (Exception e) {
                    Log.e(TAG, "Error in finishRestore", e);
                } finally {
                    mRestoreTransport = null;
                }
            }

            synchronized (BackupManagerService.this) {
                if (BackupManagerService.this.mActiveRestoreSession == this) {
                    BackupManagerService.this.mActiveRestoreSession = null;