1/* 2 * Copyright (C) 2014 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 17package com.android.tv.settings.device.apps; 18 19import android.content.Context; 20import android.content.pm.ApplicationInfo; 21import android.content.pm.PackageManager.NameNotFoundException; 22import android.graphics.drawable.Drawable; 23import android.text.format.Formatter; 24 25/** 26 * Contains all the info necessary to manage an application. 27 */ 28class AppInfo { 29 30 private final Object mLock = new Object(); 31 private final Context mContext; 32 private ApplicationsState.AppEntry mEntry; 33 34 AppInfo(Context context, ApplicationsState.AppEntry entry) { 35 mContext = context; 36 mEntry = entry; 37 } 38 39 void setEntry(ApplicationsState.AppEntry entry) { 40 synchronized (mLock) { 41 mEntry = entry; 42 } 43 } 44 45 String getName() { 46 synchronized (mLock) { 47 mEntry.ensureLabel(mContext); 48 return mEntry.label; 49 } 50 } 51 52 String getSize() { 53 synchronized (mLock) { 54 return mEntry.sizeStr; 55 } 56 } 57 58 int getIconResource() { 59 synchronized (mLock) { 60 return mEntry.info.icon; 61 } 62 } 63 64 String getPackageName() { 65 synchronized (mLock) { 66 return mEntry.info.packageName; 67 } 68 } 69 70 ApplicationInfo getApplicationInfo() { 71 synchronized (mLock) { 72 return mEntry.info; 73 } 74 } 75 76 boolean isStopped() { 77 synchronized (mLock) { 78 return (mEntry.info.flags & ApplicationInfo.FLAG_STOPPED) != 0; 79 } 80 } 81 82 boolean isInstalled() { 83 synchronized (mLock) { 84 return (mEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) != 0; 85 } 86 } 87 88 boolean isUpdatedSystemApp() { 89 synchronized (mLock) { 90 return (mEntry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; 91 } 92 } 93 94 boolean isSystemApp() { 95 synchronized (mLock) { 96 return (mEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0; 97 } 98 } 99 100 String getCacheSize() { 101 synchronized (mLock) { 102 return Formatter.formatFileSize(mContext, mEntry.cacheSize + mEntry.externalCacheSize); 103 } 104 } 105 106 String getDataSize() { 107 synchronized (mLock) { 108 return Formatter.formatFileSize(mContext, mEntry.dataSize + mEntry.externalDataSize); 109 } 110 } 111 112 String getSpaceManagerActivityName() { 113 synchronized (mLock) { 114 return mEntry.info.manageSpaceActivityName; 115 } 116 } 117 118 int getUid() { 119 synchronized (mLock) { 120 return mEntry.info.uid; 121 } 122 } 123 124 String getVersion() { 125 synchronized (mLock) { 126 return mEntry.getVersion(mContext); 127 } 128 } 129 130 @Override 131 public String toString() { 132 return getName(); 133 } 134} 135