| 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:"); |
| 2025 | ai.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 2026 | } |
| 2027 | if (ai != null) { |
| 2028 | for (int j=0; j<N; j++) { |
| 2029 | ResolveInfo ri = query.get(j); |
| 2030 | if (!ri.activityInfo.applicationInfo.packageName |
| 2031 | .equals(ai.applicationInfo.packageName)) { |
| 2032 | continue; |
| 2033 | } |
| 2034 | if (!ri.activityInfo.name.equals(ai.name)) { |
| 2035 | continue; |
| 2036 | } |
| 2037 | |
| 2038 | // Okay we found a previously set preferred app. |
| 2039 | // If the result set is different from when this |
| 2040 | // was created, we need to clear it and re-ask the |
| 2041 | // user their preference. |
| 2042 | if (!pa.sameSet(query, priority)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2043 | 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] | 2044 | + intent + " type " + resolvedType); |
| 2045 | mSettings.mPreferredActivities.removeFilter(pa); |
| 2046 | return null; |
| 2047 | } |
| 2048 | |
| 2049 | // Yay! |
| 2050 | return ri; |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | } |
| 2056 | return null; |
| 2057 | } |
| 2058 | |
| 2059 | public List<ResolveInfo> queryIntentActivities(Intent intent, |
| 2060 | String resolvedType, int flags) { |
| 2061 | ComponentName comp = intent.getComponent(); |
| 2062 | if (comp != null) { |
| 2063 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2064 | ActivityInfo ai = getActivityInfo(comp, flags); |
| 2065 | if (ai != null) { |
| 2066 | ResolveInfo ri = new ResolveInfo(); |
| 2067 | ri.activityInfo = ai; |
| 2068 | list.add(ri); |
| 2069 | } |
| 2070 | return list; |
| 2071 | } |
| 2072 | |
| 2073 | synchronized (mPackages) { |
| Dianne Hackborn | c14b9ccd | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2074 | String pkgName = intent.getPackage(); |
| 2075 | if (pkgName == null) { |
| 2076 | return (List<ResolveInfo>)mActivities.queryIntent(intent, |
| 2077 | resolvedType, flags); |
| 2078 | } |
| 2079 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2080 | if (pkg != null) { |
| 2081 | return (List<ResolveInfo>) mActivities.queryIntentForPackage(intent, |
| 2082 | resolvedType, flags, pkg.activities); |
| 2083 | } |
| 2084 | return null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, |
| 2089 | Intent[] specifics, String[] specificTypes, Intent intent, |
| 2090 | String resolvedType, int flags) { |
| 2091 | final String resultsAction = intent.getAction(); |
| 2092 | |
| 2093 | List<ResolveInfo> results = queryIntentActivities( |
| 2094 | intent, resolvedType, flags|PackageManager.GET_RESOLVED_FILTER); |
| 2095 | if (Config.LOGV) Log.v(TAG, "Query " + intent + ": " + results); |
| 2096 | |
| 2097 | int specificsPos = 0; |
| 2098 | int N; |
| 2099 | |
| 2100 | // todo: note that the algorithm used here is O(N^2). This |
| 2101 | // isn't a problem in our current environment, but if we start running |
| 2102 | // into situations where we have more than 5 or 10 matches then this |
| 2103 | // should probably be changed to something smarter... |
| 2104 | |
| 2105 | // First we go through and resolve each of the specific items |
| 2106 | // that were supplied, taking care of removing any corresponding |
| 2107 | // duplicate items in the generic resolve list. |
| 2108 | if (specifics != null) { |
| 2109 | for (int i=0; i<specifics.length; i++) { |
| 2110 | final Intent sintent = specifics[i]; |
| 2111 | if (sintent == null) { |
| 2112 | continue; |
| 2113 | } |
| 2114 | |
| 2115 | if (Config.LOGV) Log.v(TAG, "Specific #" + i + ": " + sintent); |
| 2116 | String action = sintent.getAction(); |
| 2117 | if (resultsAction != null && resultsAction.equals(action)) { |
| 2118 | // If this action was explicitly requested, then don't |
| 2119 | // remove things that have it. |
| 2120 | action = null; |
| 2121 | } |
| 2122 | ComponentName comp = sintent.getComponent(); |
| 2123 | ResolveInfo ri = null; |
| 2124 | ActivityInfo ai = null; |
| 2125 | if (comp == null) { |
| 2126 | ri = resolveIntent( |
| 2127 | sintent, |
| 2128 | specificTypes != null ? specificTypes[i] : null, |
| 2129 | flags); |
| 2130 | if (ri == null) { |
| 2131 | continue; |
| 2132 | } |
| 2133 | if (ri == mResolveInfo) { |
| 2134 | // ACK! Must do something better with this. |
| 2135 | } |
| 2136 | ai = ri.activityInfo; |
| 2137 | comp = new ComponentName(ai.applicationInfo.packageName, |
| 2138 | ai.name); |
| 2139 | } else { |
| 2140 | ai = getActivityInfo(comp, flags); |
| 2141 | if (ai == null) { |
| 2142 | continue; |
| 2143 | } |
| 2144 | } |
| 2145 | |
| 2146 | // Look for any generic query activities that are duplicates |
| 2147 | // of this specific one, and remove them from the results. |
| 2148 | if (Config.LOGV) Log.v(TAG, "Specific #" + i + ": " + ai); |
| 2149 | N = results.size(); |
| 2150 | int j; |
| 2151 | for (j=specificsPos; j<N; j++) { |
| 2152 | ResolveInfo sri = results.get(j); |
| 2153 | if ((sri.activityInfo.name.equals(comp.getClassName()) |
| 2154 | && sri.activityInfo.applicationInfo.packageName.equals( |
| 2155 | comp.getPackageName())) |
| 2156 | || (action != null && sri.filter.matchAction(action))) { |
| 2157 | results.remove(j); |
| 2158 | if (Config.LOGV) Log.v( |
| 2159 | TAG, "Removing duplicate item from " + j |
| 2160 | + " due to specific " + specificsPos); |
| 2161 | if (ri == null) { |
| 2162 | ri = sri; |
| 2163 | } |
| 2164 | j--; |
| 2165 | N--; |
| 2166 | } |
| 2167 | } |
| 2168 | |
| 2169 | // Add this specific item to its proper place. |
| 2170 | if (ri == null) { |
| 2171 | ri = new ResolveInfo(); |
| 2172 | ri.activityInfo = ai; |
| 2173 | } |
| 2174 | results.add(specificsPos, ri); |
| 2175 | ri.specificIndex = i; |
| 2176 | specificsPos++; |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | // Now we go through the remaining generic results and remove any |
| 2181 | // duplicate actions that are found here. |
| 2182 | N = results.size(); |
| 2183 | for (int i=specificsPos; i<N-1; i++) { |
| 2184 | final ResolveInfo rii = results.get(i); |
| 2185 | if (rii.filter == null) { |
| 2186 | continue; |
| 2187 | } |
| 2188 | |
| 2189 | // Iterate over all of the actions of this result's intent |
| 2190 | // filter... typically this should be just one. |
| 2191 | final Iterator<String> it = rii.filter.actionsIterator(); |
| 2192 | if (it == null) { |
| 2193 | continue; |
| 2194 | } |
| 2195 | while (it.hasNext()) { |
| 2196 | final String action = it.next(); |
| 2197 | if (resultsAction != null && resultsAction.equals(action)) { |
| 2198 | // If this action was explicitly requested, then don't |
| 2199 | // remove things that have it. |
| 2200 | continue; |
| 2201 | } |
| 2202 | for (int j=i+1; j<N; j++) { |
| 2203 | final ResolveInfo rij = results.get(j); |
| 2204 | if (rij.filter != null && rij.filter.hasAction(action)) { |
| 2205 | results.remove(j); |
| 2206 | if (Config.LOGV) Log.v( |
| 2207 | TAG, "Removing duplicate item from " + j |
| 2208 | + " due to action " + action + " at " + i); |
| 2209 | j--; |
| 2210 | N--; |
| 2211 | } |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | // If the caller didn't request filter information, drop it now |
| 2216 | // so we don't have to marshall/unmarshall it. |
| 2217 | if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) { |
| 2218 | rii.filter = null; |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | // Filter out the caller activity if so requested. |
| 2223 | if (caller != null) { |
| 2224 | N = results.size(); |
| 2225 | for (int i=0; i<N; i++) { |
| 2226 | ActivityInfo ainfo = results.get(i).activityInfo; |
| 2227 | if (caller.getPackageName().equals(ainfo.applicationInfo.packageName) |
| 2228 | && caller.getClassName().equals(ainfo.name)) { |
| 2229 | results.remove(i); |
| 2230 | break; |
| 2231 | } |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | // If the caller didn't request filter information, |
| 2236 | // drop them now so we don't have to |
| 2237 | // marshall/unmarshall it. |
| 2238 | if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) { |
| 2239 | N = results.size(); |
| 2240 | for (int i=0; i<N; i++) { |
| 2241 | results.get(i).filter = null; |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | if (Config.LOGV) Log.v(TAG, "Result: " + results); |
| 2246 | return results; |
| 2247 | } |
| 2248 | |
| 2249 | public List<ResolveInfo> queryIntentReceivers(Intent intent, |
| 2250 | String resolvedType, int flags) { |
| Dianne Hackborn | c14b9ccd | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2251 | ComponentName comp = intent.getComponent(); |
| 2252 | if (comp != null) { |
| 2253 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2254 | ActivityInfo ai = getReceiverInfo(comp, flags); |
| 2255 | if (ai != null) { |
| 2256 | ResolveInfo ri = new ResolveInfo(); |
| 2257 | ri.activityInfo = ai; |
| 2258 | list.add(ri); |
| 2259 | } |
| 2260 | return list; |
| 2261 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2262 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2263 | synchronized (mPackages) { |
| Dianne Hackborn | c14b9ccd | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2264 | String pkgName = intent.getPackage(); |
| 2265 | if (pkgName == null) { |
| 2266 | return (List<ResolveInfo>)mReceivers.queryIntent(intent, |
| 2267 | resolvedType, flags); |
| 2268 | } |
| 2269 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2270 | if (pkg != null) { |
| 2271 | return (List<ResolveInfo>) mReceivers.queryIntentForPackage(intent, |
| 2272 | resolvedType, flags, pkg.receivers); |
| 2273 | } |
| 2274 | return null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | } |
| 2276 | } |
| 2277 | |
| 2278 | public ResolveInfo resolveService(Intent intent, String resolvedType, |
| 2279 | int flags) { |
| 2280 | List<ResolveInfo> query = queryIntentServices(intent, resolvedType, |
| 2281 | flags); |
| 2282 | if (query != null) { |
| 2283 | if (query.size() >= 1) { |
| 2284 | // If there is more than one service with the same priority, |
| 2285 | // just arbitrarily pick the first one. |
| 2286 | return query.get(0); |
| 2287 | } |
| 2288 | } |
| 2289 | return null; |
| 2290 | } |
| 2291 | |
| 2292 | public List<ResolveInfo> queryIntentServices(Intent intent, |
| 2293 | String resolvedType, int flags) { |
| 2294 | ComponentName comp = intent.getComponent(); |
| 2295 | if (comp != null) { |
| 2296 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2297 | ServiceInfo si = getServiceInfo(comp, flags); |
| 2298 | if (si != null) { |
| 2299 | ResolveInfo ri = new ResolveInfo(); |
| 2300 | ri.serviceInfo = si; |
| 2301 | list.add(ri); |
| 2302 | } |
| 2303 | return list; |
| 2304 | } |
| 2305 | |
| 2306 | synchronized (mPackages) { |
| Dianne Hackborn | c14b9ccd | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2307 | String pkgName = intent.getPackage(); |
| 2308 | if (pkgName == null) { |
| 2309 | return (List<ResolveInfo>)mServices.queryIntent(intent, |
| 2310 | resolvedType, flags); |
| 2311 | } |
| 2312 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2313 | if (pkg != null) { |
| 2314 | return (List<ResolveInfo>)mServices.queryIntentForPackage(intent, |
| 2315 | resolvedType, flags, pkg.services); |
| 2316 | } |
| 2317 | return null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2318 | } |
| 2319 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2321 | public List<PackageInfo> getInstalledPackages(int flags) { |
| 2322 | ArrayList<PackageInfo> finalList = new ArrayList<PackageInfo>(); |
| 2323 | |
| 2324 | synchronized (mPackages) { |
| 2325 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 2326 | Iterator<PackageSetting> i = mSettings.mPackages.values().iterator(); |
| 2327 | while (i.hasNext()) { |
| 2328 | final PackageSetting ps = i.next(); |
| 2329 | PackageInfo psPkg = generatePackageInfoFromSettingsLP(ps.name, flags); |
| 2330 | if(psPkg != null) { |
| 2331 | finalList.add(psPkg); |
| 2332 | } |
| 2333 | } |
| 2334 | } |
| 2335 | else { |
| 2336 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2337 | while (i.hasNext()) { |
| 2338 | final PackageParser.Package p = i.next(); |
| 2339 | if (p.applicationInfo != null) { |
| 2340 | PackageInfo pi = generatePackageInfo(p, flags); |
| 2341 | if(pi != null) { |
| 2342 | finalList.add(pi); |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | } |
| 2347 | } |
| 2348 | return finalList; |
| 2349 | } |
| 2350 | |
| 2351 | public List<ApplicationInfo> getInstalledApplications(int flags) { |
| 2352 | ArrayList<ApplicationInfo> finalList = new ArrayList<ApplicationInfo>(); |
| 2353 | synchronized(mPackages) { |
| 2354 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 2355 | Iterator<PackageSetting> i = mSettings.mPackages.values().iterator(); |
| 2356 | while (i.hasNext()) { |
| 2357 | final PackageSetting ps = i.next(); |
| 2358 | ApplicationInfo ai = generateApplicationInfoFromSettingsLP(ps.name, flags); |
| 2359 | if(ai != null) { |
| 2360 | finalList.add(ai); |
| 2361 | } |
| 2362 | } |
| 2363 | } |
| 2364 | else { |
| 2365 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2366 | while (i.hasNext()) { |
| 2367 | final PackageParser.Package p = i.next(); |
| 2368 | if (p.applicationInfo != null) { |
| 2369 | ApplicationInfo ai = PackageParser.generateApplicationInfo(p, flags); |
| 2370 | if(ai != null) { |
| 2371 | finalList.add(ai); |
| 2372 | } |
| 2373 | } |
| 2374 | } |
| 2375 | } |
| 2376 | } |
| 2377 | return finalList; |
| 2378 | } |
| 2379 | |
| 2380 | public List<ApplicationInfo> getPersistentApplications(int flags) { |
| 2381 | ArrayList<ApplicationInfo> finalList = new ArrayList<ApplicationInfo>(); |
| 2382 | |
| 2383 | synchronized (mPackages) { |
| 2384 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2385 | while (i.hasNext()) { |
| 2386 | PackageParser.Package p = i.next(); |
| 2387 | if (p.applicationInfo != null |
| 2388 | && (p.applicationInfo.flags&ApplicationInfo.FLAG_PERSISTENT) != 0 |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 2389 | && (!mSafeMode || isSystemApp(p))) { |
| Jey | 2eebf5c | 2009-11-18 18:37:31 -0800 | [diff] [blame] | 2390 | finalList.add(PackageParser.generateApplicationInfo(p, flags)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | } |
| 2392 | } |
| 2393 | } |
| 2394 | |
| 2395 | return finalList; |
| 2396 | } |
| 2397 | |
| 2398 | public ProviderInfo resolveContentProvider(String name, int flags) { |
| 2399 | synchronized (mPackages) { |
| 2400 | final PackageParser.Provider provider = mProviders.get(name); |
| 2401 | return provider != null |
| 2402 | && mSettings.isEnabledLP(provider.info, flags) |
| 2403 | && (!mSafeMode || (provider.info.applicationInfo.flags |
| 2404 | &ApplicationInfo.FLAG_SYSTEM) != 0) |
| 2405 | ? PackageParser.generateProviderInfo(provider, flags) |
| 2406 | : null; |
| 2407 | } |
| 2408 | } |
| 2409 | |
| Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2410 | /** |
| 2411 | * @deprecated |
| 2412 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2413 | public void querySyncProviders(List outNames, List outInfo) { |
| 2414 | synchronized (mPackages) { |
| 2415 | Iterator<Map.Entry<String, PackageParser.Provider>> i |
| 2416 | = mProviders.entrySet().iterator(); |
| 2417 | |
| 2418 | while (i.hasNext()) { |
| 2419 | Map.Entry<String, PackageParser.Provider> entry = i.next(); |
| 2420 | PackageParser.Provider p = entry.getValue(); |
| 2421 | |
| 2422 | if (p.syncable |
| 2423 | && (!mSafeMode || (p.info.applicationInfo.flags |
| 2424 | &ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| 2425 | outNames.add(entry.getKey()); |
| 2426 | outInfo.add(PackageParser.generateProviderInfo(p, 0)); |
| 2427 | } |
| 2428 | } |
| 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | public List<ProviderInfo> queryContentProviders(String processName, |
| 2433 | int uid, int flags) { |
| 2434 | ArrayList<ProviderInfo> finalList = null; |
| 2435 | |
| 2436 | synchronized (mPackages) { |
| 2437 | Iterator<PackageParser.Provider> i = mProvidersByComponent.values().iterator(); |
| 2438 | while (i.hasNext()) { |
| 2439 | PackageParser.Provider p = i.next(); |
| 2440 | if (p.info.authority != null |
| 2441 | && (processName == null || |
| 2442 | (p.info.processName.equals(processName) |
| 2443 | && p.info.applicationInfo.uid == uid)) |
| 2444 | && mSettings.isEnabledLP(p.info, flags) |
| 2445 | && (!mSafeMode || (p.info.applicationInfo.flags |
| 2446 | &ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| 2447 | if (finalList == null) { |
| 2448 | finalList = new ArrayList<ProviderInfo>(3); |
| 2449 | } |
| 2450 | finalList.add(PackageParser.generateProviderInfo(p, |
| 2451 | flags)); |
| 2452 | } |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | if (finalList != null) { |
| 2457 | Collections.sort(finalList, mProviderInitOrderSorter); |
| 2458 | } |
| 2459 | |
| 2460 | return finalList; |
| 2461 | } |
| 2462 | |
| 2463 | public InstrumentationInfo getInstrumentationInfo(ComponentName name, |
| 2464 | int flags) { |
| 2465 | synchronized (mPackages) { |
| 2466 | final PackageParser.Instrumentation i = mInstrumentation.get(name); |
| 2467 | return PackageParser.generateInstrumentationInfo(i, flags); |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | public List<InstrumentationInfo> queryInstrumentation(String targetPackage, |
| 2472 | int flags) { |
| 2473 | ArrayList<InstrumentationInfo> finalList = |
| 2474 | new ArrayList<InstrumentationInfo>(); |
| 2475 | |
| 2476 | synchronized (mPackages) { |
| 2477 | Iterator<PackageParser.Instrumentation> i = mInstrumentation.values().iterator(); |
| 2478 | while (i.hasNext()) { |
| 2479 | PackageParser.Instrumentation p = i.next(); |
| 2480 | if (targetPackage == null |
| 2481 | || targetPackage.equals(p.info.targetPackage)) { |
| 2482 | finalList.add(PackageParser.generateInstrumentationInfo(p, |
| 2483 | flags)); |
| 2484 | } |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | return finalList; |
| 2489 | } |
| 2490 | |
| 2491 | private void scanDirLI(File dir, int flags, int scanMode) { |
| 2492 | Log.d(TAG, "Scanning app dir " + dir); |
| 2493 | |
| 2494 | String[] files = dir.list(); |
| 2495 | |
| 2496 | int i; |
| 2497 | for (i=0; i<files.length; i++) { |
| 2498 | File file = new File(dir, files[i]); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 2499 | if (!isPackageFilename(files[i])) { |
| 2500 | // Ignore entries which are not apk's |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 2501 | continue; |
| 2502 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2503 | PackageParser.Package pkg = scanPackageLI(file, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | flags|PackageParser.PARSE_MUST_BE_APK, scanMode); |
| Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2505 | // Don't mess around with apps in system partition. |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 2506 | if (pkg == null && (flags & PackageParser.PARSE_IS_SYSTEM) == 0 && |
| 2507 | mLastScanError == PackageManager.INSTALL_FAILED_INVALID_APK) { |
| Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2508 | // Delete the apk |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2509 | Slog.w(TAG, "Cleaning up failed install of " + file); |
| Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2510 | file.delete(); |
| 2511 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | } |
| 2513 | } |
| 2514 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2515 | private static File getSettingsProblemFile() { |
| 2516 | File dataDir = Environment.getDataDirectory(); |
| 2517 | File systemDir = new File(dataDir, "system"); |
| 2518 | File fname = new File(systemDir, "uiderrors.txt"); |
| 2519 | return fname; |
| 2520 | } |
| 2521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | private static void reportSettingsProblem(int priority, String msg) { |
| 2523 | try { |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2524 | File fname = getSettingsProblemFile(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | FileOutputStream out = new FileOutputStream(fname, true); |
| 2526 | PrintWriter pw = new PrintWriter(out); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2527 | SimpleDateFormat formatter = new SimpleDateFormat(); |
| 2528 | String dateString = formatter.format(new Date(System.currentTimeMillis())); |
| 2529 | pw.println(dateString + ": " + msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2530 | pw.close(); |
| 2531 | FileUtils.setPermissions( |
| 2532 | fname.toString(), |
| 2533 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IROTH, |
| 2534 | -1, -1); |
| 2535 | } catch (java.io.IOException e) { |
| 2536 | } |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2537 | Slog.println(priority, TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | private boolean collectCertificatesLI(PackageParser pp, PackageSetting ps, |
| 2541 | PackageParser.Package pkg, File srcFile, int parseFlags) { |
| 2542 | if (GET_CERTIFICATES) { |
| Jeff Brown | e760072 | 2010-04-07 18:28:23 -0700 | [diff] [blame] | 2543 | if (ps != null |
| 2544 | && ps.codePath.equals(srcFile) |
| 2545 | && ps.getTimeStamp() == srcFile.lastModified()) { |
| 2546 | if (ps.signatures.mSignatures != null |
| 2547 | && ps.signatures.mSignatures.length != 0) { |
| 2548 | // Optimization: reuse the existing cached certificates |
| 2549 | // if the package appears to be unchanged. |
| 2550 | pkg.mSignatures = ps.signatures.mSignatures; |
| 2551 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | } |
| Jeff Brown | e760072 | 2010-04-07 18:28:23 -0700 | [diff] [blame] | 2553 | |
| 2554 | 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] | 2555 | } else { |
| Jeff Brown | e760072 | 2010-04-07 18:28:23 -0700 | [diff] [blame] | 2556 | Log.i(TAG, srcFile.toString() + " changed; collecting certs"); |
| 2557 | } |
| 2558 | |
| 2559 | if (!pp.collectCertificates(pkg, parseFlags)) { |
| 2560 | mLastScanError = pp.getParseError(); |
| 2561 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | } |
| 2563 | } |
| 2564 | return true; |
| 2565 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2566 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2567 | /* |
| 2568 | * Scan a package and return the newly parsed package. |
| 2569 | * Returns null in case of errors and the error code is stored in mLastScanError |
| 2570 | */ |
| 2571 | private PackageParser.Package scanPackageLI(File scanFile, |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2572 | int parseFlags, int scanMode) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2574 | String scanPath = scanFile.getPath(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2575 | parseFlags |= mDefParseFlags; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2576 | PackageParser pp = new PackageParser(scanPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2577 | pp.setSeparateProcesses(mSeparateProcesses); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2578 | final PackageParser.Package pkg = pp.parsePackage(scanFile, |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2579 | scanPath, mMetrics, parseFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2580 | if (pkg == null) { |
| 2581 | mLastScanError = pp.getParseError(); |
| 2582 | return null; |
| 2583 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2584 | PackageSetting ps = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2585 | PackageSetting updatedPkg; |
| 2586 | synchronized (mPackages) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2587 | // Look to see if we already know about this package. |
| 2588 | String oldName = mSettings.mRenamedPackages.get(pkg.packageName); |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2589 | if (pkg.mOriginalPackages != null && pkg.mOriginalPackages.contains(oldName)) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2590 | // This package has been renamed to its original name. Let's |
| 2591 | // use that. |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2592 | ps = mSettings.peekPackageLP(oldName); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2593 | } |
| 2594 | // If there was no original package, see one for the real package name. |
| 2595 | if (ps == null) { |
| 2596 | ps = mSettings.peekPackageLP(pkg.packageName); |
| 2597 | } |
| 2598 | // Check to see if this package could be hiding/updating a system |
| 2599 | // package. Must look for it either under the original or real |
| 2600 | // package name depending on our state. |
| 2601 | updatedPkg = mSettings.mDisabledSysPackages.get( |
| 2602 | ps != null ? ps.name : pkg.packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2603 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2604 | // First check if this is a system package that may involve an update |
| 2605 | if (updatedPkg != null && (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| Kenny Root | 9ee9274 | 2010-09-01 13:40:57 -0700 | [diff] [blame] | 2606 | if (ps != null && !ps.codePath.equals(scanFile)) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2607 | // The path has changed from what was last scanned... check the |
| 2608 | // version of the new path against what we have stored to determine |
| 2609 | // what to do. |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2610 | if (pkg.mVersionCode < ps.versionCode) { |
| 2611 | // 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] | 2612 | // Ignore entry. Skip it. |
| 2613 | Log.i(TAG, "Package " + ps.name + " at " + scanFile |
| 2614 | + "ignored: updated version " + ps.versionCode |
| 2615 | + " better than this " + pkg.mVersionCode); |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2616 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2617 | return null; |
| 2618 | } else { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2619 | // The current app on the system partion is better than |
| 2620 | // what we have updated to on the data partition; switch |
| 2621 | // back to the system partition version. |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2622 | // At this point, its safely assumed that package installation for |
| 2623 | // apps in system partition will go through. If not there won't be a working |
| 2624 | // version of the app |
| 2625 | synchronized (mPackages) { |
| 2626 | // Just remove the loaded entries from package lists. |
| 2627 | mPackages.remove(ps.name); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 2628 | } |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2629 | Slog.w(TAG, "Package " + ps.name + " at " + scanFile |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2630 | + "reverting from " + ps.codePathString |
| 2631 | + ": new version " + pkg.mVersionCode |
| 2632 | + " better than installed " + ps.versionCode); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 2633 | InstallArgs args = new FileInstallArgs(ps.codePathString, |
| 2634 | ps.resourcePathString, ps.nativeLibraryPathString); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2635 | args.cleanUpResourcesLI(); |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2636 | mSettings.enableSystemPackageLP(ps.name); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 2637 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2638 | } |
| 2639 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2640 | if (updatedPkg != null) { |
| 2641 | // An updated system app will not have the PARSE_IS_SYSTEM flag set initially |
| 2642 | parseFlags |= PackageParser.PARSE_IS_SYSTEM; |
| 2643 | } |
| 2644 | // Verify certificates against what was last scanned |
| 2645 | if (!collectCertificatesLI(pp, ps, pkg, scanFile, parseFlags)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2646 | Slog.w(TAG, "Failed verifying certificates for package:" + pkg.packageName); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2647 | return null; |
| 2648 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2649 | // The apk is forward locked (not public) if its code and resources |
| 2650 | // are kept in different files. |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2651 | // TODO grab this value from PackageSettings |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | if (ps != null && !ps.codePath.equals(ps.resourcePath)) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2653 | parseFlags |= PackageParser.PARSE_FORWARD_LOCK; |
| Suchi Amalapurapu | f2c1072 | 2009-07-29 17:19:39 -0700 | [diff] [blame] | 2654 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2655 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2656 | String codePath = null; |
| 2657 | String resPath = null; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2658 | if ((parseFlags & PackageParser.PARSE_FORWARD_LOCK) != 0) { |
| 2659 | if (ps != null && ps.resourcePathString != null) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2660 | resPath = ps.resourcePathString; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2661 | } else { |
| 2662 | // Should not happen at all. Just log an error. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2663 | Slog.e(TAG, "Resource path not set for pkg : " + pkg.packageName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2664 | } |
| 2665 | } else { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2666 | resPath = pkg.mScanPath; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2667 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2668 | codePath = pkg.mScanPath; |
| 2669 | // Set application objects path explicitly. |
| 2670 | setApplicationInfoPaths(pkg, codePath, resPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2671 | // 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] | 2672 | return scanPackageLI(pkg, parseFlags, scanMode | SCAN_UPDATE_SIGNATURE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2673 | } |
| 2674 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 2675 | private static void setApplicationInfoPaths(PackageParser.Package pkg, String destCodePath, |
| 2676 | String destResPath) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2677 | pkg.mPath = pkg.mScanPath = destCodePath; |
| 2678 | pkg.applicationInfo.sourceDir = destCodePath; |
| 2679 | pkg.applicationInfo.publicSourceDir = destResPath; |
| 2680 | } |
| 2681 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2682 | private static String fixProcessName(String defProcessName, |
| 2683 | String processName, int uid) { |
| 2684 | if (processName == null) { |
| 2685 | return defProcessName; |
| 2686 | } |
| 2687 | return processName; |
| 2688 | } |
| 2689 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2690 | private boolean verifySignaturesLP(PackageSetting pkgSetting, |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 2691 | PackageParser.Package pkg) { |
| 2692 | if (pkgSetting.signatures.mSignatures != null) { |
| 2693 | // Already existing package. Make sure signatures match |
| 2694 | if (checkSignaturesLP(pkgSetting.signatures.mSignatures, pkg.mSignatures) != |
| 2695 | PackageManager.SIGNATURE_MATCH) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2696 | Slog.e(TAG, "Package " + pkg.packageName |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 2697 | + " signatures do not match the previously installed version; ignoring!"); |
| 2698 | mLastScanError = PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2699 | return false; |
| 2700 | } |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 2701 | } |
| 2702 | // Check for shared user signatures |
| 2703 | if (pkgSetting.sharedUser != null && pkgSetting.sharedUser.signatures.mSignatures != null) { |
| 2704 | if (checkSignaturesLP(pkgSetting.sharedUser.signatures.mSignatures, |
| 2705 | pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) { |
| 2706 | Slog.e(TAG, "Package " + pkg.packageName |
| 2707 | + " has no signatures that match those in shared user " |
| 2708 | + pkgSetting.sharedUser.name + "; ignoring!"); |
| 2709 | mLastScanError = PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE; |
| 2710 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2711 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2712 | } |
| 2713 | return true; |
| 2714 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2715 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2716 | public boolean performDexOpt(String packageName) { |
| 2717 | if (!mNoDexOpt) { |
| 2718 | return false; |
| 2719 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2720 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2721 | PackageParser.Package p; |
| 2722 | synchronized (mPackages) { |
| 2723 | p = mPackages.get(packageName); |
| 2724 | if (p == null || p.mDidDexOpt) { |
| 2725 | return false; |
| 2726 | } |
| 2727 | } |
| 2728 | synchronized (mInstallLock) { |
| 2729 | return performDexOptLI(p, false) == DEX_OPT_PERFORMED; |
| 2730 | } |
| 2731 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2732 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2733 | static final int DEX_OPT_SKIPPED = 0; |
| 2734 | static final int DEX_OPT_PERFORMED = 1; |
| 2735 | static final int DEX_OPT_FAILED = -1; |
| 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 | private int performDexOptLI(PackageParser.Package pkg, boolean forceDex) { |
| 2738 | boolean performed = false; |
| Marco Nelissen | d595c79 | 2009-07-02 15:23:26 -0700 | [diff] [blame] | 2739 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0 && mInstaller != null) { |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2740 | String path = pkg.mScanPath; |
| 2741 | int ret = 0; |
| 2742 | try { |
| 2743 | if (forceDex || dalvik.system.DexFile.isDexOptNeeded(path)) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2744 | ret = mInstaller.dexopt(path, pkg.applicationInfo.uid, |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2745 | !isForwardLocked(pkg)); |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2746 | pkg.mDidDexOpt = true; |
| 2747 | performed = true; |
| 2748 | } |
| 2749 | } catch (FileNotFoundException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2750 | Slog.w(TAG, "Apk not found for dexopt: " + path); |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2751 | ret = -1; |
| 2752 | } catch (IOException e) { |
| Suchi Amalapurapu | 73dafa1 | 2010-04-01 16:31:31 -0700 | [diff] [blame] | 2753 | Slog.w(TAG, "IOException reading apk: " + path, e); |
| 2754 | ret = -1; |
| 2755 | } catch (dalvik.system.StaleDexCacheError e) { |
| 2756 | Slog.w(TAG, "StaleDexCacheError when reading apk: " + path, e); |
| 2757 | ret = -1; |
| 2758 | } catch (Exception e) { |
| 2759 | Slog.w(TAG, "Exception when doing dexopt : ", e); |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2760 | ret = -1; |
| 2761 | } |
| 2762 | if (ret < 0) { |
| 2763 | //error from installer |
| 2764 | return DEX_OPT_FAILED; |
| 2765 | } |
| 2766 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2767 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2768 | return performed ? DEX_OPT_PERFORMED : DEX_OPT_SKIPPED; |
| 2769 | } |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 2770 | |
| 2771 | private static boolean useEncryptedFilesystemForPackage(PackageParser.Package pkg) { |
| 2772 | return Environment.isEncryptedFilesystemEnabled() && |
| 2773 | ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_NEVER_ENCRYPT) == 0); |
| 2774 | } |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2775 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2776 | private boolean verifyPackageUpdate(PackageSetting oldPkg, PackageParser.Package newPkg) { |
| 2777 | if ((oldPkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2778 | Slog.w(TAG, "Unable to update from " + oldPkg.name |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2779 | + " to " + newPkg.packageName |
| 2780 | + ": old package not in system partition"); |
| 2781 | return false; |
| 2782 | } else if (mPackages.get(oldPkg.name) != null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2783 | Slog.w(TAG, "Unable to update from " + oldPkg.name |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2784 | + " to " + newPkg.packageName |
| 2785 | + ": old package still exists"); |
| 2786 | return false; |
| 2787 | } |
| 2788 | return true; |
| 2789 | } |
| Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 2790 | |
| 2791 | private File getDataPathForPackage(PackageParser.Package pkg) { |
| 2792 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(pkg); |
| 2793 | File dataPath; |
| 2794 | if (useEncryptedFSDir) { |
| 2795 | dataPath = new File(mSecureAppDataDir, pkg.packageName); |
| 2796 | } else { |
| 2797 | dataPath = new File(mAppDataDir, pkg.packageName); |
| 2798 | } |
| 2799 | return dataPath; |
| 2800 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2801 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2802 | private PackageParser.Package scanPackageLI(PackageParser.Package pkg, |
| 2803 | int parseFlags, int scanMode) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2804 | File scanFile = new File(pkg.mScanPath); |
| Suchi Amalapurapu | 7040ce7 | 2010-02-08 23:55:56 -0800 | [diff] [blame] | 2805 | if (scanFile == null || pkg.applicationInfo.sourceDir == null || |
| 2806 | pkg.applicationInfo.publicSourceDir == null) { |
| Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2807 | // Bail out. The resource and code paths haven't been set. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2808 | Slog.w(TAG, " Code and resource paths haven't been set correctly"); |
| Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2809 | mLastScanError = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 2810 | return null; |
| 2811 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2812 | mScanningPath = scanFile; |
| 2813 | if (pkg == null) { |
| 2814 | mLastScanError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 2815 | return null; |
| 2816 | } |
| 2817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2818 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| 2819 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM; |
| 2820 | } |
| 2821 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2822 | if (pkg.packageName.equals("android")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | synchronized (mPackages) { |
| 2824 | if (mAndroidApplication != null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2825 | Slog.w(TAG, "*************************************************"); |
| 2826 | Slog.w(TAG, "Core android package being redefined. Skipping."); |
| 2827 | Slog.w(TAG, " file=" + mScanningPath); |
| 2828 | Slog.w(TAG, "*************************************************"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2829 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2830 | return null; |
| 2831 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2832 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | // Set up information for our fall-back user intent resolution |
| 2834 | // activity. |
| 2835 | mPlatformPackage = pkg; |
| 2836 | pkg.mVersionCode = mSdkVersion; |
| 2837 | mAndroidApplication = pkg.applicationInfo; |
| 2838 | mResolveActivity.applicationInfo = mAndroidApplication; |
| 2839 | mResolveActivity.name = ResolverActivity.class.getName(); |
| 2840 | mResolveActivity.packageName = mAndroidApplication.packageName; |
| 2841 | mResolveActivity.processName = mAndroidApplication.processName; |
| 2842 | mResolveActivity.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 2843 | mResolveActivity.flags = ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 2844 | mResolveActivity.theme = com.android.internal.R.style.Theme_Dialog_Alert; |
| 2845 | mResolveActivity.exported = true; |
| 2846 | mResolveActivity.enabled = true; |
| 2847 | mResolveInfo.activityInfo = mResolveActivity; |
| 2848 | mResolveInfo.priority = 0; |
| 2849 | mResolveInfo.preferredOrder = 0; |
| 2850 | mResolveInfo.match = 0; |
| 2851 | mResolveComponentName = new ComponentName( |
| 2852 | mAndroidApplication.packageName, mResolveActivity.name); |
| 2853 | } |
| 2854 | } |
| 2855 | |
| 2856 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) Log.d( |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2857 | TAG, "Scanning package " + pkg.packageName); |
| 2858 | if (mPackages.containsKey(pkg.packageName) |
| 2859 | || mSharedLibraries.containsKey(pkg.packageName)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2860 | Slog.w(TAG, "*************************************************"); |
| 2861 | Slog.w(TAG, "Application package " + pkg.packageName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2862 | + " already installed. Skipping duplicate."); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2863 | Slog.w(TAG, "*************************************************"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2864 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2865 | return null; |
| 2866 | } |
| 2867 | |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2868 | // Initialize package source and resource directories |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2869 | File destCodeFile = new File(pkg.applicationInfo.sourceDir); |
| 2870 | File destResourceFile = new File(pkg.applicationInfo.publicSourceDir); |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2871 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2872 | SharedUserSetting suid = null; |
| 2873 | PackageSetting pkgSetting = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2874 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2875 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 2876 | // Only system apps can use these features. |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2877 | pkg.mOriginalPackages = null; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2878 | pkg.mRealPackage = null; |
| 2879 | pkg.mAdoptPermissions = null; |
| 2880 | } |
| 2881 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2882 | synchronized (mPackages) { |
| 2883 | // Check all shared libraries and map to their actual file path. |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2884 | if (pkg.usesLibraries != null || pkg.usesOptionalLibraries != null) { |
| 2885 | if (mTmpSharedLibraries == null || |
| 2886 | mTmpSharedLibraries.length < mSharedLibraries.size()) { |
| 2887 | mTmpSharedLibraries = new String[mSharedLibraries.size()]; |
| 2888 | } |
| 2889 | int num = 0; |
| 2890 | int N = pkg.usesLibraries != null ? pkg.usesLibraries.size() : 0; |
| 2891 | for (int i=0; i<N; i++) { |
| 2892 | String file = mSharedLibraries.get(pkg.usesLibraries.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | if (file == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2894 | Slog.e(TAG, "Package " + pkg.packageName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2895 | + " requires unavailable shared library " |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2896 | + pkg.usesLibraries.get(i) + "; failing!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2897 | mLastScanError = PackageManager.INSTALL_FAILED_MISSING_SHARED_LIBRARY; |
| 2898 | return null; |
| 2899 | } |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2900 | mTmpSharedLibraries[num] = file; |
| 2901 | num++; |
| 2902 | } |
| 2903 | N = pkg.usesOptionalLibraries != null ? pkg.usesOptionalLibraries.size() : 0; |
| 2904 | for (int i=0; i<N; i++) { |
| 2905 | String file = mSharedLibraries.get(pkg.usesOptionalLibraries.get(i)); |
| 2906 | if (file == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2907 | Slog.w(TAG, "Package " + pkg.packageName |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2908 | + " desires unavailable shared library " |
| 2909 | + pkg.usesOptionalLibraries.get(i) + "; ignoring!"); |
| 2910 | } else { |
| 2911 | mTmpSharedLibraries[num] = file; |
| 2912 | num++; |
| 2913 | } |
| 2914 | } |
| 2915 | if (num > 0) { |
| 2916 | pkg.usesLibraryFiles = new String[num]; |
| 2917 | System.arraycopy(mTmpSharedLibraries, 0, |
| 2918 | pkg.usesLibraryFiles, 0, num); |
| 2919 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2920 | |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2921 | if (pkg.reqFeatures != null) { |
| 2922 | N = pkg.reqFeatures.size(); |
| 2923 | for (int i=0; i<N; i++) { |
| 2924 | FeatureInfo fi = pkg.reqFeatures.get(i); |
| 2925 | if ((fi.flags&FeatureInfo.FLAG_REQUIRED) == 0) { |
| 2926 | // Don't care. |
| 2927 | continue; |
| 2928 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2929 | |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2930 | if (fi.name != null) { |
| 2931 | if (mAvailableFeatures.get(fi.name) == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2932 | Slog.e(TAG, "Package " + pkg.packageName |
| Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2933 | + " requires unavailable feature " |
| 2934 | + fi.name + "; failing!"); |
| 2935 | mLastScanError = PackageManager.INSTALL_FAILED_MISSING_FEATURE; |
| 2936 | return null; |
| 2937 | } |
| 2938 | } |
| 2939 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2940 | } |
| 2941 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2943 | if (pkg.mSharedUserId != null) { |
| 2944 | suid = mSettings.getSharedUserLP(pkg.mSharedUserId, |
| 2945 | pkg.applicationInfo.flags, true); |
| 2946 | if (suid == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2947 | Slog.w(TAG, "Creating application package " + pkg.packageName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2948 | + " for shared user failed"); |
| 2949 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 2950 | return null; |
| 2951 | } |
| 2952 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) { |
| 2953 | Log.d(TAG, "Shared UserID " + pkg.mSharedUserId + " (uid=" |
| 2954 | + suid.userId + "): packages=" + suid.packages); |
| 2955 | } |
| 2956 | } |
| Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 2957 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2958 | if (false) { |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2959 | if (pkg.mOriginalPackages != null) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2960 | Log.w(TAG, "WAITING FOR DEBUGGER"); |
| 2961 | Debug.waitForDebugger(); |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2962 | Log.i(TAG, "Package " + pkg.packageName + " from original packages" |
| 2963 | + pkg.mOriginalPackages); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2964 | } |
| 2965 | } |
| 2966 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2967 | // Check if we are renaming from an original package name. |
| 2968 | PackageSetting origPackage = null; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2969 | String realName = null; |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2970 | if (pkg.mOriginalPackages != null) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2971 | // This package may need to be renamed to a previously |
| 2972 | // installed name. Let's check on that... |
| 2973 | String renamed = mSettings.mRenamedPackages.get(pkg.mRealPackage); |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2974 | if (pkg.mOriginalPackages.contains(renamed)) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2975 | // This package had originally been installed as the |
| 2976 | // original name, and we have already taken care of |
| 2977 | // transitioning to the new one. Just update the new |
| 2978 | // one to continue using the old name. |
| 2979 | realName = pkg.mRealPackage; |
| 2980 | if (!pkg.packageName.equals(renamed)) { |
| 2981 | // Callers into this function may have already taken |
| 2982 | // care of renaming the package; only do it here if |
| 2983 | // it is not already done. |
| 2984 | pkg.setPackageName(renamed); |
| 2985 | } |
| 2986 | |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2987 | } else { |
| 2988 | for (int i=pkg.mOriginalPackages.size()-1; i>=0; i--) { |
| 2989 | if ((origPackage=mSettings.peekPackageLP( |
| 2990 | pkg.mOriginalPackages.get(i))) != null) { |
| 2991 | // We do have the package already installed under its |
| 2992 | // original name... should we use it? |
| 2993 | if (!verifyPackageUpdate(origPackage, pkg)) { |
| 2994 | // New package is not compatible with original. |
| 2995 | origPackage = null; |
| 2996 | continue; |
| 2997 | } else if (origPackage.sharedUser != null) { |
| 2998 | // Make sure uid is compatible between packages. |
| 2999 | if (!origPackage.sharedUser.name.equals(pkg.mSharedUserId)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3000 | Slog.w(TAG, "Unable to migrate data from " + origPackage.name |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 3001 | + " to " + pkg.packageName + ": old uid " |
| 3002 | + origPackage.sharedUser.name |
| 3003 | + " differs from " + pkg.mSharedUserId); |
| 3004 | origPackage = null; |
| 3005 | continue; |
| 3006 | } |
| 3007 | } else { |
| 3008 | if (DEBUG_UPGRADE) Log.v(TAG, "Renaming new package " |
| 3009 | + pkg.packageName + " to old name " + origPackage.name); |
| 3010 | } |
| 3011 | break; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3012 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3013 | } |
| 3014 | } |
| 3015 | } |
| 3016 | |
| 3017 | if (mTransferedPackages.contains(pkg.packageName)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3018 | Slog.w(TAG, "Package " + pkg.packageName |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3019 | + " was transferred to another, but its .apk remains"); |
| 3020 | } |
| 3021 | |
| Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 3022 | // Just create the setting, don't add it yet. For already existing packages |
| 3023 | // the PkgSetting exists already and doesn't have to be created. |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3024 | pkgSetting = mSettings.getPackageLP(pkg, origPackage, realName, suid, destCodeFile, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3025 | destResourceFile, pkg.applicationInfo.flags, true, false); |
| 3026 | if (pkgSetting == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3027 | Slog.w(TAG, "Creating application package " + pkg.packageName + " failed"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3028 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3029 | return null; |
| 3030 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3031 | |
| 3032 | if (pkgSetting.origPackage != null) { |
| 3033 | // If we are first transitioning from an original package, |
| 3034 | // fix up the new package's name now. We need to do this after |
| 3035 | // looking up the package under its new name, so getPackageLP |
| 3036 | // can take care of fiddling things correctly. |
| 3037 | pkg.setPackageName(origPackage.name); |
| 3038 | |
| 3039 | // File a report about this. |
| 3040 | String msg = "New package " + pkgSetting.realName |
| 3041 | + " renamed to replace old package " + pkgSetting.name; |
| 3042 | reportSettingsProblem(Log.WARN, msg); |
| 3043 | |
| 3044 | // Make a note of it. |
| 3045 | mTransferedPackages.add(origPackage.name); |
| 3046 | |
| 3047 | // No longer need to retain this. |
| 3048 | pkgSetting.origPackage = null; |
| 3049 | } |
| 3050 | |
| 3051 | if (realName != null) { |
| 3052 | // Make a note of it. |
| 3053 | mTransferedPackages.add(pkg.packageName); |
| 3054 | } |
| 3055 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3056 | if (mSettings.mDisabledSysPackages.get(pkg.packageName) != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 3058 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3059 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3060 | pkg.applicationInfo.uid = pkgSetting.userId; |
| 3061 | pkg.mExtras = pkgSetting; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3062 | |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 3063 | if (!verifySignaturesLP(pkgSetting, pkg)) { |
| Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 3064 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM_DIR) == 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | return null; |
| 3066 | } |
| 3067 | // The signature has changed, but this package is in the system |
| 3068 | // image... let's recover! |
| Suchi Amalapurapu | c4dd60f | 2009-03-24 21:10:53 -0700 | [diff] [blame] | 3069 | pkgSetting.signatures.mSignatures = pkg.mSignatures; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3070 | // However... if this package is part of a shared user, but it |
| 3071 | // doesn't match the signature of the shared user, let's fail. |
| 3072 | // What this means is that you can't change the signatures |
| 3073 | // associated with an overall shared user, which doesn't seem all |
| 3074 | // that unreasonable. |
| 3075 | if (pkgSetting.sharedUser != null) { |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 3076 | if (checkSignaturesLP(pkgSetting.sharedUser.signatures.mSignatures, |
| 3077 | pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) { |
| 3078 | 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] | 3079 | mLastScanError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 3080 | return null; |
| 3081 | } |
| 3082 | } |
| Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 3083 | // File a report about this. |
| 3084 | String msg = "System package " + pkg.packageName |
| 3085 | + " signature changed; retaining data."; |
| 3086 | reportSettingsProblem(Log.WARN, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3088 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3089 | // Verify that this new package doesn't have any content providers |
| 3090 | // that conflict with existing packages. Only do this if the |
| 3091 | // package isn't already installed, since we don't want to break |
| 3092 | // things that are installed. |
| 3093 | if ((scanMode&SCAN_NEW_INSTALL) != 0) { |
| 3094 | int N = pkg.providers.size(); |
| 3095 | int i; |
| 3096 | for (i=0; i<N; i++) { |
| 3097 | PackageParser.Provider p = pkg.providers.get(i); |
| Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3098 | if (p.info.authority != null) { |
| 3099 | String names[] = p.info.authority.split(";"); |
| 3100 | for (int j = 0; j < names.length; j++) { |
| 3101 | if (mProviders.containsKey(names[j])) { |
| 3102 | PackageParser.Provider other = mProviders.get(names[j]); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3103 | Slog.w(TAG, "Can't install because provider name " + names[j] + |
| Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3104 | " (in package " + pkg.applicationInfo.packageName + |
| 3105 | ") is already used by " |
| 3106 | + ((other != null && other.getComponentName() != null) |
| 3107 | ? other.getComponentName().getPackageName() : "?")); |
| 3108 | mLastScanError = PackageManager.INSTALL_FAILED_CONFLICTING_PROVIDER; |
| 3109 | return null; |
| 3110 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3111 | } |
| 3112 | } |
| 3113 | } |
| 3114 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3115 | } |
| 3116 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3117 | final String pkgName = pkg.packageName; |
| 3118 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3119 | if (pkg.mAdoptPermissions != null) { |
| 3120 | // This package wants to adopt ownership of permissions from |
| 3121 | // another package. |
| 3122 | for (int i=pkg.mAdoptPermissions.size()-1; i>=0; i--) { |
| 3123 | String origName = pkg.mAdoptPermissions.get(i); |
| 3124 | PackageSetting orig = mSettings.peekPackageLP(origName); |
| 3125 | if (orig != null) { |
| 3126 | if (verifyPackageUpdate(orig, pkg)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3127 | Slog.i(TAG, "Adopting permissions from " |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3128 | + origName + " to " + pkg.packageName); |
| 3129 | mSettings.transferPermissions(origName, pkg.packageName); |
| 3130 | } |
| 3131 | } |
| 3132 | } |
| 3133 | } |
| 3134 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | long scanFileTime = scanFile.lastModified(); |
| 3136 | final boolean forceDex = (scanMode&SCAN_FORCE_DEX) != 0; |
| 3137 | final boolean scanFileNewer = forceDex || scanFileTime != pkgSetting.getTimeStamp(); |
| 3138 | pkg.applicationInfo.processName = fixProcessName( |
| 3139 | pkg.applicationInfo.packageName, |
| 3140 | pkg.applicationInfo.processName, |
| 3141 | pkg.applicationInfo.uid); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | |
| 3143 | File dataPath; |
| 3144 | if (mPlatformPackage == pkg) { |
| 3145 | // The system package is special. |
| 3146 | dataPath = new File (Environment.getDataDirectory(), "system"); |
| 3147 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3148 | } else { |
| 3149 | // This is a normal package, need to make its data directory. |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3150 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(pkg); |
| Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 3151 | dataPath = getDataPathForPackage(pkg); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3152 | |
| 3153 | boolean uidError = false; |
| 3154 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3155 | if (dataPath.exists()) { |
| 3156 | mOutPermissions[1] = 0; |
| 3157 | FileUtils.getPermissions(dataPath.getPath(), mOutPermissions); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3158 | |
| 3159 | // If we have mismatched owners for the data path, we have a |
| 3160 | // problem (unless we're running in the simulator.) |
| 3161 | if (mOutPermissions[1] != pkg.applicationInfo.uid && Process.supportsProcesses()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | boolean recovered = false; |
| 3163 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| 3164 | // If this is a system app, we can at least delete its |
| 3165 | // current data so the application will still work. |
| 3166 | if (mInstaller != null) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3167 | int ret = mInstaller.remove(pkgName, useEncryptedFSDir); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3168 | if (ret >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3169 | // Old data gone! |
| 3170 | String msg = "System package " + pkg.packageName |
| 3171 | + " has changed from uid: " |
| 3172 | + mOutPermissions[1] + " to " |
| 3173 | + pkg.applicationInfo.uid + "; old data erased"; |
| 3174 | reportSettingsProblem(Log.WARN, msg); |
| 3175 | recovered = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3176 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3177 | // And now re-install the app. |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3178 | ret = mInstaller.install(pkgName, useEncryptedFSDir, pkg.applicationInfo.uid, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3179 | pkg.applicationInfo.uid); |
| 3180 | if (ret == -1) { |
| 3181 | // Ack should not happen! |
| 3182 | msg = "System package " + pkg.packageName |
| 3183 | + " could not have data directory re-created after delete."; |
| 3184 | reportSettingsProblem(Log.WARN, msg); |
| 3185 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3186 | return null; |
| 3187 | } |
| 3188 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3189 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3190 | if (!recovered) { |
| 3191 | mHasSystemUidErrors = true; |
| 3192 | } |
| 3193 | } |
| 3194 | if (!recovered) { |
| 3195 | pkg.applicationInfo.dataDir = "/mismatched_uid/settings_" |
| 3196 | + pkg.applicationInfo.uid + "/fs_" |
| 3197 | + mOutPermissions[1]; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3198 | pkg.applicationInfo.nativeLibraryDir = pkg.applicationInfo.dataDir; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | String msg = "Package " + pkg.packageName |
| 3200 | + " has mismatched uid: " |
| 3201 | + mOutPermissions[1] + " on disk, " |
| 3202 | + pkg.applicationInfo.uid + " in settings"; |
| 3203 | synchronized (mPackages) { |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3204 | mSettings.mReadMessages.append(msg); |
| 3205 | mSettings.mReadMessages.append('\n'); |
| 3206 | uidError = true; |
| 3207 | if (!pkgSetting.uidError) { |
| 3208 | reportSettingsProblem(Log.ERROR, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3209 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | } |
| 3213 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3214 | } else { |
| 3215 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGV) |
| 3216 | Log.v(TAG, "Want this data dir: " + dataPath); |
| 3217 | //invoke installer to do the actual installation |
| 3218 | if (mInstaller != null) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3219 | int ret = mInstaller.install(pkgName, useEncryptedFSDir, pkg.applicationInfo.uid, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3220 | pkg.applicationInfo.uid); |
| 3221 | if(ret < 0) { |
| 3222 | // Error from installer |
| 3223 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3224 | return null; |
| 3225 | } |
| 3226 | } else { |
| 3227 | dataPath.mkdirs(); |
| 3228 | if (dataPath.exists()) { |
| 3229 | FileUtils.setPermissions( |
| 3230 | dataPath.toString(), |
| 3231 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 3232 | pkg.applicationInfo.uid, pkg.applicationInfo.uid); |
| 3233 | } |
| 3234 | } |
| 3235 | if (dataPath.exists()) { |
| 3236 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3237 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3238 | Slog.w(TAG, "Unable to create data directory: " + dataPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | pkg.applicationInfo.dataDir = null; |
| 3240 | } |
| 3241 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3242 | |
| 3243 | /* |
| 3244 | * Set the data dir to the default "/data/data/<package name>/lib" |
| 3245 | * if we got here without anyone telling us different (e.g., apps |
| 3246 | * stored on SD card have their native libraries stored in the ASEC |
| 3247 | * container with the APK). |
| 3248 | */ |
| 3249 | if (pkg.applicationInfo.nativeLibraryDir == null && pkg.applicationInfo.dataDir != null) { |
| 3250 | pkg.applicationInfo.nativeLibraryDir = new File(dataPath, LIB_DIR_NAME).getPath(); |
| 3251 | } |
| 3252 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3253 | pkgSetting.uidError = uidError; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | } |
| 3255 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3256 | // 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] | 3257 | if (mInstaller != null) { |
| 3258 | String path = scanFile.getPath(); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3259 | /* Note: We don't want to unpack the native binaries for |
| 3260 | * system applications, unless they have been updated |
| 3261 | * (the binaries are already under /system/lib). |
| 3262 | * Also, don't unpack libs for apps on the external card |
| 3263 | * since they should have their libraries in the ASEC |
| 3264 | * container already. |
| 3265 | * |
| 3266 | * In other words, we're going to unpack the binaries |
| 3267 | * only for non-system apps and system app upgrades. |
| 3268 | */ |
| 3269 | if ((!isSystemApp(pkg) || isUpdatedSystemApp(pkg)) && !isExternal(pkg)) { |
| 3270 | Log.i(TAG, path + " changed; unpacking"); |
| 3271 | File sharedLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir); |
| 3272 | sharedLibraryDir.mkdir(); |
| 3273 | NativeLibraryHelper.copyNativeBinariesLI(scanFile, sharedLibraryDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3274 | } |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 3275 | pkg.mScanPath = path; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3276 | |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 3277 | if ((scanMode&SCAN_NO_DEX) == 0) { |
| 3278 | if (performDexOptLI(pkg, forceDex) == DEX_OPT_FAILED) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3279 | mLastScanError = PackageManager.INSTALL_FAILED_DEXOPT; |
| 3280 | return null; |
| 3281 | } |
| 3282 | } |
| 3283 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3285 | if (mFactoryTest && pkg.requestedPermissions.contains( |
| 3286 | android.Manifest.permission.FACTORY_TEST)) { |
| 3287 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FACTORY_TEST; |
| 3288 | } |
| 3289 | |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3290 | // Request the ActivityManager to kill the process(only for existing packages) |
| 3291 | // so that we do not end up in a confused state while the user is still using the older |
| 3292 | // version of the application while the new one gets installed. |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3293 | if ((parseFlags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3294 | killApplication(pkg.applicationInfo.packageName, |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3295 | pkg.applicationInfo.uid); |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3296 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3297 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | synchronized (mPackages) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 3299 | // We don't expect installation to fail beyond this point, |
| 3300 | if ((scanMode&SCAN_MONITOR) != 0) { |
| 3301 | mAppDirs.put(pkg.mPath, pkg); |
| 3302 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3303 | // Add the new setting to mSettings |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 3304 | mSettings.insertPackageSettingLP(pkgSetting, pkg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | // Add the new setting to mPackages |
| Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 3306 | mPackages.put(pkg.applicationInfo.packageName, pkg); |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 3307 | // Make sure we don't accidentally delete its data. |
| 3308 | mSettings.mPackagesToBeCleaned.remove(pkgName); |
| 3309 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3310 | int N = pkg.providers.size(); |
| 3311 | StringBuilder r = null; |
| 3312 | int i; |
| 3313 | for (i=0; i<N; i++) { |
| 3314 | PackageParser.Provider p = pkg.providers.get(i); |
| 3315 | p.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3316 | p.info.processName, pkg.applicationInfo.uid); |
| 3317 | mProvidersByComponent.put(new ComponentName(p.info.packageName, |
| 3318 | p.info.name), p); |
| 3319 | p.syncable = p.info.isSyncable; |
| Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3320 | if (p.info.authority != null) { |
| 3321 | String names[] = p.info.authority.split(";"); |
| 3322 | p.info.authority = null; |
| 3323 | for (int j = 0; j < names.length; j++) { |
| 3324 | if (j == 1 && p.syncable) { |
| 3325 | // We only want the first authority for a provider to possibly be |
| 3326 | // syncable, so if we already added this provider using a different |
| 3327 | // authority clear the syncable flag. We copy the provider before |
| 3328 | // changing it because the mProviders object contains a reference |
| 3329 | // to a provider that we don't want to change. |
| 3330 | // Only do this for the second authority since the resulting provider |
| 3331 | // object can be the same for all future authorities for this provider. |
| 3332 | p = new PackageParser.Provider(p); |
| 3333 | p.syncable = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3334 | } |
| Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3335 | if (!mProviders.containsKey(names[j])) { |
| 3336 | mProviders.put(names[j], p); |
| 3337 | if (p.info.authority == null) { |
| 3338 | p.info.authority = names[j]; |
| 3339 | } else { |
| 3340 | p.info.authority = p.info.authority + ";" + names[j]; |
| 3341 | } |
| 3342 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) |
| 3343 | Log.d(TAG, "Registered content provider: " + names[j] + |
| 3344 | ", className = " + p.info.name + |
| 3345 | ", isSyncable = " + p.info.isSyncable); |
| 3346 | } else { |
| 3347 | PackageParser.Provider other = mProviders.get(names[j]); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3348 | Slog.w(TAG, "Skipping provider name " + names[j] + |
| Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3349 | " (in package " + pkg.applicationInfo.packageName + |
| 3350 | "): name already used by " |
| 3351 | + ((other != null && other.getComponentName() != null) |
| 3352 | ? other.getComponentName().getPackageName() : "?")); |
| 3353 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3354 | } |
| 3355 | } |
| 3356 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3357 | if (r == null) { |
| 3358 | r = new StringBuilder(256); |
| 3359 | } else { |
| 3360 | r.append(' '); |
| 3361 | } |
| 3362 | r.append(p.info.name); |
| 3363 | } |
| 3364 | } |
| 3365 | if (r != null) { |
| 3366 | if (Config.LOGD) Log.d(TAG, " Providers: " + r); |
| 3367 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3368 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | N = pkg.services.size(); |
| 3370 | r = null; |
| 3371 | for (i=0; i<N; i++) { |
| 3372 | PackageParser.Service s = pkg.services.get(i); |
| 3373 | s.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3374 | s.info.processName, pkg.applicationInfo.uid); |
| 3375 | mServices.addService(s); |
| 3376 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3377 | if (r == null) { |
| 3378 | r = new StringBuilder(256); |
| 3379 | } else { |
| 3380 | r.append(' '); |
| 3381 | } |
| 3382 | r.append(s.info.name); |
| 3383 | } |
| 3384 | } |
| 3385 | if (r != null) { |
| 3386 | if (Config.LOGD) Log.d(TAG, " Services: " + r); |
| 3387 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3388 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3389 | N = pkg.receivers.size(); |
| 3390 | r = null; |
| 3391 | for (i=0; i<N; i++) { |
| 3392 | PackageParser.Activity a = pkg.receivers.get(i); |
| 3393 | a.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3394 | a.info.processName, pkg.applicationInfo.uid); |
| 3395 | mReceivers.addActivity(a, "receiver"); |
| 3396 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3397 | if (r == null) { |
| 3398 | r = new StringBuilder(256); |
| 3399 | } else { |
| 3400 | r.append(' '); |
| 3401 | } |
| 3402 | r.append(a.info.name); |
| 3403 | } |
| 3404 | } |
| 3405 | if (r != null) { |
| 3406 | if (Config.LOGD) Log.d(TAG, " Receivers: " + r); |
| 3407 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3408 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | N = pkg.activities.size(); |
| 3410 | r = null; |
| 3411 | for (i=0; i<N; i++) { |
| 3412 | PackageParser.Activity a = pkg.activities.get(i); |
| 3413 | a.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3414 | a.info.processName, pkg.applicationInfo.uid); |
| 3415 | mActivities.addActivity(a, "activity"); |
| 3416 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3417 | if (r == null) { |
| 3418 | r = new StringBuilder(256); |
| 3419 | } else { |
| 3420 | r.append(' '); |
| 3421 | } |
| 3422 | r.append(a.info.name); |
| 3423 | } |
| 3424 | } |
| 3425 | if (r != null) { |
| 3426 | if (Config.LOGD) Log.d(TAG, " Activities: " + r); |
| 3427 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3428 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3429 | N = pkg.permissionGroups.size(); |
| 3430 | r = null; |
| 3431 | for (i=0; i<N; i++) { |
| 3432 | PackageParser.PermissionGroup pg = pkg.permissionGroups.get(i); |
| 3433 | PackageParser.PermissionGroup cur = mPermissionGroups.get(pg.info.name); |
| 3434 | if (cur == null) { |
| 3435 | mPermissionGroups.put(pg.info.name, pg); |
| 3436 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3437 | if (r == null) { |
| 3438 | r = new StringBuilder(256); |
| 3439 | } else { |
| 3440 | r.append(' '); |
| 3441 | } |
| 3442 | r.append(pg.info.name); |
| 3443 | } |
| 3444 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3445 | 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] | 3446 | + pg.info.packageName + " ignored: original from " |
| 3447 | + cur.info.packageName); |
| 3448 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3449 | if (r == null) { |
| 3450 | r = new StringBuilder(256); |
| 3451 | } else { |
| 3452 | r.append(' '); |
| 3453 | } |
| 3454 | r.append("DUP:"); |
| 3455 | r.append(pg.info.name); |
| 3456 | } |
| 3457 | } |
| 3458 | } |
| 3459 | if (r != null) { |
| 3460 | if (Config.LOGD) Log.d(TAG, " Permission Groups: " + r); |
| 3461 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3462 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3463 | N = pkg.permissions.size(); |
| 3464 | r = null; |
| 3465 | for (i=0; i<N; i++) { |
| 3466 | PackageParser.Permission p = pkg.permissions.get(i); |
| 3467 | HashMap<String, BasePermission> permissionMap = |
| 3468 | p.tree ? mSettings.mPermissionTrees |
| 3469 | : mSettings.mPermissions; |
| 3470 | p.group = mPermissionGroups.get(p.info.group); |
| 3471 | if (p.info.group == null || p.group != null) { |
| 3472 | BasePermission bp = permissionMap.get(p.info.name); |
| 3473 | if (bp == null) { |
| 3474 | bp = new BasePermission(p.info.name, p.info.packageName, |
| 3475 | BasePermission.TYPE_NORMAL); |
| 3476 | permissionMap.put(p.info.name, bp); |
| 3477 | } |
| 3478 | if (bp.perm == null) { |
| 3479 | if (bp.sourcePackage == null |
| 3480 | || bp.sourcePackage.equals(p.info.packageName)) { |
| 3481 | BasePermission tree = findPermissionTreeLP(p.info.name); |
| 3482 | if (tree == null |
| 3483 | || tree.sourcePackage.equals(p.info.packageName)) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3484 | bp.packageSetting = pkgSetting; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3485 | bp.perm = p; |
| 3486 | bp.uid = pkg.applicationInfo.uid; |
| 3487 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3488 | if (r == null) { |
| 3489 | r = new StringBuilder(256); |
| 3490 | } else { |
| 3491 | r.append(' '); |
| 3492 | } |
| 3493 | r.append(p.info.name); |
| 3494 | } |
| 3495 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3496 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3497 | + p.info.packageName + " ignored: base tree " |
| 3498 | + tree.name + " is from package " |
| 3499 | + tree.sourcePackage); |
| 3500 | } |
| 3501 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3502 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3503 | + p.info.packageName + " ignored: original from " |
| 3504 | + bp.sourcePackage); |
| 3505 | } |
| 3506 | } else if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3507 | if (r == null) { |
| 3508 | r = new StringBuilder(256); |
| 3509 | } else { |
| 3510 | r.append(' '); |
| 3511 | } |
| 3512 | r.append("DUP:"); |
| 3513 | r.append(p.info.name); |
| 3514 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3515 | if (bp.perm == p) { |
| 3516 | bp.protectionLevel = p.info.protectionLevel; |
| 3517 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3519 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | + p.info.packageName + " ignored: no group " |
| 3521 | + p.group); |
| 3522 | } |
| 3523 | } |
| 3524 | if (r != null) { |
| 3525 | if (Config.LOGD) Log.d(TAG, " Permissions: " + r); |
| 3526 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3527 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3528 | N = pkg.instrumentation.size(); |
| 3529 | r = null; |
| 3530 | for (i=0; i<N; i++) { |
| 3531 | PackageParser.Instrumentation a = pkg.instrumentation.get(i); |
| 3532 | a.info.packageName = pkg.applicationInfo.packageName; |
| 3533 | a.info.sourceDir = pkg.applicationInfo.sourceDir; |
| 3534 | a.info.publicSourceDir = pkg.applicationInfo.publicSourceDir; |
| 3535 | a.info.dataDir = pkg.applicationInfo.dataDir; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3536 | a.info.nativeLibraryDir = pkg.applicationInfo.nativeLibraryDir; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3537 | mInstrumentation.put(a.getComponentName(), a); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3539 | if (r == null) { |
| 3540 | r = new StringBuilder(256); |
| 3541 | } else { |
| 3542 | r.append(' '); |
| 3543 | } |
| 3544 | r.append(a.info.name); |
| 3545 | } |
| 3546 | } |
| 3547 | if (r != null) { |
| 3548 | if (Config.LOGD) Log.d(TAG, " Instrumentation: " + r); |
| 3549 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3550 | |
| Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 3551 | if (pkg.protectedBroadcasts != null) { |
| 3552 | N = pkg.protectedBroadcasts.size(); |
| 3553 | for (i=0; i<N; i++) { |
| 3554 | mProtectedBroadcasts.add(pkg.protectedBroadcasts.get(i)); |
| 3555 | } |
| 3556 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | pkgSetting.setTimeStamp(scanFileTime); |
| 3559 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3560 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3561 | return pkg; |
| 3562 | } |
| 3563 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3564 | private void killApplication(String pkgName, int uid) { |
| 3565 | // Request the ActivityManager to kill the process(only for existing packages) |
| 3566 | // so that we do not end up in a confused state while the user is still using the older |
| 3567 | // version of the application while the new one gets installed. |
| 3568 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 3569 | if (am != null) { |
| 3570 | try { |
| 3571 | am.killApplicationWithUid(pkgName, uid); |
| 3572 | } catch (RemoteException e) { |
| 3573 | } |
| 3574 | } |
| 3575 | } |
| 3576 | |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3577 | // Return the path of the directory that will contain the native binaries |
| 3578 | // of a given installed package. This is relative to the data path. |
| 3579 | // |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3580 | private File getNativeBinaryDirForPackage(PackageParser.Package pkg) { |
| 3581 | final String nativeLibraryDir = pkg.applicationInfo.nativeLibraryDir; |
| 3582 | if (nativeLibraryDir != null) { |
| 3583 | return new File(nativeLibraryDir); |
| 3584 | } else { |
| 3585 | // Fall back for old packages |
| 3586 | return new File(pkg.applicationInfo.dataDir, LIB_DIR_NAME); |
| 3587 | } |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3588 | } |
| 3589 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3590 | // Convenience call for removeNativeBinariesLI(File) |
| 3591 | private void removeNativeBinariesLI(PackageParser.Package pkg) { |
| 3592 | File nativeLibraryDir = getNativeBinaryDirForPackage(pkg); |
| 3593 | removeNativeBinariesLI(nativeLibraryDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3594 | } |
| 3595 | |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3596 | // Remove the native binaries of a given package. This simply |
| 3597 | // gets rid of the files in the 'lib' sub-directory. |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3598 | public void removeNativeBinariesLI(File binaryDir) { |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3599 | if (DEBUG_NATIVE) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3600 | Slog.w(TAG, "Deleting native binaries from: " + binaryDir.getPath()); |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | // Just remove any file in the directory. Since the directory |
| 3604 | // is owned by the 'system' UID, the application is not supposed |
| 3605 | // to have written anything there. |
| 3606 | // |
| 3607 | if (binaryDir.exists()) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3608 | File[] binaries = binaryDir.listFiles(); |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3609 | if (binaries != null) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3610 | for (int nn = 0; nn < binaries.length; nn++) { |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3611 | if (DEBUG_NATIVE) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3612 | Slog.d(TAG, " Deleting " + binaries[nn].getName()); |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3613 | } |
| 3614 | if (!binaries[nn].delete()) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3615 | Slog.w(TAG, "Could not delete native binary: " + binaries[nn].getPath()); |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3616 | } |
| 3617 | } |
| 3618 | } |
| 3619 | // Do not delete 'lib' directory itself, or this will prevent |
| 3620 | // installation of future updates. |
| 3621 | } |
| 3622 | } |
| 3623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3624 | void removePackageLI(PackageParser.Package pkg, boolean chatty) { |
| 3625 | if (chatty && Config.LOGD) Log.d( |
| 3626 | TAG, "Removing package " + pkg.applicationInfo.packageName ); |
| 3627 | |
| 3628 | synchronized (mPackages) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3629 | clearPackagePreferredActivitiesLP(pkg.packageName); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3630 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3631 | mPackages.remove(pkg.applicationInfo.packageName); |
| 3632 | if (pkg.mPath != null) { |
| 3633 | mAppDirs.remove(pkg.mPath); |
| 3634 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3635 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3636 | PackageSetting ps = (PackageSetting)pkg.mExtras; |
| 3637 | if (ps != null && ps.sharedUser != null) { |
| 3638 | // XXX don't do this until the data is removed. |
| 3639 | if (false) { |
| 3640 | ps.sharedUser.packages.remove(ps); |
| 3641 | if (ps.sharedUser.packages.size() == 0) { |
| 3642 | // Remove. |
| 3643 | } |
| 3644 | } |
| 3645 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3646 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | int N = pkg.providers.size(); |
| 3648 | StringBuilder r = null; |
| 3649 | int i; |
| 3650 | for (i=0; i<N; i++) { |
| 3651 | PackageParser.Provider p = pkg.providers.get(i); |
| 3652 | mProvidersByComponent.remove(new ComponentName(p.info.packageName, |
| 3653 | p.info.name)); |
| 3654 | if (p.info.authority == null) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3655 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3656 | /* The is another ContentProvider with this authority when |
| 3657 | * this app was installed so this authority is null, |
| 3658 | * Ignore it as we don't have to unregister the provider. |
| 3659 | */ |
| 3660 | continue; |
| 3661 | } |
| 3662 | String names[] = p.info.authority.split(";"); |
| 3663 | for (int j = 0; j < names.length; j++) { |
| 3664 | if (mProviders.get(names[j]) == p) { |
| 3665 | mProviders.remove(names[j]); |
| 3666 | if (chatty && Config.LOGD) Log.d( |
| 3667 | TAG, "Unregistered content provider: " + names[j] + |
| 3668 | ", className = " + p.info.name + |
| 3669 | ", isSyncable = " + p.info.isSyncable); |
| 3670 | } |
| 3671 | } |
| 3672 | if (chatty) { |
| 3673 | if (r == null) { |
| 3674 | r = new StringBuilder(256); |
| 3675 | } else { |
| 3676 | r.append(' '); |
| 3677 | } |
| 3678 | r.append(p.info.name); |
| 3679 | } |
| 3680 | } |
| 3681 | if (r != null) { |
| 3682 | if (Config.LOGD) Log.d(TAG, " Providers: " + r); |
| 3683 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3685 | N = pkg.services.size(); |
| 3686 | r = null; |
| 3687 | for (i=0; i<N; i++) { |
| 3688 | PackageParser.Service s = pkg.services.get(i); |
| 3689 | mServices.removeService(s); |
| 3690 | if (chatty) { |
| 3691 | if (r == null) { |
| 3692 | r = new StringBuilder(256); |
| 3693 | } else { |
| 3694 | r.append(' '); |
| 3695 | } |
| 3696 | r.append(s.info.name); |
| 3697 | } |
| 3698 | } |
| 3699 | if (r != null) { |
| 3700 | if (Config.LOGD) Log.d(TAG, " Services: " + r); |
| 3701 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3702 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3703 | N = pkg.receivers.size(); |
| 3704 | r = null; |
| 3705 | for (i=0; i<N; i++) { |
| 3706 | PackageParser.Activity a = pkg.receivers.get(i); |
| 3707 | mReceivers.removeActivity(a, "receiver"); |
| 3708 | if (chatty) { |
| 3709 | if (r == null) { |
| 3710 | r = new StringBuilder(256); |
| 3711 | } else { |
| 3712 | r.append(' '); |
| 3713 | } |
| 3714 | r.append(a.info.name); |
| 3715 | } |
| 3716 | } |
| 3717 | if (r != null) { |
| 3718 | if (Config.LOGD) Log.d(TAG, " Receivers: " + r); |
| 3719 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3720 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3721 | N = pkg.activities.size(); |
| 3722 | r = null; |
| 3723 | for (i=0; i<N; i++) { |
| 3724 | PackageParser.Activity a = pkg.activities.get(i); |
| 3725 | mActivities.removeActivity(a, "activity"); |
| 3726 | if (chatty) { |
| 3727 | if (r == null) { |
| 3728 | r = new StringBuilder(256); |
| 3729 | } else { |
| 3730 | r.append(' '); |
| 3731 | } |
| 3732 | r.append(a.info.name); |
| 3733 | } |
| 3734 | } |
| 3735 | if (r != null) { |
| 3736 | if (Config.LOGD) Log.d(TAG, " Activities: " + r); |
| 3737 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3738 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | N = pkg.permissions.size(); |
| 3740 | r = null; |
| 3741 | for (i=0; i<N; i++) { |
| 3742 | PackageParser.Permission p = pkg.permissions.get(i); |
| 3743 | boolean tree = false; |
| 3744 | BasePermission bp = mSettings.mPermissions.get(p.info.name); |
| 3745 | if (bp == null) { |
| 3746 | tree = true; |
| 3747 | bp = mSettings.mPermissionTrees.get(p.info.name); |
| 3748 | } |
| 3749 | if (bp != null && bp.perm == p) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3750 | bp.perm = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3751 | if (chatty) { |
| 3752 | if (r == null) { |
| 3753 | r = new StringBuilder(256); |
| 3754 | } else { |
| 3755 | r.append(' '); |
| 3756 | } |
| 3757 | r.append(p.info.name); |
| 3758 | } |
| 3759 | } |
| 3760 | } |
| 3761 | if (r != null) { |
| 3762 | if (Config.LOGD) Log.d(TAG, " Permissions: " + r); |
| 3763 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3764 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3765 | N = pkg.instrumentation.size(); |
| 3766 | r = null; |
| 3767 | for (i=0; i<N; i++) { |
| 3768 | PackageParser.Instrumentation a = pkg.instrumentation.get(i); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3769 | mInstrumentation.remove(a.getComponentName()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3770 | if (chatty) { |
| 3771 | if (r == null) { |
| 3772 | r = new StringBuilder(256); |
| 3773 | } else { |
| 3774 | r.append(' '); |
| 3775 | } |
| 3776 | r.append(a.info.name); |
| 3777 | } |
| 3778 | } |
| 3779 | if (r != null) { |
| 3780 | if (Config.LOGD) Log.d(TAG, " Instrumentation: " + r); |
| 3781 | } |
| 3782 | } |
| 3783 | } |
| 3784 | |
| 3785 | private static final boolean isPackageFilename(String name) { |
| 3786 | return name != null && name.endsWith(".apk"); |
| 3787 | } |
| 3788 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3789 | private static boolean hasPermission(PackageParser.Package pkgInfo, String perm) { |
| 3790 | for (int i=pkgInfo.permissions.size()-1; i>=0; i--) { |
| 3791 | if (pkgInfo.permissions.get(i).info.name.equals(perm)) { |
| 3792 | return true; |
| 3793 | } |
| 3794 | } |
| 3795 | return false; |
| 3796 | } |
| 3797 | |
| 3798 | private void updatePermissionsLP(String changingPkg, |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 3799 | PackageParser.Package pkgInfo, boolean grantPermissions, |
| 3800 | boolean replace, boolean replaceAll) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3801 | // Make sure there are no dangling permission trees. |
| 3802 | Iterator<BasePermission> it = mSettings.mPermissionTrees |
| 3803 | .values().iterator(); |
| 3804 | while (it.hasNext()) { |
| 3805 | BasePermission bp = it.next(); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3806 | if (bp.packageSetting == null) { |
| 3807 | // We may not yet have parsed the package, so just see if |
| 3808 | // we still know about its settings. |
| 3809 | bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage); |
| 3810 | } |
| 3811 | if (bp.packageSetting == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3812 | Slog.w(TAG, "Removing dangling permission tree: " + bp.name |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3813 | + " from package " + bp.sourcePackage); |
| 3814 | it.remove(); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3815 | } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) { |
| 3816 | if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) { |
| 3817 | Slog.i(TAG, "Removing old permission tree: " + bp.name |
| 3818 | + " from package " + bp.sourcePackage); |
| 3819 | grantPermissions = true; |
| 3820 | it.remove(); |
| 3821 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3822 | } |
| 3823 | } |
| 3824 | |
| 3825 | // Make sure all dynamic permissions have been assigned to a package, |
| 3826 | // and make sure there are no dangling permissions. |
| 3827 | it = mSettings.mPermissions.values().iterator(); |
| 3828 | while (it.hasNext()) { |
| 3829 | BasePermission bp = it.next(); |
| 3830 | if (bp.type == BasePermission.TYPE_DYNAMIC) { |
| 3831 | if (DEBUG_SETTINGS) Log.v(TAG, "Dynamic permission: name=" |
| 3832 | + bp.name + " pkg=" + bp.sourcePackage |
| 3833 | + " info=" + bp.pendingInfo); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3834 | if (bp.packageSetting == null && bp.pendingInfo != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3835 | BasePermission tree = findPermissionTreeLP(bp.name); |
| 3836 | if (tree != null) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3837 | bp.packageSetting = tree.packageSetting; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3838 | bp.perm = new PackageParser.Permission(tree.perm.owner, |
| 3839 | new PermissionInfo(bp.pendingInfo)); |
| 3840 | bp.perm.info.packageName = tree.perm.info.packageName; |
| 3841 | bp.perm.info.name = bp.name; |
| 3842 | bp.uid = tree.uid; |
| 3843 | } |
| 3844 | } |
| 3845 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3846 | if (bp.packageSetting == null) { |
| 3847 | // We may not yet have parsed the package, so just see if |
| 3848 | // we still know about its settings. |
| 3849 | bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage); |
| 3850 | } |
| 3851 | if (bp.packageSetting == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3852 | Slog.w(TAG, "Removing dangling permission: " + bp.name |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3853 | + " from package " + bp.sourcePackage); |
| 3854 | it.remove(); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3855 | } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) { |
| 3856 | if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) { |
| 3857 | Slog.i(TAG, "Removing old permission: " + bp.name |
| 3858 | + " from package " + bp.sourcePackage); |
| 3859 | grantPermissions = true; |
| 3860 | it.remove(); |
| 3861 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | } |
| 3863 | } |
| 3864 | |
| 3865 | // Now update the permissions for all packages, in particular |
| 3866 | // replace the granted permissions of the system packages. |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3867 | if (grantPermissions) { |
| 3868 | for (PackageParser.Package pkg : mPackages.values()) { |
| 3869 | if (pkg != pkgInfo) { |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 3870 | grantPermissionsLP(pkg, replaceAll); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3871 | } |
| 3872 | } |
| 3873 | } |
| 3874 | |
| 3875 | if (pkgInfo != null) { |
| 3876 | grantPermissionsLP(pkgInfo, replace); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | } |
| 3878 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3879 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | private void grantPermissionsLP(PackageParser.Package pkg, boolean replace) { |
| 3881 | final PackageSetting ps = (PackageSetting)pkg.mExtras; |
| 3882 | if (ps == null) { |
| 3883 | return; |
| 3884 | } |
| 3885 | final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3886 | boolean changedPermission = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3887 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3888 | if (replace) { |
| 3889 | ps.permissionsFixed = false; |
| 3890 | if (gp == ps) { |
| 3891 | gp.grantedPermissions.clear(); |
| 3892 | gp.gids = mGlobalGids; |
| 3893 | } |
| 3894 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3895 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3896 | if (gp.gids == null) { |
| 3897 | gp.gids = mGlobalGids; |
| 3898 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3899 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3900 | final int N = pkg.requestedPermissions.size(); |
| 3901 | for (int i=0; i<N; i++) { |
| 3902 | String name = pkg.requestedPermissions.get(i); |
| 3903 | BasePermission bp = mSettings.mPermissions.get(name); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3904 | if (false) { |
| 3905 | if (gp != ps) { |
| 3906 | Log.i(TAG, "Package " + pkg.packageName + " checking " + name |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3907 | + ": " + bp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3908 | } |
| 3909 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3910 | if (bp != null && bp.packageSetting != null) { |
| 3911 | final String perm = bp.name; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3912 | boolean allowed; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3913 | boolean allowedSig = false; |
| 3914 | if (bp.protectionLevel == PermissionInfo.PROTECTION_NORMAL |
| 3915 | || bp.protectionLevel == PermissionInfo.PROTECTION_DANGEROUS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3916 | allowed = true; |
| Dianne Hackborn | 6e52b5d | 2010-04-05 14:33:01 -0700 | [diff] [blame] | 3917 | } else if (bp.packageSetting == null) { |
| 3918 | // This permission is invalid; skip it. |
| 3919 | allowed = false; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3920 | } else if (bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE |
| 3921 | || bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM) { |
| 3922 | allowed = (checkSignaturesLP(bp.packageSetting.signatures.mSignatures, pkg.mSignatures) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3923 | == PackageManager.SIGNATURE_MATCH) |
| Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 3924 | || (checkSignaturesLP(mPlatformPackage.mSignatures, pkg.mSignatures) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3925 | == PackageManager.SIGNATURE_MATCH); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3926 | if (bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3927 | if (isSystemApp(pkg)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3928 | // For updated system applications, the signatureOrSystem permission |
| 3929 | // is granted only if it had been defined by the original application. |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 3930 | if (isUpdatedSystemApp(pkg)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3931 | PackageSetting sysPs = mSettings.getDisabledSystemPkg(pkg.packageName); |
| 3932 | if(sysPs.grantedPermissions.contains(perm)) { |
| 3933 | allowed = true; |
| 3934 | } else { |
| 3935 | allowed = false; |
| 3936 | } |
| 3937 | } else { |
| 3938 | allowed = true; |
| 3939 | } |
| 3940 | } |
| 3941 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3942 | if (allowed) { |
| 3943 | allowedSig = true; |
| 3944 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3945 | } else { |
| 3946 | allowed = false; |
| 3947 | } |
| 3948 | if (false) { |
| 3949 | if (gp != ps) { |
| 3950 | Log.i(TAG, "Package " + pkg.packageName + " granting " + perm); |
| 3951 | } |
| 3952 | } |
| 3953 | if (allowed) { |
| 3954 | if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0 |
| 3955 | && ps.permissionsFixed) { |
| 3956 | // If this is an existing, non-system package, then |
| 3957 | // we can't add any new permissions to it. |
| Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 3958 | if (!allowedSig && !gp.grantedPermissions.contains(perm)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3959 | allowed = false; |
| Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 3960 | // Except... if this is a permission that was added |
| 3961 | // to the platform (note: need to only do this when |
| 3962 | // updating the platform). |
| 3963 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
| 3964 | for (int ip=0; ip<NP; ip++) { |
| 3965 | final PackageParser.NewPermissionInfo npi |
| 3966 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 3967 | if (npi.name.equals(perm) |
| 3968 | && pkg.applicationInfo.targetSdkVersion < npi.sdkVersion) { |
| 3969 | allowed = true; |
| Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 3970 | Log.i(TAG, "Auto-granting " + perm + " to old pkg " |
| Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 3971 | + pkg.packageName); |
| 3972 | break; |
| 3973 | } |
| 3974 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3975 | } |
| 3976 | } |
| 3977 | if (allowed) { |
| 3978 | if (!gp.grantedPermissions.contains(perm)) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3979 | changedPermission = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | gp.grantedPermissions.add(perm); |
| 3981 | gp.gids = appendInts(gp.gids, bp.gids); |
| Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 3982 | } else if (!ps.haveGids) { |
| 3983 | gp.gids = appendInts(gp.gids, bp.gids); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3984 | } |
| 3985 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3986 | Slog.w(TAG, "Not granting permission " + perm |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | + " to package " + pkg.packageName |
| 3988 | + " because it was previously installed without"); |
| 3989 | } |
| 3990 | } else { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3991 | if (gp.grantedPermissions.remove(perm)) { |
| 3992 | changedPermission = true; |
| 3993 | gp.gids = removeInts(gp.gids, bp.gids); |
| 3994 | Slog.i(TAG, "Un-granting permission " + perm |
| 3995 | + " from package " + pkg.packageName |
| 3996 | + " (protectionLevel=" + bp.protectionLevel |
| 3997 | + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags) |
| 3998 | + ")"); |
| 3999 | } else { |
| 4000 | Slog.w(TAG, "Not granting permission " + perm |
| 4001 | + " to package " + pkg.packageName |
| 4002 | + " (protectionLevel=" + bp.protectionLevel |
| 4003 | + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags) |
| 4004 | + ")"); |
| 4005 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4006 | } |
| 4007 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4008 | Slog.w(TAG, "Unknown permission " + name |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4009 | + " in package " + pkg.packageName); |
| 4010 | } |
| 4011 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4012 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4013 | if ((changedPermission || replace) && !ps.permissionsFixed && |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 4014 | ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) || |
| 4015 | ((ps.pkgFlags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)){ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4016 | // This is the first that we have heard about this package, so the |
| 4017 | // permissions we have now selected are fixed until explicitly |
| 4018 | // changed. |
| 4019 | ps.permissionsFixed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4020 | } |
| Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 4021 | ps.haveGids = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4022 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4023 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | private final class ActivityIntentResolver |
| 4025 | extends IntentResolver<PackageParser.ActivityIntentInfo, ResolveInfo> { |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4026 | public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4027 | mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0; |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4028 | return super.queryIntent(intent, resolvedType, defaultOnly); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4029 | } |
| 4030 | |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4031 | public List queryIntent(Intent intent, String resolvedType, int flags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4032 | mFlags = flags; |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4033 | return super.queryIntent(intent, resolvedType, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4034 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 4035 | } |
| 4036 | |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4037 | public List queryIntentForPackage(Intent intent, String resolvedType, int flags, |
| 4038 | ArrayList<PackageParser.Activity> packageActivities) { |
| 4039 | if (packageActivities == null) { |
| 4040 | return null; |
| 4041 | } |
| 4042 | mFlags = flags; |
| 4043 | final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0; |
| 4044 | int N = packageActivities.size(); |
| 4045 | ArrayList<ArrayList<PackageParser.ActivityIntentInfo>> listCut = |
| 4046 | new ArrayList<ArrayList<PackageParser.ActivityIntentInfo>>(N); |
| Mihai Preda | c3320db | 2009-05-18 20:15:32 +0200 | [diff] [blame] | 4047 | |
| 4048 | ArrayList<PackageParser.ActivityIntentInfo> intentFilters; |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4049 | for (int i = 0; i < N; ++i) { |
| Mihai Preda | c3320db | 2009-05-18 20:15:32 +0200 | [diff] [blame] | 4050 | intentFilters = packageActivities.get(i).intents; |
| 4051 | if (intentFilters != null && intentFilters.size() > 0) { |
| 4052 | listCut.add(intentFilters); |
| 4053 | } |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4054 | } |
| 4055 | return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut); |
| 4056 | } |
| 4057 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4058 | public final void addActivity(PackageParser.Activity a, String type) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4059 | mActivities.put(a.getComponentName(), a); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4060 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4061 | TAG, " " + type + " " + |
| 4062 | (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":"); |
| 4063 | if (SHOW_INFO || Config.LOGV) Log.v(TAG, " Class=" + a.info.name); |
| 4064 | int NI = a.intents.size(); |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4065 | for (int j=0; j<NI; j++) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4066 | PackageParser.ActivityIntentInfo intent = a.intents.get(j); |
| 4067 | if (SHOW_INFO || Config.LOGV) { |
| 4068 | Log.v(TAG, " IntentFilter:"); |
| 4069 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4070 | } |
| 4071 | if (!intent.debugCheck()) { |
| 4072 | Log.w(TAG, "==> For Activity " + a.info.name); |
| 4073 | } |
| 4074 | addFilter(intent); |
| 4075 | } |
| 4076 | } |
| 4077 | |
| 4078 | public final void removeActivity(PackageParser.Activity a, String type) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4079 | mActivities.remove(a.getComponentName()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4080 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4081 | TAG, " " + type + " " + |
| 4082 | (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":"); |
| 4083 | if (SHOW_INFO || Config.LOGV) Log.v(TAG, " Class=" + a.info.name); |
| 4084 | int NI = a.intents.size(); |
| Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4085 | for (int j=0; j<NI; j++) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4086 | PackageParser.ActivityIntentInfo intent = a.intents.get(j); |
| 4087 | if (SHOW_INFO || Config.LOGV) { |
| 4088 | Log.v(TAG, " IntentFilter:"); |
| 4089 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4090 | } |
| 4091 | removeFilter(intent); |
| 4092 | } |
| 4093 | } |
| 4094 | |
| 4095 | @Override |
| 4096 | protected boolean allowFilterResult( |
| 4097 | PackageParser.ActivityIntentInfo filter, List<ResolveInfo> dest) { |
| 4098 | ActivityInfo filterAi = filter.activity.info; |
| 4099 | for (int i=dest.size()-1; i>=0; i--) { |
| 4100 | ActivityInfo destAi = dest.get(i).activityInfo; |
| 4101 | if (destAi.name == filterAi.name |
| 4102 | && destAi.packageName == filterAi.packageName) { |
| 4103 | return false; |
| 4104 | } |
| 4105 | } |
| 4106 | return true; |
| 4107 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4108 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4109 | @Override |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4110 | protected String packageForFilter(PackageParser.ActivityIntentInfo info) { |
| 4111 | return info.activity.owner.packageName; |
| 4112 | } |
| 4113 | |
| 4114 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4115 | protected ResolveInfo newResult(PackageParser.ActivityIntentInfo info, |
| 4116 | int match) { |
| 4117 | if (!mSettings.isEnabledLP(info.activity.info, mFlags)) { |
| 4118 | return null; |
| 4119 | } |
| 4120 | final PackageParser.Activity activity = info.activity; |
| 4121 | if (mSafeMode && (activity.info.applicationInfo.flags |
| 4122 | &ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 4123 | return null; |
| 4124 | } |
| 4125 | final ResolveInfo res = new ResolveInfo(); |
| 4126 | res.activityInfo = PackageParser.generateActivityInfo(activity, |
| 4127 | mFlags); |
| 4128 | if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) { |
| 4129 | res.filter = info; |
| 4130 | } |
| 4131 | res.priority = info.getPriority(); |
| 4132 | res.preferredOrder = activity.owner.mPreferredOrder; |
| 4133 | //System.out.println("Result: " + res.activityInfo.className + |
| 4134 | // " = " + res.priority); |
| 4135 | res.match = match; |
| 4136 | res.isDefault = info.hasDefault; |
| 4137 | res.labelRes = info.labelRes; |
| 4138 | res.nonLocalizedLabel = info.nonLocalizedLabel; |
| 4139 | res.icon = info.icon; |
| 4140 | return res; |
| 4141 | } |
| 4142 | |
| 4143 | @Override |
| 4144 | protected void sortResults(List<ResolveInfo> results) { |
| 4145 | Collections.sort(results, mResolvePrioritySorter); |
| 4146 | } |
| 4147 | |
| 4148 | @Override |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4149 | protected void dumpFilter(PrintWriter out, String prefix, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4150 | PackageParser.ActivityIntentInfo filter) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4151 | out.print(prefix); out.print( |
| 4152 | Integer.toHexString(System.identityHashCode(filter.activity))); |
| 4153 | out.print(' '); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4154 | out.print(filter.activity.getComponentShortName()); |
| 4155 | out.print(" filter "); |
| 4156 | out.println(Integer.toHexString(System.identityHashCode(filter))); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | // List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) { |
| 4160 | // final Iterator<ResolveInfo> i = resolveInfoList.iterator(); |
| 4161 | // final List<ResolveInfo> retList = Lists.newArrayList(); |
| 4162 | // while (i.hasNext()) { |
| 4163 | // final ResolveInfo resolveInfo = i.next(); |
| 4164 | // if (isEnabledLP(resolveInfo.activityInfo)) { |
| 4165 | // retList.add(resolveInfo); |
| 4166 | // } |
| 4167 | // } |
| 4168 | // return retList; |
| 4169 | // } |
| 4170 | |
| 4171 | // Keys are String (activity class name), values are Activity. |
| 4172 | private final HashMap<ComponentName, PackageParser.Activity> mActivities |
| 4173 | = new HashMap<ComponentName, PackageParser.Activity>(); |
| 4174 | private int mFlags; |
| 4175 | } |
| 4176 | |
| 4177 | private final class ServiceIntentResolver |
| 4178 | extends IntentResolver<PackageParser.ServiceIntentInfo, ResolveInfo> { |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4179 | public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0; |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4181 | return super.queryIntent(intent, resolvedType, defaultOnly); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | } |
| 4183 | |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4184 | public List queryIntent(Intent intent, String resolvedType, int flags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | mFlags = flags; |
| Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4186 | return super.queryIntent(intent, resolvedType, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4187 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 4188 | } |
| 4189 | |
| Dianne Hackborn | c14b9ccd | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 4190 | public List queryIntentForPackage(Intent intent, String resolvedType, int flags, |
| 4191 | ArrayList<PackageParser.Service> packageServices) { |
| 4192 | if (packageServices == null) { |
| 4193 | return null; |
| 4194 | } |
| 4195 | mFlags = flags; |
| 4196 | final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0; |
| 4197 | int N = packageServices.size(); |
| 4198 | ArrayList<ArrayList<PackageParser.ServiceIntentInfo>> listCut = |
| 4199 | new ArrayList<ArrayList<PackageParser.ServiceIntentInfo>>(N); |
| 4200 | |
| 4201 | ArrayList<PackageParser.ServiceIntentInfo> intentFilters; |
| 4202 | for (int i = 0; i < N; ++i) { |
| 4203 | intentFilters = packageServices.get(i).intents; |
| 4204 | if (intentFilters != null && intentFilters.size() > 0) { |
| 4205 | listCut.add(intentFilters); |
| 4206 | } |
| 4207 | } |
| 4208 | return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut); |
| 4209 | } |
| 4210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4211 | public final void addService(PackageParser.Service s) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4212 | mServices.put(s.getComponentName(), s); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4213 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4214 | TAG, " " + (s.info.nonLocalizedLabel != null |
| 4215 | ? s.info.nonLocalizedLabel : s.info.name) + ":"); |
| 4216 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4217 | TAG, " Class=" + s.info.name); |
| 4218 | int NI = s.intents.size(); |
| 4219 | int j; |
| 4220 | for (j=0; j<NI; j++) { |
| 4221 | PackageParser.ServiceIntentInfo intent = s.intents.get(j); |
| 4222 | if (SHOW_INFO || Config.LOGV) { |
| 4223 | Log.v(TAG, " IntentFilter:"); |
| 4224 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4225 | } |
| 4226 | if (!intent.debugCheck()) { |
| 4227 | Log.w(TAG, "==> For Service " + s.info.name); |
| 4228 | } |
| 4229 | addFilter(intent); |
| 4230 | } |
| 4231 | } |
| 4232 | |
| 4233 | public final void removeService(PackageParser.Service s) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4234 | mServices.remove(s.getComponentName()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4235 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4236 | TAG, " " + (s.info.nonLocalizedLabel != null |
| 4237 | ? s.info.nonLocalizedLabel : s.info.name) + ":"); |
| 4238 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4239 | TAG, " Class=" + s.info.name); |
| 4240 | int NI = s.intents.size(); |
| 4241 | int j; |
| 4242 | for (j=0; j<NI; j++) { |
| 4243 | PackageParser.ServiceIntentInfo intent = s.intents.get(j); |
| 4244 | if (SHOW_INFO || Config.LOGV) { |
| 4245 | Log.v(TAG, " IntentFilter:"); |
| 4246 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4247 | } |
| 4248 | removeFilter(intent); |
| 4249 | } |
| 4250 | } |
| 4251 | |
| 4252 | @Override |
| 4253 | protected boolean allowFilterResult( |
| 4254 | PackageParser.ServiceIntentInfo filter, List<ResolveInfo> dest) { |
| 4255 | ServiceInfo filterSi = filter.service.info; |
| 4256 | for (int i=dest.size()-1; i>=0; i--) { |
| 4257 | ServiceInfo destAi = dest.get(i).serviceInfo; |
| 4258 | if (destAi.name == filterSi.name |
| 4259 | && destAi.packageName == filterSi.packageName) { |
| 4260 | return false; |
| 4261 | } |
| 4262 | } |
| 4263 | return true; |
| 4264 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4265 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | @Override |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4267 | protected String packageForFilter(PackageParser.ServiceIntentInfo info) { |
| 4268 | return info.service.owner.packageName; |
| 4269 | } |
| 4270 | |
| 4271 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4272 | protected ResolveInfo newResult(PackageParser.ServiceIntentInfo filter, |
| 4273 | int match) { |
| 4274 | final PackageParser.ServiceIntentInfo info = (PackageParser.ServiceIntentInfo)filter; |
| 4275 | if (!mSettings.isEnabledLP(info.service.info, mFlags)) { |
| 4276 | return null; |
| 4277 | } |
| 4278 | final PackageParser.Service service = info.service; |
| 4279 | if (mSafeMode && (service.info.applicationInfo.flags |
| 4280 | &ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 4281 | return null; |
| 4282 | } |
| 4283 | final ResolveInfo res = new ResolveInfo(); |
| 4284 | res.serviceInfo = PackageParser.generateServiceInfo(service, |
| 4285 | mFlags); |
| 4286 | if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) { |
| 4287 | res.filter = filter; |
| 4288 | } |
| 4289 | res.priority = info.getPriority(); |
| 4290 | res.preferredOrder = service.owner.mPreferredOrder; |
| 4291 | //System.out.println("Result: " + res.activityInfo.className + |
| 4292 | // " = " + res.priority); |
| 4293 | res.match = match; |
| 4294 | res.isDefault = info.hasDefault; |
| 4295 | res.labelRes = info.labelRes; |
| 4296 | res.nonLocalizedLabel = info.nonLocalizedLabel; |
| 4297 | res.icon = info.icon; |
| 4298 | return res; |
| 4299 | } |
| 4300 | |
| 4301 | @Override |
| 4302 | protected void sortResults(List<ResolveInfo> results) { |
| 4303 | Collections.sort(results, mResolvePrioritySorter); |
| 4304 | } |
| 4305 | |
| 4306 | @Override |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4307 | protected void dumpFilter(PrintWriter out, String prefix, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4308 | PackageParser.ServiceIntentInfo filter) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4309 | out.print(prefix); out.print( |
| 4310 | Integer.toHexString(System.identityHashCode(filter.service))); |
| 4311 | out.print(' '); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4312 | out.print(filter.service.getComponentShortName()); |
| 4313 | out.print(" filter "); |
| 4314 | out.println(Integer.toHexString(System.identityHashCode(filter))); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | // List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) { |
| 4318 | // final Iterator<ResolveInfo> i = resolveInfoList.iterator(); |
| 4319 | // final List<ResolveInfo> retList = Lists.newArrayList(); |
| 4320 | // while (i.hasNext()) { |
| 4321 | // final ResolveInfo resolveInfo = (ResolveInfo) i; |
| 4322 | // if (isEnabledLP(resolveInfo.serviceInfo)) { |
| 4323 | // retList.add(resolveInfo); |
| 4324 | // } |
| 4325 | // } |
| 4326 | // return retList; |
| 4327 | // } |
| 4328 | |
| 4329 | // Keys are String (activity class name), values are Activity. |
| 4330 | private final HashMap<ComponentName, PackageParser.Service> mServices |
| 4331 | = new HashMap<ComponentName, PackageParser.Service>(); |
| 4332 | private int mFlags; |
| 4333 | }; |
| 4334 | |
| 4335 | private static final Comparator<ResolveInfo> mResolvePrioritySorter = |
| 4336 | new Comparator<ResolveInfo>() { |
| 4337 | public int compare(ResolveInfo r1, ResolveInfo r2) { |
| 4338 | int v1 = r1.priority; |
| 4339 | int v2 = r2.priority; |
| 4340 | //System.out.println("Comparing: q1=" + q1 + " q2=" + q2); |
| 4341 | if (v1 != v2) { |
| 4342 | return (v1 > v2) ? -1 : 1; |
| 4343 | } |
| 4344 | v1 = r1.preferredOrder; |
| 4345 | v2 = r2.preferredOrder; |
| 4346 | if (v1 != v2) { |
| 4347 | return (v1 > v2) ? -1 : 1; |
| 4348 | } |
| 4349 | if (r1.isDefault != r2.isDefault) { |
| 4350 | return r1.isDefault ? -1 : 1; |
| 4351 | } |
| 4352 | v1 = r1.match; |
| 4353 | v2 = r2.match; |
| 4354 | //System.out.println("Comparing: m1=" + m1 + " m2=" + m2); |
| 4355 | return (v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0); |
| 4356 | } |
| 4357 | }; |
| 4358 | |
| 4359 | private static final Comparator<ProviderInfo> mProviderInitOrderSorter = |
| 4360 | new Comparator<ProviderInfo>() { |
| 4361 | public int compare(ProviderInfo p1, ProviderInfo p2) { |
| 4362 | final int v1 = p1.initOrder; |
| 4363 | final int v2 = p2.initOrder; |
| 4364 | return (v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0); |
| 4365 | } |
| 4366 | }; |
| 4367 | |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 4368 | private static final boolean DEBUG_OBB = false; |
| 4369 | |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4370 | private static final void sendPackageBroadcast(String action, String pkg, |
| 4371 | Bundle extras, IIntentReceiver finishedReceiver) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4372 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 4373 | if (am != null) { |
| 4374 | try { |
| 4375 | final Intent intent = new Intent(action, |
| 4376 | pkg != null ? Uri.fromParts("package", pkg, null) : null); |
| 4377 | if (extras != null) { |
| 4378 | intent.putExtras(extras); |
| 4379 | } |
| Dianne Hackborn | de7faf6 | 2009-06-30 13:27:30 -0700 | [diff] [blame] | 4380 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4381 | am.broadcastIntent(null, intent, null, finishedReceiver, |
| 4382 | 0, null, null, null, finishedReceiver != null, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4383 | } catch (RemoteException ex) { |
| 4384 | } |
| 4385 | } |
| 4386 | } |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 4387 | |
| 4388 | public String nextPackageToClean(String lastPackage) { |
| 4389 | synchronized (mPackages) { |
| 4390 | if (!mMediaMounted) { |
| 4391 | // If the external storage is no longer mounted at this point, |
| 4392 | // the caller may not have been able to delete all of this |
| 4393 | // packages files and can not delete any more. Bail. |
| 4394 | return null; |
| 4395 | } |
| 4396 | if (lastPackage != null) { |
| 4397 | mSettings.mPackagesToBeCleaned.remove(lastPackage); |
| 4398 | } |
| 4399 | return mSettings.mPackagesToBeCleaned.size() > 0 |
| 4400 | ? mSettings.mPackagesToBeCleaned.get(0) : null; |
| 4401 | } |
| 4402 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 4404 | void schedulePackageCleaning(String packageName) { |
| 4405 | mHandler.sendMessage(mHandler.obtainMessage(START_CLEANING_PACKAGE, packageName)); |
| 4406 | } |
| 4407 | |
| 4408 | void startCleaningPackages() { |
| 4409 | synchronized (mPackages) { |
| 4410 | if (!mMediaMounted) { |
| 4411 | return; |
| 4412 | } |
| 4413 | if (mSettings.mPackagesToBeCleaned.size() <= 0) { |
| 4414 | return; |
| 4415 | } |
| 4416 | } |
| 4417 | Intent intent = new Intent(PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE); |
| 4418 | intent.setComponent(DEFAULT_CONTAINER_COMPONENT); |
| 4419 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 4420 | if (am != null) { |
| 4421 | try { |
| 4422 | am.startService(null, intent, null); |
| 4423 | } catch (RemoteException e) { |
| 4424 | } |
| 4425 | } |
| 4426 | } |
| 4427 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4428 | private final class AppDirObserver extends FileObserver { |
| 4429 | public AppDirObserver(String path, int mask, boolean isrom) { |
| 4430 | super(path, mask); |
| 4431 | mRootDir = path; |
| 4432 | mIsRom = isrom; |
| 4433 | } |
| 4434 | |
| 4435 | public void onEvent(int event, String path) { |
| 4436 | String removedPackage = null; |
| 4437 | int removedUid = -1; |
| 4438 | String addedPackage = null; |
| 4439 | int addedUid = -1; |
| 4440 | |
| 4441 | synchronized (mInstallLock) { |
| 4442 | String fullPathStr = null; |
| 4443 | File fullPath = null; |
| 4444 | if (path != null) { |
| 4445 | fullPath = new File(mRootDir, path); |
| 4446 | fullPathStr = fullPath.getPath(); |
| 4447 | } |
| 4448 | |
| 4449 | if (Config.LOGV) Log.v( |
| 4450 | TAG, "File " + fullPathStr + " changed: " |
| 4451 | + Integer.toHexString(event)); |
| 4452 | |
| 4453 | if (!isPackageFilename(path)) { |
| 4454 | if (Config.LOGV) Log.v( |
| 4455 | TAG, "Ignoring change of non-package file: " + fullPathStr); |
| 4456 | return; |
| 4457 | } |
| 4458 | |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4459 | // Ignore packages that are being installed or |
| 4460 | // have just been installed. |
| 4461 | if (ignoreCodePath(fullPathStr)) { |
| 4462 | return; |
| 4463 | } |
| 4464 | PackageParser.Package p = null; |
| 4465 | synchronized (mPackages) { |
| 4466 | p = mAppDirs.get(fullPathStr); |
| 4467 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4468 | if ((event&REMOVE_EVENTS) != 0) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4469 | if (p != null) { |
| 4470 | removePackageLI(p, true); |
| 4471 | removedPackage = p.applicationInfo.packageName; |
| 4472 | removedUid = p.applicationInfo.uid; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | } |
| 4474 | } |
| 4475 | |
| 4476 | if ((event&ADD_EVENTS) != 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4477 | if (p == null) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 4478 | p = scanPackageLI(fullPath, |
| Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 4479 | (mIsRom ? PackageParser.PARSE_IS_SYSTEM |
| 4480 | | PackageParser.PARSE_IS_SYSTEM_DIR: 0) | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4481 | PackageParser.PARSE_CHATTY | |
| 4482 | PackageParser.PARSE_MUST_BE_APK, |
| Andrew Stadler | 48c0273 | 2010-01-15 00:03:41 -0800 | [diff] [blame] | 4483 | SCAN_MONITOR | SCAN_NO_PATHS); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | if (p != null) { |
| 4485 | synchronized (mPackages) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4486 | updatePermissionsLP(p.packageName, p, |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 4487 | p.permissions.size() > 0, false, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | } |
| 4489 | addedPackage = p.applicationInfo.packageName; |
| 4490 | addedUid = p.applicationInfo.uid; |
| 4491 | } |
| 4492 | } |
| 4493 | } |
| 4494 | |
| 4495 | synchronized (mPackages) { |
| 4496 | mSettings.writeLP(); |
| 4497 | } |
| 4498 | } |
| 4499 | |
| 4500 | if (removedPackage != null) { |
| 4501 | Bundle extras = new Bundle(1); |
| 4502 | extras.putInt(Intent.EXTRA_UID, removedUid); |
| 4503 | extras.putBoolean(Intent.EXTRA_DATA_REMOVED, false); |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4504 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage, |
| 4505 | extras, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | } |
| 4507 | if (addedPackage != null) { |
| 4508 | Bundle extras = new Bundle(1); |
| 4509 | extras.putInt(Intent.EXTRA_UID, addedUid); |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4510 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, addedPackage, |
| 4511 | extras, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4512 | } |
| 4513 | } |
| 4514 | |
| 4515 | private final String mRootDir; |
| 4516 | private final boolean mIsRom; |
| 4517 | } |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4518 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4519 | /* Called when a downloaded package installation has been confirmed by the user */ |
| 4520 | public void installPackage( |
| 4521 | final Uri packageURI, final IPackageInstallObserver observer, final int flags) { |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4522 | installPackage(packageURI, observer, flags, null); |
| 4523 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4524 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4525 | /* Called when a downloaded package installation has been confirmed by the user */ |
| 4526 | public void installPackage( |
| 4527 | final Uri packageURI, final IPackageInstallObserver observer, final int flags, |
| 4528 | final String installerPackageName) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | mContext.enforceCallingOrSelfPermission( |
| 4530 | android.Manifest.permission.INSTALL_PACKAGES, null); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4531 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4532 | Message msg = mHandler.obtainMessage(INIT_COPY); |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4533 | msg.obj = new InstallParams(packageURI, observer, flags, |
| 4534 | installerPackageName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4535 | mHandler.sendMessage(msg); |
| 4536 | } |
| 4537 | |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4538 | public void finishPackageInstall(int token) { |
| 4539 | if (DEBUG_INSTALL) Log.v(TAG, "BM finishing package install for " + token); |
| 4540 | Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0); |
| 4541 | mHandler.sendMessage(msg); |
| 4542 | } |
| 4543 | |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 4544 | public void setPackageObbPath(String packageName, String path) { |
| 4545 | if (DEBUG_OBB) |
| 4546 | Log.v(TAG, "Setting .obb path for " + packageName + " to: " + path); |
| 4547 | PackageSetting pkgSetting; |
| 4548 | final int uid = Binder.getCallingUid(); |
| Kenny Root | e059b27 | 2010-07-12 08:36:07 -0700 | [diff] [blame] | 4549 | final int permission = mContext.checkCallingPermission( |
| 4550 | android.Manifest.permission.INSTALL_PACKAGES); |
| 4551 | final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED); |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 4552 | synchronized (mPackages) { |
| 4553 | pkgSetting = mSettings.mPackages.get(packageName); |
| 4554 | if (pkgSetting == null) { |
| 4555 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4556 | } |
| 4557 | if (!allowedByPermission && (uid != pkgSetting.userId)) { |
| 4558 | throw new SecurityException("Permission denial: attempt to set .obb file from pid=" |
| 4559 | + Binder.getCallingPid() + ", uid=" + uid + ", package uid=" |
| 4560 | + pkgSetting.userId); |
| 4561 | } |
| 4562 | pkgSetting.obbPathString = path; |
| 4563 | mSettings.writeLP(); |
| 4564 | } |
| 4565 | } |
| 4566 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4567 | private void processPendingInstall(final InstallArgs args, final int currentStatus) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4568 | // Queue up an async operation since the package installation may take a little while. |
| 4569 | mHandler.post(new Runnable() { |
| 4570 | public void run() { |
| 4571 | mHandler.removeCallbacks(this); |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4572 | // Result object to be returned |
| 4573 | PackageInstalledInfo res = new PackageInstalledInfo(); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4574 | res.returnCode = currentStatus; |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4575 | res.uid = -1; |
| 4576 | res.pkg = null; |
| 4577 | res.removedInfo = new PackageRemovedInfo(); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4578 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) { |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4579 | args.doPreInstall(res.returnCode); |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4580 | synchronized (mInstallLock) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4581 | installPackageLI(args, true, res); |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4582 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4583 | args.doPostInstall(res.returnCode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4584 | } |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4585 | |
| 4586 | // A restore should be performed at this point if (a) the install |
| 4587 | // succeeded, (b) the operation is not an update, and (c) the new |
| 4588 | // package has a backupAgent defined. |
| 4589 | final boolean update = res.removedInfo.removedPackage != null; |
| Christopher Tate | 59eac4b | 2010-02-19 19:25:45 -0800 | [diff] [blame] | 4590 | boolean doRestore = (!update |
| 4591 | && res.pkg != null |
| 4592 | && res.pkg.applicationInfo.backupAgentName != null); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4593 | |
| 4594 | // Set up the post-install work request bookkeeping. This will be used |
| 4595 | // and cleaned up by the post-install event handling regardless of whether |
| 4596 | // there's a restore pass performed. Token values are >= 1. |
| 4597 | int token; |
| 4598 | if (mNextInstallToken < 0) mNextInstallToken = 1; |
| 4599 | token = mNextInstallToken++; |
| 4600 | |
| 4601 | PostInstallData data = new PostInstallData(args, res); |
| 4602 | mRunningInstalls.put(token, data); |
| 4603 | if (DEBUG_INSTALL) Log.v(TAG, "+ starting restore round-trip " + token); |
| 4604 | |
| 4605 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED && doRestore) { |
| 4606 | // Pass responsibility to the Backup Manager. It will perform a |
| 4607 | // restore if appropriate, then pass responsibility back to the |
| 4608 | // Package Manager to run the post-install observer callbacks |
| 4609 | // and broadcasts. |
| 4610 | IBackupManager bm = IBackupManager.Stub.asInterface( |
| 4611 | ServiceManager.getService(Context.BACKUP_SERVICE)); |
| 4612 | if (bm != null) { |
| 4613 | if (DEBUG_INSTALL) Log.v(TAG, "token " + token |
| 4614 | + " to BM for possible restore"); |
| 4615 | try { |
| 4616 | bm.restoreAtInstall(res.pkg.applicationInfo.packageName, token); |
| 4617 | } catch (RemoteException e) { |
| 4618 | // can't happen; the backup manager is local |
| 4619 | } catch (Exception e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4620 | Slog.e(TAG, "Exception trying to enqueue restore", e); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4621 | doRestore = false; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4622 | } |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4623 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4624 | Slog.e(TAG, "Backup Manager not found!"); |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4625 | doRestore = false; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4626 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4627 | } |
| Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4628 | |
| 4629 | if (!doRestore) { |
| 4630 | // No restore possible, or the Backup Manager was mysteriously not |
| 4631 | // available -- just fire the post-install work request directly. |
| 4632 | if (DEBUG_INSTALL) Log.v(TAG, "No restore - queue post-install for " + token); |
| 4633 | Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0); |
| 4634 | mHandler.sendMessage(msg); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4635 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4636 | } |
| 4637 | }); |
| 4638 | } |
| 4639 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4640 | abstract class HandlerParams { |
| 4641 | final static int MAX_RETRIES = 4; |
| 4642 | int retry = 0; |
| 4643 | final void startCopy() { |
| 4644 | try { |
| 4645 | if (DEBUG_SD_INSTALL) Log.i(TAG, "startCopy"); |
| 4646 | retry++; |
| 4647 | if (retry > MAX_RETRIES) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4648 | 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] | 4649 | mHandler.sendEmptyMessage(MCS_GIVE_UP); |
| 4650 | handleServiceError(); |
| 4651 | return; |
| 4652 | } else { |
| 4653 | handleStartCopy(); |
| 4654 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Posting install MCS_UNBIND"); |
| 4655 | mHandler.sendEmptyMessage(MCS_UNBIND); |
| 4656 | } |
| 4657 | } catch (RemoteException e) { |
| 4658 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Posting install MCS_RECONNECT"); |
| 4659 | mHandler.sendEmptyMessage(MCS_RECONNECT); |
| 4660 | } |
| 4661 | handleReturnCode(); |
| 4662 | } |
| 4663 | |
| 4664 | final void serviceError() { |
| 4665 | if (DEBUG_SD_INSTALL) Log.i(TAG, "serviceError"); |
| 4666 | handleServiceError(); |
| 4667 | handleReturnCode(); |
| 4668 | } |
| 4669 | abstract void handleStartCopy() throws RemoteException; |
| 4670 | abstract void handleServiceError(); |
| 4671 | abstract void handleReturnCode(); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4672 | } |
| 4673 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4674 | class InstallParams extends HandlerParams { |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4675 | final IPackageInstallObserver observer; |
| 4676 | int flags; |
| 4677 | final Uri packageURI; |
| 4678 | final String installerPackageName; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4679 | private InstallArgs mArgs; |
| 4680 | private int mRet; |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4681 | InstallParams(Uri packageURI, |
| 4682 | IPackageInstallObserver observer, int flags, |
| 4683 | String installerPackageName) { |
| 4684 | this.packageURI = packageURI; |
| 4685 | this.flags = flags; |
| 4686 | this.observer = observer; |
| 4687 | this.installerPackageName = installerPackageName; |
| 4688 | } |
| 4689 | |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4690 | private int installLocationPolicy(PackageInfoLite pkgLite, int flags) { |
| 4691 | String packageName = pkgLite.packageName; |
| 4692 | int installLocation = pkgLite.installLocation; |
| 4693 | boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0; |
| 4694 | synchronized (mPackages) { |
| 4695 | PackageParser.Package pkg = mPackages.get(packageName); |
| 4696 | if (pkg != null) { |
| 4697 | if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
| 4698 | // Check for updated system application. |
| 4699 | if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4700 | if (onSd) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4701 | Slog.w(TAG, "Cannot install update to system app on sdcard"); |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4702 | return PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION; |
| 4703 | } |
| 4704 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
| 4705 | } else { |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4706 | if (onSd) { |
| 4707 | // Install flag overrides everything. |
| 4708 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4709 | } |
| Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4710 | // If current upgrade specifies particular preference |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4711 | if (installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) { |
| 4712 | // Application explicitly specified internal. |
| 4713 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
| 4714 | } else if (installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) { |
| 4715 | // App explictly prefers external. Let policy decide |
| Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4716 | } else { |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4717 | // Prefer previous location |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4718 | if (isExternal(pkg)) { |
| Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4719 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4720 | } |
| 4721 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4722 | } |
| 4723 | } |
| 4724 | } else { |
| 4725 | // Invalid install. Return error code |
| 4726 | return PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS; |
| 4727 | } |
| 4728 | } |
| 4729 | } |
| 4730 | // All the special cases have been taken care of. |
| 4731 | // Return result based on recommended install location. |
| 4732 | if (onSd) { |
| 4733 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4734 | } |
| 4735 | return pkgLite.recommendedInstallLocation; |
| 4736 | } |
| 4737 | |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4738 | /* |
| 4739 | * Invoke remote method to get package information and install |
| 4740 | * location values. Override install location based on default |
| 4741 | * policy if needed and then create install arguments based |
| 4742 | * on the install location. |
| 4743 | */ |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4744 | public void handleStartCopy() throws RemoteException { |
| Suchi Amalapurapu | 1f9e1b4 | 2010-02-26 13:14:31 -0800 | [diff] [blame] | 4745 | int ret = PackageManager.INSTALL_SUCCEEDED; |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4746 | boolean fwdLocked = (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0; |
| 4747 | boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0; |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4748 | boolean onInt = (flags & PackageManager.INSTALL_INTERNAL) != 0; |
| 4749 | if (onInt && onSd) { |
| 4750 | // Check if both bits are set. |
| 4751 | Slog.w(TAG, "Conflicting flags specified for installing on both internal and external"); |
| 4752 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 4753 | } else if (fwdLocked && onSd) { |
| 4754 | // Check for forward locked apps |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4755 | Slog.w(TAG, "Cannot install fwd locked apps on sdcard"); |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4756 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4757 | } else { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4758 | // Remote call to find out default install location |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4759 | PackageInfoLite pkgLite = mContainerService.getMinimalPackageInfo(packageURI, flags); |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4760 | int loc = pkgLite.recommendedInstallLocation; |
| Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4761 | if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION){ |
| 4762 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 4763 | } else if (loc == PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS){ |
| 4764 | ret = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 4765 | } else if (loc == PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE){ |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4766 | ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4767 | } else if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_APK) { |
| 4768 | ret = PackageManager.INSTALL_FAILED_INVALID_APK; |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4769 | } else if (loc == PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE) { |
| 4770 | ret = PackageManager.INSTALL_FAILED_MEDIA_UNAVAILABLE; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4771 | } else { |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4772 | // Override with defaults if needed. |
| 4773 | loc = installLocationPolicy(pkgLite, flags); |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4774 | if (!onSd && !onInt) { |
| 4775 | // Override install location with flags |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4776 | if (loc == PackageHelper.RECOMMEND_INSTALL_EXTERNAL) { |
| 4777 | // Set the flag to install on external media. |
| 4778 | flags |= PackageManager.INSTALL_EXTERNAL; |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4779 | flags &= ~PackageManager.INSTALL_INTERNAL; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4780 | } else { |
| 4781 | // Make sure the flag for installing on external |
| 4782 | // media is unset |
| Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4783 | flags |= PackageManager.INSTALL_INTERNAL; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4784 | flags &= ~PackageManager.INSTALL_EXTERNAL; |
| 4785 | } |
| 4786 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4787 | } |
| 4788 | } |
| 4789 | // Create the file args now. |
| 4790 | mArgs = createInstallArgs(this); |
| 4791 | if (ret == PackageManager.INSTALL_SUCCEEDED) { |
| 4792 | // Create copy only if we are not in an erroneous state. |
| 4793 | // Remote call to initiate copy using temporary file |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4794 | ret = mArgs.copyApk(mContainerService, true); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4795 | } |
| 4796 | mRet = ret; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4797 | } |
| 4798 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4799 | @Override |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4800 | void handleReturnCode() { |
| Kenny Root | 6f89fa0 | 2010-07-30 16:33:47 -0700 | [diff] [blame] | 4801 | // If mArgs is null, then MCS couldn't be reached. When it |
| 4802 | // reconnects, it will try again to install. At that point, this |
| 4803 | // will succeed. |
| 4804 | if (mArgs != null) { |
| 4805 | processPendingInstall(mArgs, mRet); |
| 4806 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4807 | } |
| 4808 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4809 | @Override |
| 4810 | void handleServiceError() { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4811 | mArgs = createInstallArgs(this); |
| 4812 | mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4813 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4814 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4815 | |
| 4816 | /* |
| 4817 | * Utility class used in movePackage api. |
| 4818 | * srcArgs and targetArgs are not set for invalid flags and make |
| 4819 | * sure to do null checks when invoking methods on them. |
| 4820 | * We probably want to return ErrorPrams for both failed installs |
| 4821 | * and moves. |
| 4822 | */ |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4823 | class MoveParams extends HandlerParams { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4824 | final IPackageMoveObserver observer; |
| 4825 | final int flags; |
| 4826 | final String packageName; |
| 4827 | final InstallArgs srcArgs; |
| 4828 | final InstallArgs targetArgs; |
| 4829 | int mRet; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4830 | |
| 4831 | MoveParams(InstallArgs srcArgs, IPackageMoveObserver observer, int flags, |
| 4832 | String packageName, String dataDir) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4833 | this.srcArgs = srcArgs; |
| 4834 | this.observer = observer; |
| 4835 | this.flags = flags; |
| 4836 | this.packageName = packageName; |
| 4837 | if (srcArgs != null) { |
| 4838 | Uri packageUri = Uri.fromFile(new File(srcArgs.getCodePath())); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4839 | targetArgs = createInstallArgs(packageUri, flags, packageName, dataDir); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4840 | } else { |
| 4841 | targetArgs = null; |
| 4842 | } |
| 4843 | } |
| 4844 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4845 | public void handleStartCopy() throws RemoteException { |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4846 | mRet = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4847 | // Check for storage space on target medium |
| 4848 | if (!targetArgs.checkFreeStorage(mContainerService)) { |
| 4849 | Log.w(TAG, "Insufficient storage to install"); |
| 4850 | return; |
| 4851 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4852 | // Create the file args now. |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4853 | mRet = targetArgs.copyApk(mContainerService, false); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4854 | targetArgs.doPreInstall(mRet); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4855 | if (DEBUG_SD_INSTALL) { |
| 4856 | StringBuilder builder = new StringBuilder(); |
| 4857 | if (srcArgs != null) { |
| 4858 | builder.append("src: "); |
| 4859 | builder.append(srcArgs.getCodePath()); |
| 4860 | } |
| 4861 | if (targetArgs != null) { |
| 4862 | builder.append(" target : "); |
| 4863 | builder.append(targetArgs.getCodePath()); |
| 4864 | } |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4865 | Log.i(TAG, builder.toString()); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4866 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4867 | } |
| 4868 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4869 | @Override |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4870 | void handleReturnCode() { |
| 4871 | targetArgs.doPostInstall(mRet); |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4872 | int currentStatus = PackageManager.MOVE_FAILED_INTERNAL_ERROR; |
| 4873 | if (mRet == PackageManager.INSTALL_SUCCEEDED) { |
| 4874 | currentStatus = PackageManager.MOVE_SUCCEEDED; |
| 4875 | } else if (mRet == PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE){ |
| 4876 | currentStatus = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE; |
| 4877 | } |
| 4878 | processPendingMove(this, currentStatus); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4879 | } |
| 4880 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4881 | @Override |
| 4882 | void handleServiceError() { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4883 | mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4884 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4885 | } |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4886 | |
| 4887 | private InstallArgs createInstallArgs(InstallParams params) { |
| 4888 | if (installOnSd(params.flags)) { |
| 4889 | return new SdInstallArgs(params); |
| 4890 | } else { |
| 4891 | return new FileInstallArgs(params); |
| 4892 | } |
| 4893 | } |
| 4894 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4895 | private InstallArgs createInstallArgs(int flags, String fullCodePath, String fullResourcePath, |
| 4896 | String nativeLibraryPath) { |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4897 | if (installOnSd(flags)) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4898 | return new SdInstallArgs(fullCodePath, fullResourcePath, nativeLibraryPath); |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4899 | } else { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4900 | return new FileInstallArgs(fullCodePath, fullResourcePath, nativeLibraryPath); |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4901 | } |
| 4902 | } |
| 4903 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4904 | // Used by package mover |
| 4905 | private InstallArgs createInstallArgs(Uri packageURI, int flags, String pkgName, String dataDir) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4906 | if (installOnSd(flags)) { |
| 4907 | String cid = getNextCodePath(null, pkgName, "/" + SdInstallArgs.RES_FILE_NAME); |
| 4908 | return new SdInstallArgs(packageURI, cid); |
| 4909 | } else { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4910 | return new FileInstallArgs(packageURI, pkgName, dataDir); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4911 | } |
| 4912 | } |
| 4913 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4914 | static abstract class InstallArgs { |
| 4915 | final IPackageInstallObserver observer; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4916 | // Always refers to PackageManager flags only |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4917 | final int flags; |
| 4918 | final Uri packageURI; |
| 4919 | final String installerPackageName; |
| 4920 | |
| 4921 | InstallArgs(Uri packageURI, |
| 4922 | IPackageInstallObserver observer, int flags, |
| 4923 | String installerPackageName) { |
| 4924 | this.packageURI = packageURI; |
| 4925 | this.flags = flags; |
| 4926 | this.observer = observer; |
| 4927 | this.installerPackageName = installerPackageName; |
| 4928 | } |
| 4929 | |
| 4930 | abstract void createCopyFile(); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4931 | abstract int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 4932 | abstract int doPreInstall(int status); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4933 | abstract boolean doRename(int status, String pkgName, String oldCodePath); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 4934 | abstract int doPostInstall(int status); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4935 | abstract String getCodePath(); |
| 4936 | abstract String getResourcePath(); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4937 | abstract String getNativeLibraryPath(); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4938 | // Need installer lock especially for dex file removal. |
| 4939 | abstract void cleanUpResourcesLI(); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 4940 | abstract boolean doPostDeleteLI(boolean delete); |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4941 | abstract boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | class FileInstallArgs extends InstallArgs { |
| 4945 | File installDir; |
| 4946 | String codeFileName; |
| 4947 | String resourceFileName; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4948 | String libraryPath; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4949 | boolean created = false; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4950 | |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4951 | FileInstallArgs(InstallParams params) { |
| 4952 | super(params.packageURI, params.observer, |
| 4953 | params.flags, params.installerPackageName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4954 | } |
| 4955 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4956 | FileInstallArgs(String fullCodePath, String fullResourcePath, String nativeLibraryPath) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4957 | super(null, null, 0, null); |
| 4958 | File codeFile = new File(fullCodePath); |
| 4959 | installDir = codeFile.getParentFile(); |
| 4960 | codeFileName = fullCodePath; |
| 4961 | resourceFileName = fullResourcePath; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4962 | libraryPath = nativeLibraryPath; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4963 | } |
| 4964 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4965 | FileInstallArgs(Uri packageURI, String pkgName, String dataDir) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4966 | super(packageURI, null, 0, null); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4967 | installDir = isFwdLocked() ? mDrmAppPrivateInstallDir : mAppInstallDir; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4968 | String apkName = getNextCodePath(null, pkgName, ".apk"); |
| 4969 | codeFileName = new File(installDir, apkName + ".apk").getPath(); |
| 4970 | resourceFileName = getResourcePathFromCodePath(); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4971 | libraryPath = new File(dataDir, LIB_DIR_NAME).getPath(); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4972 | } |
| 4973 | |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4974 | boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException { |
| 4975 | return imcs.checkFreeStorage(false, packageURI); |
| 4976 | } |
| 4977 | |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4978 | String getCodePath() { |
| 4979 | return codeFileName; |
| 4980 | } |
| 4981 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4982 | void createCopyFile() { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 4983 | installDir = isFwdLocked() ? mDrmAppPrivateInstallDir : mAppInstallDir; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4984 | codeFileName = createTempPackageFile(installDir).getPath(); |
| 4985 | resourceFileName = getResourcePathFromCodePath(); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4986 | created = true; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4987 | } |
| 4988 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4989 | int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4990 | if (temp) { |
| 4991 | // Generate temp file name |
| 4992 | createCopyFile(); |
| 4993 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4994 | // Get a ParcelFileDescriptor to write to the output file |
| 4995 | File codeFile = new File(codeFileName); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4996 | if (!created) { |
| 4997 | try { |
| 4998 | codeFile.createNewFile(); |
| 4999 | // Set permissions |
| 5000 | if (!setPermissions()) { |
| 5001 | // Failed setting permissions. |
| 5002 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5003 | } |
| 5004 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5005 | Slog.w(TAG, "Failed to create file " + codeFile); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5006 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5007 | } |
| 5008 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5009 | ParcelFileDescriptor out = null; |
| 5010 | try { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5011 | out = ParcelFileDescriptor.open(codeFile, ParcelFileDescriptor.MODE_READ_WRITE); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5012 | } catch (FileNotFoundException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5013 | Slog.e(TAG, "Failed to create file descritpor for : " + codeFileName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5014 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5015 | } |
| 5016 | // Copy the resource now |
| 5017 | int ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5018 | try { |
| 5019 | if (imcs.copyResource(packageURI, out)) { |
| 5020 | ret = PackageManager.INSTALL_SUCCEEDED; |
| 5021 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5022 | } finally { |
| 5023 | try { if (out != null) out.close(); } catch (IOException e) {} |
| 5024 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5025 | |
| 5026 | if (!temp) { |
| 5027 | NativeLibraryHelper.copyNativeBinariesLI(codeFile, new File(libraryPath)); |
| 5028 | } |
| 5029 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5030 | return ret; |
| 5031 | } |
| 5032 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5033 | int doPreInstall(int status) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5034 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5035 | cleanUp(); |
| 5036 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5037 | return status; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | boolean doRename(int status, final String pkgName, String oldCodePath) { |
| 5041 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5042 | cleanUp(); |
| 5043 | return false; |
| 5044 | } else { |
| 5045 | // Rename based on packageName |
| 5046 | File codeFile = new File(getCodePath()); |
| 5047 | String apkName = getNextCodePath(oldCodePath, pkgName, ".apk"); |
| 5048 | File desFile = new File(installDir, apkName + ".apk"); |
| 5049 | if (!codeFile.renameTo(desFile)) { |
| 5050 | return false; |
| 5051 | } |
| 5052 | // Reset paths since the file has been renamed. |
| 5053 | codeFileName = desFile.getPath(); |
| 5054 | resourceFileName = getResourcePathFromCodePath(); |
| 5055 | // Set permissions |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5056 | if (!setPermissions()) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5057 | // Failed setting permissions. |
| 5058 | return false; |
| 5059 | } |
| 5060 | return true; |
| 5061 | } |
| 5062 | } |
| 5063 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5064 | int doPostInstall(int status) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5065 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5066 | cleanUp(); |
| 5067 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5068 | return status; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | String getResourcePath() { |
| 5072 | return resourceFileName; |
| 5073 | } |
| 5074 | |
| 5075 | String getResourcePathFromCodePath() { |
| 5076 | String codePath = getCodePath(); |
| 5077 | if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { |
| 5078 | String apkNameOnly = getApkName(codePath); |
| 5079 | return mAppInstallDir.getPath() + "/" + apkNameOnly + ".zip"; |
| 5080 | } else { |
| 5081 | return codePath; |
| 5082 | } |
| 5083 | } |
| 5084 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5085 | @Override |
| 5086 | String getNativeLibraryPath() { |
| 5087 | return libraryPath; |
| 5088 | } |
| 5089 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5090 | private boolean cleanUp() { |
| 5091 | boolean ret = true; |
| 5092 | String sourceDir = getCodePath(); |
| 5093 | String publicSourceDir = getResourcePath(); |
| 5094 | if (sourceDir != null) { |
| 5095 | File sourceFile = new File(sourceDir); |
| 5096 | if (!sourceFile.exists()) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5097 | Slog.w(TAG, "Package source " + sourceDir + " does not exist."); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5098 | ret = false; |
| 5099 | } |
| 5100 | // Delete application's code and resources |
| 5101 | sourceFile.delete(); |
| 5102 | } |
| 5103 | if (publicSourceDir != null && !publicSourceDir.equals(sourceDir)) { |
| 5104 | final File publicSourceFile = new File(publicSourceDir); |
| 5105 | if (!publicSourceFile.exists()) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5106 | Slog.w(TAG, "Package public source " + publicSourceFile + " does not exist."); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5107 | } |
| 5108 | if (publicSourceFile.exists()) { |
| 5109 | publicSourceFile.delete(); |
| 5110 | } |
| 5111 | } |
| 5112 | return ret; |
| 5113 | } |
| 5114 | |
| 5115 | void cleanUpResourcesLI() { |
| 5116 | String sourceDir = getCodePath(); |
| 5117 | if (cleanUp() && mInstaller != null) { |
| 5118 | int retCode = mInstaller.rmdex(sourceDir); |
| 5119 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5120 | Slog.w(TAG, "Couldn't remove dex file for package: " |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5121 | + " at location " |
| 5122 | + sourceDir + ", retcode=" + retCode); |
| 5123 | // we don't consider this to be a failure of the core package deletion |
| 5124 | } |
| 5125 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5126 | if (libraryPath != null) { |
| 5127 | removeNativeBinariesLI(new File(libraryPath)); |
| 5128 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5129 | } |
| 5130 | |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5131 | private boolean setPermissions() { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5132 | // 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] | 5133 | if (!isFwdLocked()) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5134 | final int filePermissions = |
| 5135 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP |
| 5136 | |FileUtils.S_IROTH; |
| 5137 | int retCode = FileUtils.setPermissions(getCodePath(), filePermissions, -1, -1); |
| 5138 | if (retCode != 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5139 | Slog.e(TAG, "Couldn't set new package file permissions for " + |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5140 | getCodePath() |
| 5141 | + ". The return code was: " + retCode); |
| 5142 | // TODO Define new internal error |
| 5143 | return false; |
| 5144 | } |
| 5145 | return true; |
| 5146 | } |
| 5147 | return true; |
| 5148 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5149 | |
| 5150 | boolean doPostDeleteLI(boolean delete) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5151 | // XXX err, shouldn't we respect the delete flag? |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5152 | cleanUpResourcesLI(); |
| 5153 | return true; |
| 5154 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5155 | |
| 5156 | private boolean isFwdLocked() { |
| 5157 | return (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0; |
| 5158 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | class SdInstallArgs extends InstallArgs { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5162 | static final String RES_FILE_NAME = "pkg.apk"; |
| 5163 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5164 | String cid; |
| 5165 | String packagePath; |
| 5166 | String libraryPath; |
| 5167 | |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5168 | SdInstallArgs(InstallParams params) { |
| 5169 | super(params.packageURI, params.observer, |
| 5170 | params.flags, params.installerPackageName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5171 | } |
| 5172 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5173 | SdInstallArgs(String fullCodePath, String fullResourcePath, String nativeLibraryPath) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5174 | super(null, null, PackageManager.INSTALL_EXTERNAL, null); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5175 | // Extract cid from fullCodePath |
| 5176 | int eidx = fullCodePath.lastIndexOf("/"); |
| 5177 | String subStr1 = fullCodePath.substring(0, eidx); |
| 5178 | int sidx = subStr1.lastIndexOf("/"); |
| 5179 | cid = subStr1.substring(sidx+1, eidx); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5180 | setCachePath(subStr1); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5181 | } |
| 5182 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5183 | SdInstallArgs(String cid) { |
| Dianne Hackborn | aa77de1 | 2010-05-14 22:33:54 -0700 | [diff] [blame] | 5184 | super(null, null, PackageManager.INSTALL_EXTERNAL, null); |
| 5185 | this.cid = cid; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5186 | setCachePath(PackageHelper.getSdDir(cid)); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5187 | } |
| 5188 | |
| 5189 | SdInstallArgs(Uri packageURI, String cid) { |
| 5190 | super(packageURI, null, PackageManager.INSTALL_EXTERNAL, null); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5191 | this.cid = cid; |
| 5192 | } |
| 5193 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5194 | void createCopyFile() { |
| 5195 | cid = getTempContainerId(); |
| 5196 | } |
| 5197 | |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 5198 | boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException { |
| 5199 | return imcs.checkFreeStorage(true, packageURI); |
| 5200 | } |
| 5201 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5202 | int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5203 | if (temp) { |
| 5204 | createCopyFile(); |
| 5205 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5206 | String newCachePath = imcs.copyResourceToContainer( |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5207 | packageURI, cid, |
| 5208 | getEncryptKey(), RES_FILE_NAME); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5209 | if (newCachePath != null) { |
| 5210 | setCachePath(newCachePath); |
| 5211 | return PackageManager.INSTALL_SUCCEEDED; |
| 5212 | } else { |
| 5213 | return PackageManager.INSTALL_FAILED_CONTAINER_ERROR; |
| 5214 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5215 | } |
| 5216 | |
| 5217 | @Override |
| 5218 | String getCodePath() { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5219 | return packagePath; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | @Override |
| 5223 | String getResourcePath() { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5224 | return packagePath; |
| 5225 | } |
| 5226 | |
| 5227 | @Override |
| 5228 | String getNativeLibraryPath() { |
| 5229 | return libraryPath; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5230 | } |
| 5231 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5232 | int doPreInstall(int status) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5233 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5234 | // Destroy container |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5235 | PackageHelper.destroySdDir(cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5236 | } else { |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5237 | boolean mounted = PackageHelper.isContainerMounted(cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5238 | if (!mounted) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5239 | String newCachePath = PackageHelper.mountSdDir(cid, getEncryptKey(), |
| 5240 | Process.SYSTEM_UID); |
| 5241 | if (newCachePath != null) { |
| 5242 | setCachePath(newCachePath); |
| 5243 | } else { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5244 | return PackageManager.INSTALL_FAILED_CONTAINER_ERROR; |
| 5245 | } |
| 5246 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5247 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5248 | return status; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5249 | } |
| 5250 | |
| 5251 | boolean doRename(int status, final String pkgName, |
| 5252 | String oldCodePath) { |
| 5253 | String newCacheId = getNextCodePath(oldCodePath, pkgName, "/" + RES_FILE_NAME); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5254 | String newCachePath = null; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5255 | if (PackageHelper.isContainerMounted(cid)) { |
| 5256 | // Unmount the container |
| 5257 | if (!PackageHelper.unMountSdDir(cid)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5258 | Slog.i(TAG, "Failed to unmount " + cid + " before renaming"); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5259 | return false; |
| 5260 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5261 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5262 | if (!PackageHelper.renameSdDir(cid, newCacheId)) { |
| Suchi Amalapurapu | c7537ee | 2010-03-24 09:27:19 -0700 | [diff] [blame] | 5263 | Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId + |
| 5264 | " which might be stale. Will try to clean up."); |
| 5265 | // Clean up the stale container and proceed to recreate. |
| 5266 | if (!PackageHelper.destroySdDir(newCacheId)) { |
| 5267 | Slog.e(TAG, "Very strange. Cannot clean up stale container " + newCacheId); |
| 5268 | return false; |
| 5269 | } |
| 5270 | // Successfully cleaned up stale container. Try to rename again. |
| 5271 | if (!PackageHelper.renameSdDir(cid, newCacheId)) { |
| 5272 | Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId |
| 5273 | + " inspite of cleaning it up."); |
| 5274 | return false; |
| 5275 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5276 | } |
| 5277 | if (!PackageHelper.isContainerMounted(newCacheId)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5278 | Slog.w(TAG, "Mounting container " + newCacheId); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5279 | newCachePath = PackageHelper.mountSdDir(newCacheId, |
| 5280 | getEncryptKey(), Process.SYSTEM_UID); |
| 5281 | } else { |
| 5282 | newCachePath = PackageHelper.getSdDir(newCacheId); |
| 5283 | } |
| 5284 | if (newCachePath == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5285 | Slog.w(TAG, "Failed to get cache path for " + newCacheId); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5286 | return false; |
| 5287 | } |
| 5288 | Log.i(TAG, "Succesfully renamed " + cid + |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5289 | " to " + newCacheId + |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5290 | " at new path: " + newCachePath); |
| 5291 | cid = newCacheId; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5292 | setCachePath(newCachePath); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5293 | return true; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5294 | } |
| 5295 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5296 | private void setCachePath(String newCachePath) { |
| 5297 | File cachePath = new File(newCachePath); |
| 5298 | libraryPath = new File(cachePath, LIB_DIR_NAME).getPath(); |
| 5299 | packagePath = new File(cachePath, RES_FILE_NAME).getPath(); |
| 5300 | } |
| 5301 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5302 | int doPostInstall(int status) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5303 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5304 | cleanUp(); |
| 5305 | } else { |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5306 | boolean mounted = PackageHelper.isContainerMounted(cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5307 | if (!mounted) { |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5308 | PackageHelper.mountSdDir(cid, |
| 5309 | getEncryptKey(), Process.myUid()); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5310 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5311 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5312 | return status; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | private void cleanUp() { |
| 5316 | // Destroy secure container |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5317 | PackageHelper.destroySdDir(cid); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | void cleanUpResourcesLI() { |
| 5321 | String sourceFile = getCodePath(); |
| 5322 | // Remove dex file |
| 5323 | if (mInstaller != null) { |
| Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 5324 | int retCode = mInstaller.rmdex(sourceFile); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5325 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5326 | Slog.w(TAG, "Couldn't remove dex file for package: " |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5327 | + " at location " |
| 5328 | + sourceFile.toString() + ", retcode=" + retCode); |
| 5329 | // we don't consider this to be a failure of the core package deletion |
| 5330 | } |
| 5331 | } |
| 5332 | cleanUp(); |
| 5333 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5334 | |
| 5335 | boolean matchContainer(String app) { |
| 5336 | if (cid.startsWith(app)) { |
| 5337 | return true; |
| 5338 | } |
| 5339 | return false; |
| 5340 | } |
| 5341 | |
| 5342 | String getPackageName() { |
| 5343 | int idx = cid.lastIndexOf("-"); |
| 5344 | if (idx == -1) { |
| 5345 | return cid; |
| 5346 | } |
| 5347 | return cid.substring(0, idx); |
| 5348 | } |
| 5349 | |
| 5350 | boolean doPostDeleteLI(boolean delete) { |
| 5351 | boolean ret = false; |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5352 | boolean mounted = PackageHelper.isContainerMounted(cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5353 | if (mounted) { |
| 5354 | // Unmount first |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5355 | ret = PackageHelper.unMountSdDir(cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5356 | } |
| 5357 | if (ret && delete) { |
| 5358 | cleanUpResourcesLI(); |
| 5359 | } |
| 5360 | return ret; |
| 5361 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5362 | }; |
| 5363 | |
| 5364 | // Utility method used to create code paths based on package name and available index. |
| 5365 | private static String getNextCodePath(String oldCodePath, String prefix, String suffix) { |
| 5366 | String idxStr = ""; |
| 5367 | int idx = 1; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5368 | // Fall back to default value of idx=1 if prefix is not |
| 5369 | // part of oldCodePath |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5370 | if (oldCodePath != null) { |
| Bjorn Bringert | 5fd5bfe | 2010-01-29 12:11:30 +0000 | [diff] [blame] | 5371 | String subStr = oldCodePath; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5372 | // Drop the suffix right away |
| Bjorn Bringert | 5fd5bfe | 2010-01-29 12:11:30 +0000 | [diff] [blame] | 5373 | if (subStr.endsWith(suffix)) { |
| 5374 | subStr = subStr.substring(0, subStr.length() - suffix.length()); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5375 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5376 | // If oldCodePath already contains prefix find out the |
| 5377 | // ending index to either increment or decrement. |
| 5378 | int sidx = subStr.lastIndexOf(prefix); |
| 5379 | if (sidx != -1) { |
| 5380 | subStr = subStr.substring(sidx + prefix.length()); |
| 5381 | if (subStr != null) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5382 | if (subStr.startsWith(INSTALL_PACKAGE_SUFFIX)) { |
| 5383 | subStr = subStr.substring(INSTALL_PACKAGE_SUFFIX.length()); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5384 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5385 | try { |
| 5386 | idx = Integer.parseInt(subStr); |
| 5387 | if (idx <= 1) { |
| 5388 | idx++; |
| 5389 | } else { |
| 5390 | idx--; |
| 5391 | } |
| 5392 | } catch(NumberFormatException e) { |
| 5393 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5394 | } |
| 5395 | } |
| 5396 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5397 | idxStr = INSTALL_PACKAGE_SUFFIX + Integer.toString(idx); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5398 | return prefix + idxStr; |
| 5399 | } |
| 5400 | |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5401 | // Utility method used to ignore ADD/REMOVE events |
| 5402 | // by directory observer. |
| 5403 | private static boolean ignoreCodePath(String fullPathStr) { |
| 5404 | String apkName = getApkName(fullPathStr); |
| 5405 | int idx = apkName.lastIndexOf(INSTALL_PACKAGE_SUFFIX); |
| 5406 | if (idx != -1 && ((idx+1) < apkName.length())) { |
| 5407 | // Make sure the package ends with a numeral |
| 5408 | String version = apkName.substring(idx+1); |
| 5409 | try { |
| 5410 | Integer.parseInt(version); |
| 5411 | return true; |
| 5412 | } catch (NumberFormatException e) {} |
| 5413 | } |
| 5414 | return false; |
| 5415 | } |
| 5416 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5417 | // Utility method that returns the relative package path with respect |
| 5418 | // to the installation directory. Like say for /data/data/com.test-1.apk |
| 5419 | // string com.test-1 is returned. |
| 5420 | static String getApkName(String codePath) { |
| 5421 | if (codePath == null) { |
| 5422 | return null; |
| 5423 | } |
| 5424 | int sidx = codePath.lastIndexOf("/"); |
| 5425 | int eidx = codePath.lastIndexOf("."); |
| 5426 | if (eidx == -1) { |
| 5427 | eidx = codePath.length(); |
| 5428 | } else if (eidx == 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5429 | Slog.w(TAG, " Invalid code path, "+ codePath + " Not a valid apk name"); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5430 | return null; |
| 5431 | } |
| 5432 | return codePath.substring(sidx+1, eidx); |
| 5433 | } |
| 5434 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5435 | class PackageInstalledInfo { |
| 5436 | String name; |
| 5437 | int uid; |
| 5438 | PackageParser.Package pkg; |
| 5439 | int returnCode; |
| 5440 | PackageRemovedInfo removedInfo; |
| 5441 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5443 | /* |
| 5444 | * Install a non-existing package. |
| 5445 | */ |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5446 | private void installNewPackageLI(PackageParser.Package pkg, |
| 5447 | int parseFlags, |
| 5448 | int scanMode, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5449 | String installerPackageName, PackageInstalledInfo res) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5450 | // Remember this for later, in case we need to rollback this install |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5451 | String pkgName = pkg.packageName; |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 5452 | |
| Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 5453 | boolean dataDirExists = getDataPathForPackage(pkg).exists(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5454 | res.name = pkgName; |
| 5455 | synchronized(mPackages) { |
| Dianne Hackborn | e259bc7 | 2010-03-30 19:24:44 -0700 | [diff] [blame] | 5456 | if (mSettings.mRenamedPackages.containsKey(pkgName)) { |
| 5457 | // A package with the same name is already installed, though |
| 5458 | // it has been renamed to an older name. The package we |
| 5459 | // are trying to install should be installed as an update to |
| 5460 | // the existing one, but that has not been requested, so bail. |
| 5461 | Slog.w(TAG, "Attempt to re-install " + pkgName |
| 5462 | + " without first uninstalling package running as " |
| 5463 | + mSettings.mRenamedPackages.get(pkgName)); |
| 5464 | res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 5465 | return; |
| 5466 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5467 | if (mPackages.containsKey(pkgName) || mAppDirs.containsKey(pkg.mPath)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5468 | // Don't allow installation over an existing package with the same name. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5469 | Slog.w(TAG, "Attempt to re-install " + pkgName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5470 | + " without first uninstalling."); |
| 5471 | res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 5472 | return; |
| 5473 | } |
| 5474 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5475 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5476 | PackageParser.Package newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5477 | if (newPackage == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5478 | 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] | 5479 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5480 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 5481 | } |
| 5482 | } else { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5483 | updateSettingsLI(newPackage, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5484 | installerPackageName, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5485 | res); |
| 5486 | // delete the partially installed application. the data directory will have to be |
| 5487 | // restored if it was already existing |
| 5488 | if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
| 5489 | // remove package from internal structures. Note that we want deletePackageX to |
| 5490 | // delete the package data and cache directories that it created in |
| 5491 | // scanPackageLocked, unless those directories existed before we even tried to |
| 5492 | // install. |
| 5493 | deletePackageLI( |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5494 | pkgName, false, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5495 | dataDirExists ? PackageManager.DONT_DELETE_DATA : 0, |
| 5496 | res.removedInfo); |
| 5497 | } |
| 5498 | } |
| 5499 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5500 | |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5501 | private void replacePackageLI(PackageParser.Package pkg, |
| 5502 | int parseFlags, |
| 5503 | int scanMode, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5504 | String installerPackageName, PackageInstalledInfo res) { |
| 5505 | |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 5506 | PackageParser.Package oldPackage; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5507 | String pkgName = pkg.packageName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5508 | // First find the old package info and check signatures |
| 5509 | synchronized(mPackages) { |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 5510 | oldPackage = mPackages.get(pkgName); |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5511 | if (checkSignaturesLP(oldPackage.mSignatures, pkg.mSignatures) |
| Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 5512 | != PackageManager.SIGNATURE_MATCH) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5513 | res.returnCode = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 5514 | return; |
| 5515 | } |
| 5516 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5517 | boolean sysPkg = (isSystemApp(oldPackage)); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5518 | if (sysPkg) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5519 | replaceSystemPackageLI(oldPackage, pkg, parseFlags, scanMode, installerPackageName, res); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5520 | } else { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5521 | replaceNonSystemPackageLI(oldPackage, pkg, parseFlags, scanMode, installerPackageName, res); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5522 | } |
| 5523 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5525 | private void replaceNonSystemPackageLI(PackageParser.Package deletedPackage, |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5526 | PackageParser.Package pkg, |
| 5527 | int parseFlags, int scanMode, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5528 | String installerPackageName, PackageInstalledInfo res) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5529 | PackageParser.Package newPackage = null; |
| 5530 | String pkgName = deletedPackage.packageName; |
| 5531 | boolean deletedPkg = true; |
| 5532 | boolean updatedSettings = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5533 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5534 | String oldInstallerPackageName = null; |
| 5535 | synchronized (mPackages) { |
| 5536 | oldInstallerPackageName = mSettings.getInstallerPackageName(pkgName); |
| 5537 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5539 | // First delete the existing package while retaining the data directory |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5540 | if (!deletePackageLI(pkgName, true, PackageManager.DONT_DELETE_DATA, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5541 | res.removedInfo)) { |
| 5542 | // If the existing package was'nt successfully deleted |
| 5543 | res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE; |
| 5544 | deletedPkg = false; |
| 5545 | } else { |
| 5546 | // Successfully deleted the old package. Now proceed with re-installation |
| 5547 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5548 | newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5549 | if (newPackage == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5550 | 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] | 5551 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5552 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
| Suchi Amalapurapu | 110fea7 | 2010-01-14 17:50:23 -0800 | [diff] [blame] | 5553 | } |
| 5554 | } else { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5555 | updateSettingsLI(newPackage, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5556 | installerPackageName, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5557 | res); |
| 5558 | updatedSettings = true; |
| 5559 | } |
| 5560 | } |
| 5561 | |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5562 | if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5563 | // remove package from internal structures. Note that we want deletePackageX to |
| 5564 | // delete the package data and cache directories that it created in |
| 5565 | // scanPackageLocked, unless those directories existed before we even tried to |
| 5566 | // install. |
| 5567 | if(updatedSettings) { |
| 5568 | deletePackageLI( |
| 5569 | pkgName, true, |
| 5570 | PackageManager.DONT_DELETE_DATA, |
| 5571 | res.removedInfo); |
| 5572 | } |
| 5573 | // Since we failed to install the new package we need to restore the old |
| 5574 | // package that we deleted. |
| 5575 | if(deletedPkg) { |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5576 | File restoreFile = new File(deletedPackage.mPath); |
| 5577 | if (restoreFile == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5578 | Slog.e(TAG, "Failed allocating storage when restoring pkg : " + pkgName); |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5579 | return; |
| 5580 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5581 | // Parse old package |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5582 | boolean oldOnSd = isExternal(deletedPackage); |
| 5583 | int oldParseFlags = mDefParseFlags | PackageParser.PARSE_CHATTY | |
| 5584 | (isForwardLocked(deletedPackage) ? PackageParser.PARSE_FORWARD_LOCK : 0) | |
| 5585 | (oldOnSd ? PackageParser.PARSE_ON_SDCARD : 0); |
| 5586 | int oldScanMode = (oldOnSd ? 0 : SCAN_MONITOR) | SCAN_UPDATE_SIGNATURE; |
| 5587 | if (scanPackageLI(restoreFile, oldParseFlags, oldScanMode) == null) { |
| 5588 | Slog.e(TAG, "Failed to restore package : " + pkgName + " after failed upgrade"); |
| 5589 | return; |
| 5590 | } |
| 5591 | // Restore of old package succeeded. Update permissions. |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5592 | synchronized (mPackages) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 5593 | updatePermissionsLP(deletedPackage.packageName, deletedPackage, |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 5594 | true, false, false); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5595 | mSettings.writeLP(); |
| 5596 | } |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5597 | 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] | 5598 | } |
| 5599 | } |
| 5600 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5602 | private void replaceSystemPackageLI(PackageParser.Package deletedPackage, |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5603 | PackageParser.Package pkg, |
| 5604 | int parseFlags, int scanMode, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5605 | String installerPackageName, PackageInstalledInfo res) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5606 | PackageParser.Package newPackage = null; |
| 5607 | boolean updatedSettings = false; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5608 | parseFlags |= PackageManager.INSTALL_REPLACE_EXISTING | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5609 | PackageParser.PARSE_IS_SYSTEM; |
| 5610 | String packageName = deletedPackage.packageName; |
| 5611 | res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE; |
| 5612 | if (packageName == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5613 | Slog.w(TAG, "Attempt to delete null packageName."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5614 | return; |
| 5615 | } |
| 5616 | PackageParser.Package oldPkg; |
| 5617 | PackageSetting oldPkgSetting; |
| 5618 | synchronized (mPackages) { |
| 5619 | oldPkg = mPackages.get(packageName); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5620 | oldPkgSetting = mSettings.mPackages.get(packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5621 | if((oldPkg == null) || (oldPkg.applicationInfo == null) || |
| 5622 | (oldPkgSetting == null)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5623 | Slog.w(TAG, "Couldn't find package:"+packageName+" information"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5624 | return; |
| 5625 | } |
| 5626 | } |
| 5627 | res.removedInfo.uid = oldPkg.applicationInfo.uid; |
| 5628 | res.removedInfo.removedPackage = packageName; |
| 5629 | // Remove existing system package |
| 5630 | removePackageLI(oldPkg, true); |
| 5631 | synchronized (mPackages) { |
| 5632 | res.removedInfo.removedUid = mSettings.disableSystemPackageLP(packageName); |
| 5633 | } |
| 5634 | |
| 5635 | // Successfully disabled the old package. Now proceed with re-installation |
| 5636 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
| 5637 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5638 | newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5639 | if (newPackage == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5640 | 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] | 5641 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5642 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 5643 | } |
| 5644 | } else { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5645 | updateSettingsLI(newPackage, installerPackageName, res); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5646 | updatedSettings = true; |
| 5647 | } |
| 5648 | |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5649 | if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5650 | // Re installation failed. Restore old information |
| 5651 | // Remove new pkg information |
| Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 5652 | if (newPackage != null) { |
| 5653 | removePackageLI(newPackage, true); |
| 5654 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5655 | // Add back the old system package |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5656 | scanPackageLI(oldPkg, parseFlags, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5657 | SCAN_MONITOR |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5658 | | SCAN_UPDATE_SIGNATURE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5659 | // Restore the old system information in Settings |
| 5660 | synchronized(mPackages) { |
| 5661 | if(updatedSettings) { |
| 5662 | mSettings.enableSystemPackageLP(packageName); |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5663 | mSettings.setInstallerPackageName(packageName, |
| 5664 | oldPkgSetting.installerPackageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5665 | } |
| 5666 | mSettings.writeLP(); |
| 5667 | } |
| Suchi Amalapurapu | c1d07d9 | 2010-05-05 13:37:12 -0700 | [diff] [blame] | 5668 | } else { |
| 5669 | // If this is an update to an existing update, setup |
| 5670 | // to remove the existing update. |
| 5671 | synchronized (mPackages) { |
| 5672 | PackageSetting ps = mSettings.getDisabledSystemPkg(packageName); |
| 5673 | if (ps != null && ps.codePathString != null && |
| 5674 | !ps.codePathString.equals(oldPkgSetting.codePathString)) { |
| 5675 | int installFlags = 0; |
| 5676 | res.removedInfo.args = createInstallArgs(0, oldPkgSetting.codePathString, |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5677 | oldPkgSetting.resourcePathString, oldPkgSetting.nativeLibraryPathString); |
| Suchi Amalapurapu | c1d07d9 | 2010-05-05 13:37:12 -0700 | [diff] [blame] | 5678 | } |
| 5679 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5680 | } |
| 5681 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5682 | |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5683 | // Utility method used to move dex files during install. |
| Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 5684 | private int moveDexFilesLI(PackageParser.Package newPackage) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5685 | int retCode; |
| 5686 | if ((newPackage.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 5687 | retCode = mInstaller.movedex(newPackage.mScanPath, newPackage.mPath); |
| 5688 | if (retCode != 0) { |
| Kenny Root | e2f7417 | 2010-08-04 13:35:33 -0700 | [diff] [blame] | 5689 | if (mNoDexOpt) { |
| 5690 | /* |
| 5691 | * If we're in an engineering build, programs are lazily run |
| 5692 | * through dexopt. If the .dex file doesn't exist yet, it |
| 5693 | * will be created when the program is run next. |
| 5694 | */ |
| 5695 | Slog.i(TAG, "dex file doesn't exist, skipping move: " + newPackage.mPath); |
| 5696 | } else { |
| 5697 | Slog.e(TAG, "Couldn't rename dex file: " + newPackage.mPath); |
| 5698 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5699 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5700 | } |
| 5701 | } |
| 5702 | return PackageManager.INSTALL_SUCCEEDED; |
| 5703 | } |
| 5704 | |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5705 | private void updateSettingsLI(PackageParser.Package newPackage, |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5706 | String installerPackageName, PackageInstalledInfo res) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5707 | String pkgName = newPackage.packageName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5708 | synchronized (mPackages) { |
| 5709 | //write settings. the installStatus will be incomplete at this stage. |
| 5710 | //note that the new package setting would have already been |
| 5711 | //added to mPackages. It hasn't been persisted yet. |
| 5712 | mSettings.setInstallStatus(pkgName, PKG_INSTALL_INCOMPLETE); |
| 5713 | mSettings.writeLP(); |
| 5714 | } |
| 5715 | |
| Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 5716 | if ((res.returnCode = moveDexFilesLI(newPackage)) |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5717 | != PackageManager.INSTALL_SUCCEEDED) { |
| 5718 | // Discontinue if moving dex files failed. |
| 5719 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5720 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5721 | if((res.returnCode = setPermissionsLI(newPackage)) |
| 5722 | != PackageManager.INSTALL_SUCCEEDED) { |
| 5723 | if (mInstaller != null) { |
| 5724 | mInstaller.rmdex(newPackage.mScanPath); |
| 5725 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5726 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5727 | } else { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5728 | Log.d(TAG, "New package installed in " + newPackage.mPath); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5729 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5730 | synchronized (mPackages) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 5731 | updatePermissionsLP(newPackage.packageName, newPackage, |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 5732 | newPackage.permissions.size() > 0, true, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5733 | res.name = pkgName; |
| 5734 | res.uid = newPackage.applicationInfo.uid; |
| 5735 | res.pkg = newPackage; |
| 5736 | mSettings.setInstallStatus(pkgName, PKG_INSTALL_COMPLETE); |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5737 | mSettings.setInstallerPackageName(pkgName, installerPackageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5738 | res.returnCode = PackageManager.INSTALL_SUCCEEDED; |
| 5739 | //to update install status |
| 5740 | mSettings.writeLP(); |
| 5741 | } |
| 5742 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5743 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5744 | private void installPackageLI(InstallArgs args, |
| 5745 | boolean newInstall, PackageInstalledInfo res) { |
| 5746 | int pFlags = args.flags; |
| 5747 | String installerPackageName = args.installerPackageName; |
| 5748 | File tmpPackageFile = new File(args.getCodePath()); |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5749 | boolean forwardLocked = ((pFlags & PackageManager.INSTALL_FORWARD_LOCK) != 0); |
| Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5750 | boolean onSd = ((pFlags & PackageManager.INSTALL_EXTERNAL) != 0); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5751 | boolean replace = false; |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5752 | int scanMode = (onSd ? 0 : SCAN_MONITOR) | SCAN_FORCE_DEX | SCAN_UPDATE_SIGNATURE |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5753 | | (newInstall ? SCAN_NEW_INSTALL : 0); |
| Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5754 | // Result object to be returned |
| 5755 | res.returnCode = PackageManager.INSTALL_SUCCEEDED; |
| 5756 | |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5757 | // Retrieve PackageSettings and parse package |
| 5758 | int parseFlags = PackageParser.PARSE_CHATTY | |
| 5759 | (forwardLocked ? PackageParser.PARSE_FORWARD_LOCK : 0) | |
| 5760 | (onSd ? PackageParser.PARSE_ON_SDCARD : 0); |
| 5761 | parseFlags |= mDefParseFlags; |
| 5762 | PackageParser pp = new PackageParser(tmpPackageFile.getPath()); |
| 5763 | pp.setSeparateProcesses(mSeparateProcesses); |
| 5764 | final PackageParser.Package pkg = pp.parsePackage(tmpPackageFile, |
| 5765 | null, mMetrics, parseFlags); |
| 5766 | if (pkg == null) { |
| 5767 | res.returnCode = pp.getParseError(); |
| 5768 | return; |
| 5769 | } |
| 5770 | String pkgName = res.name = pkg.packageName; |
| 5771 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_TEST_ONLY) != 0) { |
| 5772 | if ((pFlags&PackageManager.INSTALL_ALLOW_TEST) == 0) { |
| 5773 | res.returnCode = PackageManager.INSTALL_FAILED_TEST_ONLY; |
| 5774 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5775 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5776 | } |
| 5777 | if (GET_CERTIFICATES && !pp.collectCertificates(pkg, parseFlags)) { |
| 5778 | res.returnCode = pp.getParseError(); |
| 5779 | return; |
| 5780 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5781 | // Get rid of all references to package scan path via parser. |
| 5782 | pp = null; |
| 5783 | String oldCodePath = null; |
| 5784 | boolean systemApp = false; |
| 5785 | synchronized (mPackages) { |
| 5786 | // Check if installing already existing package |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5787 | if ((pFlags&PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
| 5788 | String oldName = mSettings.mRenamedPackages.get(pkgName); |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 5789 | if (pkg.mOriginalPackages != null |
| 5790 | && pkg.mOriginalPackages.contains(oldName) |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5791 | && mPackages.containsKey(oldName)) { |
| 5792 | // This package is derived from an original package, |
| 5793 | // and this device has been updating from that original |
| 5794 | // name. We must continue using the original name, so |
| 5795 | // rename the new package here. |
| Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 5796 | pkg.setPackageName(oldName); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5797 | pkgName = pkg.packageName; |
| 5798 | replace = true; |
| 5799 | } else if (mPackages.containsKey(pkgName)) { |
| 5800 | // This package, under its official name, already exists |
| 5801 | // on the device; we should replace it. |
| 5802 | replace = true; |
| 5803 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5804 | } |
| 5805 | PackageSetting ps = mSettings.mPackages.get(pkgName); |
| 5806 | if (ps != null) { |
| 5807 | oldCodePath = mSettings.mPackages.get(pkgName).codePathString; |
| 5808 | if (ps.pkg != null && ps.pkg.applicationInfo != null) { |
| 5809 | systemApp = (ps.pkg.applicationInfo.flags & |
| 5810 | ApplicationInfo.FLAG_SYSTEM) != 0; |
| Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 5811 | } |
| 5812 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5813 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5814 | |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5815 | if (systemApp && onSd) { |
| 5816 | // Disable updates to system apps on sdcard |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5817 | Slog.w(TAG, "Cannot install updates to system apps on sdcard"); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5818 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 5819 | return; |
| 5820 | } |
| Suchi Amalapurapu | cf6eaea | 2010-02-23 19:37:45 -0800 | [diff] [blame] | 5821 | |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5822 | if (!args.doRename(res.returnCode, pkgName, oldCodePath)) { |
| 5823 | res.returnCode = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5824 | return; |
| 5825 | } |
| 5826 | // Set application objects path explicitly after the rename |
| 5827 | setApplicationInfoPaths(pkg, args.getCodePath(), args.getResourcePath()); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5828 | pkg.applicationInfo.nativeLibraryDir = args.getNativeLibraryPath(); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5829 | if (replace) { |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5830 | replacePackageLI(pkg, parseFlags, scanMode, |
| 5831 | installerPackageName, res); |
| 5832 | } else { |
| 5833 | installNewPackageLI(pkg, parseFlags, scanMode, |
| 5834 | installerPackageName,res); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5835 | } |
| 5836 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5837 | |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5838 | private int setPermissionsLI(PackageParser.Package newPackage) { |
| 5839 | String pkgName = newPackage.packageName; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5840 | int retCode = 0; |
| 5841 | // TODO Gross hack but fix later. Ideally move this to be a post installation |
| 5842 | // check after alloting uid. |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5843 | if (isForwardLocked(newPackage)) { |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5844 | File destResourceFile = new File(newPackage.applicationInfo.publicSourceDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5845 | try { |
| 5846 | extractPublicFiles(newPackage, destResourceFile); |
| 5847 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5848 | 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] | 5849 | " forward-locked app."); |
| 5850 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5851 | } finally { |
| 5852 | //TODO clean up the extracted public files |
| 5853 | } |
| 5854 | if (mInstaller != null) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5855 | retCode = mInstaller.setForwardLockPerm(getApkName(newPackage.mPath), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5856 | newPackage.applicationInfo.uid); |
| 5857 | } else { |
| 5858 | final int filePermissions = |
| 5859 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5860 | retCode = FileUtils.setPermissions(newPackage.mPath, filePermissions, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5861 | newPackage.applicationInfo.uid); |
| 5862 | } |
| 5863 | } else { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5864 | // The permissions on the resource file was set when it was copied for |
| 5865 | // non forward locked apps and apps on sdcard |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5866 | } |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5867 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5868 | if (retCode != 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5869 | Slog.e(TAG, "Couldn't set new package file permissions for " + |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5870 | newPackage.mPath |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5871 | + ". The return code was: " + retCode); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5872 | // TODO Define new internal error |
| 5873 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5874 | } |
| 5875 | return PackageManager.INSTALL_SUCCEEDED; |
| 5876 | } |
| 5877 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5878 | private static boolean isForwardLocked(PackageParser.Package pkg) { |
| 5879 | return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5880 | } |
| 5881 | |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 5882 | private static boolean isExternal(PackageParser.Package pkg) { |
| 5883 | return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0; |
| 5884 | } |
| 5885 | |
| 5886 | private static boolean isSystemApp(PackageParser.Package pkg) { |
| 5887 | return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; |
| 5888 | } |
| 5889 | |
| 5890 | private static boolean isUpdatedSystemApp(PackageParser.Package pkg) { |
| 5891 | return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5892 | } |
| 5893 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5894 | private void extractPublicFiles(PackageParser.Package newPackage, |
| 5895 | File publicZipFile) throws IOException { |
| 5896 | final ZipOutputStream publicZipOutStream = |
| 5897 | new ZipOutputStream(new FileOutputStream(publicZipFile)); |
| 5898 | final ZipFile privateZip = new ZipFile(newPackage.mPath); |
| 5899 | |
| 5900 | // Copy manifest, resources.arsc and res directory to public zip |
| 5901 | |
| 5902 | final Enumeration<? extends ZipEntry> privateZipEntries = privateZip.entries(); |
| 5903 | while (privateZipEntries.hasMoreElements()) { |
| 5904 | final ZipEntry zipEntry = privateZipEntries.nextElement(); |
| 5905 | final String zipEntryName = zipEntry.getName(); |
| 5906 | if ("AndroidManifest.xml".equals(zipEntryName) |
| 5907 | || "resources.arsc".equals(zipEntryName) |
| 5908 | || zipEntryName.startsWith("res/")) { |
| 5909 | try { |
| 5910 | copyZipEntry(zipEntry, privateZip, publicZipOutStream); |
| 5911 | } catch (IOException e) { |
| 5912 | try { |
| 5913 | publicZipOutStream.close(); |
| 5914 | throw e; |
| 5915 | } finally { |
| 5916 | publicZipFile.delete(); |
| 5917 | } |
| 5918 | } |
| 5919 | } |
| 5920 | } |
| 5921 | |
| 5922 | publicZipOutStream.close(); |
| 5923 | FileUtils.setPermissions( |
| 5924 | publicZipFile.getAbsolutePath(), |
| 5925 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP|FileUtils.S_IROTH, |
| 5926 | -1, -1); |
| 5927 | } |
| 5928 | |
| 5929 | private static void copyZipEntry(ZipEntry zipEntry, |
| 5930 | ZipFile inZipFile, |
| 5931 | ZipOutputStream outZipStream) throws IOException { |
| 5932 | byte[] buffer = new byte[4096]; |
| 5933 | int num; |
| 5934 | |
| 5935 | ZipEntry newEntry; |
| 5936 | if (zipEntry.getMethod() == ZipEntry.STORED) { |
| 5937 | // Preserve the STORED method of the input entry. |
| 5938 | newEntry = new ZipEntry(zipEntry); |
| 5939 | } else { |
| 5940 | // Create a new entry so that the compressed len is recomputed. |
| 5941 | newEntry = new ZipEntry(zipEntry.getName()); |
| 5942 | } |
| 5943 | outZipStream.putNextEntry(newEntry); |
| 5944 | |
| 5945 | InputStream data = inZipFile.getInputStream(zipEntry); |
| 5946 | while ((num = data.read(buffer)) > 0) { |
| 5947 | outZipStream.write(buffer, 0, num); |
| 5948 | } |
| 5949 | outZipStream.flush(); |
| 5950 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5951 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5952 | private void deleteTempPackageFiles() { |
| 5953 | FilenameFilter filter = new FilenameFilter() { |
| 5954 | public boolean accept(File dir, String name) { |
| 5955 | return name.startsWith("vmdl") && name.endsWith(".tmp"); |
| 5956 | } |
| 5957 | }; |
| 5958 | String tmpFilesList[] = mAppInstallDir.list(filter); |
| 5959 | if(tmpFilesList == null) { |
| 5960 | return; |
| 5961 | } |
| 5962 | for(int i = 0; i < tmpFilesList.length; i++) { |
| 5963 | File tmpFile = new File(mAppInstallDir, tmpFilesList[i]); |
| 5964 | tmpFile.delete(); |
| 5965 | } |
| 5966 | } |
| 5967 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5968 | private File createTempPackageFile(File installDir) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5969 | File tmpPackageFile; |
| 5970 | try { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5971 | tmpPackageFile = File.createTempFile("vmdl", ".tmp", installDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5972 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5973 | 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] | 5974 | return null; |
| 5975 | } |
| 5976 | try { |
| 5977 | FileUtils.setPermissions( |
| 5978 | tmpPackageFile.getCanonicalPath(), FileUtils.S_IRUSR|FileUtils.S_IWUSR, |
| 5979 | -1, -1); |
| 5980 | } catch (IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5981 | 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] | 5982 | return null; |
| 5983 | } |
| 5984 | return tmpPackageFile; |
| 5985 | } |
| 5986 | |
| 5987 | public void deletePackage(final String packageName, |
| 5988 | final IPackageDeleteObserver observer, |
| 5989 | final int flags) { |
| 5990 | mContext.enforceCallingOrSelfPermission( |
| 5991 | android.Manifest.permission.DELETE_PACKAGES, null); |
| 5992 | // Queue up an async operation since the package deletion may take a little while. |
| 5993 | mHandler.post(new Runnable() { |
| 5994 | public void run() { |
| 5995 | mHandler.removeCallbacks(this); |
| 5996 | final boolean succeded = deletePackageX(packageName, true, true, flags); |
| 5997 | if (observer != null) { |
| 5998 | try { |
| 5999 | observer.packageDeleted(succeded); |
| 6000 | } catch (RemoteException e) { |
| 6001 | Log.i(TAG, "Observer no longer exists."); |
| 6002 | } //end catch |
| 6003 | } //end if |
| 6004 | } //end run |
| 6005 | }); |
| 6006 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6007 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6008 | /** |
| 6009 | * This method is an internal method that could be get invoked either |
| 6010 | * to delete an installed package or to clean up a failed installation. |
| 6011 | * After deleting an installed package, a broadcast is sent to notify any |
| 6012 | * listeners that the package has been installed. For cleaning up a failed |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6013 | * 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] | 6014 | * installation wouldn't have sent the initial broadcast either |
| 6015 | * The key steps in deleting a package are |
| 6016 | * deleting the package information in internal structures like mPackages, |
| 6017 | * deleting the packages base directories through installd |
| 6018 | * updating mSettings to reflect current status |
| 6019 | * persisting settings for later use |
| 6020 | * sending a broadcast if necessary |
| 6021 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6022 | private boolean deletePackageX(String packageName, boolean sendBroadCast, |
| 6023 | boolean deleteCodeAndResources, int flags) { |
| 6024 | PackageRemovedInfo info = new PackageRemovedInfo(); |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6025 | boolean res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6026 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 6027 | IDevicePolicyManager dpm = IDevicePolicyManager.Stub.asInterface( |
| 6028 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 6029 | try { |
| 6030 | if (dpm != null && dpm.packageHasActiveAdmins(packageName)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6031 | Slog.w(TAG, "Not removing package " + packageName + ": has active device admin"); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 6032 | return false; |
| 6033 | } |
| 6034 | } catch (RemoteException e) { |
| 6035 | } |
| 6036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6037 | synchronized (mInstallLock) { |
| Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6038 | res = deletePackageLI(packageName, deleteCodeAndResources, |
| 6039 | flags | REMOVE_CHATTY, info); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6040 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6041 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6042 | if(res && sendBroadCast) { |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6043 | boolean systemUpdate = info.isRemovedPackageSystemUpdate; |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6044 | info.sendBroadcast(deleteCodeAndResources, systemUpdate); |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6045 | |
| 6046 | // If the removed package was a system update, the old system packaged |
| 6047 | // was re-enabled; we need to broadcast this information |
| 6048 | if (systemUpdate) { |
| 6049 | Bundle extras = new Bundle(1); |
| 6050 | extras.putInt(Intent.EXTRA_UID, info.removedUid >= 0 ? info.removedUid : info.uid); |
| 6051 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 6052 | |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 6053 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName, extras, null); |
| 6054 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, packageName, extras, null); |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6055 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6056 | } |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6057 | // Force a gc here. |
| 6058 | Runtime.getRuntime().gc(); |
| 6059 | // Delete the resources here after sending the broadcast to let |
| 6060 | // other processes clean up before deleting resources. |
| 6061 | if (info.args != null) { |
| 6062 | synchronized (mInstallLock) { |
| 6063 | info.args.doPostDeleteLI(deleteCodeAndResources); |
| 6064 | } |
| 6065 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6066 | return res; |
| 6067 | } |
| 6068 | |
| 6069 | static class PackageRemovedInfo { |
| 6070 | String removedPackage; |
| 6071 | int uid = -1; |
| 6072 | int removedUid = -1; |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6073 | boolean isRemovedPackageSystemUpdate = false; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6074 | // Clean up resources deleted packages. |
| 6075 | InstallArgs args = null; |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6076 | |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6077 | void sendBroadcast(boolean fullRemove, boolean replacing) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6078 | Bundle extras = new Bundle(1); |
| 6079 | extras.putInt(Intent.EXTRA_UID, removedUid >= 0 ? removedUid : uid); |
| 6080 | extras.putBoolean(Intent.EXTRA_DATA_REMOVED, fullRemove); |
| 6081 | if (replacing) { |
| 6082 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 6083 | } |
| 6084 | if (removedPackage != null) { |
| Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6085 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage, extras, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6086 | } |
| 6087 | if (removedUid >= 0) { |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 6088 | sendPackageBroadcast(Intent.ACTION_UID_REMOVED, null, extras, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6089 | } |
| 6090 | } |
| 6091 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6092 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6093 | /* |
| 6094 | * This method deletes the package from internal data structures. If the DONT_DELETE_DATA |
| 6095 | * flag is not set, the data directory is removed as well. |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6096 | * 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] | 6097 | * delete a partially installed application. |
| 6098 | */ |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6099 | private void removePackageDataLI(PackageParser.Package p, PackageRemovedInfo outInfo, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6100 | int flags) { |
| 6101 | String packageName = p.packageName; |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6102 | if (outInfo != null) { |
| 6103 | outInfo.removedPackage = packageName; |
| 6104 | } |
| Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6105 | removePackageLI(p, (flags&REMOVE_CHATTY) != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6106 | // Retrieve object to delete permissions for shared user later on |
| 6107 | PackageSetting deletedPs; |
| 6108 | synchronized (mPackages) { |
| 6109 | deletedPs = mSettings.mPackages.get(packageName); |
| 6110 | } |
| 6111 | if ((flags&PackageManager.DONT_DELETE_DATA) == 0) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6112 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6113 | if (mInstaller != null) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6114 | int retCode = mInstaller.remove(packageName, useEncryptedFSDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6115 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6116 | 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] | 6117 | + packageName + ", retcode=" + retCode); |
| 6118 | // we don't consider this to be a failure of the core package deletion |
| 6119 | } |
| 6120 | } else { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6121 | // for simulator |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6122 | PackageParser.Package pkg = mPackages.get(packageName); |
| 6123 | File dataDir = new File(pkg.applicationInfo.dataDir); |
| 6124 | dataDir.delete(); |
| 6125 | } |
| Dianne Hackborn | fb1f103 | 2010-07-29 13:57:56 -0700 | [diff] [blame] | 6126 | schedulePackageCleaning(packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6127 | } |
| 6128 | synchronized (mPackages) { |
| Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 6129 | if (deletedPs != null) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6130 | if ((flags&PackageManager.DONT_DELETE_DATA) == 0) { |
| 6131 | if (outInfo != null) { |
| 6132 | outInfo.removedUid = mSettings.removePackageLP(packageName); |
| 6133 | } |
| 6134 | if (deletedPs != null) { |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 6135 | updatePermissionsLP(deletedPs.name, null, false, false, false); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6136 | if (deletedPs.sharedUser != null) { |
| 6137 | // remove permissions associated with package |
| 6138 | mSettings.updateSharedUserPermsLP(deletedPs, mGlobalGids); |
| 6139 | } |
| 6140 | } |
| 6141 | } |
| Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 6142 | // remove from preferred activities. |
| 6143 | ArrayList<PreferredActivity> removed = new ArrayList<PreferredActivity>(); |
| 6144 | for (PreferredActivity pa : mSettings.mPreferredActivities.filterSet()) { |
| 6145 | if (pa.mActivity.getPackageName().equals(deletedPs.name)) { |
| 6146 | removed.add(pa); |
| 6147 | } |
| 6148 | } |
| 6149 | for (PreferredActivity pa : removed) { |
| 6150 | mSettings.mPreferredActivities.removeFilter(pa); |
| 6151 | } |
| 6152 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6153 | // Save settings now |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 6154 | mSettings.writeLP(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6155 | } |
| 6156 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6157 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6158 | /* |
| 6159 | * Tries to delete system package. |
| 6160 | */ |
| 6161 | private boolean deleteSystemPackageLI(PackageParser.Package p, |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6162 | int flags, PackageRemovedInfo outInfo) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6163 | ApplicationInfo applicationInfo = p.applicationInfo; |
| 6164 | //applicable for non-partially installed applications only |
| 6165 | if (applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6166 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6167 | return false; |
| 6168 | } |
| 6169 | PackageSetting ps = null; |
| 6170 | // Confirm if the system package has been updated |
| 6171 | // An updated system app can be deleted. This will also have to restore |
| 6172 | // the system pkg from system partition |
| 6173 | synchronized (mPackages) { |
| 6174 | ps = mSettings.getDisabledSystemPkg(p.packageName); |
| 6175 | } |
| 6176 | if (ps == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6177 | 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] | 6178 | return false; |
| 6179 | } else { |
| 6180 | Log.i(TAG, "Deleting system pkg from data partition"); |
| 6181 | } |
| 6182 | // Delete the updated package |
| Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6183 | outInfo.isRemovedPackageSystemUpdate = true; |
| Kenny Root | 7c1bd7f | 2010-09-01 13:44:11 -0700 | [diff] [blame] | 6184 | final boolean deleteCodeAndResources; |
| 6185 | if (ps.versionCode < p.mVersionCode) { |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6186 | // Delete code and resources for downgrades |
| 6187 | deleteCodeAndResources = true; |
| Kenny Root | 7c1bd7f | 2010-09-01 13:44:11 -0700 | [diff] [blame] | 6188 | flags &= ~PackageManager.DONT_DELETE_DATA; |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6189 | } else { |
| 6190 | // Preserve data by setting flag |
| Kenny Root | 7c1bd7f | 2010-09-01 13:44:11 -0700 | [diff] [blame] | 6191 | deleteCodeAndResources = false; |
| 6192 | flags |= PackageManager.DONT_DELETE_DATA; |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6193 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | boolean ret = deleteInstalledPackageLI(p, deleteCodeAndResources, flags, outInfo); |
| 6195 | if (!ret) { |
| 6196 | return false; |
| 6197 | } |
| 6198 | synchronized (mPackages) { |
| 6199 | // Reinstate the old system package |
| 6200 | mSettings.enableSystemPackageLP(p.packageName); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6201 | // Remove any native libraries. XXX needed? |
| David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 6202 | removeNativeBinariesLI(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6203 | } |
| 6204 | // Install the system package |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6205 | PackageParser.Package newPkg = scanPackageLI(ps.codePath, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6206 | PackageParser.PARSE_MUST_BE_APK | PackageParser.PARSE_IS_SYSTEM, |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6207 | SCAN_MONITOR | SCAN_NO_PATHS); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6208 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | if (newPkg == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6210 | 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] | 6211 | return false; |
| 6212 | } |
| 6213 | synchronized (mPackages) { |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 6214 | updatePermissionsLP(newPkg.packageName, newPkg, true, true, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6215 | mSettings.writeLP(); |
| 6216 | } |
| 6217 | return true; |
| 6218 | } |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6219 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6220 | private boolean deleteInstalledPackageLI(PackageParser.Package p, |
| 6221 | boolean deleteCodeAndResources, int flags, PackageRemovedInfo outInfo) { |
| 6222 | ApplicationInfo applicationInfo = p.applicationInfo; |
| 6223 | if (applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6224 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6225 | return false; |
| 6226 | } |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6227 | if (outInfo != null) { |
| 6228 | outInfo.uid = applicationInfo.uid; |
| 6229 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6230 | |
| 6231 | // Delete package data from internal structures and also remove data if flag is set |
| 6232 | removePackageDataLI(p, outInfo, flags); |
| 6233 | |
| 6234 | // Delete application code and resources |
| 6235 | if (deleteCodeAndResources) { |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6236 | // TODO can pick up from PackageSettings as well |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6237 | int installFlags = isExternal(p) ? PackageManager.INSTALL_EXTERNAL : 0; |
| 6238 | installFlags |= isForwardLocked(p) ? PackageManager.INSTALL_FORWARD_LOCK : 0; |
| 6239 | outInfo.args = createInstallArgs(installFlags, applicationInfo.sourceDir, |
| 6240 | applicationInfo.publicSourceDir, applicationInfo.nativeLibraryDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6241 | } |
| 6242 | return true; |
| 6243 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6244 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6245 | /* |
| 6246 | * This method handles package deletion in general |
| 6247 | */ |
| 6248 | private boolean deletePackageLI(String packageName, |
| 6249 | boolean deleteCodeAndResources, int flags, PackageRemovedInfo outInfo) { |
| 6250 | if (packageName == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6251 | Slog.w(TAG, "Attempt to delete null packageName."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6252 | return false; |
| 6253 | } |
| 6254 | PackageParser.Package p; |
| 6255 | boolean dataOnly = false; |
| 6256 | synchronized (mPackages) { |
| 6257 | p = mPackages.get(packageName); |
| 6258 | if (p == null) { |
| 6259 | //this retrieves partially installed apps |
| 6260 | dataOnly = true; |
| 6261 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6262 | if (ps == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6263 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6264 | return false; |
| 6265 | } |
| 6266 | p = ps.pkg; |
| 6267 | } |
| 6268 | } |
| 6269 | if (p == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6270 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6271 | return false; |
| 6272 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6273 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6274 | if (dataOnly) { |
| 6275 | // Delete application data first |
| 6276 | removePackageDataLI(p, outInfo, flags); |
| 6277 | return true; |
| 6278 | } |
| 6279 | // At this point the package should have ApplicationInfo associated with it |
| 6280 | if (p.applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6281 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6282 | return false; |
| 6283 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6284 | boolean ret = false; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6285 | if (isSystemApp(p)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6286 | Log.i(TAG, "Removing system package:"+p.packageName); |
| 6287 | // When an updated system application is deleted we delete the existing resources as well and |
| 6288 | // fall back to existing code in system partition |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6289 | ret = deleteSystemPackageLI(p, flags, outInfo); |
| 6290 | } else { |
| 6291 | Log.i(TAG, "Removing non-system package:"+p.packageName); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6292 | // Kill application pre-emptively especially for apps on sd. |
| 6293 | killApplication(packageName, p.applicationInfo.uid); |
| Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 6294 | ret = deleteInstalledPackageLI(p, deleteCodeAndResources, flags, outInfo); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6295 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6296 | return ret; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6297 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6298 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6299 | public void clearApplicationUserData(final String packageName, |
| 6300 | final IPackageDataObserver observer) { |
| 6301 | mContext.enforceCallingOrSelfPermission( |
| 6302 | android.Manifest.permission.CLEAR_APP_USER_DATA, null); |
| 6303 | // Queue up an async operation since the package deletion may take a little while. |
| 6304 | mHandler.post(new Runnable() { |
| 6305 | public void run() { |
| 6306 | mHandler.removeCallbacks(this); |
| 6307 | final boolean succeeded; |
| 6308 | synchronized (mInstallLock) { |
| 6309 | succeeded = clearApplicationUserDataLI(packageName); |
| 6310 | } |
| 6311 | if (succeeded) { |
| 6312 | // invoke DeviceStorageMonitor's update method to clear any notifications |
| 6313 | DeviceStorageMonitorService dsm = (DeviceStorageMonitorService) |
| 6314 | ServiceManager.getService(DeviceStorageMonitorService.SERVICE); |
| 6315 | if (dsm != null) { |
| 6316 | dsm.updateMemory(); |
| 6317 | } |
| 6318 | } |
| 6319 | if(observer != null) { |
| 6320 | try { |
| 6321 | observer.onRemoveCompleted(packageName, succeeded); |
| 6322 | } catch (RemoteException e) { |
| 6323 | Log.i(TAG, "Observer no longer exists."); |
| 6324 | } |
| 6325 | } //end if observer |
| 6326 | } //end run |
| 6327 | }); |
| 6328 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6329 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6330 | private boolean clearApplicationUserDataLI(String packageName) { |
| 6331 | if (packageName == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6332 | Slog.w(TAG, "Attempt to delete null packageName."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6333 | return false; |
| 6334 | } |
| 6335 | PackageParser.Package p; |
| 6336 | boolean dataOnly = false; |
| 6337 | synchronized (mPackages) { |
| 6338 | p = mPackages.get(packageName); |
| 6339 | if(p == null) { |
| 6340 | dataOnly = true; |
| 6341 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6342 | if((ps == null) || (ps.pkg == null)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6343 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6344 | return false; |
| 6345 | } |
| 6346 | p = ps.pkg; |
| 6347 | } |
| 6348 | } |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6349 | boolean useEncryptedFSDir = false; |
| 6350 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | if(!dataOnly) { |
| 6352 | //need to check this only for fully installed applications |
| 6353 | if (p == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6354 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6355 | return false; |
| 6356 | } |
| 6357 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6358 | if (applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6359 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6360 | return false; |
| 6361 | } |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6362 | useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6363 | } |
| 6364 | if (mInstaller != null) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6365 | int retCode = mInstaller.clearUserData(packageName, useEncryptedFSDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6366 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6367 | 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] | 6368 | + packageName); |
| 6369 | return false; |
| 6370 | } |
| 6371 | } |
| 6372 | return true; |
| 6373 | } |
| 6374 | |
| 6375 | public void deleteApplicationCacheFiles(final String packageName, |
| 6376 | final IPackageDataObserver observer) { |
| 6377 | mContext.enforceCallingOrSelfPermission( |
| 6378 | android.Manifest.permission.DELETE_CACHE_FILES, null); |
| 6379 | // Queue up an async operation since the package deletion may take a little while. |
| 6380 | mHandler.post(new Runnable() { |
| 6381 | public void run() { |
| 6382 | mHandler.removeCallbacks(this); |
| 6383 | final boolean succeded; |
| 6384 | synchronized (mInstallLock) { |
| 6385 | succeded = deleteApplicationCacheFilesLI(packageName); |
| 6386 | } |
| 6387 | if(observer != null) { |
| 6388 | try { |
| 6389 | observer.onRemoveCompleted(packageName, succeded); |
| 6390 | } catch (RemoteException e) { |
| 6391 | Log.i(TAG, "Observer no longer exists."); |
| 6392 | } |
| 6393 | } //end if observer |
| 6394 | } //end run |
| 6395 | }); |
| 6396 | } |
| 6397 | |
| 6398 | private boolean deleteApplicationCacheFilesLI(String packageName) { |
| 6399 | if (packageName == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6400 | Slog.w(TAG, "Attempt to delete null packageName."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | return false; |
| 6402 | } |
| 6403 | PackageParser.Package p; |
| 6404 | synchronized (mPackages) { |
| 6405 | p = mPackages.get(packageName); |
| 6406 | } |
| 6407 | if (p == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6408 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6409 | return false; |
| 6410 | } |
| 6411 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6412 | if (applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6413 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6414 | return false; |
| 6415 | } |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6416 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6417 | if (mInstaller != null) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6418 | int retCode = mInstaller.deleteCacheFiles(packageName, useEncryptedFSDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6419 | if (retCode < 0) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6420 | 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] | 6421 | + packageName); |
| 6422 | return false; |
| 6423 | } |
| 6424 | } |
| 6425 | return true; |
| 6426 | } |
| 6427 | |
| 6428 | public void getPackageSizeInfo(final String packageName, |
| 6429 | final IPackageStatsObserver observer) { |
| 6430 | mContext.enforceCallingOrSelfPermission( |
| 6431 | android.Manifest.permission.GET_PACKAGE_SIZE, null); |
| 6432 | // Queue up an async operation since the package deletion may take a little while. |
| 6433 | mHandler.post(new Runnable() { |
| 6434 | public void run() { |
| 6435 | mHandler.removeCallbacks(this); |
| 6436 | PackageStats lStats = new PackageStats(packageName); |
| 6437 | final boolean succeded; |
| 6438 | synchronized (mInstallLock) { |
| 6439 | succeded = getPackageSizeInfoLI(packageName, lStats); |
| 6440 | } |
| 6441 | if(observer != null) { |
| 6442 | try { |
| 6443 | observer.onGetStatsCompleted(lStats, succeded); |
| 6444 | } catch (RemoteException e) { |
| 6445 | Log.i(TAG, "Observer no longer exists."); |
| 6446 | } |
| 6447 | } //end if observer |
| 6448 | } //end run |
| 6449 | }); |
| 6450 | } |
| 6451 | |
| 6452 | private boolean getPackageSizeInfoLI(String packageName, PackageStats pStats) { |
| 6453 | if (packageName == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6454 | 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] | 6455 | return false; |
| 6456 | } |
| 6457 | PackageParser.Package p; |
| 6458 | boolean dataOnly = false; |
| 6459 | synchronized (mPackages) { |
| 6460 | p = mPackages.get(packageName); |
| 6461 | if(p == null) { |
| 6462 | dataOnly = true; |
| 6463 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6464 | if((ps == null) || (ps.pkg == null)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6465 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6466 | return false; |
| 6467 | } |
| 6468 | p = ps.pkg; |
| 6469 | } |
| 6470 | } |
| 6471 | String publicSrcDir = null; |
| 6472 | if(!dataOnly) { |
| 6473 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6474 | if (applicationInfo == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6475 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6476 | return false; |
| 6477 | } |
| 6478 | publicSrcDir = isForwardLocked(p) ? applicationInfo.publicSourceDir : null; |
| 6479 | } |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6480 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6481 | if (mInstaller != null) { |
| 6482 | int res = mInstaller.getSizeInfo(packageName, p.mPath, |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6483 | publicSrcDir, pStats, useEncryptedFSDir); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6484 | if (res < 0) { |
| 6485 | return false; |
| 6486 | } else { |
| 6487 | return true; |
| 6488 | } |
| 6489 | } |
| 6490 | return true; |
| 6491 | } |
| 6492 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6494 | public void addPackageToPreferred(String packageName) { |
| Dianne Hackborn | 8377fc0 | 2010-06-07 15:54:58 -0700 | [diff] [blame] | 6495 | 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] | 6496 | } |
| 6497 | |
| 6498 | public void removePackageFromPreferred(String packageName) { |
| Dianne Hackborn | 8377fc0 | 2010-06-07 15:54:58 -0700 | [diff] [blame] | 6499 | 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] | 6500 | } |
| 6501 | |
| 6502 | public List<PackageInfo> getPreferredPackages(int flags) { |
| Dianne Hackborn | a7ca0e5 | 2009-12-01 14:31:55 -0800 | [diff] [blame] | 6503 | return new ArrayList<PackageInfo>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6504 | } |
| 6505 | |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6506 | int getUidTargetSdkVersionLockedLP(int uid) { |
| 6507 | Object obj = mSettings.getUserIdLP(uid); |
| 6508 | if (obj instanceof SharedUserSetting) { |
| 6509 | SharedUserSetting sus = (SharedUserSetting)obj; |
| 6510 | final int N = sus.packages.size(); |
| 6511 | int vers = Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 6512 | Iterator<PackageSetting> it = sus.packages.iterator(); |
| 6513 | int i=0; |
| 6514 | while (it.hasNext()) { |
| 6515 | PackageSetting ps = it.next(); |
| 6516 | if (ps.pkg != null) { |
| 6517 | int v = ps.pkg.applicationInfo.targetSdkVersion; |
| 6518 | if (v < vers) vers = v; |
| 6519 | } |
| 6520 | } |
| 6521 | return vers; |
| 6522 | } else if (obj instanceof PackageSetting) { |
| 6523 | PackageSetting ps = (PackageSetting)obj; |
| 6524 | if (ps.pkg != null) { |
| 6525 | return ps.pkg.applicationInfo.targetSdkVersion; |
| 6526 | } |
| 6527 | } |
| 6528 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 6529 | } |
| 6530 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6531 | public void addPreferredActivity(IntentFilter filter, int match, |
| 6532 | ComponentName[] set, ComponentName activity) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6533 | synchronized (mPackages) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6534 | if (mContext.checkCallingOrSelfPermission( |
| 6535 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6536 | != PackageManager.PERMISSION_GRANTED) { |
| 6537 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6538 | < Build.VERSION_CODES.FROYO) { |
| 6539 | Slog.w(TAG, "Ignoring addPreferredActivity() from uid " |
| 6540 | + Binder.getCallingUid()); |
| 6541 | return; |
| 6542 | } |
| 6543 | mContext.enforceCallingOrSelfPermission( |
| 6544 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6545 | } |
| 6546 | |
| 6547 | Slog.i(TAG, "Adding preferred activity " + activity + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6548 | filter.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 6549 | mSettings.mPreferredActivities.addFilter( |
| 6550 | new PreferredActivity(filter, match, set, activity)); |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6551 | scheduleWriteSettingsLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6552 | } |
| 6553 | } |
| 6554 | |
| Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6555 | public void replacePreferredActivity(IntentFilter filter, int match, |
| 6556 | ComponentName[] set, ComponentName activity) { |
| Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6557 | if (filter.countActions() != 1) { |
| 6558 | throw new IllegalArgumentException( |
| 6559 | "replacePreferredActivity expects filter to have only 1 action."); |
| 6560 | } |
| 6561 | if (filter.countCategories() != 1) { |
| 6562 | throw new IllegalArgumentException( |
| 6563 | "replacePreferredActivity expects filter to have only 1 category."); |
| 6564 | } |
| 6565 | if (filter.countDataAuthorities() != 0 |
| 6566 | || filter.countDataPaths() != 0 |
| 6567 | || filter.countDataSchemes() != 0 |
| 6568 | || filter.countDataTypes() != 0) { |
| 6569 | throw new IllegalArgumentException( |
| 6570 | "replacePreferredActivity expects filter to have no data authorities, " + |
| 6571 | "paths, schemes or types."); |
| 6572 | } |
| 6573 | synchronized (mPackages) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6574 | if (mContext.checkCallingOrSelfPermission( |
| 6575 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6576 | != PackageManager.PERMISSION_GRANTED) { |
| 6577 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6578 | < Build.VERSION_CODES.FROYO) { |
| 6579 | Slog.w(TAG, "Ignoring replacePreferredActivity() from uid " |
| 6580 | + Binder.getCallingUid()); |
| 6581 | return; |
| 6582 | } |
| 6583 | mContext.enforceCallingOrSelfPermission( |
| 6584 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6585 | } |
| 6586 | |
| Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6587 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6588 | String action = filter.getAction(0); |
| 6589 | String category = filter.getCategory(0); |
| 6590 | while (it.hasNext()) { |
| 6591 | PreferredActivity pa = it.next(); |
| 6592 | if (pa.getAction(0).equals(action) && pa.getCategory(0).equals(category)) { |
| 6593 | it.remove(); |
| 6594 | Log.i(TAG, "Removed preferred activity " + pa.mActivity + ":"); |
| 6595 | filter.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 6596 | } |
| 6597 | } |
| 6598 | addPreferredActivity(filter, match, set, activity); |
| 6599 | } |
| 6600 | } |
| 6601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6602 | public void clearPackagePreferredActivities(String packageName) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6603 | synchronized (mPackages) { |
| Dianne Hackborn | 2ee89ea | 2010-03-10 18:27:09 -0800 | [diff] [blame] | 6604 | int uid = Binder.getCallingUid(); |
| 6605 | PackageParser.Package pkg = mPackages.get(packageName); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6606 | if (pkg == null || pkg.applicationInfo.uid != uid) { |
| 6607 | if (mContext.checkCallingOrSelfPermission( |
| 6608 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6609 | != PackageManager.PERMISSION_GRANTED) { |
| 6610 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6611 | < Build.VERSION_CODES.FROYO) { |
| 6612 | Slog.w(TAG, "Ignoring clearPackagePreferredActivities() from uid " |
| 6613 | + Binder.getCallingUid()); |
| 6614 | return; |
| 6615 | } |
| 6616 | mContext.enforceCallingOrSelfPermission( |
| 6617 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6618 | } |
| Dianne Hackborn | 2ee89ea | 2010-03-10 18:27:09 -0800 | [diff] [blame] | 6619 | } |
| 6620 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6621 | if (clearPackagePreferredActivitiesLP(packageName)) { |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6622 | scheduleWriteSettingsLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6623 | } |
| 6624 | } |
| 6625 | } |
| 6626 | |
| 6627 | boolean clearPackagePreferredActivitiesLP(String packageName) { |
| 6628 | boolean changed = false; |
| 6629 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6630 | while (it.hasNext()) { |
| 6631 | PreferredActivity pa = it.next(); |
| 6632 | if (pa.mActivity.getPackageName().equals(packageName)) { |
| 6633 | it.remove(); |
| 6634 | changed = true; |
| 6635 | } |
| 6636 | } |
| 6637 | return changed; |
| 6638 | } |
| 6639 | |
| 6640 | public int getPreferredActivities(List<IntentFilter> outFilters, |
| 6641 | List<ComponentName> outActivities, String packageName) { |
| 6642 | |
| 6643 | int num = 0; |
| 6644 | synchronized (mPackages) { |
| 6645 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6646 | while (it.hasNext()) { |
| 6647 | PreferredActivity pa = it.next(); |
| 6648 | if (packageName == null |
| 6649 | || pa.mActivity.getPackageName().equals(packageName)) { |
| 6650 | if (outFilters != null) { |
| 6651 | outFilters.add(new IntentFilter(pa)); |
| 6652 | } |
| 6653 | if (outActivities != null) { |
| 6654 | outActivities.add(pa.mActivity); |
| 6655 | } |
| 6656 | } |
| 6657 | } |
| 6658 | } |
| 6659 | |
| 6660 | return num; |
| 6661 | } |
| 6662 | |
| 6663 | public void setApplicationEnabledSetting(String appPackageName, |
| 6664 | int newState, int flags) { |
| 6665 | setEnabledSetting(appPackageName, null, newState, flags); |
| 6666 | } |
| 6667 | |
| 6668 | public void setComponentEnabledSetting(ComponentName componentName, |
| 6669 | int newState, int flags) { |
| 6670 | setEnabledSetting(componentName.getPackageName(), |
| 6671 | componentName.getClassName(), newState, flags); |
| 6672 | } |
| 6673 | |
| 6674 | private void setEnabledSetting( |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6675 | 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] | 6676 | if (!(newState == COMPONENT_ENABLED_STATE_DEFAULT |
| 6677 | || newState == COMPONENT_ENABLED_STATE_ENABLED |
| 6678 | || newState == COMPONENT_ENABLED_STATE_DISABLED)) { |
| 6679 | throw new IllegalArgumentException("Invalid new component state: " |
| 6680 | + newState); |
| 6681 | } |
| 6682 | PackageSetting pkgSetting; |
| 6683 | final int uid = Binder.getCallingUid(); |
| 6684 | final int permission = mContext.checkCallingPermission( |
| 6685 | android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE); |
| 6686 | final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6687 | boolean sendNow = false; |
| 6688 | boolean isApp = (className == null); |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6689 | String componentName = isApp ? packageName : className; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6690 | int packageUid = -1; |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6691 | ArrayList<String> components; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6692 | synchronized (mPackages) { |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6693 | pkgSetting = mSettings.mPackages.get(packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6694 | if (pkgSetting == null) { |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6695 | if (className == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6696 | throw new IllegalArgumentException( |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6697 | "Unknown package: " + packageName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6698 | } |
| 6699 | throw new IllegalArgumentException( |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6700 | "Unknown component: " + packageName |
| 6701 | + "/" + className); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6702 | } |
| 6703 | if (!allowedByPermission && (uid != pkgSetting.userId)) { |
| 6704 | throw new SecurityException( |
| 6705 | "Permission Denial: attempt to change component state from pid=" |
| 6706 | + Binder.getCallingPid() |
| 6707 | + ", uid=" + uid + ", package uid=" + pkgSetting.userId); |
| 6708 | } |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6709 | if (className == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6710 | // We're dealing with an application/package level state change |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6711 | if (pkgSetting.enabled == newState) { |
| 6712 | // Nothing to do |
| 6713 | return; |
| 6714 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6715 | pkgSetting.enabled = newState; |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 6716 | pkgSetting.pkg.mSetEnabled = newState; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6717 | } else { |
| 6718 | // We're dealing with a component level state change |
| 6719 | switch (newState) { |
| 6720 | case COMPONENT_ENABLED_STATE_ENABLED: |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6721 | if (!pkgSetting.enableComponentLP(className)) { |
| 6722 | return; |
| 6723 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6724 | break; |
| 6725 | case COMPONENT_ENABLED_STATE_DISABLED: |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6726 | if (!pkgSetting.disableComponentLP(className)) { |
| 6727 | return; |
| 6728 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6729 | break; |
| 6730 | case COMPONENT_ENABLED_STATE_DEFAULT: |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6731 | if (!pkgSetting.restoreComponentLP(className)) { |
| 6732 | return; |
| 6733 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6734 | break; |
| 6735 | default: |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6736 | Slog.e(TAG, "Invalid new component state: " + newState); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6737 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6738 | } |
| 6739 | } |
| 6740 | mSettings.writeLP(); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6741 | packageUid = pkgSetting.userId; |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6742 | components = mPendingBroadcasts.get(packageName); |
| 6743 | boolean newPackage = components == null; |
| 6744 | if (newPackage) { |
| 6745 | components = new ArrayList<String>(); |
| 6746 | } |
| 6747 | if (!components.contains(componentName)) { |
| 6748 | components.add(componentName); |
| 6749 | } |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6750 | if ((flags&PackageManager.DONT_KILL_APP) == 0) { |
| 6751 | sendNow = true; |
| 6752 | // Purge entry from pending broadcast list if another one exists already |
| 6753 | // since we are sending one right away. |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6754 | mPendingBroadcasts.remove(packageName); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6755 | } else { |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6756 | if (newPackage) { |
| 6757 | mPendingBroadcasts.put(packageName, components); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6758 | } |
| 6759 | if (!mHandler.hasMessages(SEND_PENDING_BROADCAST)) { |
| 6760 | // Schedule a message |
| 6761 | mHandler.sendEmptyMessageDelayed(SEND_PENDING_BROADCAST, BROADCAST_DELAY); |
| 6762 | } |
| 6763 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6764 | } |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6765 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6766 | long callingId = Binder.clearCallingIdentity(); |
| 6767 | try { |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6768 | if (sendNow) { |
| 6769 | sendPackageChangedBroadcast(packageName, |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6770 | (flags&PackageManager.DONT_KILL_APP) != 0, components, packageUid); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6771 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6772 | } finally { |
| 6773 | Binder.restoreCallingIdentity(callingId); |
| 6774 | } |
| 6775 | } |
| 6776 | |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6777 | private void sendPackageChangedBroadcast(String packageName, |
| Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6778 | boolean killFlag, ArrayList<String> componentNames, int packageUid) { |
| 6779 | if (false) Log.v(TAG, "Sending package changed: package=" + packageName |
| 6780 | + " components=" + componentNames); |
| 6781 | Bundle extras = new Bundle(4); |
| 6782 | extras.putString(Intent.EXTRA_CHANGED_COMPONENT_NAME, componentNames.get(0)); |
| 6783 | String nameList[] = new String[componentNames.size()]; |
| 6784 | componentNames.toArray(nameList); |
| 6785 | extras.putStringArray(Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST, nameList); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6786 | extras.putBoolean(Intent.EXTRA_DONT_KILL_APP, killFlag); |
| 6787 | extras.putInt(Intent.EXTRA_UID, packageUid); |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 6788 | sendPackageBroadcast(Intent.ACTION_PACKAGE_CHANGED, packageName, extras, null); |
| Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6789 | } |
| 6790 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 6791 | public String getInstallerPackageName(String packageName) { |
| 6792 | synchronized (mPackages) { |
| 6793 | PackageSetting pkg = mSettings.mPackages.get(packageName); |
| 6794 | if (pkg == null) { |
| 6795 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 6796 | } |
| 6797 | return pkg.installerPackageName; |
| 6798 | } |
| 6799 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6800 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6801 | public int getApplicationEnabledSetting(String appPackageName) { |
| 6802 | synchronized (mPackages) { |
| 6803 | PackageSetting pkg = mSettings.mPackages.get(appPackageName); |
| 6804 | if (pkg == null) { |
| 6805 | throw new IllegalArgumentException("Unknown package: " + appPackageName); |
| 6806 | } |
| 6807 | return pkg.enabled; |
| 6808 | } |
| 6809 | } |
| 6810 | |
| 6811 | public int getComponentEnabledSetting(ComponentName componentName) { |
| 6812 | synchronized (mPackages) { |
| 6813 | final String packageNameStr = componentName.getPackageName(); |
| 6814 | PackageSetting pkg = mSettings.mPackages.get(packageNameStr); |
| 6815 | if (pkg == null) { |
| 6816 | throw new IllegalArgumentException("Unknown component: " + componentName); |
| 6817 | } |
| 6818 | final String classNameStr = componentName.getClassName(); |
| 6819 | return pkg.currentEnabledStateLP(classNameStr); |
| 6820 | } |
| 6821 | } |
| 6822 | |
| 6823 | public void enterSafeMode() { |
| 6824 | if (!mSystemReady) { |
| 6825 | mSafeMode = true; |
| 6826 | } |
| 6827 | } |
| 6828 | |
| 6829 | public void systemReady() { |
| 6830 | mSystemReady = true; |
| Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6831 | |
| 6832 | // Read the compatibilty setting when the system is ready. |
| Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6833 | boolean compatibilityModeEnabled = android.provider.Settings.System.getInt( |
| Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6834 | mContext.getContentResolver(), |
| 6835 | android.provider.Settings.System.COMPATIBILITY_MODE, 1) == 1; |
| Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6836 | PackageParser.setCompatibilityModeEnabled(compatibilityModeEnabled); |
| Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6837 | if (DEBUG_SETTINGS) { |
| Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6838 | Log.d(TAG, "compatibility mode:" + compatibilityModeEnabled); |
| Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6839 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6840 | } |
| 6841 | |
| 6842 | public boolean isSafeMode() { |
| 6843 | return mSafeMode; |
| 6844 | } |
| 6845 | |
| 6846 | public boolean hasSystemUidErrors() { |
| 6847 | return mHasSystemUidErrors; |
| 6848 | } |
| 6849 | |
| 6850 | static String arrayToString(int[] array) { |
| 6851 | StringBuffer buf = new StringBuffer(128); |
| 6852 | buf.append('['); |
| 6853 | if (array != null) { |
| 6854 | for (int i=0; i<array.length; i++) { |
| 6855 | if (i > 0) buf.append(", "); |
| 6856 | buf.append(array[i]); |
| 6857 | } |
| 6858 | } |
| 6859 | buf.append(']'); |
| 6860 | return buf.toString(); |
| 6861 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6862 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6863 | @Override |
| 6864 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 6865 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6866 | != PackageManager.PERMISSION_GRANTED) { |
| 6867 | pw.println("Permission Denial: can't dump ActivityManager from from pid=" |
| 6868 | + Binder.getCallingPid() |
| 6869 | + ", uid=" + Binder.getCallingUid() |
| 6870 | + " without permission " |
| 6871 | + android.Manifest.permission.DUMP); |
| 6872 | return; |
| 6873 | } |
| 6874 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6875 | String packageName = null; |
| 6876 | |
| 6877 | int opti = 0; |
| 6878 | while (opti < args.length) { |
| 6879 | String opt = args[opti]; |
| 6880 | if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') { |
| 6881 | break; |
| 6882 | } |
| 6883 | opti++; |
| 6884 | if ("-a".equals(opt)) { |
| 6885 | // Right now we only know how to print all. |
| 6886 | } else if ("-h".equals(opt)) { |
| 6887 | pw.println("Package manager dump options:"); |
| 6888 | pw.println(" [-h] [cmd] ..."); |
| 6889 | pw.println(" cmd may be one of:"); |
| 6890 | pw.println(" [package.name]: info about given package"); |
| 6891 | return; |
| 6892 | } else { |
| 6893 | pw.println("Unknown argument: " + opt + "; use -h for help"); |
| 6894 | } |
| 6895 | } |
| 6896 | |
| 6897 | // Is the caller requesting to dump a particular piece of data? |
| 6898 | if (opti < args.length) { |
| 6899 | String cmd = args[opti]; |
| 6900 | opti++; |
| 6901 | // Is this a package name? |
| 6902 | if ("android".equals(cmd) || cmd.contains(".")) { |
| 6903 | packageName = cmd; |
| 6904 | } |
| 6905 | } |
| 6906 | |
| 6907 | boolean printedTitle = false; |
| 6908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6909 | synchronized (mPackages) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6910 | if (mActivities.dump(pw, "Activity Resolver Table:", " ", packageName)) { |
| 6911 | printedTitle = true; |
| 6912 | } |
| 6913 | if (mReceivers.dump(pw, printedTitle |
| 6914 | ? "\nReceiver Resolver Table:" : "Receiver Resolver Table:", |
| 6915 | " ", packageName)) { |
| 6916 | printedTitle = true; |
| 6917 | } |
| 6918 | if (mServices.dump(pw, printedTitle |
| 6919 | ? "\nService Resolver Table:" : "Service Resolver Table:", |
| 6920 | " ", packageName)) { |
| 6921 | printedTitle = true; |
| 6922 | } |
| 6923 | if (mSettings.mPreferredActivities.dump(pw, printedTitle |
| 6924 | ? "\nPreferred Activities:" : "Preferred Activities:", |
| 6925 | " ", packageName)) { |
| 6926 | printedTitle = true; |
| 6927 | } |
| 6928 | boolean printedSomething = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6929 | { |
| 6930 | for (BasePermission p : mSettings.mPermissions.values()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6931 | if (packageName != null && !packageName.equals(p.sourcePackage)) { |
| 6932 | continue; |
| 6933 | } |
| 6934 | if (!printedSomething) { |
| 6935 | if (printedTitle) pw.println(" "); |
| 6936 | pw.println("Permissions:"); |
| 6937 | printedSomething = true; |
| 6938 | printedTitle = true; |
| 6939 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6940 | pw.print(" Permission ["); pw.print(p.name); pw.print("] ("); |
| 6941 | pw.print(Integer.toHexString(System.identityHashCode(p))); |
| 6942 | pw.println("):"); |
| 6943 | pw.print(" sourcePackage="); pw.println(p.sourcePackage); |
| 6944 | pw.print(" uid="); pw.print(p.uid); |
| 6945 | pw.print(" gids="); pw.print(arrayToString(p.gids)); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6946 | pw.print(" type="); pw.print(p.type); |
| 6947 | pw.print(" prot="); pw.println(p.protectionLevel); |
| 6948 | if (p.packageSetting != null) { |
| 6949 | pw.print(" packageSetting="); pw.println(p.packageSetting); |
| 6950 | } |
| 6951 | if (p.perm != null) { |
| 6952 | pw.print(" perm="); pw.println(p.perm); |
| 6953 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6954 | } |
| 6955 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6956 | printedSomething = false; |
| 6957 | SharedUserSetting packageSharedUser = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6958 | { |
| 6959 | for (PackageSetting ps : mSettings.mPackages.values()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6960 | if (packageName != null && !packageName.equals(ps.realName) |
| 6961 | && !packageName.equals(ps.name)) { |
| 6962 | continue; |
| 6963 | } |
| 6964 | if (!printedSomething) { |
| 6965 | if (printedTitle) pw.println(" "); |
| 6966 | pw.println("Packages:"); |
| 6967 | printedSomething = true; |
| 6968 | printedTitle = true; |
| 6969 | } |
| 6970 | packageSharedUser = ps.sharedUser; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6971 | pw.print(" Package ["); |
| 6972 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 6973 | pw.print("] ("); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6974 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 6975 | pw.println("):"); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6976 | if (ps.realName != null) { |
| 6977 | pw.print(" compat name="); pw.println(ps.name); |
| 6978 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6979 | pw.print(" userId="); pw.print(ps.userId); |
| 6980 | pw.print(" gids="); pw.println(arrayToString(ps.gids)); |
| 6981 | pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 6982 | pw.print(" pkg="); pw.println(ps.pkg); |
| 6983 | pw.print(" codePath="); pw.println(ps.codePathString); |
| 6984 | pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6985 | pw.print(" nativeLibraryPath="); pw.println(ps.nativeLibraryPathString); |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 6986 | pw.print(" obbPath="); pw.println(ps.obbPathString); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6987 | if (ps.pkg != null) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6988 | pw.print(" dataDir="); pw.println(ps.pkg.applicationInfo.dataDir); |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6989 | pw.print(" targetSdk="); pw.println(ps.pkg.applicationInfo.targetSdkVersion); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 6990 | if (ps.pkg.mOperationPending) { |
| 6991 | pw.println(" mOperationPending=true"); |
| 6992 | } |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6993 | pw.print(" supportsScreens=["); |
| 6994 | boolean first = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6995 | if ((ps.pkg.applicationInfo.flags & |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 6996 | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) { |
| 6997 | if (!first) pw.print(", "); |
| 6998 | first = false; |
| 6999 | pw.print("small"); |
| 7000 | } |
| 7001 | if ((ps.pkg.applicationInfo.flags & |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7002 | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) { |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7003 | if (!first) pw.print(", "); |
| 7004 | first = false; |
| 7005 | pw.print("medium"); |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7006 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7007 | if ((ps.pkg.applicationInfo.flags & |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7008 | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) { |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7009 | if (!first) pw.print(", "); |
| 7010 | first = false; |
| 7011 | pw.print("large"); |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7012 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7013 | if ((ps.pkg.applicationInfo.flags & |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 7014 | ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) { |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7015 | if (!first) pw.print(", "); |
| 7016 | first = false; |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 7017 | pw.print("xlarge"); |
| Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7018 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7019 | if ((ps.pkg.applicationInfo.flags & |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 7020 | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) { |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7021 | if (!first) pw.print(", "); |
| 7022 | first = false; |
| 7023 | pw.print("resizeable"); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 7024 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7025 | if ((ps.pkg.applicationInfo.flags & |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7026 | ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) { |
| 7027 | if (!first) pw.print(", "); |
| 7028 | first = false; |
| 7029 | pw.print("anyDensity"); |
| 7030 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7031 | } |
| Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7032 | pw.println("]"); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7033 | pw.print(" timeStamp="); pw.println(ps.getTimeStampStr()); |
| 7034 | pw.print(" signatures="); pw.println(ps.signatures); |
| 7035 | pw.print(" permissionsFixed="); pw.print(ps.permissionsFixed); |
| Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7036 | pw.print(" haveGids="); pw.println(ps.haveGids); |
| 7037 | pw.print(" pkgFlags=0x"); pw.print(Integer.toHexString(ps.pkgFlags)); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7038 | pw.print(" installStatus="); pw.print(ps.installStatus); |
| 7039 | pw.print(" enabled="); pw.println(ps.enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7040 | if (ps.disabledComponents.size() > 0) { |
| 7041 | pw.println(" disabledComponents:"); |
| 7042 | for (String s : ps.disabledComponents) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7043 | pw.print(" "); pw.println(s); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7044 | } |
| 7045 | } |
| 7046 | if (ps.enabledComponents.size() > 0) { |
| 7047 | pw.println(" enabledComponents:"); |
| 7048 | for (String s : ps.enabledComponents) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7049 | pw.print(" "); pw.println(s); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7050 | } |
| 7051 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7052 | if (ps.grantedPermissions.size() > 0) { |
| 7053 | pw.println(" grantedPermissions:"); |
| 7054 | for (String s : ps.grantedPermissions) { |
| 7055 | pw.print(" "); pw.println(s); |
| 7056 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7057 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7058 | } |
| 7059 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7060 | printedSomething = false; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7061 | if (mSettings.mRenamedPackages.size() > 0) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7062 | for (HashMap.Entry<String, String> e |
| 7063 | : mSettings.mRenamedPackages.entrySet()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7064 | if (packageName != null && !packageName.equals(e.getKey()) |
| 7065 | && !packageName.equals(e.getValue())) { |
| 7066 | continue; |
| 7067 | } |
| 7068 | if (!printedSomething) { |
| 7069 | if (printedTitle) pw.println(" "); |
| 7070 | pw.println("Renamed packages:"); |
| 7071 | printedSomething = true; |
| 7072 | printedTitle = true; |
| 7073 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7074 | pw.print(" "); pw.print(e.getKey()); pw.print(" -> "); |
| 7075 | pw.println(e.getValue()); |
| 7076 | } |
| 7077 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7078 | printedSomething = false; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7079 | if (mSettings.mDisabledSysPackages.size() > 0) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7080 | for (PackageSetting ps : mSettings.mDisabledSysPackages.values()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7081 | if (packageName != null && !packageName.equals(ps.realName) |
| 7082 | && !packageName.equals(ps.name)) { |
| 7083 | continue; |
| 7084 | } |
| 7085 | if (!printedSomething) { |
| 7086 | if (printedTitle) pw.println(" "); |
| 7087 | pw.println("Hidden system packages:"); |
| 7088 | printedSomething = true; |
| 7089 | printedTitle = true; |
| 7090 | } |
| 7091 | pw.print(" Package ["); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7092 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 7093 | pw.print("] ("); |
| 7094 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 7095 | pw.println("):"); |
| 7096 | if (ps.realName != null) { |
| 7097 | pw.print(" compat name="); pw.println(ps.name); |
| 7098 | } |
| 7099 | pw.print(" userId="); pw.println(ps.userId); |
| 7100 | pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 7101 | pw.print(" codePath="); pw.println(ps.codePathString); |
| 7102 | pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
| 7103 | } |
| 7104 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7105 | printedSomething = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7106 | { |
| 7107 | for (SharedUserSetting su : mSettings.mSharedUsers.values()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7108 | if (packageName != null && su != packageSharedUser) { |
| 7109 | continue; |
| 7110 | } |
| 7111 | if (!printedSomething) { |
| 7112 | if (printedTitle) pw.println(" "); |
| 7113 | pw.println("Shared users:"); |
| 7114 | printedSomething = true; |
| 7115 | printedTitle = true; |
| 7116 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7117 | pw.print(" SharedUser ["); pw.print(su.name); pw.print("] ("); |
| 7118 | pw.print(Integer.toHexString(System.identityHashCode(su))); |
| 7119 | pw.println("):"); |
| 7120 | pw.print(" userId="); pw.print(su.userId); |
| 7121 | pw.print(" gids="); pw.println(arrayToString(su.gids)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7122 | pw.println(" grantedPermissions:"); |
| 7123 | for (String s : su.grantedPermissions) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7124 | pw.print(" "); pw.println(s); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7125 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7126 | } |
| 7127 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7128 | |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7129 | if (packageName == null) { |
| 7130 | if (printedTitle) pw.println(" "); |
| 7131 | printedTitle = true; |
| 7132 | pw.println("Settings parse messages:"); |
| 7133 | pw.println(mSettings.mReadMessages.toString()); |
| 7134 | |
| 7135 | pw.println(" "); |
| 7136 | pw.println("Package warning messages:"); |
| 7137 | File fname = getSettingsProblemFile(); |
| 7138 | FileInputStream in; |
| 7139 | try { |
| 7140 | in = new FileInputStream(fname); |
| 7141 | int avail = in.available(); |
| 7142 | byte[] data = new byte[avail]; |
| 7143 | in.read(data); |
| 7144 | pw.println(new String(data)); |
| 7145 | } catch (FileNotFoundException e) { |
| 7146 | } catch (IOException e) { |
| 7147 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7148 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7149 | } |
| Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7150 | |
| 7151 | synchronized (mProviders) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7152 | boolean printedSomething = false; |
| Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7153 | for (PackageParser.Provider p : mProviders.values()) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7154 | if (packageName != null && !packageName.equals(p.info.packageName)) { |
| 7155 | continue; |
| 7156 | } |
| 7157 | if (!printedSomething) { |
| 7158 | if (printedTitle) pw.println(" "); |
| 7159 | pw.println("Registered ContentProviders:"); |
| 7160 | printedSomething = true; |
| 7161 | printedTitle = true; |
| 7162 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7163 | pw.print(" ["); pw.print(p.info.authority); pw.print("]: "); |
| Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7164 | pw.println(p.toString()); |
| 7165 | } |
| 7166 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7167 | } |
| 7168 | |
| 7169 | static final class BasePermission { |
| 7170 | final static int TYPE_NORMAL = 0; |
| 7171 | final static int TYPE_BUILTIN = 1; |
| 7172 | final static int TYPE_DYNAMIC = 2; |
| 7173 | |
| 7174 | final String name; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7175 | String sourcePackage; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7176 | PackageSettingBase packageSetting; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7177 | final int type; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7178 | int protectionLevel; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7179 | PackageParser.Permission perm; |
| 7180 | PermissionInfo pendingInfo; |
| 7181 | int uid; |
| 7182 | int[] gids; |
| 7183 | |
| 7184 | BasePermission(String _name, String _sourcePackage, int _type) { |
| 7185 | name = _name; |
| 7186 | sourcePackage = _sourcePackage; |
| 7187 | type = _type; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7188 | // Default to most conservative protection level. |
| 7189 | protectionLevel = PermissionInfo.PROTECTION_SIGNATURE; |
| 7190 | } |
| 7191 | |
| 7192 | public String toString() { |
| 7193 | return "BasePermission{" |
| 7194 | + Integer.toHexString(System.identityHashCode(this)) |
| 7195 | + " " + name + "}"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7196 | } |
| 7197 | } |
| 7198 | |
| 7199 | static class PackageSignatures { |
| 7200 | private Signature[] mSignatures; |
| 7201 | |
| 7202 | PackageSignatures(Signature[] sigs) { |
| 7203 | assignSignatures(sigs); |
| 7204 | } |
| 7205 | |
| 7206 | PackageSignatures() { |
| 7207 | } |
| 7208 | |
| 7209 | void writeXml(XmlSerializer serializer, String tagName, |
| 7210 | ArrayList<Signature> pastSignatures) throws IOException { |
| 7211 | if (mSignatures == null) { |
| 7212 | return; |
| 7213 | } |
| 7214 | serializer.startTag(null, tagName); |
| 7215 | serializer.attribute(null, "count", |
| 7216 | Integer.toString(mSignatures.length)); |
| 7217 | for (int i=0; i<mSignatures.length; i++) { |
| 7218 | serializer.startTag(null, "cert"); |
| 7219 | final Signature sig = mSignatures[i]; |
| 7220 | final int sigHash = sig.hashCode(); |
| 7221 | final int numPast = pastSignatures.size(); |
| 7222 | int j; |
| 7223 | for (j=0; j<numPast; j++) { |
| 7224 | Signature pastSig = pastSignatures.get(j); |
| 7225 | if (pastSig.hashCode() == sigHash && pastSig.equals(sig)) { |
| 7226 | serializer.attribute(null, "index", Integer.toString(j)); |
| 7227 | break; |
| 7228 | } |
| 7229 | } |
| 7230 | if (j >= numPast) { |
| 7231 | pastSignatures.add(sig); |
| 7232 | serializer.attribute(null, "index", Integer.toString(numPast)); |
| 7233 | serializer.attribute(null, "key", sig.toCharsString()); |
| 7234 | } |
| 7235 | serializer.endTag(null, "cert"); |
| 7236 | } |
| 7237 | serializer.endTag(null, tagName); |
| 7238 | } |
| 7239 | |
| 7240 | void readXml(XmlPullParser parser, ArrayList<Signature> pastSignatures) |
| 7241 | throws IOException, XmlPullParserException { |
| 7242 | String countStr = parser.getAttributeValue(null, "count"); |
| 7243 | if (countStr == null) { |
| 7244 | reportSettingsProblem(Log.WARN, |
| 7245 | "Error in package manager settings: <signatures> has" |
| 7246 | + " no count at " + parser.getPositionDescription()); |
| 7247 | XmlUtils.skipCurrentTag(parser); |
| 7248 | } |
| 7249 | final int count = Integer.parseInt(countStr); |
| 7250 | mSignatures = new Signature[count]; |
| 7251 | int pos = 0; |
| 7252 | |
| 7253 | int outerDepth = parser.getDepth(); |
| 7254 | int type; |
| 7255 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 7256 | && (type != XmlPullParser.END_TAG |
| 7257 | || parser.getDepth() > outerDepth)) { |
| 7258 | if (type == XmlPullParser.END_TAG |
| 7259 | || type == XmlPullParser.TEXT) { |
| 7260 | continue; |
| 7261 | } |
| 7262 | |
| 7263 | String tagName = parser.getName(); |
| 7264 | if (tagName.equals("cert")) { |
| 7265 | if (pos < count) { |
| 7266 | String index = parser.getAttributeValue(null, "index"); |
| 7267 | if (index != null) { |
| 7268 | try { |
| 7269 | int idx = Integer.parseInt(index); |
| 7270 | String key = parser.getAttributeValue(null, "key"); |
| 7271 | if (key == null) { |
| 7272 | if (idx >= 0 && idx < pastSignatures.size()) { |
| 7273 | Signature sig = pastSignatures.get(idx); |
| 7274 | if (sig != null) { |
| 7275 | mSignatures[pos] = pastSignatures.get(idx); |
| 7276 | pos++; |
| 7277 | } else { |
| 7278 | reportSettingsProblem(Log.WARN, |
| 7279 | "Error in package manager settings: <cert> " |
| 7280 | + "index " + index + " is not defined at " |
| 7281 | + parser.getPositionDescription()); |
| 7282 | } |
| 7283 | } else { |
| 7284 | reportSettingsProblem(Log.WARN, |
| 7285 | "Error in package manager settings: <cert> " |
| 7286 | + "index " + index + " is out of bounds at " |
| 7287 | + parser.getPositionDescription()); |
| 7288 | } |
| 7289 | } else { |
| 7290 | while (pastSignatures.size() <= idx) { |
| 7291 | pastSignatures.add(null); |
| 7292 | } |
| 7293 | Signature sig = new Signature(key); |
| 7294 | pastSignatures.set(idx, sig); |
| 7295 | mSignatures[pos] = sig; |
| 7296 | pos++; |
| 7297 | } |
| 7298 | } catch (NumberFormatException e) { |
| 7299 | reportSettingsProblem(Log.WARN, |
| 7300 | "Error in package manager settings: <cert> " |
| 7301 | + "index " + index + " is not a number at " |
| 7302 | + parser.getPositionDescription()); |
| 7303 | } |
| 7304 | } else { |
| 7305 | reportSettingsProblem(Log.WARN, |
| 7306 | "Error in package manager settings: <cert> has" |
| 7307 | + " no index at " + parser.getPositionDescription()); |
| 7308 | } |
| 7309 | } else { |
| 7310 | reportSettingsProblem(Log.WARN, |
| 7311 | "Error in package manager settings: too " |
| 7312 | + "many <cert> tags, expected " + count |
| 7313 | + " at " + parser.getPositionDescription()); |
| 7314 | } |
| 7315 | } else { |
| 7316 | reportSettingsProblem(Log.WARN, |
| 7317 | "Unknown element under <cert>: " |
| 7318 | + parser.getName()); |
| 7319 | } |
| 7320 | XmlUtils.skipCurrentTag(parser); |
| 7321 | } |
| 7322 | |
| 7323 | if (pos < count) { |
| 7324 | // Should never happen -- there is an error in the written |
| 7325 | // settings -- but if it does we don't want to generate |
| 7326 | // a bad array. |
| 7327 | Signature[] newSigs = new Signature[pos]; |
| 7328 | System.arraycopy(mSignatures, 0, newSigs, 0, pos); |
| 7329 | mSignatures = newSigs; |
| 7330 | } |
| 7331 | } |
| 7332 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7333 | private void assignSignatures(Signature[] sigs) { |
| 7334 | if (sigs == null) { |
| 7335 | mSignatures = null; |
| 7336 | return; |
| 7337 | } |
| 7338 | mSignatures = new Signature[sigs.length]; |
| 7339 | for (int i=0; i<sigs.length; i++) { |
| 7340 | mSignatures[i] = sigs[i]; |
| 7341 | } |
| 7342 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7343 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7344 | @Override |
| 7345 | public String toString() { |
| 7346 | StringBuffer buf = new StringBuffer(128); |
| 7347 | buf.append("PackageSignatures{"); |
| 7348 | buf.append(Integer.toHexString(System.identityHashCode(this))); |
| 7349 | buf.append(" ["); |
| 7350 | if (mSignatures != null) { |
| 7351 | for (int i=0; i<mSignatures.length; i++) { |
| 7352 | if (i > 0) buf.append(", "); |
| 7353 | buf.append(Integer.toHexString( |
| 7354 | System.identityHashCode(mSignatures[i]))); |
| 7355 | } |
| 7356 | } |
| 7357 | buf.append("]}"); |
| 7358 | return buf.toString(); |
| 7359 | } |
| 7360 | } |
| 7361 | |
| 7362 | static class PreferredActivity extends IntentFilter { |
| 7363 | final int mMatch; |
| 7364 | final String[] mSetPackages; |
| 7365 | final String[] mSetClasses; |
| 7366 | final String[] mSetComponents; |
| 7367 | final ComponentName mActivity; |
| 7368 | final String mShortActivity; |
| 7369 | String mParseError; |
| 7370 | |
| 7371 | PreferredActivity(IntentFilter filter, int match, ComponentName[] set, |
| 7372 | ComponentName activity) { |
| 7373 | super(filter); |
| 7374 | mMatch = match&IntentFilter.MATCH_CATEGORY_MASK; |
| 7375 | mActivity = activity; |
| 7376 | mShortActivity = activity.flattenToShortString(); |
| 7377 | mParseError = null; |
| 7378 | if (set != null) { |
| 7379 | final int N = set.length; |
| 7380 | String[] myPackages = new String[N]; |
| 7381 | String[] myClasses = new String[N]; |
| 7382 | String[] myComponents = new String[N]; |
| 7383 | for (int i=0; i<N; i++) { |
| 7384 | ComponentName cn = set[i]; |
| 7385 | if (cn == null) { |
| 7386 | mSetPackages = null; |
| 7387 | mSetClasses = null; |
| 7388 | mSetComponents = null; |
| 7389 | return; |
| 7390 | } |
| 7391 | myPackages[i] = cn.getPackageName().intern(); |
| 7392 | myClasses[i] = cn.getClassName().intern(); |
| 7393 | myComponents[i] = cn.flattenToShortString().intern(); |
| 7394 | } |
| 7395 | mSetPackages = myPackages; |
| 7396 | mSetClasses = myClasses; |
| 7397 | mSetComponents = myComponents; |
| 7398 | } else { |
| 7399 | mSetPackages = null; |
| 7400 | mSetClasses = null; |
| 7401 | mSetComponents = null; |
| 7402 | } |
| 7403 | } |
| 7404 | |
| 7405 | PreferredActivity(XmlPullParser parser) throws XmlPullParserException, |
| 7406 | IOException { |
| 7407 | mShortActivity = parser.getAttributeValue(null, "name"); |
| 7408 | mActivity = ComponentName.unflattenFromString(mShortActivity); |
| 7409 | if (mActivity == null) { |
| 7410 | mParseError = "Bad activity name " + mShortActivity; |
| 7411 | } |
| 7412 | String matchStr = parser.getAttributeValue(null, "match"); |
| 7413 | mMatch = matchStr != null ? Integer.parseInt(matchStr, 16) : 0; |
| 7414 | String setCountStr = parser.getAttributeValue(null, "set"); |
| 7415 | int setCount = setCountStr != null ? Integer.parseInt(setCountStr) : 0; |
| 7416 | |
| 7417 | String[] myPackages = setCount > 0 ? new String[setCount] : null; |
| 7418 | String[] myClasses = setCount > 0 ? new String[setCount] : null; |
| 7419 | String[] myComponents = setCount > 0 ? new String[setCount] : null; |
| 7420 | |
| 7421 | int setPos = 0; |
| 7422 | |
| 7423 | int outerDepth = parser.getDepth(); |
| 7424 | int type; |
| 7425 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 7426 | && (type != XmlPullParser.END_TAG |
| 7427 | || parser.getDepth() > outerDepth)) { |
| 7428 | if (type == XmlPullParser.END_TAG |
| 7429 | || type == XmlPullParser.TEXT) { |
| 7430 | continue; |
| 7431 | } |
| 7432 | |
| 7433 | String tagName = parser.getName(); |
| 7434 | //Log.i(TAG, "Parse outerDepth=" + outerDepth + " depth=" |
| 7435 | // + parser.getDepth() + " tag=" + tagName); |
| 7436 | if (tagName.equals("set")) { |
| 7437 | String name = parser.getAttributeValue(null, "name"); |
| 7438 | if (name == null) { |
| 7439 | if (mParseError == null) { |
| 7440 | mParseError = "No name in set tag in preferred activity " |
| 7441 | + mShortActivity; |
| 7442 | } |
| 7443 | } else if (setPos >= setCount) { |
| 7444 | if (mParseError == null) { |
| 7445 | mParseError = "Too many set tags in preferred activity " |
| 7446 | + mShortActivity; |
| 7447 | } |
| 7448 | } else { |
| 7449 | ComponentName cn = ComponentName.unflattenFromString(name); |
| 7450 | if (cn == null) { |
| 7451 | if (mParseError == null) { |
| 7452 | mParseError = "Bad set name " + name + " in preferred activity " |
| 7453 | + mShortActivity; |
| 7454 | } |
| 7455 | } else { |
| 7456 | myPackages[setPos] = cn.getPackageName(); |
| 7457 | myClasses[setPos] = cn.getClassName(); |
| 7458 | myComponents[setPos] = name; |
| 7459 | setPos++; |
| 7460 | } |
| 7461 | } |
| 7462 | XmlUtils.skipCurrentTag(parser); |
| 7463 | } else if (tagName.equals("filter")) { |
| 7464 | //Log.i(TAG, "Starting to parse filter..."); |
| 7465 | readFromXml(parser); |
| 7466 | //Log.i(TAG, "Finished filter: outerDepth=" + outerDepth + " depth=" |
| 7467 | // + parser.getDepth() + " tag=" + parser.getName()); |
| 7468 | } else { |
| 7469 | reportSettingsProblem(Log.WARN, |
| 7470 | "Unknown element under <preferred-activities>: " |
| 7471 | + parser.getName()); |
| 7472 | XmlUtils.skipCurrentTag(parser); |
| 7473 | } |
| 7474 | } |
| 7475 | |
| 7476 | if (setPos != setCount) { |
| 7477 | if (mParseError == null) { |
| 7478 | mParseError = "Not enough set tags (expected " + setCount |
| 7479 | + " but found " + setPos + ") in " + mShortActivity; |
| 7480 | } |
| 7481 | } |
| 7482 | |
| 7483 | mSetPackages = myPackages; |
| 7484 | mSetClasses = myClasses; |
| 7485 | mSetComponents = myComponents; |
| 7486 | } |
| 7487 | |
| 7488 | public void writeToXml(XmlSerializer serializer) throws IOException { |
| 7489 | final int NS = mSetClasses != null ? mSetClasses.length : 0; |
| 7490 | serializer.attribute(null, "name", mShortActivity); |
| 7491 | serializer.attribute(null, "match", Integer.toHexString(mMatch)); |
| 7492 | serializer.attribute(null, "set", Integer.toString(NS)); |
| 7493 | for (int s=0; s<NS; s++) { |
| 7494 | serializer.startTag(null, "set"); |
| 7495 | serializer.attribute(null, "name", mSetComponents[s]); |
| 7496 | serializer.endTag(null, "set"); |
| 7497 | } |
| 7498 | serializer.startTag(null, "filter"); |
| 7499 | super.writeToXml(serializer); |
| 7500 | serializer.endTag(null, "filter"); |
| 7501 | } |
| 7502 | |
| 7503 | boolean sameSet(List<ResolveInfo> query, int priority) { |
| 7504 | if (mSetPackages == null) return false; |
| 7505 | final int NQ = query.size(); |
| 7506 | final int NS = mSetPackages.length; |
| 7507 | int numMatch = 0; |
| 7508 | for (int i=0; i<NQ; i++) { |
| 7509 | ResolveInfo ri = query.get(i); |
| 7510 | if (ri.priority != priority) continue; |
| 7511 | ActivityInfo ai = ri.activityInfo; |
| 7512 | boolean good = false; |
| 7513 | for (int j=0; j<NS; j++) { |
| 7514 | if (mSetPackages[j].equals(ai.packageName) |
| 7515 | && mSetClasses[j].equals(ai.name)) { |
| 7516 | numMatch++; |
| 7517 | good = true; |
| 7518 | break; |
| 7519 | } |
| 7520 | } |
| 7521 | if (!good) return false; |
| 7522 | } |
| 7523 | return numMatch == NS; |
| 7524 | } |
| 7525 | } |
| 7526 | |
| 7527 | static class GrantedPermissions { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 7528 | int pkgFlags; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7529 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7530 | HashSet<String> grantedPermissions = new HashSet<String>(); |
| 7531 | int[] gids; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7532 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7533 | GrantedPermissions(int pkgFlags) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 7534 | setFlags(pkgFlags); |
| 7535 | } |
| 7536 | |
| 7537 | void setFlags(int pkgFlags) { |
| Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 7538 | this.pkgFlags = pkgFlags & ( |
| 7539 | ApplicationInfo.FLAG_SYSTEM | |
| 7540 | ApplicationInfo.FLAG_FORWARD_LOCK | |
| Jeff Brown | a749f86 | 2010-03-31 00:43:36 -0700 | [diff] [blame] | 7541 | ApplicationInfo.FLAG_EXTERNAL_STORAGE | |
| Jeff Brown | 767225d | 2010-03-30 23:49:17 -0700 | [diff] [blame] | 7542 | ApplicationInfo.FLAG_NEVER_ENCRYPT); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7543 | } |
| 7544 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7545 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7546 | /** |
| 7547 | * Settings base class for pending and resolved classes. |
| 7548 | */ |
| 7549 | static class PackageSettingBase extends GrantedPermissions { |
| 7550 | final String name; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7551 | final String realName; |
| Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 7552 | File codePath; |
| 7553 | String codePathString; |
| 7554 | File resourcePath; |
| 7555 | String resourcePathString; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 7556 | String nativeLibraryPathString; |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 7557 | String obbPathString; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | private long timeStamp; |
| 7559 | private String timeStampString = "0"; |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 7560 | int versionCode; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7561 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7562 | boolean uidError; |
| 7563 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7564 | PackageSignatures signatures = new PackageSignatures(); |
| 7565 | |
| 7566 | boolean permissionsFixed; |
| Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7567 | boolean haveGids; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7568 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7569 | /* Explicitly disabled components */ |
| 7570 | HashSet<String> disabledComponents = new HashSet<String>(0); |
| 7571 | /* Explicitly enabled components */ |
| 7572 | HashSet<String> enabledComponents = new HashSet<String>(0); |
| 7573 | int enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 7574 | int installStatus = PKG_INSTALL_COMPLETE; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7575 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7576 | PackageSettingBase origPackage; |
| 7577 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7578 | /* package name of the app that installed this package */ |
| 7579 | String installerPackageName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7580 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7581 | PackageSettingBase(String name, String realName, File codePath, File resourcePath, |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7582 | int pVersionCode, int pkgFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7583 | super(pkgFlags); |
| 7584 | this.name = name; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7585 | this.realName = realName; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7586 | init(codePath, resourcePath, pVersionCode); |
| 7587 | } |
| 7588 | |
| 7589 | void init(File codePath, File resourcePath, int pVersionCode) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7590 | this.codePath = codePath; |
| 7591 | this.codePathString = codePath.toString(); |
| 7592 | this.resourcePath = resourcePath; |
| 7593 | this.resourcePathString = resourcePath.toString(); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7594 | this.versionCode = pVersionCode; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7595 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 7596 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7597 | public void setInstallerPackageName(String packageName) { |
| 7598 | installerPackageName = packageName; |
| 7599 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7600 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7601 | String getInstallerPackageName() { |
| 7602 | return installerPackageName; |
| 7603 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7604 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7605 | public void setInstallStatus(int newStatus) { |
| 7606 | installStatus = newStatus; |
| 7607 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7608 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7609 | public int getInstallStatus() { |
| 7610 | return installStatus; |
| 7611 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7612 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7613 | public void setTimeStamp(long newStamp) { |
| 7614 | if (newStamp != timeStamp) { |
| 7615 | timeStamp = newStamp; |
| 7616 | timeStampString = Long.toString(newStamp); |
| 7617 | } |
| 7618 | } |
| 7619 | |
| 7620 | public void setTimeStamp(long newStamp, String newStampStr) { |
| 7621 | timeStamp = newStamp; |
| 7622 | timeStampString = newStampStr; |
| 7623 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7625 | public long getTimeStamp() { |
| 7626 | return timeStamp; |
| 7627 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7629 | public String getTimeStampStr() { |
| 7630 | return timeStampString; |
| 7631 | } |
| 7632 | |
| 7633 | public void copyFrom(PackageSettingBase base) { |
| 7634 | grantedPermissions = base.grantedPermissions; |
| 7635 | gids = base.gids; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7636 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7637 | timeStamp = base.timeStamp; |
| 7638 | timeStampString = base.timeStampString; |
| 7639 | signatures = base.signatures; |
| 7640 | permissionsFixed = base.permissionsFixed; |
| Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7641 | haveGids = base.haveGids; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7642 | disabledComponents = base.disabledComponents; |
| 7643 | enabledComponents = base.enabledComponents; |
| 7644 | enabled = base.enabled; |
| 7645 | installStatus = base.installStatus; |
| 7646 | } |
| 7647 | |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 7648 | boolean enableComponentLP(String componentClassName) { |
| 7649 | boolean changed = disabledComponents.remove(componentClassName); |
| 7650 | changed |= enabledComponents.add(componentClassName); |
| 7651 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7652 | } |
| 7653 | |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 7654 | boolean disableComponentLP(String componentClassName) { |
| 7655 | boolean changed = enabledComponents.remove(componentClassName); |
| 7656 | changed |= disabledComponents.add(componentClassName); |
| 7657 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7658 | } |
| 7659 | |
| Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 7660 | boolean restoreComponentLP(String componentClassName) { |
| 7661 | boolean changed = enabledComponents.remove(componentClassName); |
| 7662 | changed |= disabledComponents.remove(componentClassName); |
| 7663 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7664 | } |
| 7665 | |
| 7666 | int currentEnabledStateLP(String componentName) { |
| 7667 | if (enabledComponents.contains(componentName)) { |
| 7668 | return COMPONENT_ENABLED_STATE_ENABLED; |
| 7669 | } else if (disabledComponents.contains(componentName)) { |
| 7670 | return COMPONENT_ENABLED_STATE_DISABLED; |
| 7671 | } else { |
| 7672 | return COMPONENT_ENABLED_STATE_DEFAULT; |
| 7673 | } |
| 7674 | } |
| 7675 | } |
| 7676 | |
| 7677 | /** |
| 7678 | * Settings data for a particular package we know about. |
| 7679 | */ |
| 7680 | static final class PackageSetting extends PackageSettingBase { |
| 7681 | int userId; |
| 7682 | PackageParser.Package pkg; |
| 7683 | SharedUserSetting sharedUser; |
| 7684 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7685 | PackageSetting(String name, String realName, File codePath, File resourcePath, |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7686 | int pVersionCode, int pkgFlags) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7687 | super(name, realName, codePath, resourcePath, pVersionCode, pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7688 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7689 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7690 | @Override |
| 7691 | public String toString() { |
| 7692 | return "PackageSetting{" |
| 7693 | + Integer.toHexString(System.identityHashCode(this)) |
| 7694 | + " " + name + "/" + userId + "}"; |
| 7695 | } |
| 7696 | } |
| 7697 | |
| 7698 | /** |
| 7699 | * Settings data for a particular shared user ID we know about. |
| 7700 | */ |
| 7701 | static final class SharedUserSetting extends GrantedPermissions { |
| 7702 | final String name; |
| 7703 | int userId; |
| 7704 | final HashSet<PackageSetting> packages = new HashSet<PackageSetting>(); |
| 7705 | final PackageSignatures signatures = new PackageSignatures(); |
| 7706 | |
| 7707 | SharedUserSetting(String _name, int _pkgFlags) { |
| 7708 | super(_pkgFlags); |
| 7709 | name = _name; |
| 7710 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7711 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | @Override |
| 7713 | public String toString() { |
| 7714 | return "SharedUserSetting{" |
| 7715 | + Integer.toHexString(System.identityHashCode(this)) |
| 7716 | + " " + name + "/" + userId + "}"; |
| 7717 | } |
| 7718 | } |
| 7719 | |
| 7720 | /** |
| 7721 | * Holds information about dynamic settings. |
| 7722 | */ |
| 7723 | private static final class Settings { |
| 7724 | private final File mSettingsFilename; |
| 7725 | private final File mBackupSettingsFilename; |
| David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 7726 | private final File mPackageListFilename; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7727 | private final HashMap<String, PackageSetting> mPackages = |
| 7728 | new HashMap<String, PackageSetting>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7729 | // List of replaced system applications |
| 7730 | final HashMap<String, PackageSetting> mDisabledSysPackages = |
| 7731 | new HashMap<String, PackageSetting>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7732 | |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 7733 | // These are the last platform API version we were using for |
| 7734 | // the apps installed on internal and external storage. It is |
| 7735 | // used to grant newer permissions one time during a system upgrade. |
| 7736 | int mInternalSdkPlatform; |
| 7737 | int mExternalSdkPlatform; |
| 7738 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7739 | // The user's preferred activities associated with particular intent |
| 7740 | // filters. |
| 7741 | private final IntentResolver<PreferredActivity, PreferredActivity> mPreferredActivities = |
| 7742 | new IntentResolver<PreferredActivity, PreferredActivity>() { |
| 7743 | @Override |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7744 | protected String packageForFilter(PreferredActivity filter) { |
| 7745 | return filter.mActivity.getPackageName(); |
| 7746 | } |
| 7747 | @Override |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7748 | protected void dumpFilter(PrintWriter out, String prefix, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7749 | PreferredActivity filter) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7750 | out.print(prefix); out.print( |
| 7751 | Integer.toHexString(System.identityHashCode(filter))); |
| 7752 | out.print(' '); |
| 7753 | out.print(filter.mActivity.flattenToShortString()); |
| 7754 | out.print(" match=0x"); |
| 7755 | out.println( Integer.toHexString(filter.mMatch)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7756 | if (filter.mSetComponents != null) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7757 | out.print(prefix); out.println(" Selected from:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7758 | for (int i=0; i<filter.mSetComponents.length; i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7759 | out.print(prefix); out.print(" "); |
| 7760 | out.println(filter.mSetComponents[i]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7761 | } |
| 7762 | } |
| 7763 | } |
| 7764 | }; |
| 7765 | private final HashMap<String, SharedUserSetting> mSharedUsers = |
| 7766 | new HashMap<String, SharedUserSetting>(); |
| 7767 | private final ArrayList<Object> mUserIds = new ArrayList<Object>(); |
| 7768 | private final SparseArray<Object> mOtherUserIds = |
| 7769 | new SparseArray<Object>(); |
| 7770 | |
| 7771 | // For reading/writing settings file. |
| 7772 | private final ArrayList<Signature> mPastSignatures = |
| 7773 | new ArrayList<Signature>(); |
| 7774 | |
| 7775 | // Mapping from permission names to info about them. |
| 7776 | final HashMap<String, BasePermission> mPermissions = |
| 7777 | new HashMap<String, BasePermission>(); |
| 7778 | |
| 7779 | // Mapping from permission tree names to info about them. |
| 7780 | final HashMap<String, BasePermission> mPermissionTrees = |
| 7781 | new HashMap<String, BasePermission>(); |
| 7782 | |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 7783 | // Packages that have been uninstalled and still need their external |
| 7784 | // storage data deleted. |
| 7785 | final ArrayList<String> mPackagesToBeCleaned = new ArrayList<String>(); |
| 7786 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7787 | // Packages that have been renamed since they were first installed. |
| 7788 | // Keys are the new names of the packages, values are the original |
| 7789 | // names. The packages appear everwhere else under their original |
| 7790 | // names. |
| 7791 | final HashMap<String, String> mRenamedPackages = new HashMap<String, String>(); |
| 7792 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7793 | private final StringBuilder mReadMessages = new StringBuilder(); |
| 7794 | |
| 7795 | private static final class PendingPackage extends PackageSettingBase { |
| 7796 | final int sharedId; |
| 7797 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7798 | PendingPackage(String name, String realName, File codePath, File resourcePath, |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7799 | int sharedId, int pVersionCode, int pkgFlags) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7800 | super(name, realName, codePath, resourcePath, pVersionCode, pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7801 | this.sharedId = sharedId; |
| 7802 | } |
| 7803 | } |
| 7804 | private final ArrayList<PendingPackage> mPendingPackages |
| 7805 | = new ArrayList<PendingPackage>(); |
| 7806 | |
| 7807 | Settings() { |
| 7808 | File dataDir = Environment.getDataDirectory(); |
| 7809 | File systemDir = new File(dataDir, "system"); |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7810 | // TODO(oam): This secure dir creation needs to be moved somewhere else (later) |
| 7811 | File systemSecureDir = new File(dataDir, "secure/system"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7812 | systemDir.mkdirs(); |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7813 | systemSecureDir.mkdirs(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7814 | FileUtils.setPermissions(systemDir.toString(), |
| 7815 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 7816 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 7817 | -1, -1); |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7818 | FileUtils.setPermissions(systemSecureDir.toString(), |
| 7819 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 7820 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 7821 | -1, -1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7822 | mSettingsFilename = new File(systemDir, "packages.xml"); |
| 7823 | mBackupSettingsFilename = new File(systemDir, "packages-backup.xml"); |
| David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 7824 | mPackageListFilename = new File(systemDir, "packages.list"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7825 | } |
| 7826 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7827 | PackageSetting getPackageLP(PackageParser.Package pkg, PackageSetting origPackage, |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7828 | String realName, SharedUserSetting sharedUser, File codePath, File resourcePath, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7829 | int pkgFlags, boolean create, boolean add) { |
| 7830 | final String name = pkg.packageName; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7831 | PackageSetting p = getPackageLP(name, origPackage, realName, sharedUser, codePath, |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7832 | resourcePath, pkg.mVersionCode, pkgFlags, create, add); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7833 | return p; |
| 7834 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7835 | |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7836 | PackageSetting peekPackageLP(String name) { |
| 7837 | return mPackages.get(name); |
| 7838 | /* |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7839 | PackageSetting p = mPackages.get(name); |
| 7840 | if (p != null && p.codePath.getPath().equals(codePath)) { |
| 7841 | return p; |
| 7842 | } |
| 7843 | return null; |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7844 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7845 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7846 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7847 | void setInstallStatus(String pkgName, int status) { |
| 7848 | PackageSetting p = mPackages.get(pkgName); |
| 7849 | if(p != null) { |
| 7850 | if(p.getInstallStatus() != status) { |
| 7851 | p.setInstallStatus(status); |
| 7852 | } |
| 7853 | } |
| 7854 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7855 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7856 | void setInstallerPackageName(String pkgName, |
| 7857 | String installerPkgName) { |
| 7858 | PackageSetting p = mPackages.get(pkgName); |
| 7859 | if(p != null) { |
| 7860 | p.setInstallerPackageName(installerPkgName); |
| 7861 | } |
| 7862 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7863 | |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7864 | String getInstallerPackageName(String pkgName) { |
| 7865 | PackageSetting p = mPackages.get(pkgName); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7866 | return (p == null) ? null : p.getInstallerPackageName(); |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7867 | } |
| 7868 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | int getInstallStatus(String pkgName) { |
| 7870 | PackageSetting p = mPackages.get(pkgName); |
| 7871 | if(p != null) { |
| 7872 | return p.getInstallStatus(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7873 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7874 | return -1; |
| 7875 | } |
| 7876 | |
| 7877 | SharedUserSetting getSharedUserLP(String name, |
| 7878 | int pkgFlags, boolean create) { |
| 7879 | SharedUserSetting s = mSharedUsers.get(name); |
| 7880 | if (s == null) { |
| 7881 | if (!create) { |
| 7882 | return null; |
| 7883 | } |
| 7884 | s = new SharedUserSetting(name, pkgFlags); |
| 7885 | if (MULTIPLE_APPLICATION_UIDS) { |
| 7886 | s.userId = newUserIdLP(s); |
| 7887 | } else { |
| 7888 | s.userId = FIRST_APPLICATION_UID; |
| 7889 | } |
| 7890 | Log.i(TAG, "New shared user " + name + ": id=" + s.userId); |
| 7891 | // < 0 means we couldn't assign a userid; fall out and return |
| 7892 | // s, which is currently null |
| 7893 | if (s.userId >= 0) { |
| 7894 | mSharedUsers.put(name, s); |
| 7895 | } |
| 7896 | } |
| 7897 | |
| 7898 | return s; |
| 7899 | } |
| 7900 | |
| 7901 | int disableSystemPackageLP(String name) { |
| 7902 | PackageSetting p = mPackages.get(name); |
| 7903 | if(p == null) { |
| 7904 | Log.w(TAG, "Package:"+name+" is not an installed package"); |
| 7905 | return -1; |
| 7906 | } |
| 7907 | PackageSetting dp = mDisabledSysPackages.get(name); |
| 7908 | // always make sure the system package code and resource paths dont change |
| 7909 | if(dp == null) { |
| 7910 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 7911 | p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 7912 | } |
| 7913 | mDisabledSysPackages.put(name, p); |
| 7914 | } |
| 7915 | return removePackageLP(name); |
| 7916 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7917 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7918 | PackageSetting enableSystemPackageLP(String name) { |
| 7919 | PackageSetting p = mDisabledSysPackages.get(name); |
| 7920 | if(p == null) { |
| 7921 | Log.w(TAG, "Package:"+name+" is not disabled"); |
| 7922 | return null; |
| 7923 | } |
| 7924 | // Reset flag in ApplicationInfo object |
| 7925 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 7926 | p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 7927 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7928 | PackageSetting ret = addPackageLP(name, p.realName, p.codePath, |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7929 | p.resourcePath, p.userId, p.versionCode, p.pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7930 | mDisabledSysPackages.remove(name); |
| 7931 | return ret; |
| 7932 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7933 | |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7934 | PackageSetting addPackageLP(String name, String realName, File codePath, |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7935 | File resourcePath, int uid, int vc, int pkgFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7936 | PackageSetting p = mPackages.get(name); |
| 7937 | if (p != null) { |
| 7938 | if (p.userId == uid) { |
| 7939 | return p; |
| 7940 | } |
| 7941 | reportSettingsProblem(Log.ERROR, |
| 7942 | "Adding duplicate package, keeping first: " + name); |
| 7943 | return null; |
| 7944 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7945 | p = new PackageSetting(name, realName, codePath, resourcePath, vc, pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7946 | p.userId = uid; |
| 7947 | if (addUserIdLP(uid, p, name)) { |
| 7948 | mPackages.put(name, p); |
| 7949 | return p; |
| 7950 | } |
| 7951 | return null; |
| 7952 | } |
| 7953 | |
| 7954 | SharedUserSetting addSharedUserLP(String name, int uid, int pkgFlags) { |
| 7955 | SharedUserSetting s = mSharedUsers.get(name); |
| 7956 | if (s != null) { |
| 7957 | if (s.userId == uid) { |
| 7958 | return s; |
| 7959 | } |
| 7960 | reportSettingsProblem(Log.ERROR, |
| 7961 | "Adding duplicate shared user, keeping first: " + name); |
| 7962 | return null; |
| 7963 | } |
| 7964 | s = new SharedUserSetting(name, pkgFlags); |
| 7965 | s.userId = uid; |
| 7966 | if (addUserIdLP(uid, s, name)) { |
| 7967 | mSharedUsers.put(name, s); |
| 7968 | return s; |
| 7969 | } |
| 7970 | return null; |
| 7971 | } |
| 7972 | |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7973 | // Transfer ownership of permissions from one package to another. |
| 7974 | private void transferPermissions(String origPkg, String newPkg) { |
| 7975 | // Transfer ownership of permissions to the new package. |
| 7976 | for (int i=0; i<2; i++) { |
| 7977 | HashMap<String, BasePermission> permissions = |
| 7978 | i == 0 ? mPermissionTrees : mPermissions; |
| 7979 | for (BasePermission bp : permissions.values()) { |
| 7980 | if (origPkg.equals(bp.sourcePackage)) { |
| 7981 | if (DEBUG_UPGRADE) Log.v(TAG, |
| 7982 | "Moving permission " + bp.name |
| 7983 | + " from pkg " + bp.sourcePackage |
| 7984 | + " to " + newPkg); |
| 7985 | bp.sourcePackage = newPkg; |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7986 | bp.packageSetting = null; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7987 | bp.perm = null; |
| 7988 | if (bp.pendingInfo != null) { |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7989 | bp.pendingInfo.packageName = newPkg; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7990 | } |
| 7991 | bp.uid = 0; |
| 7992 | bp.gids = null; |
| 7993 | } |
| 7994 | } |
| 7995 | } |
| 7996 | } |
| 7997 | |
| 7998 | private PackageSetting getPackageLP(String name, PackageSetting origPackage, |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7999 | String realName, SharedUserSetting sharedUser, File codePath, File resourcePath, |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8000 | int vc, int pkgFlags, boolean create, boolean add) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8001 | PackageSetting p = mPackages.get(name); |
| 8002 | if (p != null) { |
| 8003 | if (!p.codePath.equals(codePath)) { |
| 8004 | // Check to see if its a disabled system app |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8005 | if((p != null) && ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| Suchi Amalapurapu | b24a967 | 2009-07-01 14:04:43 -0700 | [diff] [blame] | 8006 | // This is an updated system app with versions in both system |
| 8007 | // and data partition. Just let the most recent version |
| 8008 | // take precedence. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8009 | Slog.w(TAG, "Trying to update system app code path from " + |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8010 | p.codePathString + " to " + codePath.toString()); |
| Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 8011 | } else { |
| Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 8012 | // Just a change in the code path is not an issue, but |
| 8013 | // let's log a message about it. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8014 | Slog.i(TAG, "Package " + name + " codePath changed from " + p.codePath |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8015 | + " to " + codePath + "; Retaining data and using new"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8016 | } |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8017 | } |
| 8018 | if (p.sharedUser != sharedUser) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8019 | reportSettingsProblem(Log.WARN, |
| 8020 | "Package " + name + " shared user changed from " |
| 8021 | + (p.sharedUser != null ? p.sharedUser.name : "<nothing>") |
| 8022 | + " to " |
| 8023 | + (sharedUser != null ? sharedUser.name : "<nothing>") |
| 8024 | + "; replacing with new"); |
| 8025 | p = null; |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8026 | } else { |
| 8027 | if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 8028 | // If what we are scanning is a system package, then |
| 8029 | // make it so, regardless of whether it was previously |
| 8030 | // installed only in the data partition. |
| 8031 | p.pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 8032 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8033 | } |
| 8034 | } |
| 8035 | if (p == null) { |
| 8036 | // Create a new PackageSettings entry. this can end up here because |
| 8037 | // of code path mismatch or user id mismatch of an updated system partition |
| 8038 | if (!create) { |
| 8039 | return null; |
| 8040 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8041 | if (origPackage != null) { |
| 8042 | // We are consuming the data from an existing package. |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8043 | p = new PackageSetting(origPackage.name, name, codePath, |
| 8044 | resourcePath, vc, pkgFlags); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8045 | if (DEBUG_UPGRADE) Log.v(TAG, "Package " + name |
| 8046 | + " is adopting original package " + origPackage.name); |
| Dianne Hackborn | 4b45041 | 2010-03-11 16:20:08 -0800 | [diff] [blame] | 8047 | // Note that we will retain the new package's signature so |
| 8048 | // that we can keep its data. |
| 8049 | PackageSignatures s = p.signatures; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8050 | p.copyFrom(origPackage); |
| Dianne Hackborn | 4b45041 | 2010-03-11 16:20:08 -0800 | [diff] [blame] | 8051 | p.signatures = s; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8052 | p.sharedUser = origPackage.sharedUser; |
| 8053 | p.userId = origPackage.userId; |
| 8054 | p.origPackage = origPackage; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8055 | mRenamedPackages.put(name, origPackage.name); |
| 8056 | name = origPackage.name; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8057 | // Update new package state. |
| 8058 | p.setTimeStamp(codePath.lastModified()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8059 | } else { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8060 | p = new PackageSetting(name, realName, codePath, resourcePath, vc, pkgFlags); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8061 | p.setTimeStamp(codePath.lastModified()); |
| 8062 | p.sharedUser = sharedUser; |
| 8063 | if (sharedUser != null) { |
| 8064 | p.userId = sharedUser.userId; |
| 8065 | } else if (MULTIPLE_APPLICATION_UIDS) { |
| 8066 | // Clone the setting here for disabled system packages |
| 8067 | PackageSetting dis = mDisabledSysPackages.get(name); |
| 8068 | if (dis != null) { |
| 8069 | // For disabled packages a new setting is created |
| 8070 | // from the existing user id. This still has to be |
| 8071 | // added to list of user id's |
| 8072 | // Copy signatures from previous setting |
| 8073 | if (dis.signatures.mSignatures != null) { |
| 8074 | p.signatures.mSignatures = dis.signatures.mSignatures.clone(); |
| 8075 | } |
| 8076 | p.userId = dis.userId; |
| 8077 | // Clone permissions |
| 8078 | p.grantedPermissions = new HashSet<String>(dis.grantedPermissions); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8079 | // Clone component info |
| 8080 | p.disabledComponents = new HashSet<String>(dis.disabledComponents); |
| 8081 | p.enabledComponents = new HashSet<String>(dis.enabledComponents); |
| 8082 | // Add new setting to list of user ids |
| 8083 | addUserIdLP(p.userId, p, name); |
| 8084 | } else { |
| 8085 | // Assign new user id |
| 8086 | p.userId = newUserIdLP(p); |
| 8087 | } |
| 8088 | } else { |
| 8089 | p.userId = FIRST_APPLICATION_UID; |
| 8090 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8091 | } |
| 8092 | if (p.userId < 0) { |
| 8093 | reportSettingsProblem(Log.WARN, |
| 8094 | "Package " + name + " could not be assigned a valid uid"); |
| 8095 | return null; |
| 8096 | } |
| 8097 | if (add) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8098 | // 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] | 8099 | // user preferences |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8100 | addPackageSettingLP(p, name, sharedUser); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8101 | } |
| 8102 | } |
| 8103 | return p; |
| 8104 | } |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8105 | |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8106 | private void insertPackageSettingLP(PackageSetting p, PackageParser.Package pkg) { |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8107 | p.pkg = pkg; |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 8108 | pkg.mSetEnabled = p.enabled; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8109 | final String codePath = pkg.applicationInfo.sourceDir; |
| 8110 | final String resourcePath = pkg.applicationInfo.publicSourceDir; |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8111 | // Update code path if needed |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8112 | if (!codePath.equalsIgnoreCase(p.codePathString)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8113 | Slog.w(TAG, "Code path for pkg : " + p.pkg.packageName + |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8114 | " changing from " + p.codePathString + " to " + codePath); |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8115 | p.codePath = new File(codePath); |
| 8116 | p.codePathString = codePath; |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8117 | } |
| 8118 | //Update resource path if needed |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8119 | if (!resourcePath.equalsIgnoreCase(p.resourcePathString)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8120 | Slog.w(TAG, "Resource path for pkg : " + p.pkg.packageName + |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8121 | " changing from " + p.resourcePathString + " to " + resourcePath); |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8122 | p.resourcePath = new File(resourcePath); |
| 8123 | p.resourcePathString = resourcePath; |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8124 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8125 | // Update the native library path if needed |
| 8126 | final String nativeLibraryPath = pkg.applicationInfo.nativeLibraryDir; |
| 8127 | if (nativeLibraryPath != null |
| 8128 | && !nativeLibraryPath.equalsIgnoreCase(p.nativeLibraryPathString)) { |
| 8129 | p.nativeLibraryPathString = nativeLibraryPath; |
| 8130 | } |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8131 | // Update version code if needed |
| 8132 | if (pkg.mVersionCode != p.versionCode) { |
| 8133 | p.versionCode = pkg.mVersionCode; |
| 8134 | } |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 8135 | // Update signatures if needed. |
| 8136 | if (p.signatures.mSignatures == null) { |
| 8137 | p.signatures.assignSignatures(pkg.mSignatures); |
| 8138 | } |
| 8139 | // If this app defines a shared user id initialize |
| 8140 | // the shared user signatures as well. |
| 8141 | if (p.sharedUser != null && p.sharedUser.signatures.mSignatures == null) { |
| 8142 | p.sharedUser.signatures.assignSignatures(pkg.mSignatures); |
| 8143 | } |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8144 | addPackageSettingLP(p, pkg.packageName, p.sharedUser); |
| 8145 | } |
| 8146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8147 | // Utility method that adds a PackageSetting to mPackages and |
| 8148 | // completes updating the shared user attributes |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8149 | private void addPackageSettingLP(PackageSetting p, String name, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8150 | SharedUserSetting sharedUser) { |
| 8151 | mPackages.put(name, p); |
| 8152 | if (sharedUser != null) { |
| 8153 | if (p.sharedUser != null && p.sharedUser != sharedUser) { |
| 8154 | reportSettingsProblem(Log.ERROR, |
| 8155 | "Package " + p.name + " was user " |
| 8156 | + p.sharedUser + " but is now " + sharedUser |
| 8157 | + "; I am not changing its files so it will probably fail!"); |
| 8158 | p.sharedUser.packages.remove(p); |
| 8159 | } else if (p.userId != sharedUser.userId) { |
| 8160 | reportSettingsProblem(Log.ERROR, |
| 8161 | "Package " + p.name + " was user id " + p.userId |
| 8162 | + " but is now user " + sharedUser |
| 8163 | + " with id " + sharedUser.userId |
| 8164 | + "; I am not changing its files so it will probably fail!"); |
| 8165 | } |
| 8166 | |
| 8167 | sharedUser.packages.add(p); |
| 8168 | p.sharedUser = sharedUser; |
| 8169 | p.userId = sharedUser.userId; |
| 8170 | } |
| 8171 | } |
| 8172 | |
| Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8173 | /* |
| 8174 | * Update the shared user setting when a package using |
| 8175 | * specifying the shared user id is removed. The gids |
| 8176 | * associated with each permission of the deleted package |
| 8177 | * are removed from the shared user's gid list only if its |
| 8178 | * not in use by other permissions of packages in the |
| 8179 | * shared user setting. |
| 8180 | */ |
| 8181 | private void updateSharedUserPermsLP(PackageSetting deletedPs, int[] globalGids) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8182 | if ( (deletedPs == null) || (deletedPs.pkg == null)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8183 | 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] | 8184 | return; |
| 8185 | } |
| 8186 | // No sharedUserId |
| 8187 | if (deletedPs.sharedUser == null) { |
| 8188 | return; |
| 8189 | } |
| 8190 | SharedUserSetting sus = deletedPs.sharedUser; |
| 8191 | // Update permissions |
| 8192 | for (String eachPerm: deletedPs.pkg.requestedPermissions) { |
| 8193 | boolean used = false; |
| 8194 | if (!sus.grantedPermissions.contains (eachPerm)) { |
| 8195 | continue; |
| 8196 | } |
| 8197 | for (PackageSetting pkg:sus.packages) { |
| Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8198 | if (pkg.pkg != null && |
| Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 8199 | !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) && |
| Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8200 | pkg.pkg.requestedPermissions.contains(eachPerm)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8201 | used = true; |
| 8202 | break; |
| 8203 | } |
| 8204 | } |
| 8205 | if (!used) { |
| 8206 | // can safely delete this permission from list |
| 8207 | sus.grantedPermissions.remove(eachPerm); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8208 | } |
| 8209 | } |
| 8210 | // Update gids |
| Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8211 | int newGids[] = globalGids; |
| 8212 | for (String eachPerm : sus.grantedPermissions) { |
| 8213 | BasePermission bp = mPermissions.get(eachPerm); |
| Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8214 | if (bp != null) { |
| 8215 | newGids = appendInts(newGids, bp.gids); |
| 8216 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8217 | } |
| 8218 | sus.gids = newGids; |
| 8219 | } |
| Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8220 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8221 | private int removePackageLP(String name) { |
| 8222 | PackageSetting p = mPackages.get(name); |
| 8223 | if (p != null) { |
| 8224 | mPackages.remove(name); |
| 8225 | if (p.sharedUser != null) { |
| 8226 | p.sharedUser.packages.remove(p); |
| 8227 | if (p.sharedUser.packages.size() == 0) { |
| 8228 | mSharedUsers.remove(p.sharedUser.name); |
| 8229 | removeUserIdLP(p.sharedUser.userId); |
| 8230 | return p.sharedUser.userId; |
| 8231 | } |
| 8232 | } else { |
| 8233 | removeUserIdLP(p.userId); |
| 8234 | return p.userId; |
| 8235 | } |
| 8236 | } |
| 8237 | return -1; |
| 8238 | } |
| 8239 | |
| 8240 | private boolean addUserIdLP(int uid, Object obj, Object name) { |
| 8241 | if (uid >= FIRST_APPLICATION_UID + MAX_APPLICATION_UIDS) { |
| 8242 | return false; |
| 8243 | } |
| 8244 | |
| 8245 | if (uid >= FIRST_APPLICATION_UID) { |
| 8246 | int N = mUserIds.size(); |
| 8247 | final int index = uid - FIRST_APPLICATION_UID; |
| 8248 | while (index >= N) { |
| 8249 | mUserIds.add(null); |
| 8250 | N++; |
| 8251 | } |
| 8252 | if (mUserIds.get(index) != null) { |
| 8253 | reportSettingsProblem(Log.ERROR, |
| Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8254 | "Adding duplicate user id: " + uid |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8255 | + " name=" + name); |
| 8256 | return false; |
| 8257 | } |
| 8258 | mUserIds.set(index, obj); |
| 8259 | } else { |
| 8260 | if (mOtherUserIds.get(uid) != null) { |
| 8261 | reportSettingsProblem(Log.ERROR, |
| 8262 | "Adding duplicate shared id: " + uid |
| 8263 | + " name=" + name); |
| 8264 | return false; |
| 8265 | } |
| 8266 | mOtherUserIds.put(uid, obj); |
| 8267 | } |
| 8268 | return true; |
| 8269 | } |
| 8270 | |
| 8271 | public Object getUserIdLP(int uid) { |
| 8272 | if (uid >= FIRST_APPLICATION_UID) { |
| 8273 | int N = mUserIds.size(); |
| 8274 | final int index = uid - FIRST_APPLICATION_UID; |
| 8275 | return index < N ? mUserIds.get(index) : null; |
| 8276 | } else { |
| 8277 | return mOtherUserIds.get(uid); |
| 8278 | } |
| 8279 | } |
| 8280 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 8281 | private Set<String> findPackagesWithFlag(int flag) { |
| 8282 | Set<String> ret = new HashSet<String>(); |
| 8283 | for (PackageSetting ps : mPackages.values()) { |
| 8284 | // Has to match atleast all the flag bits set on flag |
| 8285 | if ((ps.pkgFlags & flag) == flag) { |
| 8286 | ret.add(ps.name); |
| 8287 | } |
| 8288 | } |
| 8289 | return ret; |
| 8290 | } |
| 8291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8292 | private void removeUserIdLP(int uid) { |
| 8293 | if (uid >= FIRST_APPLICATION_UID) { |
| 8294 | int N = mUserIds.size(); |
| 8295 | final int index = uid - FIRST_APPLICATION_UID; |
| 8296 | if (index < N) mUserIds.set(index, null); |
| 8297 | } else { |
| 8298 | mOtherUserIds.remove(uid); |
| 8299 | } |
| 8300 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8301 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8302 | void writeLP() { |
| 8303 | //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024); |
| 8304 | |
| 8305 | // Keep the old settings around until we know the new ones have |
| 8306 | // been successfully written. |
| 8307 | if (mSettingsFilename.exists()) { |
| Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8308 | // Presence of backup settings file indicates that we failed |
| 8309 | // to persist settings earlier. So preserve the older |
| 8310 | // backup for future reference since the current settings |
| 8311 | // might have been corrupted. |
| 8312 | if (!mBackupSettingsFilename.exists()) { |
| 8313 | if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8314 | 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] | 8315 | return; |
| 8316 | } |
| 8317 | } else { |
| Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8318 | mSettingsFilename.delete(); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8319 | Slog.w(TAG, "Preserving older settings backup"); |
| Suchi Amalapurapu | 3d7e855 | 2009-09-17 15:38:20 -0700 | [diff] [blame] | 8320 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8321 | } |
| 8322 | |
| 8323 | mPastSignatures.clear(); |
| 8324 | |
| 8325 | try { |
| 8326 | FileOutputStream str = new FileOutputStream(mSettingsFilename); |
| 8327 | |
| 8328 | //XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 8329 | XmlSerializer serializer = new FastXmlSerializer(); |
| 8330 | serializer.setOutput(str, "utf-8"); |
| 8331 | serializer.startDocument(null, true); |
| 8332 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 8333 | |
| 8334 | serializer.startTag(null, "packages"); |
| 8335 | |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 8336 | serializer.startTag(null, "last-platform-version"); |
| 8337 | serializer.attribute(null, "internal", Integer.toString(mInternalSdkPlatform)); |
| 8338 | serializer.attribute(null, "external", Integer.toString(mExternalSdkPlatform)); |
| 8339 | serializer.endTag(null, "last-platform-version"); |
| 8340 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8341 | serializer.startTag(null, "permission-trees"); |
| 8342 | for (BasePermission bp : mPermissionTrees.values()) { |
| 8343 | writePermission(serializer, bp); |
| 8344 | } |
| 8345 | serializer.endTag(null, "permission-trees"); |
| 8346 | |
| 8347 | serializer.startTag(null, "permissions"); |
| 8348 | for (BasePermission bp : mPermissions.values()) { |
| 8349 | writePermission(serializer, bp); |
| 8350 | } |
| 8351 | serializer.endTag(null, "permissions"); |
| 8352 | |
| 8353 | for (PackageSetting pkg : mPackages.values()) { |
| 8354 | writePackage(serializer, pkg); |
| 8355 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8356 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8357 | for (PackageSetting pkg : mDisabledSysPackages.values()) { |
| 8358 | writeDisabledSysPackage(serializer, pkg); |
| 8359 | } |
| 8360 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8361 | serializer.startTag(null, "preferred-activities"); |
| 8362 | for (PreferredActivity pa : mPreferredActivities.filterSet()) { |
| 8363 | serializer.startTag(null, "item"); |
| 8364 | pa.writeToXml(serializer); |
| 8365 | serializer.endTag(null, "item"); |
| 8366 | } |
| 8367 | serializer.endTag(null, "preferred-activities"); |
| 8368 | |
| 8369 | for (SharedUserSetting usr : mSharedUsers.values()) { |
| 8370 | serializer.startTag(null, "shared-user"); |
| 8371 | serializer.attribute(null, "name", usr.name); |
| 8372 | serializer.attribute(null, "userId", |
| 8373 | Integer.toString(usr.userId)); |
| 8374 | usr.signatures.writeXml(serializer, "sigs", mPastSignatures); |
| 8375 | serializer.startTag(null, "perms"); |
| 8376 | for (String name : usr.grantedPermissions) { |
| 8377 | serializer.startTag(null, "item"); |
| 8378 | serializer.attribute(null, "name", name); |
| 8379 | serializer.endTag(null, "item"); |
| 8380 | } |
| 8381 | serializer.endTag(null, "perms"); |
| 8382 | serializer.endTag(null, "shared-user"); |
| 8383 | } |
| 8384 | |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8385 | if (mPackagesToBeCleaned.size() > 0) { |
| 8386 | for (int i=0; i<mPackagesToBeCleaned.size(); i++) { |
| 8387 | serializer.startTag(null, "cleaning-package"); |
| 8388 | serializer.attribute(null, "name", mPackagesToBeCleaned.get(i)); |
| 8389 | serializer.endTag(null, "cleaning-package"); |
| 8390 | } |
| 8391 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8392 | |
| 8393 | if (mRenamedPackages.size() > 0) { |
| 8394 | for (HashMap.Entry<String, String> e : mRenamedPackages.entrySet()) { |
| 8395 | serializer.startTag(null, "renamed-package"); |
| 8396 | serializer.attribute(null, "new", e.getKey()); |
| 8397 | serializer.attribute(null, "old", e.getValue()); |
| 8398 | serializer.endTag(null, "renamed-package"); |
| 8399 | } |
| 8400 | } |
| 8401 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8402 | serializer.endTag(null, "packages"); |
| 8403 | |
| 8404 | serializer.endDocument(); |
| 8405 | |
| 8406 | str.flush(); |
| 8407 | str.close(); |
| 8408 | |
| 8409 | // New settings successfully written, old ones are no longer |
| 8410 | // needed. |
| 8411 | mBackupSettingsFilename.delete(); |
| 8412 | FileUtils.setPermissions(mSettingsFilename.toString(), |
| 8413 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
| 8414 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP |
| 8415 | |FileUtils.S_IROTH, |
| 8416 | -1, -1); |
| David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 8417 | |
| 8418 | // Write package list file now, use a JournaledFile. |
| 8419 | // |
| 8420 | File tempFile = new File(mPackageListFilename.toString() + ".tmp"); |
| 8421 | JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile); |
| 8422 | |
| 8423 | str = new FileOutputStream(journal.chooseForWrite()); |
| 8424 | try { |
| 8425 | StringBuilder sb = new StringBuilder(); |
| 8426 | for (PackageSetting pkg : mPackages.values()) { |
| 8427 | ApplicationInfo ai = pkg.pkg.applicationInfo; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8428 | String dataPath = ai.dataDir; |
| David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 8429 | boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 8430 | |
| 8431 | // Avoid any application that has a space in its path |
| 8432 | // or that is handled by the system. |
| 8433 | if (dataPath.indexOf(" ") >= 0 || ai.uid <= Process.FIRST_APPLICATION_UID) |
| 8434 | continue; |
| 8435 | |
| 8436 | // we store on each line the following information for now: |
| 8437 | // |
| 8438 | // pkgName - package name |
| 8439 | // userId - application-specific user id |
| 8440 | // debugFlag - 0 or 1 if the package is debuggable. |
| 8441 | // dataPath - path to package's data path |
| 8442 | // |
| 8443 | // NOTE: We prefer not to expose all ApplicationInfo flags for now. |
| 8444 | // |
| 8445 | // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS |
| 8446 | // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES: |
| 8447 | // system/core/run-as/run-as.c |
| 8448 | // |
| 8449 | sb.setLength(0); |
| 8450 | sb.append(ai.packageName); |
| 8451 | sb.append(" "); |
| 8452 | sb.append((int)ai.uid); |
| 8453 | sb.append(isDebug ? " 1 " : " 0 "); |
| 8454 | sb.append(dataPath); |
| 8455 | sb.append("\n"); |
| 8456 | str.write(sb.toString().getBytes()); |
| 8457 | } |
| 8458 | str.flush(); |
| 8459 | str.close(); |
| 8460 | journal.commit(); |
| 8461 | } |
| 8462 | catch (Exception e) { |
| 8463 | journal.rollback(); |
| 8464 | } |
| 8465 | |
| 8466 | FileUtils.setPermissions(mPackageListFilename.toString(), |
| 8467 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
| 8468 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP |
| 8469 | |FileUtils.S_IROTH, |
| 8470 | -1, -1); |
| 8471 | |
| Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8472 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8473 | |
| 8474 | } catch(XmlPullParserException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8475 | 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] | 8476 | } catch(java.io.IOException e) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8477 | 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] | 8478 | } |
| David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 8479 | // Clean up partially written files |
| Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8480 | if (mSettingsFilename.exists()) { |
| 8481 | if (!mSettingsFilename.delete()) { |
| 8482 | Log.i(TAG, "Failed to clean up mangled file: " + mSettingsFilename); |
| 8483 | } |
| 8484 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8485 | //Debug.stopMethodTracing(); |
| 8486 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8487 | |
| 8488 | void writeDisabledSysPackage(XmlSerializer serializer, final PackageSetting pkg) |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8489 | throws java.io.IOException { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8490 | serializer.startTag(null, "updated-package"); |
| 8491 | serializer.attribute(null, "name", pkg.name); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8492 | if (pkg.realName != null) { |
| 8493 | serializer.attribute(null, "realName", pkg.realName); |
| 8494 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8495 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 8496 | serializer.attribute(null, "ts", pkg.getTimeStampStr()); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8497 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8498 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 8499 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 8500 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8501 | if (pkg.nativeLibraryPathString != null) { |
| 8502 | serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString); |
| 8503 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8504 | if (pkg.sharedUser == null) { |
| 8505 | serializer.attribute(null, "userId", |
| 8506 | Integer.toString(pkg.userId)); |
| 8507 | } else { |
| 8508 | serializer.attribute(null, "sharedUserId", |
| 8509 | Integer.toString(pkg.userId)); |
| 8510 | } |
| 8511 | serializer.startTag(null, "perms"); |
| 8512 | if (pkg.sharedUser == null) { |
| 8513 | // If this is a shared user, the permissions will |
| 8514 | // be written there. We still need to write an |
| 8515 | // empty permissions list so permissionsFixed will |
| 8516 | // be set. |
| 8517 | for (final String name : pkg.grantedPermissions) { |
| 8518 | BasePermission bp = mPermissions.get(name); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8519 | if (bp != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8520 | // We only need to write signature or system permissions but this wont |
| 8521 | // match the semantics of grantedPermissions. So write all permissions. |
| 8522 | serializer.startTag(null, "item"); |
| 8523 | serializer.attribute(null, "name", name); |
| 8524 | serializer.endTag(null, "item"); |
| 8525 | } |
| 8526 | } |
| 8527 | } |
| 8528 | serializer.endTag(null, "perms"); |
| 8529 | serializer.endTag(null, "updated-package"); |
| 8530 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8531 | |
| 8532 | void writePackage(XmlSerializer serializer, final PackageSetting pkg) |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8533 | throws java.io.IOException { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8534 | serializer.startTag(null, "package"); |
| 8535 | serializer.attribute(null, "name", pkg.name); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8536 | if (pkg.realName != null) { |
| 8537 | serializer.attribute(null, "realName", pkg.realName); |
| 8538 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8539 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 8540 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 8541 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 8542 | } |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8543 | if (pkg.nativeLibraryPathString != null) { |
| 8544 | serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString); |
| 8545 | } |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8546 | serializer.attribute(null, "flags", |
| 8547 | Integer.toString(pkg.pkgFlags)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8548 | serializer.attribute(null, "ts", pkg.getTimeStampStr()); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8549 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8550 | if (pkg.sharedUser == null) { |
| 8551 | serializer.attribute(null, "userId", |
| 8552 | Integer.toString(pkg.userId)); |
| 8553 | } else { |
| 8554 | serializer.attribute(null, "sharedUserId", |
| 8555 | Integer.toString(pkg.userId)); |
| 8556 | } |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8557 | if (pkg.uidError) { |
| 8558 | serializer.attribute(null, "uidError", "true"); |
| 8559 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8560 | if (pkg.enabled != COMPONENT_ENABLED_STATE_DEFAULT) { |
| 8561 | serializer.attribute(null, "enabled", |
| 8562 | pkg.enabled == COMPONENT_ENABLED_STATE_ENABLED |
| 8563 | ? "true" : "false"); |
| 8564 | } |
| 8565 | if(pkg.installStatus == PKG_INSTALL_INCOMPLETE) { |
| 8566 | serializer.attribute(null, "installStatus", "false"); |
| 8567 | } |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8568 | if (pkg.installerPackageName != null) { |
| 8569 | serializer.attribute(null, "installer", pkg.installerPackageName); |
| 8570 | } |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 8571 | if (pkg.obbPathString != null) { |
| 8572 | serializer.attribute(null, "obbPath", pkg.obbPathString); |
| 8573 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8574 | pkg.signatures.writeXml(serializer, "sigs", mPastSignatures); |
| 8575 | if ((pkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 8576 | serializer.startTag(null, "perms"); |
| 8577 | if (pkg.sharedUser == null) { |
| 8578 | // If this is a shared user, the permissions will |
| 8579 | // be written there. We still need to write an |
| 8580 | // empty permissions list so permissionsFixed will |
| 8581 | // be set. |
| 8582 | for (final String name : pkg.grantedPermissions) { |
| 8583 | serializer.startTag(null, "item"); |
| 8584 | serializer.attribute(null, "name", name); |
| 8585 | serializer.endTag(null, "item"); |
| 8586 | } |
| 8587 | } |
| 8588 | serializer.endTag(null, "perms"); |
| 8589 | } |
| 8590 | if (pkg.disabledComponents.size() > 0) { |
| 8591 | serializer.startTag(null, "disabled-components"); |
| 8592 | for (final String name : pkg.disabledComponents) { |
| 8593 | serializer.startTag(null, "item"); |
| 8594 | serializer.attribute(null, "name", name); |
| 8595 | serializer.endTag(null, "item"); |
| 8596 | } |
| 8597 | serializer.endTag(null, "disabled-components"); |
| 8598 | } |
| 8599 | if (pkg.enabledComponents.size() > 0) { |
| 8600 | serializer.startTag(null, "enabled-components"); |
| 8601 | for (final String name : pkg.enabledComponents) { |
| 8602 | serializer.startTag(null, "item"); |
| 8603 | serializer.attribute(null, "name", name); |
| 8604 | serializer.endTag(null, "item"); |
| 8605 | } |
| 8606 | serializer.endTag(null, "enabled-components"); |
| 8607 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8608 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8609 | serializer.endTag(null, "package"); |
| 8610 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8611 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8612 | void writePermission(XmlSerializer serializer, BasePermission bp) |
| 8613 | throws XmlPullParserException, java.io.IOException { |
| 8614 | if (bp.type != BasePermission.TYPE_BUILTIN |
| 8615 | && bp.sourcePackage != null) { |
| 8616 | serializer.startTag(null, "item"); |
| 8617 | serializer.attribute(null, "name", bp.name); |
| 8618 | serializer.attribute(null, "package", bp.sourcePackage); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8619 | if (bp.protectionLevel != |
| 8620 | PermissionInfo.PROTECTION_NORMAL) { |
| 8621 | serializer.attribute(null, "protection", |
| 8622 | Integer.toString(bp.protectionLevel)); |
| 8623 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8624 | if (DEBUG_SETTINGS) Log.v(TAG, |
| 8625 | "Writing perm: name=" + bp.name + " type=" + bp.type); |
| 8626 | if (bp.type == BasePermission.TYPE_DYNAMIC) { |
| 8627 | PermissionInfo pi = bp.perm != null ? bp.perm.info |
| 8628 | : bp.pendingInfo; |
| 8629 | if (pi != null) { |
| 8630 | serializer.attribute(null, "type", "dynamic"); |
| 8631 | if (pi.icon != 0) { |
| 8632 | serializer.attribute(null, "icon", |
| 8633 | Integer.toString(pi.icon)); |
| 8634 | } |
| 8635 | if (pi.nonLocalizedLabel != null) { |
| 8636 | serializer.attribute(null, "label", |
| 8637 | pi.nonLocalizedLabel.toString()); |
| 8638 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8639 | } |
| 8640 | } |
| 8641 | serializer.endTag(null, "item"); |
| 8642 | } |
| 8643 | } |
| 8644 | |
| 8645 | String getReadMessagesLP() { |
| 8646 | return mReadMessages.toString(); |
| 8647 | } |
| 8648 | |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8649 | ArrayList<PackageSetting> getListOfIncompleteInstallPackages() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8650 | HashSet<String> kList = new HashSet<String>(mPackages.keySet()); |
| 8651 | Iterator<String> its = kList.iterator(); |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8652 | ArrayList<PackageSetting> ret = new ArrayList<PackageSetting>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8653 | while(its.hasNext()) { |
| 8654 | String key = its.next(); |
| 8655 | PackageSetting ps = mPackages.get(key); |
| 8656 | if(ps.getInstallStatus() == PKG_INSTALL_INCOMPLETE) { |
| Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8657 | ret.add(ps); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8658 | } |
| 8659 | } |
| 8660 | return ret; |
| 8661 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8662 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8663 | boolean readLP() { |
| 8664 | FileInputStream str = null; |
| 8665 | if (mBackupSettingsFilename.exists()) { |
| 8666 | try { |
| 8667 | str = new FileInputStream(mBackupSettingsFilename); |
| 8668 | mReadMessages.append("Reading from backup settings file\n"); |
| 8669 | Log.i(TAG, "Reading from backup settings file!"); |
| Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8670 | if (mSettingsFilename.exists()) { |
| 8671 | // If both the backup and settings file exist, we |
| 8672 | // ignore the settings since it might have been |
| 8673 | // corrupted. |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8674 | Slog.w(TAG, "Cleaning up settings file " + mSettingsFilename); |
| Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8675 | mSettingsFilename.delete(); |
| 8676 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8677 | } catch (java.io.IOException e) { |
| 8678 | // We'll try for the normal settings file. |
| 8679 | } |
| 8680 | } |
| 8681 | |
| 8682 | mPastSignatures.clear(); |
| 8683 | |
| 8684 | try { |
| 8685 | if (str == null) { |
| 8686 | if (!mSettingsFilename.exists()) { |
| 8687 | mReadMessages.append("No settings file found\n"); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8688 | Slog.i(TAG, "No current settings file!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8689 | return false; |
| 8690 | } |
| 8691 | str = new FileInputStream(mSettingsFilename); |
| 8692 | } |
| 8693 | XmlPullParser parser = Xml.newPullParser(); |
| 8694 | parser.setInput(str, null); |
| 8695 | |
| 8696 | int type; |
| 8697 | while ((type=parser.next()) != XmlPullParser.START_TAG |
| 8698 | && type != XmlPullParser.END_DOCUMENT) { |
| 8699 | ; |
| 8700 | } |
| 8701 | |
| 8702 | if (type != XmlPullParser.START_TAG) { |
| 8703 | mReadMessages.append("No start tag found in settings file\n"); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8704 | 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] | 8705 | return false; |
| 8706 | } |
| 8707 | |
| 8708 | int outerDepth = parser.getDepth(); |
| 8709 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8710 | && (type != XmlPullParser.END_TAG |
| 8711 | || parser.getDepth() > outerDepth)) { |
| 8712 | if (type == XmlPullParser.END_TAG |
| 8713 | || type == XmlPullParser.TEXT) { |
| 8714 | continue; |
| 8715 | } |
| 8716 | |
| 8717 | String tagName = parser.getName(); |
| 8718 | if (tagName.equals("package")) { |
| 8719 | readPackageLP(parser); |
| 8720 | } else if (tagName.equals("permissions")) { |
| 8721 | readPermissionsLP(mPermissions, parser); |
| 8722 | } else if (tagName.equals("permission-trees")) { |
| 8723 | readPermissionsLP(mPermissionTrees, parser); |
| 8724 | } else if (tagName.equals("shared-user")) { |
| 8725 | readSharedUserLP(parser); |
| 8726 | } else if (tagName.equals("preferred-packages")) { |
| Dianne Hackborn | a7ca0e5 | 2009-12-01 14:31:55 -0800 | [diff] [blame] | 8727 | // no longer used. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8728 | } else if (tagName.equals("preferred-activities")) { |
| 8729 | readPreferredActivitiesLP(parser); |
| 8730 | } else if(tagName.equals("updated-package")) { |
| 8731 | readDisabledSysPackageLP(parser); |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8732 | } else if (tagName.equals("cleaning-package")) { |
| 8733 | String name = parser.getAttributeValue(null, "name"); |
| 8734 | if (name != null) { |
| 8735 | mPackagesToBeCleaned.add(name); |
| 8736 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8737 | } else if (tagName.equals("renamed-package")) { |
| 8738 | String nname = parser.getAttributeValue(null, "new"); |
| 8739 | String oname = parser.getAttributeValue(null, "old"); |
| 8740 | if (nname != null && oname != null) { |
| 8741 | mRenamedPackages.put(nname, oname); |
| 8742 | } |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 8743 | } else if (tagName.equals("last-platform-version")) { |
| 8744 | mInternalSdkPlatform = mExternalSdkPlatform = 0; |
| 8745 | try { |
| 8746 | String internal = parser.getAttributeValue(null, "internal"); |
| 8747 | if (internal != null) { |
| 8748 | mInternalSdkPlatform = Integer.parseInt(internal); |
| 8749 | } |
| 8750 | String external = parser.getAttributeValue(null, "external"); |
| 8751 | if (external != null) { |
| Bryan Mawhinney | 2131a3c | 2010-04-23 14:38:31 +0100 | [diff] [blame] | 8752 | mExternalSdkPlatform = Integer.parseInt(external); |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 8753 | } |
| 8754 | } catch (NumberFormatException e) { |
| 8755 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8756 | } else { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8757 | Slog.w(TAG, "Unknown element under <packages>: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8758 | + parser.getName()); |
| 8759 | XmlUtils.skipCurrentTag(parser); |
| 8760 | } |
| 8761 | } |
| 8762 | |
| 8763 | str.close(); |
| 8764 | |
| 8765 | } catch(XmlPullParserException e) { |
| 8766 | mReadMessages.append("Error reading: " + e.toString()); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8767 | Slog.e(TAG, "Error reading package manager settings", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8768 | |
| 8769 | } catch(java.io.IOException e) { |
| 8770 | mReadMessages.append("Error reading: " + e.toString()); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8771 | Slog.e(TAG, "Error reading package manager settings", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8772 | |
| 8773 | } |
| 8774 | |
| 8775 | int N = mPendingPackages.size(); |
| 8776 | for (int i=0; i<N; i++) { |
| 8777 | final PendingPackage pp = mPendingPackages.get(i); |
| 8778 | Object idObj = getUserIdLP(pp.sharedId); |
| 8779 | if (idObj != null && idObj instanceof SharedUserSetting) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8780 | PackageSetting p = getPackageLP(pp.name, null, pp.realName, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8781 | (SharedUserSetting)idObj, pp.codePath, pp.resourcePath, |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8782 | pp.versionCode, pp.pkgFlags, true, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8783 | if (p == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8784 | Slog.w(TAG, "Unable to create application package for " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8785 | + pp.name); |
| 8786 | continue; |
| 8787 | } |
| 8788 | p.copyFrom(pp); |
| 8789 | } else if (idObj != null) { |
| 8790 | String msg = "Bad package setting: package " + pp.name |
| 8791 | + " has shared uid " + pp.sharedId |
| 8792 | + " that is not a shared uid\n"; |
| 8793 | mReadMessages.append(msg); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8794 | Slog.e(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8795 | } else { |
| 8796 | String msg = "Bad package setting: package " + pp.name |
| 8797 | + " has shared uid " + pp.sharedId |
| 8798 | + " that is not defined\n"; |
| 8799 | mReadMessages.append(msg); |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8800 | Slog.e(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8801 | } |
| 8802 | } |
| 8803 | mPendingPackages.clear(); |
| 8804 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8805 | mReadMessages.append("Read completed successfully: " |
| 8806 | + mPackages.size() + " packages, " |
| 8807 | + mSharedUsers.size() + " shared uids\n"); |
| 8808 | |
| 8809 | return true; |
| 8810 | } |
| 8811 | |
| 8812 | private int readInt(XmlPullParser parser, String ns, String name, |
| 8813 | int defValue) { |
| 8814 | String v = parser.getAttributeValue(ns, name); |
| 8815 | try { |
| 8816 | if (v == null) { |
| 8817 | return defValue; |
| 8818 | } |
| 8819 | return Integer.parseInt(v); |
| 8820 | } catch (NumberFormatException e) { |
| 8821 | reportSettingsProblem(Log.WARN, |
| 8822 | "Error in package manager settings: attribute " + |
| 8823 | name + " has bad integer value " + v + " at " |
| 8824 | + parser.getPositionDescription()); |
| 8825 | } |
| 8826 | return defValue; |
| 8827 | } |
| 8828 | |
| 8829 | private void readPermissionsLP(HashMap<String, BasePermission> out, |
| 8830 | XmlPullParser parser) |
| 8831 | throws IOException, XmlPullParserException { |
| 8832 | int outerDepth = parser.getDepth(); |
| 8833 | int type; |
| 8834 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8835 | && (type != XmlPullParser.END_TAG |
| 8836 | || parser.getDepth() > outerDepth)) { |
| 8837 | if (type == XmlPullParser.END_TAG |
| 8838 | || type == XmlPullParser.TEXT) { |
| 8839 | continue; |
| 8840 | } |
| 8841 | |
| 8842 | String tagName = parser.getName(); |
| 8843 | if (tagName.equals("item")) { |
| 8844 | String name = parser.getAttributeValue(null, "name"); |
| 8845 | String sourcePackage = parser.getAttributeValue(null, "package"); |
| 8846 | String ptype = parser.getAttributeValue(null, "type"); |
| 8847 | if (name != null && sourcePackage != null) { |
| 8848 | boolean dynamic = "dynamic".equals(ptype); |
| 8849 | BasePermission bp = new BasePermission(name, sourcePackage, |
| 8850 | dynamic |
| 8851 | ? BasePermission.TYPE_DYNAMIC |
| 8852 | : BasePermission.TYPE_NORMAL); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8853 | bp.protectionLevel = readInt(parser, null, "protection", |
| 8854 | PermissionInfo.PROTECTION_NORMAL); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8855 | if (dynamic) { |
| 8856 | PermissionInfo pi = new PermissionInfo(); |
| 8857 | pi.packageName = sourcePackage.intern(); |
| 8858 | pi.name = name.intern(); |
| 8859 | pi.icon = readInt(parser, null, "icon", 0); |
| 8860 | pi.nonLocalizedLabel = parser.getAttributeValue( |
| 8861 | null, "label"); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8862 | pi.protectionLevel = bp.protectionLevel; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8863 | bp.pendingInfo = pi; |
| 8864 | } |
| 8865 | out.put(bp.name, bp); |
| 8866 | } else { |
| 8867 | reportSettingsProblem(Log.WARN, |
| 8868 | "Error in package manager settings: permissions has" |
| 8869 | + " no name at " + parser.getPositionDescription()); |
| 8870 | } |
| 8871 | } else { |
| 8872 | reportSettingsProblem(Log.WARN, |
| 8873 | "Unknown element reading permissions: " |
| 8874 | + parser.getName() + " at " |
| 8875 | + parser.getPositionDescription()); |
| 8876 | } |
| 8877 | XmlUtils.skipCurrentTag(parser); |
| 8878 | } |
| 8879 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8881 | private void readDisabledSysPackageLP(XmlPullParser parser) |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8882 | throws XmlPullParserException, IOException { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8883 | String name = parser.getAttributeValue(null, "name"); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8884 | String realName = parser.getAttributeValue(null, "realName"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8885 | String codePathStr = parser.getAttributeValue(null, "codePath"); |
| 8886 | String resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8887 | if (resourcePathStr == null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8888 | resourcePathStr = codePathStr; |
| 8889 | } |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8890 | String version = parser.getAttributeValue(null, "version"); |
| 8891 | int versionCode = 0; |
| 8892 | if (version != null) { |
| 8893 | try { |
| 8894 | versionCode = Integer.parseInt(version); |
| 8895 | } catch (NumberFormatException e) { |
| 8896 | } |
| 8897 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8898 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8899 | int pkgFlags = 0; |
| 8900 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8901 | PackageSetting ps = new PackageSetting(name, realName, |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8902 | new File(codePathStr), |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8903 | new File(resourcePathStr), versionCode, pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8904 | String timeStampStr = parser.getAttributeValue(null, "ts"); |
| 8905 | if (timeStampStr != null) { |
| 8906 | try { |
| 8907 | long timeStamp = Long.parseLong(timeStampStr); |
| 8908 | ps.setTimeStamp(timeStamp, timeStampStr); |
| 8909 | } catch (NumberFormatException e) { |
| 8910 | } |
| 8911 | } |
| 8912 | String idStr = parser.getAttributeValue(null, "userId"); |
| 8913 | ps.userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 8914 | if(ps.userId <= 0) { |
| 8915 | String sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 8916 | ps.userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; |
| 8917 | } |
| 8918 | int outerDepth = parser.getDepth(); |
| 8919 | int type; |
| 8920 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8921 | && (type != XmlPullParser.END_TAG |
| 8922 | || parser.getDepth() > outerDepth)) { |
| 8923 | if (type == XmlPullParser.END_TAG |
| 8924 | || type == XmlPullParser.TEXT) { |
| 8925 | continue; |
| 8926 | } |
| 8927 | |
| 8928 | String tagName = parser.getName(); |
| 8929 | if (tagName.equals("perms")) { |
| 8930 | readGrantedPermissionsLP(parser, |
| 8931 | ps.grantedPermissions); |
| 8932 | } else { |
| 8933 | reportSettingsProblem(Log.WARN, |
| 8934 | "Unknown element under <updated-package>: " |
| 8935 | + parser.getName()); |
| 8936 | XmlUtils.skipCurrentTag(parser); |
| 8937 | } |
| 8938 | } |
| 8939 | mDisabledSysPackages.put(name, ps); |
| 8940 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8941 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8942 | private void readPackageLP(XmlPullParser parser) |
| 8943 | throws XmlPullParserException, IOException { |
| 8944 | String name = null; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8945 | String realName = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8946 | String idStr = null; |
| 8947 | String sharedIdStr = null; |
| 8948 | String codePathStr = null; |
| 8949 | String resourcePathStr = null; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8950 | String nativeLibraryPathStr = null; |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 8951 | String obbPathStr = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8952 | String systemStr = null; |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8953 | String installerPackageName = null; |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8954 | String uidError = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8955 | int pkgFlags = 0; |
| 8956 | String timeStampStr; |
| 8957 | long timeStamp = 0; |
| 8958 | PackageSettingBase packageSetting = null; |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8959 | String version = null; |
| 8960 | int versionCode = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8961 | try { |
| 8962 | name = parser.getAttributeValue(null, "name"); |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8963 | realName = parser.getAttributeValue(null, "realName"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8964 | idStr = parser.getAttributeValue(null, "userId"); |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8965 | uidError = parser.getAttributeValue(null, "uidError"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8966 | sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 8967 | codePathStr = parser.getAttributeValue(null, "codePath"); |
| 8968 | resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 8969 | nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath"); |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 8970 | obbPathStr = parser.getAttributeValue(null, "obbPath"); |
| Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8971 | version = parser.getAttributeValue(null, "version"); |
| 8972 | if (version != null) { |
| 8973 | try { |
| 8974 | versionCode = Integer.parseInt(version); |
| 8975 | } catch (NumberFormatException e) { |
| 8976 | } |
| 8977 | } |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8978 | installerPackageName = parser.getAttributeValue(null, "installer"); |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8979 | |
| 8980 | systemStr = parser.getAttributeValue(null, "flags"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8981 | if (systemStr != null) { |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8982 | try { |
| 8983 | pkgFlags = Integer.parseInt(systemStr); |
| 8984 | } catch (NumberFormatException e) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8985 | } |
| 8986 | } else { |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8987 | // For backward compatibility |
| 8988 | systemStr = parser.getAttributeValue(null, "system"); |
| 8989 | if (systemStr != null) { |
| 8990 | pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM : 0; |
| 8991 | } else { |
| 8992 | // Old settings that don't specify system... just treat |
| 8993 | // them as system, good enough. |
| 8994 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 8995 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8996 | } |
| 8997 | timeStampStr = parser.getAttributeValue(null, "ts"); |
| 8998 | if (timeStampStr != null) { |
| 8999 | try { |
| 9000 | timeStamp = Long.parseLong(timeStampStr); |
| 9001 | } catch (NumberFormatException e) { |
| 9002 | } |
| 9003 | } |
| 9004 | if (DEBUG_SETTINGS) Log.v(TAG, "Reading package: " + name |
| 9005 | + " userId=" + idStr + " sharedUserId=" + sharedIdStr); |
| 9006 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 9007 | if (resourcePathStr == null) { |
| 9008 | resourcePathStr = codePathStr; |
| 9009 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9010 | if (realName != null) { |
| 9011 | realName = realName.intern(); |
| 9012 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9013 | if (name == null) { |
| 9014 | reportSettingsProblem(Log.WARN, |
| 9015 | "Error in package manager settings: <package> has no name at " |
| 9016 | + parser.getPositionDescription()); |
| 9017 | } else if (codePathStr == null) { |
| 9018 | reportSettingsProblem(Log.WARN, |
| 9019 | "Error in package manager settings: <package> has no codePath at " |
| 9020 | + parser.getPositionDescription()); |
| 9021 | } else if (userId > 0) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9022 | packageSetting = addPackageLP(name.intern(), realName, |
| 9023 | new File(codePathStr), new File(resourcePathStr), |
| 9024 | userId, versionCode, pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9025 | if (DEBUG_SETTINGS) Log.i(TAG, "Reading package " + name |
| 9026 | + ": userId=" + userId + " pkg=" + packageSetting); |
| 9027 | if (packageSetting == null) { |
| 9028 | reportSettingsProblem(Log.ERROR, |
| 9029 | "Failure adding uid " + userId |
| 9030 | + " while parsing settings at " |
| 9031 | + parser.getPositionDescription()); |
| 9032 | } else { |
| 9033 | packageSetting.setTimeStamp(timeStamp, timeStampStr); |
| 9034 | } |
| 9035 | } else if (sharedIdStr != null) { |
| 9036 | userId = sharedIdStr != null |
| 9037 | ? Integer.parseInt(sharedIdStr) : 0; |
| 9038 | if (userId > 0) { |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9039 | packageSetting = new PendingPackage(name.intern(), realName, |
| 9040 | new File(codePathStr), new File(resourcePathStr), |
| 9041 | userId, versionCode, pkgFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9042 | packageSetting.setTimeStamp(timeStamp, timeStampStr); |
| 9043 | mPendingPackages.add((PendingPackage) packageSetting); |
| 9044 | if (DEBUG_SETTINGS) Log.i(TAG, "Reading package " + name |
| 9045 | + ": sharedUserId=" + userId + " pkg=" |
| 9046 | + packageSetting); |
| 9047 | } else { |
| 9048 | reportSettingsProblem(Log.WARN, |
| 9049 | "Error in package manager settings: package " |
| 9050 | + name + " has bad sharedId " + sharedIdStr |
| 9051 | + " at " + parser.getPositionDescription()); |
| 9052 | } |
| 9053 | } else { |
| 9054 | reportSettingsProblem(Log.WARN, |
| 9055 | "Error in package manager settings: package " |
| 9056 | + name + " has bad userId " + idStr + " at " |
| 9057 | + parser.getPositionDescription()); |
| 9058 | } |
| 9059 | } catch (NumberFormatException e) { |
| 9060 | reportSettingsProblem(Log.WARN, |
| 9061 | "Error in package manager settings: package " |
| 9062 | + name + " has bad userId " + idStr + " at " |
| 9063 | + parser.getPositionDescription()); |
| 9064 | } |
| 9065 | if (packageSetting != null) { |
| Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 9066 | packageSetting.uidError = "true".equals(uidError); |
| Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 9067 | packageSetting.installerPackageName = installerPackageName; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9068 | packageSetting.nativeLibraryPathString = nativeLibraryPathStr; |
| Kenny Root | 93565c4b | 2010-06-18 15:46:06 -0700 | [diff] [blame] | 9069 | packageSetting.obbPathString = obbPathStr; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9070 | final String enabledStr = parser.getAttributeValue(null, "enabled"); |
| 9071 | if (enabledStr != null) { |
| 9072 | if (enabledStr.equalsIgnoreCase("true")) { |
| 9073 | packageSetting.enabled = COMPONENT_ENABLED_STATE_ENABLED; |
| 9074 | } else if (enabledStr.equalsIgnoreCase("false")) { |
| 9075 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DISABLED; |
| 9076 | } else if (enabledStr.equalsIgnoreCase("default")) { |
| 9077 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 9078 | } else { |
| 9079 | reportSettingsProblem(Log.WARN, |
| 9080 | "Error in package manager settings: package " |
| 9081 | + name + " has bad enabled value: " + idStr |
| 9082 | + " at " + parser.getPositionDescription()); |
| 9083 | } |
| 9084 | } else { |
| 9085 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 9086 | } |
| 9087 | final String installStatusStr = parser.getAttributeValue(null, "installStatus"); |
| 9088 | if (installStatusStr != null) { |
| 9089 | if (installStatusStr.equalsIgnoreCase("false")) { |
| 9090 | packageSetting.installStatus = PKG_INSTALL_INCOMPLETE; |
| 9091 | } else { |
| 9092 | packageSetting.installStatus = PKG_INSTALL_COMPLETE; |
| 9093 | } |
| 9094 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9095 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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("disabled-components")) { |
| 9108 | readDisabledComponentsLP(packageSetting, parser); |
| 9109 | } else if (tagName.equals("enabled-components")) { |
| 9110 | readEnabledComponentsLP(packageSetting, parser); |
| 9111 | } else if (tagName.equals("sigs")) { |
| 9112 | packageSetting.signatures.readXml(parser, mPastSignatures); |
| 9113 | } else if (tagName.equals("perms")) { |
| 9114 | readGrantedPermissionsLP(parser, |
| Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 9115 | packageSetting.grantedPermissions); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9116 | packageSetting.permissionsFixed = true; |
| 9117 | } else { |
| 9118 | reportSettingsProblem(Log.WARN, |
| 9119 | "Unknown element under <package>: " |
| 9120 | + parser.getName()); |
| 9121 | XmlUtils.skipCurrentTag(parser); |
| 9122 | } |
| 9123 | } |
| 9124 | } else { |
| 9125 | XmlUtils.skipCurrentTag(parser); |
| 9126 | } |
| 9127 | } |
| 9128 | |
| 9129 | private void readDisabledComponentsLP(PackageSettingBase packageSetting, |
| 9130 | XmlPullParser parser) |
| 9131 | throws IOException, XmlPullParserException { |
| 9132 | int outerDepth = parser.getDepth(); |
| 9133 | int type; |
| 9134 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9135 | && (type != XmlPullParser.END_TAG |
| 9136 | || parser.getDepth() > outerDepth)) { |
| 9137 | if (type == XmlPullParser.END_TAG |
| 9138 | || type == XmlPullParser.TEXT) { |
| 9139 | continue; |
| 9140 | } |
| 9141 | |
| 9142 | String tagName = parser.getName(); |
| 9143 | if (tagName.equals("item")) { |
| 9144 | String name = parser.getAttributeValue(null, "name"); |
| 9145 | if (name != null) { |
| 9146 | packageSetting.disabledComponents.add(name.intern()); |
| 9147 | } else { |
| 9148 | reportSettingsProblem(Log.WARN, |
| 9149 | "Error in package manager settings: <disabled-components> has" |
| 9150 | + " no name at " + parser.getPositionDescription()); |
| 9151 | } |
| 9152 | } else { |
| 9153 | reportSettingsProblem(Log.WARN, |
| 9154 | "Unknown element under <disabled-components>: " |
| 9155 | + parser.getName()); |
| 9156 | } |
| 9157 | XmlUtils.skipCurrentTag(parser); |
| 9158 | } |
| 9159 | } |
| 9160 | |
| 9161 | private void readEnabledComponentsLP(PackageSettingBase packageSetting, |
| 9162 | XmlPullParser parser) |
| 9163 | throws IOException, XmlPullParserException { |
| 9164 | int outerDepth = parser.getDepth(); |
| 9165 | int type; |
| 9166 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9167 | && (type != XmlPullParser.END_TAG |
| 9168 | || parser.getDepth() > outerDepth)) { |
| 9169 | if (type == XmlPullParser.END_TAG |
| 9170 | || type == XmlPullParser.TEXT) { |
| 9171 | continue; |
| 9172 | } |
| 9173 | |
| 9174 | String tagName = parser.getName(); |
| 9175 | if (tagName.equals("item")) { |
| 9176 | String name = parser.getAttributeValue(null, "name"); |
| 9177 | if (name != null) { |
| 9178 | packageSetting.enabledComponents.add(name.intern()); |
| 9179 | } else { |
| 9180 | reportSettingsProblem(Log.WARN, |
| 9181 | "Error in package manager settings: <enabled-components> has" |
| 9182 | + " no name at " + parser.getPositionDescription()); |
| 9183 | } |
| 9184 | } else { |
| 9185 | reportSettingsProblem(Log.WARN, |
| 9186 | "Unknown element under <enabled-components>: " |
| 9187 | + parser.getName()); |
| 9188 | } |
| 9189 | XmlUtils.skipCurrentTag(parser); |
| 9190 | } |
| 9191 | } |
| 9192 | |
| 9193 | private void readSharedUserLP(XmlPullParser parser) |
| 9194 | throws XmlPullParserException, IOException { |
| 9195 | String name = null; |
| 9196 | String idStr = null; |
| 9197 | int pkgFlags = 0; |
| 9198 | SharedUserSetting su = null; |
| 9199 | try { |
| 9200 | name = parser.getAttributeValue(null, "name"); |
| 9201 | idStr = parser.getAttributeValue(null, "userId"); |
| 9202 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 9203 | if ("true".equals(parser.getAttributeValue(null, "system"))) { |
| 9204 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 9205 | } |
| 9206 | if (name == null) { |
| 9207 | reportSettingsProblem(Log.WARN, |
| 9208 | "Error in package manager settings: <shared-user> has no name at " |
| 9209 | + parser.getPositionDescription()); |
| 9210 | } else if (userId == 0) { |
| 9211 | reportSettingsProblem(Log.WARN, |
| 9212 | "Error in package manager settings: shared-user " |
| 9213 | + name + " has bad userId " + idStr + " at " |
| 9214 | + parser.getPositionDescription()); |
| 9215 | } else { |
| 9216 | if ((su=addSharedUserLP(name.intern(), userId, pkgFlags)) == null) { |
| 9217 | reportSettingsProblem(Log.ERROR, |
| 9218 | "Occurred while parsing settings at " |
| 9219 | + parser.getPositionDescription()); |
| 9220 | } |
| 9221 | } |
| 9222 | } catch (NumberFormatException e) { |
| 9223 | reportSettingsProblem(Log.WARN, |
| 9224 | "Error in package manager settings: package " |
| 9225 | + name + " has bad userId " + idStr + " at " |
| 9226 | + parser.getPositionDescription()); |
| 9227 | }; |
| 9228 | |
| 9229 | if (su != null) { |
| 9230 | int outerDepth = parser.getDepth(); |
| 9231 | int type; |
| 9232 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9233 | && (type != XmlPullParser.END_TAG |
| 9234 | || parser.getDepth() > outerDepth)) { |
| 9235 | if (type == XmlPullParser.END_TAG |
| 9236 | || type == XmlPullParser.TEXT) { |
| 9237 | continue; |
| 9238 | } |
| 9239 | |
| 9240 | String tagName = parser.getName(); |
| 9241 | if (tagName.equals("sigs")) { |
| 9242 | su.signatures.readXml(parser, mPastSignatures); |
| 9243 | } else if (tagName.equals("perms")) { |
| Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 9244 | readGrantedPermissionsLP(parser, su.grantedPermissions); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9245 | } else { |
| 9246 | reportSettingsProblem(Log.WARN, |
| 9247 | "Unknown element under <shared-user>: " |
| 9248 | + parser.getName()); |
| 9249 | XmlUtils.skipCurrentTag(parser); |
| 9250 | } |
| 9251 | } |
| 9252 | |
| 9253 | } else { |
| 9254 | XmlUtils.skipCurrentTag(parser); |
| 9255 | } |
| 9256 | } |
| 9257 | |
| 9258 | private void readGrantedPermissionsLP(XmlPullParser parser, |
| 9259 | HashSet<String> outPerms) throws IOException, XmlPullParserException { |
| 9260 | int outerDepth = parser.getDepth(); |
| 9261 | int type; |
| 9262 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9263 | && (type != XmlPullParser.END_TAG |
| 9264 | || parser.getDepth() > outerDepth)) { |
| 9265 | if (type == XmlPullParser.END_TAG |
| 9266 | || type == XmlPullParser.TEXT) { |
| 9267 | continue; |
| 9268 | } |
| 9269 | |
| 9270 | String tagName = parser.getName(); |
| 9271 | if (tagName.equals("item")) { |
| 9272 | String name = parser.getAttributeValue(null, "name"); |
| 9273 | if (name != null) { |
| 9274 | outPerms.add(name.intern()); |
| 9275 | } else { |
| 9276 | reportSettingsProblem(Log.WARN, |
| 9277 | "Error in package manager settings: <perms> has" |
| 9278 | + " no name at " + parser.getPositionDescription()); |
| 9279 | } |
| 9280 | } else { |
| 9281 | reportSettingsProblem(Log.WARN, |
| 9282 | "Unknown element under <perms>: " |
| 9283 | + parser.getName()); |
| 9284 | } |
| 9285 | XmlUtils.skipCurrentTag(parser); |
| 9286 | } |
| 9287 | } |
| 9288 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9289 | private void readPreferredActivitiesLP(XmlPullParser parser) |
| 9290 | throws XmlPullParserException, IOException { |
| 9291 | int outerDepth = parser.getDepth(); |
| 9292 | int type; |
| 9293 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9294 | && (type != XmlPullParser.END_TAG |
| 9295 | || parser.getDepth() > outerDepth)) { |
| 9296 | if (type == XmlPullParser.END_TAG |
| 9297 | || type == XmlPullParser.TEXT) { |
| 9298 | continue; |
| 9299 | } |
| 9300 | |
| 9301 | String tagName = parser.getName(); |
| 9302 | if (tagName.equals("item")) { |
| 9303 | PreferredActivity pa = new PreferredActivity(parser); |
| 9304 | if (pa.mParseError == null) { |
| 9305 | mPreferredActivities.addFilter(pa); |
| 9306 | } else { |
| 9307 | reportSettingsProblem(Log.WARN, |
| 9308 | "Error in package manager settings: <preferred-activity> " |
| 9309 | + pa.mParseError + " at " |
| 9310 | + parser.getPositionDescription()); |
| 9311 | } |
| 9312 | } else { |
| 9313 | reportSettingsProblem(Log.WARN, |
| 9314 | "Unknown element under <preferred-activities>: " |
| 9315 | + parser.getName()); |
| 9316 | XmlUtils.skipCurrentTag(parser); |
| 9317 | } |
| 9318 | } |
| 9319 | } |
| 9320 | |
| 9321 | // Returns -1 if we could not find an available UserId to assign |
| 9322 | private int newUserIdLP(Object obj) { |
| 9323 | // Let's be stupidly inefficient for now... |
| 9324 | final int N = mUserIds.size(); |
| 9325 | for (int i=0; i<N; i++) { |
| 9326 | if (mUserIds.get(i) == null) { |
| 9327 | mUserIds.set(i, obj); |
| 9328 | return FIRST_APPLICATION_UID + i; |
| 9329 | } |
| 9330 | } |
| 9331 | |
| 9332 | // None left? |
| 9333 | if (N >= MAX_APPLICATION_UIDS) { |
| 9334 | return -1; |
| 9335 | } |
| 9336 | |
| 9337 | mUserIds.add(obj); |
| 9338 | return FIRST_APPLICATION_UID + N; |
| 9339 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9340 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9341 | public PackageSetting getDisabledSystemPkg(String name) { |
| 9342 | synchronized(mPackages) { |
| 9343 | PackageSetting ps = mDisabledSysPackages.get(name); |
| 9344 | return ps; |
| 9345 | } |
| 9346 | } |
| 9347 | |
| 9348 | boolean isEnabledLP(ComponentInfo componentInfo, int flags) { |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 9349 | if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) { |
| 9350 | return true; |
| 9351 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9352 | final PackageSetting packageSettings = mPackages.get(componentInfo.packageName); |
| 9353 | if (Config.LOGV) { |
| 9354 | Log.v(TAG, "isEnabledLock - packageName = " + componentInfo.packageName |
| 9355 | + " componentName = " + componentInfo.name); |
| 9356 | Log.v(TAG, "enabledComponents: " |
| 9357 | + Arrays.toString(packageSettings.enabledComponents.toArray())); |
| 9358 | Log.v(TAG, "disabledComponents: " |
| 9359 | + Arrays.toString(packageSettings.disabledComponents.toArray())); |
| 9360 | } |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9361 | if (packageSettings == null) { |
| 9362 | if (false) { |
| 9363 | Log.w(TAG, "WAITING FOR DEBUGGER"); |
| 9364 | Debug.waitForDebugger(); |
| 9365 | Log.i(TAG, "We will crash!"); |
| 9366 | } |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 9367 | return false; |
| Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9368 | } |
| Dianne Hackborn | 46730fc | 2010-07-24 16:32:42 -0700 | [diff] [blame] | 9369 | if (packageSettings.enabled == COMPONENT_ENABLED_STATE_DISABLED |
| 9370 | || (packageSettings.pkg != null && !packageSettings.pkg.applicationInfo.enabled |
| 9371 | && packageSettings.enabled == COMPONENT_ENABLED_STATE_DEFAULT)) { |
| 9372 | return false; |
| 9373 | } |
| 9374 | if (packageSettings.enabledComponents.contains(componentInfo.name)) { |
| 9375 | return true; |
| 9376 | } |
| 9377 | if (packageSettings.disabledComponents.contains(componentInfo.name)) { |
| 9378 | return false; |
| 9379 | } |
| 9380 | return componentInfo.enabled; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9381 | } |
| 9382 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9383 | |
| 9384 | // ------- apps on sdcard specific code ------- |
| 9385 | static final boolean DEBUG_SD_INSTALL = false; |
| Oscar Montemayor | d02546b | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 9386 | final private String mSdEncryptKey = "AppsOnSD"; |
| Oscar Montemayor | 462f037 | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 9387 | final private String mSdEncryptAlg = "AES"; |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9388 | private boolean mMediaMounted = false; |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9389 | private static final int MAX_CONTAINERS = 250; |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9390 | |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9391 | private String getEncryptKey() { |
| 9392 | try { |
| 9393 | String sdEncKey = SystemKeyStore.getInstance().retrieveKeyHexString(mSdEncryptKey); |
| 9394 | if (sdEncKey == null) { |
| 9395 | sdEncKey = SystemKeyStore.getInstance(). |
| 9396 | generateNewKeyHexString(128, mSdEncryptAlg, mSdEncryptKey); |
| 9397 | if (sdEncKey == null) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9398 | Slog.e(TAG, "Failed to create encryption keys"); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9399 | return null; |
| 9400 | } |
| 9401 | } |
| 9402 | return sdEncKey; |
| 9403 | } catch (NoSuchAlgorithmException nsae) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9404 | Slog.e(TAG, "Failed to create encryption keys with exception: " + nsae); |
| Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9405 | return null; |
| 9406 | } |
| 9407 | } |
| 9408 | |
| Kenny Root | c78a807 | 2010-07-27 15:18:38 -0700 | [diff] [blame] | 9409 | /* package */ static String getTempContainerId() { |
| 9410 | int tmpIdx = 1; |
| 9411 | String list[] = PackageHelper.getSecureContainerList(); |
| 9412 | if (list != null) { |
| 9413 | for (final String name : list) { |
| 9414 | // Ignore null and non-temporary container entries |
| 9415 | if (name == null || !name.startsWith(mTempContainerPrefix)) { |
| 9416 | continue; |
| 9417 | } |
| 9418 | |
| 9419 | String subStr = name.substring(mTempContainerPrefix.length()); |
| 9420 | try { |
| 9421 | int cid = Integer.parseInt(subStr); |
| 9422 | if (cid >= tmpIdx) { |
| 9423 | tmpIdx = cid + 1; |
| 9424 | } |
| 9425 | } catch (NumberFormatException e) { |
| 9426 | } |
| 9427 | } |
| 9428 | } |
| 9429 | return mTempContainerPrefix + tmpIdx; |
| 9430 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9431 | |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9432 | /* |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9433 | * Update media status on PackageManager. |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9434 | */ |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9435 | public void updateExternalMediaStatus(final boolean mediaStatus, final boolean reportStatus) { |
| 9436 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9437 | throw new SecurityException("Media status can only be updated by the system"); |
| 9438 | } |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9439 | synchronized (mPackages) { |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 9440 | Log.i(TAG, "Updating external media status from " + |
| 9441 | (mMediaMounted ? "mounted" : "unmounted") + " to " + |
| 9442 | (mediaStatus ? "mounted" : "unmounted")); |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9443 | if (DEBUG_SD_INSTALL) Log.i(TAG, "updateExternalMediaStatus:: mediaStatus=" + |
| 9444 | mediaStatus+", mMediaMounted=" + mMediaMounted); |
| 9445 | if (mediaStatus == mMediaMounted) { |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9446 | Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, |
| 9447 | reportStatus ? 1 : 0, -1); |
| 9448 | mHandler.sendMessage(msg); |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9449 | return; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9450 | } |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9451 | mMediaMounted = mediaStatus; |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9452 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9453 | // Queue up an async operation since the package installation may take a little while. |
| 9454 | mHandler.post(new Runnable() { |
| 9455 | public void run() { |
| 9456 | mHandler.removeCallbacks(this); |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9457 | updateExternalMediaStatusInner(mediaStatus, reportStatus); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9458 | } |
| 9459 | }); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9460 | } |
| 9461 | |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9462 | /* |
| 9463 | * Collect information of applications on external media, map them |
| 9464 | * against existing containers and update information based on current |
| 9465 | * mount status. Please note that we always have to report status |
| 9466 | * if reportStatus has been set to true especially when unloading packages. |
| 9467 | */ |
| 9468 | private void updateExternalMediaStatusInner(boolean mediaStatus, |
| 9469 | boolean reportStatus) { |
| 9470 | // Collection of uids |
| 9471 | int uidArr[] = null; |
| 9472 | // Collection of stale containers |
| 9473 | HashSet<String> removeCids = new HashSet<String>(); |
| 9474 | // Collection of packages on external media with valid containers. |
| 9475 | HashMap<SdInstallArgs, String> processCids = new HashMap<SdInstallArgs, String>(); |
| 9476 | // Get list of secure containers. |
| Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 9477 | final String list[] = PackageHelper.getSecureContainerList(); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9478 | if (list == null || list.length == 0) { |
| Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 9479 | Log.i(TAG, "No secure containers on sdcard"); |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9480 | } else { |
| 9481 | // Process list of secure containers and categorize them |
| 9482 | // as active or stale based on their package internal state. |
| 9483 | int uidList[] = new int[list.length]; |
| 9484 | int num = 0; |
| 9485 | synchronized (mPackages) { |
| 9486 | for (String cid : list) { |
| 9487 | SdInstallArgs args = new SdInstallArgs(cid); |
| 9488 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Processing container " + cid); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9489 | String pkgName = args.getPackageName(); |
| 9490 | if (pkgName == null) { |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9491 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " stale"); |
| 9492 | removeCids.add(cid); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9493 | continue; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9494 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9495 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Looking for pkg : " + pkgName); |
| 9496 | PackageSetting ps = mSettings.mPackages.get(pkgName); |
| Suchi Amalapurapu | 1ace5bc | 2010-05-13 12:05:53 -0700 | [diff] [blame] | 9497 | // The package status is changed only if the code path |
| 9498 | // matches between settings and the container id. |
| 9499 | if (ps != null && ps.codePathString != null && |
| 9500 | ps.codePathString.equals(args.getCodePath())) { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9501 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + |
| 9502 | " corresponds to pkg : " + pkgName + |
| 9503 | " at code path: " + ps.codePathString); |
| 9504 | // We do have a valid package installed on sdcard |
| 9505 | processCids.put(args, ps.codePathString); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9506 | int uid = ps.userId; |
| 9507 | if (uid != -1) { |
| 9508 | uidList[num++] = uid; |
| 9509 | } |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9510 | } else { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9511 | // Stale container on sdcard. Just delete |
| 9512 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " stale"); |
| 9513 | removeCids.add(cid); |
| 9514 | } |
| Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9515 | } |
| 9516 | } |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9517 | |
| 9518 | if (num > 0) { |
| 9519 | // Sort uid list |
| 9520 | Arrays.sort(uidList, 0, num); |
| 9521 | // Throw away duplicates |
| 9522 | uidArr = new int[num]; |
| 9523 | uidArr[0] = uidList[0]; |
| 9524 | int di = 0; |
| 9525 | for (int i = 1; i < num; i++) { |
| 9526 | if (uidList[i-1] != uidList[i]) { |
| 9527 | uidArr[di++] = uidList[i]; |
| 9528 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9529 | } |
| 9530 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9531 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9532 | // Process packages with valid entries. |
| 9533 | if (mediaStatus) { |
| 9534 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Loading packages"); |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9535 | loadMediaPackages(processCids, uidArr, removeCids); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9536 | startCleaningPackages(); |
| 9537 | } else { |
| 9538 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Unloading packages"); |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9539 | unloadMediaPackages(processCids, uidArr, reportStatus); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9540 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9541 | } |
| 9542 | |
| 9543 | private void sendResourcesChangedBroadcast(boolean mediaStatus, |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9544 | ArrayList<String> pkgList, int uidArr[], IIntentReceiver finishedReceiver) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9545 | int size = pkgList.size(); |
| 9546 | if (size > 0) { |
| 9547 | // Send broadcasts here |
| 9548 | Bundle extras = new Bundle(); |
| 9549 | extras.putStringArray(Intent.EXTRA_CHANGED_PACKAGE_LIST, |
| 9550 | pkgList.toArray(new String[size])); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9551 | if (uidArr != null) { |
| 9552 | extras.putIntArray(Intent.EXTRA_CHANGED_UID_LIST, uidArr); |
| 9553 | } |
| 9554 | String action = mediaStatus ? Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE |
| 9555 | : Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE; |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9556 | sendPackageBroadcast(action, null, extras, finishedReceiver); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9557 | } |
| 9558 | } |
| 9559 | |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9560 | /* |
| 9561 | * Look at potentially valid container ids from processCids |
| 9562 | * If package information doesn't match the one on record |
| 9563 | * or package scanning fails, the cid is added to list of |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9564 | * removeCids. We currently don't delete stale containers. |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9565 | */ |
| 9566 | private void loadMediaPackages(HashMap<SdInstallArgs, String> processCids, |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9567 | int uidArr[], HashSet<String> removeCids) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9568 | ArrayList<String> pkgList = new ArrayList<String>(); |
| 9569 | Set<SdInstallArgs> keys = processCids.keySet(); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9570 | boolean doGc = false; |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9571 | for (SdInstallArgs args : keys) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9572 | String codePath = processCids.get(args); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9573 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Loading container : " |
| 9574 | + args.cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9575 | int retCode = PackageManager.INSTALL_FAILED_CONTAINER_ERROR; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9576 | try { |
| 9577 | // Make sure there are no container errors first. |
| 9578 | if (args.doPreInstall(PackageManager.INSTALL_SUCCEEDED) |
| 9579 | != PackageManager.INSTALL_SUCCEEDED) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9580 | Slog.e(TAG, "Failed to mount cid : " + args.cid + |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9581 | " when installing from sdcard"); |
| 9582 | continue; |
| 9583 | } |
| 9584 | // Check code path here. |
| 9585 | if (codePath == null || !codePath.equals(args.getCodePath())) { |
| Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9586 | Slog.e(TAG, "Container " + args.cid + " cachepath " + args.getCodePath()+ |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9587 | " does not match one in settings " + codePath); |
| 9588 | continue; |
| 9589 | } |
| 9590 | // Parse package |
| Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 9591 | int parseFlags = PackageParser.PARSE_ON_SDCARD | mDefParseFlags; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9592 | doGc = true; |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9593 | synchronized (mInstallLock) { |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 9594 | final PackageParser.Package pkg = scanPackageLI(new File(codePath), |
| 9595 | parseFlags, 0); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9596 | // Scan the package |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 9597 | if (pkg != null) { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9598 | synchronized (mPackages) { |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9599 | retCode = PackageManager.INSTALL_SUCCEEDED; |
| 9600 | pkgList.add(pkg.packageName); |
| 9601 | // Post process args |
| 9602 | args.doPostInstall(PackageManager.INSTALL_SUCCEEDED); |
| 9603 | } |
| 9604 | } else { |
| Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 9605 | Slog.i(TAG, "Failed to install pkg from " + |
| 9606 | codePath + " from sdcard"); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9607 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9608 | } |
| 9609 | |
| 9610 | } finally { |
| 9611 | if (retCode != PackageManager.INSTALL_SUCCEEDED) { |
| 9612 | // Don't destroy container here. Wait till gc clears things up. |
| 9613 | removeCids.add(args.cid); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9614 | } |
| 9615 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9616 | } |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 9617 | synchronized (mPackages) { |
| Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 9618 | // If the platform SDK has changed since the last time we booted, |
| 9619 | // we need to re-grant app permission to catch any new ones that |
| 9620 | // appear. This is really a hack, and means that apps can in some |
| 9621 | // cases get permissions that the user didn't initially explicitly |
| 9622 | // allow... it would be nice to have some better way to handle |
| 9623 | // this situation. |
| 9624 | final boolean regrantPermissions = mSettings.mExternalSdkPlatform |
| 9625 | != mSdkVersion; |
| 9626 | if (regrantPermissions) Slog.i(TAG, "Platform changed from " |
| 9627 | + mSettings.mExternalSdkPlatform + " to " + mSdkVersion |
| 9628 | + "; regranting permissions for external storage"); |
| 9629 | mSettings.mExternalSdkPlatform = mSdkVersion; |
| 9630 | |
| Dianne Hackborn | af7cea3 | 2010-03-24 12:59:52 -0700 | [diff] [blame] | 9631 | // Make sure group IDs have been assigned, and any permission |
| 9632 | // changes in other apps are accounted for |
| Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 9633 | updatePermissionsLP(null, null, true, regrantPermissions, regrantPermissions); |
| Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 9634 | // Persist settings |
| 9635 | mSettings.writeLP(); |
| 9636 | } |
| Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9637 | // Send a broadcast to let everyone know we are done processing |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9638 | if (pkgList.size() > 0) { |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9639 | sendResourcesChangedBroadcast(true, pkgList, uidArr, null); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9640 | } |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9641 | // Force gc to avoid any stale parser references that we might have. |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9642 | if (doGc) { |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9643 | Runtime.getRuntime().gc(); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9644 | } |
| Kenny Root | f369a9b | 2010-07-28 14:47:01 -0700 | [diff] [blame] | 9645 | // List stale containers and destroy stale temporary containers. |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9646 | if (removeCids != null) { |
| 9647 | for (String cid : removeCids) { |
| Kenny Root | f369a9b | 2010-07-28 14:47:01 -0700 | [diff] [blame] | 9648 | if (cid.startsWith(mTempContainerPrefix)) { |
| 9649 | Log.i(TAG, "Destroying stale temporary container " + cid); |
| 9650 | PackageHelper.destroySdDir(cid); |
| 9651 | } else { |
| 9652 | Log.w(TAG, "Container " + cid + " is stale"); |
| 9653 | } |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9654 | } |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9655 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9656 | } |
| 9657 | |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9658 | /* |
| 9659 | * Utility method to unload a list of specified containers |
| 9660 | */ |
| 9661 | private void unloadAllContainers(Set<SdInstallArgs> cidArgs) { |
| 9662 | // Just unmount all valid containers. |
| 9663 | for (SdInstallArgs arg : cidArgs) { |
| 9664 | synchronized (mInstallLock) { |
| 9665 | arg.doPostDeleteLI(false); |
| 9666 | } |
| 9667 | } |
| 9668 | } |
| 9669 | |
| 9670 | /* |
| 9671 | * Unload packages mounted on external media. This involves deleting |
| 9672 | * package data from internal structures, sending broadcasts about |
| 9673 | * diabled packages, gc'ing to free up references, unmounting all |
| 9674 | * secure containers corresponding to packages on external media, and |
| 9675 | * posting a UPDATED_MEDIA_STATUS message if status has been requested. |
| 9676 | * Please note that we always have to post this message if status has |
| 9677 | * been requested no matter what. |
| 9678 | */ |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9679 | private void unloadMediaPackages(HashMap<SdInstallArgs, String> processCids, |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9680 | int uidArr[], final boolean reportStatus) { |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9681 | if (DEBUG_SD_INSTALL) Log.i(TAG, "unloading media packages"); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9682 | ArrayList<String> pkgList = new ArrayList<String>(); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9683 | ArrayList<SdInstallArgs> failedList = new ArrayList<SdInstallArgs>(); |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9684 | final Set<SdInstallArgs> keys = processCids.keySet(); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9685 | for (SdInstallArgs args : keys) { |
| 9686 | String cid = args.cid; |
| 9687 | String pkgName = args.getPackageName(); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9688 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to unload pkg : " + pkgName); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9689 | // Delete package internally |
| 9690 | PackageRemovedInfo outInfo = new PackageRemovedInfo(); |
| 9691 | synchronized (mInstallLock) { |
| 9692 | boolean res = deletePackageLI(pkgName, false, |
| 9693 | PackageManager.DONT_DELETE_DATA, outInfo); |
| 9694 | if (res) { |
| 9695 | pkgList.add(pkgName); |
| 9696 | } else { |
| Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 9697 | Slog.e(TAG, "Failed to delete pkg from sdcard : " + pkgName); |
| Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9698 | failedList.add(args); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9699 | } |
| 9700 | } |
| 9701 | } |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9702 | // We have to absolutely send UPDATED_MEDIA_STATUS only |
| 9703 | // after confirming that all the receivers processed the ordered |
| 9704 | // broadcast when packages get disabled, force a gc to clean things up. |
| 9705 | // and unload all the containers. |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9706 | if (pkgList.size() > 0) { |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9707 | sendResourcesChangedBroadcast(false, pkgList, uidArr, new IIntentReceiver.Stub() { |
| 9708 | public void performReceive(Intent intent, int resultCode, String data, Bundle extras, |
| 9709 | boolean ordered, boolean sticky) throws RemoteException { |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9710 | Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, |
| 9711 | reportStatus ? 1 : 0, 1, keys); |
| 9712 | mHandler.sendMessage(msg); |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9713 | } |
| 9714 | }); |
| Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9715 | } else { |
| 9716 | Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, |
| 9717 | reportStatus ? 1 : 0, -1, keys); |
| 9718 | mHandler.sendMessage(msg); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9719 | } |
| Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9720 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9721 | |
| 9722 | public void movePackage(final String packageName, |
| 9723 | final IPackageMoveObserver observer, final int flags) { |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9724 | mContext.enforceCallingOrSelfPermission( |
| 9725 | android.Manifest.permission.MOVE_PACKAGE, null); |
| 9726 | int returnCode = PackageManager.MOVE_SUCCEEDED; |
| 9727 | int currFlags = 0; |
| 9728 | int newFlags = 0; |
| 9729 | synchronized (mPackages) { |
| 9730 | PackageParser.Package pkg = mPackages.get(packageName); |
| 9731 | if (pkg == null) { |
| 9732 | returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9733 | } else { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9734 | // Disable moving fwd locked apps and system packages |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9735 | if (pkg.applicationInfo != null && isSystemApp(pkg)) { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9736 | Slog.w(TAG, "Cannot move system application"); |
| 9737 | returnCode = PackageManager.MOVE_FAILED_SYSTEM_PACKAGE; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9738 | } else if (pkg.applicationInfo != null && isForwardLocked(pkg)) { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9739 | Slog.w(TAG, "Cannot move forward locked app."); |
| 9740 | returnCode = PackageManager.MOVE_FAILED_FORWARD_LOCKED; |
| Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 9741 | } else if (pkg.mOperationPending) { |
| 9742 | Slog.w(TAG, "Attempt to move package which has pending operations"); |
| 9743 | returnCode = PackageManager.MOVE_FAILED_OPERATION_PENDING; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9744 | } else { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9745 | // Find install location first |
| 9746 | if ((flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0 && |
| 9747 | (flags & PackageManager.MOVE_INTERNAL) != 0) { |
| 9748 | Slog.w(TAG, "Ambigous flags specified for move location."); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9749 | returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION; |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9750 | } else { |
| 9751 | newFlags = (flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0 ? |
| 9752 | PackageManager.INSTALL_EXTERNAL : PackageManager.INSTALL_INTERNAL; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9753 | currFlags = isExternal(pkg) ? PackageManager.INSTALL_EXTERNAL |
| 9754 | : PackageManager.INSTALL_INTERNAL; |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9755 | if (newFlags == currFlags) { |
| 9756 | Slog.w(TAG, "No move required. Trying to move to same location"); |
| 9757 | returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION; |
| 9758 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9759 | } |
| Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 9760 | if (returnCode == PackageManager.MOVE_SUCCEEDED) { |
| 9761 | pkg.mOperationPending = true; |
| 9762 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9763 | } |
| 9764 | } |
| 9765 | if (returnCode != PackageManager.MOVE_SUCCEEDED) { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9766 | processPendingMove(new MoveParams(null, observer, 0, packageName, null), returnCode); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9767 | } else { |
| 9768 | Message msg = mHandler.obtainMessage(INIT_COPY); |
| 9769 | InstallArgs srcArgs = createInstallArgs(currFlags, pkg.applicationInfo.sourceDir, |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9770 | pkg.applicationInfo.publicSourceDir, pkg.applicationInfo.nativeLibraryDir); |
| 9771 | MoveParams mp = new MoveParams(srcArgs, observer, newFlags, packageName, |
| 9772 | pkg.applicationInfo.dataDir); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9773 | msg.obj = mp; |
| 9774 | mHandler.sendMessage(msg); |
| 9775 | } |
| 9776 | } |
| 9777 | } |
| 9778 | |
| 9779 | private void processPendingMove(final MoveParams mp, final int currentStatus) { |
| 9780 | // Queue up an async operation since the package deletion may take a little while. |
| 9781 | mHandler.post(new Runnable() { |
| 9782 | public void run() { |
| 9783 | mHandler.removeCallbacks(this); |
| 9784 | int returnCode = currentStatus; |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9785 | if (currentStatus == PackageManager.MOVE_SUCCEEDED) { |
| 9786 | int uidArr[] = null; |
| 9787 | ArrayList<String> pkgList = null; |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9788 | synchronized (mPackages) { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9789 | PackageParser.Package pkg = mPackages.get(mp.packageName); |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9790 | if (pkg == null) { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9791 | Slog.w(TAG, " Package " + mp.packageName + |
| 9792 | " doesn't exist. Aborting move"); |
| 9793 | returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST; |
| 9794 | } else if (!mp.srcArgs.getCodePath().equals(pkg.applicationInfo.sourceDir)) { |
| 9795 | Slog.w(TAG, "Package " + mp.packageName + " code path changed from " + |
| 9796 | mp.srcArgs.getCodePath() + " to " + pkg.applicationInfo.sourceDir + |
| 9797 | " Aborting move and returning error"); |
| 9798 | returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR; |
| 9799 | } else { |
| 9800 | uidArr = new int[] { pkg.applicationInfo.uid }; |
| 9801 | pkgList = new ArrayList<String>(); |
| 9802 | pkgList.add(mp.packageName); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9803 | } |
| 9804 | } |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9805 | if (returnCode == PackageManager.MOVE_SUCCEEDED) { |
| 9806 | // Send resources unavailable broadcast |
| Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9807 | sendResourcesChangedBroadcast(false, pkgList, uidArr, null); |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9808 | // Update package code and resource paths |
| 9809 | synchronized (mInstallLock) { |
| 9810 | synchronized (mPackages) { |
| 9811 | PackageParser.Package pkg = mPackages.get(mp.packageName); |
| 9812 | // Recheck for package again. |
| 9813 | if (pkg == null ) { |
| 9814 | Slog.w(TAG, " Package " + mp.packageName + |
| 9815 | " doesn't exist. Aborting move"); |
| 9816 | returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST; |
| 9817 | } else if (!mp.srcArgs.getCodePath().equals(pkg.applicationInfo.sourceDir)) { |
| 9818 | Slog.w(TAG, "Package " + mp.packageName + " code path changed from " + |
| 9819 | mp.srcArgs.getCodePath() + " to " + pkg.applicationInfo.sourceDir + |
| 9820 | " Aborting move and returning error"); |
| 9821 | returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR; |
| 9822 | } else { |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9823 | final String oldCodePath = pkg.mPath; |
| 9824 | final String newCodePath = mp.targetArgs.getCodePath(); |
| 9825 | final String newResPath = mp.targetArgs.getResourcePath(); |
| 9826 | final String newNativePath = mp.targetArgs.getNativeLibraryPath(); |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9827 | pkg.mPath = newCodePath; |
| 9828 | // Move dex files around |
| 9829 | if (moveDexFilesLI(pkg) |
| 9830 | != PackageManager.INSTALL_SUCCEEDED) { |
| 9831 | // Moving of dex files failed. Set |
| 9832 | // error code and abort move. |
| 9833 | pkg.mPath = pkg.mScanPath; |
| 9834 | returnCode = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE; |
| 9835 | } else { |
| 9836 | pkg.mScanPath = newCodePath; |
| 9837 | pkg.applicationInfo.sourceDir = newCodePath; |
| 9838 | pkg.applicationInfo.publicSourceDir = newResPath; |
| Kenny Root | 85387d7 | 2010-08-26 10:13:11 -0700 | [diff] [blame] | 9839 | pkg.applicationInfo.nativeLibraryDir = newNativePath; |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9840 | PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 9841 | ps.codePath = new File(pkg.applicationInfo.sourceDir); |
| 9842 | ps.codePathString = ps.codePath.getPath(); |
| 9843 | ps.resourcePath = new File(pkg.applicationInfo.publicSourceDir); |
| 9844 | ps.resourcePathString = ps.resourcePath.getPath(); |
| Kenny Root | 0ac83f5 | 2010-08-30 15:12:24 -0700 | [diff] [blame] | 9845 | ps.nativeLibraryPathString = newNativePath; |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9846 | // Set the application info flag correctly. |
| 9847 | if ((mp.flags & PackageManager.INSTALL_EXTERNAL) != 0) { |
| 9848 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 9849 | } else { |
| 9850 | pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 9851 | } |
| 9852 | ps.setFlags(pkg.applicationInfo.flags); |
| 9853 | mAppDirs.remove(oldCodePath); |
| 9854 | mAppDirs.put(newCodePath, pkg); |
| 9855 | // Persist settings |
| 9856 | mSettings.writeLP(); |
| 9857 | } |
| 9858 | } |
| 9859 | } |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9860 | } |
| Suchi Amalapurapu | 0c1285f | 2010-04-14 17:05:48 -0700 | [diff] [blame] | 9861 | // Send resources available broadcast |
| 9862 | sendResourcesChangedBroadcast(true, pkgList, uidArr, null); |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9863 | } |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9864 | } |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9865 | if (returnCode != PackageManager.MOVE_SUCCEEDED){ |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9866 | // Clean up failed installation |
| 9867 | if (mp.targetArgs != null) { |
| Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9868 | mp.targetArgs.doPostInstall(PackageManager.INSTALL_FAILED_INTERNAL_ERROR); |
| Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9869 | } |
| 9870 | } else { |
| 9871 | // Force a gc to clear things up. |
| 9872 | Runtime.getRuntime().gc(); |
| 9873 | // Delete older code |
| 9874 | synchronized (mInstallLock) { |
| 9875 | mp.srcArgs.doPostDeleteLI(true); |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9876 | } |
| 9877 | } |
| Kenny Root | deb1126 | 2010-08-02 11:36:21 -0700 | [diff] [blame] | 9878 | |
| 9879 | // Allow more operations on this file if we didn't fail because |
| 9880 | // an operation was already pending for this package. |
| 9881 | if (returnCode != PackageManager.MOVE_FAILED_OPERATION_PENDING) { |
| 9882 | synchronized (mPackages) { |
| 9883 | PackageParser.Package pkg = mPackages.get(mp.packageName); |
| 9884 | if (pkg != null) { |
| 9885 | pkg.mOperationPending = false; |
| 9886 | } |
| 9887 | } |
| 9888 | } |
| 9889 | |
| Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9890 | IPackageMoveObserver observer = mp.observer; |
| 9891 | if (observer != null) { |
| 9892 | try { |
| 9893 | observer.packageMoved(mp.packageName, returnCode); |
| 9894 | } catch (RemoteException e) { |
| 9895 | Log.i(TAG, "Observer no longer exists."); |
| 9896 | } |
| 9897 | } |
| 9898 | } |
| 9899 | }); |
| 9900 | } |
| Suchi Amalapurapu | 40e4725 | 2010-04-07 16:15:50 -0700 | [diff] [blame] | 9901 | |
| 9902 | public boolean setInstallLocation(int loc) { |
| 9903 | mContext.enforceCallingOrSelfPermission( |
| 9904 | android.Manifest.permission.WRITE_SECURE_SETTINGS, null); |
| 9905 | if (getInstallLocation() == loc) { |
| 9906 | return true; |
| 9907 | } |
| 9908 | if (loc == PackageHelper.APP_INSTALL_AUTO || |
| 9909 | loc == PackageHelper.APP_INSTALL_INTERNAL || |
| 9910 | loc == PackageHelper.APP_INSTALL_EXTERNAL) { |
| 9911 | android.provider.Settings.System.putInt(mContext.getContentResolver(), |
| 9912 | android.provider.Settings.Secure.DEFAULT_INSTALL_LOCATION, loc); |
| 9913 | return true; |
| 9914 | } |
| 9915 | return false; |
| 9916 | } |
| 9917 | |
| 9918 | public int getInstallLocation() { |
| 9919 | return android.provider.Settings.System.getInt(mContext.getContentResolver(), |
| 9920 | android.provider.Settings.Secure.DEFAULT_INSTALL_LOCATION, PackageHelper.APP_INSTALL_AUTO); |
| 9921 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9922 | } |