Lines Matching refs:Key
49 import com.android.launcher3.backup.nano.BackupProtos.Key;
84 // Journal key is such that it is always smaller than any dynamically generated
85 // key (any Base64 encoded string).
145 private final ArrayList<Key> mKeys;
171 mKeys = new ArrayList<Key>();
189 if (journal.key != null) {
190 for (Key key : journal.key) {
191 mExistingKeys.add(keyToBackupKey(key));
202 * <P>Keys may come back in any order, so each key/value is one complete row of the database.
205 * @param data incremental key/value pairs to persist off-device
242 // Delete any key which still exist in the old backup, but is not valid anymore.
244 for (Key key : mKeys) {
245 validKeys.add(keyToBackupKey(key));
336 * @param data the key/value pair from the server
364 // We received the journal key after a restore key.
378 if (DEBUG) Log.e(TAG, "Ignoring key not present in the backup state " + backupKey);
381 Key key = backupKeyToKey(backupKey);
382 mKeys.add(key);
383 switch (key.type) {
384 case Key.FAVORITE:
385 restoreFavorite(key, mBuffer, dataSize);
388 case Key.SCREEN:
389 restoreScreen(key, mBuffer, dataSize);
392 case Key.ICON:
393 restoreIcon(key, mBuffer, dataSize);
396 case Key.WIDGET:
397 restoreWidget(key, mBuffer, dataSize);
401 Log.w(TAG, "unknown restore entity type: " + key.type);
402 mKeys.remove(key);
423 journal.key = mKeys.toArray(new BackupProtos.Key[mKeys.size()]);
451 * @param data output stream for key/value pairs
465 Key key = getKey(Key.FAVORITE, id);
466 mKeys.add(key);
467 final String backupKey = keyToBackupKey(key);
472 writeRowToBackup(key, packFavorite(cursor), data);
487 * @param key identifier for the row
491 private void restoreFavorite(Key key, byte[] buffer, int dataSize) throws IOException {
492 if (VERBOSE) Log.v(TAG, "unpacking favorite " + key.id);
504 * @param data output stream for key/value pairs
518 Key key = getKey(Key.SCREEN, id);
519 mKeys.add(key);
520 final String backupKey = keyToBackupKey(key);
522 writeRowToBackup(key, packScreen(cursor), data);
537 * @param key identifier for the row
541 private void restoreScreen(Key key, byte[] buffer, int dataSize) throws IOException {
542 if (VERBOSE) Log.v(TAG, "unpacking screen " + key.id);
555 * @param data output stream for key/value pairs
578 Key key = null;
581 key = getKey(Key.ICON, cn.flattenToShortString());
582 backupKey = keyToBackupKey(key);
590 mKeys.add(key);
597 writeRowToBackup(key, packIcon(dpi, icon), data);
598 mKeys.add(key);
624 * @param key identifier for the row
628 private void restoreIcon(Key key, byte[] buffer, int dataSize) throws IOException {
629 if (VERBOSE) Log.v(TAG, "unpacking icon " + key.id);
639 Log.w(TAG, "failed to unpack icon for " + key.name);
641 if (VERBOSE) Log.v(TAG, "saving restored icon as: " + key.name);
642 mIconCache.preloadIcon(ComponentName.unflattenFromString(key.name), icon, res.dpi,
651 * @param data output stream for key/value pairs
672 Key key = null;
675 key = getKey(Key.WIDGET, providerName);
676 backupKey = keyToBackupKey(key);
686 mKeys.add(key);
694 writeRowToBackup(key, packWidget(dpi, widgetInfo), data);
695 mKeys.add(key);
715 * @param key identifier for the row
719 private void restoreWidget(Key key, byte[] buffer, int dataSize) throws IOException {
720 if (VERBOSE) Log.v(TAG, "unpacking widget " + key.id);
729 Log.w(TAG, "failed to unpack widget icon for " + key.name);
740 /** create a new key, with an integer ID.
745 private Key getKey(int type, long id) {
746 Key key = new Key();
747 key.type = type;
748 key.id = id;
749 key.checksum = checkKey(key);
750 return key;
753 /** create a new key for a named object.
758 private Key getKey(int type, String name) {
759 Key key = new Key();
760 key.type = type;
761 key.name = name;
762 key.checksum = checkKey(key);
763 return key;
767 private String keyToBackupKey(Key key) {
768 return Base64.encodeToString(Key.toByteArray(key), Base64.NO_WRAP);
772 private Key backupKeyToKey(String backupKey) throws InvalidBackupException {
774 Key key = Key.parseFrom(Base64.decode(backupKey, Base64.DEFAULT));
775 if (key.checksum != checkKey(key)) {
776 throw new InvalidBackupException("invalid key read from stream" + backupKey);
778 return key;
784 /** Compute the checksum over the important bits of a key. */
785 private long checkKey(Key key) {
787 checksum.update(key.type);
788 checksum.update((int) (key.id & 0xffff));
789 checksum.update((int) ((key.id >> 32) & 0xffff));
790 if (!TextUtils.isEmpty(key.name)) {
791 checksum.update(key.name.getBytes());
1109 private void writeRowToBackup(Key key, MessageNano proto, BackupDataOutput data)
1111 writeRowToBackup(keyToBackupKey(key), proto, data);