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

Commit c6adc683 authored by Joanne Chung's avatar Joanne Chung
Browse files

Handle SyncResultReceiver.TimeoutException

1.Change SyncResultReceiver.TimeoutException to checked exception
2.Handle the SyncResultReceiver.TimeoutException in AutofillManager,
ContentCaptureManager, ContentSuggestionsManager
3.Fix the bug we should throw e.rethrowFromSystemServer()

Bug: 156044027
Test: atest CtsAutoFillServiceTestCases
Test: atest ContentSuggestionsManagerTest
Test: atest CtsContentCaptureServiceTestCases
Change-Id: I959d2aca2b80866c076fae2520de66c123f5367d
parent c54d84a8
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public final class ContentSuggestionsManager {
        try {
            mService.provideContextBitmap(mUser, bitmap, imageContextRequestExtras);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
    }

@@ -117,7 +117,7 @@ public final class ContentSuggestionsManager {
        try {
            mService.provideContextImage(mUser, taskId, imageContextRequestExtras);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
    }

@@ -146,7 +146,7 @@ public final class ContentSuggestionsManager {
            mService.suggestContentSelections(
                    mUser, request, new SelectionsCallbackWrapper(callback, callbackExecutor));
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
    }

@@ -173,7 +173,7 @@ public final class ContentSuggestionsManager {
            mService.classifyContentSelections(
                    mUser, request, new ClassificationsCallbackWrapper(callback, callbackExecutor));
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
    }

@@ -193,7 +193,7 @@ public final class ContentSuggestionsManager {
        try {
            mService.notifyInteraction(mUser, requestId, interaction);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
    }

@@ -213,9 +213,10 @@ public final class ContentSuggestionsManager {
            mService.isEnabled(mUser, receiver);
            return receiver.getIntResult() != 0;
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get the enable status.");
        }
        return false;
    }

    /**
+35 −16
Original line number Diff line number Diff line
@@ -751,6 +751,8 @@ public final class AutofillManager {
                        }
                    } catch (RemoteException e) {
                        Log.e(TAG, "Could not figure out if there was an autofill session", e);
                    } catch (SyncResultReceiver.TimeoutException e) {
                        Log.e(TAG, "Fail to get session restore status: " + e);
                    }
                }
            }
@@ -864,7 +866,9 @@ public final class AutofillManager {
            mService.getFillEventHistory(receiver);
            return receiver.getParcelableResult();
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            Log.e(TAG, "Fail to get fill event history: " + e);
            return null;
        }
    }
@@ -1477,10 +1481,13 @@ public final class AutofillManager {

        final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
        try {
            mService.isServiceEnabled(mContext.getUserId(), mContext.getPackageName(), receiver);
            mService.isServiceEnabled(mContext.getUserId(), mContext.getPackageName(),
                    receiver);
            return receiver.getIntResult() == 1;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get enabled autofill services status.");
        }
    }

@@ -1498,6 +1505,8 @@ public final class AutofillManager {
            return receiver.getParcelableResult();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get autofill services component name.");
        }
    }

@@ -1522,8 +1531,9 @@ public final class AutofillManager {
            mService.getUserDataId(receiver);
            return receiver.getStringResult();
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            return null;
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get user data id for field classification.");
        }
    }

@@ -1544,8 +1554,9 @@ public final class AutofillManager {
            mService.getUserData(receiver);
            return receiver.getParcelableResult();
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            return null;
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get user data for field classification.");
        }
    }

@@ -1561,7 +1572,7 @@ public final class AutofillManager {
        try {
            mService.setUserData(userData);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
    }

@@ -1583,8 +1594,9 @@ public final class AutofillManager {
            mService.isFieldClassificationEnabled(receiver);
            return receiver.getIntResult() == 1;
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            return false;
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get field classification enabled status.");
        }
    }

@@ -1606,8 +1618,9 @@ public final class AutofillManager {
            mService.getDefaultFieldClassificationAlgorithm(receiver);
            return receiver.getStringResult();
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            return null;
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get default field classification algorithm.");
        }
    }

@@ -1627,8 +1640,9 @@ public final class AutofillManager {
            final String[] algorithms = receiver.getStringArrayResult();
            return algorithms != null ? Arrays.asList(algorithms) : Collections.emptyList();
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            return null;
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get available field classification algorithms.");
        }
    }

@@ -1651,6 +1665,8 @@ public final class AutofillManager {
            return receiver.getIntResult() == 1;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get autofill supported status.");
        }
    }

@@ -2040,13 +2056,16 @@ public final class AutofillManager {
        }

        final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
        final int resultCode;
        int resultCode;
        try {
            mService.setAugmentedAutofillWhitelist(toList(packages), toList(activities),
                    resultReceiver);
            resultCode = resultReceiver.getIntResult();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            Log.e(TAG, "Fail to get the result of set AugmentedAutofill whitelist. " + e);
            return;
        }
        switch (resultCode) {
            case RESULT_OK:
@@ -2283,7 +2302,7 @@ public final class AutofillManager {
                    // In theory, we could ignore this error since it's not a big deal, but
                    // in reality, we rather crash the app anyways, as the failure could be
                    // a consequence of something going wrong on the server side...
                    e.rethrowFromSystemServer();
                    throw e.rethrowFromSystemServer();
                }
            }

@@ -2661,7 +2680,7 @@ public final class AutofillManager {
            try {
                mService.onPendingSaveUi(operation, token);
            } catch (RemoteException e) {
                e.rethrowFromSystemServer();
                Log.e(TAG, "Error in onPendingSaveUi: ", e);
            }
        }
    }
+32 −15
Original line number Diff line number Diff line
@@ -487,6 +487,8 @@ public final class ContentCaptureManager {
            return resultReceiver.getParcelableResult();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get service componentName.");
        }
    }

@@ -516,6 +518,9 @@ public final class ContentCaptureManager {
            return resultReceiver.getParcelableResult();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            Log.e(TAG, "Fail to get service settings componentName: " + e);
            return null;
        }
    }

@@ -567,9 +572,13 @@ public final class ContentCaptureManager {
        final SyncResultReceiver resultReceiver = syncRun(
                (r) -> mService.getContentCaptureConditions(mContext.getPackageName(), r));

        try {
            final ArrayList<ContentCaptureCondition> result = resultReceiver
                    .getParcelableListResult();
            return toSet(result);
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get content capture conditions.");
        }
    }

    /**
@@ -639,6 +648,8 @@ public final class ContentCaptureManager {
    public boolean isContentCaptureFeatureEnabled() {
        final SyncResultReceiver resultReceiver = syncRun(
                (r) -> mService.isContentCaptureFeatureEnabled(r));

        try {
            final int resultCode = resultReceiver.getIntResult();
            switch (resultCode) {
                case RESULT_CODE_TRUE:
@@ -649,6 +660,10 @@ public final class ContentCaptureManager {
                    Log.wtf(TAG, "received invalid result: " + resultCode);
                    return false;
            }
        } catch (SyncResultReceiver.TimeoutException e) {
            Log.e(TAG, "Fail to get content capture feature enable status: " + e);
            return false;
        }
    }

    /**
@@ -663,7 +678,7 @@ public final class ContentCaptureManager {
        try {
            mService.removeData(request);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
    }

@@ -691,7 +706,7 @@ public final class ContentCaptureManager {
                    new DataShareAdapterDelegate(executor, dataShareWriteAdapter,
                            mDataShareAdapterResourceManager));
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
    }

@@ -709,10 +724,12 @@ public final class ContentCaptureManager {
            if (resultCode == RESULT_CODE_SECURITY_EXCEPTION) {
                throw new SecurityException(resultReceiver.getStringResult());
            }
            return resultReceiver;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        } catch (SyncResultReceiver.TimeoutException e) {
            throw new RuntimeException("Fail to get syn run result from SyncResultReceiver.");
        }
        return resultReceiver;
    }

    /** @hide */
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ public final class SyncResultReceiver extends IResultReceiver.Stub {
    }

    /** @hide */
    public static final class TimeoutException extends RuntimeException {
    public static final class TimeoutException extends Exception {
        private TimeoutException(String msg) {
            super(msg);
        }