1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.server.backup; 18 19 import static com.android.server.backup.BackupManagerService.TAG; 20 21 import android.app.backup.BackupAgent; 22 import android.util.Slog; 23 24 import java.text.SimpleDateFormat; 25 import java.util.Date; 26 27 /** 28 * Description of a file in the restore datastream. 29 */ 30 public class FileMetadata { 31 public String packageName; // name of the owning app 32 public String installerPackageName; // name of the market-type app that installed the owner 33 public int type; // e.g. BackupAgent.TYPE_DIRECTORY 34 public String domain; // e.g. FullBackup.DATABASE_TREE_TOKEN 35 public String path; // subpath within the semantic domain 36 public long mode; // e.g. 0666 (actually int) 37 public long mtime; // last mod time, UTC time_t (actually int) 38 public long size; // bytes of content 39 public long version; // App version. 40 public boolean hasApk; // Whether backup file contains apk. 41 42 @Override toString()43 public String toString() { 44 // TODO: Clean this up. 45 StringBuilder sb = new StringBuilder(128); 46 sb.append("FileMetadata{"); 47 sb.append(packageName); 48 sb.append(','); 49 sb.append(type); 50 sb.append(','); 51 sb.append(domain); 52 sb.append(':'); 53 sb.append(path); 54 sb.append(','); 55 sb.append(size); 56 sb.append('}'); 57 return sb.toString(); 58 } 59 dump()60 public void dump() { 61 StringBuilder b = new StringBuilder(128); 62 63 // mode string 64 b.append((type == BackupAgent.TYPE_DIRECTORY) ? 'd' : '-'); 65 b.append(((mode & 0400) != 0) ? 'r' : '-'); 66 b.append(((mode & 0200) != 0) ? 'w' : '-'); 67 b.append(((mode & 0100) != 0) ? 'x' : '-'); 68 b.append(((mode & 0040) != 0) ? 'r' : '-'); 69 b.append(((mode & 0020) != 0) ? 'w' : '-'); 70 b.append(((mode & 0010) != 0) ? 'x' : '-'); 71 b.append(((mode & 0004) != 0) ? 'r' : '-'); 72 b.append(((mode & 0002) != 0) ? 'w' : '-'); 73 b.append(((mode & 0001) != 0) ? 'x' : '-'); 74 b.append(String.format(" %9d ", size)); 75 76 Date stamp = new Date(mtime); 77 b.append(new SimpleDateFormat("MMM dd HH:mm:ss ").format(stamp)); 78 79 b.append(packageName); 80 b.append(" :: "); 81 b.append(domain); 82 b.append(" :: "); 83 b.append(path); 84 85 Slog.i(TAG, b.toString()); 86 } 87 88 } 89