| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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; |
| 18 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 19 | import com.android.internal.app.IMediaContainerService; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import com.android.internal.app.ResolverActivity; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 21 | import com.android.internal.content.NativeLibraryHelper; |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 22 | import com.android.internal.content.PackageHelper; |
| Dianne Hackborn | 2269d157 | 2010-02-24 19:54:22 -0800 | [diff] [blame] | 23 | import com.android.internal.util.FastXmlSerializer; |
| Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 24 | import com.android.internal.util.JournaledFile; |
| Dianne Hackborn | 2269d157 | 2010-02-24 19:54:22 -0800 | [diff] [blame] | 25 | import com.android.internal.util.XmlUtils; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
| 27 | import org.xmlpull.v1.XmlPullParser; |
| 28 | import org.xmlpull.v1.XmlPullParserException; |
| 29 | import org.xmlpull.v1.XmlSerializer; |
| 30 | |
| 31 | import android.app.ActivityManagerNative; |
| 32 | import android.app.IActivityManager; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 33 | import android.app.admin.IDevicePolicyManager; |
| Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 34 | import android.app.backup.IBackupManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.content.Context; |
| Suchi Amalapurapu | 40e4725 | 2010-04-07 16:15:50 -0700 | [diff] [blame] | 36 | import android.content.ComponentName; |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 37 | import android.content.IIntentReceiver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.content.Intent; |
| 39 | import android.content.IntentFilter; |
| Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 40 | import android.content.IntentSender; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 41 | import android.content.ServiceConnection; |
| Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 42 | import android.content.IntentSender.SendIntentException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.content.pm.ActivityInfo; |
| 44 | import android.content.pm.ApplicationInfo; |
| 45 | import android.content.pm.ComponentInfo; |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 46 | import android.content.pm.FeatureInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.content.pm.IPackageDataObserver; |
| 48 | import android.content.pm.IPackageDeleteObserver; |
| 49 | import android.content.pm.IPackageInstallObserver; |
| 50 | import android.content.pm.IPackageManager; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 51 | import android.content.pm.IPackageMoveObserver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.content.pm.IPackageStatsObserver; |
| 53 | import android.content.pm.InstrumentationInfo; |
| 54 | import android.content.pm.PackageInfo; |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 55 | import android.content.pm.PackageInfoLite; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.content.pm.PackageManager; |
| 57 | import android.content.pm.PackageStats; |
| 58 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 59 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; |
| 60 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.content.pm.PackageParser; |
| 62 | import android.content.pm.PermissionInfo; |
| 63 | import android.content.pm.PermissionGroupInfo; |
| 64 | import android.content.pm.ProviderInfo; |
| 65 | import android.content.pm.ResolveInfo; |
| 66 | import android.content.pm.ServiceInfo; |
| 67 | import android.content.pm.Signature; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.net.Uri; |
| 69 | import android.os.Binder; |
| Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 70 | import android.os.Build; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.os.Bundle; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 72 | import android.os.Debug; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.os.HandlerThread; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 74 | import android.os.IBinder; |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 75 | import android.os.Looper; |
| 76 | import android.os.Message; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.os.Parcel; |
| 78 | import android.os.RemoteException; |
| 79 | import android.os.Environment; |
| 80 | import android.os.FileObserver; |
| 81 | import android.os.FileUtils; |
| 82 | import android.os.Handler; |
| 83 | import android.os.ParcelFileDescriptor; |
| 84 | import android.os.Process; |
| 85 | import android.os.ServiceManager; |
| 86 | import android.os.SystemClock; |
| 87 | import android.os.SystemProperties; |
| Suchi Amalapurapu | 40e4725 | 2010-04-07 16:15:50 -0700 | [diff] [blame] | 88 | import android.provider.Settings; |
| Oscar Montemayor | d02546b | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 89 | import android.security.SystemKeyStore; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | import android.util.*; |
| 91 | import android.view.Display; |
| 92 | import android.view.WindowManager; |
| 93 | |
| 94 | import java.io.File; |
| 95 | import java.io.FileDescriptor; |
| 96 | import java.io.FileInputStream; |
| 97 | import java.io.FileNotFoundException; |
| 98 | import java.io.FileOutputStream; |
| 99 | import java.io.FileReader; |
| 100 | import java.io.FilenameFilter; |
| 101 | import java.io.IOException; |
| 102 | import java.io.InputStream; |
| 103 | import java.io.PrintWriter; |
| Oscar Montemayor | d02546b | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 104 | import java.security.NoSuchAlgorithmException; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 105 | import java.text.SimpleDateFormat; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import java.util.ArrayList; |
| 107 | import java.util.Arrays; |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 108 | import java.util.Collection; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | import java.util.Collections; |
| 110 | import java.util.Comparator; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 111 | import java.util.Date; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | import java.util.Enumeration; |
| 113 | import java.util.HashMap; |
| 114 | import java.util.HashSet; |
| 115 | import java.util.Iterator; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 116 | import java.util.LinkedList; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | import java.util.List; |
| 118 | import java.util.Map; |
| 119 | import java.util.Set; |
| 120 | import java.util.zip.ZipEntry; |
| David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 121 | import java.util.zip.ZipException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | import java.util.zip.ZipFile; |
| 123 | import java.util.zip.ZipOutputStream; |
| 124 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 125 | /** |
| 126 | * Keep track of all those .apks everywhere. |
| 127 | * |
| 128 | * This is very central to the platform's security; please run the unit |
| 129 | * tests whenever making modifications here: |
| 130 | * |
| 131 | mmm frameworks/base/tests/AndroidTests |
| 132 | adb install -r -f out/target/product/passion/data/app/AndroidTests.apk |
| 133 | adb shell am instrument -w -e class com.android.unit_tests.PackageManagerTests com.android.unit_tests/android.test.InstrumentationTestRunner |
| 134 | * |
| 135 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | class PackageManagerService extends IPackageManager.Stub { |
| 137 | private static final String TAG = "PackageManager"; |
| 138 | private static final boolean DEBUG_SETTINGS = false; |
| 139 | private static final boolean DEBUG_PREFERRED = false; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 140 | private static final boolean DEBUG_UPGRADE = false; |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 141 | private static final boolean DEBUG_INSTALL = false; |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 142 | private static final boolean DEBUG_NATIVE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | |
| 144 | private static final boolean MULTIPLE_APPLICATION_UIDS = true; |
| 145 | private static final int RADIO_UID = Process.PHONE_UID; |
| Mike Lockwood | d42685d | 2009-09-03 09:25:22 -0400 | [diff] [blame] | 146 | private static final int LOG_UID = Process.LOG_UID; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | private static final int FIRST_APPLICATION_UID = |
| 148 | Process.FIRST_APPLICATION_UID; |
| 149 | private static final int MAX_APPLICATION_UIDS = 1000; |
| 150 | |
| 151 | private static final boolean SHOW_INFO = false; |
| 152 | |
| 153 | private static final boolean GET_CERTIFICATES = true; |
| 154 | |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 155 | private static final String SYSTEM_PROPERTY_EFS_ENABLED = "persist.security.efs.enabled"; |
| 156 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | private static final int REMOVE_EVENTS = |
| 158 | FileObserver.CLOSE_WRITE | FileObserver.DELETE | FileObserver.MOVED_FROM; |
| 159 | private static final int ADD_EVENTS = |
| 160 | FileObserver.CLOSE_WRITE /*| FileObserver.CREATE*/ | FileObserver.MOVED_TO; |
| 161 | |
| 162 | private static final int OBSERVER_EVENTS = REMOVE_EVENTS | ADD_EVENTS; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 163 | // Suffix used during package installation when copying/moving |
| 164 | // package apks to install directory. |
| 165 | private static final String INSTALL_PACKAGE_SUFFIX = "-"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | |
| Suchi Amalapurapu | 1f9e1b4 | 2010-02-26 13:14:31 -0800 | [diff] [blame] | 167 | /** |
| 168 | * Indicates the state of installation. Used by PackageManager to |
| 169 | * figure out incomplete installations. Say a package is being installed |
| 170 | * (the state is set to PKG_INSTALL_INCOMPLETE) and remains so till |
| 171 | * the package installation is successful or unsuccesful lin which case |
| 172 | * the PackageManager will no longer maintain state information associated |
| 173 | * with the package. If some exception(like device freeze or battery being |
| 174 | * pulled out) occurs during installation of a package, the PackageManager |
| 175 | * needs this information to clean up the previously failed installation. |
| 176 | */ |
| 177 | private static final int PKG_INSTALL_INCOMPLETE = 0; |
| 178 | private static final int PKG_INSTALL_COMPLETE = 1; |
| 179 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | static final int SCAN_MONITOR = 1<<0; |
| 181 | static final int SCAN_NO_DEX = 1<<1; |
| 182 | static final int SCAN_FORCE_DEX = 1<<2; |
| 183 | static final int SCAN_UPDATE_SIGNATURE = 1<<3; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 184 | static final int SCAN_NEW_INSTALL = 1<<4; |
| 185 | static final int SCAN_NO_PATHS = 1<<5; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | |
| Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 187 | static final int REMOVE_CHATTY = 1<<16; |
| 188 | |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 189 | static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName( |
| 190 | "com.android.defcontainer", |
| 191 | "com.android.defcontainer.DefaultContainerService"); |
| Kenny Root | c78a807 | 2010-07-27 15:18:38 -0700 | [diff] [blame] | 192 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 193 | private static final String LIB_DIR_NAME = "lib"; |
| 194 | |
| Kenny Root | c78a807 | 2010-07-27 15:18:38 -0700 | [diff] [blame] | 195 | static final String mTempContainerPrefix = "smdl2tmp"; |
| 196 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | final HandlerThread mHandlerThread = new HandlerThread("PackageManager", |
| 198 | Process.THREAD_PRIORITY_BACKGROUND); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 199 | final PackageHandler mHandler; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | |
| Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 201 | final int mSdkVersion = Build.VERSION.SDK_INT; |
| 202 | final String mSdkCodename = "REL".equals(Build.VERSION.CODENAME) |
| 203 | ? null : Build.VERSION.CODENAME; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | final Context mContext; |
| 206 | final boolean mFactoryTest; |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 207 | final boolean mNoDexOpt; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | final DisplayMetrics mMetrics; |
| 209 | final int mDefParseFlags; |
| 210 | final String[] mSeparateProcesses; |
| 211 | |
| 212 | // This is where all application persistent data goes. |
| 213 | final File mAppDataDir; |
| 214 | |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 215 | // If Encrypted File System feature is enabled, all application persistent data |
| 216 | // should go here instead. |
| 217 | final File mSecureAppDataDir; |
| 218 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | // This is the object monitoring the framework dir. |
| 220 | final FileObserver mFrameworkInstallObserver; |
| 221 | |
| 222 | // This is the object monitoring the system app dir. |
| 223 | final FileObserver mSystemInstallObserver; |
| 224 | |
| 225 | // This is the object monitoring mAppInstallDir. |
| 226 | final FileObserver mAppInstallObserver; |
| 227 | |
| 228 | // This is the object monitoring mDrmAppPrivateInstallDir. |
| 229 | final FileObserver mDrmAppInstallObserver; |
| 230 | |
| 231 | // Used for priviledge escalation. MUST NOT BE CALLED WITH mPackages |
| 232 | // LOCK HELD. Can be called with mInstallLock held. |
| 233 | final Installer mInstaller; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 234 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | final File mFrameworkDir; |
| 236 | final File mSystemAppDir; |
| 237 | final File mAppInstallDir; |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 238 | final File mDalvikCacheDir; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | |
| 240 | // Directory containing the private parts (e.g. code and non-resource assets) of forward-locked |
| 241 | // apps. |
| 242 | final File mDrmAppPrivateInstallDir; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 243 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | // ---------------------------------------------------------------- |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | // Lock for state used when installing and doing other long running |
| 247 | // operations. Methods that must be called with this lock held have |
| 248 | // the prefix "LI". |
| 249 | final Object mInstallLock = new Object(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 250 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | // These are the directories in the 3rd party applications installed dir |
| 252 | // that we have currently loaded packages from. Keys are the application's |
| 253 | // installed zip file (absolute codePath), and values are Package. |
| 254 | final HashMap<String, PackageParser.Package> mAppDirs = |
| 255 | new HashMap<String, PackageParser.Package>(); |
| 256 | |
| 257 | // Information for the parser to write more useful error messages. |
| 258 | File mScanningPath; |
| 259 | int mLastScanError; |
| 260 | |
| 261 | final int[] mOutPermissions = new int[3]; |
| 262 | |
| 263 | // ---------------------------------------------------------------- |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 264 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | // Keys are String (package name), values are Package. This also serves |
| 266 | // as the lock for the global state. Methods that must be called with |
| 267 | // this lock held have the prefix "LP". |
| 268 | final HashMap<String, PackageParser.Package> mPackages = |
| 269 | new HashMap<String, PackageParser.Package>(); |
| 270 | |
| 271 | final Settings mSettings; |
| 272 | boolean mRestoredSettings; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | |
| 274 | // Group-ids that are given to all packages as read from etc/permissions/*.xml. |
| 275 | int[] mGlobalGids; |
| 276 | |
| 277 | // These are the built-in uid -> permission mappings that were read from the |
| 278 | // etc/permissions.xml file. |
| 279 | final SparseArray<HashSet<String>> mSystemPermissions = |
| 280 | new SparseArray<HashSet<String>>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | // These are the built-in shared libraries that were read from the |
| 283 | // etc/permissions.xml file. |
| 284 | final HashMap<String, String> mSharedLibraries = new HashMap<String, String>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 285 | |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 286 | // Temporary for building the final shared libraries for an .apk. |
| 287 | String[] mTmpSharedLibraries = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 288 | |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 289 | // These are the features this devices supports that were read from the |
| 290 | // etc/permissions.xml file. |
| 291 | final HashMap<String, FeatureInfo> mAvailableFeatures = |
| 292 | new HashMap<String, FeatureInfo>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | // All available activities, for your resolving pleasure. |
| 295 | final ActivityIntentResolver mActivities = |
| 296 | new ActivityIntentResolver(); |
| 297 | |
| 298 | // All available receivers, for your resolving pleasure. |
| 299 | final ActivityIntentResolver mReceivers = |
| 300 | new ActivityIntentResolver(); |
| 301 | |
| 302 | // All available services, for your resolving pleasure. |
| 303 | final ServiceIntentResolver mServices = new ServiceIntentResolver(); |
| 304 | |
| 305 | // Keys are String (provider class name), values are Provider. |
| 306 | final HashMap<ComponentName, PackageParser.Provider> mProvidersByComponent = |
| 307 | new HashMap<ComponentName, PackageParser.Provider>(); |
| 308 | |
| 309 | // Mapping from provider base names (first directory in content URI codePath) |
| 310 | // to the provider information. |
| 311 | final HashMap<String, PackageParser.Provider> mProviders = |
| 312 | new HashMap<String, PackageParser.Provider>(); |
| 313 | |
| 314 | // Mapping from instrumentation class names to info about them. |
| 315 | final HashMap<ComponentName, PackageParser.Instrumentation> mInstrumentation = |
| 316 | new HashMap<ComponentName, PackageParser.Instrumentation>(); |
| 317 | |
| 318 | // Mapping from permission names to info about them. |
| 319 | final HashMap<String, PackageParser.PermissionGroup> mPermissionGroups = |
| 320 | new HashMap<String, PackageParser.PermissionGroup>(); |
| 321 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 322 | // Packages whose data we have transfered into another package, thus |
| 323 | // should no longer exist. |
| 324 | final HashSet<String> mTransferedPackages = new HashSet<String>(); |
| 325 | |
| Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 326 | // Broadcast actions that are only available to the system. |
| 327 | final HashSet<String> mProtectedBroadcasts = new HashSet<String>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 328 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | boolean mSystemReady; |
| 330 | boolean mSafeMode; |
| 331 | boolean mHasSystemUidErrors; |
| 332 | |
| 333 | ApplicationInfo mAndroidApplication; |
| 334 | final ActivityInfo mResolveActivity = new ActivityInfo(); |
| 335 | final ResolveInfo mResolveInfo = new ResolveInfo(); |
| 336 | ComponentName mResolveComponentName; |
| 337 | PackageParser.Package mPlatformPackage; |
| 338 | |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 339 | // Set of pending broadcasts for aggregating enable/disable of components. |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 340 | final HashMap<String, ArrayList<String>> mPendingBroadcasts |
| 341 | = new HashMap<String, ArrayList<String>>(); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 342 | // Service Connection to remote media container service to copy |
| 343 | // package uri's from external media onto secure containers |
| 344 | // or internal storage. |
| 345 | private IMediaContainerService mContainerService = null; |
| 346 | |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 347 | static final int SEND_PENDING_BROADCAST = 1; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 348 | static final int MCS_BOUND = 3; |
| 349 | static final int END_COPY = 4; |
| 350 | static final int INIT_COPY = 5; |
| 351 | static final int MCS_UNBIND = 6; |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 352 | static final int START_CLEANING_PACKAGE = 7; |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 353 | static final int FIND_INSTALL_LOC = 8; |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 354 | static final int POST_INSTALL = 9; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 355 | static final int MCS_RECONNECT = 10; |
| 356 | static final int MCS_GIVE_UP = 11; |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 357 | static final int UPDATED_MEDIA_STATUS = 12; |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 358 | static final int WRITE_SETTINGS = 13; |
| 359 | |
| 360 | static final int WRITE_SETTINGS_DELAY = 10*1000; // 10 seconds |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 361 | |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 362 | // Delay time in millisecs |
| 363 | static final int BROADCAST_DELAY = 10 * 1000; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 364 | final private DefaultContainerConnection mDefContainerConn = |
| 365 | new DefaultContainerConnection(); |
| 366 | class DefaultContainerConnection implements ServiceConnection { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 367 | public void onServiceConnected(ComponentName name, IBinder service) { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 368 | if (DEBUG_SD_INSTALL) Log.i(TAG, "onServiceConnected"); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 369 | IMediaContainerService imcs = |
| 370 | IMediaContainerService.Stub.asInterface(service); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 371 | mHandler.sendMessage(mHandler.obtainMessage(MCS_BOUND, imcs)); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | public void onServiceDisconnected(ComponentName name) { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 375 | if (DEBUG_SD_INSTALL) Log.i(TAG, "onServiceDisconnected"); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 376 | } |
| 377 | }; |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 378 | |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 379 | // Recordkeeping of restore-after-install operations that are currently in flight |
| 380 | // between the Package Manager and the Backup Manager |
| 381 | class PostInstallData { |
| 382 | public InstallArgs args; |
| 383 | public PackageInstalledInfo res; |
| 384 | |
| 385 | PostInstallData(InstallArgs _a, PackageInstalledInfo _r) { |
| 386 | args = _a; |
| 387 | res = _r; |
| 388 | } |
| 389 | }; |
| 390 | final SparseArray<PostInstallData> mRunningInstalls = new SparseArray<PostInstallData>(); |
| 391 | int mNextInstallToken = 1; // nonzero; will be wrapped back to 1 when ++ overflows |
| 392 | |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 393 | class PackageHandler extends Handler { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 394 | private boolean mBound = false; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 395 | final ArrayList<HandlerParams> mPendingInstalls = |
| 396 | new ArrayList<HandlerParams>(); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 397 | |
| 398 | private boolean connectToService() { |
| 399 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to bind to" + |
| 400 | " DefaultContainerService"); |
| 401 | Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT); |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 402 | Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 403 | if (mContext.bindService(service, mDefContainerConn, |
| 404 | Context.BIND_AUTO_CREATE)) { |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 405 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 406 | mBound = true; |
| 407 | return true; |
| 408 | } |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 409 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 410 | return false; |
| 411 | } |
| 412 | |
| 413 | private void disconnectService() { |
| 414 | mContainerService = null; |
| 415 | mBound = false; |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 416 | Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 417 | mContext.unbindService(mDefContainerConn); |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 418 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 419 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 420 | |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 421 | PackageHandler(Looper looper) { |
| 422 | super(looper); |
| 423 | } |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 424 | |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 425 | public void handleMessage(Message msg) { |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 426 | try { |
| 427 | doHandleMessage(msg); |
| 428 | } finally { |
| 429 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | void doHandleMessage(Message msg) { |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 434 | switch (msg.what) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 435 | case INIT_COPY: { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 436 | if (DEBUG_SD_INSTALL) Log.i(TAG, "init_copy"); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 437 | HandlerParams params = (HandlerParams) msg.obj; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 438 | int idx = mPendingInstalls.size(); |
| 439 | if (DEBUG_SD_INSTALL) Log.i(TAG, "idx=" + idx); |
| 440 | // If a bind was already initiated we dont really |
| 441 | // need to do anything. The pending install |
| 442 | // will be processed later on. |
| 443 | if (!mBound) { |
| 444 | // If this is the only one pending we might |
| 445 | // have to bind to the service again. |
| 446 | if (!connectToService()) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 447 | Slog.e(TAG, "Failed to bind to media container service"); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 448 | params.serviceError(); |
| 449 | return; |
| 450 | } else { |
| 451 | // Once we bind to the service, the first |
| 452 | // pending request will be processed. |
| 453 | mPendingInstalls.add(idx, params); |
| 454 | } |
| 455 | } else { |
| 456 | mPendingInstalls.add(idx, params); |
| 457 | // Already bound to the service. Just make |
| 458 | // sure we trigger off processing the first request. |
| 459 | if (idx == 0) { |
| 460 | mHandler.sendEmptyMessage(MCS_BOUND); |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | break; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 464 | } |
| 465 | case MCS_BOUND: { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 466 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_bound"); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 467 | if (msg.obj != null) { |
| 468 | mContainerService = (IMediaContainerService) msg.obj; |
| 469 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 470 | if (mContainerService == null) { |
| 471 | // Something seriously wrong. Bail out |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 472 | Slog.e(TAG, "Cannot bind to media container service"); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 473 | for (HandlerParams params : mPendingInstalls) { |
| 474 | mPendingInstalls.remove(0); |
| 475 | // Indicate service bind error |
| 476 | params.serviceError(); |
| 477 | } |
| 478 | mPendingInstalls.clear(); |
| 479 | } else if (mPendingInstalls.size() > 0) { |
| 480 | HandlerParams params = mPendingInstalls.get(0); |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 481 | if (params != null) { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 482 | params.startCopy(); |
| 483 | } |
| 484 | } else { |
| 485 | // Should never happen ideally. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 486 | Slog.w(TAG, "Empty queue"); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 487 | } |
| 488 | break; |
| 489 | } |
| 490 | case MCS_RECONNECT : { |
| 491 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_reconnect"); |
| 492 | if (mPendingInstalls.size() > 0) { |
| 493 | if (mBound) { |
| 494 | disconnectService(); |
| 495 | } |
| 496 | if (!connectToService()) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 497 | Slog.e(TAG, "Failed to bind to media container service"); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 498 | for (HandlerParams params : mPendingInstalls) { |
| 499 | mPendingInstalls.remove(0); |
| 500 | // Indicate service bind error |
| 501 | params.serviceError(); |
| 502 | } |
| 503 | mPendingInstalls.clear(); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | break; |
| 507 | } |
| 508 | case MCS_UNBIND : { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 509 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_unbind"); |
| 510 | // Delete pending install |
| 511 | if (mPendingInstalls.size() > 0) { |
| 512 | mPendingInstalls.remove(0); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 513 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 514 | if (mPendingInstalls.size() == 0) { |
| 515 | if (mBound) { |
| 516 | disconnectService(); |
| 517 | } |
| 518 | } else { |
| 519 | // There are more pending requests in queue. |
| 520 | // Just post MCS_BOUND message to trigger processing |
| 521 | // of next pending install. |
| 522 | mHandler.sendEmptyMessage(MCS_BOUND); |
| 523 | } |
| 524 | break; |
| 525 | } |
| 526 | case MCS_GIVE_UP: { |
| 527 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_giveup too many retries"); |
| 528 | HandlerParams params = mPendingInstalls.remove(0); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 529 | break; |
| 530 | } |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 531 | case SEND_PENDING_BROADCAST : { |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 532 | String packages[]; |
| 533 | ArrayList components[]; |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 534 | int size = 0; |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 535 | int uids[]; |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 536 | Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 537 | synchronized (mPackages) { |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 538 | if (mPendingBroadcasts == null) { |
| 539 | return; |
| 540 | } |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 541 | size = mPendingBroadcasts.size(); |
| 542 | if (size <= 0) { |
| 543 | // Nothing to be done. Just return |
| 544 | return; |
| 545 | } |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 546 | packages = new String[size]; |
| 547 | components = new ArrayList[size]; |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 548 | uids = new int[size]; |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 549 | Iterator<HashMap.Entry<String, ArrayList<String>>> |
| 550 | it = mPendingBroadcasts.entrySet().iterator(); |
| 551 | int i = 0; |
| 552 | while (it.hasNext() && i < size) { |
| 553 | HashMap.Entry<String, ArrayList<String>> ent = it.next(); |
| 554 | packages[i] = ent.getKey(); |
| 555 | components[i] = ent.getValue(); |
| 556 | PackageSetting ps = mSettings.mPackages.get(ent.getKey()); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 557 | uids[i] = (ps != null) ? ps.userId : -1; |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 558 | i++; |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 559 | } |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 560 | size = i; |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 561 | mPendingBroadcasts.clear(); |
| 562 | } |
| 563 | // Send broadcasts |
| 564 | for (int i = 0; i < size; i++) { |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 565 | sendPackageChangedBroadcast(packages[i], true, |
| 566 | (ArrayList<String>)components[i], uids[i]); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 567 | } |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 568 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 569 | break; |
| 570 | } |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 571 | case START_CLEANING_PACKAGE: { |
| 572 | String packageName = (String)msg.obj; |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 573 | Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 574 | synchronized (mPackages) { |
| 575 | if (!mSettings.mPackagesToBeCleaned.contains(packageName)) { |
| 576 | mSettings.mPackagesToBeCleaned.add(packageName); |
| 577 | } |
| 578 | } |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 579 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 580 | startCleaningPackages(); |
| 581 | } break; |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 582 | case POST_INSTALL: { |
| 583 | if (DEBUG_INSTALL) Log.v(TAG, "Handling post-install for " + msg.arg1); |
| 584 | PostInstallData data = mRunningInstalls.get(msg.arg1); |
| 585 | mRunningInstalls.delete(msg.arg1); |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 586 | boolean deleteOld = false; |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 587 | |
| 588 | if (data != null) { |
| 589 | InstallArgs args = data.args; |
| 590 | PackageInstalledInfo res = data.res; |
| 591 | |
| 592 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) { |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 593 | res.removedInfo.sendBroadcast(false, true); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 594 | Bundle extras = new Bundle(1); |
| 595 | extras.putInt(Intent.EXTRA_UID, res.uid); |
| 596 | final boolean update = res.removedInfo.removedPackage != null; |
| 597 | if (update) { |
| 598 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 599 | } |
| 600 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, |
| 601 | res.pkg.applicationInfo.packageName, |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 602 | extras, null); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 603 | if (update) { |
| 604 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, |
| 605 | res.pkg.applicationInfo.packageName, |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 606 | extras, null); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 607 | } |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 608 | if (res.removedInfo.args != null) { |
| 609 | // Remove the replaced package's older resources safely now |
| 610 | deleteOld = true; |
| 611 | } |
| 612 | } |
| 613 | // Force a gc to clear up things |
| 614 | Runtime.getRuntime().gc(); |
| 615 | // We delete after a gc for applications on sdcard. |
| 616 | if (deleteOld) { |
| 617 | synchronized (mInstallLock) { |
| 618 | res.removedInfo.args.doPostDeleteLI(true); |
| 619 | } |
| Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 620 | } |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 621 | if (args.observer != null) { |
| 622 | try { |
| 623 | args.observer.packageInstalled(res.name, res.returnCode); |
| 624 | } catch (RemoteException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 625 | Slog.i(TAG, "Observer no longer exists."); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 629 | Slog.e(TAG, "Bogus post-install token " + msg.arg1); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 630 | } |
| 631 | } break; |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 632 | case UPDATED_MEDIA_STATUS: { |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 633 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Got message UPDATED_MEDIA_STATUS"); |
| 634 | boolean reportStatus = msg.arg1 == 1; |
| 635 | boolean doGc = msg.arg2 == 1; |
| 636 | if (DEBUG_SD_INSTALL) Log.i(TAG, "reportStatus=" + reportStatus + ", doGc = " + doGc); |
| 637 | if (doGc) { |
| 638 | // Force a gc to clear up stale containers. |
| 639 | Runtime.getRuntime().gc(); |
| 640 | } |
| 641 | if (msg.obj != null) { |
| 642 | Set<SdInstallArgs> args = (Set<SdInstallArgs>) msg.obj; |
| 643 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Unloading all containers"); |
| 644 | // Unload containers |
| 645 | unloadAllContainers(args); |
| 646 | } |
| 647 | if (reportStatus) { |
| 648 | try { |
| 649 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Invoking MountService call back"); |
| 650 | PackageHelper.getMountService().finishMediaUpdate(); |
| 651 | } catch (RemoteException e) { |
| 652 | Log.e(TAG, "MountService not running?"); |
| 653 | } |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 654 | } |
| 655 | } break; |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 656 | case WRITE_SETTINGS: { |
| 657 | Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
| 658 | synchronized (mPackages) { |
| 659 | removeMessages(WRITE_SETTINGS); |
| 660 | mSettings.writeLP(); |
| 661 | } |
| 662 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 663 | } break; |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 667 | |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 668 | void scheduleWriteSettingsLocked() { |
| 669 | if (!mHandler.hasMessages(WRITE_SETTINGS)) { |
| 670 | mHandler.sendEmptyMessageDelayed(WRITE_SETTINGS, WRITE_SETTINGS_DELAY); |
| 671 | } |
| 672 | } |
| 673 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 674 | static boolean installOnSd(int flags) { |
| 675 | if (((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) || |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 676 | ((flags & PackageManager.INSTALL_INTERNAL) != 0)) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 677 | return false; |
| 678 | } |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 679 | if ((flags & PackageManager.INSTALL_EXTERNAL) != 0) { |
| 680 | return true; |
| 681 | } |
| 682 | return false; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 683 | } |
| 684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | public static final IPackageManager main(Context context, boolean factoryTest) { |
| 686 | PackageManagerService m = new PackageManagerService(context, factoryTest); |
| 687 | ServiceManager.addService("package", m); |
| 688 | return m; |
| 689 | } |
| 690 | |
| 691 | static String[] splitString(String str, char sep) { |
| 692 | int count = 1; |
| 693 | int i = 0; |
| 694 | while ((i=str.indexOf(sep, i)) >= 0) { |
| 695 | count++; |
| 696 | i++; |
| 697 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 698 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | String[] res = new String[count]; |
| 700 | i=0; |
| 701 | count = 0; |
| 702 | int lastI=0; |
| 703 | while ((i=str.indexOf(sep, i)) >= 0) { |
| 704 | res[count] = str.substring(lastI, i); |
| 705 | count++; |
| 706 | i++; |
| 707 | lastI = i; |
| 708 | } |
| 709 | res[count] = str.substring(lastI, str.length()); |
| 710 | return res; |
| 711 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 712 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | public PackageManagerService(Context context, boolean factoryTest) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 714 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_START, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 715 | SystemClock.uptimeMillis()); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 716 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | if (mSdkVersion <= 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 718 | Slog.w(TAG, "**** ro.build.version.sdk not set!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 720 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | mContext = context; |
| 722 | mFactoryTest = factoryTest; |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 723 | mNoDexOpt = "eng".equals(SystemProperties.get("ro.build.type")); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | mMetrics = new DisplayMetrics(); |
| 725 | mSettings = new Settings(); |
| 726 | mSettings.addSharedUserLP("android.uid.system", |
| 727 | Process.SYSTEM_UID, ApplicationInfo.FLAG_SYSTEM); |
| 728 | mSettings.addSharedUserLP("android.uid.phone", |
| 729 | MULTIPLE_APPLICATION_UIDS |
| 730 | ? RADIO_UID : FIRST_APPLICATION_UID, |
| 731 | ApplicationInfo.FLAG_SYSTEM); |
| Mike Lockwood | d42685d | 2009-09-03 09:25:22 -0400 | [diff] [blame] | 732 | mSettings.addSharedUserLP("android.uid.log", |
| 733 | MULTIPLE_APPLICATION_UIDS |
| 734 | ? LOG_UID : FIRST_APPLICATION_UID, |
| 735 | ApplicationInfo.FLAG_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | |
| 737 | String separateProcesses = SystemProperties.get("debug.separate_processes"); |
| 738 | if (separateProcesses != null && separateProcesses.length() > 0) { |
| 739 | if ("*".equals(separateProcesses)) { |
| 740 | mDefParseFlags = PackageParser.PARSE_IGNORE_PROCESSES; |
| 741 | mSeparateProcesses = null; |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 742 | Slog.w(TAG, "Running with debug.separate_processes: * (ALL)"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | } else { |
| 744 | mDefParseFlags = 0; |
| 745 | mSeparateProcesses = separateProcesses.split(","); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 746 | Slog.w(TAG, "Running with debug.separate_processes: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 747 | + separateProcesses); |
| 748 | } |
| 749 | } else { |
| 750 | mDefParseFlags = 0; |
| 751 | mSeparateProcesses = null; |
| 752 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 753 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | Installer installer = new Installer(); |
| 755 | // Little hacky thing to check if installd is here, to determine |
| 756 | // whether we are running on the simulator and thus need to take |
| 757 | // care of building the /data file structure ourself. |
| 758 | // (apparently the sim now has a working installer) |
| 759 | if (installer.ping() && Process.supportsProcesses()) { |
| 760 | mInstaller = installer; |
| 761 | } else { |
| 762 | mInstaller = null; |
| 763 | } |
| 764 | |
| 765 | WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 766 | Display d = wm.getDefaultDisplay(); |
| 767 | d.getMetrics(mMetrics); |
| 768 | |
| 769 | synchronized (mInstallLock) { |
| 770 | synchronized (mPackages) { |
| 771 | mHandlerThread.start(); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 772 | mHandler = new PackageHandler(mHandlerThread.getLooper()); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 773 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | File dataDir = Environment.getDataDirectory(); |
| 775 | mAppDataDir = new File(dataDir, "data"); |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 776 | mSecureAppDataDir = new File(dataDir, "secure/data"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | mDrmAppPrivateInstallDir = new File(dataDir, "app-private"); |
| 778 | |
| 779 | if (mInstaller == null) { |
| 780 | // Make sure these dirs exist, when we are running in |
| 781 | // the simulator. |
| 782 | // Make a wide-open directory for random misc stuff. |
| 783 | File miscDir = new File(dataDir, "misc"); |
| 784 | miscDir.mkdirs(); |
| 785 | mAppDataDir.mkdirs(); |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 786 | mSecureAppDataDir.mkdirs(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | mDrmAppPrivateInstallDir.mkdirs(); |
| 788 | } |
| 789 | |
| 790 | readPermissions(); |
| 791 | |
| 792 | mRestoredSettings = mSettings.readLP(); |
| 793 | long startTime = SystemClock.uptimeMillis(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 794 | |
| 795 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SYSTEM_SCAN_START, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | startTime); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 797 | |
| Suchi Amalapurapu | daec1722 | 2010-01-14 21:25:16 -0800 | [diff] [blame] | 798 | // Set flag to monitor and not change apk file paths when |
| 799 | // scanning install directories. |
| 800 | int scanMode = SCAN_MONITOR | SCAN_NO_PATHS; |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 801 | if (mNoDexOpt) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 802 | Slog.w(TAG, "Running ENG build: no pre-dexopt!"); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 803 | scanMode |= SCAN_NO_DEX; |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 804 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 805 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | final HashSet<String> libFiles = new HashSet<String>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 807 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | mFrameworkDir = new File(Environment.getRootDirectory(), "framework"); |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 809 | mDalvikCacheDir = new File(dataDir, "dalvik-cache"); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 810 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | if (mInstaller != null) { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 812 | boolean didDexOpt = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 813 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | /** |
| 815 | * Out of paranoia, ensure that everything in the boot class |
| 816 | * path has been dexed. |
| 817 | */ |
| 818 | String bootClassPath = System.getProperty("java.boot.class.path"); |
| 819 | if (bootClassPath != null) { |
| 820 | String[] paths = splitString(bootClassPath, ':'); |
| 821 | for (int i=0; i<paths.length; i++) { |
| 822 | try { |
| 823 | if (dalvik.system.DexFile.isDexOptNeeded(paths[i])) { |
| 824 | libFiles.add(paths[i]); |
| 825 | mInstaller.dexopt(paths[i], Process.SYSTEM_UID, true); |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 826 | didDexOpt = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | } |
| 828 | } catch (FileNotFoundException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 829 | Slog.w(TAG, "Boot class path not found: " + paths[i]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 831 | Slog.w(TAG, "Exception reading boot class path: " + paths[i], e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 835 | Slog.w(TAG, "No BOOTCLASSPATH found!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 836 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | /** |
| 839 | * Also ensure all external libraries have had dexopt run on them. |
| 840 | */ |
| 841 | if (mSharedLibraries.size() > 0) { |
| 842 | Iterator<String> libs = mSharedLibraries.values().iterator(); |
| 843 | while (libs.hasNext()) { |
| 844 | String lib = libs.next(); |
| 845 | try { |
| 846 | if (dalvik.system.DexFile.isDexOptNeeded(lib)) { |
| 847 | libFiles.add(lib); |
| 848 | mInstaller.dexopt(lib, Process.SYSTEM_UID, true); |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 849 | didDexOpt = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 850 | } |
| 851 | } catch (FileNotFoundException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 852 | Slog.w(TAG, "Library not found: " + lib); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 854 | Slog.w(TAG, "Exception reading library: " + lib, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 858 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 859 | // Gross hack for now: we know this file doesn't contain any |
| 860 | // code, so don't dexopt it to avoid the resulting log spew. |
| 861 | libFiles.add(mFrameworkDir.getPath() + "/framework-res.apk"); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 862 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | /** |
| 864 | * And there are a number of commands implemented in Java, which |
| 865 | * we currently need to do the dexopt on so that they can be |
| 866 | * run from a non-root shell. |
| 867 | */ |
| 868 | String[] frameworkFiles = mFrameworkDir.list(); |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 869 | if (frameworkFiles != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | for (int i=0; i<frameworkFiles.length; i++) { |
| 871 | File libPath = new File(mFrameworkDir, frameworkFiles[i]); |
| 872 | String path = libPath.getPath(); |
| 873 | // Skip the file if we alrady did it. |
| 874 | if (libFiles.contains(path)) { |
| 875 | continue; |
| 876 | } |
| 877 | // Skip the file if it is not a type we want to dexopt. |
| 878 | if (!path.endsWith(".apk") && !path.endsWith(".jar")) { |
| 879 | continue; |
| 880 | } |
| 881 | try { |
| 882 | if (dalvik.system.DexFile.isDexOptNeeded(path)) { |
| 883 | mInstaller.dexopt(path, Process.SYSTEM_UID, true); |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 884 | didDexOpt = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | } |
| 886 | } catch (FileNotFoundException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 887 | Slog.w(TAG, "Jar not found: " + path); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 889 | Slog.w(TAG, "Exception reading jar: " + path, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 893 | |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 894 | if (didDexOpt) { |
| 895 | // If we had to do a dexopt of one of the previous |
| 896 | // things, then something on the system has changed. |
| 897 | // Consider this significant, and wipe away all other |
| 898 | // existing dexopt files to ensure we don't leave any |
| 899 | // dangling around. |
| 900 | String[] files = mDalvikCacheDir.list(); |
| 901 | if (files != null) { |
| 902 | for (int i=0; i<files.length; i++) { |
| 903 | String fn = files[i]; |
| 904 | if (fn.startsWith("data@app@") |
| 905 | || fn.startsWith("data@app-private@")) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 906 | Slog.i(TAG, "Pruning dalvik file: " + fn); |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 907 | (new File(mDalvikCacheDir, fn)).delete(); |
| 908 | } |
| 909 | } |
| 910 | } |
| 911 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 913 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 914 | // Find base frameworks (resource packages without code). |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | mFrameworkInstallObserver = new AppDirObserver( |
| 916 | mFrameworkDir.getPath(), OBSERVER_EVENTS, true); |
| 917 | mFrameworkInstallObserver.startWatching(); |
| Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 918 | scanDirLI(mFrameworkDir, PackageParser.PARSE_IS_SYSTEM |
| 919 | | PackageParser.PARSE_IS_SYSTEM_DIR, |
| Suchi Amalapurapu | daec1722 | 2010-01-14 21:25:16 -0800 | [diff] [blame] | 920 | scanMode | SCAN_NO_DEX); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 921 | |
| 922 | // Collect all system packages. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | mSystemAppDir = new File(Environment.getRootDirectory(), "app"); |
| 924 | mSystemInstallObserver = new AppDirObserver( |
| 925 | mSystemAppDir.getPath(), OBSERVER_EVENTS, true); |
| 926 | mSystemInstallObserver.startWatching(); |
| Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 927 | scanDirLI(mSystemAppDir, PackageParser.PARSE_IS_SYSTEM |
| 928 | | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 929 | |
| 930 | if (mInstaller != null) { |
| 931 | if (DEBUG_UPGRADE) Log.v(TAG, "Running installd update commands"); |
| 932 | mInstaller.moveFiles(); |
| 933 | } |
| 934 | |
| 935 | // Prune any system packages that no longer exist. |
| 936 | Iterator<PackageSetting> psit = mSettings.mPackages.values().iterator(); |
| 937 | while (psit.hasNext()) { |
| 938 | PackageSetting ps = psit.next(); |
| 939 | if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0 |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 940 | && !mPackages.containsKey(ps.name) |
| 941 | && !mSettings.mDisabledSysPackages.containsKey(ps.name)) { |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 942 | psit.remove(); |
| 943 | String msg = "System package " + ps.name |
| 944 | + " no longer exists; wiping its data"; |
| 945 | reportSettingsProblem(Log.WARN, msg); |
| 946 | if (mInstaller != null) { |
| 947 | // XXX how to set useEncryptedFSDir for packages that |
| 948 | // are not encrypted? |
| 949 | mInstaller.remove(ps.name, true); |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | mAppInstallDir = new File(dataDir, "app"); |
| 955 | if (mInstaller == null) { |
| 956 | // Make sure these dirs exist, when we are running in |
| 957 | // the simulator. |
| 958 | mAppInstallDir.mkdirs(); // scanDirLI() assumes this dir exists |
| 959 | } |
| 960 | //look for any incomplete package installations |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 961 | ArrayList<PackageSetting> deletePkgsList = mSettings.getListOfIncompleteInstallPackages(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | //clean up list |
| 963 | for(int i = 0; i < deletePkgsList.size(); i++) { |
| 964 | //clean up here |
| 965 | cleanupInstallFailedPackage(deletePkgsList.get(i)); |
| 966 | } |
| 967 | //delete tmp files |
| 968 | deleteTempPackageFiles(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 969 | |
| 970 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_DATA_SCAN_START, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 971 | SystemClock.uptimeMillis()); |
| 972 | mAppInstallObserver = new AppDirObserver( |
| 973 | mAppInstallDir.getPath(), OBSERVER_EVENTS, false); |
| 974 | mAppInstallObserver.startWatching(); |
| 975 | scanDirLI(mAppInstallDir, 0, scanMode); |
| 976 | |
| 977 | mDrmAppInstallObserver = new AppDirObserver( |
| 978 | mDrmAppPrivateInstallDir.getPath(), OBSERVER_EVENTS, false); |
| 979 | mDrmAppInstallObserver.startWatching(); |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 980 | scanDirLI(mDrmAppPrivateInstallDir, PackageParser.PARSE_FORWARD_LOCK, scanMode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 982 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SCAN_END, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | SystemClock.uptimeMillis()); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 984 | Slog.i(TAG, "Time to scan packages: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 985 | + ((SystemClock.uptimeMillis()-startTime)/1000f) |
| 986 | + " seconds"); |
| 987 | |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 988 | // If the platform SDK has changed since the last time we booted, |
| 989 | // we need to re-grant app permission to catch any new ones that |
| 990 | // appear. This is really a hack, and means that apps can in some |
| 991 | // cases get permissions that the user didn't initially explicitly |
| 992 | // allow... it would be nice to have some better way to handle |
| 993 | // this situation. |
| 994 | final boolean regrantPermissions = mSettings.mInternalSdkPlatform |
| 995 | != mSdkVersion; |
| 996 | if (regrantPermissions) Slog.i(TAG, "Platform changed from " |
| 997 | + mSettings.mInternalSdkPlatform + " to " + mSdkVersion |
| 998 | + "; regranting permissions for internal storage"); |
| 999 | mSettings.mInternalSdkPlatform = mSdkVersion; |
| 1000 | |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 1001 | updatePermissionsLP(null, null, true, regrantPermissions, regrantPermissions); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | |
| 1003 | mSettings.writeLP(); |
| 1004 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1005 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_READY, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | SystemClock.uptimeMillis()); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1007 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | // Now after opening every single application zip, make sure they |
| 1009 | // are all flushed. Not really needed, but keeps things nice and |
| 1010 | // tidy. |
| 1011 | Runtime.getRuntime().gc(); |
| 1012 | } // synchronized (mPackages) |
| 1013 | } // synchronized (mInstallLock) |
| 1014 | } |
| Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 1015 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | @Override |
| 1017 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1018 | throws RemoteException { |
| 1019 | try { |
| 1020 | return super.onTransact(code, data, reply, flags); |
| 1021 | } catch (RuntimeException e) { |
| 1022 | if (!(e instanceof SecurityException) && !(e instanceof IllegalArgumentException)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1023 | Slog.e(TAG, "Package Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | } |
| 1025 | throw e; |
| 1026 | } |
| 1027 | } |
| 1028 | |
| Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1029 | void cleanupInstallFailedPackage(PackageSetting ps) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1030 | Slog.i(TAG, "Cleaning up incompletely installed app: " + ps.name); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | if (mInstaller != null) { |
| Kenny Root | bdbc925 | 2010-01-28 12:03:49 -0800 | [diff] [blame] | 1032 | boolean useSecureFS = useEncryptedFilesystemForPackage(ps.pkg); |
| 1033 | int retCode = mInstaller.remove(ps.name, useSecureFS); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1035 | Slog.w(TAG, "Couldn't remove app data directory for package: " |
| Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1036 | + ps.name + ", retcode=" + retCode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | } |
| 1038 | } else { |
| 1039 | //for emulator |
| Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1040 | PackageParser.Package pkg = mPackages.get(ps.name); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | File dataDir = new File(pkg.applicationInfo.dataDir); |
| 1042 | dataDir.delete(); |
| 1043 | } |
| Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1044 | if (ps.codePath != null) { |
| 1045 | if (!ps.codePath.delete()) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1046 | Slog.w(TAG, "Unable to remove old code file: " + ps.codePath); |
| Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | if (ps.resourcePath != null) { |
| 1050 | if (!ps.resourcePath.delete() && !ps.resourcePath.equals(ps.codePath)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1051 | Slog.w(TAG, "Unable to remove old code file: " + ps.resourcePath); |
| Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | mSettings.removePackageLP(ps.name); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | void readPermissions() { |
| 1058 | // Read permissions from .../etc/permission directory. |
| 1059 | File libraryDir = new File(Environment.getRootDirectory(), "etc/permissions"); |
| 1060 | if (!libraryDir.exists() || !libraryDir.isDirectory()) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1061 | Slog.w(TAG, "No directory " + libraryDir + ", skipping"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | return; |
| 1063 | } |
| 1064 | if (!libraryDir.canRead()) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1065 | Slog.w(TAG, "Directory " + libraryDir + " cannot be read"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | return; |
| 1067 | } |
| 1068 | |
| 1069 | // Iterate over the files in the directory and scan .xml files |
| 1070 | for (File f : libraryDir.listFiles()) { |
| 1071 | // We'll read platform.xml last |
| 1072 | if (f.getPath().endsWith("etc/permissions/platform.xml")) { |
| 1073 | continue; |
| 1074 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1075 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | if (!f.getPath().endsWith(".xml")) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1077 | Slog.i(TAG, "Non-xml file " + f + " in " + libraryDir + " directory, ignoring"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | continue; |
| 1079 | } |
| 1080 | if (!f.canRead()) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1081 | Slog.w(TAG, "Permissions library file " + f + " cannot be read"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | continue; |
| 1083 | } |
| 1084 | |
| 1085 | readPermissionsFromXml(f); |
| 1086 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1087 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | // Read permissions from .../etc/permissions/platform.xml last so it will take precedence |
| 1089 | final File permFile = new File(Environment.getRootDirectory(), |
| 1090 | "etc/permissions/platform.xml"); |
| 1091 | readPermissionsFromXml(permFile); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1092 | |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1093 | StringBuilder sb = new StringBuilder(128); |
| 1094 | sb.append("Libs:"); |
| 1095 | Iterator<String> it = mSharedLibraries.keySet().iterator(); |
| 1096 | while (it.hasNext()) { |
| 1097 | sb.append(' '); |
| 1098 | String name = it.next(); |
| 1099 | sb.append(name); |
| 1100 | sb.append(':'); |
| 1101 | sb.append(mSharedLibraries.get(name)); |
| 1102 | } |
| 1103 | Log.i(TAG, sb.toString()); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1104 | |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1105 | sb.setLength(0); |
| 1106 | sb.append("Features:"); |
| 1107 | it = mAvailableFeatures.keySet().iterator(); |
| 1108 | while (it.hasNext()) { |
| 1109 | sb.append(' '); |
| 1110 | sb.append(it.next()); |
| 1111 | } |
| 1112 | Log.i(TAG, sb.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1113 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1114 | |
| 1115 | private void readPermissionsFromXml(File permFile) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | FileReader permReader = null; |
| 1117 | try { |
| 1118 | permReader = new FileReader(permFile); |
| 1119 | } catch (FileNotFoundException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1120 | Slog.w(TAG, "Couldn't find or open permissions file " + permFile); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | return; |
| 1122 | } |
| 1123 | |
| 1124 | try { |
| 1125 | XmlPullParser parser = Xml.newPullParser(); |
| 1126 | parser.setInput(permReader); |
| 1127 | |
| 1128 | XmlUtils.beginDocument(parser, "permissions"); |
| 1129 | |
| 1130 | while (true) { |
| 1131 | XmlUtils.nextElement(parser); |
| 1132 | if (parser.getEventType() == XmlPullParser.END_DOCUMENT) { |
| 1133 | break; |
| 1134 | } |
| 1135 | |
| 1136 | String name = parser.getName(); |
| 1137 | if ("group".equals(name)) { |
| 1138 | String gidStr = parser.getAttributeValue(null, "gid"); |
| 1139 | if (gidStr != null) { |
| 1140 | int gid = Integer.parseInt(gidStr); |
| 1141 | mGlobalGids = appendInt(mGlobalGids, gid); |
| 1142 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1143 | Slog.w(TAG, "<group> without gid at " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | + parser.getPositionDescription()); |
| 1145 | } |
| 1146 | |
| 1147 | XmlUtils.skipCurrentTag(parser); |
| 1148 | continue; |
| 1149 | } else if ("permission".equals(name)) { |
| 1150 | String perm = parser.getAttributeValue(null, "name"); |
| 1151 | if (perm == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1152 | Slog.w(TAG, "<permission> without name at " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | + parser.getPositionDescription()); |
| 1154 | XmlUtils.skipCurrentTag(parser); |
| 1155 | continue; |
| 1156 | } |
| 1157 | perm = perm.intern(); |
| 1158 | readPermission(parser, perm); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1159 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | } else if ("assign-permission".equals(name)) { |
| 1161 | String perm = parser.getAttributeValue(null, "name"); |
| 1162 | if (perm == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1163 | Slog.w(TAG, "<assign-permission> without name at " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1164 | + parser.getPositionDescription()); |
| 1165 | XmlUtils.skipCurrentTag(parser); |
| 1166 | continue; |
| 1167 | } |
| 1168 | String uidStr = parser.getAttributeValue(null, "uid"); |
| 1169 | if (uidStr == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1170 | Slog.w(TAG, "<assign-permission> without uid at " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | + parser.getPositionDescription()); |
| 1172 | XmlUtils.skipCurrentTag(parser); |
| 1173 | continue; |
| 1174 | } |
| 1175 | int uid = Process.getUidForName(uidStr); |
| 1176 | if (uid < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1177 | Slog.w(TAG, "<assign-permission> with unknown uid \"" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | + uidStr + "\" at " |
| 1179 | + parser.getPositionDescription()); |
| 1180 | XmlUtils.skipCurrentTag(parser); |
| 1181 | continue; |
| 1182 | } |
| 1183 | perm = perm.intern(); |
| 1184 | HashSet<String> perms = mSystemPermissions.get(uid); |
| 1185 | if (perms == null) { |
| 1186 | perms = new HashSet<String>(); |
| 1187 | mSystemPermissions.put(uid, perms); |
| 1188 | } |
| 1189 | perms.add(perm); |
| 1190 | XmlUtils.skipCurrentTag(parser); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | } else if ("library".equals(name)) { |
| 1193 | String lname = parser.getAttributeValue(null, "name"); |
| 1194 | String lfile = parser.getAttributeValue(null, "file"); |
| 1195 | if (lname == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1196 | Slog.w(TAG, "<library> without name at " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | + parser.getPositionDescription()); |
| 1198 | } else if (lfile == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1199 | Slog.w(TAG, "<library> without file at " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1200 | + parser.getPositionDescription()); |
| 1201 | } else { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1202 | //Log.i(TAG, "Got library " + lname + " in " + lfile); |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1203 | mSharedLibraries.put(lname, lfile); |
| 1204 | } |
| 1205 | XmlUtils.skipCurrentTag(parser); |
| 1206 | continue; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1207 | |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1208 | } else if ("feature".equals(name)) { |
| 1209 | String fname = parser.getAttributeValue(null, "name"); |
| 1210 | if (fname == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1211 | Slog.w(TAG, "<feature> without name at " |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1212 | + parser.getPositionDescription()); |
| 1213 | } else { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1214 | //Log.i(TAG, "Got feature " + fname); |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1215 | FeatureInfo fi = new FeatureInfo(); |
| 1216 | fi.name = fname; |
| 1217 | mAvailableFeatures.put(fname, fi); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | } |
| 1219 | XmlUtils.skipCurrentTag(parser); |
| 1220 | continue; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | } else { |
| 1223 | XmlUtils.skipCurrentTag(parser); |
| 1224 | continue; |
| 1225 | } |
| 1226 | |
| 1227 | } |
| 1228 | } catch (XmlPullParserException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1229 | Slog.w(TAG, "Got execption parsing permissions.", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1231 | Slog.w(TAG, "Got execption parsing permissions.", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | void readPermission(XmlPullParser parser, String name) |
| 1236 | throws IOException, XmlPullParserException { |
| 1237 | |
| 1238 | name = name.intern(); |
| 1239 | |
| 1240 | BasePermission bp = mSettings.mPermissions.get(name); |
| 1241 | if (bp == null) { |
| 1242 | bp = new BasePermission(name, null, BasePermission.TYPE_BUILTIN); |
| 1243 | mSettings.mPermissions.put(name, bp); |
| 1244 | } |
| 1245 | int outerDepth = parser.getDepth(); |
| 1246 | int type; |
| 1247 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1248 | && (type != XmlPullParser.END_TAG |
| 1249 | || parser.getDepth() > outerDepth)) { |
| 1250 | if (type == XmlPullParser.END_TAG |
| 1251 | || type == XmlPullParser.TEXT) { |
| 1252 | continue; |
| 1253 | } |
| 1254 | |
| 1255 | String tagName = parser.getName(); |
| 1256 | if ("group".equals(tagName)) { |
| 1257 | String gidStr = parser.getAttributeValue(null, "gid"); |
| 1258 | if (gidStr != null) { |
| 1259 | int gid = Process.getGidForName(gidStr); |
| 1260 | bp.gids = appendInt(bp.gids, gid); |
| 1261 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1262 | Slog.w(TAG, "<group> without gid at " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1263 | + parser.getPositionDescription()); |
| 1264 | } |
| 1265 | } |
| 1266 | XmlUtils.skipCurrentTag(parser); |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | static int[] appendInt(int[] cur, int val) { |
| 1271 | if (cur == null) { |
| 1272 | return new int[] { val }; |
| 1273 | } |
| 1274 | final int N = cur.length; |
| 1275 | for (int i=0; i<N; i++) { |
| 1276 | if (cur[i] == val) { |
| 1277 | return cur; |
| 1278 | } |
| 1279 | } |
| 1280 | int[] ret = new int[N+1]; |
| 1281 | System.arraycopy(cur, 0, ret, 0, N); |
| 1282 | ret[N] = val; |
| 1283 | return ret; |
| 1284 | } |
| 1285 | |
| 1286 | static int[] appendInts(int[] cur, int[] add) { |
| 1287 | if (add == null) return cur; |
| 1288 | if (cur == null) return add; |
| 1289 | final int N = add.length; |
| 1290 | for (int i=0; i<N; i++) { |
| 1291 | cur = appendInt(cur, add[i]); |
| 1292 | } |
| 1293 | return cur; |
| 1294 | } |
| 1295 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1296 | static int[] removeInt(int[] cur, int val) { |
| 1297 | if (cur == null) { |
| 1298 | return null; |
| 1299 | } |
| 1300 | final int N = cur.length; |
| 1301 | for (int i=0; i<N; i++) { |
| 1302 | if (cur[i] == val) { |
| 1303 | int[] ret = new int[N-1]; |
| 1304 | if (i > 0) { |
| 1305 | System.arraycopy(cur, 0, ret, 0, i); |
| 1306 | } |
| 1307 | if (i < (N-1)) { |
| Jeff Brown | 8c8bb8b | 2010-04-20 17:21:47 -0700 | [diff] [blame] | 1308 | System.arraycopy(cur, i + 1, ret, i, N - i - 1); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1309 | } |
| 1310 | return ret; |
| 1311 | } |
| 1312 | } |
| 1313 | return cur; |
| 1314 | } |
| 1315 | |
| 1316 | static int[] removeInts(int[] cur, int[] rem) { |
| 1317 | if (rem == null) return cur; |
| 1318 | if (cur == null) return cur; |
| 1319 | final int N = rem.length; |
| 1320 | for (int i=0; i<N; i++) { |
| 1321 | cur = removeInt(cur, rem[i]); |
| 1322 | } |
| 1323 | return cur; |
| 1324 | } |
| 1325 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1326 | PackageInfo generatePackageInfo(PackageParser.Package p, int flags) { |
| Suchi Amalapurapu | b897cff | 2009-10-14 12:11:48 -0700 | [diff] [blame] | 1327 | if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 1328 | // The package has been uninstalled but has retained data and resources. |
| 1329 | return PackageParser.generatePackageInfo(p, null, flags); |
| 1330 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | final PackageSetting ps = (PackageSetting)p.mExtras; |
| 1332 | if (ps == null) { |
| 1333 | return null; |
| 1334 | } |
| 1335 | final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps; |
| 1336 | return PackageParser.generatePackageInfo(p, gp.gids, flags); |
| 1337 | } |
| 1338 | |
| 1339 | public PackageInfo getPackageInfo(String packageName, int flags) { |
| 1340 | synchronized (mPackages) { |
| 1341 | PackageParser.Package p = mPackages.get(packageName); |
| 1342 | if (Config.LOGV) Log.v( |
| Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 1343 | TAG, "getPackageInfo " + packageName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | + ": " + p); |
| 1345 | if (p != null) { |
| 1346 | return generatePackageInfo(p, flags); |
| 1347 | } |
| 1348 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 1349 | return generatePackageInfoFromSettingsLP(packageName, flags); |
| 1350 | } |
| 1351 | } |
| 1352 | return null; |
| 1353 | } |
| 1354 | |
| Dianne Hackborn | 4709693 | 2010-02-11 15:57:09 -0800 | [diff] [blame] | 1355 | public String[] currentToCanonicalPackageNames(String[] names) { |
| 1356 | String[] out = new String[names.length]; |
| 1357 | synchronized (mPackages) { |
| 1358 | for (int i=names.length-1; i>=0; i--) { |
| 1359 | PackageSetting ps = mSettings.mPackages.get(names[i]); |
| 1360 | out[i] = ps != null && ps.realName != null ? ps.realName : names[i]; |
| 1361 | } |
| 1362 | } |
| 1363 | return out; |
| 1364 | } |
| 1365 | |
| 1366 | public String[] canonicalToCurrentPackageNames(String[] names) { |
| 1367 | String[] out = new String[names.length]; |
| 1368 | synchronized (mPackages) { |
| 1369 | for (int i=names.length-1; i>=0; i--) { |
| 1370 | String cur = mSettings.mRenamedPackages.get(names[i]); |
| 1371 | out[i] = cur != null ? cur : names[i]; |
| 1372 | } |
| 1373 | } |
| 1374 | return out; |
| 1375 | } |
| 1376 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | public int getPackageUid(String packageName) { |
| 1378 | synchronized (mPackages) { |
| 1379 | PackageParser.Package p = mPackages.get(packageName); |
| 1380 | if(p != null) { |
| 1381 | return p.applicationInfo.uid; |
| 1382 | } |
| 1383 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 1384 | if((ps == null) || (ps.pkg == null) || (ps.pkg.applicationInfo == null)) { |
| 1385 | return -1; |
| 1386 | } |
| 1387 | p = ps.pkg; |
| 1388 | return p != null ? p.applicationInfo.uid : -1; |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | public int[] getPackageGids(String packageName) { |
| 1393 | synchronized (mPackages) { |
| 1394 | PackageParser.Package p = mPackages.get(packageName); |
| 1395 | if (Config.LOGV) Log.v( |
| Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 1396 | TAG, "getPackageGids" + packageName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1397 | + ": " + p); |
| 1398 | if (p != null) { |
| 1399 | final PackageSetting ps = (PackageSetting)p.mExtras; |
| 1400 | final SharedUserSetting suid = ps.sharedUser; |
| 1401 | return suid != null ? suid.gids : ps.gids; |
| 1402 | } |
| 1403 | } |
| 1404 | // stupid thing to indicate an error. |
| 1405 | return new int[0]; |
| 1406 | } |
| 1407 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1408 | static final PermissionInfo generatePermissionInfo( |
| 1409 | BasePermission bp, int flags) { |
| 1410 | if (bp.perm != null) { |
| 1411 | return PackageParser.generatePermissionInfo(bp.perm, flags); |
| 1412 | } |
| 1413 | PermissionInfo pi = new PermissionInfo(); |
| 1414 | pi.name = bp.name; |
| 1415 | pi.packageName = bp.sourcePackage; |
| 1416 | pi.nonLocalizedLabel = bp.name; |
| 1417 | pi.protectionLevel = bp.protectionLevel; |
| 1418 | return pi; |
| 1419 | } |
| 1420 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1421 | public PermissionInfo getPermissionInfo(String name, int flags) { |
| 1422 | synchronized (mPackages) { |
| 1423 | final BasePermission p = mSettings.mPermissions.get(name); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1424 | if (p != null) { |
| 1425 | return generatePermissionInfo(p, flags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1426 | } |
| 1427 | return null; |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) { |
| 1432 | synchronized (mPackages) { |
| 1433 | ArrayList<PermissionInfo> out = new ArrayList<PermissionInfo>(10); |
| 1434 | for (BasePermission p : mSettings.mPermissions.values()) { |
| 1435 | if (group == null) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1436 | if (p.perm == null || p.perm.info.group == null) { |
| 1437 | out.add(generatePermissionInfo(p, flags)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1438 | } |
| 1439 | } else { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1440 | if (p.perm != null && group.equals(p.perm.info.group)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1441 | out.add(PackageParser.generatePermissionInfo(p.perm, flags)); |
| 1442 | } |
| 1443 | } |
| 1444 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | if (out.size() > 0) { |
| 1447 | return out; |
| 1448 | } |
| 1449 | return mPermissionGroups.containsKey(group) ? out : null; |
| 1450 | } |
| 1451 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1452 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | public PermissionGroupInfo getPermissionGroupInfo(String name, int flags) { |
| 1454 | synchronized (mPackages) { |
| 1455 | return PackageParser.generatePermissionGroupInfo( |
| 1456 | mPermissionGroups.get(name), flags); |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | public List<PermissionGroupInfo> getAllPermissionGroups(int flags) { |
| 1461 | synchronized (mPackages) { |
| 1462 | final int N = mPermissionGroups.size(); |
| 1463 | ArrayList<PermissionGroupInfo> out |
| 1464 | = new ArrayList<PermissionGroupInfo>(N); |
| 1465 | for (PackageParser.PermissionGroup pg : mPermissionGroups.values()) { |
| 1466 | out.add(PackageParser.generatePermissionGroupInfo(pg, flags)); |
| 1467 | } |
| 1468 | return out; |
| 1469 | } |
| 1470 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1471 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | private ApplicationInfo generateApplicationInfoFromSettingsLP(String packageName, int flags) { |
| 1473 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 1474 | if(ps != null) { |
| 1475 | if(ps.pkg == null) { |
| 1476 | PackageInfo pInfo = generatePackageInfoFromSettingsLP(packageName, flags); |
| 1477 | if(pInfo != null) { |
| 1478 | return pInfo.applicationInfo; |
| 1479 | } |
| 1480 | return null; |
| 1481 | } |
| 1482 | return PackageParser.generateApplicationInfo(ps.pkg, flags); |
| 1483 | } |
| 1484 | return null; |
| 1485 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1486 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1487 | private PackageInfo generatePackageInfoFromSettingsLP(String packageName, int flags) { |
| 1488 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 1489 | if(ps != null) { |
| 1490 | if(ps.pkg == null) { |
| 1491 | ps.pkg = new PackageParser.Package(packageName); |
| 1492 | ps.pkg.applicationInfo.packageName = packageName; |
| Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 1493 | ps.pkg.applicationInfo.flags = ps.pkgFlags; |
| 1494 | ps.pkg.applicationInfo.publicSourceDir = ps.resourcePathString; |
| 1495 | ps.pkg.applicationInfo.sourceDir = ps.codePathString; |
| 1496 | ps.pkg.applicationInfo.dataDir = getDataPathForPackage(ps.pkg).getPath(); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 1497 | ps.pkg.applicationInfo.nativeLibraryDir = ps.nativeLibraryPathString; |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 1498 | ps.pkg.mSetEnabled = ps.enabled; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1499 | } |
| 1500 | return generatePackageInfo(ps.pkg, flags); |
| 1501 | } |
| 1502 | return null; |
| 1503 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1504 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1505 | public ApplicationInfo getApplicationInfo(String packageName, int flags) { |
| 1506 | synchronized (mPackages) { |
| 1507 | PackageParser.Package p = mPackages.get(packageName); |
| 1508 | if (Config.LOGV) Log.v( |
| 1509 | TAG, "getApplicationInfo " + packageName |
| 1510 | + ": " + p); |
| 1511 | if (p != null) { |
| 1512 | // Note: isEnabledLP() does not apply here - always return info |
| Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 1513 | return PackageParser.generateApplicationInfo(p, flags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | } |
| 1515 | if ("android".equals(packageName)||"system".equals(packageName)) { |
| 1516 | return mAndroidApplication; |
| 1517 | } |
| 1518 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 1519 | return generateApplicationInfoFromSettingsLP(packageName, flags); |
| 1520 | } |
| 1521 | } |
| 1522 | return null; |
| 1523 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1524 | |
| 1525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1526 | public void freeStorageAndNotify(final long freeStorageSize, final IPackageDataObserver observer) { |
| 1527 | mContext.enforceCallingOrSelfPermission( |
| 1528 | android.Manifest.permission.CLEAR_APP_CACHE, null); |
| 1529 | // Queue up an async operation since clearing cache may take a little while. |
| 1530 | mHandler.post(new Runnable() { |
| 1531 | public void run() { |
| 1532 | mHandler.removeCallbacks(this); |
| 1533 | int retCode = -1; |
| 1534 | if (mInstaller != null) { |
| 1535 | retCode = mInstaller.freeCache(freeStorageSize); |
| 1536 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1537 | Slog.w(TAG, "Couldn't clear application caches"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | } |
| 1539 | } //end if mInstaller |
| 1540 | if (observer != null) { |
| 1541 | try { |
| 1542 | observer.onRemoveCompleted(null, (retCode >= 0)); |
| 1543 | } catch (RemoteException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1544 | Slog.w(TAG, "RemoveException when invoking call back"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | } |
| 1546 | } |
| 1547 | } |
| 1548 | }); |
| 1549 | } |
| 1550 | |
| Suchi Amalapurapu | bc806f6 | 2009-06-17 15:18:19 -0700 | [diff] [blame] | 1551 | public void freeStorage(final long freeStorageSize, final IntentSender pi) { |
| Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 1552 | mContext.enforceCallingOrSelfPermission( |
| 1553 | android.Manifest.permission.CLEAR_APP_CACHE, null); |
| 1554 | // Queue up an async operation since clearing cache may take a little while. |
| 1555 | mHandler.post(new Runnable() { |
| 1556 | public void run() { |
| 1557 | mHandler.removeCallbacks(this); |
| 1558 | int retCode = -1; |
| 1559 | if (mInstaller != null) { |
| 1560 | retCode = mInstaller.freeCache(freeStorageSize); |
| 1561 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1562 | Slog.w(TAG, "Couldn't clear application caches"); |
| Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 1563 | } |
| 1564 | } |
| 1565 | if(pi != null) { |
| 1566 | try { |
| 1567 | // Callback via pending intent |
| 1568 | int code = (retCode >= 0) ? 1 : 0; |
| 1569 | pi.sendIntent(null, code, null, |
| 1570 | null, null); |
| 1571 | } catch (SendIntentException e1) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1572 | Slog.i(TAG, "Failed to send pending intent"); |
| Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 1573 | } |
| 1574 | } |
| 1575 | } |
| 1576 | }); |
| 1577 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1579 | public ActivityInfo getActivityInfo(ComponentName component, int flags) { |
| 1580 | synchronized (mPackages) { |
| 1581 | PackageParser.Activity a = mActivities.mActivities.get(component); |
| Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 1582 | |
| 1583 | if (Config.LOGV) Log.v(TAG, "getActivityInfo " + component + ": " + a); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1584 | if (a != null && mSettings.isEnabledLP(a.info, flags)) { |
| Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1585 | return PackageParser.generateActivityInfo(a, flags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1586 | } |
| 1587 | if (mResolveComponentName.equals(component)) { |
| 1588 | return mResolveActivity; |
| 1589 | } |
| 1590 | } |
| 1591 | return null; |
| 1592 | } |
| 1593 | |
| 1594 | public ActivityInfo getReceiverInfo(ComponentName component, int flags) { |
| 1595 | synchronized (mPackages) { |
| 1596 | PackageParser.Activity a = mReceivers.mActivities.get(component); |
| 1597 | if (Config.LOGV) Log.v( |
| 1598 | TAG, "getReceiverInfo " + component + ": " + a); |
| 1599 | if (a != null && mSettings.isEnabledLP(a.info, flags)) { |
| 1600 | return PackageParser.generateActivityInfo(a, flags); |
| 1601 | } |
| 1602 | } |
| 1603 | return null; |
| 1604 | } |
| 1605 | |
| 1606 | public ServiceInfo getServiceInfo(ComponentName component, int flags) { |
| 1607 | synchronized (mPackages) { |
| 1608 | PackageParser.Service s = mServices.mServices.get(component); |
| 1609 | if (Config.LOGV) Log.v( |
| 1610 | TAG, "getServiceInfo " + component + ": " + s); |
| 1611 | if (s != null && mSettings.isEnabledLP(s.info, flags)) { |
| 1612 | return PackageParser.generateServiceInfo(s, flags); |
| 1613 | } |
| 1614 | } |
| 1615 | return null; |
| 1616 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1617 | |
| Dianne Hackborn | 361199b | 2010-08-30 17:42:07 -0700 | [diff] [blame] | 1618 | public ProviderInfo getProviderInfo(ComponentName component, int flags) { |
| 1619 | synchronized (mPackages) { |
| 1620 | PackageParser.Provider p = mProvidersByComponent.get(component); |
| 1621 | if (Config.LOGV) Log.v( |
| 1622 | TAG, "getProviderInfo " + component + ": " + p); |
| 1623 | if (p != null && mSettings.isEnabledLP(p.info, flags)) { |
| 1624 | return PackageParser.generateProviderInfo(p, flags); |
| 1625 | } |
| 1626 | } |
| 1627 | return null; |
| 1628 | } |
| 1629 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | public String[] getSystemSharedLibraryNames() { |
| 1631 | Set<String> libSet; |
| 1632 | synchronized (mPackages) { |
| 1633 | libSet = mSharedLibraries.keySet(); |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1634 | int size = libSet.size(); |
| 1635 | if (size > 0) { |
| 1636 | String[] libs = new String[size]; |
| 1637 | libSet.toArray(libs); |
| 1638 | return libs; |
| 1639 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1640 | } |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1641 | return null; |
| 1642 | } |
| 1643 | |
| 1644 | public FeatureInfo[] getSystemAvailableFeatures() { |
| 1645 | Collection<FeatureInfo> featSet; |
| 1646 | synchronized (mPackages) { |
| 1647 | featSet = mAvailableFeatures.values(); |
| 1648 | int size = featSet.size(); |
| 1649 | if (size > 0) { |
| 1650 | FeatureInfo[] features = new FeatureInfo[size+1]; |
| 1651 | featSet.toArray(features); |
| 1652 | FeatureInfo fi = new FeatureInfo(); |
| 1653 | fi.reqGlEsVersion = SystemProperties.getInt("ro.opengles.version", |
| 1654 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 1655 | features[size] = fi; |
| 1656 | return features; |
| 1657 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1658 | } |
| 1659 | return null; |
| 1660 | } |
| 1661 | |
| Dianne Hackborn | 039c68e | 2009-09-26 16:39:23 -0700 | [diff] [blame] | 1662 | public boolean hasSystemFeature(String name) { |
| 1663 | synchronized (mPackages) { |
| 1664 | return mAvailableFeatures.containsKey(name); |
| 1665 | } |
| 1666 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1667 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1668 | public int checkPermission(String permName, String pkgName) { |
| 1669 | synchronized (mPackages) { |
| 1670 | PackageParser.Package p = mPackages.get(pkgName); |
| 1671 | if (p != null && p.mExtras != null) { |
| 1672 | PackageSetting ps = (PackageSetting)p.mExtras; |
| 1673 | if (ps.sharedUser != null) { |
| 1674 | if (ps.sharedUser.grantedPermissions.contains(permName)) { |
| 1675 | return PackageManager.PERMISSION_GRANTED; |
| 1676 | } |
| 1677 | } else if (ps.grantedPermissions.contains(permName)) { |
| 1678 | return PackageManager.PERMISSION_GRANTED; |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | return PackageManager.PERMISSION_DENIED; |
| 1683 | } |
| 1684 | |
| 1685 | public int checkUidPermission(String permName, int uid) { |
| 1686 | synchronized (mPackages) { |
| 1687 | Object obj = mSettings.getUserIdLP(uid); |
| 1688 | if (obj != null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1689 | GrantedPermissions gp = (GrantedPermissions)obj; |
| 1690 | if (gp.grantedPermissions.contains(permName)) { |
| 1691 | return PackageManager.PERMISSION_GRANTED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1692 | } |
| 1693 | } else { |
| 1694 | HashSet<String> perms = mSystemPermissions.get(uid); |
| 1695 | if (perms != null && perms.contains(permName)) { |
| 1696 | return PackageManager.PERMISSION_GRANTED; |
| 1697 | } |
| 1698 | } |
| 1699 | } |
| 1700 | return PackageManager.PERMISSION_DENIED; |
| 1701 | } |
| 1702 | |
| 1703 | private BasePermission findPermissionTreeLP(String permName) { |
| 1704 | for(BasePermission bp : mSettings.mPermissionTrees.values()) { |
| 1705 | if (permName.startsWith(bp.name) && |
| 1706 | permName.length() > bp.name.length() && |
| 1707 | permName.charAt(bp.name.length()) == '.') { |
| 1708 | return bp; |
| 1709 | } |
| 1710 | } |
| 1711 | return null; |
| 1712 | } |
| 1713 | |
| 1714 | private BasePermission checkPermissionTreeLP(String permName) { |
| 1715 | if (permName != null) { |
| 1716 | BasePermission bp = findPermissionTreeLP(permName); |
| 1717 | if (bp != null) { |
| 1718 | if (bp.uid == Binder.getCallingUid()) { |
| 1719 | return bp; |
| 1720 | } |
| 1721 | throw new SecurityException("Calling uid " |
| 1722 | + Binder.getCallingUid() |
| 1723 | + " is not allowed to add to permission tree " |
| 1724 | + bp.name + " owned by uid " + bp.uid); |
| 1725 | } |
| 1726 | } |
| 1727 | throw new SecurityException("No permission tree found for " + permName); |
| 1728 | } |
| 1729 | |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 1730 | static boolean compareStrings(CharSequence s1, CharSequence s2) { |
| 1731 | if (s1 == null) { |
| 1732 | return s2 == null; |
| 1733 | } |
| 1734 | if (s2 == null) { |
| 1735 | return false; |
| 1736 | } |
| 1737 | if (s1.getClass() != s2.getClass()) { |
| 1738 | return false; |
| 1739 | } |
| 1740 | return s1.equals(s2); |
| 1741 | } |
| 1742 | |
| 1743 | static boolean comparePermissionInfos(PermissionInfo pi1, PermissionInfo pi2) { |
| 1744 | if (pi1.icon != pi2.icon) return false; |
| Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1745 | if (pi1.logo != pi2.logo) return false; |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 1746 | if (pi1.protectionLevel != pi2.protectionLevel) return false; |
| 1747 | if (!compareStrings(pi1.name, pi2.name)) return false; |
| 1748 | if (!compareStrings(pi1.nonLocalizedLabel, pi2.nonLocalizedLabel)) return false; |
| 1749 | // We'll take care of setting this one. |
| 1750 | if (!compareStrings(pi1.packageName, pi2.packageName)) return false; |
| 1751 | // These are not currently stored in settings. |
| 1752 | //if (!compareStrings(pi1.group, pi2.group)) return false; |
| 1753 | //if (!compareStrings(pi1.nonLocalizedDescription, pi2.nonLocalizedDescription)) return false; |
| 1754 | //if (pi1.labelRes != pi2.labelRes) return false; |
| 1755 | //if (pi1.descriptionRes != pi2.descriptionRes) return false; |
| 1756 | return true; |
| 1757 | } |
| 1758 | |
| 1759 | boolean addPermissionLocked(PermissionInfo info, boolean async) { |
| 1760 | if (info.labelRes == 0 && info.nonLocalizedLabel == null) { |
| 1761 | throw new SecurityException("Label must be specified in permission"); |
| 1762 | } |
| 1763 | BasePermission tree = checkPermissionTreeLP(info.name); |
| 1764 | BasePermission bp = mSettings.mPermissions.get(info.name); |
| 1765 | boolean added = bp == null; |
| 1766 | boolean changed = true; |
| 1767 | if (added) { |
| 1768 | bp = new BasePermission(info.name, tree.sourcePackage, |
| 1769 | BasePermission.TYPE_DYNAMIC); |
| 1770 | } else if (bp.type != BasePermission.TYPE_DYNAMIC) { |
| 1771 | throw new SecurityException( |
| 1772 | "Not allowed to modify non-dynamic permission " |
| 1773 | + info.name); |
| 1774 | } else { |
| 1775 | if (bp.protectionLevel == info.protectionLevel |
| 1776 | && bp.perm.owner.equals(tree.perm.owner) |
| 1777 | && bp.uid == tree.uid |
| 1778 | && comparePermissionInfos(bp.perm.info, info)) { |
| 1779 | changed = false; |
| 1780 | } |
| 1781 | } |
| 1782 | bp.protectionLevel = info.protectionLevel; |
| 1783 | bp.perm = new PackageParser.Permission(tree.perm.owner, |
| 1784 | new PermissionInfo(info)); |
| 1785 | bp.perm.info.packageName = tree.perm.info.packageName; |
| 1786 | bp.uid = tree.uid; |
| 1787 | if (added) { |
| 1788 | mSettings.mPermissions.put(info.name, bp); |
| 1789 | } |
| 1790 | if (changed) { |
| 1791 | if (!async) { |
| 1792 | mSettings.writeLP(); |
| 1793 | } else { |
| 1794 | scheduleWriteSettingsLocked(); |
| 1795 | } |
| 1796 | } |
| 1797 | return added; |
| 1798 | } |
| 1799 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1800 | public boolean addPermission(PermissionInfo info) { |
| 1801 | synchronized (mPackages) { |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 1802 | return addPermissionLocked(info, false); |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | public boolean addPermissionAsync(PermissionInfo info) { |
| 1807 | synchronized (mPackages) { |
| 1808 | return addPermissionLocked(info, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | public void removePermission(String name) { |
| 1813 | synchronized (mPackages) { |
| 1814 | checkPermissionTreeLP(name); |
| 1815 | BasePermission bp = mSettings.mPermissions.get(name); |
| 1816 | if (bp != null) { |
| 1817 | if (bp.type != BasePermission.TYPE_DYNAMIC) { |
| 1818 | throw new SecurityException( |
| 1819 | "Not allowed to modify non-dynamic permission " |
| 1820 | + name); |
| 1821 | } |
| 1822 | mSettings.mPermissions.remove(name); |
| 1823 | mSettings.writeLP(); |
| 1824 | } |
| 1825 | } |
| 1826 | } |
| 1827 | |
| Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1828 | public boolean isProtectedBroadcast(String actionName) { |
| 1829 | synchronized (mPackages) { |
| 1830 | return mProtectedBroadcasts.contains(actionName); |
| 1831 | } |
| 1832 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1833 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1834 | public int checkSignatures(String pkg1, String pkg2) { |
| 1835 | synchronized (mPackages) { |
| 1836 | PackageParser.Package p1 = mPackages.get(pkg1); |
| 1837 | PackageParser.Package p2 = mPackages.get(pkg2); |
| 1838 | if (p1 == null || p1.mExtras == null |
| 1839 | || p2 == null || p2.mExtras == null) { |
| 1840 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1841 | } |
| Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1842 | return checkSignaturesLP(p1.mSignatures, p2.mSignatures); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1843 | } |
| 1844 | } |
| 1845 | |
| Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1846 | public int checkUidSignatures(int uid1, int uid2) { |
| 1847 | synchronized (mPackages) { |
| 1848 | Signature[] s1; |
| 1849 | Signature[] s2; |
| 1850 | Object obj = mSettings.getUserIdLP(uid1); |
| 1851 | if (obj != null) { |
| 1852 | if (obj instanceof SharedUserSetting) { |
| 1853 | s1 = ((SharedUserSetting)obj).signatures.mSignatures; |
| 1854 | } else if (obj instanceof PackageSetting) { |
| 1855 | s1 = ((PackageSetting)obj).signatures.mSignatures; |
| 1856 | } else { |
| 1857 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1858 | } |
| 1859 | } else { |
| 1860 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1861 | } |
| 1862 | obj = mSettings.getUserIdLP(uid2); |
| 1863 | if (obj != null) { |
| 1864 | if (obj instanceof SharedUserSetting) { |
| 1865 | s2 = ((SharedUserSetting)obj).signatures.mSignatures; |
| 1866 | } else if (obj instanceof PackageSetting) { |
| 1867 | s2 = ((PackageSetting)obj).signatures.mSignatures; |
| 1868 | } else { |
| 1869 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1870 | } |
| 1871 | } else { |
| 1872 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1873 | } |
| 1874 | return checkSignaturesLP(s1, s2); |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | int checkSignaturesLP(Signature[] s1, Signature[] s2) { |
| 1879 | if (s1 == null) { |
| 1880 | return s2 == null |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1881 | ? PackageManager.SIGNATURE_NEITHER_SIGNED |
| 1882 | : PackageManager.SIGNATURE_FIRST_NOT_SIGNED; |
| 1883 | } |
| Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1884 | if (s2 == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | return PackageManager.SIGNATURE_SECOND_NOT_SIGNED; |
| 1886 | } |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 1887 | HashSet<Signature> set1 = new HashSet<Signature>(); |
| 1888 | for (Signature sig : s1) { |
| 1889 | set1.add(sig); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1890 | } |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 1891 | HashSet<Signature> set2 = new HashSet<Signature>(); |
| 1892 | for (Signature sig : s2) { |
| 1893 | set2.add(sig); |
| 1894 | } |
| 1895 | // Make sure s2 contains all signatures in s1. |
| 1896 | if (set1.equals(set2)) { |
| 1897 | return PackageManager.SIGNATURE_MATCH; |
| 1898 | } |
| 1899 | return PackageManager.SIGNATURE_NO_MATCH; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | public String[] getPackagesForUid(int uid) { |
| 1903 | synchronized (mPackages) { |
| 1904 | Object obj = mSettings.getUserIdLP(uid); |
| 1905 | if (obj instanceof SharedUserSetting) { |
| 1906 | SharedUserSetting sus = (SharedUserSetting)obj; |
| 1907 | final int N = sus.packages.size(); |
| 1908 | String[] res = new String[N]; |
| 1909 | Iterator<PackageSetting> it = sus.packages.iterator(); |
| 1910 | int i=0; |
| 1911 | while (it.hasNext()) { |
| 1912 | res[i++] = it.next().name; |
| 1913 | } |
| 1914 | return res; |
| 1915 | } else if (obj instanceof PackageSetting) { |
| 1916 | PackageSetting ps = (PackageSetting)obj; |
| 1917 | return new String[] { ps.name }; |
| 1918 | } |
| 1919 | } |
| 1920 | return null; |
| 1921 | } |
| 1922 | |
| 1923 | public String getNameForUid(int uid) { |
| 1924 | synchronized (mPackages) { |
| 1925 | Object obj = mSettings.getUserIdLP(uid); |
| 1926 | if (obj instanceof SharedUserSetting) { |
| 1927 | SharedUserSetting sus = (SharedUserSetting)obj; |
| 1928 | return sus.name + ":" + sus.userId; |
| 1929 | } else if (obj instanceof PackageSetting) { |
| 1930 | PackageSetting ps = (PackageSetting)obj; |
| 1931 | return ps.name; |
| 1932 | } |
| 1933 | } |
| 1934 | return null; |
| 1935 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1936 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1937 | public int getUidForSharedUser(String sharedUserName) { |
| 1938 | if(sharedUserName == null) { |
| 1939 | return -1; |
| 1940 | } |
| 1941 | synchronized (mPackages) { |
| 1942 | SharedUserSetting suid = mSettings.getSharedUserLP(sharedUserName, 0, false); |
| 1943 | if(suid == null) { |
| 1944 | return -1; |
| 1945 | } |
| 1946 | return suid.userId; |
| 1947 | } |
| 1948 | } |
| 1949 | |
| 1950 | public ResolveInfo resolveIntent(Intent intent, String resolvedType, |
| 1951 | int flags) { |
| 1952 | List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags); |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 1953 | return chooseBestActivity(intent, resolvedType, flags, query); |
| 1954 | } |
| 1955 | |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 1956 | private ResolveInfo chooseBestActivity(Intent intent, String resolvedType, |
| 1957 | int flags, List<ResolveInfo> query) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1958 | if (query != null) { |
| 1959 | final int N = query.size(); |
| 1960 | if (N == 1) { |
| 1961 | return query.get(0); |
| 1962 | } else if (N > 1) { |
| 1963 | // If there is more than one activity with the same priority, |
| 1964 | // then let the user decide between them. |
| 1965 | ResolveInfo r0 = query.get(0); |
| 1966 | ResolveInfo r1 = query.get(1); |
| 1967 | if (false) { |
| 1968 | System.out.println(r0.activityInfo.name + |
| 1969 | "=" + r0.priority + " vs " + |
| 1970 | r1.activityInfo.name + |
| 1971 | "=" + r1.priority); |
| 1972 | } |
| 1973 | // If the first activity has a higher priority, or a different |
| 1974 | // default, then it is always desireable to pick it. |
| 1975 | if (r0.priority != r1.priority |
| 1976 | || r0.preferredOrder != r1.preferredOrder |
| 1977 | || r0.isDefault != r1.isDefault) { |
| 1978 | return query.get(0); |
| 1979 | } |
| 1980 | // If we have saved a preference for a preferred activity for |
| 1981 | // this Intent, use that. |
| 1982 | ResolveInfo ri = findPreferredActivity(intent, resolvedType, |
| 1983 | flags, query, r0.priority); |
| 1984 | if (ri != null) { |
| 1985 | return ri; |
| 1986 | } |
| 1987 | return mResolveInfo; |
| 1988 | } |
| 1989 | } |
| 1990 | return null; |
| 1991 | } |
| 1992 | |
| 1993 | ResolveInfo findPreferredActivity(Intent intent, String resolvedType, |
| 1994 | int flags, List<ResolveInfo> query, int priority) { |
| 1995 | synchronized (mPackages) { |
| 1996 | if (DEBUG_PREFERRED) intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION); |
| 1997 | List<PreferredActivity> prefs = |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 1998 | mSettings.mPreferredActivities.queryIntent(intent, resolvedType, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 2000 | if (prefs != null && prefs.size() > 0) { |
| 2001 | // First figure out how good the original match set is. |
| 2002 | // We will only allow preferred activities that came |
| 2003 | // from the same match quality. |
| 2004 | int match = 0; |
| 2005 | final int N = query.size(); |
| 2006 | if (DEBUG_PREFERRED) Log.v(TAG, "Figuring out best match..."); |
| 2007 | for (int j=0; j<N; j++) { |
| 2008 | ResolveInfo ri = query.get(j); |
| 2009 | if (DEBUG_PREFERRED) Log.v(TAG, "Match for " + ri.activityInfo |
| 2010 | + ": 0x" + Integer.toHexString(match)); |
| 2011 | if (ri.match > match) match = ri.match; |
| 2012 | } |
| 2013 | if (DEBUG_PREFERRED) Log.v(TAG, "Best match: 0x" |
| 2014 | + Integer.toHexString(match)); |
| 2015 | match &= IntentFilter.MATCH_CATEGORY_MASK; |
| 2016 | final int M = prefs.size(); |
| 2017 | for (int i=0; i<M; i++) { |
| 2018 | PreferredActivity pa = prefs.get(i); |
| 2019 | if (pa.mMatch != match) { |
| 2020 | continue; |
| 2021 | } |
| 2022 | ActivityInfo ai = getActivityInfo(pa.mActivity, flags); |
| 2023 | if (DEBUG_PREFERRED) { |
| 2024 | Log.v(TAG, "Got preferred activity:"); |
| Marco Nelissen | d85621c | 2010-09-03 09:25:33 -0700 | [diff] [blame] | 2025 | if (ai != null) { |
| 2026 | ai.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 2027 | } else { |
| 2028 | Log.v(TAG, " null"); |
| 2029 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | } |
| 2031 | if (ai != null) { |
| 2032 | for (int j=0; j<N; j++) { |
| 2033 | ResolveInfo ri = query.get(j); |
| 2034 | if (!ri.activityInfo.applicationInfo.packageName |
| 2035 | .equals(ai.applicationInfo.packageName)) { |
| 2036 | continue; |
| 2037 | } |
| 2038 | if (!ri.activityInfo.name.equals(ai.name)) { |
| 2039 | continue; |
| 2040 | } |
| 2041 | |
| 2042 | // Okay we found a previously set preferred app. |
| 2043 | // If the result set is different from when this |
| 2044 | // was created, we need to clear it and re-ask the |
| 2045 | // user their preference. |
| 2046 | if (!pa.sameSet(query, priority)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2047 | Slog.i(TAG, "Result set changed, dropping preferred activity for " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2048 | + intent + " type " + resolvedType); |
| 2049 | mSettings.mPreferredActivities.removeFilter(pa); |
| 2050 | return null; |
| 2051 | } |
| 2052 | |
| 2053 | // Yay! |
| 2054 | return ri; |
| 2055 | } |
| 2056 | } |
| 2057 | } |
| 2058 | } |
| 2059 | } |
| 2060 | return null; |
| 2061 | } |
| 2062 | |
| 2063 | public List<ResolveInfo> queryIntentActivities(Intent intent, |
| 2064 | String resolvedType, int flags) { |
| 2065 | ComponentName comp = intent.getComponent(); |
| 2066 | if (comp != null) { |
| 2067 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2068 | ActivityInfo ai = getActivityInfo(comp, flags); |
| 2069 | if (ai != null) { |
| 2070 | ResolveInfo ri = new ResolveInfo(); |
| 2071 | ri.activityInfo = ai; |
| 2072 | list.add(ri); |
| 2073 | } |
| 2074 | return list; |
| 2075 | } |
| 2076 | |
| 2077 | synchronized (mPackages) { |
| Dianne Hackborn | c14b9ccd | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2078 | String pkgName = intent.getPackage(); |
| 2079 | if (pkgName == null) { |
| 2080 | return (List<ResolveInfo>)mActivities.queryIntent(intent, |
| 2081 | resolvedType, flags); |
| 2082 | } |
| 2083 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2084 | if (pkg != null) { |
| 2085 | return (List<ResolveInfo>) mActivities.queryIntentForPackage(intent, |
| 2086 | resolvedType, flags, pkg.activities); |
| 2087 | } |
| 2088 | return null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, |
| 2093 | Intent[] specifics, String[] specificTypes, Intent intent, |
| 2094 | String resolvedType, int flags) { |
| 2095 | final String resultsAction = intent.getAction(); |
| 2096 | |
| 2097 | List<ResolveInfo> results = queryIntentActivities( |
| 2098 | intent, resolvedType, flags|PackageManager.GET_RESOLVED_FILTER); |
| 2099 | if (Config.LOGV) Log.v(TAG, "Query " + intent + ": " + results); |
| 2100 | |
| 2101 | int specificsPos = 0; |
| 2102 | int N; |
| 2103 | |
| 2104 | // todo: note that the algorithm used here is O(N^2). This |
| 2105 | // isn't a problem in our current environment, but if we start running |
| 2106 | // into situations where we have more than 5 or 10 matches then this |
| 2107 | // should probably be changed to something smarter... |
| 2108 | |
| 2109 | // First we go through and resolve each of the specific items |
| 2110 | // that were supplied, taking care of removing any corresponding |
| 2111 | // duplicate items in the generic resolve list. |
| 2112 | if (specifics != null) { |
| 2113 | for (int i=0; i<specifics.length; i++) { |
| 2114 | final Intent sintent = specifics[i]; |
| 2115 | if (sintent == null) { |
| 2116 | continue; |
| 2117 | } |
| 2118 | |
| 2119 | if (Config.LOGV) Log.v(TAG, "Specific #" + i + ": " + sintent); |
| 2120 | String action = sintent.getAction(); |
| 2121 | if (resultsAction != null && resultsAction.equals(action)) { |
| 2122 | // If this action was explicitly requested, then don't |
| 2123 | // remove things that have it. |
| 2124 | action = null; |
| 2125 | } |
| 2126 | ComponentName comp = sintent.getComponent(); |
| 2127 | ResolveInfo ri = null; |
| 2128 | ActivityInfo ai = null; |
| 2129 | if (comp == null) { |
| 2130 | ri = resolveIntent( |
| 2131 | sintent, |
| 2132 | specificTypes != null ? specificTypes[i] : null, |
| 2133 | flags); |
| 2134 | if (ri == null) { |
| 2135 | continue; |
| 2136 | } |
| 2137 | if (ri == mResolveInfo) { |
| 2138 | // ACK! Must do something better with this. |
| 2139 | } |
| 2140 | ai = ri.activityInfo; |
| 2141 | comp = new ComponentName(ai.applicationInfo.packageName, |
| 2142 | ai.name); |
| 2143 | } else { |
| 2144 | ai = getActivityInfo(comp, flags); |
| 2145 | if (ai == null) { |
| 2146 | continue; |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | // Look for any generic query activities that are duplicates |
| 2151 | // of this specific one, and remove them from the results. |
| 2152 | if (Config.LOGV) Log.v(TAG, "Specific #" + i + ": " + ai); |
| 2153 | N = results.size(); |
| 2154 | int j; |
| 2155 | for (j=specificsPos; j<N; j++) { |
| 2156 | ResolveInfo sri = results.get(j); |
| 2157 | if ((sri.activityInfo.name.equals(comp.getClassName()) |
| 2158 | && sri.activityInfo.applicationInfo.packageName.equals( |
| 2159 | comp.getPackageName())) |
| 2160 | || (action != null && sri.filter.matchAction(action))) { |
| 2161 | results.remove(j); |
| 2162 | if (Config.LOGV) Log.v( |
| 2163 | TAG, "Removing duplicate item from " + j |
| 2164 | + " due to specific " + specificsPos); |
| 2165 | if (ri == null) { |
| 2166 | ri = sri; |
| 2167 | } |
| 2168 | j--; |
| 2169 | N--; |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | // Add this specific item to its proper place. |
| 2174 | if (ri == null) { |
| 2175 | ri = new ResolveInfo(); |
| 2176 | ri.activityInfo = ai; |
| 2177 | } |
| 2178 | results.add(specificsPos, ri); |
| 2179 | ri.specificIndex = i; |
| 2180 | specificsPos++; |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | // Now we go through the remaining generic results and remove any |
| 2185 | // duplicate actions that are found here. |
| 2186 | N = results.size(); |
| 2187 | for (int i=specificsPos; i<N-1; i++) { |
| 2188 | final ResolveInfo rii = results.get(i); |
| 2189 | if (rii.filter == null) { |
| 2190 | continue; |
| 2191 | } |
| 2192 | |
| 2193 | // Iterate over all of the actions of this result's intent |
| 2194 | // filter... typically this should be just one. |
| 2195 | final Iterator<String> it = rii.filter.actionsIterator(); |
| 2196 | if (it == null) { |
| 2197 | continue; |
| 2198 | } |
| 2199 | while (it.hasNext()) { |
| 2200 | final String action = it.next(); |
| 2201 | if (resultsAction != null && resultsAction.equals(action)) { |
| 2202 | // If this action was explicitly requested, then don't |
| 2203 | // remove things that have it. |
| 2204 | continue; |
| 2205 | } |
| 2206 | for (int j=i+1; j<N; j++) { |
| 2207 | final ResolveInfo rij = results.get(j); |
| 2208 | if (rij.filter != null && rij.filter.hasAction(action)) { |
| 2209 | results.remove(j); |
| 2210 | if (Config.LOGV) Log.v( |
| 2211 | TAG, "Removing duplicate item from " + j |
| 2212 | + " due to action " + action + " at " + i); |
| 2213 | j--; |
| 2214 | N--; |
| 2215 | } |
| 2216 | } |
| 2217 | } |
| 2218 | |
| 2219 | // If the caller didn't request filter information, drop it now |
| 2220 | // so we don't have to marshall/unmarshall it. |
| 2221 | if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) { |
| 2222 | rii.filter = null; |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | // Filter out the caller activity if so requested. |
| 2227 | if (caller != null) { |
| 2228 | N = results.size(); |
| 2229 | for (int i=0; i<N; i++) { |
| 2230 | ActivityInfo ainfo = results.get(i).activityInfo; |
| 2231 | if (caller.getPackageName().equals(ainfo.applicationInfo.packageName) |
| 2232 | && caller.getClassName().equals(ainfo.name)) { |
| 2233 | results.remove(i); |
| 2234 | break; |
| 2235 | } |
| 2236 | } |
| 2237 | } |
| 2238 | |
| 2239 | // If the caller didn't request filter information, |
| 2240 | // drop them now so we don't have to |
| 2241 | // marshall/unmarshall it. |
| 2242 | if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) { |
| 2243 | N = results.size(); |
| 2244 | for (int i=0; i<N; i++) { |
| 2245 | results.get(i).filter = null; |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | if (Config.LOGV) Log.v(TAG, "Result: " + results); |
| 2250 | return results; |
| 2251 | } |
| 2252 | |
| 2253 | public List<ResolveInfo> queryIntentReceivers(Intent intent, |
| 2254 | String resolvedType, int flags) { |
| Dianne Hackborn | c14b9ccd | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2255 | ComponentName comp = intent.getComponent(); |
| 2256 | if (comp != null) { |
| 2257 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2258 | ActivityInfo ai = getReceiverInfo(comp, flags); |
| 2259 | if (ai != null) { |
| 2260 | ResolveInfo ri = new ResolveInfo(); |
| 2261 | ri.activityInfo = ai; |
| 2262 | list.add(ri); |
| 2263 | } |
| 2264 | return list; |
| 2265 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2267 | synchronized (mPackages) { |
| Dianne Hackborn | c14b9ccd | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2268 | String pkgName = intent.getPackage(); |
| 2269 | if (pkgName == null) { |
| 2270 | return (List<ResolveInfo>)mReceivers.queryIntent(intent, |
| 2271 | resolvedType, flags); |
| 2272 | } |
| 2273 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2274 | if (pkg != null) { |
| 2275 | return (List<ResolveInfo>) mReceivers.queryIntentForPackage(intent, |
| 2276 | resolvedType, flags, pkg.receivers); |
| 2277 | } |
| 2278 | return null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | public ResolveInfo resolveService(Intent intent, String resolvedType, |
| 2283 | int flags) { |
| 2284 | List<ResolveInfo> query = queryIntentServices(intent, resolvedType, |
| 2285 | flags); |
| 2286 | if (query != null) { |
| 2287 | if (query.size() >= 1) { |
| 2288 | // If there is more than one service with the same priority, |
| 2289 | // just arbitrarily pick the first one. |
| 2290 | return query.get(0); |
| 2291 | } |
| 2292 | } |
| 2293 | return null; |
| 2294 | } |
| 2295 | |
| 2296 | public List<ResolveInfo> queryIntentServices(Intent intent, |
| 2297 | String resolvedType, int flags) { |
| 2298 | ComponentName comp = intent.getComponent(); |
| 2299 | if (comp != null) { |
| 2300 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2301 | ServiceInfo si = getServiceInfo(comp, flags); |
| 2302 | if (si != null) { |
| 2303 | ResolveInfo ri = new ResolveInfo(); |
| 2304 | ri.serviceInfo = si; |
| 2305 | list.add(ri); |
| 2306 | } |
| 2307 | return list; |
| 2308 | } |
| 2309 | |
| 2310 | synchronized (mPackages) { |
| Dianne Hackborn | c14b9ccd | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2311 | String pkgName = intent.getPackage(); |
| 2312 | if (pkgName == null) { |
| 2313 | return (List<ResolveInfo>)mServices.queryIntent(intent, |
| 2314 | resolvedType, flags); |
| 2315 | } |
| 2316 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2317 | if (pkg != null) { |
| 2318 | return (List<ResolveInfo>)mServices.queryIntentForPackage(intent, |
| 2319 | resolvedType, flags, pkg.services); |
| 2320 | } |
| 2321 | return null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | } |
| 2323 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2324 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | public List<PackageInfo> getInstalledPackages(int flags) { |
| 2326 | ArrayList<PackageInfo> finalList = new ArrayList<PackageInfo>(); |
| 2327 | |
| 2328 | synchronized (mPackages) { |
| 2329 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 2330 | Iterator<PackageSetting> i = mSettings.mPackages.values().iterator(); |
| 2331 | while (i.hasNext()) { |
| 2332 | final PackageSetting ps = i.next(); |
| 2333 | PackageInfo psPkg = generatePackageInfoFromSettingsLP(ps.name, flags); |
| 2334 | if(psPkg != null) { |
| 2335 | finalList.add(psPkg); |
| 2336 | } |
| 2337 | } |
| 2338 | } |
| 2339 | else { |
| 2340 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2341 | while (i.hasNext()) { |
| 2342 | final PackageParser.Package p = i.next(); |
| 2343 | if (p.applicationInfo != null) { |
| 2344 | PackageInfo pi = generatePackageInfo(p, flags); |
| 2345 | if(pi != null) { |
| 2346 | finalList.add(pi); |
| 2347 | } |
| 2348 | } |
| 2349 | } |
| 2350 | } |
| 2351 | } |
| 2352 | return finalList; |
| 2353 | } |
| 2354 | |
| 2355 | public List<ApplicationInfo> getInstalledApplications(int flags) { |
| 2356 | ArrayList<ApplicationInfo> finalList = new ArrayList<ApplicationInfo>(); |
| 2357 | synchronized(mPackages) { |
| 2358 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 2359 | Iterator<PackageSetting> i = mSettings.mPackages.values().iterator(); |
| 2360 | while (i.hasNext()) { |
| 2361 | final PackageSetting ps = i.next(); |
| 2362 | ApplicationInfo ai = generateApplicationInfoFromSettingsLP(ps.name, flags); |
| 2363 | if(ai != null) { |
| 2364 | finalList.add(ai); |
| 2365 | } |
| 2366 | } |
| 2367 | } |
| 2368 | else { |
| 2369 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2370 | while (i.hasNext()) { |
| 2371 | final PackageParser.Package p = i.next(); |
| 2372 | if (p.applicationInfo != null) { |
| 2373 | ApplicationInfo ai = PackageParser.generateApplicationInfo(p, flags); |
| 2374 | if(ai != null) { |
| 2375 | finalList.add(ai); |
| 2376 | } |
| 2377 | } |
| 2378 | } |
| 2379 | } |
| 2380 | } |
| 2381 | return finalList; |
| 2382 | } |
| 2383 | |
| 2384 | public List<ApplicationInfo> getPersistentApplications(int flags) { |
| 2385 | ArrayList<ApplicationInfo> finalList = new ArrayList<ApplicationInfo>(); |
| 2386 | |
| 2387 | synchronized (mPackages) { |
| 2388 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2389 | while (i.hasNext()) { |
| 2390 | PackageParser.Package p = i.next(); |
| 2391 | if (p.applicationInfo != null |
| 2392 | && (p.applicationInfo.flags&ApplicationInfo.FLAG_PERSISTENT) != 0 |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 2393 | && (!mSafeMode || isSystemApp(p))) { |
| Jey | 2eebf5c | 2009-11-18 18:37:31 -0800 | [diff] [blame] | 2394 | finalList.add(PackageParser.generateApplicationInfo(p, flags)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | } |
| 2396 | } |
| 2397 | } |
| 2398 | |
| 2399 | return finalList; |
| 2400 | } |
| 2401 | |
| 2402 | public ProviderInfo resolveContentProvider(String name, int flags) { |
| 2403 | synchronized (mPackages) { |
| 2404 | final PackageParser.Provider provider = mProviders.get(name); |
| 2405 | return provider != null |
| 2406 | && mSettings.isEnabledLP(provider.info, flags) |
| 2407 | && (!mSafeMode || (provider.info.applicationInfo.flags |
| 2408 | &ApplicationInfo.FLAG_SYSTEM) != 0) |
| 2409 | ? PackageParser.generateProviderInfo(provider, flags) |
| 2410 | : null; |
| 2411 | } |
| 2412 | } |
| 2413 | |
| Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2414 | /** |
| 2415 | * @deprecated |
| 2416 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | public void querySyncProviders(List outNames, List outInfo) { |
| 2418 | synchronized (mPackages) { |
| 2419 | Iterator<Map.Entry<String, PackageParser.Provider>> i |
| 2420 | = mProviders.entrySet().iterator(); |
| 2421 | |
| 2422 | while (i.hasNext()) { |
| 2423 | Map.Entry<String, PackageParser.Provider> entry = i.next(); |
| 2424 | PackageParser.Provider p = entry.getValue(); |
| 2425 | |
| 2426 | if (p.syncable |
| 2427 | && (!mSafeMode || (p.info.applicationInfo.flags |
| 2428 | &ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| 2429 | outNames.add(entry.getKey()); |
| 2430 | outInfo.add(PackageParser.generateProviderInfo(p, 0)); |
| 2431 | } |
| 2432 | } |
| 2433 | } |
| 2434 | } |
| 2435 | |
| 2436 | public List<ProviderInfo> queryContentProviders(String processName, |
| 2437 | int uid, int flags) { |
| 2438 | ArrayList<ProviderInfo> finalList = null; |
| 2439 | |
| 2440 | synchronized (mPackages) { |
| 2441 | Iterator<PackageParser.Provider> i = mProvidersByComponent.values().iterator(); |
| 2442 | while (i.hasNext()) { |
| 2443 | PackageParser.Provider p = i.next(); |
| 2444 | if (p.info.authority != null |
| 2445 | && (processName == null || |
| 2446 | (p.info.processName.equals(processName) |
| 2447 | && p.info.applicationInfo.uid == uid)) |
| 2448 | && mSettings.isEnabledLP(p.info, flags) |
| 2449 | && (!mSafeMode || (p.info.applicationInfo.flags |
| 2450 | &ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| 2451 | if (finalList == null) { |
| 2452 | finalList = new ArrayList<ProviderInfo>(3); |
| 2453 | } |
| 2454 | finalList.add(PackageParser.generateProviderInfo(p, |
| 2455 | flags)); |
| 2456 | } |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | if (finalList != null) { |
| 2461 | Collections.sort(finalList, mProviderInitOrderSorter); |
| 2462 | } |
| 2463 | |
| 2464 | return finalList; |
| 2465 | } |
| 2466 | |
| 2467 | public InstrumentationInfo getInstrumentationInfo(ComponentName name, |
| 2468 | int flags) { |
| 2469 | synchronized (mPackages) { |
| 2470 | final PackageParser.Instrumentation i = mInstrumentation.get(name); |
| 2471 | return PackageParser.generateInstrumentationInfo(i, flags); |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | public List<InstrumentationInfo> queryInstrumentation(String targetPackage, |
| 2476 | int flags) { |
| 2477 | ArrayList<InstrumentationInfo> finalList = |
| 2478 | new ArrayList<InstrumentationInfo>(); |
| 2479 | |
| 2480 | synchronized (mPackages) { |
| 2481 | Iterator<PackageParser.Instrumentation> i = mInstrumentation.values().iterator(); |
| 2482 | while (i.hasNext()) { |
| 2483 | PackageParser.Instrumentation p = i.next(); |
| 2484 | if (targetPackage == null |
| 2485 | || targetPackage.equals(p.info.targetPackage)) { |
| 2486 | finalList.add(PackageParser.generateInstrumentationInfo(p, |
| 2487 | flags)); |
| 2488 | } |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | return finalList; |
| 2493 | } |
| 2494 | |
| 2495 | private void scanDirLI(File dir, int flags, int scanMode) { |
| 2496 | Log.d(TAG, "Scanning app dir " + dir); |
| 2497 | |
| 2498 | String[] files = dir.list(); |
| 2499 | |
| 2500 | int i; |
| 2501 | for (i=0; i<files.length; i++) { |
| 2502 | File file = new File(dir, files[i]); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 2503 | if (!isPackageFilename(files[i])) { |
| 2504 | // Ignore entries which are not apk's |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 2505 | continue; |
| 2506 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2507 | PackageParser.Package pkg = scanPackageLI(file, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2508 | flags|PackageParser.PARSE_MUST_BE_APK, scanMode); |
| Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2509 | // Don't mess around with apps in system partition. |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 2510 | if (pkg == null && (flags & PackageParser.PARSE_IS_SYSTEM) == 0 && |
| 2511 | mLastScanError == PackageManager.INSTALL_FAILED_INVALID_APK) { |
| Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2512 | // Delete the apk |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2513 | Slog.w(TAG, "Cleaning up failed install of " + file); |
| Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2514 | file.delete(); |
| 2515 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | } |
| 2517 | } |
| 2518 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2519 | private static File getSettingsProblemFile() { |
| 2520 | File dataDir = Environment.getDataDirectory(); |
| 2521 | File systemDir = new File(dataDir, "system"); |
| 2522 | File fname = new File(systemDir, "uiderrors.txt"); |
| 2523 | return fname; |
| 2524 | } |
| 2525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | private static void reportSettingsProblem(int priority, String msg) { |
| 2527 | try { |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2528 | File fname = getSettingsProblemFile(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2529 | FileOutputStream out = new FileOutputStream(fname, true); |
| 2530 | PrintWriter pw = new PrintWriter(out); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2531 | SimpleDateFormat formatter = new SimpleDateFormat(); |
| 2532 | String dateString = formatter.format(new Date(System.currentTimeMillis())); |
| 2533 | pw.println(dateString + ": " + msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2534 | pw.close(); |
| 2535 | FileUtils.setPermissions( |
| 2536 | fname.toString(), |
| 2537 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IROTH, |
| 2538 | -1, -1); |
| 2539 | } catch (java.io.IOException e) { |
| 2540 | } |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2541 | Slog.println(priority, TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | private boolean collectCertificatesLI(PackageParser pp, PackageSetting ps, |
| 2545 | PackageParser.Package pkg, File srcFile, int parseFlags) { |
| 2546 | if (GET_CERTIFICATES) { |
| Jeff Brown | e760072 | 2010-04-07 18:28:23 -0700 | [diff] [blame] | 2547 | if (ps != null |
| 2548 | && ps.codePath.equals(srcFile) |
| Kenny Root | 7d794fb | 2010-09-13 16:29:49 -0700 | [diff] [blame] | 2549 | && ps.timeStamp == srcFile.lastModified()) { |
| Jeff Brown | e760072 | 2010-04-07 18:28:23 -0700 | [diff] [blame] | 2550 | if (ps.signatures.mSignatures != null |
| 2551 | && ps.signatures.mSignatures.length != 0) { |
| 2552 | // Optimization: reuse the existing cached certificates |
| 2553 | // if the package appears to be unchanged. |
| 2554 | pkg.mSignatures = ps.signatures.mSignatures; |
| 2555 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2556 | } |
| Jeff Brown | e760072 | 2010-04-07 18:28:23 -0700 | [diff] [blame] | 2557 | |
| 2558 | Slog.w(TAG, "PackageSetting for " + ps.name + " is missing signatures. Collecting certs again to recover them."); |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 2559 | } else { |
| Jeff Brown | e760072 | 2010-04-07 18:28:23 -0700 | [diff] [blame] | 2560 | Log.i(TAG, srcFile.toString() + " changed; collecting certs"); |
| 2561 | } |
| 2562 | |
| 2563 | if (!pp.collectCertificates(pkg, parseFlags)) { |
| 2564 | mLastScanError = pp.getParseError(); |
| 2565 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2566 | } |
| 2567 | } |
| 2568 | return true; |
| 2569 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2570 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | /* |
| 2572 | * Scan a package and return the newly parsed package. |
| 2573 | * Returns null in case of errors and the error code is stored in mLastScanError |
| 2574 | */ |
| 2575 | private PackageParser.Package scanPackageLI(File scanFile, |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2576 | int parseFlags, int scanMode) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2577 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2578 | String scanPath = scanFile.getPath(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2579 | parseFlags |= mDefParseFlags; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2580 | PackageParser pp = new PackageParser(scanPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | pp.setSeparateProcesses(mSeparateProcesses); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2582 | final PackageParser.Package pkg = pp.parsePackage(scanFile, |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2583 | scanPath, mMetrics, parseFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2584 | if (pkg == null) { |
| 2585 | mLastScanError = pp.getParseError(); |
| 2586 | return null; |
| 2587 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2588 | PackageSetting ps = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2589 | PackageSetting updatedPkg; |
| 2590 | synchronized (mPackages) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2591 | // Look to see if we already know about this package. |
| 2592 | String oldName = mSettings.mRenamedPackages.get(pkg.packageName); |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2593 | if (pkg.mOriginalPackages != null && pkg.mOriginalPackages.contains(oldName)) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2594 | // This package has been renamed to its original name. Let's |
| 2595 | // use that. |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2596 | ps = mSettings.peekPackageLP(oldName); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2597 | } |
| 2598 | // If there was no original package, see one for the real package name. |
| 2599 | if (ps == null) { |
| 2600 | ps = mSettings.peekPackageLP(pkg.packageName); |
| 2601 | } |
| 2602 | // Check to see if this package could be hiding/updating a system |
| 2603 | // package. Must look for it either under the original or real |
| 2604 | // package name depending on our state. |
| 2605 | updatedPkg = mSettings.mDisabledSysPackages.get( |
| 2606 | ps != null ? ps.name : pkg.packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2607 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2608 | // First check if this is a system package that may involve an update |
| 2609 | if (updatedPkg != null && (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| Kenny Root | 9ee9274 | 2010-09-01 13:40:57 -0700 | [diff] [blame] | 2610 | if (ps != null && !ps.codePath.equals(scanFile)) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2611 | // The path has changed from what was last scanned... check the |
| 2612 | // version of the new path against what we have stored to determine |
| 2613 | // what to do. |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2614 | if (pkg.mVersionCode < ps.versionCode) { |
| 2615 | // The system package has been updated and the code path does not match |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2616 | // Ignore entry. Skip it. |
| 2617 | Log.i(TAG, "Package " + ps.name + " at " + scanFile |
| 2618 | + "ignored: updated version " + ps.versionCode |
| 2619 | + " better than this " + pkg.mVersionCode); |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2620 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2621 | return null; |
| 2622 | } else { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2623 | // The current app on the system partion is better than |
| 2624 | // what we have updated to on the data partition; switch |
| 2625 | // back to the system partition version. |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2626 | // At this point, its safely assumed that package installation for |
| 2627 | // apps in system partition will go through. If not there won't be a working |
| 2628 | // version of the app |
| 2629 | synchronized (mPackages) { |
| 2630 | // Just remove the loaded entries from package lists. |
| 2631 | mPackages.remove(ps.name); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 2632 | } |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2633 | Slog.w(TAG, "Package " + ps.name + " at " + scanFile |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2634 | + "reverting from " + ps.codePathString |
| 2635 | + ": new version " + pkg.mVersionCode |
| 2636 | + " better than installed " + ps.versionCode); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 2637 | InstallArgs args = new FileInstallArgs(ps.codePathString, |
| 2638 | ps.resourcePathString, ps.nativeLibraryPathString); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2639 | args.cleanUpResourcesLI(); |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2640 | mSettings.enableSystemPackageLP(ps.name); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 2641 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2642 | } |
| 2643 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2644 | if (updatedPkg != null) { |
| 2645 | // An updated system app will not have the PARSE_IS_SYSTEM flag set initially |
| 2646 | parseFlags |= PackageParser.PARSE_IS_SYSTEM; |
| 2647 | } |
| 2648 | // Verify certificates against what was last scanned |
| 2649 | if (!collectCertificatesLI(pp, ps, pkg, scanFile, parseFlags)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2650 | Slog.w(TAG, "Failed verifying certificates for package:" + pkg.packageName); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2651 | return null; |
| 2652 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2653 | // The apk is forward locked (not public) if its code and resources |
| 2654 | // are kept in different files. |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2655 | // TODO grab this value from PackageSettings |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2656 | if (ps != null && !ps.codePath.equals(ps.resourcePath)) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2657 | parseFlags |= PackageParser.PARSE_FORWARD_LOCK; |
| Suchi Amalapurapu | f2c1072 | 2009-07-29 17:19:39 -0700 | [diff] [blame] | 2658 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2659 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2660 | String codePath = null; |
| 2661 | String resPath = null; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2662 | if ((parseFlags & PackageParser.PARSE_FORWARD_LOCK) != 0) { |
| 2663 | if (ps != null && ps.resourcePathString != null) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2664 | resPath = ps.resourcePathString; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2665 | } else { |
| 2666 | // Should not happen at all. Just log an error. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2667 | Slog.e(TAG, "Resource path not set for pkg : " + pkg.packageName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2668 | } |
| 2669 | } else { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2670 | resPath = pkg.mScanPath; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2671 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2672 | codePath = pkg.mScanPath; |
| 2673 | // Set application objects path explicitly. |
| 2674 | setApplicationInfoPaths(pkg, codePath, resPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2675 | // Note that we invoke the following method only if we are about to unpack an application |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2676 | return scanPackageLI(pkg, parseFlags, scanMode | SCAN_UPDATE_SIGNATURE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2677 | } |
| 2678 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 2679 | private static void setApplicationInfoPaths(PackageParser.Package pkg, String destCodePath, |
| 2680 | String destResPath) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2681 | pkg.mPath = pkg.mScanPath = destCodePath; |
| 2682 | pkg.applicationInfo.sourceDir = destCodePath; |
| 2683 | pkg.applicationInfo.publicSourceDir = destResPath; |
| 2684 | } |
| 2685 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2686 | private static String fixProcessName(String defProcessName, |
| 2687 | String processName, int uid) { |
| 2688 | if (processName == null) { |
| 2689 | return defProcessName; |
| 2690 | } |
| 2691 | return processName; |
| 2692 | } |
| 2693 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2694 | private boolean verifySignaturesLP(PackageSetting pkgSetting, |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 2695 | PackageParser.Package pkg) { |
| 2696 | if (pkgSetting.signatures.mSignatures != null) { |
| 2697 | // Already existing package. Make sure signatures match |
| 2698 | if (checkSignaturesLP(pkgSetting.signatures.mSignatures, pkg.mSignatures) != |
| 2699 | PackageManager.SIGNATURE_MATCH) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2700 | Slog.e(TAG, "Package " + pkg.packageName |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 2701 | + " signatures do not match the previously installed version; ignoring!"); |
| 2702 | mLastScanError = PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2703 | return false; |
| 2704 | } |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 2705 | } |
| 2706 | // Check for shared user signatures |
| 2707 | if (pkgSetting.sharedUser != null && pkgSetting.sharedUser.signatures.mSignatures != null) { |
| 2708 | if (checkSignaturesLP(pkgSetting.sharedUser.signatures.mSignatures, |
| 2709 | pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) { |
| 2710 | Slog.e(TAG, "Package " + pkg.packageName |
| 2711 | + " has no signatures that match those in shared user " |
| 2712 | + pkgSetting.sharedUser.name + "; ignoring!"); |
| 2713 | mLastScanError = PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE; |
| 2714 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2715 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2716 | } |
| 2717 | return true; |
| 2718 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2719 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2720 | public boolean performDexOpt(String packageName) { |
| 2721 | if (!mNoDexOpt) { |
| 2722 | return false; |
| 2723 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2724 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2725 | PackageParser.Package p; |
| 2726 | synchronized (mPackages) { |
| 2727 | p = mPackages.get(packageName); |
| 2728 | if (p == null || p.mDidDexOpt) { |
| 2729 | return false; |
| 2730 | } |
| 2731 | } |
| 2732 | synchronized (mInstallLock) { |
| 2733 | return performDexOptLI(p, false) == DEX_OPT_PERFORMED; |
| 2734 | } |
| 2735 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2736 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2737 | static final int DEX_OPT_SKIPPED = 0; |
| 2738 | static final int DEX_OPT_PERFORMED = 1; |
| 2739 | static final int DEX_OPT_FAILED = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2740 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2741 | private int performDexOptLI(PackageParser.Package pkg, boolean forceDex) { |
| 2742 | boolean performed = false; |
| Marco Nelissen | d595c79 | 2009-07-02 15:23:26 -0700 | [diff] [blame] | 2743 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0 && mInstaller != null) { |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2744 | String path = pkg.mScanPath; |
| 2745 | int ret = 0; |
| 2746 | try { |
| 2747 | if (forceDex || dalvik.system.DexFile.isDexOptNeeded(path)) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2748 | ret = mInstaller.dexopt(path, pkg.applicationInfo.uid, |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2749 | !isForwardLocked(pkg)); |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2750 | pkg.mDidDexOpt = true; |
| 2751 | performed = true; |
| 2752 | } |
| 2753 | } catch (FileNotFoundException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2754 | Slog.w(TAG, "Apk not found for dexopt: " + path); |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2755 | ret = -1; |
| 2756 | } catch (IOException e) { |
| Suchi Amalapurapu | 73dafa1 | 2010-04-01 16:31:31 -0700 | [diff] [blame] | 2757 | Slog.w(TAG, "IOException reading apk: " + path, e); |
| 2758 | ret = -1; |
| 2759 | } catch (dalvik.system.StaleDexCacheError e) { |
| 2760 | Slog.w(TAG, "StaleDexCacheError when reading apk: " + path, e); |
| 2761 | ret = -1; |
| 2762 | } catch (Exception e) { |
| 2763 | Slog.w(TAG, "Exception when doing dexopt : ", e); |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2764 | ret = -1; |
| 2765 | } |
| 2766 | if (ret < 0) { |
| 2767 | //error from installer |
| 2768 | return DEX_OPT_FAILED; |
| 2769 | } |
| 2770 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2771 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2772 | return performed ? DEX_OPT_PERFORMED : DEX_OPT_SKIPPED; |
| 2773 | } |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 2774 | |
| 2775 | private static boolean useEncryptedFilesystemForPackage(PackageParser.Package pkg) { |
| 2776 | return Environment.isEncryptedFilesystemEnabled() && |
| 2777 | ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_NEVER_ENCRYPT) == 0); |
| 2778 | } |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2779 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2780 | private boolean verifyPackageUpdate(PackageSetting oldPkg, PackageParser.Package newPkg) { |
| 2781 | if ((oldPkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2782 | Slog.w(TAG, "Unable to update from " + oldPkg.name |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2783 | + " to " + newPkg.packageName |
| 2784 | + ": old package not in system partition"); |
| 2785 | return false; |
| 2786 | } else if (mPackages.get(oldPkg.name) != null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2787 | Slog.w(TAG, "Unable to update from " + oldPkg.name |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2788 | + " to " + newPkg.packageName |
| 2789 | + ": old package still exists"); |
| 2790 | return false; |
| 2791 | } |
| 2792 | return true; |
| 2793 | } |
| Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 2794 | |
| 2795 | private File getDataPathForPackage(PackageParser.Package pkg) { |
| 2796 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(pkg); |
| 2797 | File dataPath; |
| 2798 | if (useEncryptedFSDir) { |
| 2799 | dataPath = new File(mSecureAppDataDir, pkg.packageName); |
| 2800 | } else { |
| 2801 | dataPath = new File(mAppDataDir, pkg.packageName); |
| 2802 | } |
| 2803 | return dataPath; |
| 2804 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2805 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2806 | private PackageParser.Package scanPackageLI(PackageParser.Package pkg, |
| 2807 | int parseFlags, int scanMode) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2808 | File scanFile = new File(pkg.mScanPath); |
| Suchi Amalapurapu | 7040ce7 | 2010-02-08 23:55:56 -0800 | [diff] [blame] | 2809 | if (scanFile == null || pkg.applicationInfo.sourceDir == null || |
| 2810 | pkg.applicationInfo.publicSourceDir == null) { |
| Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2811 | // Bail out. The resource and code paths haven't been set. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2812 | Slog.w(TAG, " Code and resource paths haven't been set correctly"); |
| Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2813 | mLastScanError = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 2814 | return null; |
| 2815 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2816 | mScanningPath = scanFile; |
| 2817 | if (pkg == null) { |
| 2818 | mLastScanError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 2819 | return null; |
| 2820 | } |
| 2821 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2822 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| 2823 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM; |
| 2824 | } |
| 2825 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2826 | if (pkg.packageName.equals("android")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2827 | synchronized (mPackages) { |
| 2828 | if (mAndroidApplication != null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2829 | Slog.w(TAG, "*************************************************"); |
| 2830 | Slog.w(TAG, "Core android package being redefined. Skipping."); |
| 2831 | Slog.w(TAG, " file=" + mScanningPath); |
| 2832 | Slog.w(TAG, "*************************************************"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2834 | return null; |
| 2835 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2836 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2837 | // Set up information for our fall-back user intent resolution |
| 2838 | // activity. |
| 2839 | mPlatformPackage = pkg; |
| 2840 | pkg.mVersionCode = mSdkVersion; |
| 2841 | mAndroidApplication = pkg.applicationInfo; |
| 2842 | mResolveActivity.applicationInfo = mAndroidApplication; |
| 2843 | mResolveActivity.name = ResolverActivity.class.getName(); |
| 2844 | mResolveActivity.packageName = mAndroidApplication.packageName; |
| 2845 | mResolveActivity.processName = mAndroidApplication.processName; |
| 2846 | mResolveActivity.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 2847 | mResolveActivity.flags = ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 2848 | mResolveActivity.theme = com.android.internal.R.style.Theme_Dialog_Alert; |
| 2849 | mResolveActivity.exported = true; |
| 2850 | mResolveActivity.enabled = true; |
| 2851 | mResolveInfo.activityInfo = mResolveActivity; |
| 2852 | mResolveInfo.priority = 0; |
| 2853 | mResolveInfo.preferredOrder = 0; |
| 2854 | mResolveInfo.match = 0; |
| 2855 | mResolveComponentName = new ComponentName( |
| 2856 | mAndroidApplication.packageName, mResolveActivity.name); |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) Log.d( |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2861 | TAG, "Scanning package " + pkg.packageName); |
| 2862 | if (mPackages.containsKey(pkg.packageName) |
| 2863 | || mSharedLibraries.containsKey(pkg.packageName)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2864 | Slog.w(TAG, "*************************************************"); |
| 2865 | Slog.w(TAG, "Application package " + pkg.packageName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2866 | + " already installed. Skipping duplicate."); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2867 | Slog.w(TAG, "*************************************************"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2868 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2869 | return null; |
| 2870 | } |
| 2871 | |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2872 | // Initialize package source and resource directories |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2873 | File destCodeFile = new File(pkg.applicationInfo.sourceDir); |
| 2874 | File destResourceFile = new File(pkg.applicationInfo.publicSourceDir); |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2875 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | SharedUserSetting suid = null; |
| 2877 | PackageSetting pkgSetting = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2878 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2879 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 2880 | // Only system apps can use these features. |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2881 | pkg.mOriginalPackages = null; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2882 | pkg.mRealPackage = null; |
| 2883 | pkg.mAdoptPermissions = null; |
| 2884 | } |
| 2885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2886 | synchronized (mPackages) { |
| 2887 | // Check all shared libraries and map to their actual file path. |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2888 | if (pkg.usesLibraries != null || pkg.usesOptionalLibraries != null) { |
| 2889 | if (mTmpSharedLibraries == null || |
| 2890 | mTmpSharedLibraries.length < mSharedLibraries.size()) { |
| 2891 | mTmpSharedLibraries = new String[mSharedLibraries.size()]; |
| 2892 | } |
| 2893 | int num = 0; |
| 2894 | int N = pkg.usesLibraries != null ? pkg.usesLibraries.size() : 0; |
| 2895 | for (int i=0; i<N; i++) { |
| 2896 | String file = mSharedLibraries.get(pkg.usesLibraries.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2897 | if (file == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2898 | Slog.e(TAG, "Package " + pkg.packageName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2899 | + " requires unavailable shared library " |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2900 | + pkg.usesLibraries.get(i) + "; failing!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | mLastScanError = PackageManager.INSTALL_FAILED_MISSING_SHARED_LIBRARY; |
| 2902 | return null; |
| 2903 | } |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2904 | mTmpSharedLibraries[num] = file; |
| 2905 | num++; |
| 2906 | } |
| 2907 | N = pkg.usesOptionalLibraries != null ? pkg.usesOptionalLibraries.size() : 0; |
| 2908 | for (int i=0; i<N; i++) { |
| 2909 | String file = mSharedLibraries.get(pkg.usesOptionalLibraries.get(i)); |
| 2910 | if (file == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2911 | Slog.w(TAG, "Package " + pkg.packageName |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2912 | + " desires unavailable shared library " |
| 2913 | + pkg.usesOptionalLibraries.get(i) + "; ignoring!"); |
| 2914 | } else { |
| 2915 | mTmpSharedLibraries[num] = file; |
| 2916 | num++; |
| 2917 | } |
| 2918 | } |
| 2919 | if (num > 0) { |
| 2920 | pkg.usesLibraryFiles = new String[num]; |
| 2921 | System.arraycopy(mTmpSharedLibraries, 0, |
| 2922 | pkg.usesLibraryFiles, 0, num); |
| 2923 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2924 | |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2925 | if (pkg.reqFeatures != null) { |
| 2926 | N = pkg.reqFeatures.size(); |
| 2927 | for (int i=0; i<N; i++) { |
| 2928 | FeatureInfo fi = pkg.reqFeatures.get(i); |
| 2929 | if ((fi.flags&FeatureInfo.FLAG_REQUIRED) == 0) { |
| 2930 | // Don't care. |
| 2931 | continue; |
| 2932 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2933 | |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2934 | if (fi.name != null) { |
| 2935 | if (mAvailableFeatures.get(fi.name) == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2936 | Slog.e(TAG, "Package " + pkg.packageName |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2937 | + " requires unavailable feature " |
| 2938 | + fi.name + "; failing!"); |
| 2939 | mLastScanError = PackageManager.INSTALL_FAILED_MISSING_FEATURE; |
| 2940 | return null; |
| 2941 | } |
| 2942 | } |
| 2943 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2944 | } |
| 2945 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2947 | if (pkg.mSharedUserId != null) { |
| 2948 | suid = mSettings.getSharedUserLP(pkg.mSharedUserId, |
| 2949 | pkg.applicationInfo.flags, true); |
| 2950 | if (suid == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2951 | Slog.w(TAG, "Creating application package " + pkg.packageName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2952 | + " for shared user failed"); |
| 2953 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 2954 | return null; |
| 2955 | } |
| 2956 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) { |
| 2957 | Log.d(TAG, "Shared UserID " + pkg.mSharedUserId + " (uid=" |
| 2958 | + suid.userId + "): packages=" + suid.packages); |
| 2959 | } |
| 2960 | } |
| Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 2961 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2962 | if (false) { |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2963 | if (pkg.mOriginalPackages != null) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2964 | Log.w(TAG, "WAITING FOR DEBUGGER"); |
| 2965 | Debug.waitForDebugger(); |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2966 | Log.i(TAG, "Package " + pkg.packageName + " from original packages" |
| 2967 | + pkg.mOriginalPackages); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2968 | } |
| 2969 | } |
| 2970 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2971 | // Check if we are renaming from an original package name. |
| 2972 | PackageSetting origPackage = null; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2973 | String realName = null; |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2974 | if (pkg.mOriginalPackages != null) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2975 | // This package may need to be renamed to a previously |
| 2976 | // installed name. Let's check on that... |
| 2977 | String renamed = mSettings.mRenamedPackages.get(pkg.mRealPackage); |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2978 | if (pkg.mOriginalPackages.contains(renamed)) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2979 | // This package had originally been installed as the |
| 2980 | // original name, and we have already taken care of |
| 2981 | // transitioning to the new one. Just update the new |
| 2982 | // one to continue using the old name. |
| 2983 | realName = pkg.mRealPackage; |
| 2984 | if (!pkg.packageName.equals(renamed)) { |
| 2985 | // Callers into this function may have already taken |
| 2986 | // care of renaming the package; only do it here if |
| 2987 | // it is not already done. |
| 2988 | pkg.setPackageName(renamed); |
| 2989 | } |
| 2990 | |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2991 | } else { |
| 2992 | for (int i=pkg.mOriginalPackages.size()-1; i>=0; i--) { |
| 2993 | if ((origPackage=mSettings.peekPackageLP( |
| 2994 | pkg.mOriginalPackages.get(i))) != null) { |
| 2995 | // We do have the package already installed under its |
| 2996 | // original name... should we use it? |
| 2997 | if (!verifyPackageUpdate(origPackage, pkg)) { |
| 2998 | // New package is not compatible with original. |
| 2999 | origPackage = null; |
| 3000 | continue; |
| 3001 | } else if (origPackage.sharedUser != null) { |
| 3002 | // Make sure uid is compatible between packages. |
| 3003 | if (!origPackage.sharedUser.name.equals(pkg.mSharedUserId)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3004 | Slog.w(TAG, "Unable to migrate data from " + origPackage.name |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 3005 | + " to " + pkg.packageName + ": old uid " |
| 3006 | + origPackage.sharedUser.name |
| 3007 | + " differs from " + pkg.mSharedUserId); |
| 3008 | origPackage = null; |
| 3009 | continue; |
| 3010 | } |
| 3011 | } else { |
| 3012 | if (DEBUG_UPGRADE) Log.v(TAG, "Renaming new package " |
| 3013 | + pkg.packageName + " to old name " + origPackage.name); |
| 3014 | } |
| 3015 | break; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3016 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3017 | } |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | if (mTransferedPackages.contains(pkg.packageName)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3022 | Slog.w(TAG, "Package " + pkg.packageName |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3023 | + " was transferred to another, but its .apk remains"); |
| 3024 | } |
| 3025 | |
| Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 3026 | // Just create the setting, don't add it yet. For already existing packages |
| 3027 | // the PkgSetting exists already and doesn't have to be created. |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3028 | pkgSetting = mSettings.getPackageLP(pkg, origPackage, realName, suid, destCodeFile, |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 3029 | destResourceFile, pkg.applicationInfo.nativeLibraryDir, |
| 3030 | pkg.applicationInfo.flags, true, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3031 | if (pkgSetting == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3032 | Slog.w(TAG, "Creating application package " + pkg.packageName + " failed"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3033 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3034 | return null; |
| 3035 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3036 | |
| 3037 | if (pkgSetting.origPackage != null) { |
| 3038 | // If we are first transitioning from an original package, |
| 3039 | // fix up the new package's name now. We need to do this after |
| 3040 | // looking up the package under its new name, so getPackageLP |
| 3041 | // can take care of fiddling things correctly. |
| 3042 | pkg.setPackageName(origPackage.name); |
| 3043 | |
| 3044 | // File a report about this. |
| 3045 | String msg = "New package " + pkgSetting.realName |
| 3046 | + " renamed to replace old package " + pkgSetting.name; |
| 3047 | reportSettingsProblem(Log.WARN, msg); |
| 3048 | |
| 3049 | // Make a note of it. |
| 3050 | mTransferedPackages.add(origPackage.name); |
| 3051 | |
| 3052 | // No longer need to retain this. |
| 3053 | pkgSetting.origPackage = null; |
| 3054 | } |
| 3055 | |
| 3056 | if (realName != null) { |
| 3057 | // Make a note of it. |
| 3058 | mTransferedPackages.add(pkg.packageName); |
| 3059 | } |
| 3060 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3061 | if (mSettings.mDisabledSysPackages.get(pkg.packageName) != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3062 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 3063 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3064 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | pkg.applicationInfo.uid = pkgSetting.userId; |
| 3066 | pkg.mExtras = pkgSetting; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3067 | |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 3068 | if (!verifySignaturesLP(pkgSetting, pkg)) { |
| Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 3069 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM_DIR) == 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3070 | return null; |
| 3071 | } |
| 3072 | // The signature has changed, but this package is in the system |
| 3073 | // image... let's recover! |
| Suchi Amalapurapu | c4dd60f | 2009-03-24 21:10:53 -0700 | [diff] [blame] | 3074 | pkgSetting.signatures.mSignatures = pkg.mSignatures; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | // However... if this package is part of a shared user, but it |
| 3076 | // doesn't match the signature of the shared user, let's fail. |
| 3077 | // What this means is that you can't change the signatures |
| 3078 | // associated with an overall shared user, which doesn't seem all |
| 3079 | // that unreasonable. |
| 3080 | if (pkgSetting.sharedUser != null) { |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 3081 | if (checkSignaturesLP(pkgSetting.sharedUser.signatures.mSignatures, |
| 3082 | pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) { |
| 3083 | Log.w(TAG, "Signature mismatch for shared user : " + pkgSetting.sharedUser); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3084 | mLastScanError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 3085 | return null; |
| 3086 | } |
| 3087 | } |
| Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 3088 | // File a report about this. |
| 3089 | String msg = "System package " + pkg.packageName |
| 3090 | + " signature changed; retaining data."; |
| 3091 | reportSettingsProblem(Log.WARN, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3092 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3093 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3094 | // Verify that this new package doesn't have any content providers |
| 3095 | // that conflict with existing packages. Only do this if the |
| 3096 | // package isn't already installed, since we don't want to break |
| 3097 | // things that are installed. |
| 3098 | if ((scanMode&SCAN_NEW_INSTALL) != 0) { |
| 3099 | int N = pkg.providers.size(); |
| 3100 | int i; |
| 3101 | for (i=0; i<N; i++) { |
| 3102 | PackageParser.Provider p = pkg.providers.get(i); |
| Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3103 | if (p.info.authority != null) { |
| 3104 | String names[] = p.info.authority.split(";"); |
| 3105 | for (int j = 0; j < names.length; j++) { |
| 3106 | if (mProviders.containsKey(names[j])) { |
| 3107 | PackageParser.Provider other = mProviders.get(names[j]); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3108 | Slog.w(TAG, "Can't install because provider name " + names[j] + |
| Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3109 | " (in package " + pkg.applicationInfo.packageName + |
| 3110 | ") is already used by " |
| 3111 | + ((other != null && other.getComponentName() != null) |
| 3112 | ? other.getComponentName().getPackageName() : "?")); |
| 3113 | mLastScanError = PackageManager.INSTALL_FAILED_CONFLICTING_PROVIDER; |
| 3114 | return null; |
| 3115 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3116 | } |
| 3117 | } |
| 3118 | } |
| 3119 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3120 | } |
| 3121 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3122 | final String pkgName = pkg.packageName; |
| 3123 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3124 | if (pkg.mAdoptPermissions != null) { |
| 3125 | // This package wants to adopt ownership of permissions from |
| 3126 | // another package. |
| 3127 | for (int i=pkg.mAdoptPermissions.size()-1; i>=0; i--) { |
| 3128 | String origName = pkg.mAdoptPermissions.get(i); |
| 3129 | PackageSetting orig = mSettings.peekPackageLP(origName); |
| 3130 | if (orig != null) { |
| 3131 | if (verifyPackageUpdate(orig, pkg)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3132 | Slog.i(TAG, "Adopting permissions from " |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3133 | + origName + " to " + pkg.packageName); |
| 3134 | mSettings.transferPermissions(origName, pkg.packageName); |
| 3135 | } |
| 3136 | } |
| 3137 | } |
| 3138 | } |
| 3139 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3140 | long scanFileTime = scanFile.lastModified(); |
| 3141 | final boolean forceDex = (scanMode&SCAN_FORCE_DEX) != 0; |
| Kenny Root | 7d794fb | 2010-09-13 16:29:49 -0700 | [diff] [blame] | 3142 | final boolean scanFileNewer = forceDex || scanFileTime != pkgSetting.timeStamp; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | pkg.applicationInfo.processName = fixProcessName( |
| 3144 | pkg.applicationInfo.packageName, |
| 3145 | pkg.applicationInfo.processName, |
| 3146 | pkg.applicationInfo.uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | |
| 3148 | File dataPath; |
| 3149 | if (mPlatformPackage == pkg) { |
| 3150 | // The system package is special. |
| 3151 | dataPath = new File (Environment.getDataDirectory(), "system"); |
| 3152 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3153 | } else { |
| 3154 | // This is a normal package, need to make its data directory. |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3155 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(pkg); |
| Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 3156 | dataPath = getDataPathForPackage(pkg); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3157 | |
| 3158 | boolean uidError = false; |
| 3159 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | if (dataPath.exists()) { |
| 3161 | mOutPermissions[1] = 0; |
| 3162 | FileUtils.getPermissions(dataPath.getPath(), mOutPermissions); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3163 | |
| 3164 | // If we have mismatched owners for the data path, we have a |
| 3165 | // problem (unless we're running in the simulator.) |
| 3166 | if (mOutPermissions[1] != pkg.applicationInfo.uid && Process.supportsProcesses()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | boolean recovered = false; |
| 3168 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| 3169 | // If this is a system app, we can at least delete its |
| 3170 | // current data so the application will still work. |
| 3171 | if (mInstaller != null) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3172 | int ret = mInstaller.remove(pkgName, useEncryptedFSDir); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3173 | if (ret >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | // Old data gone! |
| 3175 | String msg = "System package " + pkg.packageName |
| 3176 | + " has changed from uid: " |
| 3177 | + mOutPermissions[1] + " to " |
| 3178 | + pkg.applicationInfo.uid + "; old data erased"; |
| 3179 | reportSettingsProblem(Log.WARN, msg); |
| 3180 | recovered = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3181 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3182 | // And now re-install the app. |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3183 | ret = mInstaller.install(pkgName, useEncryptedFSDir, pkg.applicationInfo.uid, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3184 | pkg.applicationInfo.uid); |
| 3185 | if (ret == -1) { |
| 3186 | // Ack should not happen! |
| 3187 | msg = "System package " + pkg.packageName |
| 3188 | + " could not have data directory re-created after delete."; |
| 3189 | reportSettingsProblem(Log.WARN, msg); |
| 3190 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3191 | return null; |
| 3192 | } |
| 3193 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3194 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3195 | if (!recovered) { |
| 3196 | mHasSystemUidErrors = true; |
| 3197 | } |
| 3198 | } |
| 3199 | if (!recovered) { |
| 3200 | pkg.applicationInfo.dataDir = "/mismatched_uid/settings_" |
| 3201 | + pkg.applicationInfo.uid + "/fs_" |
| 3202 | + mOutPermissions[1]; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3203 | pkg.applicationInfo.nativeLibraryDir = pkg.applicationInfo.dataDir; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3204 | String msg = "Package " + pkg.packageName |
| 3205 | + " has mismatched uid: " |
| 3206 | + mOutPermissions[1] + " on disk, " |
| 3207 | + pkg.applicationInfo.uid + " in settings"; |
| 3208 | synchronized (mPackages) { |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3209 | mSettings.mReadMessages.append(msg); |
| 3210 | mSettings.mReadMessages.append('\n'); |
| 3211 | uidError = true; |
| 3212 | if (!pkgSetting.uidError) { |
| 3213 | reportSettingsProblem(Log.ERROR, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3214 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3215 | } |
| 3216 | } |
| 3217 | } |
| 3218 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3219 | } else { |
| 3220 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGV) |
| 3221 | Log.v(TAG, "Want this data dir: " + dataPath); |
| 3222 | //invoke installer to do the actual installation |
| 3223 | if (mInstaller != null) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3224 | int ret = mInstaller.install(pkgName, useEncryptedFSDir, pkg.applicationInfo.uid, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3225 | pkg.applicationInfo.uid); |
| 3226 | if(ret < 0) { |
| 3227 | // Error from installer |
| 3228 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3229 | return null; |
| 3230 | } |
| 3231 | } else { |
| 3232 | dataPath.mkdirs(); |
| 3233 | if (dataPath.exists()) { |
| 3234 | FileUtils.setPermissions( |
| 3235 | dataPath.toString(), |
| 3236 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 3237 | pkg.applicationInfo.uid, pkg.applicationInfo.uid); |
| 3238 | } |
| 3239 | } |
| 3240 | if (dataPath.exists()) { |
| 3241 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3242 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3243 | Slog.w(TAG, "Unable to create data directory: " + dataPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3244 | pkg.applicationInfo.dataDir = null; |
| 3245 | } |
| 3246 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3247 | |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 3248 | pkg.applicationInfo.nativeLibraryDir = pkgSetting.nativeLibraryPathString; |
| 3249 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3250 | /* |
| 3251 | * Set the data dir to the default "/data/data/<package name>/lib" |
| 3252 | * if we got here without anyone telling us different (e.g., apps |
| 3253 | * stored on SD card have their native libraries stored in the ASEC |
| 3254 | * container with the APK). |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 3255 | * |
| 3256 | * This happens during an upgrade from a package settings file that |
| 3257 | * doesn't have a native library path attribute at all. |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3258 | */ |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 3259 | if (pkgSetting.nativeLibraryPathString == null && pkg.applicationInfo.dataDir != null) { |
| 3260 | final String nativeLibraryPath = new File(dataPath, LIB_DIR_NAME).getPath(); |
| 3261 | pkg.applicationInfo.nativeLibraryDir = nativeLibraryPath; |
| 3262 | pkgSetting.nativeLibraryPathString = nativeLibraryPath; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3265 | pkgSetting.uidError = uidError; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3266 | } |
| 3267 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3268 | // If we're running in the simulator, we don't need to unpack anything. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3269 | if (mInstaller != null) { |
| 3270 | String path = scanFile.getPath(); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3271 | /* Note: We don't want to unpack the native binaries for |
| 3272 | * system applications, unless they have been updated |
| 3273 | * (the binaries are already under /system/lib). |
| 3274 | * Also, don't unpack libs for apps on the external card |
| 3275 | * since they should have their libraries in the ASEC |
| 3276 | * container already. |
| 3277 | * |
| 3278 | * In other words, we're going to unpack the binaries |
| 3279 | * only for non-system apps and system app upgrades. |
| 3280 | */ |
| 3281 | if ((!isSystemApp(pkg) || isUpdatedSystemApp(pkg)) && !isExternal(pkg)) { |
| 3282 | Log.i(TAG, path + " changed; unpacking"); |
| 3283 | File sharedLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3284 | NativeLibraryHelper.copyNativeBinariesLI(scanFile, sharedLibraryDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3285 | } |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 3286 | pkg.mScanPath = path; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3287 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 3288 | if ((scanMode&SCAN_NO_DEX) == 0) { |
| 3289 | if (performDexOptLI(pkg, forceDex) == DEX_OPT_FAILED) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3290 | mLastScanError = PackageManager.INSTALL_FAILED_DEXOPT; |
| 3291 | return null; |
| 3292 | } |
| 3293 | } |
| 3294 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3295 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | if (mFactoryTest && pkg.requestedPermissions.contains( |
| 3297 | android.Manifest.permission.FACTORY_TEST)) { |
| 3298 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FACTORY_TEST; |
| 3299 | } |
| 3300 | |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3301 | // Request the ActivityManager to kill the process(only for existing packages) |
| 3302 | // so that we do not end up in a confused state while the user is still using the older |
| 3303 | // version of the application while the new one gets installed. |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3304 | if ((parseFlags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3305 | killApplication(pkg.applicationInfo.packageName, |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3306 | pkg.applicationInfo.uid); |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3307 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3308 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3309 | synchronized (mPackages) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 3310 | // We don't expect installation to fail beyond this point, |
| 3311 | if ((scanMode&SCAN_MONITOR) != 0) { |
| 3312 | mAppDirs.put(pkg.mPath, pkg); |
| 3313 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3314 | // Add the new setting to mSettings |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 3315 | mSettings.insertPackageSettingLP(pkgSetting, pkg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3316 | // Add the new setting to mPackages |
| Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 3317 | mPackages.put(pkg.applicationInfo.packageName, pkg); |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 3318 | // Make sure we don't accidentally delete its data. |
| 3319 | mSettings.mPackagesToBeCleaned.remove(pkgName); |
| 3320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3321 | int N = pkg.providers.size(); |
| 3322 | StringBuilder r = null; |
| 3323 | int i; |
| 3324 | for (i=0; i<N; i++) { |
| 3325 | PackageParser.Provider p = pkg.providers.get(i); |
| 3326 | p.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3327 | p.info.processName, pkg.applicationInfo.uid); |
| 3328 | mProvidersByComponent.put(new ComponentName(p.info.packageName, |
| 3329 | p.info.name), p); |
| 3330 | p.syncable = p.info.isSyncable; |
| Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3331 | if (p.info.authority != null) { |
| 3332 | String names[] = p.info.authority.split(";"); |
| 3333 | p.info.authority = null; |
| 3334 | for (int j = 0; j < names.length; j++) { |
| 3335 | if (j == 1 && p.syncable) { |
| 3336 | // We only want the first authority for a provider to possibly be |
| 3337 | // syncable, so if we already added this provider using a different |
| 3338 | // authority clear the syncable flag. We copy the provider before |
| 3339 | // changing it because the mProviders object contains a reference |
| 3340 | // to a provider that we don't want to change. |
| 3341 | // Only do this for the second authority since the resulting provider |
| 3342 | // object can be the same for all future authorities for this provider. |
| 3343 | p = new PackageParser.Provider(p); |
| 3344 | p.syncable = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3345 | } |
| Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3346 | if (!mProviders.containsKey(names[j])) { |
| 3347 | mProviders.put(names[j], p); |
| 3348 | if (p.info.authority == null) { |
| 3349 | p.info.authority = names[j]; |
| 3350 | } else { |
| 3351 | p.info.authority = p.info.authority + ";" + names[j]; |
| 3352 | } |
| 3353 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) |
| 3354 | Log.d(TAG, "Registered content provider: " + names[j] + |
| 3355 | ", className = " + p.info.name + |
| 3356 | ", isSyncable = " + p.info.isSyncable); |
| 3357 | } else { |
| 3358 | PackageParser.Provider other = mProviders.get(names[j]); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3359 | Slog.w(TAG, "Skipping provider name " + names[j] + |
| Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3360 | " (in package " + pkg.applicationInfo.packageName + |
| 3361 | "): name already used by " |
| 3362 | + ((other != null && other.getComponentName() != null) |
| 3363 | ? other.getComponentName().getPackageName() : "?")); |
| 3364 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | } |
| 3366 | } |
| 3367 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3368 | if (r == null) { |
| 3369 | r = new StringBuilder(256); |
| 3370 | } else { |
| 3371 | r.append(' '); |
| 3372 | } |
| 3373 | r.append(p.info.name); |
| 3374 | } |
| 3375 | } |
| 3376 | if (r != null) { |
| 3377 | if (Config.LOGD) Log.d(TAG, " Providers: " + r); |
| 3378 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3379 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3380 | N = pkg.services.size(); |
| 3381 | r = null; |
| 3382 | for (i=0; i<N; i++) { |
| 3383 | PackageParser.Service s = pkg.services.get(i); |
| 3384 | s.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3385 | s.info.processName, pkg.applicationInfo.uid); |
| 3386 | mServices.addService(s); |
| 3387 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3388 | if (r == null) { |
| 3389 | r = new StringBuilder(256); |
| 3390 | } else { |
| 3391 | r.append(' '); |
| 3392 | } |
| 3393 | r.append(s.info.name); |
| 3394 | } |
| 3395 | } |
| 3396 | if (r != null) { |
| 3397 | if (Config.LOGD) Log.d(TAG, " Services: " + r); |
| 3398 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3399 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3400 | N = pkg.receivers.size(); |
| 3401 | r = null; |
| 3402 | for (i=0; i<N; i++) { |
| 3403 | PackageParser.Activity a = pkg.receivers.get(i); |
| 3404 | a.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3405 | a.info.processName, pkg.applicationInfo.uid); |
| 3406 | mReceivers.addActivity(a, "receiver"); |
| 3407 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3408 | if (r == null) { |
| 3409 | r = new StringBuilder(256); |
| 3410 | } else { |
| 3411 | r.append(' '); |
| 3412 | } |
| 3413 | r.append(a.info.name); |
| 3414 | } |
| 3415 | } |
| 3416 | if (r != null) { |
| 3417 | if (Config.LOGD) Log.d(TAG, " Receivers: " + r); |
| 3418 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3419 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3420 | N = pkg.activities.size(); |
| 3421 | r = null; |
| 3422 | for (i=0; i<N; i++) { |
| 3423 | PackageParser.Activity a = pkg.activities.get(i); |
| 3424 | a.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3425 | a.info.processName, pkg.applicationInfo.uid); |
| 3426 | mActivities.addActivity(a, "activity"); |
| 3427 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3428 | if (r == null) { |
| 3429 | r = new StringBuilder(256); |
| 3430 | } else { |
| 3431 | r.append(' '); |
| 3432 | } |
| 3433 | r.append(a.info.name); |
| 3434 | } |
| 3435 | } |
| 3436 | if (r != null) { |
| 3437 | if (Config.LOGD) Log.d(TAG, " Activities: " + r); |
| 3438 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3439 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3440 | N = pkg.permissionGroups.size(); |
| 3441 | r = null; |
| 3442 | for (i=0; i<N; i++) { |
| 3443 | PackageParser.PermissionGroup pg = pkg.permissionGroups.get(i); |
| 3444 | PackageParser.PermissionGroup cur = mPermissionGroups.get(pg.info.name); |
| 3445 | if (cur == null) { |
| 3446 | mPermissionGroups.put(pg.info.name, pg); |
| 3447 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3448 | if (r == null) { |
| 3449 | r = new StringBuilder(256); |
| 3450 | } else { |
| 3451 | r.append(' '); |
| 3452 | } |
| 3453 | r.append(pg.info.name); |
| 3454 | } |
| 3455 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3456 | Slog.w(TAG, "Permission group " + pg.info.name + " from package " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3457 | + pg.info.packageName + " ignored: original from " |
| 3458 | + cur.info.packageName); |
| 3459 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3460 | if (r == null) { |
| 3461 | r = new StringBuilder(256); |
| 3462 | } else { |
| 3463 | r.append(' '); |
| 3464 | } |
| 3465 | r.append("DUP:"); |
| 3466 | r.append(pg.info.name); |
| 3467 | } |
| 3468 | } |
| 3469 | } |
| 3470 | if (r != null) { |
| 3471 | if (Config.LOGD) Log.d(TAG, " Permission Groups: " + r); |
| 3472 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3473 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3474 | N = pkg.permissions.size(); |
| 3475 | r = null; |
| 3476 | for (i=0; i<N; i++) { |
| 3477 | PackageParser.Permission p = pkg.permissions.get(i); |
| 3478 | HashMap<String, BasePermission> permissionMap = |
| 3479 | p.tree ? mSettings.mPermissionTrees |
| 3480 | : mSettings.mPermissions; |
| 3481 | p.group = mPermissionGroups.get(p.info.group); |
| 3482 | if (p.info.group == null || p.group != null) { |
| 3483 | BasePermission bp = permissionMap.get(p.info.name); |
| 3484 | if (bp == null) { |
| 3485 | bp = new BasePermission(p.info.name, p.info.packageName, |
| 3486 | BasePermission.TYPE_NORMAL); |
| 3487 | permissionMap.put(p.info.name, bp); |
| 3488 | } |
| 3489 | if (bp.perm == null) { |
| 3490 | if (bp.sourcePackage == null |
| 3491 | || bp.sourcePackage.equals(p.info.packageName)) { |
| 3492 | BasePermission tree = findPermissionTreeLP(p.info.name); |
| 3493 | if (tree == null |
| 3494 | || tree.sourcePackage.equals(p.info.packageName)) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3495 | bp.packageSetting = pkgSetting; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | bp.perm = p; |
| 3497 | bp.uid = pkg.applicationInfo.uid; |
| 3498 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3499 | if (r == null) { |
| 3500 | r = new StringBuilder(256); |
| 3501 | } else { |
| 3502 | r.append(' '); |
| 3503 | } |
| 3504 | r.append(p.info.name); |
| 3505 | } |
| 3506 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3507 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3508 | + p.info.packageName + " ignored: base tree " |
| 3509 | + tree.name + " is from package " |
| 3510 | + tree.sourcePackage); |
| 3511 | } |
| 3512 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3513 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3514 | + p.info.packageName + " ignored: original from " |
| 3515 | + bp.sourcePackage); |
| 3516 | } |
| 3517 | } else if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3518 | if (r == null) { |
| 3519 | r = new StringBuilder(256); |
| 3520 | } else { |
| 3521 | r.append(' '); |
| 3522 | } |
| 3523 | r.append("DUP:"); |
| 3524 | r.append(p.info.name); |
| 3525 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3526 | if (bp.perm == p) { |
| 3527 | bp.protectionLevel = p.info.protectionLevel; |
| 3528 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3530 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3531 | + p.info.packageName + " ignored: no group " |
| 3532 | + p.group); |
| 3533 | } |
| 3534 | } |
| 3535 | if (r != null) { |
| 3536 | if (Config.LOGD) Log.d(TAG, " Permissions: " + r); |
| 3537 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3539 | N = pkg.instrumentation.size(); |
| 3540 | r = null; |
| 3541 | for (i=0; i<N; i++) { |
| 3542 | PackageParser.Instrumentation a = pkg.instrumentation.get(i); |
| 3543 | a.info.packageName = pkg.applicationInfo.packageName; |
| 3544 | a.info.sourceDir = pkg.applicationInfo.sourceDir; |
| 3545 | a.info.publicSourceDir = pkg.applicationInfo.publicSourceDir; |
| 3546 | a.info.dataDir = pkg.applicationInfo.dataDir; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3547 | a.info.nativeLibraryDir = pkg.applicationInfo.nativeLibraryDir; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3548 | mInstrumentation.put(a.getComponentName(), a); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3550 | if (r == null) { |
| 3551 | r = new StringBuilder(256); |
| 3552 | } else { |
| 3553 | r.append(' '); |
| 3554 | } |
| 3555 | r.append(a.info.name); |
| 3556 | } |
| 3557 | } |
| 3558 | if (r != null) { |
| 3559 | if (Config.LOGD) Log.d(TAG, " Instrumentation: " + r); |
| 3560 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3561 | |
| Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 3562 | if (pkg.protectedBroadcasts != null) { |
| 3563 | N = pkg.protectedBroadcasts.size(); |
| 3564 | for (i=0; i<N; i++) { |
| 3565 | mProtectedBroadcasts.add(pkg.protectedBroadcasts.get(i)); |
| 3566 | } |
| 3567 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3568 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3569 | pkgSetting.setTimeStamp(scanFileTime); |
| 3570 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3571 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | return pkg; |
| 3573 | } |
| 3574 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3575 | private void killApplication(String pkgName, int uid) { |
| 3576 | // Request the ActivityManager to kill the process(only for existing packages) |
| 3577 | // so that we do not end up in a confused state while the user is still using the older |
| 3578 | // version of the application while the new one gets installed. |
| 3579 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 3580 | if (am != null) { |
| 3581 | try { |
| 3582 | am.killApplicationWithUid(pkgName, uid); |
| 3583 | } catch (RemoteException e) { |
| 3584 | } |
| 3585 | } |
| 3586 | } |
| 3587 | |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3588 | // Return the path of the directory that will contain the native binaries |
| 3589 | // of a given installed package. This is relative to the data path. |
| 3590 | // |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3591 | private File getNativeBinaryDirForPackage(PackageParser.Package pkg) { |
| 3592 | final String nativeLibraryDir = pkg.applicationInfo.nativeLibraryDir; |
| 3593 | if (nativeLibraryDir != null) { |
| 3594 | return new File(nativeLibraryDir); |
| 3595 | } else { |
| 3596 | // Fall back for old packages |
| 3597 | return new File(pkg.applicationInfo.dataDir, LIB_DIR_NAME); |
| 3598 | } |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3599 | } |
| 3600 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | void removePackageLI(PackageParser.Package pkg, boolean chatty) { |
| 3602 | if (chatty && Config.LOGD) Log.d( |
| 3603 | TAG, "Removing package " + pkg.applicationInfo.packageName ); |
| 3604 | |
| 3605 | synchronized (mPackages) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3606 | clearPackagePreferredActivitiesLP(pkg.packageName); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3608 | mPackages.remove(pkg.applicationInfo.packageName); |
| 3609 | if (pkg.mPath != null) { |
| 3610 | mAppDirs.remove(pkg.mPath); |
| 3611 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3612 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | PackageSetting ps = (PackageSetting)pkg.mExtras; |
| 3614 | if (ps != null && ps.sharedUser != null) { |
| 3615 | // XXX don't do this until the data is removed. |
| 3616 | if (false) { |
| 3617 | ps.sharedUser.packages.remove(ps); |
| 3618 | if (ps.sharedUser.packages.size() == 0) { |
| 3619 | // Remove. |
| 3620 | } |
| 3621 | } |
| 3622 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3624 | int N = pkg.providers.size(); |
| 3625 | StringBuilder r = null; |
| 3626 | int i; |
| 3627 | for (i=0; i<N; i++) { |
| 3628 | PackageParser.Provider p = pkg.providers.get(i); |
| 3629 | mProvidersByComponent.remove(new ComponentName(p.info.packageName, |
| 3630 | p.info.name)); |
| 3631 | if (p.info.authority == null) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3633 | /* The is another ContentProvider with this authority when |
| 3634 | * this app was installed so this authority is null, |
| 3635 | * Ignore it as we don't have to unregister the provider. |
| 3636 | */ |
| 3637 | continue; |
| 3638 | } |
| 3639 | String names[] = p.info.authority.split(";"); |
| 3640 | for (int j = 0; j < names.length; j++) { |
| 3641 | if (mProviders.get(names[j]) == p) { |
| 3642 | mProviders.remove(names[j]); |
| 3643 | if (chatty && Config.LOGD) Log.d( |
| 3644 | TAG, "Unregistered content provider: " + names[j] + |
| 3645 | ", className = " + p.info.name + |
| 3646 | ", isSyncable = " + p.info.isSyncable); |
| 3647 | } |
| 3648 | } |
| 3649 | if (chatty) { |
| 3650 | if (r == null) { |
| 3651 | r = new StringBuilder(256); |
| 3652 | } else { |
| 3653 | r.append(' '); |
| 3654 | } |
| 3655 | r.append(p.info.name); |
| 3656 | } |
| 3657 | } |
| 3658 | if (r != null) { |
| 3659 | if (Config.LOGD) Log.d(TAG, " Providers: " + r); |
| 3660 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3661 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | N = pkg.services.size(); |
| 3663 | r = null; |
| 3664 | for (i=0; i<N; i++) { |
| 3665 | PackageParser.Service s = pkg.services.get(i); |
| 3666 | mServices.removeService(s); |
| 3667 | if (chatty) { |
| 3668 | if (r == null) { |
| 3669 | r = new StringBuilder(256); |
| 3670 | } else { |
| 3671 | r.append(' '); |
| 3672 | } |
| 3673 | r.append(s.info.name); |
| 3674 | } |
| 3675 | } |
| 3676 | if (r != null) { |
| 3677 | if (Config.LOGD) Log.d(TAG, " Services: " + r); |
| 3678 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3679 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3680 | N = pkg.receivers.size(); |
| 3681 | r = null; |
| 3682 | for (i=0; i<N; i++) { |
| 3683 | PackageParser.Activity a = pkg.receivers.get(i); |
| 3684 | mReceivers.removeActivity(a, "receiver"); |
| 3685 | if (chatty) { |
| 3686 | if (r == null) { |
| 3687 | r = new StringBuilder(256); |
| 3688 | } else { |
| 3689 | r.append(' '); |
| 3690 | } |
| 3691 | r.append(a.info.name); |
| 3692 | } |
| 3693 | } |
| 3694 | if (r != null) { |
| 3695 | if (Config.LOGD) Log.d(TAG, " Receivers: " + r); |
| 3696 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3697 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3698 | N = pkg.activities.size(); |
| 3699 | r = null; |
| 3700 | for (i=0; i<N; i++) { |
| 3701 | PackageParser.Activity a = pkg.activities.get(i); |
| 3702 | mActivities.removeActivity(a, "activity"); |
| 3703 | if (chatty) { |
| 3704 | if (r == null) { |
| 3705 | r = new StringBuilder(256); |
| 3706 | } else { |
| 3707 | r.append(' '); |
| 3708 | } |
| 3709 | r.append(a.info.name); |
| 3710 | } |
| 3711 | } |
| 3712 | if (r != null) { |
| 3713 | if (Config.LOGD) Log.d(TAG, " Activities: " + r); |
| 3714 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3715 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3716 | N = pkg.permissions.size(); |
| 3717 | r = null; |
| 3718 | for (i=0; i<N; i++) { |
| 3719 | PackageParser.Permission p = pkg.permissions.get(i); |
| 3720 | boolean tree = false; |
| 3721 | BasePermission bp = mSettings.mPermissions.get(p.info.name); |
| 3722 | if (bp == null) { |
| 3723 | tree = true; |
| 3724 | bp = mSettings.mPermissionTrees.get(p.info.name); |
| 3725 | } |
| 3726 | if (bp != null && bp.perm == p) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3727 | bp.perm = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | if (chatty) { |
| 3729 | if (r == null) { |
| 3730 | r = new StringBuilder(256); |
| 3731 | } else { |
| 3732 | r.append(' '); |
| 3733 | } |
| 3734 | r.append(p.info.name); |
| 3735 | } |
| 3736 | } |
| 3737 | } |
| 3738 | if (r != null) { |
| 3739 | if (Config.LOGD) Log.d(TAG, " Permissions: " + r); |
| 3740 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3741 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | N = pkg.instrumentation.size(); |
| 3743 | r = null; |
| 3744 | for (i=0; i<N; i++) { |
| 3745 | PackageParser.Instrumentation a = pkg.instrumentation.get(i); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3746 | mInstrumentation.remove(a.getComponentName()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3747 | if (chatty) { |
| 3748 | if (r == null) { |
| 3749 | r = new StringBuilder(256); |
| 3750 | } else { |
| 3751 | r.append(' '); |
| 3752 | } |
| 3753 | r.append(a.info.name); |
| 3754 | } |
| 3755 | } |
| 3756 | if (r != null) { |
| 3757 | if (Config.LOGD) Log.d(TAG, " Instrumentation: " + r); |
| 3758 | } |
| 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | private static final boolean isPackageFilename(String name) { |
| 3763 | return name != null && name.endsWith(".apk"); |
| 3764 | } |
| 3765 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3766 | private static boolean hasPermission(PackageParser.Package pkgInfo, String perm) { |
| 3767 | for (int i=pkgInfo.permissions.size()-1; i>=0; i--) { |
| 3768 | if (pkgInfo.permissions.get(i).info.name.equals(perm)) { |
| 3769 | return true; |
| 3770 | } |
| 3771 | } |
| 3772 | return false; |
| 3773 | } |
| 3774 | |
| 3775 | private void updatePermissionsLP(String changingPkg, |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 3776 | PackageParser.Package pkgInfo, boolean grantPermissions, |
| 3777 | boolean replace, boolean replaceAll) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3778 | // Make sure there are no dangling permission trees. |
| 3779 | Iterator<BasePermission> it = mSettings.mPermissionTrees |
| 3780 | .values().iterator(); |
| 3781 | while (it.hasNext()) { |
| 3782 | BasePermission bp = it.next(); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3783 | if (bp.packageSetting == null) { |
| 3784 | // We may not yet have parsed the package, so just see if |
| 3785 | // we still know about its settings. |
| 3786 | bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage); |
| 3787 | } |
| 3788 | if (bp.packageSetting == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3789 | Slog.w(TAG, "Removing dangling permission tree: " + bp.name |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | + " from package " + bp.sourcePackage); |
| 3791 | it.remove(); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3792 | } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) { |
| 3793 | if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) { |
| 3794 | Slog.i(TAG, "Removing old permission tree: " + bp.name |
| 3795 | + " from package " + bp.sourcePackage); |
| 3796 | grantPermissions = true; |
| 3797 | it.remove(); |
| 3798 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | // Make sure all dynamic permissions have been assigned to a package, |
| 3803 | // and make sure there are no dangling permissions. |
| 3804 | it = mSettings.mPermissions.values().iterator(); |
| 3805 | while (it.hasNext()) { |
| 3806 | BasePermission bp = it.next(); |
| 3807 | if (bp.type == BasePermission.TYPE_DYNAMIC) { |
| 3808 | if (DEBUG_SETTINGS) Log.v(TAG, "Dynamic permission: name=" |
| 3809 | + bp.name + " pkg=" + bp.sourcePackage |
| 3810 | + " info=" + bp.pendingInfo); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3811 | if (bp.packageSetting == null && bp.pendingInfo != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3812 | BasePermission tree = findPermissionTreeLP(bp.name); |
| 3813 | if (tree != null) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3814 | bp.packageSetting = tree.packageSetting; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3815 | bp.perm = new PackageParser.Permission(tree.perm.owner, |
| 3816 | new PermissionInfo(bp.pendingInfo)); |
| 3817 | bp.perm.info.packageName = tree.perm.info.packageName; |
| 3818 | bp.perm.info.name = bp.name; |
| 3819 | bp.uid = tree.uid; |
| 3820 | } |
| 3821 | } |
| 3822 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3823 | if (bp.packageSetting == null) { |
| 3824 | // We may not yet have parsed the package, so just see if |
| 3825 | // we still know about its settings. |
| 3826 | bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage); |
| 3827 | } |
| 3828 | if (bp.packageSetting == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3829 | Slog.w(TAG, "Removing dangling permission: " + bp.name |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | + " from package " + bp.sourcePackage); |
| 3831 | it.remove(); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3832 | } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) { |
| 3833 | if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) { |
| 3834 | Slog.i(TAG, "Removing old permission: " + bp.name |
| 3835 | + " from package " + bp.sourcePackage); |
| 3836 | grantPermissions = true; |
| 3837 | it.remove(); |
| 3838 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3839 | } |
| 3840 | } |
| 3841 | |
| 3842 | // Now update the permissions for all packages, in particular |
| 3843 | // replace the granted permissions of the system packages. |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3844 | if (grantPermissions) { |
| 3845 | for (PackageParser.Package pkg : mPackages.values()) { |
| 3846 | if (pkg != pkgInfo) { |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 3847 | grantPermissionsLP(pkg, replaceAll); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3848 | } |
| 3849 | } |
| 3850 | } |
| 3851 | |
| 3852 | if (pkgInfo != null) { |
| 3853 | grantPermissionsLP(pkgInfo, replace); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3854 | } |
| 3855 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3856 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3857 | private void grantPermissionsLP(PackageParser.Package pkg, boolean replace) { |
| 3858 | final PackageSetting ps = (PackageSetting)pkg.mExtras; |
| 3859 | if (ps == null) { |
| 3860 | return; |
| 3861 | } |
| 3862 | final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3863 | boolean changedPermission = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3864 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | if (replace) { |
| 3866 | ps.permissionsFixed = false; |
| 3867 | if (gp == ps) { |
| 3868 | gp.grantedPermissions.clear(); |
| 3869 | gp.gids = mGlobalGids; |
| 3870 | } |
| 3871 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3872 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3873 | if (gp.gids == null) { |
| 3874 | gp.gids = mGlobalGids; |
| 3875 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3876 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | final int N = pkg.requestedPermissions.size(); |
| 3878 | for (int i=0; i<N; i++) { |
| 3879 | String name = pkg.requestedPermissions.get(i); |
| 3880 | BasePermission bp = mSettings.mPermissions.get(name); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3881 | if (false) { |
| 3882 | if (gp != ps) { |
| 3883 | Log.i(TAG, "Package " + pkg.packageName + " checking " + name |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3884 | + ": " + bp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3885 | } |
| 3886 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3887 | if (bp != null && bp.packageSetting != null) { |
| 3888 | final String perm = bp.name; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3889 | boolean allowed; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3890 | boolean allowedSig = false; |
| 3891 | if (bp.protectionLevel == PermissionInfo.PROTECTION_NORMAL |
| 3892 | || bp.protectionLevel == PermissionInfo.PROTECTION_DANGEROUS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3893 | allowed = true; |
| Dianne Hackborn | 6e52b5d | 2010-04-05 14:33:01 -0700 | [diff] [blame] | 3894 | } else if (bp.packageSetting == null) { |
| 3895 | // This permission is invalid; skip it. |
| 3896 | allowed = false; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3897 | } else if (bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE |
| 3898 | || bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM) { |
| 3899 | allowed = (checkSignaturesLP(bp.packageSetting.signatures.mSignatures, pkg.mSignatures) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3900 | == PackageManager.SIGNATURE_MATCH) |
| Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 3901 | || (checkSignaturesLP(mPlatformPackage.mSignatures, pkg.mSignatures) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | == PackageManager.SIGNATURE_MATCH); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3903 | if (bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3904 | if (isSystemApp(pkg)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | // For updated system applications, the signatureOrSystem permission |
| 3906 | // is granted only if it had been defined by the original application. |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3907 | if (isUpdatedSystemApp(pkg)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3908 | PackageSetting sysPs = mSettings.getDisabledSystemPkg(pkg.packageName); |
| 3909 | if(sysPs.grantedPermissions.contains(perm)) { |
| 3910 | allowed = true; |
| 3911 | } else { |
| 3912 | allowed = false; |
| 3913 | } |
| 3914 | } else { |
| 3915 | allowed = true; |
| 3916 | } |
| 3917 | } |
| 3918 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3919 | if (allowed) { |
| 3920 | allowedSig = true; |
| 3921 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | } else { |
| 3923 | allowed = false; |
| 3924 | } |
| 3925 | if (false) { |
| 3926 | if (gp != ps) { |
| 3927 | Log.i(TAG, "Package " + pkg.packageName + " granting " + perm); |
| 3928 | } |
| 3929 | } |
| 3930 | if (allowed) { |
| 3931 | if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0 |
| 3932 | && ps.permissionsFixed) { |
| 3933 | // If this is an existing, non-system package, then |
| 3934 | // we can't add any new permissions to it. |
| Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 3935 | if (!allowedSig && !gp.grantedPermissions.contains(perm)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3936 | allowed = false; |
| Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 3937 | // Except... if this is a permission that was added |
| 3938 | // to the platform (note: need to only do this when |
| 3939 | // updating the platform). |
| 3940 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
| 3941 | for (int ip=0; ip<NP; ip++) { |
| 3942 | final PackageParser.NewPermissionInfo npi |
| 3943 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 3944 | if (npi.name.equals(perm) |
| 3945 | && pkg.applicationInfo.targetSdkVersion < npi.sdkVersion) { |
| 3946 | allowed = true; |
| Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 3947 | Log.i(TAG, "Auto-granting " + perm + " to old pkg " |
| Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 3948 | + pkg.packageName); |
| 3949 | break; |
| 3950 | } |
| 3951 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3952 | } |
| 3953 | } |
| 3954 | if (allowed) { |
| 3955 | if (!gp.grantedPermissions.contains(perm)) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3956 | changedPermission = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | gp.grantedPermissions.add(perm); |
| 3958 | gp.gids = appendInts(gp.gids, bp.gids); |
| Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 3959 | } else if (!ps.haveGids) { |
| 3960 | gp.gids = appendInts(gp.gids, bp.gids); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3961 | } |
| 3962 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3963 | Slog.w(TAG, "Not granting permission " + perm |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3964 | + " to package " + pkg.packageName |
| 3965 | + " because it was previously installed without"); |
| 3966 | } |
| 3967 | } else { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3968 | if (gp.grantedPermissions.remove(perm)) { |
| 3969 | changedPermission = true; |
| 3970 | gp.gids = removeInts(gp.gids, bp.gids); |
| 3971 | Slog.i(TAG, "Un-granting permission " + perm |
| 3972 | + " from package " + pkg.packageName |
| 3973 | + " (protectionLevel=" + bp.protectionLevel |
| 3974 | + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags) |
| 3975 | + ")"); |
| 3976 | } else { |
| 3977 | Slog.w(TAG, "Not granting permission " + perm |
| 3978 | + " to package " + pkg.packageName |
| 3979 | + " (protectionLevel=" + bp.protectionLevel |
| 3980 | + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags) |
| 3981 | + ")"); |
| 3982 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3983 | } |
| 3984 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3985 | Slog.w(TAG, "Unknown permission " + name |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3986 | + " in package " + pkg.packageName); |
| 3987 | } |
| 3988 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3989 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3990 | if ((changedPermission || replace) && !ps.permissionsFixed && |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3991 | ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) || |
| 3992 | ((ps.pkgFlags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)){ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3993 | // This is the first that we have heard about this package, so the |
| 3994 | // permissions we have now selected are fixed until explicitly |
| 3995 | // changed. |
| 3996 | ps.permissionsFixed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3997 | } |
| Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 3998 | ps.haveGids = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3999 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4001 | private final class ActivityIntentResolver |
| 4002 | extends IntentResolver<PackageParser.ActivityIntentInfo, ResolveInfo> { |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4003 | public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4004 | mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0; |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4005 | return super.queryIntent(intent, resolvedType, defaultOnly); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4006 | } |
| 4007 | |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4008 | public List queryIntent(Intent intent, String resolvedType, int flags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4009 | mFlags = flags; |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4010 | return super.queryIntent(intent, resolvedType, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4011 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 4012 | } |
| 4013 | |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4014 | public List queryIntentForPackage(Intent intent, String resolvedType, int flags, |
| 4015 | ArrayList<PackageParser.Activity> packageActivities) { |
| 4016 | if (packageActivities == null) { |
| 4017 | return null; |
| 4018 | } |
| 4019 | mFlags = flags; |
| 4020 | final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0; |
| 4021 | int N = packageActivities.size(); |
| 4022 | ArrayList<ArrayList<PackageParser.ActivityIntentInfo>> listCut = |
| 4023 | new ArrayList<ArrayList<PackageParser.ActivityIntentInfo>>(N); |
| Mihai Preda | c3320db | 2009-05-18 20:15:32 +0200 | [diff] [blame] | 4024 | |
| 4025 | ArrayList<PackageParser.ActivityIntentInfo> intentFilters; |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4026 | for (int i = 0; i < N; ++i) { |
| Mihai Preda | c3320db | 2009-05-18 20:15:32 +0200 | [diff] [blame] | 4027 | intentFilters = packageActivities.get(i).intents; |
| 4028 | if (intentFilters != null && intentFilters.size() > 0) { |
| 4029 | listCut.add(intentFilters); |
| 4030 | } |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4031 | } |
| 4032 | return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut); |
| 4033 | } |
| 4034 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4035 | public final void addActivity(PackageParser.Activity a, String type) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4036 | mActivities.put(a.getComponentName(), a); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4037 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4038 | TAG, " " + type + " " + |
| 4039 | (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":"); |
| 4040 | if (SHOW_INFO || Config.LOGV) Log.v(TAG, " Class=" + a.info.name); |
| 4041 | int NI = a.intents.size(); |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4042 | for (int j=0; j<NI; j++) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4043 | PackageParser.ActivityIntentInfo intent = a.intents.get(j); |
| 4044 | if (SHOW_INFO || Config.LOGV) { |
| 4045 | Log.v(TAG, " IntentFilter:"); |
| 4046 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4047 | } |
| 4048 | if (!intent.debugCheck()) { |
| 4049 | Log.w(TAG, "==> For Activity " + a.info.name); |
| 4050 | } |
| 4051 | addFilter(intent); |
| 4052 | } |
| 4053 | } |
| 4054 | |
| 4055 | public final void removeActivity(PackageParser.Activity a, String type) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4056 | mActivities.remove(a.getComponentName()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4058 | TAG, " " + type + " " + |
| 4059 | (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":"); |
| 4060 | if (SHOW_INFO || Config.LOGV) Log.v(TAG, " Class=" + a.info.name); |
| 4061 | int NI = a.intents.size(); |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4062 | for (int j=0; j<NI; j++) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | PackageParser.ActivityIntentInfo intent = a.intents.get(j); |
| 4064 | if (SHOW_INFO || Config.LOGV) { |
| 4065 | Log.v(TAG, " IntentFilter:"); |
| 4066 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4067 | } |
| 4068 | removeFilter(intent); |
| 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | @Override |
| 4073 | protected boolean allowFilterResult( |
| 4074 | PackageParser.ActivityIntentInfo filter, List<ResolveInfo> dest) { |
| 4075 | ActivityInfo filterAi = filter.activity.info; |
| 4076 | for (int i=dest.size()-1; i>=0; i--) { |
| 4077 | ActivityInfo destAi = dest.get(i).activityInfo; |
| 4078 | if (destAi.name == filterAi.name |
| 4079 | && destAi.packageName == filterAi.packageName) { |
| 4080 | return false; |
| 4081 | } |
| 4082 | } |
| 4083 | return true; |
| 4084 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4085 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4086 | @Override |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4087 | protected String packageForFilter(PackageParser.ActivityIntentInfo info) { |
| 4088 | return info.activity.owner.packageName; |
| 4089 | } |
| 4090 | |
| 4091 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4092 | protected ResolveInfo newResult(PackageParser.ActivityIntentInfo info, |
| 4093 | int match) { |
| 4094 | if (!mSettings.isEnabledLP(info.activity.info, mFlags)) { |
| 4095 | return null; |
| 4096 | } |
| 4097 | final PackageParser.Activity activity = info.activity; |
| 4098 | if (mSafeMode && (activity.info.applicationInfo.flags |
| 4099 | &ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 4100 | return null; |
| 4101 | } |
| 4102 | final ResolveInfo res = new ResolveInfo(); |
| 4103 | res.activityInfo = PackageParser.generateActivityInfo(activity, |
| 4104 | mFlags); |
| 4105 | if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) { |
| 4106 | res.filter = info; |
| 4107 | } |
| 4108 | res.priority = info.getPriority(); |
| 4109 | res.preferredOrder = activity.owner.mPreferredOrder; |
| 4110 | //System.out.println("Result: " + res.activityInfo.className + |
| 4111 | // " = " + res.priority); |
| 4112 | res.match = match; |
| 4113 | res.isDefault = info.hasDefault; |
| 4114 | res.labelRes = info.labelRes; |
| 4115 | res.nonLocalizedLabel = info.nonLocalizedLabel; |
| 4116 | res.icon = info.icon; |
| 4117 | return res; |
| 4118 | } |
| 4119 | |
| 4120 | @Override |
| 4121 | protected void sortResults(List<ResolveInfo> results) { |
| 4122 | Collections.sort(results, mResolvePrioritySorter); |
| 4123 | } |
| 4124 | |
| 4125 | @Override |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4126 | protected void dumpFilter(PrintWriter out, String prefix, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4127 | PackageParser.ActivityIntentInfo filter) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4128 | out.print(prefix); out.print( |
| 4129 | Integer.toHexString(System.identityHashCode(filter.activity))); |
| 4130 | out.print(' '); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4131 | out.print(filter.activity.getComponentShortName()); |
| 4132 | out.print(" filter "); |
| 4133 | out.println(Integer.toHexString(System.identityHashCode(filter))); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | // List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) { |
| 4137 | // final Iterator<ResolveInfo> i = resolveInfoList.iterator(); |
| 4138 | // final List<ResolveInfo> retList = Lists.newArrayList(); |
| 4139 | // while (i.hasNext()) { |
| 4140 | // final ResolveInfo resolveInfo = i.next(); |
| 4141 | // if (isEnabledLP(resolveInfo.activityInfo)) { |
| 4142 | // retList.add(resolveInfo); |
| 4143 | // } |
| 4144 | // } |
| 4145 | // return retList; |
| 4146 | // } |
| 4147 | |
| 4148 | // Keys are String (activity class name), values are Activity. |
| 4149 | private final HashMap<ComponentName, PackageParser.Activity> mActivities |
| 4150 | = new HashMap<ComponentName, PackageParser.Activity>(); |
| 4151 | private int mFlags; |
| 4152 | } |
| 4153 | |
| 4154 | private final class ServiceIntentResolver |
| 4155 | extends IntentResolver<PackageParser.ServiceIntentInfo, ResolveInfo> { |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4156 | public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4157 | mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0; |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4158 | return super.queryIntent(intent, resolvedType, defaultOnly); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4159 | } |
| 4160 | |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4161 | public List queryIntent(Intent intent, String resolvedType, int flags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4162 | mFlags = flags; |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4163 | return super.queryIntent(intent, resolvedType, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 4165 | } |
| 4166 | |
| Dianne Hackborn | c14b9ccd | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 4167 | public List queryIntentForPackage(Intent intent, String resolvedType, int flags, |
| 4168 | ArrayList<PackageParser.Service> packageServices) { |
| 4169 | if (packageServices == null) { |
| 4170 | return null; |
| 4171 | } |
| 4172 | mFlags = flags; |
| 4173 | final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0; |
| 4174 | int N = packageServices.size(); |
| 4175 | ArrayList<ArrayList<PackageParser.ServiceIntentInfo>> listCut = |
| 4176 | new ArrayList<ArrayList<PackageParser.ServiceIntentInfo>>(N); |
| 4177 | |
| 4178 | ArrayList<PackageParser.ServiceIntentInfo> intentFilters; |
| 4179 | for (int i = 0; i < N; ++i) { |
| 4180 | intentFilters = packageServices.get(i).intents; |
| 4181 | if (intentFilters != null && intentFilters.size() > 0) { |
| 4182 | listCut.add(intentFilters); |
| 4183 | } |
| 4184 | } |
| 4185 | return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut); |
| 4186 | } |
| 4187 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | public final void addService(PackageParser.Service s) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4189 | mServices.put(s.getComponentName(), s); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4190 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4191 | TAG, " " + (s.info.nonLocalizedLabel != null |
| 4192 | ? s.info.nonLocalizedLabel : s.info.name) + ":"); |
| 4193 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4194 | TAG, " Class=" + s.info.name); |
| 4195 | int NI = s.intents.size(); |
| 4196 | int j; |
| 4197 | for (j=0; j<NI; j++) { |
| 4198 | PackageParser.ServiceIntentInfo intent = s.intents.get(j); |
| 4199 | if (SHOW_INFO || Config.LOGV) { |
| 4200 | Log.v(TAG, " IntentFilter:"); |
| 4201 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4202 | } |
| 4203 | if (!intent.debugCheck()) { |
| 4204 | Log.w(TAG, "==> For Service " + s.info.name); |
| 4205 | } |
| 4206 | addFilter(intent); |
| 4207 | } |
| 4208 | } |
| 4209 | |
| 4210 | public final void removeService(PackageParser.Service s) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4211 | mServices.remove(s.getComponentName()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4212 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4213 | TAG, " " + (s.info.nonLocalizedLabel != null |
| 4214 | ? s.info.nonLocalizedLabel : s.info.name) + ":"); |
| 4215 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4216 | TAG, " Class=" + s.info.name); |
| 4217 | int NI = s.intents.size(); |
| 4218 | int j; |
| 4219 | for (j=0; j<NI; j++) { |
| 4220 | PackageParser.ServiceIntentInfo intent = s.intents.get(j); |
| 4221 | if (SHOW_INFO || Config.LOGV) { |
| 4222 | Log.v(TAG, " IntentFilter:"); |
| 4223 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4224 | } |
| 4225 | removeFilter(intent); |
| 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | @Override |
| 4230 | protected boolean allowFilterResult( |
| 4231 | PackageParser.ServiceIntentInfo filter, List<ResolveInfo> dest) { |
| 4232 | ServiceInfo filterSi = filter.service.info; |
| 4233 | for (int i=dest.size()-1; i>=0; i--) { |
| 4234 | ServiceInfo destAi = dest.get(i).serviceInfo; |
| 4235 | if (destAi.name == filterSi.name |
| 4236 | && destAi.packageName == filterSi.packageName) { |
| 4237 | return false; |
| 4238 | } |
| 4239 | } |
| 4240 | return true; |
| 4241 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4242 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4243 | @Override |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4244 | protected String packageForFilter(PackageParser.ServiceIntentInfo info) { |
| 4245 | return info.service.owner.packageName; |
| 4246 | } |
| 4247 | |
| 4248 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4249 | protected ResolveInfo newResult(PackageParser.ServiceIntentInfo filter, |
| 4250 | int match) { |
| 4251 | final PackageParser.ServiceIntentInfo info = (PackageParser.ServiceIntentInfo)filter; |
| 4252 | if (!mSettings.isEnabledLP(info.service.info, mFlags)) { |
| 4253 | return null; |
| 4254 | } |
| 4255 | final PackageParser.Service service = info.service; |
| 4256 | if (mSafeMode && (service.info.applicationInfo.flags |
| 4257 | &ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 4258 | return null; |
| 4259 | } |
| 4260 | final ResolveInfo res = new ResolveInfo(); |
| 4261 | res.serviceInfo = PackageParser.generateServiceInfo(service, |
| 4262 | mFlags); |
| 4263 | if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) { |
| 4264 | res.filter = filter; |
| 4265 | } |
| 4266 | res.priority = info.getPriority(); |
| 4267 | res.preferredOrder = service.owner.mPreferredOrder; |
| 4268 | //System.out.println("Result: " + res.activityInfo.className + |
| 4269 | // " = " + res.priority); |
| 4270 | res.match = match; |
| 4271 | res.isDefault = info.hasDefault; |
| 4272 | res.labelRes = info.labelRes; |
| 4273 | res.nonLocalizedLabel = info.nonLocalizedLabel; |
| 4274 | res.icon = info.icon; |
| 4275 | return res; |
| 4276 | } |
| 4277 | |
| 4278 | @Override |
| 4279 | protected void sortResults(List<ResolveInfo> results) { |
| 4280 | Collections.sort(results, mResolvePrioritySorter); |
| 4281 | } |
| 4282 | |
| 4283 | @Override |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4284 | protected void dumpFilter(PrintWriter out, String prefix, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4285 | PackageParser.ServiceIntentInfo filter) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4286 | out.print(prefix); out.print( |
| 4287 | Integer.toHexString(System.identityHashCode(filter.service))); |
| 4288 | out.print(' '); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4289 | out.print(filter.service.getComponentShortName()); |
| 4290 | out.print(" filter "); |
| 4291 | out.println(Integer.toHexString(System.identityHashCode(filter))); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | // List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) { |
| 4295 | // final Iterator<ResolveInfo> i = resolveInfoList.iterator(); |
| 4296 | // final List<ResolveInfo> retList = Lists.newArrayList(); |
| 4297 | // while (i.hasNext()) { |
| 4298 | // final ResolveInfo resolveInfo = (ResolveInfo) i; |
| 4299 | // if (isEnabledLP(resolveInfo.serviceInfo)) { |
| 4300 | // retList.add(resolveInfo); |
| 4301 | // } |
| 4302 | // } |
| 4303 | // return retList; |
| 4304 | // } |
| 4305 | |
| 4306 | // Keys are String (activity class name), values are Activity. |
| 4307 | private final HashMap<ComponentName, PackageParser.Service> mServices |
| 4308 | = new HashMap<ComponentName, PackageParser.Service>(); |
| 4309 | private int mFlags; |
| 4310 | }; |
| 4311 | |
| 4312 | private static final Comparator<ResolveInfo> mResolvePrioritySorter = |
| 4313 | new Comparator<ResolveInfo>() { |
| 4314 | public int compare(ResolveInfo r1, ResolveInfo r2) { |
| 4315 | int v1 = r1.priority; |
| 4316 | int v2 = r2.priority; |
| 4317 | //System.out.println("Comparing: q1=" + q1 + " q2=" + q2); |
| 4318 | if (v1 != v2) { |
| 4319 | return (v1 > v2) ? -1 : 1; |
| 4320 | } |
| 4321 | v1 = r1.preferredOrder; |
| 4322 | v2 = r2.preferredOrder; |
| 4323 | if (v1 != v2) { |
| 4324 | return (v1 > v2) ? -1 : 1; |
| 4325 | } |
| 4326 | if (r1.isDefault != r2.isDefault) { |
| 4327 | return r1.isDefault ? -1 : 1; |
| 4328 | } |
| 4329 | v1 = r1.match; |
| 4330 | v2 = r2.match; |
| 4331 | //System.out.println("Comparing: m1=" + m1 + " m2=" + m2); |
| 4332 | return (v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0); |
| 4333 | } |
| 4334 | }; |
| 4335 | |
| 4336 | private static final Comparator<ProviderInfo> mProviderInitOrderSorter = |
| 4337 | new Comparator<ProviderInfo>() { |
| 4338 | public int compare(ProviderInfo p1, ProviderInfo p2) { |
| 4339 | final int v1 = p1.initOrder; |
| 4340 | final int v2 = p2.initOrder; |
| 4341 | return (v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0); |
| 4342 | } |
| 4343 | }; |
| 4344 | |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 4345 | private static final boolean DEBUG_OBB = false; |
| 4346 | |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4347 | private static final void sendPackageBroadcast(String action, String pkg, |
| 4348 | Bundle extras, IIntentReceiver finishedReceiver) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 4350 | if (am != null) { |
| 4351 | try { |
| 4352 | final Intent intent = new Intent(action, |
| 4353 | pkg != null ? Uri.fromParts("package", pkg, null) : null); |
| 4354 | if (extras != null) { |
| 4355 | intent.putExtras(extras); |
| 4356 | } |
| Dianne Hackborn | de7faf6 | 2009-06-30 13:27:30 -0700 | [diff] [blame] | 4357 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4358 | am.broadcastIntent(null, intent, null, finishedReceiver, |
| 4359 | 0, null, null, null, finishedReceiver != null, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4360 | } catch (RemoteException ex) { |
| 4361 | } |
| 4362 | } |
| 4363 | } |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 4364 | |
| 4365 | public String nextPackageToClean(String lastPackage) { |
| 4366 | synchronized (mPackages) { |
| 4367 | if (!mMediaMounted) { |
| 4368 | // If the external storage is no longer mounted at this point, |
| 4369 | // the caller may not have been able to delete all of this |
| 4370 | // packages files and can not delete any more. Bail. |
| 4371 | return null; |
| 4372 | } |
| 4373 | if (lastPackage != null) { |
| 4374 | mSettings.mPackagesToBeCleaned.remove(lastPackage); |
| 4375 | } |
| 4376 | return mSettings.mPackagesToBeCleaned.size() > 0 |
| 4377 | ? mSettings.mPackagesToBeCleaned.get(0) : null; |
| 4378 | } |
| 4379 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4380 | |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 4381 | void schedulePackageCleaning(String packageName) { |
| 4382 | mHandler.sendMessage(mHandler.obtainMessage(START_CLEANING_PACKAGE, packageName)); |
| 4383 | } |
| 4384 | |
| 4385 | void startCleaningPackages() { |
| 4386 | synchronized (mPackages) { |
| 4387 | if (!mMediaMounted) { |
| 4388 | return; |
| 4389 | } |
| 4390 | if (mSettings.mPackagesToBeCleaned.size() <= 0) { |
| 4391 | return; |
| 4392 | } |
| 4393 | } |
| 4394 | Intent intent = new Intent(PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE); |
| 4395 | intent.setComponent(DEFAULT_CONTAINER_COMPONENT); |
| 4396 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 4397 | if (am != null) { |
| 4398 | try { |
| 4399 | am.startService(null, intent, null); |
| 4400 | } catch (RemoteException e) { |
| 4401 | } |
| 4402 | } |
| 4403 | } |
| 4404 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4405 | private final class AppDirObserver extends FileObserver { |
| 4406 | public AppDirObserver(String path, int mask, boolean isrom) { |
| 4407 | super(path, mask); |
| 4408 | mRootDir = path; |
| 4409 | mIsRom = isrom; |
| 4410 | } |
| 4411 | |
| 4412 | public void onEvent(int event, String path) { |
| 4413 | String removedPackage = null; |
| 4414 | int removedUid = -1; |
| 4415 | String addedPackage = null; |
| 4416 | int addedUid = -1; |
| 4417 | |
| 4418 | synchronized (mInstallLock) { |
| 4419 | String fullPathStr = null; |
| 4420 | File fullPath = null; |
| 4421 | if (path != null) { |
| 4422 | fullPath = new File(mRootDir, path); |
| 4423 | fullPathStr = fullPath.getPath(); |
| 4424 | } |
| 4425 | |
| 4426 | if (Config.LOGV) Log.v( |
| 4427 | TAG, "File " + fullPathStr + " changed: " |
| 4428 | + Integer.toHexString(event)); |
| 4429 | |
| 4430 | if (!isPackageFilename(path)) { |
| 4431 | if (Config.LOGV) Log.v( |
| 4432 | TAG, "Ignoring change of non-package file: " + fullPathStr); |
| 4433 | return; |
| 4434 | } |
| 4435 | |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4436 | // Ignore packages that are being installed or |
| 4437 | // have just been installed. |
| 4438 | if (ignoreCodePath(fullPathStr)) { |
| 4439 | return; |
| 4440 | } |
| 4441 | PackageParser.Package p = null; |
| 4442 | synchronized (mPackages) { |
| 4443 | p = mAppDirs.get(fullPathStr); |
| 4444 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4445 | if ((event&REMOVE_EVENTS) != 0) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4446 | if (p != null) { |
| 4447 | removePackageLI(p, true); |
| 4448 | removedPackage = p.applicationInfo.packageName; |
| 4449 | removedUid = p.applicationInfo.uid; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | if ((event&ADD_EVENTS) != 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4454 | if (p == null) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 4455 | p = scanPackageLI(fullPath, |
| Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 4456 | (mIsRom ? PackageParser.PARSE_IS_SYSTEM |
| 4457 | | PackageParser.PARSE_IS_SYSTEM_DIR: 0) | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4458 | PackageParser.PARSE_CHATTY | |
| 4459 | PackageParser.PARSE_MUST_BE_APK, |
| Andrew Stadler | 48c0273 | 2010-01-15 00:03:41 -0800 | [diff] [blame] | 4460 | SCAN_MONITOR | SCAN_NO_PATHS); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4461 | if (p != null) { |
| 4462 | synchronized (mPackages) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4463 | updatePermissionsLP(p.packageName, p, |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 4464 | p.permissions.size() > 0, false, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4465 | } |
| 4466 | addedPackage = p.applicationInfo.packageName; |
| 4467 | addedUid = p.applicationInfo.uid; |
| 4468 | } |
| 4469 | } |
| 4470 | } |
| 4471 | |
| 4472 | synchronized (mPackages) { |
| 4473 | mSettings.writeLP(); |
| 4474 | } |
| 4475 | } |
| 4476 | |
| 4477 | if (removedPackage != null) { |
| 4478 | Bundle extras = new Bundle(1); |
| 4479 | extras.putInt(Intent.EXTRA_UID, removedUid); |
| 4480 | extras.putBoolean(Intent.EXTRA_DATA_REMOVED, false); |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4481 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage, |
| 4482 | extras, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4483 | } |
| 4484 | if (addedPackage != null) { |
| 4485 | Bundle extras = new Bundle(1); |
| 4486 | extras.putInt(Intent.EXTRA_UID, addedUid); |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4487 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, addedPackage, |
| 4488 | extras, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | private final String mRootDir; |
| 4493 | private final boolean mIsRom; |
| 4494 | } |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4495 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4496 | /* Called when a downloaded package installation has been confirmed by the user */ |
| 4497 | public void installPackage( |
| 4498 | final Uri packageURI, final IPackageInstallObserver observer, final int flags) { |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4499 | installPackage(packageURI, observer, flags, null); |
| 4500 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4501 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4502 | /* Called when a downloaded package installation has been confirmed by the user */ |
| 4503 | public void installPackage( |
| 4504 | final Uri packageURI, final IPackageInstallObserver observer, final int flags, |
| 4505 | final String installerPackageName) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | mContext.enforceCallingOrSelfPermission( |
| 4507 | android.Manifest.permission.INSTALL_PACKAGES, null); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4508 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4509 | Message msg = mHandler.obtainMessage(INIT_COPY); |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4510 | msg.obj = new InstallParams(packageURI, observer, flags, |
| 4511 | installerPackageName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4512 | mHandler.sendMessage(msg); |
| 4513 | } |
| 4514 | |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4515 | public void finishPackageInstall(int token) { |
| 4516 | if (DEBUG_INSTALL) Log.v(TAG, "BM finishing package install for " + token); |
| 4517 | Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0); |
| 4518 | mHandler.sendMessage(msg); |
| 4519 | } |
| 4520 | |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 4521 | public void setPackageObbPath(String packageName, String path) { |
| 4522 | if (DEBUG_OBB) |
| 4523 | Log.v(TAG, "Setting .obb path for " + packageName + " to: " + path); |
| 4524 | PackageSetting pkgSetting; |
| 4525 | final int uid = Binder.getCallingUid(); |
| Kenny Root | e059b27 | 2010-07-12 08:36:07 -0700 | [diff] [blame] | 4526 | final int permission = mContext.checkCallingPermission( |
| 4527 | android.Manifest.permission.INSTALL_PACKAGES); |
| 4528 | final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED); |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 4529 | synchronized (mPackages) { |
| 4530 | pkgSetting = mSettings.mPackages.get(packageName); |
| 4531 | if (pkgSetting == null) { |
| 4532 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4533 | } |
| 4534 | if (!allowedByPermission && (uid != pkgSetting.userId)) { |
| 4535 | throw new SecurityException("Permission denial: attempt to set .obb file from pid=" |
| 4536 | + Binder.getCallingPid() + ", uid=" + uid + ", package uid=" |
| 4537 | + pkgSetting.userId); |
| 4538 | } |
| 4539 | pkgSetting.obbPathString = path; |
| 4540 | mSettings.writeLP(); |
| 4541 | } |
| 4542 | } |
| 4543 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4544 | private void processPendingInstall(final InstallArgs args, final int currentStatus) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4545 | // Queue up an async operation since the package installation may take a little while. |
| 4546 | mHandler.post(new Runnable() { |
| 4547 | public void run() { |
| 4548 | mHandler.removeCallbacks(this); |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4549 | // Result object to be returned |
| 4550 | PackageInstalledInfo res = new PackageInstalledInfo(); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4551 | res.returnCode = currentStatus; |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4552 | res.uid = -1; |
| 4553 | res.pkg = null; |
| 4554 | res.removedInfo = new PackageRemovedInfo(); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4555 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) { |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4556 | args.doPreInstall(res.returnCode); |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4557 | synchronized (mInstallLock) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4558 | installPackageLI(args, true, res); |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4559 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4560 | args.doPostInstall(res.returnCode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4561 | } |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4562 | |
| 4563 | // A restore should be performed at this point if (a) the install |
| 4564 | // succeeded, (b) the operation is not an update, and (c) the new |
| 4565 | // package has a backupAgent defined. |
| 4566 | final boolean update = res.removedInfo.removedPackage != null; |
| Christopher Tate | 59eac4b | 2010-02-19 19:25:45 -0800 | [diff] [blame] | 4567 | boolean doRestore = (!update |
| 4568 | && res.pkg != null |
| 4569 | && res.pkg.applicationInfo.backupAgentName != null); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4570 | |
| 4571 | // Set up the post-install work request bookkeeping. This will be used |
| 4572 | // and cleaned up by the post-install event handling regardless of whether |
| 4573 | // there's a restore pass performed. Token values are >= 1. |
| 4574 | int token; |
| 4575 | if (mNextInstallToken < 0) mNextInstallToken = 1; |
| 4576 | token = mNextInstallToken++; |
| 4577 | |
| 4578 | PostInstallData data = new PostInstallData(args, res); |
| 4579 | mRunningInstalls.put(token, data); |
| 4580 | if (DEBUG_INSTALL) Log.v(TAG, "+ starting restore round-trip " + token); |
| 4581 | |
| 4582 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED && doRestore) { |
| 4583 | // Pass responsibility to the Backup Manager. It will perform a |
| 4584 | // restore if appropriate, then pass responsibility back to the |
| 4585 | // Package Manager to run the post-install observer callbacks |
| 4586 | // and broadcasts. |
| 4587 | IBackupManager bm = IBackupManager.Stub.asInterface( |
| 4588 | ServiceManager.getService(Context.BACKUP_SERVICE)); |
| 4589 | if (bm != null) { |
| 4590 | if (DEBUG_INSTALL) Log.v(TAG, "token " + token |
| 4591 | + " to BM for possible restore"); |
| 4592 | try { |
| 4593 | bm.restoreAtInstall(res.pkg.applicationInfo.packageName, token); |
| 4594 | } catch (RemoteException e) { |
| 4595 | // can't happen; the backup manager is local |
| 4596 | } catch (Exception e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4597 | Slog.e(TAG, "Exception trying to enqueue restore", e); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4598 | doRestore = false; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4599 | } |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4600 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4601 | Slog.e(TAG, "Backup Manager not found!"); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4602 | doRestore = false; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4603 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4604 | } |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4605 | |
| 4606 | if (!doRestore) { |
| 4607 | // No restore possible, or the Backup Manager was mysteriously not |
| 4608 | // available -- just fire the post-install work request directly. |
| 4609 | if (DEBUG_INSTALL) Log.v(TAG, "No restore - queue post-install for " + token); |
| 4610 | Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0); |
| 4611 | mHandler.sendMessage(msg); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4612 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4613 | } |
| 4614 | }); |
| 4615 | } |
| 4616 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4617 | abstract class HandlerParams { |
| 4618 | final static int MAX_RETRIES = 4; |
| 4619 | int retry = 0; |
| 4620 | final void startCopy() { |
| 4621 | try { |
| 4622 | if (DEBUG_SD_INSTALL) Log.i(TAG, "startCopy"); |
| 4623 | retry++; |
| 4624 | if (retry > MAX_RETRIES) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4625 | Slog.w(TAG, "Failed to invoke remote methods on default container service. Giving up"); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4626 | mHandler.sendEmptyMessage(MCS_GIVE_UP); |
| 4627 | handleServiceError(); |
| 4628 | return; |
| 4629 | } else { |
| 4630 | handleStartCopy(); |
| 4631 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Posting install MCS_UNBIND"); |
| 4632 | mHandler.sendEmptyMessage(MCS_UNBIND); |
| 4633 | } |
| 4634 | } catch (RemoteException e) { |
| 4635 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Posting install MCS_RECONNECT"); |
| 4636 | mHandler.sendEmptyMessage(MCS_RECONNECT); |
| 4637 | } |
| 4638 | handleReturnCode(); |
| 4639 | } |
| 4640 | |
| 4641 | final void serviceError() { |
| 4642 | if (DEBUG_SD_INSTALL) Log.i(TAG, "serviceError"); |
| 4643 | handleServiceError(); |
| 4644 | handleReturnCode(); |
| 4645 | } |
| 4646 | abstract void handleStartCopy() throws RemoteException; |
| 4647 | abstract void handleServiceError(); |
| 4648 | abstract void handleReturnCode(); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4649 | } |
| 4650 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4651 | class InstallParams extends HandlerParams { |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4652 | final IPackageInstallObserver observer; |
| 4653 | int flags; |
| 4654 | final Uri packageURI; |
| 4655 | final String installerPackageName; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4656 | private InstallArgs mArgs; |
| 4657 | private int mRet; |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4658 | InstallParams(Uri packageURI, |
| 4659 | IPackageInstallObserver observer, int flags, |
| 4660 | String installerPackageName) { |
| 4661 | this.packageURI = packageURI; |
| 4662 | this.flags = flags; |
| 4663 | this.observer = observer; |
| 4664 | this.installerPackageName = installerPackageName; |
| 4665 | } |
| 4666 | |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4667 | private int installLocationPolicy(PackageInfoLite pkgLite, int flags) { |
| 4668 | String packageName = pkgLite.packageName; |
| 4669 | int installLocation = pkgLite.installLocation; |
| 4670 | boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0; |
| 4671 | synchronized (mPackages) { |
| 4672 | PackageParser.Package pkg = mPackages.get(packageName); |
| 4673 | if (pkg != null) { |
| 4674 | if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
| 4675 | // Check for updated system application. |
| 4676 | if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4677 | if (onSd) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4678 | Slog.w(TAG, "Cannot install update to system app on sdcard"); |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4679 | return PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION; |
| 4680 | } |
| 4681 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
| 4682 | } else { |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4683 | if (onSd) { |
| 4684 | // Install flag overrides everything. |
| 4685 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4686 | } |
| Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4687 | // If current upgrade specifies particular preference |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4688 | if (installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) { |
| 4689 | // Application explicitly specified internal. |
| 4690 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
| 4691 | } else if (installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) { |
| 4692 | // App explictly prefers external. Let policy decide |
| Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4693 | } else { |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4694 | // Prefer previous location |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4695 | if (isExternal(pkg)) { |
| Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4696 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4697 | } |
| 4698 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4699 | } |
| 4700 | } |
| 4701 | } else { |
| 4702 | // Invalid install. Return error code |
| 4703 | return PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS; |
| 4704 | } |
| 4705 | } |
| 4706 | } |
| 4707 | // All the special cases have been taken care of. |
| 4708 | // Return result based on recommended install location. |
| 4709 | if (onSd) { |
| 4710 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4711 | } |
| 4712 | return pkgLite.recommendedInstallLocation; |
| 4713 | } |
| 4714 | |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4715 | /* |
| 4716 | * Invoke remote method to get package information and install |
| 4717 | * location values. Override install location based on default |
| 4718 | * policy if needed and then create install arguments based |
| 4719 | * on the install location. |
| 4720 | */ |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4721 | public void handleStartCopy() throws RemoteException { |
| Suchi Amalapurapu | 1f9e1b4 | 2010-02-26 13:14:31 -0800 | [diff] [blame] | 4722 | int ret = PackageManager.INSTALL_SUCCEEDED; |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4723 | boolean fwdLocked = (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0; |
| 4724 | boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0; |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4725 | boolean onInt = (flags & PackageManager.INSTALL_INTERNAL) != 0; |
| 4726 | if (onInt && onSd) { |
| 4727 | // Check if both bits are set. |
| 4728 | Slog.w(TAG, "Conflicting flags specified for installing on both internal and external"); |
| 4729 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 4730 | } else if (fwdLocked && onSd) { |
| 4731 | // Check for forward locked apps |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4732 | Slog.w(TAG, "Cannot install fwd locked apps on sdcard"); |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4733 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4734 | } else { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4735 | // Remote call to find out default install location |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4736 | PackageInfoLite pkgLite = mContainerService.getMinimalPackageInfo(packageURI, flags); |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4737 | int loc = pkgLite.recommendedInstallLocation; |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4738 | if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION){ |
| 4739 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 4740 | } else if (loc == PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS){ |
| 4741 | ret = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 4742 | } else if (loc == PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE){ |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4743 | ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4744 | } else if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_APK) { |
| 4745 | ret = PackageManager.INSTALL_FAILED_INVALID_APK; |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4746 | } else if (loc == PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE) { |
| 4747 | ret = PackageManager.INSTALL_FAILED_MEDIA_UNAVAILABLE; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4748 | } else { |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4749 | // Override with defaults if needed. |
| 4750 | loc = installLocationPolicy(pkgLite, flags); |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4751 | if (!onSd && !onInt) { |
| 4752 | // Override install location with flags |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4753 | if (loc == PackageHelper.RECOMMEND_INSTALL_EXTERNAL) { |
| 4754 | // Set the flag to install on external media. |
| 4755 | flags |= PackageManager.INSTALL_EXTERNAL; |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4756 | flags &= ~PackageManager.INSTALL_INTERNAL; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4757 | } else { |
| 4758 | // Make sure the flag for installing on external |
| 4759 | // media is unset |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4760 | flags |= PackageManager.INSTALL_INTERNAL; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4761 | flags &= ~PackageManager.INSTALL_EXTERNAL; |
| 4762 | } |
| 4763 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4764 | } |
| 4765 | } |
| 4766 | // Create the file args now. |
| 4767 | mArgs = createInstallArgs(this); |
| 4768 | if (ret == PackageManager.INSTALL_SUCCEEDED) { |
| 4769 | // Create copy only if we are not in an erroneous state. |
| 4770 | // Remote call to initiate copy using temporary file |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4771 | ret = mArgs.copyApk(mContainerService, true); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4772 | } |
| 4773 | mRet = ret; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4774 | } |
| 4775 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4776 | @Override |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4777 | void handleReturnCode() { |
| Kenny Root | 6f89fa0 | 2010-07-30 16:33:47 -0700 | [diff] [blame] | 4778 | // If mArgs is null, then MCS couldn't be reached. When it |
| 4779 | // reconnects, it will try again to install. At that point, this |
| 4780 | // will succeed. |
| 4781 | if (mArgs != null) { |
| 4782 | processPendingInstall(mArgs, mRet); |
| 4783 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4784 | } |
| 4785 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4786 | @Override |
| 4787 | void handleServiceError() { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4788 | mArgs = createInstallArgs(this); |
| 4789 | mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4790 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4791 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4792 | |
| 4793 | /* |
| 4794 | * Utility class used in movePackage api. |
| 4795 | * srcArgs and targetArgs are not set for invalid flags and make |
| 4796 | * sure to do null checks when invoking methods on them. |
| 4797 | * We probably want to return ErrorPrams for both failed installs |
| 4798 | * and moves. |
| 4799 | */ |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4800 | class MoveParams extends HandlerParams { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4801 | final IPackageMoveObserver observer; |
| 4802 | final int flags; |
| 4803 | final String packageName; |
| 4804 | final InstallArgs srcArgs; |
| 4805 | final InstallArgs targetArgs; |
| 4806 | int mRet; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4807 | |
| 4808 | MoveParams(InstallArgs srcArgs, IPackageMoveObserver observer, int flags, |
| 4809 | String packageName, String dataDir) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4810 | this.srcArgs = srcArgs; |
| 4811 | this.observer = observer; |
| 4812 | this.flags = flags; |
| 4813 | this.packageName = packageName; |
| 4814 | if (srcArgs != null) { |
| 4815 | Uri packageUri = Uri.fromFile(new File(srcArgs.getCodePath())); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4816 | targetArgs = createInstallArgs(packageUri, flags, packageName, dataDir); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4817 | } else { |
| 4818 | targetArgs = null; |
| 4819 | } |
| 4820 | } |
| 4821 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4822 | public void handleStartCopy() throws RemoteException { |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4823 | mRet = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4824 | // Check for storage space on target medium |
| 4825 | if (!targetArgs.checkFreeStorage(mContainerService)) { |
| 4826 | Log.w(TAG, "Insufficient storage to install"); |
| 4827 | return; |
| 4828 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4829 | // Create the file args now. |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4830 | mRet = targetArgs.copyApk(mContainerService, false); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4831 | targetArgs.doPreInstall(mRet); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4832 | if (DEBUG_SD_INSTALL) { |
| 4833 | StringBuilder builder = new StringBuilder(); |
| 4834 | if (srcArgs != null) { |
| 4835 | builder.append("src: "); |
| 4836 | builder.append(srcArgs.getCodePath()); |
| 4837 | } |
| 4838 | if (targetArgs != null) { |
| 4839 | builder.append(" target : "); |
| 4840 | builder.append(targetArgs.getCodePath()); |
| 4841 | } |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4842 | Log.i(TAG, builder.toString()); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4843 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4844 | } |
| 4845 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4846 | @Override |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4847 | void handleReturnCode() { |
| 4848 | targetArgs.doPostInstall(mRet); |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4849 | int currentStatus = PackageManager.MOVE_FAILED_INTERNAL_ERROR; |
| 4850 | if (mRet == PackageManager.INSTALL_SUCCEEDED) { |
| 4851 | currentStatus = PackageManager.MOVE_SUCCEEDED; |
| 4852 | } else if (mRet == PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE){ |
| 4853 | currentStatus = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE; |
| 4854 | } |
| 4855 | processPendingMove(this, currentStatus); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4856 | } |
| 4857 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4858 | @Override |
| 4859 | void handleServiceError() { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4860 | mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4861 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4862 | } |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4863 | |
| 4864 | private InstallArgs createInstallArgs(InstallParams params) { |
| 4865 | if (installOnSd(params.flags)) { |
| 4866 | return new SdInstallArgs(params); |
| 4867 | } else { |
| 4868 | return new FileInstallArgs(params); |
| 4869 | } |
| 4870 | } |
| 4871 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4872 | private InstallArgs createInstallArgs(int flags, String fullCodePath, String fullResourcePath, |
| 4873 | String nativeLibraryPath) { |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4874 | if (installOnSd(flags)) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4875 | return new SdInstallArgs(fullCodePath, fullResourcePath, nativeLibraryPath); |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4876 | } else { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4877 | return new FileInstallArgs(fullCodePath, fullResourcePath, nativeLibraryPath); |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4878 | } |
| 4879 | } |
| 4880 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4881 | // Used by package mover |
| 4882 | private InstallArgs createInstallArgs(Uri packageURI, int flags, String pkgName, String dataDir) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4883 | if (installOnSd(flags)) { |
| 4884 | String cid = getNextCodePath(null, pkgName, "/" + SdInstallArgs.RES_FILE_NAME); |
| 4885 | return new SdInstallArgs(packageURI, cid); |
| 4886 | } else { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4887 | return new FileInstallArgs(packageURI, pkgName, dataDir); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4888 | } |
| 4889 | } |
| 4890 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4891 | static abstract class InstallArgs { |
| 4892 | final IPackageInstallObserver observer; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4893 | // Always refers to PackageManager flags only |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4894 | final int flags; |
| 4895 | final Uri packageURI; |
| 4896 | final String installerPackageName; |
| 4897 | |
| 4898 | InstallArgs(Uri packageURI, |
| 4899 | IPackageInstallObserver observer, int flags, |
| 4900 | String installerPackageName) { |
| 4901 | this.packageURI = packageURI; |
| 4902 | this.flags = flags; |
| 4903 | this.observer = observer; |
| 4904 | this.installerPackageName = installerPackageName; |
| 4905 | } |
| 4906 | |
| 4907 | abstract void createCopyFile(); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4908 | abstract int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 4909 | abstract int doPreInstall(int status); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4910 | abstract boolean doRename(int status, String pkgName, String oldCodePath); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 4911 | abstract int doPostInstall(int status); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4912 | abstract String getCodePath(); |
| 4913 | abstract String getResourcePath(); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4914 | abstract String getNativeLibraryPath(); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4915 | // Need installer lock especially for dex file removal. |
| 4916 | abstract void cleanUpResourcesLI(); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 4917 | abstract boolean doPostDeleteLI(boolean delete); |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4918 | abstract boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4919 | } |
| 4920 | |
| 4921 | class FileInstallArgs extends InstallArgs { |
| 4922 | File installDir; |
| 4923 | String codeFileName; |
| 4924 | String resourceFileName; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4925 | String libraryPath; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4926 | boolean created = false; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4927 | |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4928 | FileInstallArgs(InstallParams params) { |
| 4929 | super(params.packageURI, params.observer, |
| 4930 | params.flags, params.installerPackageName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4931 | } |
| 4932 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4933 | FileInstallArgs(String fullCodePath, String fullResourcePath, String nativeLibraryPath) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4934 | super(null, null, 0, null); |
| 4935 | File codeFile = new File(fullCodePath); |
| 4936 | installDir = codeFile.getParentFile(); |
| 4937 | codeFileName = fullCodePath; |
| 4938 | resourceFileName = fullResourcePath; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4939 | libraryPath = nativeLibraryPath; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4940 | } |
| 4941 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4942 | FileInstallArgs(Uri packageURI, String pkgName, String dataDir) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4943 | super(packageURI, null, 0, null); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4944 | installDir = isFwdLocked() ? mDrmAppPrivateInstallDir : mAppInstallDir; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4945 | String apkName = getNextCodePath(null, pkgName, ".apk"); |
| 4946 | codeFileName = new File(installDir, apkName + ".apk").getPath(); |
| 4947 | resourceFileName = getResourcePathFromCodePath(); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4948 | libraryPath = new File(dataDir, LIB_DIR_NAME).getPath(); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4949 | } |
| 4950 | |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4951 | boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException { |
| 4952 | return imcs.checkFreeStorage(false, packageURI); |
| 4953 | } |
| 4954 | |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4955 | String getCodePath() { |
| 4956 | return codeFileName; |
| 4957 | } |
| 4958 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4959 | void createCopyFile() { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4960 | installDir = isFwdLocked() ? mDrmAppPrivateInstallDir : mAppInstallDir; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4961 | codeFileName = createTempPackageFile(installDir).getPath(); |
| 4962 | resourceFileName = getResourcePathFromCodePath(); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4963 | created = true; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4964 | } |
| 4965 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4966 | int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4967 | if (temp) { |
| 4968 | // Generate temp file name |
| 4969 | createCopyFile(); |
| 4970 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4971 | // Get a ParcelFileDescriptor to write to the output file |
| 4972 | File codeFile = new File(codeFileName); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4973 | if (!created) { |
| 4974 | try { |
| 4975 | codeFile.createNewFile(); |
| 4976 | // Set permissions |
| 4977 | if (!setPermissions()) { |
| 4978 | // Failed setting permissions. |
| 4979 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4980 | } |
| 4981 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4982 | Slog.w(TAG, "Failed to create file " + codeFile); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4983 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4984 | } |
| 4985 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4986 | ParcelFileDescriptor out = null; |
| 4987 | try { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4988 | out = ParcelFileDescriptor.open(codeFile, ParcelFileDescriptor.MODE_READ_WRITE); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4989 | } catch (FileNotFoundException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4990 | Slog.e(TAG, "Failed to create file descritpor for : " + codeFileName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4991 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4992 | } |
| 4993 | // Copy the resource now |
| 4994 | int ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4995 | try { |
| 4996 | if (imcs.copyResource(packageURI, out)) { |
| 4997 | ret = PackageManager.INSTALL_SUCCEEDED; |
| 4998 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4999 | } finally { |
| 5000 | try { if (out != null) out.close(); } catch (IOException e) {} |
| 5001 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5002 | |
| 5003 | if (!temp) { |
| 5004 | NativeLibraryHelper.copyNativeBinariesLI(codeFile, new File(libraryPath)); |
| 5005 | } |
| 5006 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5007 | return ret; |
| 5008 | } |
| 5009 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5010 | int doPreInstall(int status) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5011 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5012 | cleanUp(); |
| 5013 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5014 | return status; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | boolean doRename(int status, final String pkgName, String oldCodePath) { |
| 5018 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5019 | cleanUp(); |
| 5020 | return false; |
| 5021 | } else { |
| 5022 | // Rename based on packageName |
| 5023 | File codeFile = new File(getCodePath()); |
| 5024 | String apkName = getNextCodePath(oldCodePath, pkgName, ".apk"); |
| 5025 | File desFile = new File(installDir, apkName + ".apk"); |
| 5026 | if (!codeFile.renameTo(desFile)) { |
| 5027 | return false; |
| 5028 | } |
| 5029 | // Reset paths since the file has been renamed. |
| 5030 | codeFileName = desFile.getPath(); |
| 5031 | resourceFileName = getResourcePathFromCodePath(); |
| 5032 | // Set permissions |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5033 | if (!setPermissions()) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5034 | // Failed setting permissions. |
| 5035 | return false; |
| 5036 | } |
| 5037 | return true; |
| 5038 | } |
| 5039 | } |
| 5040 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5041 | int doPostInstall(int status) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5042 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5043 | cleanUp(); |
| 5044 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5045 | return status; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | String getResourcePath() { |
| 5049 | return resourceFileName; |
| 5050 | } |
| 5051 | |
| 5052 | String getResourcePathFromCodePath() { |
| 5053 | String codePath = getCodePath(); |
| 5054 | if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { |
| 5055 | String apkNameOnly = getApkName(codePath); |
| 5056 | return mAppInstallDir.getPath() + "/" + apkNameOnly + ".zip"; |
| 5057 | } else { |
| 5058 | return codePath; |
| 5059 | } |
| 5060 | } |
| 5061 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5062 | @Override |
| 5063 | String getNativeLibraryPath() { |
| 5064 | return libraryPath; |
| 5065 | } |
| 5066 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5067 | private boolean cleanUp() { |
| 5068 | boolean ret = true; |
| 5069 | String sourceDir = getCodePath(); |
| 5070 | String publicSourceDir = getResourcePath(); |
| 5071 | if (sourceDir != null) { |
| 5072 | File sourceFile = new File(sourceDir); |
| 5073 | if (!sourceFile.exists()) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5074 | Slog.w(TAG, "Package source " + sourceDir + " does not exist."); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5075 | ret = false; |
| 5076 | } |
| 5077 | // Delete application's code and resources |
| 5078 | sourceFile.delete(); |
| 5079 | } |
| 5080 | if (publicSourceDir != null && !publicSourceDir.equals(sourceDir)) { |
| 5081 | final File publicSourceFile = new File(publicSourceDir); |
| 5082 | if (!publicSourceFile.exists()) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5083 | Slog.w(TAG, "Package public source " + publicSourceFile + " does not exist."); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5084 | } |
| 5085 | if (publicSourceFile.exists()) { |
| 5086 | publicSourceFile.delete(); |
| 5087 | } |
| 5088 | } |
| 5089 | return ret; |
| 5090 | } |
| 5091 | |
| 5092 | void cleanUpResourcesLI() { |
| 5093 | String sourceDir = getCodePath(); |
| 5094 | if (cleanUp() && mInstaller != null) { |
| 5095 | int retCode = mInstaller.rmdex(sourceDir); |
| 5096 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5097 | Slog.w(TAG, "Couldn't remove dex file for package: " |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5098 | + " at location " |
| 5099 | + sourceDir + ", retcode=" + retCode); |
| 5100 | // we don't consider this to be a failure of the core package deletion |
| 5101 | } |
| 5102 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5103 | if (libraryPath != null) { |
| Kenny Root | 8f7cc02 | 2010-09-12 09:04:56 -0700 | [diff] [blame] | 5104 | NativeLibraryHelper.removeNativeBinariesLI(libraryPath); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5105 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5106 | } |
| 5107 | |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5108 | private boolean setPermissions() { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5109 | // TODO Do this in a more elegant way later on. for now just a hack |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5110 | if (!isFwdLocked()) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5111 | final int filePermissions = |
| 5112 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP |
| 5113 | |FileUtils.S_IROTH; |
| 5114 | int retCode = FileUtils.setPermissions(getCodePath(), filePermissions, -1, -1); |
| 5115 | if (retCode != 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5116 | Slog.e(TAG, "Couldn't set new package file permissions for " + |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5117 | getCodePath() |
| 5118 | + ". The return code was: " + retCode); |
| 5119 | // TODO Define new internal error |
| 5120 | return false; |
| 5121 | } |
| 5122 | return true; |
| 5123 | } |
| 5124 | return true; |
| 5125 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5126 | |
| 5127 | boolean doPostDeleteLI(boolean delete) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5128 | // XXX err, shouldn't we respect the delete flag? |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5129 | cleanUpResourcesLI(); |
| 5130 | return true; |
| 5131 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5132 | |
| 5133 | private boolean isFwdLocked() { |
| 5134 | return (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0; |
| 5135 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5136 | } |
| 5137 | |
| 5138 | class SdInstallArgs extends InstallArgs { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5139 | static final String RES_FILE_NAME = "pkg.apk"; |
| 5140 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5141 | String cid; |
| 5142 | String packagePath; |
| 5143 | String libraryPath; |
| 5144 | |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5145 | SdInstallArgs(InstallParams params) { |
| 5146 | super(params.packageURI, params.observer, |
| 5147 | params.flags, params.installerPackageName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5148 | } |
| 5149 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5150 | SdInstallArgs(String fullCodePath, String fullResourcePath, String nativeLibraryPath) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5151 | super(null, null, PackageManager.INSTALL_EXTERNAL, null); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5152 | // Extract cid from fullCodePath |
| 5153 | int eidx = fullCodePath.lastIndexOf("/"); |
| 5154 | String subStr1 = fullCodePath.substring(0, eidx); |
| 5155 | int sidx = subStr1.lastIndexOf("/"); |
| 5156 | cid = subStr1.substring(sidx+1, eidx); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5157 | setCachePath(subStr1); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5158 | } |
| 5159 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5160 | SdInstallArgs(String cid) { |
| Dianne Hackborn | aa77de1 | 2010-05-14 22:33:54 -0700 | [diff] [blame] | 5161 | super(null, null, PackageManager.INSTALL_EXTERNAL, null); |
| 5162 | this.cid = cid; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5163 | setCachePath(PackageHelper.getSdDir(cid)); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | SdInstallArgs(Uri packageURI, String cid) { |
| 5167 | super(packageURI, null, PackageManager.INSTALL_EXTERNAL, null); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5168 | this.cid = cid; |
| 5169 | } |
| 5170 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5171 | void createCopyFile() { |
| 5172 | cid = getTempContainerId(); |
| 5173 | } |
| 5174 | |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 5175 | boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException { |
| 5176 | return imcs.checkFreeStorage(true, packageURI); |
| 5177 | } |
| 5178 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5179 | int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5180 | if (temp) { |
| 5181 | createCopyFile(); |
| 5182 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5183 | String newCachePath = imcs.copyResourceToContainer( |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5184 | packageURI, cid, |
| 5185 | getEncryptKey(), RES_FILE_NAME); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5186 | if (newCachePath != null) { |
| 5187 | setCachePath(newCachePath); |
| 5188 | return PackageManager.INSTALL_SUCCEEDED; |
| 5189 | } else { |
| 5190 | return PackageManager.INSTALL_FAILED_CONTAINER_ERROR; |
| 5191 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5192 | } |
| 5193 | |
| 5194 | @Override |
| 5195 | String getCodePath() { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5196 | return packagePath; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | @Override |
| 5200 | String getResourcePath() { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5201 | return packagePath; |
| 5202 | } |
| 5203 | |
| 5204 | @Override |
| 5205 | String getNativeLibraryPath() { |
| 5206 | return libraryPath; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5207 | } |
| 5208 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5209 | int doPreInstall(int status) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5210 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5211 | // Destroy container |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5212 | PackageHelper.destroySdDir(cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5213 | } else { |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5214 | boolean mounted = PackageHelper.isContainerMounted(cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5215 | if (!mounted) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5216 | String newCachePath = PackageHelper.mountSdDir(cid, getEncryptKey(), |
| 5217 | Process.SYSTEM_UID); |
| 5218 | if (newCachePath != null) { |
| 5219 | setCachePath(newCachePath); |
| 5220 | } else { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5221 | return PackageManager.INSTALL_FAILED_CONTAINER_ERROR; |
| 5222 | } |
| 5223 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5224 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5225 | return status; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | boolean doRename(int status, final String pkgName, |
| 5229 | String oldCodePath) { |
| 5230 | String newCacheId = getNextCodePath(oldCodePath, pkgName, "/" + RES_FILE_NAME); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5231 | String newCachePath = null; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5232 | if (PackageHelper.isContainerMounted(cid)) { |
| 5233 | // Unmount the container |
| 5234 | if (!PackageHelper.unMountSdDir(cid)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5235 | Slog.i(TAG, "Failed to unmount " + cid + " before renaming"); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5236 | return false; |
| 5237 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5238 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5239 | if (!PackageHelper.renameSdDir(cid, newCacheId)) { |
| Suchi Amalapurapu | c7537ee | 2010-03-24 09:27:19 -0700 | [diff] [blame] | 5240 | Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId + |
| 5241 | " which might be stale. Will try to clean up."); |
| 5242 | // Clean up the stale container and proceed to recreate. |
| 5243 | if (!PackageHelper.destroySdDir(newCacheId)) { |
| 5244 | Slog.e(TAG, "Very strange. Cannot clean up stale container " + newCacheId); |
| 5245 | return false; |
| 5246 | } |
| 5247 | // Successfully cleaned up stale container. Try to rename again. |
| 5248 | if (!PackageHelper.renameSdDir(cid, newCacheId)) { |
| 5249 | Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId |
| 5250 | + " inspite of cleaning it up."); |
| 5251 | return false; |
| 5252 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5253 | } |
| 5254 | if (!PackageHelper.isContainerMounted(newCacheId)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5255 | Slog.w(TAG, "Mounting container " + newCacheId); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5256 | newCachePath = PackageHelper.mountSdDir(newCacheId, |
| 5257 | getEncryptKey(), Process.SYSTEM_UID); |
| 5258 | } else { |
| 5259 | newCachePath = PackageHelper.getSdDir(newCacheId); |
| 5260 | } |
| 5261 | if (newCachePath == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5262 | Slog.w(TAG, "Failed to get cache path for " + newCacheId); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5263 | return false; |
| 5264 | } |
| 5265 | Log.i(TAG, "Succesfully renamed " + cid + |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5266 | " to " + newCacheId + |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5267 | " at new path: " + newCachePath); |
| 5268 | cid = newCacheId; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5269 | setCachePath(newCachePath); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5270 | return true; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5271 | } |
| 5272 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5273 | private void setCachePath(String newCachePath) { |
| 5274 | File cachePath = new File(newCachePath); |
| 5275 | libraryPath = new File(cachePath, LIB_DIR_NAME).getPath(); |
| 5276 | packagePath = new File(cachePath, RES_FILE_NAME).getPath(); |
| 5277 | } |
| 5278 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5279 | int doPostInstall(int status) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5280 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5281 | cleanUp(); |
| 5282 | } else { |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5283 | boolean mounted = PackageHelper.isContainerMounted(cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5284 | if (!mounted) { |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5285 | PackageHelper.mountSdDir(cid, |
| 5286 | getEncryptKey(), Process.myUid()); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5287 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5288 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5289 | return status; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | private void cleanUp() { |
| 5293 | // Destroy secure container |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5294 | PackageHelper.destroySdDir(cid); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5295 | } |
| 5296 | |
| 5297 | void cleanUpResourcesLI() { |
| 5298 | String sourceFile = getCodePath(); |
| 5299 | // Remove dex file |
| 5300 | if (mInstaller != null) { |
| Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 5301 | int retCode = mInstaller.rmdex(sourceFile); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5302 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5303 | Slog.w(TAG, "Couldn't remove dex file for package: " |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5304 | + " at location " |
| 5305 | + sourceFile.toString() + ", retcode=" + retCode); |
| 5306 | // we don't consider this to be a failure of the core package deletion |
| 5307 | } |
| 5308 | } |
| 5309 | cleanUp(); |
| 5310 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5311 | |
| 5312 | boolean matchContainer(String app) { |
| 5313 | if (cid.startsWith(app)) { |
| 5314 | return true; |
| 5315 | } |
| 5316 | return false; |
| 5317 | } |
| 5318 | |
| 5319 | String getPackageName() { |
| 5320 | int idx = cid.lastIndexOf("-"); |
| 5321 | if (idx == -1) { |
| 5322 | return cid; |
| 5323 | } |
| 5324 | return cid.substring(0, idx); |
| 5325 | } |
| 5326 | |
| 5327 | boolean doPostDeleteLI(boolean delete) { |
| 5328 | boolean ret = false; |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5329 | boolean mounted = PackageHelper.isContainerMounted(cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5330 | if (mounted) { |
| 5331 | // Unmount first |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5332 | ret = PackageHelper.unMountSdDir(cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5333 | } |
| 5334 | if (ret && delete) { |
| 5335 | cleanUpResourcesLI(); |
| 5336 | } |
| 5337 | return ret; |
| 5338 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5339 | }; |
| 5340 | |
| 5341 | // Utility method used to create code paths based on package name and available index. |
| 5342 | private static String getNextCodePath(String oldCodePath, String prefix, String suffix) { |
| 5343 | String idxStr = ""; |
| 5344 | int idx = 1; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5345 | // Fall back to default value of idx=1 if prefix is not |
| 5346 | // part of oldCodePath |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5347 | if (oldCodePath != null) { |
| Bjorn Bringert | 5fd5bfe | 2010-01-29 12:11:30 +0000 | [diff] [blame] | 5348 | String subStr = oldCodePath; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5349 | // Drop the suffix right away |
| Bjorn Bringert | 5fd5bfe | 2010-01-29 12:11:30 +0000 | [diff] [blame] | 5350 | if (subStr.endsWith(suffix)) { |
| 5351 | subStr = subStr.substring(0, subStr.length() - suffix.length()); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5352 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5353 | // If oldCodePath already contains prefix find out the |
| 5354 | // ending index to either increment or decrement. |
| 5355 | int sidx = subStr.lastIndexOf(prefix); |
| 5356 | if (sidx != -1) { |
| 5357 | subStr = subStr.substring(sidx + prefix.length()); |
| 5358 | if (subStr != null) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5359 | if (subStr.startsWith(INSTALL_PACKAGE_SUFFIX)) { |
| 5360 | subStr = subStr.substring(INSTALL_PACKAGE_SUFFIX.length()); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5361 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5362 | try { |
| 5363 | idx = Integer.parseInt(subStr); |
| 5364 | if (idx <= 1) { |
| 5365 | idx++; |
| 5366 | } else { |
| 5367 | idx--; |
| 5368 | } |
| 5369 | } catch(NumberFormatException e) { |
| 5370 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5371 | } |
| 5372 | } |
| 5373 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5374 | idxStr = INSTALL_PACKAGE_SUFFIX + Integer.toString(idx); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5375 | return prefix + idxStr; |
| 5376 | } |
| 5377 | |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5378 | // Utility method used to ignore ADD/REMOVE events |
| 5379 | // by directory observer. |
| 5380 | private static boolean ignoreCodePath(String fullPathStr) { |
| 5381 | String apkName = getApkName(fullPathStr); |
| 5382 | int idx = apkName.lastIndexOf(INSTALL_PACKAGE_SUFFIX); |
| 5383 | if (idx != -1 && ((idx+1) < apkName.length())) { |
| 5384 | // Make sure the package ends with a numeral |
| 5385 | String version = apkName.substring(idx+1); |
| 5386 | try { |
| 5387 | Integer.parseInt(version); |
| 5388 | return true; |
| 5389 | } catch (NumberFormatException e) {} |
| 5390 | } |
| 5391 | return false; |
| 5392 | } |
| 5393 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5394 | // Utility method that returns the relative package path with respect |
| 5395 | // to the installation directory. Like say for /data/data/com.test-1.apk |
| 5396 | // string com.test-1 is returned. |
| 5397 | static String getApkName(String codePath) { |
| 5398 | if (codePath == null) { |
| 5399 | return null; |
| 5400 | } |
| 5401 | int sidx = codePath.lastIndexOf("/"); |
| 5402 | int eidx = codePath.lastIndexOf("."); |
| 5403 | if (eidx == -1) { |
| 5404 | eidx = codePath.length(); |
| 5405 | } else if (eidx == 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5406 | Slog.w(TAG, " Invalid code path, "+ codePath + " Not a valid apk name"); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5407 | return null; |
| 5408 | } |
| 5409 | return codePath.substring(sidx+1, eidx); |
| 5410 | } |
| 5411 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5412 | class PackageInstalledInfo { |
| 5413 | String name; |
| 5414 | int uid; |
| 5415 | PackageParser.Package pkg; |
| 5416 | int returnCode; |
| 5417 | PackageRemovedInfo removedInfo; |
| 5418 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5419 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5420 | /* |
| 5421 | * Install a non-existing package. |
| 5422 | */ |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5423 | private void installNewPackageLI(PackageParser.Package pkg, |
| 5424 | int parseFlags, |
| 5425 | int scanMode, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5426 | String installerPackageName, PackageInstalledInfo res) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5427 | // Remember this for later, in case we need to rollback this install |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5428 | String pkgName = pkg.packageName; |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 5429 | |
| Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 5430 | boolean dataDirExists = getDataPathForPackage(pkg).exists(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5431 | res.name = pkgName; |
| 5432 | synchronized(mPackages) { |
| Dianne Hackborn | e259bc7 | 2010-03-30 19:24:44 -0700 | [diff] [blame] | 5433 | if (mSettings.mRenamedPackages.containsKey(pkgName)) { |
| 5434 | // A package with the same name is already installed, though |
| 5435 | // it has been renamed to an older name. The package we |
| 5436 | // are trying to install should be installed as an update to |
| 5437 | // the existing one, but that has not been requested, so bail. |
| 5438 | Slog.w(TAG, "Attempt to re-install " + pkgName |
| 5439 | + " without first uninstalling package running as " |
| 5440 | + mSettings.mRenamedPackages.get(pkgName)); |
| 5441 | res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 5442 | return; |
| 5443 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5444 | if (mPackages.containsKey(pkgName) || mAppDirs.containsKey(pkg.mPath)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5445 | // Don't allow installation over an existing package with the same name. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5446 | Slog.w(TAG, "Attempt to re-install " + pkgName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5447 | + " without first uninstalling."); |
| 5448 | res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 5449 | return; |
| 5450 | } |
| 5451 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5452 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5453 | PackageParser.Package newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5454 | if (newPackage == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5455 | Slog.w(TAG, "Package couldn't be installed in " + pkg.mPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5456 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5457 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 5458 | } |
| 5459 | } else { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5460 | updateSettingsLI(newPackage, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5461 | installerPackageName, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5462 | res); |
| 5463 | // delete the partially installed application. the data directory will have to be |
| 5464 | // restored if it was already existing |
| 5465 | if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
| 5466 | // remove package from internal structures. Note that we want deletePackageX to |
| 5467 | // delete the package data and cache directories that it created in |
| 5468 | // scanPackageLocked, unless those directories existed before we even tried to |
| 5469 | // install. |
| 5470 | deletePackageLI( |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5471 | pkgName, false, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5472 | dataDirExists ? PackageManager.DONT_DELETE_DATA : 0, |
| 5473 | res.removedInfo); |
| 5474 | } |
| 5475 | } |
| 5476 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5477 | |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5478 | private void replacePackageLI(PackageParser.Package pkg, |
| 5479 | int parseFlags, |
| 5480 | int scanMode, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5481 | String installerPackageName, PackageInstalledInfo res) { |
| 5482 | |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 5483 | PackageParser.Package oldPackage; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5484 | String pkgName = pkg.packageName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5485 | // First find the old package info and check signatures |
| 5486 | synchronized(mPackages) { |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 5487 | oldPackage = mPackages.get(pkgName); |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5488 | if (checkSignaturesLP(oldPackage.mSignatures, pkg.mSignatures) |
| Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 5489 | != PackageManager.SIGNATURE_MATCH) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5490 | res.returnCode = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 5491 | return; |
| 5492 | } |
| 5493 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5494 | boolean sysPkg = (isSystemApp(oldPackage)); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5495 | if (sysPkg) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5496 | replaceSystemPackageLI(oldPackage, pkg, parseFlags, scanMode, installerPackageName, res); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5497 | } else { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5498 | replaceNonSystemPackageLI(oldPackage, pkg, parseFlags, scanMode, installerPackageName, res); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5499 | } |
| 5500 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5501 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5502 | private void replaceNonSystemPackageLI(PackageParser.Package deletedPackage, |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5503 | PackageParser.Package pkg, |
| 5504 | int parseFlags, int scanMode, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5505 | String installerPackageName, PackageInstalledInfo res) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5506 | PackageParser.Package newPackage = null; |
| 5507 | String pkgName = deletedPackage.packageName; |
| 5508 | boolean deletedPkg = true; |
| 5509 | boolean updatedSettings = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5510 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5511 | String oldInstallerPackageName = null; |
| 5512 | synchronized (mPackages) { |
| 5513 | oldInstallerPackageName = mSettings.getInstallerPackageName(pkgName); |
| 5514 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5515 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5516 | // First delete the existing package while retaining the data directory |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5517 | if (!deletePackageLI(pkgName, true, PackageManager.DONT_DELETE_DATA, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5518 | res.removedInfo)) { |
| 5519 | // If the existing package was'nt successfully deleted |
| 5520 | res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE; |
| 5521 | deletedPkg = false; |
| 5522 | } else { |
| 5523 | // Successfully deleted the old package. Now proceed with re-installation |
| 5524 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5525 | newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5526 | if (newPackage == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5527 | Slog.w(TAG, "Package couldn't be installed in " + pkg.mPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5528 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5529 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
| Suchi Amalapurapu | 110fea7 | 2010-01-14 17:50:23 -0800 | [diff] [blame] | 5530 | } |
| 5531 | } else { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5532 | updateSettingsLI(newPackage, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5533 | installerPackageName, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5534 | res); |
| 5535 | updatedSettings = true; |
| 5536 | } |
| 5537 | } |
| 5538 | |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5539 | if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5540 | // remove package from internal structures. Note that we want deletePackageX to |
| 5541 | // delete the package data and cache directories that it created in |
| 5542 | // scanPackageLocked, unless those directories existed before we even tried to |
| 5543 | // install. |
| 5544 | if(updatedSettings) { |
| 5545 | deletePackageLI( |
| 5546 | pkgName, true, |
| 5547 | PackageManager.DONT_DELETE_DATA, |
| 5548 | res.removedInfo); |
| 5549 | } |
| 5550 | // Since we failed to install the new package we need to restore the old |
| 5551 | // package that we deleted. |
| 5552 | if(deletedPkg) { |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5553 | File restoreFile = new File(deletedPackage.mPath); |
| 5554 | if (restoreFile == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5555 | Slog.e(TAG, "Failed allocating storage when restoring pkg : " + pkgName); |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5556 | return; |
| 5557 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5558 | // Parse old package |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5559 | boolean oldOnSd = isExternal(deletedPackage); |
| 5560 | int oldParseFlags = mDefParseFlags | PackageParser.PARSE_CHATTY | |
| 5561 | (isForwardLocked(deletedPackage) ? PackageParser.PARSE_FORWARD_LOCK : 0) | |
| 5562 | (oldOnSd ? PackageParser.PARSE_ON_SDCARD : 0); |
| 5563 | int oldScanMode = (oldOnSd ? 0 : SCAN_MONITOR) | SCAN_UPDATE_SIGNATURE; |
| 5564 | if (scanPackageLI(restoreFile, oldParseFlags, oldScanMode) == null) { |
| 5565 | Slog.e(TAG, "Failed to restore package : " + pkgName + " after failed upgrade"); |
| 5566 | return; |
| 5567 | } |
| 5568 | // Restore of old package succeeded. Update permissions. |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5569 | synchronized (mPackages) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 5570 | updatePermissionsLP(deletedPackage.packageName, deletedPackage, |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 5571 | true, false, false); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5572 | mSettings.writeLP(); |
| 5573 | } |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5574 | Slog.i(TAG, "Successfully restored package : " + pkgName + " after failed upgrade"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | } |
| 5576 | } |
| 5577 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5579 | private void replaceSystemPackageLI(PackageParser.Package deletedPackage, |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5580 | PackageParser.Package pkg, |
| 5581 | int parseFlags, int scanMode, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5582 | String installerPackageName, PackageInstalledInfo res) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5583 | PackageParser.Package newPackage = null; |
| 5584 | boolean updatedSettings = false; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5585 | parseFlags |= PackageManager.INSTALL_REPLACE_EXISTING | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5586 | PackageParser.PARSE_IS_SYSTEM; |
| 5587 | String packageName = deletedPackage.packageName; |
| 5588 | res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE; |
| 5589 | if (packageName == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5590 | Slog.w(TAG, "Attempt to delete null packageName."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5591 | return; |
| 5592 | } |
| 5593 | PackageParser.Package oldPkg; |
| 5594 | PackageSetting oldPkgSetting; |
| 5595 | synchronized (mPackages) { |
| 5596 | oldPkg = mPackages.get(packageName); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5597 | oldPkgSetting = mSettings.mPackages.get(packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5598 | if((oldPkg == null) || (oldPkg.applicationInfo == null) || |
| 5599 | (oldPkgSetting == null)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5600 | Slog.w(TAG, "Couldn't find package:"+packageName+" information"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5601 | return; |
| 5602 | } |
| 5603 | } |
| 5604 | res.removedInfo.uid = oldPkg.applicationInfo.uid; |
| 5605 | res.removedInfo.removedPackage = packageName; |
| 5606 | // Remove existing system package |
| 5607 | removePackageLI(oldPkg, true); |
| 5608 | synchronized (mPackages) { |
| 5609 | res.removedInfo.removedUid = mSettings.disableSystemPackageLP(packageName); |
| 5610 | } |
| 5611 | |
| 5612 | // Successfully disabled the old package. Now proceed with re-installation |
| 5613 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
| 5614 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5615 | newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5616 | if (newPackage == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5617 | Slog.w(TAG, "Package couldn't be installed in " + pkg.mPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5618 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5619 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 5620 | } |
| 5621 | } else { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5622 | updateSettingsLI(newPackage, installerPackageName, res); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5623 | updatedSettings = true; |
| 5624 | } |
| 5625 | |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5626 | if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5627 | // Re installation failed. Restore old information |
| 5628 | // Remove new pkg information |
| Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 5629 | if (newPackage != null) { |
| 5630 | removePackageLI(newPackage, true); |
| 5631 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5632 | // Add back the old system package |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5633 | scanPackageLI(oldPkg, parseFlags, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5634 | SCAN_MONITOR |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5635 | | SCAN_UPDATE_SIGNATURE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5636 | // Restore the old system information in Settings |
| 5637 | synchronized(mPackages) { |
| 5638 | if(updatedSettings) { |
| 5639 | mSettings.enableSystemPackageLP(packageName); |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5640 | mSettings.setInstallerPackageName(packageName, |
| 5641 | oldPkgSetting.installerPackageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5642 | } |
| 5643 | mSettings.writeLP(); |
| 5644 | } |
| Suchi Amalapurapu | c1d07d9 | 2010-05-05 13:37:12 -0700 | [diff] [blame] | 5645 | } else { |
| 5646 | // If this is an update to an existing update, setup |
| 5647 | // to remove the existing update. |
| 5648 | synchronized (mPackages) { |
| 5649 | PackageSetting ps = mSettings.getDisabledSystemPkg(packageName); |
| 5650 | if (ps != null && ps.codePathString != null && |
| 5651 | !ps.codePathString.equals(oldPkgSetting.codePathString)) { |
| 5652 | int installFlags = 0; |
| 5653 | res.removedInfo.args = createInstallArgs(0, oldPkgSetting.codePathString, |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5654 | oldPkgSetting.resourcePathString, oldPkgSetting.nativeLibraryPathString); |
| Suchi Amalapurapu | c1d07d9 | 2010-05-05 13:37:12 -0700 | [diff] [blame] | 5655 | } |
| 5656 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5657 | } |
| 5658 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5659 | |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5660 | // Utility method used to move dex files during install. |
| Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 5661 | private int moveDexFilesLI(PackageParser.Package newPackage) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5662 | int retCode; |
| 5663 | if ((newPackage.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 5664 | retCode = mInstaller.movedex(newPackage.mScanPath, newPackage.mPath); |
| 5665 | if (retCode != 0) { |
| Kenny Root | e2f7417 | 2010-08-04 13:35:33 -0700 | [diff] [blame] | 5666 | if (mNoDexOpt) { |
| 5667 | /* |
| 5668 | * If we're in an engineering build, programs are lazily run |
| 5669 | * through dexopt. If the .dex file doesn't exist yet, it |
| 5670 | * will be created when the program is run next. |
| 5671 | */ |
| 5672 | Slog.i(TAG, "dex file doesn't exist, skipping move: " + newPackage.mPath); |
| 5673 | } else { |
| 5674 | Slog.e(TAG, "Couldn't rename dex file: " + newPackage.mPath); |
| 5675 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5676 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5677 | } |
| 5678 | } |
| 5679 | return PackageManager.INSTALL_SUCCEEDED; |
| 5680 | } |
| 5681 | |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5682 | private void updateSettingsLI(PackageParser.Package newPackage, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5683 | String installerPackageName, PackageInstalledInfo res) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5684 | String pkgName = newPackage.packageName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5685 | synchronized (mPackages) { |
| 5686 | //write settings. the installStatus will be incomplete at this stage. |
| 5687 | //note that the new package setting would have already been |
| 5688 | //added to mPackages. It hasn't been persisted yet. |
| 5689 | mSettings.setInstallStatus(pkgName, PKG_INSTALL_INCOMPLETE); |
| 5690 | mSettings.writeLP(); |
| 5691 | } |
| 5692 | |
| Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 5693 | if ((res.returnCode = moveDexFilesLI(newPackage)) |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5694 | != PackageManager.INSTALL_SUCCEEDED) { |
| 5695 | // Discontinue if moving dex files failed. |
| 5696 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5697 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5698 | if((res.returnCode = setPermissionsLI(newPackage)) |
| 5699 | != PackageManager.INSTALL_SUCCEEDED) { |
| 5700 | if (mInstaller != null) { |
| 5701 | mInstaller.rmdex(newPackage.mScanPath); |
| 5702 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5703 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5704 | } else { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5705 | Log.d(TAG, "New package installed in " + newPackage.mPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5706 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5707 | synchronized (mPackages) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 5708 | updatePermissionsLP(newPackage.packageName, newPackage, |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 5709 | newPackage.permissions.size() > 0, true, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5710 | res.name = pkgName; |
| 5711 | res.uid = newPackage.applicationInfo.uid; |
| 5712 | res.pkg = newPackage; |
| 5713 | mSettings.setInstallStatus(pkgName, PKG_INSTALL_COMPLETE); |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5714 | mSettings.setInstallerPackageName(pkgName, installerPackageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5715 | res.returnCode = PackageManager.INSTALL_SUCCEEDED; |
| 5716 | //to update install status |
| 5717 | mSettings.writeLP(); |
| 5718 | } |
| 5719 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5720 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5721 | private void installPackageLI(InstallArgs args, |
| 5722 | boolean newInstall, PackageInstalledInfo res) { |
| 5723 | int pFlags = args.flags; |
| 5724 | String installerPackageName = args.installerPackageName; |
| 5725 | File tmpPackageFile = new File(args.getCodePath()); |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5726 | boolean forwardLocked = ((pFlags & PackageManager.INSTALL_FORWARD_LOCK) != 0); |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5727 | boolean onSd = ((pFlags & PackageManager.INSTALL_EXTERNAL) != 0); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5728 | boolean replace = false; |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5729 | int scanMode = (onSd ? 0 : SCAN_MONITOR) | SCAN_FORCE_DEX | SCAN_UPDATE_SIGNATURE |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5730 | | (newInstall ? SCAN_NEW_INSTALL : 0); |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5731 | // Result object to be returned |
| 5732 | res.returnCode = PackageManager.INSTALL_SUCCEEDED; |
| 5733 | |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5734 | // Retrieve PackageSettings and parse package |
| 5735 | int parseFlags = PackageParser.PARSE_CHATTY | |
| 5736 | (forwardLocked ? PackageParser.PARSE_FORWARD_LOCK : 0) | |
| 5737 | (onSd ? PackageParser.PARSE_ON_SDCARD : 0); |
| 5738 | parseFlags |= mDefParseFlags; |
| 5739 | PackageParser pp = new PackageParser(tmpPackageFile.getPath()); |
| 5740 | pp.setSeparateProcesses(mSeparateProcesses); |
| 5741 | final PackageParser.Package pkg = pp.parsePackage(tmpPackageFile, |
| 5742 | null, mMetrics, parseFlags); |
| 5743 | if (pkg == null) { |
| 5744 | res.returnCode = pp.getParseError(); |
| 5745 | return; |
| 5746 | } |
| 5747 | String pkgName = res.name = pkg.packageName; |
| 5748 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_TEST_ONLY) != 0) { |
| 5749 | if ((pFlags&PackageManager.INSTALL_ALLOW_TEST) == 0) { |
| 5750 | res.returnCode = PackageManager.INSTALL_FAILED_TEST_ONLY; |
| 5751 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5752 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5753 | } |
| 5754 | if (GET_CERTIFICATES && !pp.collectCertificates(pkg, parseFlags)) { |
| 5755 | res.returnCode = pp.getParseError(); |
| 5756 | return; |
| 5757 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5758 | // Get rid of all references to package scan path via parser. |
| 5759 | pp = null; |
| 5760 | String oldCodePath = null; |
| 5761 | boolean systemApp = false; |
| 5762 | synchronized (mPackages) { |
| 5763 | // Check if installing already existing package |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5764 | if ((pFlags&PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
| 5765 | String oldName = mSettings.mRenamedPackages.get(pkgName); |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 5766 | if (pkg.mOriginalPackages != null |
| 5767 | && pkg.mOriginalPackages.contains(oldName) |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5768 | && mPackages.containsKey(oldName)) { |
| 5769 | // This package is derived from an original package, |
| 5770 | // and this device has been updating from that original |
| 5771 | // name. We must continue using the original name, so |
| 5772 | // rename the new package here. |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 5773 | pkg.setPackageName(oldName); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5774 | pkgName = pkg.packageName; |
| 5775 | replace = true; |
| 5776 | } else if (mPackages.containsKey(pkgName)) { |
| 5777 | // This package, under its official name, already exists |
| 5778 | // on the device; we should replace it. |
| 5779 | replace = true; |
| 5780 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5781 | } |
| 5782 | PackageSetting ps = mSettings.mPackages.get(pkgName); |
| 5783 | if (ps != null) { |
| 5784 | oldCodePath = mSettings.mPackages.get(pkgName).codePathString; |
| 5785 | if (ps.pkg != null && ps.pkg.applicationInfo != null) { |
| 5786 | systemApp = (ps.pkg.applicationInfo.flags & |
| 5787 | ApplicationInfo.FLAG_SYSTEM) != 0; |
| Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 5788 | } |
| 5789 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5790 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5791 | |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5792 | if (systemApp && onSd) { |
| 5793 | // Disable updates to system apps on sdcard |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5794 | Slog.w(TAG, "Cannot install updates to system apps on sdcard"); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5795 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 5796 | return; |
| 5797 | } |
| Suchi Amalapurapu | cf6eaea | 2010-02-23 19:37:45 -0800 | [diff] [blame] | 5798 | |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5799 | if (!args.doRename(res.returnCode, pkgName, oldCodePath)) { |
| 5800 | res.returnCode = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5801 | return; |
| 5802 | } |
| 5803 | // Set application objects path explicitly after the rename |
| 5804 | setApplicationInfoPaths(pkg, args.getCodePath(), args.getResourcePath()); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5805 | pkg.applicationInfo.nativeLibraryDir = args.getNativeLibraryPath(); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5806 | if (replace) { |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5807 | replacePackageLI(pkg, parseFlags, scanMode, |
| 5808 | installerPackageName, res); |
| 5809 | } else { |
| 5810 | installNewPackageLI(pkg, parseFlags, scanMode, |
| 5811 | installerPackageName,res); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5812 | } |
| 5813 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5814 | |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5815 | private int setPermissionsLI(PackageParser.Package newPackage) { |
| 5816 | String pkgName = newPackage.packageName; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5817 | int retCode = 0; |
| 5818 | // TODO Gross hack but fix later. Ideally move this to be a post installation |
| 5819 | // check after alloting uid. |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5820 | if (isForwardLocked(newPackage)) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5821 | File destResourceFile = new File(newPackage.applicationInfo.publicSourceDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | try { |
| 5823 | extractPublicFiles(newPackage, destResourceFile); |
| 5824 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5825 | Slog.e(TAG, "Couldn't create a new zip file for the public parts of a" + |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5826 | " forward-locked app."); |
| 5827 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5828 | } finally { |
| 5829 | //TODO clean up the extracted public files |
| 5830 | } |
| 5831 | if (mInstaller != null) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5832 | retCode = mInstaller.setForwardLockPerm(getApkName(newPackage.mPath), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5833 | newPackage.applicationInfo.uid); |
| 5834 | } else { |
| 5835 | final int filePermissions = |
| 5836 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5837 | retCode = FileUtils.setPermissions(newPackage.mPath, filePermissions, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5838 | newPackage.applicationInfo.uid); |
| 5839 | } |
| 5840 | } else { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5841 | // The permissions on the resource file was set when it was copied for |
| 5842 | // non forward locked apps and apps on sdcard |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5843 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5844 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5845 | if (retCode != 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5846 | Slog.e(TAG, "Couldn't set new package file permissions for " + |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5847 | newPackage.mPath |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5848 | + ". The return code was: " + retCode); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5849 | // TODO Define new internal error |
| 5850 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5851 | } |
| 5852 | return PackageManager.INSTALL_SUCCEEDED; |
| 5853 | } |
| 5854 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5855 | private static boolean isForwardLocked(PackageParser.Package pkg) { |
| 5856 | return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5857 | } |
| 5858 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5859 | private static boolean isExternal(PackageParser.Package pkg) { |
| 5860 | return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0; |
| 5861 | } |
| 5862 | |
| 5863 | private static boolean isSystemApp(PackageParser.Package pkg) { |
| 5864 | return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; |
| 5865 | } |
| 5866 | |
| 5867 | private static boolean isUpdatedSystemApp(PackageParser.Package pkg) { |
| 5868 | return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5869 | } |
| 5870 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5871 | private void extractPublicFiles(PackageParser.Package newPackage, |
| 5872 | File publicZipFile) throws IOException { |
| 5873 | final ZipOutputStream publicZipOutStream = |
| 5874 | new ZipOutputStream(new FileOutputStream(publicZipFile)); |
| 5875 | final ZipFile privateZip = new ZipFile(newPackage.mPath); |
| 5876 | |
| 5877 | // Copy manifest, resources.arsc and res directory to public zip |
| 5878 | |
| 5879 | final Enumeration<? extends ZipEntry> privateZipEntries = privateZip.entries(); |
| 5880 | while (privateZipEntries.hasMoreElements()) { |
| 5881 | final ZipEntry zipEntry = privateZipEntries.nextElement(); |
| 5882 | final String zipEntryName = zipEntry.getName(); |
| 5883 | if ("AndroidManifest.xml".equals(zipEntryName) |
| 5884 | || "resources.arsc".equals(zipEntryName) |
| 5885 | || zipEntryName.startsWith("res/")) { |
| 5886 | try { |
| 5887 | copyZipEntry(zipEntry, privateZip, publicZipOutStream); |
| 5888 | } catch (IOException e) { |
| 5889 | try { |
| 5890 | publicZipOutStream.close(); |
| 5891 | throw e; |
| 5892 | } finally { |
| 5893 | publicZipFile.delete(); |
| 5894 | } |
| 5895 | } |
| 5896 | } |
| 5897 | } |
| 5898 | |
| 5899 | publicZipOutStream.close(); |
| 5900 | FileUtils.setPermissions( |
| 5901 | publicZipFile.getAbsolutePath(), |
| 5902 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP|FileUtils.S_IROTH, |
| 5903 | -1, -1); |
| 5904 | } |
| 5905 | |
| 5906 | private static void copyZipEntry(ZipEntry zipEntry, |
| 5907 | ZipFile inZipFile, |
| 5908 | ZipOutputStream outZipStream) throws IOException { |
| 5909 | byte[] buffer = new byte[4096]; |
| 5910 | int num; |
| 5911 | |
| 5912 | ZipEntry newEntry; |
| 5913 | if (zipEntry.getMethod() == ZipEntry.STORED) { |
| 5914 | // Preserve the STORED method of the input entry. |
| 5915 | newEntry = new ZipEntry(zipEntry); |
| 5916 | } else { |
| 5917 | // Create a new entry so that the compressed len is recomputed. |
| 5918 | newEntry = new ZipEntry(zipEntry.getName()); |
| 5919 | } |
| 5920 | outZipStream.putNextEntry(newEntry); |
| 5921 | |
| 5922 | InputStream data = inZipFile.getInputStream(zipEntry); |
| 5923 | while ((num = data.read(buffer)) > 0) { |
| 5924 | outZipStream.write(buffer, 0, num); |
| 5925 | } |
| 5926 | outZipStream.flush(); |
| 5927 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5929 | private void deleteTempPackageFiles() { |
| 5930 | FilenameFilter filter = new FilenameFilter() { |
| 5931 | public boolean accept(File dir, String name) { |
| 5932 | return name.startsWith("vmdl") && name.endsWith(".tmp"); |
| 5933 | } |
| 5934 | }; |
| 5935 | String tmpFilesList[] = mAppInstallDir.list(filter); |
| 5936 | if(tmpFilesList == null) { |
| 5937 | return; |
| 5938 | } |
| 5939 | for(int i = 0; i < tmpFilesList.length; i++) { |
| 5940 | File tmpFile = new File(mAppInstallDir, tmpFilesList[i]); |
| 5941 | tmpFile.delete(); |
| 5942 | } |
| 5943 | } |
| 5944 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5945 | private File createTempPackageFile(File installDir) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5946 | File tmpPackageFile; |
| 5947 | try { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5948 | tmpPackageFile = File.createTempFile("vmdl", ".tmp", installDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5949 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5950 | Slog.e(TAG, "Couldn't create temp file for downloaded package file."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5951 | return null; |
| 5952 | } |
| 5953 | try { |
| 5954 | FileUtils.setPermissions( |
| 5955 | tmpPackageFile.getCanonicalPath(), FileUtils.S_IRUSR|FileUtils.S_IWUSR, |
| 5956 | -1, -1); |
| 5957 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5958 | Slog.e(TAG, "Trouble getting the canoncical path for a temp file."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5959 | return null; |
| 5960 | } |
| 5961 | return tmpPackageFile; |
| 5962 | } |
| 5963 | |
| 5964 | public void deletePackage(final String packageName, |
| 5965 | final IPackageDeleteObserver observer, |
| 5966 | final int flags) { |
| 5967 | mContext.enforceCallingOrSelfPermission( |
| 5968 | android.Manifest.permission.DELETE_PACKAGES, null); |
| 5969 | // Queue up an async operation since the package deletion may take a little while. |
| 5970 | mHandler.post(new Runnable() { |
| 5971 | public void run() { |
| 5972 | mHandler.removeCallbacks(this); |
| 5973 | final boolean succeded = deletePackageX(packageName, true, true, flags); |
| 5974 | if (observer != null) { |
| 5975 | try { |
| 5976 | observer.packageDeleted(succeded); |
| 5977 | } catch (RemoteException e) { |
| 5978 | Log.i(TAG, "Observer no longer exists."); |
| 5979 | } //end catch |
| 5980 | } //end if |
| 5981 | } //end run |
| 5982 | }); |
| 5983 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5984 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5985 | /** |
| 5986 | * This method is an internal method that could be get invoked either |
| 5987 | * to delete an installed package or to clean up a failed installation. |
| 5988 | * After deleting an installed package, a broadcast is sent to notify any |
| 5989 | * listeners that the package has been installed. For cleaning up a failed |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5990 | * installation, the broadcast is not necessary since the package's |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5991 | * installation wouldn't have sent the initial broadcast either |
| 5992 | * The key steps in deleting a package are |
| 5993 | * deleting the package information in internal structures like mPackages, |
| 5994 | * deleting the packages base directories through installd |
| 5995 | * updating mSettings to reflect current status |
| 5996 | * persisting settings for later use |
| 5997 | * sending a broadcast if necessary |
| 5998 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5999 | private boolean deletePackageX(String packageName, boolean sendBroadCast, |
| 6000 | boolean deleteCodeAndResources, int flags) { |
| 6001 | PackageRemovedInfo info = new PackageRemovedInfo(); |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6002 | boolean res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 6004 | IDevicePolicyManager dpm = IDevicePolicyManager.Stub.asInterface( |
| 6005 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 6006 | try { |
| 6007 | if (dpm != null && dpm.packageHasActiveAdmins(packageName)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6008 | Slog.w(TAG, "Not removing package " + packageName + ": has active device admin"); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 6009 | return false; |
| 6010 | } |
| 6011 | } catch (RemoteException e) { |
| 6012 | } |
| 6013 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6014 | synchronized (mInstallLock) { |
| Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6015 | res = deletePackageLI(packageName, deleteCodeAndResources, |
| 6016 | flags | REMOVE_CHATTY, info); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6017 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6018 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6019 | if(res && sendBroadCast) { |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6020 | boolean systemUpdate = info.isRemovedPackageSystemUpdate; |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6021 | info.sendBroadcast(deleteCodeAndResources, systemUpdate); |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6022 | |
| 6023 | // If the removed package was a system update, the old system packaged |
| 6024 | // was re-enabled; we need to broadcast this information |
| 6025 | if (systemUpdate) { |
| 6026 | Bundle extras = new Bundle(1); |
| 6027 | extras.putInt(Intent.EXTRA_UID, info.removedUid >= 0 ? info.removedUid : info.uid); |
| 6028 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 6029 | |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 6030 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName, extras, null); |
| 6031 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, packageName, extras, null); |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6032 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6033 | } |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6034 | // Force a gc here. |
| 6035 | Runtime.getRuntime().gc(); |
| 6036 | // Delete the resources here after sending the broadcast to let |
| 6037 | // other processes clean up before deleting resources. |
| 6038 | if (info.args != null) { |
| 6039 | synchronized (mInstallLock) { |
| 6040 | info.args.doPostDeleteLI(deleteCodeAndResources); |
| 6041 | } |
| 6042 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6043 | return res; |
| 6044 | } |
| 6045 | |
| 6046 | static class PackageRemovedInfo { |
| 6047 | String removedPackage; |
| 6048 | int uid = -1; |
| 6049 | int removedUid = -1; |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6050 | boolean isRemovedPackageSystemUpdate = false; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6051 | // Clean up resources deleted packages. |
| 6052 | InstallArgs args = null; |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6053 | |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6054 | void sendBroadcast(boolean fullRemove, boolean replacing) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6055 | Bundle extras = new Bundle(1); |
| 6056 | extras.putInt(Intent.EXTRA_UID, removedUid >= 0 ? removedUid : uid); |
| 6057 | extras.putBoolean(Intent.EXTRA_DATA_REMOVED, fullRemove); |
| 6058 | if (replacing) { |
| 6059 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 6060 | } |
| 6061 | if (removedPackage != null) { |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6062 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage, extras, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6063 | } |
| 6064 | if (removedUid >= 0) { |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 6065 | sendPackageBroadcast(Intent.ACTION_UID_REMOVED, null, extras, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6066 | } |
| 6067 | } |
| 6068 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6069 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6070 | /* |
| 6071 | * This method deletes the package from internal data structures. If the DONT_DELETE_DATA |
| 6072 | * flag is not set, the data directory is removed as well. |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6073 | * make sure this flag is set for partially installed apps. If not its meaningless to |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6074 | * delete a partially installed application. |
| 6075 | */ |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6076 | private void removePackageDataLI(PackageParser.Package p, PackageRemovedInfo outInfo, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6077 | int flags) { |
| 6078 | String packageName = p.packageName; |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6079 | if (outInfo != null) { |
| 6080 | outInfo.removedPackage = packageName; |
| 6081 | } |
| Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6082 | removePackageLI(p, (flags&REMOVE_CHATTY) != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6083 | // Retrieve object to delete permissions for shared user later on |
| 6084 | PackageSetting deletedPs; |
| 6085 | synchronized (mPackages) { |
| 6086 | deletedPs = mSettings.mPackages.get(packageName); |
| 6087 | } |
| 6088 | if ((flags&PackageManager.DONT_DELETE_DATA) == 0) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6089 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6090 | if (mInstaller != null) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6091 | int retCode = mInstaller.remove(packageName, useEncryptedFSDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6092 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6093 | Slog.w(TAG, "Couldn't remove app data or cache directory for package: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6094 | + packageName + ", retcode=" + retCode); |
| 6095 | // we don't consider this to be a failure of the core package deletion |
| 6096 | } |
| 6097 | } else { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6098 | // for simulator |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6099 | PackageParser.Package pkg = mPackages.get(packageName); |
| 6100 | File dataDir = new File(pkg.applicationInfo.dataDir); |
| 6101 | dataDir.delete(); |
| 6102 | } |
| Dianne Hackborn | fb1f103 | 2010-07-29 13:57:56 -0700 | [diff] [blame] | 6103 | schedulePackageCleaning(packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6104 | } |
| 6105 | synchronized (mPackages) { |
| Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 6106 | if (deletedPs != null) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6107 | if ((flags&PackageManager.DONT_DELETE_DATA) == 0) { |
| 6108 | if (outInfo != null) { |
| 6109 | outInfo.removedUid = mSettings.removePackageLP(packageName); |
| 6110 | } |
| 6111 | if (deletedPs != null) { |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 6112 | updatePermissionsLP(deletedPs.name, null, false, false, false); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6113 | if (deletedPs.sharedUser != null) { |
| 6114 | // remove permissions associated with package |
| 6115 | mSettings.updateSharedUserPermsLP(deletedPs, mGlobalGids); |
| 6116 | } |
| 6117 | } |
| 6118 | } |
| Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 6119 | // remove from preferred activities. |
| 6120 | ArrayList<PreferredActivity> removed = new ArrayList<PreferredActivity>(); |
| 6121 | for (PreferredActivity pa : mSettings.mPreferredActivities.filterSet()) { |
| 6122 | if (pa.mActivity.getPackageName().equals(deletedPs.name)) { |
| 6123 | removed.add(pa); |
| 6124 | } |
| 6125 | } |
| 6126 | for (PreferredActivity pa : removed) { |
| 6127 | mSettings.mPreferredActivities.removeFilter(pa); |
| 6128 | } |
| 6129 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6130 | // Save settings now |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 6131 | mSettings.writeLP(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6132 | } |
| 6133 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6134 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6135 | /* |
| 6136 | * Tries to delete system package. |
| 6137 | */ |
| 6138 | private boolean deleteSystemPackageLI(PackageParser.Package p, |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6139 | int flags, PackageRemovedInfo outInfo) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6140 | ApplicationInfo applicationInfo = p.applicationInfo; |
| 6141 | //applicable for non-partially installed applications only |
| 6142 | if (applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6143 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6144 | return false; |
| 6145 | } |
| 6146 | PackageSetting ps = null; |
| 6147 | // Confirm if the system package has been updated |
| 6148 | // An updated system app can be deleted. This will also have to restore |
| 6149 | // the system pkg from system partition |
| 6150 | synchronized (mPackages) { |
| 6151 | ps = mSettings.getDisabledSystemPkg(p.packageName); |
| 6152 | } |
| 6153 | if (ps == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6154 | Slog.w(TAG, "Attempt to delete system package "+ p.packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6155 | return false; |
| 6156 | } else { |
| 6157 | Log.i(TAG, "Deleting system pkg from data partition"); |
| 6158 | } |
| 6159 | // Delete the updated package |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6160 | outInfo.isRemovedPackageSystemUpdate = true; |
| Kenny Root | 7c1bd7f | 2010-09-01 13:44:11 -0700 | [diff] [blame] | 6161 | final boolean deleteCodeAndResources; |
| 6162 | if (ps.versionCode < p.mVersionCode) { |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6163 | // Delete code and resources for downgrades |
| 6164 | deleteCodeAndResources = true; |
| Kenny Root | 7c1bd7f | 2010-09-01 13:44:11 -0700 | [diff] [blame] | 6165 | flags &= ~PackageManager.DONT_DELETE_DATA; |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6166 | } else { |
| 6167 | // Preserve data by setting flag |
| Kenny Root | 7c1bd7f | 2010-09-01 13:44:11 -0700 | [diff] [blame] | 6168 | deleteCodeAndResources = false; |
| 6169 | flags |= PackageManager.DONT_DELETE_DATA; |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6170 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6171 | boolean ret = deleteInstalledPackageLI(p, deleteCodeAndResources, flags, outInfo); |
| 6172 | if (!ret) { |
| 6173 | return false; |
| 6174 | } |
| 6175 | synchronized (mPackages) { |
| 6176 | // Reinstate the old system package |
| 6177 | mSettings.enableSystemPackageLP(p.packageName); |
| Kenny Root | 8f7cc02 | 2010-09-12 09:04:56 -0700 | [diff] [blame] | 6178 | // Remove any native libraries from the upgraded package. |
| 6179 | NativeLibraryHelper.removeNativeBinariesLI(p.applicationInfo.nativeLibraryDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6180 | } |
| 6181 | // Install the system package |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6182 | PackageParser.Package newPkg = scanPackageLI(ps.codePath, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6183 | PackageParser.PARSE_MUST_BE_APK | PackageParser.PARSE_IS_SYSTEM, |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6184 | SCAN_MONITOR | SCAN_NO_PATHS); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6186 | if (newPkg == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6187 | Slog.w(TAG, "Failed to restore system package:"+p.packageName+" with error:" + mLastScanError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6188 | return false; |
| 6189 | } |
| 6190 | synchronized (mPackages) { |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 6191 | updatePermissionsLP(newPkg.packageName, newPkg, true, true, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6192 | mSettings.writeLP(); |
| 6193 | } |
| 6194 | return true; |
| 6195 | } |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6196 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6197 | private boolean deleteInstalledPackageLI(PackageParser.Package p, |
| 6198 | boolean deleteCodeAndResources, int flags, PackageRemovedInfo outInfo) { |
| 6199 | ApplicationInfo applicationInfo = p.applicationInfo; |
| 6200 | if (applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6201 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6202 | return false; |
| 6203 | } |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6204 | if (outInfo != null) { |
| 6205 | outInfo.uid = applicationInfo.uid; |
| 6206 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6207 | |
| 6208 | // Delete package data from internal structures and also remove data if flag is set |
| 6209 | removePackageDataLI(p, outInfo, flags); |
| 6210 | |
| 6211 | // Delete application code and resources |
| 6212 | if (deleteCodeAndResources) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6213 | // TODO can pick up from PackageSettings as well |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6214 | int installFlags = isExternal(p) ? PackageManager.INSTALL_EXTERNAL : 0; |
| 6215 | installFlags |= isForwardLocked(p) ? PackageManager.INSTALL_FORWARD_LOCK : 0; |
| 6216 | outInfo.args = createInstallArgs(installFlags, applicationInfo.sourceDir, |
| 6217 | applicationInfo.publicSourceDir, applicationInfo.nativeLibraryDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6218 | } |
| 6219 | return true; |
| 6220 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6222 | /* |
| 6223 | * This method handles package deletion in general |
| 6224 | */ |
| 6225 | private boolean deletePackageLI(String packageName, |
| 6226 | boolean deleteCodeAndResources, int flags, PackageRemovedInfo outInfo) { |
| 6227 | if (packageName == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6228 | Slog.w(TAG, "Attempt to delete null packageName."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | return false; |
| 6230 | } |
| 6231 | PackageParser.Package p; |
| 6232 | boolean dataOnly = false; |
| 6233 | synchronized (mPackages) { |
| 6234 | p = mPackages.get(packageName); |
| 6235 | if (p == null) { |
| 6236 | //this retrieves partially installed apps |
| 6237 | dataOnly = true; |
| 6238 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6239 | if (ps == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6240 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6241 | return false; |
| 6242 | } |
| 6243 | p = ps.pkg; |
| 6244 | } |
| 6245 | } |
| 6246 | if (p == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6247 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6248 | return false; |
| 6249 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6250 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | if (dataOnly) { |
| 6252 | // Delete application data first |
| 6253 | removePackageDataLI(p, outInfo, flags); |
| 6254 | return true; |
| 6255 | } |
| 6256 | // At this point the package should have ApplicationInfo associated with it |
| 6257 | if (p.applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6258 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6259 | return false; |
| 6260 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6261 | boolean ret = false; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6262 | if (isSystemApp(p)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6263 | Log.i(TAG, "Removing system package:"+p.packageName); |
| 6264 | // When an updated system application is deleted we delete the existing resources as well and |
| 6265 | // fall back to existing code in system partition |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6266 | ret = deleteSystemPackageLI(p, flags, outInfo); |
| 6267 | } else { |
| 6268 | Log.i(TAG, "Removing non-system package:"+p.packageName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6269 | // Kill application pre-emptively especially for apps on sd. |
| 6270 | killApplication(packageName, p.applicationInfo.uid); |
| Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 6271 | ret = deleteInstalledPackageLI(p, deleteCodeAndResources, flags, outInfo); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6272 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6273 | return ret; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6274 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | public void clearApplicationUserData(final String packageName, |
| 6277 | final IPackageDataObserver observer) { |
| 6278 | mContext.enforceCallingOrSelfPermission( |
| 6279 | android.Manifest.permission.CLEAR_APP_USER_DATA, null); |
| 6280 | // Queue up an async operation since the package deletion may take a little while. |
| 6281 | mHandler.post(new Runnable() { |
| 6282 | public void run() { |
| 6283 | mHandler.removeCallbacks(this); |
| 6284 | final boolean succeeded; |
| 6285 | synchronized (mInstallLock) { |
| 6286 | succeeded = clearApplicationUserDataLI(packageName); |
| 6287 | } |
| 6288 | if (succeeded) { |
| 6289 | // invoke DeviceStorageMonitor's update method to clear any notifications |
| 6290 | DeviceStorageMonitorService dsm = (DeviceStorageMonitorService) |
| 6291 | ServiceManager.getService(DeviceStorageMonitorService.SERVICE); |
| 6292 | if (dsm != null) { |
| 6293 | dsm.updateMemory(); |
| 6294 | } |
| 6295 | } |
| 6296 | if(observer != null) { |
| 6297 | try { |
| 6298 | observer.onRemoveCompleted(packageName, succeeded); |
| 6299 | } catch (RemoteException e) { |
| 6300 | Log.i(TAG, "Observer no longer exists."); |
| 6301 | } |
| 6302 | } //end if observer |
| 6303 | } //end run |
| 6304 | }); |
| 6305 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6306 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6307 | private boolean clearApplicationUserDataLI(String packageName) { |
| 6308 | if (packageName == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6309 | Slog.w(TAG, "Attempt to delete null packageName."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6310 | return false; |
| 6311 | } |
| 6312 | PackageParser.Package p; |
| 6313 | boolean dataOnly = false; |
| 6314 | synchronized (mPackages) { |
| 6315 | p = mPackages.get(packageName); |
| 6316 | if(p == null) { |
| 6317 | dataOnly = true; |
| 6318 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6319 | if((ps == null) || (ps.pkg == null)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6320 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6321 | return false; |
| 6322 | } |
| 6323 | p = ps.pkg; |
| 6324 | } |
| 6325 | } |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6326 | boolean useEncryptedFSDir = false; |
| 6327 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6328 | if(!dataOnly) { |
| 6329 | //need to check this only for fully installed applications |
| 6330 | if (p == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6331 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6332 | return false; |
| 6333 | } |
| 6334 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6335 | if (applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6336 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6337 | return false; |
| 6338 | } |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6339 | useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6340 | } |
| 6341 | if (mInstaller != null) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6342 | int retCode = mInstaller.clearUserData(packageName, useEncryptedFSDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6343 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6344 | Slog.w(TAG, "Couldn't remove cache files for package: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6345 | + packageName); |
| 6346 | return false; |
| 6347 | } |
| 6348 | } |
| 6349 | return true; |
| 6350 | } |
| 6351 | |
| 6352 | public void deleteApplicationCacheFiles(final String packageName, |
| 6353 | final IPackageDataObserver observer) { |
| 6354 | mContext.enforceCallingOrSelfPermission( |
| 6355 | android.Manifest.permission.DELETE_CACHE_FILES, null); |
| 6356 | // Queue up an async operation since the package deletion may take a little while. |
| 6357 | mHandler.post(new Runnable() { |
| 6358 | public void run() { |
| 6359 | mHandler.removeCallbacks(this); |
| 6360 | final boolean succeded; |
| 6361 | synchronized (mInstallLock) { |
| 6362 | succeded = deleteApplicationCacheFilesLI(packageName); |
| 6363 | } |
| 6364 | if(observer != null) { |
| 6365 | try { |
| 6366 | observer.onRemoveCompleted(packageName, succeded); |
| 6367 | } catch (RemoteException e) { |
| 6368 | Log.i(TAG, "Observer no longer exists."); |
| 6369 | } |
| 6370 | } //end if observer |
| 6371 | } //end run |
| 6372 | }); |
| 6373 | } |
| 6374 | |
| 6375 | private boolean deleteApplicationCacheFilesLI(String packageName) { |
| 6376 | if (packageName == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6377 | Slog.w(TAG, "Attempt to delete null packageName."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | return false; |
| 6379 | } |
| 6380 | PackageParser.Package p; |
| 6381 | synchronized (mPackages) { |
| 6382 | p = mPackages.get(packageName); |
| 6383 | } |
| 6384 | if (p == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6385 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6386 | return false; |
| 6387 | } |
| 6388 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6389 | if (applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6390 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6391 | return false; |
| 6392 | } |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6393 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6394 | if (mInstaller != null) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6395 | int retCode = mInstaller.deleteCacheFiles(packageName, useEncryptedFSDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6396 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6397 | Slog.w(TAG, "Couldn't remove cache files for package: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6398 | + packageName); |
| 6399 | return false; |
| 6400 | } |
| 6401 | } |
| 6402 | return true; |
| 6403 | } |
| 6404 | |
| 6405 | public void getPackageSizeInfo(final String packageName, |
| 6406 | final IPackageStatsObserver observer) { |
| 6407 | mContext.enforceCallingOrSelfPermission( |
| 6408 | android.Manifest.permission.GET_PACKAGE_SIZE, null); |
| 6409 | // Queue up an async operation since the package deletion may take a little while. |
| 6410 | mHandler.post(new Runnable() { |
| 6411 | public void run() { |
| 6412 | mHandler.removeCallbacks(this); |
| 6413 | PackageStats lStats = new PackageStats(packageName); |
| 6414 | final boolean succeded; |
| 6415 | synchronized (mInstallLock) { |
| 6416 | succeded = getPackageSizeInfoLI(packageName, lStats); |
| 6417 | } |
| 6418 | if(observer != null) { |
| 6419 | try { |
| 6420 | observer.onGetStatsCompleted(lStats, succeded); |
| 6421 | } catch (RemoteException e) { |
| 6422 | Log.i(TAG, "Observer no longer exists."); |
| 6423 | } |
| 6424 | } //end if observer |
| 6425 | } //end run |
| 6426 | }); |
| 6427 | } |
| 6428 | |
| 6429 | private boolean getPackageSizeInfoLI(String packageName, PackageStats pStats) { |
| 6430 | if (packageName == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6431 | Slog.w(TAG, "Attempt to get size of null packageName."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6432 | return false; |
| 6433 | } |
| 6434 | PackageParser.Package p; |
| 6435 | boolean dataOnly = false; |
| 6436 | synchronized (mPackages) { |
| 6437 | p = mPackages.get(packageName); |
| 6438 | if(p == null) { |
| 6439 | dataOnly = true; |
| 6440 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6441 | if((ps == null) || (ps.pkg == null)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6442 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6443 | return false; |
| 6444 | } |
| 6445 | p = ps.pkg; |
| 6446 | } |
| 6447 | } |
| 6448 | String publicSrcDir = null; |
| 6449 | if(!dataOnly) { |
| 6450 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6451 | if (applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6452 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | return false; |
| 6454 | } |
| 6455 | publicSrcDir = isForwardLocked(p) ? applicationInfo.publicSourceDir : null; |
| 6456 | } |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6457 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6458 | if (mInstaller != null) { |
| 6459 | int res = mInstaller.getSizeInfo(packageName, p.mPath, |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6460 | publicSrcDir, pStats, useEncryptedFSDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6461 | if (res < 0) { |
| 6462 | return false; |
| 6463 | } else { |
| 6464 | return true; |
| 6465 | } |
| 6466 | } |
| 6467 | return true; |
| 6468 | } |
| 6469 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6471 | public void addPackageToPreferred(String packageName) { |
| Dianne Hackborn | 8377fc0 | 2010-06-07 15:54:58 -0700 | [diff] [blame] | 6472 | Slog.w(TAG, "addPackageToPreferred: this is now a no-op"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6473 | } |
| 6474 | |
| 6475 | public void removePackageFromPreferred(String packageName) { |
| Dianne Hackborn | 8377fc0 | 2010-06-07 15:54:58 -0700 | [diff] [blame] | 6476 | Slog.w(TAG, "removePackageFromPreferred: this is now a no-op"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6477 | } |
| 6478 | |
| 6479 | public List<PackageInfo> getPreferredPackages(int flags) { |
| Dianne Hackborn | a7ca0e5 | 2009-12-01 14:31:55 -0800 | [diff] [blame] | 6480 | return new ArrayList<PackageInfo>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6481 | } |
| 6482 | |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6483 | int getUidTargetSdkVersionLockedLP(int uid) { |
| 6484 | Object obj = mSettings.getUserIdLP(uid); |
| 6485 | if (obj instanceof SharedUserSetting) { |
| 6486 | SharedUserSetting sus = (SharedUserSetting)obj; |
| 6487 | final int N = sus.packages.size(); |
| 6488 | int vers = Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 6489 | Iterator<PackageSetting> it = sus.packages.iterator(); |
| 6490 | int i=0; |
| 6491 | while (it.hasNext()) { |
| 6492 | PackageSetting ps = it.next(); |
| 6493 | if (ps.pkg != null) { |
| 6494 | int v = ps.pkg.applicationInfo.targetSdkVersion; |
| 6495 | if (v < vers) vers = v; |
| 6496 | } |
| 6497 | } |
| 6498 | return vers; |
| 6499 | } else if (obj instanceof PackageSetting) { |
| 6500 | PackageSetting ps = (PackageSetting)obj; |
| 6501 | if (ps.pkg != null) { |
| 6502 | return ps.pkg.applicationInfo.targetSdkVersion; |
| 6503 | } |
| 6504 | } |
| 6505 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 6506 | } |
| 6507 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6508 | public void addPreferredActivity(IntentFilter filter, int match, |
| 6509 | ComponentName[] set, ComponentName activity) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | synchronized (mPackages) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6511 | if (mContext.checkCallingOrSelfPermission( |
| 6512 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6513 | != PackageManager.PERMISSION_GRANTED) { |
| 6514 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6515 | < Build.VERSION_CODES.FROYO) { |
| 6516 | Slog.w(TAG, "Ignoring addPreferredActivity() from uid " |
| 6517 | + Binder.getCallingUid()); |
| 6518 | return; |
| 6519 | } |
| 6520 | mContext.enforceCallingOrSelfPermission( |
| 6521 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6522 | } |
| 6523 | |
| 6524 | Slog.i(TAG, "Adding preferred activity " + activity + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6525 | filter.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 6526 | mSettings.mPreferredActivities.addFilter( |
| 6527 | new PreferredActivity(filter, match, set, activity)); |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6528 | scheduleWriteSettingsLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6529 | } |
| 6530 | } |
| 6531 | |
| Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6532 | public void replacePreferredActivity(IntentFilter filter, int match, |
| 6533 | ComponentName[] set, ComponentName activity) { |
| Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6534 | if (filter.countActions() != 1) { |
| 6535 | throw new IllegalArgumentException( |
| 6536 | "replacePreferredActivity expects filter to have only 1 action."); |
| 6537 | } |
| 6538 | if (filter.countCategories() != 1) { |
| 6539 | throw new IllegalArgumentException( |
| 6540 | "replacePreferredActivity expects filter to have only 1 category."); |
| 6541 | } |
| 6542 | if (filter.countDataAuthorities() != 0 |
| 6543 | || filter.countDataPaths() != 0 |
| 6544 | || filter.countDataSchemes() != 0 |
| 6545 | || filter.countDataTypes() != 0) { |
| 6546 | throw new IllegalArgumentException( |
| 6547 | "replacePreferredActivity expects filter to have no data authorities, " + |
| 6548 | "paths, schemes or types."); |
| 6549 | } |
| 6550 | synchronized (mPackages) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6551 | if (mContext.checkCallingOrSelfPermission( |
| 6552 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6553 | != PackageManager.PERMISSION_GRANTED) { |
| 6554 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6555 | < Build.VERSION_CODES.FROYO) { |
| 6556 | Slog.w(TAG, "Ignoring replacePreferredActivity() from uid " |
| 6557 | + Binder.getCallingUid()); |
| 6558 | return; |
| 6559 | } |
| 6560 | mContext.enforceCallingOrSelfPermission( |
| 6561 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6562 | } |
| 6563 | |
| Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6564 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6565 | String action = filter.getAction(0); |
| 6566 | String category = filter.getCategory(0); |
| 6567 | while (it.hasNext()) { |
| 6568 | PreferredActivity pa = it.next(); |
| 6569 | if (pa.getAction(0).equals(action) && pa.getCategory(0).equals(category)) { |
| 6570 | it.remove(); |
| 6571 | Log.i(TAG, "Removed preferred activity " + pa.mActivity + ":"); |
| 6572 | filter.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 6573 | } |
| 6574 | } |
| 6575 | addPreferredActivity(filter, match, set, activity); |
| 6576 | } |
| 6577 | } |
| 6578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | public void clearPackagePreferredActivities(String packageName) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6580 | synchronized (mPackages) { |
| Dianne Hackborn | 2ee89ea | 2010-03-10 18:27:09 -0800 | [diff] [blame] | 6581 | int uid = Binder.getCallingUid(); |
| 6582 | PackageParser.Package pkg = mPackages.get(packageName); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6583 | if (pkg == null || pkg.applicationInfo.uid != uid) { |
| 6584 | if (mContext.checkCallingOrSelfPermission( |
| 6585 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6586 | != PackageManager.PERMISSION_GRANTED) { |
| 6587 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6588 | < Build.VERSION_CODES.FROYO) { |
| 6589 | Slog.w(TAG, "Ignoring clearPackagePreferredActivities() from uid " |
| 6590 | + Binder.getCallingUid()); |
| 6591 | return; |
| 6592 | } |
| 6593 | mContext.enforceCallingOrSelfPermission( |
| 6594 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6595 | } |
| Dianne Hackborn | 2ee89ea | 2010-03-10 18:27:09 -0800 | [diff] [blame] | 6596 | } |
| 6597 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6598 | if (clearPackagePreferredActivitiesLP(packageName)) { |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6599 | scheduleWriteSettingsLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6600 | } |
| 6601 | } |
| 6602 | } |
| 6603 | |
| 6604 | boolean clearPackagePreferredActivitiesLP(String packageName) { |
| 6605 | boolean changed = false; |
| 6606 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6607 | while (it.hasNext()) { |
| 6608 | PreferredActivity pa = it.next(); |
| 6609 | if (pa.mActivity.getPackageName().equals(packageName)) { |
| 6610 | it.remove(); |
| 6611 | changed = true; |
| 6612 | } |
| 6613 | } |
| 6614 | return changed; |
| 6615 | } |
| 6616 | |
| 6617 | public int getPreferredActivities(List<IntentFilter> outFilters, |
| 6618 | List<ComponentName> outActivities, String packageName) { |
| 6619 | |
| 6620 | int num = 0; |
| 6621 | synchronized (mPackages) { |
| 6622 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6623 | while (it.hasNext()) { |
| 6624 | PreferredActivity pa = it.next(); |
| 6625 | if (packageName == null |
| 6626 | || pa.mActivity.getPackageName().equals(packageName)) { |
| 6627 | if (outFilters != null) { |
| 6628 | outFilters.add(new IntentFilter(pa)); |
| 6629 | } |
| 6630 | if (outActivities != null) { |
| 6631 | outActivities.add(pa.mActivity); |
| 6632 | } |
| 6633 | } |
| 6634 | } |
| 6635 | } |
| 6636 | |
| 6637 | return num; |
| 6638 | } |
| 6639 | |
| 6640 | public void setApplicationEnabledSetting(String appPackageName, |
| 6641 | int newState, int flags) { |
| 6642 | setEnabledSetting(appPackageName, null, newState, flags); |
| 6643 | } |
| 6644 | |
| 6645 | public void setComponentEnabledSetting(ComponentName componentName, |
| 6646 | int newState, int flags) { |
| 6647 | setEnabledSetting(componentName.getPackageName(), |
| 6648 | componentName.getClassName(), newState, flags); |
| 6649 | } |
| 6650 | |
| 6651 | private void setEnabledSetting( |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6652 | final String packageName, String className, int newState, final int flags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6653 | if (!(newState == COMPONENT_ENABLED_STATE_DEFAULT |
| 6654 | || newState == COMPONENT_ENABLED_STATE_ENABLED |
| 6655 | || newState == COMPONENT_ENABLED_STATE_DISABLED)) { |
| 6656 | throw new IllegalArgumentException("Invalid new component state: " |
| 6657 | + newState); |
| 6658 | } |
| 6659 | PackageSetting pkgSetting; |
| 6660 | final int uid = Binder.getCallingUid(); |
| 6661 | final int permission = mContext.checkCallingPermission( |
| 6662 | android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE); |
| 6663 | final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6664 | boolean sendNow = false; |
| 6665 | boolean isApp = (className == null); |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6666 | String componentName = isApp ? packageName : className; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6667 | int packageUid = -1; |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6668 | ArrayList<String> components; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6669 | synchronized (mPackages) { |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6670 | pkgSetting = mSettings.mPackages.get(packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6671 | if (pkgSetting == null) { |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6672 | if (className == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6673 | throw new IllegalArgumentException( |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6674 | "Unknown package: " + packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6675 | } |
| 6676 | throw new IllegalArgumentException( |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6677 | "Unknown component: " + packageName |
| 6678 | + "/" + className); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | } |
| 6680 | if (!allowedByPermission && (uid != pkgSetting.userId)) { |
| 6681 | throw new SecurityException( |
| 6682 | "Permission Denial: attempt to change component state from pid=" |
| 6683 | + Binder.getCallingPid() |
| 6684 | + ", uid=" + uid + ", package uid=" + pkgSetting.userId); |
| 6685 | } |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6686 | if (className == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6687 | // We're dealing with an application/package level state change |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6688 | if (pkgSetting.enabled == newState) { |
| 6689 | // Nothing to do |
| 6690 | return; |
| 6691 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6692 | pkgSetting.enabled = newState; |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 6693 | pkgSetting.pkg.mSetEnabled = newState; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6694 | } else { |
| 6695 | // We're dealing with a component level state change |
| 6696 | switch (newState) { |
| 6697 | case COMPONENT_ENABLED_STATE_ENABLED: |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6698 | if (!pkgSetting.enableComponentLP(className)) { |
| 6699 | return; |
| 6700 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6701 | break; |
| 6702 | case COMPONENT_ENABLED_STATE_DISABLED: |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6703 | if (!pkgSetting.disableComponentLP(className)) { |
| 6704 | return; |
| 6705 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6706 | break; |
| 6707 | case COMPONENT_ENABLED_STATE_DEFAULT: |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6708 | if (!pkgSetting.restoreComponentLP(className)) { |
| 6709 | return; |
| 6710 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6711 | break; |
| 6712 | default: |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6713 | Slog.e(TAG, "Invalid new component state: " + newState); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6714 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6715 | } |
| 6716 | } |
| 6717 | mSettings.writeLP(); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6718 | packageUid = pkgSetting.userId; |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6719 | components = mPendingBroadcasts.get(packageName); |
| 6720 | boolean newPackage = components == null; |
| 6721 | if (newPackage) { |
| 6722 | components = new ArrayList<String>(); |
| 6723 | } |
| 6724 | if (!components.contains(componentName)) { |
| 6725 | components.add(componentName); |
| 6726 | } |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6727 | if ((flags&PackageManager.DONT_KILL_APP) == 0) { |
| 6728 | sendNow = true; |
| 6729 | // Purge entry from pending broadcast list if another one exists already |
| 6730 | // since we are sending one right away. |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6731 | mPendingBroadcasts.remove(packageName); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6732 | } else { |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6733 | if (newPackage) { |
| 6734 | mPendingBroadcasts.put(packageName, components); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6735 | } |
| 6736 | if (!mHandler.hasMessages(SEND_PENDING_BROADCAST)) { |
| 6737 | // Schedule a message |
| 6738 | mHandler.sendEmptyMessageDelayed(SEND_PENDING_BROADCAST, BROADCAST_DELAY); |
| 6739 | } |
| 6740 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6741 | } |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6742 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6743 | long callingId = Binder.clearCallingIdentity(); |
| 6744 | try { |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6745 | if (sendNow) { |
| 6746 | sendPackageChangedBroadcast(packageName, |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6747 | (flags&PackageManager.DONT_KILL_APP) != 0, components, packageUid); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6748 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6749 | } finally { |
| 6750 | Binder.restoreCallingIdentity(callingId); |
| 6751 | } |
| 6752 | } |
| 6753 | |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6754 | private void sendPackageChangedBroadcast(String packageName, |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6755 | boolean killFlag, ArrayList<String> componentNames, int packageUid) { |
| 6756 | if (false) Log.v(TAG, "Sending package changed: package=" + packageName |
| 6757 | + " components=" + componentNames); |
| 6758 | Bundle extras = new Bundle(4); |
| 6759 | extras.putString(Intent.EXTRA_CHANGED_COMPONENT_NAME, componentNames.get(0)); |
| 6760 | String nameList[] = new String[componentNames.size()]; |
| 6761 | componentNames.toArray(nameList); |
| 6762 | extras.putStringArray(Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST, nameList); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6763 | extras.putBoolean(Intent.EXTRA_DONT_KILL_APP, killFlag); |
| 6764 | extras.putInt(Intent.EXTRA_UID, packageUid); |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 6765 | sendPackageBroadcast(Intent.ACTION_PACKAGE_CHANGED, packageName, extras, null); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6766 | } |
| 6767 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 6768 | public String getInstallerPackageName(String packageName) { |
| 6769 | synchronized (mPackages) { |
| 6770 | PackageSetting pkg = mSettings.mPackages.get(packageName); |
| 6771 | if (pkg == null) { |
| 6772 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 6773 | } |
| 6774 | return pkg.installerPackageName; |
| 6775 | } |
| 6776 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6777 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6778 | public int getApplicationEnabledSetting(String appPackageName) { |
| 6779 | synchronized (mPackages) { |
| 6780 | PackageSetting pkg = mSettings.mPackages.get(appPackageName); |
| 6781 | if (pkg == null) { |
| 6782 | throw new IllegalArgumentException("Unknown package: " + appPackageName); |
| 6783 | } |
| 6784 | return pkg.enabled; |
| 6785 | } |
| 6786 | } |
| 6787 | |
| 6788 | public int getComponentEnabledSetting(ComponentName componentName) { |
| 6789 | synchronized (mPackages) { |
| 6790 | final String packageNameStr = componentName.getPackageName(); |
| 6791 | PackageSetting pkg = mSettings.mPackages.get(packageNameStr); |
| 6792 | if (pkg == null) { |
| 6793 | throw new IllegalArgumentException("Unknown component: " + componentName); |
| 6794 | } |
| 6795 | final String classNameStr = componentName.getClassName(); |
| 6796 | return pkg.currentEnabledStateLP(classNameStr); |
| 6797 | } |
| 6798 | } |
| 6799 | |
| 6800 | public void enterSafeMode() { |
| 6801 | if (!mSystemReady) { |
| 6802 | mSafeMode = true; |
| 6803 | } |
| 6804 | } |
| 6805 | |
| 6806 | public void systemReady() { |
| 6807 | mSystemReady = true; |
| Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6808 | |
| 6809 | // Read the compatibilty setting when the system is ready. |
| Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6810 | boolean compatibilityModeEnabled = android.provider.Settings.System.getInt( |
| Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6811 | mContext.getContentResolver(), |
| 6812 | android.provider.Settings.System.COMPATIBILITY_MODE, 1) == 1; |
| Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6813 | PackageParser.setCompatibilityModeEnabled(compatibilityModeEnabled); |
| Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6814 | if (DEBUG_SETTINGS) { |
| Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6815 | Log.d(TAG, "compatibility mode:" + compatibilityModeEnabled); |
| Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6816 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6817 | } |
| 6818 | |
| 6819 | public boolean isSafeMode() { |
| 6820 | return mSafeMode; |
| 6821 | } |
| 6822 | |
| 6823 | public boolean hasSystemUidErrors() { |
| 6824 | return mHasSystemUidErrors; |
| 6825 | } |
| 6826 | |
| 6827 | static String arrayToString(int[] array) { |
| 6828 | StringBuffer buf = new StringBuffer(128); |
| 6829 | buf.append('['); |
| 6830 | if (array != null) { |
| 6831 | for (int i=0; i<array.length; i++) { |
| 6832 | if (i > 0) buf.append(", "); |
| 6833 | buf.append(array[i]); |
| 6834 | } |
| 6835 | } |
| 6836 | buf.append(']'); |
| 6837 | return buf.toString(); |
| 6838 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6839 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6840 | @Override |
| 6841 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 6842 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6843 | != PackageManager.PERMISSION_GRANTED) { |
| 6844 | pw.println("Permission Denial: can't dump ActivityManager from from pid=" |
| 6845 | + Binder.getCallingPid() |
| 6846 | + ", uid=" + Binder.getCallingUid() |
| 6847 | + " without permission " |
| 6848 | + android.Manifest.permission.DUMP); |
| 6849 | return; |
| 6850 | } |
| 6851 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6852 | String packageName = null; |
| 6853 | |
| 6854 | int opti = 0; |
| 6855 | while (opti < args.length) { |
| 6856 | String opt = args[opti]; |
| 6857 | if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') { |
| 6858 | break; |
| 6859 | } |
| 6860 | opti++; |
| 6861 | if ("-a".equals(opt)) { |
| 6862 | // Right now we only know how to print all. |
| 6863 | } else if ("-h".equals(opt)) { |
| 6864 | pw.println("Package manager dump options:"); |
| 6865 | pw.println(" [-h] [cmd] ..."); |
| 6866 | pw.println(" cmd may be one of:"); |
| 6867 | pw.println(" [package.name]: info about given package"); |
| 6868 | return; |
| 6869 | } else { |
| 6870 | pw.println("Unknown argument: " + opt + "; use -h for help"); |
| 6871 | } |
| 6872 | } |
| 6873 | |
| 6874 | // Is the caller requesting to dump a particular piece of data? |
| 6875 | if (opti < args.length) { |
| 6876 | String cmd = args[opti]; |
| 6877 | opti++; |
| 6878 | // Is this a package name? |
| 6879 | if ("android".equals(cmd) || cmd.contains(".")) { |
| 6880 | packageName = cmd; |
| 6881 | } |
| 6882 | } |
| 6883 | |
| 6884 | boolean printedTitle = false; |
| 6885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6886 | synchronized (mPackages) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6887 | if (mActivities.dump(pw, "Activity Resolver Table:", " ", packageName)) { |
| 6888 | printedTitle = true; |
| 6889 | } |
| 6890 | if (mReceivers.dump(pw, printedTitle |
| 6891 | ? "\nReceiver Resolver Table:" : "Receiver Resolver Table:", |
| 6892 | " ", packageName)) { |
| 6893 | printedTitle = true; |
| 6894 | } |
| 6895 | if (mServices.dump(pw, printedTitle |
| 6896 | ? "\nService Resolver Table:" : "Service Resolver Table:", |
| 6897 | " ", packageName)) { |
| 6898 | printedTitle = true; |
| 6899 | } |
| 6900 | if (mSettings.mPreferredActivities.dump(pw, printedTitle |
| 6901 | ? "\nPreferred Activities:" : "Preferred Activities:", |
| 6902 | " ", packageName)) { |
| 6903 | printedTitle = true; |
| 6904 | } |
| 6905 | boolean printedSomething = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6906 | { |
| 6907 | for (BasePermission p : mSettings.mPermissions.values()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6908 | if (packageName != null && !packageName.equals(p.sourcePackage)) { |
| 6909 | continue; |
| 6910 | } |
| 6911 | if (!printedSomething) { |
| 6912 | if (printedTitle) pw.println(" "); |
| 6913 | pw.println("Permissions:"); |
| 6914 | printedSomething = true; |
| 6915 | printedTitle = true; |
| 6916 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6917 | pw.print(" Permission ["); pw.print(p.name); pw.print("] ("); |
| 6918 | pw.print(Integer.toHexString(System.identityHashCode(p))); |
| 6919 | pw.println("):"); |
| 6920 | pw.print(" sourcePackage="); pw.println(p.sourcePackage); |
| 6921 | pw.print(" uid="); pw.print(p.uid); |
| 6922 | pw.print(" gids="); pw.print(arrayToString(p.gids)); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6923 | pw.print(" type="); pw.print(p.type); |
| 6924 | pw.print(" prot="); pw.println(p.protectionLevel); |
| 6925 | if (p.packageSetting != null) { |
| 6926 | pw.print(" packageSetting="); pw.println(p.packageSetting); |
| 6927 | } |
| 6928 | if (p.perm != null) { |
| 6929 | pw.print(" perm="); pw.println(p.perm); |
| 6930 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6931 | } |
| 6932 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6933 | printedSomething = false; |
| 6934 | SharedUserSetting packageSharedUser = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6935 | { |
| 6936 | for (PackageSetting ps : mSettings.mPackages.values()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6937 | if (packageName != null && !packageName.equals(ps.realName) |
| 6938 | && !packageName.equals(ps.name)) { |
| 6939 | continue; |
| 6940 | } |
| 6941 | if (!printedSomething) { |
| 6942 | if (printedTitle) pw.println(" "); |
| 6943 | pw.println("Packages:"); |
| 6944 | printedSomething = true; |
| 6945 | printedTitle = true; |
| 6946 | } |
| 6947 | packageSharedUser = ps.sharedUser; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6948 | pw.print(" Package ["); |
| 6949 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 6950 | pw.print("] ("); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6951 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 6952 | pw.println("):"); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6953 | if (ps.realName != null) { |
| 6954 | pw.print(" compat name="); pw.println(ps.name); |
| 6955 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6956 | pw.print(" userId="); pw.print(ps.userId); |
| 6957 | pw.print(" gids="); pw.println(arrayToString(ps.gids)); |
| 6958 | pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 6959 | pw.print(" pkg="); pw.println(ps.pkg); |
| 6960 | pw.print(" codePath="); pw.println(ps.codePathString); |
| 6961 | pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6962 | pw.print(" nativeLibraryPath="); pw.println(ps.nativeLibraryPathString); |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 6963 | pw.print(" obbPath="); pw.println(ps.obbPathString); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6964 | if (ps.pkg != null) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6965 | pw.print(" dataDir="); pw.println(ps.pkg.applicationInfo.dataDir); |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6966 | pw.print(" targetSdk="); pw.println(ps.pkg.applicationInfo.targetSdkVersion); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6967 | if (ps.pkg.mOperationPending) { |
| 6968 | pw.println(" mOperationPending=true"); |
| 6969 | } |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6970 | pw.print(" supportsScreens=["); |
| 6971 | boolean first = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6972 | if ((ps.pkg.applicationInfo.flags & |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 6973 | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) { |
| 6974 | if (!first) pw.print(", "); |
| 6975 | first = false; |
| 6976 | pw.print("small"); |
| 6977 | } |
| 6978 | if ((ps.pkg.applicationInfo.flags & |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6979 | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) { |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6980 | if (!first) pw.print(", "); |
| 6981 | first = false; |
| 6982 | pw.print("medium"); |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6983 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6984 | if ((ps.pkg.applicationInfo.flags & |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6985 | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) { |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6986 | if (!first) pw.print(", "); |
| 6987 | first = false; |
| 6988 | pw.print("large"); |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6989 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6990 | if ((ps.pkg.applicationInfo.flags & |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 6991 | ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) { |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6992 | if (!first) pw.print(", "); |
| 6993 | first = false; |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 6994 | pw.print("xlarge"); |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6995 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6996 | if ((ps.pkg.applicationInfo.flags & |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 6997 | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) { |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6998 | if (!first) pw.print(", "); |
| 6999 | first = false; |
| 7000 | pw.print("resizeable"); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 7001 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7002 | if ((ps.pkg.applicationInfo.flags & |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7003 | ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) { |
| 7004 | if (!first) pw.print(", "); |
| 7005 | first = false; |
| 7006 | pw.print("anyDensity"); |
| 7007 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7008 | } |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7009 | pw.println("]"); |
| Kenny Root | 7d794fb | 2010-09-13 16:29:49 -0700 | [diff] [blame] | 7010 | pw.print(" timeStamp="); pw.println(String.valueOf(ps.timeStamp)); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7011 | pw.print(" signatures="); pw.println(ps.signatures); |
| 7012 | pw.print(" permissionsFixed="); pw.print(ps.permissionsFixed); |
| Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7013 | pw.print(" haveGids="); pw.println(ps.haveGids); |
| 7014 | pw.print(" pkgFlags=0x"); pw.print(Integer.toHexString(ps.pkgFlags)); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7015 | pw.print(" installStatus="); pw.print(ps.installStatus); |
| 7016 | pw.print(" enabled="); pw.println(ps.enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7017 | if (ps.disabledComponents.size() > 0) { |
| 7018 | pw.println(" disabledComponents:"); |
| 7019 | for (String s : ps.disabledComponents) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7020 | pw.print(" "); pw.println(s); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7021 | } |
| 7022 | } |
| 7023 | if (ps.enabledComponents.size() > 0) { |
| 7024 | pw.println(" enabledComponents:"); |
| 7025 | for (String s : ps.enabledComponents) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7026 | pw.print(" "); pw.println(s); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7027 | } |
| 7028 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7029 | if (ps.grantedPermissions.size() > 0) { |
| 7030 | pw.println(" grantedPermissions:"); |
| 7031 | for (String s : ps.grantedPermissions) { |
| 7032 | pw.print(" "); pw.println(s); |
| 7033 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7034 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7035 | } |
| 7036 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7037 | printedSomething = false; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7038 | if (mSettings.mRenamedPackages.size() > 0) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7039 | for (HashMap.Entry<String, String> e |
| 7040 | : mSettings.mRenamedPackages.entrySet()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7041 | if (packageName != null && !packageName.equals(e.getKey()) |
| 7042 | && !packageName.equals(e.getValue())) { |
| 7043 | continue; |
| 7044 | } |
| 7045 | if (!printedSomething) { |
| 7046 | if (printedTitle) pw.println(" "); |
| 7047 | pw.println("Renamed packages:"); |
| 7048 | printedSomething = true; |
| 7049 | printedTitle = true; |
| 7050 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7051 | pw.print(" "); pw.print(e.getKey()); pw.print(" -> "); |
| 7052 | pw.println(e.getValue()); |
| 7053 | } |
| 7054 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7055 | printedSomething = false; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7056 | if (mSettings.mDisabledSysPackages.size() > 0) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7057 | for (PackageSetting ps : mSettings.mDisabledSysPackages.values()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7058 | if (packageName != null && !packageName.equals(ps.realName) |
| 7059 | && !packageName.equals(ps.name)) { |
| 7060 | continue; |
| 7061 | } |
| 7062 | if (!printedSomething) { |
| 7063 | if (printedTitle) pw.println(" "); |
| 7064 | pw.println("Hidden system packages:"); |
| 7065 | printedSomething = true; |
| 7066 | printedTitle = true; |
| 7067 | } |
| 7068 | pw.print(" Package ["); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7069 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 7070 | pw.print("] ("); |
| 7071 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 7072 | pw.println("):"); |
| 7073 | if (ps.realName != null) { |
| 7074 | pw.print(" compat name="); pw.println(ps.name); |
| 7075 | } |
| 7076 | pw.print(" userId="); pw.println(ps.userId); |
| 7077 | pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 7078 | pw.print(" codePath="); pw.println(ps.codePathString); |
| 7079 | pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
| 7080 | } |
| 7081 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7082 | printedSomething = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7083 | { |
| 7084 | for (SharedUserSetting su : mSettings.mSharedUsers.values()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7085 | if (packageName != null && su != packageSharedUser) { |
| 7086 | continue; |
| 7087 | } |
| 7088 | if (!printedSomething) { |
| 7089 | if (printedTitle) pw.println(" "); |
| 7090 | pw.println("Shared users:"); |
| 7091 | printedSomething = true; |
| 7092 | printedTitle = true; |
| 7093 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7094 | pw.print(" SharedUser ["); pw.print(su.name); pw.print("] ("); |
| 7095 | pw.print(Integer.toHexString(System.identityHashCode(su))); |
| 7096 | pw.println("):"); |
| 7097 | pw.print(" userId="); pw.print(su.userId); |
| 7098 | pw.print(" gids="); pw.println(arrayToString(su.gids)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7099 | pw.println(" grantedPermissions:"); |
| 7100 | for (String s : su.grantedPermissions) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7101 | pw.print(" "); pw.println(s); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7102 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7103 | } |
| 7104 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7105 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7106 | if (packageName == null) { |
| 7107 | if (printedTitle) pw.println(" "); |
| 7108 | printedTitle = true; |
| 7109 | pw.println("Settings parse messages:"); |
| 7110 | pw.println(mSettings.mReadMessages.toString()); |
| 7111 | |
| 7112 | pw.println(" "); |
| 7113 | pw.println("Package warning messages:"); |
| 7114 | File fname = getSettingsProblemFile(); |
| 7115 | FileInputStream in; |
| 7116 | try { |
| 7117 | in = new FileInputStream(fname); |
| 7118 | int avail = in.available(); |
| 7119 | byte[] data = new byte[avail]; |
| 7120 | in.read(data); |
| 7121 | pw.println(new String(data)); |
| 7122 | } catch (FileNotFoundException e) { |
| 7123 | } catch (IOException e) { |
| 7124 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7125 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7126 | } |
| Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7127 | |
| 7128 | synchronized (mProviders) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7129 | boolean printedSomething = false; |
| Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7130 | for (PackageParser.Provider p : mProviders.values()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7131 | if (packageName != null && !packageName.equals(p.info.packageName)) { |
| 7132 | continue; |
| 7133 | } |
| 7134 | if (!printedSomething) { |
| 7135 | if (printedTitle) pw.println(" "); |
| 7136 | pw.println("Registered ContentProviders:"); |
| 7137 | printedSomething = true; |
| 7138 | printedTitle = true; |
| 7139 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7140 | pw.print(" ["); pw.print(p.info.authority); pw.print("]: "); |
| Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7141 | pw.println(p.toString()); |
| 7142 | } |
| 7143 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7144 | } |
| 7145 | |
| 7146 | static final class BasePermission { |
| 7147 | final static int TYPE_NORMAL = 0; |
| 7148 | final static int TYPE_BUILTIN = 1; |
| 7149 | final static int TYPE_DYNAMIC = 2; |
| 7150 | |
| 7151 | final String name; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7152 | String sourcePackage; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7153 | PackageSettingBase packageSetting; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7154 | final int type; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7155 | int protectionLevel; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7156 | PackageParser.Permission perm; |
| 7157 | PermissionInfo pendingInfo; |
| 7158 | int uid; |
| 7159 | int[] gids; |
| 7160 | |
| 7161 | BasePermission(String _name, String _sourcePackage, int _type) { |
| 7162 | name = _name; |
| 7163 | sourcePackage = _sourcePackage; |
| 7164 | type = _type; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7165 | // Default to most conservative protection level. |
| 7166 | protectionLevel = PermissionInfo.PROTECTION_SIGNATURE; |
| 7167 | } |
| 7168 | |
| 7169 | public String toString() { |
| 7170 | return "BasePermission{" |
| 7171 | + Integer.toHexString(System.identityHashCode(this)) |
| 7172 | + " " + name + "}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7173 | } |
| 7174 | } |
| 7175 | |
| 7176 | static class PackageSignatures { |
| 7177 | private Signature[] mSignatures; |
| 7178 | |
| 7179 | PackageSignatures(Signature[] sigs) { |
| 7180 | assignSignatures(sigs); |
| 7181 | } |
| 7182 | |
| 7183 | PackageSignatures() { |
| 7184 | } |
| 7185 | |
| 7186 | void writeXml(XmlSerializer serializer, String tagName, |
| 7187 | ArrayList<Signature> pastSignatures) throws IOException { |
| 7188 | if (mSignatures == null) { |
| 7189 | return; |
| 7190 | } |
| 7191 | serializer.startTag(null, tagName); |
| 7192 | serializer.attribute(null, "count", |
| 7193 | Integer.toString(mSignatures.length)); |
| 7194 | for (int i=0; i<mSignatures.length; i++) { |
| 7195 | serializer.startTag(null, "cert"); |
| 7196 | final Signature sig = mSignatures[i]; |
| 7197 | final int sigHash = sig.hashCode(); |
| 7198 | final int numPast = pastSignatures.size(); |
| 7199 | int j; |
| 7200 | for (j=0; j<numPast; j++) { |
| 7201 | Signature pastSig = pastSignatures.get(j); |
| 7202 | if (pastSig.hashCode() == sigHash && pastSig.equals(sig)) { |
| 7203 | serializer.attribute(null, "index", Integer.toString(j)); |
| 7204 | break; |
| 7205 | } |
| 7206 | } |
| 7207 | if (j >= numPast) { |
| 7208 | pastSignatures.add(sig); |
| 7209 | serializer.attribute(null, "index", Integer.toString(numPast)); |
| 7210 | serializer.attribute(null, "key", sig.toCharsString()); |
| 7211 | } |
| 7212 | serializer.endTag(null, "cert"); |
| 7213 | } |
| 7214 | serializer.endTag(null, tagName); |
| 7215 | } |
| 7216 | |
| 7217 | void readXml(XmlPullParser parser, ArrayList<Signature> pastSignatures) |
| 7218 | throws IOException, XmlPullParserException { |
| 7219 | String countStr = parser.getAttributeValue(null, "count"); |
| 7220 | if (countStr == null) { |
| 7221 | reportSettingsProblem(Log.WARN, |
| 7222 | "Error in package manager settings: <signatures> has" |
| 7223 | + " no count at " + parser.getPositionDescription()); |
| 7224 | XmlUtils.skipCurrentTag(parser); |
| 7225 | } |
| 7226 | final int count = Integer.parseInt(countStr); |
| 7227 | mSignatures = new Signature[count]; |
| 7228 | int pos = 0; |
| 7229 | |
| 7230 | int outerDepth = parser.getDepth(); |
| 7231 | int type; |
| 7232 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 7233 | && (type != XmlPullParser.END_TAG |
| 7234 | || parser.getDepth() > outerDepth)) { |
| 7235 | if (type == XmlPullParser.END_TAG |
| 7236 | || type == XmlPullParser.TEXT) { |
| 7237 | continue; |
| 7238 | } |
| 7239 | |
| 7240 | String tagName = parser.getName(); |
| 7241 | if (tagName.equals("cert")) { |
| 7242 | if (pos < count) { |
| 7243 | String index = parser.getAttributeValue(null, "index"); |
| 7244 | if (index != null) { |
| 7245 | try { |
| 7246 | int idx = Integer.parseInt(index); |
| 7247 | String key = parser.getAttributeValue(null, "key"); |
| 7248 | if (key == null) { |
| 7249 | if (idx >= 0 && idx < pastSignatures.size()) { |
| 7250 | Signature sig = pastSignatures.get(idx); |
| 7251 | if (sig != null) { |
| 7252 | mSignatures[pos] = pastSignatures.get(idx); |
| 7253 | pos++; |
| 7254 | } else { |
| 7255 | reportSettingsProblem(Log.WARN, |
| 7256 | "Error in package manager settings: <cert> " |
| 7257 | + "index " + index + " is not defined at " |
| 7258 | + parser.getPositionDescription()); |
| 7259 | } |
| 7260 | } else { |
| 7261 | reportSettingsProblem(Log.WARN, |
| 7262 | "Error in package manager settings: <cert> " |
| 7263 | + "index " + index + " is out of bounds at " |
| 7264 | + parser.getPositionDescription()); |
| 7265 | } |
| 7266 | } else { |
| 7267 | while (pastSignatures.size() <= idx) { |
| 7268 | pastSignatures.add(null); |
| 7269 | } |
| 7270 | Signature sig = new Signature(key); |
| 7271 | pastSignatures.set(idx, sig); |
| 7272 | mSignatures[pos] = sig; |
| 7273 | pos++; |
| 7274 | } |
| 7275 | } catch (NumberFormatException e) { |
| 7276 | reportSettingsProblem(Log.WARN, |
| 7277 | "Error in package manager settings: <cert> " |
| 7278 | + "index " + index + " is not a number at " |
| 7279 | + parser.getPositionDescription()); |
| 7280 | } |
| 7281 | } else { |
| 7282 | reportSettingsProblem(Log.WARN, |
| 7283 | "Error in package manager settings: <cert> has" |
| 7284 | + " no index at " + parser.getPositionDescription()); |
| 7285 | } |
| 7286 | } else { |
| 7287 | reportSettingsProblem(Log.WARN, |
| 7288 | "Error in package manager settings: too " |
| 7289 | + "many <cert> tags, expected " + count |
| 7290 | + " at " + parser.getPositionDescription()); |
| 7291 | } |
| 7292 | } else { |
| 7293 | reportSettingsProblem(Log.WARN, |
| 7294 | "Unknown element under <cert>: " |
| 7295 | + parser.getName()); |
| 7296 | } |
| 7297 | XmlUtils.skipCurrentTag(parser); |
| 7298 | } |
| 7299 | |
| 7300 | if (pos < count) { |
| 7301 | // Should never happen -- there is an error in the written |
| 7302 | // settings -- but if it does we don't want to generate |
| 7303 | // a bad array. |
| 7304 | Signature[] newSigs = new Signature[pos]; |
| 7305 | System.arraycopy(mSignatures, 0, newSigs, 0, pos); |
| 7306 | mSignatures = newSigs; |
| 7307 | } |
| 7308 | } |
| 7309 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7310 | private void assignSignatures(Signature[] sigs) { |
| 7311 | if (sigs == null) { |
| 7312 | mSignatures = null; |
| 7313 | return; |
| 7314 | } |
| 7315 | mSignatures = new Signature[sigs.length]; |
| 7316 | for (int i=0; i<sigs.length; i++) { |
| 7317 | mSignatures[i] = sigs[i]; |
| 7318 | } |
| 7319 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7321 | @Override |
| 7322 | public String toString() { |
| 7323 | StringBuffer buf = new StringBuffer(128); |
| 7324 | buf.append("PackageSignatures{"); |
| 7325 | buf.append(Integer.toHexString(System.identityHashCode(this))); |
| 7326 | buf.append(" ["); |
| 7327 | if (mSignatures != null) { |
| 7328 | for (int i=0; i<mSignatures.length; i++) { |
| 7329 | if (i > 0) buf.append(", "); |
| 7330 | buf.append(Integer.toHexString( |
| 7331 | System.identityHashCode(mSignatures[i]))); |
| 7332 | } |
| 7333 | } |
| 7334 | buf.append("]}"); |
| 7335 | return buf.toString(); |
| 7336 | } |
| 7337 | } |
| 7338 | |
| 7339 | static class PreferredActivity extends IntentFilter { |
| 7340 | final int mMatch; |
| 7341 | final String[] mSetPackages; |
| 7342 | final String[] mSetClasses; |
| 7343 | final String[] mSetComponents; |
| 7344 | final ComponentName mActivity; |
| 7345 | final String mShortActivity; |
| 7346 | String mParseError; |
| 7347 | |
| 7348 | PreferredActivity(IntentFilter filter, int match, ComponentName[] set, |
| 7349 | ComponentName activity) { |
| 7350 | super(filter); |
| 7351 | mMatch = match&IntentFilter.MATCH_CATEGORY_MASK; |
| 7352 | mActivity = activity; |
| 7353 | mShortActivity = activity.flattenToShortString(); |
| 7354 | mParseError = null; |
| 7355 | if (set != null) { |
| 7356 | final int N = set.length; |
| 7357 | String[] myPackages = new String[N]; |
| 7358 | String[] myClasses = new String[N]; |
| 7359 | String[] myComponents = new String[N]; |
| 7360 | for (int i=0; i<N; i++) { |
| 7361 | ComponentName cn = set[i]; |
| 7362 | if (cn == null) { |
| 7363 | mSetPackages = null; |
| 7364 | mSetClasses = null; |
| 7365 | mSetComponents = null; |
| 7366 | return; |
| 7367 | } |
| 7368 | myPackages[i] = cn.getPackageName().intern(); |
| 7369 | myClasses[i] = cn.getClassName().intern(); |
| 7370 | myComponents[i] = cn.flattenToShortString().intern(); |
| 7371 | } |
| 7372 | mSetPackages = myPackages; |
| 7373 | mSetClasses = myClasses; |
| 7374 | mSetComponents = myComponents; |
| 7375 | } else { |
| 7376 | mSetPackages = null; |
| 7377 | mSetClasses = null; |
| 7378 | mSetComponents = null; |
| 7379 | } |
| 7380 | } |
| 7381 | |
| 7382 | PreferredActivity(XmlPullParser parser) throws XmlPullParserException, |
| 7383 | IOException { |
| 7384 | mShortActivity = parser.getAttributeValue(null, "name"); |
| 7385 | mActivity = ComponentName.unflattenFromString(mShortActivity); |
| 7386 | if (mActivity == null) { |
| 7387 | mParseError = "Bad activity name " + mShortActivity; |
| 7388 | } |
| 7389 | String matchStr = parser.getAttributeValue(null, "match"); |
| 7390 | mMatch = matchStr != null ? Integer.parseInt(matchStr, 16) : 0; |
| 7391 | String setCountStr = parser.getAttributeValue(null, "set"); |
| 7392 | int setCount = setCountStr != null ? Integer.parseInt(setCountStr) : 0; |
| 7393 | |
| 7394 | String[] myPackages = setCount > 0 ? new String[setCount] : null; |
| 7395 | String[] myClasses = setCount > 0 ? new String[setCount] : null; |
| 7396 | String[] myComponents = setCount > 0 ? new String[setCount] : null; |
| 7397 | |
| 7398 | int setPos = 0; |
| 7399 | |
| 7400 | int outerDepth = parser.getDepth(); |
| 7401 | int type; |
| 7402 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 7403 | && (type != XmlPullParser.END_TAG |
| 7404 | || parser.getDepth() > outerDepth)) { |
| 7405 | if (type == XmlPullParser.END_TAG |
| 7406 | || type == XmlPullParser.TEXT) { |
| 7407 | continue; |
| 7408 | } |
| 7409 | |
| 7410 | String tagName = parser.getName(); |
| 7411 | //Log.i(TAG, "Parse outerDepth=" + outerDepth + " depth=" |
| 7412 | // + parser.getDepth() + " tag=" + tagName); |
| 7413 | if (tagName.equals("set")) { |
| 7414 | String name = parser.getAttributeValue(null, "name"); |
| 7415 | if (name == null) { |
| 7416 | if (mParseError == null) { |
| 7417 | mParseError = "No name in set tag in preferred activity " |
| 7418 | + mShortActivity; |
| 7419 | } |
| 7420 | } else if (setPos >= setCount) { |
| 7421 | if (mParseError == null) { |
| 7422 | mParseError = "Too many set tags in preferred activity " |
| 7423 | + mShortActivity; |
| 7424 | } |
| 7425 | } else { |
| 7426 | ComponentName cn = ComponentName.unflattenFromString(name); |
| 7427 | if (cn == null) { |
| 7428 | if (mParseError == null) { |
| 7429 | mParseError = "Bad set name " + name + " in preferred activity " |
| 7430 | + mShortActivity; |
| 7431 | } |
| 7432 | } else { |
| 7433 | myPackages[setPos] = cn.getPackageName(); |
| 7434 | myClasses[setPos] = cn.getClassName(); |
| 7435 | myComponents[setPos] = name; |
| 7436 | setPos++; |
| 7437 | } |
| 7438 | } |
| 7439 | XmlUtils.skipCurrentTag(parser); |
| 7440 | } else if (tagName.equals("filter")) { |
| 7441 | //Log.i(TAG, "Starting to parse filter..."); |
| 7442 | readFromXml(parser); |
| 7443 | //Log.i(TAG, "Finished filter: outerDepth=" + outerDepth + " depth=" |
| 7444 | // + parser.getDepth() + " tag=" + parser.getName()); |
| 7445 | } else { |
| 7446 | reportSettingsProblem(Log.WARN, |
| 7447 | "Unknown element under <preferred-activities>: " |
| 7448 | + parser.getName()); |
| 7449 | XmlUtils.skipCurrentTag(parser); |
| 7450 | } |
| 7451 | } |
| 7452 | |
| 7453 | if (setPos != setCount) { |
| 7454 | if (mParseError == null) { |
| 7455 | mParseError = "Not enough set tags (expected " + setCount |
| 7456 | + " but found " + setPos + ") in " + mShortActivity; |
| 7457 | } |
| 7458 | } |
| 7459 | |
| 7460 | mSetPackages = myPackages; |
| 7461 | mSetClasses = myClasses; |
| 7462 | mSetComponents = myComponents; |
| 7463 | } |
| 7464 | |
| 7465 | public void writeToXml(XmlSerializer serializer) throws IOException { |
| 7466 | final int NS = mSetClasses != null ? mSetClasses.length : 0; |
| 7467 | serializer.attribute(null, "name", mShortActivity); |
| 7468 | serializer.attribute(null, "match", Integer.toHexString(mMatch)); |
| 7469 | serializer.attribute(null, "set", Integer.toString(NS)); |
| 7470 | for (int s=0; s<NS; s++) { |
| 7471 | serializer.startTag(null, "set"); |
| 7472 | serializer.attribute(null, "name", mSetComponents[s]); |
| 7473 | serializer.endTag(null, "set"); |
| 7474 | } |
| 7475 | serializer.startTag(null, "filter"); |
| 7476 | super.writeToXml(serializer); |
| 7477 | serializer.endTag(null, "filter"); |
| 7478 | } |
| 7479 | |
| 7480 | boolean sameSet(List<ResolveInfo> query, int priority) { |
| 7481 | if (mSetPackages == null) return false; |
| 7482 | final int NQ = query.size(); |
| 7483 | final int NS = mSetPackages.length; |
| 7484 | int numMatch = 0; |
| 7485 | for (int i=0; i<NQ; i++) { |
| 7486 | ResolveInfo ri = query.get(i); |
| 7487 | if (ri.priority != priority) continue; |
| 7488 | ActivityInfo ai = ri.activityInfo; |
| 7489 | boolean good = false; |
| 7490 | for (int j=0; j<NS; j++) { |
| 7491 | if (mSetPackages[j].equals(ai.packageName) |
| 7492 | && mSetClasses[j].equals(ai.name)) { |
| 7493 | numMatch++; |
| 7494 | good = true; |
| 7495 | break; |
| 7496 | } |
| 7497 | } |
| 7498 | if (!good) return false; |
| 7499 | } |
| 7500 | return numMatch == NS; |
| 7501 | } |
| 7502 | } |
| 7503 | |
| 7504 | static class GrantedPermissions { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 7505 | int pkgFlags; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7506 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7507 | HashSet<String> grantedPermissions = new HashSet<String>(); |
| 7508 | int[] gids; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7509 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7510 | GrantedPermissions(int pkgFlags) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 7511 | setFlags(pkgFlags); |
| 7512 | } |
| 7513 | |
| 7514 | void setFlags(int pkgFlags) { |
| Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 7515 | this.pkgFlags = pkgFlags & ( |
| 7516 | ApplicationInfo.FLAG_SYSTEM | |
| 7517 | ApplicationInfo.FLAG_FORWARD_LOCK | |
| Jeff Brown | a749f86 | 2010-03-31 00:43:36 -0700 | [diff] [blame] | 7518 | ApplicationInfo.FLAG_EXTERNAL_STORAGE | |
| Jeff Brown | 767225d | 2010-03-30 23:49:17 -0700 | [diff] [blame] | 7519 | ApplicationInfo.FLAG_NEVER_ENCRYPT); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7520 | } |
| 7521 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7522 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7523 | /** |
| 7524 | * Settings base class for pending and resolved classes. |
| 7525 | */ |
| 7526 | static class PackageSettingBase extends GrantedPermissions { |
| 7527 | final String name; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7528 | final String realName; |
| Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 7529 | File codePath; |
| 7530 | String codePathString; |
| 7531 | File resourcePath; |
| 7532 | String resourcePathString; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 7533 | String nativeLibraryPathString; |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 7534 | String obbPathString; |
| Kenny Root | 7d794fb | 2010-09-13 16:29:49 -0700 | [diff] [blame] | 7535 | long timeStamp; |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 7536 | int versionCode; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7537 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7538 | boolean uidError; |
| 7539 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7540 | PackageSignatures signatures = new PackageSignatures(); |
| 7541 | |
| 7542 | boolean permissionsFixed; |
| Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7543 | boolean haveGids; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7545 | /* Explicitly disabled components */ |
| 7546 | HashSet<String> disabledComponents = new HashSet<String>(0); |
| 7547 | /* Explicitly enabled components */ |
| 7548 | HashSet<String> enabledComponents = new HashSet<String>(0); |
| 7549 | int enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 7550 | int installStatus = PKG_INSTALL_COMPLETE; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7551 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7552 | PackageSettingBase origPackage; |
| 7553 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7554 | /* package name of the app that installed this package */ |
| 7555 | String installerPackageName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7556 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7557 | PackageSettingBase(String name, String realName, File codePath, File resourcePath, |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7558 | String nativeLibraryPathString, int pVersionCode, int pkgFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7559 | super(pkgFlags); |
| 7560 | this.name = name; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7561 | this.realName = realName; |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7562 | init(codePath, resourcePath, nativeLibraryPathString, pVersionCode); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7563 | } |
| 7564 | |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7565 | void init(File codePath, File resourcePath, String nativeLibraryPathString, |
| 7566 | int pVersionCode) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7567 | this.codePath = codePath; |
| 7568 | this.codePathString = codePath.toString(); |
| 7569 | this.resourcePath = resourcePath; |
| 7570 | this.resourcePathString = resourcePath.toString(); |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7571 | this.nativeLibraryPathString = nativeLibraryPathString; |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7572 | this.versionCode = pVersionCode; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7573 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 7574 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7575 | public void setInstallerPackageName(String packageName) { |
| 7576 | installerPackageName = packageName; |
| 7577 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7578 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7579 | String getInstallerPackageName() { |
| 7580 | return installerPackageName; |
| 7581 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7582 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7583 | public void setInstallStatus(int newStatus) { |
| 7584 | installStatus = newStatus; |
| 7585 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7586 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7587 | public int getInstallStatus() { |
| 7588 | return installStatus; |
| 7589 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7590 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7591 | public void setTimeStamp(long newStamp) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7592 | timeStamp = newStamp; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7593 | } |
| 7594 | |
| 7595 | public void copyFrom(PackageSettingBase base) { |
| 7596 | grantedPermissions = base.grantedPermissions; |
| 7597 | gids = base.gids; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7599 | timeStamp = base.timeStamp; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7600 | signatures = base.signatures; |
| 7601 | permissionsFixed = base.permissionsFixed; |
| Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7602 | haveGids = base.haveGids; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7603 | disabledComponents = base.disabledComponents; |
| 7604 | enabledComponents = base.enabledComponents; |
| 7605 | enabled = base.enabled; |
| 7606 | installStatus = base.installStatus; |
| 7607 | } |
| 7608 | |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 7609 | boolean enableComponentLP(String componentClassName) { |
| 7610 | boolean changed = disabledComponents.remove(componentClassName); |
| 7611 | changed |= enabledComponents.add(componentClassName); |
| 7612 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7613 | } |
| 7614 | |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 7615 | boolean disableComponentLP(String componentClassName) { |
| 7616 | boolean changed = enabledComponents.remove(componentClassName); |
| 7617 | changed |= disabledComponents.add(componentClassName); |
| 7618 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7619 | } |
| 7620 | |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 7621 | boolean restoreComponentLP(String componentClassName) { |
| 7622 | boolean changed = enabledComponents.remove(componentClassName); |
| 7623 | changed |= disabledComponents.remove(componentClassName); |
| 7624 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7625 | } |
| 7626 | |
| 7627 | int currentEnabledStateLP(String componentName) { |
| 7628 | if (enabledComponents.contains(componentName)) { |
| 7629 | return COMPONENT_ENABLED_STATE_ENABLED; |
| 7630 | } else if (disabledComponents.contains(componentName)) { |
| 7631 | return COMPONENT_ENABLED_STATE_DISABLED; |
| 7632 | } else { |
| 7633 | return COMPONENT_ENABLED_STATE_DEFAULT; |
| 7634 | } |
| 7635 | } |
| 7636 | } |
| 7637 | |
| 7638 | /** |
| 7639 | * Settings data for a particular package we know about. |
| 7640 | */ |
| 7641 | static final class PackageSetting extends PackageSettingBase { |
| 7642 | int userId; |
| 7643 | PackageParser.Package pkg; |
| 7644 | SharedUserSetting sharedUser; |
| 7645 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7646 | PackageSetting(String name, String realName, File codePath, File resourcePath, |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7647 | String nativeLibraryPathString, int pVersionCode, int pkgFlags) { |
| 7648 | super(name, realName, codePath, resourcePath, nativeLibraryPathString, pVersionCode, |
| 7649 | pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7650 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7651 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7652 | @Override |
| 7653 | public String toString() { |
| 7654 | return "PackageSetting{" |
| 7655 | + Integer.toHexString(System.identityHashCode(this)) |
| 7656 | + " " + name + "/" + userId + "}"; |
| 7657 | } |
| 7658 | } |
| 7659 | |
| 7660 | /** |
| 7661 | * Settings data for a particular shared user ID we know about. |
| 7662 | */ |
| 7663 | static final class SharedUserSetting extends GrantedPermissions { |
| 7664 | final String name; |
| 7665 | int userId; |
| 7666 | final HashSet<PackageSetting> packages = new HashSet<PackageSetting>(); |
| 7667 | final PackageSignatures signatures = new PackageSignatures(); |
| 7668 | |
| 7669 | SharedUserSetting(String _name, int _pkgFlags) { |
| 7670 | super(_pkgFlags); |
| 7671 | name = _name; |
| 7672 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7674 | @Override |
| 7675 | public String toString() { |
| 7676 | return "SharedUserSetting{" |
| 7677 | + Integer.toHexString(System.identityHashCode(this)) |
| 7678 | + " " + name + "/" + userId + "}"; |
| 7679 | } |
| 7680 | } |
| 7681 | |
| 7682 | /** |
| 7683 | * Holds information about dynamic settings. |
| 7684 | */ |
| 7685 | private static final class Settings { |
| 7686 | private final File mSettingsFilename; |
| 7687 | private final File mBackupSettingsFilename; |
| David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 7688 | private final File mPackageListFilename; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7689 | private final HashMap<String, PackageSetting> mPackages = |
| 7690 | new HashMap<String, PackageSetting>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7691 | // List of replaced system applications |
| 7692 | final HashMap<String, PackageSetting> mDisabledSysPackages = |
| 7693 | new HashMap<String, PackageSetting>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7694 | |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 7695 | // These are the last platform API version we were using for |
| 7696 | // the apps installed on internal and external storage. It is |
| 7697 | // used to grant newer permissions one time during a system upgrade. |
| 7698 | int mInternalSdkPlatform; |
| 7699 | int mExternalSdkPlatform; |
| 7700 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7701 | // The user's preferred activities associated with particular intent |
| 7702 | // filters. |
| 7703 | private final IntentResolver<PreferredActivity, PreferredActivity> mPreferredActivities = |
| 7704 | new IntentResolver<PreferredActivity, PreferredActivity>() { |
| 7705 | @Override |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7706 | protected String packageForFilter(PreferredActivity filter) { |
| 7707 | return filter.mActivity.getPackageName(); |
| 7708 | } |
| 7709 | @Override |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7710 | protected void dumpFilter(PrintWriter out, String prefix, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7711 | PreferredActivity filter) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7712 | out.print(prefix); out.print( |
| 7713 | Integer.toHexString(System.identityHashCode(filter))); |
| 7714 | out.print(' '); |
| 7715 | out.print(filter.mActivity.flattenToShortString()); |
| 7716 | out.print(" match=0x"); |
| 7717 | out.println( Integer.toHexString(filter.mMatch)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7718 | if (filter.mSetComponents != null) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7719 | out.print(prefix); out.println(" Selected from:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7720 | for (int i=0; i<filter.mSetComponents.length; i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7721 | out.print(prefix); out.print(" "); |
| 7722 | out.println(filter.mSetComponents[i]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7723 | } |
| 7724 | } |
| 7725 | } |
| 7726 | }; |
| 7727 | private final HashMap<String, SharedUserSetting> mSharedUsers = |
| 7728 | new HashMap<String, SharedUserSetting>(); |
| 7729 | private final ArrayList<Object> mUserIds = new ArrayList<Object>(); |
| 7730 | private final SparseArray<Object> mOtherUserIds = |
| 7731 | new SparseArray<Object>(); |
| 7732 | |
| 7733 | // For reading/writing settings file. |
| 7734 | private final ArrayList<Signature> mPastSignatures = |
| 7735 | new ArrayList<Signature>(); |
| 7736 | |
| 7737 | // Mapping from permission names to info about them. |
| 7738 | final HashMap<String, BasePermission> mPermissions = |
| 7739 | new HashMap<String, BasePermission>(); |
| 7740 | |
| 7741 | // Mapping from permission tree names to info about them. |
| 7742 | final HashMap<String, BasePermission> mPermissionTrees = |
| 7743 | new HashMap<String, BasePermission>(); |
| 7744 | |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 7745 | // Packages that have been uninstalled and still need their external |
| 7746 | // storage data deleted. |
| 7747 | final ArrayList<String> mPackagesToBeCleaned = new ArrayList<String>(); |
| 7748 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7749 | // Packages that have been renamed since they were first installed. |
| 7750 | // Keys are the new names of the packages, values are the original |
| 7751 | // names. The packages appear everwhere else under their original |
| 7752 | // names. |
| 7753 | final HashMap<String, String> mRenamedPackages = new HashMap<String, String>(); |
| 7754 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7755 | private final StringBuilder mReadMessages = new StringBuilder(); |
| 7756 | |
| 7757 | private static final class PendingPackage extends PackageSettingBase { |
| 7758 | final int sharedId; |
| 7759 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7760 | PendingPackage(String name, String realName, File codePath, File resourcePath, |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7761 | String nativeLibraryPathString, int sharedId, int pVersionCode, int pkgFlags) { |
| 7762 | super(name, realName, codePath, resourcePath, nativeLibraryPathString, |
| 7763 | pVersionCode, pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7764 | this.sharedId = sharedId; |
| 7765 | } |
| 7766 | } |
| 7767 | private final ArrayList<PendingPackage> mPendingPackages |
| 7768 | = new ArrayList<PendingPackage>(); |
| 7769 | |
| 7770 | Settings() { |
| 7771 | File dataDir = Environment.getDataDirectory(); |
| 7772 | File systemDir = new File(dataDir, "system"); |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7773 | // TODO(oam): This secure dir creation needs to be moved somewhere else (later) |
| 7774 | File systemSecureDir = new File(dataDir, "secure/system"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7775 | systemDir.mkdirs(); |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7776 | systemSecureDir.mkdirs(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7777 | FileUtils.setPermissions(systemDir.toString(), |
| 7778 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 7779 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 7780 | -1, -1); |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7781 | FileUtils.setPermissions(systemSecureDir.toString(), |
| 7782 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 7783 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 7784 | -1, -1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7785 | mSettingsFilename = new File(systemDir, "packages.xml"); |
| 7786 | mBackupSettingsFilename = new File(systemDir, "packages-backup.xml"); |
| David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 7787 | mPackageListFilename = new File(systemDir, "packages.list"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7788 | } |
| 7789 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7790 | PackageSetting getPackageLP(PackageParser.Package pkg, PackageSetting origPackage, |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7791 | String realName, SharedUserSetting sharedUser, File codePath, File resourcePath, |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7792 | String nativeLibraryPathString, int pkgFlags, boolean create, boolean add) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7793 | final String name = pkg.packageName; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7794 | PackageSetting p = getPackageLP(name, origPackage, realName, sharedUser, codePath, |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7795 | resourcePath, nativeLibraryPathString, pkg.mVersionCode, pkgFlags, create, add); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7796 | return p; |
| 7797 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7798 | |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7799 | PackageSetting peekPackageLP(String name) { |
| 7800 | return mPackages.get(name); |
| 7801 | /* |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7802 | PackageSetting p = mPackages.get(name); |
| 7803 | if (p != null && p.codePath.getPath().equals(codePath)) { |
| 7804 | return p; |
| 7805 | } |
| 7806 | return null; |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7807 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7808 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7809 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7810 | void setInstallStatus(String pkgName, int status) { |
| 7811 | PackageSetting p = mPackages.get(pkgName); |
| 7812 | if(p != null) { |
| 7813 | if(p.getInstallStatus() != status) { |
| 7814 | p.setInstallStatus(status); |
| 7815 | } |
| 7816 | } |
| 7817 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7818 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7819 | void setInstallerPackageName(String pkgName, |
| 7820 | String installerPkgName) { |
| 7821 | PackageSetting p = mPackages.get(pkgName); |
| 7822 | if(p != null) { |
| 7823 | p.setInstallerPackageName(installerPkgName); |
| 7824 | } |
| 7825 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7826 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7827 | String getInstallerPackageName(String pkgName) { |
| 7828 | PackageSetting p = mPackages.get(pkgName); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7829 | return (p == null) ? null : p.getInstallerPackageName(); |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7830 | } |
| 7831 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7832 | int getInstallStatus(String pkgName) { |
| 7833 | PackageSetting p = mPackages.get(pkgName); |
| 7834 | if(p != null) { |
| 7835 | return p.getInstallStatus(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7836 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7837 | return -1; |
| 7838 | } |
| 7839 | |
| 7840 | SharedUserSetting getSharedUserLP(String name, |
| 7841 | int pkgFlags, boolean create) { |
| 7842 | SharedUserSetting s = mSharedUsers.get(name); |
| 7843 | if (s == null) { |
| 7844 | if (!create) { |
| 7845 | return null; |
| 7846 | } |
| 7847 | s = new SharedUserSetting(name, pkgFlags); |
| 7848 | if (MULTIPLE_APPLICATION_UIDS) { |
| 7849 | s.userId = newUserIdLP(s); |
| 7850 | } else { |
| 7851 | s.userId = FIRST_APPLICATION_UID; |
| 7852 | } |
| 7853 | Log.i(TAG, "New shared user " + name + ": id=" + s.userId); |
| 7854 | // < 0 means we couldn't assign a userid; fall out and return |
| 7855 | // s, which is currently null |
| 7856 | if (s.userId >= 0) { |
| 7857 | mSharedUsers.put(name, s); |
| 7858 | } |
| 7859 | } |
| 7860 | |
| 7861 | return s; |
| 7862 | } |
| 7863 | |
| 7864 | int disableSystemPackageLP(String name) { |
| 7865 | PackageSetting p = mPackages.get(name); |
| 7866 | if(p == null) { |
| 7867 | Log.w(TAG, "Package:"+name+" is not an installed package"); |
| 7868 | return -1; |
| 7869 | } |
| 7870 | PackageSetting dp = mDisabledSysPackages.get(name); |
| 7871 | // always make sure the system package code and resource paths dont change |
| 7872 | if(dp == null) { |
| 7873 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 7874 | p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 7875 | } |
| 7876 | mDisabledSysPackages.put(name, p); |
| 7877 | } |
| 7878 | return removePackageLP(name); |
| 7879 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7881 | PackageSetting enableSystemPackageLP(String name) { |
| 7882 | PackageSetting p = mDisabledSysPackages.get(name); |
| 7883 | if(p == null) { |
| 7884 | Log.w(TAG, "Package:"+name+" is not disabled"); |
| 7885 | return null; |
| 7886 | } |
| 7887 | // Reset flag in ApplicationInfo object |
| 7888 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 7889 | p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 7890 | } |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7891 | PackageSetting ret = addPackageLP(name, p.realName, p.codePath, p.resourcePath, |
| 7892 | p.nativeLibraryPathString, p.userId, p.versionCode, p.pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7893 | mDisabledSysPackages.remove(name); |
| 7894 | return ret; |
| 7895 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7896 | |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7897 | PackageSetting addPackageLP(String name, String realName, File codePath, File resourcePath, |
| 7898 | String nativeLibraryPathString, int uid, int vc, int pkgFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7899 | PackageSetting p = mPackages.get(name); |
| 7900 | if (p != null) { |
| 7901 | if (p.userId == uid) { |
| 7902 | return p; |
| 7903 | } |
| 7904 | reportSettingsProblem(Log.ERROR, |
| 7905 | "Adding duplicate package, keeping first: " + name); |
| 7906 | return null; |
| 7907 | } |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7908 | p = new PackageSetting(name, realName, codePath, resourcePath, nativeLibraryPathString, |
| 7909 | vc, pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7910 | p.userId = uid; |
| 7911 | if (addUserIdLP(uid, p, name)) { |
| 7912 | mPackages.put(name, p); |
| 7913 | return p; |
| 7914 | } |
| 7915 | return null; |
| 7916 | } |
| 7917 | |
| 7918 | SharedUserSetting addSharedUserLP(String name, int uid, int pkgFlags) { |
| 7919 | SharedUserSetting s = mSharedUsers.get(name); |
| 7920 | if (s != null) { |
| 7921 | if (s.userId == uid) { |
| 7922 | return s; |
| 7923 | } |
| 7924 | reportSettingsProblem(Log.ERROR, |
| 7925 | "Adding duplicate shared user, keeping first: " + name); |
| 7926 | return null; |
| 7927 | } |
| 7928 | s = new SharedUserSetting(name, pkgFlags); |
| 7929 | s.userId = uid; |
| 7930 | if (addUserIdLP(uid, s, name)) { |
| 7931 | mSharedUsers.put(name, s); |
| 7932 | return s; |
| 7933 | } |
| 7934 | return null; |
| 7935 | } |
| 7936 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7937 | // Transfer ownership of permissions from one package to another. |
| 7938 | private void transferPermissions(String origPkg, String newPkg) { |
| 7939 | // Transfer ownership of permissions to the new package. |
| 7940 | for (int i=0; i<2; i++) { |
| 7941 | HashMap<String, BasePermission> permissions = |
| 7942 | i == 0 ? mPermissionTrees : mPermissions; |
| 7943 | for (BasePermission bp : permissions.values()) { |
| 7944 | if (origPkg.equals(bp.sourcePackage)) { |
| 7945 | if (DEBUG_UPGRADE) Log.v(TAG, |
| 7946 | "Moving permission " + bp.name |
| 7947 | + " from pkg " + bp.sourcePackage |
| 7948 | + " to " + newPkg); |
| 7949 | bp.sourcePackage = newPkg; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7950 | bp.packageSetting = null; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7951 | bp.perm = null; |
| 7952 | if (bp.pendingInfo != null) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7953 | bp.pendingInfo.packageName = newPkg; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7954 | } |
| 7955 | bp.uid = 0; |
| 7956 | bp.gids = null; |
| 7957 | } |
| 7958 | } |
| 7959 | } |
| 7960 | } |
| 7961 | |
| 7962 | private PackageSetting getPackageLP(String name, PackageSetting origPackage, |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7963 | String realName, SharedUserSetting sharedUser, File codePath, File resourcePath, |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 7964 | String nativeLibraryPathString, int vc, int pkgFlags, boolean create, boolean add) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7965 | PackageSetting p = mPackages.get(name); |
| 7966 | if (p != null) { |
| 7967 | if (!p.codePath.equals(codePath)) { |
| 7968 | // Check to see if its a disabled system app |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 7969 | if((p != null) && ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| Suchi Amalapurapu | b24a967 | 2009-07-01 14:04:43 -0700 | [diff] [blame] | 7970 | // This is an updated system app with versions in both system |
| 7971 | // and data partition. Just let the most recent version |
| 7972 | // take precedence. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 7973 | Slog.w(TAG, "Trying to update system app code path from " + |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 7974 | p.codePathString + " to " + codePath.toString()); |
| Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 7975 | } else { |
| Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 7976 | // Just a change in the code path is not an issue, but |
| 7977 | // let's log a message about it. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 7978 | Slog.i(TAG, "Package " + name + " codePath changed from " + p.codePath |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 7979 | + " to " + codePath + "; Retaining data and using new"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7980 | } |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 7981 | } |
| 7982 | if (p.sharedUser != sharedUser) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7983 | reportSettingsProblem(Log.WARN, |
| 7984 | "Package " + name + " shared user changed from " |
| 7985 | + (p.sharedUser != null ? p.sharedUser.name : "<nothing>") |
| 7986 | + " to " |
| 7987 | + (sharedUser != null ? sharedUser.name : "<nothing>") |
| 7988 | + "; replacing with new"); |
| 7989 | p = null; |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 7990 | } else { |
| 7991 | if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 7992 | // If what we are scanning is a system package, then |
| 7993 | // make it so, regardless of whether it was previously |
| 7994 | // installed only in the data partition. |
| 7995 | p.pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 7996 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7997 | } |
| 7998 | } |
| 7999 | if (p == null) { |
| 8000 | // Create a new PackageSettings entry. this can end up here because |
| 8001 | // of code path mismatch or user id mismatch of an updated system partition |
| 8002 | if (!create) { |
| 8003 | return null; |
| 8004 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8005 | if (origPackage != null) { |
| 8006 | // We are consuming the data from an existing package. |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 8007 | p = new PackageSetting(origPackage.name, name, codePath, resourcePath, |
| 8008 | nativeLibraryPathString, vc, pkgFlags); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8009 | if (DEBUG_UPGRADE) Log.v(TAG, "Package " + name |
| 8010 | + " is adopting original package " + origPackage.name); |
| Dianne Hackborn | 4b45041 | 2010-03-11 16:20:08 -0800 | [diff] [blame] | 8011 | // Note that we will retain the new package's signature so |
| 8012 | // that we can keep its data. |
| 8013 | PackageSignatures s = p.signatures; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8014 | p.copyFrom(origPackage); |
| Dianne Hackborn | 4b45041 | 2010-03-11 16:20:08 -0800 | [diff] [blame] | 8015 | p.signatures = s; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8016 | p.sharedUser = origPackage.sharedUser; |
| 8017 | p.userId = origPackage.userId; |
| 8018 | p.origPackage = origPackage; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8019 | mRenamedPackages.put(name, origPackage.name); |
| 8020 | name = origPackage.name; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8021 | // Update new package state. |
| 8022 | p.setTimeStamp(codePath.lastModified()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8023 | } else { |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 8024 | p = new PackageSetting(name, realName, codePath, resourcePath, |
| 8025 | nativeLibraryPathString, vc, pkgFlags); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8026 | p.setTimeStamp(codePath.lastModified()); |
| 8027 | p.sharedUser = sharedUser; |
| 8028 | if (sharedUser != null) { |
| 8029 | p.userId = sharedUser.userId; |
| 8030 | } else if (MULTIPLE_APPLICATION_UIDS) { |
| 8031 | // Clone the setting here for disabled system packages |
| 8032 | PackageSetting dis = mDisabledSysPackages.get(name); |
| 8033 | if (dis != null) { |
| 8034 | // For disabled packages a new setting is created |
| 8035 | // from the existing user id. This still has to be |
| 8036 | // added to list of user id's |
| 8037 | // Copy signatures from previous setting |
| 8038 | if (dis.signatures.mSignatures != null) { |
| 8039 | p.signatures.mSignatures = dis.signatures.mSignatures.clone(); |
| 8040 | } |
| 8041 | p.userId = dis.userId; |
| 8042 | // Clone permissions |
| 8043 | p.grantedPermissions = new HashSet<String>(dis.grantedPermissions); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8044 | // Clone component info |
| 8045 | p.disabledComponents = new HashSet<String>(dis.disabledComponents); |
| 8046 | p.enabledComponents = new HashSet<String>(dis.enabledComponents); |
| 8047 | // Add new setting to list of user ids |
| 8048 | addUserIdLP(p.userId, p, name); |
| 8049 | } else { |
| 8050 | // Assign new user id |
| 8051 | p.userId = newUserIdLP(p); |
| 8052 | } |
| 8053 | } else { |
| 8054 | p.userId = FIRST_APPLICATION_UID; |
| 8055 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8056 | } |
| 8057 | if (p.userId < 0) { |
| 8058 | reportSettingsProblem(Log.WARN, |
| 8059 | "Package " + name + " could not be assigned a valid uid"); |
| 8060 | return null; |
| 8061 | } |
| 8062 | if (add) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8063 | // Finish adding new package by adding it and updating shared |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8064 | // user preferences |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8065 | addPackageSettingLP(p, name, sharedUser); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8066 | } |
| 8067 | } |
| 8068 | return p; |
| 8069 | } |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8070 | |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8071 | private void insertPackageSettingLP(PackageSetting p, PackageParser.Package pkg) { |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8072 | p.pkg = pkg; |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 8073 | pkg.mSetEnabled = p.enabled; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8074 | final String codePath = pkg.applicationInfo.sourceDir; |
| 8075 | final String resourcePath = pkg.applicationInfo.publicSourceDir; |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8076 | // Update code path if needed |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8077 | if (!codePath.equalsIgnoreCase(p.codePathString)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8078 | Slog.w(TAG, "Code path for pkg : " + p.pkg.packageName + |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8079 | " changing from " + p.codePathString + " to " + codePath); |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8080 | p.codePath = new File(codePath); |
| 8081 | p.codePathString = codePath; |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8082 | } |
| 8083 | //Update resource path if needed |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8084 | if (!resourcePath.equalsIgnoreCase(p.resourcePathString)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8085 | Slog.w(TAG, "Resource path for pkg : " + p.pkg.packageName + |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8086 | " changing from " + p.resourcePathString + " to " + resourcePath); |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8087 | p.resourcePath = new File(resourcePath); |
| 8088 | p.resourcePathString = resourcePath; |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8089 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8090 | // Update the native library path if needed |
| 8091 | final String nativeLibraryPath = pkg.applicationInfo.nativeLibraryDir; |
| 8092 | if (nativeLibraryPath != null |
| 8093 | && !nativeLibraryPath.equalsIgnoreCase(p.nativeLibraryPathString)) { |
| 8094 | p.nativeLibraryPathString = nativeLibraryPath; |
| 8095 | } |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8096 | // Update version code if needed |
| 8097 | if (pkg.mVersionCode != p.versionCode) { |
| 8098 | p.versionCode = pkg.mVersionCode; |
| 8099 | } |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 8100 | // Update signatures if needed. |
| 8101 | if (p.signatures.mSignatures == null) { |
| 8102 | p.signatures.assignSignatures(pkg.mSignatures); |
| 8103 | } |
| 8104 | // If this app defines a shared user id initialize |
| 8105 | // the shared user signatures as well. |
| 8106 | if (p.sharedUser != null && p.sharedUser.signatures.mSignatures == null) { |
| 8107 | p.sharedUser.signatures.assignSignatures(pkg.mSignatures); |
| 8108 | } |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8109 | addPackageSettingLP(p, pkg.packageName, p.sharedUser); |
| 8110 | } |
| 8111 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8112 | // Utility method that adds a PackageSetting to mPackages and |
| 8113 | // completes updating the shared user attributes |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8114 | private void addPackageSettingLP(PackageSetting p, String name, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8115 | SharedUserSetting sharedUser) { |
| 8116 | mPackages.put(name, p); |
| 8117 | if (sharedUser != null) { |
| 8118 | if (p.sharedUser != null && p.sharedUser != sharedUser) { |
| 8119 | reportSettingsProblem(Log.ERROR, |
| 8120 | "Package " + p.name + " was user " |
| 8121 | + p.sharedUser + " but is now " + sharedUser |
| 8122 | + "; I am not changing its files so it will probably fail!"); |
| 8123 | p.sharedUser.packages.remove(p); |
| 8124 | } else if (p.userId != sharedUser.userId) { |
| 8125 | reportSettingsProblem(Log.ERROR, |
| 8126 | "Package " + p.name + " was user id " + p.userId |
| 8127 | + " but is now user " + sharedUser |
| 8128 | + " with id " + sharedUser.userId |
| 8129 | + "; I am not changing its files so it will probably fail!"); |
| 8130 | } |
| 8131 | |
| 8132 | sharedUser.packages.add(p); |
| 8133 | p.sharedUser = sharedUser; |
| 8134 | p.userId = sharedUser.userId; |
| 8135 | } |
| 8136 | } |
| 8137 | |
| Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8138 | /* |
| 8139 | * Update the shared user setting when a package using |
| 8140 | * specifying the shared user id is removed. The gids |
| 8141 | * associated with each permission of the deleted package |
| 8142 | * are removed from the shared user's gid list only if its |
| 8143 | * not in use by other permissions of packages in the |
| 8144 | * shared user setting. |
| 8145 | */ |
| 8146 | private void updateSharedUserPermsLP(PackageSetting deletedPs, int[] globalGids) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8147 | if ( (deletedPs == null) || (deletedPs.pkg == null)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8148 | Slog.i(TAG, "Trying to update info for null package. Just ignoring"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8149 | return; |
| 8150 | } |
| 8151 | // No sharedUserId |
| 8152 | if (deletedPs.sharedUser == null) { |
| 8153 | return; |
| 8154 | } |
| 8155 | SharedUserSetting sus = deletedPs.sharedUser; |
| 8156 | // Update permissions |
| 8157 | for (String eachPerm: deletedPs.pkg.requestedPermissions) { |
| 8158 | boolean used = false; |
| 8159 | if (!sus.grantedPermissions.contains (eachPerm)) { |
| 8160 | continue; |
| 8161 | } |
| 8162 | for (PackageSetting pkg:sus.packages) { |
| Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8163 | if (pkg.pkg != null && |
| Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 8164 | !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) && |
| Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8165 | pkg.pkg.requestedPermissions.contains(eachPerm)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8166 | used = true; |
| 8167 | break; |
| 8168 | } |
| 8169 | } |
| 8170 | if (!used) { |
| 8171 | // can safely delete this permission from list |
| 8172 | sus.grantedPermissions.remove(eachPerm); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8173 | } |
| 8174 | } |
| 8175 | // Update gids |
| Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8176 | int newGids[] = globalGids; |
| 8177 | for (String eachPerm : sus.grantedPermissions) { |
| 8178 | BasePermission bp = mPermissions.get(eachPerm); |
| Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8179 | if (bp != null) { |
| 8180 | newGids = appendInts(newGids, bp.gids); |
| 8181 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8182 | } |
| 8183 | sus.gids = newGids; |
| 8184 | } |
| Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8186 | private int removePackageLP(String name) { |
| 8187 | PackageSetting p = mPackages.get(name); |
| 8188 | if (p != null) { |
| 8189 | mPackages.remove(name); |
| 8190 | if (p.sharedUser != null) { |
| 8191 | p.sharedUser.packages.remove(p); |
| 8192 | if (p.sharedUser.packages.size() == 0) { |
| 8193 | mSharedUsers.remove(p.sharedUser.name); |
| 8194 | removeUserIdLP(p.sharedUser.userId); |
| 8195 | return p.sharedUser.userId; |
| 8196 | } |
| 8197 | } else { |
| 8198 | removeUserIdLP(p.userId); |
| 8199 | return p.userId; |
| 8200 | } |
| 8201 | } |
| 8202 | return -1; |
| 8203 | } |
| 8204 | |
| 8205 | private boolean addUserIdLP(int uid, Object obj, Object name) { |
| 8206 | if (uid >= FIRST_APPLICATION_UID + MAX_APPLICATION_UIDS) { |
| 8207 | return false; |
| 8208 | } |
| 8209 | |
| 8210 | if (uid >= FIRST_APPLICATION_UID) { |
| 8211 | int N = mUserIds.size(); |
| 8212 | final int index = uid - FIRST_APPLICATION_UID; |
| 8213 | while (index >= N) { |
| 8214 | mUserIds.add(null); |
| 8215 | N++; |
| 8216 | } |
| 8217 | if (mUserIds.get(index) != null) { |
| 8218 | reportSettingsProblem(Log.ERROR, |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8219 | "Adding duplicate user id: " + uid |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8220 | + " name=" + name); |
| 8221 | return false; |
| 8222 | } |
| 8223 | mUserIds.set(index, obj); |
| 8224 | } else { |
| 8225 | if (mOtherUserIds.get(uid) != null) { |
| 8226 | reportSettingsProblem(Log.ERROR, |
| 8227 | "Adding duplicate shared id: " + uid |
| 8228 | + " name=" + name); |
| 8229 | return false; |
| 8230 | } |
| 8231 | mOtherUserIds.put(uid, obj); |
| 8232 | } |
| 8233 | return true; |
| 8234 | } |
| 8235 | |
| 8236 | public Object getUserIdLP(int uid) { |
| 8237 | if (uid >= FIRST_APPLICATION_UID) { |
| 8238 | int N = mUserIds.size(); |
| 8239 | final int index = uid - FIRST_APPLICATION_UID; |
| 8240 | return index < N ? mUserIds.get(index) : null; |
| 8241 | } else { |
| 8242 | return mOtherUserIds.get(uid); |
| 8243 | } |
| 8244 | } |
| 8245 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 8246 | private Set<String> findPackagesWithFlag(int flag) { |
| 8247 | Set<String> ret = new HashSet<String>(); |
| 8248 | for (PackageSetting ps : mPackages.values()) { |
| 8249 | // Has to match atleast all the flag bits set on flag |
| 8250 | if ((ps.pkgFlags & flag) == flag) { |
| 8251 | ret.add(ps.name); |
| 8252 | } |
| 8253 | } |
| 8254 | return ret; |
| 8255 | } |
| 8256 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8257 | private void removeUserIdLP(int uid) { |
| 8258 | if (uid >= FIRST_APPLICATION_UID) { |
| 8259 | int N = mUserIds.size(); |
| 8260 | final int index = uid - FIRST_APPLICATION_UID; |
| 8261 | if (index < N) mUserIds.set(index, null); |
| 8262 | } else { |
| 8263 | mOtherUserIds.remove(uid); |
| 8264 | } |
| 8265 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8267 | void writeLP() { |
| 8268 | //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024); |
| 8269 | |
| 8270 | // Keep the old settings around until we know the new ones have |
| 8271 | // been successfully written. |
| 8272 | if (mSettingsFilename.exists()) { |
| Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8273 | // Presence of backup settings file indicates that we failed |
| 8274 | // to persist settings earlier. So preserve the older |
| 8275 | // backup for future reference since the current settings |
| 8276 | // might have been corrupted. |
| 8277 | if (!mBackupSettingsFilename.exists()) { |
| 8278 | if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8279 | Slog.w(TAG, "Unable to backup package manager settings, current changes will be lost at reboot"); |
| Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8280 | return; |
| 8281 | } |
| 8282 | } else { |
| Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8283 | mSettingsFilename.delete(); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8284 | Slog.w(TAG, "Preserving older settings backup"); |
| Suchi Amalapurapu | 3d7e855 | 2009-09-17 15:38:20 -0700 | [diff] [blame] | 8285 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8286 | } |
| 8287 | |
| 8288 | mPastSignatures.clear(); |
| 8289 | |
| 8290 | try { |
| 8291 | FileOutputStream str = new FileOutputStream(mSettingsFilename); |
| 8292 | |
| 8293 | //XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 8294 | XmlSerializer serializer = new FastXmlSerializer(); |
| 8295 | serializer.setOutput(str, "utf-8"); |
| 8296 | serializer.startDocument(null, true); |
| 8297 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 8298 | |
| 8299 | serializer.startTag(null, "packages"); |
| 8300 | |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 8301 | serializer.startTag(null, "last-platform-version"); |
| 8302 | serializer.attribute(null, "internal", Integer.toString(mInternalSdkPlatform)); |
| 8303 | serializer.attribute(null, "external", Integer.toString(mExternalSdkPlatform)); |
| 8304 | serializer.endTag(null, "last-platform-version"); |
| 8305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8306 | serializer.startTag(null, "permission-trees"); |
| 8307 | for (BasePermission bp : mPermissionTrees.values()) { |
| 8308 | writePermission(serializer, bp); |
| 8309 | } |
| 8310 | serializer.endTag(null, "permission-trees"); |
| 8311 | |
| 8312 | serializer.startTag(null, "permissions"); |
| 8313 | for (BasePermission bp : mPermissions.values()) { |
| 8314 | writePermission(serializer, bp); |
| 8315 | } |
| 8316 | serializer.endTag(null, "permissions"); |
| 8317 | |
| 8318 | for (PackageSetting pkg : mPackages.values()) { |
| 8319 | writePackage(serializer, pkg); |
| 8320 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8321 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8322 | for (PackageSetting pkg : mDisabledSysPackages.values()) { |
| 8323 | writeDisabledSysPackage(serializer, pkg); |
| 8324 | } |
| 8325 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8326 | serializer.startTag(null, "preferred-activities"); |
| 8327 | for (PreferredActivity pa : mPreferredActivities.filterSet()) { |
| 8328 | serializer.startTag(null, "item"); |
| 8329 | pa.writeToXml(serializer); |
| 8330 | serializer.endTag(null, "item"); |
| 8331 | } |
| 8332 | serializer.endTag(null, "preferred-activities"); |
| 8333 | |
| 8334 | for (SharedUserSetting usr : mSharedUsers.values()) { |
| 8335 | serializer.startTag(null, "shared-user"); |
| 8336 | serializer.attribute(null, "name", usr.name); |
| 8337 | serializer.attribute(null, "userId", |
| 8338 | Integer.toString(usr.userId)); |
| 8339 | usr.signatures.writeXml(serializer, "sigs", mPastSignatures); |
| 8340 | serializer.startTag(null, "perms"); |
| 8341 | for (String name : usr.grantedPermissions) { |
| 8342 | serializer.startTag(null, "item"); |
| 8343 | serializer.attribute(null, "name", name); |
| 8344 | serializer.endTag(null, "item"); |
| 8345 | } |
| 8346 | serializer.endTag(null, "perms"); |
| 8347 | serializer.endTag(null, "shared-user"); |
| 8348 | } |
| 8349 | |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8350 | if (mPackagesToBeCleaned.size() > 0) { |
| 8351 | for (int i=0; i<mPackagesToBeCleaned.size(); i++) { |
| 8352 | serializer.startTag(null, "cleaning-package"); |
| 8353 | serializer.attribute(null, "name", mPackagesToBeCleaned.get(i)); |
| 8354 | serializer.endTag(null, "cleaning-package"); |
| 8355 | } |
| 8356 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8357 | |
| 8358 | if (mRenamedPackages.size() > 0) { |
| 8359 | for (HashMap.Entry<String, String> e : mRenamedPackages.entrySet()) { |
| 8360 | serializer.startTag(null, "renamed-package"); |
| 8361 | serializer.attribute(null, "new", e.getKey()); |
| 8362 | serializer.attribute(null, "old", e.getValue()); |
| 8363 | serializer.endTag(null, "renamed-package"); |
| 8364 | } |
| 8365 | } |
| 8366 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8367 | serializer.endTag(null, "packages"); |
| 8368 | |
| 8369 | serializer.endDocument(); |
| 8370 | |
| 8371 | str.flush(); |
| 8372 | str.close(); |
| 8373 | |
| 8374 | // New settings successfully written, old ones are no longer |
| 8375 | // needed. |
| 8376 | mBackupSettingsFilename.delete(); |
| 8377 | FileUtils.setPermissions(mSettingsFilename.toString(), |
| 8378 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
| 8379 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP |
| 8380 | |FileUtils.S_IROTH, |
| 8381 | -1, -1); |
| David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 8382 | |
| 8383 | // Write package list file now, use a JournaledFile. |
| 8384 | // |
| 8385 | File tempFile = new File(mPackageListFilename.toString() + ".tmp"); |
| 8386 | JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile); |
| 8387 | |
| 8388 | str = new FileOutputStream(journal.chooseForWrite()); |
| 8389 | try { |
| 8390 | StringBuilder sb = new StringBuilder(); |
| 8391 | for (PackageSetting pkg : mPackages.values()) { |
| 8392 | ApplicationInfo ai = pkg.pkg.applicationInfo; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8393 | String dataPath = ai.dataDir; |
| David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 8394 | boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 8395 | |
| 8396 | // Avoid any application that has a space in its path |
| 8397 | // or that is handled by the system. |
| 8398 | if (dataPath.indexOf(" ") >= 0 || ai.uid <= Process.FIRST_APPLICATION_UID) |
| 8399 | continue; |
| 8400 | |
| 8401 | // we store on each line the following information for now: |
| 8402 | // |
| 8403 | // pkgName - package name |
| 8404 | // userId - application-specific user id |
| 8405 | // debugFlag - 0 or 1 if the package is debuggable. |
| 8406 | // dataPath - path to package's data path |
| 8407 | // |
| 8408 | // NOTE: We prefer not to expose all ApplicationInfo flags for now. |
| 8409 | // |
| 8410 | // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS |
| 8411 | // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES: |
| 8412 | // system/core/run-as/run-as.c |
| 8413 | // |
| 8414 | sb.setLength(0); |
| 8415 | sb.append(ai.packageName); |
| 8416 | sb.append(" "); |
| 8417 | sb.append((int)ai.uid); |
| 8418 | sb.append(isDebug ? " 1 " : " 0 "); |
| 8419 | sb.append(dataPath); |
| 8420 | sb.append("\n"); |
| 8421 | str.write(sb.toString().getBytes()); |
| 8422 | } |
| 8423 | str.flush(); |
| 8424 | str.close(); |
| 8425 | journal.commit(); |
| 8426 | } |
| 8427 | catch (Exception e) { |
| 8428 | journal.rollback(); |
| 8429 | } |
| 8430 | |
| 8431 | FileUtils.setPermissions(mPackageListFilename.toString(), |
| 8432 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
| 8433 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP |
| 8434 | |FileUtils.S_IROTH, |
| 8435 | -1, -1); |
| 8436 | |
| Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8437 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8438 | |
| 8439 | } catch(XmlPullParserException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8440 | Slog.w(TAG, "Unable to write package manager settings, current changes will be lost at reboot", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8441 | } catch(java.io.IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8442 | Slog.w(TAG, "Unable to write package manager settings, current changes will be lost at reboot", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8443 | } |
| David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 8444 | // Clean up partially written files |
| Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8445 | if (mSettingsFilename.exists()) { |
| 8446 | if (!mSettingsFilename.delete()) { |
| 8447 | Log.i(TAG, "Failed to clean up mangled file: " + mSettingsFilename); |
| 8448 | } |
| 8449 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8450 | //Debug.stopMethodTracing(); |
| 8451 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8452 | |
| 8453 | void writeDisabledSysPackage(XmlSerializer serializer, final PackageSetting pkg) |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8454 | throws java.io.IOException { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8455 | serializer.startTag(null, "updated-package"); |
| 8456 | serializer.attribute(null, "name", pkg.name); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8457 | if (pkg.realName != null) { |
| 8458 | serializer.attribute(null, "realName", pkg.realName); |
| 8459 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8460 | serializer.attribute(null, "codePath", pkg.codePathString); |
| Kenny Root | 7d794fb | 2010-09-13 16:29:49 -0700 | [diff] [blame] | 8461 | serializer.attribute(null, "ts", String.valueOf(pkg.timeStamp)); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8462 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8463 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 8464 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 8465 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8466 | if (pkg.nativeLibraryPathString != null) { |
| 8467 | serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString); |
| 8468 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8469 | if (pkg.sharedUser == null) { |
| 8470 | serializer.attribute(null, "userId", |
| 8471 | Integer.toString(pkg.userId)); |
| 8472 | } else { |
| 8473 | serializer.attribute(null, "sharedUserId", |
| 8474 | Integer.toString(pkg.userId)); |
| 8475 | } |
| 8476 | serializer.startTag(null, "perms"); |
| 8477 | if (pkg.sharedUser == null) { |
| 8478 | // If this is a shared user, the permissions will |
| 8479 | // be written there. We still need to write an |
| 8480 | // empty permissions list so permissionsFixed will |
| 8481 | // be set. |
| 8482 | for (final String name : pkg.grantedPermissions) { |
| 8483 | BasePermission bp = mPermissions.get(name); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8484 | if (bp != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8485 | // We only need to write signature or system permissions but this wont |
| 8486 | // match the semantics of grantedPermissions. So write all permissions. |
| 8487 | serializer.startTag(null, "item"); |
| 8488 | serializer.attribute(null, "name", name); |
| 8489 | serializer.endTag(null, "item"); |
| 8490 | } |
| 8491 | } |
| 8492 | } |
| 8493 | serializer.endTag(null, "perms"); |
| 8494 | serializer.endTag(null, "updated-package"); |
| 8495 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8496 | |
| 8497 | void writePackage(XmlSerializer serializer, final PackageSetting pkg) |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8498 | throws java.io.IOException { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8499 | serializer.startTag(null, "package"); |
| 8500 | serializer.attribute(null, "name", pkg.name); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8501 | if (pkg.realName != null) { |
| 8502 | serializer.attribute(null, "realName", pkg.realName); |
| 8503 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8504 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 8505 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 8506 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 8507 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8508 | if (pkg.nativeLibraryPathString != null) { |
| 8509 | serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString); |
| 8510 | } |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8511 | serializer.attribute(null, "flags", |
| 8512 | Integer.toString(pkg.pkgFlags)); |
| Kenny Root | 7d794fb | 2010-09-13 16:29:49 -0700 | [diff] [blame] | 8513 | serializer.attribute(null, "ts", String.valueOf(pkg.timeStamp)); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8514 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8515 | if (pkg.sharedUser == null) { |
| 8516 | serializer.attribute(null, "userId", |
| 8517 | Integer.toString(pkg.userId)); |
| 8518 | } else { |
| 8519 | serializer.attribute(null, "sharedUserId", |
| 8520 | Integer.toString(pkg.userId)); |
| 8521 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8522 | if (pkg.uidError) { |
| 8523 | serializer.attribute(null, "uidError", "true"); |
| 8524 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8525 | if (pkg.enabled != COMPONENT_ENABLED_STATE_DEFAULT) { |
| 8526 | serializer.attribute(null, "enabled", |
| 8527 | pkg.enabled == COMPONENT_ENABLED_STATE_ENABLED |
| 8528 | ? "true" : "false"); |
| 8529 | } |
| 8530 | if(pkg.installStatus == PKG_INSTALL_INCOMPLETE) { |
| 8531 | serializer.attribute(null, "installStatus", "false"); |
| 8532 | } |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8533 | if (pkg.installerPackageName != null) { |
| 8534 | serializer.attribute(null, "installer", pkg.installerPackageName); |
| 8535 | } |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 8536 | if (pkg.obbPathString != null) { |
| 8537 | serializer.attribute(null, "obbPath", pkg.obbPathString); |
| 8538 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8539 | pkg.signatures.writeXml(serializer, "sigs", mPastSignatures); |
| 8540 | if ((pkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 8541 | serializer.startTag(null, "perms"); |
| 8542 | if (pkg.sharedUser == null) { |
| 8543 | // If this is a shared user, the permissions will |
| 8544 | // be written there. We still need to write an |
| 8545 | // empty permissions list so permissionsFixed will |
| 8546 | // be set. |
| 8547 | for (final String name : pkg.grantedPermissions) { |
| 8548 | serializer.startTag(null, "item"); |
| 8549 | serializer.attribute(null, "name", name); |
| 8550 | serializer.endTag(null, "item"); |
| 8551 | } |
| 8552 | } |
| 8553 | serializer.endTag(null, "perms"); |
| 8554 | } |
| 8555 | if (pkg.disabledComponents.size() > 0) { |
| 8556 | serializer.startTag(null, "disabled-components"); |
| 8557 | for (final String name : pkg.disabledComponents) { |
| 8558 | serializer.startTag(null, "item"); |
| 8559 | serializer.attribute(null, "name", name); |
| 8560 | serializer.endTag(null, "item"); |
| 8561 | } |
| 8562 | serializer.endTag(null, "disabled-components"); |
| 8563 | } |
| 8564 | if (pkg.enabledComponents.size() > 0) { |
| 8565 | serializer.startTag(null, "enabled-components"); |
| 8566 | for (final String name : pkg.enabledComponents) { |
| 8567 | serializer.startTag(null, "item"); |
| 8568 | serializer.attribute(null, "name", name); |
| 8569 | serializer.endTag(null, "item"); |
| 8570 | } |
| 8571 | serializer.endTag(null, "enabled-components"); |
| 8572 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8574 | serializer.endTag(null, "package"); |
| 8575 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8576 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8577 | void writePermission(XmlSerializer serializer, BasePermission bp) |
| 8578 | throws XmlPullParserException, java.io.IOException { |
| 8579 | if (bp.type != BasePermission.TYPE_BUILTIN |
| 8580 | && bp.sourcePackage != null) { |
| 8581 | serializer.startTag(null, "item"); |
| 8582 | serializer.attribute(null, "name", bp.name); |
| 8583 | serializer.attribute(null, "package", bp.sourcePackage); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8584 | if (bp.protectionLevel != |
| 8585 | PermissionInfo.PROTECTION_NORMAL) { |
| 8586 | serializer.attribute(null, "protection", |
| 8587 | Integer.toString(bp.protectionLevel)); |
| 8588 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8589 | if (DEBUG_SETTINGS) Log.v(TAG, |
| 8590 | "Writing perm: name=" + bp.name + " type=" + bp.type); |
| 8591 | if (bp.type == BasePermission.TYPE_DYNAMIC) { |
| 8592 | PermissionInfo pi = bp.perm != null ? bp.perm.info |
| 8593 | : bp.pendingInfo; |
| 8594 | if (pi != null) { |
| 8595 | serializer.attribute(null, "type", "dynamic"); |
| 8596 | if (pi.icon != 0) { |
| 8597 | serializer.attribute(null, "icon", |
| 8598 | Integer.toString(pi.icon)); |
| 8599 | } |
| 8600 | if (pi.nonLocalizedLabel != null) { |
| 8601 | serializer.attribute(null, "label", |
| 8602 | pi.nonLocalizedLabel.toString()); |
| 8603 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8604 | } |
| 8605 | } |
| 8606 | serializer.endTag(null, "item"); |
| 8607 | } |
| 8608 | } |
| 8609 | |
| 8610 | String getReadMessagesLP() { |
| 8611 | return mReadMessages.toString(); |
| 8612 | } |
| 8613 | |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8614 | ArrayList<PackageSetting> getListOfIncompleteInstallPackages() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8615 | HashSet<String> kList = new HashSet<String>(mPackages.keySet()); |
| 8616 | Iterator<String> its = kList.iterator(); |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8617 | ArrayList<PackageSetting> ret = new ArrayList<PackageSetting>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8618 | while(its.hasNext()) { |
| 8619 | String key = its.next(); |
| 8620 | PackageSetting ps = mPackages.get(key); |
| 8621 | if(ps.getInstallStatus() == PKG_INSTALL_INCOMPLETE) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8622 | ret.add(ps); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8623 | } |
| 8624 | } |
| 8625 | return ret; |
| 8626 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8627 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8628 | boolean readLP() { |
| 8629 | FileInputStream str = null; |
| 8630 | if (mBackupSettingsFilename.exists()) { |
| 8631 | try { |
| 8632 | str = new FileInputStream(mBackupSettingsFilename); |
| 8633 | mReadMessages.append("Reading from backup settings file\n"); |
| 8634 | Log.i(TAG, "Reading from backup settings file!"); |
| Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8635 | if (mSettingsFilename.exists()) { |
| 8636 | // If both the backup and settings file exist, we |
| 8637 | // ignore the settings since it might have been |
| 8638 | // corrupted. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8639 | Slog.w(TAG, "Cleaning up settings file " + mSettingsFilename); |
| Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8640 | mSettingsFilename.delete(); |
| 8641 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8642 | } catch (java.io.IOException e) { |
| 8643 | // We'll try for the normal settings file. |
| 8644 | } |
| 8645 | } |
| 8646 | |
| 8647 | mPastSignatures.clear(); |
| 8648 | |
| 8649 | try { |
| 8650 | if (str == null) { |
| 8651 | if (!mSettingsFilename.exists()) { |
| 8652 | mReadMessages.append("No settings file found\n"); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8653 | Slog.i(TAG, "No current settings file!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8654 | return false; |
| 8655 | } |
| 8656 | str = new FileInputStream(mSettingsFilename); |
| 8657 | } |
| 8658 | XmlPullParser parser = Xml.newPullParser(); |
| 8659 | parser.setInput(str, null); |
| 8660 | |
| 8661 | int type; |
| 8662 | while ((type=parser.next()) != XmlPullParser.START_TAG |
| 8663 | && type != XmlPullParser.END_DOCUMENT) { |
| 8664 | ; |
| 8665 | } |
| 8666 | |
| 8667 | if (type != XmlPullParser.START_TAG) { |
| 8668 | mReadMessages.append("No start tag found in settings file\n"); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8669 | Slog.e(TAG, "No start tag found in package manager settings"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8670 | return false; |
| 8671 | } |
| 8672 | |
| 8673 | int outerDepth = parser.getDepth(); |
| 8674 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8675 | && (type != XmlPullParser.END_TAG |
| 8676 | || parser.getDepth() > outerDepth)) { |
| 8677 | if (type == XmlPullParser.END_TAG |
| 8678 | || type == XmlPullParser.TEXT) { |
| 8679 | continue; |
| 8680 | } |
| 8681 | |
| 8682 | String tagName = parser.getName(); |
| 8683 | if (tagName.equals("package")) { |
| 8684 | readPackageLP(parser); |
| 8685 | } else if (tagName.equals("permissions")) { |
| 8686 | readPermissionsLP(mPermissions, parser); |
| 8687 | } else if (tagName.equals("permission-trees")) { |
| 8688 | readPermissionsLP(mPermissionTrees, parser); |
| 8689 | } else if (tagName.equals("shared-user")) { |
| 8690 | readSharedUserLP(parser); |
| 8691 | } else if (tagName.equals("preferred-packages")) { |
| Dianne Hackborn | a7ca0e5 | 2009-12-01 14:31:55 -0800 | [diff] [blame] | 8692 | // no longer used. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8693 | } else if (tagName.equals("preferred-activities")) { |
| 8694 | readPreferredActivitiesLP(parser); |
| 8695 | } else if(tagName.equals("updated-package")) { |
| 8696 | readDisabledSysPackageLP(parser); |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8697 | } else if (tagName.equals("cleaning-package")) { |
| 8698 | String name = parser.getAttributeValue(null, "name"); |
| 8699 | if (name != null) { |
| 8700 | mPackagesToBeCleaned.add(name); |
| 8701 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8702 | } else if (tagName.equals("renamed-package")) { |
| 8703 | String nname = parser.getAttributeValue(null, "new"); |
| 8704 | String oname = parser.getAttributeValue(null, "old"); |
| 8705 | if (nname != null && oname != null) { |
| 8706 | mRenamedPackages.put(nname, oname); |
| 8707 | } |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 8708 | } else if (tagName.equals("last-platform-version")) { |
| 8709 | mInternalSdkPlatform = mExternalSdkPlatform = 0; |
| 8710 | try { |
| 8711 | String internal = parser.getAttributeValue(null, "internal"); |
| 8712 | if (internal != null) { |
| 8713 | mInternalSdkPlatform = Integer.parseInt(internal); |
| 8714 | } |
| 8715 | String external = parser.getAttributeValue(null, "external"); |
| 8716 | if (external != null) { |
| Bryan Mawhinney | 2131a3c | 2010-04-23 14:38:31 +0100 | [diff] [blame] | 8717 | mExternalSdkPlatform = Integer.parseInt(external); |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 8718 | } |
| 8719 | } catch (NumberFormatException e) { |
| 8720 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8721 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8722 | Slog.w(TAG, "Unknown element under <packages>: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8723 | + parser.getName()); |
| 8724 | XmlUtils.skipCurrentTag(parser); |
| 8725 | } |
| 8726 | } |
| 8727 | |
| 8728 | str.close(); |
| 8729 | |
| 8730 | } catch(XmlPullParserException e) { |
| 8731 | mReadMessages.append("Error reading: " + e.toString()); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8732 | Slog.e(TAG, "Error reading package manager settings", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8733 | |
| 8734 | } catch(java.io.IOException e) { |
| 8735 | mReadMessages.append("Error reading: " + e.toString()); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8736 | Slog.e(TAG, "Error reading package manager settings", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8737 | |
| 8738 | } |
| 8739 | |
| 8740 | int N = mPendingPackages.size(); |
| 8741 | for (int i=0; i<N; i++) { |
| 8742 | final PendingPackage pp = mPendingPackages.get(i); |
| 8743 | Object idObj = getUserIdLP(pp.sharedId); |
| 8744 | if (idObj != null && idObj instanceof SharedUserSetting) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8745 | PackageSetting p = getPackageLP(pp.name, null, pp.realName, |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 8746 | (SharedUserSetting) idObj, pp.codePath, pp.resourcePath, |
| 8747 | pp.nativeLibraryPathString, pp.versionCode, pp.pkgFlags, true, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8748 | if (p == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8749 | Slog.w(TAG, "Unable to create application package for " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8750 | + pp.name); |
| 8751 | continue; |
| 8752 | } |
| 8753 | p.copyFrom(pp); |
| 8754 | } else if (idObj != null) { |
| 8755 | String msg = "Bad package setting: package " + pp.name |
| 8756 | + " has shared uid " + pp.sharedId |
| 8757 | + " that is not a shared uid\n"; |
| 8758 | mReadMessages.append(msg); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8759 | Slog.e(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8760 | } else { |
| 8761 | String msg = "Bad package setting: package " + pp.name |
| 8762 | + " has shared uid " + pp.sharedId |
| 8763 | + " that is not defined\n"; |
| 8764 | mReadMessages.append(msg); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8765 | Slog.e(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8766 | } |
| 8767 | } |
| 8768 | mPendingPackages.clear(); |
| 8769 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8770 | mReadMessages.append("Read completed successfully: " |
| 8771 | + mPackages.size() + " packages, " |
| 8772 | + mSharedUsers.size() + " shared uids\n"); |
| 8773 | |
| 8774 | return true; |
| 8775 | } |
| 8776 | |
| 8777 | private int readInt(XmlPullParser parser, String ns, String name, |
| 8778 | int defValue) { |
| 8779 | String v = parser.getAttributeValue(ns, name); |
| 8780 | try { |
| 8781 | if (v == null) { |
| 8782 | return defValue; |
| 8783 | } |
| 8784 | return Integer.parseInt(v); |
| 8785 | } catch (NumberFormatException e) { |
| 8786 | reportSettingsProblem(Log.WARN, |
| 8787 | "Error in package manager settings: attribute " + |
| 8788 | name + " has bad integer value " + v + " at " |
| 8789 | + parser.getPositionDescription()); |
| 8790 | } |
| 8791 | return defValue; |
| 8792 | } |
| 8793 | |
| 8794 | private void readPermissionsLP(HashMap<String, BasePermission> out, |
| 8795 | XmlPullParser parser) |
| 8796 | throws IOException, XmlPullParserException { |
| 8797 | int outerDepth = parser.getDepth(); |
| 8798 | int type; |
| 8799 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8800 | && (type != XmlPullParser.END_TAG |
| 8801 | || parser.getDepth() > outerDepth)) { |
| 8802 | if (type == XmlPullParser.END_TAG |
| 8803 | || type == XmlPullParser.TEXT) { |
| 8804 | continue; |
| 8805 | } |
| 8806 | |
| 8807 | String tagName = parser.getName(); |
| 8808 | if (tagName.equals("item")) { |
| 8809 | String name = parser.getAttributeValue(null, "name"); |
| 8810 | String sourcePackage = parser.getAttributeValue(null, "package"); |
| 8811 | String ptype = parser.getAttributeValue(null, "type"); |
| 8812 | if (name != null && sourcePackage != null) { |
| 8813 | boolean dynamic = "dynamic".equals(ptype); |
| 8814 | BasePermission bp = new BasePermission(name, sourcePackage, |
| 8815 | dynamic |
| 8816 | ? BasePermission.TYPE_DYNAMIC |
| 8817 | : BasePermission.TYPE_NORMAL); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8818 | bp.protectionLevel = readInt(parser, null, "protection", |
| 8819 | PermissionInfo.PROTECTION_NORMAL); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8820 | if (dynamic) { |
| 8821 | PermissionInfo pi = new PermissionInfo(); |
| 8822 | pi.packageName = sourcePackage.intern(); |
| 8823 | pi.name = name.intern(); |
| 8824 | pi.icon = readInt(parser, null, "icon", 0); |
| 8825 | pi.nonLocalizedLabel = parser.getAttributeValue( |
| 8826 | null, "label"); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8827 | pi.protectionLevel = bp.protectionLevel; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8828 | bp.pendingInfo = pi; |
| 8829 | } |
| 8830 | out.put(bp.name, bp); |
| 8831 | } else { |
| 8832 | reportSettingsProblem(Log.WARN, |
| 8833 | "Error in package manager settings: permissions has" |
| 8834 | + " no name at " + parser.getPositionDescription()); |
| 8835 | } |
| 8836 | } else { |
| 8837 | reportSettingsProblem(Log.WARN, |
| 8838 | "Unknown element reading permissions: " |
| 8839 | + parser.getName() + " at " |
| 8840 | + parser.getPositionDescription()); |
| 8841 | } |
| 8842 | XmlUtils.skipCurrentTag(parser); |
| 8843 | } |
| 8844 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8845 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8846 | private void readDisabledSysPackageLP(XmlPullParser parser) |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8847 | throws XmlPullParserException, IOException { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8848 | String name = parser.getAttributeValue(null, "name"); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8849 | String realName = parser.getAttributeValue(null, "realName"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8850 | String codePathStr = parser.getAttributeValue(null, "codePath"); |
| 8851 | String resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 8852 | String nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8853 | if (resourcePathStr == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8854 | resourcePathStr = codePathStr; |
| 8855 | } |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8856 | String version = parser.getAttributeValue(null, "version"); |
| 8857 | int versionCode = 0; |
| 8858 | if (version != null) { |
| 8859 | try { |
| 8860 | versionCode = Integer.parseInt(version); |
| 8861 | } catch (NumberFormatException e) { |
| 8862 | } |
| 8863 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8864 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8865 | int pkgFlags = 0; |
| 8866 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 8867 | PackageSetting ps = new PackageSetting(name, realName, new File(codePathStr), |
| 8868 | new File(resourcePathStr), nativeLibraryPathStr, versionCode, pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8869 | String timeStampStr = parser.getAttributeValue(null, "ts"); |
| 8870 | if (timeStampStr != null) { |
| 8871 | try { |
| 8872 | long timeStamp = Long.parseLong(timeStampStr); |
| Kenny Root | 7d794fb | 2010-09-13 16:29:49 -0700 | [diff] [blame] | 8873 | ps.setTimeStamp(timeStamp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8874 | } catch (NumberFormatException e) { |
| 8875 | } |
| 8876 | } |
| 8877 | String idStr = parser.getAttributeValue(null, "userId"); |
| 8878 | ps.userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 8879 | if(ps.userId <= 0) { |
| 8880 | String sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 8881 | ps.userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; |
| 8882 | } |
| 8883 | int outerDepth = parser.getDepth(); |
| 8884 | int type; |
| 8885 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8886 | && (type != XmlPullParser.END_TAG |
| 8887 | || parser.getDepth() > outerDepth)) { |
| 8888 | if (type == XmlPullParser.END_TAG |
| 8889 | || type == XmlPullParser.TEXT) { |
| 8890 | continue; |
| 8891 | } |
| 8892 | |
| 8893 | String tagName = parser.getName(); |
| 8894 | if (tagName.equals("perms")) { |
| 8895 | readGrantedPermissionsLP(parser, |
| 8896 | ps.grantedPermissions); |
| 8897 | } else { |
| 8898 | reportSettingsProblem(Log.WARN, |
| 8899 | "Unknown element under <updated-package>: " |
| 8900 | + parser.getName()); |
| 8901 | XmlUtils.skipCurrentTag(parser); |
| 8902 | } |
| 8903 | } |
| 8904 | mDisabledSysPackages.put(name, ps); |
| 8905 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8906 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8907 | private void readPackageLP(XmlPullParser parser) |
| 8908 | throws XmlPullParserException, IOException { |
| 8909 | String name = null; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8910 | String realName = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8911 | String idStr = null; |
| 8912 | String sharedIdStr = null; |
| 8913 | String codePathStr = null; |
| 8914 | String resourcePathStr = null; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8915 | String nativeLibraryPathStr = null; |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 8916 | String obbPathStr = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8917 | String systemStr = null; |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8918 | String installerPackageName = null; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8919 | String uidError = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8920 | int pkgFlags = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8921 | long timeStamp = 0; |
| 8922 | PackageSettingBase packageSetting = null; |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8923 | String version = null; |
| 8924 | int versionCode = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8925 | try { |
| 8926 | name = parser.getAttributeValue(null, "name"); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8927 | realName = parser.getAttributeValue(null, "realName"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | idStr = parser.getAttributeValue(null, "userId"); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8929 | uidError = parser.getAttributeValue(null, "uidError"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8930 | sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 8931 | codePathStr = parser.getAttributeValue(null, "codePath"); |
| 8932 | resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8933 | nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 8934 | obbPathStr = parser.getAttributeValue(null, "obbPath"); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8935 | version = parser.getAttributeValue(null, "version"); |
| 8936 | if (version != null) { |
| 8937 | try { |
| 8938 | versionCode = Integer.parseInt(version); |
| 8939 | } catch (NumberFormatException e) { |
| 8940 | } |
| 8941 | } |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8942 | installerPackageName = parser.getAttributeValue(null, "installer"); |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8943 | |
| 8944 | systemStr = parser.getAttributeValue(null, "flags"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8945 | if (systemStr != null) { |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8946 | try { |
| 8947 | pkgFlags = Integer.parseInt(systemStr); |
| 8948 | } catch (NumberFormatException e) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8949 | } |
| 8950 | } else { |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8951 | // For backward compatibility |
| 8952 | systemStr = parser.getAttributeValue(null, "system"); |
| 8953 | if (systemStr != null) { |
| 8954 | pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM : 0; |
| 8955 | } else { |
| 8956 | // Old settings that don't specify system... just treat |
| 8957 | // them as system, good enough. |
| 8958 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 8959 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8960 | } |
| Kenny Root | 7d794fb | 2010-09-13 16:29:49 -0700 | [diff] [blame] | 8961 | final String timeStampStr = parser.getAttributeValue(null, "ts"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8962 | if (timeStampStr != null) { |
| 8963 | try { |
| 8964 | timeStamp = Long.parseLong(timeStampStr); |
| 8965 | } catch (NumberFormatException e) { |
| 8966 | } |
| 8967 | } |
| 8968 | if (DEBUG_SETTINGS) Log.v(TAG, "Reading package: " + name |
| 8969 | + " userId=" + idStr + " sharedUserId=" + sharedIdStr); |
| 8970 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 8971 | if (resourcePathStr == null) { |
| 8972 | resourcePathStr = codePathStr; |
| 8973 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8974 | if (realName != null) { |
| 8975 | realName = realName.intern(); |
| 8976 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8977 | if (name == null) { |
| 8978 | reportSettingsProblem(Log.WARN, |
| 8979 | "Error in package manager settings: <package> has no name at " |
| 8980 | + parser.getPositionDescription()); |
| 8981 | } else if (codePathStr == null) { |
| 8982 | reportSettingsProblem(Log.WARN, |
| 8983 | "Error in package manager settings: <package> has no codePath at " |
| 8984 | + parser.getPositionDescription()); |
| 8985 | } else if (userId > 0) { |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 8986 | packageSetting = addPackageLP(name.intern(), realName, new File(codePathStr), |
| 8987 | new File(resourcePathStr), nativeLibraryPathStr, userId, versionCode, |
| 8988 | pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8989 | if (DEBUG_SETTINGS) Log.i(TAG, "Reading package " + name |
| 8990 | + ": userId=" + userId + " pkg=" + packageSetting); |
| 8991 | if (packageSetting == null) { |
| 8992 | reportSettingsProblem(Log.ERROR, |
| 8993 | "Failure adding uid " + userId |
| 8994 | + " while parsing settings at " |
| 8995 | + parser.getPositionDescription()); |
| 8996 | } else { |
| Kenny Root | 7d794fb | 2010-09-13 16:29:49 -0700 | [diff] [blame] | 8997 | packageSetting.setTimeStamp(timeStamp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8998 | } |
| 8999 | } else if (sharedIdStr != null) { |
| 9000 | userId = sharedIdStr != null |
| 9001 | ? Integer.parseInt(sharedIdStr) : 0; |
| 9002 | if (userId > 0) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9003 | packageSetting = new PendingPackage(name.intern(), realName, |
| 9004 | new File(codePathStr), new File(resourcePathStr), |
| Kenny Root | 806cc13 | 2010-09-12 08:34:19 -0700 | [diff] [blame] | 9005 | nativeLibraryPathStr, userId, versionCode, pkgFlags); |
| Kenny Root | 7d794fb | 2010-09-13 16:29:49 -0700 | [diff] [blame] | 9006 | packageSetting.setTimeStamp(timeStamp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9007 | mPendingPackages.add((PendingPackage) packageSetting); |
| 9008 | if (DEBUG_SETTINGS) Log.i(TAG, "Reading package " + name |
| 9009 | + ": sharedUserId=" + userId + " pkg=" |
| 9010 | + packageSetting); |
| 9011 | } else { |
| 9012 | reportSettingsProblem(Log.WARN, |
| 9013 | "Error in package manager settings: package " |
| 9014 | + name + " has bad sharedId " + sharedIdStr |
| 9015 | + " at " + parser.getPositionDescription()); |
| 9016 | } |
| 9017 | } else { |
| 9018 | reportSettingsProblem(Log.WARN, |
| 9019 | "Error in package manager settings: package " |
| 9020 | + name + " has bad userId " + idStr + " at " |
| 9021 | + parser.getPositionDescription()); |
| 9022 | } |
| 9023 | } catch (NumberFormatException e) { |
| 9024 | reportSettingsProblem(Log.WARN, |
| 9025 | "Error in package manager settings: package " |
| 9026 | + name + " has bad userId " + idStr + " at " |
| 9027 | + parser.getPositionDescription()); |
| 9028 | } |
| 9029 | if (packageSetting != null) { |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 9030 | packageSetting.uidError = "true".equals(uidError); |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 9031 | packageSetting.installerPackageName = installerPackageName; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9032 | packageSetting.nativeLibraryPathString = nativeLibraryPathStr; |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 9033 | packageSetting.obbPathString = obbPathStr; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9034 | final String enabledStr = parser.getAttributeValue(null, "enabled"); |
| 9035 | if (enabledStr != null) { |
| 9036 | if (enabledStr.equalsIgnoreCase("true")) { |
| 9037 | packageSetting.enabled = COMPONENT_ENABLED_STATE_ENABLED; |
| 9038 | } else if (enabledStr.equalsIgnoreCase("false")) { |
| 9039 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DISABLED; |
| 9040 | } else if (enabledStr.equalsIgnoreCase("default")) { |
| 9041 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 9042 | } else { |
| 9043 | reportSettingsProblem(Log.WARN, |
| 9044 | "Error in package manager settings: package " |
| 9045 | + name + " has bad enabled value: " + idStr |
| 9046 | + " at " + parser.getPositionDescription()); |
| 9047 | } |
| 9048 | } else { |
| 9049 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 9050 | } |
| 9051 | final String installStatusStr = parser.getAttributeValue(null, "installStatus"); |
| 9052 | if (installStatusStr != null) { |
| 9053 | if (installStatusStr.equalsIgnoreCase("false")) { |
| 9054 | packageSetting.installStatus = PKG_INSTALL_INCOMPLETE; |
| 9055 | } else { |
| 9056 | packageSetting.installStatus = PKG_INSTALL_COMPLETE; |
| 9057 | } |
| 9058 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9059 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9060 | int outerDepth = parser.getDepth(); |
| 9061 | int type; |
| 9062 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9063 | && (type != XmlPullParser.END_TAG |
| 9064 | || parser.getDepth() > outerDepth)) { |
| 9065 | if (type == XmlPullParser.END_TAG |
| 9066 | || type == XmlPullParser.TEXT) { |
| 9067 | continue; |
| 9068 | } |
| 9069 | |
| 9070 | String tagName = parser.getName(); |
| 9071 | if (tagName.equals("disabled-components")) { |
| 9072 | readDisabledComponentsLP(packageSetting, parser); |
| 9073 | } else if (tagName.equals("enabled-components")) { |
| 9074 | readEnabledComponentsLP(packageSetting, parser); |
| 9075 | } else if (tagName.equals("sigs")) { |
| 9076 | packageSetting.signatures.readXml(parser, mPastSignatures); |
| 9077 | } else if (tagName.equals("perms")) { |
| 9078 | readGrantedPermissionsLP(parser, |
| Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 9079 | packageSetting.grantedPermissions); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9080 | packageSetting.permissionsFixed = true; |
| 9081 | } else { |
| 9082 | reportSettingsProblem(Log.WARN, |
| 9083 | "Unknown element under <package>: " |
| 9084 | + parser.getName()); |
| 9085 | XmlUtils.skipCurrentTag(parser); |
| 9086 | } |
| 9087 | } |
| 9088 | } else { |
| 9089 | XmlUtils.skipCurrentTag(parser); |
| 9090 | } |
| 9091 | } |
| 9092 | |
| 9093 | private void readDisabledComponentsLP(PackageSettingBase packageSetting, |
| 9094 | XmlPullParser parser) |
| 9095 | throws IOException, XmlPullParserException { |
| 9096 | int outerDepth = parser.getDepth(); |
| 9097 | int type; |
| 9098 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9099 | && (type != XmlPullParser.END_TAG |
| 9100 | || parser.getDepth() > outerDepth)) { |
| 9101 | if (type == XmlPullParser.END_TAG |
| 9102 | || type == XmlPullParser.TEXT) { |
| 9103 | continue; |
| 9104 | } |
| 9105 | |
| 9106 | String tagName = parser.getName(); |
| 9107 | if (tagName.equals("item")) { |
| 9108 | String name = parser.getAttributeValue(null, "name"); |
| 9109 | if (name != null) { |
| 9110 | packageSetting.disabledComponents.add(name.intern()); |
| 9111 | } else { |
| 9112 | reportSettingsProblem(Log.WARN, |
| 9113 | "Error in package manager settings: <disabled-components> has" |
| 9114 | + " no name at " + parser.getPositionDescription()); |
| 9115 | } |
| 9116 | } else { |
| 9117 | reportSettingsProblem(Log.WARN, |
| 9118 | "Unknown element under <disabled-components>: " |
| 9119 | + parser.getName()); |
| 9120 | } |
| 9121 | XmlUtils.skipCurrentTag(parser); |
| 9122 | } |
| 9123 | } |
| 9124 | |
| 9125 | private void readEnabledComponentsLP(PackageSettingBase packageSetting, |
| 9126 | XmlPullParser parser) |
| 9127 | throws IOException, XmlPullParserException { |
| 9128 | int outerDepth = parser.getDepth(); |
| 9129 | int type; |
| 9130 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9131 | && (type != XmlPullParser.END_TAG |
| 9132 | || parser.getDepth() > outerDepth)) { |
| 9133 | if (type == XmlPullParser.END_TAG |
| 9134 | || type == XmlPullParser.TEXT) { |
| 9135 | continue; |
| 9136 | } |
| 9137 | |
| 9138 | String tagName = parser.getName(); |
| 9139 | if (tagName.equals("item")) { |
| 9140 | String name = parser.getAttributeValue(null, "name"); |
| 9141 | if (name != null) { |
| 9142 | packageSetting.enabledComponents.add(name.intern()); |
| 9143 | } else { |
| 9144 | reportSettingsProblem(Log.WARN, |
| 9145 | "Error in package manager settings: <enabled-components> has" |
| 9146 | + " no name at " + parser.getPositionDescription()); |
| 9147 | } |
| 9148 | } else { |
| 9149 | reportSettingsProblem(Log.WARN, |
| 9150 | "Unknown element under <enabled-components>: " |
| 9151 | + parser.getName()); |
| 9152 | } |
| 9153 | XmlUtils.skipCurrentTag(parser); |
| 9154 | } |
| 9155 | } |
| 9156 | |
| 9157 | private void readSharedUserLP(XmlPullParser parser) |
| 9158 | throws XmlPullParserException, IOException { |
| 9159 | String name = null; |
| 9160 | String idStr = null; |
| 9161 | int pkgFlags = 0; |
| 9162 | SharedUserSetting su = null; |
| 9163 | try { |
| 9164 | name = parser.getAttributeValue(null, "name"); |
| 9165 | idStr = parser.getAttributeValue(null, "userId"); |
| 9166 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 9167 | if ("true".equals(parser.getAttributeValue(null, "system"))) { |
| 9168 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 9169 | } |
| 9170 | if (name == null) { |
| 9171 | reportSettingsProblem(Log.WARN, |
| 9172 | "Error in package manager settings: <shared-user> has no name at " |
| 9173 | + parser.getPositionDescription()); |
| 9174 | } else if (userId == 0) { |
| 9175 | reportSettingsProblem(Log.WARN, |
| 9176 | "Error in package manager settings: shared-user " |
| 9177 | + name + " has bad userId " + idStr + " at " |
| 9178 | + parser.getPositionDescription()); |
| 9179 | } else { |
| 9180 | if ((su=addSharedUserLP(name.intern(), userId, pkgFlags)) == null) { |
| 9181 | reportSettingsProblem(Log.ERROR, |
| 9182 | "Occurred while parsing settings at " |
| 9183 | + parser.getPositionDescription()); |
| 9184 | } |
| 9185 | } |
| 9186 | } catch (NumberFormatException e) { |
| 9187 | reportSettingsProblem(Log.WARN, |
| 9188 | "Error in package manager settings: package " |
| 9189 | + name + " has bad userId " + idStr + " at " |
| 9190 | + parser.getPositionDescription()); |
| 9191 | }; |
| 9192 | |
| 9193 | if (su != null) { |
| 9194 | int outerDepth = parser.getDepth(); |
| 9195 | int type; |
| 9196 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9197 | && (type != XmlPullParser.END_TAG |
| 9198 | || parser.getDepth() > outerDepth)) { |
| 9199 | if (type == XmlPullParser.END_TAG |
| 9200 | || type == XmlPullParser.TEXT) { |
| 9201 | continue; |
| 9202 | } |
| 9203 | |
| 9204 | String tagName = parser.getName(); |
| 9205 | if (tagName.equals("sigs")) { |
| 9206 | su.signatures.readXml(parser, mPastSignatures); |
| 9207 | } else if (tagName.equals("perms")) { |
| Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 9208 | readGrantedPermissionsLP(parser, su.grantedPermissions); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9209 | } else { |
| 9210 | reportSettingsProblem(Log.WARN, |
| 9211 | "Unknown element under <shared-user>: " |
| 9212 | + parser.getName()); |
| 9213 | XmlUtils.skipCurrentTag(parser); |
| 9214 | } |
| 9215 | } |
| 9216 | |
| 9217 | } else { |
| 9218 | XmlUtils.skipCurrentTag(parser); |
| 9219 | } |
| 9220 | } |
| 9221 | |
| 9222 | private void readGrantedPermissionsLP(XmlPullParser parser, |
| 9223 | HashSet<String> outPerms) throws IOException, XmlPullParserException { |
| 9224 | int outerDepth = parser.getDepth(); |
| 9225 | int type; |
| 9226 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9227 | && (type != XmlPullParser.END_TAG |
| 9228 | || parser.getDepth() > outerDepth)) { |
| 9229 | if (type == XmlPullParser.END_TAG |
| 9230 | || type == XmlPullParser.TEXT) { |
| 9231 | continue; |
| 9232 | } |
| 9233 | |
| 9234 | String tagName = parser.getName(); |
| 9235 | if (tagName.equals("item")) { |
| 9236 | String name = parser.getAttributeValue(null, "name"); |
| 9237 | if (name != null) { |
| 9238 | outPerms.add(name.intern()); |
| 9239 | } else { |
| 9240 | reportSettingsProblem(Log.WARN, |
| 9241 | "Error in package manager settings: <perms> has" |
| 9242 | + " no name at " + parser.getPositionDescription()); |
| 9243 | } |
| 9244 | } else { |
| 9245 | reportSettingsProblem(Log.WARN, |
| 9246 | "Unknown element under <perms>: " |
| 9247 | + parser.getName()); |
| 9248 | } |
| 9249 | XmlUtils.skipCurrentTag(parser); |
| 9250 | } |
| 9251 | } |
| 9252 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9253 | private void readPreferredActivitiesLP(XmlPullParser parser) |
| 9254 | throws XmlPullParserException, IOException { |
| 9255 | int outerDepth = parser.getDepth(); |
| 9256 | int type; |
| 9257 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9258 | && (type != XmlPullParser.END_TAG |
| 9259 | || parser.getDepth() > outerDepth)) { |
| 9260 | if (type == XmlPullParser.END_TAG |
| 9261 | || type == XmlPullParser.TEXT) { |
| 9262 | continue; |
| 9263 | } |
| 9264 | |
| 9265 | String tagName = parser.getName(); |
| 9266 | if (tagName.equals("item")) { |
| 9267 | PreferredActivity pa = new PreferredActivity(parser); |
| 9268 | if (pa.mParseError == null) { |
| 9269 | mPreferredActivities.addFilter(pa); |
| 9270 | } else { |
| 9271 | reportSettingsProblem(Log.WARN, |
| 9272 | "Error in package manager settings: <preferred-activity> " |
| 9273 | + pa.mParseError + " at " |
| 9274 | + parser.getPositionDescription()); |
| 9275 | } |
| 9276 | } else { |
| 9277 | reportSettingsProblem(Log.WARN, |
| 9278 | "Unknown element under <preferred-activities>: " |
| 9279 | + parser.getName()); |
| 9280 | XmlUtils.skipCurrentTag(parser); |
| 9281 | } |
| 9282 | } |
| 9283 | } |
| 9284 | |
| 9285 | // Returns -1 if we could not find an available UserId to assign |
| 9286 | private int newUserIdLP(Object obj) { |
| 9287 | // Let's be stupidly inefficient for now... |
| 9288 | final int N = mUserIds.size(); |
| 9289 | for (int i=0; i<N; i++) { |
| 9290 | if (mUserIds.get(i) == null) { |
| 9291 | mUserIds.set(i, obj); |
| 9292 | return FIRST_APPLICATION_UID + i; |
| 9293 | } |
| 9294 | } |
| 9295 | |
| 9296 | // None left? |
| 9297 | if (N >= MAX_APPLICATION_UIDS) { |
| 9298 | return -1; |
| 9299 | } |
| 9300 | |
| 9301 | mUserIds.add(obj); |
| 9302 | return FIRST_APPLICATION_UID + N; |
| 9303 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9304 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9305 | public PackageSetting getDisabledSystemPkg(String name) { |
| 9306 | synchronized(mPackages) { |
| 9307 | PackageSetting ps = mDisabledSysPackages.get(name); |
| 9308 | return ps; |
| 9309 | } |
| 9310 | } |
| 9311 | |
| 9312 | boolean isEnabledLP(ComponentInfo componentInfo, int flags) { |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 9313 | if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
| 9314 | return true; |
| 9315 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9316 | final PackageSetting packageSettings = mPackages.get(componentInfo.packageName); |
| 9317 | if (Config.LOGV) { |
| 9318 | Log.v(TAG, "isEnabledLock - packageName = " + componentInfo.packageName |
| 9319 | + " componentName = " + componentInfo.name); |
| 9320 | Log.v(TAG, "enabledComponents: " |
| 9321 | + Arrays.toString(packageSettings.enabledComponents.toArray())); |
| 9322 | Log.v(TAG, "disabledComponents: " |
| 9323 | + Arrays.toString(packageSettings.disabledComponents.toArray())); |
| 9324 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9325 | if (packageSettings == null) { |
| 9326 | if (false) { |
| 9327 | Log.w(TAG, "WAITING FOR DEBUGGER"); |
| 9328 | Debug.waitForDebugger(); |
| 9329 | Log.i(TAG, "We will crash!"); |
| 9330 | } |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 9331 | return false; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9332 | } |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 9333 | if (packageSettings.enabled == COMPONENT_ENABLED_STATE_DISABLED |
| 9334 | || (packageSettings.pkg != null && !packageSettings.pkg.applicationInfo.enabled |
| 9335 | && packageSettings.enabled == COMPONENT_ENABLED_STATE_DEFAULT)) { |
| 9336 | return false; |
| 9337 | } |
| 9338 | if (packageSettings.enabledComponents.contains(componentInfo.name)) { |
| 9339 | return true; |
| 9340 | } |
| 9341 | if (packageSettings.disabledComponents.contains(componentInfo.name)) { |
| 9342 | return false; |
| 9343 | } |
| 9344 | return componentInfo.enabled; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9345 | } |
| 9346 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9347 | |
| 9348 | // ------- apps on sdcard specific code ------- |
| 9349 | static final boolean DEBUG_SD_INSTALL = false; |
| Kenny Root | 305bcbf | 2010-09-03 07:56:38 -0700 | [diff] [blame] | 9350 | private static final String SD_ENCRYPTION_KEYSTORE_NAME = "AppsOnSD"; |
| 9351 | private static final String SD_ENCRYPTION_ALGORITHM = "AES"; |
| 9352 | static final int MAX_CONTAINERS = 250; |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9353 | private boolean mMediaMounted = false; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9354 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9355 | private String getEncryptKey() { |
| 9356 | try { |
| Kenny Root | 305bcbf | 2010-09-03 07:56:38 -0700 | [diff] [blame] | 9357 | String sdEncKey = SystemKeyStore.getInstance().retrieveKeyHexString( |
| 9358 | SD_ENCRYPTION_KEYSTORE_NAME); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9359 | if (sdEncKey == null) { |
| Kenny Root | 305bcbf | 2010-09-03 07:56:38 -0700 | [diff] [blame] | 9360 | sdEncKey = SystemKeyStore.getInstance().generateNewKeyHexString(128, |
| 9361 | SD_ENCRYPTION_ALGORITHM, SD_ENCRYPTION_KEYSTORE_NAME); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9362 | if (sdEncKey == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9363 | Slog.e(TAG, "Failed to create encryption keys"); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9364 | return null; |
| 9365 | } |
| 9366 | } |
| 9367 | return sdEncKey; |
| 9368 | } catch (NoSuchAlgorithmException nsae) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9369 | Slog.e(TAG, "Failed to create encryption keys with exception: " + nsae); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9370 | return null; |
| Rich Cannings | 8d57883 | 2010-09-09 15:12:40 -0700 | [diff] [blame] | 9371 | } catch (IOException ioe) { |
| 9372 | Slog.e(TAG, "Failed to retrieve encryption keys with exception: " |
| 9373 | + ioe); |
| 9374 | return null; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9375 | } |
| Rich Cannings | 8d57883 | 2010-09-09 15:12:40 -0700 | [diff] [blame] | 9376 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9377 | } |
| 9378 | |
| Kenny Root | c78a807 | 2010-07-27 15:18:38 -0700 | [diff] [blame] | 9379 | /* package */ static String getTempContainerId() { |
| 9380 | int tmpIdx = 1; |
| 9381 | String list[] = PackageHelper.getSecureContainerList(); |
| 9382 | if (list != null) { |
| 9383 | for (final String name : list) { |
| 9384 | // Ignore null and non-temporary container entries |
| 9385 | if (name == null || !name.startsWith(mTempContainerPrefix)) { |
| 9386 | continue; |
| 9387 | } |
| 9388 | |
| 9389 | String subStr = name.substring(mTempContainerPrefix.length()); |
| 9390 | try { |
| 9391 | int cid = Integer.parseInt(subStr); |
| 9392 | if (cid >= tmpIdx) { |
| 9393 | tmpIdx = cid + 1; |
| 9394 | } |
| 9395 | } catch (NumberFormatException e) { |
| 9396 | } |
| 9397 | } |
| 9398 | } |
| 9399 | return mTempContainerPrefix + tmpIdx; |
| 9400 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9401 | |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9402 | /* |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9403 | * Update media status on PackageManager. |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9404 | */ |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9405 | public void updateExternalMediaStatus(final boolean mediaStatus, final boolean reportStatus) { |
| 9406 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9407 | throw new SecurityException("Media status can only be updated by the system"); |
| 9408 | } |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9409 | synchronized (mPackages) { |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 9410 | Log.i(TAG, "Updating external media status from " + |
| 9411 | (mMediaMounted ? "mounted" : "unmounted") + " to " + |
| 9412 | (mediaStatus ? "mounted" : "unmounted")); |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9413 | if (DEBUG_SD_INSTALL) Log.i(TAG, "updateExternalMediaStatus:: mediaStatus=" + |
| 9414 | mediaStatus+", mMediaMounted=" + mMediaMounted); |
| 9415 | if (mediaStatus == mMediaMounted) { |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9416 | Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, |
| 9417 | reportStatus ? 1 : 0, -1); |
| 9418 | mHandler.sendMessage(msg); |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9419 | return; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9420 | } |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9421 | mMediaMounted = mediaStatus; |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9422 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9423 | // Queue up an async operation since the package installation may take a little while. |
| 9424 | mHandler.post(new Runnable() { |
| 9425 | public void run() { |
| 9426 | mHandler.removeCallbacks(this); |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9427 | updateExternalMediaStatusInner(mediaStatus, reportStatus); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9428 | } |
| 9429 | }); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9430 | } |
| 9431 | |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9432 | /* |
| 9433 | * Collect information of applications on external media, map them |
| 9434 | * against existing containers and update information based on current |
| 9435 | * mount status. Please note that we always have to report status |
| 9436 | * if reportStatus has been set to true especially when unloading packages. |
| 9437 | */ |
| 9438 | private void updateExternalMediaStatusInner(boolean mediaStatus, |
| 9439 | boolean reportStatus) { |
| 9440 | // Collection of uids |
| 9441 | int uidArr[] = null; |
| 9442 | // Collection of stale containers |
| 9443 | HashSet<String> removeCids = new HashSet<String>(); |
| 9444 | // Collection of packages on external media with valid containers. |
| 9445 | HashMap<SdInstallArgs, String> processCids = new HashMap<SdInstallArgs, String>(); |
| 9446 | // Get list of secure containers. |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 9447 | final String list[] = PackageHelper.getSecureContainerList(); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9448 | if (list == null || list.length == 0) { |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 9449 | Log.i(TAG, "No secure containers on sdcard"); |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9450 | } else { |
| 9451 | // Process list of secure containers and categorize them |
| 9452 | // as active or stale based on their package internal state. |
| 9453 | int uidList[] = new int[list.length]; |
| 9454 | int num = 0; |
| 9455 | synchronized (mPackages) { |
| 9456 | for (String cid : list) { |
| 9457 | SdInstallArgs args = new SdInstallArgs(cid); |
| 9458 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Processing container " + cid); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9459 | String pkgName = args.getPackageName(); |
| 9460 | if (pkgName == null) { |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9461 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " stale"); |
| 9462 | removeCids.add(cid); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9463 | continue; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9464 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9465 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Looking for pkg : " + pkgName); |
| 9466 | PackageSetting ps = mSettings.mPackages.get(pkgName); |
| Suchi Amalapurapu | 1ace5bc | 2010-05-13 12:05:53 -0700 | [diff] [blame] | 9467 | // The package status is changed only if the code path |
| 9468 | // matches between settings and the container id. |
| 9469 | if (ps != null && ps.codePathString != null && |
| 9470 | ps.codePathString.equals(args.getCodePath())) { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9471 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + |
| 9472 | " corresponds to pkg : " + pkgName + |
| 9473 | " at code path: " + ps.codePathString); |
| 9474 | // We do have a valid package installed on sdcard |
| 9475 | processCids.put(args, ps.codePathString); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9476 | int uid = ps.userId; |
| 9477 | if (uid != -1) { |
| 9478 | uidList[num++] = uid; |
| 9479 | } |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9480 | } else { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9481 | // Stale container on sdcard. Just delete |
| 9482 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " stale"); |
| 9483 | removeCids.add(cid); |
| 9484 | } |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9485 | } |
| 9486 | } |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9487 | |
| 9488 | if (num > 0) { |
| 9489 | // Sort uid list |
| 9490 | Arrays.sort(uidList, 0, num); |
| 9491 | // Throw away duplicates |
| 9492 | uidArr = new int[num]; |
| 9493 | uidArr[0] = uidList[0]; |
| 9494 | int di = 0; |
| 9495 | for (int i = 1; i < num; i++) { |
| 9496 | if (uidList[i-1] != uidList[i]) { |
| 9497 | uidArr[di++] = uidList[i]; |
| 9498 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9499 | } |
| 9500 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9501 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9502 | // Process packages with valid entries. |
| 9503 | if (mediaStatus) { |
| 9504 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Loading packages"); |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9505 | loadMediaPackages(processCids, uidArr, removeCids); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9506 | startCleaningPackages(); |
| 9507 | } else { |
| 9508 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Unloading packages"); |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9509 | unloadMediaPackages(processCids, uidArr, reportStatus); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9510 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9511 | } |
| 9512 | |
| 9513 | private void sendResourcesChangedBroadcast(boolean mediaStatus, |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9514 | ArrayList<String> pkgList, int uidArr[], IIntentReceiver finishedReceiver) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9515 | int size = pkgList.size(); |
| 9516 | if (size > 0) { |
| 9517 | // Send broadcasts here |
| 9518 | Bundle extras = new Bundle(); |
| 9519 | extras.putStringArray(Intent.EXTRA_CHANGED_PACKAGE_LIST, |
| 9520 | pkgList.toArray(new String[size])); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9521 | if (uidArr != null) { |
| 9522 | extras.putIntArray(Intent.EXTRA_CHANGED_UID_LIST, uidArr); |
| 9523 | } |
| 9524 | String action = mediaStatus ? Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE |
| 9525 | : Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE; |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9526 | sendPackageBroadcast(action, null, extras, finishedReceiver); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9527 | } |
| 9528 | } |
| 9529 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9530 | /* |
| 9531 | * Look at potentially valid container ids from processCids |
| 9532 | * If package information doesn't match the one on record |
| 9533 | * or package scanning fails, the cid is added to list of |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9534 | * removeCids. We currently don't delete stale containers. |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9535 | */ |
| 9536 | private void loadMediaPackages(HashMap<SdInstallArgs, String> processCids, |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9537 | int uidArr[], HashSet<String> removeCids) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9538 | ArrayList<String> pkgList = new ArrayList<String>(); |
| 9539 | Set<SdInstallArgs> keys = processCids.keySet(); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9540 | boolean doGc = false; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9541 | for (SdInstallArgs args : keys) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9542 | String codePath = processCids.get(args); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9543 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Loading container : " |
| 9544 | + args.cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9545 | int retCode = PackageManager.INSTALL_FAILED_CONTAINER_ERROR; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9546 | try { |
| 9547 | // Make sure there are no container errors first. |
| 9548 | if (args.doPreInstall(PackageManager.INSTALL_SUCCEEDED) |
| 9549 | != PackageManager.INSTALL_SUCCEEDED) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9550 | Slog.e(TAG, "Failed to mount cid : " + args.cid + |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9551 | " when installing from sdcard"); |
| 9552 | continue; |
| 9553 | } |
| 9554 | // Check code path here. |
| 9555 | if (codePath == null || !codePath.equals(args.getCodePath())) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9556 | Slog.e(TAG, "Container " + args.cid + " cachepath " + args.getCodePath()+ |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9557 | " does not match one in settings " + codePath); |
| 9558 | continue; |
| 9559 | } |
| 9560 | // Parse package |
| Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 9561 | int parseFlags = PackageParser.PARSE_ON_SDCARD | mDefParseFlags; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9562 | doGc = true; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9563 | synchronized (mInstallLock) { |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 9564 | final PackageParser.Package pkg = scanPackageLI(new File(codePath), |
| 9565 | parseFlags, 0); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9566 | // Scan the package |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 9567 | if (pkg != null) { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9568 | synchronized (mPackages) { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9569 | retCode = PackageManager.INSTALL_SUCCEEDED; |
| 9570 | pkgList.add(pkg.packageName); |
| 9571 | // Post process args |
| 9572 | args.doPostInstall(PackageManager.INSTALL_SUCCEEDED); |
| 9573 | } |
| 9574 | } else { |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 9575 | Slog.i(TAG, "Failed to install pkg from " + |
| 9576 | codePath + " from sdcard"); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9577 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9578 | } |
| 9579 | |
| 9580 | } finally { |
| 9581 | if (retCode != PackageManager.INSTALL_SUCCEEDED) { |
| 9582 | // Don't destroy container here. Wait till gc clears things up. |
| 9583 | removeCids.add(args.cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9584 | } |
| 9585 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9586 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 9587 | synchronized (mPackages) { |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 9588 | // If the platform SDK has changed since the last time we booted, |
| 9589 | // we need to re-grant app permission to catch any new ones that |
| 9590 | // appear. This is really a hack, and means that apps can in some |
| 9591 | // cases get permissions that the user didn't initially explicitly |
| 9592 | // allow... it would be nice to have some better way to handle |
| 9593 | // this situation. |
| 9594 | final boolean regrantPermissions = mSettings.mExternalSdkPlatform |
| 9595 | != mSdkVersion; |
| 9596 | if (regrantPermissions) Slog.i(TAG, "Platform changed from " |
| 9597 | + mSettings.mExternalSdkPlatform + " to " + mSdkVersion |
| 9598 | + "; regranting permissions for external storage"); |
| 9599 | mSettings.mExternalSdkPlatform = mSdkVersion; |
| 9600 | |
| Dianne Hackborn | af7cea3 | 2010-03-24 12:59:52 -0700 | [diff] [blame] | 9601 | // Make sure group IDs have been assigned, and any permission |
| 9602 | // changes in other apps are accounted for |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 9603 | updatePermissionsLP(null, null, true, regrantPermissions, regrantPermissions); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 9604 | // Persist settings |
| 9605 | mSettings.writeLP(); |
| 9606 | } |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9607 | // Send a broadcast to let everyone know we are done processing |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9608 | if (pkgList.size() > 0) { |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9609 | sendResourcesChangedBroadcast(true, pkgList, uidArr, null); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9610 | } |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9611 | // Force gc to avoid any stale parser references that we might have. |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9612 | if (doGc) { |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9613 | Runtime.getRuntime().gc(); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9614 | } |
| Kenny Root | f369a9b | 2010-07-28 14:47:01 -0700 | [diff] [blame] | 9615 | // List stale containers and destroy stale temporary containers. |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9616 | if (removeCids != null) { |
| 9617 | for (String cid : removeCids) { |
| Kenny Root | f369a9b | 2010-07-28 14:47:01 -0700 | [diff] [blame] | 9618 | if (cid.startsWith(mTempContainerPrefix)) { |
| 9619 | Log.i(TAG, "Destroying stale temporary container " + cid); |
| 9620 | PackageHelper.destroySdDir(cid); |
| 9621 | } else { |
| 9622 | Log.w(TAG, "Container " + cid + " is stale"); |
| 9623 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9624 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9625 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9626 | } |
| 9627 | |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9628 | /* |
| 9629 | * Utility method to unload a list of specified containers |
| 9630 | */ |
| 9631 | private void unloadAllContainers(Set<SdInstallArgs> cidArgs) { |
| 9632 | // Just unmount all valid containers. |
| 9633 | for (SdInstallArgs arg : cidArgs) { |
| 9634 | synchronized (mInstallLock) { |
| 9635 | arg.doPostDeleteLI(false); |
| 9636 | } |
| 9637 | } |
| 9638 | } |
| 9639 | |
| 9640 | /* |
| 9641 | * Unload packages mounted on external media. This involves deleting |
| 9642 | * package data from internal structures, sending broadcasts about |
| 9643 | * diabled packages, gc'ing to free up references, unmounting all |
| 9644 | * secure containers corresponding to packages on external media, and |
| 9645 | * posting a UPDATED_MEDIA_STATUS message if status has been requested. |
| 9646 | * Please note that we always have to post this message if status has |
| 9647 | * been requested no matter what. |
| 9648 | */ |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9649 | private void unloadMediaPackages(HashMap<SdInstallArgs, String> processCids, |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9650 | int uidArr[], final boolean reportStatus) { |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9651 | if (DEBUG_SD_INSTALL) Log.i(TAG, "unloading media packages"); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9652 | ArrayList<String> pkgList = new ArrayList<String>(); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9653 | ArrayList<SdInstallArgs> failedList = new ArrayList<SdInstallArgs>(); |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9654 | final Set<SdInstallArgs> keys = processCids.keySet(); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9655 | for (SdInstallArgs args : keys) { |
| 9656 | String cid = args.cid; |
| 9657 | String pkgName = args.getPackageName(); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9658 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to unload pkg : " + pkgName); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9659 | // Delete package internally |
| 9660 | PackageRemovedInfo outInfo = new PackageRemovedInfo(); |
| 9661 | synchronized (mInstallLock) { |
| 9662 | boolean res = deletePackageLI(pkgName, false, |
| 9663 | PackageManager.DONT_DELETE_DATA, outInfo); |
| 9664 | if (res) { |
| 9665 | pkgList.add(pkgName); |
| 9666 | } else { |
| Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 9667 | Slog.e(TAG, "Failed to delete pkg from sdcard : " + pkgName); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9668 | failedList.add(args); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9669 | } |
| 9670 | } |
| 9671 | } |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9672 | // We have to absolutely send UPDATED_MEDIA_STATUS only |
| 9673 | // after confirming that all the receivers processed the ordered |
| 9674 | // broadcast when packages get disabled, force a gc to clean things up. |
| 9675 | // and unload all the containers. |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9676 | if (pkgList.size() > 0) { |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9677 | sendResourcesChangedBroadcast(false, pkgList, uidArr, new IIntentReceiver.Stub() { |
| 9678 | public void performReceive(Intent intent, int resultCode, String data, Bundle extras, |
| 9679 | boolean ordered, boolean sticky) throws RemoteException { |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9680 | Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, |
| 9681 | reportStatus ? 1 : 0, 1, keys); |
| 9682 | mHandler.sendMessage(msg); |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9683 | } |
| 9684 | }); |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9685 | } else { |
| 9686 | Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, |
| 9687 | reportStatus ? 1 : 0, -1, keys); |
| 9688 | mHandler.sendMessage(msg); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9689 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9690 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9691 | |
| 9692 | public void movePackage(final String packageName, |
| 9693 | final IPackageMoveObserver observer, final int flags) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9694 | mContext.enforceCallingOrSelfPermission( |
| 9695 | android.Manifest.permission.MOVE_PACKAGE, null); |
| 9696 | int returnCode = PackageManager.MOVE_SUCCEEDED; |
| 9697 | int currFlags = 0; |
| 9698 | int newFlags = 0; |
| 9699 | synchronized (mPackages) { |
| 9700 | PackageParser.Package pkg = mPackages.get(packageName); |
| 9701 | if (pkg == null) { |
| 9702 | returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9703 | } else { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9704 | // Disable moving fwd locked apps and system packages |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9705 | if (pkg.applicationInfo != null && isSystemApp(pkg)) { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9706 | Slog.w(TAG, "Cannot move system application"); |
| 9707 | returnCode = PackageManager.MOVE_FAILED_SYSTEM_PACKAGE; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9708 | } else if (pkg.applicationInfo != null && isForwardLocked(pkg)) { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9709 | Slog.w(TAG, "Cannot move forward locked app."); |
| 9710 | returnCode = PackageManager.MOVE_FAILED_FORWARD_LOCKED; |
| Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 9711 | } else if (pkg.mOperationPending) { |
| 9712 | Slog.w(TAG, "Attempt to move package which has pending operations"); |
| 9713 | returnCode = PackageManager.MOVE_FAILED_OPERATION_PENDING; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9714 | } else { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9715 | // Find install location first |
| 9716 | if ((flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0 && |
| 9717 | (flags & PackageManager.MOVE_INTERNAL) != 0) { |
| 9718 | Slog.w(TAG, "Ambigous flags specified for move location."); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9719 | returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION; |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9720 | } else { |
| 9721 | newFlags = (flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0 ? |
| 9722 | PackageManager.INSTALL_EXTERNAL : PackageManager.INSTALL_INTERNAL; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9723 | currFlags = isExternal(pkg) ? PackageManager.INSTALL_EXTERNAL |
| 9724 | : PackageManager.INSTALL_INTERNAL; |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9725 | if (newFlags == currFlags) { |
| 9726 | Slog.w(TAG, "No move required. Trying to move to same location"); |
| 9727 | returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION; |
| 9728 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9729 | } |
| Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 9730 | if (returnCode == PackageManager.MOVE_SUCCEEDED) { |
| 9731 | pkg.mOperationPending = true; |
| 9732 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9733 | } |
| 9734 | } |
| 9735 | if (returnCode != PackageManager.MOVE_SUCCEEDED) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9736 | processPendingMove(new MoveParams(null, observer, 0, packageName, null), returnCode); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9737 | } else { |
| 9738 | Message msg = mHandler.obtainMessage(INIT_COPY); |
| 9739 | InstallArgs srcArgs = createInstallArgs(currFlags, pkg.applicationInfo.sourceDir, |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9740 | pkg.applicationInfo.publicSourceDir, pkg.applicationInfo.nativeLibraryDir); |
| 9741 | MoveParams mp = new MoveParams(srcArgs, observer, newFlags, packageName, |
| 9742 | pkg.applicationInfo.dataDir); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9743 | msg.obj = mp; |
| 9744 | mHandler.sendMessage(msg); |
| 9745 | } |
| 9746 | } |
| 9747 | } |
| 9748 | |
| 9749 | private void processPendingMove(final MoveParams mp, final int currentStatus) { |
| 9750 | // Queue up an async operation since the package deletion may take a little while. |
| 9751 | mHandler.post(new Runnable() { |
| 9752 | public void run() { |
| 9753 | mHandler.removeCallbacks(this); |
| 9754 | int returnCode = currentStatus; |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9755 | if (currentStatus == PackageManager.MOVE_SUCCEEDED) { |
| 9756 | int uidArr[] = null; |
| 9757 | ArrayList<String> pkgList = null; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9758 | synchronized (mPackages) { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9759 | PackageParser.Package pkg = mPackages.get(mp.packageName); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9760 | if (pkg == null) { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9761 | Slog.w(TAG, " Package " + mp.packageName + |
| 9762 | " doesn't exist. Aborting move"); |
| 9763 | returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST; |
| 9764 | } else if (!mp.srcArgs.getCodePath().equals(pkg.applicationInfo.sourceDir)) { |
| 9765 | Slog.w(TAG, "Package " + mp.packageName + " code path changed from " + |
| 9766 | mp.srcArgs.getCodePath() + " to " + pkg.applicationInfo.sourceDir + |
| 9767 | " Aborting move and returning error"); |
| 9768 | returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR; |
| 9769 | } else { |
| 9770 | uidArr = new int[] { pkg.applicationInfo.uid }; |
| 9771 | pkgList = new ArrayList<String>(); |
| 9772 | pkgList.add(mp.packageName); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9773 | } |
| 9774 | } |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9775 | if (returnCode == PackageManager.MOVE_SUCCEEDED) { |
| 9776 | // Send resources unavailable broadcast |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9777 | sendResourcesChangedBroadcast(false, pkgList, uidArr, null); |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9778 | // Update package code and resource paths |
| 9779 | synchronized (mInstallLock) { |
| 9780 | synchronized (mPackages) { |
| 9781 | PackageParser.Package pkg = mPackages.get(mp.packageName); |
| 9782 | // Recheck for package again. |
| 9783 | if (pkg == null ) { |
| 9784 | Slog.w(TAG, " Package " + mp.packageName + |
| 9785 | " doesn't exist. Aborting move"); |
| 9786 | returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST; |
| 9787 | } else if (!mp.srcArgs.getCodePath().equals(pkg.applicationInfo.sourceDir)) { |
| 9788 | Slog.w(TAG, "Package " + mp.packageName + " code path changed from " + |
| 9789 | mp.srcArgs.getCodePath() + " to " + pkg.applicationInfo.sourceDir + |
| 9790 | " Aborting move and returning error"); |
| 9791 | returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR; |
| 9792 | } else { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9793 | final String oldCodePath = pkg.mPath; |
| 9794 | final String newCodePath = mp.targetArgs.getCodePath(); |
| 9795 | final String newResPath = mp.targetArgs.getResourcePath(); |
| 9796 | final String newNativePath = mp.targetArgs.getNativeLibraryPath(); |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9797 | pkg.mPath = newCodePath; |
| 9798 | // Move dex files around |
| 9799 | if (moveDexFilesLI(pkg) |
| 9800 | != PackageManager.INSTALL_SUCCEEDED) { |
| 9801 | // Moving of dex files failed. Set |
| 9802 | // error code and abort move. |
| 9803 | pkg.mPath = pkg.mScanPath; |
| 9804 | returnCode = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE; |
| 9805 | } else { |
| 9806 | pkg.mScanPath = newCodePath; |
| 9807 | pkg.applicationInfo.sourceDir = newCodePath; |
| 9808 | pkg.applicationInfo.publicSourceDir = newResPath; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9809 | pkg.applicationInfo.nativeLibraryDir = newNativePath; |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9810 | PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 9811 | ps.codePath = new File(pkg.applicationInfo.sourceDir); |
| 9812 | ps.codePathString = ps.codePath.getPath(); |
| 9813 | ps.resourcePath = new File(pkg.applicationInfo.publicSourceDir); |
| 9814 | ps.resourcePathString = ps.resourcePath.getPath(); |
| Kenny Root | 0ac83f5 | 2010-08-30 15:12:24 -0700 | [diff] [blame] | 9815 | ps.nativeLibraryPathString = newNativePath; |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9816 | // Set the application info flag correctly. |
| 9817 | if ((mp.flags & PackageManager.INSTALL_EXTERNAL) != 0) { |
| 9818 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 9819 | } else { |
| 9820 | pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 9821 | } |
| 9822 | ps.setFlags(pkg.applicationInfo.flags); |
| 9823 | mAppDirs.remove(oldCodePath); |
| 9824 | mAppDirs.put(newCodePath, pkg); |
| 9825 | // Persist settings |
| 9826 | mSettings.writeLP(); |
| 9827 | } |
| 9828 | } |
| 9829 | } |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9830 | } |
| Suchi Amalapurapu | 0c1285f | 2010-04-14 17:05:48 -0700 | [diff] [blame] | 9831 | // Send resources available broadcast |
| 9832 | sendResourcesChangedBroadcast(true, pkgList, uidArr, null); |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9833 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9834 | } |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9835 | if (returnCode != PackageManager.MOVE_SUCCEEDED){ |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9836 | // Clean up failed installation |
| 9837 | if (mp.targetArgs != null) { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9838 | mp.targetArgs.doPostInstall(PackageManager.INSTALL_FAILED_INTERNAL_ERROR); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9839 | } |
| 9840 | } else { |
| 9841 | // Force a gc to clear things up. |
| 9842 | Runtime.getRuntime().gc(); |
| 9843 | // Delete older code |
| 9844 | synchronized (mInstallLock) { |
| 9845 | mp.srcArgs.doPostDeleteLI(true); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9846 | } |
| 9847 | } |
| Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 9848 | |
| 9849 | // Allow more operations on this file if we didn't fail because |
| 9850 | // an operation was already pending for this package. |
| 9851 | if (returnCode != PackageManager.MOVE_FAILED_OPERATION_PENDING) { |
| 9852 | synchronized (mPackages) { |
| 9853 | PackageParser.Package pkg = mPackages.get(mp.packageName); |
| 9854 | if (pkg != null) { |
| 9855 | pkg.mOperationPending = false; |
| 9856 | } |
| 9857 | } |
| 9858 | } |
| 9859 | |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9860 | IPackageMoveObserver observer = mp.observer; |
| 9861 | if (observer != null) { |
| 9862 | try { |
| 9863 | observer.packageMoved(mp.packageName, returnCode); |
| 9864 | } catch (RemoteException e) { |
| 9865 | Log.i(TAG, "Observer no longer exists."); |
| 9866 | } |
| 9867 | } |
| 9868 | } |
| 9869 | }); |
| 9870 | } |
| Suchi Amalapurapu | 40e4725 | 2010-04-07 16:15:50 -0700 | [diff] [blame] | 9871 | |
| 9872 | public boolean setInstallLocation(int loc) { |
| 9873 | mContext.enforceCallingOrSelfPermission( |
| 9874 | android.Manifest.permission.WRITE_SECURE_SETTINGS, null); |
| 9875 | if (getInstallLocation() == loc) { |
| 9876 | return true; |
| 9877 | } |
| 9878 | if (loc == PackageHelper.APP_INSTALL_AUTO || |
| 9879 | loc == PackageHelper.APP_INSTALL_INTERNAL || |
| 9880 | loc == PackageHelper.APP_INSTALL_EXTERNAL) { |
| 9881 | android.provider.Settings.System.putInt(mContext.getContentResolver(), |
| 9882 | android.provider.Settings.Secure.DEFAULT_INSTALL_LOCATION, loc); |
| 9883 | return true; |
| 9884 | } |
| 9885 | return false; |
| 9886 | } |
| 9887 | |
| 9888 | public int getInstallLocation() { |
| 9889 | return android.provider.Settings.System.getInt(mContext.getContentResolver(), |
| 9890 | android.provider.Settings.Secure.DEFAULT_INSTALL_LOCATION, PackageHelper.APP_INSTALL_AUTO); |
| 9891 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9892 | } |