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; |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 21 | import com.android.internal.content.PackageHelper; |
Dianne Hackborn | 2269d157 | 2010-02-24 19:54:22 -0800 | [diff] [blame] | 22 | import com.android.internal.util.FastXmlSerializer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 23 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | 2269d157 | 2010-02-24 19:54:22 -0800 | [diff] [blame] | 24 | import com.android.internal.util.XmlUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
| 26 | import org.xmlpull.v1.XmlPullParser; |
| 27 | import org.xmlpull.v1.XmlPullParserException; |
| 28 | import org.xmlpull.v1.XmlSerializer; |
| 29 | |
| 30 | import android.app.ActivityManagerNative; |
| 31 | import android.app.IActivityManager; |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 32 | import android.app.admin.IDevicePolicyManager; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 33 | import android.app.backup.IBackupManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.content.Context; |
Suchi Amalapurapu | 40e4725 | 2010-04-07 16:15:50 -0700 | [diff] [blame] | 35 | import android.content.ComponentName; |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 36 | import android.content.IIntentReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.Intent; |
| 38 | import android.content.IntentFilter; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 39 | import android.content.IntentSender; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 40 | import android.content.ServiceConnection; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 41 | import android.content.IntentSender.SendIntentException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.content.pm.ActivityInfo; |
| 43 | import android.content.pm.ApplicationInfo; |
| 44 | import android.content.pm.ComponentInfo; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 45 | import android.content.pm.FeatureInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.content.pm.IPackageDataObserver; |
| 47 | import android.content.pm.IPackageDeleteObserver; |
| 48 | import android.content.pm.IPackageInstallObserver; |
| 49 | import android.content.pm.IPackageManager; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 50 | import android.content.pm.IPackageMoveObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.content.pm.IPackageStatsObserver; |
| 52 | import android.content.pm.InstrumentationInfo; |
| 53 | import android.content.pm.PackageInfo; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 54 | import android.content.pm.PackageInfoLite; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.pm.PackageManager; |
| 56 | import android.content.pm.PackageStats; |
| 57 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 58 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; |
| 59 | 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] | 60 | import android.content.pm.PackageParser; |
| 61 | import android.content.pm.PermissionInfo; |
| 62 | import android.content.pm.PermissionGroupInfo; |
| 63 | import android.content.pm.ProviderInfo; |
| 64 | import android.content.pm.ResolveInfo; |
| 65 | import android.content.pm.ServiceInfo; |
| 66 | import android.content.pm.Signature; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.net.Uri; |
| 68 | import android.os.Binder; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 69 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.os.Bundle; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 71 | import android.os.Debug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.HandlerThread; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 73 | import android.os.IBinder; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 74 | import android.os.Looper; |
| 75 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import android.os.Parcel; |
| 77 | import android.os.RemoteException; |
| 78 | import android.os.Environment; |
| 79 | import android.os.FileObserver; |
| 80 | import android.os.FileUtils; |
| 81 | import android.os.Handler; |
| 82 | import android.os.ParcelFileDescriptor; |
| 83 | import android.os.Process; |
| 84 | import android.os.ServiceManager; |
| 85 | import android.os.SystemClock; |
| 86 | import android.os.SystemProperties; |
Suchi Amalapurapu | 40e4725 | 2010-04-07 16:15:50 -0700 | [diff] [blame] | 87 | import android.provider.Settings; |
Oscar Montemayor | d02546b | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 88 | import android.security.SystemKeyStore; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.util.*; |
| 90 | import android.view.Display; |
| 91 | import android.view.WindowManager; |
| 92 | |
| 93 | import java.io.File; |
| 94 | import java.io.FileDescriptor; |
| 95 | import java.io.FileInputStream; |
| 96 | import java.io.FileNotFoundException; |
| 97 | import java.io.FileOutputStream; |
| 98 | import java.io.FileReader; |
| 99 | import java.io.FilenameFilter; |
| 100 | import java.io.IOException; |
| 101 | import java.io.InputStream; |
| 102 | import java.io.PrintWriter; |
Oscar Montemayor | d02546b | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 103 | import java.security.NoSuchAlgorithmException; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 104 | import java.text.SimpleDateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | import java.util.ArrayList; |
| 106 | import java.util.Arrays; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 107 | import java.util.Collection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import java.util.Collections; |
| 109 | import java.util.Comparator; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 110 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | import java.util.Enumeration; |
| 112 | import java.util.HashMap; |
| 113 | import java.util.HashSet; |
| 114 | import java.util.Iterator; |
| 115 | import java.util.List; |
| 116 | import java.util.Map; |
| 117 | import java.util.Set; |
| 118 | import java.util.zip.ZipEntry; |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 119 | import java.util.zip.ZipException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | import java.util.zip.ZipFile; |
| 121 | import java.util.zip.ZipOutputStream; |
| 122 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 123 | /** |
| 124 | * Keep track of all those .apks everywhere. |
| 125 | * |
| 126 | * This is very central to the platform's security; please run the unit |
| 127 | * tests whenever making modifications here: |
| 128 | * |
| 129 | mmm frameworks/base/tests/AndroidTests |
| 130 | adb install -r -f out/target/product/passion/data/app/AndroidTests.apk |
| 131 | adb shell am instrument -w -e class com.android.unit_tests.PackageManagerTests com.android.unit_tests/android.test.InstrumentationTestRunner |
| 132 | * |
| 133 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | class PackageManagerService extends IPackageManager.Stub { |
| 135 | private static final String TAG = "PackageManager"; |
| 136 | private static final boolean DEBUG_SETTINGS = false; |
| 137 | private static final boolean DEBUG_PREFERRED = false; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 138 | private static final boolean DEBUG_UPGRADE = false; |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 139 | private static final boolean DEBUG_INSTALL = false; |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 140 | private static final boolean DEBUG_NATIVE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | |
| 142 | private static final boolean MULTIPLE_APPLICATION_UIDS = true; |
| 143 | private static final int RADIO_UID = Process.PHONE_UID; |
Mike Lockwood | d42685d | 2009-09-03 09:25:22 -0400 | [diff] [blame] | 144 | private static final int LOG_UID = Process.LOG_UID; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | private static final int FIRST_APPLICATION_UID = |
| 146 | Process.FIRST_APPLICATION_UID; |
| 147 | private static final int MAX_APPLICATION_UIDS = 1000; |
| 148 | |
| 149 | private static final boolean SHOW_INFO = false; |
| 150 | |
| 151 | private static final boolean GET_CERTIFICATES = true; |
| 152 | |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 153 | private static final String SYSTEM_PROPERTY_EFS_ENABLED = "persist.security.efs.enabled"; |
| 154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | private static final int REMOVE_EVENTS = |
| 156 | FileObserver.CLOSE_WRITE | FileObserver.DELETE | FileObserver.MOVED_FROM; |
| 157 | private static final int ADD_EVENTS = |
| 158 | FileObserver.CLOSE_WRITE /*| FileObserver.CREATE*/ | FileObserver.MOVED_TO; |
| 159 | |
| 160 | private static final int OBSERVER_EVENTS = REMOVE_EVENTS | ADD_EVENTS; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 161 | // Suffix used during package installation when copying/moving |
| 162 | // package apks to install directory. |
| 163 | private static final String INSTALL_PACKAGE_SUFFIX = "-"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | |
Suchi Amalapurapu | 1f9e1b4 | 2010-02-26 13:14:31 -0800 | [diff] [blame] | 165 | /** |
| 166 | * Indicates the state of installation. Used by PackageManager to |
| 167 | * figure out incomplete installations. Say a package is being installed |
| 168 | * (the state is set to PKG_INSTALL_INCOMPLETE) and remains so till |
| 169 | * the package installation is successful or unsuccesful lin which case |
| 170 | * the PackageManager will no longer maintain state information associated |
| 171 | * with the package. If some exception(like device freeze or battery being |
| 172 | * pulled out) occurs during installation of a package, the PackageManager |
| 173 | * needs this information to clean up the previously failed installation. |
| 174 | */ |
| 175 | private static final int PKG_INSTALL_INCOMPLETE = 0; |
| 176 | private static final int PKG_INSTALL_COMPLETE = 1; |
| 177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | static final int SCAN_MONITOR = 1<<0; |
| 179 | static final int SCAN_NO_DEX = 1<<1; |
| 180 | static final int SCAN_FORCE_DEX = 1<<2; |
| 181 | static final int SCAN_UPDATE_SIGNATURE = 1<<3; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 182 | static final int SCAN_NEW_INSTALL = 1<<4; |
| 183 | static final int SCAN_NO_PATHS = 1<<5; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 185 | static final int REMOVE_CHATTY = 1<<16; |
| 186 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 187 | static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName( |
| 188 | "com.android.defcontainer", |
| 189 | "com.android.defcontainer.DefaultContainerService"); |
| 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | final HandlerThread mHandlerThread = new HandlerThread("PackageManager", |
| 192 | Process.THREAD_PRIORITY_BACKGROUND); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 193 | final PackageHandler mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 195 | final int mSdkVersion = Build.VERSION.SDK_INT; |
| 196 | final String mSdkCodename = "REL".equals(Build.VERSION.CODENAME) |
| 197 | ? null : Build.VERSION.CODENAME; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | final Context mContext; |
| 200 | final boolean mFactoryTest; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 201 | final boolean mNoDexOpt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | final DisplayMetrics mMetrics; |
| 203 | final int mDefParseFlags; |
| 204 | final String[] mSeparateProcesses; |
| 205 | |
| 206 | // This is where all application persistent data goes. |
| 207 | final File mAppDataDir; |
| 208 | |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 209 | // If Encrypted File System feature is enabled, all application persistent data |
| 210 | // should go here instead. |
| 211 | final File mSecureAppDataDir; |
| 212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | // This is the object monitoring the framework dir. |
| 214 | final FileObserver mFrameworkInstallObserver; |
| 215 | |
| 216 | // This is the object monitoring the system app dir. |
| 217 | final FileObserver mSystemInstallObserver; |
| 218 | |
| 219 | // This is the object monitoring mAppInstallDir. |
| 220 | final FileObserver mAppInstallObserver; |
| 221 | |
| 222 | // This is the object monitoring mDrmAppPrivateInstallDir. |
| 223 | final FileObserver mDrmAppInstallObserver; |
| 224 | |
| 225 | // Used for priviledge escalation. MUST NOT BE CALLED WITH mPackages |
| 226 | // LOCK HELD. Can be called with mInstallLock held. |
| 227 | final Installer mInstaller; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | final File mFrameworkDir; |
| 230 | final File mSystemAppDir; |
| 231 | final File mAppInstallDir; |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 232 | final File mDalvikCacheDir; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | |
| 234 | // Directory containing the private parts (e.g. code and non-resource assets) of forward-locked |
| 235 | // apps. |
| 236 | final File mDrmAppPrivateInstallDir; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | // ---------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 239 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | // Lock for state used when installing and doing other long running |
| 241 | // operations. Methods that must be called with this lock held have |
| 242 | // the prefix "LI". |
| 243 | final Object mInstallLock = new Object(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | // These are the directories in the 3rd party applications installed dir |
| 246 | // that we have currently loaded packages from. Keys are the application's |
| 247 | // installed zip file (absolute codePath), and values are Package. |
| 248 | final HashMap<String, PackageParser.Package> mAppDirs = |
| 249 | new HashMap<String, PackageParser.Package>(); |
| 250 | |
| 251 | // Information for the parser to write more useful error messages. |
| 252 | File mScanningPath; |
| 253 | int mLastScanError; |
| 254 | |
| 255 | final int[] mOutPermissions = new int[3]; |
| 256 | |
| 257 | // ---------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 258 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | // Keys are String (package name), values are Package. This also serves |
| 260 | // as the lock for the global state. Methods that must be called with |
| 261 | // this lock held have the prefix "LP". |
| 262 | final HashMap<String, PackageParser.Package> mPackages = |
| 263 | new HashMap<String, PackageParser.Package>(); |
| 264 | |
| 265 | final Settings mSettings; |
| 266 | boolean mRestoredSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | |
| 268 | // Group-ids that are given to all packages as read from etc/permissions/*.xml. |
| 269 | int[] mGlobalGids; |
| 270 | |
| 271 | // These are the built-in uid -> permission mappings that were read from the |
| 272 | // etc/permissions.xml file. |
| 273 | final SparseArray<HashSet<String>> mSystemPermissions = |
| 274 | new SparseArray<HashSet<String>>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | // These are the built-in shared libraries that were read from the |
| 277 | // etc/permissions.xml file. |
| 278 | final HashMap<String, String> mSharedLibraries = new HashMap<String, String>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 279 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 280 | // Temporary for building the final shared libraries for an .apk. |
| 281 | String[] mTmpSharedLibraries = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 282 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 283 | // These are the features this devices supports that were read from the |
| 284 | // etc/permissions.xml file. |
| 285 | final HashMap<String, FeatureInfo> mAvailableFeatures = |
| 286 | new HashMap<String, FeatureInfo>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | // All available activities, for your resolving pleasure. |
| 289 | final ActivityIntentResolver mActivities = |
| 290 | new ActivityIntentResolver(); |
| 291 | |
| 292 | // All available receivers, for your resolving pleasure. |
| 293 | final ActivityIntentResolver mReceivers = |
| 294 | new ActivityIntentResolver(); |
| 295 | |
| 296 | // All available services, for your resolving pleasure. |
| 297 | final ServiceIntentResolver mServices = new ServiceIntentResolver(); |
| 298 | |
| 299 | // Keys are String (provider class name), values are Provider. |
| 300 | final HashMap<ComponentName, PackageParser.Provider> mProvidersByComponent = |
| 301 | new HashMap<ComponentName, PackageParser.Provider>(); |
| 302 | |
| 303 | // Mapping from provider base names (first directory in content URI codePath) |
| 304 | // to the provider information. |
| 305 | final HashMap<String, PackageParser.Provider> mProviders = |
| 306 | new HashMap<String, PackageParser.Provider>(); |
| 307 | |
| 308 | // Mapping from instrumentation class names to info about them. |
| 309 | final HashMap<ComponentName, PackageParser.Instrumentation> mInstrumentation = |
| 310 | new HashMap<ComponentName, PackageParser.Instrumentation>(); |
| 311 | |
| 312 | // Mapping from permission names to info about them. |
| 313 | final HashMap<String, PackageParser.PermissionGroup> mPermissionGroups = |
| 314 | new HashMap<String, PackageParser.PermissionGroup>(); |
| 315 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 316 | // Packages whose data we have transfered into another package, thus |
| 317 | // should no longer exist. |
| 318 | final HashSet<String> mTransferedPackages = new HashSet<String>(); |
| 319 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 320 | // Broadcast actions that are only available to the system. |
| 321 | final HashSet<String> mProtectedBroadcasts = new HashSet<String>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | boolean mSystemReady; |
| 324 | boolean mSafeMode; |
| 325 | boolean mHasSystemUidErrors; |
| 326 | |
| 327 | ApplicationInfo mAndroidApplication; |
| 328 | final ActivityInfo mResolveActivity = new ActivityInfo(); |
| 329 | final ResolveInfo mResolveInfo = new ResolveInfo(); |
| 330 | ComponentName mResolveComponentName; |
| 331 | PackageParser.Package mPlatformPackage; |
| 332 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 333 | // Set of pending broadcasts for aggregating enable/disable of components. |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 334 | final HashMap<String, ArrayList<String>> mPendingBroadcasts |
| 335 | = new HashMap<String, ArrayList<String>>(); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 336 | // Service Connection to remote media container service to copy |
| 337 | // package uri's from external media onto secure containers |
| 338 | // or internal storage. |
| 339 | private IMediaContainerService mContainerService = null; |
| 340 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 341 | static final int SEND_PENDING_BROADCAST = 1; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 342 | static final int MCS_BOUND = 3; |
| 343 | static final int END_COPY = 4; |
| 344 | static final int INIT_COPY = 5; |
| 345 | static final int MCS_UNBIND = 6; |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 346 | static final int START_CLEANING_PACKAGE = 7; |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 347 | static final int FIND_INSTALL_LOC = 8; |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 348 | static final int POST_INSTALL = 9; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 349 | static final int MCS_RECONNECT = 10; |
| 350 | static final int MCS_GIVE_UP = 11; |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 351 | static final int UPDATED_MEDIA_STATUS = 12; |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 352 | static final int WRITE_SETTINGS = 13; |
| 353 | |
| 354 | static final int WRITE_SETTINGS_DELAY = 10*1000; // 10 seconds |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 355 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 356 | // Delay time in millisecs |
| 357 | static final int BROADCAST_DELAY = 10 * 1000; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 358 | final private DefaultContainerConnection mDefContainerConn = |
| 359 | new DefaultContainerConnection(); |
| 360 | class DefaultContainerConnection implements ServiceConnection { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 361 | public void onServiceConnected(ComponentName name, IBinder service) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 362 | if (DEBUG_SD_INSTALL) Log.i(TAG, "onServiceConnected"); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 363 | IMediaContainerService imcs = |
| 364 | IMediaContainerService.Stub.asInterface(service); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 365 | mHandler.sendMessage(mHandler.obtainMessage(MCS_BOUND, imcs)); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | public void onServiceDisconnected(ComponentName name) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 369 | if (DEBUG_SD_INSTALL) Log.i(TAG, "onServiceDisconnected"); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 370 | } |
| 371 | }; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 372 | |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 373 | // Recordkeeping of restore-after-install operations that are currently in flight |
| 374 | // between the Package Manager and the Backup Manager |
| 375 | class PostInstallData { |
| 376 | public InstallArgs args; |
| 377 | public PackageInstalledInfo res; |
| 378 | |
| 379 | PostInstallData(InstallArgs _a, PackageInstalledInfo _r) { |
| 380 | args = _a; |
| 381 | res = _r; |
| 382 | } |
| 383 | }; |
| 384 | final SparseArray<PostInstallData> mRunningInstalls = new SparseArray<PostInstallData>(); |
| 385 | int mNextInstallToken = 1; // nonzero; will be wrapped back to 1 when ++ overflows |
| 386 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 387 | class PackageHandler extends Handler { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 388 | private boolean mBound = false; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 389 | final ArrayList<HandlerParams> mPendingInstalls = |
| 390 | new ArrayList<HandlerParams>(); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 391 | |
| 392 | private boolean connectToService() { |
| 393 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to bind to" + |
| 394 | " DefaultContainerService"); |
| 395 | Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT); |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 396 | Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 397 | if (mContext.bindService(service, mDefContainerConn, |
| 398 | Context.BIND_AUTO_CREATE)) { |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 399 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 400 | mBound = true; |
| 401 | return true; |
| 402 | } |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 403 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 404 | return false; |
| 405 | } |
| 406 | |
| 407 | private void disconnectService() { |
| 408 | mContainerService = null; |
| 409 | mBound = false; |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 410 | Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 411 | mContext.unbindService(mDefContainerConn); |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 412 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 413 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 414 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 415 | PackageHandler(Looper looper) { |
| 416 | super(looper); |
| 417 | } |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 418 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 419 | public void handleMessage(Message msg) { |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 420 | try { |
| 421 | doHandleMessage(msg); |
| 422 | } finally { |
| 423 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | void doHandleMessage(Message msg) { |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 428 | switch (msg.what) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 429 | case INIT_COPY: { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 430 | if (DEBUG_SD_INSTALL) Log.i(TAG, "init_copy"); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 431 | HandlerParams params = (HandlerParams) msg.obj; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 432 | int idx = mPendingInstalls.size(); |
| 433 | if (DEBUG_SD_INSTALL) Log.i(TAG, "idx=" + idx); |
| 434 | // If a bind was already initiated we dont really |
| 435 | // need to do anything. The pending install |
| 436 | // will be processed later on. |
| 437 | if (!mBound) { |
| 438 | // If this is the only one pending we might |
| 439 | // have to bind to the service again. |
| 440 | if (!connectToService()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 441 | Slog.e(TAG, "Failed to bind to media container service"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 442 | params.serviceError(); |
| 443 | return; |
| 444 | } else { |
| 445 | // Once we bind to the service, the first |
| 446 | // pending request will be processed. |
| 447 | mPendingInstalls.add(idx, params); |
| 448 | } |
| 449 | } else { |
| 450 | mPendingInstalls.add(idx, params); |
| 451 | // Already bound to the service. Just make |
| 452 | // sure we trigger off processing the first request. |
| 453 | if (idx == 0) { |
| 454 | mHandler.sendEmptyMessage(MCS_BOUND); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | break; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 458 | } |
| 459 | case MCS_BOUND: { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 460 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_bound"); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 461 | if (msg.obj != null) { |
| 462 | mContainerService = (IMediaContainerService) msg.obj; |
| 463 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 464 | if (mContainerService == null) { |
| 465 | // Something seriously wrong. Bail out |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 466 | Slog.e(TAG, "Cannot bind to media container service"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 467 | for (HandlerParams params : mPendingInstalls) { |
| 468 | mPendingInstalls.remove(0); |
| 469 | // Indicate service bind error |
| 470 | params.serviceError(); |
| 471 | } |
| 472 | mPendingInstalls.clear(); |
| 473 | } else if (mPendingInstalls.size() > 0) { |
| 474 | HandlerParams params = mPendingInstalls.get(0); |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 475 | if (params != null) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 476 | params.startCopy(); |
| 477 | } |
| 478 | } else { |
| 479 | // Should never happen ideally. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 480 | Slog.w(TAG, "Empty queue"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 481 | } |
| 482 | break; |
| 483 | } |
| 484 | case MCS_RECONNECT : { |
| 485 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_reconnect"); |
| 486 | if (mPendingInstalls.size() > 0) { |
| 487 | if (mBound) { |
| 488 | disconnectService(); |
| 489 | } |
| 490 | if (!connectToService()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 491 | Slog.e(TAG, "Failed to bind to media container service"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 492 | for (HandlerParams params : mPendingInstalls) { |
| 493 | mPendingInstalls.remove(0); |
| 494 | // Indicate service bind error |
| 495 | params.serviceError(); |
| 496 | } |
| 497 | mPendingInstalls.clear(); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | break; |
| 501 | } |
| 502 | case MCS_UNBIND : { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 503 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_unbind"); |
| 504 | // Delete pending install |
| 505 | if (mPendingInstalls.size() > 0) { |
| 506 | mPendingInstalls.remove(0); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 507 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 508 | if (mPendingInstalls.size() == 0) { |
| 509 | if (mBound) { |
| 510 | disconnectService(); |
| 511 | } |
| 512 | } else { |
| 513 | // There are more pending requests in queue. |
| 514 | // Just post MCS_BOUND message to trigger processing |
| 515 | // of next pending install. |
| 516 | mHandler.sendEmptyMessage(MCS_BOUND); |
| 517 | } |
| 518 | break; |
| 519 | } |
| 520 | case MCS_GIVE_UP: { |
| 521 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_giveup too many retries"); |
| 522 | HandlerParams params = mPendingInstalls.remove(0); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 523 | break; |
| 524 | } |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 525 | case SEND_PENDING_BROADCAST : { |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 526 | String packages[]; |
| 527 | ArrayList components[]; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 528 | int size = 0; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 529 | int uids[]; |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 530 | Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 531 | synchronized (mPackages) { |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 532 | if (mPendingBroadcasts == null) { |
| 533 | return; |
| 534 | } |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 535 | size = mPendingBroadcasts.size(); |
| 536 | if (size <= 0) { |
| 537 | // Nothing to be done. Just return |
| 538 | return; |
| 539 | } |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 540 | packages = new String[size]; |
| 541 | components = new ArrayList[size]; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 542 | uids = new int[size]; |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 543 | Iterator<HashMap.Entry<String, ArrayList<String>>> |
| 544 | it = mPendingBroadcasts.entrySet().iterator(); |
| 545 | int i = 0; |
| 546 | while (it.hasNext() && i < size) { |
| 547 | HashMap.Entry<String, ArrayList<String>> ent = it.next(); |
| 548 | packages[i] = ent.getKey(); |
| 549 | components[i] = ent.getValue(); |
| 550 | PackageSetting ps = mSettings.mPackages.get(ent.getKey()); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 551 | uids[i] = (ps != null) ? ps.userId : -1; |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 552 | i++; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 553 | } |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 554 | size = i; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 555 | mPendingBroadcasts.clear(); |
| 556 | } |
| 557 | // Send broadcasts |
| 558 | for (int i = 0; i < size; i++) { |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 559 | sendPackageChangedBroadcast(packages[i], true, |
| 560 | (ArrayList<String>)components[i], uids[i]); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 561 | } |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 562 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 563 | break; |
| 564 | } |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 565 | case START_CLEANING_PACKAGE: { |
| 566 | String packageName = (String)msg.obj; |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 567 | Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 568 | synchronized (mPackages) { |
| 569 | if (!mSettings.mPackagesToBeCleaned.contains(packageName)) { |
| 570 | mSettings.mPackagesToBeCleaned.add(packageName); |
| 571 | } |
| 572 | } |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 573 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 574 | startCleaningPackages(); |
| 575 | } break; |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 576 | case POST_INSTALL: { |
| 577 | if (DEBUG_INSTALL) Log.v(TAG, "Handling post-install for " + msg.arg1); |
| 578 | PostInstallData data = mRunningInstalls.get(msg.arg1); |
| 579 | mRunningInstalls.delete(msg.arg1); |
Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 580 | boolean deleteOld = false; |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 581 | |
| 582 | if (data != null) { |
| 583 | InstallArgs args = data.args; |
| 584 | PackageInstalledInfo res = data.res; |
| 585 | |
| 586 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) { |
Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 587 | res.removedInfo.sendBroadcast(false, true); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 588 | Bundle extras = new Bundle(1); |
| 589 | extras.putInt(Intent.EXTRA_UID, res.uid); |
| 590 | final boolean update = res.removedInfo.removedPackage != null; |
| 591 | if (update) { |
| 592 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 593 | } |
| 594 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, |
| 595 | res.pkg.applicationInfo.packageName, |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 596 | extras, null); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 597 | if (update) { |
| 598 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, |
| 599 | res.pkg.applicationInfo.packageName, |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 600 | extras, null); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 601 | } |
Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 602 | if (res.removedInfo.args != null) { |
| 603 | // Remove the replaced package's older resources safely now |
| 604 | deleteOld = true; |
| 605 | } |
| 606 | } |
| 607 | // Force a gc to clear up things |
| 608 | Runtime.getRuntime().gc(); |
| 609 | // We delete after a gc for applications on sdcard. |
| 610 | if (deleteOld) { |
| 611 | synchronized (mInstallLock) { |
| 612 | res.removedInfo.args.doPostDeleteLI(true); |
| 613 | } |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 614 | } |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 615 | if (args.observer != null) { |
| 616 | try { |
| 617 | args.observer.packageInstalled(res.name, res.returnCode); |
| 618 | } catch (RemoteException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 619 | Slog.i(TAG, "Observer no longer exists."); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 623 | Slog.e(TAG, "Bogus post-install token " + msg.arg1); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 624 | } |
| 625 | } break; |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 626 | case UPDATED_MEDIA_STATUS: { |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 627 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Got message UPDATED_MEDIA_STATUS"); |
| 628 | boolean reportStatus = msg.arg1 == 1; |
| 629 | boolean doGc = msg.arg2 == 1; |
| 630 | if (DEBUG_SD_INSTALL) Log.i(TAG, "reportStatus=" + reportStatus + ", doGc = " + doGc); |
| 631 | if (doGc) { |
| 632 | // Force a gc to clear up stale containers. |
| 633 | Runtime.getRuntime().gc(); |
| 634 | } |
| 635 | if (msg.obj != null) { |
| 636 | Set<SdInstallArgs> args = (Set<SdInstallArgs>) msg.obj; |
| 637 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Unloading all containers"); |
| 638 | // Unload containers |
| 639 | unloadAllContainers(args); |
| 640 | } |
| 641 | if (reportStatus) { |
| 642 | try { |
| 643 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Invoking MountService call back"); |
| 644 | PackageHelper.getMountService().finishMediaUpdate(); |
| 645 | } catch (RemoteException e) { |
| 646 | Log.e(TAG, "MountService not running?"); |
| 647 | } |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 648 | } |
| 649 | } break; |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 650 | case WRITE_SETTINGS: { |
| 651 | Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); |
| 652 | synchronized (mPackages) { |
| 653 | removeMessages(WRITE_SETTINGS); |
| 654 | mSettings.writeLP(); |
| 655 | } |
| 656 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 657 | } break; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 661 | |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 662 | void scheduleWriteSettingsLocked() { |
| 663 | if (!mHandler.hasMessages(WRITE_SETTINGS)) { |
| 664 | mHandler.sendEmptyMessageDelayed(WRITE_SETTINGS, WRITE_SETTINGS_DELAY); |
| 665 | } |
| 666 | } |
| 667 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 668 | static boolean installOnSd(int flags) { |
| 669 | if (((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) || |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 670 | ((flags & PackageManager.INSTALL_INTERNAL) != 0)) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 671 | return false; |
| 672 | } |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 673 | if ((flags & PackageManager.INSTALL_EXTERNAL) != 0) { |
| 674 | return true; |
| 675 | } |
| 676 | return false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | static boolean isFwdLocked(int flags) { |
| 680 | if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { |
| 681 | return true; |
| 682 | } |
| 683 | return false; |
| 684 | } |
| 685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 686 | public static final IPackageManager main(Context context, boolean factoryTest) { |
| 687 | PackageManagerService m = new PackageManagerService(context, factoryTest); |
| 688 | ServiceManager.addService("package", m); |
| 689 | return m; |
| 690 | } |
| 691 | |
| 692 | static String[] splitString(String str, char sep) { |
| 693 | int count = 1; |
| 694 | int i = 0; |
| 695 | while ((i=str.indexOf(sep, i)) >= 0) { |
| 696 | count++; |
| 697 | i++; |
| 698 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | String[] res = new String[count]; |
| 701 | i=0; |
| 702 | count = 0; |
| 703 | int lastI=0; |
| 704 | while ((i=str.indexOf(sep, i)) >= 0) { |
| 705 | res[count] = str.substring(lastI, i); |
| 706 | count++; |
| 707 | i++; |
| 708 | lastI = i; |
| 709 | } |
| 710 | res[count] = str.substring(lastI, str.length()); |
| 711 | return res; |
| 712 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | public PackageManagerService(Context context, boolean factoryTest) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 715 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_START, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | SystemClock.uptimeMillis()); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | if (mSdkVersion <= 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 719 | Slog.w(TAG, "**** ro.build.version.sdk not set!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 721 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | mContext = context; |
| 723 | mFactoryTest = factoryTest; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 724 | mNoDexOpt = "eng".equals(SystemProperties.get("ro.build.type")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | mMetrics = new DisplayMetrics(); |
| 726 | mSettings = new Settings(); |
| 727 | mSettings.addSharedUserLP("android.uid.system", |
| 728 | Process.SYSTEM_UID, ApplicationInfo.FLAG_SYSTEM); |
| 729 | mSettings.addSharedUserLP("android.uid.phone", |
| 730 | MULTIPLE_APPLICATION_UIDS |
| 731 | ? RADIO_UID : FIRST_APPLICATION_UID, |
| 732 | ApplicationInfo.FLAG_SYSTEM); |
Mike Lockwood | d42685d | 2009-09-03 09:25:22 -0400 | [diff] [blame] | 733 | mSettings.addSharedUserLP("android.uid.log", |
| 734 | MULTIPLE_APPLICATION_UIDS |
| 735 | ? LOG_UID : FIRST_APPLICATION_UID, |
| 736 | ApplicationInfo.FLAG_SYSTEM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | |
| 738 | String separateProcesses = SystemProperties.get("debug.separate_processes"); |
| 739 | if (separateProcesses != null && separateProcesses.length() > 0) { |
| 740 | if ("*".equals(separateProcesses)) { |
| 741 | mDefParseFlags = PackageParser.PARSE_IGNORE_PROCESSES; |
| 742 | mSeparateProcesses = null; |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 743 | Slog.w(TAG, "Running with debug.separate_processes: * (ALL)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | } else { |
| 745 | mDefParseFlags = 0; |
| 746 | mSeparateProcesses = separateProcesses.split(","); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 747 | Slog.w(TAG, "Running with debug.separate_processes: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | + separateProcesses); |
| 749 | } |
| 750 | } else { |
| 751 | mDefParseFlags = 0; |
| 752 | mSeparateProcesses = null; |
| 753 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 754 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | Installer installer = new Installer(); |
| 756 | // Little hacky thing to check if installd is here, to determine |
| 757 | // whether we are running on the simulator and thus need to take |
| 758 | // care of building the /data file structure ourself. |
| 759 | // (apparently the sim now has a working installer) |
| 760 | if (installer.ping() && Process.supportsProcesses()) { |
| 761 | mInstaller = installer; |
| 762 | } else { |
| 763 | mInstaller = null; |
| 764 | } |
| 765 | |
| 766 | WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 767 | Display d = wm.getDefaultDisplay(); |
| 768 | d.getMetrics(mMetrics); |
| 769 | |
| 770 | synchronized (mInstallLock) { |
| 771 | synchronized (mPackages) { |
| 772 | mHandlerThread.start(); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 773 | mHandler = new PackageHandler(mHandlerThread.getLooper()); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 774 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | File dataDir = Environment.getDataDirectory(); |
| 776 | mAppDataDir = new File(dataDir, "data"); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 777 | mSecureAppDataDir = new File(dataDir, "secure/data"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | mDrmAppPrivateInstallDir = new File(dataDir, "app-private"); |
| 779 | |
| 780 | if (mInstaller == null) { |
| 781 | // Make sure these dirs exist, when we are running in |
| 782 | // the simulator. |
| 783 | // Make a wide-open directory for random misc stuff. |
| 784 | File miscDir = new File(dataDir, "misc"); |
| 785 | miscDir.mkdirs(); |
| 786 | mAppDataDir.mkdirs(); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 787 | mSecureAppDataDir.mkdirs(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | mDrmAppPrivateInstallDir.mkdirs(); |
| 789 | } |
| 790 | |
| 791 | readPermissions(); |
| 792 | |
| 793 | mRestoredSettings = mSettings.readLP(); |
| 794 | long startTime = SystemClock.uptimeMillis(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 795 | |
| 796 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SYSTEM_SCAN_START, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | startTime); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 798 | |
Suchi Amalapurapu | daec172 | 2010-01-14 21:25:16 -0800 | [diff] [blame] | 799 | // Set flag to monitor and not change apk file paths when |
| 800 | // scanning install directories. |
| 801 | int scanMode = SCAN_MONITOR | SCAN_NO_PATHS; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 802 | if (mNoDexOpt) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 803 | Slog.w(TAG, "Running ENG build: no pre-dexopt!"); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 804 | scanMode |= SCAN_NO_DEX; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 805 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | final HashSet<String> libFiles = new HashSet<String>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | mFrameworkDir = new File(Environment.getRootDirectory(), "framework"); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 810 | mDalvikCacheDir = new File(dataDir, "dalvik-cache"); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 811 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | if (mInstaller != null) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 813 | boolean didDexOpt = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 814 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | /** |
| 816 | * Out of paranoia, ensure that everything in the boot class |
| 817 | * path has been dexed. |
| 818 | */ |
| 819 | String bootClassPath = System.getProperty("java.boot.class.path"); |
| 820 | if (bootClassPath != null) { |
| 821 | String[] paths = splitString(bootClassPath, ':'); |
| 822 | for (int i=0; i<paths.length; i++) { |
| 823 | try { |
| 824 | if (dalvik.system.DexFile.isDexOptNeeded(paths[i])) { |
| 825 | libFiles.add(paths[i]); |
| 826 | mInstaller.dexopt(paths[i], Process.SYSTEM_UID, true); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 827 | didDexOpt = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | } |
| 829 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 830 | 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] | 831 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 832 | 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] | 833 | } |
| 834 | } |
| 835 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 836 | Slog.w(TAG, "No BOOTCLASSPATH found!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | /** |
| 840 | * Also ensure all external libraries have had dexopt run on them. |
| 841 | */ |
| 842 | if (mSharedLibraries.size() > 0) { |
| 843 | Iterator<String> libs = mSharedLibraries.values().iterator(); |
| 844 | while (libs.hasNext()) { |
| 845 | String lib = libs.next(); |
| 846 | try { |
| 847 | if (dalvik.system.DexFile.isDexOptNeeded(lib)) { |
| 848 | libFiles.add(lib); |
| 849 | mInstaller.dexopt(lib, Process.SYSTEM_UID, true); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 850 | didDexOpt = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | } |
| 852 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 853 | Slog.w(TAG, "Library not found: " + lib); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 855 | Slog.w(TAG, "Exception reading library: " + lib, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 859 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | // Gross hack for now: we know this file doesn't contain any |
| 861 | // code, so don't dexopt it to avoid the resulting log spew. |
| 862 | libFiles.add(mFrameworkDir.getPath() + "/framework-res.apk"); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | /** |
| 865 | * And there are a number of commands implemented in Java, which |
| 866 | * we currently need to do the dexopt on so that they can be |
| 867 | * run from a non-root shell. |
| 868 | */ |
| 869 | String[] frameworkFiles = mFrameworkDir.list(); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 870 | if (frameworkFiles != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 871 | for (int i=0; i<frameworkFiles.length; i++) { |
| 872 | File libPath = new File(mFrameworkDir, frameworkFiles[i]); |
| 873 | String path = libPath.getPath(); |
| 874 | // Skip the file if we alrady did it. |
| 875 | if (libFiles.contains(path)) { |
| 876 | continue; |
| 877 | } |
| 878 | // Skip the file if it is not a type we want to dexopt. |
| 879 | if (!path.endsWith(".apk") && !path.endsWith(".jar")) { |
| 880 | continue; |
| 881 | } |
| 882 | try { |
| 883 | if (dalvik.system.DexFile.isDexOptNeeded(path)) { |
| 884 | mInstaller.dexopt(path, Process.SYSTEM_UID, true); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 885 | didDexOpt = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | } |
| 887 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 888 | Slog.w(TAG, "Jar not found: " + path); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 890 | Slog.w(TAG, "Exception reading jar: " + path, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 894 | |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 895 | if (didDexOpt) { |
| 896 | // If we had to do a dexopt of one of the previous |
| 897 | // things, then something on the system has changed. |
| 898 | // Consider this significant, and wipe away all other |
| 899 | // existing dexopt files to ensure we don't leave any |
| 900 | // dangling around. |
| 901 | String[] files = mDalvikCacheDir.list(); |
| 902 | if (files != null) { |
| 903 | for (int i=0; i<files.length; i++) { |
| 904 | String fn = files[i]; |
| 905 | if (fn.startsWith("data@app@") |
| 906 | || fn.startsWith("data@app-private@")) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 907 | Slog.i(TAG, "Pruning dalvik file: " + fn); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 908 | (new File(mDalvikCacheDir, fn)).delete(); |
| 909 | } |
| 910 | } |
| 911 | } |
| 912 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 914 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 915 | // Find base frameworks (resource packages without code). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | mFrameworkInstallObserver = new AppDirObserver( |
| 917 | mFrameworkDir.getPath(), OBSERVER_EVENTS, true); |
| 918 | mFrameworkInstallObserver.startWatching(); |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 919 | scanDirLI(mFrameworkDir, PackageParser.PARSE_IS_SYSTEM |
| 920 | | PackageParser.PARSE_IS_SYSTEM_DIR, |
Suchi Amalapurapu | daec172 | 2010-01-14 21:25:16 -0800 | [diff] [blame] | 921 | scanMode | SCAN_NO_DEX); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 922 | |
| 923 | // Collect all system packages. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | mSystemAppDir = new File(Environment.getRootDirectory(), "app"); |
| 925 | mSystemInstallObserver = new AppDirObserver( |
| 926 | mSystemAppDir.getPath(), OBSERVER_EVENTS, true); |
| 927 | mSystemInstallObserver.startWatching(); |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 928 | scanDirLI(mSystemAppDir, PackageParser.PARSE_IS_SYSTEM |
| 929 | | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 930 | |
| 931 | if (mInstaller != null) { |
| 932 | if (DEBUG_UPGRADE) Log.v(TAG, "Running installd update commands"); |
| 933 | mInstaller.moveFiles(); |
| 934 | } |
| 935 | |
| 936 | // Prune any system packages that no longer exist. |
| 937 | Iterator<PackageSetting> psit = mSettings.mPackages.values().iterator(); |
| 938 | while (psit.hasNext()) { |
| 939 | PackageSetting ps = psit.next(); |
| 940 | if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0 |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 941 | && !mPackages.containsKey(ps.name) |
| 942 | && !mSettings.mDisabledSysPackages.containsKey(ps.name)) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 943 | psit.remove(); |
| 944 | String msg = "System package " + ps.name |
| 945 | + " no longer exists; wiping its data"; |
| 946 | reportSettingsProblem(Log.WARN, msg); |
| 947 | if (mInstaller != null) { |
| 948 | // XXX how to set useEncryptedFSDir for packages that |
| 949 | // are not encrypted? |
| 950 | mInstaller.remove(ps.name, true); |
| 951 | } |
| 952 | } |
| 953 | } |
| 954 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | mAppInstallDir = new File(dataDir, "app"); |
| 956 | if (mInstaller == null) { |
| 957 | // Make sure these dirs exist, when we are running in |
| 958 | // the simulator. |
| 959 | mAppInstallDir.mkdirs(); // scanDirLI() assumes this dir exists |
| 960 | } |
| 961 | //look for any incomplete package installations |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 962 | ArrayList<PackageSetting> deletePkgsList = mSettings.getListOfIncompleteInstallPackages(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 963 | //clean up list |
| 964 | for(int i = 0; i < deletePkgsList.size(); i++) { |
| 965 | //clean up here |
| 966 | cleanupInstallFailedPackage(deletePkgsList.get(i)); |
| 967 | } |
| 968 | //delete tmp files |
| 969 | deleteTempPackageFiles(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 970 | |
| 971 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_DATA_SCAN_START, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | SystemClock.uptimeMillis()); |
| 973 | mAppInstallObserver = new AppDirObserver( |
| 974 | mAppInstallDir.getPath(), OBSERVER_EVENTS, false); |
| 975 | mAppInstallObserver.startWatching(); |
| 976 | scanDirLI(mAppInstallDir, 0, scanMode); |
| 977 | |
| 978 | mDrmAppInstallObserver = new AppDirObserver( |
| 979 | mDrmAppPrivateInstallDir.getPath(), OBSERVER_EVENTS, false); |
| 980 | mDrmAppInstallObserver.startWatching(); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 981 | scanDirLI(mDrmAppPrivateInstallDir, PackageParser.PARSE_FORWARD_LOCK, scanMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 983 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SCAN_END, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | SystemClock.uptimeMillis()); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 985 | Slog.i(TAG, "Time to scan packages: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | + ((SystemClock.uptimeMillis()-startTime)/1000f) |
| 987 | + " seconds"); |
| 988 | |
Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 989 | // If the platform SDK has changed since the last time we booted, |
| 990 | // we need to re-grant app permission to catch any new ones that |
| 991 | // appear. This is really a hack, and means that apps can in some |
| 992 | // cases get permissions that the user didn't initially explicitly |
| 993 | // allow... it would be nice to have some better way to handle |
| 994 | // this situation. |
| 995 | final boolean regrantPermissions = mSettings.mInternalSdkPlatform |
| 996 | != mSdkVersion; |
| 997 | if (regrantPermissions) Slog.i(TAG, "Platform changed from " |
| 998 | + mSettings.mInternalSdkPlatform + " to " + mSdkVersion |
| 999 | + "; regranting permissions for internal storage"); |
| 1000 | mSettings.mInternalSdkPlatform = mSdkVersion; |
| 1001 | |
Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 1002 | updatePermissionsLP(null, null, true, regrantPermissions, regrantPermissions); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | |
| 1004 | mSettings.writeLP(); |
| 1005 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1006 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_READY, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | SystemClock.uptimeMillis()); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | // Now after opening every single application zip, make sure they |
| 1010 | // are all flushed. Not really needed, but keeps things nice and |
| 1011 | // tidy. |
| 1012 | Runtime.getRuntime().gc(); |
| 1013 | } // synchronized (mPackages) |
| 1014 | } // synchronized (mInstallLock) |
| 1015 | } |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 1016 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | @Override |
| 1018 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1019 | throws RemoteException { |
| 1020 | try { |
| 1021 | return super.onTransact(code, data, reply, flags); |
| 1022 | } catch (RuntimeException e) { |
| 1023 | if (!(e instanceof SecurityException) && !(e instanceof IllegalArgumentException)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1024 | Slog.e(TAG, "Package Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | } |
| 1026 | throw e; |
| 1027 | } |
| 1028 | } |
| 1029 | |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1030 | void cleanupInstallFailedPackage(PackageSetting ps) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1031 | 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] | 1032 | if (mInstaller != null) { |
Kenny Root | bdbc925 | 2010-01-28 12:03:49 -0800 | [diff] [blame] | 1033 | boolean useSecureFS = useEncryptedFilesystemForPackage(ps.pkg); |
| 1034 | int retCode = mInstaller.remove(ps.name, useSecureFS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1036 | Slog.w(TAG, "Couldn't remove app data directory for package: " |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1037 | + ps.name + ", retcode=" + retCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | } |
| 1039 | } else { |
| 1040 | //for emulator |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1041 | PackageParser.Package pkg = mPackages.get(ps.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | File dataDir = new File(pkg.applicationInfo.dataDir); |
| 1043 | dataDir.delete(); |
| 1044 | } |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1045 | if (ps.codePath != null) { |
| 1046 | if (!ps.codePath.delete()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1047 | Slog.w(TAG, "Unable to remove old code file: " + ps.codePath); |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1048 | } |
| 1049 | } |
| 1050 | if (ps.resourcePath != null) { |
| 1051 | if (!ps.resourcePath.delete() && !ps.resourcePath.equals(ps.codePath)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1052 | Slog.w(TAG, "Unable to remove old code file: " + ps.resourcePath); |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | mSettings.removePackageLP(ps.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | void readPermissions() { |
| 1059 | // Read permissions from .../etc/permission directory. |
| 1060 | File libraryDir = new File(Environment.getRootDirectory(), "etc/permissions"); |
| 1061 | if (!libraryDir.exists() || !libraryDir.isDirectory()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1062 | Slog.w(TAG, "No directory " + libraryDir + ", skipping"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | return; |
| 1064 | } |
| 1065 | if (!libraryDir.canRead()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1066 | Slog.w(TAG, "Directory " + libraryDir + " cannot be read"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | return; |
| 1068 | } |
| 1069 | |
| 1070 | // Iterate over the files in the directory and scan .xml files |
| 1071 | for (File f : libraryDir.listFiles()) { |
| 1072 | // We'll read platform.xml last |
| 1073 | if (f.getPath().endsWith("etc/permissions/platform.xml")) { |
| 1074 | continue; |
| 1075 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | if (!f.getPath().endsWith(".xml")) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1078 | 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] | 1079 | continue; |
| 1080 | } |
| 1081 | if (!f.canRead()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1082 | 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] | 1083 | continue; |
| 1084 | } |
| 1085 | |
| 1086 | readPermissionsFromXml(f); |
| 1087 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | // Read permissions from .../etc/permissions/platform.xml last so it will take precedence |
| 1090 | final File permFile = new File(Environment.getRootDirectory(), |
| 1091 | "etc/permissions/platform.xml"); |
| 1092 | readPermissionsFromXml(permFile); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1093 | |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1094 | StringBuilder sb = new StringBuilder(128); |
| 1095 | sb.append("Libs:"); |
| 1096 | Iterator<String> it = mSharedLibraries.keySet().iterator(); |
| 1097 | while (it.hasNext()) { |
| 1098 | sb.append(' '); |
| 1099 | String name = it.next(); |
| 1100 | sb.append(name); |
| 1101 | sb.append(':'); |
| 1102 | sb.append(mSharedLibraries.get(name)); |
| 1103 | } |
| 1104 | Log.i(TAG, sb.toString()); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1105 | |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1106 | sb.setLength(0); |
| 1107 | sb.append("Features:"); |
| 1108 | it = mAvailableFeatures.keySet().iterator(); |
| 1109 | while (it.hasNext()) { |
| 1110 | sb.append(' '); |
| 1111 | sb.append(it.next()); |
| 1112 | } |
| 1113 | Log.i(TAG, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1115 | |
| 1116 | private void readPermissionsFromXml(File permFile) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | FileReader permReader = null; |
| 1118 | try { |
| 1119 | permReader = new FileReader(permFile); |
| 1120 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1121 | 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] | 1122 | return; |
| 1123 | } |
| 1124 | |
| 1125 | try { |
| 1126 | XmlPullParser parser = Xml.newPullParser(); |
| 1127 | parser.setInput(permReader); |
| 1128 | |
| 1129 | XmlUtils.beginDocument(parser, "permissions"); |
| 1130 | |
| 1131 | while (true) { |
| 1132 | XmlUtils.nextElement(parser); |
| 1133 | if (parser.getEventType() == XmlPullParser.END_DOCUMENT) { |
| 1134 | break; |
| 1135 | } |
| 1136 | |
| 1137 | String name = parser.getName(); |
| 1138 | if ("group".equals(name)) { |
| 1139 | String gidStr = parser.getAttributeValue(null, "gid"); |
| 1140 | if (gidStr != null) { |
| 1141 | int gid = Integer.parseInt(gidStr); |
| 1142 | mGlobalGids = appendInt(mGlobalGids, gid); |
| 1143 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1144 | Slog.w(TAG, "<group> without gid at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | + parser.getPositionDescription()); |
| 1146 | } |
| 1147 | |
| 1148 | XmlUtils.skipCurrentTag(parser); |
| 1149 | continue; |
| 1150 | } else if ("permission".equals(name)) { |
| 1151 | String perm = parser.getAttributeValue(null, "name"); |
| 1152 | if (perm == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1153 | Slog.w(TAG, "<permission> without name at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | + parser.getPositionDescription()); |
| 1155 | XmlUtils.skipCurrentTag(parser); |
| 1156 | continue; |
| 1157 | } |
| 1158 | perm = perm.intern(); |
| 1159 | readPermission(parser, perm); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | } else if ("assign-permission".equals(name)) { |
| 1162 | String perm = parser.getAttributeValue(null, "name"); |
| 1163 | if (perm == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1164 | Slog.w(TAG, "<assign-permission> without name at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | + parser.getPositionDescription()); |
| 1166 | XmlUtils.skipCurrentTag(parser); |
| 1167 | continue; |
| 1168 | } |
| 1169 | String uidStr = parser.getAttributeValue(null, "uid"); |
| 1170 | if (uidStr == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1171 | Slog.w(TAG, "<assign-permission> without uid at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | + parser.getPositionDescription()); |
| 1173 | XmlUtils.skipCurrentTag(parser); |
| 1174 | continue; |
| 1175 | } |
| 1176 | int uid = Process.getUidForName(uidStr); |
| 1177 | if (uid < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1178 | Slog.w(TAG, "<assign-permission> with unknown uid \"" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | + uidStr + "\" at " |
| 1180 | + parser.getPositionDescription()); |
| 1181 | XmlUtils.skipCurrentTag(parser); |
| 1182 | continue; |
| 1183 | } |
| 1184 | perm = perm.intern(); |
| 1185 | HashSet<String> perms = mSystemPermissions.get(uid); |
| 1186 | if (perms == null) { |
| 1187 | perms = new HashSet<String>(); |
| 1188 | mSystemPermissions.put(uid, perms); |
| 1189 | } |
| 1190 | perms.add(perm); |
| 1191 | XmlUtils.skipCurrentTag(parser); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1193 | } else if ("library".equals(name)) { |
| 1194 | String lname = parser.getAttributeValue(null, "name"); |
| 1195 | String lfile = parser.getAttributeValue(null, "file"); |
| 1196 | if (lname == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1197 | Slog.w(TAG, "<library> without name at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | + parser.getPositionDescription()); |
| 1199 | } else if (lfile == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1200 | Slog.w(TAG, "<library> without file at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | + parser.getPositionDescription()); |
| 1202 | } else { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1203 | //Log.i(TAG, "Got library " + lname + " in " + lfile); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1204 | mSharedLibraries.put(lname, lfile); |
| 1205 | } |
| 1206 | XmlUtils.skipCurrentTag(parser); |
| 1207 | continue; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1208 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1209 | } else if ("feature".equals(name)) { |
| 1210 | String fname = parser.getAttributeValue(null, "name"); |
| 1211 | if (fname == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1212 | Slog.w(TAG, "<feature> without name at " |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1213 | + parser.getPositionDescription()); |
| 1214 | } else { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1215 | //Log.i(TAG, "Got feature " + fname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1216 | FeatureInfo fi = new FeatureInfo(); |
| 1217 | fi.name = fname; |
| 1218 | mAvailableFeatures.put(fname, fi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | } |
| 1220 | XmlUtils.skipCurrentTag(parser); |
| 1221 | continue; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | } else { |
| 1224 | XmlUtils.skipCurrentTag(parser); |
| 1225 | continue; |
| 1226 | } |
| 1227 | |
| 1228 | } |
| 1229 | } catch (XmlPullParserException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1230 | Slog.w(TAG, "Got execption parsing permissions.", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1232 | Slog.w(TAG, "Got execption parsing permissions.", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | void readPermission(XmlPullParser parser, String name) |
| 1237 | throws IOException, XmlPullParserException { |
| 1238 | |
| 1239 | name = name.intern(); |
| 1240 | |
| 1241 | BasePermission bp = mSettings.mPermissions.get(name); |
| 1242 | if (bp == null) { |
| 1243 | bp = new BasePermission(name, null, BasePermission.TYPE_BUILTIN); |
| 1244 | mSettings.mPermissions.put(name, bp); |
| 1245 | } |
| 1246 | int outerDepth = parser.getDepth(); |
| 1247 | int type; |
| 1248 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1249 | && (type != XmlPullParser.END_TAG |
| 1250 | || parser.getDepth() > outerDepth)) { |
| 1251 | if (type == XmlPullParser.END_TAG |
| 1252 | || type == XmlPullParser.TEXT) { |
| 1253 | continue; |
| 1254 | } |
| 1255 | |
| 1256 | String tagName = parser.getName(); |
| 1257 | if ("group".equals(tagName)) { |
| 1258 | String gidStr = parser.getAttributeValue(null, "gid"); |
| 1259 | if (gidStr != null) { |
| 1260 | int gid = Process.getGidForName(gidStr); |
| 1261 | bp.gids = appendInt(bp.gids, gid); |
| 1262 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1263 | Slog.w(TAG, "<group> without gid at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | + parser.getPositionDescription()); |
| 1265 | } |
| 1266 | } |
| 1267 | XmlUtils.skipCurrentTag(parser); |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | static int[] appendInt(int[] cur, int val) { |
| 1272 | if (cur == null) { |
| 1273 | return new int[] { val }; |
| 1274 | } |
| 1275 | final int N = cur.length; |
| 1276 | for (int i=0; i<N; i++) { |
| 1277 | if (cur[i] == val) { |
| 1278 | return cur; |
| 1279 | } |
| 1280 | } |
| 1281 | int[] ret = new int[N+1]; |
| 1282 | System.arraycopy(cur, 0, ret, 0, N); |
| 1283 | ret[N] = val; |
| 1284 | return ret; |
| 1285 | } |
| 1286 | |
| 1287 | static int[] appendInts(int[] cur, int[] add) { |
| 1288 | if (add == null) return cur; |
| 1289 | if (cur == null) return add; |
| 1290 | final int N = add.length; |
| 1291 | for (int i=0; i<N; i++) { |
| 1292 | cur = appendInt(cur, add[i]); |
| 1293 | } |
| 1294 | return cur; |
| 1295 | } |
| 1296 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1297 | static int[] removeInt(int[] cur, int val) { |
| 1298 | if (cur == null) { |
| 1299 | return null; |
| 1300 | } |
| 1301 | final int N = cur.length; |
| 1302 | for (int i=0; i<N; i++) { |
| 1303 | if (cur[i] == val) { |
| 1304 | int[] ret = new int[N-1]; |
| 1305 | if (i > 0) { |
| 1306 | System.arraycopy(cur, 0, ret, 0, i); |
| 1307 | } |
| 1308 | if (i < (N-1)) { |
Jeff Brown | 8c8bb8b | 2010-04-20 17:21:47 -0700 | [diff] [blame] | 1309 | System.arraycopy(cur, i + 1, ret, i, N - i - 1); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1310 | } |
| 1311 | return ret; |
| 1312 | } |
| 1313 | } |
| 1314 | return cur; |
| 1315 | } |
| 1316 | |
| 1317 | static int[] removeInts(int[] cur, int[] rem) { |
| 1318 | if (rem == null) return cur; |
| 1319 | if (cur == null) return cur; |
| 1320 | final int N = rem.length; |
| 1321 | for (int i=0; i<N; i++) { |
| 1322 | cur = removeInt(cur, rem[i]); |
| 1323 | } |
| 1324 | return cur; |
| 1325 | } |
| 1326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | PackageInfo generatePackageInfo(PackageParser.Package p, int flags) { |
Suchi Amalapurapu | b897cff | 2009-10-14 12:11:48 -0700 | [diff] [blame] | 1328 | if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 1329 | // The package has been uninstalled but has retained data and resources. |
| 1330 | return PackageParser.generatePackageInfo(p, null, flags); |
| 1331 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1332 | final PackageSetting ps = (PackageSetting)p.mExtras; |
| 1333 | if (ps == null) { |
| 1334 | return null; |
| 1335 | } |
| 1336 | final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps; |
| 1337 | return PackageParser.generatePackageInfo(p, gp.gids, flags); |
| 1338 | } |
| 1339 | |
| 1340 | public PackageInfo getPackageInfo(String packageName, int flags) { |
| 1341 | synchronized (mPackages) { |
| 1342 | PackageParser.Package p = mPackages.get(packageName); |
| 1343 | if (Config.LOGV) Log.v( |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 1344 | TAG, "getPackageInfo " + packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1345 | + ": " + p); |
| 1346 | if (p != null) { |
| 1347 | return generatePackageInfo(p, flags); |
| 1348 | } |
| 1349 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 1350 | return generatePackageInfoFromSettingsLP(packageName, flags); |
| 1351 | } |
| 1352 | } |
| 1353 | return null; |
| 1354 | } |
| 1355 | |
Dianne Hackborn | 4709693 | 2010-02-11 15:57:09 -0800 | [diff] [blame] | 1356 | public String[] currentToCanonicalPackageNames(String[] names) { |
| 1357 | String[] out = new String[names.length]; |
| 1358 | synchronized (mPackages) { |
| 1359 | for (int i=names.length-1; i>=0; i--) { |
| 1360 | PackageSetting ps = mSettings.mPackages.get(names[i]); |
| 1361 | out[i] = ps != null && ps.realName != null ? ps.realName : names[i]; |
| 1362 | } |
| 1363 | } |
| 1364 | return out; |
| 1365 | } |
| 1366 | |
| 1367 | public String[] canonicalToCurrentPackageNames(String[] names) { |
| 1368 | String[] out = new String[names.length]; |
| 1369 | synchronized (mPackages) { |
| 1370 | for (int i=names.length-1; i>=0; i--) { |
| 1371 | String cur = mSettings.mRenamedPackages.get(names[i]); |
| 1372 | out[i] = cur != null ? cur : names[i]; |
| 1373 | } |
| 1374 | } |
| 1375 | return out; |
| 1376 | } |
| 1377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | public int getPackageUid(String packageName) { |
| 1379 | synchronized (mPackages) { |
| 1380 | PackageParser.Package p = mPackages.get(packageName); |
| 1381 | if(p != null) { |
| 1382 | return p.applicationInfo.uid; |
| 1383 | } |
| 1384 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 1385 | if((ps == null) || (ps.pkg == null) || (ps.pkg.applicationInfo == null)) { |
| 1386 | return -1; |
| 1387 | } |
| 1388 | p = ps.pkg; |
| 1389 | return p != null ? p.applicationInfo.uid : -1; |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | public int[] getPackageGids(String packageName) { |
| 1394 | synchronized (mPackages) { |
| 1395 | PackageParser.Package p = mPackages.get(packageName); |
| 1396 | if (Config.LOGV) Log.v( |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 1397 | TAG, "getPackageGids" + packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | + ": " + p); |
| 1399 | if (p != null) { |
| 1400 | final PackageSetting ps = (PackageSetting)p.mExtras; |
| 1401 | final SharedUserSetting suid = ps.sharedUser; |
| 1402 | return suid != null ? suid.gids : ps.gids; |
| 1403 | } |
| 1404 | } |
| 1405 | // stupid thing to indicate an error. |
| 1406 | return new int[0]; |
| 1407 | } |
| 1408 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1409 | static final PermissionInfo generatePermissionInfo( |
| 1410 | BasePermission bp, int flags) { |
| 1411 | if (bp.perm != null) { |
| 1412 | return PackageParser.generatePermissionInfo(bp.perm, flags); |
| 1413 | } |
| 1414 | PermissionInfo pi = new PermissionInfo(); |
| 1415 | pi.name = bp.name; |
| 1416 | pi.packageName = bp.sourcePackage; |
| 1417 | pi.nonLocalizedLabel = bp.name; |
| 1418 | pi.protectionLevel = bp.protectionLevel; |
| 1419 | return pi; |
| 1420 | } |
| 1421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1422 | public PermissionInfo getPermissionInfo(String name, int flags) { |
| 1423 | synchronized (mPackages) { |
| 1424 | final BasePermission p = mSettings.mPermissions.get(name); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1425 | if (p != null) { |
| 1426 | return generatePermissionInfo(p, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | } |
| 1428 | return null; |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) { |
| 1433 | synchronized (mPackages) { |
| 1434 | ArrayList<PermissionInfo> out = new ArrayList<PermissionInfo>(10); |
| 1435 | for (BasePermission p : mSettings.mPermissions.values()) { |
| 1436 | if (group == null) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1437 | if (p.perm == null || p.perm.info.group == null) { |
| 1438 | out.add(generatePermissionInfo(p, flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | } |
| 1440 | } else { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1441 | 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] | 1442 | out.add(PackageParser.generatePermissionInfo(p.perm, flags)); |
| 1443 | } |
| 1444 | } |
| 1445 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | if (out.size() > 0) { |
| 1448 | return out; |
| 1449 | } |
| 1450 | return mPermissionGroups.containsKey(group) ? out : null; |
| 1451 | } |
| 1452 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | public PermissionGroupInfo getPermissionGroupInfo(String name, int flags) { |
| 1455 | synchronized (mPackages) { |
| 1456 | return PackageParser.generatePermissionGroupInfo( |
| 1457 | mPermissionGroups.get(name), flags); |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | public List<PermissionGroupInfo> getAllPermissionGroups(int flags) { |
| 1462 | synchronized (mPackages) { |
| 1463 | final int N = mPermissionGroups.size(); |
| 1464 | ArrayList<PermissionGroupInfo> out |
| 1465 | = new ArrayList<PermissionGroupInfo>(N); |
| 1466 | for (PackageParser.PermissionGroup pg : mPermissionGroups.values()) { |
| 1467 | out.add(PackageParser.generatePermissionGroupInfo(pg, flags)); |
| 1468 | } |
| 1469 | return out; |
| 1470 | } |
| 1471 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | private ApplicationInfo generateApplicationInfoFromSettingsLP(String packageName, int flags) { |
| 1474 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 1475 | if(ps != null) { |
| 1476 | if(ps.pkg == null) { |
| 1477 | PackageInfo pInfo = generatePackageInfoFromSettingsLP(packageName, flags); |
| 1478 | if(pInfo != null) { |
| 1479 | return pInfo.applicationInfo; |
| 1480 | } |
| 1481 | return null; |
| 1482 | } |
| 1483 | return PackageParser.generateApplicationInfo(ps.pkg, flags); |
| 1484 | } |
| 1485 | return null; |
| 1486 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | private PackageInfo generatePackageInfoFromSettingsLP(String packageName, int flags) { |
| 1489 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 1490 | if(ps != null) { |
| 1491 | if(ps.pkg == null) { |
| 1492 | ps.pkg = new PackageParser.Package(packageName); |
| 1493 | ps.pkg.applicationInfo.packageName = packageName; |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 1494 | ps.pkg.applicationInfo.flags = ps.pkgFlags; |
| 1495 | ps.pkg.applicationInfo.publicSourceDir = ps.resourcePathString; |
| 1496 | ps.pkg.applicationInfo.sourceDir = ps.codePathString; |
| 1497 | ps.pkg.applicationInfo.dataDir = getDataPathForPackage(ps.pkg).getPath(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | } |
| 1499 | return generatePackageInfo(ps.pkg, flags); |
| 1500 | } |
| 1501 | return null; |
| 1502 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1504 | public ApplicationInfo getApplicationInfo(String packageName, int flags) { |
| 1505 | synchronized (mPackages) { |
| 1506 | PackageParser.Package p = mPackages.get(packageName); |
| 1507 | if (Config.LOGV) Log.v( |
| 1508 | TAG, "getApplicationInfo " + packageName |
| 1509 | + ": " + p); |
| 1510 | if (p != null) { |
| 1511 | // Note: isEnabledLP() does not apply here - always return info |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 1512 | return PackageParser.generateApplicationInfo(p, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1513 | } |
| 1514 | if ("android".equals(packageName)||"system".equals(packageName)) { |
| 1515 | return mAndroidApplication; |
| 1516 | } |
| 1517 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 1518 | return generateApplicationInfoFromSettingsLP(packageName, flags); |
| 1519 | } |
| 1520 | } |
| 1521 | return null; |
| 1522 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1523 | |
| 1524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1525 | public void freeStorageAndNotify(final long freeStorageSize, final IPackageDataObserver observer) { |
| 1526 | mContext.enforceCallingOrSelfPermission( |
| 1527 | android.Manifest.permission.CLEAR_APP_CACHE, null); |
| 1528 | // Queue up an async operation since clearing cache may take a little while. |
| 1529 | mHandler.post(new Runnable() { |
| 1530 | public void run() { |
| 1531 | mHandler.removeCallbacks(this); |
| 1532 | int retCode = -1; |
| 1533 | if (mInstaller != null) { |
| 1534 | retCode = mInstaller.freeCache(freeStorageSize); |
| 1535 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1536 | Slog.w(TAG, "Couldn't clear application caches"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1537 | } |
| 1538 | } //end if mInstaller |
| 1539 | if (observer != null) { |
| 1540 | try { |
| 1541 | observer.onRemoveCompleted(null, (retCode >= 0)); |
| 1542 | } catch (RemoteException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1543 | Slog.w(TAG, "RemoveException when invoking call back"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1544 | } |
| 1545 | } |
| 1546 | } |
| 1547 | }); |
| 1548 | } |
| 1549 | |
Suchi Amalapurapu | bc806f6 | 2009-06-17 15:18:19 -0700 | [diff] [blame] | 1550 | public void freeStorage(final long freeStorageSize, final IntentSender pi) { |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 1551 | mContext.enforceCallingOrSelfPermission( |
| 1552 | android.Manifest.permission.CLEAR_APP_CACHE, null); |
| 1553 | // Queue up an async operation since clearing cache may take a little while. |
| 1554 | mHandler.post(new Runnable() { |
| 1555 | public void run() { |
| 1556 | mHandler.removeCallbacks(this); |
| 1557 | int retCode = -1; |
| 1558 | if (mInstaller != null) { |
| 1559 | retCode = mInstaller.freeCache(freeStorageSize); |
| 1560 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1561 | Slog.w(TAG, "Couldn't clear application caches"); |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 1562 | } |
| 1563 | } |
| 1564 | if(pi != null) { |
| 1565 | try { |
| 1566 | // Callback via pending intent |
| 1567 | int code = (retCode >= 0) ? 1 : 0; |
| 1568 | pi.sendIntent(null, code, null, |
| 1569 | null, null); |
| 1570 | } catch (SendIntentException e1) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1571 | Slog.i(TAG, "Failed to send pending intent"); |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 1572 | } |
| 1573 | } |
| 1574 | } |
| 1575 | }); |
| 1576 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | public ActivityInfo getActivityInfo(ComponentName component, int flags) { |
| 1579 | synchronized (mPackages) { |
| 1580 | PackageParser.Activity a = mActivities.mActivities.get(component); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 1581 | |
| 1582 | if (Config.LOGV) Log.v(TAG, "getActivityInfo " + component + ": " + a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1583 | if (a != null && mSettings.isEnabledLP(a.info, flags)) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1584 | return PackageParser.generateActivityInfo(a, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | } |
| 1586 | if (mResolveComponentName.equals(component)) { |
| 1587 | return mResolveActivity; |
| 1588 | } |
| 1589 | } |
| 1590 | return null; |
| 1591 | } |
| 1592 | |
| 1593 | public ActivityInfo getReceiverInfo(ComponentName component, int flags) { |
| 1594 | synchronized (mPackages) { |
| 1595 | PackageParser.Activity a = mReceivers.mActivities.get(component); |
| 1596 | if (Config.LOGV) Log.v( |
| 1597 | TAG, "getReceiverInfo " + component + ": " + a); |
| 1598 | if (a != null && mSettings.isEnabledLP(a.info, flags)) { |
| 1599 | return PackageParser.generateActivityInfo(a, flags); |
| 1600 | } |
| 1601 | } |
| 1602 | return null; |
| 1603 | } |
| 1604 | |
| 1605 | public ServiceInfo getServiceInfo(ComponentName component, int flags) { |
| 1606 | synchronized (mPackages) { |
| 1607 | PackageParser.Service s = mServices.mServices.get(component); |
| 1608 | if (Config.LOGV) Log.v( |
| 1609 | TAG, "getServiceInfo " + component + ": " + s); |
| 1610 | if (s != null && mSettings.isEnabledLP(s.info, flags)) { |
| 1611 | return PackageParser.generateServiceInfo(s, flags); |
| 1612 | } |
| 1613 | } |
| 1614 | return null; |
| 1615 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1617 | public String[] getSystemSharedLibraryNames() { |
| 1618 | Set<String> libSet; |
| 1619 | synchronized (mPackages) { |
| 1620 | libSet = mSharedLibraries.keySet(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1621 | int size = libSet.size(); |
| 1622 | if (size > 0) { |
| 1623 | String[] libs = new String[size]; |
| 1624 | libSet.toArray(libs); |
| 1625 | return libs; |
| 1626 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | } |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1628 | return null; |
| 1629 | } |
| 1630 | |
| 1631 | public FeatureInfo[] getSystemAvailableFeatures() { |
| 1632 | Collection<FeatureInfo> featSet; |
| 1633 | synchronized (mPackages) { |
| 1634 | featSet = mAvailableFeatures.values(); |
| 1635 | int size = featSet.size(); |
| 1636 | if (size > 0) { |
| 1637 | FeatureInfo[] features = new FeatureInfo[size+1]; |
| 1638 | featSet.toArray(features); |
| 1639 | FeatureInfo fi = new FeatureInfo(); |
| 1640 | fi.reqGlEsVersion = SystemProperties.getInt("ro.opengles.version", |
| 1641 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 1642 | features[size] = fi; |
| 1643 | return features; |
| 1644 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | } |
| 1646 | return null; |
| 1647 | } |
| 1648 | |
Dianne Hackborn | 039c68e | 2009-09-26 16:39:23 -0700 | [diff] [blame] | 1649 | public boolean hasSystemFeature(String name) { |
| 1650 | synchronized (mPackages) { |
| 1651 | return mAvailableFeatures.containsKey(name); |
| 1652 | } |
| 1653 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1654 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | public int checkPermission(String permName, String pkgName) { |
| 1656 | synchronized (mPackages) { |
| 1657 | PackageParser.Package p = mPackages.get(pkgName); |
| 1658 | if (p != null && p.mExtras != null) { |
| 1659 | PackageSetting ps = (PackageSetting)p.mExtras; |
| 1660 | if (ps.sharedUser != null) { |
| 1661 | if (ps.sharedUser.grantedPermissions.contains(permName)) { |
| 1662 | return PackageManager.PERMISSION_GRANTED; |
| 1663 | } |
| 1664 | } else if (ps.grantedPermissions.contains(permName)) { |
| 1665 | return PackageManager.PERMISSION_GRANTED; |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | return PackageManager.PERMISSION_DENIED; |
| 1670 | } |
| 1671 | |
| 1672 | public int checkUidPermission(String permName, int uid) { |
| 1673 | synchronized (mPackages) { |
| 1674 | Object obj = mSettings.getUserIdLP(uid); |
| 1675 | if (obj != null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1676 | GrantedPermissions gp = (GrantedPermissions)obj; |
| 1677 | if (gp.grantedPermissions.contains(permName)) { |
| 1678 | return PackageManager.PERMISSION_GRANTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | } |
| 1680 | } else { |
| 1681 | HashSet<String> perms = mSystemPermissions.get(uid); |
| 1682 | if (perms != null && perms.contains(permName)) { |
| 1683 | return PackageManager.PERMISSION_GRANTED; |
| 1684 | } |
| 1685 | } |
| 1686 | } |
| 1687 | return PackageManager.PERMISSION_DENIED; |
| 1688 | } |
| 1689 | |
| 1690 | private BasePermission findPermissionTreeLP(String permName) { |
| 1691 | for(BasePermission bp : mSettings.mPermissionTrees.values()) { |
| 1692 | if (permName.startsWith(bp.name) && |
| 1693 | permName.length() > bp.name.length() && |
| 1694 | permName.charAt(bp.name.length()) == '.') { |
| 1695 | return bp; |
| 1696 | } |
| 1697 | } |
| 1698 | return null; |
| 1699 | } |
| 1700 | |
| 1701 | private BasePermission checkPermissionTreeLP(String permName) { |
| 1702 | if (permName != null) { |
| 1703 | BasePermission bp = findPermissionTreeLP(permName); |
| 1704 | if (bp != null) { |
| 1705 | if (bp.uid == Binder.getCallingUid()) { |
| 1706 | return bp; |
| 1707 | } |
| 1708 | throw new SecurityException("Calling uid " |
| 1709 | + Binder.getCallingUid() |
| 1710 | + " is not allowed to add to permission tree " |
| 1711 | + bp.name + " owned by uid " + bp.uid); |
| 1712 | } |
| 1713 | } |
| 1714 | throw new SecurityException("No permission tree found for " + permName); |
| 1715 | } |
| 1716 | |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 1717 | static boolean compareStrings(CharSequence s1, CharSequence s2) { |
| 1718 | if (s1 == null) { |
| 1719 | return s2 == null; |
| 1720 | } |
| 1721 | if (s2 == null) { |
| 1722 | return false; |
| 1723 | } |
| 1724 | if (s1.getClass() != s2.getClass()) { |
| 1725 | return false; |
| 1726 | } |
| 1727 | return s1.equals(s2); |
| 1728 | } |
| 1729 | |
| 1730 | static boolean comparePermissionInfos(PermissionInfo pi1, PermissionInfo pi2) { |
| 1731 | if (pi1.icon != pi2.icon) return false; |
Adam Powell | 81cd2e9 | 2010-04-21 16:35:18 -0700 | [diff] [blame] | 1732 | if (pi1.logo != pi2.logo) return false; |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 1733 | if (pi1.protectionLevel != pi2.protectionLevel) return false; |
| 1734 | if (!compareStrings(pi1.name, pi2.name)) return false; |
| 1735 | if (!compareStrings(pi1.nonLocalizedLabel, pi2.nonLocalizedLabel)) return false; |
| 1736 | // We'll take care of setting this one. |
| 1737 | if (!compareStrings(pi1.packageName, pi2.packageName)) return false; |
| 1738 | // These are not currently stored in settings. |
| 1739 | //if (!compareStrings(pi1.group, pi2.group)) return false; |
| 1740 | //if (!compareStrings(pi1.nonLocalizedDescription, pi2.nonLocalizedDescription)) return false; |
| 1741 | //if (pi1.labelRes != pi2.labelRes) return false; |
| 1742 | //if (pi1.descriptionRes != pi2.descriptionRes) return false; |
| 1743 | return true; |
| 1744 | } |
| 1745 | |
| 1746 | boolean addPermissionLocked(PermissionInfo info, boolean async) { |
| 1747 | if (info.labelRes == 0 && info.nonLocalizedLabel == null) { |
| 1748 | throw new SecurityException("Label must be specified in permission"); |
| 1749 | } |
| 1750 | BasePermission tree = checkPermissionTreeLP(info.name); |
| 1751 | BasePermission bp = mSettings.mPermissions.get(info.name); |
| 1752 | boolean added = bp == null; |
| 1753 | boolean changed = true; |
| 1754 | if (added) { |
| 1755 | bp = new BasePermission(info.name, tree.sourcePackage, |
| 1756 | BasePermission.TYPE_DYNAMIC); |
| 1757 | } else if (bp.type != BasePermission.TYPE_DYNAMIC) { |
| 1758 | throw new SecurityException( |
| 1759 | "Not allowed to modify non-dynamic permission " |
| 1760 | + info.name); |
| 1761 | } else { |
| 1762 | if (bp.protectionLevel == info.protectionLevel |
| 1763 | && bp.perm.owner.equals(tree.perm.owner) |
| 1764 | && bp.uid == tree.uid |
| 1765 | && comparePermissionInfos(bp.perm.info, info)) { |
| 1766 | changed = false; |
| 1767 | } |
| 1768 | } |
| 1769 | bp.protectionLevel = info.protectionLevel; |
| 1770 | bp.perm = new PackageParser.Permission(tree.perm.owner, |
| 1771 | new PermissionInfo(info)); |
| 1772 | bp.perm.info.packageName = tree.perm.info.packageName; |
| 1773 | bp.uid = tree.uid; |
| 1774 | if (added) { |
| 1775 | mSettings.mPermissions.put(info.name, bp); |
| 1776 | } |
| 1777 | if (changed) { |
| 1778 | if (!async) { |
| 1779 | mSettings.writeLP(); |
| 1780 | } else { |
| 1781 | scheduleWriteSettingsLocked(); |
| 1782 | } |
| 1783 | } |
| 1784 | return added; |
| 1785 | } |
| 1786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | public boolean addPermission(PermissionInfo info) { |
| 1788 | synchronized (mPackages) { |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 1789 | return addPermissionLocked(info, false); |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | public boolean addPermissionAsync(PermissionInfo info) { |
| 1794 | synchronized (mPackages) { |
| 1795 | return addPermissionLocked(info, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | public void removePermission(String name) { |
| 1800 | synchronized (mPackages) { |
| 1801 | checkPermissionTreeLP(name); |
| 1802 | BasePermission bp = mSettings.mPermissions.get(name); |
| 1803 | if (bp != null) { |
| 1804 | if (bp.type != BasePermission.TYPE_DYNAMIC) { |
| 1805 | throw new SecurityException( |
| 1806 | "Not allowed to modify non-dynamic permission " |
| 1807 | + name); |
| 1808 | } |
| 1809 | mSettings.mPermissions.remove(name); |
| 1810 | mSettings.writeLP(); |
| 1811 | } |
| 1812 | } |
| 1813 | } |
| 1814 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1815 | public boolean isProtectedBroadcast(String actionName) { |
| 1816 | synchronized (mPackages) { |
| 1817 | return mProtectedBroadcasts.contains(actionName); |
| 1818 | } |
| 1819 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1820 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | public int checkSignatures(String pkg1, String pkg2) { |
| 1822 | synchronized (mPackages) { |
| 1823 | PackageParser.Package p1 = mPackages.get(pkg1); |
| 1824 | PackageParser.Package p2 = mPackages.get(pkg2); |
| 1825 | if (p1 == null || p1.mExtras == null |
| 1826 | || p2 == null || p2.mExtras == null) { |
| 1827 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1828 | } |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1829 | return checkSignaturesLP(p1.mSignatures, p2.mSignatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1830 | } |
| 1831 | } |
| 1832 | |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1833 | public int checkUidSignatures(int uid1, int uid2) { |
| 1834 | synchronized (mPackages) { |
| 1835 | Signature[] s1; |
| 1836 | Signature[] s2; |
| 1837 | Object obj = mSettings.getUserIdLP(uid1); |
| 1838 | if (obj != null) { |
| 1839 | if (obj instanceof SharedUserSetting) { |
| 1840 | s1 = ((SharedUserSetting)obj).signatures.mSignatures; |
| 1841 | } else if (obj instanceof PackageSetting) { |
| 1842 | s1 = ((PackageSetting)obj).signatures.mSignatures; |
| 1843 | } else { |
| 1844 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1845 | } |
| 1846 | } else { |
| 1847 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1848 | } |
| 1849 | obj = mSettings.getUserIdLP(uid2); |
| 1850 | if (obj != null) { |
| 1851 | if (obj instanceof SharedUserSetting) { |
| 1852 | s2 = ((SharedUserSetting)obj).signatures.mSignatures; |
| 1853 | } else if (obj instanceof PackageSetting) { |
| 1854 | s2 = ((PackageSetting)obj).signatures.mSignatures; |
| 1855 | } else { |
| 1856 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1857 | } |
| 1858 | } else { |
| 1859 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1860 | } |
| 1861 | return checkSignaturesLP(s1, s2); |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | int checkSignaturesLP(Signature[] s1, Signature[] s2) { |
| 1866 | if (s1 == null) { |
| 1867 | return s2 == null |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1868 | ? PackageManager.SIGNATURE_NEITHER_SIGNED |
| 1869 | : PackageManager.SIGNATURE_FIRST_NOT_SIGNED; |
| 1870 | } |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1871 | if (s2 == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1872 | return PackageManager.SIGNATURE_SECOND_NOT_SIGNED; |
| 1873 | } |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 1874 | HashSet<Signature> set1 = new HashSet<Signature>(); |
| 1875 | for (Signature sig : s1) { |
| 1876 | set1.add(sig); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | } |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 1878 | HashSet<Signature> set2 = new HashSet<Signature>(); |
| 1879 | for (Signature sig : s2) { |
| 1880 | set2.add(sig); |
| 1881 | } |
| 1882 | // Make sure s2 contains all signatures in s1. |
| 1883 | if (set1.equals(set2)) { |
| 1884 | return PackageManager.SIGNATURE_MATCH; |
| 1885 | } |
| 1886 | return PackageManager.SIGNATURE_NO_MATCH; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | public String[] getPackagesForUid(int uid) { |
| 1890 | synchronized (mPackages) { |
| 1891 | Object obj = mSettings.getUserIdLP(uid); |
| 1892 | if (obj instanceof SharedUserSetting) { |
| 1893 | SharedUserSetting sus = (SharedUserSetting)obj; |
| 1894 | final int N = sus.packages.size(); |
| 1895 | String[] res = new String[N]; |
| 1896 | Iterator<PackageSetting> it = sus.packages.iterator(); |
| 1897 | int i=0; |
| 1898 | while (it.hasNext()) { |
| 1899 | res[i++] = it.next().name; |
| 1900 | } |
| 1901 | return res; |
| 1902 | } else if (obj instanceof PackageSetting) { |
| 1903 | PackageSetting ps = (PackageSetting)obj; |
| 1904 | return new String[] { ps.name }; |
| 1905 | } |
| 1906 | } |
| 1907 | return null; |
| 1908 | } |
| 1909 | |
| 1910 | public String getNameForUid(int uid) { |
| 1911 | synchronized (mPackages) { |
| 1912 | Object obj = mSettings.getUserIdLP(uid); |
| 1913 | if (obj instanceof SharedUserSetting) { |
| 1914 | SharedUserSetting sus = (SharedUserSetting)obj; |
| 1915 | return sus.name + ":" + sus.userId; |
| 1916 | } else if (obj instanceof PackageSetting) { |
| 1917 | PackageSetting ps = (PackageSetting)obj; |
| 1918 | return ps.name; |
| 1919 | } |
| 1920 | } |
| 1921 | return null; |
| 1922 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | public int getUidForSharedUser(String sharedUserName) { |
| 1925 | if(sharedUserName == null) { |
| 1926 | return -1; |
| 1927 | } |
| 1928 | synchronized (mPackages) { |
| 1929 | SharedUserSetting suid = mSettings.getSharedUserLP(sharedUserName, 0, false); |
| 1930 | if(suid == null) { |
| 1931 | return -1; |
| 1932 | } |
| 1933 | return suid.userId; |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | public ResolveInfo resolveIntent(Intent intent, String resolvedType, |
| 1938 | int flags) { |
| 1939 | List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags); |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 1940 | return chooseBestActivity(intent, resolvedType, flags, query); |
| 1941 | } |
| 1942 | |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 1943 | private ResolveInfo chooseBestActivity(Intent intent, String resolvedType, |
| 1944 | int flags, List<ResolveInfo> query) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1945 | if (query != null) { |
| 1946 | final int N = query.size(); |
| 1947 | if (N == 1) { |
| 1948 | return query.get(0); |
| 1949 | } else if (N > 1) { |
| 1950 | // If there is more than one activity with the same priority, |
| 1951 | // then let the user decide between them. |
| 1952 | ResolveInfo r0 = query.get(0); |
| 1953 | ResolveInfo r1 = query.get(1); |
| 1954 | if (false) { |
| 1955 | System.out.println(r0.activityInfo.name + |
| 1956 | "=" + r0.priority + " vs " + |
| 1957 | r1.activityInfo.name + |
| 1958 | "=" + r1.priority); |
| 1959 | } |
| 1960 | // If the first activity has a higher priority, or a different |
| 1961 | // default, then it is always desireable to pick it. |
| 1962 | if (r0.priority != r1.priority |
| 1963 | || r0.preferredOrder != r1.preferredOrder |
| 1964 | || r0.isDefault != r1.isDefault) { |
| 1965 | return query.get(0); |
| 1966 | } |
| 1967 | // If we have saved a preference for a preferred activity for |
| 1968 | // this Intent, use that. |
| 1969 | ResolveInfo ri = findPreferredActivity(intent, resolvedType, |
| 1970 | flags, query, r0.priority); |
| 1971 | if (ri != null) { |
| 1972 | return ri; |
| 1973 | } |
| 1974 | return mResolveInfo; |
| 1975 | } |
| 1976 | } |
| 1977 | return null; |
| 1978 | } |
| 1979 | |
| 1980 | ResolveInfo findPreferredActivity(Intent intent, String resolvedType, |
| 1981 | int flags, List<ResolveInfo> query, int priority) { |
| 1982 | synchronized (mPackages) { |
| 1983 | if (DEBUG_PREFERRED) intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION); |
| 1984 | List<PreferredActivity> prefs = |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 1985 | mSettings.mPreferredActivities.queryIntent(intent, resolvedType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 1987 | if (prefs != null && prefs.size() > 0) { |
| 1988 | // First figure out how good the original match set is. |
| 1989 | // We will only allow preferred activities that came |
| 1990 | // from the same match quality. |
| 1991 | int match = 0; |
| 1992 | final int N = query.size(); |
| 1993 | if (DEBUG_PREFERRED) Log.v(TAG, "Figuring out best match..."); |
| 1994 | for (int j=0; j<N; j++) { |
| 1995 | ResolveInfo ri = query.get(j); |
| 1996 | if (DEBUG_PREFERRED) Log.v(TAG, "Match for " + ri.activityInfo |
| 1997 | + ": 0x" + Integer.toHexString(match)); |
| 1998 | if (ri.match > match) match = ri.match; |
| 1999 | } |
| 2000 | if (DEBUG_PREFERRED) Log.v(TAG, "Best match: 0x" |
| 2001 | + Integer.toHexString(match)); |
| 2002 | match &= IntentFilter.MATCH_CATEGORY_MASK; |
| 2003 | final int M = prefs.size(); |
| 2004 | for (int i=0; i<M; i++) { |
| 2005 | PreferredActivity pa = prefs.get(i); |
| 2006 | if (pa.mMatch != match) { |
| 2007 | continue; |
| 2008 | } |
| 2009 | ActivityInfo ai = getActivityInfo(pa.mActivity, flags); |
| 2010 | if (DEBUG_PREFERRED) { |
| 2011 | Log.v(TAG, "Got preferred activity:"); |
| 2012 | ai.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 2013 | } |
| 2014 | if (ai != null) { |
| 2015 | for (int j=0; j<N; j++) { |
| 2016 | ResolveInfo ri = query.get(j); |
| 2017 | if (!ri.activityInfo.applicationInfo.packageName |
| 2018 | .equals(ai.applicationInfo.packageName)) { |
| 2019 | continue; |
| 2020 | } |
| 2021 | if (!ri.activityInfo.name.equals(ai.name)) { |
| 2022 | continue; |
| 2023 | } |
| 2024 | |
| 2025 | // Okay we found a previously set preferred app. |
| 2026 | // If the result set is different from when this |
| 2027 | // was created, we need to clear it and re-ask the |
| 2028 | // user their preference. |
| 2029 | if (!pa.sameSet(query, priority)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2030 | 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] | 2031 | + intent + " type " + resolvedType); |
| 2032 | mSettings.mPreferredActivities.removeFilter(pa); |
| 2033 | return null; |
| 2034 | } |
| 2035 | |
| 2036 | // Yay! |
| 2037 | return ri; |
| 2038 | } |
| 2039 | } |
| 2040 | } |
| 2041 | } |
| 2042 | } |
| 2043 | return null; |
| 2044 | } |
| 2045 | |
| 2046 | public List<ResolveInfo> queryIntentActivities(Intent intent, |
| 2047 | String resolvedType, int flags) { |
| 2048 | ComponentName comp = intent.getComponent(); |
| 2049 | if (comp != null) { |
| 2050 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2051 | ActivityInfo ai = getActivityInfo(comp, flags); |
| 2052 | if (ai != null) { |
| 2053 | ResolveInfo ri = new ResolveInfo(); |
| 2054 | ri.activityInfo = ai; |
| 2055 | list.add(ri); |
| 2056 | } |
| 2057 | return list; |
| 2058 | } |
| 2059 | |
| 2060 | synchronized (mPackages) { |
Dianne Hackborn | c14b9cc | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2061 | String pkgName = intent.getPackage(); |
| 2062 | if (pkgName == null) { |
| 2063 | return (List<ResolveInfo>)mActivities.queryIntent(intent, |
| 2064 | resolvedType, flags); |
| 2065 | } |
| 2066 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2067 | if (pkg != null) { |
| 2068 | return (List<ResolveInfo>) mActivities.queryIntentForPackage(intent, |
| 2069 | resolvedType, flags, pkg.activities); |
| 2070 | } |
| 2071 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, |
| 2076 | Intent[] specifics, String[] specificTypes, Intent intent, |
| 2077 | String resolvedType, int flags) { |
| 2078 | final String resultsAction = intent.getAction(); |
| 2079 | |
| 2080 | List<ResolveInfo> results = queryIntentActivities( |
| 2081 | intent, resolvedType, flags|PackageManager.GET_RESOLVED_FILTER); |
| 2082 | if (Config.LOGV) Log.v(TAG, "Query " + intent + ": " + results); |
| 2083 | |
| 2084 | int specificsPos = 0; |
| 2085 | int N; |
| 2086 | |
| 2087 | // todo: note that the algorithm used here is O(N^2). This |
| 2088 | // isn't a problem in our current environment, but if we start running |
| 2089 | // into situations where we have more than 5 or 10 matches then this |
| 2090 | // should probably be changed to something smarter... |
| 2091 | |
| 2092 | // First we go through and resolve each of the specific items |
| 2093 | // that were supplied, taking care of removing any corresponding |
| 2094 | // duplicate items in the generic resolve list. |
| 2095 | if (specifics != null) { |
| 2096 | for (int i=0; i<specifics.length; i++) { |
| 2097 | final Intent sintent = specifics[i]; |
| 2098 | if (sintent == null) { |
| 2099 | continue; |
| 2100 | } |
| 2101 | |
| 2102 | if (Config.LOGV) Log.v(TAG, "Specific #" + i + ": " + sintent); |
| 2103 | String action = sintent.getAction(); |
| 2104 | if (resultsAction != null && resultsAction.equals(action)) { |
| 2105 | // If this action was explicitly requested, then don't |
| 2106 | // remove things that have it. |
| 2107 | action = null; |
| 2108 | } |
| 2109 | ComponentName comp = sintent.getComponent(); |
| 2110 | ResolveInfo ri = null; |
| 2111 | ActivityInfo ai = null; |
| 2112 | if (comp == null) { |
| 2113 | ri = resolveIntent( |
| 2114 | sintent, |
| 2115 | specificTypes != null ? specificTypes[i] : null, |
| 2116 | flags); |
| 2117 | if (ri == null) { |
| 2118 | continue; |
| 2119 | } |
| 2120 | if (ri == mResolveInfo) { |
| 2121 | // ACK! Must do something better with this. |
| 2122 | } |
| 2123 | ai = ri.activityInfo; |
| 2124 | comp = new ComponentName(ai.applicationInfo.packageName, |
| 2125 | ai.name); |
| 2126 | } else { |
| 2127 | ai = getActivityInfo(comp, flags); |
| 2128 | if (ai == null) { |
| 2129 | continue; |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | // Look for any generic query activities that are duplicates |
| 2134 | // of this specific one, and remove them from the results. |
| 2135 | if (Config.LOGV) Log.v(TAG, "Specific #" + i + ": " + ai); |
| 2136 | N = results.size(); |
| 2137 | int j; |
| 2138 | for (j=specificsPos; j<N; j++) { |
| 2139 | ResolveInfo sri = results.get(j); |
| 2140 | if ((sri.activityInfo.name.equals(comp.getClassName()) |
| 2141 | && sri.activityInfo.applicationInfo.packageName.equals( |
| 2142 | comp.getPackageName())) |
| 2143 | || (action != null && sri.filter.matchAction(action))) { |
| 2144 | results.remove(j); |
| 2145 | if (Config.LOGV) Log.v( |
| 2146 | TAG, "Removing duplicate item from " + j |
| 2147 | + " due to specific " + specificsPos); |
| 2148 | if (ri == null) { |
| 2149 | ri = sri; |
| 2150 | } |
| 2151 | j--; |
| 2152 | N--; |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | // Add this specific item to its proper place. |
| 2157 | if (ri == null) { |
| 2158 | ri = new ResolveInfo(); |
| 2159 | ri.activityInfo = ai; |
| 2160 | } |
| 2161 | results.add(specificsPos, ri); |
| 2162 | ri.specificIndex = i; |
| 2163 | specificsPos++; |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | // Now we go through the remaining generic results and remove any |
| 2168 | // duplicate actions that are found here. |
| 2169 | N = results.size(); |
| 2170 | for (int i=specificsPos; i<N-1; i++) { |
| 2171 | final ResolveInfo rii = results.get(i); |
| 2172 | if (rii.filter == null) { |
| 2173 | continue; |
| 2174 | } |
| 2175 | |
| 2176 | // Iterate over all of the actions of this result's intent |
| 2177 | // filter... typically this should be just one. |
| 2178 | final Iterator<String> it = rii.filter.actionsIterator(); |
| 2179 | if (it == null) { |
| 2180 | continue; |
| 2181 | } |
| 2182 | while (it.hasNext()) { |
| 2183 | final String action = it.next(); |
| 2184 | if (resultsAction != null && resultsAction.equals(action)) { |
| 2185 | // If this action was explicitly requested, then don't |
| 2186 | // remove things that have it. |
| 2187 | continue; |
| 2188 | } |
| 2189 | for (int j=i+1; j<N; j++) { |
| 2190 | final ResolveInfo rij = results.get(j); |
| 2191 | if (rij.filter != null && rij.filter.hasAction(action)) { |
| 2192 | results.remove(j); |
| 2193 | if (Config.LOGV) Log.v( |
| 2194 | TAG, "Removing duplicate item from " + j |
| 2195 | + " due to action " + action + " at " + i); |
| 2196 | j--; |
| 2197 | N--; |
| 2198 | } |
| 2199 | } |
| 2200 | } |
| 2201 | |
| 2202 | // If the caller didn't request filter information, drop it now |
| 2203 | // so we don't have to marshall/unmarshall it. |
| 2204 | if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) { |
| 2205 | rii.filter = null; |
| 2206 | } |
| 2207 | } |
| 2208 | |
| 2209 | // Filter out the caller activity if so requested. |
| 2210 | if (caller != null) { |
| 2211 | N = results.size(); |
| 2212 | for (int i=0; i<N; i++) { |
| 2213 | ActivityInfo ainfo = results.get(i).activityInfo; |
| 2214 | if (caller.getPackageName().equals(ainfo.applicationInfo.packageName) |
| 2215 | && caller.getClassName().equals(ainfo.name)) { |
| 2216 | results.remove(i); |
| 2217 | break; |
| 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | // If the caller didn't request filter information, |
| 2223 | // drop them now so we don't have to |
| 2224 | // marshall/unmarshall it. |
| 2225 | if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) { |
| 2226 | N = results.size(); |
| 2227 | for (int i=0; i<N; i++) { |
| 2228 | results.get(i).filter = null; |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | if (Config.LOGV) Log.v(TAG, "Result: " + results); |
| 2233 | return results; |
| 2234 | } |
| 2235 | |
| 2236 | public List<ResolveInfo> queryIntentReceivers(Intent intent, |
| 2237 | String resolvedType, int flags) { |
Dianne Hackborn | c14b9cc | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2238 | ComponentName comp = intent.getComponent(); |
| 2239 | if (comp != null) { |
| 2240 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2241 | ActivityInfo ai = getReceiverInfo(comp, flags); |
| 2242 | if (ai != null) { |
| 2243 | ResolveInfo ri = new ResolveInfo(); |
| 2244 | ri.activityInfo = ai; |
| 2245 | list.add(ri); |
| 2246 | } |
| 2247 | return list; |
| 2248 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2250 | synchronized (mPackages) { |
Dianne Hackborn | c14b9cc | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2251 | String pkgName = intent.getPackage(); |
| 2252 | if (pkgName == null) { |
| 2253 | return (List<ResolveInfo>)mReceivers.queryIntent(intent, |
| 2254 | resolvedType, flags); |
| 2255 | } |
| 2256 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2257 | if (pkg != null) { |
| 2258 | return (List<ResolveInfo>) mReceivers.queryIntentForPackage(intent, |
| 2259 | resolvedType, flags, pkg.receivers); |
| 2260 | } |
| 2261 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | } |
| 2263 | } |
| 2264 | |
| 2265 | public ResolveInfo resolveService(Intent intent, String resolvedType, |
| 2266 | int flags) { |
| 2267 | List<ResolveInfo> query = queryIntentServices(intent, resolvedType, |
| 2268 | flags); |
| 2269 | if (query != null) { |
| 2270 | if (query.size() >= 1) { |
| 2271 | // If there is more than one service with the same priority, |
| 2272 | // just arbitrarily pick the first one. |
| 2273 | return query.get(0); |
| 2274 | } |
| 2275 | } |
| 2276 | return null; |
| 2277 | } |
| 2278 | |
| 2279 | public List<ResolveInfo> queryIntentServices(Intent intent, |
| 2280 | String resolvedType, int flags) { |
| 2281 | ComponentName comp = intent.getComponent(); |
| 2282 | if (comp != null) { |
| 2283 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2284 | ServiceInfo si = getServiceInfo(comp, flags); |
| 2285 | if (si != null) { |
| 2286 | ResolveInfo ri = new ResolveInfo(); |
| 2287 | ri.serviceInfo = si; |
| 2288 | list.add(ri); |
| 2289 | } |
| 2290 | return list; |
| 2291 | } |
| 2292 | |
| 2293 | synchronized (mPackages) { |
Dianne Hackborn | c14b9cc | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2294 | String pkgName = intent.getPackage(); |
| 2295 | if (pkgName == null) { |
| 2296 | return (List<ResolveInfo>)mServices.queryIntent(intent, |
| 2297 | resolvedType, flags); |
| 2298 | } |
| 2299 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2300 | if (pkg != null) { |
| 2301 | return (List<ResolveInfo>)mServices.queryIntentForPackage(intent, |
| 2302 | resolvedType, flags, pkg.services); |
| 2303 | } |
| 2304 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2305 | } |
| 2306 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2308 | public List<PackageInfo> getInstalledPackages(int flags) { |
| 2309 | ArrayList<PackageInfo> finalList = new ArrayList<PackageInfo>(); |
| 2310 | |
| 2311 | synchronized (mPackages) { |
| 2312 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 2313 | Iterator<PackageSetting> i = mSettings.mPackages.values().iterator(); |
| 2314 | while (i.hasNext()) { |
| 2315 | final PackageSetting ps = i.next(); |
| 2316 | PackageInfo psPkg = generatePackageInfoFromSettingsLP(ps.name, flags); |
| 2317 | if(psPkg != null) { |
| 2318 | finalList.add(psPkg); |
| 2319 | } |
| 2320 | } |
| 2321 | } |
| 2322 | else { |
| 2323 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2324 | while (i.hasNext()) { |
| 2325 | final PackageParser.Package p = i.next(); |
| 2326 | if (p.applicationInfo != null) { |
| 2327 | PackageInfo pi = generatePackageInfo(p, flags); |
| 2328 | if(pi != null) { |
| 2329 | finalList.add(pi); |
| 2330 | } |
| 2331 | } |
| 2332 | } |
| 2333 | } |
| 2334 | } |
| 2335 | return finalList; |
| 2336 | } |
| 2337 | |
| 2338 | public List<ApplicationInfo> getInstalledApplications(int flags) { |
| 2339 | ArrayList<ApplicationInfo> finalList = new ArrayList<ApplicationInfo>(); |
| 2340 | synchronized(mPackages) { |
| 2341 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 2342 | Iterator<PackageSetting> i = mSettings.mPackages.values().iterator(); |
| 2343 | while (i.hasNext()) { |
| 2344 | final PackageSetting ps = i.next(); |
| 2345 | ApplicationInfo ai = generateApplicationInfoFromSettingsLP(ps.name, flags); |
| 2346 | if(ai != null) { |
| 2347 | finalList.add(ai); |
| 2348 | } |
| 2349 | } |
| 2350 | } |
| 2351 | else { |
| 2352 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2353 | while (i.hasNext()) { |
| 2354 | final PackageParser.Package p = i.next(); |
| 2355 | if (p.applicationInfo != null) { |
| 2356 | ApplicationInfo ai = PackageParser.generateApplicationInfo(p, flags); |
| 2357 | if(ai != null) { |
| 2358 | finalList.add(ai); |
| 2359 | } |
| 2360 | } |
| 2361 | } |
| 2362 | } |
| 2363 | } |
| 2364 | return finalList; |
| 2365 | } |
| 2366 | |
| 2367 | public List<ApplicationInfo> getPersistentApplications(int flags) { |
| 2368 | ArrayList<ApplicationInfo> finalList = new ArrayList<ApplicationInfo>(); |
| 2369 | |
| 2370 | synchronized (mPackages) { |
| 2371 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2372 | while (i.hasNext()) { |
| 2373 | PackageParser.Package p = i.next(); |
| 2374 | if (p.applicationInfo != null |
| 2375 | && (p.applicationInfo.flags&ApplicationInfo.FLAG_PERSISTENT) != 0 |
| 2376 | && (!mSafeMode || (p.applicationInfo.flags |
| 2377 | &ApplicationInfo.FLAG_SYSTEM) != 0)) { |
Jey | 2eebf5c | 2009-11-18 18:37:31 -0800 | [diff] [blame] | 2378 | finalList.add(PackageParser.generateApplicationInfo(p, flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2379 | } |
| 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | return finalList; |
| 2384 | } |
| 2385 | |
| 2386 | public ProviderInfo resolveContentProvider(String name, int flags) { |
| 2387 | synchronized (mPackages) { |
| 2388 | final PackageParser.Provider provider = mProviders.get(name); |
| 2389 | return provider != null |
| 2390 | && mSettings.isEnabledLP(provider.info, flags) |
| 2391 | && (!mSafeMode || (provider.info.applicationInfo.flags |
| 2392 | &ApplicationInfo.FLAG_SYSTEM) != 0) |
| 2393 | ? PackageParser.generateProviderInfo(provider, flags) |
| 2394 | : null; |
| 2395 | } |
| 2396 | } |
| 2397 | |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2398 | /** |
| 2399 | * @deprecated |
| 2400 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2401 | public void querySyncProviders(List outNames, List outInfo) { |
| 2402 | synchronized (mPackages) { |
| 2403 | Iterator<Map.Entry<String, PackageParser.Provider>> i |
| 2404 | = mProviders.entrySet().iterator(); |
| 2405 | |
| 2406 | while (i.hasNext()) { |
| 2407 | Map.Entry<String, PackageParser.Provider> entry = i.next(); |
| 2408 | PackageParser.Provider p = entry.getValue(); |
| 2409 | |
| 2410 | if (p.syncable |
| 2411 | && (!mSafeMode || (p.info.applicationInfo.flags |
| 2412 | &ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| 2413 | outNames.add(entry.getKey()); |
| 2414 | outInfo.add(PackageParser.generateProviderInfo(p, 0)); |
| 2415 | } |
| 2416 | } |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | public List<ProviderInfo> queryContentProviders(String processName, |
| 2421 | int uid, int flags) { |
| 2422 | ArrayList<ProviderInfo> finalList = null; |
| 2423 | |
| 2424 | synchronized (mPackages) { |
| 2425 | Iterator<PackageParser.Provider> i = mProvidersByComponent.values().iterator(); |
| 2426 | while (i.hasNext()) { |
| 2427 | PackageParser.Provider p = i.next(); |
| 2428 | if (p.info.authority != null |
| 2429 | && (processName == null || |
| 2430 | (p.info.processName.equals(processName) |
| 2431 | && p.info.applicationInfo.uid == uid)) |
| 2432 | && mSettings.isEnabledLP(p.info, flags) |
| 2433 | && (!mSafeMode || (p.info.applicationInfo.flags |
| 2434 | &ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| 2435 | if (finalList == null) { |
| 2436 | finalList = new ArrayList<ProviderInfo>(3); |
| 2437 | } |
| 2438 | finalList.add(PackageParser.generateProviderInfo(p, |
| 2439 | flags)); |
| 2440 | } |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | if (finalList != null) { |
| 2445 | Collections.sort(finalList, mProviderInitOrderSorter); |
| 2446 | } |
| 2447 | |
| 2448 | return finalList; |
| 2449 | } |
| 2450 | |
| 2451 | public InstrumentationInfo getInstrumentationInfo(ComponentName name, |
| 2452 | int flags) { |
| 2453 | synchronized (mPackages) { |
| 2454 | final PackageParser.Instrumentation i = mInstrumentation.get(name); |
| 2455 | return PackageParser.generateInstrumentationInfo(i, flags); |
| 2456 | } |
| 2457 | } |
| 2458 | |
| 2459 | public List<InstrumentationInfo> queryInstrumentation(String targetPackage, |
| 2460 | int flags) { |
| 2461 | ArrayList<InstrumentationInfo> finalList = |
| 2462 | new ArrayList<InstrumentationInfo>(); |
| 2463 | |
| 2464 | synchronized (mPackages) { |
| 2465 | Iterator<PackageParser.Instrumentation> i = mInstrumentation.values().iterator(); |
| 2466 | while (i.hasNext()) { |
| 2467 | PackageParser.Instrumentation p = i.next(); |
| 2468 | if (targetPackage == null |
| 2469 | || targetPackage.equals(p.info.targetPackage)) { |
| 2470 | finalList.add(PackageParser.generateInstrumentationInfo(p, |
| 2471 | flags)); |
| 2472 | } |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | return finalList; |
| 2477 | } |
| 2478 | |
| 2479 | private void scanDirLI(File dir, int flags, int scanMode) { |
| 2480 | Log.d(TAG, "Scanning app dir " + dir); |
| 2481 | |
| 2482 | String[] files = dir.list(); |
| 2483 | |
| 2484 | int i; |
| 2485 | for (i=0; i<files.length; i++) { |
| 2486 | File file = new File(dir, files[i]); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 2487 | if (!isPackageFilename(files[i])) { |
| 2488 | // Ignore entries which are not apk's |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 2489 | continue; |
| 2490 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2491 | PackageParser.Package pkg = scanPackageLI(file, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | flags|PackageParser.PARSE_MUST_BE_APK, scanMode); |
Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2493 | // Don't mess around with apps in system partition. |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 2494 | if (pkg == null && (flags & PackageParser.PARSE_IS_SYSTEM) == 0 && |
| 2495 | mLastScanError == PackageManager.INSTALL_FAILED_INVALID_APK) { |
Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2496 | // Delete the apk |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2497 | Slog.w(TAG, "Cleaning up failed install of " + file); |
Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2498 | file.delete(); |
| 2499 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2500 | } |
| 2501 | } |
| 2502 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2503 | private static File getSettingsProblemFile() { |
| 2504 | File dataDir = Environment.getDataDirectory(); |
| 2505 | File systemDir = new File(dataDir, "system"); |
| 2506 | File fname = new File(systemDir, "uiderrors.txt"); |
| 2507 | return fname; |
| 2508 | } |
| 2509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2510 | private static void reportSettingsProblem(int priority, String msg) { |
| 2511 | try { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2512 | File fname = getSettingsProblemFile(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2513 | FileOutputStream out = new FileOutputStream(fname, true); |
| 2514 | PrintWriter pw = new PrintWriter(out); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2515 | SimpleDateFormat formatter = new SimpleDateFormat(); |
| 2516 | String dateString = formatter.format(new Date(System.currentTimeMillis())); |
| 2517 | pw.println(dateString + ": " + msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2518 | pw.close(); |
| 2519 | FileUtils.setPermissions( |
| 2520 | fname.toString(), |
| 2521 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IROTH, |
| 2522 | -1, -1); |
| 2523 | } catch (java.io.IOException e) { |
| 2524 | } |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2525 | Slog.println(priority, TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | private boolean collectCertificatesLI(PackageParser pp, PackageSetting ps, |
| 2529 | PackageParser.Package pkg, File srcFile, int parseFlags) { |
| 2530 | if (GET_CERTIFICATES) { |
Jeff Brown | e760072 | 2010-04-07 18:28:23 -0700 | [diff] [blame] | 2531 | if (ps != null |
| 2532 | && ps.codePath.equals(srcFile) |
| 2533 | && ps.getTimeStamp() == srcFile.lastModified()) { |
| 2534 | if (ps.signatures.mSignatures != null |
| 2535 | && ps.signatures.mSignatures.length != 0) { |
| 2536 | // Optimization: reuse the existing cached certificates |
| 2537 | // if the package appears to be unchanged. |
| 2538 | pkg.mSignatures = ps.signatures.mSignatures; |
| 2539 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | } |
Jeff Brown | e760072 | 2010-04-07 18:28:23 -0700 | [diff] [blame] | 2541 | |
| 2542 | 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] | 2543 | } else { |
Jeff Brown | e760072 | 2010-04-07 18:28:23 -0700 | [diff] [blame] | 2544 | Log.i(TAG, srcFile.toString() + " changed; collecting certs"); |
| 2545 | } |
| 2546 | |
| 2547 | if (!pp.collectCertificates(pkg, parseFlags)) { |
| 2548 | mLastScanError = pp.getParseError(); |
| 2549 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | } |
| 2551 | } |
| 2552 | return true; |
| 2553 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2555 | /* |
| 2556 | * Scan a package and return the newly parsed package. |
| 2557 | * Returns null in case of errors and the error code is stored in mLastScanError |
| 2558 | */ |
| 2559 | private PackageParser.Package scanPackageLI(File scanFile, |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2560 | int parseFlags, int scanMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2561 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2562 | String scanPath = scanFile.getPath(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2563 | parseFlags |= mDefParseFlags; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2564 | PackageParser pp = new PackageParser(scanPath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2565 | pp.setSeparateProcesses(mSeparateProcesses); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2566 | final PackageParser.Package pkg = pp.parsePackage(scanFile, |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2567 | scanPath, mMetrics, parseFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2568 | if (pkg == null) { |
| 2569 | mLastScanError = pp.getParseError(); |
| 2570 | return null; |
| 2571 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2572 | PackageSetting ps = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | PackageSetting updatedPkg; |
| 2574 | synchronized (mPackages) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2575 | // Look to see if we already know about this package. |
| 2576 | String oldName = mSettings.mRenamedPackages.get(pkg.packageName); |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2577 | if (pkg.mOriginalPackages != null && pkg.mOriginalPackages.contains(oldName)) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2578 | // This package has been renamed to its original name. Let's |
| 2579 | // use that. |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2580 | ps = mSettings.peekPackageLP(oldName); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2581 | } |
| 2582 | // If there was no original package, see one for the real package name. |
| 2583 | if (ps == null) { |
| 2584 | ps = mSettings.peekPackageLP(pkg.packageName); |
| 2585 | } |
| 2586 | // Check to see if this package could be hiding/updating a system |
| 2587 | // package. Must look for it either under the original or real |
| 2588 | // package name depending on our state. |
| 2589 | updatedPkg = mSettings.mDisabledSysPackages.get( |
| 2590 | ps != null ? ps.name : pkg.packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2592 | // First check if this is a system package that may involve an update |
| 2593 | if (updatedPkg != null && (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| 2594 | if (!ps.codePath.equals(scanFile)) { |
| 2595 | // The path has changed from what was last scanned... check the |
| 2596 | // version of the new path against what we have stored to determine |
| 2597 | // what to do. |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2598 | if (pkg.mVersionCode < ps.versionCode) { |
| 2599 | // 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] | 2600 | // Ignore entry. Skip it. |
| 2601 | Log.i(TAG, "Package " + ps.name + " at " + scanFile |
| 2602 | + "ignored: updated version " + ps.versionCode |
| 2603 | + " better than this " + pkg.mVersionCode); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2604 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2605 | return null; |
| 2606 | } else { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2607 | // The current app on the system partion is better than |
| 2608 | // what we have updated to on the data partition; switch |
| 2609 | // back to the system partition version. |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2610 | // At this point, its safely assumed that package installation for |
| 2611 | // apps in system partition will go through. If not there won't be a working |
| 2612 | // version of the app |
| 2613 | synchronized (mPackages) { |
| 2614 | // Just remove the loaded entries from package lists. |
| 2615 | mPackages.remove(ps.name); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 2616 | } |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2617 | Slog.w(TAG, "Package " + ps.name + " at " + scanFile |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2618 | + "reverting from " + ps.codePathString |
| 2619 | + ": new version " + pkg.mVersionCode |
| 2620 | + " better than installed " + ps.versionCode); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2621 | InstallArgs args = new FileInstallArgs(ps.codePathString, ps.resourcePathString); |
| 2622 | args.cleanUpResourcesLI(); |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 2623 | removeNativeBinariesLI(pkg); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2624 | mSettings.enableSystemPackageLP(ps.name); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 2625 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2626 | } |
| 2627 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2628 | if (updatedPkg != null) { |
| 2629 | // An updated system app will not have the PARSE_IS_SYSTEM flag set initially |
| 2630 | parseFlags |= PackageParser.PARSE_IS_SYSTEM; |
| 2631 | } |
| 2632 | // Verify certificates against what was last scanned |
| 2633 | if (!collectCertificatesLI(pp, ps, pkg, scanFile, parseFlags)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2634 | Slog.w(TAG, "Failed verifying certificates for package:" + pkg.packageName); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2635 | return null; |
| 2636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2637 | // The apk is forward locked (not public) if its code and resources |
| 2638 | // are kept in different files. |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2639 | // TODO grab this value from PackageSettings |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | if (ps != null && !ps.codePath.equals(ps.resourcePath)) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2641 | parseFlags |= PackageParser.PARSE_FORWARD_LOCK; |
Suchi Amalapurapu | f2c1072 | 2009-07-29 17:19:39 -0700 | [diff] [blame] | 2642 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2643 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2644 | String codePath = null; |
| 2645 | String resPath = null; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2646 | if ((parseFlags & PackageParser.PARSE_FORWARD_LOCK) != 0) { |
| 2647 | if (ps != null && ps.resourcePathString != null) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2648 | resPath = ps.resourcePathString; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2649 | } else { |
| 2650 | // Should not happen at all. Just log an error. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2651 | Slog.e(TAG, "Resource path not set for pkg : " + pkg.packageName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2652 | } |
| 2653 | } else { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2654 | resPath = pkg.mScanPath; |
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 | codePath = pkg.mScanPath; |
| 2657 | // Set application objects path explicitly. |
| 2658 | setApplicationInfoPaths(pkg, codePath, resPath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | // 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] | 2660 | return scanPackageLI(pkg, parseFlags, scanMode | SCAN_UPDATE_SIGNATURE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | } |
| 2662 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2663 | private static void setApplicationInfoPaths(PackageParser.Package pkg, |
| 2664 | String destCodePath, String destResPath) { |
| 2665 | pkg.mPath = pkg.mScanPath = destCodePath; |
| 2666 | pkg.applicationInfo.sourceDir = destCodePath; |
| 2667 | pkg.applicationInfo.publicSourceDir = destResPath; |
| 2668 | } |
| 2669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2670 | private static String fixProcessName(String defProcessName, |
| 2671 | String processName, int uid) { |
| 2672 | if (processName == null) { |
| 2673 | return defProcessName; |
| 2674 | } |
| 2675 | return processName; |
| 2676 | } |
| 2677 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2678 | private boolean verifySignaturesLP(PackageSetting pkgSetting, |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 2679 | PackageParser.Package pkg) { |
| 2680 | if (pkgSetting.signatures.mSignatures != null) { |
| 2681 | // Already existing package. Make sure signatures match |
| 2682 | if (checkSignaturesLP(pkgSetting.signatures.mSignatures, pkg.mSignatures) != |
| 2683 | PackageManager.SIGNATURE_MATCH) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2684 | Slog.e(TAG, "Package " + pkg.packageName |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 2685 | + " signatures do not match the previously installed version; ignoring!"); |
| 2686 | mLastScanError = PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2687 | return false; |
| 2688 | } |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 2689 | } |
| 2690 | // Check for shared user signatures |
| 2691 | if (pkgSetting.sharedUser != null && pkgSetting.sharedUser.signatures.mSignatures != null) { |
| 2692 | if (checkSignaturesLP(pkgSetting.sharedUser.signatures.mSignatures, |
| 2693 | pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) { |
| 2694 | Slog.e(TAG, "Package " + pkg.packageName |
| 2695 | + " has no signatures that match those in shared user " |
| 2696 | + pkgSetting.sharedUser.name + "; ignoring!"); |
| 2697 | mLastScanError = PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE; |
| 2698 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2699 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | } |
| 2701 | return true; |
| 2702 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2703 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2704 | public boolean performDexOpt(String packageName) { |
| 2705 | if (!mNoDexOpt) { |
| 2706 | return false; |
| 2707 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2708 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2709 | PackageParser.Package p; |
| 2710 | synchronized (mPackages) { |
| 2711 | p = mPackages.get(packageName); |
| 2712 | if (p == null || p.mDidDexOpt) { |
| 2713 | return false; |
| 2714 | } |
| 2715 | } |
| 2716 | synchronized (mInstallLock) { |
| 2717 | return performDexOptLI(p, false) == DEX_OPT_PERFORMED; |
| 2718 | } |
| 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 | static final int DEX_OPT_SKIPPED = 0; |
| 2722 | static final int DEX_OPT_PERFORMED = 1; |
| 2723 | static final int DEX_OPT_FAILED = -1; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2724 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2725 | private int performDexOptLI(PackageParser.Package pkg, boolean forceDex) { |
| 2726 | boolean performed = false; |
Marco Nelissen | d595c79 | 2009-07-02 15:23:26 -0700 | [diff] [blame] | 2727 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0 && mInstaller != null) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2728 | String path = pkg.mScanPath; |
| 2729 | int ret = 0; |
| 2730 | try { |
| 2731 | if (forceDex || dalvik.system.DexFile.isDexOptNeeded(path)) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2732 | ret = mInstaller.dexopt(path, pkg.applicationInfo.uid, |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2733 | !isForwardLocked(pkg)); |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2734 | pkg.mDidDexOpt = true; |
| 2735 | performed = true; |
| 2736 | } |
| 2737 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2738 | Slog.w(TAG, "Apk not found for dexopt: " + path); |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2739 | ret = -1; |
| 2740 | } catch (IOException e) { |
Suchi Amalapurapu | 73dafa1 | 2010-04-01 16:31:31 -0700 | [diff] [blame] | 2741 | Slog.w(TAG, "IOException reading apk: " + path, e); |
| 2742 | ret = -1; |
| 2743 | } catch (dalvik.system.StaleDexCacheError e) { |
| 2744 | Slog.w(TAG, "StaleDexCacheError when reading apk: " + path, e); |
| 2745 | ret = -1; |
| 2746 | } catch (Exception e) { |
| 2747 | Slog.w(TAG, "Exception when doing dexopt : ", e); |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2748 | ret = -1; |
| 2749 | } |
| 2750 | if (ret < 0) { |
| 2751 | //error from installer |
| 2752 | return DEX_OPT_FAILED; |
| 2753 | } |
| 2754 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2755 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2756 | return performed ? DEX_OPT_PERFORMED : DEX_OPT_SKIPPED; |
| 2757 | } |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 2758 | |
| 2759 | private static boolean useEncryptedFilesystemForPackage(PackageParser.Package pkg) { |
| 2760 | return Environment.isEncryptedFilesystemEnabled() && |
| 2761 | ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_NEVER_ENCRYPT) == 0); |
| 2762 | } |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2763 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2764 | private boolean verifyPackageUpdate(PackageSetting oldPkg, PackageParser.Package newPkg) { |
| 2765 | if ((oldPkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2766 | Slog.w(TAG, "Unable to update from " + oldPkg.name |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2767 | + " to " + newPkg.packageName |
| 2768 | + ": old package not in system partition"); |
| 2769 | return false; |
| 2770 | } else if (mPackages.get(oldPkg.name) != null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2771 | Slog.w(TAG, "Unable to update from " + oldPkg.name |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2772 | + " to " + newPkg.packageName |
| 2773 | + ": old package still exists"); |
| 2774 | return false; |
| 2775 | } |
| 2776 | return true; |
| 2777 | } |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 2778 | |
| 2779 | private File getDataPathForPackage(PackageParser.Package pkg) { |
| 2780 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(pkg); |
| 2781 | File dataPath; |
| 2782 | if (useEncryptedFSDir) { |
| 2783 | dataPath = new File(mSecureAppDataDir, pkg.packageName); |
| 2784 | } else { |
| 2785 | dataPath = new File(mAppDataDir, pkg.packageName); |
| 2786 | } |
| 2787 | return dataPath; |
| 2788 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2789 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2790 | private PackageParser.Package scanPackageLI(PackageParser.Package pkg, |
| 2791 | int parseFlags, int scanMode) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2792 | File scanFile = new File(pkg.mScanPath); |
Suchi Amalapurapu | 7040ce7 | 2010-02-08 23:55:56 -0800 | [diff] [blame] | 2793 | if (scanFile == null || pkg.applicationInfo.sourceDir == null || |
| 2794 | pkg.applicationInfo.publicSourceDir == null) { |
Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2795 | // Bail out. The resource and code paths haven't been set. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2796 | Slog.w(TAG, " Code and resource paths haven't been set correctly"); |
Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2797 | mLastScanError = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 2798 | return null; |
| 2799 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | mScanningPath = scanFile; |
| 2801 | if (pkg == null) { |
| 2802 | mLastScanError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 2803 | return null; |
| 2804 | } |
| 2805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| 2807 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM; |
| 2808 | } |
| 2809 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2810 | if (pkg.packageName.equals("android")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | synchronized (mPackages) { |
| 2812 | if (mAndroidApplication != null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2813 | Slog.w(TAG, "*************************************************"); |
| 2814 | Slog.w(TAG, "Core android package being redefined. Skipping."); |
| 2815 | Slog.w(TAG, " file=" + mScanningPath); |
| 2816 | Slog.w(TAG, "*************************************************"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2817 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2818 | return null; |
| 2819 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2820 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2821 | // Set up information for our fall-back user intent resolution |
| 2822 | // activity. |
| 2823 | mPlatformPackage = pkg; |
| 2824 | pkg.mVersionCode = mSdkVersion; |
| 2825 | mAndroidApplication = pkg.applicationInfo; |
| 2826 | mResolveActivity.applicationInfo = mAndroidApplication; |
| 2827 | mResolveActivity.name = ResolverActivity.class.getName(); |
| 2828 | mResolveActivity.packageName = mAndroidApplication.packageName; |
| 2829 | mResolveActivity.processName = mAndroidApplication.processName; |
| 2830 | mResolveActivity.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 2831 | mResolveActivity.flags = ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 2832 | mResolveActivity.theme = com.android.internal.R.style.Theme_Dialog_Alert; |
| 2833 | mResolveActivity.exported = true; |
| 2834 | mResolveActivity.enabled = true; |
| 2835 | mResolveInfo.activityInfo = mResolveActivity; |
| 2836 | mResolveInfo.priority = 0; |
| 2837 | mResolveInfo.preferredOrder = 0; |
| 2838 | mResolveInfo.match = 0; |
| 2839 | mResolveComponentName = new ComponentName( |
| 2840 | mAndroidApplication.packageName, mResolveActivity.name); |
| 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) Log.d( |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2845 | TAG, "Scanning package " + pkg.packageName); |
| 2846 | if (mPackages.containsKey(pkg.packageName) |
| 2847 | || mSharedLibraries.containsKey(pkg.packageName)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2848 | Slog.w(TAG, "*************************************************"); |
| 2849 | Slog.w(TAG, "Application package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | + " already installed. Skipping duplicate."); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2851 | Slog.w(TAG, "*************************************************"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2853 | return null; |
| 2854 | } |
| 2855 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2856 | // Initialize package source and resource directories |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2857 | File destCodeFile = new File(pkg.applicationInfo.sourceDir); |
| 2858 | File destResourceFile = new File(pkg.applicationInfo.publicSourceDir); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2859 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | SharedUserSetting suid = null; |
| 2861 | PackageSetting pkgSetting = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2862 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2863 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 2864 | // Only system apps can use these features. |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2865 | pkg.mOriginalPackages = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2866 | pkg.mRealPackage = null; |
| 2867 | pkg.mAdoptPermissions = null; |
| 2868 | } |
| 2869 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | synchronized (mPackages) { |
| 2871 | // Check all shared libraries and map to their actual file path. |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2872 | if (pkg.usesLibraries != null || pkg.usesOptionalLibraries != null) { |
| 2873 | if (mTmpSharedLibraries == null || |
| 2874 | mTmpSharedLibraries.length < mSharedLibraries.size()) { |
| 2875 | mTmpSharedLibraries = new String[mSharedLibraries.size()]; |
| 2876 | } |
| 2877 | int num = 0; |
| 2878 | int N = pkg.usesLibraries != null ? pkg.usesLibraries.size() : 0; |
| 2879 | for (int i=0; i<N; i++) { |
| 2880 | String file = mSharedLibraries.get(pkg.usesLibraries.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | if (file == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2882 | Slog.e(TAG, "Package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | + " requires unavailable shared library " |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2884 | + pkg.usesLibraries.get(i) + "; failing!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2885 | mLastScanError = PackageManager.INSTALL_FAILED_MISSING_SHARED_LIBRARY; |
| 2886 | return null; |
| 2887 | } |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2888 | mTmpSharedLibraries[num] = file; |
| 2889 | num++; |
| 2890 | } |
| 2891 | N = pkg.usesOptionalLibraries != null ? pkg.usesOptionalLibraries.size() : 0; |
| 2892 | for (int i=0; i<N; i++) { |
| 2893 | String file = mSharedLibraries.get(pkg.usesOptionalLibraries.get(i)); |
| 2894 | if (file == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2895 | Slog.w(TAG, "Package " + pkg.packageName |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2896 | + " desires unavailable shared library " |
| 2897 | + pkg.usesOptionalLibraries.get(i) + "; ignoring!"); |
| 2898 | } else { |
| 2899 | mTmpSharedLibraries[num] = file; |
| 2900 | num++; |
| 2901 | } |
| 2902 | } |
| 2903 | if (num > 0) { |
| 2904 | pkg.usesLibraryFiles = new String[num]; |
| 2905 | System.arraycopy(mTmpSharedLibraries, 0, |
| 2906 | pkg.usesLibraryFiles, 0, num); |
| 2907 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2908 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2909 | if (pkg.reqFeatures != null) { |
| 2910 | N = pkg.reqFeatures.size(); |
| 2911 | for (int i=0; i<N; i++) { |
| 2912 | FeatureInfo fi = pkg.reqFeatures.get(i); |
| 2913 | if ((fi.flags&FeatureInfo.FLAG_REQUIRED) == 0) { |
| 2914 | // Don't care. |
| 2915 | continue; |
| 2916 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2917 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2918 | if (fi.name != null) { |
| 2919 | if (mAvailableFeatures.get(fi.name) == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2920 | Slog.e(TAG, "Package " + pkg.packageName |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2921 | + " requires unavailable feature " |
| 2922 | + fi.name + "; failing!"); |
| 2923 | mLastScanError = PackageManager.INSTALL_FAILED_MISSING_FEATURE; |
| 2924 | return null; |
| 2925 | } |
| 2926 | } |
| 2927 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2928 | } |
| 2929 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2931 | if (pkg.mSharedUserId != null) { |
| 2932 | suid = mSettings.getSharedUserLP(pkg.mSharedUserId, |
| 2933 | pkg.applicationInfo.flags, true); |
| 2934 | if (suid == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2935 | Slog.w(TAG, "Creating application package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2936 | + " for shared user failed"); |
| 2937 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 2938 | return null; |
| 2939 | } |
| 2940 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) { |
| 2941 | Log.d(TAG, "Shared UserID " + pkg.mSharedUserId + " (uid=" |
| 2942 | + suid.userId + "): packages=" + suid.packages); |
| 2943 | } |
| 2944 | } |
Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 2945 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2946 | if (false) { |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2947 | if (pkg.mOriginalPackages != null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2948 | Log.w(TAG, "WAITING FOR DEBUGGER"); |
| 2949 | Debug.waitForDebugger(); |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2950 | Log.i(TAG, "Package " + pkg.packageName + " from original packages" |
| 2951 | + pkg.mOriginalPackages); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2952 | } |
| 2953 | } |
| 2954 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2955 | // Check if we are renaming from an original package name. |
| 2956 | PackageSetting origPackage = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2957 | String realName = null; |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2958 | if (pkg.mOriginalPackages != null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2959 | // This package may need to be renamed to a previously |
| 2960 | // installed name. Let's check on that... |
| 2961 | String renamed = mSettings.mRenamedPackages.get(pkg.mRealPackage); |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2962 | if (pkg.mOriginalPackages.contains(renamed)) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2963 | // This package had originally been installed as the |
| 2964 | // original name, and we have already taken care of |
| 2965 | // transitioning to the new one. Just update the new |
| 2966 | // one to continue using the old name. |
| 2967 | realName = pkg.mRealPackage; |
| 2968 | if (!pkg.packageName.equals(renamed)) { |
| 2969 | // Callers into this function may have already taken |
| 2970 | // care of renaming the package; only do it here if |
| 2971 | // it is not already done. |
| 2972 | pkg.setPackageName(renamed); |
| 2973 | } |
| 2974 | |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2975 | } else { |
| 2976 | for (int i=pkg.mOriginalPackages.size()-1; i>=0; i--) { |
| 2977 | if ((origPackage=mSettings.peekPackageLP( |
| 2978 | pkg.mOriginalPackages.get(i))) != null) { |
| 2979 | // We do have the package already installed under its |
| 2980 | // original name... should we use it? |
| 2981 | if (!verifyPackageUpdate(origPackage, pkg)) { |
| 2982 | // New package is not compatible with original. |
| 2983 | origPackage = null; |
| 2984 | continue; |
| 2985 | } else if (origPackage.sharedUser != null) { |
| 2986 | // Make sure uid is compatible between packages. |
| 2987 | if (!origPackage.sharedUser.name.equals(pkg.mSharedUserId)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2988 | Slog.w(TAG, "Unable to migrate data from " + origPackage.name |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2989 | + " to " + pkg.packageName + ": old uid " |
| 2990 | + origPackage.sharedUser.name |
| 2991 | + " differs from " + pkg.mSharedUserId); |
| 2992 | origPackage = null; |
| 2993 | continue; |
| 2994 | } |
| 2995 | } else { |
| 2996 | if (DEBUG_UPGRADE) Log.v(TAG, "Renaming new package " |
| 2997 | + pkg.packageName + " to old name " + origPackage.name); |
| 2998 | } |
| 2999 | break; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3000 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3001 | } |
| 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | if (mTransferedPackages.contains(pkg.packageName)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3006 | Slog.w(TAG, "Package " + pkg.packageName |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3007 | + " was transferred to another, but its .apk remains"); |
| 3008 | } |
| 3009 | |
Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 3010 | // Just create the setting, don't add it yet. For already existing packages |
| 3011 | // the PkgSetting exists already and doesn't have to be created. |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3012 | pkgSetting = mSettings.getPackageLP(pkg, origPackage, realName, suid, destCodeFile, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3013 | destResourceFile, pkg.applicationInfo.flags, true, false); |
| 3014 | if (pkgSetting == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3015 | Slog.w(TAG, "Creating application package " + pkg.packageName + " failed"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3016 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3017 | return null; |
| 3018 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3019 | |
| 3020 | if (pkgSetting.origPackage != null) { |
| 3021 | // If we are first transitioning from an original package, |
| 3022 | // fix up the new package's name now. We need to do this after |
| 3023 | // looking up the package under its new name, so getPackageLP |
| 3024 | // can take care of fiddling things correctly. |
| 3025 | pkg.setPackageName(origPackage.name); |
| 3026 | |
| 3027 | // File a report about this. |
| 3028 | String msg = "New package " + pkgSetting.realName |
| 3029 | + " renamed to replace old package " + pkgSetting.name; |
| 3030 | reportSettingsProblem(Log.WARN, msg); |
| 3031 | |
| 3032 | // Make a note of it. |
| 3033 | mTransferedPackages.add(origPackage.name); |
| 3034 | |
| 3035 | // No longer need to retain this. |
| 3036 | pkgSetting.origPackage = null; |
| 3037 | } |
| 3038 | |
| 3039 | if (realName != null) { |
| 3040 | // Make a note of it. |
| 3041 | mTransferedPackages.add(pkg.packageName); |
| 3042 | } |
| 3043 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3044 | if (mSettings.mDisabledSysPackages.get(pkg.packageName) != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3045 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 3046 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3048 | pkg.applicationInfo.uid = pkgSetting.userId; |
| 3049 | pkg.mExtras = pkgSetting; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3050 | |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 3051 | if (!verifySignaturesLP(pkgSetting, pkg)) { |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 3052 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM_DIR) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3053 | return null; |
| 3054 | } |
| 3055 | // The signature has changed, but this package is in the system |
| 3056 | // image... let's recover! |
Suchi Amalapurapu | c4dd60f | 2009-03-24 21:10:53 -0700 | [diff] [blame] | 3057 | pkgSetting.signatures.mSignatures = pkg.mSignatures; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3058 | // However... if this package is part of a shared user, but it |
| 3059 | // doesn't match the signature of the shared user, let's fail. |
| 3060 | // What this means is that you can't change the signatures |
| 3061 | // associated with an overall shared user, which doesn't seem all |
| 3062 | // that unreasonable. |
| 3063 | if (pkgSetting.sharedUser != null) { |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 3064 | if (checkSignaturesLP(pkgSetting.sharedUser.signatures.mSignatures, |
| 3065 | pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) { |
| 3066 | 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] | 3067 | mLastScanError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 3068 | return null; |
| 3069 | } |
| 3070 | } |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 3071 | // File a report about this. |
| 3072 | String msg = "System package " + pkg.packageName |
| 3073 | + " signature changed; retaining data."; |
| 3074 | reportSettingsProblem(Log.WARN, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3076 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3077 | // Verify that this new package doesn't have any content providers |
| 3078 | // that conflict with existing packages. Only do this if the |
| 3079 | // package isn't already installed, since we don't want to break |
| 3080 | // things that are installed. |
| 3081 | if ((scanMode&SCAN_NEW_INSTALL) != 0) { |
| 3082 | int N = pkg.providers.size(); |
| 3083 | int i; |
| 3084 | for (i=0; i<N; i++) { |
| 3085 | PackageParser.Provider p = pkg.providers.get(i); |
Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3086 | if (p.info.authority != null) { |
| 3087 | String names[] = p.info.authority.split(";"); |
| 3088 | for (int j = 0; j < names.length; j++) { |
| 3089 | if (mProviders.containsKey(names[j])) { |
| 3090 | PackageParser.Provider other = mProviders.get(names[j]); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3091 | Slog.w(TAG, "Can't install because provider name " + names[j] + |
Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3092 | " (in package " + pkg.applicationInfo.packageName + |
| 3093 | ") is already used by " |
| 3094 | + ((other != null && other.getComponentName() != null) |
| 3095 | ? other.getComponentName().getPackageName() : "?")); |
| 3096 | mLastScanError = PackageManager.INSTALL_FAILED_CONFLICTING_PROVIDER; |
| 3097 | return null; |
| 3098 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | } |
| 3102 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3103 | } |
| 3104 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3105 | final String pkgName = pkg.packageName; |
| 3106 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3107 | if (pkg.mAdoptPermissions != null) { |
| 3108 | // This package wants to adopt ownership of permissions from |
| 3109 | // another package. |
| 3110 | for (int i=pkg.mAdoptPermissions.size()-1; i>=0; i--) { |
| 3111 | String origName = pkg.mAdoptPermissions.get(i); |
| 3112 | PackageSetting orig = mSettings.peekPackageLP(origName); |
| 3113 | if (orig != null) { |
| 3114 | if (verifyPackageUpdate(orig, pkg)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3115 | Slog.i(TAG, "Adopting permissions from " |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3116 | + origName + " to " + pkg.packageName); |
| 3117 | mSettings.transferPermissions(origName, pkg.packageName); |
| 3118 | } |
| 3119 | } |
| 3120 | } |
| 3121 | } |
| 3122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3123 | long scanFileTime = scanFile.lastModified(); |
| 3124 | final boolean forceDex = (scanMode&SCAN_FORCE_DEX) != 0; |
| 3125 | final boolean scanFileNewer = forceDex || scanFileTime != pkgSetting.getTimeStamp(); |
| 3126 | pkg.applicationInfo.processName = fixProcessName( |
| 3127 | pkg.applicationInfo.packageName, |
| 3128 | pkg.applicationInfo.processName, |
| 3129 | pkg.applicationInfo.uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | |
| 3131 | File dataPath; |
| 3132 | if (mPlatformPackage == pkg) { |
| 3133 | // The system package is special. |
| 3134 | dataPath = new File (Environment.getDataDirectory(), "system"); |
| 3135 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3136 | } else { |
| 3137 | // This is a normal package, need to make its data directory. |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3138 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(pkg); |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 3139 | dataPath = getDataPathForPackage(pkg); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3140 | |
| 3141 | boolean uidError = false; |
| 3142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | if (dataPath.exists()) { |
| 3144 | mOutPermissions[1] = 0; |
| 3145 | FileUtils.getPermissions(dataPath.getPath(), mOutPermissions); |
| 3146 | if (mOutPermissions[1] == pkg.applicationInfo.uid |
| 3147 | || !Process.supportsProcesses()) { |
| 3148 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3149 | } else { |
| 3150 | boolean recovered = false; |
| 3151 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| 3152 | // If this is a system app, we can at least delete its |
| 3153 | // current data so the application will still work. |
| 3154 | if (mInstaller != null) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3155 | int ret = mInstaller.remove(pkgName, useEncryptedFSDir); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3156 | if (ret >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3157 | // Old data gone! |
| 3158 | String msg = "System package " + pkg.packageName |
| 3159 | + " has changed from uid: " |
| 3160 | + mOutPermissions[1] + " to " |
| 3161 | + pkg.applicationInfo.uid + "; old data erased"; |
| 3162 | reportSettingsProblem(Log.WARN, msg); |
| 3163 | recovered = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | // And now re-install the app. |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3166 | ret = mInstaller.install(pkgName, useEncryptedFSDir, pkg.applicationInfo.uid, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | pkg.applicationInfo.uid); |
| 3168 | if (ret == -1) { |
| 3169 | // Ack should not happen! |
| 3170 | msg = "System package " + pkg.packageName |
| 3171 | + " could not have data directory re-created after delete."; |
| 3172 | reportSettingsProblem(Log.WARN, msg); |
| 3173 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3174 | return null; |
| 3175 | } |
| 3176 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3177 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3178 | if (!recovered) { |
| 3179 | mHasSystemUidErrors = true; |
| 3180 | } |
| 3181 | } |
| 3182 | if (!recovered) { |
| 3183 | pkg.applicationInfo.dataDir = "/mismatched_uid/settings_" |
| 3184 | + pkg.applicationInfo.uid + "/fs_" |
| 3185 | + mOutPermissions[1]; |
| 3186 | String msg = "Package " + pkg.packageName |
| 3187 | + " has mismatched uid: " |
| 3188 | + mOutPermissions[1] + " on disk, " |
| 3189 | + pkg.applicationInfo.uid + " in settings"; |
| 3190 | synchronized (mPackages) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3191 | mSettings.mReadMessages.append(msg); |
| 3192 | mSettings.mReadMessages.append('\n'); |
| 3193 | uidError = true; |
| 3194 | if (!pkgSetting.uidError) { |
| 3195 | reportSettingsProblem(Log.ERROR, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3197 | } |
| 3198 | } |
| 3199 | } |
| 3200 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3201 | } else { |
| 3202 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGV) |
| 3203 | Log.v(TAG, "Want this data dir: " + dataPath); |
| 3204 | //invoke installer to do the actual installation |
| 3205 | if (mInstaller != null) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3206 | int ret = mInstaller.install(pkgName, useEncryptedFSDir, pkg.applicationInfo.uid, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | pkg.applicationInfo.uid); |
| 3208 | if(ret < 0) { |
| 3209 | // Error from installer |
| 3210 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3211 | return null; |
| 3212 | } |
| 3213 | } else { |
| 3214 | dataPath.mkdirs(); |
| 3215 | if (dataPath.exists()) { |
| 3216 | FileUtils.setPermissions( |
| 3217 | dataPath.toString(), |
| 3218 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 3219 | pkg.applicationInfo.uid, pkg.applicationInfo.uid); |
| 3220 | } |
| 3221 | } |
| 3222 | if (dataPath.exists()) { |
| 3223 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3224 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3225 | Slog.w(TAG, "Unable to create data directory: " + dataPath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3226 | pkg.applicationInfo.dataDir = null; |
| 3227 | } |
| 3228 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3229 | |
| 3230 | pkgSetting.uidError = uidError; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | // Perform shared library installation and dex validation and |
| 3234 | // optimization, if this is not a system app. |
| 3235 | if (mInstaller != null) { |
| 3236 | String path = scanFile.getPath(); |
| 3237 | if (scanFileNewer) { |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3238 | // Note: We don't want to unpack the native binaries for |
| 3239 | // system applications, unless they have been updated |
| 3240 | // (the binaries are already under /system/lib). |
| 3241 | // |
| 3242 | // In other words, we're going to unpack the binaries |
| 3243 | // only for non-system apps and system app upgrades. |
| 3244 | // |
| 3245 | int flags = pkg.applicationInfo.flags; |
| 3246 | if ((flags & ApplicationInfo.FLAG_SYSTEM) == 0 || |
| 3247 | (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 3248 | Log.i(TAG, path + " changed; unpacking"); |
| 3249 | int err = cachePackageSharedLibsLI(pkg, scanFile); |
| 3250 | if (err != PackageManager.INSTALL_SUCCEEDED) { |
| 3251 | mLastScanError = err; |
| 3252 | return null; |
| 3253 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | } |
| 3255 | } |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 3256 | pkg.mScanPath = path; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3257 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 3258 | if ((scanMode&SCAN_NO_DEX) == 0) { |
| 3259 | if (performDexOptLI(pkg, forceDex) == DEX_OPT_FAILED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3260 | mLastScanError = PackageManager.INSTALL_FAILED_DEXOPT; |
| 3261 | return null; |
| 3262 | } |
| 3263 | } |
| 3264 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3266 | if (mFactoryTest && pkg.requestedPermissions.contains( |
| 3267 | android.Manifest.permission.FACTORY_TEST)) { |
| 3268 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FACTORY_TEST; |
| 3269 | } |
| 3270 | |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3271 | // Request the ActivityManager to kill the process(only for existing packages) |
| 3272 | // so that we do not end up in a confused state while the user is still using the older |
| 3273 | // version of the application while the new one gets installed. |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3274 | if ((parseFlags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3275 | killApplication(pkg.applicationInfo.packageName, |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3276 | pkg.applicationInfo.uid); |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3277 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3279 | synchronized (mPackages) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 3280 | // We don't expect installation to fail beyond this point, |
| 3281 | if ((scanMode&SCAN_MONITOR) != 0) { |
| 3282 | mAppDirs.put(pkg.mPath, pkg); |
| 3283 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3284 | // Add the new setting to mSettings |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 3285 | mSettings.insertPackageSettingLP(pkgSetting, pkg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3286 | // Add the new setting to mPackages |
Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 3287 | mPackages.put(pkg.applicationInfo.packageName, pkg); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 3288 | // Make sure we don't accidentally delete its data. |
| 3289 | mSettings.mPackagesToBeCleaned.remove(pkgName); |
| 3290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3291 | int N = pkg.providers.size(); |
| 3292 | StringBuilder r = null; |
| 3293 | int i; |
| 3294 | for (i=0; i<N; i++) { |
| 3295 | PackageParser.Provider p = pkg.providers.get(i); |
| 3296 | p.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3297 | p.info.processName, pkg.applicationInfo.uid); |
| 3298 | mProvidersByComponent.put(new ComponentName(p.info.packageName, |
| 3299 | p.info.name), p); |
| 3300 | p.syncable = p.info.isSyncable; |
Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3301 | if (p.info.authority != null) { |
| 3302 | String names[] = p.info.authority.split(";"); |
| 3303 | p.info.authority = null; |
| 3304 | for (int j = 0; j < names.length; j++) { |
| 3305 | if (j == 1 && p.syncable) { |
| 3306 | // We only want the first authority for a provider to possibly be |
| 3307 | // syncable, so if we already added this provider using a different |
| 3308 | // authority clear the syncable flag. We copy the provider before |
| 3309 | // changing it because the mProviders object contains a reference |
| 3310 | // to a provider that we don't want to change. |
| 3311 | // Only do this for the second authority since the resulting provider |
| 3312 | // object can be the same for all future authorities for this provider. |
| 3313 | p = new PackageParser.Provider(p); |
| 3314 | p.syncable = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3315 | } |
Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3316 | if (!mProviders.containsKey(names[j])) { |
| 3317 | mProviders.put(names[j], p); |
| 3318 | if (p.info.authority == null) { |
| 3319 | p.info.authority = names[j]; |
| 3320 | } else { |
| 3321 | p.info.authority = p.info.authority + ";" + names[j]; |
| 3322 | } |
| 3323 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) |
| 3324 | Log.d(TAG, "Registered content provider: " + names[j] + |
| 3325 | ", className = " + p.info.name + |
| 3326 | ", isSyncable = " + p.info.isSyncable); |
| 3327 | } else { |
| 3328 | PackageParser.Provider other = mProviders.get(names[j]); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3329 | Slog.w(TAG, "Skipping provider name " + names[j] + |
Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3330 | " (in package " + pkg.applicationInfo.packageName + |
| 3331 | "): name already used by " |
| 3332 | + ((other != null && other.getComponentName() != null) |
| 3333 | ? other.getComponentName().getPackageName() : "?")); |
| 3334 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | } |
| 3336 | } |
| 3337 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3338 | if (r == null) { |
| 3339 | r = new StringBuilder(256); |
| 3340 | } else { |
| 3341 | r.append(' '); |
| 3342 | } |
| 3343 | r.append(p.info.name); |
| 3344 | } |
| 3345 | } |
| 3346 | if (r != null) { |
| 3347 | if (Config.LOGD) Log.d(TAG, " Providers: " + r); |
| 3348 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3350 | N = pkg.services.size(); |
| 3351 | r = null; |
| 3352 | for (i=0; i<N; i++) { |
| 3353 | PackageParser.Service s = pkg.services.get(i); |
| 3354 | s.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3355 | s.info.processName, pkg.applicationInfo.uid); |
| 3356 | mServices.addService(s); |
| 3357 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3358 | if (r == null) { |
| 3359 | r = new StringBuilder(256); |
| 3360 | } else { |
| 3361 | r.append(' '); |
| 3362 | } |
| 3363 | r.append(s.info.name); |
| 3364 | } |
| 3365 | } |
| 3366 | if (r != null) { |
| 3367 | if (Config.LOGD) Log.d(TAG, " Services: " + r); |
| 3368 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | N = pkg.receivers.size(); |
| 3371 | r = null; |
| 3372 | for (i=0; i<N; i++) { |
| 3373 | PackageParser.Activity a = pkg.receivers.get(i); |
| 3374 | a.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3375 | a.info.processName, pkg.applicationInfo.uid); |
| 3376 | mReceivers.addActivity(a, "receiver"); |
| 3377 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3378 | if (r == null) { |
| 3379 | r = new StringBuilder(256); |
| 3380 | } else { |
| 3381 | r.append(' '); |
| 3382 | } |
| 3383 | r.append(a.info.name); |
| 3384 | } |
| 3385 | } |
| 3386 | if (r != null) { |
| 3387 | if (Config.LOGD) Log.d(TAG, " Receivers: " + r); |
| 3388 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3389 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | N = pkg.activities.size(); |
| 3391 | r = null; |
| 3392 | for (i=0; i<N; i++) { |
| 3393 | PackageParser.Activity a = pkg.activities.get(i); |
| 3394 | a.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3395 | a.info.processName, pkg.applicationInfo.uid); |
| 3396 | mActivities.addActivity(a, "activity"); |
| 3397 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3398 | if (r == null) { |
| 3399 | r = new StringBuilder(256); |
| 3400 | } else { |
| 3401 | r.append(' '); |
| 3402 | } |
| 3403 | r.append(a.info.name); |
| 3404 | } |
| 3405 | } |
| 3406 | if (r != null) { |
| 3407 | if (Config.LOGD) Log.d(TAG, " Activities: " + r); |
| 3408 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | N = pkg.permissionGroups.size(); |
| 3411 | r = null; |
| 3412 | for (i=0; i<N; i++) { |
| 3413 | PackageParser.PermissionGroup pg = pkg.permissionGroups.get(i); |
| 3414 | PackageParser.PermissionGroup cur = mPermissionGroups.get(pg.info.name); |
| 3415 | if (cur == null) { |
| 3416 | mPermissionGroups.put(pg.info.name, pg); |
| 3417 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3418 | if (r == null) { |
| 3419 | r = new StringBuilder(256); |
| 3420 | } else { |
| 3421 | r.append(' '); |
| 3422 | } |
| 3423 | r.append(pg.info.name); |
| 3424 | } |
| 3425 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3426 | 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] | 3427 | + pg.info.packageName + " ignored: original from " |
| 3428 | + cur.info.packageName); |
| 3429 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3430 | if (r == null) { |
| 3431 | r = new StringBuilder(256); |
| 3432 | } else { |
| 3433 | r.append(' '); |
| 3434 | } |
| 3435 | r.append("DUP:"); |
| 3436 | r.append(pg.info.name); |
| 3437 | } |
| 3438 | } |
| 3439 | } |
| 3440 | if (r != null) { |
| 3441 | if (Config.LOGD) Log.d(TAG, " Permission Groups: " + r); |
| 3442 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3444 | N = pkg.permissions.size(); |
| 3445 | r = null; |
| 3446 | for (i=0; i<N; i++) { |
| 3447 | PackageParser.Permission p = pkg.permissions.get(i); |
| 3448 | HashMap<String, BasePermission> permissionMap = |
| 3449 | p.tree ? mSettings.mPermissionTrees |
| 3450 | : mSettings.mPermissions; |
| 3451 | p.group = mPermissionGroups.get(p.info.group); |
| 3452 | if (p.info.group == null || p.group != null) { |
| 3453 | BasePermission bp = permissionMap.get(p.info.name); |
| 3454 | if (bp == null) { |
| 3455 | bp = new BasePermission(p.info.name, p.info.packageName, |
| 3456 | BasePermission.TYPE_NORMAL); |
| 3457 | permissionMap.put(p.info.name, bp); |
| 3458 | } |
| 3459 | if (bp.perm == null) { |
| 3460 | if (bp.sourcePackage == null |
| 3461 | || bp.sourcePackage.equals(p.info.packageName)) { |
| 3462 | BasePermission tree = findPermissionTreeLP(p.info.name); |
| 3463 | if (tree == null |
| 3464 | || tree.sourcePackage.equals(p.info.packageName)) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3465 | bp.packageSetting = pkgSetting; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3466 | bp.perm = p; |
| 3467 | bp.uid = pkg.applicationInfo.uid; |
| 3468 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3469 | if (r == null) { |
| 3470 | r = new StringBuilder(256); |
| 3471 | } else { |
| 3472 | r.append(' '); |
| 3473 | } |
| 3474 | r.append(p.info.name); |
| 3475 | } |
| 3476 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3477 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3478 | + p.info.packageName + " ignored: base tree " |
| 3479 | + tree.name + " is from package " |
| 3480 | + tree.sourcePackage); |
| 3481 | } |
| 3482 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3483 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3484 | + p.info.packageName + " ignored: original from " |
| 3485 | + bp.sourcePackage); |
| 3486 | } |
| 3487 | } else if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3488 | if (r == null) { |
| 3489 | r = new StringBuilder(256); |
| 3490 | } else { |
| 3491 | r.append(' '); |
| 3492 | } |
| 3493 | r.append("DUP:"); |
| 3494 | r.append(p.info.name); |
| 3495 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3496 | if (bp.perm == p) { |
| 3497 | bp.protectionLevel = p.info.protectionLevel; |
| 3498 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3499 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3500 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | + p.info.packageName + " ignored: no group " |
| 3502 | + p.group); |
| 3503 | } |
| 3504 | } |
| 3505 | if (r != null) { |
| 3506 | if (Config.LOGD) Log.d(TAG, " Permissions: " + r); |
| 3507 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3509 | N = pkg.instrumentation.size(); |
| 3510 | r = null; |
| 3511 | for (i=0; i<N; i++) { |
| 3512 | PackageParser.Instrumentation a = pkg.instrumentation.get(i); |
| 3513 | a.info.packageName = pkg.applicationInfo.packageName; |
| 3514 | a.info.sourceDir = pkg.applicationInfo.sourceDir; |
| 3515 | a.info.publicSourceDir = pkg.applicationInfo.publicSourceDir; |
| 3516 | a.info.dataDir = pkg.applicationInfo.dataDir; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3517 | mInstrumentation.put(a.getComponentName(), a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3519 | if (r == null) { |
| 3520 | r = new StringBuilder(256); |
| 3521 | } else { |
| 3522 | r.append(' '); |
| 3523 | } |
| 3524 | r.append(a.info.name); |
| 3525 | } |
| 3526 | } |
| 3527 | if (r != null) { |
| 3528 | if (Config.LOGD) Log.d(TAG, " Instrumentation: " + r); |
| 3529 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3530 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 3531 | if (pkg.protectedBroadcasts != null) { |
| 3532 | N = pkg.protectedBroadcasts.size(); |
| 3533 | for (i=0; i<N; i++) { |
| 3534 | mProtectedBroadcasts.add(pkg.protectedBroadcasts.get(i)); |
| 3535 | } |
| 3536 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3538 | pkgSetting.setTimeStamp(scanFileTime); |
| 3539 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3541 | return pkg; |
| 3542 | } |
| 3543 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3544 | private void killApplication(String pkgName, int uid) { |
| 3545 | // Request the ActivityManager to kill the process(only for existing packages) |
| 3546 | // so that we do not end up in a confused state while the user is still using the older |
| 3547 | // version of the application while the new one gets installed. |
| 3548 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 3549 | if (am != null) { |
| 3550 | try { |
| 3551 | am.killApplicationWithUid(pkgName, uid); |
| 3552 | } catch (RemoteException e) { |
| 3553 | } |
| 3554 | } |
| 3555 | } |
| 3556 | |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3557 | // The following constants are returned by cachePackageSharedLibsForAbiLI |
| 3558 | // to indicate if native shared libraries were found in the package. |
| 3559 | // Values are: |
| 3560 | // PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES => native libraries found and installed |
| 3561 | // PACKAGE_INSTALL_NATIVE_NO_LIBRARIES => no native libraries in package |
| 3562 | // PACKAGE_INSTALL_NATIVE_ABI_MISMATCH => native libraries for another ABI found |
| 3563 | // in package (and not installed) |
| 3564 | // |
| 3565 | private static final int PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES = 0; |
| 3566 | private static final int PACKAGE_INSTALL_NATIVE_NO_LIBRARIES = 1; |
| 3567 | private static final int PACKAGE_INSTALL_NATIVE_ABI_MISMATCH = 2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3569 | // Return the path of the directory that will contain the native binaries |
| 3570 | // of a given installed package. This is relative to the data path. |
| 3571 | // |
| 3572 | private static File getNativeBinaryDirForPackage(PackageParser.Package pkg) { |
| 3573 | return new File(pkg.applicationInfo.dataDir + "/lib"); |
| 3574 | } |
| 3575 | |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3576 | // Find all files of the form lib/<cpuAbi>/lib<name>.so in the .apk |
| 3577 | // and automatically copy them to /data/data/<appname>/lib if present. |
| 3578 | // |
| 3579 | // NOTE: this method may throw an IOException if the library cannot |
| 3580 | // be copied to its final destination, e.g. if there isn't enough |
| 3581 | // room left on the data partition, or a ZipException if the package |
| 3582 | // file is malformed. |
| 3583 | // |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3584 | private int cachePackageSharedLibsForAbiLI(PackageParser.Package pkg, |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3585 | File scanFile, String cpuAbi) throws IOException, ZipException { |
| 3586 | File sharedLibraryDir = getNativeBinaryDirForPackage(pkg); |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3587 | final String apkLib = "lib/"; |
| 3588 | final int apkLibLen = apkLib.length(); |
| 3589 | final int cpuAbiLen = cpuAbi.length(); |
| 3590 | final String libPrefix = "lib"; |
| 3591 | final int libPrefixLen = libPrefix.length(); |
| 3592 | final String libSuffix = ".so"; |
| 3593 | final int libSuffixLen = libSuffix.length(); |
| 3594 | boolean hasNativeLibraries = false; |
| 3595 | boolean installedNativeLibraries = false; |
| 3596 | |
| 3597 | // the minimum length of a valid native shared library of the form |
| 3598 | // lib/<something>/lib<name>.so. |
| 3599 | final int minEntryLen = apkLibLen + 2 + libPrefixLen + 1 + libSuffixLen; |
| 3600 | |
| 3601 | ZipFile zipFile = new ZipFile(scanFile); |
| 3602 | Enumeration<ZipEntry> entries = |
| 3603 | (Enumeration<ZipEntry>) zipFile.entries(); |
| 3604 | |
| 3605 | while (entries.hasMoreElements()) { |
| 3606 | ZipEntry entry = entries.nextElement(); |
| 3607 | // skip directories |
| 3608 | if (entry.isDirectory()) { |
| 3609 | continue; |
| 3610 | } |
| 3611 | String entryName = entry.getName(); |
| 3612 | |
| 3613 | // check that the entry looks like lib/<something>/lib<name>.so |
| 3614 | // here, but don't check the ABI just yet. |
| 3615 | // |
| 3616 | // - must be sufficiently long |
| 3617 | // - must end with libSuffix, i.e. ".so" |
| 3618 | // - must start with apkLib, i.e. "lib/" |
| 3619 | if (entryName.length() < minEntryLen || |
| 3620 | !entryName.endsWith(libSuffix) || |
| 3621 | !entryName.startsWith(apkLib) ) { |
| 3622 | continue; |
| 3623 | } |
| 3624 | |
| 3625 | // file name must start with libPrefix, i.e. "lib" |
| 3626 | int lastSlash = entryName.lastIndexOf('/'); |
| 3627 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3628 | if (lastSlash < 0 || |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3629 | !entryName.regionMatches(lastSlash+1, libPrefix, 0, libPrefixLen) ) { |
| 3630 | continue; |
| 3631 | } |
| 3632 | |
| 3633 | hasNativeLibraries = true; |
| 3634 | |
| 3635 | // check the cpuAbi now, between lib/ and /lib<name>.so |
| 3636 | // |
| 3637 | if (lastSlash != apkLibLen + cpuAbiLen || |
| 3638 | !entryName.regionMatches(apkLibLen, cpuAbi, 0, cpuAbiLen) ) |
| 3639 | continue; |
| 3640 | |
| 3641 | // extract the library file name, ensure it doesn't contain |
| 3642 | // weird characters. we're guaranteed here that it doesn't contain |
| 3643 | // a directory separator though. |
| 3644 | String libFileName = entryName.substring(lastSlash+1); |
| 3645 | if (!FileUtils.isFilenameSafe(new File(libFileName))) { |
| 3646 | continue; |
| 3647 | } |
| 3648 | |
| 3649 | installedNativeLibraries = true; |
| 3650 | |
David 'Digit' Turner | 6390929 | 2010-06-03 14:37:42 -0700 | [diff] [blame] | 3651 | // Always extract the shared library |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3652 | String sharedLibraryFilePath = sharedLibraryDir.getPath() + |
| 3653 | File.separator + libFileName; |
| 3654 | File sharedLibraryFile = new File(sharedLibraryFilePath); |
David 'Digit' Turner | 6390929 | 2010-06-03 14:37:42 -0700 | [diff] [blame] | 3655 | |
| 3656 | if (Config.LOGD) { |
| 3657 | Log.d(TAG, "Caching shared lib " + entry.getName()); |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3658 | } |
David 'Digit' Turner | 6390929 | 2010-06-03 14:37:42 -0700 | [diff] [blame] | 3659 | if (mInstaller == null) { |
| 3660 | sharedLibraryDir.mkdir(); |
| 3661 | } |
| 3662 | cacheNativeBinaryLI(pkg, zipFile, entry, sharedLibraryDir, |
| 3663 | sharedLibraryFile); |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3664 | } |
| 3665 | if (!hasNativeLibraries) |
| 3666 | return PACKAGE_INSTALL_NATIVE_NO_LIBRARIES; |
| 3667 | |
| 3668 | if (!installedNativeLibraries) |
| 3669 | return PACKAGE_INSTALL_NATIVE_ABI_MISMATCH; |
| 3670 | |
| 3671 | return PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES; |
| 3672 | } |
| 3673 | |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3674 | // Find the gdbserver executable program in a package at |
| 3675 | // lib/<cpuAbi>/gdbserver and copy it to /data/data/<name>/lib/gdbserver |
| 3676 | // |
| 3677 | // Returns PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES on success, |
| 3678 | // or PACKAGE_INSTALL_NATIVE_NO_LIBRARIES otherwise. |
| 3679 | // |
| 3680 | private int cachePackageGdbServerLI(PackageParser.Package pkg, |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3681 | File scanFile, String cpuAbi) throws IOException, ZipException { |
| 3682 | File installGdbServerDir = getNativeBinaryDirForPackage(pkg); |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3683 | final String GDBSERVER = "gdbserver"; |
| 3684 | final String apkGdbServerPath = "lib/" + cpuAbi + "/" + GDBSERVER; |
| 3685 | |
| 3686 | ZipFile zipFile = new ZipFile(scanFile); |
| 3687 | Enumeration<ZipEntry> entries = |
| 3688 | (Enumeration<ZipEntry>) zipFile.entries(); |
| 3689 | |
| 3690 | while (entries.hasMoreElements()) { |
| 3691 | ZipEntry entry = entries.nextElement(); |
| 3692 | // skip directories |
| 3693 | if (entry.isDirectory()) { |
| 3694 | continue; |
| 3695 | } |
| 3696 | String entryName = entry.getName(); |
| 3697 | |
| 3698 | if (!entryName.equals(apkGdbServerPath)) { |
| 3699 | continue; |
| 3700 | } |
| 3701 | |
| 3702 | String installGdbServerPath = installGdbServerDir.getPath() + |
| 3703 | "/" + GDBSERVER; |
| 3704 | File installGdbServerFile = new File(installGdbServerPath); |
David 'Digit' Turner | 6390929 | 2010-06-03 14:37:42 -0700 | [diff] [blame] | 3705 | |
| 3706 | if (Config.LOGD) { |
| 3707 | Log.d(TAG, "Caching gdbserver " + entry.getName()); |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3708 | } |
David 'Digit' Turner | 6390929 | 2010-06-03 14:37:42 -0700 | [diff] [blame] | 3709 | if (mInstaller == null) { |
| 3710 | installGdbServerDir.mkdir(); |
| 3711 | } |
| 3712 | cacheNativeBinaryLI(pkg, zipFile, entry, installGdbServerDir, |
| 3713 | installGdbServerFile); |
| 3714 | |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3715 | return PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES; |
| 3716 | } |
| 3717 | return PACKAGE_INSTALL_NATIVE_NO_LIBRARIES; |
| 3718 | } |
| 3719 | |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3720 | // extract shared libraries stored in the APK as lib/<cpuAbi>/lib<name>.so |
| 3721 | // and copy them to /data/data/<appname>/lib. |
| 3722 | // |
| 3723 | // This function will first try the main CPU ABI defined by Build.CPU_ABI |
| 3724 | // (which corresponds to ro.product.cpu.abi), and also try an alternate |
| 3725 | // one if ro.product.cpu.abi2 is defined. |
| 3726 | // |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3727 | private int cachePackageSharedLibsLI(PackageParser.Package pkg, File scanFile) { |
David 'Digit' Turner | 6390929 | 2010-06-03 14:37:42 -0700 | [diff] [blame] | 3728 | // Remove all native binaries from a directory. This is used when upgrading |
| 3729 | // a package: in case the new .apk doesn't contain a native binary that was |
| 3730 | // in the old one (and thus installed), we need to remove it from |
| 3731 | // /data/data/<appname>/lib |
| 3732 | // |
| 3733 | // The simplest way to do that is to remove all files in this directory, |
| 3734 | // since it is owned by "system", applications are not supposed to write |
| 3735 | // anything there. |
| 3736 | removeNativeBinariesLI(pkg); |
| 3737 | |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3738 | String cpuAbi = Build.CPU_ABI; |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3739 | try { |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3740 | int result = cachePackageSharedLibsForAbiLI(pkg, scanFile, cpuAbi); |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3741 | |
| 3742 | // some architectures are capable of supporting several CPU ABIs |
| 3743 | // for example, 'armeabi-v7a' also supports 'armeabi' native code |
| 3744 | // this is indicated by the definition of the ro.product.cpu.abi2 |
| 3745 | // system property. |
| 3746 | // |
| 3747 | // only scan the package twice in case of ABI mismatch |
| 3748 | if (result == PACKAGE_INSTALL_NATIVE_ABI_MISMATCH) { |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3749 | final String cpuAbi2 = SystemProperties.get("ro.product.cpu.abi2",null); |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3750 | if (cpuAbi2 != null) { |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3751 | result = cachePackageSharedLibsForAbiLI(pkg, scanFile, cpuAbi2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3752 | } |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3753 | |
| 3754 | if (result == PACKAGE_INSTALL_NATIVE_ABI_MISMATCH) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3755 | Slog.w(TAG,"Native ABI mismatch from package file"); |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3756 | return PackageManager.INSTALL_FAILED_INVALID_APK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3757 | } |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3758 | |
| 3759 | if (result == PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES) { |
| 3760 | cpuAbi = cpuAbi2; |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | // for debuggable packages, also extract gdbserver from lib/<abi> |
| 3765 | // into /data/data/<appname>/lib too. |
| 3766 | if (result == PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES && |
| 3767 | (pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3768 | int result2 = cachePackageGdbServerLI(pkg, scanFile, cpuAbi); |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3769 | if (result2 == PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES) { |
| 3770 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_NATIVE_DEBUGGABLE; |
| 3771 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3772 | } |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3773 | } catch (ZipException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3774 | Slog.w(TAG, "Failed to extract data from package file", e); |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3775 | return PackageManager.INSTALL_FAILED_INVALID_APK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3776 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3777 | Slog.w(TAG, "Failed to cache package shared libs", e); |
Dianne Hackborn | b181118 | 2009-05-21 15:45:42 -0700 | [diff] [blame] | 3778 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3779 | } |
Dianne Hackborn | b181118 | 2009-05-21 15:45:42 -0700 | [diff] [blame] | 3780 | return PackageManager.INSTALL_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3781 | } |
| 3782 | |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3783 | private void cacheNativeBinaryLI(PackageParser.Package pkg, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | ZipFile zipFile, ZipEntry entry, |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3785 | File binaryDir, |
| 3786 | File binaryFile) throws IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3787 | InputStream inputStream = zipFile.getInputStream(entry); |
| 3788 | try { |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3789 | File tempFile = File.createTempFile("tmp", "tmp", binaryDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | String tempFilePath = tempFile.getPath(); |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3791 | // XXX package manager can't change owner, so the executable files for |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3792 | // now need to be left as world readable and owned by the system. |
| 3793 | if (! FileUtils.copyToFile(inputStream, tempFile) || |
| 3794 | ! tempFile.setLastModified(entry.getTime()) || |
| 3795 | FileUtils.setPermissions(tempFilePath, |
| 3796 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3797 | |FileUtils.S_IXUSR|FileUtils.S_IXGRP|FileUtils.S_IXOTH |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3798 | |FileUtils.S_IROTH, -1, -1) != 0 || |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3799 | ! tempFile.renameTo(binaryFile)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | // Failed to properly write file. |
| 3801 | tempFile.delete(); |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3802 | throw new IOException("Couldn't create cached binary " |
| 3803 | + binaryFile + " in " + binaryDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3804 | } |
| 3805 | } finally { |
| 3806 | inputStream.close(); |
| 3807 | } |
| 3808 | } |
| 3809 | |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 3810 | // Remove the native binaries of a given package. This simply |
| 3811 | // gets rid of the files in the 'lib' sub-directory. |
| 3812 | private void removeNativeBinariesLI(PackageParser.Package pkg) { |
| 3813 | File binaryDir = getNativeBinaryDirForPackage(pkg); |
| 3814 | |
| 3815 | if (DEBUG_NATIVE) { |
| 3816 | Slog.w(TAG,"Deleting native binaries from: " + binaryDir.getPath()); |
| 3817 | } |
| 3818 | |
| 3819 | // Just remove any file in the directory. Since the directory |
| 3820 | // is owned by the 'system' UID, the application is not supposed |
| 3821 | // to have written anything there. |
| 3822 | // |
| 3823 | if (binaryDir.exists()) { |
| 3824 | File[] binaries = binaryDir.listFiles(); |
| 3825 | if (binaries != null) { |
| 3826 | for (int nn=0; nn < binaries.length; nn++) { |
| 3827 | if (DEBUG_NATIVE) { |
| 3828 | Slog.d(TAG," Deleting " + binaries[nn].getName()); |
| 3829 | } |
| 3830 | if (!binaries[nn].delete()) { |
| 3831 | Slog.w(TAG,"Could not delete native binary: " + |
| 3832 | binaries[nn].getPath()); |
| 3833 | } |
| 3834 | } |
| 3835 | } |
| 3836 | // Do not delete 'lib' directory itself, or this will prevent |
| 3837 | // installation of future updates. |
| 3838 | } |
| 3839 | } |
| 3840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3841 | void removePackageLI(PackageParser.Package pkg, boolean chatty) { |
| 3842 | if (chatty && Config.LOGD) Log.d( |
| 3843 | TAG, "Removing package " + pkg.applicationInfo.packageName ); |
| 3844 | |
| 3845 | synchronized (mPackages) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3846 | clearPackagePreferredActivitiesLP(pkg.packageName); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3848 | mPackages.remove(pkg.applicationInfo.packageName); |
| 3849 | if (pkg.mPath != null) { |
| 3850 | mAppDirs.remove(pkg.mPath); |
| 3851 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3853 | PackageSetting ps = (PackageSetting)pkg.mExtras; |
| 3854 | if (ps != null && ps.sharedUser != null) { |
| 3855 | // XXX don't do this until the data is removed. |
| 3856 | if (false) { |
| 3857 | ps.sharedUser.packages.remove(ps); |
| 3858 | if (ps.sharedUser.packages.size() == 0) { |
| 3859 | // Remove. |
| 3860 | } |
| 3861 | } |
| 3862 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3864 | int N = pkg.providers.size(); |
| 3865 | StringBuilder r = null; |
| 3866 | int i; |
| 3867 | for (i=0; i<N; i++) { |
| 3868 | PackageParser.Provider p = pkg.providers.get(i); |
| 3869 | mProvidersByComponent.remove(new ComponentName(p.info.packageName, |
| 3870 | p.info.name)); |
| 3871 | if (p.info.authority == null) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3872 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3873 | /* The is another ContentProvider with this authority when |
| 3874 | * this app was installed so this authority is null, |
| 3875 | * Ignore it as we don't have to unregister the provider. |
| 3876 | */ |
| 3877 | continue; |
| 3878 | } |
| 3879 | String names[] = p.info.authority.split(";"); |
| 3880 | for (int j = 0; j < names.length; j++) { |
| 3881 | if (mProviders.get(names[j]) == p) { |
| 3882 | mProviders.remove(names[j]); |
| 3883 | if (chatty && Config.LOGD) Log.d( |
| 3884 | TAG, "Unregistered content provider: " + names[j] + |
| 3885 | ", className = " + p.info.name + |
| 3886 | ", isSyncable = " + p.info.isSyncable); |
| 3887 | } |
| 3888 | } |
| 3889 | if (chatty) { |
| 3890 | if (r == null) { |
| 3891 | r = new StringBuilder(256); |
| 3892 | } else { |
| 3893 | r.append(' '); |
| 3894 | } |
| 3895 | r.append(p.info.name); |
| 3896 | } |
| 3897 | } |
| 3898 | if (r != null) { |
| 3899 | if (Config.LOGD) Log.d(TAG, " Providers: " + r); |
| 3900 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | N = pkg.services.size(); |
| 3903 | r = null; |
| 3904 | for (i=0; i<N; i++) { |
| 3905 | PackageParser.Service s = pkg.services.get(i); |
| 3906 | mServices.removeService(s); |
| 3907 | if (chatty) { |
| 3908 | if (r == null) { |
| 3909 | r = new StringBuilder(256); |
| 3910 | } else { |
| 3911 | r.append(' '); |
| 3912 | } |
| 3913 | r.append(s.info.name); |
| 3914 | } |
| 3915 | } |
| 3916 | if (r != null) { |
| 3917 | if (Config.LOGD) Log.d(TAG, " Services: " + r); |
| 3918 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3920 | N = pkg.receivers.size(); |
| 3921 | r = null; |
| 3922 | for (i=0; i<N; i++) { |
| 3923 | PackageParser.Activity a = pkg.receivers.get(i); |
| 3924 | mReceivers.removeActivity(a, "receiver"); |
| 3925 | if (chatty) { |
| 3926 | if (r == null) { |
| 3927 | r = new StringBuilder(256); |
| 3928 | } else { |
| 3929 | r.append(' '); |
| 3930 | } |
| 3931 | r.append(a.info.name); |
| 3932 | } |
| 3933 | } |
| 3934 | if (r != null) { |
| 3935 | if (Config.LOGD) Log.d(TAG, " Receivers: " + r); |
| 3936 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3938 | N = pkg.activities.size(); |
| 3939 | r = null; |
| 3940 | for (i=0; i<N; i++) { |
| 3941 | PackageParser.Activity a = pkg.activities.get(i); |
| 3942 | mActivities.removeActivity(a, "activity"); |
| 3943 | if (chatty) { |
| 3944 | if (r == null) { |
| 3945 | r = new StringBuilder(256); |
| 3946 | } else { |
| 3947 | r.append(' '); |
| 3948 | } |
| 3949 | r.append(a.info.name); |
| 3950 | } |
| 3951 | } |
| 3952 | if (r != null) { |
| 3953 | if (Config.LOGD) Log.d(TAG, " Activities: " + r); |
| 3954 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3956 | N = pkg.permissions.size(); |
| 3957 | r = null; |
| 3958 | for (i=0; i<N; i++) { |
| 3959 | PackageParser.Permission p = pkg.permissions.get(i); |
| 3960 | boolean tree = false; |
| 3961 | BasePermission bp = mSettings.mPermissions.get(p.info.name); |
| 3962 | if (bp == null) { |
| 3963 | tree = true; |
| 3964 | bp = mSettings.mPermissionTrees.get(p.info.name); |
| 3965 | } |
| 3966 | if (bp != null && bp.perm == p) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3967 | bp.perm = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3968 | if (chatty) { |
| 3969 | if (r == null) { |
| 3970 | r = new StringBuilder(256); |
| 3971 | } else { |
| 3972 | r.append(' '); |
| 3973 | } |
| 3974 | r.append(p.info.name); |
| 3975 | } |
| 3976 | } |
| 3977 | } |
| 3978 | if (r != null) { |
| 3979 | if (Config.LOGD) Log.d(TAG, " Permissions: " + r); |
| 3980 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3982 | N = pkg.instrumentation.size(); |
| 3983 | r = null; |
| 3984 | for (i=0; i<N; i++) { |
| 3985 | PackageParser.Instrumentation a = pkg.instrumentation.get(i); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3986 | mInstrumentation.remove(a.getComponentName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | if (chatty) { |
| 3988 | if (r == null) { |
| 3989 | r = new StringBuilder(256); |
| 3990 | } else { |
| 3991 | r.append(' '); |
| 3992 | } |
| 3993 | r.append(a.info.name); |
| 3994 | } |
| 3995 | } |
| 3996 | if (r != null) { |
| 3997 | if (Config.LOGD) Log.d(TAG, " Instrumentation: " + r); |
| 3998 | } |
| 3999 | } |
| 4000 | } |
| 4001 | |
| 4002 | private static final boolean isPackageFilename(String name) { |
| 4003 | return name != null && name.endsWith(".apk"); |
| 4004 | } |
| 4005 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4006 | private static boolean hasPermission(PackageParser.Package pkgInfo, String perm) { |
| 4007 | for (int i=pkgInfo.permissions.size()-1; i>=0; i--) { |
| 4008 | if (pkgInfo.permissions.get(i).info.name.equals(perm)) { |
| 4009 | return true; |
| 4010 | } |
| 4011 | } |
| 4012 | return false; |
| 4013 | } |
| 4014 | |
| 4015 | private void updatePermissionsLP(String changingPkg, |
Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 4016 | PackageParser.Package pkgInfo, boolean grantPermissions, |
| 4017 | boolean replace, boolean replaceAll) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4018 | // Make sure there are no dangling permission trees. |
| 4019 | Iterator<BasePermission> it = mSettings.mPermissionTrees |
| 4020 | .values().iterator(); |
| 4021 | while (it.hasNext()) { |
| 4022 | BasePermission bp = it.next(); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4023 | if (bp.packageSetting == null) { |
| 4024 | // We may not yet have parsed the package, so just see if |
| 4025 | // we still know about its settings. |
| 4026 | bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage); |
| 4027 | } |
| 4028 | if (bp.packageSetting == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4029 | Slog.w(TAG, "Removing dangling permission tree: " + bp.name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | + " from package " + bp.sourcePackage); |
| 4031 | it.remove(); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4032 | } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) { |
| 4033 | if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) { |
| 4034 | Slog.i(TAG, "Removing old permission tree: " + bp.name |
| 4035 | + " from package " + bp.sourcePackage); |
| 4036 | grantPermissions = true; |
| 4037 | it.remove(); |
| 4038 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4039 | } |
| 4040 | } |
| 4041 | |
| 4042 | // Make sure all dynamic permissions have been assigned to a package, |
| 4043 | // and make sure there are no dangling permissions. |
| 4044 | it = mSettings.mPermissions.values().iterator(); |
| 4045 | while (it.hasNext()) { |
| 4046 | BasePermission bp = it.next(); |
| 4047 | if (bp.type == BasePermission.TYPE_DYNAMIC) { |
| 4048 | if (DEBUG_SETTINGS) Log.v(TAG, "Dynamic permission: name=" |
| 4049 | + bp.name + " pkg=" + bp.sourcePackage |
| 4050 | + " info=" + bp.pendingInfo); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4051 | if (bp.packageSetting == null && bp.pendingInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4052 | BasePermission tree = findPermissionTreeLP(bp.name); |
| 4053 | if (tree != null) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4054 | bp.packageSetting = tree.packageSetting; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | bp.perm = new PackageParser.Permission(tree.perm.owner, |
| 4056 | new PermissionInfo(bp.pendingInfo)); |
| 4057 | bp.perm.info.packageName = tree.perm.info.packageName; |
| 4058 | bp.perm.info.name = bp.name; |
| 4059 | bp.uid = tree.uid; |
| 4060 | } |
| 4061 | } |
| 4062 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4063 | if (bp.packageSetting == null) { |
| 4064 | // We may not yet have parsed the package, so just see if |
| 4065 | // we still know about its settings. |
| 4066 | bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage); |
| 4067 | } |
| 4068 | if (bp.packageSetting == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4069 | Slog.w(TAG, "Removing dangling permission: " + bp.name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4070 | + " from package " + bp.sourcePackage); |
| 4071 | it.remove(); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4072 | } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) { |
| 4073 | if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) { |
| 4074 | Slog.i(TAG, "Removing old permission: " + bp.name |
| 4075 | + " from package " + bp.sourcePackage); |
| 4076 | grantPermissions = true; |
| 4077 | it.remove(); |
| 4078 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | // Now update the permissions for all packages, in particular |
| 4083 | // replace the granted permissions of the system packages. |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4084 | if (grantPermissions) { |
| 4085 | for (PackageParser.Package pkg : mPackages.values()) { |
| 4086 | if (pkg != pkgInfo) { |
Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 4087 | grantPermissionsLP(pkg, replaceAll); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4088 | } |
| 4089 | } |
| 4090 | } |
| 4091 | |
| 4092 | if (pkgInfo != null) { |
| 4093 | grantPermissionsLP(pkgInfo, replace); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | } |
| 4095 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | private void grantPermissionsLP(PackageParser.Package pkg, boolean replace) { |
| 4098 | final PackageSetting ps = (PackageSetting)pkg.mExtras; |
| 4099 | if (ps == null) { |
| 4100 | return; |
| 4101 | } |
| 4102 | final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4103 | boolean changedPermission = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4105 | if (replace) { |
| 4106 | ps.permissionsFixed = false; |
| 4107 | if (gp == ps) { |
| 4108 | gp.grantedPermissions.clear(); |
| 4109 | gp.gids = mGlobalGids; |
| 4110 | } |
| 4111 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4113 | if (gp.gids == null) { |
| 4114 | gp.gids = mGlobalGids; |
| 4115 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4117 | final int N = pkg.requestedPermissions.size(); |
| 4118 | for (int i=0; i<N; i++) { |
| 4119 | String name = pkg.requestedPermissions.get(i); |
| 4120 | BasePermission bp = mSettings.mPermissions.get(name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4121 | if (false) { |
| 4122 | if (gp != ps) { |
| 4123 | Log.i(TAG, "Package " + pkg.packageName + " checking " + name |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4124 | + ": " + bp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4125 | } |
| 4126 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4127 | if (bp != null && bp.packageSetting != null) { |
| 4128 | final String perm = bp.name; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4129 | boolean allowed; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4130 | boolean allowedSig = false; |
| 4131 | if (bp.protectionLevel == PermissionInfo.PROTECTION_NORMAL |
| 4132 | || bp.protectionLevel == PermissionInfo.PROTECTION_DANGEROUS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4133 | allowed = true; |
Dianne Hackborn | 6e52b5d | 2010-04-05 14:33:01 -0700 | [diff] [blame] | 4134 | } else if (bp.packageSetting == null) { |
| 4135 | // This permission is invalid; skip it. |
| 4136 | allowed = false; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4137 | } else if (bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE |
| 4138 | || bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM) { |
| 4139 | allowed = (checkSignaturesLP(bp.packageSetting.signatures.mSignatures, pkg.mSignatures) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | == PackageManager.SIGNATURE_MATCH) |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 4141 | || (checkSignaturesLP(mPlatformPackage.mSignatures, pkg.mSignatures) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4142 | == PackageManager.SIGNATURE_MATCH); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4143 | if (bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4145 | // For updated system applications, the signatureOrSystem permission |
| 4146 | // is granted only if it had been defined by the original application. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4147 | if ((pkg.applicationInfo.flags |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4148 | & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 4149 | PackageSetting sysPs = mSettings.getDisabledSystemPkg(pkg.packageName); |
| 4150 | if(sysPs.grantedPermissions.contains(perm)) { |
| 4151 | allowed = true; |
| 4152 | } else { |
| 4153 | allowed = false; |
| 4154 | } |
| 4155 | } else { |
| 4156 | allowed = true; |
| 4157 | } |
| 4158 | } |
| 4159 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4160 | if (allowed) { |
| 4161 | allowedSig = true; |
| 4162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4163 | } else { |
| 4164 | allowed = false; |
| 4165 | } |
| 4166 | if (false) { |
| 4167 | if (gp != ps) { |
| 4168 | Log.i(TAG, "Package " + pkg.packageName + " granting " + perm); |
| 4169 | } |
| 4170 | } |
| 4171 | if (allowed) { |
| 4172 | if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0 |
| 4173 | && ps.permissionsFixed) { |
| 4174 | // If this is an existing, non-system package, then |
| 4175 | // we can't add any new permissions to it. |
Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 4176 | if (!allowedSig && !gp.grantedPermissions.contains(perm)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | allowed = false; |
Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 4178 | // Except... if this is a permission that was added |
| 4179 | // to the platform (note: need to only do this when |
| 4180 | // updating the platform). |
| 4181 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
| 4182 | for (int ip=0; ip<NP; ip++) { |
| 4183 | final PackageParser.NewPermissionInfo npi |
| 4184 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 4185 | if (npi.name.equals(perm) |
| 4186 | && pkg.applicationInfo.targetSdkVersion < npi.sdkVersion) { |
| 4187 | allowed = true; |
Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 4188 | Log.i(TAG, "Auto-granting " + perm + " to old pkg " |
Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 4189 | + pkg.packageName); |
| 4190 | break; |
| 4191 | } |
| 4192 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4193 | } |
| 4194 | } |
| 4195 | if (allowed) { |
| 4196 | if (!gp.grantedPermissions.contains(perm)) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4197 | changedPermission = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4198 | gp.grantedPermissions.add(perm); |
| 4199 | gp.gids = appendInts(gp.gids, bp.gids); |
Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 4200 | } else if (!ps.haveGids) { |
| 4201 | gp.gids = appendInts(gp.gids, bp.gids); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | } |
| 4203 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4204 | Slog.w(TAG, "Not granting permission " + perm |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4205 | + " to package " + pkg.packageName |
| 4206 | + " because it was previously installed without"); |
| 4207 | } |
| 4208 | } else { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4209 | if (gp.grantedPermissions.remove(perm)) { |
| 4210 | changedPermission = true; |
| 4211 | gp.gids = removeInts(gp.gids, bp.gids); |
| 4212 | Slog.i(TAG, "Un-granting permission " + perm |
| 4213 | + " from package " + pkg.packageName |
| 4214 | + " (protectionLevel=" + bp.protectionLevel |
| 4215 | + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags) |
| 4216 | + ")"); |
| 4217 | } else { |
| 4218 | Slog.w(TAG, "Not granting permission " + perm |
| 4219 | + " to package " + pkg.packageName |
| 4220 | + " (protectionLevel=" + bp.protectionLevel |
| 4221 | + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags) |
| 4222 | + ")"); |
| 4223 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4224 | } |
| 4225 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4226 | Slog.w(TAG, "Unknown permission " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4227 | + " in package " + pkg.packageName); |
| 4228 | } |
| 4229 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4230 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4231 | if ((changedPermission || replace) && !ps.permissionsFixed && |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 4232 | ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) || |
| 4233 | ((ps.pkgFlags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)){ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4234 | // This is the first that we have heard about this package, so the |
| 4235 | // permissions we have now selected are fixed until explicitly |
| 4236 | // changed. |
| 4237 | ps.permissionsFixed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4238 | } |
Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 4239 | ps.haveGids = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4241 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4242 | private final class ActivityIntentResolver |
| 4243 | extends IntentResolver<PackageParser.ActivityIntentInfo, ResolveInfo> { |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4244 | public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4245 | mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0; |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4246 | return super.queryIntent(intent, resolvedType, defaultOnly); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | } |
| 4248 | |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4249 | public List queryIntent(Intent intent, String resolvedType, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4250 | mFlags = flags; |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4251 | return super.queryIntent(intent, resolvedType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4252 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 4253 | } |
| 4254 | |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4255 | public List queryIntentForPackage(Intent intent, String resolvedType, int flags, |
| 4256 | ArrayList<PackageParser.Activity> packageActivities) { |
| 4257 | if (packageActivities == null) { |
| 4258 | return null; |
| 4259 | } |
| 4260 | mFlags = flags; |
| 4261 | final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0; |
| 4262 | int N = packageActivities.size(); |
| 4263 | ArrayList<ArrayList<PackageParser.ActivityIntentInfo>> listCut = |
| 4264 | new ArrayList<ArrayList<PackageParser.ActivityIntentInfo>>(N); |
Mihai Preda | c3320db | 2009-05-18 20:15:32 +0200 | [diff] [blame] | 4265 | |
| 4266 | ArrayList<PackageParser.ActivityIntentInfo> intentFilters; |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4267 | for (int i = 0; i < N; ++i) { |
Mihai Preda | c3320db | 2009-05-18 20:15:32 +0200 | [diff] [blame] | 4268 | intentFilters = packageActivities.get(i).intents; |
| 4269 | if (intentFilters != null && intentFilters.size() > 0) { |
| 4270 | listCut.add(intentFilters); |
| 4271 | } |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4272 | } |
| 4273 | return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut); |
| 4274 | } |
| 4275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4276 | public final void addActivity(PackageParser.Activity a, String type) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4277 | mActivities.put(a.getComponentName(), a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4279 | TAG, " " + type + " " + |
| 4280 | (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":"); |
| 4281 | if (SHOW_INFO || Config.LOGV) Log.v(TAG, " Class=" + a.info.name); |
| 4282 | int NI = a.intents.size(); |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4283 | for (int j=0; j<NI; j++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | PackageParser.ActivityIntentInfo intent = a.intents.get(j); |
| 4285 | if (SHOW_INFO || Config.LOGV) { |
| 4286 | Log.v(TAG, " IntentFilter:"); |
| 4287 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4288 | } |
| 4289 | if (!intent.debugCheck()) { |
| 4290 | Log.w(TAG, "==> For Activity " + a.info.name); |
| 4291 | } |
| 4292 | addFilter(intent); |
| 4293 | } |
| 4294 | } |
| 4295 | |
| 4296 | public final void removeActivity(PackageParser.Activity a, String type) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4297 | mActivities.remove(a.getComponentName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4298 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4299 | TAG, " " + type + " " + |
| 4300 | (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":"); |
| 4301 | if (SHOW_INFO || Config.LOGV) Log.v(TAG, " Class=" + a.info.name); |
| 4302 | int NI = a.intents.size(); |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4303 | for (int j=0; j<NI; j++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | PackageParser.ActivityIntentInfo intent = a.intents.get(j); |
| 4305 | if (SHOW_INFO || Config.LOGV) { |
| 4306 | Log.v(TAG, " IntentFilter:"); |
| 4307 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4308 | } |
| 4309 | removeFilter(intent); |
| 4310 | } |
| 4311 | } |
| 4312 | |
| 4313 | @Override |
| 4314 | protected boolean allowFilterResult( |
| 4315 | PackageParser.ActivityIntentInfo filter, List<ResolveInfo> dest) { |
| 4316 | ActivityInfo filterAi = filter.activity.info; |
| 4317 | for (int i=dest.size()-1; i>=0; i--) { |
| 4318 | ActivityInfo destAi = dest.get(i).activityInfo; |
| 4319 | if (destAi.name == filterAi.name |
| 4320 | && destAi.packageName == filterAi.packageName) { |
| 4321 | return false; |
| 4322 | } |
| 4323 | } |
| 4324 | return true; |
| 4325 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | @Override |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4328 | protected String packageForFilter(PackageParser.ActivityIntentInfo info) { |
| 4329 | return info.activity.owner.packageName; |
| 4330 | } |
| 4331 | |
| 4332 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | protected ResolveInfo newResult(PackageParser.ActivityIntentInfo info, |
| 4334 | int match) { |
| 4335 | if (!mSettings.isEnabledLP(info.activity.info, mFlags)) { |
| 4336 | return null; |
| 4337 | } |
| 4338 | final PackageParser.Activity activity = info.activity; |
| 4339 | if (mSafeMode && (activity.info.applicationInfo.flags |
| 4340 | &ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 4341 | return null; |
| 4342 | } |
| 4343 | final ResolveInfo res = new ResolveInfo(); |
| 4344 | res.activityInfo = PackageParser.generateActivityInfo(activity, |
| 4345 | mFlags); |
| 4346 | if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) { |
| 4347 | res.filter = info; |
| 4348 | } |
| 4349 | res.priority = info.getPriority(); |
| 4350 | res.preferredOrder = activity.owner.mPreferredOrder; |
| 4351 | //System.out.println("Result: " + res.activityInfo.className + |
| 4352 | // " = " + res.priority); |
| 4353 | res.match = match; |
| 4354 | res.isDefault = info.hasDefault; |
| 4355 | res.labelRes = info.labelRes; |
| 4356 | res.nonLocalizedLabel = info.nonLocalizedLabel; |
| 4357 | res.icon = info.icon; |
| 4358 | return res; |
| 4359 | } |
| 4360 | |
| 4361 | @Override |
| 4362 | protected void sortResults(List<ResolveInfo> results) { |
| 4363 | Collections.sort(results, mResolvePrioritySorter); |
| 4364 | } |
| 4365 | |
| 4366 | @Override |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4367 | protected void dumpFilter(PrintWriter out, String prefix, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4368 | PackageParser.ActivityIntentInfo filter) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4369 | out.print(prefix); out.print( |
| 4370 | Integer.toHexString(System.identityHashCode(filter.activity))); |
| 4371 | out.print(' '); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4372 | out.print(filter.activity.getComponentShortName()); |
| 4373 | out.print(" filter "); |
| 4374 | out.println(Integer.toHexString(System.identityHashCode(filter))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | // List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) { |
| 4378 | // final Iterator<ResolveInfo> i = resolveInfoList.iterator(); |
| 4379 | // final List<ResolveInfo> retList = Lists.newArrayList(); |
| 4380 | // while (i.hasNext()) { |
| 4381 | // final ResolveInfo resolveInfo = i.next(); |
| 4382 | // if (isEnabledLP(resolveInfo.activityInfo)) { |
| 4383 | // retList.add(resolveInfo); |
| 4384 | // } |
| 4385 | // } |
| 4386 | // return retList; |
| 4387 | // } |
| 4388 | |
| 4389 | // Keys are String (activity class name), values are Activity. |
| 4390 | private final HashMap<ComponentName, PackageParser.Activity> mActivities |
| 4391 | = new HashMap<ComponentName, PackageParser.Activity>(); |
| 4392 | private int mFlags; |
| 4393 | } |
| 4394 | |
| 4395 | private final class ServiceIntentResolver |
| 4396 | extends IntentResolver<PackageParser.ServiceIntentInfo, ResolveInfo> { |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4397 | public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4398 | mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0; |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4399 | return super.queryIntent(intent, resolvedType, defaultOnly); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4400 | } |
| 4401 | |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4402 | public List queryIntent(Intent intent, String resolvedType, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | mFlags = flags; |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4404 | return super.queryIntent(intent, resolvedType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4405 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 4406 | } |
| 4407 | |
Dianne Hackborn | c14b9cc | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 4408 | public List queryIntentForPackage(Intent intent, String resolvedType, int flags, |
| 4409 | ArrayList<PackageParser.Service> packageServices) { |
| 4410 | if (packageServices == null) { |
| 4411 | return null; |
| 4412 | } |
| 4413 | mFlags = flags; |
| 4414 | final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0; |
| 4415 | int N = packageServices.size(); |
| 4416 | ArrayList<ArrayList<PackageParser.ServiceIntentInfo>> listCut = |
| 4417 | new ArrayList<ArrayList<PackageParser.ServiceIntentInfo>>(N); |
| 4418 | |
| 4419 | ArrayList<PackageParser.ServiceIntentInfo> intentFilters; |
| 4420 | for (int i = 0; i < N; ++i) { |
| 4421 | intentFilters = packageServices.get(i).intents; |
| 4422 | if (intentFilters != null && intentFilters.size() > 0) { |
| 4423 | listCut.add(intentFilters); |
| 4424 | } |
| 4425 | } |
| 4426 | return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut); |
| 4427 | } |
| 4428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4429 | public final void addService(PackageParser.Service s) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4430 | mServices.put(s.getComponentName(), s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4431 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4432 | TAG, " " + (s.info.nonLocalizedLabel != null |
| 4433 | ? s.info.nonLocalizedLabel : s.info.name) + ":"); |
| 4434 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4435 | TAG, " Class=" + s.info.name); |
| 4436 | int NI = s.intents.size(); |
| 4437 | int j; |
| 4438 | for (j=0; j<NI; j++) { |
| 4439 | PackageParser.ServiceIntentInfo intent = s.intents.get(j); |
| 4440 | if (SHOW_INFO || Config.LOGV) { |
| 4441 | Log.v(TAG, " IntentFilter:"); |
| 4442 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4443 | } |
| 4444 | if (!intent.debugCheck()) { |
| 4445 | Log.w(TAG, "==> For Service " + s.info.name); |
| 4446 | } |
| 4447 | addFilter(intent); |
| 4448 | } |
| 4449 | } |
| 4450 | |
| 4451 | public final void removeService(PackageParser.Service s) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4452 | mServices.remove(s.getComponentName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4453 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4454 | TAG, " " + (s.info.nonLocalizedLabel != null |
| 4455 | ? s.info.nonLocalizedLabel : s.info.name) + ":"); |
| 4456 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4457 | TAG, " Class=" + s.info.name); |
| 4458 | int NI = s.intents.size(); |
| 4459 | int j; |
| 4460 | for (j=0; j<NI; j++) { |
| 4461 | PackageParser.ServiceIntentInfo intent = s.intents.get(j); |
| 4462 | if (SHOW_INFO || Config.LOGV) { |
| 4463 | Log.v(TAG, " IntentFilter:"); |
| 4464 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4465 | } |
| 4466 | removeFilter(intent); |
| 4467 | } |
| 4468 | } |
| 4469 | |
| 4470 | @Override |
| 4471 | protected boolean allowFilterResult( |
| 4472 | PackageParser.ServiceIntentInfo filter, List<ResolveInfo> dest) { |
| 4473 | ServiceInfo filterSi = filter.service.info; |
| 4474 | for (int i=dest.size()-1; i>=0; i--) { |
| 4475 | ServiceInfo destAi = dest.get(i).serviceInfo; |
| 4476 | if (destAi.name == filterSi.name |
| 4477 | && destAi.packageName == filterSi.packageName) { |
| 4478 | return false; |
| 4479 | } |
| 4480 | } |
| 4481 | return true; |
| 4482 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | @Override |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4485 | protected String packageForFilter(PackageParser.ServiceIntentInfo info) { |
| 4486 | return info.service.owner.packageName; |
| 4487 | } |
| 4488 | |
| 4489 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4490 | protected ResolveInfo newResult(PackageParser.ServiceIntentInfo filter, |
| 4491 | int match) { |
| 4492 | final PackageParser.ServiceIntentInfo info = (PackageParser.ServiceIntentInfo)filter; |
| 4493 | if (!mSettings.isEnabledLP(info.service.info, mFlags)) { |
| 4494 | return null; |
| 4495 | } |
| 4496 | final PackageParser.Service service = info.service; |
| 4497 | if (mSafeMode && (service.info.applicationInfo.flags |
| 4498 | &ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 4499 | return null; |
| 4500 | } |
| 4501 | final ResolveInfo res = new ResolveInfo(); |
| 4502 | res.serviceInfo = PackageParser.generateServiceInfo(service, |
| 4503 | mFlags); |
| 4504 | if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) { |
| 4505 | res.filter = filter; |
| 4506 | } |
| 4507 | res.priority = info.getPriority(); |
| 4508 | res.preferredOrder = service.owner.mPreferredOrder; |
| 4509 | //System.out.println("Result: " + res.activityInfo.className + |
| 4510 | // " = " + res.priority); |
| 4511 | res.match = match; |
| 4512 | res.isDefault = info.hasDefault; |
| 4513 | res.labelRes = info.labelRes; |
| 4514 | res.nonLocalizedLabel = info.nonLocalizedLabel; |
| 4515 | res.icon = info.icon; |
| 4516 | return res; |
| 4517 | } |
| 4518 | |
| 4519 | @Override |
| 4520 | protected void sortResults(List<ResolveInfo> results) { |
| 4521 | Collections.sort(results, mResolvePrioritySorter); |
| 4522 | } |
| 4523 | |
| 4524 | @Override |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4525 | protected void dumpFilter(PrintWriter out, String prefix, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4526 | PackageParser.ServiceIntentInfo filter) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4527 | out.print(prefix); out.print( |
| 4528 | Integer.toHexString(System.identityHashCode(filter.service))); |
| 4529 | out.print(' '); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4530 | out.print(filter.service.getComponentShortName()); |
| 4531 | out.print(" filter "); |
| 4532 | out.println(Integer.toHexString(System.identityHashCode(filter))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | // List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) { |
| 4536 | // final Iterator<ResolveInfo> i = resolveInfoList.iterator(); |
| 4537 | // final List<ResolveInfo> retList = Lists.newArrayList(); |
| 4538 | // while (i.hasNext()) { |
| 4539 | // final ResolveInfo resolveInfo = (ResolveInfo) i; |
| 4540 | // if (isEnabledLP(resolveInfo.serviceInfo)) { |
| 4541 | // retList.add(resolveInfo); |
| 4542 | // } |
| 4543 | // } |
| 4544 | // return retList; |
| 4545 | // } |
| 4546 | |
| 4547 | // Keys are String (activity class name), values are Activity. |
| 4548 | private final HashMap<ComponentName, PackageParser.Service> mServices |
| 4549 | = new HashMap<ComponentName, PackageParser.Service>(); |
| 4550 | private int mFlags; |
| 4551 | }; |
| 4552 | |
| 4553 | private static final Comparator<ResolveInfo> mResolvePrioritySorter = |
| 4554 | new Comparator<ResolveInfo>() { |
| 4555 | public int compare(ResolveInfo r1, ResolveInfo r2) { |
| 4556 | int v1 = r1.priority; |
| 4557 | int v2 = r2.priority; |
| 4558 | //System.out.println("Comparing: q1=" + q1 + " q2=" + q2); |
| 4559 | if (v1 != v2) { |
| 4560 | return (v1 > v2) ? -1 : 1; |
| 4561 | } |
| 4562 | v1 = r1.preferredOrder; |
| 4563 | v2 = r2.preferredOrder; |
| 4564 | if (v1 != v2) { |
| 4565 | return (v1 > v2) ? -1 : 1; |
| 4566 | } |
| 4567 | if (r1.isDefault != r2.isDefault) { |
| 4568 | return r1.isDefault ? -1 : 1; |
| 4569 | } |
| 4570 | v1 = r1.match; |
| 4571 | v2 = r2.match; |
| 4572 | //System.out.println("Comparing: m1=" + m1 + " m2=" + m2); |
| 4573 | return (v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0); |
| 4574 | } |
| 4575 | }; |
| 4576 | |
| 4577 | private static final Comparator<ProviderInfo> mProviderInitOrderSorter = |
| 4578 | new Comparator<ProviderInfo>() { |
| 4579 | public int compare(ProviderInfo p1, ProviderInfo p2) { |
| 4580 | final int v1 = p1.initOrder; |
| 4581 | final int v2 = p2.initOrder; |
| 4582 | return (v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0); |
| 4583 | } |
| 4584 | }; |
| 4585 | |
Kenny Root | 93565c4 | 2010-06-18 15:46:06 -0700 | [diff] [blame^] | 4586 | private static final boolean DEBUG_OBB = false; |
| 4587 | |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4588 | private static final void sendPackageBroadcast(String action, String pkg, |
| 4589 | Bundle extras, IIntentReceiver finishedReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4590 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 4591 | if (am != null) { |
| 4592 | try { |
| 4593 | final Intent intent = new Intent(action, |
| 4594 | pkg != null ? Uri.fromParts("package", pkg, null) : null); |
| 4595 | if (extras != null) { |
| 4596 | intent.putExtras(extras); |
| 4597 | } |
Dianne Hackborn | de7faf6 | 2009-06-30 13:27:30 -0700 | [diff] [blame] | 4598 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4599 | am.broadcastIntent(null, intent, null, finishedReceiver, |
| 4600 | 0, null, null, null, finishedReceiver != null, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4601 | } catch (RemoteException ex) { |
| 4602 | } |
| 4603 | } |
| 4604 | } |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 4605 | |
| 4606 | public String nextPackageToClean(String lastPackage) { |
| 4607 | synchronized (mPackages) { |
| 4608 | if (!mMediaMounted) { |
| 4609 | // If the external storage is no longer mounted at this point, |
| 4610 | // the caller may not have been able to delete all of this |
| 4611 | // packages files and can not delete any more. Bail. |
| 4612 | return null; |
| 4613 | } |
| 4614 | if (lastPackage != null) { |
| 4615 | mSettings.mPackagesToBeCleaned.remove(lastPackage); |
| 4616 | } |
| 4617 | return mSettings.mPackagesToBeCleaned.size() > 0 |
| 4618 | ? mSettings.mPackagesToBeCleaned.get(0) : null; |
| 4619 | } |
| 4620 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4621 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 4622 | void schedulePackageCleaning(String packageName) { |
| 4623 | mHandler.sendMessage(mHandler.obtainMessage(START_CLEANING_PACKAGE, packageName)); |
| 4624 | } |
| 4625 | |
| 4626 | void startCleaningPackages() { |
| 4627 | synchronized (mPackages) { |
| 4628 | if (!mMediaMounted) { |
| 4629 | return; |
| 4630 | } |
| 4631 | if (mSettings.mPackagesToBeCleaned.size() <= 0) { |
| 4632 | return; |
| 4633 | } |
| 4634 | } |
| 4635 | Intent intent = new Intent(PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE); |
| 4636 | intent.setComponent(DEFAULT_CONTAINER_COMPONENT); |
| 4637 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 4638 | if (am != null) { |
| 4639 | try { |
| 4640 | am.startService(null, intent, null); |
| 4641 | } catch (RemoteException e) { |
| 4642 | } |
| 4643 | } |
| 4644 | } |
| 4645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4646 | private final class AppDirObserver extends FileObserver { |
| 4647 | public AppDirObserver(String path, int mask, boolean isrom) { |
| 4648 | super(path, mask); |
| 4649 | mRootDir = path; |
| 4650 | mIsRom = isrom; |
| 4651 | } |
| 4652 | |
| 4653 | public void onEvent(int event, String path) { |
| 4654 | String removedPackage = null; |
| 4655 | int removedUid = -1; |
| 4656 | String addedPackage = null; |
| 4657 | int addedUid = -1; |
| 4658 | |
| 4659 | synchronized (mInstallLock) { |
| 4660 | String fullPathStr = null; |
| 4661 | File fullPath = null; |
| 4662 | if (path != null) { |
| 4663 | fullPath = new File(mRootDir, path); |
| 4664 | fullPathStr = fullPath.getPath(); |
| 4665 | } |
| 4666 | |
| 4667 | if (Config.LOGV) Log.v( |
| 4668 | TAG, "File " + fullPathStr + " changed: " |
| 4669 | + Integer.toHexString(event)); |
| 4670 | |
| 4671 | if (!isPackageFilename(path)) { |
| 4672 | if (Config.LOGV) Log.v( |
| 4673 | TAG, "Ignoring change of non-package file: " + fullPathStr); |
| 4674 | return; |
| 4675 | } |
| 4676 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4677 | // Ignore packages that are being installed or |
| 4678 | // have just been installed. |
| 4679 | if (ignoreCodePath(fullPathStr)) { |
| 4680 | return; |
| 4681 | } |
| 4682 | PackageParser.Package p = null; |
| 4683 | synchronized (mPackages) { |
| 4684 | p = mAppDirs.get(fullPathStr); |
| 4685 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4686 | if ((event&REMOVE_EVENTS) != 0) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4687 | if (p != null) { |
| 4688 | removePackageLI(p, true); |
| 4689 | removedPackage = p.applicationInfo.packageName; |
| 4690 | removedUid = p.applicationInfo.uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4691 | } |
| 4692 | } |
| 4693 | |
| 4694 | if ((event&ADD_EVENTS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4695 | if (p == null) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 4696 | p = scanPackageLI(fullPath, |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 4697 | (mIsRom ? PackageParser.PARSE_IS_SYSTEM |
| 4698 | | PackageParser.PARSE_IS_SYSTEM_DIR: 0) | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4699 | PackageParser.PARSE_CHATTY | |
| 4700 | PackageParser.PARSE_MUST_BE_APK, |
Andrew Stadler | 48c0273 | 2010-01-15 00:03:41 -0800 | [diff] [blame] | 4701 | SCAN_MONITOR | SCAN_NO_PATHS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4702 | if (p != null) { |
| 4703 | synchronized (mPackages) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4704 | updatePermissionsLP(p.packageName, p, |
Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 4705 | p.permissions.size() > 0, false, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4706 | } |
| 4707 | addedPackage = p.applicationInfo.packageName; |
| 4708 | addedUid = p.applicationInfo.uid; |
| 4709 | } |
| 4710 | } |
| 4711 | } |
| 4712 | |
| 4713 | synchronized (mPackages) { |
| 4714 | mSettings.writeLP(); |
| 4715 | } |
| 4716 | } |
| 4717 | |
| 4718 | if (removedPackage != null) { |
| 4719 | Bundle extras = new Bundle(1); |
| 4720 | extras.putInt(Intent.EXTRA_UID, removedUid); |
| 4721 | extras.putBoolean(Intent.EXTRA_DATA_REMOVED, false); |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4722 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage, |
| 4723 | extras, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4724 | } |
| 4725 | if (addedPackage != null) { |
| 4726 | Bundle extras = new Bundle(1); |
| 4727 | extras.putInt(Intent.EXTRA_UID, addedUid); |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 4728 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, addedPackage, |
| 4729 | extras, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | private final String mRootDir; |
| 4734 | private final boolean mIsRom; |
| 4735 | } |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | /* Called when a downloaded package installation has been confirmed by the user */ |
| 4738 | public void installPackage( |
| 4739 | final Uri packageURI, final IPackageInstallObserver observer, final int flags) { |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4740 | installPackage(packageURI, observer, flags, null); |
| 4741 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4742 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4743 | /* Called when a downloaded package installation has been confirmed by the user */ |
| 4744 | public void installPackage( |
| 4745 | final Uri packageURI, final IPackageInstallObserver observer, final int flags, |
| 4746 | final String installerPackageName) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4747 | mContext.enforceCallingOrSelfPermission( |
| 4748 | android.Manifest.permission.INSTALL_PACKAGES, null); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4749 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4750 | Message msg = mHandler.obtainMessage(INIT_COPY); |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4751 | msg.obj = new InstallParams(packageURI, observer, flags, |
| 4752 | installerPackageName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4753 | mHandler.sendMessage(msg); |
| 4754 | } |
| 4755 | |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4756 | public void finishPackageInstall(int token) { |
| 4757 | if (DEBUG_INSTALL) Log.v(TAG, "BM finishing package install for " + token); |
| 4758 | Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0); |
| 4759 | mHandler.sendMessage(msg); |
| 4760 | } |
| 4761 | |
Kenny Root | 93565c4 | 2010-06-18 15:46:06 -0700 | [diff] [blame^] | 4762 | public void setPackageObbPath(String packageName, String path) { |
| 4763 | if (DEBUG_OBB) |
| 4764 | Log.v(TAG, "Setting .obb path for " + packageName + " to: " + path); |
| 4765 | PackageSetting pkgSetting; |
| 4766 | final int uid = Binder.getCallingUid(); |
| 4767 | boolean allowedByPermission = false; |
| 4768 | synchronized (mPackages) { |
| 4769 | pkgSetting = mSettings.mPackages.get(packageName); |
| 4770 | if (pkgSetting == null) { |
| 4771 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 4772 | } |
| 4773 | if (!allowedByPermission && (uid != pkgSetting.userId)) { |
| 4774 | throw new SecurityException("Permission denial: attempt to set .obb file from pid=" |
| 4775 | + Binder.getCallingPid() + ", uid=" + uid + ", package uid=" |
| 4776 | + pkgSetting.userId); |
| 4777 | } |
| 4778 | pkgSetting.obbPathString = path; |
| 4779 | mSettings.writeLP(); |
| 4780 | } |
| 4781 | } |
| 4782 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4783 | private void processPendingInstall(final InstallArgs args, final int currentStatus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4784 | // Queue up an async operation since the package installation may take a little while. |
| 4785 | mHandler.post(new Runnable() { |
| 4786 | public void run() { |
| 4787 | mHandler.removeCallbacks(this); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4788 | // Result object to be returned |
| 4789 | PackageInstalledInfo res = new PackageInstalledInfo(); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4790 | res.returnCode = currentStatus; |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4791 | res.uid = -1; |
| 4792 | res.pkg = null; |
| 4793 | res.removedInfo = new PackageRemovedInfo(); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4794 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) { |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4795 | args.doPreInstall(res.returnCode); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4796 | synchronized (mInstallLock) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4797 | installPackageLI(args, true, res); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4798 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4799 | args.doPostInstall(res.returnCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4800 | } |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4801 | |
| 4802 | // A restore should be performed at this point if (a) the install |
| 4803 | // succeeded, (b) the operation is not an update, and (c) the new |
| 4804 | // package has a backupAgent defined. |
| 4805 | final boolean update = res.removedInfo.removedPackage != null; |
Christopher Tate | 59eac4b | 2010-02-19 19:25:45 -0800 | [diff] [blame] | 4806 | boolean doRestore = (!update |
| 4807 | && res.pkg != null |
| 4808 | && res.pkg.applicationInfo.backupAgentName != null); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4809 | |
| 4810 | // Set up the post-install work request bookkeeping. This will be used |
| 4811 | // and cleaned up by the post-install event handling regardless of whether |
| 4812 | // there's a restore pass performed. Token values are >= 1. |
| 4813 | int token; |
| 4814 | if (mNextInstallToken < 0) mNextInstallToken = 1; |
| 4815 | token = mNextInstallToken++; |
| 4816 | |
| 4817 | PostInstallData data = new PostInstallData(args, res); |
| 4818 | mRunningInstalls.put(token, data); |
| 4819 | if (DEBUG_INSTALL) Log.v(TAG, "+ starting restore round-trip " + token); |
| 4820 | |
| 4821 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED && doRestore) { |
| 4822 | // Pass responsibility to the Backup Manager. It will perform a |
| 4823 | // restore if appropriate, then pass responsibility back to the |
| 4824 | // Package Manager to run the post-install observer callbacks |
| 4825 | // and broadcasts. |
| 4826 | IBackupManager bm = IBackupManager.Stub.asInterface( |
| 4827 | ServiceManager.getService(Context.BACKUP_SERVICE)); |
| 4828 | if (bm != null) { |
| 4829 | if (DEBUG_INSTALL) Log.v(TAG, "token " + token |
| 4830 | + " to BM for possible restore"); |
| 4831 | try { |
| 4832 | bm.restoreAtInstall(res.pkg.applicationInfo.packageName, token); |
| 4833 | } catch (RemoteException e) { |
| 4834 | // can't happen; the backup manager is local |
| 4835 | } catch (Exception e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4836 | Slog.e(TAG, "Exception trying to enqueue restore", e); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4837 | doRestore = false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4838 | } |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4839 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4840 | Slog.e(TAG, "Backup Manager not found!"); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4841 | doRestore = false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4842 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4843 | } |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4844 | |
| 4845 | if (!doRestore) { |
| 4846 | // No restore possible, or the Backup Manager was mysteriously not |
| 4847 | // available -- just fire the post-install work request directly. |
| 4848 | if (DEBUG_INSTALL) Log.v(TAG, "No restore - queue post-install for " + token); |
| 4849 | Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0); |
| 4850 | mHandler.sendMessage(msg); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4851 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4852 | } |
| 4853 | }); |
| 4854 | } |
| 4855 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4856 | abstract class HandlerParams { |
| 4857 | final static int MAX_RETRIES = 4; |
| 4858 | int retry = 0; |
| 4859 | final void startCopy() { |
| 4860 | try { |
| 4861 | if (DEBUG_SD_INSTALL) Log.i(TAG, "startCopy"); |
| 4862 | retry++; |
| 4863 | if (retry > MAX_RETRIES) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4864 | 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] | 4865 | mHandler.sendEmptyMessage(MCS_GIVE_UP); |
| 4866 | handleServiceError(); |
| 4867 | return; |
| 4868 | } else { |
| 4869 | handleStartCopy(); |
| 4870 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Posting install MCS_UNBIND"); |
| 4871 | mHandler.sendEmptyMessage(MCS_UNBIND); |
| 4872 | } |
| 4873 | } catch (RemoteException e) { |
| 4874 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Posting install MCS_RECONNECT"); |
| 4875 | mHandler.sendEmptyMessage(MCS_RECONNECT); |
| 4876 | } |
| 4877 | handleReturnCode(); |
| 4878 | } |
| 4879 | |
| 4880 | final void serviceError() { |
| 4881 | if (DEBUG_SD_INSTALL) Log.i(TAG, "serviceError"); |
| 4882 | handleServiceError(); |
| 4883 | handleReturnCode(); |
| 4884 | } |
| 4885 | abstract void handleStartCopy() throws RemoteException; |
| 4886 | abstract void handleServiceError(); |
| 4887 | abstract void handleReturnCode(); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4888 | } |
| 4889 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4890 | class InstallParams extends HandlerParams { |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4891 | final IPackageInstallObserver observer; |
| 4892 | int flags; |
| 4893 | final Uri packageURI; |
| 4894 | final String installerPackageName; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4895 | private InstallArgs mArgs; |
| 4896 | private int mRet; |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4897 | InstallParams(Uri packageURI, |
| 4898 | IPackageInstallObserver observer, int flags, |
| 4899 | String installerPackageName) { |
| 4900 | this.packageURI = packageURI; |
| 4901 | this.flags = flags; |
| 4902 | this.observer = observer; |
| 4903 | this.installerPackageName = installerPackageName; |
| 4904 | } |
| 4905 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4906 | private int installLocationPolicy(PackageInfoLite pkgLite, int flags) { |
| 4907 | String packageName = pkgLite.packageName; |
| 4908 | int installLocation = pkgLite.installLocation; |
| 4909 | boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0; |
| 4910 | synchronized (mPackages) { |
| 4911 | PackageParser.Package pkg = mPackages.get(packageName); |
| 4912 | if (pkg != null) { |
| 4913 | if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
| 4914 | // Check for updated system application. |
| 4915 | if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4916 | if (onSd) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4917 | Slog.w(TAG, "Cannot install update to system app on sdcard"); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4918 | return PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION; |
| 4919 | } |
| 4920 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
| 4921 | } else { |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4922 | if (onSd) { |
| 4923 | // Install flag overrides everything. |
| 4924 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4925 | } |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4926 | // If current upgrade specifies particular preference |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4927 | if (installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) { |
| 4928 | // Application explicitly specified internal. |
| 4929 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
| 4930 | } else if (installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) { |
| 4931 | // App explictly prefers external. Let policy decide |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4932 | } else { |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4933 | // Prefer previous location |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4934 | if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) { |
| 4935 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4936 | } |
| 4937 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4938 | } |
| 4939 | } |
| 4940 | } else { |
| 4941 | // Invalid install. Return error code |
| 4942 | return PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS; |
| 4943 | } |
| 4944 | } |
| 4945 | } |
| 4946 | // All the special cases have been taken care of. |
| 4947 | // Return result based on recommended install location. |
| 4948 | if (onSd) { |
| 4949 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4950 | } |
| 4951 | return pkgLite.recommendedInstallLocation; |
| 4952 | } |
| 4953 | |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4954 | /* |
| 4955 | * Invoke remote method to get package information and install |
| 4956 | * location values. Override install location based on default |
| 4957 | * policy if needed and then create install arguments based |
| 4958 | * on the install location. |
| 4959 | */ |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4960 | public void handleStartCopy() throws RemoteException { |
Suchi Amalapurapu | 1f9e1b4 | 2010-02-26 13:14:31 -0800 | [diff] [blame] | 4961 | int ret = PackageManager.INSTALL_SUCCEEDED; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4962 | boolean fwdLocked = (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0; |
| 4963 | boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0; |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4964 | boolean onInt = (flags & PackageManager.INSTALL_INTERNAL) != 0; |
| 4965 | if (onInt && onSd) { |
| 4966 | // Check if both bits are set. |
| 4967 | Slog.w(TAG, "Conflicting flags specified for installing on both internal and external"); |
| 4968 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 4969 | } else if (fwdLocked && onSd) { |
| 4970 | // Check for forward locked apps |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4971 | Slog.w(TAG, "Cannot install fwd locked apps on sdcard"); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4972 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4973 | } else { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4974 | // Remote call to find out default install location |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4975 | PackageInfoLite pkgLite = mContainerService.getMinimalPackageInfo(packageURI, flags); |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4976 | int loc = pkgLite.recommendedInstallLocation; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4977 | if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION){ |
| 4978 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 4979 | } else if (loc == PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS){ |
| 4980 | ret = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 4981 | } else if (loc == PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE){ |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4982 | ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4983 | } else if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_APK) { |
| 4984 | ret = PackageManager.INSTALL_FAILED_INVALID_APK; |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4985 | } else if (loc == PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE) { |
| 4986 | ret = PackageManager.INSTALL_FAILED_MEDIA_UNAVAILABLE; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4987 | } else { |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4988 | // Override with defaults if needed. |
| 4989 | loc = installLocationPolicy(pkgLite, flags); |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4990 | if (!onSd && !onInt) { |
| 4991 | // Override install location with flags |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4992 | if (loc == PackageHelper.RECOMMEND_INSTALL_EXTERNAL) { |
| 4993 | // Set the flag to install on external media. |
| 4994 | flags |= PackageManager.INSTALL_EXTERNAL; |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4995 | flags &= ~PackageManager.INSTALL_INTERNAL; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4996 | } else { |
| 4997 | // Make sure the flag for installing on external |
| 4998 | // media is unset |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4999 | flags |= PackageManager.INSTALL_INTERNAL; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5000 | flags &= ~PackageManager.INSTALL_EXTERNAL; |
| 5001 | } |
| 5002 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5003 | } |
| 5004 | } |
| 5005 | // Create the file args now. |
| 5006 | mArgs = createInstallArgs(this); |
| 5007 | if (ret == PackageManager.INSTALL_SUCCEEDED) { |
| 5008 | // Create copy only if we are not in an erroneous state. |
| 5009 | // Remote call to initiate copy using temporary file |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5010 | ret = mArgs.copyApk(mContainerService, true); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5011 | } |
| 5012 | mRet = ret; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5013 | } |
| 5014 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5015 | @Override |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5016 | void handleReturnCode() { |
| 5017 | processPendingInstall(mArgs, mRet); |
| 5018 | } |
| 5019 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5020 | @Override |
| 5021 | void handleServiceError() { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5022 | mArgs = createInstallArgs(this); |
| 5023 | mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5024 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5025 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5026 | |
| 5027 | /* |
| 5028 | * Utility class used in movePackage api. |
| 5029 | * srcArgs and targetArgs are not set for invalid flags and make |
| 5030 | * sure to do null checks when invoking methods on them. |
| 5031 | * We probably want to return ErrorPrams for both failed installs |
| 5032 | * and moves. |
| 5033 | */ |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5034 | class MoveParams extends HandlerParams { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5035 | final IPackageMoveObserver observer; |
| 5036 | final int flags; |
| 5037 | final String packageName; |
| 5038 | final InstallArgs srcArgs; |
| 5039 | final InstallArgs targetArgs; |
| 5040 | int mRet; |
| 5041 | MoveParams(InstallArgs srcArgs, |
| 5042 | IPackageMoveObserver observer, |
| 5043 | int flags, String packageName) { |
| 5044 | this.srcArgs = srcArgs; |
| 5045 | this.observer = observer; |
| 5046 | this.flags = flags; |
| 5047 | this.packageName = packageName; |
| 5048 | if (srcArgs != null) { |
| 5049 | Uri packageUri = Uri.fromFile(new File(srcArgs.getCodePath())); |
| 5050 | targetArgs = createInstallArgs(packageUri, flags, packageName); |
| 5051 | } else { |
| 5052 | targetArgs = null; |
| 5053 | } |
| 5054 | } |
| 5055 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5056 | public void handleStartCopy() throws RemoteException { |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 5057 | mRet = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5058 | // Check for storage space on target medium |
| 5059 | if (!targetArgs.checkFreeStorage(mContainerService)) { |
| 5060 | Log.w(TAG, "Insufficient storage to install"); |
| 5061 | return; |
| 5062 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5063 | // Create the file args now. |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5064 | mRet = targetArgs.copyApk(mContainerService, false); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5065 | targetArgs.doPreInstall(mRet); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5066 | if (DEBUG_SD_INSTALL) { |
| 5067 | StringBuilder builder = new StringBuilder(); |
| 5068 | if (srcArgs != null) { |
| 5069 | builder.append("src: "); |
| 5070 | builder.append(srcArgs.getCodePath()); |
| 5071 | } |
| 5072 | if (targetArgs != null) { |
| 5073 | builder.append(" target : "); |
| 5074 | builder.append(targetArgs.getCodePath()); |
| 5075 | } |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 5076 | Log.i(TAG, builder.toString()); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5077 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5078 | } |
| 5079 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5080 | @Override |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5081 | void handleReturnCode() { |
| 5082 | targetArgs.doPostInstall(mRet); |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 5083 | int currentStatus = PackageManager.MOVE_FAILED_INTERNAL_ERROR; |
| 5084 | if (mRet == PackageManager.INSTALL_SUCCEEDED) { |
| 5085 | currentStatus = PackageManager.MOVE_SUCCEEDED; |
| 5086 | } else if (mRet == PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE){ |
| 5087 | currentStatus = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE; |
| 5088 | } |
| 5089 | processPendingMove(this, currentStatus); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5090 | } |
| 5091 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5092 | @Override |
| 5093 | void handleServiceError() { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5094 | mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5095 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5096 | } |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5097 | |
| 5098 | private InstallArgs createInstallArgs(InstallParams params) { |
| 5099 | if (installOnSd(params.flags)) { |
| 5100 | return new SdInstallArgs(params); |
| 5101 | } else { |
| 5102 | return new FileInstallArgs(params); |
| 5103 | } |
| 5104 | } |
| 5105 | |
| 5106 | private InstallArgs createInstallArgs(int flags, String fullCodePath, String fullResourcePath) { |
| 5107 | if (installOnSd(flags)) { |
| 5108 | return new SdInstallArgs(fullCodePath, fullResourcePath); |
| 5109 | } else { |
| 5110 | return new FileInstallArgs(fullCodePath, fullResourcePath); |
| 5111 | } |
| 5112 | } |
| 5113 | |
Suchi Amalapurapu | 9a212ad | 2010-05-18 11:06:53 -0700 | [diff] [blame] | 5114 | private InstallArgs createInstallArgs(Uri packageURI, int flags, |
| 5115 | String pkgName) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5116 | if (installOnSd(flags)) { |
| 5117 | String cid = getNextCodePath(null, pkgName, "/" + SdInstallArgs.RES_FILE_NAME); |
| 5118 | return new SdInstallArgs(packageURI, cid); |
| 5119 | } else { |
| 5120 | return new FileInstallArgs(packageURI, pkgName); |
| 5121 | } |
| 5122 | } |
| 5123 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5124 | static abstract class InstallArgs { |
| 5125 | final IPackageInstallObserver observer; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5126 | // Always refers to PackageManager flags only |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5127 | final int flags; |
| 5128 | final Uri packageURI; |
| 5129 | final String installerPackageName; |
| 5130 | |
| 5131 | InstallArgs(Uri packageURI, |
| 5132 | IPackageInstallObserver observer, int flags, |
| 5133 | String installerPackageName) { |
| 5134 | this.packageURI = packageURI; |
| 5135 | this.flags = flags; |
| 5136 | this.observer = observer; |
| 5137 | this.installerPackageName = installerPackageName; |
| 5138 | } |
| 5139 | |
| 5140 | abstract void createCopyFile(); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5141 | abstract int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5142 | abstract int doPreInstall(int status); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5143 | abstract boolean doRename(int status, String pkgName, String oldCodePath); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5144 | abstract int doPostInstall(int status); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5145 | abstract String getCodePath(); |
| 5146 | abstract String getResourcePath(); |
| 5147 | // Need installer lock especially for dex file removal. |
| 5148 | abstract void cleanUpResourcesLI(); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5149 | abstract boolean doPostDeleteLI(boolean delete); |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 5150 | abstract boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5151 | } |
| 5152 | |
| 5153 | class FileInstallArgs extends InstallArgs { |
| 5154 | File installDir; |
| 5155 | String codeFileName; |
| 5156 | String resourceFileName; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5157 | boolean created = false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5158 | |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5159 | FileInstallArgs(InstallParams params) { |
| 5160 | super(params.packageURI, params.observer, |
| 5161 | params.flags, params.installerPackageName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5162 | } |
| 5163 | |
| 5164 | FileInstallArgs(String fullCodePath, String fullResourcePath) { |
| 5165 | super(null, null, 0, null); |
| 5166 | File codeFile = new File(fullCodePath); |
| 5167 | installDir = codeFile.getParentFile(); |
| 5168 | codeFileName = fullCodePath; |
| 5169 | resourceFileName = fullResourcePath; |
| 5170 | } |
| 5171 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5172 | FileInstallArgs(Uri packageURI, String pkgName) { |
| 5173 | super(packageURI, null, 0, null); |
| 5174 | boolean fwdLocked = isFwdLocked(flags); |
| 5175 | installDir = fwdLocked ? mDrmAppPrivateInstallDir : mAppInstallDir; |
| 5176 | String apkName = getNextCodePath(null, pkgName, ".apk"); |
| 5177 | codeFileName = new File(installDir, apkName + ".apk").getPath(); |
| 5178 | resourceFileName = getResourcePathFromCodePath(); |
| 5179 | } |
| 5180 | |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 5181 | boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException { |
| 5182 | return imcs.checkFreeStorage(false, packageURI); |
| 5183 | } |
| 5184 | |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5185 | String getCodePath() { |
| 5186 | return codeFileName; |
| 5187 | } |
| 5188 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5189 | void createCopyFile() { |
| 5190 | boolean fwdLocked = isFwdLocked(flags); |
| 5191 | installDir = fwdLocked ? mDrmAppPrivateInstallDir : mAppInstallDir; |
| 5192 | codeFileName = createTempPackageFile(installDir).getPath(); |
| 5193 | resourceFileName = getResourcePathFromCodePath(); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5194 | created = true; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5195 | } |
| 5196 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5197 | int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5198 | if (temp) { |
| 5199 | // Generate temp file name |
| 5200 | createCopyFile(); |
| 5201 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5202 | // Get a ParcelFileDescriptor to write to the output file |
| 5203 | File codeFile = new File(codeFileName); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5204 | if (!created) { |
| 5205 | try { |
| 5206 | codeFile.createNewFile(); |
| 5207 | // Set permissions |
| 5208 | if (!setPermissions()) { |
| 5209 | // Failed setting permissions. |
| 5210 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5211 | } |
| 5212 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5213 | Slog.w(TAG, "Failed to create file " + codeFile); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5214 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5215 | } |
| 5216 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5217 | ParcelFileDescriptor out = null; |
| 5218 | try { |
| 5219 | out = ParcelFileDescriptor.open(codeFile, |
| 5220 | ParcelFileDescriptor.MODE_READ_WRITE); |
| 5221 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5222 | Slog.e(TAG, "Failed to create file descritpor for : " + codeFileName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5223 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5224 | } |
| 5225 | // Copy the resource now |
| 5226 | int ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5227 | try { |
| 5228 | if (imcs.copyResource(packageURI, out)) { |
| 5229 | ret = PackageManager.INSTALL_SUCCEEDED; |
| 5230 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5231 | } finally { |
| 5232 | try { if (out != null) out.close(); } catch (IOException e) {} |
| 5233 | } |
| 5234 | return ret; |
| 5235 | } |
| 5236 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5237 | int doPreInstall(int status) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5238 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5239 | cleanUp(); |
| 5240 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5241 | return status; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | boolean doRename(int status, final String pkgName, String oldCodePath) { |
| 5245 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5246 | cleanUp(); |
| 5247 | return false; |
| 5248 | } else { |
| 5249 | // Rename based on packageName |
| 5250 | File codeFile = new File(getCodePath()); |
| 5251 | String apkName = getNextCodePath(oldCodePath, pkgName, ".apk"); |
| 5252 | File desFile = new File(installDir, apkName + ".apk"); |
| 5253 | if (!codeFile.renameTo(desFile)) { |
| 5254 | return false; |
| 5255 | } |
| 5256 | // Reset paths since the file has been renamed. |
| 5257 | codeFileName = desFile.getPath(); |
| 5258 | resourceFileName = getResourcePathFromCodePath(); |
| 5259 | // Set permissions |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5260 | if (!setPermissions()) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5261 | // Failed setting permissions. |
| 5262 | return false; |
| 5263 | } |
| 5264 | return true; |
| 5265 | } |
| 5266 | } |
| 5267 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5268 | int doPostInstall(int status) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5269 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5270 | cleanUp(); |
| 5271 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5272 | return status; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | String getResourcePath() { |
| 5276 | return resourceFileName; |
| 5277 | } |
| 5278 | |
| 5279 | String getResourcePathFromCodePath() { |
| 5280 | String codePath = getCodePath(); |
| 5281 | if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { |
| 5282 | String apkNameOnly = getApkName(codePath); |
| 5283 | return mAppInstallDir.getPath() + "/" + apkNameOnly + ".zip"; |
| 5284 | } else { |
| 5285 | return codePath; |
| 5286 | } |
| 5287 | } |
| 5288 | |
| 5289 | private boolean cleanUp() { |
| 5290 | boolean ret = true; |
| 5291 | String sourceDir = getCodePath(); |
| 5292 | String publicSourceDir = getResourcePath(); |
| 5293 | if (sourceDir != null) { |
| 5294 | File sourceFile = new File(sourceDir); |
| 5295 | if (!sourceFile.exists()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5296 | Slog.w(TAG, "Package source " + sourceDir + " does not exist."); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5297 | ret = false; |
| 5298 | } |
| 5299 | // Delete application's code and resources |
| 5300 | sourceFile.delete(); |
| 5301 | } |
| 5302 | if (publicSourceDir != null && !publicSourceDir.equals(sourceDir)) { |
| 5303 | final File publicSourceFile = new File(publicSourceDir); |
| 5304 | if (!publicSourceFile.exists()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5305 | Slog.w(TAG, "Package public source " + publicSourceFile + " does not exist."); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5306 | } |
| 5307 | if (publicSourceFile.exists()) { |
| 5308 | publicSourceFile.delete(); |
| 5309 | } |
| 5310 | } |
| 5311 | return ret; |
| 5312 | } |
| 5313 | |
| 5314 | void cleanUpResourcesLI() { |
| 5315 | String sourceDir = getCodePath(); |
| 5316 | if (cleanUp() && mInstaller != null) { |
| 5317 | int retCode = mInstaller.rmdex(sourceDir); |
| 5318 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5319 | Slog.w(TAG, "Couldn't remove dex file for package: " |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5320 | + " at location " |
| 5321 | + sourceDir + ", retcode=" + retCode); |
| 5322 | // we don't consider this to be a failure of the core package deletion |
| 5323 | } |
| 5324 | } |
| 5325 | } |
| 5326 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5327 | private boolean setPermissions() { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5328 | // TODO Do this in a more elegant way later on. for now just a hack |
| 5329 | if (!isFwdLocked(flags)) { |
| 5330 | final int filePermissions = |
| 5331 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP |
| 5332 | |FileUtils.S_IROTH; |
| 5333 | int retCode = FileUtils.setPermissions(getCodePath(), filePermissions, -1, -1); |
| 5334 | if (retCode != 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5335 | Slog.e(TAG, "Couldn't set new package file permissions for " + |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5336 | getCodePath() |
| 5337 | + ". The return code was: " + retCode); |
| 5338 | // TODO Define new internal error |
| 5339 | return false; |
| 5340 | } |
| 5341 | return true; |
| 5342 | } |
| 5343 | return true; |
| 5344 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5345 | |
| 5346 | boolean doPostDeleteLI(boolean delete) { |
| 5347 | cleanUpResourcesLI(); |
| 5348 | return true; |
| 5349 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | class SdInstallArgs extends InstallArgs { |
| 5353 | String cid; |
| 5354 | String cachePath; |
| 5355 | static final String RES_FILE_NAME = "pkg.apk"; |
| 5356 | |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5357 | SdInstallArgs(InstallParams params) { |
| 5358 | super(params.packageURI, params.observer, |
| 5359 | params.flags, params.installerPackageName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | SdInstallArgs(String fullCodePath, String fullResourcePath) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5363 | super(null, null, PackageManager.INSTALL_EXTERNAL, null); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5364 | // Extract cid from fullCodePath |
| 5365 | int eidx = fullCodePath.lastIndexOf("/"); |
| 5366 | String subStr1 = fullCodePath.substring(0, eidx); |
| 5367 | int sidx = subStr1.lastIndexOf("/"); |
| 5368 | cid = subStr1.substring(sidx+1, eidx); |
| 5369 | cachePath = subStr1; |
| 5370 | } |
| 5371 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5372 | SdInstallArgs(String cid) { |
Dianne Hackborn | aa77de1 | 2010-05-14 22:33:54 -0700 | [diff] [blame] | 5373 | super(null, null, PackageManager.INSTALL_EXTERNAL, null); |
| 5374 | this.cid = cid; |
Suchi Amalapurapu | 9a212ad | 2010-05-18 11:06:53 -0700 | [diff] [blame] | 5375 | cachePath = PackageHelper.getSdDir(cid); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | SdInstallArgs(Uri packageURI, String cid) { |
| 5379 | super(packageURI, null, PackageManager.INSTALL_EXTERNAL, null); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5380 | this.cid = cid; |
| 5381 | } |
| 5382 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5383 | void createCopyFile() { |
| 5384 | cid = getTempContainerId(); |
| 5385 | } |
| 5386 | |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 5387 | boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException { |
| 5388 | return imcs.checkFreeStorage(true, packageURI); |
| 5389 | } |
| 5390 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5391 | int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5392 | if (temp) { |
| 5393 | createCopyFile(); |
| 5394 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5395 | cachePath = imcs.copyResourceToContainer( |
| 5396 | packageURI, cid, |
| 5397 | getEncryptKey(), RES_FILE_NAME); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5398 | return (cachePath == null) ? PackageManager.INSTALL_FAILED_CONTAINER_ERROR : |
| 5399 | PackageManager.INSTALL_SUCCEEDED; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | @Override |
| 5403 | String getCodePath() { |
| 5404 | return cachePath + "/" + RES_FILE_NAME; |
| 5405 | } |
| 5406 | |
| 5407 | @Override |
| 5408 | String getResourcePath() { |
| 5409 | return cachePath + "/" + RES_FILE_NAME; |
| 5410 | } |
| 5411 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5412 | int doPreInstall(int status) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5413 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5414 | // Destroy container |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5415 | PackageHelper.destroySdDir(cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5416 | } else { |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5417 | boolean mounted = PackageHelper.isContainerMounted(cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5418 | if (!mounted) { |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5419 | cachePath = PackageHelper.mountSdDir(cid, getEncryptKey(), Process.SYSTEM_UID); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5420 | if (cachePath == null) { |
| 5421 | return PackageManager.INSTALL_FAILED_CONTAINER_ERROR; |
| 5422 | } |
| 5423 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5424 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5425 | return status; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5426 | } |
| 5427 | |
| 5428 | boolean doRename(int status, final String pkgName, |
| 5429 | String oldCodePath) { |
| 5430 | String newCacheId = getNextCodePath(oldCodePath, pkgName, "/" + RES_FILE_NAME); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5431 | String newCachePath = null; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5432 | if (PackageHelper.isContainerMounted(cid)) { |
| 5433 | // Unmount the container |
| 5434 | if (!PackageHelper.unMountSdDir(cid)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5435 | Slog.i(TAG, "Failed to unmount " + cid + " before renaming"); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5436 | return false; |
| 5437 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5438 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5439 | if (!PackageHelper.renameSdDir(cid, newCacheId)) { |
Suchi Amalapurapu | c7537ee | 2010-03-24 09:27:19 -0700 | [diff] [blame] | 5440 | Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId + |
| 5441 | " which might be stale. Will try to clean up."); |
| 5442 | // Clean up the stale container and proceed to recreate. |
| 5443 | if (!PackageHelper.destroySdDir(newCacheId)) { |
| 5444 | Slog.e(TAG, "Very strange. Cannot clean up stale container " + newCacheId); |
| 5445 | return false; |
| 5446 | } |
| 5447 | // Successfully cleaned up stale container. Try to rename again. |
| 5448 | if (!PackageHelper.renameSdDir(cid, newCacheId)) { |
| 5449 | Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId |
| 5450 | + " inspite of cleaning it up."); |
| 5451 | return false; |
| 5452 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5453 | } |
| 5454 | if (!PackageHelper.isContainerMounted(newCacheId)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5455 | Slog.w(TAG, "Mounting container " + newCacheId); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5456 | newCachePath = PackageHelper.mountSdDir(newCacheId, |
| 5457 | getEncryptKey(), Process.SYSTEM_UID); |
| 5458 | } else { |
| 5459 | newCachePath = PackageHelper.getSdDir(newCacheId); |
| 5460 | } |
| 5461 | if (newCachePath == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5462 | Slog.w(TAG, "Failed to get cache path for " + newCacheId); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5463 | return false; |
| 5464 | } |
| 5465 | Log.i(TAG, "Succesfully renamed " + cid + |
| 5466 | " at path: " + cachePath + " to " + newCacheId + |
| 5467 | " at new path: " + newCachePath); |
| 5468 | cid = newCacheId; |
| 5469 | cachePath = newCachePath; |
| 5470 | return true; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5471 | } |
| 5472 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5473 | int doPostInstall(int status) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5474 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5475 | cleanUp(); |
| 5476 | } else { |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5477 | boolean mounted = PackageHelper.isContainerMounted(cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5478 | if (!mounted) { |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5479 | PackageHelper.mountSdDir(cid, |
| 5480 | getEncryptKey(), Process.myUid()); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5481 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5482 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5483 | return status; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | private void cleanUp() { |
| 5487 | // Destroy secure container |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5488 | PackageHelper.destroySdDir(cid); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5489 | } |
| 5490 | |
| 5491 | void cleanUpResourcesLI() { |
| 5492 | String sourceFile = getCodePath(); |
| 5493 | // Remove dex file |
| 5494 | if (mInstaller != null) { |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 5495 | int retCode = mInstaller.rmdex(sourceFile); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5496 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5497 | Slog.w(TAG, "Couldn't remove dex file for package: " |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5498 | + " at location " |
| 5499 | + sourceFile.toString() + ", retcode=" + retCode); |
| 5500 | // we don't consider this to be a failure of the core package deletion |
| 5501 | } |
| 5502 | } |
| 5503 | cleanUp(); |
| 5504 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5505 | |
| 5506 | boolean matchContainer(String app) { |
| 5507 | if (cid.startsWith(app)) { |
| 5508 | return true; |
| 5509 | } |
| 5510 | return false; |
| 5511 | } |
| 5512 | |
| 5513 | String getPackageName() { |
| 5514 | int idx = cid.lastIndexOf("-"); |
| 5515 | if (idx == -1) { |
| 5516 | return cid; |
| 5517 | } |
| 5518 | return cid.substring(0, idx); |
| 5519 | } |
| 5520 | |
| 5521 | boolean doPostDeleteLI(boolean delete) { |
| 5522 | boolean ret = false; |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5523 | boolean mounted = PackageHelper.isContainerMounted(cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5524 | if (mounted) { |
| 5525 | // Unmount first |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5526 | ret = PackageHelper.unMountSdDir(cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5527 | } |
| 5528 | if (ret && delete) { |
| 5529 | cleanUpResourcesLI(); |
| 5530 | } |
| 5531 | return ret; |
| 5532 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5533 | }; |
| 5534 | |
| 5535 | // Utility method used to create code paths based on package name and available index. |
| 5536 | private static String getNextCodePath(String oldCodePath, String prefix, String suffix) { |
| 5537 | String idxStr = ""; |
| 5538 | int idx = 1; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5539 | // Fall back to default value of idx=1 if prefix is not |
| 5540 | // part of oldCodePath |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5541 | if (oldCodePath != null) { |
Bjorn Bringert | 5fd5bfe | 2010-01-29 12:11:30 +0000 | [diff] [blame] | 5542 | String subStr = oldCodePath; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5543 | // Drop the suffix right away |
Bjorn Bringert | 5fd5bfe | 2010-01-29 12:11:30 +0000 | [diff] [blame] | 5544 | if (subStr.endsWith(suffix)) { |
| 5545 | subStr = subStr.substring(0, subStr.length() - suffix.length()); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5546 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5547 | // If oldCodePath already contains prefix find out the |
| 5548 | // ending index to either increment or decrement. |
| 5549 | int sidx = subStr.lastIndexOf(prefix); |
| 5550 | if (sidx != -1) { |
| 5551 | subStr = subStr.substring(sidx + prefix.length()); |
| 5552 | if (subStr != null) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5553 | if (subStr.startsWith(INSTALL_PACKAGE_SUFFIX)) { |
| 5554 | subStr = subStr.substring(INSTALL_PACKAGE_SUFFIX.length()); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5555 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5556 | try { |
| 5557 | idx = Integer.parseInt(subStr); |
| 5558 | if (idx <= 1) { |
| 5559 | idx++; |
| 5560 | } else { |
| 5561 | idx--; |
| 5562 | } |
| 5563 | } catch(NumberFormatException e) { |
| 5564 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5565 | } |
| 5566 | } |
| 5567 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5568 | idxStr = INSTALL_PACKAGE_SUFFIX + Integer.toString(idx); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5569 | return prefix + idxStr; |
| 5570 | } |
| 5571 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5572 | // Utility method used to ignore ADD/REMOVE events |
| 5573 | // by directory observer. |
| 5574 | private static boolean ignoreCodePath(String fullPathStr) { |
| 5575 | String apkName = getApkName(fullPathStr); |
| 5576 | int idx = apkName.lastIndexOf(INSTALL_PACKAGE_SUFFIX); |
| 5577 | if (idx != -1 && ((idx+1) < apkName.length())) { |
| 5578 | // Make sure the package ends with a numeral |
| 5579 | String version = apkName.substring(idx+1); |
| 5580 | try { |
| 5581 | Integer.parseInt(version); |
| 5582 | return true; |
| 5583 | } catch (NumberFormatException e) {} |
| 5584 | } |
| 5585 | return false; |
| 5586 | } |
| 5587 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5588 | // Utility method that returns the relative package path with respect |
| 5589 | // to the installation directory. Like say for /data/data/com.test-1.apk |
| 5590 | // string com.test-1 is returned. |
| 5591 | static String getApkName(String codePath) { |
| 5592 | if (codePath == null) { |
| 5593 | return null; |
| 5594 | } |
| 5595 | int sidx = codePath.lastIndexOf("/"); |
| 5596 | int eidx = codePath.lastIndexOf("."); |
| 5597 | if (eidx == -1) { |
| 5598 | eidx = codePath.length(); |
| 5599 | } else if (eidx == 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5600 | Slog.w(TAG, " Invalid code path, "+ codePath + " Not a valid apk name"); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5601 | return null; |
| 5602 | } |
| 5603 | return codePath.substring(sidx+1, eidx); |
| 5604 | } |
| 5605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5606 | class PackageInstalledInfo { |
| 5607 | String name; |
| 5608 | int uid; |
| 5609 | PackageParser.Package pkg; |
| 5610 | int returnCode; |
| 5611 | PackageRemovedInfo removedInfo; |
| 5612 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5613 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5614 | /* |
| 5615 | * Install a non-existing package. |
| 5616 | */ |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5617 | private void installNewPackageLI(PackageParser.Package pkg, |
| 5618 | int parseFlags, |
| 5619 | int scanMode, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5620 | String installerPackageName, PackageInstalledInfo res) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5621 | // Remember this for later, in case we need to rollback this install |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5622 | String pkgName = pkg.packageName; |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 5623 | |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 5624 | boolean dataDirExists = getDataPathForPackage(pkg).exists(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5625 | res.name = pkgName; |
| 5626 | synchronized(mPackages) { |
Dianne Hackborn | e259bc7 | 2010-03-30 19:24:44 -0700 | [diff] [blame] | 5627 | if (mSettings.mRenamedPackages.containsKey(pkgName)) { |
| 5628 | // A package with the same name is already installed, though |
| 5629 | // it has been renamed to an older name. The package we |
| 5630 | // are trying to install should be installed as an update to |
| 5631 | // the existing one, but that has not been requested, so bail. |
| 5632 | Slog.w(TAG, "Attempt to re-install " + pkgName |
| 5633 | + " without first uninstalling package running as " |
| 5634 | + mSettings.mRenamedPackages.get(pkgName)); |
| 5635 | res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 5636 | return; |
| 5637 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5638 | if (mPackages.containsKey(pkgName) || mAppDirs.containsKey(pkg.mPath)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5639 | // Don't allow installation over an existing package with the same name. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5640 | Slog.w(TAG, "Attempt to re-install " + pkgName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | + " without first uninstalling."); |
| 5642 | res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 5643 | return; |
| 5644 | } |
| 5645 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5646 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5647 | PackageParser.Package newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5648 | if (newPackage == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5649 | 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] | 5650 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5651 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 5652 | } |
| 5653 | } else { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5654 | updateSettingsLI(newPackage, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5655 | installerPackageName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5656 | res); |
| 5657 | // delete the partially installed application. the data directory will have to be |
| 5658 | // restored if it was already existing |
| 5659 | if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
| 5660 | // remove package from internal structures. Note that we want deletePackageX to |
| 5661 | // delete the package data and cache directories that it created in |
| 5662 | // scanPackageLocked, unless those directories existed before we even tried to |
| 5663 | // install. |
| 5664 | deletePackageLI( |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5665 | pkgName, false, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5666 | dataDirExists ? PackageManager.DONT_DELETE_DATA : 0, |
| 5667 | res.removedInfo); |
| 5668 | } |
| 5669 | } |
| 5670 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5671 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5672 | private void replacePackageLI(PackageParser.Package pkg, |
| 5673 | int parseFlags, |
| 5674 | int scanMode, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5675 | String installerPackageName, PackageInstalledInfo res) { |
| 5676 | |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 5677 | PackageParser.Package oldPackage; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5678 | String pkgName = pkg.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5679 | // First find the old package info and check signatures |
| 5680 | synchronized(mPackages) { |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 5681 | oldPackage = mPackages.get(pkgName); |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5682 | if (checkSignaturesLP(oldPackage.mSignatures, pkg.mSignatures) |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 5683 | != PackageManager.SIGNATURE_MATCH) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5684 | res.returnCode = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 5685 | return; |
| 5686 | } |
| 5687 | } |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 5688 | boolean sysPkg = ((oldPackage.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5689 | if (sysPkg) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5690 | replaceSystemPackageLI(oldPackage, pkg, parseFlags, scanMode, installerPackageName, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5691 | } else { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5692 | replaceNonSystemPackageLI(oldPackage, pkg, parseFlags, scanMode, installerPackageName, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5693 | } |
| 5694 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5695 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5696 | private void replaceNonSystemPackageLI(PackageParser.Package deletedPackage, |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5697 | PackageParser.Package pkg, |
| 5698 | int parseFlags, int scanMode, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5699 | String installerPackageName, PackageInstalledInfo res) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5700 | PackageParser.Package newPackage = null; |
| 5701 | String pkgName = deletedPackage.packageName; |
| 5702 | boolean deletedPkg = true; |
| 5703 | boolean updatedSettings = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5704 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5705 | String oldInstallerPackageName = null; |
| 5706 | synchronized (mPackages) { |
| 5707 | oldInstallerPackageName = mSettings.getInstallerPackageName(pkgName); |
| 5708 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5710 | // First delete the existing package while retaining the data directory |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5711 | if (!deletePackageLI(pkgName, true, PackageManager.DONT_DELETE_DATA, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5712 | res.removedInfo)) { |
| 5713 | // If the existing package was'nt successfully deleted |
| 5714 | res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE; |
| 5715 | deletedPkg = false; |
| 5716 | } else { |
| 5717 | // Successfully deleted the old package. Now proceed with re-installation |
| 5718 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5719 | newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5720 | if (newPackage == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5721 | 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] | 5722 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5723 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
Suchi Amalapurapu | 110fea7 | 2010-01-14 17:50:23 -0800 | [diff] [blame] | 5724 | } |
| 5725 | } else { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5726 | updateSettingsLI(newPackage, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5727 | installerPackageName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5728 | res); |
| 5729 | updatedSettings = true; |
| 5730 | } |
| 5731 | } |
| 5732 | |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5733 | if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5734 | // remove package from internal structures. Note that we want deletePackageX to |
| 5735 | // delete the package data and cache directories that it created in |
| 5736 | // scanPackageLocked, unless those directories existed before we even tried to |
| 5737 | // install. |
| 5738 | if(updatedSettings) { |
| 5739 | deletePackageLI( |
| 5740 | pkgName, true, |
| 5741 | PackageManager.DONT_DELETE_DATA, |
| 5742 | res.removedInfo); |
| 5743 | } |
| 5744 | // Since we failed to install the new package we need to restore the old |
| 5745 | // package that we deleted. |
| 5746 | if(deletedPkg) { |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5747 | File restoreFile = new File(deletedPackage.mPath); |
| 5748 | if (restoreFile == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5749 | Slog.e(TAG, "Failed allocating storage when restoring pkg : " + pkgName); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5750 | return; |
| 5751 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5752 | // Parse old package |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5753 | boolean oldOnSd = isExternal(deletedPackage); |
| 5754 | int oldParseFlags = mDefParseFlags | PackageParser.PARSE_CHATTY | |
| 5755 | (isForwardLocked(deletedPackage) ? PackageParser.PARSE_FORWARD_LOCK : 0) | |
| 5756 | (oldOnSd ? PackageParser.PARSE_ON_SDCARD : 0); |
| 5757 | int oldScanMode = (oldOnSd ? 0 : SCAN_MONITOR) | SCAN_UPDATE_SIGNATURE; |
| 5758 | if (scanPackageLI(restoreFile, oldParseFlags, oldScanMode) == null) { |
| 5759 | Slog.e(TAG, "Failed to restore package : " + pkgName + " after failed upgrade"); |
| 5760 | return; |
| 5761 | } |
| 5762 | // Restore of old package succeeded. Update permissions. |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5763 | synchronized (mPackages) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 5764 | updatePermissionsLP(deletedPackage.packageName, deletedPackage, |
Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 5765 | true, false, false); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5766 | mSettings.writeLP(); |
| 5767 | } |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5768 | 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] | 5769 | } |
| 5770 | } |
| 5771 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5773 | private void replaceSystemPackageLI(PackageParser.Package deletedPackage, |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5774 | PackageParser.Package pkg, |
| 5775 | int parseFlags, int scanMode, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5776 | String installerPackageName, PackageInstalledInfo res) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5777 | PackageParser.Package newPackage = null; |
| 5778 | boolean updatedSettings = false; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5779 | parseFlags |= PackageManager.INSTALL_REPLACE_EXISTING | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5780 | PackageParser.PARSE_IS_SYSTEM; |
| 5781 | String packageName = deletedPackage.packageName; |
| 5782 | res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE; |
| 5783 | if (packageName == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5784 | Slog.w(TAG, "Attempt to delete null packageName."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5785 | return; |
| 5786 | } |
| 5787 | PackageParser.Package oldPkg; |
| 5788 | PackageSetting oldPkgSetting; |
| 5789 | synchronized (mPackages) { |
| 5790 | oldPkg = mPackages.get(packageName); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5791 | oldPkgSetting = mSettings.mPackages.get(packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5792 | if((oldPkg == null) || (oldPkg.applicationInfo == null) || |
| 5793 | (oldPkgSetting == null)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5794 | Slog.w(TAG, "Couldn't find package:"+packageName+" information"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5795 | return; |
| 5796 | } |
| 5797 | } |
| 5798 | res.removedInfo.uid = oldPkg.applicationInfo.uid; |
| 5799 | res.removedInfo.removedPackage = packageName; |
| 5800 | // Remove existing system package |
| 5801 | removePackageLI(oldPkg, true); |
| 5802 | synchronized (mPackages) { |
| 5803 | res.removedInfo.removedUid = mSettings.disableSystemPackageLP(packageName); |
| 5804 | } |
| 5805 | |
| 5806 | // Successfully disabled the old package. Now proceed with re-installation |
| 5807 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
| 5808 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5809 | newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5810 | if (newPackage == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5811 | 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] | 5812 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5813 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 5814 | } |
| 5815 | } else { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5816 | updateSettingsLI(newPackage, installerPackageName, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5817 | updatedSettings = true; |
| 5818 | } |
| 5819 | |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5820 | if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5821 | // Re installation failed. Restore old information |
| 5822 | // Remove new pkg information |
Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 5823 | if (newPackage != null) { |
| 5824 | removePackageLI(newPackage, true); |
| 5825 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5826 | // Add back the old system package |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5827 | scanPackageLI(oldPkg, parseFlags, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5828 | SCAN_MONITOR |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5829 | | SCAN_UPDATE_SIGNATURE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5830 | // Restore the old system information in Settings |
| 5831 | synchronized(mPackages) { |
| 5832 | if(updatedSettings) { |
| 5833 | mSettings.enableSystemPackageLP(packageName); |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5834 | mSettings.setInstallerPackageName(packageName, |
| 5835 | oldPkgSetting.installerPackageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5836 | } |
| 5837 | mSettings.writeLP(); |
| 5838 | } |
Suchi Amalapurapu | c1d07d9 | 2010-05-05 13:37:12 -0700 | [diff] [blame] | 5839 | } else { |
| 5840 | // If this is an update to an existing update, setup |
| 5841 | // to remove the existing update. |
| 5842 | synchronized (mPackages) { |
| 5843 | PackageSetting ps = mSettings.getDisabledSystemPkg(packageName); |
| 5844 | if (ps != null && ps.codePathString != null && |
| 5845 | !ps.codePathString.equals(oldPkgSetting.codePathString)) { |
| 5846 | int installFlags = 0; |
| 5847 | res.removedInfo.args = createInstallArgs(0, oldPkgSetting.codePathString, |
| 5848 | oldPkgSetting.resourcePathString); |
| 5849 | } |
| 5850 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5851 | } |
| 5852 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5853 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5854 | // Utility method used to move dex files during install. |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 5855 | private int moveDexFilesLI(PackageParser.Package newPackage) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5856 | int retCode; |
| 5857 | if ((newPackage.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 5858 | retCode = mInstaller.movedex(newPackage.mScanPath, newPackage.mPath); |
| 5859 | if (retCode != 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5860 | Slog.e(TAG, "Couldn't rename dex file: " + newPackage.mPath); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5861 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5862 | } |
| 5863 | } |
| 5864 | return PackageManager.INSTALL_SUCCEEDED; |
| 5865 | } |
| 5866 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5867 | private void updateSettingsLI(PackageParser.Package newPackage, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5868 | String installerPackageName, PackageInstalledInfo res) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5869 | String pkgName = newPackage.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5870 | synchronized (mPackages) { |
| 5871 | //write settings. the installStatus will be incomplete at this stage. |
| 5872 | //note that the new package setting would have already been |
| 5873 | //added to mPackages. It hasn't been persisted yet. |
| 5874 | mSettings.setInstallStatus(pkgName, PKG_INSTALL_INCOMPLETE); |
| 5875 | mSettings.writeLP(); |
| 5876 | } |
| 5877 | |
Suchi Amalapurapu | f7f5dda | 2010-03-23 10:34:28 -0700 | [diff] [blame] | 5878 | if ((res.returnCode = moveDexFilesLI(newPackage)) |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5879 | != PackageManager.INSTALL_SUCCEEDED) { |
| 5880 | // Discontinue if moving dex files failed. |
| 5881 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5882 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5883 | if((res.returnCode = setPermissionsLI(newPackage)) |
| 5884 | != PackageManager.INSTALL_SUCCEEDED) { |
| 5885 | if (mInstaller != null) { |
| 5886 | mInstaller.rmdex(newPackage.mScanPath); |
| 5887 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5888 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5889 | } else { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5890 | Log.d(TAG, "New package installed in " + newPackage.mPath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5891 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5892 | synchronized (mPackages) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 5893 | updatePermissionsLP(newPackage.packageName, newPackage, |
Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 5894 | newPackage.permissions.size() > 0, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5895 | res.name = pkgName; |
| 5896 | res.uid = newPackage.applicationInfo.uid; |
| 5897 | res.pkg = newPackage; |
| 5898 | mSettings.setInstallStatus(pkgName, PKG_INSTALL_COMPLETE); |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5899 | mSettings.setInstallerPackageName(pkgName, installerPackageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5900 | res.returnCode = PackageManager.INSTALL_SUCCEEDED; |
| 5901 | //to update install status |
| 5902 | mSettings.writeLP(); |
| 5903 | } |
| 5904 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5905 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5906 | private void installPackageLI(InstallArgs args, |
| 5907 | boolean newInstall, PackageInstalledInfo res) { |
| 5908 | int pFlags = args.flags; |
| 5909 | String installerPackageName = args.installerPackageName; |
| 5910 | File tmpPackageFile = new File(args.getCodePath()); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5911 | boolean forwardLocked = ((pFlags & PackageManager.INSTALL_FORWARD_LOCK) != 0); |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5912 | boolean onSd = ((pFlags & PackageManager.INSTALL_EXTERNAL) != 0); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5913 | boolean replace = false; |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 5914 | int scanMode = (onSd ? 0 : SCAN_MONITOR) | SCAN_FORCE_DEX | SCAN_UPDATE_SIGNATURE |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5915 | | (newInstall ? SCAN_NEW_INSTALL : 0); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5916 | // Result object to be returned |
| 5917 | res.returnCode = PackageManager.INSTALL_SUCCEEDED; |
| 5918 | |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5919 | // Retrieve PackageSettings and parse package |
| 5920 | int parseFlags = PackageParser.PARSE_CHATTY | |
| 5921 | (forwardLocked ? PackageParser.PARSE_FORWARD_LOCK : 0) | |
| 5922 | (onSd ? PackageParser.PARSE_ON_SDCARD : 0); |
| 5923 | parseFlags |= mDefParseFlags; |
| 5924 | PackageParser pp = new PackageParser(tmpPackageFile.getPath()); |
| 5925 | pp.setSeparateProcesses(mSeparateProcesses); |
| 5926 | final PackageParser.Package pkg = pp.parsePackage(tmpPackageFile, |
| 5927 | null, mMetrics, parseFlags); |
| 5928 | if (pkg == null) { |
| 5929 | res.returnCode = pp.getParseError(); |
| 5930 | return; |
| 5931 | } |
| 5932 | String pkgName = res.name = pkg.packageName; |
| 5933 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_TEST_ONLY) != 0) { |
| 5934 | if ((pFlags&PackageManager.INSTALL_ALLOW_TEST) == 0) { |
| 5935 | res.returnCode = PackageManager.INSTALL_FAILED_TEST_ONLY; |
| 5936 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5937 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5938 | } |
| 5939 | if (GET_CERTIFICATES && !pp.collectCertificates(pkg, parseFlags)) { |
| 5940 | res.returnCode = pp.getParseError(); |
| 5941 | return; |
| 5942 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5943 | // Get rid of all references to package scan path via parser. |
| 5944 | pp = null; |
| 5945 | String oldCodePath = null; |
| 5946 | boolean systemApp = false; |
| 5947 | synchronized (mPackages) { |
| 5948 | // Check if installing already existing package |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5949 | if ((pFlags&PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
| 5950 | String oldName = mSettings.mRenamedPackages.get(pkgName); |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 5951 | if (pkg.mOriginalPackages != null |
| 5952 | && pkg.mOriginalPackages.contains(oldName) |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5953 | && mPackages.containsKey(oldName)) { |
| 5954 | // This package is derived from an original package, |
| 5955 | // and this device has been updating from that original |
| 5956 | // name. We must continue using the original name, so |
| 5957 | // rename the new package here. |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 5958 | pkg.setPackageName(oldName); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5959 | pkgName = pkg.packageName; |
| 5960 | replace = true; |
| 5961 | } else if (mPackages.containsKey(pkgName)) { |
| 5962 | // This package, under its official name, already exists |
| 5963 | // on the device; we should replace it. |
| 5964 | replace = true; |
| 5965 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5966 | } |
| 5967 | PackageSetting ps = mSettings.mPackages.get(pkgName); |
| 5968 | if (ps != null) { |
| 5969 | oldCodePath = mSettings.mPackages.get(pkgName).codePathString; |
| 5970 | if (ps.pkg != null && ps.pkg.applicationInfo != null) { |
| 5971 | systemApp = (ps.pkg.applicationInfo.flags & |
| 5972 | ApplicationInfo.FLAG_SYSTEM) != 0; |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 5973 | } |
| 5974 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5975 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5976 | |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5977 | if (systemApp && onSd) { |
| 5978 | // Disable updates to system apps on sdcard |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5979 | Slog.w(TAG, "Cannot install updates to system apps on sdcard"); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5980 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 5981 | return; |
| 5982 | } |
Suchi Amalapurapu | cf6eaea | 2010-02-23 19:37:45 -0800 | [diff] [blame] | 5983 | |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5984 | if (!args.doRename(res.returnCode, pkgName, oldCodePath)) { |
| 5985 | res.returnCode = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5986 | return; |
| 5987 | } |
| 5988 | // Set application objects path explicitly after the rename |
| 5989 | setApplicationInfoPaths(pkg, args.getCodePath(), args.getResourcePath()); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5990 | if (replace) { |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5991 | replacePackageLI(pkg, parseFlags, scanMode, |
| 5992 | installerPackageName, res); |
| 5993 | } else { |
| 5994 | installNewPackageLI(pkg, parseFlags, scanMode, |
| 5995 | installerPackageName,res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5996 | } |
| 5997 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5998 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5999 | private int setPermissionsLI(PackageParser.Package newPackage) { |
| 6000 | String pkgName = newPackage.packageName; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6001 | int retCode = 0; |
| 6002 | // TODO Gross hack but fix later. Ideally move this to be a post installation |
| 6003 | // check after alloting uid. |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6004 | if ((newPackage.applicationInfo.flags |
| 6005 | & ApplicationInfo.FLAG_FORWARD_LOCK) != 0) { |
| 6006 | File destResourceFile = new File(newPackage.applicationInfo.publicSourceDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6007 | try { |
| 6008 | extractPublicFiles(newPackage, destResourceFile); |
| 6009 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6010 | 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] | 6011 | " forward-locked app."); |
| 6012 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 6013 | } finally { |
| 6014 | //TODO clean up the extracted public files |
| 6015 | } |
| 6016 | if (mInstaller != null) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6017 | retCode = mInstaller.setForwardLockPerm(getApkName(newPackage.mPath), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6018 | newPackage.applicationInfo.uid); |
| 6019 | } else { |
| 6020 | final int filePermissions = |
| 6021 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6022 | retCode = FileUtils.setPermissions(newPackage.mPath, filePermissions, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6023 | newPackage.applicationInfo.uid); |
| 6024 | } |
| 6025 | } else { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6026 | // The permissions on the resource file was set when it was copied for |
| 6027 | // non forward locked apps and apps on sdcard |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6029 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6030 | if (retCode != 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6031 | Slog.e(TAG, "Couldn't set new package file permissions for " + |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6032 | newPackage.mPath |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6033 | + ". The return code was: " + retCode); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6034 | // TODO Define new internal error |
| 6035 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6036 | } |
| 6037 | return PackageManager.INSTALL_SUCCEEDED; |
| 6038 | } |
| 6039 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6040 | private boolean isForwardLocked(PackageParser.Package pkg) { |
| 6041 | return ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6042 | } |
| 6043 | |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 6044 | private boolean isExternal(PackageParser.Package pkg) { |
| 6045 | return ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); |
| 6046 | } |
| 6047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6048 | private void extractPublicFiles(PackageParser.Package newPackage, |
| 6049 | File publicZipFile) throws IOException { |
| 6050 | final ZipOutputStream publicZipOutStream = |
| 6051 | new ZipOutputStream(new FileOutputStream(publicZipFile)); |
| 6052 | final ZipFile privateZip = new ZipFile(newPackage.mPath); |
| 6053 | |
| 6054 | // Copy manifest, resources.arsc and res directory to public zip |
| 6055 | |
| 6056 | final Enumeration<? extends ZipEntry> privateZipEntries = privateZip.entries(); |
| 6057 | while (privateZipEntries.hasMoreElements()) { |
| 6058 | final ZipEntry zipEntry = privateZipEntries.nextElement(); |
| 6059 | final String zipEntryName = zipEntry.getName(); |
| 6060 | if ("AndroidManifest.xml".equals(zipEntryName) |
| 6061 | || "resources.arsc".equals(zipEntryName) |
| 6062 | || zipEntryName.startsWith("res/")) { |
| 6063 | try { |
| 6064 | copyZipEntry(zipEntry, privateZip, publicZipOutStream); |
| 6065 | } catch (IOException e) { |
| 6066 | try { |
| 6067 | publicZipOutStream.close(); |
| 6068 | throw e; |
| 6069 | } finally { |
| 6070 | publicZipFile.delete(); |
| 6071 | } |
| 6072 | } |
| 6073 | } |
| 6074 | } |
| 6075 | |
| 6076 | publicZipOutStream.close(); |
| 6077 | FileUtils.setPermissions( |
| 6078 | publicZipFile.getAbsolutePath(), |
| 6079 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP|FileUtils.S_IROTH, |
| 6080 | -1, -1); |
| 6081 | } |
| 6082 | |
| 6083 | private static void copyZipEntry(ZipEntry zipEntry, |
| 6084 | ZipFile inZipFile, |
| 6085 | ZipOutputStream outZipStream) throws IOException { |
| 6086 | byte[] buffer = new byte[4096]; |
| 6087 | int num; |
| 6088 | |
| 6089 | ZipEntry newEntry; |
| 6090 | if (zipEntry.getMethod() == ZipEntry.STORED) { |
| 6091 | // Preserve the STORED method of the input entry. |
| 6092 | newEntry = new ZipEntry(zipEntry); |
| 6093 | } else { |
| 6094 | // Create a new entry so that the compressed len is recomputed. |
| 6095 | newEntry = new ZipEntry(zipEntry.getName()); |
| 6096 | } |
| 6097 | outZipStream.putNextEntry(newEntry); |
| 6098 | |
| 6099 | InputStream data = inZipFile.getInputStream(zipEntry); |
| 6100 | while ((num = data.read(buffer)) > 0) { |
| 6101 | outZipStream.write(buffer, 0, num); |
| 6102 | } |
| 6103 | outZipStream.flush(); |
| 6104 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6106 | private void deleteTempPackageFiles() { |
| 6107 | FilenameFilter filter = new FilenameFilter() { |
| 6108 | public boolean accept(File dir, String name) { |
| 6109 | return name.startsWith("vmdl") && name.endsWith(".tmp"); |
| 6110 | } |
| 6111 | }; |
| 6112 | String tmpFilesList[] = mAppInstallDir.list(filter); |
| 6113 | if(tmpFilesList == null) { |
| 6114 | return; |
| 6115 | } |
| 6116 | for(int i = 0; i < tmpFilesList.length; i++) { |
| 6117 | File tmpFile = new File(mAppInstallDir, tmpFilesList[i]); |
| 6118 | tmpFile.delete(); |
| 6119 | } |
| 6120 | } |
| 6121 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6122 | private File createTempPackageFile(File installDir) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6123 | File tmpPackageFile; |
| 6124 | try { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6125 | tmpPackageFile = File.createTempFile("vmdl", ".tmp", installDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6126 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6127 | 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] | 6128 | return null; |
| 6129 | } |
| 6130 | try { |
| 6131 | FileUtils.setPermissions( |
| 6132 | tmpPackageFile.getCanonicalPath(), FileUtils.S_IRUSR|FileUtils.S_IWUSR, |
| 6133 | -1, -1); |
| 6134 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6135 | 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] | 6136 | return null; |
| 6137 | } |
| 6138 | return tmpPackageFile; |
| 6139 | } |
| 6140 | |
| 6141 | public void deletePackage(final String packageName, |
| 6142 | final IPackageDeleteObserver observer, |
| 6143 | final int flags) { |
| 6144 | mContext.enforceCallingOrSelfPermission( |
| 6145 | android.Manifest.permission.DELETE_PACKAGES, null); |
| 6146 | // Queue up an async operation since the package deletion may take a little while. |
| 6147 | mHandler.post(new Runnable() { |
| 6148 | public void run() { |
| 6149 | mHandler.removeCallbacks(this); |
| 6150 | final boolean succeded = deletePackageX(packageName, true, true, flags); |
| 6151 | if (observer != null) { |
| 6152 | try { |
| 6153 | observer.packageDeleted(succeded); |
| 6154 | } catch (RemoteException e) { |
| 6155 | Log.i(TAG, "Observer no longer exists."); |
| 6156 | } //end catch |
| 6157 | } //end if |
| 6158 | } //end run |
| 6159 | }); |
| 6160 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6162 | /** |
| 6163 | * This method is an internal method that could be get invoked either |
| 6164 | * to delete an installed package or to clean up a failed installation. |
| 6165 | * After deleting an installed package, a broadcast is sent to notify any |
| 6166 | * listeners that the package has been installed. For cleaning up a failed |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6167 | * 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] | 6168 | * installation wouldn't have sent the initial broadcast either |
| 6169 | * The key steps in deleting a package are |
| 6170 | * deleting the package information in internal structures like mPackages, |
| 6171 | * deleting the packages base directories through installd |
| 6172 | * updating mSettings to reflect current status |
| 6173 | * persisting settings for later use |
| 6174 | * sending a broadcast if necessary |
| 6175 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6176 | private boolean deletePackageX(String packageName, boolean sendBroadCast, |
| 6177 | boolean deleteCodeAndResources, int flags) { |
| 6178 | PackageRemovedInfo info = new PackageRemovedInfo(); |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6179 | boolean res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6180 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 6181 | IDevicePolicyManager dpm = IDevicePolicyManager.Stub.asInterface( |
| 6182 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 6183 | try { |
| 6184 | if (dpm != null && dpm.packageHasActiveAdmins(packageName)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6185 | Slog.w(TAG, "Not removing package " + packageName + ": has active device admin"); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 6186 | return false; |
| 6187 | } |
| 6188 | } catch (RemoteException e) { |
| 6189 | } |
| 6190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6191 | synchronized (mInstallLock) { |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6192 | res = deletePackageLI(packageName, deleteCodeAndResources, |
| 6193 | flags | REMOVE_CHATTY, info); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6196 | if(res && sendBroadCast) { |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6197 | boolean systemUpdate = info.isRemovedPackageSystemUpdate; |
Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6198 | info.sendBroadcast(deleteCodeAndResources, systemUpdate); |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6199 | |
| 6200 | // If the removed package was a system update, the old system packaged |
| 6201 | // was re-enabled; we need to broadcast this information |
| 6202 | if (systemUpdate) { |
| 6203 | Bundle extras = new Bundle(1); |
| 6204 | extras.putInt(Intent.EXTRA_UID, info.removedUid >= 0 ? info.removedUid : info.uid); |
| 6205 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 6206 | |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 6207 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName, extras, null); |
| 6208 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, packageName, extras, null); |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6209 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6210 | } |
Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6211 | // Force a gc here. |
| 6212 | Runtime.getRuntime().gc(); |
| 6213 | // Delete the resources here after sending the broadcast to let |
| 6214 | // other processes clean up before deleting resources. |
| 6215 | if (info.args != null) { |
| 6216 | synchronized (mInstallLock) { |
| 6217 | info.args.doPostDeleteLI(deleteCodeAndResources); |
| 6218 | } |
| 6219 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6220 | return res; |
| 6221 | } |
| 6222 | |
| 6223 | static class PackageRemovedInfo { |
| 6224 | String removedPackage; |
| 6225 | int uid = -1; |
| 6226 | int removedUid = -1; |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6227 | boolean isRemovedPackageSystemUpdate = false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6228 | // Clean up resources deleted packages. |
| 6229 | InstallArgs args = null; |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6230 | |
Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6231 | void sendBroadcast(boolean fullRemove, boolean replacing) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6232 | Bundle extras = new Bundle(1); |
| 6233 | extras.putInt(Intent.EXTRA_UID, removedUid >= 0 ? removedUid : uid); |
| 6234 | extras.putBoolean(Intent.EXTRA_DATA_REMOVED, fullRemove); |
| 6235 | if (replacing) { |
| 6236 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 6237 | } |
| 6238 | if (removedPackage != null) { |
Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 6239 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage, extras, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6240 | } |
| 6241 | if (removedUid >= 0) { |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 6242 | sendPackageBroadcast(Intent.ACTION_UID_REMOVED, null, extras, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6243 | } |
| 6244 | } |
| 6245 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6247 | /* |
| 6248 | * This method deletes the package from internal data structures. If the DONT_DELETE_DATA |
| 6249 | * flag is not set, the data directory is removed as well. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6250 | * 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] | 6251 | * delete a partially installed application. |
| 6252 | */ |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6253 | private void removePackageDataLI(PackageParser.Package p, PackageRemovedInfo outInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6254 | int flags) { |
| 6255 | String packageName = p.packageName; |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6256 | if (outInfo != null) { |
| 6257 | outInfo.removedPackage = packageName; |
| 6258 | } |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 6259 | removePackageLI(p, (flags&REMOVE_CHATTY) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6260 | // Retrieve object to delete permissions for shared user later on |
| 6261 | PackageSetting deletedPs; |
| 6262 | synchronized (mPackages) { |
| 6263 | deletedPs = mSettings.mPackages.get(packageName); |
| 6264 | } |
| 6265 | if ((flags&PackageManager.DONT_DELETE_DATA) == 0) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6266 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6267 | if (mInstaller != null) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6268 | int retCode = mInstaller.remove(packageName, useEncryptedFSDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6269 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6270 | 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] | 6271 | + packageName + ", retcode=" + retCode); |
| 6272 | // we don't consider this to be a failure of the core package deletion |
| 6273 | } |
| 6274 | } else { |
| 6275 | //for emulator |
| 6276 | PackageParser.Package pkg = mPackages.get(packageName); |
| 6277 | File dataDir = new File(pkg.applicationInfo.dataDir); |
| 6278 | dataDir.delete(); |
| 6279 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6280 | } |
| 6281 | synchronized (mPackages) { |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 6282 | if (deletedPs != null) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6283 | schedulePackageCleaning(packageName); |
| 6284 | |
| 6285 | if ((flags&PackageManager.DONT_DELETE_DATA) == 0) { |
| 6286 | if (outInfo != null) { |
| 6287 | outInfo.removedUid = mSettings.removePackageLP(packageName); |
| 6288 | } |
| 6289 | if (deletedPs != null) { |
Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 6290 | updatePermissionsLP(deletedPs.name, null, false, false, false); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6291 | if (deletedPs.sharedUser != null) { |
| 6292 | // remove permissions associated with package |
| 6293 | mSettings.updateSharedUserPermsLP(deletedPs, mGlobalGids); |
| 6294 | } |
| 6295 | } |
| 6296 | } |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 6297 | // remove from preferred activities. |
| 6298 | ArrayList<PreferredActivity> removed = new ArrayList<PreferredActivity>(); |
| 6299 | for (PreferredActivity pa : mSettings.mPreferredActivities.filterSet()) { |
| 6300 | if (pa.mActivity.getPackageName().equals(deletedPs.name)) { |
| 6301 | removed.add(pa); |
| 6302 | } |
| 6303 | } |
| 6304 | for (PreferredActivity pa : removed) { |
| 6305 | mSettings.mPreferredActivities.removeFilter(pa); |
| 6306 | } |
| 6307 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6308 | // Save settings now |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 6309 | mSettings.writeLP(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6310 | } |
| 6311 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6313 | /* |
| 6314 | * Tries to delete system package. |
| 6315 | */ |
| 6316 | private boolean deleteSystemPackageLI(PackageParser.Package p, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6317 | int flags, PackageRemovedInfo outInfo) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6318 | ApplicationInfo applicationInfo = p.applicationInfo; |
| 6319 | //applicable for non-partially installed applications only |
| 6320 | if (applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6321 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6322 | return false; |
| 6323 | } |
| 6324 | PackageSetting ps = null; |
| 6325 | // Confirm if the system package has been updated |
| 6326 | // An updated system app can be deleted. This will also have to restore |
| 6327 | // the system pkg from system partition |
| 6328 | synchronized (mPackages) { |
| 6329 | ps = mSettings.getDisabledSystemPkg(p.packageName); |
| 6330 | } |
| 6331 | if (ps == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6332 | 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] | 6333 | return false; |
| 6334 | } else { |
| 6335 | Log.i(TAG, "Deleting system pkg from data partition"); |
| 6336 | } |
| 6337 | // Delete the updated package |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6338 | outInfo.isRemovedPackageSystemUpdate = true; |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6339 | boolean deleteCodeAndResources = false; |
| 6340 | if (ps.versionCode < p.mVersionCode) { |
| 6341 | // Delete code and resources for downgrades |
| 6342 | deleteCodeAndResources = true; |
| 6343 | if ((flags & PackageManager.DONT_DELETE_DATA) == 0) { |
| 6344 | flags &= ~PackageManager.DONT_DELETE_DATA; |
| 6345 | } |
| 6346 | } else { |
| 6347 | // Preserve data by setting flag |
| 6348 | if ((flags & PackageManager.DONT_DELETE_DATA) == 0) { |
| 6349 | flags |= PackageManager.DONT_DELETE_DATA; |
| 6350 | } |
| 6351 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6352 | boolean ret = deleteInstalledPackageLI(p, deleteCodeAndResources, flags, outInfo); |
| 6353 | if (!ret) { |
| 6354 | return false; |
| 6355 | } |
| 6356 | synchronized (mPackages) { |
| 6357 | // Reinstate the old system package |
| 6358 | mSettings.enableSystemPackageLP(p.packageName); |
David 'Digit' Turner | 4f99e3c | 2010-04-12 16:11:15 -0700 | [diff] [blame] | 6359 | // Remove any native libraries. |
| 6360 | removeNativeBinariesLI(p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | } |
| 6362 | // Install the system package |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6363 | PackageParser.Package newPkg = scanPackageLI(ps.codePath, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6364 | PackageParser.PARSE_MUST_BE_APK | PackageParser.PARSE_IS_SYSTEM, |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6365 | SCAN_MONITOR | SCAN_NO_PATHS); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6367 | if (newPkg == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6368 | 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] | 6369 | return false; |
| 6370 | } |
| 6371 | synchronized (mPackages) { |
Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 6372 | updatePermissionsLP(newPkg.packageName, newPkg, true, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6373 | mSettings.writeLP(); |
| 6374 | } |
| 6375 | return true; |
| 6376 | } |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | private boolean deleteInstalledPackageLI(PackageParser.Package p, |
| 6379 | boolean deleteCodeAndResources, int flags, PackageRemovedInfo outInfo) { |
| 6380 | ApplicationInfo applicationInfo = p.applicationInfo; |
| 6381 | if (applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6382 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6383 | return false; |
| 6384 | } |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6385 | if (outInfo != null) { |
| 6386 | outInfo.uid = applicationInfo.uid; |
| 6387 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6388 | |
| 6389 | // Delete package data from internal structures and also remove data if flag is set |
| 6390 | removePackageDataLI(p, outInfo, flags); |
| 6391 | |
| 6392 | // Delete application code and resources |
| 6393 | if (deleteCodeAndResources) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6394 | // TODO can pick up from PackageSettings as well |
Suchi Amalapurapu | 6069beb | 2010-03-10 09:46:49 -0800 | [diff] [blame] | 6395 | int installFlags = ((p.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE)!=0) ? |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 6396 | PackageManager.INSTALL_EXTERNAL : 0; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6397 | installFlags |= ((p.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK)!=0) ? |
| 6398 | PackageManager.INSTALL_FORWARD_LOCK : 0; |
| 6399 | outInfo.args = createInstallArgs(installFlags, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6400 | applicationInfo.sourceDir, applicationInfo.publicSourceDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | } |
| 6402 | return true; |
| 6403 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6404 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6405 | /* |
| 6406 | * This method handles package deletion in general |
| 6407 | */ |
| 6408 | private boolean deletePackageLI(String packageName, |
| 6409 | boolean deleteCodeAndResources, int flags, PackageRemovedInfo outInfo) { |
| 6410 | if (packageName == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6411 | Slog.w(TAG, "Attempt to delete null packageName."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6412 | return false; |
| 6413 | } |
| 6414 | PackageParser.Package p; |
| 6415 | boolean dataOnly = false; |
| 6416 | synchronized (mPackages) { |
| 6417 | p = mPackages.get(packageName); |
| 6418 | if (p == null) { |
| 6419 | //this retrieves partially installed apps |
| 6420 | dataOnly = true; |
| 6421 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6422 | if (ps == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6423 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6424 | return false; |
| 6425 | } |
| 6426 | p = ps.pkg; |
| 6427 | } |
| 6428 | } |
| 6429 | if (p == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6430 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6431 | return false; |
| 6432 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6434 | if (dataOnly) { |
| 6435 | // Delete application data first |
| 6436 | removePackageDataLI(p, outInfo, flags); |
| 6437 | return true; |
| 6438 | } |
| 6439 | // At this point the package should have ApplicationInfo associated with it |
| 6440 | if (p.applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6441 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6442 | return false; |
| 6443 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6444 | boolean ret = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6445 | if ( (p.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6446 | Log.i(TAG, "Removing system package:"+p.packageName); |
| 6447 | // When an updated system application is deleted we delete the existing resources as well and |
| 6448 | // fall back to existing code in system partition |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6449 | ret = deleteSystemPackageLI(p, flags, outInfo); |
| 6450 | } else { |
| 6451 | Log.i(TAG, "Removing non-system package:"+p.packageName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6452 | // Kill application pre-emptively especially for apps on sd. |
| 6453 | killApplication(packageName, p.applicationInfo.uid); |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 6454 | ret = deleteInstalledPackageLI(p, deleteCodeAndResources, flags, outInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6455 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6456 | return ret; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6457 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6459 | public void clearApplicationUserData(final String packageName, |
| 6460 | final IPackageDataObserver observer) { |
| 6461 | mContext.enforceCallingOrSelfPermission( |
| 6462 | android.Manifest.permission.CLEAR_APP_USER_DATA, null); |
| 6463 | // Queue up an async operation since the package deletion may take a little while. |
| 6464 | mHandler.post(new Runnable() { |
| 6465 | public void run() { |
| 6466 | mHandler.removeCallbacks(this); |
| 6467 | final boolean succeeded; |
| 6468 | synchronized (mInstallLock) { |
| 6469 | succeeded = clearApplicationUserDataLI(packageName); |
| 6470 | } |
| 6471 | if (succeeded) { |
| 6472 | // invoke DeviceStorageMonitor's update method to clear any notifications |
| 6473 | DeviceStorageMonitorService dsm = (DeviceStorageMonitorService) |
| 6474 | ServiceManager.getService(DeviceStorageMonitorService.SERVICE); |
| 6475 | if (dsm != null) { |
| 6476 | dsm.updateMemory(); |
| 6477 | } |
| 6478 | } |
| 6479 | if(observer != null) { |
| 6480 | try { |
| 6481 | observer.onRemoveCompleted(packageName, succeeded); |
| 6482 | } catch (RemoteException e) { |
| 6483 | Log.i(TAG, "Observer no longer exists."); |
| 6484 | } |
| 6485 | } //end if observer |
| 6486 | } //end run |
| 6487 | }); |
| 6488 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6490 | private boolean clearApplicationUserDataLI(String packageName) { |
| 6491 | if (packageName == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6492 | Slog.w(TAG, "Attempt to delete null packageName."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6493 | return false; |
| 6494 | } |
| 6495 | PackageParser.Package p; |
| 6496 | boolean dataOnly = false; |
| 6497 | synchronized (mPackages) { |
| 6498 | p = mPackages.get(packageName); |
| 6499 | if(p == null) { |
| 6500 | dataOnly = true; |
| 6501 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6502 | if((ps == null) || (ps.pkg == null)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6503 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6504 | return false; |
| 6505 | } |
| 6506 | p = ps.pkg; |
| 6507 | } |
| 6508 | } |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6509 | boolean useEncryptedFSDir = false; |
| 6510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6511 | if(!dataOnly) { |
| 6512 | //need to check this only for fully installed applications |
| 6513 | if (p == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6514 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6515 | return false; |
| 6516 | } |
| 6517 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6518 | if (applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6519 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6520 | return false; |
| 6521 | } |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6522 | useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6523 | } |
| 6524 | if (mInstaller != null) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6525 | int retCode = mInstaller.clearUserData(packageName, useEncryptedFSDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6526 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6527 | 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] | 6528 | + packageName); |
| 6529 | return false; |
| 6530 | } |
| 6531 | } |
| 6532 | return true; |
| 6533 | } |
| 6534 | |
| 6535 | public void deleteApplicationCacheFiles(final String packageName, |
| 6536 | final IPackageDataObserver observer) { |
| 6537 | mContext.enforceCallingOrSelfPermission( |
| 6538 | android.Manifest.permission.DELETE_CACHE_FILES, null); |
| 6539 | // Queue up an async operation since the package deletion may take a little while. |
| 6540 | mHandler.post(new Runnable() { |
| 6541 | public void run() { |
| 6542 | mHandler.removeCallbacks(this); |
| 6543 | final boolean succeded; |
| 6544 | synchronized (mInstallLock) { |
| 6545 | succeded = deleteApplicationCacheFilesLI(packageName); |
| 6546 | } |
| 6547 | if(observer != null) { |
| 6548 | try { |
| 6549 | observer.onRemoveCompleted(packageName, succeded); |
| 6550 | } catch (RemoteException e) { |
| 6551 | Log.i(TAG, "Observer no longer exists."); |
| 6552 | } |
| 6553 | } //end if observer |
| 6554 | } //end run |
| 6555 | }); |
| 6556 | } |
| 6557 | |
| 6558 | private boolean deleteApplicationCacheFilesLI(String packageName) { |
| 6559 | if (packageName == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6560 | Slog.w(TAG, "Attempt to delete null packageName."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6561 | return false; |
| 6562 | } |
| 6563 | PackageParser.Package p; |
| 6564 | synchronized (mPackages) { |
| 6565 | p = mPackages.get(packageName); |
| 6566 | } |
| 6567 | if (p == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6568 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6569 | return false; |
| 6570 | } |
| 6571 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6572 | if (applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6573 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6574 | return false; |
| 6575 | } |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6576 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6577 | if (mInstaller != null) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6578 | int retCode = mInstaller.deleteCacheFiles(packageName, useEncryptedFSDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6580 | 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] | 6581 | + packageName); |
| 6582 | return false; |
| 6583 | } |
| 6584 | } |
| 6585 | return true; |
| 6586 | } |
| 6587 | |
| 6588 | public void getPackageSizeInfo(final String packageName, |
| 6589 | final IPackageStatsObserver observer) { |
| 6590 | mContext.enforceCallingOrSelfPermission( |
| 6591 | android.Manifest.permission.GET_PACKAGE_SIZE, null); |
| 6592 | // Queue up an async operation since the package deletion may take a little while. |
| 6593 | mHandler.post(new Runnable() { |
| 6594 | public void run() { |
| 6595 | mHandler.removeCallbacks(this); |
| 6596 | PackageStats lStats = new PackageStats(packageName); |
| 6597 | final boolean succeded; |
| 6598 | synchronized (mInstallLock) { |
| 6599 | succeded = getPackageSizeInfoLI(packageName, lStats); |
| 6600 | } |
| 6601 | if(observer != null) { |
| 6602 | try { |
| 6603 | observer.onGetStatsCompleted(lStats, succeded); |
| 6604 | } catch (RemoteException e) { |
| 6605 | Log.i(TAG, "Observer no longer exists."); |
| 6606 | } |
| 6607 | } //end if observer |
| 6608 | } //end run |
| 6609 | }); |
| 6610 | } |
| 6611 | |
| 6612 | private boolean getPackageSizeInfoLI(String packageName, PackageStats pStats) { |
| 6613 | if (packageName == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6614 | 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] | 6615 | return false; |
| 6616 | } |
| 6617 | PackageParser.Package p; |
| 6618 | boolean dataOnly = false; |
| 6619 | synchronized (mPackages) { |
| 6620 | p = mPackages.get(packageName); |
| 6621 | if(p == null) { |
| 6622 | dataOnly = true; |
| 6623 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6624 | if((ps == null) || (ps.pkg == null)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6625 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6626 | return false; |
| 6627 | } |
| 6628 | p = ps.pkg; |
| 6629 | } |
| 6630 | } |
| 6631 | String publicSrcDir = null; |
| 6632 | if(!dataOnly) { |
| 6633 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6634 | if (applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6635 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6636 | return false; |
| 6637 | } |
| 6638 | publicSrcDir = isForwardLocked(p) ? applicationInfo.publicSourceDir : null; |
| 6639 | } |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6640 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6641 | if (mInstaller != null) { |
| 6642 | int res = mInstaller.getSizeInfo(packageName, p.mPath, |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6643 | publicSrcDir, pStats, useEncryptedFSDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6644 | if (res < 0) { |
| 6645 | return false; |
| 6646 | } else { |
| 6647 | return true; |
| 6648 | } |
| 6649 | } |
| 6650 | return true; |
| 6651 | } |
| 6652 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6654 | public void addPackageToPreferred(String packageName) { |
Dianne Hackborn | 8377fc0 | 2010-06-07 15:54:58 -0700 | [diff] [blame] | 6655 | 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] | 6656 | } |
| 6657 | |
| 6658 | public void removePackageFromPreferred(String packageName) { |
Dianne Hackborn | 8377fc0 | 2010-06-07 15:54:58 -0700 | [diff] [blame] | 6659 | 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] | 6660 | } |
| 6661 | |
| 6662 | public List<PackageInfo> getPreferredPackages(int flags) { |
Dianne Hackborn | a7ca0e5 | 2009-12-01 14:31:55 -0800 | [diff] [blame] | 6663 | return new ArrayList<PackageInfo>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6664 | } |
| 6665 | |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6666 | int getUidTargetSdkVersionLockedLP(int uid) { |
| 6667 | Object obj = mSettings.getUserIdLP(uid); |
| 6668 | if (obj instanceof SharedUserSetting) { |
| 6669 | SharedUserSetting sus = (SharedUserSetting)obj; |
| 6670 | final int N = sus.packages.size(); |
| 6671 | int vers = Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 6672 | Iterator<PackageSetting> it = sus.packages.iterator(); |
| 6673 | int i=0; |
| 6674 | while (it.hasNext()) { |
| 6675 | PackageSetting ps = it.next(); |
| 6676 | if (ps.pkg != null) { |
| 6677 | int v = ps.pkg.applicationInfo.targetSdkVersion; |
| 6678 | if (v < vers) vers = v; |
| 6679 | } |
| 6680 | } |
| 6681 | return vers; |
| 6682 | } else if (obj instanceof PackageSetting) { |
| 6683 | PackageSetting ps = (PackageSetting)obj; |
| 6684 | if (ps.pkg != null) { |
| 6685 | return ps.pkg.applicationInfo.targetSdkVersion; |
| 6686 | } |
| 6687 | } |
| 6688 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 6689 | } |
| 6690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6691 | public void addPreferredActivity(IntentFilter filter, int match, |
| 6692 | ComponentName[] set, ComponentName activity) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6693 | synchronized (mPackages) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6694 | if (mContext.checkCallingOrSelfPermission( |
| 6695 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6696 | != PackageManager.PERMISSION_GRANTED) { |
| 6697 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6698 | < Build.VERSION_CODES.FROYO) { |
| 6699 | Slog.w(TAG, "Ignoring addPreferredActivity() from uid " |
| 6700 | + Binder.getCallingUid()); |
| 6701 | return; |
| 6702 | } |
| 6703 | mContext.enforceCallingOrSelfPermission( |
| 6704 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6705 | } |
| 6706 | |
| 6707 | Slog.i(TAG, "Adding preferred activity " + activity + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6708 | filter.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 6709 | mSettings.mPreferredActivities.addFilter( |
| 6710 | new PreferredActivity(filter, match, set, activity)); |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6711 | scheduleWriteSettingsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6712 | } |
| 6713 | } |
| 6714 | |
Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6715 | public void replacePreferredActivity(IntentFilter filter, int match, |
| 6716 | ComponentName[] set, ComponentName activity) { |
Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6717 | if (filter.countActions() != 1) { |
| 6718 | throw new IllegalArgumentException( |
| 6719 | "replacePreferredActivity expects filter to have only 1 action."); |
| 6720 | } |
| 6721 | if (filter.countCategories() != 1) { |
| 6722 | throw new IllegalArgumentException( |
| 6723 | "replacePreferredActivity expects filter to have only 1 category."); |
| 6724 | } |
| 6725 | if (filter.countDataAuthorities() != 0 |
| 6726 | || filter.countDataPaths() != 0 |
| 6727 | || filter.countDataSchemes() != 0 |
| 6728 | || filter.countDataTypes() != 0) { |
| 6729 | throw new IllegalArgumentException( |
| 6730 | "replacePreferredActivity expects filter to have no data authorities, " + |
| 6731 | "paths, schemes or types."); |
| 6732 | } |
| 6733 | synchronized (mPackages) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6734 | if (mContext.checkCallingOrSelfPermission( |
| 6735 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6736 | != PackageManager.PERMISSION_GRANTED) { |
| 6737 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6738 | < Build.VERSION_CODES.FROYO) { |
| 6739 | Slog.w(TAG, "Ignoring replacePreferredActivity() from uid " |
| 6740 | + Binder.getCallingUid()); |
| 6741 | return; |
| 6742 | } |
| 6743 | mContext.enforceCallingOrSelfPermission( |
| 6744 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6745 | } |
| 6746 | |
Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6747 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6748 | String action = filter.getAction(0); |
| 6749 | String category = filter.getCategory(0); |
| 6750 | while (it.hasNext()) { |
| 6751 | PreferredActivity pa = it.next(); |
| 6752 | if (pa.getAction(0).equals(action) && pa.getCategory(0).equals(category)) { |
| 6753 | it.remove(); |
| 6754 | Log.i(TAG, "Removed preferred activity " + pa.mActivity + ":"); |
| 6755 | filter.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 6756 | } |
| 6757 | } |
| 6758 | addPreferredActivity(filter, match, set, activity); |
| 6759 | } |
| 6760 | } |
| 6761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6762 | public void clearPackagePreferredActivities(String packageName) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6763 | synchronized (mPackages) { |
Dianne Hackborn | 2ee89ea | 2010-03-10 18:27:09 -0800 | [diff] [blame] | 6764 | int uid = Binder.getCallingUid(); |
| 6765 | PackageParser.Package pkg = mPackages.get(packageName); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6766 | if (pkg == null || pkg.applicationInfo.uid != uid) { |
| 6767 | if (mContext.checkCallingOrSelfPermission( |
| 6768 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6769 | != PackageManager.PERMISSION_GRANTED) { |
| 6770 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6771 | < Build.VERSION_CODES.FROYO) { |
| 6772 | Slog.w(TAG, "Ignoring clearPackagePreferredActivities() from uid " |
| 6773 | + Binder.getCallingUid()); |
| 6774 | return; |
| 6775 | } |
| 6776 | mContext.enforceCallingOrSelfPermission( |
| 6777 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6778 | } |
Dianne Hackborn | 2ee89ea | 2010-03-10 18:27:09 -0800 | [diff] [blame] | 6779 | } |
| 6780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6781 | if (clearPackagePreferredActivitiesLP(packageName)) { |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6782 | scheduleWriteSettingsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6783 | } |
| 6784 | } |
| 6785 | } |
| 6786 | |
| 6787 | boolean clearPackagePreferredActivitiesLP(String packageName) { |
| 6788 | boolean changed = false; |
| 6789 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6790 | while (it.hasNext()) { |
| 6791 | PreferredActivity pa = it.next(); |
| 6792 | if (pa.mActivity.getPackageName().equals(packageName)) { |
| 6793 | it.remove(); |
| 6794 | changed = true; |
| 6795 | } |
| 6796 | } |
| 6797 | return changed; |
| 6798 | } |
| 6799 | |
| 6800 | public int getPreferredActivities(List<IntentFilter> outFilters, |
| 6801 | List<ComponentName> outActivities, String packageName) { |
| 6802 | |
| 6803 | int num = 0; |
| 6804 | synchronized (mPackages) { |
| 6805 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6806 | while (it.hasNext()) { |
| 6807 | PreferredActivity pa = it.next(); |
| 6808 | if (packageName == null |
| 6809 | || pa.mActivity.getPackageName().equals(packageName)) { |
| 6810 | if (outFilters != null) { |
| 6811 | outFilters.add(new IntentFilter(pa)); |
| 6812 | } |
| 6813 | if (outActivities != null) { |
| 6814 | outActivities.add(pa.mActivity); |
| 6815 | } |
| 6816 | } |
| 6817 | } |
| 6818 | } |
| 6819 | |
| 6820 | return num; |
| 6821 | } |
| 6822 | |
| 6823 | public void setApplicationEnabledSetting(String appPackageName, |
| 6824 | int newState, int flags) { |
| 6825 | setEnabledSetting(appPackageName, null, newState, flags); |
| 6826 | } |
| 6827 | |
| 6828 | public void setComponentEnabledSetting(ComponentName componentName, |
| 6829 | int newState, int flags) { |
| 6830 | setEnabledSetting(componentName.getPackageName(), |
| 6831 | componentName.getClassName(), newState, flags); |
| 6832 | } |
| 6833 | |
| 6834 | private void setEnabledSetting( |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6835 | 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] | 6836 | if (!(newState == COMPONENT_ENABLED_STATE_DEFAULT |
| 6837 | || newState == COMPONENT_ENABLED_STATE_ENABLED |
| 6838 | || newState == COMPONENT_ENABLED_STATE_DISABLED)) { |
| 6839 | throw new IllegalArgumentException("Invalid new component state: " |
| 6840 | + newState); |
| 6841 | } |
| 6842 | PackageSetting pkgSetting; |
| 6843 | final int uid = Binder.getCallingUid(); |
| 6844 | final int permission = mContext.checkCallingPermission( |
| 6845 | android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE); |
| 6846 | final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6847 | boolean sendNow = false; |
| 6848 | boolean isApp = (className == null); |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6849 | String componentName = isApp ? packageName : className; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6850 | int packageUid = -1; |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6851 | ArrayList<String> components; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6852 | synchronized (mPackages) { |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6853 | pkgSetting = mSettings.mPackages.get(packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6854 | if (pkgSetting == null) { |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6855 | if (className == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6856 | throw new IllegalArgumentException( |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6857 | "Unknown package: " + packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6858 | } |
| 6859 | throw new IllegalArgumentException( |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6860 | "Unknown component: " + packageName |
| 6861 | + "/" + className); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6862 | } |
| 6863 | if (!allowedByPermission && (uid != pkgSetting.userId)) { |
| 6864 | throw new SecurityException( |
| 6865 | "Permission Denial: attempt to change component state from pid=" |
| 6866 | + Binder.getCallingPid() |
| 6867 | + ", uid=" + uid + ", package uid=" + pkgSetting.userId); |
| 6868 | } |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6869 | if (className == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6870 | // We're dealing with an application/package level state change |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6871 | if (pkgSetting.enabled == newState) { |
| 6872 | // Nothing to do |
| 6873 | return; |
| 6874 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | pkgSetting.enabled = newState; |
| 6876 | } else { |
| 6877 | // We're dealing with a component level state change |
| 6878 | switch (newState) { |
| 6879 | case COMPONENT_ENABLED_STATE_ENABLED: |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6880 | if (!pkgSetting.enableComponentLP(className)) { |
| 6881 | return; |
| 6882 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6883 | break; |
| 6884 | case COMPONENT_ENABLED_STATE_DISABLED: |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6885 | if (!pkgSetting.disableComponentLP(className)) { |
| 6886 | return; |
| 6887 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6888 | break; |
| 6889 | case COMPONENT_ENABLED_STATE_DEFAULT: |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 6890 | if (!pkgSetting.restoreComponentLP(className)) { |
| 6891 | return; |
| 6892 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6893 | break; |
| 6894 | default: |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6895 | Slog.e(TAG, "Invalid new component state: " + newState); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6896 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6897 | } |
| 6898 | } |
| 6899 | mSettings.writeLP(); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6900 | packageUid = pkgSetting.userId; |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6901 | components = mPendingBroadcasts.get(packageName); |
| 6902 | boolean newPackage = components == null; |
| 6903 | if (newPackage) { |
| 6904 | components = new ArrayList<String>(); |
| 6905 | } |
| 6906 | if (!components.contains(componentName)) { |
| 6907 | components.add(componentName); |
| 6908 | } |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6909 | if ((flags&PackageManager.DONT_KILL_APP) == 0) { |
| 6910 | sendNow = true; |
| 6911 | // Purge entry from pending broadcast list if another one exists already |
| 6912 | // since we are sending one right away. |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6913 | mPendingBroadcasts.remove(packageName); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6914 | } else { |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6915 | if (newPackage) { |
| 6916 | mPendingBroadcasts.put(packageName, components); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6917 | } |
| 6918 | if (!mHandler.hasMessages(SEND_PENDING_BROADCAST)) { |
| 6919 | // Schedule a message |
| 6920 | mHandler.sendEmptyMessageDelayed(SEND_PENDING_BROADCAST, BROADCAST_DELAY); |
| 6921 | } |
| 6922 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6923 | } |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6925 | long callingId = Binder.clearCallingIdentity(); |
| 6926 | try { |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6927 | if (sendNow) { |
| 6928 | sendPackageChangedBroadcast(packageName, |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6929 | (flags&PackageManager.DONT_KILL_APP) != 0, components, packageUid); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6930 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6931 | } finally { |
| 6932 | Binder.restoreCallingIdentity(callingId); |
| 6933 | } |
| 6934 | } |
| 6935 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6936 | private void sendPackageChangedBroadcast(String packageName, |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6937 | boolean killFlag, ArrayList<String> componentNames, int packageUid) { |
| 6938 | if (false) Log.v(TAG, "Sending package changed: package=" + packageName |
| 6939 | + " components=" + componentNames); |
| 6940 | Bundle extras = new Bundle(4); |
| 6941 | extras.putString(Intent.EXTRA_CHANGED_COMPONENT_NAME, componentNames.get(0)); |
| 6942 | String nameList[] = new String[componentNames.size()]; |
| 6943 | componentNames.toArray(nameList); |
| 6944 | extras.putStringArray(Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST, nameList); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6945 | extras.putBoolean(Intent.EXTRA_DONT_KILL_APP, killFlag); |
| 6946 | extras.putInt(Intent.EXTRA_UID, packageUid); |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 6947 | sendPackageBroadcast(Intent.ACTION_PACKAGE_CHANGED, packageName, extras, null); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6948 | } |
| 6949 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 6950 | public String getInstallerPackageName(String packageName) { |
| 6951 | synchronized (mPackages) { |
| 6952 | PackageSetting pkg = mSettings.mPackages.get(packageName); |
| 6953 | if (pkg == null) { |
| 6954 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 6955 | } |
| 6956 | return pkg.installerPackageName; |
| 6957 | } |
| 6958 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6960 | public int getApplicationEnabledSetting(String appPackageName) { |
| 6961 | synchronized (mPackages) { |
| 6962 | PackageSetting pkg = mSettings.mPackages.get(appPackageName); |
| 6963 | if (pkg == null) { |
| 6964 | throw new IllegalArgumentException("Unknown package: " + appPackageName); |
| 6965 | } |
| 6966 | return pkg.enabled; |
| 6967 | } |
| 6968 | } |
| 6969 | |
| 6970 | public int getComponentEnabledSetting(ComponentName componentName) { |
| 6971 | synchronized (mPackages) { |
| 6972 | final String packageNameStr = componentName.getPackageName(); |
| 6973 | PackageSetting pkg = mSettings.mPackages.get(packageNameStr); |
| 6974 | if (pkg == null) { |
| 6975 | throw new IllegalArgumentException("Unknown component: " + componentName); |
| 6976 | } |
| 6977 | final String classNameStr = componentName.getClassName(); |
| 6978 | return pkg.currentEnabledStateLP(classNameStr); |
| 6979 | } |
| 6980 | } |
| 6981 | |
| 6982 | public void enterSafeMode() { |
| 6983 | if (!mSystemReady) { |
| 6984 | mSafeMode = true; |
| 6985 | } |
| 6986 | } |
| 6987 | |
| 6988 | public void systemReady() { |
| 6989 | mSystemReady = true; |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6990 | |
| 6991 | // Read the compatibilty setting when the system is ready. |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6992 | boolean compatibilityModeEnabled = android.provider.Settings.System.getInt( |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6993 | mContext.getContentResolver(), |
| 6994 | android.provider.Settings.System.COMPATIBILITY_MODE, 1) == 1; |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6995 | PackageParser.setCompatibilityModeEnabled(compatibilityModeEnabled); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6996 | if (DEBUG_SETTINGS) { |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6997 | Log.d(TAG, "compatibility mode:" + compatibilityModeEnabled); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6998 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6999 | } |
| 7000 | |
| 7001 | public boolean isSafeMode() { |
| 7002 | return mSafeMode; |
| 7003 | } |
| 7004 | |
| 7005 | public boolean hasSystemUidErrors() { |
| 7006 | return mHasSystemUidErrors; |
| 7007 | } |
| 7008 | |
| 7009 | static String arrayToString(int[] array) { |
| 7010 | StringBuffer buf = new StringBuffer(128); |
| 7011 | buf.append('['); |
| 7012 | if (array != null) { |
| 7013 | for (int i=0; i<array.length; i++) { |
| 7014 | if (i > 0) buf.append(", "); |
| 7015 | buf.append(array[i]); |
| 7016 | } |
| 7017 | } |
| 7018 | buf.append(']'); |
| 7019 | return buf.toString(); |
| 7020 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7022 | @Override |
| 7023 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 7024 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7025 | != PackageManager.PERMISSION_GRANTED) { |
| 7026 | pw.println("Permission Denial: can't dump ActivityManager from from pid=" |
| 7027 | + Binder.getCallingPid() |
| 7028 | + ", uid=" + Binder.getCallingUid() |
| 7029 | + " without permission " |
| 7030 | + android.Manifest.permission.DUMP); |
| 7031 | return; |
| 7032 | } |
| 7033 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7034 | String packageName = null; |
| 7035 | |
| 7036 | int opti = 0; |
| 7037 | while (opti < args.length) { |
| 7038 | String opt = args[opti]; |
| 7039 | if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') { |
| 7040 | break; |
| 7041 | } |
| 7042 | opti++; |
| 7043 | if ("-a".equals(opt)) { |
| 7044 | // Right now we only know how to print all. |
| 7045 | } else if ("-h".equals(opt)) { |
| 7046 | pw.println("Package manager dump options:"); |
| 7047 | pw.println(" [-h] [cmd] ..."); |
| 7048 | pw.println(" cmd may be one of:"); |
| 7049 | pw.println(" [package.name]: info about given package"); |
| 7050 | return; |
| 7051 | } else { |
| 7052 | pw.println("Unknown argument: " + opt + "; use -h for help"); |
| 7053 | } |
| 7054 | } |
| 7055 | |
| 7056 | // Is the caller requesting to dump a particular piece of data? |
| 7057 | if (opti < args.length) { |
| 7058 | String cmd = args[opti]; |
| 7059 | opti++; |
| 7060 | // Is this a package name? |
| 7061 | if ("android".equals(cmd) || cmd.contains(".")) { |
| 7062 | packageName = cmd; |
| 7063 | } |
| 7064 | } |
| 7065 | |
| 7066 | boolean printedTitle = false; |
| 7067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7068 | synchronized (mPackages) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7069 | if (mActivities.dump(pw, "Activity Resolver Table:", " ", packageName)) { |
| 7070 | printedTitle = true; |
| 7071 | } |
| 7072 | if (mReceivers.dump(pw, printedTitle |
| 7073 | ? "\nReceiver Resolver Table:" : "Receiver Resolver Table:", |
| 7074 | " ", packageName)) { |
| 7075 | printedTitle = true; |
| 7076 | } |
| 7077 | if (mServices.dump(pw, printedTitle |
| 7078 | ? "\nService Resolver Table:" : "Service Resolver Table:", |
| 7079 | " ", packageName)) { |
| 7080 | printedTitle = true; |
| 7081 | } |
| 7082 | if (mSettings.mPreferredActivities.dump(pw, printedTitle |
| 7083 | ? "\nPreferred Activities:" : "Preferred Activities:", |
| 7084 | " ", packageName)) { |
| 7085 | printedTitle = true; |
| 7086 | } |
| 7087 | boolean printedSomething = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7088 | { |
| 7089 | for (BasePermission p : mSettings.mPermissions.values()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7090 | if (packageName != null && !packageName.equals(p.sourcePackage)) { |
| 7091 | continue; |
| 7092 | } |
| 7093 | if (!printedSomething) { |
| 7094 | if (printedTitle) pw.println(" "); |
| 7095 | pw.println("Permissions:"); |
| 7096 | printedSomething = true; |
| 7097 | printedTitle = true; |
| 7098 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7099 | pw.print(" Permission ["); pw.print(p.name); pw.print("] ("); |
| 7100 | pw.print(Integer.toHexString(System.identityHashCode(p))); |
| 7101 | pw.println("):"); |
| 7102 | pw.print(" sourcePackage="); pw.println(p.sourcePackage); |
| 7103 | pw.print(" uid="); pw.print(p.uid); |
| 7104 | pw.print(" gids="); pw.print(arrayToString(p.gids)); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7105 | pw.print(" type="); pw.print(p.type); |
| 7106 | pw.print(" prot="); pw.println(p.protectionLevel); |
| 7107 | if (p.packageSetting != null) { |
| 7108 | pw.print(" packageSetting="); pw.println(p.packageSetting); |
| 7109 | } |
| 7110 | if (p.perm != null) { |
| 7111 | pw.print(" perm="); pw.println(p.perm); |
| 7112 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7113 | } |
| 7114 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7115 | printedSomething = false; |
| 7116 | SharedUserSetting packageSharedUser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7117 | { |
| 7118 | for (PackageSetting ps : mSettings.mPackages.values()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7119 | if (packageName != null && !packageName.equals(ps.realName) |
| 7120 | && !packageName.equals(ps.name)) { |
| 7121 | continue; |
| 7122 | } |
| 7123 | if (!printedSomething) { |
| 7124 | if (printedTitle) pw.println(" "); |
| 7125 | pw.println("Packages:"); |
| 7126 | printedSomething = true; |
| 7127 | printedTitle = true; |
| 7128 | } |
| 7129 | packageSharedUser = ps.sharedUser; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7130 | pw.print(" Package ["); |
| 7131 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 7132 | pw.print("] ("); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7133 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 7134 | pw.println("):"); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7135 | if (ps.realName != null) { |
| 7136 | pw.print(" compat name="); pw.println(ps.name); |
| 7137 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7138 | pw.print(" userId="); pw.print(ps.userId); |
| 7139 | pw.print(" gids="); pw.println(arrayToString(ps.gids)); |
| 7140 | pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 7141 | pw.print(" pkg="); pw.println(ps.pkg); |
| 7142 | pw.print(" codePath="); pw.println(ps.codePathString); |
| 7143 | pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
Kenny Root | 93565c4 | 2010-06-18 15:46:06 -0700 | [diff] [blame^] | 7144 | pw.print(" obbPath="); pw.println(ps.obbPathString); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7145 | if (ps.pkg != null) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7146 | pw.print(" dataDir="); pw.println(ps.pkg.applicationInfo.dataDir); |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7147 | pw.print(" targetSdk="); pw.println(ps.pkg.applicationInfo.targetSdkVersion); |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7148 | pw.print(" supportsScreens=["); |
| 7149 | boolean first = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7150 | if ((ps.pkg.applicationInfo.flags & |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 7151 | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) { |
| 7152 | if (!first) pw.print(", "); |
| 7153 | first = false; |
| 7154 | pw.print("small"); |
| 7155 | } |
| 7156 | if ((ps.pkg.applicationInfo.flags & |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7157 | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) { |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7158 | if (!first) pw.print(", "); |
| 7159 | first = false; |
| 7160 | pw.print("medium"); |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7161 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7162 | if ((ps.pkg.applicationInfo.flags & |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7163 | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) { |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7164 | if (!first) pw.print(", "); |
| 7165 | first = false; |
| 7166 | pw.print("large"); |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7167 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7168 | if ((ps.pkg.applicationInfo.flags & |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 7169 | ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) { |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7170 | if (!first) pw.print(", "); |
| 7171 | first = false; |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 7172 | pw.print("xlarge"); |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 7173 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7174 | if ((ps.pkg.applicationInfo.flags & |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 7175 | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) { |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7176 | if (!first) pw.print(", "); |
| 7177 | first = false; |
| 7178 | pw.print("resizeable"); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 7179 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7180 | if ((ps.pkg.applicationInfo.flags & |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7181 | ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) { |
| 7182 | if (!first) pw.print(", "); |
| 7183 | first = false; |
| 7184 | pw.print("anyDensity"); |
| 7185 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7186 | } |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 7187 | pw.println("]"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7188 | pw.print(" timeStamp="); pw.println(ps.getTimeStampStr()); |
| 7189 | pw.print(" signatures="); pw.println(ps.signatures); |
| 7190 | pw.print(" permissionsFixed="); pw.print(ps.permissionsFixed); |
Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7191 | pw.print(" haveGids="); pw.println(ps.haveGids); |
| 7192 | pw.print(" pkgFlags=0x"); pw.print(Integer.toHexString(ps.pkgFlags)); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7193 | pw.print(" installStatus="); pw.print(ps.installStatus); |
| 7194 | pw.print(" enabled="); pw.println(ps.enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | if (ps.disabledComponents.size() > 0) { |
| 7196 | pw.println(" disabledComponents:"); |
| 7197 | for (String s : ps.disabledComponents) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7198 | pw.print(" "); pw.println(s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7199 | } |
| 7200 | } |
| 7201 | if (ps.enabledComponents.size() > 0) { |
| 7202 | pw.println(" enabledComponents:"); |
| 7203 | for (String s : ps.enabledComponents) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7204 | pw.print(" "); pw.println(s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | } |
| 7206 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7207 | if (ps.grantedPermissions.size() > 0) { |
| 7208 | pw.println(" grantedPermissions:"); |
| 7209 | for (String s : ps.grantedPermissions) { |
| 7210 | pw.print(" "); pw.println(s); |
| 7211 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7212 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7213 | } |
| 7214 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7215 | printedSomething = false; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7216 | if (mSettings.mRenamedPackages.size() > 0) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7217 | for (HashMap.Entry<String, String> e |
| 7218 | : mSettings.mRenamedPackages.entrySet()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7219 | if (packageName != null && !packageName.equals(e.getKey()) |
| 7220 | && !packageName.equals(e.getValue())) { |
| 7221 | continue; |
| 7222 | } |
| 7223 | if (!printedSomething) { |
| 7224 | if (printedTitle) pw.println(" "); |
| 7225 | pw.println("Renamed packages:"); |
| 7226 | printedSomething = true; |
| 7227 | printedTitle = true; |
| 7228 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7229 | pw.print(" "); pw.print(e.getKey()); pw.print(" -> "); |
| 7230 | pw.println(e.getValue()); |
| 7231 | } |
| 7232 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7233 | printedSomething = false; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7234 | if (mSettings.mDisabledSysPackages.size() > 0) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7235 | for (PackageSetting ps : mSettings.mDisabledSysPackages.values()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7236 | if (packageName != null && !packageName.equals(ps.realName) |
| 7237 | && !packageName.equals(ps.name)) { |
| 7238 | continue; |
| 7239 | } |
| 7240 | if (!printedSomething) { |
| 7241 | if (printedTitle) pw.println(" "); |
| 7242 | pw.println("Hidden system packages:"); |
| 7243 | printedSomething = true; |
| 7244 | printedTitle = true; |
| 7245 | } |
| 7246 | pw.print(" Package ["); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7247 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 7248 | pw.print("] ("); |
| 7249 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 7250 | pw.println("):"); |
| 7251 | if (ps.realName != null) { |
| 7252 | pw.print(" compat name="); pw.println(ps.name); |
| 7253 | } |
| 7254 | pw.print(" userId="); pw.println(ps.userId); |
| 7255 | pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 7256 | pw.print(" codePath="); pw.println(ps.codePathString); |
| 7257 | pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
| 7258 | } |
| 7259 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7260 | printedSomething = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7261 | { |
| 7262 | for (SharedUserSetting su : mSettings.mSharedUsers.values()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7263 | if (packageName != null && su != packageSharedUser) { |
| 7264 | continue; |
| 7265 | } |
| 7266 | if (!printedSomething) { |
| 7267 | if (printedTitle) pw.println(" "); |
| 7268 | pw.println("Shared users:"); |
| 7269 | printedSomething = true; |
| 7270 | printedTitle = true; |
| 7271 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7272 | pw.print(" SharedUser ["); pw.print(su.name); pw.print("] ("); |
| 7273 | pw.print(Integer.toHexString(System.identityHashCode(su))); |
| 7274 | pw.println("):"); |
| 7275 | pw.print(" userId="); pw.print(su.userId); |
| 7276 | pw.print(" gids="); pw.println(arrayToString(su.gids)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7277 | pw.println(" grantedPermissions:"); |
| 7278 | for (String s : su.grantedPermissions) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7279 | pw.print(" "); pw.println(s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7280 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7281 | } |
| 7282 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7283 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7284 | if (packageName == null) { |
| 7285 | if (printedTitle) pw.println(" "); |
| 7286 | printedTitle = true; |
| 7287 | pw.println("Settings parse messages:"); |
| 7288 | pw.println(mSettings.mReadMessages.toString()); |
| 7289 | |
| 7290 | pw.println(" "); |
| 7291 | pw.println("Package warning messages:"); |
| 7292 | File fname = getSettingsProblemFile(); |
| 7293 | FileInputStream in; |
| 7294 | try { |
| 7295 | in = new FileInputStream(fname); |
| 7296 | int avail = in.available(); |
| 7297 | byte[] data = new byte[avail]; |
| 7298 | in.read(data); |
| 7299 | pw.println(new String(data)); |
| 7300 | } catch (FileNotFoundException e) { |
| 7301 | } catch (IOException e) { |
| 7302 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7303 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7304 | } |
Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7305 | |
| 7306 | synchronized (mProviders) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7307 | boolean printedSomething = false; |
Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7308 | for (PackageParser.Provider p : mProviders.values()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7309 | if (packageName != null && !packageName.equals(p.info.packageName)) { |
| 7310 | continue; |
| 7311 | } |
| 7312 | if (!printedSomething) { |
| 7313 | if (printedTitle) pw.println(" "); |
| 7314 | pw.println("Registered ContentProviders:"); |
| 7315 | printedSomething = true; |
| 7316 | printedTitle = true; |
| 7317 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7318 | pw.print(" ["); pw.print(p.info.authority); pw.print("]: "); |
Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7319 | pw.println(p.toString()); |
| 7320 | } |
| 7321 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7322 | } |
| 7323 | |
| 7324 | static final class BasePermission { |
| 7325 | final static int TYPE_NORMAL = 0; |
| 7326 | final static int TYPE_BUILTIN = 1; |
| 7327 | final static int TYPE_DYNAMIC = 2; |
| 7328 | |
| 7329 | final String name; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7330 | String sourcePackage; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7331 | PackageSettingBase packageSetting; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7332 | final int type; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7333 | int protectionLevel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7334 | PackageParser.Permission perm; |
| 7335 | PermissionInfo pendingInfo; |
| 7336 | int uid; |
| 7337 | int[] gids; |
| 7338 | |
| 7339 | BasePermission(String _name, String _sourcePackage, int _type) { |
| 7340 | name = _name; |
| 7341 | sourcePackage = _sourcePackage; |
| 7342 | type = _type; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7343 | // Default to most conservative protection level. |
| 7344 | protectionLevel = PermissionInfo.PROTECTION_SIGNATURE; |
| 7345 | } |
| 7346 | |
| 7347 | public String toString() { |
| 7348 | return "BasePermission{" |
| 7349 | + Integer.toHexString(System.identityHashCode(this)) |
| 7350 | + " " + name + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7351 | } |
| 7352 | } |
| 7353 | |
| 7354 | static class PackageSignatures { |
| 7355 | private Signature[] mSignatures; |
| 7356 | |
| 7357 | PackageSignatures(Signature[] sigs) { |
| 7358 | assignSignatures(sigs); |
| 7359 | } |
| 7360 | |
| 7361 | PackageSignatures() { |
| 7362 | } |
| 7363 | |
| 7364 | void writeXml(XmlSerializer serializer, String tagName, |
| 7365 | ArrayList<Signature> pastSignatures) throws IOException { |
| 7366 | if (mSignatures == null) { |
| 7367 | return; |
| 7368 | } |
| 7369 | serializer.startTag(null, tagName); |
| 7370 | serializer.attribute(null, "count", |
| 7371 | Integer.toString(mSignatures.length)); |
| 7372 | for (int i=0; i<mSignatures.length; i++) { |
| 7373 | serializer.startTag(null, "cert"); |
| 7374 | final Signature sig = mSignatures[i]; |
| 7375 | final int sigHash = sig.hashCode(); |
| 7376 | final int numPast = pastSignatures.size(); |
| 7377 | int j; |
| 7378 | for (j=0; j<numPast; j++) { |
| 7379 | Signature pastSig = pastSignatures.get(j); |
| 7380 | if (pastSig.hashCode() == sigHash && pastSig.equals(sig)) { |
| 7381 | serializer.attribute(null, "index", Integer.toString(j)); |
| 7382 | break; |
| 7383 | } |
| 7384 | } |
| 7385 | if (j >= numPast) { |
| 7386 | pastSignatures.add(sig); |
| 7387 | serializer.attribute(null, "index", Integer.toString(numPast)); |
| 7388 | serializer.attribute(null, "key", sig.toCharsString()); |
| 7389 | } |
| 7390 | serializer.endTag(null, "cert"); |
| 7391 | } |
| 7392 | serializer.endTag(null, tagName); |
| 7393 | } |
| 7394 | |
| 7395 | void readXml(XmlPullParser parser, ArrayList<Signature> pastSignatures) |
| 7396 | throws IOException, XmlPullParserException { |
| 7397 | String countStr = parser.getAttributeValue(null, "count"); |
| 7398 | if (countStr == null) { |
| 7399 | reportSettingsProblem(Log.WARN, |
| 7400 | "Error in package manager settings: <signatures> has" |
| 7401 | + " no count at " + parser.getPositionDescription()); |
| 7402 | XmlUtils.skipCurrentTag(parser); |
| 7403 | } |
| 7404 | final int count = Integer.parseInt(countStr); |
| 7405 | mSignatures = new Signature[count]; |
| 7406 | int pos = 0; |
| 7407 | |
| 7408 | int outerDepth = parser.getDepth(); |
| 7409 | int type; |
| 7410 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 7411 | && (type != XmlPullParser.END_TAG |
| 7412 | || parser.getDepth() > outerDepth)) { |
| 7413 | if (type == XmlPullParser.END_TAG |
| 7414 | || type == XmlPullParser.TEXT) { |
| 7415 | continue; |
| 7416 | } |
| 7417 | |
| 7418 | String tagName = parser.getName(); |
| 7419 | if (tagName.equals("cert")) { |
| 7420 | if (pos < count) { |
| 7421 | String index = parser.getAttributeValue(null, "index"); |
| 7422 | if (index != null) { |
| 7423 | try { |
| 7424 | int idx = Integer.parseInt(index); |
| 7425 | String key = parser.getAttributeValue(null, "key"); |
| 7426 | if (key == null) { |
| 7427 | if (idx >= 0 && idx < pastSignatures.size()) { |
| 7428 | Signature sig = pastSignatures.get(idx); |
| 7429 | if (sig != null) { |
| 7430 | mSignatures[pos] = pastSignatures.get(idx); |
| 7431 | pos++; |
| 7432 | } else { |
| 7433 | reportSettingsProblem(Log.WARN, |
| 7434 | "Error in package manager settings: <cert> " |
| 7435 | + "index " + index + " is not defined at " |
| 7436 | + parser.getPositionDescription()); |
| 7437 | } |
| 7438 | } else { |
| 7439 | reportSettingsProblem(Log.WARN, |
| 7440 | "Error in package manager settings: <cert> " |
| 7441 | + "index " + index + " is out of bounds at " |
| 7442 | + parser.getPositionDescription()); |
| 7443 | } |
| 7444 | } else { |
| 7445 | while (pastSignatures.size() <= idx) { |
| 7446 | pastSignatures.add(null); |
| 7447 | } |
| 7448 | Signature sig = new Signature(key); |
| 7449 | pastSignatures.set(idx, sig); |
| 7450 | mSignatures[pos] = sig; |
| 7451 | pos++; |
| 7452 | } |
| 7453 | } catch (NumberFormatException e) { |
| 7454 | reportSettingsProblem(Log.WARN, |
| 7455 | "Error in package manager settings: <cert> " |
| 7456 | + "index " + index + " is not a number at " |
| 7457 | + parser.getPositionDescription()); |
| 7458 | } |
| 7459 | } else { |
| 7460 | reportSettingsProblem(Log.WARN, |
| 7461 | "Error in package manager settings: <cert> has" |
| 7462 | + " no index at " + parser.getPositionDescription()); |
| 7463 | } |
| 7464 | } else { |
| 7465 | reportSettingsProblem(Log.WARN, |
| 7466 | "Error in package manager settings: too " |
| 7467 | + "many <cert> tags, expected " + count |
| 7468 | + " at " + parser.getPositionDescription()); |
| 7469 | } |
| 7470 | } else { |
| 7471 | reportSettingsProblem(Log.WARN, |
| 7472 | "Unknown element under <cert>: " |
| 7473 | + parser.getName()); |
| 7474 | } |
| 7475 | XmlUtils.skipCurrentTag(parser); |
| 7476 | } |
| 7477 | |
| 7478 | if (pos < count) { |
| 7479 | // Should never happen -- there is an error in the written |
| 7480 | // settings -- but if it does we don't want to generate |
| 7481 | // a bad array. |
| 7482 | Signature[] newSigs = new Signature[pos]; |
| 7483 | System.arraycopy(mSignatures, 0, newSigs, 0, pos); |
| 7484 | mSignatures = newSigs; |
| 7485 | } |
| 7486 | } |
| 7487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7488 | private void assignSignatures(Signature[] sigs) { |
| 7489 | if (sigs == null) { |
| 7490 | mSignatures = null; |
| 7491 | return; |
| 7492 | } |
| 7493 | mSignatures = new Signature[sigs.length]; |
| 7494 | for (int i=0; i<sigs.length; i++) { |
| 7495 | mSignatures[i] = sigs[i]; |
| 7496 | } |
| 7497 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7499 | @Override |
| 7500 | public String toString() { |
| 7501 | StringBuffer buf = new StringBuffer(128); |
| 7502 | buf.append("PackageSignatures{"); |
| 7503 | buf.append(Integer.toHexString(System.identityHashCode(this))); |
| 7504 | buf.append(" ["); |
| 7505 | if (mSignatures != null) { |
| 7506 | for (int i=0; i<mSignatures.length; i++) { |
| 7507 | if (i > 0) buf.append(", "); |
| 7508 | buf.append(Integer.toHexString( |
| 7509 | System.identityHashCode(mSignatures[i]))); |
| 7510 | } |
| 7511 | } |
| 7512 | buf.append("]}"); |
| 7513 | return buf.toString(); |
| 7514 | } |
| 7515 | } |
| 7516 | |
| 7517 | static class PreferredActivity extends IntentFilter { |
| 7518 | final int mMatch; |
| 7519 | final String[] mSetPackages; |
| 7520 | final String[] mSetClasses; |
| 7521 | final String[] mSetComponents; |
| 7522 | final ComponentName mActivity; |
| 7523 | final String mShortActivity; |
| 7524 | String mParseError; |
| 7525 | |
| 7526 | PreferredActivity(IntentFilter filter, int match, ComponentName[] set, |
| 7527 | ComponentName activity) { |
| 7528 | super(filter); |
| 7529 | mMatch = match&IntentFilter.MATCH_CATEGORY_MASK; |
| 7530 | mActivity = activity; |
| 7531 | mShortActivity = activity.flattenToShortString(); |
| 7532 | mParseError = null; |
| 7533 | if (set != null) { |
| 7534 | final int N = set.length; |
| 7535 | String[] myPackages = new String[N]; |
| 7536 | String[] myClasses = new String[N]; |
| 7537 | String[] myComponents = new String[N]; |
| 7538 | for (int i=0; i<N; i++) { |
| 7539 | ComponentName cn = set[i]; |
| 7540 | if (cn == null) { |
| 7541 | mSetPackages = null; |
| 7542 | mSetClasses = null; |
| 7543 | mSetComponents = null; |
| 7544 | return; |
| 7545 | } |
| 7546 | myPackages[i] = cn.getPackageName().intern(); |
| 7547 | myClasses[i] = cn.getClassName().intern(); |
| 7548 | myComponents[i] = cn.flattenToShortString().intern(); |
| 7549 | } |
| 7550 | mSetPackages = myPackages; |
| 7551 | mSetClasses = myClasses; |
| 7552 | mSetComponents = myComponents; |
| 7553 | } else { |
| 7554 | mSetPackages = null; |
| 7555 | mSetClasses = null; |
| 7556 | mSetComponents = null; |
| 7557 | } |
| 7558 | } |
| 7559 | |
| 7560 | PreferredActivity(XmlPullParser parser) throws XmlPullParserException, |
| 7561 | IOException { |
| 7562 | mShortActivity = parser.getAttributeValue(null, "name"); |
| 7563 | mActivity = ComponentName.unflattenFromString(mShortActivity); |
| 7564 | if (mActivity == null) { |
| 7565 | mParseError = "Bad activity name " + mShortActivity; |
| 7566 | } |
| 7567 | String matchStr = parser.getAttributeValue(null, "match"); |
| 7568 | mMatch = matchStr != null ? Integer.parseInt(matchStr, 16) : 0; |
| 7569 | String setCountStr = parser.getAttributeValue(null, "set"); |
| 7570 | int setCount = setCountStr != null ? Integer.parseInt(setCountStr) : 0; |
| 7571 | |
| 7572 | String[] myPackages = setCount > 0 ? new String[setCount] : null; |
| 7573 | String[] myClasses = setCount > 0 ? new String[setCount] : null; |
| 7574 | String[] myComponents = setCount > 0 ? new String[setCount] : null; |
| 7575 | |
| 7576 | int setPos = 0; |
| 7577 | |
| 7578 | int outerDepth = parser.getDepth(); |
| 7579 | int type; |
| 7580 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 7581 | && (type != XmlPullParser.END_TAG |
| 7582 | || parser.getDepth() > outerDepth)) { |
| 7583 | if (type == XmlPullParser.END_TAG |
| 7584 | || type == XmlPullParser.TEXT) { |
| 7585 | continue; |
| 7586 | } |
| 7587 | |
| 7588 | String tagName = parser.getName(); |
| 7589 | //Log.i(TAG, "Parse outerDepth=" + outerDepth + " depth=" |
| 7590 | // + parser.getDepth() + " tag=" + tagName); |
| 7591 | if (tagName.equals("set")) { |
| 7592 | String name = parser.getAttributeValue(null, "name"); |
| 7593 | if (name == null) { |
| 7594 | if (mParseError == null) { |
| 7595 | mParseError = "No name in set tag in preferred activity " |
| 7596 | + mShortActivity; |
| 7597 | } |
| 7598 | } else if (setPos >= setCount) { |
| 7599 | if (mParseError == null) { |
| 7600 | mParseError = "Too many set tags in preferred activity " |
| 7601 | + mShortActivity; |
| 7602 | } |
| 7603 | } else { |
| 7604 | ComponentName cn = ComponentName.unflattenFromString(name); |
| 7605 | if (cn == null) { |
| 7606 | if (mParseError == null) { |
| 7607 | mParseError = "Bad set name " + name + " in preferred activity " |
| 7608 | + mShortActivity; |
| 7609 | } |
| 7610 | } else { |
| 7611 | myPackages[setPos] = cn.getPackageName(); |
| 7612 | myClasses[setPos] = cn.getClassName(); |
| 7613 | myComponents[setPos] = name; |
| 7614 | setPos++; |
| 7615 | } |
| 7616 | } |
| 7617 | XmlUtils.skipCurrentTag(parser); |
| 7618 | } else if (tagName.equals("filter")) { |
| 7619 | //Log.i(TAG, "Starting to parse filter..."); |
| 7620 | readFromXml(parser); |
| 7621 | //Log.i(TAG, "Finished filter: outerDepth=" + outerDepth + " depth=" |
| 7622 | // + parser.getDepth() + " tag=" + parser.getName()); |
| 7623 | } else { |
| 7624 | reportSettingsProblem(Log.WARN, |
| 7625 | "Unknown element under <preferred-activities>: " |
| 7626 | + parser.getName()); |
| 7627 | XmlUtils.skipCurrentTag(parser); |
| 7628 | } |
| 7629 | } |
| 7630 | |
| 7631 | if (setPos != setCount) { |
| 7632 | if (mParseError == null) { |
| 7633 | mParseError = "Not enough set tags (expected " + setCount |
| 7634 | + " but found " + setPos + ") in " + mShortActivity; |
| 7635 | } |
| 7636 | } |
| 7637 | |
| 7638 | mSetPackages = myPackages; |
| 7639 | mSetClasses = myClasses; |
| 7640 | mSetComponents = myComponents; |
| 7641 | } |
| 7642 | |
| 7643 | public void writeToXml(XmlSerializer serializer) throws IOException { |
| 7644 | final int NS = mSetClasses != null ? mSetClasses.length : 0; |
| 7645 | serializer.attribute(null, "name", mShortActivity); |
| 7646 | serializer.attribute(null, "match", Integer.toHexString(mMatch)); |
| 7647 | serializer.attribute(null, "set", Integer.toString(NS)); |
| 7648 | for (int s=0; s<NS; s++) { |
| 7649 | serializer.startTag(null, "set"); |
| 7650 | serializer.attribute(null, "name", mSetComponents[s]); |
| 7651 | serializer.endTag(null, "set"); |
| 7652 | } |
| 7653 | serializer.startTag(null, "filter"); |
| 7654 | super.writeToXml(serializer); |
| 7655 | serializer.endTag(null, "filter"); |
| 7656 | } |
| 7657 | |
| 7658 | boolean sameSet(List<ResolveInfo> query, int priority) { |
| 7659 | if (mSetPackages == null) return false; |
| 7660 | final int NQ = query.size(); |
| 7661 | final int NS = mSetPackages.length; |
| 7662 | int numMatch = 0; |
| 7663 | for (int i=0; i<NQ; i++) { |
| 7664 | ResolveInfo ri = query.get(i); |
| 7665 | if (ri.priority != priority) continue; |
| 7666 | ActivityInfo ai = ri.activityInfo; |
| 7667 | boolean good = false; |
| 7668 | for (int j=0; j<NS; j++) { |
| 7669 | if (mSetPackages[j].equals(ai.packageName) |
| 7670 | && mSetClasses[j].equals(ai.name)) { |
| 7671 | numMatch++; |
| 7672 | good = true; |
| 7673 | break; |
| 7674 | } |
| 7675 | } |
| 7676 | if (!good) return false; |
| 7677 | } |
| 7678 | return numMatch == NS; |
| 7679 | } |
| 7680 | } |
| 7681 | |
| 7682 | static class GrantedPermissions { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 7683 | int pkgFlags; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7685 | HashSet<String> grantedPermissions = new HashSet<String>(); |
| 7686 | int[] gids; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7688 | GrantedPermissions(int pkgFlags) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 7689 | setFlags(pkgFlags); |
| 7690 | } |
| 7691 | |
| 7692 | void setFlags(int pkgFlags) { |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 7693 | this.pkgFlags = pkgFlags & ( |
| 7694 | ApplicationInfo.FLAG_SYSTEM | |
| 7695 | ApplicationInfo.FLAG_FORWARD_LOCK | |
Jeff Brown | a749f86 | 2010-03-31 00:43:36 -0700 | [diff] [blame] | 7696 | ApplicationInfo.FLAG_EXTERNAL_STORAGE | |
Jeff Brown | 767225d | 2010-03-30 23:49:17 -0700 | [diff] [blame] | 7697 | ApplicationInfo.FLAG_NEVER_ENCRYPT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7698 | } |
| 7699 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7701 | /** |
| 7702 | * Settings base class for pending and resolved classes. |
| 7703 | */ |
| 7704 | static class PackageSettingBase extends GrantedPermissions { |
| 7705 | final String name; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7706 | final String realName; |
Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 7707 | File codePath; |
| 7708 | String codePathString; |
| 7709 | File resourcePath; |
| 7710 | String resourcePathString; |
Kenny Root | 93565c4 | 2010-06-18 15:46:06 -0700 | [diff] [blame^] | 7711 | String obbPathString; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | private long timeStamp; |
| 7713 | private String timeStampString = "0"; |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 7714 | int versionCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7715 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7716 | boolean uidError; |
| 7717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7718 | PackageSignatures signatures = new PackageSignatures(); |
| 7719 | |
| 7720 | boolean permissionsFixed; |
Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7721 | boolean haveGids; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7723 | /* Explicitly disabled components */ |
| 7724 | HashSet<String> disabledComponents = new HashSet<String>(0); |
| 7725 | /* Explicitly enabled components */ |
| 7726 | HashSet<String> enabledComponents = new HashSet<String>(0); |
| 7727 | int enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 7728 | int installStatus = PKG_INSTALL_COMPLETE; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7729 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7730 | PackageSettingBase origPackage; |
| 7731 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7732 | /* package name of the app that installed this package */ |
| 7733 | String installerPackageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7734 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7735 | PackageSettingBase(String name, String realName, File codePath, File resourcePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7736 | int pVersionCode, int pkgFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7737 | super(pkgFlags); |
| 7738 | this.name = name; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7739 | this.realName = realName; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7740 | init(codePath, resourcePath, pVersionCode); |
| 7741 | } |
| 7742 | |
| 7743 | void init(File codePath, File resourcePath, int pVersionCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7744 | this.codePath = codePath; |
| 7745 | this.codePathString = codePath.toString(); |
| 7746 | this.resourcePath = resourcePath; |
| 7747 | this.resourcePathString = resourcePath.toString(); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7748 | this.versionCode = pVersionCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7749 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7750 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7751 | public void setInstallerPackageName(String packageName) { |
| 7752 | installerPackageName = packageName; |
| 7753 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7754 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7755 | String getInstallerPackageName() { |
| 7756 | return installerPackageName; |
| 7757 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7758 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7759 | public void setInstallStatus(int newStatus) { |
| 7760 | installStatus = newStatus; |
| 7761 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7763 | public int getInstallStatus() { |
| 7764 | return installStatus; |
| 7765 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7767 | public void setTimeStamp(long newStamp) { |
| 7768 | if (newStamp != timeStamp) { |
| 7769 | timeStamp = newStamp; |
| 7770 | timeStampString = Long.toString(newStamp); |
| 7771 | } |
| 7772 | } |
| 7773 | |
| 7774 | public void setTimeStamp(long newStamp, String newStampStr) { |
| 7775 | timeStamp = newStamp; |
| 7776 | timeStampString = newStampStr; |
| 7777 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7778 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7779 | public long getTimeStamp() { |
| 7780 | return timeStamp; |
| 7781 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7783 | public String getTimeStampStr() { |
| 7784 | return timeStampString; |
| 7785 | } |
| 7786 | |
| 7787 | public void copyFrom(PackageSettingBase base) { |
| 7788 | grantedPermissions = base.grantedPermissions; |
| 7789 | gids = base.gids; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | timeStamp = base.timeStamp; |
| 7792 | timeStampString = base.timeStampString; |
| 7793 | signatures = base.signatures; |
| 7794 | permissionsFixed = base.permissionsFixed; |
Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7795 | haveGids = base.haveGids; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7796 | disabledComponents = base.disabledComponents; |
| 7797 | enabledComponents = base.enabledComponents; |
| 7798 | enabled = base.enabled; |
| 7799 | installStatus = base.installStatus; |
| 7800 | } |
| 7801 | |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 7802 | boolean enableComponentLP(String componentClassName) { |
| 7803 | boolean changed = disabledComponents.remove(componentClassName); |
| 7804 | changed |= enabledComponents.add(componentClassName); |
| 7805 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7806 | } |
| 7807 | |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 7808 | boolean disableComponentLP(String componentClassName) { |
| 7809 | boolean changed = enabledComponents.remove(componentClassName); |
| 7810 | changed |= disabledComponents.add(componentClassName); |
| 7811 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7812 | } |
| 7813 | |
Dianne Hackborn | d7c0968 | 2010-03-30 10:42:20 -0700 | [diff] [blame] | 7814 | boolean restoreComponentLP(String componentClassName) { |
| 7815 | boolean changed = enabledComponents.remove(componentClassName); |
| 7816 | changed |= disabledComponents.remove(componentClassName); |
| 7817 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7818 | } |
| 7819 | |
| 7820 | int currentEnabledStateLP(String componentName) { |
| 7821 | if (enabledComponents.contains(componentName)) { |
| 7822 | return COMPONENT_ENABLED_STATE_ENABLED; |
| 7823 | } else if (disabledComponents.contains(componentName)) { |
| 7824 | return COMPONENT_ENABLED_STATE_DISABLED; |
| 7825 | } else { |
| 7826 | return COMPONENT_ENABLED_STATE_DEFAULT; |
| 7827 | } |
| 7828 | } |
| 7829 | } |
| 7830 | |
| 7831 | /** |
| 7832 | * Settings data for a particular package we know about. |
| 7833 | */ |
| 7834 | static final class PackageSetting extends PackageSettingBase { |
| 7835 | int userId; |
| 7836 | PackageParser.Package pkg; |
| 7837 | SharedUserSetting sharedUser; |
| 7838 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7839 | PackageSetting(String name, String realName, File codePath, File resourcePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7840 | int pVersionCode, int pkgFlags) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7841 | super(name, realName, codePath, resourcePath, pVersionCode, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7842 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7843 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7844 | @Override |
| 7845 | public String toString() { |
| 7846 | return "PackageSetting{" |
| 7847 | + Integer.toHexString(System.identityHashCode(this)) |
| 7848 | + " " + name + "/" + userId + "}"; |
| 7849 | } |
| 7850 | } |
| 7851 | |
| 7852 | /** |
| 7853 | * Settings data for a particular shared user ID we know about. |
| 7854 | */ |
| 7855 | static final class SharedUserSetting extends GrantedPermissions { |
| 7856 | final String name; |
| 7857 | int userId; |
| 7858 | final HashSet<PackageSetting> packages = new HashSet<PackageSetting>(); |
| 7859 | final PackageSignatures signatures = new PackageSignatures(); |
| 7860 | |
| 7861 | SharedUserSetting(String _name, int _pkgFlags) { |
| 7862 | super(_pkgFlags); |
| 7863 | name = _name; |
| 7864 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7866 | @Override |
| 7867 | public String toString() { |
| 7868 | return "SharedUserSetting{" |
| 7869 | + Integer.toHexString(System.identityHashCode(this)) |
| 7870 | + " " + name + "/" + userId + "}"; |
| 7871 | } |
| 7872 | } |
| 7873 | |
| 7874 | /** |
| 7875 | * Holds information about dynamic settings. |
| 7876 | */ |
| 7877 | private static final class Settings { |
| 7878 | private final File mSettingsFilename; |
| 7879 | private final File mBackupSettingsFilename; |
David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 7880 | private final File mPackageListFilename; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7881 | private final HashMap<String, PackageSetting> mPackages = |
| 7882 | new HashMap<String, PackageSetting>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7883 | // List of replaced system applications |
| 7884 | final HashMap<String, PackageSetting> mDisabledSysPackages = |
| 7885 | new HashMap<String, PackageSetting>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7886 | |
Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 7887 | // These are the last platform API version we were using for |
| 7888 | // the apps installed on internal and external storage. It is |
| 7889 | // used to grant newer permissions one time during a system upgrade. |
| 7890 | int mInternalSdkPlatform; |
| 7891 | int mExternalSdkPlatform; |
| 7892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7893 | // The user's preferred activities associated with particular intent |
| 7894 | // filters. |
| 7895 | private final IntentResolver<PreferredActivity, PreferredActivity> mPreferredActivities = |
| 7896 | new IntentResolver<PreferredActivity, PreferredActivity>() { |
| 7897 | @Override |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7898 | protected String packageForFilter(PreferredActivity filter) { |
| 7899 | return filter.mActivity.getPackageName(); |
| 7900 | } |
| 7901 | @Override |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7902 | protected void dumpFilter(PrintWriter out, String prefix, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7903 | PreferredActivity filter) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7904 | out.print(prefix); out.print( |
| 7905 | Integer.toHexString(System.identityHashCode(filter))); |
| 7906 | out.print(' '); |
| 7907 | out.print(filter.mActivity.flattenToShortString()); |
| 7908 | out.print(" match=0x"); |
| 7909 | out.println( Integer.toHexString(filter.mMatch)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7910 | if (filter.mSetComponents != null) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7911 | out.print(prefix); out.println(" Selected from:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7912 | for (int i=0; i<filter.mSetComponents.length; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7913 | out.print(prefix); out.print(" "); |
| 7914 | out.println(filter.mSetComponents[i]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7915 | } |
| 7916 | } |
| 7917 | } |
| 7918 | }; |
| 7919 | private final HashMap<String, SharedUserSetting> mSharedUsers = |
| 7920 | new HashMap<String, SharedUserSetting>(); |
| 7921 | private final ArrayList<Object> mUserIds = new ArrayList<Object>(); |
| 7922 | private final SparseArray<Object> mOtherUserIds = |
| 7923 | new SparseArray<Object>(); |
| 7924 | |
| 7925 | // For reading/writing settings file. |
| 7926 | private final ArrayList<Signature> mPastSignatures = |
| 7927 | new ArrayList<Signature>(); |
| 7928 | |
| 7929 | // Mapping from permission names to info about them. |
| 7930 | final HashMap<String, BasePermission> mPermissions = |
| 7931 | new HashMap<String, BasePermission>(); |
| 7932 | |
| 7933 | // Mapping from permission tree names to info about them. |
| 7934 | final HashMap<String, BasePermission> mPermissionTrees = |
| 7935 | new HashMap<String, BasePermission>(); |
| 7936 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 7937 | // Packages that have been uninstalled and still need their external |
| 7938 | // storage data deleted. |
| 7939 | final ArrayList<String> mPackagesToBeCleaned = new ArrayList<String>(); |
| 7940 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7941 | // Packages that have been renamed since they were first installed. |
| 7942 | // Keys are the new names of the packages, values are the original |
| 7943 | // names. The packages appear everwhere else under their original |
| 7944 | // names. |
| 7945 | final HashMap<String, String> mRenamedPackages = new HashMap<String, String>(); |
| 7946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7947 | private final StringBuilder mReadMessages = new StringBuilder(); |
| 7948 | |
| 7949 | private static final class PendingPackage extends PackageSettingBase { |
| 7950 | final int sharedId; |
| 7951 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7952 | PendingPackage(String name, String realName, File codePath, File resourcePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7953 | int sharedId, int pVersionCode, int pkgFlags) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7954 | super(name, realName, codePath, resourcePath, pVersionCode, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7955 | this.sharedId = sharedId; |
| 7956 | } |
| 7957 | } |
| 7958 | private final ArrayList<PendingPackage> mPendingPackages |
| 7959 | = new ArrayList<PendingPackage>(); |
| 7960 | |
| 7961 | Settings() { |
| 7962 | File dataDir = Environment.getDataDirectory(); |
| 7963 | File systemDir = new File(dataDir, "system"); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7964 | // TODO(oam): This secure dir creation needs to be moved somewhere else (later) |
| 7965 | File systemSecureDir = new File(dataDir, "secure/system"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7966 | systemDir.mkdirs(); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7967 | systemSecureDir.mkdirs(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7968 | FileUtils.setPermissions(systemDir.toString(), |
| 7969 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 7970 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 7971 | -1, -1); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7972 | FileUtils.setPermissions(systemSecureDir.toString(), |
| 7973 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 7974 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 7975 | -1, -1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7976 | mSettingsFilename = new File(systemDir, "packages.xml"); |
| 7977 | mBackupSettingsFilename = new File(systemDir, "packages-backup.xml"); |
David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 7978 | mPackageListFilename = new File(systemDir, "packages.list"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7979 | } |
| 7980 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7981 | PackageSetting getPackageLP(PackageParser.Package pkg, PackageSetting origPackage, |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7982 | String realName, SharedUserSetting sharedUser, File codePath, File resourcePath, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7983 | int pkgFlags, boolean create, boolean add) { |
| 7984 | final String name = pkg.packageName; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7985 | PackageSetting p = getPackageLP(name, origPackage, realName, sharedUser, codePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7986 | resourcePath, pkg.mVersionCode, pkgFlags, create, add); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7987 | return p; |
| 7988 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7989 | |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7990 | PackageSetting peekPackageLP(String name) { |
| 7991 | return mPackages.get(name); |
| 7992 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7993 | PackageSetting p = mPackages.get(name); |
| 7994 | if (p != null && p.codePath.getPath().equals(codePath)) { |
| 7995 | return p; |
| 7996 | } |
| 7997 | return null; |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7998 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7999 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8001 | void setInstallStatus(String pkgName, int status) { |
| 8002 | PackageSetting p = mPackages.get(pkgName); |
| 8003 | if(p != null) { |
| 8004 | if(p.getInstallStatus() != status) { |
| 8005 | p.setInstallStatus(status); |
| 8006 | } |
| 8007 | } |
| 8008 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8009 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8010 | void setInstallerPackageName(String pkgName, |
| 8011 | String installerPkgName) { |
| 8012 | PackageSetting p = mPackages.get(pkgName); |
| 8013 | if(p != null) { |
| 8014 | p.setInstallerPackageName(installerPkgName); |
| 8015 | } |
| 8016 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8017 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8018 | String getInstallerPackageName(String pkgName) { |
| 8019 | PackageSetting p = mPackages.get(pkgName); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8020 | return (p == null) ? null : p.getInstallerPackageName(); |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8021 | } |
| 8022 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8023 | int getInstallStatus(String pkgName) { |
| 8024 | PackageSetting p = mPackages.get(pkgName); |
| 8025 | if(p != null) { |
| 8026 | return p.getInstallStatus(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8027 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8028 | return -1; |
| 8029 | } |
| 8030 | |
| 8031 | SharedUserSetting getSharedUserLP(String name, |
| 8032 | int pkgFlags, boolean create) { |
| 8033 | SharedUserSetting s = mSharedUsers.get(name); |
| 8034 | if (s == null) { |
| 8035 | if (!create) { |
| 8036 | return null; |
| 8037 | } |
| 8038 | s = new SharedUserSetting(name, pkgFlags); |
| 8039 | if (MULTIPLE_APPLICATION_UIDS) { |
| 8040 | s.userId = newUserIdLP(s); |
| 8041 | } else { |
| 8042 | s.userId = FIRST_APPLICATION_UID; |
| 8043 | } |
| 8044 | Log.i(TAG, "New shared user " + name + ": id=" + s.userId); |
| 8045 | // < 0 means we couldn't assign a userid; fall out and return |
| 8046 | // s, which is currently null |
| 8047 | if (s.userId >= 0) { |
| 8048 | mSharedUsers.put(name, s); |
| 8049 | } |
| 8050 | } |
| 8051 | |
| 8052 | return s; |
| 8053 | } |
| 8054 | |
| 8055 | int disableSystemPackageLP(String name) { |
| 8056 | PackageSetting p = mPackages.get(name); |
| 8057 | if(p == null) { |
| 8058 | Log.w(TAG, "Package:"+name+" is not an installed package"); |
| 8059 | return -1; |
| 8060 | } |
| 8061 | PackageSetting dp = mDisabledSysPackages.get(name); |
| 8062 | // always make sure the system package code and resource paths dont change |
| 8063 | if(dp == null) { |
| 8064 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 8065 | p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 8066 | } |
| 8067 | mDisabledSysPackages.put(name, p); |
| 8068 | } |
| 8069 | return removePackageLP(name); |
| 8070 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8072 | PackageSetting enableSystemPackageLP(String name) { |
| 8073 | PackageSetting p = mDisabledSysPackages.get(name); |
| 8074 | if(p == null) { |
| 8075 | Log.w(TAG, "Package:"+name+" is not disabled"); |
| 8076 | return null; |
| 8077 | } |
| 8078 | // Reset flag in ApplicationInfo object |
| 8079 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 8080 | p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 8081 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8082 | PackageSetting ret = addPackageLP(name, p.realName, p.codePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8083 | p.resourcePath, p.userId, p.versionCode, p.pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8084 | mDisabledSysPackages.remove(name); |
| 8085 | return ret; |
| 8086 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8087 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8088 | PackageSetting addPackageLP(String name, String realName, File codePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8089 | File resourcePath, int uid, int vc, int pkgFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8090 | PackageSetting p = mPackages.get(name); |
| 8091 | if (p != null) { |
| 8092 | if (p.userId == uid) { |
| 8093 | return p; |
| 8094 | } |
| 8095 | reportSettingsProblem(Log.ERROR, |
| 8096 | "Adding duplicate package, keeping first: " + name); |
| 8097 | return null; |
| 8098 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8099 | p = new PackageSetting(name, realName, codePath, resourcePath, vc, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8100 | p.userId = uid; |
| 8101 | if (addUserIdLP(uid, p, name)) { |
| 8102 | mPackages.put(name, p); |
| 8103 | return p; |
| 8104 | } |
| 8105 | return null; |
| 8106 | } |
| 8107 | |
| 8108 | SharedUserSetting addSharedUserLP(String name, int uid, int pkgFlags) { |
| 8109 | SharedUserSetting s = mSharedUsers.get(name); |
| 8110 | if (s != null) { |
| 8111 | if (s.userId == uid) { |
| 8112 | return s; |
| 8113 | } |
| 8114 | reportSettingsProblem(Log.ERROR, |
| 8115 | "Adding duplicate shared user, keeping first: " + name); |
| 8116 | return null; |
| 8117 | } |
| 8118 | s = new SharedUserSetting(name, pkgFlags); |
| 8119 | s.userId = uid; |
| 8120 | if (addUserIdLP(uid, s, name)) { |
| 8121 | mSharedUsers.put(name, s); |
| 8122 | return s; |
| 8123 | } |
| 8124 | return null; |
| 8125 | } |
| 8126 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8127 | // Transfer ownership of permissions from one package to another. |
| 8128 | private void transferPermissions(String origPkg, String newPkg) { |
| 8129 | // Transfer ownership of permissions to the new package. |
| 8130 | for (int i=0; i<2; i++) { |
| 8131 | HashMap<String, BasePermission> permissions = |
| 8132 | i == 0 ? mPermissionTrees : mPermissions; |
| 8133 | for (BasePermission bp : permissions.values()) { |
| 8134 | if (origPkg.equals(bp.sourcePackage)) { |
| 8135 | if (DEBUG_UPGRADE) Log.v(TAG, |
| 8136 | "Moving permission " + bp.name |
| 8137 | + " from pkg " + bp.sourcePackage |
| 8138 | + " to " + newPkg); |
| 8139 | bp.sourcePackage = newPkg; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8140 | bp.packageSetting = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8141 | bp.perm = null; |
| 8142 | if (bp.pendingInfo != null) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8143 | bp.pendingInfo.packageName = newPkg; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8144 | } |
| 8145 | bp.uid = 0; |
| 8146 | bp.gids = null; |
| 8147 | } |
| 8148 | } |
| 8149 | } |
| 8150 | } |
| 8151 | |
| 8152 | private PackageSetting getPackageLP(String name, PackageSetting origPackage, |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8153 | String realName, SharedUserSetting sharedUser, File codePath, File resourcePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8154 | int vc, int pkgFlags, boolean create, boolean add) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8155 | PackageSetting p = mPackages.get(name); |
| 8156 | if (p != null) { |
| 8157 | if (!p.codePath.equals(codePath)) { |
| 8158 | // Check to see if its a disabled system app |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8159 | if((p != null) && ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0)) { |
Suchi Amalapurapu | b24a967 | 2009-07-01 14:04:43 -0700 | [diff] [blame] | 8160 | // This is an updated system app with versions in both system |
| 8161 | // and data partition. Just let the most recent version |
| 8162 | // take precedence. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8163 | Slog.w(TAG, "Trying to update system app code path from " + |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8164 | p.codePathString + " to " + codePath.toString()); |
Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 8165 | } else { |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 8166 | // Just a change in the code path is not an issue, but |
| 8167 | // let's log a message about it. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8168 | Slog.i(TAG, "Package " + name + " codePath changed from " + p.codePath |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8169 | + " to " + codePath + "; Retaining data and using new"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8170 | } |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8171 | } |
| 8172 | if (p.sharedUser != sharedUser) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8173 | reportSettingsProblem(Log.WARN, |
| 8174 | "Package " + name + " shared user changed from " |
| 8175 | + (p.sharedUser != null ? p.sharedUser.name : "<nothing>") |
| 8176 | + " to " |
| 8177 | + (sharedUser != null ? sharedUser.name : "<nothing>") |
| 8178 | + "; replacing with new"); |
| 8179 | p = null; |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8180 | } else { |
| 8181 | if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 8182 | // If what we are scanning is a system package, then |
| 8183 | // make it so, regardless of whether it was previously |
| 8184 | // installed only in the data partition. |
| 8185 | p.pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 8186 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8187 | } |
| 8188 | } |
| 8189 | if (p == null) { |
| 8190 | // Create a new PackageSettings entry. this can end up here because |
| 8191 | // of code path mismatch or user id mismatch of an updated system partition |
| 8192 | if (!create) { |
| 8193 | return null; |
| 8194 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8195 | if (origPackage != null) { |
| 8196 | // We are consuming the data from an existing package. |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8197 | p = new PackageSetting(origPackage.name, name, codePath, |
| 8198 | resourcePath, vc, pkgFlags); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8199 | if (DEBUG_UPGRADE) Log.v(TAG, "Package " + name |
| 8200 | + " is adopting original package " + origPackage.name); |
Dianne Hackborn | 4b45041 | 2010-03-11 16:20:08 -0800 | [diff] [blame] | 8201 | // Note that we will retain the new package's signature so |
| 8202 | // that we can keep its data. |
| 8203 | PackageSignatures s = p.signatures; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8204 | p.copyFrom(origPackage); |
Dianne Hackborn | 4b45041 | 2010-03-11 16:20:08 -0800 | [diff] [blame] | 8205 | p.signatures = s; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8206 | p.sharedUser = origPackage.sharedUser; |
| 8207 | p.userId = origPackage.userId; |
| 8208 | p.origPackage = origPackage; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8209 | mRenamedPackages.put(name, origPackage.name); |
| 8210 | name = origPackage.name; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8211 | // Update new package state. |
| 8212 | p.setTimeStamp(codePath.lastModified()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8213 | } else { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8214 | p = new PackageSetting(name, realName, codePath, resourcePath, vc, pkgFlags); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8215 | p.setTimeStamp(codePath.lastModified()); |
| 8216 | p.sharedUser = sharedUser; |
| 8217 | if (sharedUser != null) { |
| 8218 | p.userId = sharedUser.userId; |
| 8219 | } else if (MULTIPLE_APPLICATION_UIDS) { |
| 8220 | // Clone the setting here for disabled system packages |
| 8221 | PackageSetting dis = mDisabledSysPackages.get(name); |
| 8222 | if (dis != null) { |
| 8223 | // For disabled packages a new setting is created |
| 8224 | // from the existing user id. This still has to be |
| 8225 | // added to list of user id's |
| 8226 | // Copy signatures from previous setting |
| 8227 | if (dis.signatures.mSignatures != null) { |
| 8228 | p.signatures.mSignatures = dis.signatures.mSignatures.clone(); |
| 8229 | } |
| 8230 | p.userId = dis.userId; |
| 8231 | // Clone permissions |
| 8232 | p.grantedPermissions = new HashSet<String>(dis.grantedPermissions); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8233 | // Clone component info |
| 8234 | p.disabledComponents = new HashSet<String>(dis.disabledComponents); |
| 8235 | p.enabledComponents = new HashSet<String>(dis.enabledComponents); |
| 8236 | // Add new setting to list of user ids |
| 8237 | addUserIdLP(p.userId, p, name); |
| 8238 | } else { |
| 8239 | // Assign new user id |
| 8240 | p.userId = newUserIdLP(p); |
| 8241 | } |
| 8242 | } else { |
| 8243 | p.userId = FIRST_APPLICATION_UID; |
| 8244 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8245 | } |
| 8246 | if (p.userId < 0) { |
| 8247 | reportSettingsProblem(Log.WARN, |
| 8248 | "Package " + name + " could not be assigned a valid uid"); |
| 8249 | return null; |
| 8250 | } |
| 8251 | if (add) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8252 | // 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] | 8253 | // user preferences |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8254 | addPackageSettingLP(p, name, sharedUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8255 | } |
| 8256 | } |
| 8257 | return p; |
| 8258 | } |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8259 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8260 | private void insertPackageSettingLP(PackageSetting p, PackageParser.Package pkg) { |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8261 | p.pkg = pkg; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8262 | String codePath = pkg.applicationInfo.sourceDir; |
| 8263 | String resourcePath = pkg.applicationInfo.publicSourceDir; |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8264 | // Update code path if needed |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8265 | if (!codePath.equalsIgnoreCase(p.codePathString)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8266 | Slog.w(TAG, "Code path for pkg : " + p.pkg.packageName + |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8267 | " changing from " + p.codePathString + " to " + codePath); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8268 | p.codePath = new File(codePath); |
| 8269 | p.codePathString = codePath; |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8270 | } |
| 8271 | //Update resource path if needed |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8272 | if (!resourcePath.equalsIgnoreCase(p.resourcePathString)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8273 | Slog.w(TAG, "Resource path for pkg : " + p.pkg.packageName + |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8274 | " changing from " + p.resourcePathString + " to " + resourcePath); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8275 | p.resourcePath = new File(resourcePath); |
| 8276 | p.resourcePathString = resourcePath; |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8277 | } |
| 8278 | // Update version code if needed |
| 8279 | if (pkg.mVersionCode != p.versionCode) { |
| 8280 | p.versionCode = pkg.mVersionCode; |
| 8281 | } |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 8282 | // Update signatures if needed. |
| 8283 | if (p.signatures.mSignatures == null) { |
| 8284 | p.signatures.assignSignatures(pkg.mSignatures); |
| 8285 | } |
| 8286 | // If this app defines a shared user id initialize |
| 8287 | // the shared user signatures as well. |
| 8288 | if (p.sharedUser != null && p.sharedUser.signatures.mSignatures == null) { |
| 8289 | p.sharedUser.signatures.assignSignatures(pkg.mSignatures); |
| 8290 | } |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8291 | addPackageSettingLP(p, pkg.packageName, p.sharedUser); |
| 8292 | } |
| 8293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8294 | // Utility method that adds a PackageSetting to mPackages and |
| 8295 | // completes updating the shared user attributes |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8296 | private void addPackageSettingLP(PackageSetting p, String name, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8297 | SharedUserSetting sharedUser) { |
| 8298 | mPackages.put(name, p); |
| 8299 | if (sharedUser != null) { |
| 8300 | if (p.sharedUser != null && p.sharedUser != sharedUser) { |
| 8301 | reportSettingsProblem(Log.ERROR, |
| 8302 | "Package " + p.name + " was user " |
| 8303 | + p.sharedUser + " but is now " + sharedUser |
| 8304 | + "; I am not changing its files so it will probably fail!"); |
| 8305 | p.sharedUser.packages.remove(p); |
| 8306 | } else if (p.userId != sharedUser.userId) { |
| 8307 | reportSettingsProblem(Log.ERROR, |
| 8308 | "Package " + p.name + " was user id " + p.userId |
| 8309 | + " but is now user " + sharedUser |
| 8310 | + " with id " + sharedUser.userId |
| 8311 | + "; I am not changing its files so it will probably fail!"); |
| 8312 | } |
| 8313 | |
| 8314 | sharedUser.packages.add(p); |
| 8315 | p.sharedUser = sharedUser; |
| 8316 | p.userId = sharedUser.userId; |
| 8317 | } |
| 8318 | } |
| 8319 | |
Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8320 | /* |
| 8321 | * Update the shared user setting when a package using |
| 8322 | * specifying the shared user id is removed. The gids |
| 8323 | * associated with each permission of the deleted package |
| 8324 | * are removed from the shared user's gid list only if its |
| 8325 | * not in use by other permissions of packages in the |
| 8326 | * shared user setting. |
| 8327 | */ |
| 8328 | private void updateSharedUserPermsLP(PackageSetting deletedPs, int[] globalGids) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8329 | if ( (deletedPs == null) || (deletedPs.pkg == null)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8330 | 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] | 8331 | return; |
| 8332 | } |
| 8333 | // No sharedUserId |
| 8334 | if (deletedPs.sharedUser == null) { |
| 8335 | return; |
| 8336 | } |
| 8337 | SharedUserSetting sus = deletedPs.sharedUser; |
| 8338 | // Update permissions |
| 8339 | for (String eachPerm: deletedPs.pkg.requestedPermissions) { |
| 8340 | boolean used = false; |
| 8341 | if (!sus.grantedPermissions.contains (eachPerm)) { |
| 8342 | continue; |
| 8343 | } |
| 8344 | for (PackageSetting pkg:sus.packages) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8345 | if (pkg.pkg != null && |
Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 8346 | !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) && |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8347 | pkg.pkg.requestedPermissions.contains(eachPerm)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8348 | used = true; |
| 8349 | break; |
| 8350 | } |
| 8351 | } |
| 8352 | if (!used) { |
| 8353 | // can safely delete this permission from list |
| 8354 | sus.grantedPermissions.remove(eachPerm); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8355 | } |
| 8356 | } |
| 8357 | // Update gids |
Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8358 | int newGids[] = globalGids; |
| 8359 | for (String eachPerm : sus.grantedPermissions) { |
| 8360 | BasePermission bp = mPermissions.get(eachPerm); |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8361 | if (bp != null) { |
| 8362 | newGids = appendInts(newGids, bp.gids); |
| 8363 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8364 | } |
| 8365 | sus.gids = newGids; |
| 8366 | } |
Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8368 | private int removePackageLP(String name) { |
| 8369 | PackageSetting p = mPackages.get(name); |
| 8370 | if (p != null) { |
| 8371 | mPackages.remove(name); |
| 8372 | if (p.sharedUser != null) { |
| 8373 | p.sharedUser.packages.remove(p); |
| 8374 | if (p.sharedUser.packages.size() == 0) { |
| 8375 | mSharedUsers.remove(p.sharedUser.name); |
| 8376 | removeUserIdLP(p.sharedUser.userId); |
| 8377 | return p.sharedUser.userId; |
| 8378 | } |
| 8379 | } else { |
| 8380 | removeUserIdLP(p.userId); |
| 8381 | return p.userId; |
| 8382 | } |
| 8383 | } |
| 8384 | return -1; |
| 8385 | } |
| 8386 | |
| 8387 | private boolean addUserIdLP(int uid, Object obj, Object name) { |
| 8388 | if (uid >= FIRST_APPLICATION_UID + MAX_APPLICATION_UIDS) { |
| 8389 | return false; |
| 8390 | } |
| 8391 | |
| 8392 | if (uid >= FIRST_APPLICATION_UID) { |
| 8393 | int N = mUserIds.size(); |
| 8394 | final int index = uid - FIRST_APPLICATION_UID; |
| 8395 | while (index >= N) { |
| 8396 | mUserIds.add(null); |
| 8397 | N++; |
| 8398 | } |
| 8399 | if (mUserIds.get(index) != null) { |
| 8400 | reportSettingsProblem(Log.ERROR, |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8401 | "Adding duplicate user id: " + uid |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8402 | + " name=" + name); |
| 8403 | return false; |
| 8404 | } |
| 8405 | mUserIds.set(index, obj); |
| 8406 | } else { |
| 8407 | if (mOtherUserIds.get(uid) != null) { |
| 8408 | reportSettingsProblem(Log.ERROR, |
| 8409 | "Adding duplicate shared id: " + uid |
| 8410 | + " name=" + name); |
| 8411 | return false; |
| 8412 | } |
| 8413 | mOtherUserIds.put(uid, obj); |
| 8414 | } |
| 8415 | return true; |
| 8416 | } |
| 8417 | |
| 8418 | public Object getUserIdLP(int uid) { |
| 8419 | if (uid >= FIRST_APPLICATION_UID) { |
| 8420 | int N = mUserIds.size(); |
| 8421 | final int index = uid - FIRST_APPLICATION_UID; |
| 8422 | return index < N ? mUserIds.get(index) : null; |
| 8423 | } else { |
| 8424 | return mOtherUserIds.get(uid); |
| 8425 | } |
| 8426 | } |
| 8427 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 8428 | private Set<String> findPackagesWithFlag(int flag) { |
| 8429 | Set<String> ret = new HashSet<String>(); |
| 8430 | for (PackageSetting ps : mPackages.values()) { |
| 8431 | // Has to match atleast all the flag bits set on flag |
| 8432 | if ((ps.pkgFlags & flag) == flag) { |
| 8433 | ret.add(ps.name); |
| 8434 | } |
| 8435 | } |
| 8436 | return ret; |
| 8437 | } |
| 8438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8439 | private void removeUserIdLP(int uid) { |
| 8440 | if (uid >= FIRST_APPLICATION_UID) { |
| 8441 | int N = mUserIds.size(); |
| 8442 | final int index = uid - FIRST_APPLICATION_UID; |
| 8443 | if (index < N) mUserIds.set(index, null); |
| 8444 | } else { |
| 8445 | mOtherUserIds.remove(uid); |
| 8446 | } |
| 8447 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8449 | void writeLP() { |
| 8450 | //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024); |
| 8451 | |
| 8452 | // Keep the old settings around until we know the new ones have |
| 8453 | // been successfully written. |
| 8454 | if (mSettingsFilename.exists()) { |
Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8455 | // Presence of backup settings file indicates that we failed |
| 8456 | // to persist settings earlier. So preserve the older |
| 8457 | // backup for future reference since the current settings |
| 8458 | // might have been corrupted. |
| 8459 | if (!mBackupSettingsFilename.exists()) { |
| 8460 | if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8461 | 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] | 8462 | return; |
| 8463 | } |
| 8464 | } else { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8465 | mSettingsFilename.delete(); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8466 | Slog.w(TAG, "Preserving older settings backup"); |
Suchi Amalapurapu | 3d7e855 | 2009-09-17 15:38:20 -0700 | [diff] [blame] | 8467 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8468 | } |
| 8469 | |
| 8470 | mPastSignatures.clear(); |
| 8471 | |
| 8472 | try { |
| 8473 | FileOutputStream str = new FileOutputStream(mSettingsFilename); |
| 8474 | |
| 8475 | //XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 8476 | XmlSerializer serializer = new FastXmlSerializer(); |
| 8477 | serializer.setOutput(str, "utf-8"); |
| 8478 | serializer.startDocument(null, true); |
| 8479 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 8480 | |
| 8481 | serializer.startTag(null, "packages"); |
| 8482 | |
Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 8483 | serializer.startTag(null, "last-platform-version"); |
| 8484 | serializer.attribute(null, "internal", Integer.toString(mInternalSdkPlatform)); |
| 8485 | serializer.attribute(null, "external", Integer.toString(mExternalSdkPlatform)); |
| 8486 | serializer.endTag(null, "last-platform-version"); |
| 8487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8488 | serializer.startTag(null, "permission-trees"); |
| 8489 | for (BasePermission bp : mPermissionTrees.values()) { |
| 8490 | writePermission(serializer, bp); |
| 8491 | } |
| 8492 | serializer.endTag(null, "permission-trees"); |
| 8493 | |
| 8494 | serializer.startTag(null, "permissions"); |
| 8495 | for (BasePermission bp : mPermissions.values()) { |
| 8496 | writePermission(serializer, bp); |
| 8497 | } |
| 8498 | serializer.endTag(null, "permissions"); |
| 8499 | |
| 8500 | for (PackageSetting pkg : mPackages.values()) { |
| 8501 | writePackage(serializer, pkg); |
| 8502 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8504 | for (PackageSetting pkg : mDisabledSysPackages.values()) { |
| 8505 | writeDisabledSysPackage(serializer, pkg); |
| 8506 | } |
| 8507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8508 | serializer.startTag(null, "preferred-activities"); |
| 8509 | for (PreferredActivity pa : mPreferredActivities.filterSet()) { |
| 8510 | serializer.startTag(null, "item"); |
| 8511 | pa.writeToXml(serializer); |
| 8512 | serializer.endTag(null, "item"); |
| 8513 | } |
| 8514 | serializer.endTag(null, "preferred-activities"); |
| 8515 | |
| 8516 | for (SharedUserSetting usr : mSharedUsers.values()) { |
| 8517 | serializer.startTag(null, "shared-user"); |
| 8518 | serializer.attribute(null, "name", usr.name); |
| 8519 | serializer.attribute(null, "userId", |
| 8520 | Integer.toString(usr.userId)); |
| 8521 | usr.signatures.writeXml(serializer, "sigs", mPastSignatures); |
| 8522 | serializer.startTag(null, "perms"); |
| 8523 | for (String name : usr.grantedPermissions) { |
| 8524 | serializer.startTag(null, "item"); |
| 8525 | serializer.attribute(null, "name", name); |
| 8526 | serializer.endTag(null, "item"); |
| 8527 | } |
| 8528 | serializer.endTag(null, "perms"); |
| 8529 | serializer.endTag(null, "shared-user"); |
| 8530 | } |
| 8531 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8532 | if (mPackagesToBeCleaned.size() > 0) { |
| 8533 | for (int i=0; i<mPackagesToBeCleaned.size(); i++) { |
| 8534 | serializer.startTag(null, "cleaning-package"); |
| 8535 | serializer.attribute(null, "name", mPackagesToBeCleaned.get(i)); |
| 8536 | serializer.endTag(null, "cleaning-package"); |
| 8537 | } |
| 8538 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8539 | |
| 8540 | if (mRenamedPackages.size() > 0) { |
| 8541 | for (HashMap.Entry<String, String> e : mRenamedPackages.entrySet()) { |
| 8542 | serializer.startTag(null, "renamed-package"); |
| 8543 | serializer.attribute(null, "new", e.getKey()); |
| 8544 | serializer.attribute(null, "old", e.getValue()); |
| 8545 | serializer.endTag(null, "renamed-package"); |
| 8546 | } |
| 8547 | } |
| 8548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8549 | serializer.endTag(null, "packages"); |
| 8550 | |
| 8551 | serializer.endDocument(); |
| 8552 | |
| 8553 | str.flush(); |
| 8554 | str.close(); |
| 8555 | |
| 8556 | // New settings successfully written, old ones are no longer |
| 8557 | // needed. |
| 8558 | mBackupSettingsFilename.delete(); |
| 8559 | FileUtils.setPermissions(mSettingsFilename.toString(), |
| 8560 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
| 8561 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP |
| 8562 | |FileUtils.S_IROTH, |
| 8563 | -1, -1); |
David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 8564 | |
| 8565 | // Write package list file now, use a JournaledFile. |
| 8566 | // |
| 8567 | File tempFile = new File(mPackageListFilename.toString() + ".tmp"); |
| 8568 | JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile); |
| 8569 | |
| 8570 | str = new FileOutputStream(journal.chooseForWrite()); |
| 8571 | try { |
| 8572 | StringBuilder sb = new StringBuilder(); |
| 8573 | for (PackageSetting pkg : mPackages.values()) { |
| 8574 | ApplicationInfo ai = pkg.pkg.applicationInfo; |
| 8575 | String dataPath = ai.dataDir; |
| 8576 | boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 8577 | |
| 8578 | // Avoid any application that has a space in its path |
| 8579 | // or that is handled by the system. |
| 8580 | if (dataPath.indexOf(" ") >= 0 || ai.uid <= Process.FIRST_APPLICATION_UID) |
| 8581 | continue; |
| 8582 | |
| 8583 | // we store on each line the following information for now: |
| 8584 | // |
| 8585 | // pkgName - package name |
| 8586 | // userId - application-specific user id |
| 8587 | // debugFlag - 0 or 1 if the package is debuggable. |
| 8588 | // dataPath - path to package's data path |
| 8589 | // |
| 8590 | // NOTE: We prefer not to expose all ApplicationInfo flags for now. |
| 8591 | // |
| 8592 | // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS |
| 8593 | // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES: |
| 8594 | // system/core/run-as/run-as.c |
| 8595 | // |
| 8596 | sb.setLength(0); |
| 8597 | sb.append(ai.packageName); |
| 8598 | sb.append(" "); |
| 8599 | sb.append((int)ai.uid); |
| 8600 | sb.append(isDebug ? " 1 " : " 0 "); |
| 8601 | sb.append(dataPath); |
| 8602 | sb.append("\n"); |
| 8603 | str.write(sb.toString().getBytes()); |
| 8604 | } |
| 8605 | str.flush(); |
| 8606 | str.close(); |
| 8607 | journal.commit(); |
| 8608 | } |
| 8609 | catch (Exception e) { |
| 8610 | journal.rollback(); |
| 8611 | } |
| 8612 | |
| 8613 | FileUtils.setPermissions(mPackageListFilename.toString(), |
| 8614 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
| 8615 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP |
| 8616 | |FileUtils.S_IROTH, |
| 8617 | -1, -1); |
| 8618 | |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8619 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | |
| 8621 | } catch(XmlPullParserException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8622 | 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] | 8623 | } catch(java.io.IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8624 | 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] | 8625 | } |
David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 8626 | // Clean up partially written files |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8627 | if (mSettingsFilename.exists()) { |
| 8628 | if (!mSettingsFilename.delete()) { |
| 8629 | Log.i(TAG, "Failed to clean up mangled file: " + mSettingsFilename); |
| 8630 | } |
| 8631 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8632 | //Debug.stopMethodTracing(); |
| 8633 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8634 | |
| 8635 | void writeDisabledSysPackage(XmlSerializer serializer, final PackageSetting pkg) |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8636 | throws java.io.IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8637 | serializer.startTag(null, "updated-package"); |
| 8638 | serializer.attribute(null, "name", pkg.name); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8639 | if (pkg.realName != null) { |
| 8640 | serializer.attribute(null, "realName", pkg.realName); |
| 8641 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8642 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 8643 | serializer.attribute(null, "ts", pkg.getTimeStampStr()); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8644 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8645 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 8646 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 8647 | } |
| 8648 | if (pkg.sharedUser == null) { |
| 8649 | serializer.attribute(null, "userId", |
| 8650 | Integer.toString(pkg.userId)); |
| 8651 | } else { |
| 8652 | serializer.attribute(null, "sharedUserId", |
| 8653 | Integer.toString(pkg.userId)); |
| 8654 | } |
| 8655 | serializer.startTag(null, "perms"); |
| 8656 | if (pkg.sharedUser == null) { |
| 8657 | // If this is a shared user, the permissions will |
| 8658 | // be written there. We still need to write an |
| 8659 | // empty permissions list so permissionsFixed will |
| 8660 | // be set. |
| 8661 | for (final String name : pkg.grantedPermissions) { |
| 8662 | BasePermission bp = mPermissions.get(name); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8663 | if (bp != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8664 | // We only need to write signature or system permissions but this wont |
| 8665 | // match the semantics of grantedPermissions. So write all permissions. |
| 8666 | serializer.startTag(null, "item"); |
| 8667 | serializer.attribute(null, "name", name); |
| 8668 | serializer.endTag(null, "item"); |
| 8669 | } |
| 8670 | } |
| 8671 | } |
| 8672 | serializer.endTag(null, "perms"); |
| 8673 | serializer.endTag(null, "updated-package"); |
| 8674 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8675 | |
| 8676 | void writePackage(XmlSerializer serializer, final PackageSetting pkg) |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8677 | throws java.io.IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8678 | serializer.startTag(null, "package"); |
| 8679 | serializer.attribute(null, "name", pkg.name); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8680 | if (pkg.realName != null) { |
| 8681 | serializer.attribute(null, "realName", pkg.realName); |
| 8682 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8683 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 8684 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 8685 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 8686 | } |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8687 | serializer.attribute(null, "flags", |
| 8688 | Integer.toString(pkg.pkgFlags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8689 | serializer.attribute(null, "ts", pkg.getTimeStampStr()); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8690 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8691 | if (pkg.sharedUser == null) { |
| 8692 | serializer.attribute(null, "userId", |
| 8693 | Integer.toString(pkg.userId)); |
| 8694 | } else { |
| 8695 | serializer.attribute(null, "sharedUserId", |
| 8696 | Integer.toString(pkg.userId)); |
| 8697 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8698 | if (pkg.uidError) { |
| 8699 | serializer.attribute(null, "uidError", "true"); |
| 8700 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8701 | if (pkg.enabled != COMPONENT_ENABLED_STATE_DEFAULT) { |
| 8702 | serializer.attribute(null, "enabled", |
| 8703 | pkg.enabled == COMPONENT_ENABLED_STATE_ENABLED |
| 8704 | ? "true" : "false"); |
| 8705 | } |
| 8706 | if(pkg.installStatus == PKG_INSTALL_INCOMPLETE) { |
| 8707 | serializer.attribute(null, "installStatus", "false"); |
| 8708 | } |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8709 | if (pkg.installerPackageName != null) { |
| 8710 | serializer.attribute(null, "installer", pkg.installerPackageName); |
| 8711 | } |
Kenny Root | 93565c4 | 2010-06-18 15:46:06 -0700 | [diff] [blame^] | 8712 | if (pkg.obbPathString != null) { |
| 8713 | serializer.attribute(null, "obbPath", pkg.obbPathString); |
| 8714 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8715 | pkg.signatures.writeXml(serializer, "sigs", mPastSignatures); |
| 8716 | if ((pkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 8717 | serializer.startTag(null, "perms"); |
| 8718 | if (pkg.sharedUser == null) { |
| 8719 | // If this is a shared user, the permissions will |
| 8720 | // be written there. We still need to write an |
| 8721 | // empty permissions list so permissionsFixed will |
| 8722 | // be set. |
| 8723 | for (final String name : pkg.grantedPermissions) { |
| 8724 | serializer.startTag(null, "item"); |
| 8725 | serializer.attribute(null, "name", name); |
| 8726 | serializer.endTag(null, "item"); |
| 8727 | } |
| 8728 | } |
| 8729 | serializer.endTag(null, "perms"); |
| 8730 | } |
| 8731 | if (pkg.disabledComponents.size() > 0) { |
| 8732 | serializer.startTag(null, "disabled-components"); |
| 8733 | for (final String name : pkg.disabledComponents) { |
| 8734 | serializer.startTag(null, "item"); |
| 8735 | serializer.attribute(null, "name", name); |
| 8736 | serializer.endTag(null, "item"); |
| 8737 | } |
| 8738 | serializer.endTag(null, "disabled-components"); |
| 8739 | } |
| 8740 | if (pkg.enabledComponents.size() > 0) { |
| 8741 | serializer.startTag(null, "enabled-components"); |
| 8742 | for (final String name : pkg.enabledComponents) { |
| 8743 | serializer.startTag(null, "item"); |
| 8744 | serializer.attribute(null, "name", name); |
| 8745 | serializer.endTag(null, "item"); |
| 8746 | } |
| 8747 | serializer.endTag(null, "enabled-components"); |
| 8748 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8750 | serializer.endTag(null, "package"); |
| 8751 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8752 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8753 | void writePermission(XmlSerializer serializer, BasePermission bp) |
| 8754 | throws XmlPullParserException, java.io.IOException { |
| 8755 | if (bp.type != BasePermission.TYPE_BUILTIN |
| 8756 | && bp.sourcePackage != null) { |
| 8757 | serializer.startTag(null, "item"); |
| 8758 | serializer.attribute(null, "name", bp.name); |
| 8759 | serializer.attribute(null, "package", bp.sourcePackage); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8760 | if (bp.protectionLevel != |
| 8761 | PermissionInfo.PROTECTION_NORMAL) { |
| 8762 | serializer.attribute(null, "protection", |
| 8763 | Integer.toString(bp.protectionLevel)); |
| 8764 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8765 | if (DEBUG_SETTINGS) Log.v(TAG, |
| 8766 | "Writing perm: name=" + bp.name + " type=" + bp.type); |
| 8767 | if (bp.type == BasePermission.TYPE_DYNAMIC) { |
| 8768 | PermissionInfo pi = bp.perm != null ? bp.perm.info |
| 8769 | : bp.pendingInfo; |
| 8770 | if (pi != null) { |
| 8771 | serializer.attribute(null, "type", "dynamic"); |
| 8772 | if (pi.icon != 0) { |
| 8773 | serializer.attribute(null, "icon", |
| 8774 | Integer.toString(pi.icon)); |
| 8775 | } |
| 8776 | if (pi.nonLocalizedLabel != null) { |
| 8777 | serializer.attribute(null, "label", |
| 8778 | pi.nonLocalizedLabel.toString()); |
| 8779 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8780 | } |
| 8781 | } |
| 8782 | serializer.endTag(null, "item"); |
| 8783 | } |
| 8784 | } |
| 8785 | |
| 8786 | String getReadMessagesLP() { |
| 8787 | return mReadMessages.toString(); |
| 8788 | } |
| 8789 | |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8790 | ArrayList<PackageSetting> getListOfIncompleteInstallPackages() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8791 | HashSet<String> kList = new HashSet<String>(mPackages.keySet()); |
| 8792 | Iterator<String> its = kList.iterator(); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8793 | ArrayList<PackageSetting> ret = new ArrayList<PackageSetting>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8794 | while(its.hasNext()) { |
| 8795 | String key = its.next(); |
| 8796 | PackageSetting ps = mPackages.get(key); |
| 8797 | if(ps.getInstallStatus() == PKG_INSTALL_INCOMPLETE) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8798 | ret.add(ps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8799 | } |
| 8800 | } |
| 8801 | return ret; |
| 8802 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8803 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8804 | boolean readLP() { |
| 8805 | FileInputStream str = null; |
| 8806 | if (mBackupSettingsFilename.exists()) { |
| 8807 | try { |
| 8808 | str = new FileInputStream(mBackupSettingsFilename); |
| 8809 | mReadMessages.append("Reading from backup settings file\n"); |
| 8810 | Log.i(TAG, "Reading from backup settings file!"); |
Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8811 | if (mSettingsFilename.exists()) { |
| 8812 | // If both the backup and settings file exist, we |
| 8813 | // ignore the settings since it might have been |
| 8814 | // corrupted. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8815 | Slog.w(TAG, "Cleaning up settings file " + mSettingsFilename); |
Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8816 | mSettingsFilename.delete(); |
| 8817 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8818 | } catch (java.io.IOException e) { |
| 8819 | // We'll try for the normal settings file. |
| 8820 | } |
| 8821 | } |
| 8822 | |
| 8823 | mPastSignatures.clear(); |
| 8824 | |
| 8825 | try { |
| 8826 | if (str == null) { |
| 8827 | if (!mSettingsFilename.exists()) { |
| 8828 | mReadMessages.append("No settings file found\n"); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8829 | Slog.i(TAG, "No current settings file!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8830 | return false; |
| 8831 | } |
| 8832 | str = new FileInputStream(mSettingsFilename); |
| 8833 | } |
| 8834 | XmlPullParser parser = Xml.newPullParser(); |
| 8835 | parser.setInput(str, null); |
| 8836 | |
| 8837 | int type; |
| 8838 | while ((type=parser.next()) != XmlPullParser.START_TAG |
| 8839 | && type != XmlPullParser.END_DOCUMENT) { |
| 8840 | ; |
| 8841 | } |
| 8842 | |
| 8843 | if (type != XmlPullParser.START_TAG) { |
| 8844 | mReadMessages.append("No start tag found in settings file\n"); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8845 | 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] | 8846 | return false; |
| 8847 | } |
| 8848 | |
| 8849 | int outerDepth = parser.getDepth(); |
| 8850 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8851 | && (type != XmlPullParser.END_TAG |
| 8852 | || parser.getDepth() > outerDepth)) { |
| 8853 | if (type == XmlPullParser.END_TAG |
| 8854 | || type == XmlPullParser.TEXT) { |
| 8855 | continue; |
| 8856 | } |
| 8857 | |
| 8858 | String tagName = parser.getName(); |
| 8859 | if (tagName.equals("package")) { |
| 8860 | readPackageLP(parser); |
| 8861 | } else if (tagName.equals("permissions")) { |
| 8862 | readPermissionsLP(mPermissions, parser); |
| 8863 | } else if (tagName.equals("permission-trees")) { |
| 8864 | readPermissionsLP(mPermissionTrees, parser); |
| 8865 | } else if (tagName.equals("shared-user")) { |
| 8866 | readSharedUserLP(parser); |
| 8867 | } else if (tagName.equals("preferred-packages")) { |
Dianne Hackborn | a7ca0e5 | 2009-12-01 14:31:55 -0800 | [diff] [blame] | 8868 | // no longer used. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8869 | } else if (tagName.equals("preferred-activities")) { |
| 8870 | readPreferredActivitiesLP(parser); |
| 8871 | } else if(tagName.equals("updated-package")) { |
| 8872 | readDisabledSysPackageLP(parser); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8873 | } else if (tagName.equals("cleaning-package")) { |
| 8874 | String name = parser.getAttributeValue(null, "name"); |
| 8875 | if (name != null) { |
| 8876 | mPackagesToBeCleaned.add(name); |
| 8877 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8878 | } else if (tagName.equals("renamed-package")) { |
| 8879 | String nname = parser.getAttributeValue(null, "new"); |
| 8880 | String oname = parser.getAttributeValue(null, "old"); |
| 8881 | if (nname != null && oname != null) { |
| 8882 | mRenamedPackages.put(nname, oname); |
| 8883 | } |
Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 8884 | } else if (tagName.equals("last-platform-version")) { |
| 8885 | mInternalSdkPlatform = mExternalSdkPlatform = 0; |
| 8886 | try { |
| 8887 | String internal = parser.getAttributeValue(null, "internal"); |
| 8888 | if (internal != null) { |
| 8889 | mInternalSdkPlatform = Integer.parseInt(internal); |
| 8890 | } |
| 8891 | String external = parser.getAttributeValue(null, "external"); |
| 8892 | if (external != null) { |
Bryan Mawhinney | 2131a3c | 2010-04-23 14:38:31 +0100 | [diff] [blame] | 8893 | mExternalSdkPlatform = Integer.parseInt(external); |
Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 8894 | } |
| 8895 | } catch (NumberFormatException e) { |
| 8896 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8897 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8898 | Slog.w(TAG, "Unknown element under <packages>: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8899 | + parser.getName()); |
| 8900 | XmlUtils.skipCurrentTag(parser); |
| 8901 | } |
| 8902 | } |
| 8903 | |
| 8904 | str.close(); |
| 8905 | |
| 8906 | } catch(XmlPullParserException e) { |
| 8907 | mReadMessages.append("Error reading: " + e.toString()); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8908 | Slog.e(TAG, "Error reading package manager settings", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8909 | |
| 8910 | } catch(java.io.IOException e) { |
| 8911 | mReadMessages.append("Error reading: " + e.toString()); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8912 | Slog.e(TAG, "Error reading package manager settings", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8913 | |
| 8914 | } |
| 8915 | |
| 8916 | int N = mPendingPackages.size(); |
| 8917 | for (int i=0; i<N; i++) { |
| 8918 | final PendingPackage pp = mPendingPackages.get(i); |
| 8919 | Object idObj = getUserIdLP(pp.sharedId); |
| 8920 | if (idObj != null && idObj instanceof SharedUserSetting) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8921 | PackageSetting p = getPackageLP(pp.name, null, pp.realName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8922 | (SharedUserSetting)idObj, pp.codePath, pp.resourcePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8923 | pp.versionCode, pp.pkgFlags, true, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8924 | if (p == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8925 | Slog.w(TAG, "Unable to create application package for " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8926 | + pp.name); |
| 8927 | continue; |
| 8928 | } |
| 8929 | p.copyFrom(pp); |
| 8930 | } else if (idObj != null) { |
| 8931 | String msg = "Bad package setting: package " + pp.name |
| 8932 | + " has shared uid " + pp.sharedId |
| 8933 | + " that is not a shared uid\n"; |
| 8934 | mReadMessages.append(msg); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8935 | Slog.e(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8936 | } else { |
| 8937 | String msg = "Bad package setting: package " + pp.name |
| 8938 | + " has shared uid " + pp.sharedId |
| 8939 | + " that is not defined\n"; |
| 8940 | mReadMessages.append(msg); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8941 | Slog.e(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8942 | } |
| 8943 | } |
| 8944 | mPendingPackages.clear(); |
| 8945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8946 | mReadMessages.append("Read completed successfully: " |
| 8947 | + mPackages.size() + " packages, " |
| 8948 | + mSharedUsers.size() + " shared uids\n"); |
| 8949 | |
| 8950 | return true; |
| 8951 | } |
| 8952 | |
| 8953 | private int readInt(XmlPullParser parser, String ns, String name, |
| 8954 | int defValue) { |
| 8955 | String v = parser.getAttributeValue(ns, name); |
| 8956 | try { |
| 8957 | if (v == null) { |
| 8958 | return defValue; |
| 8959 | } |
| 8960 | return Integer.parseInt(v); |
| 8961 | } catch (NumberFormatException e) { |
| 8962 | reportSettingsProblem(Log.WARN, |
| 8963 | "Error in package manager settings: attribute " + |
| 8964 | name + " has bad integer value " + v + " at " |
| 8965 | + parser.getPositionDescription()); |
| 8966 | } |
| 8967 | return defValue; |
| 8968 | } |
| 8969 | |
| 8970 | private void readPermissionsLP(HashMap<String, BasePermission> out, |
| 8971 | XmlPullParser parser) |
| 8972 | throws IOException, XmlPullParserException { |
| 8973 | int outerDepth = parser.getDepth(); |
| 8974 | int type; |
| 8975 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8976 | && (type != XmlPullParser.END_TAG |
| 8977 | || parser.getDepth() > outerDepth)) { |
| 8978 | if (type == XmlPullParser.END_TAG |
| 8979 | || type == XmlPullParser.TEXT) { |
| 8980 | continue; |
| 8981 | } |
| 8982 | |
| 8983 | String tagName = parser.getName(); |
| 8984 | if (tagName.equals("item")) { |
| 8985 | String name = parser.getAttributeValue(null, "name"); |
| 8986 | String sourcePackage = parser.getAttributeValue(null, "package"); |
| 8987 | String ptype = parser.getAttributeValue(null, "type"); |
| 8988 | if (name != null && sourcePackage != null) { |
| 8989 | boolean dynamic = "dynamic".equals(ptype); |
| 8990 | BasePermission bp = new BasePermission(name, sourcePackage, |
| 8991 | dynamic |
| 8992 | ? BasePermission.TYPE_DYNAMIC |
| 8993 | : BasePermission.TYPE_NORMAL); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8994 | bp.protectionLevel = readInt(parser, null, "protection", |
| 8995 | PermissionInfo.PROTECTION_NORMAL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8996 | if (dynamic) { |
| 8997 | PermissionInfo pi = new PermissionInfo(); |
| 8998 | pi.packageName = sourcePackage.intern(); |
| 8999 | pi.name = name.intern(); |
| 9000 | pi.icon = readInt(parser, null, "icon", 0); |
| 9001 | pi.nonLocalizedLabel = parser.getAttributeValue( |
| 9002 | null, "label"); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 9003 | pi.protectionLevel = bp.protectionLevel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9004 | bp.pendingInfo = pi; |
| 9005 | } |
| 9006 | out.put(bp.name, bp); |
| 9007 | } else { |
| 9008 | reportSettingsProblem(Log.WARN, |
| 9009 | "Error in package manager settings: permissions has" |
| 9010 | + " no name at " + parser.getPositionDescription()); |
| 9011 | } |
| 9012 | } else { |
| 9013 | reportSettingsProblem(Log.WARN, |
| 9014 | "Unknown element reading permissions: " |
| 9015 | + parser.getName() + " at " |
| 9016 | + parser.getPositionDescription()); |
| 9017 | } |
| 9018 | XmlUtils.skipCurrentTag(parser); |
| 9019 | } |
| 9020 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9022 | private void readDisabledSysPackageLP(XmlPullParser parser) |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9023 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9024 | String name = parser.getAttributeValue(null, "name"); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9025 | String realName = parser.getAttributeValue(null, "realName"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9026 | String codePathStr = parser.getAttributeValue(null, "codePath"); |
| 9027 | String resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9028 | if (resourcePathStr == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9029 | resourcePathStr = codePathStr; |
| 9030 | } |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 9031 | String version = parser.getAttributeValue(null, "version"); |
| 9032 | int versionCode = 0; |
| 9033 | if (version != null) { |
| 9034 | try { |
| 9035 | versionCode = Integer.parseInt(version); |
| 9036 | } catch (NumberFormatException e) { |
| 9037 | } |
| 9038 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9040 | int pkgFlags = 0; |
| 9041 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9042 | PackageSetting ps = new PackageSetting(name, realName, |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9043 | new File(codePathStr), |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 9044 | new File(resourcePathStr), versionCode, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9045 | String timeStampStr = parser.getAttributeValue(null, "ts"); |
| 9046 | if (timeStampStr != null) { |
| 9047 | try { |
| 9048 | long timeStamp = Long.parseLong(timeStampStr); |
| 9049 | ps.setTimeStamp(timeStamp, timeStampStr); |
| 9050 | } catch (NumberFormatException e) { |
| 9051 | } |
| 9052 | } |
| 9053 | String idStr = parser.getAttributeValue(null, "userId"); |
| 9054 | ps.userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 9055 | if(ps.userId <= 0) { |
| 9056 | String sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 9057 | ps.userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; |
| 9058 | } |
| 9059 | int outerDepth = parser.getDepth(); |
| 9060 | int type; |
| 9061 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9062 | && (type != XmlPullParser.END_TAG |
| 9063 | || parser.getDepth() > outerDepth)) { |
| 9064 | if (type == XmlPullParser.END_TAG |
| 9065 | || type == XmlPullParser.TEXT) { |
| 9066 | continue; |
| 9067 | } |
| 9068 | |
| 9069 | String tagName = parser.getName(); |
| 9070 | if (tagName.equals("perms")) { |
| 9071 | readGrantedPermissionsLP(parser, |
| 9072 | ps.grantedPermissions); |
| 9073 | } else { |
| 9074 | reportSettingsProblem(Log.WARN, |
| 9075 | "Unknown element under <updated-package>: " |
| 9076 | + parser.getName()); |
| 9077 | XmlUtils.skipCurrentTag(parser); |
| 9078 | } |
| 9079 | } |
| 9080 | mDisabledSysPackages.put(name, ps); |
| 9081 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9083 | private void readPackageLP(XmlPullParser parser) |
| 9084 | throws XmlPullParserException, IOException { |
| 9085 | String name = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9086 | String realName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9087 | String idStr = null; |
| 9088 | String sharedIdStr = null; |
| 9089 | String codePathStr = null; |
| 9090 | String resourcePathStr = null; |
Kenny Root | 93565c4 | 2010-06-18 15:46:06 -0700 | [diff] [blame^] | 9091 | String obbPathStr = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9092 | String systemStr = null; |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 9093 | String installerPackageName = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 9094 | String uidError = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9095 | int pkgFlags = 0; |
| 9096 | String timeStampStr; |
| 9097 | long timeStamp = 0; |
| 9098 | PackageSettingBase packageSetting = null; |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 9099 | String version = null; |
| 9100 | int versionCode = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9101 | try { |
| 9102 | name = parser.getAttributeValue(null, "name"); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9103 | realName = parser.getAttributeValue(null, "realName"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9104 | idStr = parser.getAttributeValue(null, "userId"); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 9105 | uidError = parser.getAttributeValue(null, "uidError"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9106 | sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 9107 | codePathStr = parser.getAttributeValue(null, "codePath"); |
| 9108 | resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
Kenny Root | 93565c4 | 2010-06-18 15:46:06 -0700 | [diff] [blame^] | 9109 | obbPathStr = parser.getAttributeValue(null, "obbPath"); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 9110 | version = parser.getAttributeValue(null, "version"); |
| 9111 | if (version != null) { |
| 9112 | try { |
| 9113 | versionCode = Integer.parseInt(version); |
| 9114 | } catch (NumberFormatException e) { |
| 9115 | } |
| 9116 | } |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 9117 | installerPackageName = parser.getAttributeValue(null, "installer"); |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9118 | |
| 9119 | systemStr = parser.getAttributeValue(null, "flags"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9120 | if (systemStr != null) { |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9121 | try { |
| 9122 | pkgFlags = Integer.parseInt(systemStr); |
| 9123 | } catch (NumberFormatException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9124 | } |
| 9125 | } else { |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9126 | // For backward compatibility |
| 9127 | systemStr = parser.getAttributeValue(null, "system"); |
| 9128 | if (systemStr != null) { |
| 9129 | pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM : 0; |
| 9130 | } else { |
| 9131 | // Old settings that don't specify system... just treat |
| 9132 | // them as system, good enough. |
| 9133 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 9134 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9135 | } |
| 9136 | timeStampStr = parser.getAttributeValue(null, "ts"); |
| 9137 | if (timeStampStr != null) { |
| 9138 | try { |
| 9139 | timeStamp = Long.parseLong(timeStampStr); |
| 9140 | } catch (NumberFormatException e) { |
| 9141 | } |
| 9142 | } |
| 9143 | if (DEBUG_SETTINGS) Log.v(TAG, "Reading package: " + name |
| 9144 | + " userId=" + idStr + " sharedUserId=" + sharedIdStr); |
| 9145 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 9146 | if (resourcePathStr == null) { |
| 9147 | resourcePathStr = codePathStr; |
| 9148 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9149 | if (realName != null) { |
| 9150 | realName = realName.intern(); |
| 9151 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9152 | if (name == null) { |
| 9153 | reportSettingsProblem(Log.WARN, |
| 9154 | "Error in package manager settings: <package> has no name at " |
| 9155 | + parser.getPositionDescription()); |
| 9156 | } else if (codePathStr == null) { |
| 9157 | reportSettingsProblem(Log.WARN, |
| 9158 | "Error in package manager settings: <package> has no codePath at " |
| 9159 | + parser.getPositionDescription()); |
| 9160 | } else if (userId > 0) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9161 | packageSetting = addPackageLP(name.intern(), realName, |
| 9162 | new File(codePathStr), new File(resourcePathStr), |
| 9163 | userId, versionCode, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9164 | if (DEBUG_SETTINGS) Log.i(TAG, "Reading package " + name |
| 9165 | + ": userId=" + userId + " pkg=" + packageSetting); |
| 9166 | if (packageSetting == null) { |
| 9167 | reportSettingsProblem(Log.ERROR, |
| 9168 | "Failure adding uid " + userId |
| 9169 | + " while parsing settings at " |
| 9170 | + parser.getPositionDescription()); |
| 9171 | } else { |
| 9172 | packageSetting.setTimeStamp(timeStamp, timeStampStr); |
| 9173 | } |
| 9174 | } else if (sharedIdStr != null) { |
| 9175 | userId = sharedIdStr != null |
| 9176 | ? Integer.parseInt(sharedIdStr) : 0; |
| 9177 | if (userId > 0) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9178 | packageSetting = new PendingPackage(name.intern(), realName, |
| 9179 | new File(codePathStr), new File(resourcePathStr), |
| 9180 | userId, versionCode, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9181 | packageSetting.setTimeStamp(timeStamp, timeStampStr); |
| 9182 | mPendingPackages.add((PendingPackage) packageSetting); |
| 9183 | if (DEBUG_SETTINGS) Log.i(TAG, "Reading package " + name |
| 9184 | + ": sharedUserId=" + userId + " pkg=" |
| 9185 | + packageSetting); |
| 9186 | } else { |
| 9187 | reportSettingsProblem(Log.WARN, |
| 9188 | "Error in package manager settings: package " |
| 9189 | + name + " has bad sharedId " + sharedIdStr |
| 9190 | + " at " + parser.getPositionDescription()); |
| 9191 | } |
| 9192 | } else { |
| 9193 | reportSettingsProblem(Log.WARN, |
| 9194 | "Error in package manager settings: package " |
| 9195 | + name + " has bad userId " + idStr + " at " |
| 9196 | + parser.getPositionDescription()); |
| 9197 | } |
| 9198 | } catch (NumberFormatException e) { |
| 9199 | reportSettingsProblem(Log.WARN, |
| 9200 | "Error in package manager settings: package " |
| 9201 | + name + " has bad userId " + idStr + " at " |
| 9202 | + parser.getPositionDescription()); |
| 9203 | } |
| 9204 | if (packageSetting != null) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 9205 | packageSetting.uidError = "true".equals(uidError); |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 9206 | packageSetting.installerPackageName = installerPackageName; |
Kenny Root | 93565c4 | 2010-06-18 15:46:06 -0700 | [diff] [blame^] | 9207 | packageSetting.obbPathString = obbPathStr; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9208 | final String enabledStr = parser.getAttributeValue(null, "enabled"); |
| 9209 | if (enabledStr != null) { |
| 9210 | if (enabledStr.equalsIgnoreCase("true")) { |
| 9211 | packageSetting.enabled = COMPONENT_ENABLED_STATE_ENABLED; |
| 9212 | } else if (enabledStr.equalsIgnoreCase("false")) { |
| 9213 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DISABLED; |
| 9214 | } else if (enabledStr.equalsIgnoreCase("default")) { |
| 9215 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 9216 | } else { |
| 9217 | reportSettingsProblem(Log.WARN, |
| 9218 | "Error in package manager settings: package " |
| 9219 | + name + " has bad enabled value: " + idStr |
| 9220 | + " at " + parser.getPositionDescription()); |
| 9221 | } |
| 9222 | } else { |
| 9223 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 9224 | } |
| 9225 | final String installStatusStr = parser.getAttributeValue(null, "installStatus"); |
| 9226 | if (installStatusStr != null) { |
| 9227 | if (installStatusStr.equalsIgnoreCase("false")) { |
| 9228 | packageSetting.installStatus = PKG_INSTALL_INCOMPLETE; |
| 9229 | } else { |
| 9230 | packageSetting.installStatus = PKG_INSTALL_COMPLETE; |
| 9231 | } |
| 9232 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9234 | int outerDepth = parser.getDepth(); |
| 9235 | int type; |
| 9236 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9237 | && (type != XmlPullParser.END_TAG |
| 9238 | || parser.getDepth() > outerDepth)) { |
| 9239 | if (type == XmlPullParser.END_TAG |
| 9240 | || type == XmlPullParser.TEXT) { |
| 9241 | continue; |
| 9242 | } |
| 9243 | |
| 9244 | String tagName = parser.getName(); |
| 9245 | if (tagName.equals("disabled-components")) { |
| 9246 | readDisabledComponentsLP(packageSetting, parser); |
| 9247 | } else if (tagName.equals("enabled-components")) { |
| 9248 | readEnabledComponentsLP(packageSetting, parser); |
| 9249 | } else if (tagName.equals("sigs")) { |
| 9250 | packageSetting.signatures.readXml(parser, mPastSignatures); |
| 9251 | } else if (tagName.equals("perms")) { |
| 9252 | readGrantedPermissionsLP(parser, |
Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 9253 | packageSetting.grantedPermissions); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9254 | packageSetting.permissionsFixed = true; |
| 9255 | } else { |
| 9256 | reportSettingsProblem(Log.WARN, |
| 9257 | "Unknown element under <package>: " |
| 9258 | + parser.getName()); |
| 9259 | XmlUtils.skipCurrentTag(parser); |
| 9260 | } |
| 9261 | } |
| 9262 | } else { |
| 9263 | XmlUtils.skipCurrentTag(parser); |
| 9264 | } |
| 9265 | } |
| 9266 | |
| 9267 | private void readDisabledComponentsLP(PackageSettingBase packageSetting, |
| 9268 | XmlPullParser parser) |
| 9269 | throws IOException, XmlPullParserException { |
| 9270 | int outerDepth = parser.getDepth(); |
| 9271 | int type; |
| 9272 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9273 | && (type != XmlPullParser.END_TAG |
| 9274 | || parser.getDepth() > outerDepth)) { |
| 9275 | if (type == XmlPullParser.END_TAG |
| 9276 | || type == XmlPullParser.TEXT) { |
| 9277 | continue; |
| 9278 | } |
| 9279 | |
| 9280 | String tagName = parser.getName(); |
| 9281 | if (tagName.equals("item")) { |
| 9282 | String name = parser.getAttributeValue(null, "name"); |
| 9283 | if (name != null) { |
| 9284 | packageSetting.disabledComponents.add(name.intern()); |
| 9285 | } else { |
| 9286 | reportSettingsProblem(Log.WARN, |
| 9287 | "Error in package manager settings: <disabled-components> has" |
| 9288 | + " no name at " + parser.getPositionDescription()); |
| 9289 | } |
| 9290 | } else { |
| 9291 | reportSettingsProblem(Log.WARN, |
| 9292 | "Unknown element under <disabled-components>: " |
| 9293 | + parser.getName()); |
| 9294 | } |
| 9295 | XmlUtils.skipCurrentTag(parser); |
| 9296 | } |
| 9297 | } |
| 9298 | |
| 9299 | private void readEnabledComponentsLP(PackageSettingBase packageSetting, |
| 9300 | XmlPullParser parser) |
| 9301 | throws IOException, XmlPullParserException { |
| 9302 | int outerDepth = parser.getDepth(); |
| 9303 | int type; |
| 9304 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9305 | && (type != XmlPullParser.END_TAG |
| 9306 | || parser.getDepth() > outerDepth)) { |
| 9307 | if (type == XmlPullParser.END_TAG |
| 9308 | || type == XmlPullParser.TEXT) { |
| 9309 | continue; |
| 9310 | } |
| 9311 | |
| 9312 | String tagName = parser.getName(); |
| 9313 | if (tagName.equals("item")) { |
| 9314 | String name = parser.getAttributeValue(null, "name"); |
| 9315 | if (name != null) { |
| 9316 | packageSetting.enabledComponents.add(name.intern()); |
| 9317 | } else { |
| 9318 | reportSettingsProblem(Log.WARN, |
| 9319 | "Error in package manager settings: <enabled-components> has" |
| 9320 | + " no name at " + parser.getPositionDescription()); |
| 9321 | } |
| 9322 | } else { |
| 9323 | reportSettingsProblem(Log.WARN, |
| 9324 | "Unknown element under <enabled-components>: " |
| 9325 | + parser.getName()); |
| 9326 | } |
| 9327 | XmlUtils.skipCurrentTag(parser); |
| 9328 | } |
| 9329 | } |
| 9330 | |
| 9331 | private void readSharedUserLP(XmlPullParser parser) |
| 9332 | throws XmlPullParserException, IOException { |
| 9333 | String name = null; |
| 9334 | String idStr = null; |
| 9335 | int pkgFlags = 0; |
| 9336 | SharedUserSetting su = null; |
| 9337 | try { |
| 9338 | name = parser.getAttributeValue(null, "name"); |
| 9339 | idStr = parser.getAttributeValue(null, "userId"); |
| 9340 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 9341 | if ("true".equals(parser.getAttributeValue(null, "system"))) { |
| 9342 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 9343 | } |
| 9344 | if (name == null) { |
| 9345 | reportSettingsProblem(Log.WARN, |
| 9346 | "Error in package manager settings: <shared-user> has no name at " |
| 9347 | + parser.getPositionDescription()); |
| 9348 | } else if (userId == 0) { |
| 9349 | reportSettingsProblem(Log.WARN, |
| 9350 | "Error in package manager settings: shared-user " |
| 9351 | + name + " has bad userId " + idStr + " at " |
| 9352 | + parser.getPositionDescription()); |
| 9353 | } else { |
| 9354 | if ((su=addSharedUserLP(name.intern(), userId, pkgFlags)) == null) { |
| 9355 | reportSettingsProblem(Log.ERROR, |
| 9356 | "Occurred while parsing settings at " |
| 9357 | + parser.getPositionDescription()); |
| 9358 | } |
| 9359 | } |
| 9360 | } catch (NumberFormatException e) { |
| 9361 | reportSettingsProblem(Log.WARN, |
| 9362 | "Error in package manager settings: package " |
| 9363 | + name + " has bad userId " + idStr + " at " |
| 9364 | + parser.getPositionDescription()); |
| 9365 | }; |
| 9366 | |
| 9367 | if (su != null) { |
| 9368 | int outerDepth = parser.getDepth(); |
| 9369 | int type; |
| 9370 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9371 | && (type != XmlPullParser.END_TAG |
| 9372 | || parser.getDepth() > outerDepth)) { |
| 9373 | if (type == XmlPullParser.END_TAG |
| 9374 | || type == XmlPullParser.TEXT) { |
| 9375 | continue; |
| 9376 | } |
| 9377 | |
| 9378 | String tagName = parser.getName(); |
| 9379 | if (tagName.equals("sigs")) { |
| 9380 | su.signatures.readXml(parser, mPastSignatures); |
| 9381 | } else if (tagName.equals("perms")) { |
Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 9382 | readGrantedPermissionsLP(parser, su.grantedPermissions); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9383 | } else { |
| 9384 | reportSettingsProblem(Log.WARN, |
| 9385 | "Unknown element under <shared-user>: " |
| 9386 | + parser.getName()); |
| 9387 | XmlUtils.skipCurrentTag(parser); |
| 9388 | } |
| 9389 | } |
| 9390 | |
| 9391 | } else { |
| 9392 | XmlUtils.skipCurrentTag(parser); |
| 9393 | } |
| 9394 | } |
| 9395 | |
| 9396 | private void readGrantedPermissionsLP(XmlPullParser parser, |
| 9397 | HashSet<String> outPerms) throws IOException, XmlPullParserException { |
| 9398 | int outerDepth = parser.getDepth(); |
| 9399 | int type; |
| 9400 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9401 | && (type != XmlPullParser.END_TAG |
| 9402 | || parser.getDepth() > outerDepth)) { |
| 9403 | if (type == XmlPullParser.END_TAG |
| 9404 | || type == XmlPullParser.TEXT) { |
| 9405 | continue; |
| 9406 | } |
| 9407 | |
| 9408 | String tagName = parser.getName(); |
| 9409 | if (tagName.equals("item")) { |
| 9410 | String name = parser.getAttributeValue(null, "name"); |
| 9411 | if (name != null) { |
| 9412 | outPerms.add(name.intern()); |
| 9413 | } else { |
| 9414 | reportSettingsProblem(Log.WARN, |
| 9415 | "Error in package manager settings: <perms> has" |
| 9416 | + " no name at " + parser.getPositionDescription()); |
| 9417 | } |
| 9418 | } else { |
| 9419 | reportSettingsProblem(Log.WARN, |
| 9420 | "Unknown element under <perms>: " |
| 9421 | + parser.getName()); |
| 9422 | } |
| 9423 | XmlUtils.skipCurrentTag(parser); |
| 9424 | } |
| 9425 | } |
| 9426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9427 | private void readPreferredActivitiesLP(XmlPullParser parser) |
| 9428 | throws XmlPullParserException, IOException { |
| 9429 | int outerDepth = parser.getDepth(); |
| 9430 | int type; |
| 9431 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9432 | && (type != XmlPullParser.END_TAG |
| 9433 | || parser.getDepth() > outerDepth)) { |
| 9434 | if (type == XmlPullParser.END_TAG |
| 9435 | || type == XmlPullParser.TEXT) { |
| 9436 | continue; |
| 9437 | } |
| 9438 | |
| 9439 | String tagName = parser.getName(); |
| 9440 | if (tagName.equals("item")) { |
| 9441 | PreferredActivity pa = new PreferredActivity(parser); |
| 9442 | if (pa.mParseError == null) { |
| 9443 | mPreferredActivities.addFilter(pa); |
| 9444 | } else { |
| 9445 | reportSettingsProblem(Log.WARN, |
| 9446 | "Error in package manager settings: <preferred-activity> " |
| 9447 | + pa.mParseError + " at " |
| 9448 | + parser.getPositionDescription()); |
| 9449 | } |
| 9450 | } else { |
| 9451 | reportSettingsProblem(Log.WARN, |
| 9452 | "Unknown element under <preferred-activities>: " |
| 9453 | + parser.getName()); |
| 9454 | XmlUtils.skipCurrentTag(parser); |
| 9455 | } |
| 9456 | } |
| 9457 | } |
| 9458 | |
| 9459 | // Returns -1 if we could not find an available UserId to assign |
| 9460 | private int newUserIdLP(Object obj) { |
| 9461 | // Let's be stupidly inefficient for now... |
| 9462 | final int N = mUserIds.size(); |
| 9463 | for (int i=0; i<N; i++) { |
| 9464 | if (mUserIds.get(i) == null) { |
| 9465 | mUserIds.set(i, obj); |
| 9466 | return FIRST_APPLICATION_UID + i; |
| 9467 | } |
| 9468 | } |
| 9469 | |
| 9470 | // None left? |
| 9471 | if (N >= MAX_APPLICATION_UIDS) { |
| 9472 | return -1; |
| 9473 | } |
| 9474 | |
| 9475 | mUserIds.add(obj); |
| 9476 | return FIRST_APPLICATION_UID + N; |
| 9477 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9479 | public PackageSetting getDisabledSystemPkg(String name) { |
| 9480 | synchronized(mPackages) { |
| 9481 | PackageSetting ps = mDisabledSysPackages.get(name); |
| 9482 | return ps; |
| 9483 | } |
| 9484 | } |
| 9485 | |
| 9486 | boolean isEnabledLP(ComponentInfo componentInfo, int flags) { |
| 9487 | final PackageSetting packageSettings = mPackages.get(componentInfo.packageName); |
| 9488 | if (Config.LOGV) { |
| 9489 | Log.v(TAG, "isEnabledLock - packageName = " + componentInfo.packageName |
| 9490 | + " componentName = " + componentInfo.name); |
| 9491 | Log.v(TAG, "enabledComponents: " |
| 9492 | + Arrays.toString(packageSettings.enabledComponents.toArray())); |
| 9493 | Log.v(TAG, "disabledComponents: " |
| 9494 | + Arrays.toString(packageSettings.disabledComponents.toArray())); |
| 9495 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9496 | if (packageSettings == null) { |
| 9497 | if (false) { |
| 9498 | Log.w(TAG, "WAITING FOR DEBUGGER"); |
| 9499 | Debug.waitForDebugger(); |
| 9500 | Log.i(TAG, "We will crash!"); |
| 9501 | } |
| 9502 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9503 | return ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) |
| 9504 | || ((componentInfo.enabled |
| 9505 | && ((packageSettings.enabled == COMPONENT_ENABLED_STATE_ENABLED) |
| 9506 | || (componentInfo.applicationInfo.enabled |
| 9507 | && packageSettings.enabled != COMPONENT_ENABLED_STATE_DISABLED)) |
| 9508 | && !packageSettings.disabledComponents.contains(componentInfo.name)) |
| 9509 | || packageSettings.enabledComponents.contains(componentInfo.name)); |
| 9510 | } |
| 9511 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9512 | |
| 9513 | // ------- apps on sdcard specific code ------- |
| 9514 | static final boolean DEBUG_SD_INSTALL = false; |
Oscar Montemayor | d02546b | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 9515 | final private String mSdEncryptKey = "AppsOnSD"; |
Oscar Montemayor | 462f037 | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 9516 | final private String mSdEncryptAlg = "AES"; |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9517 | private boolean mMediaMounted = false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9518 | private static final int MAX_CONTAINERS = 250; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9519 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9520 | private String getEncryptKey() { |
| 9521 | try { |
| 9522 | String sdEncKey = SystemKeyStore.getInstance().retrieveKeyHexString(mSdEncryptKey); |
| 9523 | if (sdEncKey == null) { |
| 9524 | sdEncKey = SystemKeyStore.getInstance(). |
| 9525 | generateNewKeyHexString(128, mSdEncryptAlg, mSdEncryptKey); |
| 9526 | if (sdEncKey == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9527 | Slog.e(TAG, "Failed to create encryption keys"); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9528 | return null; |
| 9529 | } |
| 9530 | } |
| 9531 | return sdEncKey; |
| 9532 | } catch (NoSuchAlgorithmException nsae) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9533 | Slog.e(TAG, "Failed to create encryption keys with exception: " + nsae); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9534 | return null; |
| 9535 | } |
| 9536 | } |
| 9537 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9538 | static String getTempContainerId() { |
Suchi Amalapurapu | cf6eaea | 2010-02-23 19:37:45 -0800 | [diff] [blame] | 9539 | String prefix = "smdl2tmp"; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9540 | int tmpIdx = 1; |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 9541 | String list[] = PackageHelper.getSecureContainerList(); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9542 | if (list != null) { |
| 9543 | int idx = 0; |
| 9544 | int idList[] = new int[MAX_CONTAINERS]; |
| 9545 | boolean neverFound = true; |
| 9546 | for (String name : list) { |
| 9547 | // Ignore null entries |
| 9548 | if (name == null) { |
| 9549 | continue; |
| 9550 | } |
| 9551 | int sidx = name.indexOf(prefix); |
| 9552 | if (sidx == -1) { |
| 9553 | // Not a temp file. just ignore |
| 9554 | continue; |
| 9555 | } |
| 9556 | String subStr = name.substring(sidx + prefix.length()); |
| 9557 | idList[idx] = -1; |
| 9558 | if (subStr != null) { |
| 9559 | try { |
| 9560 | int cid = Integer.parseInt(subStr); |
| 9561 | idList[idx++] = cid; |
| 9562 | neverFound = false; |
| 9563 | } catch (NumberFormatException e) { |
| 9564 | } |
| 9565 | } |
| 9566 | } |
| 9567 | if (!neverFound) { |
| 9568 | // Sort idList |
| 9569 | Arrays.sort(idList); |
| 9570 | for (int j = 1; j <= idList.length; j++) { |
| 9571 | if (idList[j-1] != j) { |
| 9572 | tmpIdx = j; |
| 9573 | break; |
| 9574 | } |
| 9575 | } |
| 9576 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9577 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9578 | return prefix + tmpIdx; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9579 | } |
| 9580 | |
Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9581 | /* |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9582 | * Update media status on PackageManager. |
Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9583 | */ |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9584 | public void updateExternalMediaStatus(final boolean mediaStatus, final boolean reportStatus) { |
| 9585 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9586 | throw new SecurityException("Media status can only be updated by the system"); |
| 9587 | } |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9588 | synchronized (mPackages) { |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 9589 | Log.i(TAG, "Updating external media status from " + |
| 9590 | (mMediaMounted ? "mounted" : "unmounted") + " to " + |
| 9591 | (mediaStatus ? "mounted" : "unmounted")); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9592 | if (DEBUG_SD_INSTALL) Log.i(TAG, "updateExternalMediaStatus:: mediaStatus=" + |
| 9593 | mediaStatus+", mMediaMounted=" + mMediaMounted); |
| 9594 | if (mediaStatus == mMediaMounted) { |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9595 | Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, |
| 9596 | reportStatus ? 1 : 0, -1); |
| 9597 | mHandler.sendMessage(msg); |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9598 | return; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9599 | } |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9600 | mMediaMounted = mediaStatus; |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9601 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9602 | // Queue up an async operation since the package installation may take a little while. |
| 9603 | mHandler.post(new Runnable() { |
| 9604 | public void run() { |
| 9605 | mHandler.removeCallbacks(this); |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9606 | updateExternalMediaStatusInner(mediaStatus, reportStatus); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9607 | } |
| 9608 | }); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9609 | } |
| 9610 | |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9611 | /* |
| 9612 | * Collect information of applications on external media, map them |
| 9613 | * against existing containers and update information based on current |
| 9614 | * mount status. Please note that we always have to report status |
| 9615 | * if reportStatus has been set to true especially when unloading packages. |
| 9616 | */ |
| 9617 | private void updateExternalMediaStatusInner(boolean mediaStatus, |
| 9618 | boolean reportStatus) { |
| 9619 | // Collection of uids |
| 9620 | int uidArr[] = null; |
| 9621 | // Collection of stale containers |
| 9622 | HashSet<String> removeCids = new HashSet<String>(); |
| 9623 | // Collection of packages on external media with valid containers. |
| 9624 | HashMap<SdInstallArgs, String> processCids = new HashMap<SdInstallArgs, String>(); |
| 9625 | // Get list of secure containers. |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 9626 | final String list[] = PackageHelper.getSecureContainerList(); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9627 | if (list == null || list.length == 0) { |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 9628 | Log.i(TAG, "No secure containers on sdcard"); |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9629 | } else { |
| 9630 | // Process list of secure containers and categorize them |
| 9631 | // as active or stale based on their package internal state. |
| 9632 | int uidList[] = new int[list.length]; |
| 9633 | int num = 0; |
| 9634 | synchronized (mPackages) { |
| 9635 | for (String cid : list) { |
| 9636 | SdInstallArgs args = new SdInstallArgs(cid); |
| 9637 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Processing container " + cid); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9638 | String pkgName = args.getPackageName(); |
| 9639 | if (pkgName == null) { |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9640 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " stale"); |
| 9641 | removeCids.add(cid); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9642 | continue; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9643 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9644 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Looking for pkg : " + pkgName); |
| 9645 | PackageSetting ps = mSettings.mPackages.get(pkgName); |
Suchi Amalapurapu | 1ace5bc | 2010-05-13 12:05:53 -0700 | [diff] [blame] | 9646 | // The package status is changed only if the code path |
| 9647 | // matches between settings and the container id. |
| 9648 | if (ps != null && ps.codePathString != null && |
| 9649 | ps.codePathString.equals(args.getCodePath())) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9650 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + |
| 9651 | " corresponds to pkg : " + pkgName + |
| 9652 | " at code path: " + ps.codePathString); |
| 9653 | // We do have a valid package installed on sdcard |
| 9654 | processCids.put(args, ps.codePathString); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9655 | int uid = ps.userId; |
| 9656 | if (uid != -1) { |
| 9657 | uidList[num++] = uid; |
| 9658 | } |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9659 | } else { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9660 | // Stale container on sdcard. Just delete |
| 9661 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " stale"); |
| 9662 | removeCids.add(cid); |
| 9663 | } |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9664 | } |
| 9665 | } |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9666 | |
| 9667 | if (num > 0) { |
| 9668 | // Sort uid list |
| 9669 | Arrays.sort(uidList, 0, num); |
| 9670 | // Throw away duplicates |
| 9671 | uidArr = new int[num]; |
| 9672 | uidArr[0] = uidList[0]; |
| 9673 | int di = 0; |
| 9674 | for (int i = 1; i < num; i++) { |
| 9675 | if (uidList[i-1] != uidList[i]) { |
| 9676 | uidArr[di++] = uidList[i]; |
| 9677 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9678 | } |
| 9679 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9680 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9681 | // Process packages with valid entries. |
| 9682 | if (mediaStatus) { |
| 9683 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Loading packages"); |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9684 | loadMediaPackages(processCids, uidArr, removeCids); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9685 | startCleaningPackages(); |
| 9686 | } else { |
| 9687 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Unloading packages"); |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9688 | unloadMediaPackages(processCids, uidArr, reportStatus); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9689 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9690 | } |
| 9691 | |
| 9692 | private void sendResourcesChangedBroadcast(boolean mediaStatus, |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9693 | ArrayList<String> pkgList, int uidArr[], IIntentReceiver finishedReceiver) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9694 | int size = pkgList.size(); |
| 9695 | if (size > 0) { |
| 9696 | // Send broadcasts here |
| 9697 | Bundle extras = new Bundle(); |
| 9698 | extras.putStringArray(Intent.EXTRA_CHANGED_PACKAGE_LIST, |
| 9699 | pkgList.toArray(new String[size])); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9700 | if (uidArr != null) { |
| 9701 | extras.putIntArray(Intent.EXTRA_CHANGED_UID_LIST, uidArr); |
| 9702 | } |
| 9703 | String action = mediaStatus ? Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE |
| 9704 | : Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE; |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9705 | sendPackageBroadcast(action, null, extras, finishedReceiver); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9706 | } |
| 9707 | } |
| 9708 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9709 | /* |
| 9710 | * Look at potentially valid container ids from processCids |
| 9711 | * If package information doesn't match the one on record |
| 9712 | * or package scanning fails, the cid is added to list of |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9713 | * removeCids. We currently don't delete stale containers. |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9714 | */ |
| 9715 | private void loadMediaPackages(HashMap<SdInstallArgs, String> processCids, |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9716 | int uidArr[], HashSet<String> removeCids) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9717 | ArrayList<String> pkgList = new ArrayList<String>(); |
| 9718 | Set<SdInstallArgs> keys = processCids.keySet(); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9719 | boolean doGc = false; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9720 | for (SdInstallArgs args : keys) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9721 | String codePath = processCids.get(args); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9722 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Loading container : " |
| 9723 | + args.cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9724 | int retCode = PackageManager.INSTALL_FAILED_CONTAINER_ERROR; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9725 | try { |
| 9726 | // Make sure there are no container errors first. |
| 9727 | if (args.doPreInstall(PackageManager.INSTALL_SUCCEEDED) |
| 9728 | != PackageManager.INSTALL_SUCCEEDED) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9729 | Slog.e(TAG, "Failed to mount cid : " + args.cid + |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9730 | " when installing from sdcard"); |
| 9731 | continue; |
| 9732 | } |
| 9733 | // Check code path here. |
| 9734 | if (codePath == null || !codePath.equals(args.getCodePath())) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9735 | Slog.e(TAG, "Container " + args.cid + " cachepath " + args.getCodePath()+ |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9736 | " does not match one in settings " + codePath); |
| 9737 | continue; |
| 9738 | } |
| 9739 | // Parse package |
Dianne Hackborn | 399cccb | 2010-04-13 22:57:49 -0700 | [diff] [blame] | 9740 | int parseFlags = PackageParser.PARSE_ON_SDCARD | mDefParseFlags; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9741 | doGc = true; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9742 | synchronized (mInstallLock) { |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 9743 | final PackageParser.Package pkg = scanPackageLI(new File(codePath), |
| 9744 | parseFlags, 0); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9745 | // Scan the package |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 9746 | if (pkg != null) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9747 | synchronized (mPackages) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9748 | retCode = PackageManager.INSTALL_SUCCEEDED; |
| 9749 | pkgList.add(pkg.packageName); |
| 9750 | // Post process args |
| 9751 | args.doPostInstall(PackageManager.INSTALL_SUCCEEDED); |
| 9752 | } |
| 9753 | } else { |
Suchi Amalapurapu | ae18171 | 2010-03-30 14:01:02 -0700 | [diff] [blame] | 9754 | Slog.i(TAG, "Failed to install pkg from " + |
| 9755 | codePath + " from sdcard"); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9756 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9757 | } |
| 9758 | |
| 9759 | } finally { |
| 9760 | if (retCode != PackageManager.INSTALL_SUCCEEDED) { |
| 9761 | // Don't destroy container here. Wait till gc clears things up. |
| 9762 | removeCids.add(args.cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9763 | } |
| 9764 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9765 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 9766 | synchronized (mPackages) { |
Dianne Hackborn | f22221f | 2010-04-05 18:35:42 -0700 | [diff] [blame] | 9767 | // If the platform SDK has changed since the last time we booted, |
| 9768 | // we need to re-grant app permission to catch any new ones that |
| 9769 | // appear. This is really a hack, and means that apps can in some |
| 9770 | // cases get permissions that the user didn't initially explicitly |
| 9771 | // allow... it would be nice to have some better way to handle |
| 9772 | // this situation. |
| 9773 | final boolean regrantPermissions = mSettings.mExternalSdkPlatform |
| 9774 | != mSdkVersion; |
| 9775 | if (regrantPermissions) Slog.i(TAG, "Platform changed from " |
| 9776 | + mSettings.mExternalSdkPlatform + " to " + mSdkVersion |
| 9777 | + "; regranting permissions for external storage"); |
| 9778 | mSettings.mExternalSdkPlatform = mSdkVersion; |
| 9779 | |
Dianne Hackborn | af7cea3 | 2010-03-24 12:59:52 -0700 | [diff] [blame] | 9780 | // Make sure group IDs have been assigned, and any permission |
| 9781 | // changes in other apps are accounted for |
Dianne Hackborn | 92cfa10 | 2010-04-28 11:00:44 -0700 | [diff] [blame] | 9782 | updatePermissionsLP(null, null, true, regrantPermissions, regrantPermissions); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 9783 | // Persist settings |
| 9784 | mSettings.writeLP(); |
| 9785 | } |
Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9786 | // Send a broadcast to let everyone know we are done processing |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9787 | if (pkgList.size() > 0) { |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9788 | sendResourcesChangedBroadcast(true, pkgList, uidArr, null); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9789 | } |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9790 | // Force gc to avoid any stale parser references that we might have. |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9791 | if (doGc) { |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9792 | Runtime.getRuntime().gc(); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9793 | } |
Suchi Amalapurapu | f654a48 | 2010-03-23 09:46:22 -0700 | [diff] [blame] | 9794 | // List stale containers. |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9795 | if (removeCids != null) { |
| 9796 | for (String cid : removeCids) { |
Suchi Amalapurapu | f654a48 | 2010-03-23 09:46:22 -0700 | [diff] [blame] | 9797 | Log.w(TAG, "Container " + cid + " is stale"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9798 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9799 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9800 | } |
| 9801 | |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9802 | /* |
| 9803 | * Utility method to unload a list of specified containers |
| 9804 | */ |
| 9805 | private void unloadAllContainers(Set<SdInstallArgs> cidArgs) { |
| 9806 | // Just unmount all valid containers. |
| 9807 | for (SdInstallArgs arg : cidArgs) { |
| 9808 | synchronized (mInstallLock) { |
| 9809 | arg.doPostDeleteLI(false); |
| 9810 | } |
| 9811 | } |
| 9812 | } |
| 9813 | |
| 9814 | /* |
| 9815 | * Unload packages mounted on external media. This involves deleting |
| 9816 | * package data from internal structures, sending broadcasts about |
| 9817 | * diabled packages, gc'ing to free up references, unmounting all |
| 9818 | * secure containers corresponding to packages on external media, and |
| 9819 | * posting a UPDATED_MEDIA_STATUS message if status has been requested. |
| 9820 | * Please note that we always have to post this message if status has |
| 9821 | * been requested no matter what. |
| 9822 | */ |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9823 | private void unloadMediaPackages(HashMap<SdInstallArgs, String> processCids, |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9824 | int uidArr[], final boolean reportStatus) { |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9825 | if (DEBUG_SD_INSTALL) Log.i(TAG, "unloading media packages"); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9826 | ArrayList<String> pkgList = new ArrayList<String>(); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9827 | ArrayList<SdInstallArgs> failedList = new ArrayList<SdInstallArgs>(); |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9828 | final Set<SdInstallArgs> keys = processCids.keySet(); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9829 | for (SdInstallArgs args : keys) { |
| 9830 | String cid = args.cid; |
| 9831 | String pkgName = args.getPackageName(); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9832 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to unload pkg : " + pkgName); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9833 | // Delete package internally |
| 9834 | PackageRemovedInfo outInfo = new PackageRemovedInfo(); |
| 9835 | synchronized (mInstallLock) { |
| 9836 | boolean res = deletePackageLI(pkgName, false, |
| 9837 | PackageManager.DONT_DELETE_DATA, outInfo); |
| 9838 | if (res) { |
| 9839 | pkgList.add(pkgName); |
| 9840 | } else { |
Jeff Brown | 0733079 | 2010-03-30 19:57:08 -0700 | [diff] [blame] | 9841 | Slog.e(TAG, "Failed to delete pkg from sdcard : " + pkgName); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9842 | failedList.add(args); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9843 | } |
| 9844 | } |
| 9845 | } |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9846 | // We have to absolutely send UPDATED_MEDIA_STATUS only |
| 9847 | // after confirming that all the receivers processed the ordered |
| 9848 | // broadcast when packages get disabled, force a gc to clean things up. |
| 9849 | // and unload all the containers. |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9850 | if (pkgList.size() > 0) { |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9851 | sendResourcesChangedBroadcast(false, pkgList, uidArr, new IIntentReceiver.Stub() { |
| 9852 | public void performReceive(Intent intent, int resultCode, String data, Bundle extras, |
| 9853 | boolean ordered, boolean sticky) throws RemoteException { |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9854 | Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, |
| 9855 | reportStatus ? 1 : 0, 1, keys); |
| 9856 | mHandler.sendMessage(msg); |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9857 | } |
| 9858 | }); |
Suchi Amalapurapu | 3d24425 | 2010-04-08 14:37:05 -0700 | [diff] [blame] | 9859 | } else { |
| 9860 | Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, |
| 9861 | reportStatus ? 1 : 0, -1, keys); |
| 9862 | mHandler.sendMessage(msg); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9863 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9864 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9865 | |
| 9866 | public void movePackage(final String packageName, |
| 9867 | final IPackageMoveObserver observer, final int flags) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9868 | mContext.enforceCallingOrSelfPermission( |
| 9869 | android.Manifest.permission.MOVE_PACKAGE, null); |
| 9870 | int returnCode = PackageManager.MOVE_SUCCEEDED; |
| 9871 | int currFlags = 0; |
| 9872 | int newFlags = 0; |
| 9873 | synchronized (mPackages) { |
| 9874 | PackageParser.Package pkg = mPackages.get(packageName); |
| 9875 | if (pkg == null) { |
| 9876 | returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9877 | } else { |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9878 | // Disable moving fwd locked apps and system packages |
| 9879 | if (pkg.applicationInfo != null && |
| 9880 | (pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 9881 | Slog.w(TAG, "Cannot move system application"); |
| 9882 | returnCode = PackageManager.MOVE_FAILED_SYSTEM_PACKAGE; |
| 9883 | } else if (pkg.applicationInfo != null && |
| 9884 | (pkg.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0) { |
| 9885 | Slog.w(TAG, "Cannot move forward locked app."); |
| 9886 | returnCode = PackageManager.MOVE_FAILED_FORWARD_LOCKED; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9887 | } else { |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9888 | // Find install location first |
| 9889 | if ((flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0 && |
| 9890 | (flags & PackageManager.MOVE_INTERNAL) != 0) { |
| 9891 | Slog.w(TAG, "Ambigous flags specified for move location."); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9892 | returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION; |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9893 | } else { |
| 9894 | newFlags = (flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0 ? |
| 9895 | PackageManager.INSTALL_EXTERNAL : PackageManager.INSTALL_INTERNAL; |
| 9896 | currFlags = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0 ? |
| 9897 | PackageManager.INSTALL_EXTERNAL : PackageManager.INSTALL_INTERNAL; |
| 9898 | if (newFlags == currFlags) { |
| 9899 | Slog.w(TAG, "No move required. Trying to move to same location"); |
| 9900 | returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION; |
| 9901 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9902 | } |
| 9903 | } |
| 9904 | } |
| 9905 | if (returnCode != PackageManager.MOVE_SUCCEEDED) { |
Suchi Amalapurapu | deb69370 | 2010-04-14 19:17:14 -0700 | [diff] [blame] | 9906 | processPendingMove(new MoveParams(null, observer, 0, packageName), returnCode); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9907 | } else { |
| 9908 | Message msg = mHandler.obtainMessage(INIT_COPY); |
| 9909 | InstallArgs srcArgs = createInstallArgs(currFlags, pkg.applicationInfo.sourceDir, |
| 9910 | pkg.applicationInfo.publicSourceDir); |
| 9911 | MoveParams mp = new MoveParams(srcArgs, observer, newFlags, |
| 9912 | packageName); |
| 9913 | msg.obj = mp; |
| 9914 | mHandler.sendMessage(msg); |
| 9915 | } |
| 9916 | } |
| 9917 | } |
| 9918 | |
| 9919 | private void processPendingMove(final MoveParams mp, final int currentStatus) { |
| 9920 | // Queue up an async operation since the package deletion may take a little while. |
| 9921 | mHandler.post(new Runnable() { |
| 9922 | public void run() { |
| 9923 | mHandler.removeCallbacks(this); |
| 9924 | int returnCode = currentStatus; |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9925 | if (currentStatus == PackageManager.MOVE_SUCCEEDED) { |
| 9926 | int uidArr[] = null; |
| 9927 | ArrayList<String> pkgList = null; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9928 | synchronized (mPackages) { |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9929 | PackageParser.Package pkg = mPackages.get(mp.packageName); |
| 9930 | if (pkg == null ) { |
| 9931 | Slog.w(TAG, " Package " + mp.packageName + |
| 9932 | " doesn't exist. Aborting move"); |
| 9933 | returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST; |
| 9934 | } else if (!mp.srcArgs.getCodePath().equals(pkg.applicationInfo.sourceDir)) { |
| 9935 | Slog.w(TAG, "Package " + mp.packageName + " code path changed from " + |
| 9936 | mp.srcArgs.getCodePath() + " to " + pkg.applicationInfo.sourceDir + |
| 9937 | " Aborting move and returning error"); |
| 9938 | returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR; |
| 9939 | } else { |
| 9940 | uidArr = new int[] { pkg.applicationInfo.uid }; |
| 9941 | pkgList = new ArrayList<String>(); |
| 9942 | pkgList.add(mp.packageName); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9943 | } |
| 9944 | } |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9945 | if (returnCode == PackageManager.MOVE_SUCCEEDED) { |
| 9946 | // Send resources unavailable broadcast |
Dianne Hackborn | ecb0e63 | 2010-04-07 20:22:55 -0700 | [diff] [blame] | 9947 | sendResourcesChangedBroadcast(false, pkgList, uidArr, null); |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9948 | // Update package code and resource paths |
| 9949 | synchronized (mInstallLock) { |
| 9950 | synchronized (mPackages) { |
| 9951 | PackageParser.Package pkg = mPackages.get(mp.packageName); |
| 9952 | // Recheck for package again. |
| 9953 | if (pkg == null ) { |
| 9954 | Slog.w(TAG, " Package " + mp.packageName + |
| 9955 | " doesn't exist. Aborting move"); |
| 9956 | returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST; |
| 9957 | } else if (!mp.srcArgs.getCodePath().equals(pkg.applicationInfo.sourceDir)) { |
| 9958 | Slog.w(TAG, "Package " + mp.packageName + " code path changed from " + |
| 9959 | mp.srcArgs.getCodePath() + " to " + pkg.applicationInfo.sourceDir + |
| 9960 | " Aborting move and returning error"); |
| 9961 | returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR; |
| 9962 | } else { |
| 9963 | String oldCodePath = pkg.mPath; |
| 9964 | String newCodePath = mp.targetArgs.getCodePath(); |
| 9965 | String newResPath = mp.targetArgs.getResourcePath(); |
| 9966 | pkg.mPath = newCodePath; |
| 9967 | // Move dex files around |
| 9968 | if (moveDexFilesLI(pkg) |
| 9969 | != PackageManager.INSTALL_SUCCEEDED) { |
| 9970 | // Moving of dex files failed. Set |
| 9971 | // error code and abort move. |
| 9972 | pkg.mPath = pkg.mScanPath; |
| 9973 | returnCode = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE; |
| 9974 | } else { |
| 9975 | pkg.mScanPath = newCodePath; |
| 9976 | pkg.applicationInfo.sourceDir = newCodePath; |
| 9977 | pkg.applicationInfo.publicSourceDir = newResPath; |
| 9978 | PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 9979 | ps.codePath = new File(pkg.applicationInfo.sourceDir); |
| 9980 | ps.codePathString = ps.codePath.getPath(); |
| 9981 | ps.resourcePath = new File(pkg.applicationInfo.publicSourceDir); |
| 9982 | ps.resourcePathString = ps.resourcePath.getPath(); |
| 9983 | // Set the application info flag correctly. |
| 9984 | if ((mp.flags & PackageManager.INSTALL_EXTERNAL) != 0) { |
| 9985 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 9986 | } else { |
| 9987 | pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
| 9988 | } |
| 9989 | ps.setFlags(pkg.applicationInfo.flags); |
| 9990 | mAppDirs.remove(oldCodePath); |
| 9991 | mAppDirs.put(newCodePath, pkg); |
| 9992 | // Persist settings |
| 9993 | mSettings.writeLP(); |
| 9994 | } |
| 9995 | } |
| 9996 | } |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 9997 | } |
Suchi Amalapurapu | 0c1285f | 2010-04-14 17:05:48 -0700 | [diff] [blame] | 9998 | // Send resources available broadcast |
| 9999 | sendResourcesChangedBroadcast(true, pkgList, uidArr, null); |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 10000 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 10001 | } |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 10002 | if (returnCode != PackageManager.MOVE_SUCCEEDED){ |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 10003 | // Clean up failed installation |
| 10004 | if (mp.targetArgs != null) { |
Suchi Amalapurapu | 30f775b | 2010-04-06 11:41:23 -0700 | [diff] [blame] | 10005 | mp.targetArgs.doPostInstall(PackageManager.INSTALL_FAILED_INTERNAL_ERROR); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 10006 | } |
| 10007 | } else { |
| 10008 | // Force a gc to clear things up. |
| 10009 | Runtime.getRuntime().gc(); |
| 10010 | // Delete older code |
| 10011 | synchronized (mInstallLock) { |
| 10012 | mp.srcArgs.doPostDeleteLI(true); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 10013 | } |
| 10014 | } |
| 10015 | IPackageMoveObserver observer = mp.observer; |
| 10016 | if (observer != null) { |
| 10017 | try { |
| 10018 | observer.packageMoved(mp.packageName, returnCode); |
| 10019 | } catch (RemoteException e) { |
| 10020 | Log.i(TAG, "Observer no longer exists."); |
| 10021 | } |
| 10022 | } |
| 10023 | } |
| 10024 | }); |
| 10025 | } |
Suchi Amalapurapu | 40e4725 | 2010-04-07 16:15:50 -0700 | [diff] [blame] | 10026 | |
| 10027 | public boolean setInstallLocation(int loc) { |
| 10028 | mContext.enforceCallingOrSelfPermission( |
| 10029 | android.Manifest.permission.WRITE_SECURE_SETTINGS, null); |
| 10030 | if (getInstallLocation() == loc) { |
| 10031 | return true; |
| 10032 | } |
| 10033 | if (loc == PackageHelper.APP_INSTALL_AUTO || |
| 10034 | loc == PackageHelper.APP_INSTALL_INTERNAL || |
| 10035 | loc == PackageHelper.APP_INSTALL_EXTERNAL) { |
| 10036 | android.provider.Settings.System.putInt(mContext.getContentResolver(), |
| 10037 | android.provider.Settings.Secure.DEFAULT_INSTALL_LOCATION, loc); |
| 10038 | return true; |
| 10039 | } |
| 10040 | return false; |
| 10041 | } |
| 10042 | |
| 10043 | public int getInstallLocation() { |
| 10044 | return android.provider.Settings.System.getInt(mContext.getContentResolver(), |
| 10045 | android.provider.Settings.Secure.DEFAULT_INSTALL_LOCATION, PackageHelper.APP_INSTALL_AUTO); |
| 10046 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10047 | } |