Loading services/companion/java/com/android/server/companion/BackupRestoreProcessor.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -136,7 +136,7 @@ class BackupRestoreProcessor { byte[] requestsPayload = new byte[buffer.getInt()]; byte[] requestsPayload = new byte[buffer.getInt()]; buffer.get(requestsPayload); buffer.get(requestsPayload); List<SystemDataTransferRequest> restoredRequestsForUser = List<SystemDataTransferRequest> restoredRequestsForUser = mSystemDataTransferRequestStore.readRequestsFromPayload(requestsPayload); mSystemDataTransferRequestStore.readRequestsFromPayload(requestsPayload, userId); // Get a list of installed packages ahead of time. // Get a list of installed packages ahead of time. List<ApplicationInfo> installedApps = mPackageManager.getInstalledApplications( List<ApplicationInfo> installedApps = mPackageManager.getInstalledApplications( Loading services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferRequestStore.java +8 −10 Original line number Original line Diff line number Diff line Loading @@ -69,7 +69,6 @@ import java.util.concurrent.TimeoutException; * <request * <request * association_id="1" * association_id="1" * data_type="1" * data_type="1" * user_id="12" * is_user_consented="true" * is_user_consented="true" * </request> * </request> * </requests> * </requests> Loading @@ -86,7 +85,6 @@ public class SystemDataTransferRequestStore { private static final String XML_ATTR_ASSOCIATION_ID = "association_id"; private static final String XML_ATTR_ASSOCIATION_ID = "association_id"; private static final String XML_ATTR_DATA_TYPE = "data_type"; private static final String XML_ATTR_DATA_TYPE = "data_type"; private static final String XML_ATTR_USER_ID = "user_id"; private static final String XML_ATTR_IS_USER_CONSENTED = "is_user_consented"; private static final String XML_ATTR_IS_USER_CONSENTED = "is_user_consented"; private static final int READ_FROM_DISK_TIMEOUT = 5; // in seconds private static final int READ_FROM_DISK_TIMEOUT = 5; // in seconds Loading Loading @@ -169,12 +167,12 @@ public class SystemDataTransferRequestStore { * Parse the byte array containing XML information of system data transfer requests into * Parse the byte array containing XML information of system data transfer requests into * an array list of requests. * an array list of requests. */ */ public List<SystemDataTransferRequest> readRequestsFromPayload(byte[] payload) { public List<SystemDataTransferRequest> readRequestsFromPayload(byte[] payload, int userId) { try (ByteArrayInputStream in = new ByteArrayInputStream(payload)) { try (ByteArrayInputStream in = new ByteArrayInputStream(payload)) { final TypedXmlPullParser parser = Xml.resolvePullParser(in); final TypedXmlPullParser parser = Xml.resolvePullParser(in); XmlUtils.beginDocument(parser, XML_TAG_REQUESTS); XmlUtils.beginDocument(parser, XML_TAG_REQUESTS); return readRequestsFromXml(parser); return readRequestsFromXml(parser, userId); } catch (XmlPullParserException | IOException e) { } catch (XmlPullParserException | IOException e) { Slog.e(LOG_TAG, "Error while reading requests file", e); Slog.e(LOG_TAG, "Error while reading requests file", e); return new ArrayList<>(); return new ArrayList<>(); Loading Loading @@ -226,7 +224,7 @@ public class SystemDataTransferRequestStore { final TypedXmlPullParser parser = Xml.resolvePullParser(in); final TypedXmlPullParser parser = Xml.resolvePullParser(in); XmlUtils.beginDocument(parser, XML_TAG_REQUESTS); XmlUtils.beginDocument(parser, XML_TAG_REQUESTS); return readRequestsFromXml(parser); return readRequestsFromXml(parser, userId); } catch (XmlPullParserException | IOException e) { } catch (XmlPullParserException | IOException e) { Slog.e(LOG_TAG, "Error while reading requests file", e); Slog.e(LOG_TAG, "Error while reading requests file", e); return new ArrayList<>(); return new ArrayList<>(); Loading @@ -236,7 +234,8 @@ public class SystemDataTransferRequestStore { @NonNull @NonNull private ArrayList<SystemDataTransferRequest> readRequestsFromXml( private ArrayList<SystemDataTransferRequest> readRequestsFromXml( @NonNull TypedXmlPullParser parser) throws XmlPullParserException, IOException { @NonNull TypedXmlPullParser parser, int userId) throws XmlPullParserException, IOException { if (!isStartOfTag(parser, XML_TAG_REQUESTS)) { if (!isStartOfTag(parser, XML_TAG_REQUESTS)) { throw new XmlPullParserException("The XML doesn't have start tag: " + XML_TAG_REQUESTS); throw new XmlPullParserException("The XML doesn't have start tag: " + XML_TAG_REQUESTS); } } Loading @@ -249,14 +248,15 @@ public class SystemDataTransferRequestStore { break; break; } } if (isStartOfTag(parser, XML_TAG_REQUEST)) { if (isStartOfTag(parser, XML_TAG_REQUEST)) { requests.add(readRequestFromXml(parser)); requests.add(readRequestFromXml(parser, userId)); } } } } return requests; return requests; } } private SystemDataTransferRequest readRequestFromXml(@NonNull TypedXmlPullParser parser) private SystemDataTransferRequest readRequestFromXml(@NonNull TypedXmlPullParser parser, int userId) throws XmlPullParserException, IOException { throws XmlPullParserException, IOException { if (!isStartOfTag(parser, XML_TAG_REQUEST)) { if (!isStartOfTag(parser, XML_TAG_REQUEST)) { throw new XmlPullParserException("XML doesn't have start tag: " + XML_TAG_REQUEST); throw new XmlPullParserException("XML doesn't have start tag: " + XML_TAG_REQUEST); Loading @@ -264,7 +264,6 @@ public class SystemDataTransferRequestStore { final int associationId = readIntAttribute(parser, XML_ATTR_ASSOCIATION_ID); final int associationId = readIntAttribute(parser, XML_ATTR_ASSOCIATION_ID); final int dataType = readIntAttribute(parser, XML_ATTR_DATA_TYPE); final int dataType = readIntAttribute(parser, XML_ATTR_DATA_TYPE); final int userId = readIntAttribute(parser, XML_ATTR_USER_ID); final boolean isUserConsented = readBooleanAttribute(parser, XML_ATTR_IS_USER_CONSENTED); final boolean isUserConsented = readBooleanAttribute(parser, XML_ATTR_IS_USER_CONSENTED); switch (dataType) { switch (dataType) { Loading Loading @@ -321,7 +320,6 @@ public class SystemDataTransferRequestStore { writeIntAttribute(serializer, XML_ATTR_ASSOCIATION_ID, request.getAssociationId()); writeIntAttribute(serializer, XML_ATTR_ASSOCIATION_ID, request.getAssociationId()); writeIntAttribute(serializer, XML_ATTR_DATA_TYPE, request.getDataType()); writeIntAttribute(serializer, XML_ATTR_DATA_TYPE, request.getDataType()); writeIntAttribute(serializer, XML_ATTR_USER_ID, request.getUserId()); writeBooleanAttribute(serializer, XML_ATTR_IS_USER_CONSENTED, request.isUserConsented()); writeBooleanAttribute(serializer, XML_ATTR_IS_USER_CONSENTED, request.isUserConsented()); serializer.endTag(null, XML_TAG_REQUEST); serializer.endTag(null, XML_TAG_REQUEST); Loading Loading
services/companion/java/com/android/server/companion/BackupRestoreProcessor.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -136,7 +136,7 @@ class BackupRestoreProcessor { byte[] requestsPayload = new byte[buffer.getInt()]; byte[] requestsPayload = new byte[buffer.getInt()]; buffer.get(requestsPayload); buffer.get(requestsPayload); List<SystemDataTransferRequest> restoredRequestsForUser = List<SystemDataTransferRequest> restoredRequestsForUser = mSystemDataTransferRequestStore.readRequestsFromPayload(requestsPayload); mSystemDataTransferRequestStore.readRequestsFromPayload(requestsPayload, userId); // Get a list of installed packages ahead of time. // Get a list of installed packages ahead of time. List<ApplicationInfo> installedApps = mPackageManager.getInstalledApplications( List<ApplicationInfo> installedApps = mPackageManager.getInstalledApplications( Loading
services/companion/java/com/android/server/companion/datatransfer/SystemDataTransferRequestStore.java +8 −10 Original line number Original line Diff line number Diff line Loading @@ -69,7 +69,6 @@ import java.util.concurrent.TimeoutException; * <request * <request * association_id="1" * association_id="1" * data_type="1" * data_type="1" * user_id="12" * is_user_consented="true" * is_user_consented="true" * </request> * </request> * </requests> * </requests> Loading @@ -86,7 +85,6 @@ public class SystemDataTransferRequestStore { private static final String XML_ATTR_ASSOCIATION_ID = "association_id"; private static final String XML_ATTR_ASSOCIATION_ID = "association_id"; private static final String XML_ATTR_DATA_TYPE = "data_type"; private static final String XML_ATTR_DATA_TYPE = "data_type"; private static final String XML_ATTR_USER_ID = "user_id"; private static final String XML_ATTR_IS_USER_CONSENTED = "is_user_consented"; private static final String XML_ATTR_IS_USER_CONSENTED = "is_user_consented"; private static final int READ_FROM_DISK_TIMEOUT = 5; // in seconds private static final int READ_FROM_DISK_TIMEOUT = 5; // in seconds Loading Loading @@ -169,12 +167,12 @@ public class SystemDataTransferRequestStore { * Parse the byte array containing XML information of system data transfer requests into * Parse the byte array containing XML information of system data transfer requests into * an array list of requests. * an array list of requests. */ */ public List<SystemDataTransferRequest> readRequestsFromPayload(byte[] payload) { public List<SystemDataTransferRequest> readRequestsFromPayload(byte[] payload, int userId) { try (ByteArrayInputStream in = new ByteArrayInputStream(payload)) { try (ByteArrayInputStream in = new ByteArrayInputStream(payload)) { final TypedXmlPullParser parser = Xml.resolvePullParser(in); final TypedXmlPullParser parser = Xml.resolvePullParser(in); XmlUtils.beginDocument(parser, XML_TAG_REQUESTS); XmlUtils.beginDocument(parser, XML_TAG_REQUESTS); return readRequestsFromXml(parser); return readRequestsFromXml(parser, userId); } catch (XmlPullParserException | IOException e) { } catch (XmlPullParserException | IOException e) { Slog.e(LOG_TAG, "Error while reading requests file", e); Slog.e(LOG_TAG, "Error while reading requests file", e); return new ArrayList<>(); return new ArrayList<>(); Loading Loading @@ -226,7 +224,7 @@ public class SystemDataTransferRequestStore { final TypedXmlPullParser parser = Xml.resolvePullParser(in); final TypedXmlPullParser parser = Xml.resolvePullParser(in); XmlUtils.beginDocument(parser, XML_TAG_REQUESTS); XmlUtils.beginDocument(parser, XML_TAG_REQUESTS); return readRequestsFromXml(parser); return readRequestsFromXml(parser, userId); } catch (XmlPullParserException | IOException e) { } catch (XmlPullParserException | IOException e) { Slog.e(LOG_TAG, "Error while reading requests file", e); Slog.e(LOG_TAG, "Error while reading requests file", e); return new ArrayList<>(); return new ArrayList<>(); Loading @@ -236,7 +234,8 @@ public class SystemDataTransferRequestStore { @NonNull @NonNull private ArrayList<SystemDataTransferRequest> readRequestsFromXml( private ArrayList<SystemDataTransferRequest> readRequestsFromXml( @NonNull TypedXmlPullParser parser) throws XmlPullParserException, IOException { @NonNull TypedXmlPullParser parser, int userId) throws XmlPullParserException, IOException { if (!isStartOfTag(parser, XML_TAG_REQUESTS)) { if (!isStartOfTag(parser, XML_TAG_REQUESTS)) { throw new XmlPullParserException("The XML doesn't have start tag: " + XML_TAG_REQUESTS); throw new XmlPullParserException("The XML doesn't have start tag: " + XML_TAG_REQUESTS); } } Loading @@ -249,14 +248,15 @@ public class SystemDataTransferRequestStore { break; break; } } if (isStartOfTag(parser, XML_TAG_REQUEST)) { if (isStartOfTag(parser, XML_TAG_REQUEST)) { requests.add(readRequestFromXml(parser)); requests.add(readRequestFromXml(parser, userId)); } } } } return requests; return requests; } } private SystemDataTransferRequest readRequestFromXml(@NonNull TypedXmlPullParser parser) private SystemDataTransferRequest readRequestFromXml(@NonNull TypedXmlPullParser parser, int userId) throws XmlPullParserException, IOException { throws XmlPullParserException, IOException { if (!isStartOfTag(parser, XML_TAG_REQUEST)) { if (!isStartOfTag(parser, XML_TAG_REQUEST)) { throw new XmlPullParserException("XML doesn't have start tag: " + XML_TAG_REQUEST); throw new XmlPullParserException("XML doesn't have start tag: " + XML_TAG_REQUEST); Loading @@ -264,7 +264,6 @@ public class SystemDataTransferRequestStore { final int associationId = readIntAttribute(parser, XML_ATTR_ASSOCIATION_ID); final int associationId = readIntAttribute(parser, XML_ATTR_ASSOCIATION_ID); final int dataType = readIntAttribute(parser, XML_ATTR_DATA_TYPE); final int dataType = readIntAttribute(parser, XML_ATTR_DATA_TYPE); final int userId = readIntAttribute(parser, XML_ATTR_USER_ID); final boolean isUserConsented = readBooleanAttribute(parser, XML_ATTR_IS_USER_CONSENTED); final boolean isUserConsented = readBooleanAttribute(parser, XML_ATTR_IS_USER_CONSENTED); switch (dataType) { switch (dataType) { Loading Loading @@ -321,7 +320,6 @@ public class SystemDataTransferRequestStore { writeIntAttribute(serializer, XML_ATTR_ASSOCIATION_ID, request.getAssociationId()); writeIntAttribute(serializer, XML_ATTR_ASSOCIATION_ID, request.getAssociationId()); writeIntAttribute(serializer, XML_ATTR_DATA_TYPE, request.getDataType()); writeIntAttribute(serializer, XML_ATTR_DATA_TYPE, request.getDataType()); writeIntAttribute(serializer, XML_ATTR_USER_ID, request.getUserId()); writeBooleanAttribute(serializer, XML_ATTR_IS_USER_CONSENTED, request.isUserConsented()); writeBooleanAttribute(serializer, XML_ATTR_IS_USER_CONSENTED, request.isUserConsented()); serializer.endTag(null, XML_TAG_REQUEST); serializer.endTag(null, XML_TAG_REQUEST); Loading