1 /* 2 * Copyright (C) 2020 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.settings.development.storage; 18 19 import android.icu.text.SimpleDateFormat; 20 import android.icu.util.Calendar; 21 import android.icu.util.TimeZone; 22 23 import java.util.Locale; 24 25 class SharedDataUtils { 26 static final String BLOB_KEY = "BLOB_KEY"; 27 28 static final int LEASE_VIEW_REQUEST_CODE = 8108; 29 static final int LEASE_VIEW_RESULT_CODE_SUCCESS = 1; 30 static final int LEASE_VIEW_RESULT_CODE_FAILURE = -1; 31 32 private static final String BLOB_EXPIRY_PATTERN = "MMM dd, yyyy HH:mm:ss z"; 33 34 private static final SimpleDateFormat FORMATTER = new SimpleDateFormat(BLOB_EXPIRY_PATTERN); 35 private static final Calendar CALENDAR = Calendar.getInstance( 36 TimeZone.getDefault(), Locale.getDefault()); 37 formatTime(long millis)38 static String formatTime(long millis) { 39 CALENDAR.setTimeInMillis(millis); 40 return FORMATTER.format(CALENDAR.getTime()); 41 } 42 formatSize(long sizeBytes)43 static String formatSize(long sizeBytes) { 44 final double sizeInMb = sizeBytes / (1024.0 * 1024.0); 45 return String.format("%.2f MB", sizeInMb); 46 } 47 } 48