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.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.content.Context; |
| 36 | import android.content.Intent; |
| 37 | import android.content.IntentFilter; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 38 | import android.content.IntentSender; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 39 | import android.content.ServiceConnection; |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 40 | import android.content.IntentSender.SendIntentException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.content.pm.ActivityInfo; |
| 42 | import android.content.pm.ApplicationInfo; |
| 43 | import android.content.pm.ComponentInfo; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 44 | import android.content.pm.FeatureInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.content.pm.IPackageDataObserver; |
| 46 | import android.content.pm.IPackageDeleteObserver; |
| 47 | import android.content.pm.IPackageInstallObserver; |
| 48 | import android.content.pm.IPackageManager; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 49 | import android.content.pm.IPackageMoveObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.content.pm.IPackageStatsObserver; |
| 51 | import android.content.pm.InstrumentationInfo; |
| 52 | import android.content.pm.PackageInfo; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 53 | import android.content.pm.PackageInfoLite; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.content.pm.PackageManager; |
| 55 | import android.content.pm.PackageStats; |
| 56 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; |
| 57 | import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; |
| 58 | 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] | 59 | import android.content.pm.PackageParser; |
| 60 | import android.content.pm.PermissionInfo; |
| 61 | import android.content.pm.PermissionGroupInfo; |
| 62 | import android.content.pm.ProviderInfo; |
| 63 | import android.content.pm.ResolveInfo; |
| 64 | import android.content.pm.ServiceInfo; |
| 65 | import android.content.pm.Signature; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.net.Uri; |
| 67 | import android.os.Binder; |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 68 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.os.Bundle; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 70 | import android.os.Debug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.os.HandlerThread; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 72 | import android.os.IBinder; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 73 | import android.os.Looper; |
| 74 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.Parcel; |
| 76 | import android.os.RemoteException; |
| 77 | import android.os.Environment; |
| 78 | import android.os.FileObserver; |
| 79 | import android.os.FileUtils; |
| 80 | import android.os.Handler; |
| 81 | import android.os.ParcelFileDescriptor; |
| 82 | import android.os.Process; |
| 83 | import android.os.ServiceManager; |
| 84 | import android.os.SystemClock; |
| 85 | import android.os.SystemProperties; |
Oscar Montemayor | d02546b | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 86 | import android.security.SystemKeyStore; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import android.util.*; |
| 88 | import android.view.Display; |
| 89 | import android.view.WindowManager; |
| 90 | |
| 91 | import java.io.File; |
| 92 | import java.io.FileDescriptor; |
| 93 | import java.io.FileInputStream; |
| 94 | import java.io.FileNotFoundException; |
| 95 | import java.io.FileOutputStream; |
| 96 | import java.io.FileReader; |
| 97 | import java.io.FilenameFilter; |
| 98 | import java.io.IOException; |
| 99 | import java.io.InputStream; |
| 100 | import java.io.PrintWriter; |
Oscar Montemayor | d02546b | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 101 | import java.security.NoSuchAlgorithmException; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 102 | import java.text.SimpleDateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | import java.util.ArrayList; |
| 104 | import java.util.Arrays; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 105 | import java.util.Collection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import java.util.Collections; |
| 107 | import java.util.Comparator; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 108 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | import java.util.Enumeration; |
| 110 | import java.util.HashMap; |
| 111 | import java.util.HashSet; |
| 112 | import java.util.Iterator; |
| 113 | import java.util.List; |
| 114 | import java.util.Map; |
| 115 | import java.util.Set; |
| 116 | import java.util.zip.ZipEntry; |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 117 | import java.util.zip.ZipException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | import java.util.zip.ZipFile; |
| 119 | import java.util.zip.ZipOutputStream; |
| 120 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 121 | /** |
| 122 | * Keep track of all those .apks everywhere. |
| 123 | * |
| 124 | * This is very central to the platform's security; please run the unit |
| 125 | * tests whenever making modifications here: |
| 126 | * |
| 127 | mmm frameworks/base/tests/AndroidTests |
| 128 | adb install -r -f out/target/product/passion/data/app/AndroidTests.apk |
| 129 | adb shell am instrument -w -e class com.android.unit_tests.PackageManagerTests com.android.unit_tests/android.test.InstrumentationTestRunner |
| 130 | * |
| 131 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | class PackageManagerService extends IPackageManager.Stub { |
| 133 | private static final String TAG = "PackageManager"; |
| 134 | private static final boolean DEBUG_SETTINGS = false; |
| 135 | private static final boolean DEBUG_PREFERRED = false; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 136 | private static final boolean DEBUG_UPGRADE = false; |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 137 | private static final boolean DEBUG_INSTALL = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | |
| 139 | private static final boolean MULTIPLE_APPLICATION_UIDS = true; |
| 140 | private static final int RADIO_UID = Process.PHONE_UID; |
Mike Lockwood | d42685d | 2009-09-03 09:25:22 -0400 | [diff] [blame] | 141 | private static final int LOG_UID = Process.LOG_UID; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | private static final int FIRST_APPLICATION_UID = |
| 143 | Process.FIRST_APPLICATION_UID; |
| 144 | private static final int MAX_APPLICATION_UIDS = 1000; |
| 145 | |
| 146 | private static final boolean SHOW_INFO = false; |
| 147 | |
| 148 | private static final boolean GET_CERTIFICATES = true; |
| 149 | |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 150 | private static final String SYSTEM_PROPERTY_EFS_ENABLED = "persist.security.efs.enabled"; |
| 151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | private static final int REMOVE_EVENTS = |
| 153 | FileObserver.CLOSE_WRITE | FileObserver.DELETE | FileObserver.MOVED_FROM; |
| 154 | private static final int ADD_EVENTS = |
| 155 | FileObserver.CLOSE_WRITE /*| FileObserver.CREATE*/ | FileObserver.MOVED_TO; |
| 156 | |
| 157 | private static final int OBSERVER_EVENTS = REMOVE_EVENTS | ADD_EVENTS; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 158 | // Suffix used during package installation when copying/moving |
| 159 | // package apks to install directory. |
| 160 | private static final String INSTALL_PACKAGE_SUFFIX = "-"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | |
Suchi Amalapurapu | 1f9e1b4 | 2010-02-26 13:14:31 -0800 | [diff] [blame] | 162 | /** |
| 163 | * Indicates the state of installation. Used by PackageManager to |
| 164 | * figure out incomplete installations. Say a package is being installed |
| 165 | * (the state is set to PKG_INSTALL_INCOMPLETE) and remains so till |
| 166 | * the package installation is successful or unsuccesful lin which case |
| 167 | * the PackageManager will no longer maintain state information associated |
| 168 | * with the package. If some exception(like device freeze or battery being |
| 169 | * pulled out) occurs during installation of a package, the PackageManager |
| 170 | * needs this information to clean up the previously failed installation. |
| 171 | */ |
| 172 | private static final int PKG_INSTALL_INCOMPLETE = 0; |
| 173 | private static final int PKG_INSTALL_COMPLETE = 1; |
| 174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | static final int SCAN_MONITOR = 1<<0; |
| 176 | static final int SCAN_NO_DEX = 1<<1; |
| 177 | static final int SCAN_FORCE_DEX = 1<<2; |
| 178 | static final int SCAN_UPDATE_SIGNATURE = 1<<3; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 179 | static final int SCAN_NEW_INSTALL = 1<<4; |
| 180 | static final int SCAN_NO_PATHS = 1<<5; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 182 | static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName( |
| 183 | "com.android.defcontainer", |
| 184 | "com.android.defcontainer.DefaultContainerService"); |
| 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | final HandlerThread mHandlerThread = new HandlerThread("PackageManager", |
| 187 | Process.THREAD_PRIORITY_BACKGROUND); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 188 | final PackageHandler mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | |
Dianne Hackborn | 851a541 | 2009-05-08 12:06:44 -0700 | [diff] [blame] | 190 | final int mSdkVersion = Build.VERSION.SDK_INT; |
| 191 | final String mSdkCodename = "REL".equals(Build.VERSION.CODENAME) |
| 192 | ? null : Build.VERSION.CODENAME; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | final Context mContext; |
| 195 | final boolean mFactoryTest; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 196 | final boolean mNoDexOpt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | final DisplayMetrics mMetrics; |
| 198 | final int mDefParseFlags; |
| 199 | final String[] mSeparateProcesses; |
| 200 | |
| 201 | // This is where all application persistent data goes. |
| 202 | final File mAppDataDir; |
| 203 | |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 204 | // If Encrypted File System feature is enabled, all application persistent data |
| 205 | // should go here instead. |
| 206 | final File mSecureAppDataDir; |
| 207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | // This is the object monitoring the framework dir. |
| 209 | final FileObserver mFrameworkInstallObserver; |
| 210 | |
| 211 | // This is the object monitoring the system app dir. |
| 212 | final FileObserver mSystemInstallObserver; |
| 213 | |
| 214 | // This is the object monitoring mAppInstallDir. |
| 215 | final FileObserver mAppInstallObserver; |
| 216 | |
| 217 | // This is the object monitoring mDrmAppPrivateInstallDir. |
| 218 | final FileObserver mDrmAppInstallObserver; |
| 219 | |
| 220 | // Used for priviledge escalation. MUST NOT BE CALLED WITH mPackages |
| 221 | // LOCK HELD. Can be called with mInstallLock held. |
| 222 | final Installer mInstaller; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | final File mFrameworkDir; |
| 225 | final File mSystemAppDir; |
| 226 | final File mAppInstallDir; |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 227 | final File mDalvikCacheDir; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | |
| 229 | // Directory containing the private parts (e.g. code and non-resource assets) of forward-locked |
| 230 | // apps. |
| 231 | final File mDrmAppPrivateInstallDir; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | // ---------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | // Lock for state used when installing and doing other long running |
| 236 | // operations. Methods that must be called with this lock held have |
| 237 | // the prefix "LI". |
| 238 | final Object mInstallLock = new Object(); |
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 | // These are the directories in the 3rd party applications installed dir |
| 241 | // that we have currently loaded packages from. Keys are the application's |
| 242 | // installed zip file (absolute codePath), and values are Package. |
| 243 | final HashMap<String, PackageParser.Package> mAppDirs = |
| 244 | new HashMap<String, PackageParser.Package>(); |
| 245 | |
| 246 | // Information for the parser to write more useful error messages. |
| 247 | File mScanningPath; |
| 248 | int mLastScanError; |
| 249 | |
| 250 | final int[] mOutPermissions = new int[3]; |
| 251 | |
| 252 | // ---------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | // Keys are String (package name), values are Package. This also serves |
| 255 | // as the lock for the global state. Methods that must be called with |
| 256 | // this lock held have the prefix "LP". |
| 257 | final HashMap<String, PackageParser.Package> mPackages = |
| 258 | new HashMap<String, PackageParser.Package>(); |
| 259 | |
| 260 | final Settings mSettings; |
| 261 | boolean mRestoredSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | |
| 263 | // Group-ids that are given to all packages as read from etc/permissions/*.xml. |
| 264 | int[] mGlobalGids; |
| 265 | |
| 266 | // These are the built-in uid -> permission mappings that were read from the |
| 267 | // etc/permissions.xml file. |
| 268 | final SparseArray<HashSet<String>> mSystemPermissions = |
| 269 | new SparseArray<HashSet<String>>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | // These are the built-in shared libraries that were read from the |
| 272 | // etc/permissions.xml file. |
| 273 | final HashMap<String, String> mSharedLibraries = new HashMap<String, String>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 274 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 275 | // Temporary for building the final shared libraries for an .apk. |
| 276 | String[] mTmpSharedLibraries = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 277 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 278 | // These are the features this devices supports that were read from the |
| 279 | // etc/permissions.xml file. |
| 280 | final HashMap<String, FeatureInfo> mAvailableFeatures = |
| 281 | new HashMap<String, FeatureInfo>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | // All available activities, for your resolving pleasure. |
| 284 | final ActivityIntentResolver mActivities = |
| 285 | new ActivityIntentResolver(); |
| 286 | |
| 287 | // All available receivers, for your resolving pleasure. |
| 288 | final ActivityIntentResolver mReceivers = |
| 289 | new ActivityIntentResolver(); |
| 290 | |
| 291 | // All available services, for your resolving pleasure. |
| 292 | final ServiceIntentResolver mServices = new ServiceIntentResolver(); |
| 293 | |
| 294 | // Keys are String (provider class name), values are Provider. |
| 295 | final HashMap<ComponentName, PackageParser.Provider> mProvidersByComponent = |
| 296 | new HashMap<ComponentName, PackageParser.Provider>(); |
| 297 | |
| 298 | // Mapping from provider base names (first directory in content URI codePath) |
| 299 | // to the provider information. |
| 300 | final HashMap<String, PackageParser.Provider> mProviders = |
| 301 | new HashMap<String, PackageParser.Provider>(); |
| 302 | |
| 303 | // Mapping from instrumentation class names to info about them. |
| 304 | final HashMap<ComponentName, PackageParser.Instrumentation> mInstrumentation = |
| 305 | new HashMap<ComponentName, PackageParser.Instrumentation>(); |
| 306 | |
| 307 | // Mapping from permission names to info about them. |
| 308 | final HashMap<String, PackageParser.PermissionGroup> mPermissionGroups = |
| 309 | new HashMap<String, PackageParser.PermissionGroup>(); |
| 310 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 311 | // Packages whose data we have transfered into another package, thus |
| 312 | // should no longer exist. |
| 313 | final HashSet<String> mTransferedPackages = new HashSet<String>(); |
| 314 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 315 | // Broadcast actions that are only available to the system. |
| 316 | final HashSet<String> mProtectedBroadcasts = new HashSet<String>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | boolean mSystemReady; |
| 319 | boolean mSafeMode; |
| 320 | boolean mHasSystemUidErrors; |
| 321 | |
| 322 | ApplicationInfo mAndroidApplication; |
| 323 | final ActivityInfo mResolveActivity = new ActivityInfo(); |
| 324 | final ResolveInfo mResolveInfo = new ResolveInfo(); |
| 325 | ComponentName mResolveComponentName; |
| 326 | PackageParser.Package mPlatformPackage; |
| 327 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 328 | // Set of pending broadcasts for aggregating enable/disable of components. |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 329 | final HashMap<String, ArrayList<String>> mPendingBroadcasts |
| 330 | = new HashMap<String, ArrayList<String>>(); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 331 | // Service Connection to remote media container service to copy |
| 332 | // package uri's from external media onto secure containers |
| 333 | // or internal storage. |
| 334 | private IMediaContainerService mContainerService = null; |
| 335 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 336 | static final int SEND_PENDING_BROADCAST = 1; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 337 | static final int MCS_BOUND = 3; |
| 338 | static final int END_COPY = 4; |
| 339 | static final int INIT_COPY = 5; |
| 340 | static final int MCS_UNBIND = 6; |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 341 | static final int START_CLEANING_PACKAGE = 7; |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 342 | static final int FIND_INSTALL_LOC = 8; |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 343 | static final int POST_INSTALL = 9; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 344 | static final int MCS_RECONNECT = 10; |
| 345 | static final int MCS_GIVE_UP = 11; |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 346 | static final int UPDATED_MEDIA_STATUS = 12; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 347 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 348 | // Delay time in millisecs |
| 349 | static final int BROADCAST_DELAY = 10 * 1000; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 350 | final private DefaultContainerConnection mDefContainerConn = |
| 351 | new DefaultContainerConnection(); |
| 352 | class DefaultContainerConnection implements ServiceConnection { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 353 | public void onServiceConnected(ComponentName name, IBinder service) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 354 | if (DEBUG_SD_INSTALL) Log.i(TAG, "onServiceConnected"); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 355 | IMediaContainerService imcs = |
| 356 | IMediaContainerService.Stub.asInterface(service); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 357 | mHandler.sendMessage(mHandler.obtainMessage(MCS_BOUND, imcs)); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | public void onServiceDisconnected(ComponentName name) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 361 | if (DEBUG_SD_INSTALL) Log.i(TAG, "onServiceDisconnected"); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 362 | } |
| 363 | }; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 364 | |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 365 | // Recordkeeping of restore-after-install operations that are currently in flight |
| 366 | // between the Package Manager and the Backup Manager |
| 367 | class PostInstallData { |
| 368 | public InstallArgs args; |
| 369 | public PackageInstalledInfo res; |
| 370 | |
| 371 | PostInstallData(InstallArgs _a, PackageInstalledInfo _r) { |
| 372 | args = _a; |
| 373 | res = _r; |
| 374 | } |
| 375 | }; |
| 376 | final SparseArray<PostInstallData> mRunningInstalls = new SparseArray<PostInstallData>(); |
| 377 | int mNextInstallToken = 1; // nonzero; will be wrapped back to 1 when ++ overflows |
| 378 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 379 | class PackageHandler extends Handler { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 380 | private boolean mBound = false; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 381 | final ArrayList<HandlerParams> mPendingInstalls = |
| 382 | new ArrayList<HandlerParams>(); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 383 | |
| 384 | private boolean connectToService() { |
| 385 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to bind to" + |
| 386 | " DefaultContainerService"); |
| 387 | Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT); |
| 388 | if (mContext.bindService(service, mDefContainerConn, |
| 389 | Context.BIND_AUTO_CREATE)) { |
| 390 | mBound = true; |
| 391 | return true; |
| 392 | } |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | private void disconnectService() { |
| 397 | mContainerService = null; |
| 398 | mBound = false; |
| 399 | mContext.unbindService(mDefContainerConn); |
| 400 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 401 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 402 | PackageHandler(Looper looper) { |
| 403 | super(looper); |
| 404 | } |
| 405 | public void handleMessage(Message msg) { |
| 406 | switch (msg.what) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 407 | case INIT_COPY: { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 408 | if (DEBUG_SD_INSTALL) Log.i(TAG, "init_copy"); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 409 | HandlerParams params = (HandlerParams) msg.obj; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 410 | int idx = mPendingInstalls.size(); |
| 411 | if (DEBUG_SD_INSTALL) Log.i(TAG, "idx=" + idx); |
| 412 | // If a bind was already initiated we dont really |
| 413 | // need to do anything. The pending install |
| 414 | // will be processed later on. |
| 415 | if (!mBound) { |
| 416 | // If this is the only one pending we might |
| 417 | // have to bind to the service again. |
| 418 | if (!connectToService()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 419 | Slog.e(TAG, "Failed to bind to media container service"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 420 | params.serviceError(); |
| 421 | return; |
| 422 | } else { |
| 423 | // Once we bind to the service, the first |
| 424 | // pending request will be processed. |
| 425 | mPendingInstalls.add(idx, params); |
| 426 | } |
| 427 | } else { |
| 428 | mPendingInstalls.add(idx, params); |
| 429 | // Already bound to the service. Just make |
| 430 | // sure we trigger off processing the first request. |
| 431 | if (idx == 0) { |
| 432 | mHandler.sendEmptyMessage(MCS_BOUND); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | break; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 436 | } |
| 437 | case MCS_BOUND: { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 438 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_bound"); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 439 | if (msg.obj != null) { |
| 440 | mContainerService = (IMediaContainerService) msg.obj; |
| 441 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 442 | if (mContainerService == null) { |
| 443 | // Something seriously wrong. Bail out |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 444 | Slog.e(TAG, "Cannot bind to media container service"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 445 | for (HandlerParams params : mPendingInstalls) { |
| 446 | mPendingInstalls.remove(0); |
| 447 | // Indicate service bind error |
| 448 | params.serviceError(); |
| 449 | } |
| 450 | mPendingInstalls.clear(); |
| 451 | } else if (mPendingInstalls.size() > 0) { |
| 452 | HandlerParams params = mPendingInstalls.get(0); |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 453 | if (params != null) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 454 | params.startCopy(); |
| 455 | } |
| 456 | } else { |
| 457 | // Should never happen ideally. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 458 | Slog.w(TAG, "Empty queue"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 459 | } |
| 460 | break; |
| 461 | } |
| 462 | case MCS_RECONNECT : { |
| 463 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_reconnect"); |
| 464 | if (mPendingInstalls.size() > 0) { |
| 465 | if (mBound) { |
| 466 | disconnectService(); |
| 467 | } |
| 468 | if (!connectToService()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 469 | Slog.e(TAG, "Failed to bind to media container service"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 470 | for (HandlerParams params : mPendingInstalls) { |
| 471 | mPendingInstalls.remove(0); |
| 472 | // Indicate service bind error |
| 473 | params.serviceError(); |
| 474 | } |
| 475 | mPendingInstalls.clear(); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | break; |
| 479 | } |
| 480 | case MCS_UNBIND : { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 481 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_unbind"); |
| 482 | // Delete pending install |
| 483 | if (mPendingInstalls.size() > 0) { |
| 484 | mPendingInstalls.remove(0); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 485 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 486 | if (mPendingInstalls.size() == 0) { |
| 487 | if (mBound) { |
| 488 | disconnectService(); |
| 489 | } |
| 490 | } else { |
| 491 | // There are more pending requests in queue. |
| 492 | // Just post MCS_BOUND message to trigger processing |
| 493 | // of next pending install. |
| 494 | mHandler.sendEmptyMessage(MCS_BOUND); |
| 495 | } |
| 496 | break; |
| 497 | } |
| 498 | case MCS_GIVE_UP: { |
| 499 | if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_giveup too many retries"); |
| 500 | HandlerParams params = mPendingInstalls.remove(0); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 501 | break; |
| 502 | } |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 503 | case SEND_PENDING_BROADCAST : { |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 504 | String packages[]; |
| 505 | ArrayList components[]; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 506 | int size = 0; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 507 | int uids[]; |
| 508 | synchronized (mPackages) { |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 509 | if (mPendingBroadcasts == null) { |
| 510 | return; |
| 511 | } |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 512 | size = mPendingBroadcasts.size(); |
| 513 | if (size <= 0) { |
| 514 | // Nothing to be done. Just return |
| 515 | return; |
| 516 | } |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 517 | packages = new String[size]; |
| 518 | components = new ArrayList[size]; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 519 | uids = new int[size]; |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 520 | Iterator<HashMap.Entry<String, ArrayList<String>>> |
| 521 | it = mPendingBroadcasts.entrySet().iterator(); |
| 522 | int i = 0; |
| 523 | while (it.hasNext() && i < size) { |
| 524 | HashMap.Entry<String, ArrayList<String>> ent = it.next(); |
| 525 | packages[i] = ent.getKey(); |
| 526 | components[i] = ent.getValue(); |
| 527 | PackageSetting ps = mSettings.mPackages.get(ent.getKey()); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 528 | uids[i] = (ps != null) ? ps.userId : -1; |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 529 | i++; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 530 | } |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 531 | size = i; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 532 | mPendingBroadcasts.clear(); |
| 533 | } |
| 534 | // Send broadcasts |
| 535 | for (int i = 0; i < size; i++) { |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 536 | sendPackageChangedBroadcast(packages[i], true, |
| 537 | (ArrayList<String>)components[i], uids[i]); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 538 | } |
| 539 | break; |
| 540 | } |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 541 | case START_CLEANING_PACKAGE: { |
| 542 | String packageName = (String)msg.obj; |
| 543 | synchronized (mPackages) { |
| 544 | if (!mSettings.mPackagesToBeCleaned.contains(packageName)) { |
| 545 | mSettings.mPackagesToBeCleaned.add(packageName); |
| 546 | } |
| 547 | } |
| 548 | startCleaningPackages(); |
| 549 | } break; |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 550 | case POST_INSTALL: { |
| 551 | if (DEBUG_INSTALL) Log.v(TAG, "Handling post-install for " + msg.arg1); |
| 552 | PostInstallData data = mRunningInstalls.get(msg.arg1); |
| 553 | mRunningInstalls.delete(msg.arg1); |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 554 | boolean deleteOld = false; |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 555 | |
| 556 | if (data != null) { |
| 557 | InstallArgs args = data.args; |
| 558 | PackageInstalledInfo res = data.res; |
| 559 | |
| 560 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) { |
| 561 | res.removedInfo.sendBroadcast(false, true); |
| 562 | Bundle extras = new Bundle(1); |
| 563 | extras.putInt(Intent.EXTRA_UID, res.uid); |
| 564 | final boolean update = res.removedInfo.removedPackage != null; |
| 565 | if (update) { |
| 566 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 567 | } |
| 568 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, |
| 569 | res.pkg.applicationInfo.packageName, |
| 570 | extras); |
| 571 | if (update) { |
| 572 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, |
| 573 | res.pkg.applicationInfo.packageName, |
| 574 | extras); |
| 575 | } |
| 576 | if (res.removedInfo.args != null) { |
| 577 | // Remove the replaced package's older resources safely now |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 578 | deleteOld = true; |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 579 | } |
| 580 | } |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 581 | // Force a gc to clear up things |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 582 | Runtime.getRuntime().gc(); |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 583 | // We delete after a gc for applications on sdcard. |
| 584 | if (deleteOld) { |
| 585 | synchronized (mInstallLock) { |
| 586 | res.removedInfo.args.doPostDeleteLI(true); |
| 587 | } |
| 588 | } |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 589 | if (args.observer != null) { |
| 590 | try { |
| 591 | args.observer.packageInstalled(res.name, res.returnCode); |
| 592 | } catch (RemoteException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 593 | Slog.i(TAG, "Observer no longer exists."); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 597 | Slog.e(TAG, "Bogus post-install token " + msg.arg1); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 598 | } |
| 599 | } break; |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 600 | case UPDATED_MEDIA_STATUS: { |
| 601 | try { |
| 602 | PackageHelper.getMountService().finishMediaUpdate(); |
| 603 | } catch (RemoteException e) { |
| 604 | Log.e(TAG, "MountService not running?"); |
| 605 | } |
| 606 | } break; |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 610 | |
| 611 | static boolean installOnSd(int flags) { |
| 612 | if (((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) || |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 613 | ((flags & PackageManager.INSTALL_INTERNAL) != 0)) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 614 | return false; |
| 615 | } |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 616 | if ((flags & PackageManager.INSTALL_EXTERNAL) != 0) { |
| 617 | return true; |
| 618 | } |
| 619 | return false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | static boolean isFwdLocked(int flags) { |
| 623 | if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { |
| 624 | return true; |
| 625 | } |
| 626 | return false; |
| 627 | } |
| 628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | public static final IPackageManager main(Context context, boolean factoryTest) { |
| 630 | PackageManagerService m = new PackageManagerService(context, factoryTest); |
| 631 | ServiceManager.addService("package", m); |
| 632 | return m; |
| 633 | } |
| 634 | |
| 635 | static String[] splitString(String str, char sep) { |
| 636 | int count = 1; |
| 637 | int i = 0; |
| 638 | while ((i=str.indexOf(sep, i)) >= 0) { |
| 639 | count++; |
| 640 | i++; |
| 641 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | String[] res = new String[count]; |
| 644 | i=0; |
| 645 | count = 0; |
| 646 | int lastI=0; |
| 647 | while ((i=str.indexOf(sep, i)) >= 0) { |
| 648 | res[count] = str.substring(lastI, i); |
| 649 | count++; |
| 650 | i++; |
| 651 | lastI = i; |
| 652 | } |
| 653 | res[count] = str.substring(lastI, str.length()); |
| 654 | return res; |
| 655 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | public PackageManagerService(Context context, boolean factoryTest) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 658 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_START, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | SystemClock.uptimeMillis()); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | if (mSdkVersion <= 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 662 | Slog.w(TAG, "**** ro.build.version.sdk not set!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | mContext = context; |
| 666 | mFactoryTest = factoryTest; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 667 | mNoDexOpt = "eng".equals(SystemProperties.get("ro.build.type")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | mMetrics = new DisplayMetrics(); |
| 669 | mSettings = new Settings(); |
| 670 | mSettings.addSharedUserLP("android.uid.system", |
| 671 | Process.SYSTEM_UID, ApplicationInfo.FLAG_SYSTEM); |
| 672 | mSettings.addSharedUserLP("android.uid.phone", |
| 673 | MULTIPLE_APPLICATION_UIDS |
| 674 | ? RADIO_UID : FIRST_APPLICATION_UID, |
| 675 | ApplicationInfo.FLAG_SYSTEM); |
Mike Lockwood | d42685d | 2009-09-03 09:25:22 -0400 | [diff] [blame] | 676 | mSettings.addSharedUserLP("android.uid.log", |
| 677 | MULTIPLE_APPLICATION_UIDS |
| 678 | ? LOG_UID : FIRST_APPLICATION_UID, |
| 679 | ApplicationInfo.FLAG_SYSTEM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 680 | |
| 681 | String separateProcesses = SystemProperties.get("debug.separate_processes"); |
| 682 | if (separateProcesses != null && separateProcesses.length() > 0) { |
| 683 | if ("*".equals(separateProcesses)) { |
| 684 | mDefParseFlags = PackageParser.PARSE_IGNORE_PROCESSES; |
| 685 | mSeparateProcesses = null; |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 686 | Slog.w(TAG, "Running with debug.separate_processes: * (ALL)"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | } else { |
| 688 | mDefParseFlags = 0; |
| 689 | mSeparateProcesses = separateProcesses.split(","); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 690 | Slog.w(TAG, "Running with debug.separate_processes: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | + separateProcesses); |
| 692 | } |
| 693 | } else { |
| 694 | mDefParseFlags = 0; |
| 695 | mSeparateProcesses = null; |
| 696 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | Installer installer = new Installer(); |
| 699 | // Little hacky thing to check if installd is here, to determine |
| 700 | // whether we are running on the simulator and thus need to take |
| 701 | // care of building the /data file structure ourself. |
| 702 | // (apparently the sim now has a working installer) |
| 703 | if (installer.ping() && Process.supportsProcesses()) { |
| 704 | mInstaller = installer; |
| 705 | } else { |
| 706 | mInstaller = null; |
| 707 | } |
| 708 | |
| 709 | WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 710 | Display d = wm.getDefaultDisplay(); |
| 711 | d.getMetrics(mMetrics); |
| 712 | |
| 713 | synchronized (mInstallLock) { |
| 714 | synchronized (mPackages) { |
| 715 | mHandlerThread.start(); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 716 | mHandler = new PackageHandler(mHandlerThread.getLooper()); |
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 | File dataDir = Environment.getDataDirectory(); |
| 719 | mAppDataDir = new File(dataDir, "data"); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 720 | mSecureAppDataDir = new File(dataDir, "secure/data"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | mDrmAppPrivateInstallDir = new File(dataDir, "app-private"); |
| 722 | |
| 723 | if (mInstaller == null) { |
| 724 | // Make sure these dirs exist, when we are running in |
| 725 | // the simulator. |
| 726 | // Make a wide-open directory for random misc stuff. |
| 727 | File miscDir = new File(dataDir, "misc"); |
| 728 | miscDir.mkdirs(); |
| 729 | mAppDataDir.mkdirs(); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 730 | mSecureAppDataDir.mkdirs(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | mDrmAppPrivateInstallDir.mkdirs(); |
| 732 | } |
| 733 | |
| 734 | readPermissions(); |
| 735 | |
| 736 | mRestoredSettings = mSettings.readLP(); |
| 737 | long startTime = SystemClock.uptimeMillis(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 738 | |
| 739 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SYSTEM_SCAN_START, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | startTime); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 741 | |
Suchi Amalapurapu | daec172 | 2010-01-14 21:25:16 -0800 | [diff] [blame] | 742 | // Set flag to monitor and not change apk file paths when |
| 743 | // scanning install directories. |
| 744 | int scanMode = SCAN_MONITOR | SCAN_NO_PATHS; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 745 | if (mNoDexOpt) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 746 | Slog.w(TAG, "Running ENG build: no pre-dexopt!"); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 747 | scanMode |= SCAN_NO_DEX; |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 748 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | final HashSet<String> libFiles = new HashSet<String>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 751 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | mFrameworkDir = new File(Environment.getRootDirectory(), "framework"); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 753 | mDalvikCacheDir = new File(dataDir, "dalvik-cache"); |
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 | if (mInstaller != null) { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 756 | boolean didDexOpt = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | /** |
| 759 | * Out of paranoia, ensure that everything in the boot class |
| 760 | * path has been dexed. |
| 761 | */ |
| 762 | String bootClassPath = System.getProperty("java.boot.class.path"); |
| 763 | if (bootClassPath != null) { |
| 764 | String[] paths = splitString(bootClassPath, ':'); |
| 765 | for (int i=0; i<paths.length; i++) { |
| 766 | try { |
| 767 | if (dalvik.system.DexFile.isDexOptNeeded(paths[i])) { |
| 768 | libFiles.add(paths[i]); |
| 769 | mInstaller.dexopt(paths[i], Process.SYSTEM_UID, true); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 770 | didDexOpt = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | } |
| 772 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 773 | 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] | 774 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 775 | 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] | 776 | } |
| 777 | } |
| 778 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 779 | Slog.w(TAG, "No BOOTCLASSPATH found!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | /** |
| 783 | * Also ensure all external libraries have had dexopt run on them. |
| 784 | */ |
| 785 | if (mSharedLibraries.size() > 0) { |
| 786 | Iterator<String> libs = mSharedLibraries.values().iterator(); |
| 787 | while (libs.hasNext()) { |
| 788 | String lib = libs.next(); |
| 789 | try { |
| 790 | if (dalvik.system.DexFile.isDexOptNeeded(lib)) { |
| 791 | libFiles.add(lib); |
| 792 | mInstaller.dexopt(lib, Process.SYSTEM_UID, true); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 793 | didDexOpt = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | } |
| 795 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 796 | Slog.w(TAG, "Library not found: " + lib); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 798 | Slog.w(TAG, "Exception reading library: " + lib, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | // Gross hack for now: we know this file doesn't contain any |
| 804 | // code, so don't dexopt it to avoid the resulting log spew. |
| 805 | libFiles.add(mFrameworkDir.getPath() + "/framework-res.apk"); |
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 | /** |
| 808 | * And there are a number of commands implemented in Java, which |
| 809 | * we currently need to do the dexopt on so that they can be |
| 810 | * run from a non-root shell. |
| 811 | */ |
| 812 | String[] frameworkFiles = mFrameworkDir.list(); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 813 | if (frameworkFiles != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | for (int i=0; i<frameworkFiles.length; i++) { |
| 815 | File libPath = new File(mFrameworkDir, frameworkFiles[i]); |
| 816 | String path = libPath.getPath(); |
| 817 | // Skip the file if we alrady did it. |
| 818 | if (libFiles.contains(path)) { |
| 819 | continue; |
| 820 | } |
| 821 | // Skip the file if it is not a type we want to dexopt. |
| 822 | if (!path.endsWith(".apk") && !path.endsWith(".jar")) { |
| 823 | continue; |
| 824 | } |
| 825 | try { |
| 826 | if (dalvik.system.DexFile.isDexOptNeeded(path)) { |
| 827 | mInstaller.dexopt(path, Process.SYSTEM_UID, true); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 828 | didDexOpt = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | } |
| 830 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 831 | Slog.w(TAG, "Jar not found: " + path); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 833 | Slog.w(TAG, "Exception reading jar: " + path, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | } |
| 835 | } |
| 836 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 837 | |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 838 | if (didDexOpt) { |
| 839 | // If we had to do a dexopt of one of the previous |
| 840 | // things, then something on the system has changed. |
| 841 | // Consider this significant, and wipe away all other |
| 842 | // existing dexopt files to ensure we don't leave any |
| 843 | // dangling around. |
| 844 | String[] files = mDalvikCacheDir.list(); |
| 845 | if (files != null) { |
| 846 | for (int i=0; i<files.length; i++) { |
| 847 | String fn = files[i]; |
| 848 | if (fn.startsWith("data@app@") |
| 849 | || fn.startsWith("data@app-private@")) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 850 | Slog.i(TAG, "Pruning dalvik file: " + fn); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 851 | (new File(mDalvikCacheDir, fn)).delete(); |
| 852 | } |
| 853 | } |
| 854 | } |
| 855 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 857 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 858 | // Find base frameworks (resource packages without code). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 859 | mFrameworkInstallObserver = new AppDirObserver( |
| 860 | mFrameworkDir.getPath(), OBSERVER_EVENTS, true); |
| 861 | mFrameworkInstallObserver.startWatching(); |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 862 | scanDirLI(mFrameworkDir, PackageParser.PARSE_IS_SYSTEM |
| 863 | | PackageParser.PARSE_IS_SYSTEM_DIR, |
Suchi Amalapurapu | daec172 | 2010-01-14 21:25:16 -0800 | [diff] [blame] | 864 | scanMode | SCAN_NO_DEX); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 865 | |
| 866 | // Collect all system packages. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | mSystemAppDir = new File(Environment.getRootDirectory(), "app"); |
| 868 | mSystemInstallObserver = new AppDirObserver( |
| 869 | mSystemAppDir.getPath(), OBSERVER_EVENTS, true); |
| 870 | mSystemInstallObserver.startWatching(); |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 871 | scanDirLI(mSystemAppDir, PackageParser.PARSE_IS_SYSTEM |
| 872 | | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 873 | |
| 874 | if (mInstaller != null) { |
| 875 | if (DEBUG_UPGRADE) Log.v(TAG, "Running installd update commands"); |
| 876 | mInstaller.moveFiles(); |
| 877 | } |
| 878 | |
| 879 | // Prune any system packages that no longer exist. |
| 880 | Iterator<PackageSetting> psit = mSettings.mPackages.values().iterator(); |
| 881 | while (psit.hasNext()) { |
| 882 | PackageSetting ps = psit.next(); |
| 883 | if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0 |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 884 | && !mPackages.containsKey(ps.name) |
| 885 | && !mSettings.mDisabledSysPackages.containsKey(ps.name)) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 886 | psit.remove(); |
| 887 | String msg = "System package " + ps.name |
| 888 | + " no longer exists; wiping its data"; |
| 889 | reportSettingsProblem(Log.WARN, msg); |
| 890 | if (mInstaller != null) { |
| 891 | // XXX how to set useEncryptedFSDir for packages that |
| 892 | // are not encrypted? |
| 893 | mInstaller.remove(ps.name, true); |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | mAppInstallDir = new File(dataDir, "app"); |
| 899 | if (mInstaller == null) { |
| 900 | // Make sure these dirs exist, when we are running in |
| 901 | // the simulator. |
| 902 | mAppInstallDir.mkdirs(); // scanDirLI() assumes this dir exists |
| 903 | } |
| 904 | //look for any incomplete package installations |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 905 | ArrayList<PackageSetting> deletePkgsList = mSettings.getListOfIncompleteInstallPackages(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | //clean up list |
| 907 | for(int i = 0; i < deletePkgsList.size(); i++) { |
| 908 | //clean up here |
| 909 | cleanupInstallFailedPackage(deletePkgsList.get(i)); |
| 910 | } |
| 911 | //delete tmp files |
| 912 | deleteTempPackageFiles(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 913 | |
| 914 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_DATA_SCAN_START, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | SystemClock.uptimeMillis()); |
| 916 | mAppInstallObserver = new AppDirObserver( |
| 917 | mAppInstallDir.getPath(), OBSERVER_EVENTS, false); |
| 918 | mAppInstallObserver.startWatching(); |
| 919 | scanDirLI(mAppInstallDir, 0, scanMode); |
| 920 | |
| 921 | mDrmAppInstallObserver = new AppDirObserver( |
| 922 | mDrmAppPrivateInstallDir.getPath(), OBSERVER_EVENTS, false); |
| 923 | mDrmAppInstallObserver.startWatching(); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 924 | scanDirLI(mDrmAppPrivateInstallDir, PackageParser.PARSE_FORWARD_LOCK, scanMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 926 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SCAN_END, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | SystemClock.uptimeMillis()); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 928 | Slog.i(TAG, "Time to scan packages: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | + ((SystemClock.uptimeMillis()-startTime)/1000f) |
| 930 | + " seconds"); |
| 931 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 932 | updatePermissionsLP(null, null, true, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | |
| 934 | mSettings.writeLP(); |
| 935 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 936 | EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_READY, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | SystemClock.uptimeMillis()); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | // Now after opening every single application zip, make sure they |
| 940 | // are all flushed. Not really needed, but keeps things nice and |
| 941 | // tidy. |
| 942 | Runtime.getRuntime().gc(); |
| 943 | } // synchronized (mPackages) |
| 944 | } // synchronized (mInstallLock) |
| 945 | } |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | @Override |
| 948 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 949 | throws RemoteException { |
| 950 | try { |
| 951 | return super.onTransact(code, data, reply, flags); |
| 952 | } catch (RuntimeException e) { |
| 953 | if (!(e instanceof SecurityException) && !(e instanceof IllegalArgumentException)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 954 | Slog.e(TAG, "Package Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | } |
| 956 | throw e; |
| 957 | } |
| 958 | } |
| 959 | |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 960 | void cleanupInstallFailedPackage(PackageSetting ps) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 961 | 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] | 962 | if (mInstaller != null) { |
Kenny Root | bdbc925 | 2010-01-28 12:03:49 -0800 | [diff] [blame] | 963 | boolean useSecureFS = useEncryptedFilesystemForPackage(ps.pkg); |
| 964 | int retCode = mInstaller.remove(ps.name, useSecureFS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 966 | Slog.w(TAG, "Couldn't remove app data directory for package: " |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 967 | + ps.name + ", retcode=" + retCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | } |
| 969 | } else { |
| 970 | //for emulator |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 971 | PackageParser.Package pkg = mPackages.get(ps.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | File dataDir = new File(pkg.applicationInfo.dataDir); |
| 973 | dataDir.delete(); |
| 974 | } |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 975 | if (ps.codePath != null) { |
| 976 | if (!ps.codePath.delete()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 977 | Slog.w(TAG, "Unable to remove old code file: " + ps.codePath); |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | if (ps.resourcePath != null) { |
| 981 | if (!ps.resourcePath.delete() && !ps.resourcePath.equals(ps.codePath)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 982 | Slog.w(TAG, "Unable to remove old code file: " + ps.resourcePath); |
Dianne Hackborn | e6620b2 | 2010-01-22 14:46:21 -0800 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | mSettings.removePackageLP(ps.name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | void readPermissions() { |
| 989 | // Read permissions from .../etc/permission directory. |
| 990 | File libraryDir = new File(Environment.getRootDirectory(), "etc/permissions"); |
| 991 | if (!libraryDir.exists() || !libraryDir.isDirectory()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 992 | Slog.w(TAG, "No directory " + libraryDir + ", skipping"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | return; |
| 994 | } |
| 995 | if (!libraryDir.canRead()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 996 | Slog.w(TAG, "Directory " + libraryDir + " cannot be read"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | return; |
| 998 | } |
| 999 | |
| 1000 | // Iterate over the files in the directory and scan .xml files |
| 1001 | for (File f : libraryDir.listFiles()) { |
| 1002 | // We'll read platform.xml last |
| 1003 | if (f.getPath().endsWith("etc/permissions/platform.xml")) { |
| 1004 | continue; |
| 1005 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1006 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | if (!f.getPath().endsWith(".xml")) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1008 | 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] | 1009 | continue; |
| 1010 | } |
| 1011 | if (!f.canRead()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1012 | 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] | 1013 | continue; |
| 1014 | } |
| 1015 | |
| 1016 | readPermissionsFromXml(f); |
| 1017 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1018 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | // Read permissions from .../etc/permissions/platform.xml last so it will take precedence |
| 1020 | final File permFile = new File(Environment.getRootDirectory(), |
| 1021 | "etc/permissions/platform.xml"); |
| 1022 | readPermissionsFromXml(permFile); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1023 | |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1024 | StringBuilder sb = new StringBuilder(128); |
| 1025 | sb.append("Libs:"); |
| 1026 | Iterator<String> it = mSharedLibraries.keySet().iterator(); |
| 1027 | while (it.hasNext()) { |
| 1028 | sb.append(' '); |
| 1029 | String name = it.next(); |
| 1030 | sb.append(name); |
| 1031 | sb.append(':'); |
| 1032 | sb.append(mSharedLibraries.get(name)); |
| 1033 | } |
| 1034 | Log.i(TAG, sb.toString()); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1035 | |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1036 | sb.setLength(0); |
| 1037 | sb.append("Features:"); |
| 1038 | it = mAvailableFeatures.keySet().iterator(); |
| 1039 | while (it.hasNext()) { |
| 1040 | sb.append(' '); |
| 1041 | sb.append(it.next()); |
| 1042 | } |
| 1043 | Log.i(TAG, sb.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1045 | |
| 1046 | private void readPermissionsFromXml(File permFile) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | FileReader permReader = null; |
| 1048 | try { |
| 1049 | permReader = new FileReader(permFile); |
| 1050 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1051 | 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] | 1052 | return; |
| 1053 | } |
| 1054 | |
| 1055 | try { |
| 1056 | XmlPullParser parser = Xml.newPullParser(); |
| 1057 | parser.setInput(permReader); |
| 1058 | |
| 1059 | XmlUtils.beginDocument(parser, "permissions"); |
| 1060 | |
| 1061 | while (true) { |
| 1062 | XmlUtils.nextElement(parser); |
| 1063 | if (parser.getEventType() == XmlPullParser.END_DOCUMENT) { |
| 1064 | break; |
| 1065 | } |
| 1066 | |
| 1067 | String name = parser.getName(); |
| 1068 | if ("group".equals(name)) { |
| 1069 | String gidStr = parser.getAttributeValue(null, "gid"); |
| 1070 | if (gidStr != null) { |
| 1071 | int gid = Integer.parseInt(gidStr); |
| 1072 | mGlobalGids = appendInt(mGlobalGids, gid); |
| 1073 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1074 | Slog.w(TAG, "<group> without gid at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | + parser.getPositionDescription()); |
| 1076 | } |
| 1077 | |
| 1078 | XmlUtils.skipCurrentTag(parser); |
| 1079 | continue; |
| 1080 | } else if ("permission".equals(name)) { |
| 1081 | String perm = parser.getAttributeValue(null, "name"); |
| 1082 | if (perm == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1083 | Slog.w(TAG, "<permission> without name at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | + parser.getPositionDescription()); |
| 1085 | XmlUtils.skipCurrentTag(parser); |
| 1086 | continue; |
| 1087 | } |
| 1088 | perm = perm.intern(); |
| 1089 | readPermission(parser, perm); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | } else if ("assign-permission".equals(name)) { |
| 1092 | String perm = parser.getAttributeValue(null, "name"); |
| 1093 | if (perm == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1094 | Slog.w(TAG, "<assign-permission> without name at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | + parser.getPositionDescription()); |
| 1096 | XmlUtils.skipCurrentTag(parser); |
| 1097 | continue; |
| 1098 | } |
| 1099 | String uidStr = parser.getAttributeValue(null, "uid"); |
| 1100 | if (uidStr == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1101 | Slog.w(TAG, "<assign-permission> without uid at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | + parser.getPositionDescription()); |
| 1103 | XmlUtils.skipCurrentTag(parser); |
| 1104 | continue; |
| 1105 | } |
| 1106 | int uid = Process.getUidForName(uidStr); |
| 1107 | if (uid < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1108 | Slog.w(TAG, "<assign-permission> with unknown uid \"" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1109 | + uidStr + "\" at " |
| 1110 | + parser.getPositionDescription()); |
| 1111 | XmlUtils.skipCurrentTag(parser); |
| 1112 | continue; |
| 1113 | } |
| 1114 | perm = perm.intern(); |
| 1115 | HashSet<String> perms = mSystemPermissions.get(uid); |
| 1116 | if (perms == null) { |
| 1117 | perms = new HashSet<String>(); |
| 1118 | mSystemPermissions.put(uid, perms); |
| 1119 | } |
| 1120 | perms.add(perm); |
| 1121 | XmlUtils.skipCurrentTag(parser); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | } else if ("library".equals(name)) { |
| 1124 | String lname = parser.getAttributeValue(null, "name"); |
| 1125 | String lfile = parser.getAttributeValue(null, "file"); |
| 1126 | if (lname == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1127 | Slog.w(TAG, "<library> without name at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | + parser.getPositionDescription()); |
| 1129 | } else if (lfile == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1130 | Slog.w(TAG, "<library> without file at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | + parser.getPositionDescription()); |
| 1132 | } else { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1133 | //Log.i(TAG, "Got library " + lname + " in " + lfile); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1134 | mSharedLibraries.put(lname, lfile); |
| 1135 | } |
| 1136 | XmlUtils.skipCurrentTag(parser); |
| 1137 | continue; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1138 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1139 | } else if ("feature".equals(name)) { |
| 1140 | String fname = parser.getAttributeValue(null, "name"); |
| 1141 | if (fname == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1142 | Slog.w(TAG, "<feature> without name at " |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1143 | + parser.getPositionDescription()); |
| 1144 | } else { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 1145 | //Log.i(TAG, "Got feature " + fname); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1146 | FeatureInfo fi = new FeatureInfo(); |
| 1147 | fi.name = fname; |
| 1148 | mAvailableFeatures.put(fname, fi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | } |
| 1150 | XmlUtils.skipCurrentTag(parser); |
| 1151 | continue; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | } else { |
| 1154 | XmlUtils.skipCurrentTag(parser); |
| 1155 | continue; |
| 1156 | } |
| 1157 | |
| 1158 | } |
| 1159 | } catch (XmlPullParserException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1160 | Slog.w(TAG, "Got execption parsing permissions.", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1162 | Slog.w(TAG, "Got execption parsing permissions.", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | void readPermission(XmlPullParser parser, String name) |
| 1167 | throws IOException, XmlPullParserException { |
| 1168 | |
| 1169 | name = name.intern(); |
| 1170 | |
| 1171 | BasePermission bp = mSettings.mPermissions.get(name); |
| 1172 | if (bp == null) { |
| 1173 | bp = new BasePermission(name, null, BasePermission.TYPE_BUILTIN); |
| 1174 | mSettings.mPermissions.put(name, bp); |
| 1175 | } |
| 1176 | int outerDepth = parser.getDepth(); |
| 1177 | int type; |
| 1178 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 1179 | && (type != XmlPullParser.END_TAG |
| 1180 | || parser.getDepth() > outerDepth)) { |
| 1181 | if (type == XmlPullParser.END_TAG |
| 1182 | || type == XmlPullParser.TEXT) { |
| 1183 | continue; |
| 1184 | } |
| 1185 | |
| 1186 | String tagName = parser.getName(); |
| 1187 | if ("group".equals(tagName)) { |
| 1188 | String gidStr = parser.getAttributeValue(null, "gid"); |
| 1189 | if (gidStr != null) { |
| 1190 | int gid = Process.getGidForName(gidStr); |
| 1191 | bp.gids = appendInt(bp.gids, gid); |
| 1192 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1193 | Slog.w(TAG, "<group> without gid at " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | + parser.getPositionDescription()); |
| 1195 | } |
| 1196 | } |
| 1197 | XmlUtils.skipCurrentTag(parser); |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | static int[] appendInt(int[] cur, int val) { |
| 1202 | if (cur == null) { |
| 1203 | return new int[] { val }; |
| 1204 | } |
| 1205 | final int N = cur.length; |
| 1206 | for (int i=0; i<N; i++) { |
| 1207 | if (cur[i] == val) { |
| 1208 | return cur; |
| 1209 | } |
| 1210 | } |
| 1211 | int[] ret = new int[N+1]; |
| 1212 | System.arraycopy(cur, 0, ret, 0, N); |
| 1213 | ret[N] = val; |
| 1214 | return ret; |
| 1215 | } |
| 1216 | |
| 1217 | static int[] appendInts(int[] cur, int[] add) { |
| 1218 | if (add == null) return cur; |
| 1219 | if (cur == null) return add; |
| 1220 | final int N = add.length; |
| 1221 | for (int i=0; i<N; i++) { |
| 1222 | cur = appendInt(cur, add[i]); |
| 1223 | } |
| 1224 | return cur; |
| 1225 | } |
| 1226 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1227 | static int[] removeInt(int[] cur, int val) { |
| 1228 | if (cur == null) { |
| 1229 | return null; |
| 1230 | } |
| 1231 | final int N = cur.length; |
| 1232 | for (int i=0; i<N; i++) { |
| 1233 | if (cur[i] == val) { |
| 1234 | int[] ret = new int[N-1]; |
| 1235 | if (i > 0) { |
| 1236 | System.arraycopy(cur, 0, ret, 0, i); |
| 1237 | } |
| 1238 | if (i < (N-1)) { |
| 1239 | System.arraycopy(cur, i, ret, i+1, N-i-1); |
| 1240 | } |
| 1241 | return ret; |
| 1242 | } |
| 1243 | } |
| 1244 | return cur; |
| 1245 | } |
| 1246 | |
| 1247 | static int[] removeInts(int[] cur, int[] rem) { |
| 1248 | if (rem == null) return cur; |
| 1249 | if (cur == null) return cur; |
| 1250 | final int N = rem.length; |
| 1251 | for (int i=0; i<N; i++) { |
| 1252 | cur = removeInt(cur, rem[i]); |
| 1253 | } |
| 1254 | return cur; |
| 1255 | } |
| 1256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | PackageInfo generatePackageInfo(PackageParser.Package p, int flags) { |
Suchi Amalapurapu | b897cff | 2009-10-14 12:11:48 -0700 | [diff] [blame] | 1258 | if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 1259 | // The package has been uninstalled but has retained data and resources. |
| 1260 | return PackageParser.generatePackageInfo(p, null, flags); |
| 1261 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1262 | final PackageSetting ps = (PackageSetting)p.mExtras; |
| 1263 | if (ps == null) { |
| 1264 | return null; |
| 1265 | } |
| 1266 | final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps; |
| 1267 | return PackageParser.generatePackageInfo(p, gp.gids, flags); |
| 1268 | } |
| 1269 | |
| 1270 | public PackageInfo getPackageInfo(String packageName, int flags) { |
| 1271 | synchronized (mPackages) { |
| 1272 | PackageParser.Package p = mPackages.get(packageName); |
| 1273 | if (Config.LOGV) Log.v( |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 1274 | TAG, "getPackageInfo " + packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | + ": " + p); |
| 1276 | if (p != null) { |
| 1277 | return generatePackageInfo(p, flags); |
| 1278 | } |
| 1279 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 1280 | return generatePackageInfoFromSettingsLP(packageName, flags); |
| 1281 | } |
| 1282 | } |
| 1283 | return null; |
| 1284 | } |
| 1285 | |
Dianne Hackborn | 4709693 | 2010-02-11 15:57:09 -0800 | [diff] [blame] | 1286 | public String[] currentToCanonicalPackageNames(String[] names) { |
| 1287 | String[] out = new String[names.length]; |
| 1288 | synchronized (mPackages) { |
| 1289 | for (int i=names.length-1; i>=0; i--) { |
| 1290 | PackageSetting ps = mSettings.mPackages.get(names[i]); |
| 1291 | out[i] = ps != null && ps.realName != null ? ps.realName : names[i]; |
| 1292 | } |
| 1293 | } |
| 1294 | return out; |
| 1295 | } |
| 1296 | |
| 1297 | public String[] canonicalToCurrentPackageNames(String[] names) { |
| 1298 | String[] out = new String[names.length]; |
| 1299 | synchronized (mPackages) { |
| 1300 | for (int i=names.length-1; i>=0; i--) { |
| 1301 | String cur = mSettings.mRenamedPackages.get(names[i]); |
| 1302 | out[i] = cur != null ? cur : names[i]; |
| 1303 | } |
| 1304 | } |
| 1305 | return out; |
| 1306 | } |
| 1307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1308 | public int getPackageUid(String packageName) { |
| 1309 | synchronized (mPackages) { |
| 1310 | PackageParser.Package p = mPackages.get(packageName); |
| 1311 | if(p != null) { |
| 1312 | return p.applicationInfo.uid; |
| 1313 | } |
| 1314 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 1315 | if((ps == null) || (ps.pkg == null) || (ps.pkg.applicationInfo == null)) { |
| 1316 | return -1; |
| 1317 | } |
| 1318 | p = ps.pkg; |
| 1319 | return p != null ? p.applicationInfo.uid : -1; |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | public int[] getPackageGids(String packageName) { |
| 1324 | synchronized (mPackages) { |
| 1325 | PackageParser.Package p = mPackages.get(packageName); |
| 1326 | if (Config.LOGV) Log.v( |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 1327 | TAG, "getPackageGids" + packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1328 | + ": " + p); |
| 1329 | if (p != null) { |
| 1330 | final PackageSetting ps = (PackageSetting)p.mExtras; |
| 1331 | final SharedUserSetting suid = ps.sharedUser; |
| 1332 | return suid != null ? suid.gids : ps.gids; |
| 1333 | } |
| 1334 | } |
| 1335 | // stupid thing to indicate an error. |
| 1336 | return new int[0]; |
| 1337 | } |
| 1338 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1339 | static final PermissionInfo generatePermissionInfo( |
| 1340 | BasePermission bp, int flags) { |
| 1341 | if (bp.perm != null) { |
| 1342 | return PackageParser.generatePermissionInfo(bp.perm, flags); |
| 1343 | } |
| 1344 | PermissionInfo pi = new PermissionInfo(); |
| 1345 | pi.name = bp.name; |
| 1346 | pi.packageName = bp.sourcePackage; |
| 1347 | pi.nonLocalizedLabel = bp.name; |
| 1348 | pi.protectionLevel = bp.protectionLevel; |
| 1349 | return pi; |
| 1350 | } |
| 1351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1352 | public PermissionInfo getPermissionInfo(String name, int flags) { |
| 1353 | synchronized (mPackages) { |
| 1354 | final BasePermission p = mSettings.mPermissions.get(name); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1355 | if (p != null) { |
| 1356 | return generatePermissionInfo(p, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1357 | } |
| 1358 | return null; |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) { |
| 1363 | synchronized (mPackages) { |
| 1364 | ArrayList<PermissionInfo> out = new ArrayList<PermissionInfo>(10); |
| 1365 | for (BasePermission p : mSettings.mPermissions.values()) { |
| 1366 | if (group == null) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1367 | if (p.perm == null || p.perm.info.group == null) { |
| 1368 | out.add(generatePermissionInfo(p, flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | } |
| 1370 | } else { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1371 | 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] | 1372 | out.add(PackageParser.generatePermissionInfo(p.perm, flags)); |
| 1373 | } |
| 1374 | } |
| 1375 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | if (out.size() > 0) { |
| 1378 | return out; |
| 1379 | } |
| 1380 | return mPermissionGroups.containsKey(group) ? out : null; |
| 1381 | } |
| 1382 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1383 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1384 | public PermissionGroupInfo getPermissionGroupInfo(String name, int flags) { |
| 1385 | synchronized (mPackages) { |
| 1386 | return PackageParser.generatePermissionGroupInfo( |
| 1387 | mPermissionGroups.get(name), flags); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | public List<PermissionGroupInfo> getAllPermissionGroups(int flags) { |
| 1392 | synchronized (mPackages) { |
| 1393 | final int N = mPermissionGroups.size(); |
| 1394 | ArrayList<PermissionGroupInfo> out |
| 1395 | = new ArrayList<PermissionGroupInfo>(N); |
| 1396 | for (PackageParser.PermissionGroup pg : mPermissionGroups.values()) { |
| 1397 | out.add(PackageParser.generatePermissionGroupInfo(pg, flags)); |
| 1398 | } |
| 1399 | return out; |
| 1400 | } |
| 1401 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1403 | private ApplicationInfo generateApplicationInfoFromSettingsLP(String packageName, int flags) { |
| 1404 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 1405 | if(ps != null) { |
| 1406 | if(ps.pkg == null) { |
| 1407 | PackageInfo pInfo = generatePackageInfoFromSettingsLP(packageName, flags); |
| 1408 | if(pInfo != null) { |
| 1409 | return pInfo.applicationInfo; |
| 1410 | } |
| 1411 | return null; |
| 1412 | } |
| 1413 | return PackageParser.generateApplicationInfo(ps.pkg, flags); |
| 1414 | } |
| 1415 | return null; |
| 1416 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1418 | private PackageInfo generatePackageInfoFromSettingsLP(String packageName, int flags) { |
| 1419 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 1420 | if(ps != null) { |
| 1421 | if(ps.pkg == null) { |
| 1422 | ps.pkg = new PackageParser.Package(packageName); |
| 1423 | ps.pkg.applicationInfo.packageName = packageName; |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 1424 | ps.pkg.applicationInfo.flags = ps.pkgFlags; |
| 1425 | ps.pkg.applicationInfo.publicSourceDir = ps.resourcePathString; |
| 1426 | ps.pkg.applicationInfo.sourceDir = ps.codePathString; |
| 1427 | ps.pkg.applicationInfo.dataDir = getDataPathForPackage(ps.pkg).getPath(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | } |
| 1429 | return generatePackageInfo(ps.pkg, flags); |
| 1430 | } |
| 1431 | return null; |
| 1432 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1434 | public ApplicationInfo getApplicationInfo(String packageName, int flags) { |
| 1435 | synchronized (mPackages) { |
| 1436 | PackageParser.Package p = mPackages.get(packageName); |
| 1437 | if (Config.LOGV) Log.v( |
| 1438 | TAG, "getApplicationInfo " + packageName |
| 1439 | + ": " + p); |
| 1440 | if (p != null) { |
| 1441 | // Note: isEnabledLP() does not apply here - always return info |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 1442 | return PackageParser.generateApplicationInfo(p, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1443 | } |
| 1444 | if ("android".equals(packageName)||"system".equals(packageName)) { |
| 1445 | return mAndroidApplication; |
| 1446 | } |
| 1447 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 1448 | return generateApplicationInfoFromSettingsLP(packageName, flags); |
| 1449 | } |
| 1450 | } |
| 1451 | return null; |
| 1452 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1453 | |
| 1454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | public void freeStorageAndNotify(final long freeStorageSize, final IPackageDataObserver observer) { |
| 1456 | mContext.enforceCallingOrSelfPermission( |
| 1457 | android.Manifest.permission.CLEAR_APP_CACHE, null); |
| 1458 | // Queue up an async operation since clearing cache may take a little while. |
| 1459 | mHandler.post(new Runnable() { |
| 1460 | public void run() { |
| 1461 | mHandler.removeCallbacks(this); |
| 1462 | int retCode = -1; |
| 1463 | if (mInstaller != null) { |
| 1464 | retCode = mInstaller.freeCache(freeStorageSize); |
| 1465 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1466 | Slog.w(TAG, "Couldn't clear application caches"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | } |
| 1468 | } //end if mInstaller |
| 1469 | if (observer != null) { |
| 1470 | try { |
| 1471 | observer.onRemoveCompleted(null, (retCode >= 0)); |
| 1472 | } catch (RemoteException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1473 | Slog.w(TAG, "RemoveException when invoking call back"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | }); |
| 1478 | } |
| 1479 | |
Suchi Amalapurapu | bc806f6 | 2009-06-17 15:18:19 -0700 | [diff] [blame] | 1480 | public void freeStorage(final long freeStorageSize, final IntentSender pi) { |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 1481 | mContext.enforceCallingOrSelfPermission( |
| 1482 | android.Manifest.permission.CLEAR_APP_CACHE, null); |
| 1483 | // Queue up an async operation since clearing cache may take a little while. |
| 1484 | mHandler.post(new Runnable() { |
| 1485 | public void run() { |
| 1486 | mHandler.removeCallbacks(this); |
| 1487 | int retCode = -1; |
| 1488 | if (mInstaller != null) { |
| 1489 | retCode = mInstaller.freeCache(freeStorageSize); |
| 1490 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1491 | Slog.w(TAG, "Couldn't clear application caches"); |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | if(pi != null) { |
| 1495 | try { |
| 1496 | // Callback via pending intent |
| 1497 | int code = (retCode >= 0) ? 1 : 0; |
| 1498 | pi.sendIntent(null, code, null, |
| 1499 | null, null); |
| 1500 | } catch (SendIntentException e1) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1501 | Slog.i(TAG, "Failed to send pending intent"); |
Suchi Amalapurapu | 1ccac75 | 2009-06-12 10:09:58 -0700 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | }); |
| 1506 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | public ActivityInfo getActivityInfo(ComponentName component, int flags) { |
| 1509 | synchronized (mPackages) { |
| 1510 | PackageParser.Activity a = mActivities.mActivities.get(component); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 1511 | |
| 1512 | if (Config.LOGV) Log.v(TAG, "getActivityInfo " + component + ": " + a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1513 | if (a != null && mSettings.isEnabledLP(a.info, flags)) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1514 | return PackageParser.generateActivityInfo(a, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | } |
| 1516 | if (mResolveComponentName.equals(component)) { |
| 1517 | return mResolveActivity; |
| 1518 | } |
| 1519 | } |
| 1520 | return null; |
| 1521 | } |
| 1522 | |
| 1523 | public ActivityInfo getReceiverInfo(ComponentName component, int flags) { |
| 1524 | synchronized (mPackages) { |
| 1525 | PackageParser.Activity a = mReceivers.mActivities.get(component); |
| 1526 | if (Config.LOGV) Log.v( |
| 1527 | TAG, "getReceiverInfo " + component + ": " + a); |
| 1528 | if (a != null && mSettings.isEnabledLP(a.info, flags)) { |
| 1529 | return PackageParser.generateActivityInfo(a, flags); |
| 1530 | } |
| 1531 | } |
| 1532 | return null; |
| 1533 | } |
| 1534 | |
| 1535 | public ServiceInfo getServiceInfo(ComponentName component, int flags) { |
| 1536 | synchronized (mPackages) { |
| 1537 | PackageParser.Service s = mServices.mServices.get(component); |
| 1538 | if (Config.LOGV) Log.v( |
| 1539 | TAG, "getServiceInfo " + component + ": " + s); |
| 1540 | if (s != null && mSettings.isEnabledLP(s.info, flags)) { |
| 1541 | return PackageParser.generateServiceInfo(s, flags); |
| 1542 | } |
| 1543 | } |
| 1544 | return null; |
| 1545 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | public String[] getSystemSharedLibraryNames() { |
| 1548 | Set<String> libSet; |
| 1549 | synchronized (mPackages) { |
| 1550 | libSet = mSharedLibraries.keySet(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1551 | int size = libSet.size(); |
| 1552 | if (size > 0) { |
| 1553 | String[] libs = new String[size]; |
| 1554 | libSet.toArray(libs); |
| 1555 | return libs; |
| 1556 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | } |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1558 | return null; |
| 1559 | } |
| 1560 | |
| 1561 | public FeatureInfo[] getSystemAvailableFeatures() { |
| 1562 | Collection<FeatureInfo> featSet; |
| 1563 | synchronized (mPackages) { |
| 1564 | featSet = mAvailableFeatures.values(); |
| 1565 | int size = featSet.size(); |
| 1566 | if (size > 0) { |
| 1567 | FeatureInfo[] features = new FeatureInfo[size+1]; |
| 1568 | featSet.toArray(features); |
| 1569 | FeatureInfo fi = new FeatureInfo(); |
| 1570 | fi.reqGlEsVersion = SystemProperties.getInt("ro.opengles.version", |
| 1571 | FeatureInfo.GL_ES_VERSION_UNDEFINED); |
| 1572 | features[size] = fi; |
| 1573 | return features; |
| 1574 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1575 | } |
| 1576 | return null; |
| 1577 | } |
| 1578 | |
Dianne Hackborn | 039c68e | 2009-09-26 16:39:23 -0700 | [diff] [blame] | 1579 | public boolean hasSystemFeature(String name) { |
| 1580 | synchronized (mPackages) { |
| 1581 | return mAvailableFeatures.containsKey(name); |
| 1582 | } |
| 1583 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | public int checkPermission(String permName, String pkgName) { |
| 1586 | synchronized (mPackages) { |
| 1587 | PackageParser.Package p = mPackages.get(pkgName); |
| 1588 | if (p != null && p.mExtras != null) { |
| 1589 | PackageSetting ps = (PackageSetting)p.mExtras; |
| 1590 | if (ps.sharedUser != null) { |
| 1591 | if (ps.sharedUser.grantedPermissions.contains(permName)) { |
| 1592 | return PackageManager.PERMISSION_GRANTED; |
| 1593 | } |
| 1594 | } else if (ps.grantedPermissions.contains(permName)) { |
| 1595 | return PackageManager.PERMISSION_GRANTED; |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | return PackageManager.PERMISSION_DENIED; |
| 1600 | } |
| 1601 | |
| 1602 | public int checkUidPermission(String permName, int uid) { |
| 1603 | synchronized (mPackages) { |
| 1604 | Object obj = mSettings.getUserIdLP(uid); |
| 1605 | if (obj != null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1606 | GrantedPermissions gp = (GrantedPermissions)obj; |
| 1607 | if (gp.grantedPermissions.contains(permName)) { |
| 1608 | return PackageManager.PERMISSION_GRANTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1609 | } |
| 1610 | } else { |
| 1611 | HashSet<String> perms = mSystemPermissions.get(uid); |
| 1612 | if (perms != null && perms.contains(permName)) { |
| 1613 | return PackageManager.PERMISSION_GRANTED; |
| 1614 | } |
| 1615 | } |
| 1616 | } |
| 1617 | return PackageManager.PERMISSION_DENIED; |
| 1618 | } |
| 1619 | |
| 1620 | private BasePermission findPermissionTreeLP(String permName) { |
| 1621 | for(BasePermission bp : mSettings.mPermissionTrees.values()) { |
| 1622 | if (permName.startsWith(bp.name) && |
| 1623 | permName.length() > bp.name.length() && |
| 1624 | permName.charAt(bp.name.length()) == '.') { |
| 1625 | return bp; |
| 1626 | } |
| 1627 | } |
| 1628 | return null; |
| 1629 | } |
| 1630 | |
| 1631 | private BasePermission checkPermissionTreeLP(String permName) { |
| 1632 | if (permName != null) { |
| 1633 | BasePermission bp = findPermissionTreeLP(permName); |
| 1634 | if (bp != null) { |
| 1635 | if (bp.uid == Binder.getCallingUid()) { |
| 1636 | return bp; |
| 1637 | } |
| 1638 | throw new SecurityException("Calling uid " |
| 1639 | + Binder.getCallingUid() |
| 1640 | + " is not allowed to add to permission tree " |
| 1641 | + bp.name + " owned by uid " + bp.uid); |
| 1642 | } |
| 1643 | } |
| 1644 | throw new SecurityException("No permission tree found for " + permName); |
| 1645 | } |
| 1646 | |
| 1647 | public boolean addPermission(PermissionInfo info) { |
| 1648 | synchronized (mPackages) { |
| 1649 | if (info.labelRes == 0 && info.nonLocalizedLabel == null) { |
| 1650 | throw new SecurityException("Label must be specified in permission"); |
| 1651 | } |
| 1652 | BasePermission tree = checkPermissionTreeLP(info.name); |
| 1653 | BasePermission bp = mSettings.mPermissions.get(info.name); |
| 1654 | boolean added = bp == null; |
| 1655 | if (added) { |
| 1656 | bp = new BasePermission(info.name, tree.sourcePackage, |
| 1657 | BasePermission.TYPE_DYNAMIC); |
| 1658 | } else if (bp.type != BasePermission.TYPE_DYNAMIC) { |
| 1659 | throw new SecurityException( |
| 1660 | "Not allowed to modify non-dynamic permission " |
| 1661 | + info.name); |
| 1662 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 1663 | bp.protectionLevel = info.protectionLevel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1664 | bp.perm = new PackageParser.Permission(tree.perm.owner, |
| 1665 | new PermissionInfo(info)); |
| 1666 | bp.perm.info.packageName = tree.perm.info.packageName; |
| 1667 | bp.uid = tree.uid; |
| 1668 | if (added) { |
| 1669 | mSettings.mPermissions.put(info.name, bp); |
| 1670 | } |
| 1671 | mSettings.writeLP(); |
| 1672 | return added; |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | public void removePermission(String name) { |
| 1677 | synchronized (mPackages) { |
| 1678 | checkPermissionTreeLP(name); |
| 1679 | BasePermission bp = mSettings.mPermissions.get(name); |
| 1680 | if (bp != null) { |
| 1681 | if (bp.type != BasePermission.TYPE_DYNAMIC) { |
| 1682 | throw new SecurityException( |
| 1683 | "Not allowed to modify non-dynamic permission " |
| 1684 | + name); |
| 1685 | } |
| 1686 | mSettings.mPermissions.remove(name); |
| 1687 | mSettings.writeLP(); |
| 1688 | } |
| 1689 | } |
| 1690 | } |
| 1691 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 1692 | public boolean isProtectedBroadcast(String actionName) { |
| 1693 | synchronized (mPackages) { |
| 1694 | return mProtectedBroadcasts.contains(actionName); |
| 1695 | } |
| 1696 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1698 | public int checkSignatures(String pkg1, String pkg2) { |
| 1699 | synchronized (mPackages) { |
| 1700 | PackageParser.Package p1 = mPackages.get(pkg1); |
| 1701 | PackageParser.Package p2 = mPackages.get(pkg2); |
| 1702 | if (p1 == null || p1.mExtras == null |
| 1703 | || p2 == null || p2.mExtras == null) { |
| 1704 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1705 | } |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1706 | return checkSignaturesLP(p1.mSignatures, p2.mSignatures); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1710 | public int checkUidSignatures(int uid1, int uid2) { |
| 1711 | synchronized (mPackages) { |
| 1712 | Signature[] s1; |
| 1713 | Signature[] s2; |
| 1714 | Object obj = mSettings.getUserIdLP(uid1); |
| 1715 | if (obj != null) { |
| 1716 | if (obj instanceof SharedUserSetting) { |
| 1717 | s1 = ((SharedUserSetting)obj).signatures.mSignatures; |
| 1718 | } else if (obj instanceof PackageSetting) { |
| 1719 | s1 = ((PackageSetting)obj).signatures.mSignatures; |
| 1720 | } else { |
| 1721 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1722 | } |
| 1723 | } else { |
| 1724 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1725 | } |
| 1726 | obj = mSettings.getUserIdLP(uid2); |
| 1727 | if (obj != null) { |
| 1728 | if (obj instanceof SharedUserSetting) { |
| 1729 | s2 = ((SharedUserSetting)obj).signatures.mSignatures; |
| 1730 | } else if (obj instanceof PackageSetting) { |
| 1731 | s2 = ((PackageSetting)obj).signatures.mSignatures; |
| 1732 | } else { |
| 1733 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1734 | } |
| 1735 | } else { |
| 1736 | return PackageManager.SIGNATURE_UNKNOWN_PACKAGE; |
| 1737 | } |
| 1738 | return checkSignaturesLP(s1, s2); |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | int checkSignaturesLP(Signature[] s1, Signature[] s2) { |
| 1743 | if (s1 == null) { |
| 1744 | return s2 == null |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1745 | ? PackageManager.SIGNATURE_NEITHER_SIGNED |
| 1746 | : PackageManager.SIGNATURE_FIRST_NOT_SIGNED; |
| 1747 | } |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1748 | if (s2 == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1749 | return PackageManager.SIGNATURE_SECOND_NOT_SIGNED; |
| 1750 | } |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1751 | final int N1 = s1.length; |
| 1752 | final int N2 = s2.length; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | for (int i=0; i<N1; i++) { |
| 1754 | boolean match = false; |
| 1755 | for (int j=0; j<N2; j++) { |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 1756 | if (s1[i].equals(s2[j])) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1757 | match = true; |
| 1758 | break; |
| 1759 | } |
| 1760 | } |
| 1761 | if (!match) { |
| 1762 | return PackageManager.SIGNATURE_NO_MATCH; |
| 1763 | } |
| 1764 | } |
| 1765 | return PackageManager.SIGNATURE_MATCH; |
| 1766 | } |
| 1767 | |
| 1768 | public String[] getPackagesForUid(int uid) { |
| 1769 | synchronized (mPackages) { |
| 1770 | Object obj = mSettings.getUserIdLP(uid); |
| 1771 | if (obj instanceof SharedUserSetting) { |
| 1772 | SharedUserSetting sus = (SharedUserSetting)obj; |
| 1773 | final int N = sus.packages.size(); |
| 1774 | String[] res = new String[N]; |
| 1775 | Iterator<PackageSetting> it = sus.packages.iterator(); |
| 1776 | int i=0; |
| 1777 | while (it.hasNext()) { |
| 1778 | res[i++] = it.next().name; |
| 1779 | } |
| 1780 | return res; |
| 1781 | } else if (obj instanceof PackageSetting) { |
| 1782 | PackageSetting ps = (PackageSetting)obj; |
| 1783 | return new String[] { ps.name }; |
| 1784 | } |
| 1785 | } |
| 1786 | return null; |
| 1787 | } |
| 1788 | |
| 1789 | public String getNameForUid(int uid) { |
| 1790 | synchronized (mPackages) { |
| 1791 | Object obj = mSettings.getUserIdLP(uid); |
| 1792 | if (obj instanceof SharedUserSetting) { |
| 1793 | SharedUserSetting sus = (SharedUserSetting)obj; |
| 1794 | return sus.name + ":" + sus.userId; |
| 1795 | } else if (obj instanceof PackageSetting) { |
| 1796 | PackageSetting ps = (PackageSetting)obj; |
| 1797 | return ps.name; |
| 1798 | } |
| 1799 | } |
| 1800 | return null; |
| 1801 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1803 | public int getUidForSharedUser(String sharedUserName) { |
| 1804 | if(sharedUserName == null) { |
| 1805 | return -1; |
| 1806 | } |
| 1807 | synchronized (mPackages) { |
| 1808 | SharedUserSetting suid = mSettings.getSharedUserLP(sharedUserName, 0, false); |
| 1809 | if(suid == null) { |
| 1810 | return -1; |
| 1811 | } |
| 1812 | return suid.userId; |
| 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | public ResolveInfo resolveIntent(Intent intent, String resolvedType, |
| 1817 | int flags) { |
| 1818 | List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags); |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 1819 | return chooseBestActivity(intent, resolvedType, flags, query); |
| 1820 | } |
| 1821 | |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 1822 | private ResolveInfo chooseBestActivity(Intent intent, String resolvedType, |
| 1823 | int flags, List<ResolveInfo> query) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1824 | if (query != null) { |
| 1825 | final int N = query.size(); |
| 1826 | if (N == 1) { |
| 1827 | return query.get(0); |
| 1828 | } else if (N > 1) { |
| 1829 | // If there is more than one activity with the same priority, |
| 1830 | // then let the user decide between them. |
| 1831 | ResolveInfo r0 = query.get(0); |
| 1832 | ResolveInfo r1 = query.get(1); |
| 1833 | if (false) { |
| 1834 | System.out.println(r0.activityInfo.name + |
| 1835 | "=" + r0.priority + " vs " + |
| 1836 | r1.activityInfo.name + |
| 1837 | "=" + r1.priority); |
| 1838 | } |
| 1839 | // If the first activity has a higher priority, or a different |
| 1840 | // default, then it is always desireable to pick it. |
| 1841 | if (r0.priority != r1.priority |
| 1842 | || r0.preferredOrder != r1.preferredOrder |
| 1843 | || r0.isDefault != r1.isDefault) { |
| 1844 | return query.get(0); |
| 1845 | } |
| 1846 | // If we have saved a preference for a preferred activity for |
| 1847 | // this Intent, use that. |
| 1848 | ResolveInfo ri = findPreferredActivity(intent, resolvedType, |
| 1849 | flags, query, r0.priority); |
| 1850 | if (ri != null) { |
| 1851 | return ri; |
| 1852 | } |
| 1853 | return mResolveInfo; |
| 1854 | } |
| 1855 | } |
| 1856 | return null; |
| 1857 | } |
| 1858 | |
| 1859 | ResolveInfo findPreferredActivity(Intent intent, String resolvedType, |
| 1860 | int flags, List<ResolveInfo> query, int priority) { |
| 1861 | synchronized (mPackages) { |
| 1862 | if (DEBUG_PREFERRED) intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION); |
| 1863 | List<PreferredActivity> prefs = |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 1864 | mSettings.mPreferredActivities.queryIntent(intent, resolvedType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1865 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 1866 | if (prefs != null && prefs.size() > 0) { |
| 1867 | // First figure out how good the original match set is. |
| 1868 | // We will only allow preferred activities that came |
| 1869 | // from the same match quality. |
| 1870 | int match = 0; |
| 1871 | final int N = query.size(); |
| 1872 | if (DEBUG_PREFERRED) Log.v(TAG, "Figuring out best match..."); |
| 1873 | for (int j=0; j<N; j++) { |
| 1874 | ResolveInfo ri = query.get(j); |
| 1875 | if (DEBUG_PREFERRED) Log.v(TAG, "Match for " + ri.activityInfo |
| 1876 | + ": 0x" + Integer.toHexString(match)); |
| 1877 | if (ri.match > match) match = ri.match; |
| 1878 | } |
| 1879 | if (DEBUG_PREFERRED) Log.v(TAG, "Best match: 0x" |
| 1880 | + Integer.toHexString(match)); |
| 1881 | match &= IntentFilter.MATCH_CATEGORY_MASK; |
| 1882 | final int M = prefs.size(); |
| 1883 | for (int i=0; i<M; i++) { |
| 1884 | PreferredActivity pa = prefs.get(i); |
| 1885 | if (pa.mMatch != match) { |
| 1886 | continue; |
| 1887 | } |
| 1888 | ActivityInfo ai = getActivityInfo(pa.mActivity, flags); |
| 1889 | if (DEBUG_PREFERRED) { |
| 1890 | Log.v(TAG, "Got preferred activity:"); |
| 1891 | ai.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 1892 | } |
| 1893 | if (ai != null) { |
| 1894 | for (int j=0; j<N; j++) { |
| 1895 | ResolveInfo ri = query.get(j); |
| 1896 | if (!ri.activityInfo.applicationInfo.packageName |
| 1897 | .equals(ai.applicationInfo.packageName)) { |
| 1898 | continue; |
| 1899 | } |
| 1900 | if (!ri.activityInfo.name.equals(ai.name)) { |
| 1901 | continue; |
| 1902 | } |
| 1903 | |
| 1904 | // Okay we found a previously set preferred app. |
| 1905 | // If the result set is different from when this |
| 1906 | // was created, we need to clear it and re-ask the |
| 1907 | // user their preference. |
| 1908 | if (!pa.sameSet(query, priority)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 1909 | 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] | 1910 | + intent + " type " + resolvedType); |
| 1911 | mSettings.mPreferredActivities.removeFilter(pa); |
| 1912 | return null; |
| 1913 | } |
| 1914 | |
| 1915 | // Yay! |
| 1916 | return ri; |
| 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | return null; |
| 1923 | } |
| 1924 | |
| 1925 | public List<ResolveInfo> queryIntentActivities(Intent intent, |
| 1926 | String resolvedType, int flags) { |
| 1927 | ComponentName comp = intent.getComponent(); |
| 1928 | if (comp != null) { |
| 1929 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 1930 | ActivityInfo ai = getActivityInfo(comp, flags); |
| 1931 | if (ai != null) { |
| 1932 | ResolveInfo ri = new ResolveInfo(); |
| 1933 | ri.activityInfo = ai; |
| 1934 | list.add(ri); |
| 1935 | } |
| 1936 | return list; |
| 1937 | } |
| 1938 | |
| 1939 | synchronized (mPackages) { |
Dianne Hackborn | c14b9cc | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 1940 | String pkgName = intent.getPackage(); |
| 1941 | if (pkgName == null) { |
| 1942 | return (List<ResolveInfo>)mActivities.queryIntent(intent, |
| 1943 | resolvedType, flags); |
| 1944 | } |
| 1945 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 1946 | if (pkg != null) { |
| 1947 | return (List<ResolveInfo>) mActivities.queryIntentForPackage(intent, |
| 1948 | resolvedType, flags, pkg.activities); |
| 1949 | } |
| 1950 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, |
| 1955 | Intent[] specifics, String[] specificTypes, Intent intent, |
| 1956 | String resolvedType, int flags) { |
| 1957 | final String resultsAction = intent.getAction(); |
| 1958 | |
| 1959 | List<ResolveInfo> results = queryIntentActivities( |
| 1960 | intent, resolvedType, flags|PackageManager.GET_RESOLVED_FILTER); |
| 1961 | if (Config.LOGV) Log.v(TAG, "Query " + intent + ": " + results); |
| 1962 | |
| 1963 | int specificsPos = 0; |
| 1964 | int N; |
| 1965 | |
| 1966 | // todo: note that the algorithm used here is O(N^2). This |
| 1967 | // isn't a problem in our current environment, but if we start running |
| 1968 | // into situations where we have more than 5 or 10 matches then this |
| 1969 | // should probably be changed to something smarter... |
| 1970 | |
| 1971 | // First we go through and resolve each of the specific items |
| 1972 | // that were supplied, taking care of removing any corresponding |
| 1973 | // duplicate items in the generic resolve list. |
| 1974 | if (specifics != null) { |
| 1975 | for (int i=0; i<specifics.length; i++) { |
| 1976 | final Intent sintent = specifics[i]; |
| 1977 | if (sintent == null) { |
| 1978 | continue; |
| 1979 | } |
| 1980 | |
| 1981 | if (Config.LOGV) Log.v(TAG, "Specific #" + i + ": " + sintent); |
| 1982 | String action = sintent.getAction(); |
| 1983 | if (resultsAction != null && resultsAction.equals(action)) { |
| 1984 | // If this action was explicitly requested, then don't |
| 1985 | // remove things that have it. |
| 1986 | action = null; |
| 1987 | } |
| 1988 | ComponentName comp = sintent.getComponent(); |
| 1989 | ResolveInfo ri = null; |
| 1990 | ActivityInfo ai = null; |
| 1991 | if (comp == null) { |
| 1992 | ri = resolveIntent( |
| 1993 | sintent, |
| 1994 | specificTypes != null ? specificTypes[i] : null, |
| 1995 | flags); |
| 1996 | if (ri == null) { |
| 1997 | continue; |
| 1998 | } |
| 1999 | if (ri == mResolveInfo) { |
| 2000 | // ACK! Must do something better with this. |
| 2001 | } |
| 2002 | ai = ri.activityInfo; |
| 2003 | comp = new ComponentName(ai.applicationInfo.packageName, |
| 2004 | ai.name); |
| 2005 | } else { |
| 2006 | ai = getActivityInfo(comp, flags); |
| 2007 | if (ai == null) { |
| 2008 | continue; |
| 2009 | } |
| 2010 | } |
| 2011 | |
| 2012 | // Look for any generic query activities that are duplicates |
| 2013 | // of this specific one, and remove them from the results. |
| 2014 | if (Config.LOGV) Log.v(TAG, "Specific #" + i + ": " + ai); |
| 2015 | N = results.size(); |
| 2016 | int j; |
| 2017 | for (j=specificsPos; j<N; j++) { |
| 2018 | ResolveInfo sri = results.get(j); |
| 2019 | if ((sri.activityInfo.name.equals(comp.getClassName()) |
| 2020 | && sri.activityInfo.applicationInfo.packageName.equals( |
| 2021 | comp.getPackageName())) |
| 2022 | || (action != null && sri.filter.matchAction(action))) { |
| 2023 | results.remove(j); |
| 2024 | if (Config.LOGV) Log.v( |
| 2025 | TAG, "Removing duplicate item from " + j |
| 2026 | + " due to specific " + specificsPos); |
| 2027 | if (ri == null) { |
| 2028 | ri = sri; |
| 2029 | } |
| 2030 | j--; |
| 2031 | N--; |
| 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | // Add this specific item to its proper place. |
| 2036 | if (ri == null) { |
| 2037 | ri = new ResolveInfo(); |
| 2038 | ri.activityInfo = ai; |
| 2039 | } |
| 2040 | results.add(specificsPos, ri); |
| 2041 | ri.specificIndex = i; |
| 2042 | specificsPos++; |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | // Now we go through the remaining generic results and remove any |
| 2047 | // duplicate actions that are found here. |
| 2048 | N = results.size(); |
| 2049 | for (int i=specificsPos; i<N-1; i++) { |
| 2050 | final ResolveInfo rii = results.get(i); |
| 2051 | if (rii.filter == null) { |
| 2052 | continue; |
| 2053 | } |
| 2054 | |
| 2055 | // Iterate over all of the actions of this result's intent |
| 2056 | // filter... typically this should be just one. |
| 2057 | final Iterator<String> it = rii.filter.actionsIterator(); |
| 2058 | if (it == null) { |
| 2059 | continue; |
| 2060 | } |
| 2061 | while (it.hasNext()) { |
| 2062 | final String action = it.next(); |
| 2063 | if (resultsAction != null && resultsAction.equals(action)) { |
| 2064 | // If this action was explicitly requested, then don't |
| 2065 | // remove things that have it. |
| 2066 | continue; |
| 2067 | } |
| 2068 | for (int j=i+1; j<N; j++) { |
| 2069 | final ResolveInfo rij = results.get(j); |
| 2070 | if (rij.filter != null && rij.filter.hasAction(action)) { |
| 2071 | results.remove(j); |
| 2072 | if (Config.LOGV) Log.v( |
| 2073 | TAG, "Removing duplicate item from " + j |
| 2074 | + " due to action " + action + " at " + i); |
| 2075 | j--; |
| 2076 | N--; |
| 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | // If the caller didn't request filter information, drop it now |
| 2082 | // so we don't have to marshall/unmarshall it. |
| 2083 | if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) { |
| 2084 | rii.filter = null; |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | // Filter out the caller activity if so requested. |
| 2089 | if (caller != null) { |
| 2090 | N = results.size(); |
| 2091 | for (int i=0; i<N; i++) { |
| 2092 | ActivityInfo ainfo = results.get(i).activityInfo; |
| 2093 | if (caller.getPackageName().equals(ainfo.applicationInfo.packageName) |
| 2094 | && caller.getClassName().equals(ainfo.name)) { |
| 2095 | results.remove(i); |
| 2096 | break; |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | // If the caller didn't request filter information, |
| 2102 | // drop them now so we don't have to |
| 2103 | // marshall/unmarshall it. |
| 2104 | if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) { |
| 2105 | N = results.size(); |
| 2106 | for (int i=0; i<N; i++) { |
| 2107 | results.get(i).filter = null; |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | if (Config.LOGV) Log.v(TAG, "Result: " + results); |
| 2112 | return results; |
| 2113 | } |
| 2114 | |
| 2115 | public List<ResolveInfo> queryIntentReceivers(Intent intent, |
| 2116 | String resolvedType, int flags) { |
Dianne Hackborn | c14b9cc | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2117 | ComponentName comp = intent.getComponent(); |
| 2118 | if (comp != null) { |
| 2119 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2120 | ActivityInfo ai = getReceiverInfo(comp, flags); |
| 2121 | if (ai != null) { |
| 2122 | ResolveInfo ri = new ResolveInfo(); |
| 2123 | ri.activityInfo = ai; |
| 2124 | list.add(ri); |
| 2125 | } |
| 2126 | return list; |
| 2127 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2129 | synchronized (mPackages) { |
Dianne Hackborn | c14b9cc | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2130 | String pkgName = intent.getPackage(); |
| 2131 | if (pkgName == null) { |
| 2132 | return (List<ResolveInfo>)mReceivers.queryIntent(intent, |
| 2133 | resolvedType, flags); |
| 2134 | } |
| 2135 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2136 | if (pkg != null) { |
| 2137 | return (List<ResolveInfo>) mReceivers.queryIntentForPackage(intent, |
| 2138 | resolvedType, flags, pkg.receivers); |
| 2139 | } |
| 2140 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | public ResolveInfo resolveService(Intent intent, String resolvedType, |
| 2145 | int flags) { |
| 2146 | List<ResolveInfo> query = queryIntentServices(intent, resolvedType, |
| 2147 | flags); |
| 2148 | if (query != null) { |
| 2149 | if (query.size() >= 1) { |
| 2150 | // If there is more than one service with the same priority, |
| 2151 | // just arbitrarily pick the first one. |
| 2152 | return query.get(0); |
| 2153 | } |
| 2154 | } |
| 2155 | return null; |
| 2156 | } |
| 2157 | |
| 2158 | public List<ResolveInfo> queryIntentServices(Intent intent, |
| 2159 | String resolvedType, int flags) { |
| 2160 | ComponentName comp = intent.getComponent(); |
| 2161 | if (comp != null) { |
| 2162 | List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); |
| 2163 | ServiceInfo si = getServiceInfo(comp, flags); |
| 2164 | if (si != null) { |
| 2165 | ResolveInfo ri = new ResolveInfo(); |
| 2166 | ri.serviceInfo = si; |
| 2167 | list.add(ri); |
| 2168 | } |
| 2169 | return list; |
| 2170 | } |
| 2171 | |
| 2172 | synchronized (mPackages) { |
Dianne Hackborn | c14b9cc | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 2173 | String pkgName = intent.getPackage(); |
| 2174 | if (pkgName == null) { |
| 2175 | return (List<ResolveInfo>)mServices.queryIntent(intent, |
| 2176 | resolvedType, flags); |
| 2177 | } |
| 2178 | PackageParser.Package pkg = mPackages.get(pkgName); |
| 2179 | if (pkg != null) { |
| 2180 | return (List<ResolveInfo>)mServices.queryIntentForPackage(intent, |
| 2181 | resolvedType, flags, pkg.services); |
| 2182 | } |
| 2183 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2184 | } |
| 2185 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2187 | public List<PackageInfo> getInstalledPackages(int flags) { |
| 2188 | ArrayList<PackageInfo> finalList = new ArrayList<PackageInfo>(); |
| 2189 | |
| 2190 | synchronized (mPackages) { |
| 2191 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 2192 | Iterator<PackageSetting> i = mSettings.mPackages.values().iterator(); |
| 2193 | while (i.hasNext()) { |
| 2194 | final PackageSetting ps = i.next(); |
| 2195 | PackageInfo psPkg = generatePackageInfoFromSettingsLP(ps.name, flags); |
| 2196 | if(psPkg != null) { |
| 2197 | finalList.add(psPkg); |
| 2198 | } |
| 2199 | } |
| 2200 | } |
| 2201 | else { |
| 2202 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2203 | while (i.hasNext()) { |
| 2204 | final PackageParser.Package p = i.next(); |
| 2205 | if (p.applicationInfo != null) { |
| 2206 | PackageInfo pi = generatePackageInfo(p, flags); |
| 2207 | if(pi != null) { |
| 2208 | finalList.add(pi); |
| 2209 | } |
| 2210 | } |
| 2211 | } |
| 2212 | } |
| 2213 | } |
| 2214 | return finalList; |
| 2215 | } |
| 2216 | |
| 2217 | public List<ApplicationInfo> getInstalledApplications(int flags) { |
| 2218 | ArrayList<ApplicationInfo> finalList = new ArrayList<ApplicationInfo>(); |
| 2219 | synchronized(mPackages) { |
| 2220 | if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) { |
| 2221 | Iterator<PackageSetting> i = mSettings.mPackages.values().iterator(); |
| 2222 | while (i.hasNext()) { |
| 2223 | final PackageSetting ps = i.next(); |
| 2224 | ApplicationInfo ai = generateApplicationInfoFromSettingsLP(ps.name, flags); |
| 2225 | if(ai != null) { |
| 2226 | finalList.add(ai); |
| 2227 | } |
| 2228 | } |
| 2229 | } |
| 2230 | else { |
| 2231 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2232 | while (i.hasNext()) { |
| 2233 | final PackageParser.Package p = i.next(); |
| 2234 | if (p.applicationInfo != null) { |
| 2235 | ApplicationInfo ai = PackageParser.generateApplicationInfo(p, flags); |
| 2236 | if(ai != null) { |
| 2237 | finalList.add(ai); |
| 2238 | } |
| 2239 | } |
| 2240 | } |
| 2241 | } |
| 2242 | } |
| 2243 | return finalList; |
| 2244 | } |
| 2245 | |
| 2246 | public List<ApplicationInfo> getPersistentApplications(int flags) { |
| 2247 | ArrayList<ApplicationInfo> finalList = new ArrayList<ApplicationInfo>(); |
| 2248 | |
| 2249 | synchronized (mPackages) { |
| 2250 | Iterator<PackageParser.Package> i = mPackages.values().iterator(); |
| 2251 | while (i.hasNext()) { |
| 2252 | PackageParser.Package p = i.next(); |
| 2253 | if (p.applicationInfo != null |
| 2254 | && (p.applicationInfo.flags&ApplicationInfo.FLAG_PERSISTENT) != 0 |
| 2255 | && (!mSafeMode || (p.applicationInfo.flags |
| 2256 | &ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| 2257 | finalList.add(p.applicationInfo); |
| 2258 | } |
| 2259 | } |
| 2260 | } |
| 2261 | |
| 2262 | return finalList; |
| 2263 | } |
| 2264 | |
| 2265 | public ProviderInfo resolveContentProvider(String name, int flags) { |
| 2266 | synchronized (mPackages) { |
| 2267 | final PackageParser.Provider provider = mProviders.get(name); |
| 2268 | return provider != null |
| 2269 | && mSettings.isEnabledLP(provider.info, flags) |
| 2270 | && (!mSafeMode || (provider.info.applicationInfo.flags |
| 2271 | &ApplicationInfo.FLAG_SYSTEM) != 0) |
| 2272 | ? PackageParser.generateProviderInfo(provider, flags) |
| 2273 | : null; |
| 2274 | } |
| 2275 | } |
| 2276 | |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2277 | /** |
| 2278 | * @deprecated |
| 2279 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | public void querySyncProviders(List outNames, List outInfo) { |
| 2281 | synchronized (mPackages) { |
| 2282 | Iterator<Map.Entry<String, PackageParser.Provider>> i |
| 2283 | = mProviders.entrySet().iterator(); |
| 2284 | |
| 2285 | while (i.hasNext()) { |
| 2286 | Map.Entry<String, PackageParser.Provider> entry = i.next(); |
| 2287 | PackageParser.Provider p = entry.getValue(); |
| 2288 | |
| 2289 | if (p.syncable |
| 2290 | && (!mSafeMode || (p.info.applicationInfo.flags |
| 2291 | &ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| 2292 | outNames.add(entry.getKey()); |
| 2293 | outInfo.add(PackageParser.generateProviderInfo(p, 0)); |
| 2294 | } |
| 2295 | } |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | public List<ProviderInfo> queryContentProviders(String processName, |
| 2300 | int uid, int flags) { |
| 2301 | ArrayList<ProviderInfo> finalList = null; |
| 2302 | |
| 2303 | synchronized (mPackages) { |
| 2304 | Iterator<PackageParser.Provider> i = mProvidersByComponent.values().iterator(); |
| 2305 | while (i.hasNext()) { |
| 2306 | PackageParser.Provider p = i.next(); |
| 2307 | if (p.info.authority != null |
| 2308 | && (processName == null || |
| 2309 | (p.info.processName.equals(processName) |
| 2310 | && p.info.applicationInfo.uid == uid)) |
| 2311 | && mSettings.isEnabledLP(p.info, flags) |
| 2312 | && (!mSafeMode || (p.info.applicationInfo.flags |
| 2313 | &ApplicationInfo.FLAG_SYSTEM) != 0)) { |
| 2314 | if (finalList == null) { |
| 2315 | finalList = new ArrayList<ProviderInfo>(3); |
| 2316 | } |
| 2317 | finalList.add(PackageParser.generateProviderInfo(p, |
| 2318 | flags)); |
| 2319 | } |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | if (finalList != null) { |
| 2324 | Collections.sort(finalList, mProviderInitOrderSorter); |
| 2325 | } |
| 2326 | |
| 2327 | return finalList; |
| 2328 | } |
| 2329 | |
| 2330 | public InstrumentationInfo getInstrumentationInfo(ComponentName name, |
| 2331 | int flags) { |
| 2332 | synchronized (mPackages) { |
| 2333 | final PackageParser.Instrumentation i = mInstrumentation.get(name); |
| 2334 | return PackageParser.generateInstrumentationInfo(i, flags); |
| 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | public List<InstrumentationInfo> queryInstrumentation(String targetPackage, |
| 2339 | int flags) { |
| 2340 | ArrayList<InstrumentationInfo> finalList = |
| 2341 | new ArrayList<InstrumentationInfo>(); |
| 2342 | |
| 2343 | synchronized (mPackages) { |
| 2344 | Iterator<PackageParser.Instrumentation> i = mInstrumentation.values().iterator(); |
| 2345 | while (i.hasNext()) { |
| 2346 | PackageParser.Instrumentation p = i.next(); |
| 2347 | if (targetPackage == null |
| 2348 | || targetPackage.equals(p.info.targetPackage)) { |
| 2349 | finalList.add(PackageParser.generateInstrumentationInfo(p, |
| 2350 | flags)); |
| 2351 | } |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | return finalList; |
| 2356 | } |
| 2357 | |
| 2358 | private void scanDirLI(File dir, int flags, int scanMode) { |
| 2359 | Log.d(TAG, "Scanning app dir " + dir); |
| 2360 | |
| 2361 | String[] files = dir.list(); |
| 2362 | |
| 2363 | int i; |
| 2364 | for (i=0; i<files.length; i++) { |
| 2365 | File file = new File(dir, files[i]); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 2366 | if (!isPackageFilename(files[i])) { |
| 2367 | // Ignore entries which are not apk's |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 2368 | continue; |
| 2369 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2370 | PackageParser.Package pkg = scanPackageLI(file, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | flags|PackageParser.PARSE_MUST_BE_APK, scanMode); |
Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2372 | // Don't mess around with apps in system partition. |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 2373 | if (pkg == null && (flags & PackageParser.PARSE_IS_SYSTEM) == 0 && |
| 2374 | mLastScanError == PackageManager.INSTALL_FAILED_INVALID_APK) { |
Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2375 | // Delete the apk |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2376 | Slog.w(TAG, "Cleaning up failed install of " + file); |
Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2377 | file.delete(); |
| 2378 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2379 | } |
| 2380 | } |
| 2381 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2382 | private static File getSettingsProblemFile() { |
| 2383 | File dataDir = Environment.getDataDirectory(); |
| 2384 | File systemDir = new File(dataDir, "system"); |
| 2385 | File fname = new File(systemDir, "uiderrors.txt"); |
| 2386 | return fname; |
| 2387 | } |
| 2388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2389 | private static void reportSettingsProblem(int priority, String msg) { |
| 2390 | try { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2391 | File fname = getSettingsProblemFile(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2392 | FileOutputStream out = new FileOutputStream(fname, true); |
| 2393 | PrintWriter pw = new PrintWriter(out); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2394 | SimpleDateFormat formatter = new SimpleDateFormat(); |
| 2395 | String dateString = formatter.format(new Date(System.currentTimeMillis())); |
| 2396 | pw.println(dateString + ": " + msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | pw.close(); |
| 2398 | FileUtils.setPermissions( |
| 2399 | fname.toString(), |
| 2400 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IROTH, |
| 2401 | -1, -1); |
| 2402 | } catch (java.io.IOException e) { |
| 2403 | } |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2404 | Slog.println(priority, TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | private boolean collectCertificatesLI(PackageParser pp, PackageSetting ps, |
| 2408 | PackageParser.Package pkg, File srcFile, int parseFlags) { |
| 2409 | if (GET_CERTIFICATES) { |
| 2410 | if (ps == null || !ps.codePath.equals(srcFile) |
| 2411 | || ps.getTimeStamp() != srcFile.lastModified()) { |
| 2412 | Log.i(TAG, srcFile.toString() + " changed; collecting certs"); |
| 2413 | if (!pp.collectCertificates(pkg, parseFlags)) { |
| 2414 | mLastScanError = pp.getParseError(); |
| 2415 | return false; |
| 2416 | } |
| 2417 | } |
| 2418 | } |
| 2419 | return true; |
| 2420 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2422 | /* |
| 2423 | * Scan a package and return the newly parsed package. |
| 2424 | * Returns null in case of errors and the error code is stored in mLastScanError |
| 2425 | */ |
| 2426 | private PackageParser.Package scanPackageLI(File scanFile, |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2427 | int parseFlags, int scanMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2428 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2429 | String scanPath = scanFile.getPath(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2430 | parseFlags |= mDefParseFlags; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2431 | PackageParser pp = new PackageParser(scanPath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | pp.setSeparateProcesses(mSeparateProcesses); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | final PackageParser.Package pkg = pp.parsePackage(scanFile, |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2434 | scanPath, mMetrics, parseFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2435 | if (pkg == null) { |
| 2436 | mLastScanError = pp.getParseError(); |
| 2437 | return null; |
| 2438 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2439 | PackageSetting ps = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | PackageSetting updatedPkg; |
| 2441 | synchronized (mPackages) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2442 | // Look to see if we already know about this package. |
| 2443 | String oldName = mSettings.mRenamedPackages.get(pkg.packageName); |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2444 | if (pkg.mOriginalPackages != null && pkg.mOriginalPackages.contains(oldName)) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2445 | // This package has been renamed to its original name. Let's |
| 2446 | // use that. |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2447 | ps = mSettings.peekPackageLP(oldName); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2448 | } |
| 2449 | // If there was no original package, see one for the real package name. |
| 2450 | if (ps == null) { |
| 2451 | ps = mSettings.peekPackageLP(pkg.packageName); |
| 2452 | } |
| 2453 | // Check to see if this package could be hiding/updating a system |
| 2454 | // package. Must look for it either under the original or real |
| 2455 | // package name depending on our state. |
| 2456 | updatedPkg = mSettings.mDisabledSysPackages.get( |
| 2457 | ps != null ? ps.name : pkg.packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2458 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2459 | // First check if this is a system package that may involve an update |
| 2460 | if (updatedPkg != null && (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| 2461 | if (!ps.codePath.equals(scanFile)) { |
| 2462 | // The path has changed from what was last scanned... check the |
| 2463 | // version of the new path against what we have stored to determine |
| 2464 | // what to do. |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2465 | if (pkg.mVersionCode < ps.versionCode) { |
| 2466 | // 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] | 2467 | // Ignore entry. Skip it. |
| 2468 | Log.i(TAG, "Package " + ps.name + " at " + scanFile |
| 2469 | + "ignored: updated version " + ps.versionCode |
| 2470 | + " better than this " + pkg.mVersionCode); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2471 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2472 | return null; |
| 2473 | } else { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2474 | // The current app on the system partion is better than |
| 2475 | // what we have updated to on the data partition; switch |
| 2476 | // back to the system partition version. |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2477 | // At this point, its safely assumed that package installation for |
| 2478 | // apps in system partition will go through. If not there won't be a working |
| 2479 | // version of the app |
| 2480 | synchronized (mPackages) { |
| 2481 | // Just remove the loaded entries from package lists. |
| 2482 | mPackages.remove(ps.name); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 2483 | } |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2484 | Slog.w(TAG, "Package " + ps.name + " at " + scanFile |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2485 | + "reverting from " + ps.codePathString |
| 2486 | + ": new version " + pkg.mVersionCode |
| 2487 | + " better than installed " + ps.versionCode); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2488 | InstallArgs args = new FileInstallArgs(ps.codePathString, ps.resourcePathString); |
| 2489 | args.cleanUpResourcesLI(); |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 2490 | mSettings.enableSystemPackageLP(ps.name); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 2491 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | } |
| 2493 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2494 | if (updatedPkg != null) { |
| 2495 | // An updated system app will not have the PARSE_IS_SYSTEM flag set initially |
| 2496 | parseFlags |= PackageParser.PARSE_IS_SYSTEM; |
| 2497 | } |
| 2498 | // Verify certificates against what was last scanned |
| 2499 | if (!collectCertificatesLI(pp, ps, pkg, scanFile, parseFlags)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2500 | Slog.w(TAG, "Failed verifying certificates for package:" + pkg.packageName); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2501 | return null; |
| 2502 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2503 | // The apk is forward locked (not public) if its code and resources |
| 2504 | // are kept in different files. |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2505 | // TODO grab this value from PackageSettings |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2506 | if (ps != null && !ps.codePath.equals(ps.resourcePath)) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2507 | parseFlags |= PackageParser.PARSE_FORWARD_LOCK; |
Suchi Amalapurapu | f2c1072 | 2009-07-29 17:19:39 -0700 | [diff] [blame] | 2508 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2509 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2510 | String codePath = null; |
| 2511 | String resPath = null; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2512 | if ((parseFlags & PackageParser.PARSE_FORWARD_LOCK) != 0) { |
| 2513 | if (ps != null && ps.resourcePathString != null) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2514 | resPath = ps.resourcePathString; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2515 | } else { |
| 2516 | // Should not happen at all. Just log an error. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2517 | Slog.e(TAG, "Resource path not set for pkg : " + pkg.packageName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2518 | } |
| 2519 | } else { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2520 | resPath = pkg.mScanPath; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2521 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2522 | codePath = pkg.mScanPath; |
| 2523 | // Set application objects path explicitly. |
| 2524 | setApplicationInfoPaths(pkg, codePath, resPath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | // 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] | 2526 | return scanPackageLI(pkg, parseFlags, scanMode | SCAN_UPDATE_SIGNATURE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | } |
| 2528 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 2529 | private static void setApplicationInfoPaths(PackageParser.Package pkg, |
| 2530 | String destCodePath, String destResPath) { |
| 2531 | pkg.mPath = pkg.mScanPath = destCodePath; |
| 2532 | pkg.applicationInfo.sourceDir = destCodePath; |
| 2533 | pkg.applicationInfo.publicSourceDir = destResPath; |
| 2534 | } |
| 2535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2536 | private static String fixProcessName(String defProcessName, |
| 2537 | String processName, int uid) { |
| 2538 | if (processName == null) { |
| 2539 | return defProcessName; |
| 2540 | } |
| 2541 | return processName; |
| 2542 | } |
| 2543 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2544 | private boolean verifySignaturesLP(PackageSetting pkgSetting, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | PackageParser.Package pkg, int parseFlags, boolean updateSignature) { |
| 2546 | if (pkg.mSignatures != null) { |
| 2547 | if (!pkgSetting.signatures.updateSignatures(pkg.mSignatures, |
| 2548 | updateSignature)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2549 | Slog.e(TAG, "Package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | + " signatures do not match the previously installed version; ignoring!"); |
| 2551 | mLastScanError = PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE; |
| 2552 | return false; |
| 2553 | } |
| 2554 | |
| 2555 | if (pkgSetting.sharedUser != null) { |
| 2556 | if (!pkgSetting.sharedUser.signatures.mergeSignatures( |
| 2557 | pkg.mSignatures, updateSignature)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2558 | Slog.e(TAG, "Package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2559 | + " has no signatures that match those in shared user " |
| 2560 | + pkgSetting.sharedUser.name + "; ignoring!"); |
| 2561 | mLastScanError = PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE; |
| 2562 | return false; |
| 2563 | } |
| 2564 | } |
| 2565 | } else { |
| 2566 | pkg.mSignatures = pkgSetting.signatures.mSignatures; |
| 2567 | } |
| 2568 | return true; |
| 2569 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2570 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2571 | public boolean performDexOpt(String packageName) { |
| 2572 | if (!mNoDexOpt) { |
| 2573 | return false; |
| 2574 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2575 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2576 | PackageParser.Package p; |
| 2577 | synchronized (mPackages) { |
| 2578 | p = mPackages.get(packageName); |
| 2579 | if (p == null || p.mDidDexOpt) { |
| 2580 | return false; |
| 2581 | } |
| 2582 | } |
| 2583 | synchronized (mInstallLock) { |
| 2584 | return performDexOptLI(p, false) == DEX_OPT_PERFORMED; |
| 2585 | } |
| 2586 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2587 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2588 | static final int DEX_OPT_SKIPPED = 0; |
| 2589 | static final int DEX_OPT_PERFORMED = 1; |
| 2590 | static final int DEX_OPT_FAILED = -1; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2591 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2592 | private int performDexOptLI(PackageParser.Package pkg, boolean forceDex) { |
| 2593 | boolean performed = false; |
Marco Nelissen | d595c79 | 2009-07-02 15:23:26 -0700 | [diff] [blame] | 2594 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0 && mInstaller != null) { |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2595 | String path = pkg.mScanPath; |
| 2596 | int ret = 0; |
| 2597 | try { |
| 2598 | if (forceDex || dalvik.system.DexFile.isDexOptNeeded(path)) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2599 | ret = mInstaller.dexopt(path, pkg.applicationInfo.uid, |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2600 | !isForwardLocked(pkg)); |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2601 | pkg.mDidDexOpt = true; |
| 2602 | performed = true; |
| 2603 | } |
| 2604 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2605 | Slog.w(TAG, "Apk not found for dexopt: " + path); |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2606 | ret = -1; |
| 2607 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2608 | Slog.w(TAG, "Exception reading apk: " + path, e); |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2609 | ret = -1; |
| 2610 | } |
| 2611 | if (ret < 0) { |
| 2612 | //error from installer |
| 2613 | return DEX_OPT_FAILED; |
| 2614 | } |
| 2615 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2616 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2617 | return performed ? DEX_OPT_PERFORMED : DEX_OPT_SKIPPED; |
| 2618 | } |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 2619 | |
| 2620 | private static boolean useEncryptedFilesystemForPackage(PackageParser.Package pkg) { |
| 2621 | return Environment.isEncryptedFilesystemEnabled() && |
| 2622 | ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_NEVER_ENCRYPT) == 0); |
| 2623 | } |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 2624 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2625 | private boolean verifyPackageUpdate(PackageSetting oldPkg, PackageParser.Package newPkg) { |
| 2626 | if ((oldPkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2627 | Slog.w(TAG, "Unable to update from " + oldPkg.name |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2628 | + " to " + newPkg.packageName |
| 2629 | + ": old package not in system partition"); |
| 2630 | return false; |
| 2631 | } else if (mPackages.get(oldPkg.name) != null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2632 | Slog.w(TAG, "Unable to update from " + oldPkg.name |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2633 | + " to " + newPkg.packageName |
| 2634 | + ": old package still exists"); |
| 2635 | return false; |
| 2636 | } |
| 2637 | return true; |
| 2638 | } |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 2639 | |
| 2640 | private File getDataPathForPackage(PackageParser.Package pkg) { |
| 2641 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(pkg); |
| 2642 | File dataPath; |
| 2643 | if (useEncryptedFSDir) { |
| 2644 | dataPath = new File(mSecureAppDataDir, pkg.packageName); |
| 2645 | } else { |
| 2646 | dataPath = new File(mAppDataDir, pkg.packageName); |
| 2647 | } |
| 2648 | return dataPath; |
| 2649 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2650 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2651 | private PackageParser.Package scanPackageLI(PackageParser.Package pkg, |
| 2652 | int parseFlags, int scanMode) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2653 | File scanFile = new File(pkg.mScanPath); |
Suchi Amalapurapu | 7040ce7 | 2010-02-08 23:55:56 -0800 | [diff] [blame] | 2654 | if (scanFile == null || pkg.applicationInfo.sourceDir == null || |
| 2655 | pkg.applicationInfo.publicSourceDir == null) { |
Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2656 | // Bail out. The resource and code paths haven't been set. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2657 | Slog.w(TAG, " Code and resource paths haven't been set correctly"); |
Suchi Amalapurapu | 08be55b | 2010-02-08 16:30:06 -0800 | [diff] [blame] | 2658 | mLastScanError = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 2659 | return null; |
| 2660 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | mScanningPath = scanFile; |
| 2662 | if (pkg == null) { |
| 2663 | mLastScanError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME; |
| 2664 | return null; |
| 2665 | } |
| 2666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| 2668 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM; |
| 2669 | } |
| 2670 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2671 | if (pkg.packageName.equals("android")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | synchronized (mPackages) { |
| 2673 | if (mAndroidApplication != null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2674 | Slog.w(TAG, "*************************************************"); |
| 2675 | Slog.w(TAG, "Core android package being redefined. Skipping."); |
| 2676 | Slog.w(TAG, " file=" + mScanningPath); |
| 2677 | Slog.w(TAG, "*************************************************"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2678 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2679 | return null; |
| 2680 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2682 | // Set up information for our fall-back user intent resolution |
| 2683 | // activity. |
| 2684 | mPlatformPackage = pkg; |
| 2685 | pkg.mVersionCode = mSdkVersion; |
| 2686 | mAndroidApplication = pkg.applicationInfo; |
| 2687 | mResolveActivity.applicationInfo = mAndroidApplication; |
| 2688 | mResolveActivity.name = ResolverActivity.class.getName(); |
| 2689 | mResolveActivity.packageName = mAndroidApplication.packageName; |
| 2690 | mResolveActivity.processName = mAndroidApplication.processName; |
| 2691 | mResolveActivity.launchMode = ActivityInfo.LAUNCH_MULTIPLE; |
| 2692 | mResolveActivity.flags = ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS; |
| 2693 | mResolveActivity.theme = com.android.internal.R.style.Theme_Dialog_Alert; |
| 2694 | mResolveActivity.exported = true; |
| 2695 | mResolveActivity.enabled = true; |
| 2696 | mResolveInfo.activityInfo = mResolveActivity; |
| 2697 | mResolveInfo.priority = 0; |
| 2698 | mResolveInfo.preferredOrder = 0; |
| 2699 | mResolveInfo.match = 0; |
| 2700 | mResolveComponentName = new ComponentName( |
| 2701 | mAndroidApplication.packageName, mResolveActivity.name); |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) Log.d( |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2706 | TAG, "Scanning package " + pkg.packageName); |
| 2707 | if (mPackages.containsKey(pkg.packageName) |
| 2708 | || mSharedLibraries.containsKey(pkg.packageName)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2709 | Slog.w(TAG, "*************************************************"); |
| 2710 | Slog.w(TAG, "Application package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2711 | + " already installed. Skipping duplicate."); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2712 | Slog.w(TAG, "*************************************************"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2713 | mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE; |
| 2714 | return null; |
| 2715 | } |
| 2716 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2717 | // Initialize package source and resource directories |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 2718 | File destCodeFile = new File(pkg.applicationInfo.sourceDir); |
| 2719 | File destResourceFile = new File(pkg.applicationInfo.publicSourceDir); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 2720 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2721 | SharedUserSetting suid = null; |
| 2722 | PackageSetting pkgSetting = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2723 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2724 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 2725 | // Only system apps can use these features. |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2726 | pkg.mOriginalPackages = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2727 | pkg.mRealPackage = null; |
| 2728 | pkg.mAdoptPermissions = null; |
| 2729 | } |
| 2730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2731 | synchronized (mPackages) { |
| 2732 | // Check all shared libraries and map to their actual file path. |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2733 | if (pkg.usesLibraries != null || pkg.usesOptionalLibraries != null) { |
| 2734 | if (mTmpSharedLibraries == null || |
| 2735 | mTmpSharedLibraries.length < mSharedLibraries.size()) { |
| 2736 | mTmpSharedLibraries = new String[mSharedLibraries.size()]; |
| 2737 | } |
| 2738 | int num = 0; |
| 2739 | int N = pkg.usesLibraries != null ? pkg.usesLibraries.size() : 0; |
| 2740 | for (int i=0; i<N; i++) { |
| 2741 | String file = mSharedLibraries.get(pkg.usesLibraries.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | if (file == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2743 | Slog.e(TAG, "Package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | + " requires unavailable shared library " |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2745 | + pkg.usesLibraries.get(i) + "; failing!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2746 | mLastScanError = PackageManager.INSTALL_FAILED_MISSING_SHARED_LIBRARY; |
| 2747 | return null; |
| 2748 | } |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2749 | mTmpSharedLibraries[num] = file; |
| 2750 | num++; |
| 2751 | } |
| 2752 | N = pkg.usesOptionalLibraries != null ? pkg.usesOptionalLibraries.size() : 0; |
| 2753 | for (int i=0; i<N; i++) { |
| 2754 | String file = mSharedLibraries.get(pkg.usesOptionalLibraries.get(i)); |
| 2755 | if (file == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2756 | Slog.w(TAG, "Package " + pkg.packageName |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2757 | + " desires unavailable shared library " |
| 2758 | + pkg.usesOptionalLibraries.get(i) + "; ignoring!"); |
| 2759 | } else { |
| 2760 | mTmpSharedLibraries[num] = file; |
| 2761 | num++; |
| 2762 | } |
| 2763 | } |
| 2764 | if (num > 0) { |
| 2765 | pkg.usesLibraryFiles = new String[num]; |
| 2766 | System.arraycopy(mTmpSharedLibraries, 0, |
| 2767 | pkg.usesLibraryFiles, 0, num); |
| 2768 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2769 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2770 | if (pkg.reqFeatures != null) { |
| 2771 | N = pkg.reqFeatures.size(); |
| 2772 | for (int i=0; i<N; i++) { |
| 2773 | FeatureInfo fi = pkg.reqFeatures.get(i); |
| 2774 | if ((fi.flags&FeatureInfo.FLAG_REQUIRED) == 0) { |
| 2775 | // Don't care. |
| 2776 | continue; |
| 2777 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2778 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2779 | if (fi.name != null) { |
| 2780 | if (mAvailableFeatures.get(fi.name) == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2781 | Slog.e(TAG, "Package " + pkg.packageName |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 2782 | + " requires unavailable feature " |
| 2783 | + fi.name + "; failing!"); |
| 2784 | mLastScanError = PackageManager.INSTALL_FAILED_MISSING_FEATURE; |
| 2785 | return null; |
| 2786 | } |
| 2787 | } |
| 2788 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2789 | } |
| 2790 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2792 | if (pkg.mSharedUserId != null) { |
| 2793 | suid = mSettings.getSharedUserLP(pkg.mSharedUserId, |
| 2794 | pkg.applicationInfo.flags, true); |
| 2795 | if (suid == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2796 | Slog.w(TAG, "Creating application package " + pkg.packageName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2797 | + " for shared user failed"); |
| 2798 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 2799 | return null; |
| 2800 | } |
| 2801 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) { |
| 2802 | Log.d(TAG, "Shared UserID " + pkg.mSharedUserId + " (uid=" |
| 2803 | + suid.userId + "): packages=" + suid.packages); |
| 2804 | } |
| 2805 | } |
Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 2806 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2807 | if (false) { |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2808 | if (pkg.mOriginalPackages != null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2809 | Log.w(TAG, "WAITING FOR DEBUGGER"); |
| 2810 | Debug.waitForDebugger(); |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2811 | Log.i(TAG, "Package " + pkg.packageName + " from original packages" |
| 2812 | + pkg.mOriginalPackages); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2813 | } |
| 2814 | } |
| 2815 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2816 | // Check if we are renaming from an original package name. |
| 2817 | PackageSetting origPackage = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2818 | String realName = null; |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2819 | if (pkg.mOriginalPackages != null) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2820 | // This package may need to be renamed to a previously |
| 2821 | // installed name. Let's check on that... |
| 2822 | String renamed = mSettings.mRenamedPackages.get(pkg.mRealPackage); |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2823 | if (pkg.mOriginalPackages.contains(renamed)) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2824 | // This package had originally been installed as the |
| 2825 | // original name, and we have already taken care of |
| 2826 | // transitioning to the new one. Just update the new |
| 2827 | // one to continue using the old name. |
| 2828 | realName = pkg.mRealPackage; |
| 2829 | if (!pkg.packageName.equals(renamed)) { |
| 2830 | // Callers into this function may have already taken |
| 2831 | // care of renaming the package; only do it here if |
| 2832 | // it is not already done. |
| 2833 | pkg.setPackageName(renamed); |
| 2834 | } |
| 2835 | |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2836 | } else { |
| 2837 | for (int i=pkg.mOriginalPackages.size()-1; i>=0; i--) { |
| 2838 | if ((origPackage=mSettings.peekPackageLP( |
| 2839 | pkg.mOriginalPackages.get(i))) != null) { |
| 2840 | // We do have the package already installed under its |
| 2841 | // original name... should we use it? |
| 2842 | if (!verifyPackageUpdate(origPackage, pkg)) { |
| 2843 | // New package is not compatible with original. |
| 2844 | origPackage = null; |
| 2845 | continue; |
| 2846 | } else if (origPackage.sharedUser != null) { |
| 2847 | // Make sure uid is compatible between packages. |
| 2848 | if (!origPackage.sharedUser.name.equals(pkg.mSharedUserId)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2849 | Slog.w(TAG, "Unable to migrate data from " + origPackage.name |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 2850 | + " to " + pkg.packageName + ": old uid " |
| 2851 | + origPackage.sharedUser.name |
| 2852 | + " differs from " + pkg.mSharedUserId); |
| 2853 | origPackage = null; |
| 2854 | continue; |
| 2855 | } |
| 2856 | } else { |
| 2857 | if (DEBUG_UPGRADE) Log.v(TAG, "Renaming new package " |
| 2858 | + pkg.packageName + " to old name " + origPackage.name); |
| 2859 | } |
| 2860 | break; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2861 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2862 | } |
| 2863 | } |
| 2864 | } |
| 2865 | |
| 2866 | if (mTransferedPackages.contains(pkg.packageName)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2867 | Slog.w(TAG, "Package " + pkg.packageName |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2868 | + " was transferred to another, but its .apk remains"); |
| 2869 | } |
| 2870 | |
Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 2871 | // Just create the setting, don't add it yet. For already existing packages |
| 2872 | // the PkgSetting exists already and doesn't have to be created. |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2873 | pkgSetting = mSettings.getPackageLP(pkg, origPackage, realName, suid, destCodeFile, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2874 | destResourceFile, pkg.applicationInfo.flags, true, false); |
| 2875 | if (pkgSetting == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2876 | Slog.w(TAG, "Creating application package " + pkg.packageName + " failed"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2877 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 2878 | return null; |
| 2879 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2880 | |
| 2881 | if (pkgSetting.origPackage != null) { |
| 2882 | // If we are first transitioning from an original package, |
| 2883 | // fix up the new package's name now. We need to do this after |
| 2884 | // looking up the package under its new name, so getPackageLP |
| 2885 | // can take care of fiddling things correctly. |
| 2886 | pkg.setPackageName(origPackage.name); |
| 2887 | |
| 2888 | // File a report about this. |
| 2889 | String msg = "New package " + pkgSetting.realName |
| 2890 | + " renamed to replace old package " + pkgSetting.name; |
| 2891 | reportSettingsProblem(Log.WARN, msg); |
| 2892 | |
| 2893 | // Make a note of it. |
| 2894 | mTransferedPackages.add(origPackage.name); |
| 2895 | |
| 2896 | // No longer need to retain this. |
| 2897 | pkgSetting.origPackage = null; |
| 2898 | } |
| 2899 | |
| 2900 | if (realName != null) { |
| 2901 | // Make a note of it. |
| 2902 | mTransferedPackages.add(pkg.packageName); |
| 2903 | } |
| 2904 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 2905 | if (mSettings.mDisabledSysPackages.get(pkg.packageName) != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 2907 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | pkg.applicationInfo.uid = pkgSetting.userId; |
| 2910 | pkg.mExtras = pkgSetting; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2911 | |
| 2912 | if (!verifySignaturesLP(pkgSetting, pkg, parseFlags, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | (scanMode&SCAN_UPDATE_SIGNATURE) != 0)) { |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 2914 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM_DIR) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | mLastScanError = PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE; |
| 2916 | return null; |
| 2917 | } |
| 2918 | // The signature has changed, but this package is in the system |
| 2919 | // image... let's recover! |
Suchi Amalapurapu | c4dd60f | 2009-03-24 21:10:53 -0700 | [diff] [blame] | 2920 | pkgSetting.signatures.mSignatures = pkg.mSignatures; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | // However... if this package is part of a shared user, but it |
| 2922 | // doesn't match the signature of the shared user, let's fail. |
| 2923 | // What this means is that you can't change the signatures |
| 2924 | // associated with an overall shared user, which doesn't seem all |
| 2925 | // that unreasonable. |
| 2926 | if (pkgSetting.sharedUser != null) { |
| 2927 | if (!pkgSetting.sharedUser.signatures.mergeSignatures( |
| 2928 | pkg.mSignatures, false)) { |
| 2929 | mLastScanError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 2930 | return null; |
| 2931 | } |
| 2932 | } |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 2933 | // File a report about this. |
| 2934 | String msg = "System package " + pkg.packageName |
| 2935 | + " signature changed; retaining data."; |
| 2936 | reportSettingsProblem(Log.WARN, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2938 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2939 | // Verify that this new package doesn't have any content providers |
| 2940 | // that conflict with existing packages. Only do this if the |
| 2941 | // package isn't already installed, since we don't want to break |
| 2942 | // things that are installed. |
| 2943 | if ((scanMode&SCAN_NEW_INSTALL) != 0) { |
| 2944 | int N = pkg.providers.size(); |
| 2945 | int i; |
| 2946 | for (i=0; i<N; i++) { |
| 2947 | PackageParser.Provider p = pkg.providers.get(i); |
Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 2948 | if (p.info.authority != null) { |
| 2949 | String names[] = p.info.authority.split(";"); |
| 2950 | for (int j = 0; j < names.length; j++) { |
| 2951 | if (mProviders.containsKey(names[j])) { |
| 2952 | PackageParser.Provider other = mProviders.get(names[j]); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2953 | Slog.w(TAG, "Can't install because provider name " + names[j] + |
Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 2954 | " (in package " + pkg.applicationInfo.packageName + |
| 2955 | ") is already used by " |
| 2956 | + ((other != null && other.getComponentName() != null) |
| 2957 | ? other.getComponentName().getPackageName() : "?")); |
| 2958 | mLastScanError = PackageManager.INSTALL_FAILED_CONFLICTING_PROVIDER; |
| 2959 | return null; |
| 2960 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2961 | } |
| 2962 | } |
| 2963 | } |
| 2964 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | } |
| 2966 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2967 | final String pkgName = pkg.packageName; |
| 2968 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2969 | if (pkg.mAdoptPermissions != null) { |
| 2970 | // This package wants to adopt ownership of permissions from |
| 2971 | // another package. |
| 2972 | for (int i=pkg.mAdoptPermissions.size()-1; i>=0; i--) { |
| 2973 | String origName = pkg.mAdoptPermissions.get(i); |
| 2974 | PackageSetting orig = mSettings.peekPackageLP(origName); |
| 2975 | if (orig != null) { |
| 2976 | if (verifyPackageUpdate(orig, pkg)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 2977 | Slog.i(TAG, "Adopting permissions from " |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 2978 | + origName + " to " + pkg.packageName); |
| 2979 | mSettings.transferPermissions(origName, pkg.packageName); |
| 2980 | } |
| 2981 | } |
| 2982 | } |
| 2983 | } |
| 2984 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2985 | long scanFileTime = scanFile.lastModified(); |
| 2986 | final boolean forceDex = (scanMode&SCAN_FORCE_DEX) != 0; |
| 2987 | final boolean scanFileNewer = forceDex || scanFileTime != pkgSetting.getTimeStamp(); |
| 2988 | pkg.applicationInfo.processName = fixProcessName( |
| 2989 | pkg.applicationInfo.packageName, |
| 2990 | pkg.applicationInfo.processName, |
| 2991 | pkg.applicationInfo.uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2992 | |
| 2993 | File dataPath; |
| 2994 | if (mPlatformPackage == pkg) { |
| 2995 | // The system package is special. |
| 2996 | dataPath = new File (Environment.getDataDirectory(), "system"); |
| 2997 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 2998 | } else { |
| 2999 | // This is a normal package, need to make its data directory. |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3000 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(pkg); |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 3001 | dataPath = getDataPathForPackage(pkg); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3002 | |
| 3003 | boolean uidError = false; |
| 3004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3005 | if (dataPath.exists()) { |
| 3006 | mOutPermissions[1] = 0; |
| 3007 | FileUtils.getPermissions(dataPath.getPath(), mOutPermissions); |
| 3008 | if (mOutPermissions[1] == pkg.applicationInfo.uid |
| 3009 | || !Process.supportsProcesses()) { |
| 3010 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3011 | } else { |
| 3012 | boolean recovered = false; |
| 3013 | if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) { |
| 3014 | // If this is a system app, we can at least delete its |
| 3015 | // current data so the application will still work. |
| 3016 | if (mInstaller != null) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3017 | int ret = mInstaller.remove(pkgName, useEncryptedFSDir); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3018 | if (ret >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3019 | // Old data gone! |
| 3020 | String msg = "System package " + pkg.packageName |
| 3021 | + " has changed from uid: " |
| 3022 | + mOutPermissions[1] + " to " |
| 3023 | + pkg.applicationInfo.uid + "; old data erased"; |
| 3024 | reportSettingsProblem(Log.WARN, msg); |
| 3025 | recovered = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3027 | // And now re-install the app. |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3028 | ret = mInstaller.install(pkgName, useEncryptedFSDir, pkg.applicationInfo.uid, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3029 | pkg.applicationInfo.uid); |
| 3030 | if (ret == -1) { |
| 3031 | // Ack should not happen! |
| 3032 | msg = "System package " + pkg.packageName |
| 3033 | + " could not have data directory re-created after delete."; |
| 3034 | reportSettingsProblem(Log.WARN, msg); |
| 3035 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3036 | return null; |
| 3037 | } |
| 3038 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3039 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | if (!recovered) { |
| 3041 | mHasSystemUidErrors = true; |
| 3042 | } |
| 3043 | } |
| 3044 | if (!recovered) { |
| 3045 | pkg.applicationInfo.dataDir = "/mismatched_uid/settings_" |
| 3046 | + pkg.applicationInfo.uid + "/fs_" |
| 3047 | + mOutPermissions[1]; |
| 3048 | String msg = "Package " + pkg.packageName |
| 3049 | + " has mismatched uid: " |
| 3050 | + mOutPermissions[1] + " on disk, " |
| 3051 | + pkg.applicationInfo.uid + " in settings"; |
| 3052 | synchronized (mPackages) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3053 | mSettings.mReadMessages.append(msg); |
| 3054 | mSettings.mReadMessages.append('\n'); |
| 3055 | uidError = true; |
| 3056 | if (!pkgSetting.uidError) { |
| 3057 | reportSettingsProblem(Log.ERROR, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3058 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3059 | } |
| 3060 | } |
| 3061 | } |
| 3062 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3063 | } else { |
| 3064 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGV) |
| 3065 | Log.v(TAG, "Want this data dir: " + dataPath); |
| 3066 | //invoke installer to do the actual installation |
| 3067 | if (mInstaller != null) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 3068 | int ret = mInstaller.install(pkgName, useEncryptedFSDir, pkg.applicationInfo.uid, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3069 | pkg.applicationInfo.uid); |
| 3070 | if(ret < 0) { |
| 3071 | // Error from installer |
| 3072 | mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 3073 | return null; |
| 3074 | } |
| 3075 | } else { |
| 3076 | dataPath.mkdirs(); |
| 3077 | if (dataPath.exists()) { |
| 3078 | FileUtils.setPermissions( |
| 3079 | dataPath.toString(), |
| 3080 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 3081 | pkg.applicationInfo.uid, pkg.applicationInfo.uid); |
| 3082 | } |
| 3083 | } |
| 3084 | if (dataPath.exists()) { |
| 3085 | pkg.applicationInfo.dataDir = dataPath.getPath(); |
| 3086 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3087 | Slog.w(TAG, "Unable to create data directory: " + dataPath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3088 | pkg.applicationInfo.dataDir = null; |
| 3089 | } |
| 3090 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 3091 | |
| 3092 | pkgSetting.uidError = uidError; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | // Perform shared library installation and dex validation and |
| 3096 | // optimization, if this is not a system app. |
| 3097 | if (mInstaller != null) { |
| 3098 | String path = scanFile.getPath(); |
| 3099 | if (scanFileNewer) { |
| 3100 | Log.i(TAG, path + " changed; unpacking"); |
Dianne Hackborn | b181118 | 2009-05-21 15:45:42 -0700 | [diff] [blame] | 3101 | int err = cachePackageSharedLibsLI(pkg, dataPath, scanFile); |
| 3102 | if (err != PackageManager.INSTALL_SUCCEEDED) { |
| 3103 | mLastScanError = err; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3104 | return null; |
| 3105 | } |
| 3106 | } |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 3107 | pkg.mScanPath = path; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3108 | |
Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 3109 | if ((scanMode&SCAN_NO_DEX) == 0) { |
| 3110 | if (performDexOptLI(pkg, forceDex) == DEX_OPT_FAILED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3111 | mLastScanError = PackageManager.INSTALL_FAILED_DEXOPT; |
| 3112 | return null; |
| 3113 | } |
| 3114 | } |
| 3115 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3117 | if (mFactoryTest && pkg.requestedPermissions.contains( |
| 3118 | android.Manifest.permission.FACTORY_TEST)) { |
| 3119 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FACTORY_TEST; |
| 3120 | } |
| 3121 | |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3122 | // Request the ActivityManager to kill the process(only for existing packages) |
| 3123 | // so that we do not end up in a confused state while the user is still using the older |
| 3124 | // version of the application while the new one gets installed. |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3125 | if ((parseFlags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3126 | killApplication(pkg.applicationInfo.packageName, |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3127 | pkg.applicationInfo.uid); |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 3128 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | synchronized (mPackages) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 3131 | // We don't expect installation to fail beyond this point, |
| 3132 | if ((scanMode&SCAN_MONITOR) != 0) { |
| 3133 | mAppDirs.put(pkg.mPath, pkg); |
| 3134 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | // Add the new setting to mSettings |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 3136 | mSettings.insertPackageSettingLP(pkgSetting, pkg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3137 | // Add the new setting to mPackages |
Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 3138 | mPackages.put(pkg.applicationInfo.packageName, pkg); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 3139 | // Make sure we don't accidentally delete its data. |
| 3140 | mSettings.mPackagesToBeCleaned.remove(pkgName); |
| 3141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | int N = pkg.providers.size(); |
| 3143 | StringBuilder r = null; |
| 3144 | int i; |
| 3145 | for (i=0; i<N; i++) { |
| 3146 | PackageParser.Provider p = pkg.providers.get(i); |
| 3147 | p.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3148 | p.info.processName, pkg.applicationInfo.uid); |
| 3149 | mProvidersByComponent.put(new ComponentName(p.info.packageName, |
| 3150 | p.info.name), p); |
| 3151 | p.syncable = p.info.isSyncable; |
Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3152 | if (p.info.authority != null) { |
| 3153 | String names[] = p.info.authority.split(";"); |
| 3154 | p.info.authority = null; |
| 3155 | for (int j = 0; j < names.length; j++) { |
| 3156 | if (j == 1 && p.syncable) { |
| 3157 | // We only want the first authority for a provider to possibly be |
| 3158 | // syncable, so if we already added this provider using a different |
| 3159 | // authority clear the syncable flag. We copy the provider before |
| 3160 | // changing it because the mProviders object contains a reference |
| 3161 | // to a provider that we don't want to change. |
| 3162 | // Only do this for the second authority since the resulting provider |
| 3163 | // object can be the same for all future authorities for this provider. |
| 3164 | p = new PackageParser.Provider(p); |
| 3165 | p.syncable = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3166 | } |
Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3167 | if (!mProviders.containsKey(names[j])) { |
| 3168 | mProviders.put(names[j], p); |
| 3169 | if (p.info.authority == null) { |
| 3170 | p.info.authority = names[j]; |
| 3171 | } else { |
| 3172 | p.info.authority = p.info.authority + ";" + names[j]; |
| 3173 | } |
| 3174 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) |
| 3175 | Log.d(TAG, "Registered content provider: " + names[j] + |
| 3176 | ", className = " + p.info.name + |
| 3177 | ", isSyncable = " + p.info.isSyncable); |
| 3178 | } else { |
| 3179 | PackageParser.Provider other = mProviders.get(names[j]); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3180 | Slog.w(TAG, "Skipping provider name " + names[j] + |
Suchi Amalapurapu | 9444bea | 2010-03-05 10:46:11 -0800 | [diff] [blame] | 3181 | " (in package " + pkg.applicationInfo.packageName + |
| 3182 | "): name already used by " |
| 3183 | + ((other != null && other.getComponentName() != null) |
| 3184 | ? other.getComponentName().getPackageName() : "?")); |
| 3185 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3186 | } |
| 3187 | } |
| 3188 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3189 | if (r == null) { |
| 3190 | r = new StringBuilder(256); |
| 3191 | } else { |
| 3192 | r.append(' '); |
| 3193 | } |
| 3194 | r.append(p.info.name); |
| 3195 | } |
| 3196 | } |
| 3197 | if (r != null) { |
| 3198 | if (Config.LOGD) Log.d(TAG, " Providers: " + r); |
| 3199 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3201 | N = pkg.services.size(); |
| 3202 | r = null; |
| 3203 | for (i=0; i<N; i++) { |
| 3204 | PackageParser.Service s = pkg.services.get(i); |
| 3205 | s.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3206 | s.info.processName, pkg.applicationInfo.uid); |
| 3207 | mServices.addService(s); |
| 3208 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3209 | if (r == null) { |
| 3210 | r = new StringBuilder(256); |
| 3211 | } else { |
| 3212 | r.append(' '); |
| 3213 | } |
| 3214 | r.append(s.info.name); |
| 3215 | } |
| 3216 | } |
| 3217 | if (r != null) { |
| 3218 | if (Config.LOGD) Log.d(TAG, " Services: " + r); |
| 3219 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3220 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3221 | N = pkg.receivers.size(); |
| 3222 | r = null; |
| 3223 | for (i=0; i<N; i++) { |
| 3224 | PackageParser.Activity a = pkg.receivers.get(i); |
| 3225 | a.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3226 | a.info.processName, pkg.applicationInfo.uid); |
| 3227 | mReceivers.addActivity(a, "receiver"); |
| 3228 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3229 | if (r == null) { |
| 3230 | r = new StringBuilder(256); |
| 3231 | } else { |
| 3232 | r.append(' '); |
| 3233 | } |
| 3234 | r.append(a.info.name); |
| 3235 | } |
| 3236 | } |
| 3237 | if (r != null) { |
| 3238 | if (Config.LOGD) Log.d(TAG, " Receivers: " + r); |
| 3239 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3241 | N = pkg.activities.size(); |
| 3242 | r = null; |
| 3243 | for (i=0; i<N; i++) { |
| 3244 | PackageParser.Activity a = pkg.activities.get(i); |
| 3245 | a.info.processName = fixProcessName(pkg.applicationInfo.processName, |
| 3246 | a.info.processName, pkg.applicationInfo.uid); |
| 3247 | mActivities.addActivity(a, "activity"); |
| 3248 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3249 | if (r == null) { |
| 3250 | r = new StringBuilder(256); |
| 3251 | } else { |
| 3252 | r.append(' '); |
| 3253 | } |
| 3254 | r.append(a.info.name); |
| 3255 | } |
| 3256 | } |
| 3257 | if (r != null) { |
| 3258 | if (Config.LOGD) Log.d(TAG, " Activities: " + r); |
| 3259 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | N = pkg.permissionGroups.size(); |
| 3262 | r = null; |
| 3263 | for (i=0; i<N; i++) { |
| 3264 | PackageParser.PermissionGroup pg = pkg.permissionGroups.get(i); |
| 3265 | PackageParser.PermissionGroup cur = mPermissionGroups.get(pg.info.name); |
| 3266 | if (cur == null) { |
| 3267 | mPermissionGroups.put(pg.info.name, pg); |
| 3268 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3269 | if (r == null) { |
| 3270 | r = new StringBuilder(256); |
| 3271 | } else { |
| 3272 | r.append(' '); |
| 3273 | } |
| 3274 | r.append(pg.info.name); |
| 3275 | } |
| 3276 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3277 | 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] | 3278 | + pg.info.packageName + " ignored: original from " |
| 3279 | + cur.info.packageName); |
| 3280 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3281 | if (r == null) { |
| 3282 | r = new StringBuilder(256); |
| 3283 | } else { |
| 3284 | r.append(' '); |
| 3285 | } |
| 3286 | r.append("DUP:"); |
| 3287 | r.append(pg.info.name); |
| 3288 | } |
| 3289 | } |
| 3290 | } |
| 3291 | if (r != null) { |
| 3292 | if (Config.LOGD) Log.d(TAG, " Permission Groups: " + r); |
| 3293 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3295 | N = pkg.permissions.size(); |
| 3296 | r = null; |
| 3297 | for (i=0; i<N; i++) { |
| 3298 | PackageParser.Permission p = pkg.permissions.get(i); |
| 3299 | HashMap<String, BasePermission> permissionMap = |
| 3300 | p.tree ? mSettings.mPermissionTrees |
| 3301 | : mSettings.mPermissions; |
| 3302 | p.group = mPermissionGroups.get(p.info.group); |
| 3303 | if (p.info.group == null || p.group != null) { |
| 3304 | BasePermission bp = permissionMap.get(p.info.name); |
| 3305 | if (bp == null) { |
| 3306 | bp = new BasePermission(p.info.name, p.info.packageName, |
| 3307 | BasePermission.TYPE_NORMAL); |
| 3308 | permissionMap.put(p.info.name, bp); |
| 3309 | } |
| 3310 | if (bp.perm == null) { |
| 3311 | if (bp.sourcePackage == null |
| 3312 | || bp.sourcePackage.equals(p.info.packageName)) { |
| 3313 | BasePermission tree = findPermissionTreeLP(p.info.name); |
| 3314 | if (tree == null |
| 3315 | || tree.sourcePackage.equals(p.info.packageName)) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3316 | bp.packageSetting = pkgSetting; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3317 | bp.perm = p; |
| 3318 | bp.uid = pkg.applicationInfo.uid; |
| 3319 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3320 | if (r == null) { |
| 3321 | r = new StringBuilder(256); |
| 3322 | } else { |
| 3323 | r.append(' '); |
| 3324 | } |
| 3325 | r.append(p.info.name); |
| 3326 | } |
| 3327 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3328 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3329 | + p.info.packageName + " ignored: base tree " |
| 3330 | + tree.name + " is from package " |
| 3331 | + tree.sourcePackage); |
| 3332 | } |
| 3333 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3334 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | + p.info.packageName + " ignored: original from " |
| 3336 | + bp.sourcePackage); |
| 3337 | } |
| 3338 | } else if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3339 | if (r == null) { |
| 3340 | r = new StringBuilder(256); |
| 3341 | } else { |
| 3342 | r.append(' '); |
| 3343 | } |
| 3344 | r.append("DUP:"); |
| 3345 | r.append(p.info.name); |
| 3346 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3347 | if (bp.perm == p) { |
| 3348 | bp.protectionLevel = p.info.protectionLevel; |
| 3349 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3350 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3351 | Slog.w(TAG, "Permission " + p.info.name + " from package " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3352 | + p.info.packageName + " ignored: no group " |
| 3353 | + p.group); |
| 3354 | } |
| 3355 | } |
| 3356 | if (r != null) { |
| 3357 | if (Config.LOGD) Log.d(TAG, " Permissions: " + r); |
| 3358 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | N = pkg.instrumentation.size(); |
| 3361 | r = null; |
| 3362 | for (i=0; i<N; i++) { |
| 3363 | PackageParser.Instrumentation a = pkg.instrumentation.get(i); |
| 3364 | a.info.packageName = pkg.applicationInfo.packageName; |
| 3365 | a.info.sourceDir = pkg.applicationInfo.sourceDir; |
| 3366 | a.info.publicSourceDir = pkg.applicationInfo.publicSourceDir; |
| 3367 | a.info.dataDir = pkg.applicationInfo.dataDir; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3368 | mInstrumentation.put(a.getComponentName(), a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) { |
| 3370 | if (r == null) { |
| 3371 | r = new StringBuilder(256); |
| 3372 | } else { |
| 3373 | r.append(' '); |
| 3374 | } |
| 3375 | r.append(a.info.name); |
| 3376 | } |
| 3377 | } |
| 3378 | if (r != null) { |
| 3379 | if (Config.LOGD) Log.d(TAG, " Instrumentation: " + r); |
| 3380 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3381 | |
Dianne Hackborn | 854060af | 2009-07-09 18:14:31 -0700 | [diff] [blame] | 3382 | if (pkg.protectedBroadcasts != null) { |
| 3383 | N = pkg.protectedBroadcasts.size(); |
| 3384 | for (i=0; i<N; i++) { |
| 3385 | mProtectedBroadcasts.add(pkg.protectedBroadcasts.get(i)); |
| 3386 | } |
| 3387 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3389 | pkgSetting.setTimeStamp(scanFileTime); |
| 3390 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | return pkg; |
| 3393 | } |
| 3394 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 3395 | private void killApplication(String pkgName, int uid) { |
| 3396 | // Request the ActivityManager to kill the process(only for existing packages) |
| 3397 | // so that we do not end up in a confused state while the user is still using the older |
| 3398 | // version of the application while the new one gets installed. |
| 3399 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 3400 | if (am != null) { |
| 3401 | try { |
| 3402 | am.killApplicationWithUid(pkgName, uid); |
| 3403 | } catch (RemoteException e) { |
| 3404 | } |
| 3405 | } |
| 3406 | } |
| 3407 | |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3408 | // The following constants are returned by cachePackageSharedLibsForAbiLI |
| 3409 | // to indicate if native shared libraries were found in the package. |
| 3410 | // Values are: |
| 3411 | // PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES => native libraries found and installed |
| 3412 | // PACKAGE_INSTALL_NATIVE_NO_LIBRARIES => no native libraries in package |
| 3413 | // PACKAGE_INSTALL_NATIVE_ABI_MISMATCH => native libraries for another ABI found |
| 3414 | // in package (and not installed) |
| 3415 | // |
| 3416 | private static final int PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES = 0; |
| 3417 | private static final int PACKAGE_INSTALL_NATIVE_NO_LIBRARIES = 1; |
| 3418 | 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] | 3419 | |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3420 | // Find all files of the form lib/<cpuAbi>/lib<name>.so in the .apk |
| 3421 | // and automatically copy them to /data/data/<appname>/lib if present. |
| 3422 | // |
| 3423 | // NOTE: this method may throw an IOException if the library cannot |
| 3424 | // be copied to its final destination, e.g. if there isn't enough |
| 3425 | // room left on the data partition, or a ZipException if the package |
| 3426 | // file is malformed. |
| 3427 | // |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3428 | private int cachePackageSharedLibsForAbiLI(PackageParser.Package pkg, |
| 3429 | File dataPath, File scanFile, String cpuAbi) throws IOException, ZipException { |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3430 | File sharedLibraryDir = new File(dataPath.getPath() + "/lib"); |
| 3431 | final String apkLib = "lib/"; |
| 3432 | final int apkLibLen = apkLib.length(); |
| 3433 | final int cpuAbiLen = cpuAbi.length(); |
| 3434 | final String libPrefix = "lib"; |
| 3435 | final int libPrefixLen = libPrefix.length(); |
| 3436 | final String libSuffix = ".so"; |
| 3437 | final int libSuffixLen = libSuffix.length(); |
| 3438 | boolean hasNativeLibraries = false; |
| 3439 | boolean installedNativeLibraries = false; |
| 3440 | |
| 3441 | // the minimum length of a valid native shared library of the form |
| 3442 | // lib/<something>/lib<name>.so. |
| 3443 | final int minEntryLen = apkLibLen + 2 + libPrefixLen + 1 + libSuffixLen; |
| 3444 | |
| 3445 | ZipFile zipFile = new ZipFile(scanFile); |
| 3446 | Enumeration<ZipEntry> entries = |
| 3447 | (Enumeration<ZipEntry>) zipFile.entries(); |
| 3448 | |
| 3449 | while (entries.hasMoreElements()) { |
| 3450 | ZipEntry entry = entries.nextElement(); |
| 3451 | // skip directories |
| 3452 | if (entry.isDirectory()) { |
| 3453 | continue; |
| 3454 | } |
| 3455 | String entryName = entry.getName(); |
| 3456 | |
| 3457 | // check that the entry looks like lib/<something>/lib<name>.so |
| 3458 | // here, but don't check the ABI just yet. |
| 3459 | // |
| 3460 | // - must be sufficiently long |
| 3461 | // - must end with libSuffix, i.e. ".so" |
| 3462 | // - must start with apkLib, i.e. "lib/" |
| 3463 | if (entryName.length() < minEntryLen || |
| 3464 | !entryName.endsWith(libSuffix) || |
| 3465 | !entryName.startsWith(apkLib) ) { |
| 3466 | continue; |
| 3467 | } |
| 3468 | |
| 3469 | // file name must start with libPrefix, i.e. "lib" |
| 3470 | int lastSlash = entryName.lastIndexOf('/'); |
| 3471 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3472 | if (lastSlash < 0 || |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3473 | !entryName.regionMatches(lastSlash+1, libPrefix, 0, libPrefixLen) ) { |
| 3474 | continue; |
| 3475 | } |
| 3476 | |
| 3477 | hasNativeLibraries = true; |
| 3478 | |
| 3479 | // check the cpuAbi now, between lib/ and /lib<name>.so |
| 3480 | // |
| 3481 | if (lastSlash != apkLibLen + cpuAbiLen || |
| 3482 | !entryName.regionMatches(apkLibLen, cpuAbi, 0, cpuAbiLen) ) |
| 3483 | continue; |
| 3484 | |
| 3485 | // extract the library file name, ensure it doesn't contain |
| 3486 | // weird characters. we're guaranteed here that it doesn't contain |
| 3487 | // a directory separator though. |
| 3488 | String libFileName = entryName.substring(lastSlash+1); |
| 3489 | if (!FileUtils.isFilenameSafe(new File(libFileName))) { |
| 3490 | continue; |
| 3491 | } |
| 3492 | |
| 3493 | installedNativeLibraries = true; |
| 3494 | |
| 3495 | String sharedLibraryFilePath = sharedLibraryDir.getPath() + |
| 3496 | File.separator + libFileName; |
| 3497 | File sharedLibraryFile = new File(sharedLibraryFilePath); |
| 3498 | if (! sharedLibraryFile.exists() || |
| 3499 | sharedLibraryFile.length() != entry.getSize() || |
| 3500 | sharedLibraryFile.lastModified() != entry.getTime()) { |
| 3501 | if (Config.LOGD) { |
| 3502 | Log.d(TAG, "Caching shared lib " + entry.getName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3503 | } |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3504 | if (mInstaller == null) { |
| 3505 | sharedLibraryDir.mkdir(); |
Dianne Hackborn | b181118 | 2009-05-21 15:45:42 -0700 | [diff] [blame] | 3506 | } |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3507 | cacheNativeBinaryLI(pkg, zipFile, entry, sharedLibraryDir, |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3508 | sharedLibraryFile); |
| 3509 | } |
| 3510 | } |
| 3511 | if (!hasNativeLibraries) |
| 3512 | return PACKAGE_INSTALL_NATIVE_NO_LIBRARIES; |
| 3513 | |
| 3514 | if (!installedNativeLibraries) |
| 3515 | return PACKAGE_INSTALL_NATIVE_ABI_MISMATCH; |
| 3516 | |
| 3517 | return PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES; |
| 3518 | } |
| 3519 | |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3520 | // Find the gdbserver executable program in a package at |
| 3521 | // lib/<cpuAbi>/gdbserver and copy it to /data/data/<name>/lib/gdbserver |
| 3522 | // |
| 3523 | // Returns PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES on success, |
| 3524 | // or PACKAGE_INSTALL_NATIVE_NO_LIBRARIES otherwise. |
| 3525 | // |
| 3526 | private int cachePackageGdbServerLI(PackageParser.Package pkg, |
| 3527 | File dataPath, File scanFile, String cpuAbi) throws IOException, ZipException { |
| 3528 | File installGdbServerDir = new File(dataPath.getPath() + "/lib"); |
| 3529 | final String GDBSERVER = "gdbserver"; |
| 3530 | final String apkGdbServerPath = "lib/" + cpuAbi + "/" + GDBSERVER; |
| 3531 | |
| 3532 | ZipFile zipFile = new ZipFile(scanFile); |
| 3533 | Enumeration<ZipEntry> entries = |
| 3534 | (Enumeration<ZipEntry>) zipFile.entries(); |
| 3535 | |
| 3536 | while (entries.hasMoreElements()) { |
| 3537 | ZipEntry entry = entries.nextElement(); |
| 3538 | // skip directories |
| 3539 | if (entry.isDirectory()) { |
| 3540 | continue; |
| 3541 | } |
| 3542 | String entryName = entry.getName(); |
| 3543 | |
| 3544 | if (!entryName.equals(apkGdbServerPath)) { |
| 3545 | continue; |
| 3546 | } |
| 3547 | |
| 3548 | String installGdbServerPath = installGdbServerDir.getPath() + |
| 3549 | "/" + GDBSERVER; |
| 3550 | File installGdbServerFile = new File(installGdbServerPath); |
| 3551 | if (! installGdbServerFile.exists() || |
| 3552 | installGdbServerFile.length() != entry.getSize() || |
| 3553 | installGdbServerFile.lastModified() != entry.getTime()) { |
| 3554 | if (Config.LOGD) { |
| 3555 | Log.d(TAG, "Caching gdbserver " + entry.getName()); |
| 3556 | } |
| 3557 | if (mInstaller == null) { |
| 3558 | installGdbServerDir.mkdir(); |
| 3559 | } |
| 3560 | cacheNativeBinaryLI(pkg, zipFile, entry, installGdbServerDir, |
| 3561 | installGdbServerFile); |
| 3562 | } |
| 3563 | return PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES; |
| 3564 | } |
| 3565 | return PACKAGE_INSTALL_NATIVE_NO_LIBRARIES; |
| 3566 | } |
| 3567 | |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3568 | // extract shared libraries stored in the APK as lib/<cpuAbi>/lib<name>.so |
| 3569 | // and copy them to /data/data/<appname>/lib. |
| 3570 | // |
| 3571 | // This function will first try the main CPU ABI defined by Build.CPU_ABI |
| 3572 | // (which corresponds to ro.product.cpu.abi), and also try an alternate |
| 3573 | // one if ro.product.cpu.abi2 is defined. |
| 3574 | // |
| 3575 | private int cachePackageSharedLibsLI(PackageParser.Package pkg, |
| 3576 | File dataPath, File scanFile) { |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3577 | String cpuAbi = Build.CPU_ABI; |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3578 | try { |
| 3579 | int result = cachePackageSharedLibsForAbiLI(pkg, dataPath, scanFile, cpuAbi); |
| 3580 | |
| 3581 | // some architectures are capable of supporting several CPU ABIs |
| 3582 | // for example, 'armeabi-v7a' also supports 'armeabi' native code |
| 3583 | // this is indicated by the definition of the ro.product.cpu.abi2 |
| 3584 | // system property. |
| 3585 | // |
| 3586 | // only scan the package twice in case of ABI mismatch |
| 3587 | if (result == PACKAGE_INSTALL_NATIVE_ABI_MISMATCH) { |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3588 | final String cpuAbi2 = SystemProperties.get("ro.product.cpu.abi2",null); |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3589 | if (cpuAbi2 != null) { |
| 3590 | result = cachePackageSharedLibsForAbiLI(pkg, dataPath, scanFile, cpuAbi2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | } |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3592 | |
| 3593 | if (result == PACKAGE_INSTALL_NATIVE_ABI_MISMATCH) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3594 | Slog.w(TAG,"Native ABI mismatch from package file"); |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3595 | return PackageManager.INSTALL_FAILED_INVALID_APK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3596 | } |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3597 | |
| 3598 | if (result == PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES) { |
| 3599 | cpuAbi = cpuAbi2; |
| 3600 | } |
| 3601 | } |
| 3602 | |
| 3603 | // for debuggable packages, also extract gdbserver from lib/<abi> |
| 3604 | // into /data/data/<appname>/lib too. |
| 3605 | if (result == PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES && |
| 3606 | (pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { |
| 3607 | int result2 = cachePackageGdbServerLI(pkg, dataPath, scanFile, cpuAbi); |
| 3608 | if (result2 == PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES) { |
| 3609 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_NATIVE_DEBUGGABLE; |
| 3610 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3611 | } |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3612 | } catch (ZipException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3613 | Slog.w(TAG, "Failed to extract data from package file", e); |
David 'Digit' Turner | feba743 | 2009-11-06 17:54:12 -0800 | [diff] [blame] | 3614 | return PackageManager.INSTALL_FAILED_INVALID_APK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3615 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3616 | Slog.w(TAG, "Failed to cache package shared libs", e); |
Dianne Hackborn | b181118 | 2009-05-21 15:45:42 -0700 | [diff] [blame] | 3617 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | } |
Dianne Hackborn | b181118 | 2009-05-21 15:45:42 -0700 | [diff] [blame] | 3619 | return PackageManager.INSTALL_SUCCEEDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3620 | } |
| 3621 | |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3622 | private void cacheNativeBinaryLI(PackageParser.Package pkg, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3623 | ZipFile zipFile, ZipEntry entry, |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3624 | File binaryDir, |
| 3625 | File binaryFile) throws IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | InputStream inputStream = zipFile.getInputStream(entry); |
| 3627 | try { |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3628 | File tempFile = File.createTempFile("tmp", "tmp", binaryDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3629 | String tempFilePath = tempFile.getPath(); |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3630 | // 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] | 3631 | // now need to be left as world readable and owned by the system. |
| 3632 | if (! FileUtils.copyToFile(inputStream, tempFile) || |
| 3633 | ! tempFile.setLastModified(entry.getTime()) || |
| 3634 | FileUtils.setPermissions(tempFilePath, |
| 3635 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3636 | |FileUtils.S_IXUSR|FileUtils.S_IXGRP|FileUtils.S_IXOTH |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3637 | |FileUtils.S_IROTH, -1, -1) != 0 || |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3638 | ! tempFile.renameTo(binaryFile)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | // Failed to properly write file. |
| 3640 | tempFile.delete(); |
David 'Digit' Turner | 1edab2b | 2010-01-21 15:15:23 -0800 | [diff] [blame] | 3641 | throw new IOException("Couldn't create cached binary " |
| 3642 | + binaryFile + " in " + binaryDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3643 | } |
| 3644 | } finally { |
| 3645 | inputStream.close(); |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | void removePackageLI(PackageParser.Package pkg, boolean chatty) { |
| 3650 | if (chatty && Config.LOGD) Log.d( |
| 3651 | TAG, "Removing package " + pkg.applicationInfo.packageName ); |
| 3652 | |
| 3653 | synchronized (mPackages) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3654 | clearPackagePreferredActivitiesLP(pkg.packageName); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3656 | mPackages.remove(pkg.applicationInfo.packageName); |
| 3657 | if (pkg.mPath != null) { |
| 3658 | mAppDirs.remove(pkg.mPath); |
| 3659 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | PackageSetting ps = (PackageSetting)pkg.mExtras; |
| 3662 | if (ps != null && ps.sharedUser != null) { |
| 3663 | // XXX don't do this until the data is removed. |
| 3664 | if (false) { |
| 3665 | ps.sharedUser.packages.remove(ps); |
| 3666 | if (ps.sharedUser.packages.size() == 0) { |
| 3667 | // Remove. |
| 3668 | } |
| 3669 | } |
| 3670 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | int N = pkg.providers.size(); |
| 3673 | StringBuilder r = null; |
| 3674 | int i; |
| 3675 | for (i=0; i<N; i++) { |
| 3676 | PackageParser.Provider p = pkg.providers.get(i); |
| 3677 | mProvidersByComponent.remove(new ComponentName(p.info.packageName, |
| 3678 | p.info.name)); |
| 3679 | if (p.info.authority == null) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3681 | /* The is another ContentProvider with this authority when |
| 3682 | * this app was installed so this authority is null, |
| 3683 | * Ignore it as we don't have to unregister the provider. |
| 3684 | */ |
| 3685 | continue; |
| 3686 | } |
| 3687 | String names[] = p.info.authority.split(";"); |
| 3688 | for (int j = 0; j < names.length; j++) { |
| 3689 | if (mProviders.get(names[j]) == p) { |
| 3690 | mProviders.remove(names[j]); |
| 3691 | if (chatty && Config.LOGD) Log.d( |
| 3692 | TAG, "Unregistered content provider: " + names[j] + |
| 3693 | ", className = " + p.info.name + |
| 3694 | ", isSyncable = " + p.info.isSyncable); |
| 3695 | } |
| 3696 | } |
| 3697 | if (chatty) { |
| 3698 | if (r == null) { |
| 3699 | r = new StringBuilder(256); |
| 3700 | } else { |
| 3701 | r.append(' '); |
| 3702 | } |
| 3703 | r.append(p.info.name); |
| 3704 | } |
| 3705 | } |
| 3706 | if (r != null) { |
| 3707 | if (Config.LOGD) Log.d(TAG, " Providers: " + r); |
| 3708 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | N = pkg.services.size(); |
| 3711 | r = null; |
| 3712 | for (i=0; i<N; i++) { |
| 3713 | PackageParser.Service s = pkg.services.get(i); |
| 3714 | mServices.removeService(s); |
| 3715 | if (chatty) { |
| 3716 | if (r == null) { |
| 3717 | r = new StringBuilder(256); |
| 3718 | } else { |
| 3719 | r.append(' '); |
| 3720 | } |
| 3721 | r.append(s.info.name); |
| 3722 | } |
| 3723 | } |
| 3724 | if (r != null) { |
| 3725 | if (Config.LOGD) Log.d(TAG, " Services: " + r); |
| 3726 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3727 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3728 | N = pkg.receivers.size(); |
| 3729 | r = null; |
| 3730 | for (i=0; i<N; i++) { |
| 3731 | PackageParser.Activity a = pkg.receivers.get(i); |
| 3732 | mReceivers.removeActivity(a, "receiver"); |
| 3733 | if (chatty) { |
| 3734 | if (r == null) { |
| 3735 | r = new StringBuilder(256); |
| 3736 | } else { |
| 3737 | r.append(' '); |
| 3738 | } |
| 3739 | r.append(a.info.name); |
| 3740 | } |
| 3741 | } |
| 3742 | if (r != null) { |
| 3743 | if (Config.LOGD) Log.d(TAG, " Receivers: " + r); |
| 3744 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | N = pkg.activities.size(); |
| 3747 | r = null; |
| 3748 | for (i=0; i<N; i++) { |
| 3749 | PackageParser.Activity a = pkg.activities.get(i); |
| 3750 | mActivities.removeActivity(a, "activity"); |
| 3751 | if (chatty) { |
| 3752 | if (r == null) { |
| 3753 | r = new StringBuilder(256); |
| 3754 | } else { |
| 3755 | r.append(' '); |
| 3756 | } |
| 3757 | r.append(a.info.name); |
| 3758 | } |
| 3759 | } |
| 3760 | if (r != null) { |
| 3761 | if (Config.LOGD) Log.d(TAG, " Activities: " + r); |
| 3762 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3763 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3764 | N = pkg.permissions.size(); |
| 3765 | r = null; |
| 3766 | for (i=0; i<N; i++) { |
| 3767 | PackageParser.Permission p = pkg.permissions.get(i); |
| 3768 | boolean tree = false; |
| 3769 | BasePermission bp = mSettings.mPermissions.get(p.info.name); |
| 3770 | if (bp == null) { |
| 3771 | tree = true; |
| 3772 | bp = mSettings.mPermissionTrees.get(p.info.name); |
| 3773 | } |
| 3774 | if (bp != null && bp.perm == p) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3775 | bp.perm = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3776 | if (chatty) { |
| 3777 | if (r == null) { |
| 3778 | r = new StringBuilder(256); |
| 3779 | } else { |
| 3780 | r.append(' '); |
| 3781 | } |
| 3782 | r.append(p.info.name); |
| 3783 | } |
| 3784 | } |
| 3785 | } |
| 3786 | if (r != null) { |
| 3787 | if (Config.LOGD) Log.d(TAG, " Permissions: " + r); |
| 3788 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | N = pkg.instrumentation.size(); |
| 3791 | r = null; |
| 3792 | for (i=0; i<N; i++) { |
| 3793 | PackageParser.Instrumentation a = pkg.instrumentation.get(i); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 3794 | mInstrumentation.remove(a.getComponentName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3795 | if (chatty) { |
| 3796 | if (r == null) { |
| 3797 | r = new StringBuilder(256); |
| 3798 | } else { |
| 3799 | r.append(' '); |
| 3800 | } |
| 3801 | r.append(a.info.name); |
| 3802 | } |
| 3803 | } |
| 3804 | if (r != null) { |
| 3805 | if (Config.LOGD) Log.d(TAG, " Instrumentation: " + r); |
| 3806 | } |
| 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | private static final boolean isPackageFilename(String name) { |
| 3811 | return name != null && name.endsWith(".apk"); |
| 3812 | } |
| 3813 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3814 | private static boolean hasPermission(PackageParser.Package pkgInfo, String perm) { |
| 3815 | for (int i=pkgInfo.permissions.size()-1; i>=0; i--) { |
| 3816 | if (pkgInfo.permissions.get(i).info.name.equals(perm)) { |
| 3817 | return true; |
| 3818 | } |
| 3819 | } |
| 3820 | return false; |
| 3821 | } |
| 3822 | |
| 3823 | private void updatePermissionsLP(String changingPkg, |
| 3824 | PackageParser.Package pkgInfo, boolean grantPermissions, boolean replace) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3825 | // Make sure there are no dangling permission trees. |
| 3826 | Iterator<BasePermission> it = mSettings.mPermissionTrees |
| 3827 | .values().iterator(); |
| 3828 | while (it.hasNext()) { |
| 3829 | BasePermission bp = it.next(); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3830 | if (bp.packageSetting == null) { |
| 3831 | // We may not yet have parsed the package, so just see if |
| 3832 | // we still know about its settings. |
| 3833 | bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage); |
| 3834 | } |
| 3835 | if (bp.packageSetting == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3836 | Slog.w(TAG, "Removing dangling permission tree: " + bp.name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3837 | + " from package " + bp.sourcePackage); |
| 3838 | it.remove(); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3839 | } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) { |
| 3840 | if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) { |
| 3841 | Slog.i(TAG, "Removing old permission tree: " + bp.name |
| 3842 | + " from package " + bp.sourcePackage); |
| 3843 | grantPermissions = true; |
| 3844 | it.remove(); |
| 3845 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3846 | } |
| 3847 | } |
| 3848 | |
| 3849 | // Make sure all dynamic permissions have been assigned to a package, |
| 3850 | // and make sure there are no dangling permissions. |
| 3851 | it = mSettings.mPermissions.values().iterator(); |
| 3852 | while (it.hasNext()) { |
| 3853 | BasePermission bp = it.next(); |
| 3854 | if (bp.type == BasePermission.TYPE_DYNAMIC) { |
| 3855 | if (DEBUG_SETTINGS) Log.v(TAG, "Dynamic permission: name=" |
| 3856 | + bp.name + " pkg=" + bp.sourcePackage |
| 3857 | + " info=" + bp.pendingInfo); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3858 | if (bp.packageSetting == null && bp.pendingInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | BasePermission tree = findPermissionTreeLP(bp.name); |
| 3860 | if (tree != null) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3861 | bp.packageSetting = tree.packageSetting; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | bp.perm = new PackageParser.Permission(tree.perm.owner, |
| 3863 | new PermissionInfo(bp.pendingInfo)); |
| 3864 | bp.perm.info.packageName = tree.perm.info.packageName; |
| 3865 | bp.perm.info.name = bp.name; |
| 3866 | bp.uid = tree.uid; |
| 3867 | } |
| 3868 | } |
| 3869 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3870 | if (bp.packageSetting == null) { |
| 3871 | // We may not yet have parsed the package, so just see if |
| 3872 | // we still know about its settings. |
| 3873 | bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage); |
| 3874 | } |
| 3875 | if (bp.packageSetting == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 3876 | Slog.w(TAG, "Removing dangling permission: " + bp.name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | + " from package " + bp.sourcePackage); |
| 3878 | it.remove(); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3879 | } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) { |
| 3880 | if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) { |
| 3881 | Slog.i(TAG, "Removing old permission: " + bp.name |
| 3882 | + " from package " + bp.sourcePackage); |
| 3883 | grantPermissions = true; |
| 3884 | it.remove(); |
| 3885 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3886 | } |
| 3887 | } |
| 3888 | |
| 3889 | // Now update the permissions for all packages, in particular |
| 3890 | // replace the granted permissions of the system packages. |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3891 | if (grantPermissions) { |
| 3892 | for (PackageParser.Package pkg : mPackages.values()) { |
| 3893 | if (pkg != pkgInfo) { |
| 3894 | grantPermissionsLP(pkg, false); |
| 3895 | } |
| 3896 | } |
| 3897 | } |
| 3898 | |
| 3899 | if (pkgInfo != null) { |
| 3900 | grantPermissionsLP(pkgInfo, replace); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | } |
| 3902 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3903 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3904 | private void grantPermissionsLP(PackageParser.Package pkg, boolean replace) { |
| 3905 | final PackageSetting ps = (PackageSetting)pkg.mExtras; |
| 3906 | if (ps == null) { |
| 3907 | return; |
| 3908 | } |
| 3909 | final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3910 | boolean changedPermission = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3912 | if (replace) { |
| 3913 | ps.permissionsFixed = false; |
| 3914 | if (gp == ps) { |
| 3915 | gp.grantedPermissions.clear(); |
| 3916 | gp.gids = mGlobalGids; |
| 3917 | } |
| 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 | if (gp.gids == null) { |
| 3921 | gp.gids = mGlobalGids; |
| 3922 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3924 | final int N = pkg.requestedPermissions.size(); |
| 3925 | for (int i=0; i<N; i++) { |
| 3926 | String name = pkg.requestedPermissions.get(i); |
| 3927 | BasePermission bp = mSettings.mPermissions.get(name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3928 | if (false) { |
| 3929 | if (gp != ps) { |
| 3930 | Log.i(TAG, "Package " + pkg.packageName + " checking " + name |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3931 | + ": " + bp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3932 | } |
| 3933 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3934 | if (bp != null && bp.packageSetting != null) { |
| 3935 | final String perm = bp.name; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3936 | boolean allowed; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3937 | boolean allowedSig = false; |
| 3938 | if (bp.protectionLevel == PermissionInfo.PROTECTION_NORMAL |
| 3939 | || bp.protectionLevel == PermissionInfo.PROTECTION_DANGEROUS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3940 | allowed = true; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3941 | } else if (bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE |
| 3942 | || bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM) { |
| 3943 | allowed = (checkSignaturesLP(bp.packageSetting.signatures.mSignatures, pkg.mSignatures) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3944 | == PackageManager.SIGNATURE_MATCH) |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 3945 | || (checkSignaturesLP(mPlatformPackage.mSignatures, pkg.mSignatures) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3946 | == PackageManager.SIGNATURE_MATCH); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3947 | if (bp.protectionLevel == PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 3949 | // For updated system applications, the signatureOrSystem permission |
| 3950 | // is granted only if it had been defined by the original application. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3951 | if ((pkg.applicationInfo.flags |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3952 | & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { |
| 3953 | PackageSetting sysPs = mSettings.getDisabledSystemPkg(pkg.packageName); |
| 3954 | if(sysPs.grantedPermissions.contains(perm)) { |
| 3955 | allowed = true; |
| 3956 | } else { |
| 3957 | allowed = false; |
| 3958 | } |
| 3959 | } else { |
| 3960 | allowed = true; |
| 3961 | } |
| 3962 | } |
| 3963 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 3964 | if (allowed) { |
| 3965 | allowedSig = true; |
| 3966 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3967 | } else { |
| 3968 | allowed = false; |
| 3969 | } |
| 3970 | if (false) { |
| 3971 | if (gp != ps) { |
| 3972 | Log.i(TAG, "Package " + pkg.packageName + " granting " + perm); |
| 3973 | } |
| 3974 | } |
| 3975 | if (allowed) { |
| 3976 | if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0 |
| 3977 | && ps.permissionsFixed) { |
| 3978 | // If this is an existing, non-system package, then |
| 3979 | // we can't add any new permissions to it. |
Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 3980 | if (!allowedSig && !gp.grantedPermissions.contains(perm)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3981 | allowed = false; |
Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 3982 | // Except... if this is a permission that was added |
| 3983 | // to the platform (note: need to only do this when |
| 3984 | // updating the platform). |
| 3985 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
| 3986 | for (int ip=0; ip<NP; ip++) { |
| 3987 | final PackageParser.NewPermissionInfo npi |
| 3988 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 3989 | if (npi.name.equals(perm) |
| 3990 | && pkg.applicationInfo.targetSdkVersion < npi.sdkVersion) { |
| 3991 | allowed = true; |
Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 3992 | Log.i(TAG, "Auto-granting " + perm + " to old pkg " |
Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 3993 | + pkg.packageName); |
| 3994 | break; |
| 3995 | } |
| 3996 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3997 | } |
| 3998 | } |
| 3999 | if (allowed) { |
| 4000 | if (!gp.grantedPermissions.contains(perm)) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4001 | changedPermission = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4002 | gp.grantedPermissions.add(perm); |
| 4003 | gp.gids = appendInts(gp.gids, bp.gids); |
Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 4004 | } else if (!ps.haveGids) { |
| 4005 | gp.gids = appendInts(gp.gids, bp.gids); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4006 | } |
| 4007 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4008 | Slog.w(TAG, "Not granting permission " + perm |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4009 | + " to package " + pkg.packageName |
| 4010 | + " because it was previously installed without"); |
| 4011 | } |
| 4012 | } else { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4013 | if (gp.grantedPermissions.remove(perm)) { |
| 4014 | changedPermission = true; |
| 4015 | gp.gids = removeInts(gp.gids, bp.gids); |
| 4016 | Slog.i(TAG, "Un-granting permission " + perm |
| 4017 | + " from package " + pkg.packageName |
| 4018 | + " (protectionLevel=" + bp.protectionLevel |
| 4019 | + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags) |
| 4020 | + ")"); |
| 4021 | } else { |
| 4022 | Slog.w(TAG, "Not granting permission " + perm |
| 4023 | + " to package " + pkg.packageName |
| 4024 | + " (protectionLevel=" + bp.protectionLevel |
| 4025 | + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags) |
| 4026 | + ")"); |
| 4027 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | } |
| 4029 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4030 | Slog.w(TAG, "Unknown permission " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4031 | + " in package " + pkg.packageName); |
| 4032 | } |
| 4033 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4034 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4035 | if ((changedPermission || replace) && !ps.permissionsFixed && |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 4036 | ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) || |
| 4037 | ((ps.pkgFlags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)){ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4038 | // This is the first that we have heard about this package, so the |
| 4039 | // permissions we have now selected are fixed until explicitly |
| 4040 | // changed. |
| 4041 | ps.permissionsFixed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4042 | } |
Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 4043 | ps.haveGids = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4044 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4046 | private final class ActivityIntentResolver |
| 4047 | extends IntentResolver<PackageParser.ActivityIntentInfo, ResolveInfo> { |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4048 | public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4049 | mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0; |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4050 | return super.queryIntent(intent, resolvedType, defaultOnly); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4051 | } |
| 4052 | |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4053 | public List queryIntent(Intent intent, String resolvedType, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4054 | mFlags = flags; |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4055 | return super.queryIntent(intent, resolvedType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4056 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 4057 | } |
| 4058 | |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4059 | public List queryIntentForPackage(Intent intent, String resolvedType, int flags, |
| 4060 | ArrayList<PackageParser.Activity> packageActivities) { |
| 4061 | if (packageActivities == null) { |
| 4062 | return null; |
| 4063 | } |
| 4064 | mFlags = flags; |
| 4065 | final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0; |
| 4066 | int N = packageActivities.size(); |
| 4067 | ArrayList<ArrayList<PackageParser.ActivityIntentInfo>> listCut = |
| 4068 | new ArrayList<ArrayList<PackageParser.ActivityIntentInfo>>(N); |
Mihai Preda | c3320db | 2009-05-18 20:15:32 +0200 | [diff] [blame] | 4069 | |
| 4070 | ArrayList<PackageParser.ActivityIntentInfo> intentFilters; |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4071 | for (int i = 0; i < N; ++i) { |
Mihai Preda | c3320db | 2009-05-18 20:15:32 +0200 | [diff] [blame] | 4072 | intentFilters = packageActivities.get(i).intents; |
| 4073 | if (intentFilters != null && intentFilters.size() > 0) { |
| 4074 | listCut.add(intentFilters); |
| 4075 | } |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4076 | } |
| 4077 | return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut); |
| 4078 | } |
| 4079 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4080 | public final void addActivity(PackageParser.Activity a, String type) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4081 | mActivities.put(a.getComponentName(), a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4082 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4083 | TAG, " " + type + " " + |
| 4084 | (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":"); |
| 4085 | if (SHOW_INFO || Config.LOGV) Log.v(TAG, " Class=" + a.info.name); |
| 4086 | int NI = a.intents.size(); |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4087 | for (int j=0; j<NI; j++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4088 | PackageParser.ActivityIntentInfo intent = a.intents.get(j); |
| 4089 | if (SHOW_INFO || Config.LOGV) { |
| 4090 | Log.v(TAG, " IntentFilter:"); |
| 4091 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4092 | } |
| 4093 | if (!intent.debugCheck()) { |
| 4094 | Log.w(TAG, "==> For Activity " + a.info.name); |
| 4095 | } |
| 4096 | addFilter(intent); |
| 4097 | } |
| 4098 | } |
| 4099 | |
| 4100 | public final void removeActivity(PackageParser.Activity a, String type) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4101 | mActivities.remove(a.getComponentName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4102 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4103 | TAG, " " + type + " " + |
| 4104 | (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":"); |
| 4105 | if (SHOW_INFO || Config.LOGV) Log.v(TAG, " Class=" + a.info.name); |
| 4106 | int NI = a.intents.size(); |
Mihai Preda | eae850c | 2009-05-13 10:13:48 +0200 | [diff] [blame] | 4107 | for (int j=0; j<NI; j++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4108 | PackageParser.ActivityIntentInfo intent = a.intents.get(j); |
| 4109 | if (SHOW_INFO || Config.LOGV) { |
| 4110 | Log.v(TAG, " IntentFilter:"); |
| 4111 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4112 | } |
| 4113 | removeFilter(intent); |
| 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | @Override |
| 4118 | protected boolean allowFilterResult( |
| 4119 | PackageParser.ActivityIntentInfo filter, List<ResolveInfo> dest) { |
| 4120 | ActivityInfo filterAi = filter.activity.info; |
| 4121 | for (int i=dest.size()-1; i>=0; i--) { |
| 4122 | ActivityInfo destAi = dest.get(i).activityInfo; |
| 4123 | if (destAi.name == filterAi.name |
| 4124 | && destAi.packageName == filterAi.packageName) { |
| 4125 | return false; |
| 4126 | } |
| 4127 | } |
| 4128 | return true; |
| 4129 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4131 | @Override |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4132 | protected String packageForFilter(PackageParser.ActivityIntentInfo info) { |
| 4133 | return info.activity.owner.packageName; |
| 4134 | } |
| 4135 | |
| 4136 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4137 | protected ResolveInfo newResult(PackageParser.ActivityIntentInfo info, |
| 4138 | int match) { |
| 4139 | if (!mSettings.isEnabledLP(info.activity.info, mFlags)) { |
| 4140 | return null; |
| 4141 | } |
| 4142 | final PackageParser.Activity activity = info.activity; |
| 4143 | if (mSafeMode && (activity.info.applicationInfo.flags |
| 4144 | &ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 4145 | return null; |
| 4146 | } |
| 4147 | final ResolveInfo res = new ResolveInfo(); |
| 4148 | res.activityInfo = PackageParser.generateActivityInfo(activity, |
| 4149 | mFlags); |
| 4150 | if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) { |
| 4151 | res.filter = info; |
| 4152 | } |
| 4153 | res.priority = info.getPriority(); |
| 4154 | res.preferredOrder = activity.owner.mPreferredOrder; |
| 4155 | //System.out.println("Result: " + res.activityInfo.className + |
| 4156 | // " = " + res.priority); |
| 4157 | res.match = match; |
| 4158 | res.isDefault = info.hasDefault; |
| 4159 | res.labelRes = info.labelRes; |
| 4160 | res.nonLocalizedLabel = info.nonLocalizedLabel; |
| 4161 | res.icon = info.icon; |
| 4162 | return res; |
| 4163 | } |
| 4164 | |
| 4165 | @Override |
| 4166 | protected void sortResults(List<ResolveInfo> results) { |
| 4167 | Collections.sort(results, mResolvePrioritySorter); |
| 4168 | } |
| 4169 | |
| 4170 | @Override |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4171 | protected void dumpFilter(PrintWriter out, String prefix, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | PackageParser.ActivityIntentInfo filter) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4173 | out.print(prefix); out.print( |
| 4174 | Integer.toHexString(System.identityHashCode(filter.activity))); |
| 4175 | out.print(' '); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4176 | out.print(filter.activity.getComponentShortName()); |
| 4177 | out.print(" filter "); |
| 4178 | out.println(Integer.toHexString(System.identityHashCode(filter))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | // List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) { |
| 4182 | // final Iterator<ResolveInfo> i = resolveInfoList.iterator(); |
| 4183 | // final List<ResolveInfo> retList = Lists.newArrayList(); |
| 4184 | // while (i.hasNext()) { |
| 4185 | // final ResolveInfo resolveInfo = i.next(); |
| 4186 | // if (isEnabledLP(resolveInfo.activityInfo)) { |
| 4187 | // retList.add(resolveInfo); |
| 4188 | // } |
| 4189 | // } |
| 4190 | // return retList; |
| 4191 | // } |
| 4192 | |
| 4193 | // Keys are String (activity class name), values are Activity. |
| 4194 | private final HashMap<ComponentName, PackageParser.Activity> mActivities |
| 4195 | = new HashMap<ComponentName, PackageParser.Activity>(); |
| 4196 | private int mFlags; |
| 4197 | } |
| 4198 | |
| 4199 | private final class ServiceIntentResolver |
| 4200 | extends IntentResolver<PackageParser.ServiceIntentInfo, ResolveInfo> { |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4201 | public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0; |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4203 | return super.queryIntent(intent, resolvedType, defaultOnly); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4204 | } |
| 4205 | |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4206 | public List queryIntent(Intent intent, String resolvedType, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4207 | mFlags = flags; |
Mihai Preda | 074edef | 2009-05-18 17:13:31 +0200 | [diff] [blame] | 4208 | return super.queryIntent(intent, resolvedType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0); |
| 4210 | } |
| 4211 | |
Dianne Hackborn | c14b9cc | 2009-06-17 18:02:12 -0700 | [diff] [blame] | 4212 | public List queryIntentForPackage(Intent intent, String resolvedType, int flags, |
| 4213 | ArrayList<PackageParser.Service> packageServices) { |
| 4214 | if (packageServices == null) { |
| 4215 | return null; |
| 4216 | } |
| 4217 | mFlags = flags; |
| 4218 | final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0; |
| 4219 | int N = packageServices.size(); |
| 4220 | ArrayList<ArrayList<PackageParser.ServiceIntentInfo>> listCut = |
| 4221 | new ArrayList<ArrayList<PackageParser.ServiceIntentInfo>>(N); |
| 4222 | |
| 4223 | ArrayList<PackageParser.ServiceIntentInfo> intentFilters; |
| 4224 | for (int i = 0; i < N; ++i) { |
| 4225 | intentFilters = packageServices.get(i).intents; |
| 4226 | if (intentFilters != null && intentFilters.size() > 0) { |
| 4227 | listCut.add(intentFilters); |
| 4228 | } |
| 4229 | } |
| 4230 | return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut); |
| 4231 | } |
| 4232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | public final void addService(PackageParser.Service s) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4234 | mServices.put(s.getComponentName(), s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4235 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4236 | TAG, " " + (s.info.nonLocalizedLabel != null |
| 4237 | ? s.info.nonLocalizedLabel : s.info.name) + ":"); |
| 4238 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4239 | TAG, " Class=" + s.info.name); |
| 4240 | int NI = s.intents.size(); |
| 4241 | int j; |
| 4242 | for (j=0; j<NI; j++) { |
| 4243 | PackageParser.ServiceIntentInfo intent = s.intents.get(j); |
| 4244 | if (SHOW_INFO || Config.LOGV) { |
| 4245 | Log.v(TAG, " IntentFilter:"); |
| 4246 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4247 | } |
| 4248 | if (!intent.debugCheck()) { |
| 4249 | Log.w(TAG, "==> For Service " + s.info.name); |
| 4250 | } |
| 4251 | addFilter(intent); |
| 4252 | } |
| 4253 | } |
| 4254 | |
| 4255 | public final void removeService(PackageParser.Service s) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 4256 | mServices.remove(s.getComponentName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4257 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4258 | TAG, " " + (s.info.nonLocalizedLabel != null |
| 4259 | ? s.info.nonLocalizedLabel : s.info.name) + ":"); |
| 4260 | if (SHOW_INFO || Config.LOGV) Log.v( |
| 4261 | TAG, " Class=" + s.info.name); |
| 4262 | int NI = s.intents.size(); |
| 4263 | int j; |
| 4264 | for (j=0; j<NI; j++) { |
| 4265 | PackageParser.ServiceIntentInfo intent = s.intents.get(j); |
| 4266 | if (SHOW_INFO || Config.LOGV) { |
| 4267 | Log.v(TAG, " IntentFilter:"); |
| 4268 | intent.dump(new LogPrinter(Log.VERBOSE, TAG), " "); |
| 4269 | } |
| 4270 | removeFilter(intent); |
| 4271 | } |
| 4272 | } |
| 4273 | |
| 4274 | @Override |
| 4275 | protected boolean allowFilterResult( |
| 4276 | PackageParser.ServiceIntentInfo filter, List<ResolveInfo> dest) { |
| 4277 | ServiceInfo filterSi = filter.service.info; |
| 4278 | for (int i=dest.size()-1; i>=0; i--) { |
| 4279 | ServiceInfo destAi = dest.get(i).serviceInfo; |
| 4280 | if (destAi.name == filterSi.name |
| 4281 | && destAi.packageName == filterSi.packageName) { |
| 4282 | return false; |
| 4283 | } |
| 4284 | } |
| 4285 | return true; |
| 4286 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | @Override |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4289 | protected String packageForFilter(PackageParser.ServiceIntentInfo info) { |
| 4290 | return info.service.owner.packageName; |
| 4291 | } |
| 4292 | |
| 4293 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4294 | protected ResolveInfo newResult(PackageParser.ServiceIntentInfo filter, |
| 4295 | int match) { |
| 4296 | final PackageParser.ServiceIntentInfo info = (PackageParser.ServiceIntentInfo)filter; |
| 4297 | if (!mSettings.isEnabledLP(info.service.info, mFlags)) { |
| 4298 | return null; |
| 4299 | } |
| 4300 | final PackageParser.Service service = info.service; |
| 4301 | if (mSafeMode && (service.info.applicationInfo.flags |
| 4302 | &ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 4303 | return null; |
| 4304 | } |
| 4305 | final ResolveInfo res = new ResolveInfo(); |
| 4306 | res.serviceInfo = PackageParser.generateServiceInfo(service, |
| 4307 | mFlags); |
| 4308 | if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) { |
| 4309 | res.filter = filter; |
| 4310 | } |
| 4311 | res.priority = info.getPriority(); |
| 4312 | res.preferredOrder = service.owner.mPreferredOrder; |
| 4313 | //System.out.println("Result: " + res.activityInfo.className + |
| 4314 | // " = " + res.priority); |
| 4315 | res.match = match; |
| 4316 | res.isDefault = info.hasDefault; |
| 4317 | res.labelRes = info.labelRes; |
| 4318 | res.nonLocalizedLabel = info.nonLocalizedLabel; |
| 4319 | res.icon = info.icon; |
| 4320 | return res; |
| 4321 | } |
| 4322 | |
| 4323 | @Override |
| 4324 | protected void sortResults(List<ResolveInfo> results) { |
| 4325 | Collections.sort(results, mResolvePrioritySorter); |
| 4326 | } |
| 4327 | |
| 4328 | @Override |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4329 | protected void dumpFilter(PrintWriter out, String prefix, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4330 | PackageParser.ServiceIntentInfo filter) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 4331 | out.print(prefix); out.print( |
| 4332 | Integer.toHexString(System.identityHashCode(filter.service))); |
| 4333 | out.print(' '); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4334 | out.print(filter.service.getComponentShortName()); |
| 4335 | out.print(" filter "); |
| 4336 | out.println(Integer.toHexString(System.identityHashCode(filter))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | // List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) { |
| 4340 | // final Iterator<ResolveInfo> i = resolveInfoList.iterator(); |
| 4341 | // final List<ResolveInfo> retList = Lists.newArrayList(); |
| 4342 | // while (i.hasNext()) { |
| 4343 | // final ResolveInfo resolveInfo = (ResolveInfo) i; |
| 4344 | // if (isEnabledLP(resolveInfo.serviceInfo)) { |
| 4345 | // retList.add(resolveInfo); |
| 4346 | // } |
| 4347 | // } |
| 4348 | // return retList; |
| 4349 | // } |
| 4350 | |
| 4351 | // Keys are String (activity class name), values are Activity. |
| 4352 | private final HashMap<ComponentName, PackageParser.Service> mServices |
| 4353 | = new HashMap<ComponentName, PackageParser.Service>(); |
| 4354 | private int mFlags; |
| 4355 | }; |
| 4356 | |
| 4357 | private static final Comparator<ResolveInfo> mResolvePrioritySorter = |
| 4358 | new Comparator<ResolveInfo>() { |
| 4359 | public int compare(ResolveInfo r1, ResolveInfo r2) { |
| 4360 | int v1 = r1.priority; |
| 4361 | int v2 = r2.priority; |
| 4362 | //System.out.println("Comparing: q1=" + q1 + " q2=" + q2); |
| 4363 | if (v1 != v2) { |
| 4364 | return (v1 > v2) ? -1 : 1; |
| 4365 | } |
| 4366 | v1 = r1.preferredOrder; |
| 4367 | v2 = r2.preferredOrder; |
| 4368 | if (v1 != v2) { |
| 4369 | return (v1 > v2) ? -1 : 1; |
| 4370 | } |
| 4371 | if (r1.isDefault != r2.isDefault) { |
| 4372 | return r1.isDefault ? -1 : 1; |
| 4373 | } |
| 4374 | v1 = r1.match; |
| 4375 | v2 = r2.match; |
| 4376 | //System.out.println("Comparing: m1=" + m1 + " m2=" + m2); |
| 4377 | return (v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0); |
| 4378 | } |
| 4379 | }; |
| 4380 | |
| 4381 | private static final Comparator<ProviderInfo> mProviderInitOrderSorter = |
| 4382 | new Comparator<ProviderInfo>() { |
| 4383 | public int compare(ProviderInfo p1, ProviderInfo p2) { |
| 4384 | final int v1 = p1.initOrder; |
| 4385 | final int v2 = p2.initOrder; |
| 4386 | return (v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0); |
| 4387 | } |
| 4388 | }; |
| 4389 | |
| 4390 | private static final void sendPackageBroadcast(String action, String pkg, Bundle extras) { |
| 4391 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 4392 | if (am != null) { |
| 4393 | try { |
| 4394 | final Intent intent = new Intent(action, |
| 4395 | pkg != null ? Uri.fromParts("package", pkg, null) : null); |
| 4396 | if (extras != null) { |
| 4397 | intent.putExtras(extras); |
| 4398 | } |
Dianne Hackborn | de7faf6 | 2009-06-30 13:27:30 -0700 | [diff] [blame] | 4399 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4400 | am.broadcastIntent( |
| 4401 | null, intent, |
| 4402 | null, null, 0, null, null, null, false, false); |
| 4403 | } catch (RemoteException ex) { |
| 4404 | } |
| 4405 | } |
| 4406 | } |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 4407 | |
| 4408 | public String nextPackageToClean(String lastPackage) { |
| 4409 | synchronized (mPackages) { |
| 4410 | if (!mMediaMounted) { |
| 4411 | // If the external storage is no longer mounted at this point, |
| 4412 | // the caller may not have been able to delete all of this |
| 4413 | // packages files and can not delete any more. Bail. |
| 4414 | return null; |
| 4415 | } |
| 4416 | if (lastPackage != null) { |
| 4417 | mSettings.mPackagesToBeCleaned.remove(lastPackage); |
| 4418 | } |
| 4419 | return mSettings.mPackagesToBeCleaned.size() > 0 |
| 4420 | ? mSettings.mPackagesToBeCleaned.get(0) : null; |
| 4421 | } |
| 4422 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 4424 | void schedulePackageCleaning(String packageName) { |
| 4425 | mHandler.sendMessage(mHandler.obtainMessage(START_CLEANING_PACKAGE, packageName)); |
| 4426 | } |
| 4427 | |
| 4428 | void startCleaningPackages() { |
| 4429 | synchronized (mPackages) { |
| 4430 | if (!mMediaMounted) { |
| 4431 | return; |
| 4432 | } |
| 4433 | if (mSettings.mPackagesToBeCleaned.size() <= 0) { |
| 4434 | return; |
| 4435 | } |
| 4436 | } |
| 4437 | Intent intent = new Intent(PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE); |
| 4438 | intent.setComponent(DEFAULT_CONTAINER_COMPONENT); |
| 4439 | IActivityManager am = ActivityManagerNative.getDefault(); |
| 4440 | if (am != null) { |
| 4441 | try { |
| 4442 | am.startService(null, intent, null); |
| 4443 | } catch (RemoteException e) { |
| 4444 | } |
| 4445 | } |
| 4446 | } |
| 4447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | private final class AppDirObserver extends FileObserver { |
| 4449 | public AppDirObserver(String path, int mask, boolean isrom) { |
| 4450 | super(path, mask); |
| 4451 | mRootDir = path; |
| 4452 | mIsRom = isrom; |
| 4453 | } |
| 4454 | |
| 4455 | public void onEvent(int event, String path) { |
| 4456 | String removedPackage = null; |
| 4457 | int removedUid = -1; |
| 4458 | String addedPackage = null; |
| 4459 | int addedUid = -1; |
| 4460 | |
| 4461 | synchronized (mInstallLock) { |
| 4462 | String fullPathStr = null; |
| 4463 | File fullPath = null; |
| 4464 | if (path != null) { |
| 4465 | fullPath = new File(mRootDir, path); |
| 4466 | fullPathStr = fullPath.getPath(); |
| 4467 | } |
| 4468 | |
| 4469 | if (Config.LOGV) Log.v( |
| 4470 | TAG, "File " + fullPathStr + " changed: " |
| 4471 | + Integer.toHexString(event)); |
| 4472 | |
| 4473 | if (!isPackageFilename(path)) { |
| 4474 | if (Config.LOGV) Log.v( |
| 4475 | TAG, "Ignoring change of non-package file: " + fullPathStr); |
| 4476 | return; |
| 4477 | } |
| 4478 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4479 | // Ignore packages that are being installed or |
| 4480 | // have just been installed. |
| 4481 | if (ignoreCodePath(fullPathStr)) { |
| 4482 | return; |
| 4483 | } |
| 4484 | PackageParser.Package p = null; |
| 4485 | synchronized (mPackages) { |
| 4486 | p = mAppDirs.get(fullPathStr); |
| 4487 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | if ((event&REMOVE_EVENTS) != 0) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4489 | if (p != null) { |
| 4490 | removePackageLI(p, true); |
| 4491 | removedPackage = p.applicationInfo.packageName; |
| 4492 | removedUid = p.applicationInfo.uid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4493 | } |
| 4494 | } |
| 4495 | |
| 4496 | if ((event&ADD_EVENTS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4497 | if (p == null) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 4498 | p = scanPackageLI(fullPath, |
Dianne Hackborn | 806da1d | 2010-03-18 16:50:07 -0700 | [diff] [blame] | 4499 | (mIsRom ? PackageParser.PARSE_IS_SYSTEM |
| 4500 | | PackageParser.PARSE_IS_SYSTEM_DIR: 0) | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4501 | PackageParser.PARSE_CHATTY | |
| 4502 | PackageParser.PARSE_MUST_BE_APK, |
Andrew Stadler | 48c0273 | 2010-01-15 00:03:41 -0800 | [diff] [blame] | 4503 | SCAN_MONITOR | SCAN_NO_PATHS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4504 | if (p != null) { |
| 4505 | synchronized (mPackages) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 4506 | updatePermissionsLP(p.packageName, p, |
| 4507 | p.permissions.size() > 0, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4508 | } |
| 4509 | addedPackage = p.applicationInfo.packageName; |
| 4510 | addedUid = p.applicationInfo.uid; |
| 4511 | } |
| 4512 | } |
| 4513 | } |
| 4514 | |
| 4515 | synchronized (mPackages) { |
| 4516 | mSettings.writeLP(); |
| 4517 | } |
| 4518 | } |
| 4519 | |
| 4520 | if (removedPackage != null) { |
| 4521 | Bundle extras = new Bundle(1); |
| 4522 | extras.putInt(Intent.EXTRA_UID, removedUid); |
| 4523 | extras.putBoolean(Intent.EXTRA_DATA_REMOVED, false); |
| 4524 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage, extras); |
| 4525 | } |
| 4526 | if (addedPackage != null) { |
| 4527 | Bundle extras = new Bundle(1); |
| 4528 | extras.putInt(Intent.EXTRA_UID, addedUid); |
| 4529 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, addedPackage, extras); |
| 4530 | } |
| 4531 | } |
| 4532 | |
| 4533 | private final String mRootDir; |
| 4534 | private final boolean mIsRom; |
| 4535 | } |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4537 | /* Called when a downloaded package installation has been confirmed by the user */ |
| 4538 | public void installPackage( |
| 4539 | final Uri packageURI, final IPackageInstallObserver observer, final int flags) { |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4540 | installPackage(packageURI, observer, flags, null); |
| 4541 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4542 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 4543 | /* Called when a downloaded package installation has been confirmed by the user */ |
| 4544 | public void installPackage( |
| 4545 | final Uri packageURI, final IPackageInstallObserver observer, final int flags, |
| 4546 | final String installerPackageName) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4547 | mContext.enforceCallingOrSelfPermission( |
| 4548 | android.Manifest.permission.INSTALL_PACKAGES, null); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4549 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4550 | Message msg = mHandler.obtainMessage(INIT_COPY); |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4551 | msg.obj = new InstallParams(packageURI, observer, flags, |
| 4552 | installerPackageName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4553 | mHandler.sendMessage(msg); |
| 4554 | } |
| 4555 | |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4556 | public void finishPackageInstall(int token) { |
| 4557 | if (DEBUG_INSTALL) Log.v(TAG, "BM finishing package install for " + token); |
| 4558 | Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0); |
| 4559 | mHandler.sendMessage(msg); |
| 4560 | } |
| 4561 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4562 | private void processPendingInstall(final InstallArgs args, final int currentStatus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4563 | // Queue up an async operation since the package installation may take a little while. |
| 4564 | mHandler.post(new Runnable() { |
| 4565 | public void run() { |
| 4566 | mHandler.removeCallbacks(this); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4567 | // Result object to be returned |
| 4568 | PackageInstalledInfo res = new PackageInstalledInfo(); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4569 | res.returnCode = currentStatus; |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4570 | res.uid = -1; |
| 4571 | res.pkg = null; |
| 4572 | res.removedInfo = new PackageRemovedInfo(); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4573 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) { |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4574 | args.doPreInstall(res.returnCode); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4575 | synchronized (mInstallLock) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4576 | installPackageLI(args, true, res); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 4577 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4578 | args.doPostInstall(res.returnCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | } |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4580 | |
| 4581 | // A restore should be performed at this point if (a) the install |
| 4582 | // succeeded, (b) the operation is not an update, and (c) the new |
| 4583 | // package has a backupAgent defined. |
| 4584 | final boolean update = res.removedInfo.removedPackage != null; |
Christopher Tate | 59eac4b | 2010-02-19 19:25:45 -0800 | [diff] [blame] | 4585 | boolean doRestore = (!update |
| 4586 | && res.pkg != null |
| 4587 | && res.pkg.applicationInfo.backupAgentName != null); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4588 | |
| 4589 | // Set up the post-install work request bookkeeping. This will be used |
| 4590 | // and cleaned up by the post-install event handling regardless of whether |
| 4591 | // there's a restore pass performed. Token values are >= 1. |
| 4592 | int token; |
| 4593 | if (mNextInstallToken < 0) mNextInstallToken = 1; |
| 4594 | token = mNextInstallToken++; |
| 4595 | |
| 4596 | PostInstallData data = new PostInstallData(args, res); |
| 4597 | mRunningInstalls.put(token, data); |
| 4598 | if (DEBUG_INSTALL) Log.v(TAG, "+ starting restore round-trip " + token); |
| 4599 | |
| 4600 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED && doRestore) { |
| 4601 | // Pass responsibility to the Backup Manager. It will perform a |
| 4602 | // restore if appropriate, then pass responsibility back to the |
| 4603 | // Package Manager to run the post-install observer callbacks |
| 4604 | // and broadcasts. |
| 4605 | IBackupManager bm = IBackupManager.Stub.asInterface( |
| 4606 | ServiceManager.getService(Context.BACKUP_SERVICE)); |
| 4607 | if (bm != null) { |
| 4608 | if (DEBUG_INSTALL) Log.v(TAG, "token " + token |
| 4609 | + " to BM for possible restore"); |
| 4610 | try { |
| 4611 | bm.restoreAtInstall(res.pkg.applicationInfo.packageName, token); |
| 4612 | } catch (RemoteException e) { |
| 4613 | // can't happen; the backup manager is local |
| 4614 | } catch (Exception e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4615 | Slog.e(TAG, "Exception trying to enqueue restore", e); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4616 | doRestore = false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4617 | } |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4618 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4619 | Slog.e(TAG, "Backup Manager not found!"); |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4620 | doRestore = false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4621 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4622 | } |
Christopher Tate | 1bb6906 | 2010-02-19 17:02:12 -0800 | [diff] [blame] | 4623 | |
| 4624 | if (!doRestore) { |
| 4625 | // No restore possible, or the Backup Manager was mysteriously not |
| 4626 | // available -- just fire the post-install work request directly. |
| 4627 | if (DEBUG_INSTALL) Log.v(TAG, "No restore - queue post-install for " + token); |
| 4628 | Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0); |
| 4629 | mHandler.sendMessage(msg); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4630 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4631 | } |
| 4632 | }); |
| 4633 | } |
| 4634 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4635 | abstract class HandlerParams { |
| 4636 | final static int MAX_RETRIES = 4; |
| 4637 | int retry = 0; |
| 4638 | final void startCopy() { |
| 4639 | try { |
| 4640 | if (DEBUG_SD_INSTALL) Log.i(TAG, "startCopy"); |
| 4641 | retry++; |
| 4642 | if (retry > MAX_RETRIES) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4643 | 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] | 4644 | mHandler.sendEmptyMessage(MCS_GIVE_UP); |
| 4645 | handleServiceError(); |
| 4646 | return; |
| 4647 | } else { |
| 4648 | handleStartCopy(); |
| 4649 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Posting install MCS_UNBIND"); |
| 4650 | mHandler.sendEmptyMessage(MCS_UNBIND); |
| 4651 | } |
| 4652 | } catch (RemoteException e) { |
| 4653 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Posting install MCS_RECONNECT"); |
| 4654 | mHandler.sendEmptyMessage(MCS_RECONNECT); |
| 4655 | } |
| 4656 | handleReturnCode(); |
| 4657 | } |
| 4658 | |
| 4659 | final void serviceError() { |
| 4660 | if (DEBUG_SD_INSTALL) Log.i(TAG, "serviceError"); |
| 4661 | handleServiceError(); |
| 4662 | handleReturnCode(); |
| 4663 | } |
| 4664 | abstract void handleStartCopy() throws RemoteException; |
| 4665 | abstract void handleServiceError(); |
| 4666 | abstract void handleReturnCode(); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4667 | } |
| 4668 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4669 | class InstallParams extends HandlerParams { |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4670 | final IPackageInstallObserver observer; |
| 4671 | int flags; |
| 4672 | final Uri packageURI; |
| 4673 | final String installerPackageName; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4674 | private InstallArgs mArgs; |
| 4675 | private int mRet; |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4676 | InstallParams(Uri packageURI, |
| 4677 | IPackageInstallObserver observer, int flags, |
| 4678 | String installerPackageName) { |
| 4679 | this.packageURI = packageURI; |
| 4680 | this.flags = flags; |
| 4681 | this.observer = observer; |
| 4682 | this.installerPackageName = installerPackageName; |
| 4683 | } |
| 4684 | |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4685 | private int installLocationPolicy(PackageInfoLite pkgLite, int flags) { |
| 4686 | String packageName = pkgLite.packageName; |
| 4687 | int installLocation = pkgLite.installLocation; |
| 4688 | boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0; |
| 4689 | synchronized (mPackages) { |
| 4690 | PackageParser.Package pkg = mPackages.get(packageName); |
| 4691 | if (pkg != null) { |
| 4692 | if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
| 4693 | // Check for updated system application. |
| 4694 | if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 4695 | if (onSd) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4696 | Slog.w(TAG, "Cannot install update to system app on sdcard"); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4697 | return PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION; |
| 4698 | } |
| 4699 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
| 4700 | } else { |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4701 | if (onSd) { |
| 4702 | // Install flag overrides everything. |
| 4703 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4704 | } |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4705 | // If current upgrade specifies particular preference |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4706 | if (installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) { |
| 4707 | // Application explicitly specified internal. |
| 4708 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
| 4709 | } else if (installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) { |
| 4710 | // App explictly prefers external. Let policy decide |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4711 | } else { |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4712 | // Prefer previous location |
Suchi Amalapurapu | 90d8ee6 | 2010-03-18 11:38:35 -0700 | [diff] [blame] | 4713 | if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) { |
| 4714 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4715 | } |
| 4716 | return PackageHelper.RECOMMEND_INSTALL_INTERNAL; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4717 | } |
| 4718 | } |
| 4719 | } else { |
| 4720 | // Invalid install. Return error code |
| 4721 | return PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS; |
| 4722 | } |
| 4723 | } |
| 4724 | } |
| 4725 | // All the special cases have been taken care of. |
| 4726 | // Return result based on recommended install location. |
| 4727 | if (onSd) { |
| 4728 | return PackageHelper.RECOMMEND_INSTALL_EXTERNAL; |
| 4729 | } |
| 4730 | return pkgLite.recommendedInstallLocation; |
| 4731 | } |
| 4732 | |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4733 | /* |
| 4734 | * Invoke remote method to get package information and install |
| 4735 | * location values. Override install location based on default |
| 4736 | * policy if needed and then create install arguments based |
| 4737 | * on the install location. |
| 4738 | */ |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4739 | public void handleStartCopy() throws RemoteException { |
Suchi Amalapurapu | 1f9e1b4 | 2010-02-26 13:14:31 -0800 | [diff] [blame] | 4740 | int ret = PackageManager.INSTALL_SUCCEEDED; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4741 | boolean fwdLocked = (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0; |
| 4742 | boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0; |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4743 | boolean onInt = (flags & PackageManager.INSTALL_INTERNAL) != 0; |
| 4744 | if (onInt && onSd) { |
| 4745 | // Check if both bits are set. |
| 4746 | Slog.w(TAG, "Conflicting flags specified for installing on both internal and external"); |
| 4747 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 4748 | } else if (fwdLocked && onSd) { |
| 4749 | // Check for forward locked apps |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4750 | Slog.w(TAG, "Cannot install fwd locked apps on sdcard"); |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4751 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4752 | } else { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4753 | // Remote call to find out default install location |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4754 | PackageInfoLite pkgLite = mContainerService.getMinimalPackageInfo(packageURI, flags); |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4755 | int loc = pkgLite.recommendedInstallLocation; |
Suchi Amalapurapu | a2b6c37 | 2010-03-05 17:40:11 -0800 | [diff] [blame] | 4756 | if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION){ |
| 4757 | ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 4758 | } else if (loc == PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS){ |
| 4759 | ret = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 4760 | } else if (loc == PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE){ |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4761 | ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4762 | } else if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_APK) { |
| 4763 | ret = PackageManager.INSTALL_FAILED_INVALID_APK; |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4764 | } else if (loc == PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE) { |
| 4765 | ret = PackageManager.INSTALL_FAILED_MEDIA_UNAVAILABLE; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4766 | } else { |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4767 | // Override with defaults if needed. |
| 4768 | loc = installLocationPolicy(pkgLite, flags); |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4769 | if (!onSd && !onInt) { |
| 4770 | // Override install location with flags |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4771 | if (loc == PackageHelper.RECOMMEND_INSTALL_EXTERNAL) { |
| 4772 | // Set the flag to install on external media. |
| 4773 | flags |= PackageManager.INSTALL_EXTERNAL; |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4774 | flags &= ~PackageManager.INSTALL_INTERNAL; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4775 | } else { |
| 4776 | // Make sure the flag for installing on external |
| 4777 | // media is unset |
Suchi Amalapurapu | 14b6abd | 2010-03-17 08:37:04 -0700 | [diff] [blame] | 4778 | flags |= PackageManager.INSTALL_INTERNAL; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4779 | flags &= ~PackageManager.INSTALL_EXTERNAL; |
| 4780 | } |
| 4781 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4782 | } |
| 4783 | } |
| 4784 | // Create the file args now. |
| 4785 | mArgs = createInstallArgs(this); |
| 4786 | if (ret == PackageManager.INSTALL_SUCCEEDED) { |
| 4787 | // Create copy only if we are not in an erroneous state. |
| 4788 | // Remote call to initiate copy using temporary file |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4789 | ret = mArgs.copyApk(mContainerService, true); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4790 | } |
| 4791 | mRet = ret; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4792 | } |
| 4793 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4794 | @Override |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4795 | void handleReturnCode() { |
| 4796 | processPendingInstall(mArgs, mRet); |
| 4797 | } |
| 4798 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4799 | @Override |
| 4800 | void handleServiceError() { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4801 | mArgs = createInstallArgs(this); |
| 4802 | mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4803 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4804 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4805 | |
| 4806 | /* |
| 4807 | * Utility class used in movePackage api. |
| 4808 | * srcArgs and targetArgs are not set for invalid flags and make |
| 4809 | * sure to do null checks when invoking methods on them. |
| 4810 | * We probably want to return ErrorPrams for both failed installs |
| 4811 | * and moves. |
| 4812 | */ |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4813 | class MoveParams extends HandlerParams { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4814 | final IPackageMoveObserver observer; |
| 4815 | final int flags; |
| 4816 | final String packageName; |
| 4817 | final InstallArgs srcArgs; |
| 4818 | final InstallArgs targetArgs; |
| 4819 | int mRet; |
| 4820 | MoveParams(InstallArgs srcArgs, |
| 4821 | IPackageMoveObserver observer, |
| 4822 | int flags, String packageName) { |
| 4823 | this.srcArgs = srcArgs; |
| 4824 | this.observer = observer; |
| 4825 | this.flags = flags; |
| 4826 | this.packageName = packageName; |
| 4827 | if (srcArgs != null) { |
| 4828 | Uri packageUri = Uri.fromFile(new File(srcArgs.getCodePath())); |
| 4829 | targetArgs = createInstallArgs(packageUri, flags, packageName); |
| 4830 | } else { |
| 4831 | targetArgs = null; |
| 4832 | } |
| 4833 | } |
| 4834 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4835 | public void handleStartCopy() throws RemoteException { |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4836 | mRet = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4837 | // Check for storage space on target medium |
| 4838 | if (!targetArgs.checkFreeStorage(mContainerService)) { |
| 4839 | Log.w(TAG, "Insufficient storage to install"); |
| 4840 | return; |
| 4841 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4842 | // Create the file args now. |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4843 | mRet = targetArgs.copyApk(mContainerService, false); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4844 | targetArgs.doPreInstall(mRet); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4845 | if (DEBUG_SD_INSTALL) { |
| 4846 | StringBuilder builder = new StringBuilder(); |
| 4847 | if (srcArgs != null) { |
| 4848 | builder.append("src: "); |
| 4849 | builder.append(srcArgs.getCodePath()); |
| 4850 | } |
| 4851 | if (targetArgs != null) { |
| 4852 | builder.append(" target : "); |
| 4853 | builder.append(targetArgs.getCodePath()); |
| 4854 | } |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4855 | Log.i(TAG, builder.toString()); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4856 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4857 | } |
| 4858 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4859 | @Override |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4860 | void handleReturnCode() { |
| 4861 | targetArgs.doPostInstall(mRet); |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4862 | int currentStatus = PackageManager.MOVE_FAILED_INTERNAL_ERROR; |
| 4863 | if (mRet == PackageManager.INSTALL_SUCCEEDED) { |
| 4864 | currentStatus = PackageManager.MOVE_SUCCEEDED; |
| 4865 | } else if (mRet == PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE){ |
| 4866 | currentStatus = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE; |
| 4867 | } |
| 4868 | processPendingMove(this, currentStatus); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4869 | } |
| 4870 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4871 | @Override |
| 4872 | void handleServiceError() { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4873 | mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4874 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4875 | } |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4876 | |
| 4877 | private InstallArgs createInstallArgs(InstallParams params) { |
| 4878 | if (installOnSd(params.flags)) { |
| 4879 | return new SdInstallArgs(params); |
| 4880 | } else { |
| 4881 | return new FileInstallArgs(params); |
| 4882 | } |
| 4883 | } |
| 4884 | |
| 4885 | private InstallArgs createInstallArgs(int flags, String fullCodePath, String fullResourcePath) { |
| 4886 | if (installOnSd(flags)) { |
| 4887 | return new SdInstallArgs(fullCodePath, fullResourcePath); |
| 4888 | } else { |
| 4889 | return new FileInstallArgs(fullCodePath, fullResourcePath); |
| 4890 | } |
| 4891 | } |
| 4892 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4893 | private InstallArgs createInstallArgs(Uri packageURI, int flags, String pkgName) { |
| 4894 | if (installOnSd(flags)) { |
| 4895 | String cid = getNextCodePath(null, pkgName, "/" + SdInstallArgs.RES_FILE_NAME); |
| 4896 | return new SdInstallArgs(packageURI, cid); |
| 4897 | } else { |
| 4898 | return new FileInstallArgs(packageURI, pkgName); |
| 4899 | } |
| 4900 | } |
| 4901 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4902 | static abstract class InstallArgs { |
| 4903 | final IPackageInstallObserver observer; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4904 | // Always refers to PackageManager flags only |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4905 | final int flags; |
| 4906 | final Uri packageURI; |
| 4907 | final String installerPackageName; |
| 4908 | |
| 4909 | InstallArgs(Uri packageURI, |
| 4910 | IPackageInstallObserver observer, int flags, |
| 4911 | String installerPackageName) { |
| 4912 | this.packageURI = packageURI; |
| 4913 | this.flags = flags; |
| 4914 | this.observer = observer; |
| 4915 | this.installerPackageName = installerPackageName; |
| 4916 | } |
| 4917 | |
| 4918 | abstract void createCopyFile(); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4919 | abstract int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 4920 | abstract int doPreInstall(int status); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4921 | abstract boolean doRename(int status, String pkgName, String oldCodePath); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 4922 | abstract int doPostInstall(int status); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4923 | abstract String getCodePath(); |
| 4924 | abstract String getResourcePath(); |
| 4925 | // Need installer lock especially for dex file removal. |
| 4926 | abstract void cleanUpResourcesLI(); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 4927 | abstract boolean doPostDeleteLI(boolean delete); |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4928 | abstract boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | class FileInstallArgs extends InstallArgs { |
| 4932 | File installDir; |
| 4933 | String codeFileName; |
| 4934 | String resourceFileName; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4935 | boolean created = false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4936 | |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4937 | FileInstallArgs(InstallParams params) { |
| 4938 | super(params.packageURI, params.observer, |
| 4939 | params.flags, params.installerPackageName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | FileInstallArgs(String fullCodePath, String fullResourcePath) { |
| 4943 | super(null, null, 0, null); |
| 4944 | File codeFile = new File(fullCodePath); |
| 4945 | installDir = codeFile.getParentFile(); |
| 4946 | codeFileName = fullCodePath; |
| 4947 | resourceFileName = fullResourcePath; |
| 4948 | } |
| 4949 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4950 | FileInstallArgs(Uri packageURI, String pkgName) { |
| 4951 | super(packageURI, null, 0, null); |
| 4952 | boolean fwdLocked = isFwdLocked(flags); |
| 4953 | installDir = fwdLocked ? mDrmAppPrivateInstallDir : mAppInstallDir; |
| 4954 | String apkName = getNextCodePath(null, pkgName, ".apk"); |
| 4955 | codeFileName = new File(installDir, apkName + ".apk").getPath(); |
| 4956 | resourceFileName = getResourcePathFromCodePath(); |
| 4957 | } |
| 4958 | |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 4959 | boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException { |
| 4960 | return imcs.checkFreeStorage(false, packageURI); |
| 4961 | } |
| 4962 | |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 4963 | String getCodePath() { |
| 4964 | return codeFileName; |
| 4965 | } |
| 4966 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4967 | void createCopyFile() { |
| 4968 | boolean fwdLocked = isFwdLocked(flags); |
| 4969 | installDir = fwdLocked ? mDrmAppPrivateInstallDir : mAppInstallDir; |
| 4970 | codeFileName = createTempPackageFile(installDir).getPath(); |
| 4971 | resourceFileName = getResourcePathFromCodePath(); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4972 | created = true; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4973 | } |
| 4974 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 4975 | int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4976 | if (temp) { |
| 4977 | // Generate temp file name |
| 4978 | createCopyFile(); |
| 4979 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4980 | // Get a ParcelFileDescriptor to write to the output file |
| 4981 | File codeFile = new File(codeFileName); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4982 | if (!created) { |
| 4983 | try { |
| 4984 | codeFile.createNewFile(); |
| 4985 | // Set permissions |
| 4986 | if (!setPermissions()) { |
| 4987 | // Failed setting permissions. |
| 4988 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4989 | } |
| 4990 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 4991 | Slog.w(TAG, "Failed to create file " + codeFile); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 4992 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 4993 | } |
| 4994 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 4995 | ParcelFileDescriptor out = null; |
| 4996 | try { |
| 4997 | out = ParcelFileDescriptor.open(codeFile, |
| 4998 | ParcelFileDescriptor.MODE_READ_WRITE); |
| 4999 | } catch (FileNotFoundException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5000 | Slog.e(TAG, "Failed to create file descritpor for : " + codeFileName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5001 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5002 | } |
| 5003 | // Copy the resource now |
| 5004 | int ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5005 | try { |
| 5006 | if (imcs.copyResource(packageURI, out)) { |
| 5007 | ret = PackageManager.INSTALL_SUCCEEDED; |
| 5008 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5009 | } finally { |
| 5010 | try { if (out != null) out.close(); } catch (IOException e) {} |
| 5011 | } |
| 5012 | return ret; |
| 5013 | } |
| 5014 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5015 | int doPreInstall(int status) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5016 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5017 | cleanUp(); |
| 5018 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5019 | return status; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | boolean doRename(int status, final String pkgName, String oldCodePath) { |
| 5023 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5024 | cleanUp(); |
| 5025 | return false; |
| 5026 | } else { |
| 5027 | // Rename based on packageName |
| 5028 | File codeFile = new File(getCodePath()); |
| 5029 | String apkName = getNextCodePath(oldCodePath, pkgName, ".apk"); |
| 5030 | File desFile = new File(installDir, apkName + ".apk"); |
| 5031 | if (!codeFile.renameTo(desFile)) { |
| 5032 | return false; |
| 5033 | } |
| 5034 | // Reset paths since the file has been renamed. |
| 5035 | codeFileName = desFile.getPath(); |
| 5036 | resourceFileName = getResourcePathFromCodePath(); |
| 5037 | // Set permissions |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5038 | if (!setPermissions()) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5039 | // Failed setting permissions. |
| 5040 | return false; |
| 5041 | } |
| 5042 | return true; |
| 5043 | } |
| 5044 | } |
| 5045 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5046 | int doPostInstall(int status) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5047 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5048 | cleanUp(); |
| 5049 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5050 | return status; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | String getResourcePath() { |
| 5054 | return resourceFileName; |
| 5055 | } |
| 5056 | |
| 5057 | String getResourcePathFromCodePath() { |
| 5058 | String codePath = getCodePath(); |
| 5059 | if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { |
| 5060 | String apkNameOnly = getApkName(codePath); |
| 5061 | return mAppInstallDir.getPath() + "/" + apkNameOnly + ".zip"; |
| 5062 | } else { |
| 5063 | return codePath; |
| 5064 | } |
| 5065 | } |
| 5066 | |
| 5067 | private boolean cleanUp() { |
| 5068 | boolean ret = true; |
| 5069 | String sourceDir = getCodePath(); |
| 5070 | String publicSourceDir = getResourcePath(); |
| 5071 | if (sourceDir != null) { |
| 5072 | File sourceFile = new File(sourceDir); |
| 5073 | if (!sourceFile.exists()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5074 | Slog.w(TAG, "Package source " + sourceDir + " does not exist."); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5075 | ret = false; |
| 5076 | } |
| 5077 | // Delete application's code and resources |
| 5078 | sourceFile.delete(); |
| 5079 | } |
| 5080 | if (publicSourceDir != null && !publicSourceDir.equals(sourceDir)) { |
| 5081 | final File publicSourceFile = new File(publicSourceDir); |
| 5082 | if (!publicSourceFile.exists()) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5083 | Slog.w(TAG, "Package public source " + publicSourceFile + " does not exist."); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5084 | } |
| 5085 | if (publicSourceFile.exists()) { |
| 5086 | publicSourceFile.delete(); |
| 5087 | } |
| 5088 | } |
| 5089 | return ret; |
| 5090 | } |
| 5091 | |
| 5092 | void cleanUpResourcesLI() { |
| 5093 | String sourceDir = getCodePath(); |
| 5094 | if (cleanUp() && mInstaller != null) { |
| 5095 | int retCode = mInstaller.rmdex(sourceDir); |
| 5096 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5097 | Slog.w(TAG, "Couldn't remove dex file for package: " |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5098 | + " at location " |
| 5099 | + sourceDir + ", retcode=" + retCode); |
| 5100 | // we don't consider this to be a failure of the core package deletion |
| 5101 | } |
| 5102 | } |
| 5103 | } |
| 5104 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5105 | private boolean setPermissions() { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5106 | // TODO Do this in a more elegant way later on. for now just a hack |
| 5107 | if (!isFwdLocked(flags)) { |
| 5108 | final int filePermissions = |
| 5109 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP |
| 5110 | |FileUtils.S_IROTH; |
| 5111 | int retCode = FileUtils.setPermissions(getCodePath(), filePermissions, -1, -1); |
| 5112 | if (retCode != 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5113 | Slog.e(TAG, "Couldn't set new package file permissions for " + |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5114 | getCodePath() |
| 5115 | + ". The return code was: " + retCode); |
| 5116 | // TODO Define new internal error |
| 5117 | return false; |
| 5118 | } |
| 5119 | return true; |
| 5120 | } |
| 5121 | return true; |
| 5122 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5123 | |
| 5124 | boolean doPostDeleteLI(boolean delete) { |
| 5125 | cleanUpResourcesLI(); |
| 5126 | return true; |
| 5127 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5128 | } |
| 5129 | |
| 5130 | class SdInstallArgs extends InstallArgs { |
| 5131 | String cid; |
| 5132 | String cachePath; |
| 5133 | static final String RES_FILE_NAME = "pkg.apk"; |
| 5134 | |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5135 | SdInstallArgs(InstallParams params) { |
| 5136 | super(params.packageURI, params.observer, |
| 5137 | params.flags, params.installerPackageName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | SdInstallArgs(String fullCodePath, String fullResourcePath) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5141 | super(null, null, PackageManager.INSTALL_EXTERNAL, null); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5142 | // Extract cid from fullCodePath |
| 5143 | int eidx = fullCodePath.lastIndexOf("/"); |
| 5144 | String subStr1 = fullCodePath.substring(0, eidx); |
| 5145 | int sidx = subStr1.lastIndexOf("/"); |
| 5146 | cid = subStr1.substring(sidx+1, eidx); |
| 5147 | cachePath = subStr1; |
| 5148 | } |
| 5149 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5150 | SdInstallArgs(String cid) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5151 | super(null, null, PackageManager.INSTALL_EXTERNAL, null); |
| 5152 | this.cid = cid; |
| 5153 | } |
| 5154 | |
| 5155 | SdInstallArgs(Uri packageURI, String cid) { |
| 5156 | super(packageURI, null, PackageManager.INSTALL_EXTERNAL, null); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5157 | this.cid = cid; |
| 5158 | } |
| 5159 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5160 | void createCopyFile() { |
| 5161 | cid = getTempContainerId(); |
| 5162 | } |
| 5163 | |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 5164 | boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException { |
| 5165 | return imcs.checkFreeStorage(true, packageURI); |
| 5166 | } |
| 5167 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5168 | int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5169 | if (temp) { |
| 5170 | createCopyFile(); |
| 5171 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5172 | cachePath = imcs.copyResourceToContainer( |
| 5173 | packageURI, cid, |
| 5174 | getEncryptKey(), RES_FILE_NAME); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5175 | return (cachePath == null) ? PackageManager.INSTALL_FAILED_CONTAINER_ERROR : |
| 5176 | PackageManager.INSTALL_SUCCEEDED; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | @Override |
| 5180 | String getCodePath() { |
| 5181 | return cachePath + "/" + RES_FILE_NAME; |
| 5182 | } |
| 5183 | |
| 5184 | @Override |
| 5185 | String getResourcePath() { |
| 5186 | return cachePath + "/" + RES_FILE_NAME; |
| 5187 | } |
| 5188 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5189 | int doPreInstall(int status) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5190 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5191 | // Destroy container |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5192 | PackageHelper.destroySdDir(cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5193 | } else { |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5194 | boolean mounted = PackageHelper.isContainerMounted(cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5195 | if (!mounted) { |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5196 | cachePath = PackageHelper.mountSdDir(cid, getEncryptKey(), Process.SYSTEM_UID); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5197 | if (cachePath == null) { |
| 5198 | return PackageManager.INSTALL_FAILED_CONTAINER_ERROR; |
| 5199 | } |
| 5200 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5201 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5202 | return status; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5203 | } |
| 5204 | |
| 5205 | boolean doRename(int status, final String pkgName, |
| 5206 | String oldCodePath) { |
| 5207 | String newCacheId = getNextCodePath(oldCodePath, pkgName, "/" + RES_FILE_NAME); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5208 | String newCachePath = null; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5209 | if (PackageHelper.isContainerMounted(cid)) { |
| 5210 | // Unmount the container |
| 5211 | if (!PackageHelper.unMountSdDir(cid)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5212 | Slog.i(TAG, "Failed to unmount " + cid + " before renaming"); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5213 | return false; |
| 5214 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5215 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5216 | if (!PackageHelper.renameSdDir(cid, newCacheId)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5217 | Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5218 | return false; |
| 5219 | } |
| 5220 | if (!PackageHelper.isContainerMounted(newCacheId)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5221 | Slog.w(TAG, "Mounting container " + newCacheId); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5222 | newCachePath = PackageHelper.mountSdDir(newCacheId, |
| 5223 | getEncryptKey(), Process.SYSTEM_UID); |
| 5224 | } else { |
| 5225 | newCachePath = PackageHelper.getSdDir(newCacheId); |
| 5226 | } |
| 5227 | if (newCachePath == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5228 | Slog.w(TAG, "Failed to get cache path for " + newCacheId); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 5229 | return false; |
| 5230 | } |
| 5231 | Log.i(TAG, "Succesfully renamed " + cid + |
| 5232 | " at path: " + cachePath + " to " + newCacheId + |
| 5233 | " at new path: " + newCachePath); |
| 5234 | cid = newCacheId; |
| 5235 | cachePath = newCachePath; |
| 5236 | return true; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5237 | } |
| 5238 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5239 | int doPostInstall(int status) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5240 | if (status != PackageManager.INSTALL_SUCCEEDED) { |
| 5241 | cleanUp(); |
| 5242 | } else { |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5243 | boolean mounted = PackageHelper.isContainerMounted(cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5244 | if (!mounted) { |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5245 | PackageHelper.mountSdDir(cid, |
| 5246 | getEncryptKey(), Process.myUid()); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5247 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5248 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5249 | return status; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | private void cleanUp() { |
| 5253 | // Destroy secure container |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5254 | PackageHelper.destroySdDir(cid); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | void cleanUpResourcesLI() { |
| 5258 | String sourceFile = getCodePath(); |
| 5259 | // Remove dex file |
| 5260 | if (mInstaller != null) { |
| 5261 | int retCode = mInstaller.rmdex(sourceFile.toString()); |
| 5262 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5263 | Slog.w(TAG, "Couldn't remove dex file for package: " |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5264 | + " at location " |
| 5265 | + sourceFile.toString() + ", retcode=" + retCode); |
| 5266 | // we don't consider this to be a failure of the core package deletion |
| 5267 | } |
| 5268 | } |
| 5269 | cleanUp(); |
| 5270 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5271 | |
| 5272 | boolean matchContainer(String app) { |
| 5273 | if (cid.startsWith(app)) { |
| 5274 | return true; |
| 5275 | } |
| 5276 | return false; |
| 5277 | } |
| 5278 | |
| 5279 | String getPackageName() { |
| 5280 | int idx = cid.lastIndexOf("-"); |
| 5281 | if (idx == -1) { |
| 5282 | return cid; |
| 5283 | } |
| 5284 | return cid.substring(0, idx); |
| 5285 | } |
| 5286 | |
| 5287 | boolean doPostDeleteLI(boolean delete) { |
| 5288 | boolean ret = false; |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5289 | boolean mounted = PackageHelper.isContainerMounted(cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5290 | if (mounted) { |
| 5291 | // Unmount first |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 5292 | ret = PackageHelper.unMountSdDir(cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5293 | } |
| 5294 | if (ret && delete) { |
| 5295 | cleanUpResourcesLI(); |
| 5296 | } |
| 5297 | return ret; |
| 5298 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5299 | }; |
| 5300 | |
| 5301 | // Utility method used to create code paths based on package name and available index. |
| 5302 | private static String getNextCodePath(String oldCodePath, String prefix, String suffix) { |
| 5303 | String idxStr = ""; |
| 5304 | int idx = 1; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5305 | // Fall back to default value of idx=1 if prefix is not |
| 5306 | // part of oldCodePath |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5307 | if (oldCodePath != null) { |
Bjorn Bringert | 5fd5bfe | 2010-01-29 12:11:30 +0000 | [diff] [blame] | 5308 | String subStr = oldCodePath; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5309 | // Drop the suffix right away |
Bjorn Bringert | 5fd5bfe | 2010-01-29 12:11:30 +0000 | [diff] [blame] | 5310 | if (subStr.endsWith(suffix)) { |
| 5311 | subStr = subStr.substring(0, subStr.length() - suffix.length()); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5312 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5313 | // If oldCodePath already contains prefix find out the |
| 5314 | // ending index to either increment or decrement. |
| 5315 | int sidx = subStr.lastIndexOf(prefix); |
| 5316 | if (sidx != -1) { |
| 5317 | subStr = subStr.substring(sidx + prefix.length()); |
| 5318 | if (subStr != null) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5319 | if (subStr.startsWith(INSTALL_PACKAGE_SUFFIX)) { |
| 5320 | subStr = subStr.substring(INSTALL_PACKAGE_SUFFIX.length()); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5321 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5322 | try { |
| 5323 | idx = Integer.parseInt(subStr); |
| 5324 | if (idx <= 1) { |
| 5325 | idx++; |
| 5326 | } else { |
| 5327 | idx--; |
| 5328 | } |
| 5329 | } catch(NumberFormatException e) { |
| 5330 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5331 | } |
| 5332 | } |
| 5333 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5334 | idxStr = INSTALL_PACKAGE_SUFFIX + Integer.toString(idx); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5335 | return prefix + idxStr; |
| 5336 | } |
| 5337 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5338 | // Utility method used to ignore ADD/REMOVE events |
| 5339 | // by directory observer. |
| 5340 | private static boolean ignoreCodePath(String fullPathStr) { |
| 5341 | String apkName = getApkName(fullPathStr); |
| 5342 | int idx = apkName.lastIndexOf(INSTALL_PACKAGE_SUFFIX); |
| 5343 | if (idx != -1 && ((idx+1) < apkName.length())) { |
| 5344 | // Make sure the package ends with a numeral |
| 5345 | String version = apkName.substring(idx+1); |
| 5346 | try { |
| 5347 | Integer.parseInt(version); |
| 5348 | return true; |
| 5349 | } catch (NumberFormatException e) {} |
| 5350 | } |
| 5351 | return false; |
| 5352 | } |
| 5353 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5354 | // Utility method that returns the relative package path with respect |
| 5355 | // to the installation directory. Like say for /data/data/com.test-1.apk |
| 5356 | // string com.test-1 is returned. |
| 5357 | static String getApkName(String codePath) { |
| 5358 | if (codePath == null) { |
| 5359 | return null; |
| 5360 | } |
| 5361 | int sidx = codePath.lastIndexOf("/"); |
| 5362 | int eidx = codePath.lastIndexOf("."); |
| 5363 | if (eidx == -1) { |
| 5364 | eidx = codePath.length(); |
| 5365 | } else if (eidx == 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5366 | Slog.w(TAG, " Invalid code path, "+ codePath + " Not a valid apk name"); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5367 | return null; |
| 5368 | } |
| 5369 | return codePath.substring(sidx+1, eidx); |
| 5370 | } |
| 5371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5372 | class PackageInstalledInfo { |
| 5373 | String name; |
| 5374 | int uid; |
| 5375 | PackageParser.Package pkg; |
| 5376 | int returnCode; |
| 5377 | PackageRemovedInfo removedInfo; |
| 5378 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5380 | /* |
| 5381 | * Install a non-existing package. |
| 5382 | */ |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5383 | private void installNewPackageLI(PackageParser.Package pkg, |
| 5384 | int parseFlags, |
| 5385 | int scanMode, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5386 | String installerPackageName, PackageInstalledInfo res) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5387 | // Remember this for later, in case we need to rollback this install |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5388 | String pkgName = pkg.packageName; |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 5389 | |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 5390 | boolean dataDirExists = getDataPathForPackage(pkg).exists(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5391 | res.name = pkgName; |
| 5392 | synchronized(mPackages) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5393 | if (mPackages.containsKey(pkgName) || mAppDirs.containsKey(pkg.mPath)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5394 | // Don't allow installation over an existing package with the same name. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5395 | Slog.w(TAG, "Attempt to re-install " + pkgName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5396 | + " without first uninstalling."); |
| 5397 | res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS; |
| 5398 | return; |
| 5399 | } |
| 5400 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5401 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5402 | PackageParser.Package newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5403 | if (newPackage == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5404 | 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] | 5405 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5406 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 5407 | } |
| 5408 | } else { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5409 | updateSettingsLI(newPackage, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5410 | installerPackageName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5411 | res); |
| 5412 | // delete the partially installed application. the data directory will have to be |
| 5413 | // restored if it was already existing |
| 5414 | if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
| 5415 | // remove package from internal structures. Note that we want deletePackageX to |
| 5416 | // delete the package data and cache directories that it created in |
| 5417 | // scanPackageLocked, unless those directories existed before we even tried to |
| 5418 | // install. |
| 5419 | deletePackageLI( |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5420 | pkgName, false, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5421 | dataDirExists ? PackageManager.DONT_DELETE_DATA : 0, |
| 5422 | res.removedInfo); |
| 5423 | } |
| 5424 | } |
| 5425 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5426 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5427 | private void replacePackageLI(PackageParser.Package pkg, |
| 5428 | int parseFlags, |
| 5429 | int scanMode, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5430 | String installerPackageName, PackageInstalledInfo res) { |
| 5431 | |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 5432 | PackageParser.Package oldPackage; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5433 | String pkgName = pkg.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5434 | // First find the old package info and check signatures |
| 5435 | synchronized(mPackages) { |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 5436 | oldPackage = mPackages.get(pkgName); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5437 | if (checkSignaturesLP(pkg.mSignatures, oldPackage.mSignatures) |
Dianne Hackborn | 766cbfe | 2009-08-12 18:33:39 -0700 | [diff] [blame] | 5438 | != PackageManager.SIGNATURE_MATCH) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5439 | res.returnCode = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES; |
| 5440 | return; |
| 5441 | } |
| 5442 | } |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 5443 | boolean sysPkg = ((oldPackage.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5444 | if (sysPkg) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5445 | replaceSystemPackageLI(oldPackage, pkg, parseFlags, scanMode, installerPackageName, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5446 | } else { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5447 | replaceNonSystemPackageLI(oldPackage, pkg, parseFlags, scanMode, installerPackageName, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5448 | } |
| 5449 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5451 | private void replaceNonSystemPackageLI(PackageParser.Package deletedPackage, |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5452 | PackageParser.Package pkg, |
| 5453 | int parseFlags, int scanMode, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5454 | String installerPackageName, PackageInstalledInfo res) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5455 | PackageParser.Package newPackage = null; |
| 5456 | String pkgName = deletedPackage.packageName; |
| 5457 | boolean deletedPkg = true; |
| 5458 | boolean updatedSettings = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5459 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5460 | String oldInstallerPackageName = null; |
| 5461 | synchronized (mPackages) { |
| 5462 | oldInstallerPackageName = mSettings.getInstallerPackageName(pkgName); |
| 5463 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5464 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5465 | parseFlags |= PackageManager.INSTALL_REPLACE_EXISTING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5466 | // First delete the existing package while retaining the data directory |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5467 | if (!deletePackageLI(pkgName, true, PackageManager.DONT_DELETE_DATA, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5468 | res.removedInfo)) { |
| 5469 | // If the existing package was'nt successfully deleted |
| 5470 | res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE; |
| 5471 | deletedPkg = false; |
| 5472 | } else { |
| 5473 | // Successfully deleted the old package. Now proceed with re-installation |
| 5474 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5475 | newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5476 | if (newPackage == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5477 | 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] | 5478 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5479 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
Suchi Amalapurapu | 110fea7 | 2010-01-14 17:50:23 -0800 | [diff] [blame] | 5480 | } |
| 5481 | } else { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5482 | updateSettingsLI(newPackage, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5483 | installerPackageName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5484 | res); |
| 5485 | updatedSettings = true; |
| 5486 | } |
| 5487 | } |
| 5488 | |
| 5489 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) { |
| 5490 | // If we deleted an exisiting package, the old source and resource files that we |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5491 | // were keeping around in case we needed them (see below) can now be deleted. |
| 5492 | // This info will be set on the res.removedInfo to clean up later on as post |
| 5493 | // install action. |
| 5494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5495 | //update signature on the new package setting |
| 5496 | //this should always succeed, since we checked the |
| 5497 | //signature earlier. |
| 5498 | synchronized(mPackages) { |
| 5499 | verifySignaturesLP(mSettings.mPackages.get(pkgName), pkg, |
| 5500 | parseFlags, true); |
| 5501 | } |
| 5502 | } else { |
| 5503 | // remove package from internal structures. Note that we want deletePackageX to |
| 5504 | // delete the package data and cache directories that it created in |
| 5505 | // scanPackageLocked, unless those directories existed before we even tried to |
| 5506 | // install. |
| 5507 | if(updatedSettings) { |
| 5508 | deletePackageLI( |
| 5509 | pkgName, true, |
| 5510 | PackageManager.DONT_DELETE_DATA, |
| 5511 | res.removedInfo); |
| 5512 | } |
| 5513 | // Since we failed to install the new package we need to restore the old |
| 5514 | // package that we deleted. |
| 5515 | if(deletedPkg) { |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5516 | File restoreFile = new File(deletedPackage.mPath); |
| 5517 | if (restoreFile == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5518 | Slog.e(TAG, "Failed allocating storage when restoring pkg : " + pkgName); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5519 | return; |
| 5520 | } |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5521 | PackageInstalledInfo restoreRes = new PackageInstalledInfo(); |
| 5522 | restoreRes.removedInfo = new PackageRemovedInfo(); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5523 | // Parse old package |
| 5524 | parseFlags |= ~PackageManager.INSTALL_REPLACE_EXISTING; |
| 5525 | scanPackageLI(restoreFile, parseFlags, scanMode); |
| 5526 | synchronized (mPackages) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 5527 | updatePermissionsLP(deletedPackage.packageName, deletedPackage, |
| 5528 | true, false); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5529 | mSettings.writeLP(); |
| 5530 | } |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5531 | if (restoreRes.returnCode != PackageManager.INSTALL_SUCCEEDED) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5532 | Slog.e(TAG, "Failed restoring pkg : " + pkgName + " after failed upgrade"); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5533 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5534 | } |
| 5535 | } |
| 5536 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5538 | private void replaceSystemPackageLI(PackageParser.Package deletedPackage, |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5539 | PackageParser.Package pkg, |
| 5540 | int parseFlags, int scanMode, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5541 | String installerPackageName, PackageInstalledInfo res) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5542 | PackageParser.Package newPackage = null; |
| 5543 | boolean updatedSettings = false; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5544 | parseFlags |= PackageManager.INSTALL_REPLACE_EXISTING | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5545 | PackageParser.PARSE_IS_SYSTEM; |
| 5546 | String packageName = deletedPackage.packageName; |
| 5547 | res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE; |
| 5548 | if (packageName == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5549 | Slog.w(TAG, "Attempt to delete null packageName."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5550 | return; |
| 5551 | } |
| 5552 | PackageParser.Package oldPkg; |
| 5553 | PackageSetting oldPkgSetting; |
| 5554 | synchronized (mPackages) { |
| 5555 | oldPkg = mPackages.get(packageName); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5556 | oldPkgSetting = mSettings.mPackages.get(packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5557 | if((oldPkg == null) || (oldPkg.applicationInfo == null) || |
| 5558 | (oldPkgSetting == null)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5559 | Slog.w(TAG, "Couldn't find package:"+packageName+" information"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5560 | return; |
| 5561 | } |
| 5562 | } |
| 5563 | res.removedInfo.uid = oldPkg.applicationInfo.uid; |
| 5564 | res.removedInfo.removedPackage = packageName; |
| 5565 | // Remove existing system package |
| 5566 | removePackageLI(oldPkg, true); |
| 5567 | synchronized (mPackages) { |
| 5568 | res.removedInfo.removedUid = mSettings.disableSystemPackageLP(packageName); |
| 5569 | } |
| 5570 | |
| 5571 | // Successfully disabled the old package. Now proceed with re-installation |
| 5572 | mLastScanError = PackageManager.INSTALL_SUCCEEDED; |
| 5573 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5574 | newPackage = scanPackageLI(pkg, parseFlags, scanMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5575 | if (newPackage == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5576 | 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] | 5577 | if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) { |
| 5578 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK; |
| 5579 | } |
| 5580 | } else { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5581 | updateSettingsLI(newPackage, installerPackageName, res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5582 | updatedSettings = true; |
| 5583 | } |
| 5584 | |
| 5585 | if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) { |
| 5586 | //update signature on the new package setting |
| 5587 | //this should always succeed, since we checked the |
| 5588 | //signature earlier. |
| 5589 | synchronized(mPackages) { |
| 5590 | verifySignaturesLP(mSettings.mPackages.get(packageName), pkg, |
| 5591 | parseFlags, true); |
| 5592 | } |
| 5593 | } else { |
| 5594 | // Re installation failed. Restore old information |
| 5595 | // Remove new pkg information |
Dianne Hackborn | 62da846 | 2009-05-13 15:06:13 -0700 | [diff] [blame] | 5596 | if (newPackage != null) { |
| 5597 | removePackageLI(newPackage, true); |
| 5598 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5599 | // Add back the old system package |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5600 | scanPackageLI(oldPkg, parseFlags, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5601 | SCAN_MONITOR |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5602 | | SCAN_UPDATE_SIGNATURE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5603 | // Restore the old system information in Settings |
| 5604 | synchronized(mPackages) { |
| 5605 | if(updatedSettings) { |
| 5606 | mSettings.enableSystemPackageLP(packageName); |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5607 | mSettings.setInstallerPackageName(packageName, |
| 5608 | oldPkgSetting.installerPackageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5609 | } |
| 5610 | mSettings.writeLP(); |
| 5611 | } |
| 5612 | } |
| 5613 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5614 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5615 | // Utility method used to move dex files during install. |
| 5616 | private int moveDexFiles(PackageParser.Package newPackage) { |
| 5617 | int retCode; |
| 5618 | if ((newPackage.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0) { |
| 5619 | retCode = mInstaller.movedex(newPackage.mScanPath, newPackage.mPath); |
| 5620 | if (retCode != 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5621 | Slog.e(TAG, "Couldn't rename dex file: " + newPackage.mPath); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5622 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5623 | } |
| 5624 | } |
| 5625 | return PackageManager.INSTALL_SUCCEEDED; |
| 5626 | } |
| 5627 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5628 | private void updateSettingsLI(PackageParser.Package newPackage, |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5629 | String installerPackageName, PackageInstalledInfo res) { |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5630 | String pkgName = newPackage.packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5631 | synchronized (mPackages) { |
| 5632 | //write settings. the installStatus will be incomplete at this stage. |
| 5633 | //note that the new package setting would have already been |
| 5634 | //added to mPackages. It hasn't been persisted yet. |
| 5635 | mSettings.setInstallStatus(pkgName, PKG_INSTALL_INCOMPLETE); |
| 5636 | mSettings.writeLP(); |
| 5637 | } |
| 5638 | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5639 | if ((res.returnCode = moveDexFiles(newPackage)) |
| 5640 | != PackageManager.INSTALL_SUCCEEDED) { |
| 5641 | // Discontinue if moving dex files failed. |
| 5642 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5643 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 5644 | if((res.returnCode = setPermissionsLI(newPackage)) |
| 5645 | != PackageManager.INSTALL_SUCCEEDED) { |
| 5646 | if (mInstaller != null) { |
| 5647 | mInstaller.rmdex(newPackage.mScanPath); |
| 5648 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5649 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5650 | } else { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5651 | Log.d(TAG, "New package installed in " + newPackage.mPath); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5652 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5653 | synchronized (mPackages) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 5654 | updatePermissionsLP(newPackage.packageName, newPackage, |
| 5655 | newPackage.permissions.size() > 0, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5656 | res.name = pkgName; |
| 5657 | res.uid = newPackage.applicationInfo.uid; |
| 5658 | res.pkg = newPackage; |
| 5659 | mSettings.setInstallStatus(pkgName, PKG_INSTALL_COMPLETE); |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 5660 | mSettings.setInstallerPackageName(pkgName, installerPackageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | res.returnCode = PackageManager.INSTALL_SUCCEEDED; |
| 5662 | //to update install status |
| 5663 | mSettings.writeLP(); |
| 5664 | } |
| 5665 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5666 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5667 | private void installPackageLI(InstallArgs args, |
| 5668 | boolean newInstall, PackageInstalledInfo res) { |
| 5669 | int pFlags = args.flags; |
| 5670 | String installerPackageName = args.installerPackageName; |
| 5671 | File tmpPackageFile = new File(args.getCodePath()); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5672 | boolean forwardLocked = ((pFlags & PackageManager.INSTALL_FORWARD_LOCK) != 0); |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 5673 | boolean onSd = ((pFlags & PackageManager.INSTALL_EXTERNAL) != 0); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5674 | boolean replace = false; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5675 | int scanMode = SCAN_MONITOR | SCAN_FORCE_DEX | SCAN_UPDATE_SIGNATURE |
| 5676 | | (newInstall ? SCAN_NEW_INSTALL : 0); |
Suchi Amalapurapu | ee5ece4 | 2009-09-15 13:41:47 -0700 | [diff] [blame] | 5677 | // Result object to be returned |
| 5678 | res.returnCode = PackageManager.INSTALL_SUCCEEDED; |
| 5679 | |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5680 | // Retrieve PackageSettings and parse package |
| 5681 | int parseFlags = PackageParser.PARSE_CHATTY | |
| 5682 | (forwardLocked ? PackageParser.PARSE_FORWARD_LOCK : 0) | |
| 5683 | (onSd ? PackageParser.PARSE_ON_SDCARD : 0); |
| 5684 | parseFlags |= mDefParseFlags; |
| 5685 | PackageParser pp = new PackageParser(tmpPackageFile.getPath()); |
| 5686 | pp.setSeparateProcesses(mSeparateProcesses); |
| 5687 | final PackageParser.Package pkg = pp.parsePackage(tmpPackageFile, |
| 5688 | null, mMetrics, parseFlags); |
| 5689 | if (pkg == null) { |
| 5690 | res.returnCode = pp.getParseError(); |
| 5691 | return; |
| 5692 | } |
| 5693 | String pkgName = res.name = pkg.packageName; |
| 5694 | if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_TEST_ONLY) != 0) { |
| 5695 | if ((pFlags&PackageManager.INSTALL_ALLOW_TEST) == 0) { |
| 5696 | res.returnCode = PackageManager.INSTALL_FAILED_TEST_ONLY; |
| 5697 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5698 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5699 | } |
| 5700 | if (GET_CERTIFICATES && !pp.collectCertificates(pkg, parseFlags)) { |
| 5701 | res.returnCode = pp.getParseError(); |
| 5702 | return; |
| 5703 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5704 | // Get rid of all references to package scan path via parser. |
| 5705 | pp = null; |
| 5706 | String oldCodePath = null; |
| 5707 | boolean systemApp = false; |
| 5708 | synchronized (mPackages) { |
| 5709 | // Check if installing already existing package |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5710 | if ((pFlags&PackageManager.INSTALL_REPLACE_EXISTING) != 0) { |
| 5711 | String oldName = mSettings.mRenamedPackages.get(pkgName); |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 5712 | if (pkg.mOriginalPackages != null |
| 5713 | && pkg.mOriginalPackages.contains(oldName) |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5714 | && mPackages.containsKey(oldName)) { |
| 5715 | // This package is derived from an original package, |
| 5716 | // and this device has been updating from that original |
| 5717 | // name. We must continue using the original name, so |
| 5718 | // rename the new package here. |
Dianne Hackborn | c155239 | 2010-03-03 16:19:01 -0800 | [diff] [blame] | 5719 | pkg.setPackageName(oldName); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5720 | pkgName = pkg.packageName; |
| 5721 | replace = true; |
| 5722 | } else if (mPackages.containsKey(pkgName)) { |
| 5723 | // This package, under its official name, already exists |
| 5724 | // on the device; we should replace it. |
| 5725 | replace = true; |
| 5726 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5727 | } |
| 5728 | PackageSetting ps = mSettings.mPackages.get(pkgName); |
| 5729 | if (ps != null) { |
| 5730 | oldCodePath = mSettings.mPackages.get(pkgName).codePathString; |
| 5731 | if (ps.pkg != null && ps.pkg.applicationInfo != null) { |
| 5732 | systemApp = (ps.pkg.applicationInfo.flags & |
| 5733 | ApplicationInfo.FLAG_SYSTEM) != 0; |
Dianne Hackborn | ade3eca | 2009-05-11 18:54:45 -0700 | [diff] [blame] | 5734 | } |
| 5735 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5736 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5737 | |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5738 | if (systemApp && onSd) { |
| 5739 | // Disable updates to system apps on sdcard |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5740 | Slog.w(TAG, "Cannot install updates to system apps on sdcard"); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5741 | res.returnCode = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION; |
| 5742 | return; |
| 5743 | } |
Suchi Amalapurapu | cf6eaea | 2010-02-23 19:37:45 -0800 | [diff] [blame] | 5744 | |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5745 | if (!args.doRename(res.returnCode, pkgName, oldCodePath)) { |
| 5746 | res.returnCode = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5747 | return; |
| 5748 | } |
| 5749 | // Set application objects path explicitly after the rename |
| 5750 | setApplicationInfoPaths(pkg, args.getCodePath(), args.getResourcePath()); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 5751 | if (replace) { |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 5752 | replacePackageLI(pkg, parseFlags, scanMode, |
| 5753 | installerPackageName, res); |
| 5754 | } else { |
| 5755 | installNewPackageLI(pkg, parseFlags, scanMode, |
| 5756 | installerPackageName,res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5757 | } |
| 5758 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5759 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5760 | private int setPermissionsLI(PackageParser.Package newPackage) { |
| 5761 | String pkgName = newPackage.packageName; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5762 | int retCode = 0; |
| 5763 | // TODO Gross hack but fix later. Ideally move this to be a post installation |
| 5764 | // check after alloting uid. |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5765 | if ((newPackage.applicationInfo.flags |
| 5766 | & ApplicationInfo.FLAG_FORWARD_LOCK) != 0) { |
| 5767 | File destResourceFile = new File(newPackage.applicationInfo.publicSourceDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5768 | try { |
| 5769 | extractPublicFiles(newPackage, destResourceFile); |
| 5770 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5771 | 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] | 5772 | " forward-locked app."); |
| 5773 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
| 5774 | } finally { |
| 5775 | //TODO clean up the extracted public files |
| 5776 | } |
| 5777 | if (mInstaller != null) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5778 | retCode = mInstaller.setForwardLockPerm(getApkName(newPackage.mPath), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5779 | newPackage.applicationInfo.uid); |
| 5780 | } else { |
| 5781 | final int filePermissions = |
| 5782 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5783 | retCode = FileUtils.setPermissions(newPackage.mPath, filePermissions, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5784 | newPackage.applicationInfo.uid); |
| 5785 | } |
| 5786 | } else { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5787 | // The permissions on the resource file was set when it was copied for |
| 5788 | // non forward locked apps and apps on sdcard |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5789 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | if (retCode != 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5792 | Slog.e(TAG, "Couldn't set new package file permissions for " + |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5793 | newPackage.mPath |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5794 | + ". The return code was: " + retCode); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5795 | // TODO Define new internal error |
| 5796 | return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5797 | } |
| 5798 | return PackageManager.INSTALL_SUCCEEDED; |
| 5799 | } |
| 5800 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 5801 | private boolean isForwardLocked(PackageParser.Package pkg) { |
| 5802 | return ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5803 | } |
| 5804 | |
| 5805 | private void extractPublicFiles(PackageParser.Package newPackage, |
| 5806 | File publicZipFile) throws IOException { |
| 5807 | final ZipOutputStream publicZipOutStream = |
| 5808 | new ZipOutputStream(new FileOutputStream(publicZipFile)); |
| 5809 | final ZipFile privateZip = new ZipFile(newPackage.mPath); |
| 5810 | |
| 5811 | // Copy manifest, resources.arsc and res directory to public zip |
| 5812 | |
| 5813 | final Enumeration<? extends ZipEntry> privateZipEntries = privateZip.entries(); |
| 5814 | while (privateZipEntries.hasMoreElements()) { |
| 5815 | final ZipEntry zipEntry = privateZipEntries.nextElement(); |
| 5816 | final String zipEntryName = zipEntry.getName(); |
| 5817 | if ("AndroidManifest.xml".equals(zipEntryName) |
| 5818 | || "resources.arsc".equals(zipEntryName) |
| 5819 | || zipEntryName.startsWith("res/")) { |
| 5820 | try { |
| 5821 | copyZipEntry(zipEntry, privateZip, publicZipOutStream); |
| 5822 | } catch (IOException e) { |
| 5823 | try { |
| 5824 | publicZipOutStream.close(); |
| 5825 | throw e; |
| 5826 | } finally { |
| 5827 | publicZipFile.delete(); |
| 5828 | } |
| 5829 | } |
| 5830 | } |
| 5831 | } |
| 5832 | |
| 5833 | publicZipOutStream.close(); |
| 5834 | FileUtils.setPermissions( |
| 5835 | publicZipFile.getAbsolutePath(), |
| 5836 | FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP|FileUtils.S_IROTH, |
| 5837 | -1, -1); |
| 5838 | } |
| 5839 | |
| 5840 | private static void copyZipEntry(ZipEntry zipEntry, |
| 5841 | ZipFile inZipFile, |
| 5842 | ZipOutputStream outZipStream) throws IOException { |
| 5843 | byte[] buffer = new byte[4096]; |
| 5844 | int num; |
| 5845 | |
| 5846 | ZipEntry newEntry; |
| 5847 | if (zipEntry.getMethod() == ZipEntry.STORED) { |
| 5848 | // Preserve the STORED method of the input entry. |
| 5849 | newEntry = new ZipEntry(zipEntry); |
| 5850 | } else { |
| 5851 | // Create a new entry so that the compressed len is recomputed. |
| 5852 | newEntry = new ZipEntry(zipEntry.getName()); |
| 5853 | } |
| 5854 | outZipStream.putNextEntry(newEntry); |
| 5855 | |
| 5856 | InputStream data = inZipFile.getInputStream(zipEntry); |
| 5857 | while ((num = data.read(buffer)) > 0) { |
| 5858 | outZipStream.write(buffer, 0, num); |
| 5859 | } |
| 5860 | outZipStream.flush(); |
| 5861 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5863 | private void deleteTempPackageFiles() { |
| 5864 | FilenameFilter filter = new FilenameFilter() { |
| 5865 | public boolean accept(File dir, String name) { |
| 5866 | return name.startsWith("vmdl") && name.endsWith(".tmp"); |
| 5867 | } |
| 5868 | }; |
| 5869 | String tmpFilesList[] = mAppInstallDir.list(filter); |
| 5870 | if(tmpFilesList == null) { |
| 5871 | return; |
| 5872 | } |
| 5873 | for(int i = 0; i < tmpFilesList.length; i++) { |
| 5874 | File tmpFile = new File(mAppInstallDir, tmpFilesList[i]); |
| 5875 | tmpFile.delete(); |
| 5876 | } |
| 5877 | } |
| 5878 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5879 | private File createTempPackageFile(File installDir) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5880 | File tmpPackageFile; |
| 5881 | try { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5882 | tmpPackageFile = File.createTempFile("vmdl", ".tmp", installDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5884 | 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] | 5885 | return null; |
| 5886 | } |
| 5887 | try { |
| 5888 | FileUtils.setPermissions( |
| 5889 | tmpPackageFile.getCanonicalPath(), FileUtils.S_IRUSR|FileUtils.S_IWUSR, |
| 5890 | -1, -1); |
| 5891 | } catch (IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5892 | 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] | 5893 | return null; |
| 5894 | } |
| 5895 | return tmpPackageFile; |
| 5896 | } |
| 5897 | |
| 5898 | public void deletePackage(final String packageName, |
| 5899 | final IPackageDeleteObserver observer, |
| 5900 | final int flags) { |
| 5901 | mContext.enforceCallingOrSelfPermission( |
| 5902 | android.Manifest.permission.DELETE_PACKAGES, null); |
| 5903 | // Queue up an async operation since the package deletion may take a little while. |
| 5904 | mHandler.post(new Runnable() { |
| 5905 | public void run() { |
| 5906 | mHandler.removeCallbacks(this); |
| 5907 | final boolean succeded = deletePackageX(packageName, true, true, flags); |
| 5908 | if (observer != null) { |
| 5909 | try { |
| 5910 | observer.packageDeleted(succeded); |
| 5911 | } catch (RemoteException e) { |
| 5912 | Log.i(TAG, "Observer no longer exists."); |
| 5913 | } //end catch |
| 5914 | } //end if |
| 5915 | } //end run |
| 5916 | }); |
| 5917 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5919 | /** |
| 5920 | * This method is an internal method that could be get invoked either |
| 5921 | * to delete an installed package or to clean up a failed installation. |
| 5922 | * After deleting an installed package, a broadcast is sent to notify any |
| 5923 | * listeners that the package has been installed. For cleaning up a failed |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5924 | * 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] | 5925 | * installation wouldn't have sent the initial broadcast either |
| 5926 | * The key steps in deleting a package are |
| 5927 | * deleting the package information in internal structures like mPackages, |
| 5928 | * deleting the packages base directories through installd |
| 5929 | * updating mSettings to reflect current status |
| 5930 | * persisting settings for later use |
| 5931 | * sending a broadcast if necessary |
| 5932 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5933 | private boolean deletePackageX(String packageName, boolean sendBroadCast, |
| 5934 | boolean deleteCodeAndResources, int flags) { |
| 5935 | PackageRemovedInfo info = new PackageRemovedInfo(); |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 5936 | boolean res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5937 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 5938 | IDevicePolicyManager dpm = IDevicePolicyManager.Stub.asInterface( |
| 5939 | ServiceManager.getService(Context.DEVICE_POLICY_SERVICE)); |
| 5940 | try { |
| 5941 | if (dpm != null && dpm.packageHasActiveAdmins(packageName)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 5942 | Slog.w(TAG, "Not removing package " + packageName + ": has active device admin"); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 5943 | return false; |
| 5944 | } |
| 5945 | } catch (RemoteException e) { |
| 5946 | } |
| 5947 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5948 | synchronized (mInstallLock) { |
| 5949 | res = deletePackageLI(packageName, deleteCodeAndResources, flags, info); |
| 5950 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5952 | if(res && sendBroadCast) { |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 5953 | boolean systemUpdate = info.isRemovedPackageSystemUpdate; |
| 5954 | info.sendBroadcast(deleteCodeAndResources, systemUpdate); |
| 5955 | |
| 5956 | // If the removed package was a system update, the old system packaged |
| 5957 | // was re-enabled; we need to broadcast this information |
| 5958 | if (systemUpdate) { |
| 5959 | Bundle extras = new Bundle(1); |
| 5960 | extras.putInt(Intent.EXTRA_UID, info.removedUid >= 0 ? info.removedUid : info.uid); |
| 5961 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 5962 | |
| 5963 | sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName, extras); |
| 5964 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, packageName, extras); |
| 5965 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5966 | } |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 5967 | // Force a gc here. |
| 5968 | Runtime.getRuntime().gc(); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5969 | // Delete the resources here after sending the broadcast to let |
| 5970 | // other processes clean up before deleting resources. |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 5971 | if (info.args != null) { |
| 5972 | synchronized (mInstallLock) { |
| 5973 | info.args.doPostDeleteLI(deleteCodeAndResources); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5974 | } |
| 5975 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5976 | return res; |
| 5977 | } |
| 5978 | |
| 5979 | static class PackageRemovedInfo { |
| 5980 | String removedPackage; |
| 5981 | int uid = -1; |
| 5982 | int removedUid = -1; |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 5983 | boolean isRemovedPackageSystemUpdate = false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 5984 | // Clean up resources deleted packages. |
| 5985 | InstallArgs args = null; |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 5986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5987 | void sendBroadcast(boolean fullRemove, boolean replacing) { |
| 5988 | Bundle extras = new Bundle(1); |
| 5989 | extras.putInt(Intent.EXTRA_UID, removedUid >= 0 ? removedUid : uid); |
| 5990 | extras.putBoolean(Intent.EXTRA_DATA_REMOVED, fullRemove); |
| 5991 | if (replacing) { |
| 5992 | extras.putBoolean(Intent.EXTRA_REPLACING, true); |
| 5993 | } |
| 5994 | if (removedPackage != null) { |
| 5995 | sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage, extras); |
| 5996 | } |
| 5997 | if (removedUid >= 0) { |
| 5998 | sendPackageBroadcast(Intent.ACTION_UID_REMOVED, null, extras); |
| 5999 | } |
| 6000 | } |
| 6001 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | /* |
| 6004 | * This method deletes the package from internal data structures. If the DONT_DELETE_DATA |
| 6005 | * flag is not set, the data directory is removed as well. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6006 | * 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] | 6007 | * delete a partially installed application. |
| 6008 | */ |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6009 | private void removePackageDataLI(PackageParser.Package p, PackageRemovedInfo outInfo, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6010 | int flags) { |
| 6011 | String packageName = p.packageName; |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6012 | if (outInfo != null) { |
| 6013 | outInfo.removedPackage = packageName; |
| 6014 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6015 | removePackageLI(p, true); |
| 6016 | // Retrieve object to delete permissions for shared user later on |
| 6017 | PackageSetting deletedPs; |
| 6018 | synchronized (mPackages) { |
| 6019 | deletedPs = mSettings.mPackages.get(packageName); |
| 6020 | } |
| 6021 | if ((flags&PackageManager.DONT_DELETE_DATA) == 0) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6022 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6023 | if (mInstaller != null) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6024 | int retCode = mInstaller.remove(packageName, useEncryptedFSDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6025 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6026 | 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] | 6027 | + packageName + ", retcode=" + retCode); |
| 6028 | // we don't consider this to be a failure of the core package deletion |
| 6029 | } |
| 6030 | } else { |
| 6031 | //for emulator |
| 6032 | PackageParser.Package pkg = mPackages.get(packageName); |
| 6033 | File dataDir = new File(pkg.applicationInfo.dataDir); |
| 6034 | dataDir.delete(); |
| 6035 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6036 | } |
| 6037 | synchronized (mPackages) { |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 6038 | if (deletedPs != null) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6039 | schedulePackageCleaning(packageName); |
| 6040 | |
| 6041 | if ((flags&PackageManager.DONT_DELETE_DATA) == 0) { |
| 6042 | if (outInfo != null) { |
| 6043 | outInfo.removedUid = mSettings.removePackageLP(packageName); |
| 6044 | } |
| 6045 | if (deletedPs != null) { |
| 6046 | updatePermissionsLP(deletedPs.name, null, false, false); |
| 6047 | if (deletedPs.sharedUser != null) { |
| 6048 | // remove permissions associated with package |
| 6049 | mSettings.updateSharedUserPermsLP(deletedPs, mGlobalGids); |
| 6050 | } |
| 6051 | } |
| 6052 | } |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 6053 | // remove from preferred activities. |
| 6054 | ArrayList<PreferredActivity> removed = new ArrayList<PreferredActivity>(); |
| 6055 | for (PreferredActivity pa : mSettings.mPreferredActivities.filterSet()) { |
| 6056 | if (pa.mActivity.getPackageName().equals(deletedPs.name)) { |
| 6057 | removed.add(pa); |
| 6058 | } |
| 6059 | } |
| 6060 | for (PreferredActivity pa : removed) { |
| 6061 | mSettings.mPreferredActivities.removeFilter(pa); |
| 6062 | } |
| 6063 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6064 | // Save settings now |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 6065 | mSettings.writeLP(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6066 | } |
| 6067 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6068 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6069 | /* |
| 6070 | * Tries to delete system package. |
| 6071 | */ |
| 6072 | private boolean deleteSystemPackageLI(PackageParser.Package p, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6073 | int flags, PackageRemovedInfo outInfo) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6074 | ApplicationInfo applicationInfo = p.applicationInfo; |
| 6075 | //applicable for non-partially installed applications only |
| 6076 | if (applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6077 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6078 | return false; |
| 6079 | } |
| 6080 | PackageSetting ps = null; |
| 6081 | // Confirm if the system package has been updated |
| 6082 | // An updated system app can be deleted. This will also have to restore |
| 6083 | // the system pkg from system partition |
| 6084 | synchronized (mPackages) { |
| 6085 | ps = mSettings.getDisabledSystemPkg(p.packageName); |
| 6086 | } |
| 6087 | if (ps == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6088 | 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] | 6089 | return false; |
| 6090 | } else { |
| 6091 | Log.i(TAG, "Deleting system pkg from data partition"); |
| 6092 | } |
| 6093 | // Delete the updated package |
Romain Guy | 96f4357 | 2009-03-24 20:27:49 -0700 | [diff] [blame] | 6094 | outInfo.isRemovedPackageSystemUpdate = true; |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6095 | boolean deleteCodeAndResources = false; |
| 6096 | if (ps.versionCode < p.mVersionCode) { |
| 6097 | // Delete code and resources for downgrades |
| 6098 | deleteCodeAndResources = true; |
| 6099 | if ((flags & PackageManager.DONT_DELETE_DATA) == 0) { |
| 6100 | flags &= ~PackageManager.DONT_DELETE_DATA; |
| 6101 | } |
| 6102 | } else { |
| 6103 | // Preserve data by setting flag |
| 6104 | if ((flags & PackageManager.DONT_DELETE_DATA) == 0) { |
| 6105 | flags |= PackageManager.DONT_DELETE_DATA; |
| 6106 | } |
| 6107 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6108 | boolean ret = deleteInstalledPackageLI(p, deleteCodeAndResources, flags, outInfo); |
| 6109 | if (!ret) { |
| 6110 | return false; |
| 6111 | } |
| 6112 | synchronized (mPackages) { |
| 6113 | // Reinstate the old system package |
| 6114 | mSettings.enableSystemPackageLP(p.packageName); |
| 6115 | } |
| 6116 | // Install the system package |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6117 | PackageParser.Package newPkg = scanPackageLI(ps.codePath, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6118 | PackageParser.PARSE_MUST_BE_APK | PackageParser.PARSE_IS_SYSTEM, |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6119 | SCAN_MONITOR | SCAN_NO_PATHS); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6121 | if (newPkg == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6122 | 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] | 6123 | return false; |
| 6124 | } |
| 6125 | synchronized (mPackages) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6126 | updatePermissionsLP(newPkg.packageName, newPkg, true, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6127 | mSettings.writeLP(); |
| 6128 | } |
| 6129 | return true; |
| 6130 | } |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6132 | private boolean deleteInstalledPackageLI(PackageParser.Package p, |
| 6133 | boolean deleteCodeAndResources, int flags, PackageRemovedInfo outInfo) { |
| 6134 | ApplicationInfo applicationInfo = p.applicationInfo; |
| 6135 | if (applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6136 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6137 | return false; |
| 6138 | } |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 6139 | if (outInfo != null) { |
| 6140 | outInfo.uid = applicationInfo.uid; |
| 6141 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6142 | |
| 6143 | // Delete package data from internal structures and also remove data if flag is set |
| 6144 | removePackageDataLI(p, outInfo, flags); |
| 6145 | |
| 6146 | // Delete application code and resources |
| 6147 | if (deleteCodeAndResources) { |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6148 | // TODO can pick up from PackageSettings as well |
Suchi Amalapurapu | 6069beb | 2010-03-10 09:46:49 -0800 | [diff] [blame] | 6149 | int installFlags = ((p.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE)!=0) ? |
Suchi Amalapurapu | 5b993ce | 2010-02-12 09:43:29 -0800 | [diff] [blame] | 6150 | PackageManager.INSTALL_EXTERNAL : 0; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6151 | installFlags |= ((p.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK)!=0) ? |
| 6152 | PackageManager.INSTALL_FORWARD_LOCK : 0; |
| 6153 | outInfo.args = createInstallArgs(installFlags, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 6154 | applicationInfo.sourceDir, applicationInfo.publicSourceDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6155 | } |
| 6156 | return true; |
| 6157 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6159 | /* |
| 6160 | * This method handles package deletion in general |
| 6161 | */ |
| 6162 | private boolean deletePackageLI(String packageName, |
| 6163 | boolean deleteCodeAndResources, int flags, PackageRemovedInfo outInfo) { |
| 6164 | if (packageName == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6165 | Slog.w(TAG, "Attempt to delete null packageName."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6166 | return false; |
| 6167 | } |
| 6168 | PackageParser.Package p; |
| 6169 | boolean dataOnly = false; |
| 6170 | synchronized (mPackages) { |
| 6171 | p = mPackages.get(packageName); |
| 6172 | if (p == null) { |
| 6173 | //this retrieves partially installed apps |
| 6174 | dataOnly = true; |
| 6175 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6176 | if (ps == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6177 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6178 | return false; |
| 6179 | } |
| 6180 | p = ps.pkg; |
| 6181 | } |
| 6182 | } |
| 6183 | if (p == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6184 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6185 | return false; |
| 6186 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6188 | if (dataOnly) { |
| 6189 | // Delete application data first |
| 6190 | removePackageDataLI(p, outInfo, flags); |
| 6191 | return true; |
| 6192 | } |
| 6193 | // At this point the package should have ApplicationInfo associated with it |
| 6194 | if (p.applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6195 | Slog.w(TAG, "Package " + p.packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6196 | return false; |
| 6197 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6198 | boolean ret = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6199 | if ( (p.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 6200 | Log.i(TAG, "Removing system package:"+p.packageName); |
| 6201 | // When an updated system application is deleted we delete the existing resources as well and |
| 6202 | // fall back to existing code in system partition |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6203 | ret = deleteSystemPackageLI(p, flags, outInfo); |
| 6204 | } else { |
| 6205 | Log.i(TAG, "Removing non-system package:"+p.packageName); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 6206 | // Kill application pre-emptively especially for apps on sd. |
| 6207 | killApplication(packageName, p.applicationInfo.uid); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6208 | ret = deleteInstalledPackageLI (p, deleteCodeAndResources, flags, outInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 6210 | return ret; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6211 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6213 | public void clearApplicationUserData(final String packageName, |
| 6214 | final IPackageDataObserver observer) { |
| 6215 | mContext.enforceCallingOrSelfPermission( |
| 6216 | android.Manifest.permission.CLEAR_APP_USER_DATA, null); |
| 6217 | // Queue up an async operation since the package deletion may take a little while. |
| 6218 | mHandler.post(new Runnable() { |
| 6219 | public void run() { |
| 6220 | mHandler.removeCallbacks(this); |
| 6221 | final boolean succeeded; |
| 6222 | synchronized (mInstallLock) { |
| 6223 | succeeded = clearApplicationUserDataLI(packageName); |
| 6224 | } |
| 6225 | if (succeeded) { |
| 6226 | // invoke DeviceStorageMonitor's update method to clear any notifications |
| 6227 | DeviceStorageMonitorService dsm = (DeviceStorageMonitorService) |
| 6228 | ServiceManager.getService(DeviceStorageMonitorService.SERVICE); |
| 6229 | if (dsm != null) { |
| 6230 | dsm.updateMemory(); |
| 6231 | } |
| 6232 | } |
| 6233 | if(observer != null) { |
| 6234 | try { |
| 6235 | observer.onRemoveCompleted(packageName, succeeded); |
| 6236 | } catch (RemoteException e) { |
| 6237 | Log.i(TAG, "Observer no longer exists."); |
| 6238 | } |
| 6239 | } //end if observer |
| 6240 | } //end run |
| 6241 | }); |
| 6242 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6244 | private boolean clearApplicationUserDataLI(String packageName) { |
| 6245 | if (packageName == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6246 | Slog.w(TAG, "Attempt to delete null packageName."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6247 | return false; |
| 6248 | } |
| 6249 | PackageParser.Package p; |
| 6250 | boolean dataOnly = false; |
| 6251 | synchronized (mPackages) { |
| 6252 | p = mPackages.get(packageName); |
| 6253 | if(p == null) { |
| 6254 | dataOnly = true; |
| 6255 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6256 | if((ps == null) || (ps.pkg == null)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6257 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6258 | return false; |
| 6259 | } |
| 6260 | p = ps.pkg; |
| 6261 | } |
| 6262 | } |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6263 | boolean useEncryptedFSDir = false; |
| 6264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6265 | if(!dataOnly) { |
| 6266 | //need to check this only for fully installed applications |
| 6267 | if (p == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6268 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6269 | return false; |
| 6270 | } |
| 6271 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6272 | if (applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6273 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6274 | return false; |
| 6275 | } |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6276 | useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6277 | } |
| 6278 | if (mInstaller != null) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6279 | int retCode = mInstaller.clearUserData(packageName, useEncryptedFSDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6280 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6281 | 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] | 6282 | + packageName); |
| 6283 | return false; |
| 6284 | } |
| 6285 | } |
| 6286 | return true; |
| 6287 | } |
| 6288 | |
| 6289 | public void deleteApplicationCacheFiles(final String packageName, |
| 6290 | final IPackageDataObserver observer) { |
| 6291 | mContext.enforceCallingOrSelfPermission( |
| 6292 | android.Manifest.permission.DELETE_CACHE_FILES, null); |
| 6293 | // Queue up an async operation since the package deletion may take a little while. |
| 6294 | mHandler.post(new Runnable() { |
| 6295 | public void run() { |
| 6296 | mHandler.removeCallbacks(this); |
| 6297 | final boolean succeded; |
| 6298 | synchronized (mInstallLock) { |
| 6299 | succeded = deleteApplicationCacheFilesLI(packageName); |
| 6300 | } |
| 6301 | if(observer != null) { |
| 6302 | try { |
| 6303 | observer.onRemoveCompleted(packageName, succeded); |
| 6304 | } catch (RemoteException e) { |
| 6305 | Log.i(TAG, "Observer no longer exists."); |
| 6306 | } |
| 6307 | } //end if observer |
| 6308 | } //end run |
| 6309 | }); |
| 6310 | } |
| 6311 | |
| 6312 | private boolean deleteApplicationCacheFilesLI(String packageName) { |
| 6313 | if (packageName == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6314 | Slog.w(TAG, "Attempt to delete null packageName."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6315 | return false; |
| 6316 | } |
| 6317 | PackageParser.Package p; |
| 6318 | synchronized (mPackages) { |
| 6319 | p = mPackages.get(packageName); |
| 6320 | } |
| 6321 | if (p == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6322 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6323 | return false; |
| 6324 | } |
| 6325 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6326 | if (applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6327 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6328 | return false; |
| 6329 | } |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6330 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6331 | if (mInstaller != null) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6332 | int retCode = mInstaller.deleteCacheFiles(packageName, useEncryptedFSDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6333 | if (retCode < 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6334 | 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] | 6335 | + packageName); |
| 6336 | return false; |
| 6337 | } |
| 6338 | } |
| 6339 | return true; |
| 6340 | } |
| 6341 | |
| 6342 | public void getPackageSizeInfo(final String packageName, |
| 6343 | final IPackageStatsObserver observer) { |
| 6344 | mContext.enforceCallingOrSelfPermission( |
| 6345 | android.Manifest.permission.GET_PACKAGE_SIZE, null); |
| 6346 | // Queue up an async operation since the package deletion may take a little while. |
| 6347 | mHandler.post(new Runnable() { |
| 6348 | public void run() { |
| 6349 | mHandler.removeCallbacks(this); |
| 6350 | PackageStats lStats = new PackageStats(packageName); |
| 6351 | final boolean succeded; |
| 6352 | synchronized (mInstallLock) { |
| 6353 | succeded = getPackageSizeInfoLI(packageName, lStats); |
| 6354 | } |
| 6355 | if(observer != null) { |
| 6356 | try { |
| 6357 | observer.onGetStatsCompleted(lStats, succeded); |
| 6358 | } catch (RemoteException e) { |
| 6359 | Log.i(TAG, "Observer no longer exists."); |
| 6360 | } |
| 6361 | } //end if observer |
| 6362 | } //end run |
| 6363 | }); |
| 6364 | } |
| 6365 | |
| 6366 | private boolean getPackageSizeInfoLI(String packageName, PackageStats pStats) { |
| 6367 | if (packageName == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6368 | 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] | 6369 | return false; |
| 6370 | } |
| 6371 | PackageParser.Package p; |
| 6372 | boolean dataOnly = false; |
| 6373 | synchronized (mPackages) { |
| 6374 | p = mPackages.get(packageName); |
| 6375 | if(p == null) { |
| 6376 | dataOnly = true; |
| 6377 | PackageSetting ps = mSettings.mPackages.get(packageName); |
| 6378 | if((ps == null) || (ps.pkg == null)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6379 | Slog.w(TAG, "Package named '" + packageName +"' doesn't exist."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6380 | return false; |
| 6381 | } |
| 6382 | p = ps.pkg; |
| 6383 | } |
| 6384 | } |
| 6385 | String publicSrcDir = null; |
| 6386 | if(!dataOnly) { |
| 6387 | final ApplicationInfo applicationInfo = p.applicationInfo; |
| 6388 | if (applicationInfo == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6389 | Slog.w(TAG, "Package " + packageName + " has no applicationInfo."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6390 | return false; |
| 6391 | } |
| 6392 | publicSrcDir = isForwardLocked(p) ? applicationInfo.publicSourceDir : null; |
| 6393 | } |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6394 | boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6395 | if (mInstaller != null) { |
| 6396 | int res = mInstaller.getSizeInfo(packageName, p.mPath, |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 6397 | publicSrcDir, pStats, useEncryptedFSDir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6398 | if (res < 0) { |
| 6399 | return false; |
| 6400 | } else { |
| 6401 | return true; |
| 6402 | } |
| 6403 | } |
| 6404 | return true; |
| 6405 | } |
| 6406 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6408 | public void addPackageToPreferred(String packageName) { |
| 6409 | mContext.enforceCallingOrSelfPermission( |
| 6410 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6411 | Slog.w(TAG, "addPackageToPreferred: no longer implemented"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6412 | } |
| 6413 | |
| 6414 | public void removePackageFromPreferred(String packageName) { |
| 6415 | mContext.enforceCallingOrSelfPermission( |
| 6416 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6417 | Slog.w(TAG, "removePackageFromPreferred: no longer implemented"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6418 | } |
| 6419 | |
| 6420 | public List<PackageInfo> getPreferredPackages(int flags) { |
Dianne Hackborn | a7ca0e5 | 2009-12-01 14:31:55 -0800 | [diff] [blame] | 6421 | return new ArrayList<PackageInfo>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6422 | } |
| 6423 | |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6424 | int getUidTargetSdkVersionLockedLP(int uid) { |
| 6425 | Object obj = mSettings.getUserIdLP(uid); |
| 6426 | if (obj instanceof SharedUserSetting) { |
| 6427 | SharedUserSetting sus = (SharedUserSetting)obj; |
| 6428 | final int N = sus.packages.size(); |
| 6429 | int vers = Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 6430 | Iterator<PackageSetting> it = sus.packages.iterator(); |
| 6431 | int i=0; |
| 6432 | while (it.hasNext()) { |
| 6433 | PackageSetting ps = it.next(); |
| 6434 | if (ps.pkg != null) { |
| 6435 | int v = ps.pkg.applicationInfo.targetSdkVersion; |
| 6436 | if (v < vers) vers = v; |
| 6437 | } |
| 6438 | } |
| 6439 | return vers; |
| 6440 | } else if (obj instanceof PackageSetting) { |
| 6441 | PackageSetting ps = (PackageSetting)obj; |
| 6442 | if (ps.pkg != null) { |
| 6443 | return ps.pkg.applicationInfo.targetSdkVersion; |
| 6444 | } |
| 6445 | } |
| 6446 | return Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 6447 | } |
| 6448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6449 | public void addPreferredActivity(IntentFilter filter, int match, |
| 6450 | ComponentName[] set, ComponentName activity) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6451 | synchronized (mPackages) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6452 | if (mContext.checkCallingOrSelfPermission( |
| 6453 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6454 | != PackageManager.PERMISSION_GRANTED) { |
| 6455 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6456 | < Build.VERSION_CODES.FROYO) { |
| 6457 | Slog.w(TAG, "Ignoring addPreferredActivity() from uid " |
| 6458 | + Binder.getCallingUid()); |
| 6459 | return; |
| 6460 | } |
| 6461 | mContext.enforceCallingOrSelfPermission( |
| 6462 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6463 | } |
| 6464 | |
| 6465 | Slog.i(TAG, "Adding preferred activity " + activity + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6466 | filter.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 6467 | mSettings.mPreferredActivities.addFilter( |
| 6468 | new PreferredActivity(filter, match, set, activity)); |
| 6469 | mSettings.writeLP(); |
| 6470 | } |
| 6471 | } |
| 6472 | |
Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6473 | public void replacePreferredActivity(IntentFilter filter, int match, |
| 6474 | ComponentName[] set, ComponentName activity) { |
Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6475 | if (filter.countActions() != 1) { |
| 6476 | throw new IllegalArgumentException( |
| 6477 | "replacePreferredActivity expects filter to have only 1 action."); |
| 6478 | } |
| 6479 | if (filter.countCategories() != 1) { |
| 6480 | throw new IllegalArgumentException( |
| 6481 | "replacePreferredActivity expects filter to have only 1 category."); |
| 6482 | } |
| 6483 | if (filter.countDataAuthorities() != 0 |
| 6484 | || filter.countDataPaths() != 0 |
| 6485 | || filter.countDataSchemes() != 0 |
| 6486 | || filter.countDataTypes() != 0) { |
| 6487 | throw new IllegalArgumentException( |
| 6488 | "replacePreferredActivity expects filter to have no data authorities, " + |
| 6489 | "paths, schemes or types."); |
| 6490 | } |
| 6491 | synchronized (mPackages) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6492 | if (mContext.checkCallingOrSelfPermission( |
| 6493 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6494 | != PackageManager.PERMISSION_GRANTED) { |
| 6495 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6496 | < Build.VERSION_CODES.FROYO) { |
| 6497 | Slog.w(TAG, "Ignoring replacePreferredActivity() from uid " |
| 6498 | + Binder.getCallingUid()); |
| 6499 | return; |
| 6500 | } |
| 6501 | mContext.enforceCallingOrSelfPermission( |
| 6502 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6503 | } |
| 6504 | |
Satish Sampath | 8dbe612 | 2009-06-02 23:35:54 +0100 | [diff] [blame] | 6505 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6506 | String action = filter.getAction(0); |
| 6507 | String category = filter.getCategory(0); |
| 6508 | while (it.hasNext()) { |
| 6509 | PreferredActivity pa = it.next(); |
| 6510 | if (pa.getAction(0).equals(action) && pa.getCategory(0).equals(category)) { |
| 6511 | it.remove(); |
| 6512 | Log.i(TAG, "Removed preferred activity " + pa.mActivity + ":"); |
| 6513 | filter.dump(new LogPrinter(Log.INFO, TAG), " "); |
| 6514 | } |
| 6515 | } |
| 6516 | addPreferredActivity(filter, match, set, activity); |
| 6517 | } |
| 6518 | } |
| 6519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6520 | public void clearPackagePreferredActivities(String packageName) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6521 | synchronized (mPackages) { |
Dianne Hackborn | 2ee89ea | 2010-03-10 18:27:09 -0800 | [diff] [blame] | 6522 | int uid = Binder.getCallingUid(); |
| 6523 | PackageParser.Package pkg = mPackages.get(packageName); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6524 | if (pkg == null || pkg.applicationInfo.uid != uid) { |
| 6525 | if (mContext.checkCallingOrSelfPermission( |
| 6526 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS) |
| 6527 | != PackageManager.PERMISSION_GRANTED) { |
| 6528 | if (getUidTargetSdkVersionLockedLP(Binder.getCallingUid()) |
| 6529 | < Build.VERSION_CODES.FROYO) { |
| 6530 | Slog.w(TAG, "Ignoring clearPackagePreferredActivities() from uid " |
| 6531 | + Binder.getCallingUid()); |
| 6532 | return; |
| 6533 | } |
| 6534 | mContext.enforceCallingOrSelfPermission( |
| 6535 | android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null); |
| 6536 | } |
Dianne Hackborn | 2ee89ea | 2010-03-10 18:27:09 -0800 | [diff] [blame] | 6537 | } |
| 6538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6539 | if (clearPackagePreferredActivitiesLP(packageName)) { |
| 6540 | mSettings.writeLP(); |
| 6541 | } |
| 6542 | } |
| 6543 | } |
| 6544 | |
| 6545 | boolean clearPackagePreferredActivitiesLP(String packageName) { |
| 6546 | boolean changed = false; |
| 6547 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6548 | while (it.hasNext()) { |
| 6549 | PreferredActivity pa = it.next(); |
| 6550 | if (pa.mActivity.getPackageName().equals(packageName)) { |
| 6551 | it.remove(); |
| 6552 | changed = true; |
| 6553 | } |
| 6554 | } |
| 6555 | return changed; |
| 6556 | } |
| 6557 | |
| 6558 | public int getPreferredActivities(List<IntentFilter> outFilters, |
| 6559 | List<ComponentName> outActivities, String packageName) { |
| 6560 | |
| 6561 | int num = 0; |
| 6562 | synchronized (mPackages) { |
| 6563 | Iterator<PreferredActivity> it = mSettings.mPreferredActivities.filterIterator(); |
| 6564 | while (it.hasNext()) { |
| 6565 | PreferredActivity pa = it.next(); |
| 6566 | if (packageName == null |
| 6567 | || pa.mActivity.getPackageName().equals(packageName)) { |
| 6568 | if (outFilters != null) { |
| 6569 | outFilters.add(new IntentFilter(pa)); |
| 6570 | } |
| 6571 | if (outActivities != null) { |
| 6572 | outActivities.add(pa.mActivity); |
| 6573 | } |
| 6574 | } |
| 6575 | } |
| 6576 | } |
| 6577 | |
| 6578 | return num; |
| 6579 | } |
| 6580 | |
| 6581 | public void setApplicationEnabledSetting(String appPackageName, |
| 6582 | int newState, int flags) { |
| 6583 | setEnabledSetting(appPackageName, null, newState, flags); |
| 6584 | } |
| 6585 | |
| 6586 | public void setComponentEnabledSetting(ComponentName componentName, |
| 6587 | int newState, int flags) { |
| 6588 | setEnabledSetting(componentName.getPackageName(), |
| 6589 | componentName.getClassName(), newState, flags); |
| 6590 | } |
| 6591 | |
| 6592 | private void setEnabledSetting( |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6593 | 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] | 6594 | if (!(newState == COMPONENT_ENABLED_STATE_DEFAULT |
| 6595 | || newState == COMPONENT_ENABLED_STATE_ENABLED |
| 6596 | || newState == COMPONENT_ENABLED_STATE_DISABLED)) { |
| 6597 | throw new IllegalArgumentException("Invalid new component state: " |
| 6598 | + newState); |
| 6599 | } |
| 6600 | PackageSetting pkgSetting; |
| 6601 | final int uid = Binder.getCallingUid(); |
| 6602 | final int permission = mContext.checkCallingPermission( |
| 6603 | android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE); |
| 6604 | final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6605 | boolean sendNow = false; |
| 6606 | boolean isApp = (className == null); |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6607 | String componentName = isApp ? packageName : className; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6608 | int packageUid = -1; |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6609 | ArrayList<String> components; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6610 | synchronized (mPackages) { |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6611 | pkgSetting = mSettings.mPackages.get(packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6612 | if (pkgSetting == null) { |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6613 | if (className == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6614 | throw new IllegalArgumentException( |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6615 | "Unknown package: " + packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6616 | } |
| 6617 | throw new IllegalArgumentException( |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6618 | "Unknown component: " + packageName |
| 6619 | + "/" + className); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6620 | } |
| 6621 | if (!allowedByPermission && (uid != pkgSetting.userId)) { |
| 6622 | throw new SecurityException( |
| 6623 | "Permission Denial: attempt to change component state from pid=" |
| 6624 | + Binder.getCallingPid() |
| 6625 | + ", uid=" + uid + ", package uid=" + pkgSetting.userId); |
| 6626 | } |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6627 | if (className == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6628 | // We're dealing with an application/package level state change |
| 6629 | pkgSetting.enabled = newState; |
| 6630 | } else { |
| 6631 | // We're dealing with a component level state change |
| 6632 | switch (newState) { |
| 6633 | case COMPONENT_ENABLED_STATE_ENABLED: |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6634 | pkgSetting.enableComponentLP(className); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6635 | break; |
| 6636 | case COMPONENT_ENABLED_STATE_DISABLED: |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6637 | pkgSetting.disableComponentLP(className); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6638 | break; |
| 6639 | case COMPONENT_ENABLED_STATE_DEFAULT: |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6640 | pkgSetting.restoreComponentLP(className); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6641 | break; |
| 6642 | default: |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 6643 | Slog.e(TAG, "Invalid new component state: " + newState); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6644 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6645 | } |
| 6646 | } |
| 6647 | mSettings.writeLP(); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6648 | packageUid = pkgSetting.userId; |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6649 | components = mPendingBroadcasts.get(packageName); |
| 6650 | boolean newPackage = components == null; |
| 6651 | if (newPackage) { |
| 6652 | components = new ArrayList<String>(); |
| 6653 | } |
| 6654 | if (!components.contains(componentName)) { |
| 6655 | components.add(componentName); |
| 6656 | } |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6657 | if ((flags&PackageManager.DONT_KILL_APP) == 0) { |
| 6658 | sendNow = true; |
| 6659 | // Purge entry from pending broadcast list if another one exists already |
| 6660 | // since we are sending one right away. |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6661 | mPendingBroadcasts.remove(packageName); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6662 | } else { |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6663 | if (newPackage) { |
| 6664 | mPendingBroadcasts.put(packageName, components); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6665 | } |
| 6666 | if (!mHandler.hasMessages(SEND_PENDING_BROADCAST)) { |
| 6667 | // Schedule a message |
| 6668 | mHandler.sendEmptyMessageDelayed(SEND_PENDING_BROADCAST, BROADCAST_DELAY); |
| 6669 | } |
| 6670 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6671 | } |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6673 | long callingId = Binder.clearCallingIdentity(); |
| 6674 | try { |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6675 | if (sendNow) { |
| 6676 | sendPackageChangedBroadcast(packageName, |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6677 | (flags&PackageManager.DONT_KILL_APP) != 0, components, packageUid); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6678 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | } finally { |
| 6680 | Binder.restoreCallingIdentity(callingId); |
| 6681 | } |
| 6682 | } |
| 6683 | |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6684 | private void sendPackageChangedBroadcast(String packageName, |
Dianne Hackborn | 86a72da | 2009-11-11 20:12:41 -0800 | [diff] [blame] | 6685 | boolean killFlag, ArrayList<String> componentNames, int packageUid) { |
| 6686 | if (false) Log.v(TAG, "Sending package changed: package=" + packageName |
| 6687 | + " components=" + componentNames); |
| 6688 | Bundle extras = new Bundle(4); |
| 6689 | extras.putString(Intent.EXTRA_CHANGED_COMPONENT_NAME, componentNames.get(0)); |
| 6690 | String nameList[] = new String[componentNames.size()]; |
| 6691 | componentNames.toArray(nameList); |
| 6692 | extras.putStringArray(Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST, nameList); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6693 | extras.putBoolean(Intent.EXTRA_DONT_KILL_APP, killFlag); |
| 6694 | extras.putInt(Intent.EXTRA_UID, packageUid); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6695 | sendPackageBroadcast(Intent.ACTION_PACKAGE_CHANGED, packageName, extras); |
Suchi Amalapurapu | 0214e94 | 2009-09-02 11:03:18 -0700 | [diff] [blame] | 6696 | } |
| 6697 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 6698 | public String getInstallerPackageName(String packageName) { |
| 6699 | synchronized (mPackages) { |
| 6700 | PackageSetting pkg = mSettings.mPackages.get(packageName); |
| 6701 | if (pkg == null) { |
| 6702 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 6703 | } |
| 6704 | return pkg.installerPackageName; |
| 6705 | } |
| 6706 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6708 | public int getApplicationEnabledSetting(String appPackageName) { |
| 6709 | synchronized (mPackages) { |
| 6710 | PackageSetting pkg = mSettings.mPackages.get(appPackageName); |
| 6711 | if (pkg == null) { |
| 6712 | throw new IllegalArgumentException("Unknown package: " + appPackageName); |
| 6713 | } |
| 6714 | return pkg.enabled; |
| 6715 | } |
| 6716 | } |
| 6717 | |
| 6718 | public int getComponentEnabledSetting(ComponentName componentName) { |
| 6719 | synchronized (mPackages) { |
| 6720 | final String packageNameStr = componentName.getPackageName(); |
| 6721 | PackageSetting pkg = mSettings.mPackages.get(packageNameStr); |
| 6722 | if (pkg == null) { |
| 6723 | throw new IllegalArgumentException("Unknown component: " + componentName); |
| 6724 | } |
| 6725 | final String classNameStr = componentName.getClassName(); |
| 6726 | return pkg.currentEnabledStateLP(classNameStr); |
| 6727 | } |
| 6728 | } |
| 6729 | |
| 6730 | public void enterSafeMode() { |
| 6731 | if (!mSystemReady) { |
| 6732 | mSafeMode = true; |
| 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | public void systemReady() { |
| 6737 | mSystemReady = true; |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6738 | |
| 6739 | // Read the compatibilty setting when the system is ready. |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6740 | boolean compatibilityModeEnabled = android.provider.Settings.System.getInt( |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6741 | mContext.getContentResolver(), |
| 6742 | android.provider.Settings.System.COMPATIBILITY_MODE, 1) == 1; |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6743 | PackageParser.setCompatibilityModeEnabled(compatibilityModeEnabled); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6744 | if (DEBUG_SETTINGS) { |
Mitsuru Oshima | 69fff4a | 2009-07-21 09:51:05 -0700 | [diff] [blame] | 6745 | Log.d(TAG, "compatibility mode:" + compatibilityModeEnabled); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6746 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6747 | } |
| 6748 | |
| 6749 | public boolean isSafeMode() { |
| 6750 | return mSafeMode; |
| 6751 | } |
| 6752 | |
| 6753 | public boolean hasSystemUidErrors() { |
| 6754 | return mHasSystemUidErrors; |
| 6755 | } |
| 6756 | |
| 6757 | static String arrayToString(int[] array) { |
| 6758 | StringBuffer buf = new StringBuffer(128); |
| 6759 | buf.append('['); |
| 6760 | if (array != null) { |
| 6761 | for (int i=0; i<array.length; i++) { |
| 6762 | if (i > 0) buf.append(", "); |
| 6763 | buf.append(array[i]); |
| 6764 | } |
| 6765 | } |
| 6766 | buf.append(']'); |
| 6767 | return buf.toString(); |
| 6768 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6770 | @Override |
| 6771 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 6772 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6773 | != PackageManager.PERMISSION_GRANTED) { |
| 6774 | pw.println("Permission Denial: can't dump ActivityManager from from pid=" |
| 6775 | + Binder.getCallingPid() |
| 6776 | + ", uid=" + Binder.getCallingUid() |
| 6777 | + " without permission " |
| 6778 | + android.Manifest.permission.DUMP); |
| 6779 | return; |
| 6780 | } |
| 6781 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6782 | String packageName = null; |
| 6783 | |
| 6784 | int opti = 0; |
| 6785 | while (opti < args.length) { |
| 6786 | String opt = args[opti]; |
| 6787 | if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') { |
| 6788 | break; |
| 6789 | } |
| 6790 | opti++; |
| 6791 | if ("-a".equals(opt)) { |
| 6792 | // Right now we only know how to print all. |
| 6793 | } else if ("-h".equals(opt)) { |
| 6794 | pw.println("Package manager dump options:"); |
| 6795 | pw.println(" [-h] [cmd] ..."); |
| 6796 | pw.println(" cmd may be one of:"); |
| 6797 | pw.println(" [package.name]: info about given package"); |
| 6798 | return; |
| 6799 | } else { |
| 6800 | pw.println("Unknown argument: " + opt + "; use -h for help"); |
| 6801 | } |
| 6802 | } |
| 6803 | |
| 6804 | // Is the caller requesting to dump a particular piece of data? |
| 6805 | if (opti < args.length) { |
| 6806 | String cmd = args[opti]; |
| 6807 | opti++; |
| 6808 | // Is this a package name? |
| 6809 | if ("android".equals(cmd) || cmd.contains(".")) { |
| 6810 | packageName = cmd; |
| 6811 | } |
| 6812 | } |
| 6813 | |
| 6814 | boolean printedTitle = false; |
| 6815 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6816 | synchronized (mPackages) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6817 | if (mActivities.dump(pw, "Activity Resolver Table:", " ", packageName)) { |
| 6818 | printedTitle = true; |
| 6819 | } |
| 6820 | if (mReceivers.dump(pw, printedTitle |
| 6821 | ? "\nReceiver Resolver Table:" : "Receiver Resolver Table:", |
| 6822 | " ", packageName)) { |
| 6823 | printedTitle = true; |
| 6824 | } |
| 6825 | if (mServices.dump(pw, printedTitle |
| 6826 | ? "\nService Resolver Table:" : "Service Resolver Table:", |
| 6827 | " ", packageName)) { |
| 6828 | printedTitle = true; |
| 6829 | } |
| 6830 | if (mSettings.mPreferredActivities.dump(pw, printedTitle |
| 6831 | ? "\nPreferred Activities:" : "Preferred Activities:", |
| 6832 | " ", packageName)) { |
| 6833 | printedTitle = true; |
| 6834 | } |
| 6835 | boolean printedSomething = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6836 | { |
| 6837 | for (BasePermission p : mSettings.mPermissions.values()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6838 | if (packageName != null && !packageName.equals(p.sourcePackage)) { |
| 6839 | continue; |
| 6840 | } |
| 6841 | if (!printedSomething) { |
| 6842 | if (printedTitle) pw.println(" "); |
| 6843 | pw.println("Permissions:"); |
| 6844 | printedSomething = true; |
| 6845 | printedTitle = true; |
| 6846 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6847 | pw.print(" Permission ["); pw.print(p.name); pw.print("] ("); |
| 6848 | pw.print(Integer.toHexString(System.identityHashCode(p))); |
| 6849 | pw.println("):"); |
| 6850 | pw.print(" sourcePackage="); pw.println(p.sourcePackage); |
| 6851 | pw.print(" uid="); pw.print(p.uid); |
| 6852 | pw.print(" gids="); pw.print(arrayToString(p.gids)); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6853 | pw.print(" type="); pw.print(p.type); |
| 6854 | pw.print(" prot="); pw.println(p.protectionLevel); |
| 6855 | if (p.packageSetting != null) { |
| 6856 | pw.print(" packageSetting="); pw.println(p.packageSetting); |
| 6857 | } |
| 6858 | if (p.perm != null) { |
| 6859 | pw.print(" perm="); pw.println(p.perm); |
| 6860 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6861 | } |
| 6862 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6863 | printedSomething = false; |
| 6864 | SharedUserSetting packageSharedUser = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6865 | { |
| 6866 | for (PackageSetting ps : mSettings.mPackages.values()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6867 | if (packageName != null && !packageName.equals(ps.realName) |
| 6868 | && !packageName.equals(ps.name)) { |
| 6869 | continue; |
| 6870 | } |
| 6871 | if (!printedSomething) { |
| 6872 | if (printedTitle) pw.println(" "); |
| 6873 | pw.println("Packages:"); |
| 6874 | printedSomething = true; |
| 6875 | printedTitle = true; |
| 6876 | } |
| 6877 | packageSharedUser = ps.sharedUser; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6878 | pw.print(" Package ["); |
| 6879 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 6880 | pw.print("] ("); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6881 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 6882 | pw.println("):"); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6883 | if (ps.realName != null) { |
| 6884 | pw.print(" compat name="); pw.println(ps.name); |
| 6885 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6886 | pw.print(" userId="); pw.print(ps.userId); |
| 6887 | pw.print(" gids="); pw.println(arrayToString(ps.gids)); |
| 6888 | pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 6889 | pw.print(" pkg="); pw.println(ps.pkg); |
| 6890 | pw.print(" codePath="); pw.println(ps.codePathString); |
| 6891 | pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6892 | if (ps.pkg != null) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6893 | pw.print(" dataDir="); pw.println(ps.pkg.applicationInfo.dataDir); |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6894 | pw.print(" targetSdk="); pw.println(ps.pkg.applicationInfo.targetSdkVersion); |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6895 | pw.print(" supportsScreens=["); |
| 6896 | boolean first = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6897 | if ((ps.pkg.applicationInfo.flags & |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6898 | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) { |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6899 | if (!first) pw.print(", "); |
| 6900 | first = false; |
| 6901 | pw.print("medium"); |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6902 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6903 | if ((ps.pkg.applicationInfo.flags & |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6904 | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) { |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6905 | if (!first) pw.print(", "); |
| 6906 | first = false; |
| 6907 | pw.print("large"); |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6908 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6909 | if ((ps.pkg.applicationInfo.flags & |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6910 | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) { |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6911 | if (!first) pw.print(", "); |
| 6912 | first = false; |
| 6913 | pw.print("small"); |
Mitsuru Oshima | 841f13c | 2009-07-17 17:23:31 -0700 | [diff] [blame] | 6914 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6915 | if ((ps.pkg.applicationInfo.flags & |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 6916 | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) { |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6917 | if (!first) pw.print(", "); |
| 6918 | first = false; |
| 6919 | pw.print("resizeable"); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 6920 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6921 | if ((ps.pkg.applicationInfo.flags & |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6922 | ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) { |
| 6923 | if (!first) pw.print(", "); |
| 6924 | first = false; |
| 6925 | pw.print("anyDensity"); |
| 6926 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6927 | } |
Dianne Hackborn | 11b822d | 2009-07-21 20:03:02 -0700 | [diff] [blame] | 6928 | pw.println("]"); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6929 | pw.print(" timeStamp="); pw.println(ps.getTimeStampStr()); |
| 6930 | pw.print(" signatures="); pw.println(ps.signatures); |
| 6931 | pw.print(" permissionsFixed="); pw.print(ps.permissionsFixed); |
Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 6932 | pw.print(" haveGids="); pw.println(ps.haveGids); |
| 6933 | pw.print(" pkgFlags=0x"); pw.print(Integer.toHexString(ps.pkgFlags)); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6934 | pw.print(" installStatus="); pw.print(ps.installStatus); |
| 6935 | pw.print(" enabled="); pw.println(ps.enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6936 | if (ps.disabledComponents.size() > 0) { |
| 6937 | pw.println(" disabledComponents:"); |
| 6938 | for (String s : ps.disabledComponents) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6939 | pw.print(" "); pw.println(s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6940 | } |
| 6941 | } |
| 6942 | if (ps.enabledComponents.size() > 0) { |
| 6943 | pw.println(" enabledComponents:"); |
| 6944 | for (String s : ps.enabledComponents) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6945 | pw.print(" "); pw.println(s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6946 | } |
| 6947 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6948 | if (ps.grantedPermissions.size() > 0) { |
| 6949 | pw.println(" grantedPermissions:"); |
| 6950 | for (String s : ps.grantedPermissions) { |
| 6951 | pw.print(" "); pw.println(s); |
| 6952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6953 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6954 | } |
| 6955 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6956 | printedSomething = false; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6957 | if (mSettings.mRenamedPackages.size() > 0) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6958 | for (HashMap.Entry<String, String> e |
| 6959 | : mSettings.mRenamedPackages.entrySet()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6960 | if (packageName != null && !packageName.equals(e.getKey()) |
| 6961 | && !packageName.equals(e.getValue())) { |
| 6962 | continue; |
| 6963 | } |
| 6964 | if (!printedSomething) { |
| 6965 | if (printedTitle) pw.println(" "); |
| 6966 | pw.println("Renamed packages:"); |
| 6967 | printedSomething = true; |
| 6968 | printedTitle = true; |
| 6969 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6970 | pw.print(" "); pw.print(e.getKey()); pw.print(" -> "); |
| 6971 | pw.println(e.getValue()); |
| 6972 | } |
| 6973 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6974 | printedSomething = false; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6975 | if (mSettings.mDisabledSysPackages.size() > 0) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6976 | for (PackageSetting ps : mSettings.mDisabledSysPackages.values()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 6977 | if (packageName != null && !packageName.equals(ps.realName) |
| 6978 | && !packageName.equals(ps.name)) { |
| 6979 | continue; |
| 6980 | } |
| 6981 | if (!printedSomething) { |
| 6982 | if (printedTitle) pw.println(" "); |
| 6983 | pw.println("Hidden system packages:"); |
| 6984 | printedSomething = true; |
| 6985 | printedTitle = true; |
| 6986 | } |
| 6987 | pw.print(" Package ["); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 6988 | pw.print(ps.realName != null ? ps.realName : ps.name); |
| 6989 | pw.print("] ("); |
| 6990 | pw.print(Integer.toHexString(System.identityHashCode(ps))); |
| 6991 | pw.println("):"); |
| 6992 | if (ps.realName != null) { |
| 6993 | pw.print(" compat name="); pw.println(ps.name); |
| 6994 | } |
| 6995 | pw.print(" userId="); pw.println(ps.userId); |
| 6996 | pw.print(" sharedUser="); pw.println(ps.sharedUser); |
| 6997 | pw.print(" codePath="); pw.println(ps.codePathString); |
| 6998 | pw.print(" resourcePath="); pw.println(ps.resourcePathString); |
| 6999 | } |
| 7000 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7001 | printedSomething = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7002 | { |
| 7003 | for (SharedUserSetting su : mSettings.mSharedUsers.values()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7004 | if (packageName != null && su != packageSharedUser) { |
| 7005 | continue; |
| 7006 | } |
| 7007 | if (!printedSomething) { |
| 7008 | if (printedTitle) pw.println(" "); |
| 7009 | pw.println("Shared users:"); |
| 7010 | printedSomething = true; |
| 7011 | printedTitle = true; |
| 7012 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7013 | pw.print(" SharedUser ["); pw.print(su.name); pw.print("] ("); |
| 7014 | pw.print(Integer.toHexString(System.identityHashCode(su))); |
| 7015 | pw.println("):"); |
| 7016 | pw.print(" userId="); pw.print(su.userId); |
| 7017 | pw.print(" gids="); pw.println(arrayToString(su.gids)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7018 | pw.println(" grantedPermissions:"); |
| 7019 | for (String s : su.grantedPermissions) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7020 | pw.print(" "); pw.println(s); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7021 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7022 | } |
| 7023 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7024 | |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7025 | if (packageName == null) { |
| 7026 | if (printedTitle) pw.println(" "); |
| 7027 | printedTitle = true; |
| 7028 | pw.println("Settings parse messages:"); |
| 7029 | pw.println(mSettings.mReadMessages.toString()); |
| 7030 | |
| 7031 | pw.println(" "); |
| 7032 | pw.println("Package warning messages:"); |
| 7033 | File fname = getSettingsProblemFile(); |
| 7034 | FileInputStream in; |
| 7035 | try { |
| 7036 | in = new FileInputStream(fname); |
| 7037 | int avail = in.available(); |
| 7038 | byte[] data = new byte[avail]; |
| 7039 | in.read(data); |
| 7040 | pw.println(new String(data)); |
| 7041 | } catch (FileNotFoundException e) { |
| 7042 | } catch (IOException e) { |
| 7043 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7044 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7045 | } |
Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7046 | |
| 7047 | synchronized (mProviders) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7048 | boolean printedSomething = false; |
Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7049 | for (PackageParser.Provider p : mProviders.values()) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7050 | if (packageName != null && !packageName.equals(p.info.packageName)) { |
| 7051 | continue; |
| 7052 | } |
| 7053 | if (!printedSomething) { |
| 7054 | if (printedTitle) pw.println(" "); |
| 7055 | pw.println("Registered ContentProviders:"); |
| 7056 | printedSomething = true; |
| 7057 | printedTitle = true; |
| 7058 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7059 | pw.print(" ["); pw.print(p.info.authority); pw.print("]: "); |
Jeff Hamilton | 5bfc64f | 2009-08-18 12:25:30 -0500 | [diff] [blame] | 7060 | pw.println(p.toString()); |
| 7061 | } |
| 7062 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7063 | } |
| 7064 | |
| 7065 | static final class BasePermission { |
| 7066 | final static int TYPE_NORMAL = 0; |
| 7067 | final static int TYPE_BUILTIN = 1; |
| 7068 | final static int TYPE_DYNAMIC = 2; |
| 7069 | |
| 7070 | final String name; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7071 | String sourcePackage; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7072 | PackageSettingBase packageSetting; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7073 | final int type; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7074 | int protectionLevel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | PackageParser.Permission perm; |
| 7076 | PermissionInfo pendingInfo; |
| 7077 | int uid; |
| 7078 | int[] gids; |
| 7079 | |
| 7080 | BasePermission(String _name, String _sourcePackage, int _type) { |
| 7081 | name = _name; |
| 7082 | sourcePackage = _sourcePackage; |
| 7083 | type = _type; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7084 | // Default to most conservative protection level. |
| 7085 | protectionLevel = PermissionInfo.PROTECTION_SIGNATURE; |
| 7086 | } |
| 7087 | |
| 7088 | public String toString() { |
| 7089 | return "BasePermission{" |
| 7090 | + Integer.toHexString(System.identityHashCode(this)) |
| 7091 | + " " + name + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7092 | } |
| 7093 | } |
| 7094 | |
| 7095 | static class PackageSignatures { |
| 7096 | private Signature[] mSignatures; |
| 7097 | |
| 7098 | PackageSignatures(Signature[] sigs) { |
| 7099 | assignSignatures(sigs); |
| 7100 | } |
| 7101 | |
| 7102 | PackageSignatures() { |
| 7103 | } |
| 7104 | |
| 7105 | void writeXml(XmlSerializer serializer, String tagName, |
| 7106 | ArrayList<Signature> pastSignatures) throws IOException { |
| 7107 | if (mSignatures == null) { |
| 7108 | return; |
| 7109 | } |
| 7110 | serializer.startTag(null, tagName); |
| 7111 | serializer.attribute(null, "count", |
| 7112 | Integer.toString(mSignatures.length)); |
| 7113 | for (int i=0; i<mSignatures.length; i++) { |
| 7114 | serializer.startTag(null, "cert"); |
| 7115 | final Signature sig = mSignatures[i]; |
| 7116 | final int sigHash = sig.hashCode(); |
| 7117 | final int numPast = pastSignatures.size(); |
| 7118 | int j; |
| 7119 | for (j=0; j<numPast; j++) { |
| 7120 | Signature pastSig = pastSignatures.get(j); |
| 7121 | if (pastSig.hashCode() == sigHash && pastSig.equals(sig)) { |
| 7122 | serializer.attribute(null, "index", Integer.toString(j)); |
| 7123 | break; |
| 7124 | } |
| 7125 | } |
| 7126 | if (j >= numPast) { |
| 7127 | pastSignatures.add(sig); |
| 7128 | serializer.attribute(null, "index", Integer.toString(numPast)); |
| 7129 | serializer.attribute(null, "key", sig.toCharsString()); |
| 7130 | } |
| 7131 | serializer.endTag(null, "cert"); |
| 7132 | } |
| 7133 | serializer.endTag(null, tagName); |
| 7134 | } |
| 7135 | |
| 7136 | void readXml(XmlPullParser parser, ArrayList<Signature> pastSignatures) |
| 7137 | throws IOException, XmlPullParserException { |
| 7138 | String countStr = parser.getAttributeValue(null, "count"); |
| 7139 | if (countStr == null) { |
| 7140 | reportSettingsProblem(Log.WARN, |
| 7141 | "Error in package manager settings: <signatures> has" |
| 7142 | + " no count at " + parser.getPositionDescription()); |
| 7143 | XmlUtils.skipCurrentTag(parser); |
| 7144 | } |
| 7145 | final int count = Integer.parseInt(countStr); |
| 7146 | mSignatures = new Signature[count]; |
| 7147 | int pos = 0; |
| 7148 | |
| 7149 | int outerDepth = parser.getDepth(); |
| 7150 | int type; |
| 7151 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 7152 | && (type != XmlPullParser.END_TAG |
| 7153 | || parser.getDepth() > outerDepth)) { |
| 7154 | if (type == XmlPullParser.END_TAG |
| 7155 | || type == XmlPullParser.TEXT) { |
| 7156 | continue; |
| 7157 | } |
| 7158 | |
| 7159 | String tagName = parser.getName(); |
| 7160 | if (tagName.equals("cert")) { |
| 7161 | if (pos < count) { |
| 7162 | String index = parser.getAttributeValue(null, "index"); |
| 7163 | if (index != null) { |
| 7164 | try { |
| 7165 | int idx = Integer.parseInt(index); |
| 7166 | String key = parser.getAttributeValue(null, "key"); |
| 7167 | if (key == null) { |
| 7168 | if (idx >= 0 && idx < pastSignatures.size()) { |
| 7169 | Signature sig = pastSignatures.get(idx); |
| 7170 | if (sig != null) { |
| 7171 | mSignatures[pos] = pastSignatures.get(idx); |
| 7172 | pos++; |
| 7173 | } else { |
| 7174 | reportSettingsProblem(Log.WARN, |
| 7175 | "Error in package manager settings: <cert> " |
| 7176 | + "index " + index + " is not defined at " |
| 7177 | + parser.getPositionDescription()); |
| 7178 | } |
| 7179 | } else { |
| 7180 | reportSettingsProblem(Log.WARN, |
| 7181 | "Error in package manager settings: <cert> " |
| 7182 | + "index " + index + " is out of bounds at " |
| 7183 | + parser.getPositionDescription()); |
| 7184 | } |
| 7185 | } else { |
| 7186 | while (pastSignatures.size() <= idx) { |
| 7187 | pastSignatures.add(null); |
| 7188 | } |
| 7189 | Signature sig = new Signature(key); |
| 7190 | pastSignatures.set(idx, sig); |
| 7191 | mSignatures[pos] = sig; |
| 7192 | pos++; |
| 7193 | } |
| 7194 | } catch (NumberFormatException e) { |
| 7195 | reportSettingsProblem(Log.WARN, |
| 7196 | "Error in package manager settings: <cert> " |
| 7197 | + "index " + index + " is not a number at " |
| 7198 | + parser.getPositionDescription()); |
| 7199 | } |
| 7200 | } else { |
| 7201 | reportSettingsProblem(Log.WARN, |
| 7202 | "Error in package manager settings: <cert> has" |
| 7203 | + " no index at " + parser.getPositionDescription()); |
| 7204 | } |
| 7205 | } else { |
| 7206 | reportSettingsProblem(Log.WARN, |
| 7207 | "Error in package manager settings: too " |
| 7208 | + "many <cert> tags, expected " + count |
| 7209 | + " at " + parser.getPositionDescription()); |
| 7210 | } |
| 7211 | } else { |
| 7212 | reportSettingsProblem(Log.WARN, |
| 7213 | "Unknown element under <cert>: " |
| 7214 | + parser.getName()); |
| 7215 | } |
| 7216 | XmlUtils.skipCurrentTag(parser); |
| 7217 | } |
| 7218 | |
| 7219 | if (pos < count) { |
| 7220 | // Should never happen -- there is an error in the written |
| 7221 | // settings -- but if it does we don't want to generate |
| 7222 | // a bad array. |
| 7223 | Signature[] newSigs = new Signature[pos]; |
| 7224 | System.arraycopy(mSignatures, 0, newSigs, 0, pos); |
| 7225 | mSignatures = newSigs; |
| 7226 | } |
| 7227 | } |
| 7228 | |
| 7229 | /** |
| 7230 | * If any of the given 'sigs' is contained in the existing signatures, |
| 7231 | * then completely replace the current signatures with the ones in |
| 7232 | * 'sigs'. This is used for updating an existing package to a newly |
| 7233 | * installed version. |
| 7234 | */ |
| 7235 | boolean updateSignatures(Signature[] sigs, boolean update) { |
| 7236 | if (mSignatures == null) { |
| 7237 | if (update) { |
| 7238 | assignSignatures(sigs); |
| 7239 | } |
| 7240 | return true; |
| 7241 | } |
| 7242 | if (sigs == null) { |
| 7243 | return false; |
| 7244 | } |
| 7245 | |
| 7246 | for (int i=0; i<sigs.length; i++) { |
| 7247 | Signature sig = sigs[i]; |
| 7248 | for (int j=0; j<mSignatures.length; j++) { |
| 7249 | if (mSignatures[j].equals(sig)) { |
| 7250 | if (update) { |
| 7251 | assignSignatures(sigs); |
| 7252 | } |
| 7253 | return true; |
| 7254 | } |
| 7255 | } |
| 7256 | } |
| 7257 | return false; |
| 7258 | } |
| 7259 | |
| 7260 | /** |
| 7261 | * If any of the given 'sigs' is contained in the existing signatures, |
| 7262 | * then add in any new signatures found in 'sigs'. This is used for |
| 7263 | * including a new package into an existing shared user id. |
| 7264 | */ |
| 7265 | boolean mergeSignatures(Signature[] sigs, boolean update) { |
| 7266 | if (mSignatures == null) { |
| 7267 | if (update) { |
| 7268 | assignSignatures(sigs); |
| 7269 | } |
| 7270 | return true; |
| 7271 | } |
| 7272 | if (sigs == null) { |
| 7273 | return false; |
| 7274 | } |
| 7275 | |
| 7276 | Signature[] added = null; |
| 7277 | int addedCount = 0; |
| 7278 | boolean haveMatch = false; |
| 7279 | for (int i=0; i<sigs.length; i++) { |
| 7280 | Signature sig = sigs[i]; |
| 7281 | boolean found = false; |
| 7282 | for (int j=0; j<mSignatures.length; j++) { |
| 7283 | if (mSignatures[j].equals(sig)) { |
| 7284 | found = true; |
| 7285 | haveMatch = true; |
| 7286 | break; |
| 7287 | } |
| 7288 | } |
| 7289 | |
| 7290 | if (!found) { |
| 7291 | if (added == null) { |
| 7292 | added = new Signature[sigs.length]; |
| 7293 | } |
| 7294 | added[i] = sig; |
| 7295 | addedCount++; |
| 7296 | } |
| 7297 | } |
| 7298 | |
| 7299 | if (!haveMatch) { |
| 7300 | // Nothing matched -- reject the new signatures. |
| 7301 | return false; |
| 7302 | } |
| 7303 | if (added == null) { |
| 7304 | // Completely matched -- nothing else to do. |
| 7305 | return true; |
| 7306 | } |
| 7307 | |
| 7308 | // Add additional signatures in. |
| 7309 | if (update) { |
| 7310 | Signature[] total = new Signature[addedCount+mSignatures.length]; |
| 7311 | System.arraycopy(mSignatures, 0, total, 0, mSignatures.length); |
| 7312 | int j = mSignatures.length; |
| 7313 | for (int i=0; i<added.length; i++) { |
| 7314 | if (added[i] != null) { |
| 7315 | total[j] = added[i]; |
| 7316 | j++; |
| 7317 | } |
| 7318 | } |
| 7319 | mSignatures = total; |
| 7320 | } |
| 7321 | return true; |
| 7322 | } |
| 7323 | |
| 7324 | private void assignSignatures(Signature[] sigs) { |
| 7325 | if (sigs == null) { |
| 7326 | mSignatures = null; |
| 7327 | return; |
| 7328 | } |
| 7329 | mSignatures = new Signature[sigs.length]; |
| 7330 | for (int i=0; i<sigs.length; i++) { |
| 7331 | mSignatures[i] = sigs[i]; |
| 7332 | } |
| 7333 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7335 | @Override |
| 7336 | public String toString() { |
| 7337 | StringBuffer buf = new StringBuffer(128); |
| 7338 | buf.append("PackageSignatures{"); |
| 7339 | buf.append(Integer.toHexString(System.identityHashCode(this))); |
| 7340 | buf.append(" ["); |
| 7341 | if (mSignatures != null) { |
| 7342 | for (int i=0; i<mSignatures.length; i++) { |
| 7343 | if (i > 0) buf.append(", "); |
| 7344 | buf.append(Integer.toHexString( |
| 7345 | System.identityHashCode(mSignatures[i]))); |
| 7346 | } |
| 7347 | } |
| 7348 | buf.append("]}"); |
| 7349 | return buf.toString(); |
| 7350 | } |
| 7351 | } |
| 7352 | |
| 7353 | static class PreferredActivity extends IntentFilter { |
| 7354 | final int mMatch; |
| 7355 | final String[] mSetPackages; |
| 7356 | final String[] mSetClasses; |
| 7357 | final String[] mSetComponents; |
| 7358 | final ComponentName mActivity; |
| 7359 | final String mShortActivity; |
| 7360 | String mParseError; |
| 7361 | |
| 7362 | PreferredActivity(IntentFilter filter, int match, ComponentName[] set, |
| 7363 | ComponentName activity) { |
| 7364 | super(filter); |
| 7365 | mMatch = match&IntentFilter.MATCH_CATEGORY_MASK; |
| 7366 | mActivity = activity; |
| 7367 | mShortActivity = activity.flattenToShortString(); |
| 7368 | mParseError = null; |
| 7369 | if (set != null) { |
| 7370 | final int N = set.length; |
| 7371 | String[] myPackages = new String[N]; |
| 7372 | String[] myClasses = new String[N]; |
| 7373 | String[] myComponents = new String[N]; |
| 7374 | for (int i=0; i<N; i++) { |
| 7375 | ComponentName cn = set[i]; |
| 7376 | if (cn == null) { |
| 7377 | mSetPackages = null; |
| 7378 | mSetClasses = null; |
| 7379 | mSetComponents = null; |
| 7380 | return; |
| 7381 | } |
| 7382 | myPackages[i] = cn.getPackageName().intern(); |
| 7383 | myClasses[i] = cn.getClassName().intern(); |
| 7384 | myComponents[i] = cn.flattenToShortString().intern(); |
| 7385 | } |
| 7386 | mSetPackages = myPackages; |
| 7387 | mSetClasses = myClasses; |
| 7388 | mSetComponents = myComponents; |
| 7389 | } else { |
| 7390 | mSetPackages = null; |
| 7391 | mSetClasses = null; |
| 7392 | mSetComponents = null; |
| 7393 | } |
| 7394 | } |
| 7395 | |
| 7396 | PreferredActivity(XmlPullParser parser) throws XmlPullParserException, |
| 7397 | IOException { |
| 7398 | mShortActivity = parser.getAttributeValue(null, "name"); |
| 7399 | mActivity = ComponentName.unflattenFromString(mShortActivity); |
| 7400 | if (mActivity == null) { |
| 7401 | mParseError = "Bad activity name " + mShortActivity; |
| 7402 | } |
| 7403 | String matchStr = parser.getAttributeValue(null, "match"); |
| 7404 | mMatch = matchStr != null ? Integer.parseInt(matchStr, 16) : 0; |
| 7405 | String setCountStr = parser.getAttributeValue(null, "set"); |
| 7406 | int setCount = setCountStr != null ? Integer.parseInt(setCountStr) : 0; |
| 7407 | |
| 7408 | String[] myPackages = setCount > 0 ? new String[setCount] : null; |
| 7409 | String[] myClasses = setCount > 0 ? new String[setCount] : null; |
| 7410 | String[] myComponents = setCount > 0 ? new String[setCount] : null; |
| 7411 | |
| 7412 | int setPos = 0; |
| 7413 | |
| 7414 | int outerDepth = parser.getDepth(); |
| 7415 | int type; |
| 7416 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 7417 | && (type != XmlPullParser.END_TAG |
| 7418 | || parser.getDepth() > outerDepth)) { |
| 7419 | if (type == XmlPullParser.END_TAG |
| 7420 | || type == XmlPullParser.TEXT) { |
| 7421 | continue; |
| 7422 | } |
| 7423 | |
| 7424 | String tagName = parser.getName(); |
| 7425 | //Log.i(TAG, "Parse outerDepth=" + outerDepth + " depth=" |
| 7426 | // + parser.getDepth() + " tag=" + tagName); |
| 7427 | if (tagName.equals("set")) { |
| 7428 | String name = parser.getAttributeValue(null, "name"); |
| 7429 | if (name == null) { |
| 7430 | if (mParseError == null) { |
| 7431 | mParseError = "No name in set tag in preferred activity " |
| 7432 | + mShortActivity; |
| 7433 | } |
| 7434 | } else if (setPos >= setCount) { |
| 7435 | if (mParseError == null) { |
| 7436 | mParseError = "Too many set tags in preferred activity " |
| 7437 | + mShortActivity; |
| 7438 | } |
| 7439 | } else { |
| 7440 | ComponentName cn = ComponentName.unflattenFromString(name); |
| 7441 | if (cn == null) { |
| 7442 | if (mParseError == null) { |
| 7443 | mParseError = "Bad set name " + name + " in preferred activity " |
| 7444 | + mShortActivity; |
| 7445 | } |
| 7446 | } else { |
| 7447 | myPackages[setPos] = cn.getPackageName(); |
| 7448 | myClasses[setPos] = cn.getClassName(); |
| 7449 | myComponents[setPos] = name; |
| 7450 | setPos++; |
| 7451 | } |
| 7452 | } |
| 7453 | XmlUtils.skipCurrentTag(parser); |
| 7454 | } else if (tagName.equals("filter")) { |
| 7455 | //Log.i(TAG, "Starting to parse filter..."); |
| 7456 | readFromXml(parser); |
| 7457 | //Log.i(TAG, "Finished filter: outerDepth=" + outerDepth + " depth=" |
| 7458 | // + parser.getDepth() + " tag=" + parser.getName()); |
| 7459 | } else { |
| 7460 | reportSettingsProblem(Log.WARN, |
| 7461 | "Unknown element under <preferred-activities>: " |
| 7462 | + parser.getName()); |
| 7463 | XmlUtils.skipCurrentTag(parser); |
| 7464 | } |
| 7465 | } |
| 7466 | |
| 7467 | if (setPos != setCount) { |
| 7468 | if (mParseError == null) { |
| 7469 | mParseError = "Not enough set tags (expected " + setCount |
| 7470 | + " but found " + setPos + ") in " + mShortActivity; |
| 7471 | } |
| 7472 | } |
| 7473 | |
| 7474 | mSetPackages = myPackages; |
| 7475 | mSetClasses = myClasses; |
| 7476 | mSetComponents = myComponents; |
| 7477 | } |
| 7478 | |
| 7479 | public void writeToXml(XmlSerializer serializer) throws IOException { |
| 7480 | final int NS = mSetClasses != null ? mSetClasses.length : 0; |
| 7481 | serializer.attribute(null, "name", mShortActivity); |
| 7482 | serializer.attribute(null, "match", Integer.toHexString(mMatch)); |
| 7483 | serializer.attribute(null, "set", Integer.toString(NS)); |
| 7484 | for (int s=0; s<NS; s++) { |
| 7485 | serializer.startTag(null, "set"); |
| 7486 | serializer.attribute(null, "name", mSetComponents[s]); |
| 7487 | serializer.endTag(null, "set"); |
| 7488 | } |
| 7489 | serializer.startTag(null, "filter"); |
| 7490 | super.writeToXml(serializer); |
| 7491 | serializer.endTag(null, "filter"); |
| 7492 | } |
| 7493 | |
| 7494 | boolean sameSet(List<ResolveInfo> query, int priority) { |
| 7495 | if (mSetPackages == null) return false; |
| 7496 | final int NQ = query.size(); |
| 7497 | final int NS = mSetPackages.length; |
| 7498 | int numMatch = 0; |
| 7499 | for (int i=0; i<NQ; i++) { |
| 7500 | ResolveInfo ri = query.get(i); |
| 7501 | if (ri.priority != priority) continue; |
| 7502 | ActivityInfo ai = ri.activityInfo; |
| 7503 | boolean good = false; |
| 7504 | for (int j=0; j<NS; j++) { |
| 7505 | if (mSetPackages[j].equals(ai.packageName) |
| 7506 | && mSetClasses[j].equals(ai.name)) { |
| 7507 | numMatch++; |
| 7508 | good = true; |
| 7509 | break; |
| 7510 | } |
| 7511 | } |
| 7512 | if (!good) return false; |
| 7513 | } |
| 7514 | return numMatch == NS; |
| 7515 | } |
| 7516 | } |
| 7517 | |
| 7518 | static class GrantedPermissions { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 7519 | int pkgFlags; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7521 | HashSet<String> grantedPermissions = new HashSet<String>(); |
| 7522 | int[] gids; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7524 | GrantedPermissions(int pkgFlags) { |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 7525 | setFlags(pkgFlags); |
| 7526 | } |
| 7527 | |
| 7528 | void setFlags(int pkgFlags) { |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 7529 | this.pkgFlags = (pkgFlags & ApplicationInfo.FLAG_SYSTEM) | |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 7530 | (pkgFlags & ApplicationInfo.FLAG_FORWARD_LOCK) | |
Suchi Amalapurapu | 6069beb | 2010-03-10 09:46:49 -0800 | [diff] [blame] | 7531 | (pkgFlags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) | |
Suchi Amalapurapu | d32c802 | 2010-03-04 17:18:14 -0800 | [diff] [blame] | 7532 | (pkgFlags & ApplicationInfo.FLAG_NEVER_ENCRYPT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7533 | } |
| 7534 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7536 | /** |
| 7537 | * Settings base class for pending and resolved classes. |
| 7538 | */ |
| 7539 | static class PackageSettingBase extends GrantedPermissions { |
| 7540 | final String name; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7541 | final String realName; |
Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 7542 | File codePath; |
| 7543 | String codePathString; |
| 7544 | File resourcePath; |
| 7545 | String resourcePathString; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7546 | private long timeStamp; |
| 7547 | private String timeStampString = "0"; |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 7548 | int versionCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7549 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7550 | boolean uidError; |
| 7551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7552 | PackageSignatures signatures = new PackageSignatures(); |
| 7553 | |
| 7554 | boolean permissionsFixed; |
Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7555 | boolean haveGids; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7556 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7557 | /* Explicitly disabled components */ |
| 7558 | HashSet<String> disabledComponents = new HashSet<String>(0); |
| 7559 | /* Explicitly enabled components */ |
| 7560 | HashSet<String> enabledComponents = new HashSet<String>(0); |
| 7561 | int enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 7562 | int installStatus = PKG_INSTALL_COMPLETE; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7563 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7564 | PackageSettingBase origPackage; |
| 7565 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7566 | /* package name of the app that installed this package */ |
| 7567 | String installerPackageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7568 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7569 | PackageSettingBase(String name, String realName, File codePath, File resourcePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7570 | int pVersionCode, int pkgFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7571 | super(pkgFlags); |
| 7572 | this.name = name; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7573 | this.realName = realName; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7574 | init(codePath, resourcePath, pVersionCode); |
| 7575 | } |
| 7576 | |
| 7577 | void init(File codePath, File resourcePath, int pVersionCode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7578 | this.codePath = codePath; |
| 7579 | this.codePathString = codePath.toString(); |
| 7580 | this.resourcePath = resourcePath; |
| 7581 | this.resourcePathString = resourcePath.toString(); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7582 | this.versionCode = pVersionCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7583 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7584 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7585 | public void setInstallerPackageName(String packageName) { |
| 7586 | installerPackageName = packageName; |
| 7587 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7588 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7589 | String getInstallerPackageName() { |
| 7590 | return installerPackageName; |
| 7591 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7593 | public void setInstallStatus(int newStatus) { |
| 7594 | installStatus = newStatus; |
| 7595 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7596 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7597 | public int getInstallStatus() { |
| 7598 | return installStatus; |
| 7599 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7600 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7601 | public void setTimeStamp(long newStamp) { |
| 7602 | if (newStamp != timeStamp) { |
| 7603 | timeStamp = newStamp; |
| 7604 | timeStampString = Long.toString(newStamp); |
| 7605 | } |
| 7606 | } |
| 7607 | |
| 7608 | public void setTimeStamp(long newStamp, String newStampStr) { |
| 7609 | timeStamp = newStamp; |
| 7610 | timeStampString = newStampStr; |
| 7611 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7613 | public long getTimeStamp() { |
| 7614 | return timeStamp; |
| 7615 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7617 | public String getTimeStampStr() { |
| 7618 | return timeStampString; |
| 7619 | } |
| 7620 | |
| 7621 | public void copyFrom(PackageSettingBase base) { |
| 7622 | grantedPermissions = base.grantedPermissions; |
| 7623 | gids = base.gids; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7625 | timeStamp = base.timeStamp; |
| 7626 | timeStampString = base.timeStampString; |
| 7627 | signatures = base.signatures; |
| 7628 | permissionsFixed = base.permissionsFixed; |
Dianne Hackborn | bbfd58a | 2010-03-23 11:49:59 -0700 | [diff] [blame] | 7629 | haveGids = base.haveGids; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7630 | disabledComponents = base.disabledComponents; |
| 7631 | enabledComponents = base.enabledComponents; |
| 7632 | enabled = base.enabled; |
| 7633 | installStatus = base.installStatus; |
| 7634 | } |
| 7635 | |
| 7636 | void enableComponentLP(String componentClassName) { |
| 7637 | disabledComponents.remove(componentClassName); |
| 7638 | enabledComponents.add(componentClassName); |
| 7639 | } |
| 7640 | |
| 7641 | void disableComponentLP(String componentClassName) { |
| 7642 | enabledComponents.remove(componentClassName); |
| 7643 | disabledComponents.add(componentClassName); |
| 7644 | } |
| 7645 | |
| 7646 | void restoreComponentLP(String componentClassName) { |
| 7647 | enabledComponents.remove(componentClassName); |
| 7648 | disabledComponents.remove(componentClassName); |
| 7649 | } |
| 7650 | |
| 7651 | int currentEnabledStateLP(String componentName) { |
| 7652 | if (enabledComponents.contains(componentName)) { |
| 7653 | return COMPONENT_ENABLED_STATE_ENABLED; |
| 7654 | } else if (disabledComponents.contains(componentName)) { |
| 7655 | return COMPONENT_ENABLED_STATE_DISABLED; |
| 7656 | } else { |
| 7657 | return COMPONENT_ENABLED_STATE_DEFAULT; |
| 7658 | } |
| 7659 | } |
| 7660 | } |
| 7661 | |
| 7662 | /** |
| 7663 | * Settings data for a particular package we know about. |
| 7664 | */ |
| 7665 | static final class PackageSetting extends PackageSettingBase { |
| 7666 | int userId; |
| 7667 | PackageParser.Package pkg; |
| 7668 | SharedUserSetting sharedUser; |
| 7669 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7670 | PackageSetting(String name, String realName, File codePath, File resourcePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7671 | int pVersionCode, int pkgFlags) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7672 | super(name, realName, codePath, resourcePath, pVersionCode, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7673 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7674 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7675 | @Override |
| 7676 | public String toString() { |
| 7677 | return "PackageSetting{" |
| 7678 | + Integer.toHexString(System.identityHashCode(this)) |
| 7679 | + " " + name + "/" + userId + "}"; |
| 7680 | } |
| 7681 | } |
| 7682 | |
| 7683 | /** |
| 7684 | * Settings data for a particular shared user ID we know about. |
| 7685 | */ |
| 7686 | static final class SharedUserSetting extends GrantedPermissions { |
| 7687 | final String name; |
| 7688 | int userId; |
| 7689 | final HashSet<PackageSetting> packages = new HashSet<PackageSetting>(); |
| 7690 | final PackageSignatures signatures = new PackageSignatures(); |
| 7691 | |
| 7692 | SharedUserSetting(String _name, int _pkgFlags) { |
| 7693 | super(_pkgFlags); |
| 7694 | name = _name; |
| 7695 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7697 | @Override |
| 7698 | public String toString() { |
| 7699 | return "SharedUserSetting{" |
| 7700 | + Integer.toHexString(System.identityHashCode(this)) |
| 7701 | + " " + name + "/" + userId + "}"; |
| 7702 | } |
| 7703 | } |
| 7704 | |
| 7705 | /** |
| 7706 | * Holds information about dynamic settings. |
| 7707 | */ |
| 7708 | private static final class Settings { |
| 7709 | private final File mSettingsFilename; |
| 7710 | private final File mBackupSettingsFilename; |
David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 7711 | private final File mPackageListFilename; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | private final HashMap<String, PackageSetting> mPackages = |
| 7713 | new HashMap<String, PackageSetting>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7714 | // List of replaced system applications |
| 7715 | final HashMap<String, PackageSetting> mDisabledSysPackages = |
| 7716 | new HashMap<String, PackageSetting>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7718 | // The user's preferred activities associated with particular intent |
| 7719 | // filters. |
| 7720 | private final IntentResolver<PreferredActivity, PreferredActivity> mPreferredActivities = |
| 7721 | new IntentResolver<PreferredActivity, PreferredActivity>() { |
| 7722 | @Override |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7723 | protected String packageForFilter(PreferredActivity filter) { |
| 7724 | return filter.mActivity.getPackageName(); |
| 7725 | } |
| 7726 | @Override |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7727 | protected void dumpFilter(PrintWriter out, String prefix, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7728 | PreferredActivity filter) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7729 | out.print(prefix); out.print( |
| 7730 | Integer.toHexString(System.identityHashCode(filter))); |
| 7731 | out.print(' '); |
| 7732 | out.print(filter.mActivity.flattenToShortString()); |
| 7733 | out.print(" match=0x"); |
| 7734 | out.println( Integer.toHexString(filter.mMatch)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7735 | if (filter.mSetComponents != null) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7736 | out.print(prefix); out.println(" Selected from:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7737 | for (int i=0; i<filter.mSetComponents.length; i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7738 | out.print(prefix); out.print(" "); |
| 7739 | out.println(filter.mSetComponents[i]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7740 | } |
| 7741 | } |
| 7742 | } |
| 7743 | }; |
| 7744 | private final HashMap<String, SharedUserSetting> mSharedUsers = |
| 7745 | new HashMap<String, SharedUserSetting>(); |
| 7746 | private final ArrayList<Object> mUserIds = new ArrayList<Object>(); |
| 7747 | private final SparseArray<Object> mOtherUserIds = |
| 7748 | new SparseArray<Object>(); |
| 7749 | |
| 7750 | // For reading/writing settings file. |
| 7751 | private final ArrayList<Signature> mPastSignatures = |
| 7752 | new ArrayList<Signature>(); |
| 7753 | |
| 7754 | // Mapping from permission names to info about them. |
| 7755 | final HashMap<String, BasePermission> mPermissions = |
| 7756 | new HashMap<String, BasePermission>(); |
| 7757 | |
| 7758 | // Mapping from permission tree names to info about them. |
| 7759 | final HashMap<String, BasePermission> mPermissionTrees = |
| 7760 | new HashMap<String, BasePermission>(); |
| 7761 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 7762 | // Packages that have been uninstalled and still need their external |
| 7763 | // storage data deleted. |
| 7764 | final ArrayList<String> mPackagesToBeCleaned = new ArrayList<String>(); |
| 7765 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7766 | // Packages that have been renamed since they were first installed. |
| 7767 | // Keys are the new names of the packages, values are the original |
| 7768 | // names. The packages appear everwhere else under their original |
| 7769 | // names. |
| 7770 | final HashMap<String, String> mRenamedPackages = new HashMap<String, String>(); |
| 7771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7772 | private final StringBuilder mReadMessages = new StringBuilder(); |
| 7773 | |
| 7774 | private static final class PendingPackage extends PackageSettingBase { |
| 7775 | final int sharedId; |
| 7776 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7777 | PendingPackage(String name, String realName, File codePath, File resourcePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7778 | int sharedId, int pVersionCode, int pkgFlags) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7779 | super(name, realName, codePath, resourcePath, pVersionCode, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7780 | this.sharedId = sharedId; |
| 7781 | } |
| 7782 | } |
| 7783 | private final ArrayList<PendingPackage> mPendingPackages |
| 7784 | = new ArrayList<PendingPackage>(); |
| 7785 | |
| 7786 | Settings() { |
| 7787 | File dataDir = Environment.getDataDirectory(); |
| 7788 | File systemDir = new File(dataDir, "system"); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7789 | // TODO(oam): This secure dir creation needs to be moved somewhere else (later) |
| 7790 | File systemSecureDir = new File(dataDir, "secure/system"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | systemDir.mkdirs(); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7792 | systemSecureDir.mkdirs(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7793 | FileUtils.setPermissions(systemDir.toString(), |
| 7794 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 7795 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 7796 | -1, -1); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 7797 | FileUtils.setPermissions(systemSecureDir.toString(), |
| 7798 | FileUtils.S_IRWXU|FileUtils.S_IRWXG |
| 7799 | |FileUtils.S_IROTH|FileUtils.S_IXOTH, |
| 7800 | -1, -1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7801 | mSettingsFilename = new File(systemDir, "packages.xml"); |
| 7802 | mBackupSettingsFilename = new File(systemDir, "packages-backup.xml"); |
David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 7803 | mPackageListFilename = new File(systemDir, "packages.list"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7804 | } |
| 7805 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7806 | PackageSetting getPackageLP(PackageParser.Package pkg, PackageSetting origPackage, |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7807 | String realName, SharedUserSetting sharedUser, File codePath, File resourcePath, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7808 | int pkgFlags, boolean create, boolean add) { |
| 7809 | final String name = pkg.packageName; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7810 | PackageSetting p = getPackageLP(name, origPackage, realName, sharedUser, codePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7811 | resourcePath, pkg.mVersionCode, pkgFlags, create, add); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7812 | return p; |
| 7813 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7814 | |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7815 | PackageSetting peekPackageLP(String name) { |
| 7816 | return mPackages.get(name); |
| 7817 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7818 | PackageSetting p = mPackages.get(name); |
| 7819 | if (p != null && p.codePath.getPath().equals(codePath)) { |
| 7820 | return p; |
| 7821 | } |
| 7822 | return null; |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7823 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7826 | void setInstallStatus(String pkgName, int status) { |
| 7827 | PackageSetting p = mPackages.get(pkgName); |
| 7828 | if(p != null) { |
| 7829 | if(p.getInstallStatus() != status) { |
| 7830 | p.setInstallStatus(status); |
| 7831 | } |
| 7832 | } |
| 7833 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7834 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7835 | void setInstallerPackageName(String pkgName, |
| 7836 | String installerPkgName) { |
| 7837 | PackageSetting p = mPackages.get(pkgName); |
| 7838 | if(p != null) { |
| 7839 | p.setInstallerPackageName(installerPkgName); |
| 7840 | } |
| 7841 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7842 | |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7843 | String getInstallerPackageName(String pkgName) { |
| 7844 | PackageSetting p = mPackages.get(pkgName); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7845 | return (p == null) ? null : p.getInstallerPackageName(); |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 7846 | } |
| 7847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7848 | int getInstallStatus(String pkgName) { |
| 7849 | PackageSetting p = mPackages.get(pkgName); |
| 7850 | if(p != null) { |
| 7851 | return p.getInstallStatus(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7852 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7853 | return -1; |
| 7854 | } |
| 7855 | |
| 7856 | SharedUserSetting getSharedUserLP(String name, |
| 7857 | int pkgFlags, boolean create) { |
| 7858 | SharedUserSetting s = mSharedUsers.get(name); |
| 7859 | if (s == null) { |
| 7860 | if (!create) { |
| 7861 | return null; |
| 7862 | } |
| 7863 | s = new SharedUserSetting(name, pkgFlags); |
| 7864 | if (MULTIPLE_APPLICATION_UIDS) { |
| 7865 | s.userId = newUserIdLP(s); |
| 7866 | } else { |
| 7867 | s.userId = FIRST_APPLICATION_UID; |
| 7868 | } |
| 7869 | Log.i(TAG, "New shared user " + name + ": id=" + s.userId); |
| 7870 | // < 0 means we couldn't assign a userid; fall out and return |
| 7871 | // s, which is currently null |
| 7872 | if (s.userId >= 0) { |
| 7873 | mSharedUsers.put(name, s); |
| 7874 | } |
| 7875 | } |
| 7876 | |
| 7877 | return s; |
| 7878 | } |
| 7879 | |
| 7880 | int disableSystemPackageLP(String name) { |
| 7881 | PackageSetting p = mPackages.get(name); |
| 7882 | if(p == null) { |
| 7883 | Log.w(TAG, "Package:"+name+" is not an installed package"); |
| 7884 | return -1; |
| 7885 | } |
| 7886 | PackageSetting dp = mDisabledSysPackages.get(name); |
| 7887 | // always make sure the system package code and resource paths dont change |
| 7888 | if(dp == null) { |
| 7889 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 7890 | p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 7891 | } |
| 7892 | mDisabledSysPackages.put(name, p); |
| 7893 | } |
| 7894 | return removePackageLP(name); |
| 7895 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7897 | PackageSetting enableSystemPackageLP(String name) { |
| 7898 | PackageSetting p = mDisabledSysPackages.get(name); |
| 7899 | if(p == null) { |
| 7900 | Log.w(TAG, "Package:"+name+" is not disabled"); |
| 7901 | return null; |
| 7902 | } |
| 7903 | // Reset flag in ApplicationInfo object |
| 7904 | if((p.pkg != null) && (p.pkg.applicationInfo != null)) { |
| 7905 | p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; |
| 7906 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7907 | PackageSetting ret = addPackageLP(name, p.realName, p.codePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7908 | p.resourcePath, p.userId, p.versionCode, p.pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7909 | mDisabledSysPackages.remove(name); |
| 7910 | return ret; |
| 7911 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7912 | |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7913 | PackageSetting addPackageLP(String name, String realName, File codePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7914 | File resourcePath, int uid, int vc, int pkgFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7915 | PackageSetting p = mPackages.get(name); |
| 7916 | if (p != null) { |
| 7917 | if (p.userId == uid) { |
| 7918 | return p; |
| 7919 | } |
| 7920 | reportSettingsProblem(Log.ERROR, |
| 7921 | "Adding duplicate package, keeping first: " + name); |
| 7922 | return null; |
| 7923 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7924 | p = new PackageSetting(name, realName, codePath, resourcePath, vc, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7925 | p.userId = uid; |
| 7926 | if (addUserIdLP(uid, p, name)) { |
| 7927 | mPackages.put(name, p); |
| 7928 | return p; |
| 7929 | } |
| 7930 | return null; |
| 7931 | } |
| 7932 | |
| 7933 | SharedUserSetting addSharedUserLP(String name, int uid, int pkgFlags) { |
| 7934 | SharedUserSetting s = mSharedUsers.get(name); |
| 7935 | if (s != null) { |
| 7936 | if (s.userId == uid) { |
| 7937 | return s; |
| 7938 | } |
| 7939 | reportSettingsProblem(Log.ERROR, |
| 7940 | "Adding duplicate shared user, keeping first: " + name); |
| 7941 | return null; |
| 7942 | } |
| 7943 | s = new SharedUserSetting(name, pkgFlags); |
| 7944 | s.userId = uid; |
| 7945 | if (addUserIdLP(uid, s, name)) { |
| 7946 | mSharedUsers.put(name, s); |
| 7947 | return s; |
| 7948 | } |
| 7949 | return null; |
| 7950 | } |
| 7951 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7952 | // Transfer ownership of permissions from one package to another. |
| 7953 | private void transferPermissions(String origPkg, String newPkg) { |
| 7954 | // Transfer ownership of permissions to the new package. |
| 7955 | for (int i=0; i<2; i++) { |
| 7956 | HashMap<String, BasePermission> permissions = |
| 7957 | i == 0 ? mPermissionTrees : mPermissions; |
| 7958 | for (BasePermission bp : permissions.values()) { |
| 7959 | if (origPkg.equals(bp.sourcePackage)) { |
| 7960 | if (DEBUG_UPGRADE) Log.v(TAG, |
| 7961 | "Moving permission " + bp.name |
| 7962 | + " from pkg " + bp.sourcePackage |
| 7963 | + " to " + newPkg); |
| 7964 | bp.sourcePackage = newPkg; |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7965 | bp.packageSetting = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7966 | bp.perm = null; |
| 7967 | if (bp.pendingInfo != null) { |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 7968 | bp.pendingInfo.packageName = newPkg; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 7969 | } |
| 7970 | bp.uid = 0; |
| 7971 | bp.gids = null; |
| 7972 | } |
| 7973 | } |
| 7974 | } |
| 7975 | } |
| 7976 | |
| 7977 | private PackageSetting getPackageLP(String name, PackageSetting origPackage, |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 7978 | String realName, SharedUserSetting sharedUser, File codePath, File resourcePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 7979 | int vc, int pkgFlags, boolean create, boolean add) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7980 | PackageSetting p = mPackages.get(name); |
| 7981 | if (p != null) { |
| 7982 | if (!p.codePath.equals(codePath)) { |
| 7983 | // Check to see if its a disabled system app |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 7984 | if((p != null) && ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0)) { |
Suchi Amalapurapu | b24a967 | 2009-07-01 14:04:43 -0700 | [diff] [blame] | 7985 | // This is an updated system app with versions in both system |
| 7986 | // and data partition. Just let the most recent version |
| 7987 | // take precedence. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 7988 | Slog.w(TAG, "Trying to update system app code path from " + |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 7989 | p.codePathString + " to " + codePath.toString()); |
Suchi Amalapurapu | ea5c044 | 2009-07-13 10:36:15 -0700 | [diff] [blame] | 7990 | } else { |
Dianne Hackborn | 9e0f5d9 | 2010-02-22 15:05:42 -0800 | [diff] [blame] | 7991 | // Just a change in the code path is not an issue, but |
| 7992 | // let's log a message about it. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 7993 | Slog.i(TAG, "Package " + name + " codePath changed from " + p.codePath |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 7994 | + " to " + codePath + "; Retaining data and using new"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7995 | } |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 7996 | } |
| 7997 | if (p.sharedUser != sharedUser) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7998 | reportSettingsProblem(Log.WARN, |
| 7999 | "Package " + name + " shared user changed from " |
| 8000 | + (p.sharedUser != null ? p.sharedUser.name : "<nothing>") |
| 8001 | + " to " |
| 8002 | + (sharedUser != null ? sharedUser.name : "<nothing>") |
| 8003 | + "; replacing with new"); |
| 8004 | p = null; |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8005 | } else { |
| 8006 | if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 8007 | // If what we are scanning is a system package, then |
| 8008 | // make it so, regardless of whether it was previously |
| 8009 | // installed only in the data partition. |
| 8010 | p.pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 8011 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8012 | } |
| 8013 | } |
| 8014 | if (p == null) { |
| 8015 | // Create a new PackageSettings entry. this can end up here because |
| 8016 | // of code path mismatch or user id mismatch of an updated system partition |
| 8017 | if (!create) { |
| 8018 | return null; |
| 8019 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8020 | if (origPackage != null) { |
| 8021 | // We are consuming the data from an existing package. |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8022 | p = new PackageSetting(origPackage.name, name, codePath, |
| 8023 | resourcePath, vc, pkgFlags); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8024 | if (DEBUG_UPGRADE) Log.v(TAG, "Package " + name |
| 8025 | + " is adopting original package " + origPackage.name); |
Dianne Hackborn | 4b45041 | 2010-03-11 16:20:08 -0800 | [diff] [blame] | 8026 | // Note that we will retain the new package's signature so |
| 8027 | // that we can keep its data. |
| 8028 | PackageSignatures s = p.signatures; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8029 | p.copyFrom(origPackage); |
Dianne Hackborn | 4b45041 | 2010-03-11 16:20:08 -0800 | [diff] [blame] | 8030 | p.signatures = s; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8031 | p.sharedUser = origPackage.sharedUser; |
| 8032 | p.userId = origPackage.userId; |
| 8033 | p.origPackage = origPackage; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8034 | mRenamedPackages.put(name, origPackage.name); |
| 8035 | name = origPackage.name; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8036 | // Update new package state. |
| 8037 | p.setTimeStamp(codePath.lastModified()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8038 | } else { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8039 | p = new PackageSetting(name, realName, codePath, resourcePath, vc, pkgFlags); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8040 | p.setTimeStamp(codePath.lastModified()); |
| 8041 | p.sharedUser = sharedUser; |
| 8042 | if (sharedUser != null) { |
| 8043 | p.userId = sharedUser.userId; |
| 8044 | } else if (MULTIPLE_APPLICATION_UIDS) { |
| 8045 | // Clone the setting here for disabled system packages |
| 8046 | PackageSetting dis = mDisabledSysPackages.get(name); |
| 8047 | if (dis != null) { |
| 8048 | // For disabled packages a new setting is created |
| 8049 | // from the existing user id. This still has to be |
| 8050 | // added to list of user id's |
| 8051 | // Copy signatures from previous setting |
| 8052 | if (dis.signatures.mSignatures != null) { |
| 8053 | p.signatures.mSignatures = dis.signatures.mSignatures.clone(); |
| 8054 | } |
| 8055 | p.userId = dis.userId; |
| 8056 | // Clone permissions |
| 8057 | p.grantedPermissions = new HashSet<String>(dis.grantedPermissions); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8058 | // Clone component info |
| 8059 | p.disabledComponents = new HashSet<String>(dis.disabledComponents); |
| 8060 | p.enabledComponents = new HashSet<String>(dis.enabledComponents); |
| 8061 | // Add new setting to list of user ids |
| 8062 | addUserIdLP(p.userId, p, name); |
| 8063 | } else { |
| 8064 | // Assign new user id |
| 8065 | p.userId = newUserIdLP(p); |
| 8066 | } |
| 8067 | } else { |
| 8068 | p.userId = FIRST_APPLICATION_UID; |
| 8069 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8070 | } |
| 8071 | if (p.userId < 0) { |
| 8072 | reportSettingsProblem(Log.WARN, |
| 8073 | "Package " + name + " could not be assigned a valid uid"); |
| 8074 | return null; |
| 8075 | } |
| 8076 | if (add) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8077 | // 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] | 8078 | // user preferences |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8079 | addPackageSettingLP(p, name, sharedUser); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8080 | } |
| 8081 | } |
| 8082 | return p; |
| 8083 | } |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8084 | |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8085 | private void insertPackageSettingLP(PackageSetting p, PackageParser.Package pkg) { |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8086 | p.pkg = pkg; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8087 | String codePath = pkg.applicationInfo.sourceDir; |
| 8088 | String resourcePath = pkg.applicationInfo.publicSourceDir; |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8089 | // Update code path if needed |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8090 | if (!codePath.equalsIgnoreCase(p.codePathString)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8091 | Slog.w(TAG, "Code path for pkg : " + p.pkg.packageName + |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8092 | " changing from " + p.codePathString + " to " + codePath); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8093 | p.codePath = new File(codePath); |
| 8094 | p.codePathString = codePath; |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8095 | } |
| 8096 | //Update resource path if needed |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8097 | if (!resourcePath.equalsIgnoreCase(p.resourcePathString)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8098 | Slog.w(TAG, "Resource path for pkg : " + p.pkg.packageName + |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 8099 | " changing from " + p.resourcePathString + " to " + resourcePath); |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 8100 | p.resourcePath = new File(resourcePath); |
| 8101 | p.resourcePathString = resourcePath; |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8102 | } |
| 8103 | // Update version code if needed |
| 8104 | if (pkg.mVersionCode != p.versionCode) { |
| 8105 | p.versionCode = pkg.mVersionCode; |
| 8106 | } |
| 8107 | addPackageSettingLP(p, pkg.packageName, p.sharedUser); |
| 8108 | } |
| 8109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8110 | // Utility method that adds a PackageSetting to mPackages and |
| 8111 | // completes updating the shared user attributes |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8112 | private void addPackageSettingLP(PackageSetting p, String name, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8113 | SharedUserSetting sharedUser) { |
| 8114 | mPackages.put(name, p); |
| 8115 | if (sharedUser != null) { |
| 8116 | if (p.sharedUser != null && p.sharedUser != sharedUser) { |
| 8117 | reportSettingsProblem(Log.ERROR, |
| 8118 | "Package " + p.name + " was user " |
| 8119 | + p.sharedUser + " but is now " + sharedUser |
| 8120 | + "; I am not changing its files so it will probably fail!"); |
| 8121 | p.sharedUser.packages.remove(p); |
| 8122 | } else if (p.userId != sharedUser.userId) { |
| 8123 | reportSettingsProblem(Log.ERROR, |
| 8124 | "Package " + p.name + " was user id " + p.userId |
| 8125 | + " but is now user " + sharedUser |
| 8126 | + " with id " + sharedUser.userId |
| 8127 | + "; I am not changing its files so it will probably fail!"); |
| 8128 | } |
| 8129 | |
| 8130 | sharedUser.packages.add(p); |
| 8131 | p.sharedUser = sharedUser; |
| 8132 | p.userId = sharedUser.userId; |
| 8133 | } |
| 8134 | } |
| 8135 | |
Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8136 | /* |
| 8137 | * Update the shared user setting when a package using |
| 8138 | * specifying the shared user id is removed. The gids |
| 8139 | * associated with each permission of the deleted package |
| 8140 | * are removed from the shared user's gid list only if its |
| 8141 | * not in use by other permissions of packages in the |
| 8142 | * shared user setting. |
| 8143 | */ |
| 8144 | private void updateSharedUserPermsLP(PackageSetting deletedPs, int[] globalGids) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8145 | if ( (deletedPs == null) || (deletedPs.pkg == null)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8146 | 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] | 8147 | return; |
| 8148 | } |
| 8149 | // No sharedUserId |
| 8150 | if (deletedPs.sharedUser == null) { |
| 8151 | return; |
| 8152 | } |
| 8153 | SharedUserSetting sus = deletedPs.sharedUser; |
| 8154 | // Update permissions |
| 8155 | for (String eachPerm: deletedPs.pkg.requestedPermissions) { |
| 8156 | boolean used = false; |
| 8157 | if (!sus.grantedPermissions.contains (eachPerm)) { |
| 8158 | continue; |
| 8159 | } |
| 8160 | for (PackageSetting pkg:sus.packages) { |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8161 | if (pkg.pkg != null && |
Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 8162 | !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) && |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8163 | pkg.pkg.requestedPermissions.contains(eachPerm)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8164 | used = true; |
| 8165 | break; |
| 8166 | } |
| 8167 | } |
| 8168 | if (!used) { |
| 8169 | // can safely delete this permission from list |
| 8170 | sus.grantedPermissions.remove(eachPerm); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8171 | } |
| 8172 | } |
| 8173 | // Update gids |
Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8174 | int newGids[] = globalGids; |
| 8175 | for (String eachPerm : sus.grantedPermissions) { |
| 8176 | BasePermission bp = mPermissions.get(eachPerm); |
Suchi Amalapurapu | d83006c | 2009-10-28 23:39:46 -0700 | [diff] [blame] | 8177 | if (bp != null) { |
| 8178 | newGids = appendInts(newGids, bp.gids); |
| 8179 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8180 | } |
| 8181 | sus.gids = newGids; |
| 8182 | } |
Suchi Amalapurapu | 2ed287b | 2009-08-05 12:43:00 -0700 | [diff] [blame] | 8183 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8184 | private int removePackageLP(String name) { |
| 8185 | PackageSetting p = mPackages.get(name); |
| 8186 | if (p != null) { |
| 8187 | mPackages.remove(name); |
| 8188 | if (p.sharedUser != null) { |
| 8189 | p.sharedUser.packages.remove(p); |
| 8190 | if (p.sharedUser.packages.size() == 0) { |
| 8191 | mSharedUsers.remove(p.sharedUser.name); |
| 8192 | removeUserIdLP(p.sharedUser.userId); |
| 8193 | return p.sharedUser.userId; |
| 8194 | } |
| 8195 | } else { |
| 8196 | removeUserIdLP(p.userId); |
| 8197 | return p.userId; |
| 8198 | } |
| 8199 | } |
| 8200 | return -1; |
| 8201 | } |
| 8202 | |
| 8203 | private boolean addUserIdLP(int uid, Object obj, Object name) { |
| 8204 | if (uid >= FIRST_APPLICATION_UID + MAX_APPLICATION_UIDS) { |
| 8205 | return false; |
| 8206 | } |
| 8207 | |
| 8208 | if (uid >= FIRST_APPLICATION_UID) { |
| 8209 | int N = mUserIds.size(); |
| 8210 | final int index = uid - FIRST_APPLICATION_UID; |
| 8211 | while (index >= N) { |
| 8212 | mUserIds.add(null); |
| 8213 | N++; |
| 8214 | } |
| 8215 | if (mUserIds.get(index) != null) { |
| 8216 | reportSettingsProblem(Log.ERROR, |
Suchi Amalapurapu | 261e66a | 2009-07-27 15:21:34 -0700 | [diff] [blame] | 8217 | "Adding duplicate user id: " + uid |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8218 | + " name=" + name); |
| 8219 | return false; |
| 8220 | } |
| 8221 | mUserIds.set(index, obj); |
| 8222 | } else { |
| 8223 | if (mOtherUserIds.get(uid) != null) { |
| 8224 | reportSettingsProblem(Log.ERROR, |
| 8225 | "Adding duplicate shared id: " + uid |
| 8226 | + " name=" + name); |
| 8227 | return false; |
| 8228 | } |
| 8229 | mOtherUserIds.put(uid, obj); |
| 8230 | } |
| 8231 | return true; |
| 8232 | } |
| 8233 | |
| 8234 | public Object getUserIdLP(int uid) { |
| 8235 | if (uid >= FIRST_APPLICATION_UID) { |
| 8236 | int N = mUserIds.size(); |
| 8237 | final int index = uid - FIRST_APPLICATION_UID; |
| 8238 | return index < N ? mUserIds.get(index) : null; |
| 8239 | } else { |
| 8240 | return mOtherUserIds.get(uid); |
| 8241 | } |
| 8242 | } |
| 8243 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 8244 | private Set<String> findPackagesWithFlag(int flag) { |
| 8245 | Set<String> ret = new HashSet<String>(); |
| 8246 | for (PackageSetting ps : mPackages.values()) { |
| 8247 | // Has to match atleast all the flag bits set on flag |
| 8248 | if ((ps.pkgFlags & flag) == flag) { |
| 8249 | ret.add(ps.name); |
| 8250 | } |
| 8251 | } |
| 8252 | return ret; |
| 8253 | } |
| 8254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8255 | private void removeUserIdLP(int uid) { |
| 8256 | if (uid >= FIRST_APPLICATION_UID) { |
| 8257 | int N = mUserIds.size(); |
| 8258 | final int index = uid - FIRST_APPLICATION_UID; |
| 8259 | if (index < N) mUserIds.set(index, null); |
| 8260 | } else { |
| 8261 | mOtherUserIds.remove(uid); |
| 8262 | } |
| 8263 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8265 | void writeLP() { |
| 8266 | //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024); |
| 8267 | |
| 8268 | // Keep the old settings around until we know the new ones have |
| 8269 | // been successfully written. |
| 8270 | if (mSettingsFilename.exists()) { |
Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8271 | // Presence of backup settings file indicates that we failed |
| 8272 | // to persist settings earlier. So preserve the older |
| 8273 | // backup for future reference since the current settings |
| 8274 | // might have been corrupted. |
| 8275 | if (!mBackupSettingsFilename.exists()) { |
| 8276 | if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8277 | 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] | 8278 | return; |
| 8279 | } |
| 8280 | } else { |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 8281 | mSettingsFilename.delete(); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8282 | Slog.w(TAG, "Preserving older settings backup"); |
Suchi Amalapurapu | 3d7e855 | 2009-09-17 15:38:20 -0700 | [diff] [blame] | 8283 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8284 | } |
| 8285 | |
| 8286 | mPastSignatures.clear(); |
| 8287 | |
| 8288 | try { |
| 8289 | FileOutputStream str = new FileOutputStream(mSettingsFilename); |
| 8290 | |
| 8291 | //XmlSerializer serializer = XmlUtils.serializerInstance(); |
| 8292 | XmlSerializer serializer = new FastXmlSerializer(); |
| 8293 | serializer.setOutput(str, "utf-8"); |
| 8294 | serializer.startDocument(null, true); |
| 8295 | serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 8296 | |
| 8297 | serializer.startTag(null, "packages"); |
| 8298 | |
| 8299 | serializer.startTag(null, "permission-trees"); |
| 8300 | for (BasePermission bp : mPermissionTrees.values()) { |
| 8301 | writePermission(serializer, bp); |
| 8302 | } |
| 8303 | serializer.endTag(null, "permission-trees"); |
| 8304 | |
| 8305 | serializer.startTag(null, "permissions"); |
| 8306 | for (BasePermission bp : mPermissions.values()) { |
| 8307 | writePermission(serializer, bp); |
| 8308 | } |
| 8309 | serializer.endTag(null, "permissions"); |
| 8310 | |
| 8311 | for (PackageSetting pkg : mPackages.values()) { |
| 8312 | writePackage(serializer, pkg); |
| 8313 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8315 | for (PackageSetting pkg : mDisabledSysPackages.values()) { |
| 8316 | writeDisabledSysPackage(serializer, pkg); |
| 8317 | } |
| 8318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8319 | serializer.startTag(null, "preferred-activities"); |
| 8320 | for (PreferredActivity pa : mPreferredActivities.filterSet()) { |
| 8321 | serializer.startTag(null, "item"); |
| 8322 | pa.writeToXml(serializer); |
| 8323 | serializer.endTag(null, "item"); |
| 8324 | } |
| 8325 | serializer.endTag(null, "preferred-activities"); |
| 8326 | |
| 8327 | for (SharedUserSetting usr : mSharedUsers.values()) { |
| 8328 | serializer.startTag(null, "shared-user"); |
| 8329 | serializer.attribute(null, "name", usr.name); |
| 8330 | serializer.attribute(null, "userId", |
| 8331 | Integer.toString(usr.userId)); |
| 8332 | usr.signatures.writeXml(serializer, "sigs", mPastSignatures); |
| 8333 | serializer.startTag(null, "perms"); |
| 8334 | for (String name : usr.grantedPermissions) { |
| 8335 | serializer.startTag(null, "item"); |
| 8336 | serializer.attribute(null, "name", name); |
| 8337 | serializer.endTag(null, "item"); |
| 8338 | } |
| 8339 | serializer.endTag(null, "perms"); |
| 8340 | serializer.endTag(null, "shared-user"); |
| 8341 | } |
| 8342 | |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8343 | if (mPackagesToBeCleaned.size() > 0) { |
| 8344 | for (int i=0; i<mPackagesToBeCleaned.size(); i++) { |
| 8345 | serializer.startTag(null, "cleaning-package"); |
| 8346 | serializer.attribute(null, "name", mPackagesToBeCleaned.get(i)); |
| 8347 | serializer.endTag(null, "cleaning-package"); |
| 8348 | } |
| 8349 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8350 | |
| 8351 | if (mRenamedPackages.size() > 0) { |
| 8352 | for (HashMap.Entry<String, String> e : mRenamedPackages.entrySet()) { |
| 8353 | serializer.startTag(null, "renamed-package"); |
| 8354 | serializer.attribute(null, "new", e.getKey()); |
| 8355 | serializer.attribute(null, "old", e.getValue()); |
| 8356 | serializer.endTag(null, "renamed-package"); |
| 8357 | } |
| 8358 | } |
| 8359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8360 | serializer.endTag(null, "packages"); |
| 8361 | |
| 8362 | serializer.endDocument(); |
| 8363 | |
| 8364 | str.flush(); |
| 8365 | str.close(); |
| 8366 | |
| 8367 | // New settings successfully written, old ones are no longer |
| 8368 | // needed. |
| 8369 | mBackupSettingsFilename.delete(); |
| 8370 | FileUtils.setPermissions(mSettingsFilename.toString(), |
| 8371 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
| 8372 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP |
| 8373 | |FileUtils.S_IROTH, |
| 8374 | -1, -1); |
David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 8375 | |
| 8376 | // Write package list file now, use a JournaledFile. |
| 8377 | // |
| 8378 | File tempFile = new File(mPackageListFilename.toString() + ".tmp"); |
| 8379 | JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile); |
| 8380 | |
| 8381 | str = new FileOutputStream(journal.chooseForWrite()); |
| 8382 | try { |
| 8383 | StringBuilder sb = new StringBuilder(); |
| 8384 | for (PackageSetting pkg : mPackages.values()) { |
| 8385 | ApplicationInfo ai = pkg.pkg.applicationInfo; |
| 8386 | String dataPath = ai.dataDir; |
| 8387 | boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; |
| 8388 | |
| 8389 | // Avoid any application that has a space in its path |
| 8390 | // or that is handled by the system. |
| 8391 | if (dataPath.indexOf(" ") >= 0 || ai.uid <= Process.FIRST_APPLICATION_UID) |
| 8392 | continue; |
| 8393 | |
| 8394 | // we store on each line the following information for now: |
| 8395 | // |
| 8396 | // pkgName - package name |
| 8397 | // userId - application-specific user id |
| 8398 | // debugFlag - 0 or 1 if the package is debuggable. |
| 8399 | // dataPath - path to package's data path |
| 8400 | // |
| 8401 | // NOTE: We prefer not to expose all ApplicationInfo flags for now. |
| 8402 | // |
| 8403 | // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS |
| 8404 | // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES: |
| 8405 | // system/core/run-as/run-as.c |
| 8406 | // |
| 8407 | sb.setLength(0); |
| 8408 | sb.append(ai.packageName); |
| 8409 | sb.append(" "); |
| 8410 | sb.append((int)ai.uid); |
| 8411 | sb.append(isDebug ? " 1 " : " 0 "); |
| 8412 | sb.append(dataPath); |
| 8413 | sb.append("\n"); |
| 8414 | str.write(sb.toString().getBytes()); |
| 8415 | } |
| 8416 | str.flush(); |
| 8417 | str.close(); |
| 8418 | journal.commit(); |
| 8419 | } |
| 8420 | catch (Exception e) { |
| 8421 | journal.rollback(); |
| 8422 | } |
| 8423 | |
| 8424 | FileUtils.setPermissions(mPackageListFilename.toString(), |
| 8425 | FileUtils.S_IRUSR|FileUtils.S_IWUSR |
| 8426 | |FileUtils.S_IRGRP|FileUtils.S_IWGRP |
| 8427 | |FileUtils.S_IROTH, |
| 8428 | -1, -1); |
| 8429 | |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8430 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8431 | |
| 8432 | } catch(XmlPullParserException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8433 | 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] | 8434 | } catch(java.io.IOException e) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8435 | 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] | 8436 | } |
David 'Digit' Turner | add1376 | 2010-02-03 17:34:58 -0800 | [diff] [blame] | 8437 | // Clean up partially written files |
Suchi Amalapurapu | 8550f25 | 2009-09-29 15:20:32 -0700 | [diff] [blame] | 8438 | if (mSettingsFilename.exists()) { |
| 8439 | if (!mSettingsFilename.delete()) { |
| 8440 | Log.i(TAG, "Failed to clean up mangled file: " + mSettingsFilename); |
| 8441 | } |
| 8442 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8443 | //Debug.stopMethodTracing(); |
| 8444 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8445 | |
| 8446 | void writeDisabledSysPackage(XmlSerializer serializer, final PackageSetting pkg) |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8447 | throws java.io.IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8448 | serializer.startTag(null, "updated-package"); |
| 8449 | serializer.attribute(null, "name", pkg.name); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8450 | if (pkg.realName != null) { |
| 8451 | serializer.attribute(null, "realName", pkg.realName); |
| 8452 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8453 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 8454 | serializer.attribute(null, "ts", pkg.getTimeStampStr()); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8455 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8456 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 8457 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 8458 | } |
| 8459 | if (pkg.sharedUser == null) { |
| 8460 | serializer.attribute(null, "userId", |
| 8461 | Integer.toString(pkg.userId)); |
| 8462 | } else { |
| 8463 | serializer.attribute(null, "sharedUserId", |
| 8464 | Integer.toString(pkg.userId)); |
| 8465 | } |
| 8466 | serializer.startTag(null, "perms"); |
| 8467 | if (pkg.sharedUser == null) { |
| 8468 | // If this is a shared user, the permissions will |
| 8469 | // be written there. We still need to write an |
| 8470 | // empty permissions list so permissionsFixed will |
| 8471 | // be set. |
| 8472 | for (final String name : pkg.grantedPermissions) { |
| 8473 | BasePermission bp = mPermissions.get(name); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8474 | if (bp != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8475 | // We only need to write signature or system permissions but this wont |
| 8476 | // match the semantics of grantedPermissions. So write all permissions. |
| 8477 | serializer.startTag(null, "item"); |
| 8478 | serializer.attribute(null, "name", name); |
| 8479 | serializer.endTag(null, "item"); |
| 8480 | } |
| 8481 | } |
| 8482 | } |
| 8483 | serializer.endTag(null, "perms"); |
| 8484 | serializer.endTag(null, "updated-package"); |
| 8485 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8486 | |
| 8487 | void writePackage(XmlSerializer serializer, final PackageSetting pkg) |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8488 | throws java.io.IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8489 | serializer.startTag(null, "package"); |
| 8490 | serializer.attribute(null, "name", pkg.name); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8491 | if (pkg.realName != null) { |
| 8492 | serializer.attribute(null, "realName", pkg.realName); |
| 8493 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8494 | serializer.attribute(null, "codePath", pkg.codePathString); |
| 8495 | if (!pkg.resourcePathString.equals(pkg.codePathString)) { |
| 8496 | serializer.attribute(null, "resourcePath", pkg.resourcePathString); |
| 8497 | } |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8498 | serializer.attribute(null, "flags", |
| 8499 | Integer.toString(pkg.pkgFlags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8500 | serializer.attribute(null, "ts", pkg.getTimeStampStr()); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8501 | serializer.attribute(null, "version", String.valueOf(pkg.versionCode)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8502 | if (pkg.sharedUser == null) { |
| 8503 | serializer.attribute(null, "userId", |
| 8504 | Integer.toString(pkg.userId)); |
| 8505 | } else { |
| 8506 | serializer.attribute(null, "sharedUserId", |
| 8507 | Integer.toString(pkg.userId)); |
| 8508 | } |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8509 | if (pkg.uidError) { |
| 8510 | serializer.attribute(null, "uidError", "true"); |
| 8511 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8512 | if (pkg.enabled != COMPONENT_ENABLED_STATE_DEFAULT) { |
| 8513 | serializer.attribute(null, "enabled", |
| 8514 | pkg.enabled == COMPONENT_ENABLED_STATE_ENABLED |
| 8515 | ? "true" : "false"); |
| 8516 | } |
| 8517 | if(pkg.installStatus == PKG_INSTALL_INCOMPLETE) { |
| 8518 | serializer.attribute(null, "installStatus", "false"); |
| 8519 | } |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8520 | if (pkg.installerPackageName != null) { |
| 8521 | serializer.attribute(null, "installer", pkg.installerPackageName); |
| 8522 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8523 | pkg.signatures.writeXml(serializer, "sigs", mPastSignatures); |
| 8524 | if ((pkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 8525 | serializer.startTag(null, "perms"); |
| 8526 | if (pkg.sharedUser == null) { |
| 8527 | // If this is a shared user, the permissions will |
| 8528 | // be written there. We still need to write an |
| 8529 | // empty permissions list so permissionsFixed will |
| 8530 | // be set. |
| 8531 | for (final String name : pkg.grantedPermissions) { |
| 8532 | serializer.startTag(null, "item"); |
| 8533 | serializer.attribute(null, "name", name); |
| 8534 | serializer.endTag(null, "item"); |
| 8535 | } |
| 8536 | } |
| 8537 | serializer.endTag(null, "perms"); |
| 8538 | } |
| 8539 | if (pkg.disabledComponents.size() > 0) { |
| 8540 | serializer.startTag(null, "disabled-components"); |
| 8541 | for (final String name : pkg.disabledComponents) { |
| 8542 | serializer.startTag(null, "item"); |
| 8543 | serializer.attribute(null, "name", name); |
| 8544 | serializer.endTag(null, "item"); |
| 8545 | } |
| 8546 | serializer.endTag(null, "disabled-components"); |
| 8547 | } |
| 8548 | if (pkg.enabledComponents.size() > 0) { |
| 8549 | serializer.startTag(null, "enabled-components"); |
| 8550 | for (final String name : pkg.enabledComponents) { |
| 8551 | serializer.startTag(null, "item"); |
| 8552 | serializer.attribute(null, "name", name); |
| 8553 | serializer.endTag(null, "item"); |
| 8554 | } |
| 8555 | serializer.endTag(null, "enabled-components"); |
| 8556 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8558 | serializer.endTag(null, "package"); |
| 8559 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | void writePermission(XmlSerializer serializer, BasePermission bp) |
| 8562 | throws XmlPullParserException, java.io.IOException { |
| 8563 | if (bp.type != BasePermission.TYPE_BUILTIN |
| 8564 | && bp.sourcePackage != null) { |
| 8565 | serializer.startTag(null, "item"); |
| 8566 | serializer.attribute(null, "name", bp.name); |
| 8567 | serializer.attribute(null, "package", bp.sourcePackage); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8568 | if (bp.protectionLevel != |
| 8569 | PermissionInfo.PROTECTION_NORMAL) { |
| 8570 | serializer.attribute(null, "protection", |
| 8571 | Integer.toString(bp.protectionLevel)); |
| 8572 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8573 | if (DEBUG_SETTINGS) Log.v(TAG, |
| 8574 | "Writing perm: name=" + bp.name + " type=" + bp.type); |
| 8575 | if (bp.type == BasePermission.TYPE_DYNAMIC) { |
| 8576 | PermissionInfo pi = bp.perm != null ? bp.perm.info |
| 8577 | : bp.pendingInfo; |
| 8578 | if (pi != null) { |
| 8579 | serializer.attribute(null, "type", "dynamic"); |
| 8580 | if (pi.icon != 0) { |
| 8581 | serializer.attribute(null, "icon", |
| 8582 | Integer.toString(pi.icon)); |
| 8583 | } |
| 8584 | if (pi.nonLocalizedLabel != null) { |
| 8585 | serializer.attribute(null, "label", |
| 8586 | pi.nonLocalizedLabel.toString()); |
| 8587 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8588 | } |
| 8589 | } |
| 8590 | serializer.endTag(null, "item"); |
| 8591 | } |
| 8592 | } |
| 8593 | |
| 8594 | String getReadMessagesLP() { |
| 8595 | return mReadMessages.toString(); |
| 8596 | } |
| 8597 | |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8598 | ArrayList<PackageSetting> getListOfIncompleteInstallPackages() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8599 | HashSet<String> kList = new HashSet<String>(mPackages.keySet()); |
| 8600 | Iterator<String> its = kList.iterator(); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8601 | ArrayList<PackageSetting> ret = new ArrayList<PackageSetting>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8602 | while(its.hasNext()) { |
| 8603 | String key = its.next(); |
| 8604 | PackageSetting ps = mPackages.get(key); |
| 8605 | if(ps.getInstallStatus() == PKG_INSTALL_INCOMPLETE) { |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 8606 | ret.add(ps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8607 | } |
| 8608 | } |
| 8609 | return ret; |
| 8610 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8612 | boolean readLP() { |
| 8613 | FileInputStream str = null; |
| 8614 | if (mBackupSettingsFilename.exists()) { |
| 8615 | try { |
| 8616 | str = new FileInputStream(mBackupSettingsFilename); |
| 8617 | mReadMessages.append("Reading from backup settings file\n"); |
| 8618 | Log.i(TAG, "Reading from backup settings file!"); |
Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8619 | if (mSettingsFilename.exists()) { |
| 8620 | // If both the backup and settings file exist, we |
| 8621 | // ignore the settings since it might have been |
| 8622 | // corrupted. |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8623 | Slog.w(TAG, "Cleaning up settings file " + mSettingsFilename); |
Suchi Amalapurapu | 14e833f | 2009-10-20 11:27:32 -0700 | [diff] [blame] | 8624 | mSettingsFilename.delete(); |
| 8625 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8626 | } catch (java.io.IOException e) { |
| 8627 | // We'll try for the normal settings file. |
| 8628 | } |
| 8629 | } |
| 8630 | |
| 8631 | mPastSignatures.clear(); |
| 8632 | |
| 8633 | try { |
| 8634 | if (str == null) { |
| 8635 | if (!mSettingsFilename.exists()) { |
| 8636 | mReadMessages.append("No settings file found\n"); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8637 | Slog.i(TAG, "No current settings file!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8638 | return false; |
| 8639 | } |
| 8640 | str = new FileInputStream(mSettingsFilename); |
| 8641 | } |
| 8642 | XmlPullParser parser = Xml.newPullParser(); |
| 8643 | parser.setInput(str, null); |
| 8644 | |
| 8645 | int type; |
| 8646 | while ((type=parser.next()) != XmlPullParser.START_TAG |
| 8647 | && type != XmlPullParser.END_DOCUMENT) { |
| 8648 | ; |
| 8649 | } |
| 8650 | |
| 8651 | if (type != XmlPullParser.START_TAG) { |
| 8652 | mReadMessages.append("No start tag found in settings file\n"); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8653 | 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] | 8654 | return false; |
| 8655 | } |
| 8656 | |
| 8657 | int outerDepth = parser.getDepth(); |
| 8658 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8659 | && (type != XmlPullParser.END_TAG |
| 8660 | || parser.getDepth() > outerDepth)) { |
| 8661 | if (type == XmlPullParser.END_TAG |
| 8662 | || type == XmlPullParser.TEXT) { |
| 8663 | continue; |
| 8664 | } |
| 8665 | |
| 8666 | String tagName = parser.getName(); |
| 8667 | if (tagName.equals("package")) { |
| 8668 | readPackageLP(parser); |
| 8669 | } else if (tagName.equals("permissions")) { |
| 8670 | readPermissionsLP(mPermissions, parser); |
| 8671 | } else if (tagName.equals("permission-trees")) { |
| 8672 | readPermissionsLP(mPermissionTrees, parser); |
| 8673 | } else if (tagName.equals("shared-user")) { |
| 8674 | readSharedUserLP(parser); |
| 8675 | } else if (tagName.equals("preferred-packages")) { |
Dianne Hackborn | a7ca0e5 | 2009-12-01 14:31:55 -0800 | [diff] [blame] | 8676 | // no longer used. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8677 | } else if (tagName.equals("preferred-activities")) { |
| 8678 | readPreferredActivitiesLP(parser); |
| 8679 | } else if(tagName.equals("updated-package")) { |
| 8680 | readDisabledSysPackageLP(parser); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8681 | } else if (tagName.equals("cleaning-package")) { |
| 8682 | String name = parser.getAttributeValue(null, "name"); |
| 8683 | if (name != null) { |
| 8684 | mPackagesToBeCleaned.add(name); |
| 8685 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8686 | } else if (tagName.equals("renamed-package")) { |
| 8687 | String nname = parser.getAttributeValue(null, "new"); |
| 8688 | String oname = parser.getAttributeValue(null, "old"); |
| 8689 | if (nname != null && oname != null) { |
| 8690 | mRenamedPackages.put(nname, oname); |
| 8691 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8692 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8693 | Slog.w(TAG, "Unknown element under <packages>: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8694 | + parser.getName()); |
| 8695 | XmlUtils.skipCurrentTag(parser); |
| 8696 | } |
| 8697 | } |
| 8698 | |
| 8699 | str.close(); |
| 8700 | |
| 8701 | } catch(XmlPullParserException e) { |
| 8702 | mReadMessages.append("Error reading: " + e.toString()); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8703 | Slog.e(TAG, "Error reading package manager settings", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8704 | |
| 8705 | } catch(java.io.IOException e) { |
| 8706 | mReadMessages.append("Error reading: " + e.toString()); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8707 | Slog.e(TAG, "Error reading package manager settings", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8708 | |
| 8709 | } |
| 8710 | |
| 8711 | int N = mPendingPackages.size(); |
| 8712 | for (int i=0; i<N; i++) { |
| 8713 | final PendingPackage pp = mPendingPackages.get(i); |
| 8714 | Object idObj = getUserIdLP(pp.sharedId); |
| 8715 | if (idObj != null && idObj instanceof SharedUserSetting) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8716 | PackageSetting p = getPackageLP(pp.name, null, pp.realName, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8717 | (SharedUserSetting)idObj, pp.codePath, pp.resourcePath, |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8718 | pp.versionCode, pp.pkgFlags, true, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8719 | if (p == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8720 | Slog.w(TAG, "Unable to create application package for " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8721 | + pp.name); |
| 8722 | continue; |
| 8723 | } |
| 8724 | p.copyFrom(pp); |
| 8725 | } else if (idObj != null) { |
| 8726 | String msg = "Bad package setting: package " + pp.name |
| 8727 | + " has shared uid " + pp.sharedId |
| 8728 | + " that is not a shared uid\n"; |
| 8729 | mReadMessages.append(msg); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8730 | Slog.e(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8731 | } else { |
| 8732 | String msg = "Bad package setting: package " + pp.name |
| 8733 | + " has shared uid " + pp.sharedId |
| 8734 | + " that is not defined\n"; |
| 8735 | mReadMessages.append(msg); |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 8736 | Slog.e(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8737 | } |
| 8738 | } |
| 8739 | mPendingPackages.clear(); |
| 8740 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8741 | mReadMessages.append("Read completed successfully: " |
| 8742 | + mPackages.size() + " packages, " |
| 8743 | + mSharedUsers.size() + " shared uids\n"); |
| 8744 | |
| 8745 | return true; |
| 8746 | } |
| 8747 | |
| 8748 | private int readInt(XmlPullParser parser, String ns, String name, |
| 8749 | int defValue) { |
| 8750 | String v = parser.getAttributeValue(ns, name); |
| 8751 | try { |
| 8752 | if (v == null) { |
| 8753 | return defValue; |
| 8754 | } |
| 8755 | return Integer.parseInt(v); |
| 8756 | } catch (NumberFormatException e) { |
| 8757 | reportSettingsProblem(Log.WARN, |
| 8758 | "Error in package manager settings: attribute " + |
| 8759 | name + " has bad integer value " + v + " at " |
| 8760 | + parser.getPositionDescription()); |
| 8761 | } |
| 8762 | return defValue; |
| 8763 | } |
| 8764 | |
| 8765 | private void readPermissionsLP(HashMap<String, BasePermission> out, |
| 8766 | XmlPullParser parser) |
| 8767 | throws IOException, XmlPullParserException { |
| 8768 | int outerDepth = parser.getDepth(); |
| 8769 | int type; |
| 8770 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8771 | && (type != XmlPullParser.END_TAG |
| 8772 | || parser.getDepth() > outerDepth)) { |
| 8773 | if (type == XmlPullParser.END_TAG |
| 8774 | || type == XmlPullParser.TEXT) { |
| 8775 | continue; |
| 8776 | } |
| 8777 | |
| 8778 | String tagName = parser.getName(); |
| 8779 | if (tagName.equals("item")) { |
| 8780 | String name = parser.getAttributeValue(null, "name"); |
| 8781 | String sourcePackage = parser.getAttributeValue(null, "package"); |
| 8782 | String ptype = parser.getAttributeValue(null, "type"); |
| 8783 | if (name != null && sourcePackage != null) { |
| 8784 | boolean dynamic = "dynamic".equals(ptype); |
| 8785 | BasePermission bp = new BasePermission(name, sourcePackage, |
| 8786 | dynamic |
| 8787 | ? BasePermission.TYPE_DYNAMIC |
| 8788 | : BasePermission.TYPE_NORMAL); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8789 | bp.protectionLevel = readInt(parser, null, "protection", |
| 8790 | PermissionInfo.PROTECTION_NORMAL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8791 | if (dynamic) { |
| 8792 | PermissionInfo pi = new PermissionInfo(); |
| 8793 | pi.packageName = sourcePackage.intern(); |
| 8794 | pi.name = name.intern(); |
| 8795 | pi.icon = readInt(parser, null, "icon", 0); |
| 8796 | pi.nonLocalizedLabel = parser.getAttributeValue( |
| 8797 | null, "label"); |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 8798 | pi.protectionLevel = bp.protectionLevel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8799 | bp.pendingInfo = pi; |
| 8800 | } |
| 8801 | out.put(bp.name, bp); |
| 8802 | } else { |
| 8803 | reportSettingsProblem(Log.WARN, |
| 8804 | "Error in package manager settings: permissions has" |
| 8805 | + " no name at " + parser.getPositionDescription()); |
| 8806 | } |
| 8807 | } else { |
| 8808 | reportSettingsProblem(Log.WARN, |
| 8809 | "Unknown element reading permissions: " |
| 8810 | + parser.getName() + " at " |
| 8811 | + parser.getPositionDescription()); |
| 8812 | } |
| 8813 | XmlUtils.skipCurrentTag(parser); |
| 8814 | } |
| 8815 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8816 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8817 | private void readDisabledSysPackageLP(XmlPullParser parser) |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 8818 | throws XmlPullParserException, IOException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8819 | String name = parser.getAttributeValue(null, "name"); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8820 | String realName = parser.getAttributeValue(null, "realName"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8821 | String codePathStr = parser.getAttributeValue(null, "codePath"); |
| 8822 | String resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8823 | if (resourcePathStr == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8824 | resourcePathStr = codePathStr; |
| 8825 | } |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8826 | String version = parser.getAttributeValue(null, "version"); |
| 8827 | int versionCode = 0; |
| 8828 | if (version != null) { |
| 8829 | try { |
| 8830 | versionCode = Integer.parseInt(version); |
| 8831 | } catch (NumberFormatException e) { |
| 8832 | } |
| 8833 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8835 | int pkgFlags = 0; |
| 8836 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8837 | PackageSetting ps = new PackageSetting(name, realName, |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8838 | new File(codePathStr), |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8839 | new File(resourcePathStr), versionCode, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8840 | String timeStampStr = parser.getAttributeValue(null, "ts"); |
| 8841 | if (timeStampStr != null) { |
| 8842 | try { |
| 8843 | long timeStamp = Long.parseLong(timeStampStr); |
| 8844 | ps.setTimeStamp(timeStamp, timeStampStr); |
| 8845 | } catch (NumberFormatException e) { |
| 8846 | } |
| 8847 | } |
| 8848 | String idStr = parser.getAttributeValue(null, "userId"); |
| 8849 | ps.userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 8850 | if(ps.userId <= 0) { |
| 8851 | String sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 8852 | ps.userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0; |
| 8853 | } |
| 8854 | int outerDepth = parser.getDepth(); |
| 8855 | int type; |
| 8856 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 8857 | && (type != XmlPullParser.END_TAG |
| 8858 | || parser.getDepth() > outerDepth)) { |
| 8859 | if (type == XmlPullParser.END_TAG |
| 8860 | || type == XmlPullParser.TEXT) { |
| 8861 | continue; |
| 8862 | } |
| 8863 | |
| 8864 | String tagName = parser.getName(); |
| 8865 | if (tagName.equals("perms")) { |
| 8866 | readGrantedPermissionsLP(parser, |
| 8867 | ps.grantedPermissions); |
| 8868 | } else { |
| 8869 | reportSettingsProblem(Log.WARN, |
| 8870 | "Unknown element under <updated-package>: " |
| 8871 | + parser.getName()); |
| 8872 | XmlUtils.skipCurrentTag(parser); |
| 8873 | } |
| 8874 | } |
| 8875 | mDisabledSysPackages.put(name, ps); |
| 8876 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8878 | private void readPackageLP(XmlPullParser parser) |
| 8879 | throws XmlPullParserException, IOException { |
| 8880 | String name = null; |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8881 | String realName = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8882 | String idStr = null; |
| 8883 | String sharedIdStr = null; |
| 8884 | String codePathStr = null; |
| 8885 | String resourcePathStr = null; |
| 8886 | String systemStr = null; |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8887 | String installerPackageName = null; |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8888 | String uidError = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8889 | int pkgFlags = 0; |
| 8890 | String timeStampStr; |
| 8891 | long timeStamp = 0; |
| 8892 | PackageSettingBase packageSetting = null; |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8893 | String version = null; |
| 8894 | int versionCode = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8895 | try { |
| 8896 | name = parser.getAttributeValue(null, "name"); |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8897 | realName = parser.getAttributeValue(null, "realName"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8898 | idStr = parser.getAttributeValue(null, "userId"); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8899 | uidError = parser.getAttributeValue(null, "uidError"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8900 | sharedIdStr = parser.getAttributeValue(null, "sharedUserId"); |
| 8901 | codePathStr = parser.getAttributeValue(null, "codePath"); |
| 8902 | resourcePathStr = parser.getAttributeValue(null, "resourcePath"); |
Suchi Amalapurapu | c2af31f | 2009-05-08 14:44:41 -0700 | [diff] [blame] | 8903 | version = parser.getAttributeValue(null, "version"); |
| 8904 | if (version != null) { |
| 8905 | try { |
| 8906 | versionCode = Integer.parseInt(version); |
| 8907 | } catch (NumberFormatException e) { |
| 8908 | } |
| 8909 | } |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8910 | installerPackageName = parser.getAttributeValue(null, "installer"); |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8911 | |
| 8912 | systemStr = parser.getAttributeValue(null, "flags"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8913 | if (systemStr != null) { |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8914 | try { |
| 8915 | pkgFlags = Integer.parseInt(systemStr); |
| 8916 | } catch (NumberFormatException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8917 | } |
| 8918 | } else { |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 8919 | // For backward compatibility |
| 8920 | systemStr = parser.getAttributeValue(null, "system"); |
| 8921 | if (systemStr != null) { |
| 8922 | pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM : 0; |
| 8923 | } else { |
| 8924 | // Old settings that don't specify system... just treat |
| 8925 | // them as system, good enough. |
| 8926 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 8927 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | } |
| 8929 | timeStampStr = parser.getAttributeValue(null, "ts"); |
| 8930 | if (timeStampStr != null) { |
| 8931 | try { |
| 8932 | timeStamp = Long.parseLong(timeStampStr); |
| 8933 | } catch (NumberFormatException e) { |
| 8934 | } |
| 8935 | } |
| 8936 | if (DEBUG_SETTINGS) Log.v(TAG, "Reading package: " + name |
| 8937 | + " userId=" + idStr + " sharedUserId=" + sharedIdStr); |
| 8938 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 8939 | if (resourcePathStr == null) { |
| 8940 | resourcePathStr = codePathStr; |
| 8941 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8942 | if (realName != null) { |
| 8943 | realName = realName.intern(); |
| 8944 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8945 | if (name == null) { |
| 8946 | reportSettingsProblem(Log.WARN, |
| 8947 | "Error in package manager settings: <package> has no name at " |
| 8948 | + parser.getPositionDescription()); |
| 8949 | } else if (codePathStr == null) { |
| 8950 | reportSettingsProblem(Log.WARN, |
| 8951 | "Error in package manager settings: <package> has no codePath at " |
| 8952 | + parser.getPositionDescription()); |
| 8953 | } else if (userId > 0) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8954 | packageSetting = addPackageLP(name.intern(), realName, |
| 8955 | new File(codePathStr), new File(resourcePathStr), |
| 8956 | userId, versionCode, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8957 | if (DEBUG_SETTINGS) Log.i(TAG, "Reading package " + name |
| 8958 | + ": userId=" + userId + " pkg=" + packageSetting); |
| 8959 | if (packageSetting == null) { |
| 8960 | reportSettingsProblem(Log.ERROR, |
| 8961 | "Failure adding uid " + userId |
| 8962 | + " while parsing settings at " |
| 8963 | + parser.getPositionDescription()); |
| 8964 | } else { |
| 8965 | packageSetting.setTimeStamp(timeStamp, timeStampStr); |
| 8966 | } |
| 8967 | } else if (sharedIdStr != null) { |
| 8968 | userId = sharedIdStr != null |
| 8969 | ? Integer.parseInt(sharedIdStr) : 0; |
| 8970 | if (userId > 0) { |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 8971 | packageSetting = new PendingPackage(name.intern(), realName, |
| 8972 | new File(codePathStr), new File(resourcePathStr), |
| 8973 | userId, versionCode, pkgFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8974 | packageSetting.setTimeStamp(timeStamp, timeStampStr); |
| 8975 | mPendingPackages.add((PendingPackage) packageSetting); |
| 8976 | if (DEBUG_SETTINGS) Log.i(TAG, "Reading package " + name |
| 8977 | + ": sharedUserId=" + userId + " pkg=" |
| 8978 | + packageSetting); |
| 8979 | } else { |
| 8980 | reportSettingsProblem(Log.WARN, |
| 8981 | "Error in package manager settings: package " |
| 8982 | + name + " has bad sharedId " + sharedIdStr |
| 8983 | + " at " + parser.getPositionDescription()); |
| 8984 | } |
| 8985 | } else { |
| 8986 | reportSettingsProblem(Log.WARN, |
| 8987 | "Error in package manager settings: package " |
| 8988 | + name + " has bad userId " + idStr + " at " |
| 8989 | + parser.getPositionDescription()); |
| 8990 | } |
| 8991 | } catch (NumberFormatException e) { |
| 8992 | reportSettingsProblem(Log.WARN, |
| 8993 | "Error in package manager settings: package " |
| 8994 | + name + " has bad userId " + idStr + " at " |
| 8995 | + parser.getPositionDescription()); |
| 8996 | } |
| 8997 | if (packageSetting != null) { |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 8998 | packageSetting.uidError = "true".equals(uidError); |
Jacek Surazski | 65e1317 | 2009-04-28 15:26:38 +0200 | [diff] [blame] | 8999 | packageSetting.installerPackageName = installerPackageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9000 | final String enabledStr = parser.getAttributeValue(null, "enabled"); |
| 9001 | if (enabledStr != null) { |
| 9002 | if (enabledStr.equalsIgnoreCase("true")) { |
| 9003 | packageSetting.enabled = COMPONENT_ENABLED_STATE_ENABLED; |
| 9004 | } else if (enabledStr.equalsIgnoreCase("false")) { |
| 9005 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DISABLED; |
| 9006 | } else if (enabledStr.equalsIgnoreCase("default")) { |
| 9007 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 9008 | } else { |
| 9009 | reportSettingsProblem(Log.WARN, |
| 9010 | "Error in package manager settings: package " |
| 9011 | + name + " has bad enabled value: " + idStr |
| 9012 | + " at " + parser.getPositionDescription()); |
| 9013 | } |
| 9014 | } else { |
| 9015 | packageSetting.enabled = COMPONENT_ENABLED_STATE_DEFAULT; |
| 9016 | } |
| 9017 | final String installStatusStr = parser.getAttributeValue(null, "installStatus"); |
| 9018 | if (installStatusStr != null) { |
| 9019 | if (installStatusStr.equalsIgnoreCase("false")) { |
| 9020 | packageSetting.installStatus = PKG_INSTALL_INCOMPLETE; |
| 9021 | } else { |
| 9022 | packageSetting.installStatus = PKG_INSTALL_COMPLETE; |
| 9023 | } |
| 9024 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9025 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9026 | int outerDepth = parser.getDepth(); |
| 9027 | int type; |
| 9028 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9029 | && (type != XmlPullParser.END_TAG |
| 9030 | || parser.getDepth() > outerDepth)) { |
| 9031 | if (type == XmlPullParser.END_TAG |
| 9032 | || type == XmlPullParser.TEXT) { |
| 9033 | continue; |
| 9034 | } |
| 9035 | |
| 9036 | String tagName = parser.getName(); |
| 9037 | if (tagName.equals("disabled-components")) { |
| 9038 | readDisabledComponentsLP(packageSetting, parser); |
| 9039 | } else if (tagName.equals("enabled-components")) { |
| 9040 | readEnabledComponentsLP(packageSetting, parser); |
| 9041 | } else if (tagName.equals("sigs")) { |
| 9042 | packageSetting.signatures.readXml(parser, mPastSignatures); |
| 9043 | } else if (tagName.equals("perms")) { |
| 9044 | readGrantedPermissionsLP(parser, |
Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 9045 | packageSetting.grantedPermissions); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9046 | packageSetting.permissionsFixed = true; |
| 9047 | } else { |
| 9048 | reportSettingsProblem(Log.WARN, |
| 9049 | "Unknown element under <package>: " |
| 9050 | + parser.getName()); |
| 9051 | XmlUtils.skipCurrentTag(parser); |
| 9052 | } |
| 9053 | } |
| 9054 | } else { |
| 9055 | XmlUtils.skipCurrentTag(parser); |
| 9056 | } |
| 9057 | } |
| 9058 | |
| 9059 | private void readDisabledComponentsLP(PackageSettingBase packageSetting, |
| 9060 | XmlPullParser parser) |
| 9061 | throws IOException, XmlPullParserException { |
| 9062 | int outerDepth = parser.getDepth(); |
| 9063 | int type; |
| 9064 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9065 | && (type != XmlPullParser.END_TAG |
| 9066 | || parser.getDepth() > outerDepth)) { |
| 9067 | if (type == XmlPullParser.END_TAG |
| 9068 | || type == XmlPullParser.TEXT) { |
| 9069 | continue; |
| 9070 | } |
| 9071 | |
| 9072 | String tagName = parser.getName(); |
| 9073 | if (tagName.equals("item")) { |
| 9074 | String name = parser.getAttributeValue(null, "name"); |
| 9075 | if (name != null) { |
| 9076 | packageSetting.disabledComponents.add(name.intern()); |
| 9077 | } else { |
| 9078 | reportSettingsProblem(Log.WARN, |
| 9079 | "Error in package manager settings: <disabled-components> has" |
| 9080 | + " no name at " + parser.getPositionDescription()); |
| 9081 | } |
| 9082 | } else { |
| 9083 | reportSettingsProblem(Log.WARN, |
| 9084 | "Unknown element under <disabled-components>: " |
| 9085 | + parser.getName()); |
| 9086 | } |
| 9087 | XmlUtils.skipCurrentTag(parser); |
| 9088 | } |
| 9089 | } |
| 9090 | |
| 9091 | private void readEnabledComponentsLP(PackageSettingBase packageSetting, |
| 9092 | XmlPullParser parser) |
| 9093 | throws IOException, XmlPullParserException { |
| 9094 | int outerDepth = parser.getDepth(); |
| 9095 | int type; |
| 9096 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9097 | && (type != XmlPullParser.END_TAG |
| 9098 | || parser.getDepth() > outerDepth)) { |
| 9099 | if (type == XmlPullParser.END_TAG |
| 9100 | || type == XmlPullParser.TEXT) { |
| 9101 | continue; |
| 9102 | } |
| 9103 | |
| 9104 | String tagName = parser.getName(); |
| 9105 | if (tagName.equals("item")) { |
| 9106 | String name = parser.getAttributeValue(null, "name"); |
| 9107 | if (name != null) { |
| 9108 | packageSetting.enabledComponents.add(name.intern()); |
| 9109 | } else { |
| 9110 | reportSettingsProblem(Log.WARN, |
| 9111 | "Error in package manager settings: <enabled-components> has" |
| 9112 | + " no name at " + parser.getPositionDescription()); |
| 9113 | } |
| 9114 | } else { |
| 9115 | reportSettingsProblem(Log.WARN, |
| 9116 | "Unknown element under <enabled-components>: " |
| 9117 | + parser.getName()); |
| 9118 | } |
| 9119 | XmlUtils.skipCurrentTag(parser); |
| 9120 | } |
| 9121 | } |
| 9122 | |
| 9123 | private void readSharedUserLP(XmlPullParser parser) |
| 9124 | throws XmlPullParserException, IOException { |
| 9125 | String name = null; |
| 9126 | String idStr = null; |
| 9127 | int pkgFlags = 0; |
| 9128 | SharedUserSetting su = null; |
| 9129 | try { |
| 9130 | name = parser.getAttributeValue(null, "name"); |
| 9131 | idStr = parser.getAttributeValue(null, "userId"); |
| 9132 | int userId = idStr != null ? Integer.parseInt(idStr) : 0; |
| 9133 | if ("true".equals(parser.getAttributeValue(null, "system"))) { |
| 9134 | pkgFlags |= ApplicationInfo.FLAG_SYSTEM; |
| 9135 | } |
| 9136 | if (name == null) { |
| 9137 | reportSettingsProblem(Log.WARN, |
| 9138 | "Error in package manager settings: <shared-user> has no name at " |
| 9139 | + parser.getPositionDescription()); |
| 9140 | } else if (userId == 0) { |
| 9141 | reportSettingsProblem(Log.WARN, |
| 9142 | "Error in package manager settings: shared-user " |
| 9143 | + name + " has bad userId " + idStr + " at " |
| 9144 | + parser.getPositionDescription()); |
| 9145 | } else { |
| 9146 | if ((su=addSharedUserLP(name.intern(), userId, pkgFlags)) == null) { |
| 9147 | reportSettingsProblem(Log.ERROR, |
| 9148 | "Occurred while parsing settings at " |
| 9149 | + parser.getPositionDescription()); |
| 9150 | } |
| 9151 | } |
| 9152 | } catch (NumberFormatException e) { |
| 9153 | reportSettingsProblem(Log.WARN, |
| 9154 | "Error in package manager settings: package " |
| 9155 | + name + " has bad userId " + idStr + " at " |
| 9156 | + parser.getPositionDescription()); |
| 9157 | }; |
| 9158 | |
| 9159 | if (su != null) { |
| 9160 | int outerDepth = parser.getDepth(); |
| 9161 | int type; |
| 9162 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9163 | && (type != XmlPullParser.END_TAG |
| 9164 | || parser.getDepth() > outerDepth)) { |
| 9165 | if (type == XmlPullParser.END_TAG |
| 9166 | || type == XmlPullParser.TEXT) { |
| 9167 | continue; |
| 9168 | } |
| 9169 | |
| 9170 | String tagName = parser.getName(); |
| 9171 | if (tagName.equals("sigs")) { |
| 9172 | su.signatures.readXml(parser, mPastSignatures); |
| 9173 | } else if (tagName.equals("perms")) { |
Dianne Hackborn | f657b63 | 2010-03-22 18:08:07 -0700 | [diff] [blame] | 9174 | readGrantedPermissionsLP(parser, su.grantedPermissions); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9175 | } else { |
| 9176 | reportSettingsProblem(Log.WARN, |
| 9177 | "Unknown element under <shared-user>: " |
| 9178 | + parser.getName()); |
| 9179 | XmlUtils.skipCurrentTag(parser); |
| 9180 | } |
| 9181 | } |
| 9182 | |
| 9183 | } else { |
| 9184 | XmlUtils.skipCurrentTag(parser); |
| 9185 | } |
| 9186 | } |
| 9187 | |
| 9188 | private void readGrantedPermissionsLP(XmlPullParser parser, |
| 9189 | HashSet<String> outPerms) throws IOException, XmlPullParserException { |
| 9190 | int outerDepth = parser.getDepth(); |
| 9191 | int type; |
| 9192 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9193 | && (type != XmlPullParser.END_TAG |
| 9194 | || parser.getDepth() > outerDepth)) { |
| 9195 | if (type == XmlPullParser.END_TAG |
| 9196 | || type == XmlPullParser.TEXT) { |
| 9197 | continue; |
| 9198 | } |
| 9199 | |
| 9200 | String tagName = parser.getName(); |
| 9201 | if (tagName.equals("item")) { |
| 9202 | String name = parser.getAttributeValue(null, "name"); |
| 9203 | if (name != null) { |
| 9204 | outPerms.add(name.intern()); |
| 9205 | } else { |
| 9206 | reportSettingsProblem(Log.WARN, |
| 9207 | "Error in package manager settings: <perms> has" |
| 9208 | + " no name at " + parser.getPositionDescription()); |
| 9209 | } |
| 9210 | } else { |
| 9211 | reportSettingsProblem(Log.WARN, |
| 9212 | "Unknown element under <perms>: " |
| 9213 | + parser.getName()); |
| 9214 | } |
| 9215 | XmlUtils.skipCurrentTag(parser); |
| 9216 | } |
| 9217 | } |
| 9218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9219 | private void readPreferredActivitiesLP(XmlPullParser parser) |
| 9220 | throws XmlPullParserException, IOException { |
| 9221 | int outerDepth = parser.getDepth(); |
| 9222 | int type; |
| 9223 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 9224 | && (type != XmlPullParser.END_TAG |
| 9225 | || parser.getDepth() > outerDepth)) { |
| 9226 | if (type == XmlPullParser.END_TAG |
| 9227 | || type == XmlPullParser.TEXT) { |
| 9228 | continue; |
| 9229 | } |
| 9230 | |
| 9231 | String tagName = parser.getName(); |
| 9232 | if (tagName.equals("item")) { |
| 9233 | PreferredActivity pa = new PreferredActivity(parser); |
| 9234 | if (pa.mParseError == null) { |
| 9235 | mPreferredActivities.addFilter(pa); |
| 9236 | } else { |
| 9237 | reportSettingsProblem(Log.WARN, |
| 9238 | "Error in package manager settings: <preferred-activity> " |
| 9239 | + pa.mParseError + " at " |
| 9240 | + parser.getPositionDescription()); |
| 9241 | } |
| 9242 | } else { |
| 9243 | reportSettingsProblem(Log.WARN, |
| 9244 | "Unknown element under <preferred-activities>: " |
| 9245 | + parser.getName()); |
| 9246 | XmlUtils.skipCurrentTag(parser); |
| 9247 | } |
| 9248 | } |
| 9249 | } |
| 9250 | |
| 9251 | // Returns -1 if we could not find an available UserId to assign |
| 9252 | private int newUserIdLP(Object obj) { |
| 9253 | // Let's be stupidly inefficient for now... |
| 9254 | final int N = mUserIds.size(); |
| 9255 | for (int i=0; i<N; i++) { |
| 9256 | if (mUserIds.get(i) == null) { |
| 9257 | mUserIds.set(i, obj); |
| 9258 | return FIRST_APPLICATION_UID + i; |
| 9259 | } |
| 9260 | } |
| 9261 | |
| 9262 | // None left? |
| 9263 | if (N >= MAX_APPLICATION_UIDS) { |
| 9264 | return -1; |
| 9265 | } |
| 9266 | |
| 9267 | mUserIds.add(obj); |
| 9268 | return FIRST_APPLICATION_UID + N; |
| 9269 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9271 | public PackageSetting getDisabledSystemPkg(String name) { |
| 9272 | synchronized(mPackages) { |
| 9273 | PackageSetting ps = mDisabledSysPackages.get(name); |
| 9274 | return ps; |
| 9275 | } |
| 9276 | } |
| 9277 | |
| 9278 | boolean isEnabledLP(ComponentInfo componentInfo, int flags) { |
| 9279 | final PackageSetting packageSettings = mPackages.get(componentInfo.packageName); |
| 9280 | if (Config.LOGV) { |
| 9281 | Log.v(TAG, "isEnabledLock - packageName = " + componentInfo.packageName |
| 9282 | + " componentName = " + componentInfo.name); |
| 9283 | Log.v(TAG, "enabledComponents: " |
| 9284 | + Arrays.toString(packageSettings.enabledComponents.toArray())); |
| 9285 | Log.v(TAG, "disabledComponents: " |
| 9286 | + Arrays.toString(packageSettings.disabledComponents.toArray())); |
| 9287 | } |
Dianne Hackborn | 6dee18c | 2010-02-09 23:59:16 -0800 | [diff] [blame] | 9288 | if (packageSettings == null) { |
| 9289 | if (false) { |
| 9290 | Log.w(TAG, "WAITING FOR DEBUGGER"); |
| 9291 | Debug.waitForDebugger(); |
| 9292 | Log.i(TAG, "We will crash!"); |
| 9293 | } |
| 9294 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9295 | return ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) |
| 9296 | || ((componentInfo.enabled |
| 9297 | && ((packageSettings.enabled == COMPONENT_ENABLED_STATE_ENABLED) |
| 9298 | || (componentInfo.applicationInfo.enabled |
| 9299 | && packageSettings.enabled != COMPONENT_ENABLED_STATE_DISABLED)) |
| 9300 | && !packageSettings.disabledComponents.contains(componentInfo.name)) |
| 9301 | || packageSettings.enabledComponents.contains(componentInfo.name)); |
| 9302 | } |
| 9303 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9304 | |
| 9305 | // ------- apps on sdcard specific code ------- |
| 9306 | static final boolean DEBUG_SD_INSTALL = false; |
Oscar Montemayor | d02546b | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 9307 | final private String mSdEncryptKey = "AppsOnSD"; |
Oscar Montemayor | 462f037 | 2010-01-14 16:38:40 -0800 | [diff] [blame] | 9308 | final private String mSdEncryptAlg = "AES"; |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9309 | private boolean mMediaMounted = false; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9310 | private static final int MAX_CONTAINERS = 250; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9311 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9312 | private String getEncryptKey() { |
| 9313 | try { |
| 9314 | String sdEncKey = SystemKeyStore.getInstance().retrieveKeyHexString(mSdEncryptKey); |
| 9315 | if (sdEncKey == null) { |
| 9316 | sdEncKey = SystemKeyStore.getInstance(). |
| 9317 | generateNewKeyHexString(128, mSdEncryptAlg, mSdEncryptKey); |
| 9318 | if (sdEncKey == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9319 | Slog.e(TAG, "Failed to create encryption keys"); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9320 | return null; |
| 9321 | } |
| 9322 | } |
| 9323 | return sdEncKey; |
| 9324 | } catch (NoSuchAlgorithmException nsae) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9325 | Slog.e(TAG, "Failed to create encryption keys with exception: " + nsae); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9326 | return null; |
| 9327 | } |
| 9328 | } |
| 9329 | |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9330 | static String getTempContainerId() { |
Suchi Amalapurapu | cf6eaea | 2010-02-23 19:37:45 -0800 | [diff] [blame] | 9331 | String prefix = "smdl2tmp"; |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9332 | int tmpIdx = 1; |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 9333 | String list[] = PackageHelper.getSecureContainerList(); |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9334 | if (list != null) { |
| 9335 | int idx = 0; |
| 9336 | int idList[] = new int[MAX_CONTAINERS]; |
| 9337 | boolean neverFound = true; |
| 9338 | for (String name : list) { |
| 9339 | // Ignore null entries |
| 9340 | if (name == null) { |
| 9341 | continue; |
| 9342 | } |
| 9343 | int sidx = name.indexOf(prefix); |
| 9344 | if (sidx == -1) { |
| 9345 | // Not a temp file. just ignore |
| 9346 | continue; |
| 9347 | } |
| 9348 | String subStr = name.substring(sidx + prefix.length()); |
| 9349 | idList[idx] = -1; |
| 9350 | if (subStr != null) { |
| 9351 | try { |
| 9352 | int cid = Integer.parseInt(subStr); |
| 9353 | idList[idx++] = cid; |
| 9354 | neverFound = false; |
| 9355 | } catch (NumberFormatException e) { |
| 9356 | } |
| 9357 | } |
| 9358 | } |
| 9359 | if (!neverFound) { |
| 9360 | // Sort idList |
| 9361 | Arrays.sort(idList); |
| 9362 | for (int j = 1; j <= idList.length; j++) { |
| 9363 | if (idList[j-1] != j) { |
| 9364 | tmpIdx = j; |
| 9365 | break; |
| 9366 | } |
| 9367 | } |
| 9368 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9369 | } |
Suchi Amalapurapu | c028be4 | 2010-01-25 12:19:12 -0800 | [diff] [blame] | 9370 | return prefix + tmpIdx; |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9371 | } |
| 9372 | |
Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9373 | /* |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9374 | * Update media status on PackageManager. |
Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9375 | */ |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9376 | public void updateExternalMediaStatus(final boolean mediaStatus, final boolean reportStatus) { |
| 9377 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9378 | throw new SecurityException("Media status can only be updated by the system"); |
| 9379 | } |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9380 | synchronized (mPackages) { |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 9381 | Log.i(TAG, "Updating external media status from " + |
| 9382 | (mMediaMounted ? "mounted" : "unmounted") + " to " + |
| 9383 | (mediaStatus ? "mounted" : "unmounted")); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9384 | if (DEBUG_SD_INSTALL) Log.i(TAG, "updateExternalMediaStatus:: mediaStatus=" + |
| 9385 | mediaStatus+", mMediaMounted=" + mMediaMounted); |
| 9386 | if (mediaStatus == mMediaMounted) { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9387 | if (reportStatus) { |
| 9388 | mHandler.sendEmptyMessage(UPDATED_MEDIA_STATUS); |
| 9389 | } |
| 9390 | return; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9391 | } |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9392 | mMediaMounted = mediaStatus; |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 9393 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9394 | // Queue up an async operation since the package installation may take a little while. |
| 9395 | mHandler.post(new Runnable() { |
| 9396 | public void run() { |
| 9397 | mHandler.removeCallbacks(this); |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9398 | try { |
| 9399 | updateExternalMediaStatusInner(mediaStatus); |
| 9400 | } finally { |
| 9401 | if (reportStatus) { |
| 9402 | mHandler.sendEmptyMessage(UPDATED_MEDIA_STATUS); |
| 9403 | } |
| 9404 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9405 | } |
| 9406 | }); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9407 | } |
| 9408 | |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9409 | private void updateExternalMediaStatusInner(boolean mediaStatus) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9410 | // If we are up here that means there are packages to be |
| 9411 | // enabled or disabled. |
Suchi Amalapurapu | 679bba3 | 2010-02-16 11:52:44 -0800 | [diff] [blame] | 9412 | final String list[] = PackageHelper.getSecureContainerList(); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9413 | if (list == null || list.length == 0) { |
Suchi Amalapurapu | 8a9ab24 | 2010-03-11 16:49:16 -0800 | [diff] [blame] | 9414 | Log.i(TAG, "No secure containers on sdcard"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9415 | return; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9416 | } |
Suchi Amalapurapu | cf6eaea | 2010-02-23 19:37:45 -0800 | [diff] [blame] | 9417 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9418 | int uidList[] = new int[list.length]; |
| 9419 | int num = 0; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9420 | HashSet<String> removeCids = new HashSet<String>(); |
| 9421 | HashMap<SdInstallArgs, String> processCids = new HashMap<SdInstallArgs, String>(); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9422 | synchronized (mPackages) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9423 | for (String cid : list) { |
| 9424 | SdInstallArgs args = new SdInstallArgs(cid); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9425 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Processing container " + cid); |
| 9426 | boolean failed = true; |
| 9427 | try { |
| 9428 | String pkgName = args.getPackageName(); |
| 9429 | if (pkgName == null) { |
| 9430 | continue; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9431 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9432 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Looking for pkg : " + pkgName); |
| 9433 | PackageSetting ps = mSettings.mPackages.get(pkgName); |
| 9434 | if (ps != null && ps.codePathString != null && |
Suchi Amalapurapu | 6069beb | 2010-03-10 09:46:49 -0800 | [diff] [blame] | 9435 | (ps.pkgFlags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9436 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + |
| 9437 | " corresponds to pkg : " + pkgName + |
| 9438 | " at code path: " + ps.codePathString); |
| 9439 | // We do have a valid package installed on sdcard |
| 9440 | processCids.put(args, ps.codePathString); |
| 9441 | failed = false; |
| 9442 | int uid = ps.userId; |
| 9443 | if (uid != -1) { |
| 9444 | uidList[num++] = uid; |
| 9445 | } |
| 9446 | } |
| 9447 | } finally { |
| 9448 | if (failed) { |
| 9449 | // Stale container on sdcard. Just delete |
| 9450 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Container : " + cid + " stale"); |
| 9451 | removeCids.add(cid); |
| 9452 | } |
Suchi Amalapurapu | fd3530f | 2010-01-18 00:15:59 -0800 | [diff] [blame] | 9453 | } |
| 9454 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9455 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9456 | // Organize uids |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9457 | int uidArr[] = null; |
| 9458 | if (num > 0) { |
| 9459 | // Sort uid list |
| 9460 | Arrays.sort(uidList, 0, num); |
| 9461 | // Throw away duplicates |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9462 | uidArr = new int[num]; |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9463 | uidArr[0] = uidList[0]; |
| 9464 | int di = 0; |
| 9465 | for (int i = 1; i < num; i++) { |
| 9466 | if (uidList[i-1] != uidList[i]) { |
| 9467 | uidArr[di++] = uidList[i]; |
| 9468 | } |
| 9469 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9470 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9471 | // Process packages with valid entries. |
| 9472 | if (mediaStatus) { |
| 9473 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Loading packages"); |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9474 | loadMediaPackages(processCids, uidArr, removeCids); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9475 | startCleaningPackages(); |
| 9476 | } else { |
| 9477 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Unloading packages"); |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9478 | unloadMediaPackages(processCids, uidArr); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9479 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9480 | } |
| 9481 | |
| 9482 | private void sendResourcesChangedBroadcast(boolean mediaStatus, |
| 9483 | ArrayList<String> pkgList, int uidArr[]) { |
| 9484 | int size = pkgList.size(); |
| 9485 | if (size > 0) { |
| 9486 | // Send broadcasts here |
| 9487 | Bundle extras = new Bundle(); |
| 9488 | extras.putStringArray(Intent.EXTRA_CHANGED_PACKAGE_LIST, |
| 9489 | pkgList.toArray(new String[size])); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9490 | if (uidArr != null) { |
| 9491 | extras.putIntArray(Intent.EXTRA_CHANGED_UID_LIST, uidArr); |
| 9492 | } |
| 9493 | String action = mediaStatus ? Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE |
| 9494 | : Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9495 | sendPackageBroadcast(action, null, extras); |
| 9496 | } |
| 9497 | } |
| 9498 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9499 | /* |
| 9500 | * Look at potentially valid container ids from processCids |
| 9501 | * If package information doesn't match the one on record |
| 9502 | * or package scanning fails, the cid is added to list of |
| 9503 | * removeCids and cleaned up. Since cleaning up containers |
| 9504 | * involves destroying them, we do not want any parse |
| 9505 | * references to such stale containers. So force gc's |
| 9506 | * to avoid unnecessary crashes. |
| 9507 | */ |
| 9508 | private void loadMediaPackages(HashMap<SdInstallArgs, String> processCids, |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9509 | int uidArr[], HashSet<String> removeCids) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9510 | ArrayList<String> pkgList = new ArrayList<String>(); |
| 9511 | Set<SdInstallArgs> keys = processCids.keySet(); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9512 | boolean doGc = false; |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9513 | for (SdInstallArgs args : keys) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9514 | String codePath = processCids.get(args); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9515 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Loading container : " |
| 9516 | + args.cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9517 | int retCode = PackageManager.INSTALL_FAILED_CONTAINER_ERROR; |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9518 | try { |
| 9519 | // Make sure there are no container errors first. |
| 9520 | if (args.doPreInstall(PackageManager.INSTALL_SUCCEEDED) |
| 9521 | != PackageManager.INSTALL_SUCCEEDED) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9522 | Slog.e(TAG, "Failed to mount cid : " + args.cid + |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9523 | " when installing from sdcard"); |
| 9524 | continue; |
| 9525 | } |
| 9526 | // Check code path here. |
| 9527 | if (codePath == null || !codePath.equals(args.getCodePath())) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9528 | Slog.e(TAG, "Container " + args.cid + " cachepath " + args.getCodePath()+ |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9529 | " does not match one in settings " + codePath); |
| 9530 | continue; |
| 9531 | } |
| 9532 | // Parse package |
| 9533 | int parseFlags = PackageParser.PARSE_CHATTY | |
| 9534 | PackageParser.PARSE_ON_SDCARD | mDefParseFlags; |
| 9535 | PackageParser pp = new PackageParser(codePath); |
| 9536 | pp.setSeparateProcesses(mSeparateProcesses); |
| 9537 | final PackageParser.Package pkg = pp.parsePackage(new File(codePath), |
| 9538 | codePath, mMetrics, parseFlags); |
| 9539 | pp = null; |
| 9540 | doGc = true; |
| 9541 | // Check for parse errors |
| 9542 | if (pkg == null) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9543 | Slog.e(TAG, "Parse error when installing install pkg : " |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9544 | + args.cid + " from " + args.cachePath); |
| 9545 | continue; |
| 9546 | } |
| 9547 | setApplicationInfoPaths(pkg, codePath, codePath); |
| 9548 | synchronized (mInstallLock) { |
| 9549 | // Scan the package |
| 9550 | if (scanPackageLI(pkg, parseFlags, SCAN_MONITOR) != null) { |
| 9551 | synchronized (mPackages) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9552 | retCode = PackageManager.INSTALL_SUCCEEDED; |
| 9553 | pkgList.add(pkg.packageName); |
| 9554 | // Post process args |
| 9555 | args.doPostInstall(PackageManager.INSTALL_SUCCEEDED); |
| 9556 | } |
| 9557 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9558 | Slog.i(TAG, "Failed to install pkg: " + |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9559 | pkg.packageName + " from sdcard"); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9560 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9561 | } |
| 9562 | |
| 9563 | } finally { |
| 9564 | if (retCode != PackageManager.INSTALL_SUCCEEDED) { |
| 9565 | // Don't destroy container here. Wait till gc clears things up. |
| 9566 | removeCids.add(args.cid); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9567 | } |
| 9568 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9569 | } |
Dianne Hackborn | d4310ac | 2010-03-16 22:55:08 -0700 | [diff] [blame] | 9570 | synchronized (mPackages) { |
| 9571 | // Persist settings |
| 9572 | mSettings.writeLP(); |
| 9573 | } |
Suchi Amalapurapu | c42e29e | 2010-02-22 16:03:53 -0800 | [diff] [blame] | 9574 | // Send a broadcast to let everyone know we are done processing |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9575 | if (pkgList.size() > 0) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9576 | sendResourcesChangedBroadcast(true, pkgList, uidArr); |
| 9577 | } |
| 9578 | if (doGc) { |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9579 | Runtime.getRuntime().gc(); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9580 | } |
Suchi Amalapurapu | f654a48 | 2010-03-23 09:46:22 -0700 | [diff] [blame] | 9581 | // List stale containers. |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9582 | if (removeCids != null) { |
| 9583 | for (String cid : removeCids) { |
Suchi Amalapurapu | f654a48 | 2010-03-23 09:46:22 -0700 | [diff] [blame] | 9584 | Log.w(TAG, "Container " + cid + " is stale"); |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9585 | } |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9586 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9587 | } |
| 9588 | |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9589 | private void unloadMediaPackages(HashMap<SdInstallArgs, String> processCids, |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9590 | int uidArr[]) { |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9591 | if (DEBUG_SD_INSTALL) Log.i(TAG, "unloading media packages"); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9592 | ArrayList<String> pkgList = new ArrayList<String>(); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9593 | ArrayList<SdInstallArgs> failedList = new ArrayList<SdInstallArgs>(); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9594 | Set<SdInstallArgs> keys = processCids.keySet(); |
| 9595 | for (SdInstallArgs args : keys) { |
| 9596 | String cid = args.cid; |
| 9597 | String pkgName = args.getPackageName(); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9598 | if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to unload pkg : " + pkgName); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9599 | // Delete package internally |
| 9600 | PackageRemovedInfo outInfo = new PackageRemovedInfo(); |
| 9601 | synchronized (mInstallLock) { |
| 9602 | boolean res = deletePackageLI(pkgName, false, |
| 9603 | PackageManager.DONT_DELETE_DATA, outInfo); |
| 9604 | if (res) { |
| 9605 | pkgList.add(pkgName); |
| 9606 | } else { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9607 | Slog.e(TAG, "Failed to delete pkg from sdcard : " + pkgName); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9608 | failedList.add(args); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9609 | } |
| 9610 | } |
| 9611 | } |
| 9612 | // Send broadcasts |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9613 | if (pkgList.size() > 0) { |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9614 | sendResourcesChangedBroadcast(false, pkgList, uidArr); |
Suchi Amalapurapu | b56ae20 | 2010-02-04 22:51:07 -0800 | [diff] [blame] | 9615 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9616 | // Force gc |
| 9617 | Runtime.getRuntime().gc(); |
| 9618 | // Just unmount all valid containers. |
| 9619 | for (SdInstallArgs args : keys) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 9620 | synchronized (mInstallLock) { |
| 9621 | args.doPostDeleteLI(false); |
| 9622 | } |
| 9623 | } |
Suchi Amalapurapu | af8e9f4 | 2010-01-12 10:17:28 -0800 | [diff] [blame] | 9624 | } |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9625 | |
| 9626 | public void movePackage(final String packageName, |
| 9627 | final IPackageMoveObserver observer, final int flags) { |
| 9628 | if (packageName == null) { |
| 9629 | return; |
| 9630 | } |
| 9631 | mContext.enforceCallingOrSelfPermission( |
| 9632 | android.Manifest.permission.MOVE_PACKAGE, null); |
| 9633 | int returnCode = PackageManager.MOVE_SUCCEEDED; |
| 9634 | int currFlags = 0; |
| 9635 | int newFlags = 0; |
| 9636 | synchronized (mPackages) { |
| 9637 | PackageParser.Package pkg = mPackages.get(packageName); |
| 9638 | if (pkg == null) { |
| 9639 | returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST; |
| 9640 | } |
| 9641 | // Disable moving fwd locked apps and system packages |
| 9642 | if (pkg.applicationInfo != null && |
| 9643 | (pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9644 | Slog.w(TAG, "Cannot move system application"); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9645 | returnCode = PackageManager.MOVE_FAILED_SYSTEM_PACKAGE; |
| 9646 | } else if (pkg.applicationInfo != null && |
| 9647 | (pkg.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9648 | Slog.w(TAG, "Cannot move forward locked app."); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9649 | returnCode = PackageManager.MOVE_FAILED_FORWARD_LOCKED; |
| 9650 | } else { |
| 9651 | // Find install location first |
| 9652 | if ((flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0 && |
| 9653 | (flags & PackageManager.MOVE_INTERNAL) != 0) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9654 | Slog.w(TAG, "Ambigous flags specified for move location."); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9655 | returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION; |
| 9656 | } else { |
| 9657 | newFlags = (flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0 ? |
| 9658 | PackageManager.INSTALL_EXTERNAL : 0; |
Suchi Amalapurapu | 6069beb | 2010-03-10 09:46:49 -0800 | [diff] [blame] | 9659 | currFlags = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0 ? |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9660 | PackageManager.INSTALL_EXTERNAL : 0; |
| 9661 | if (newFlags == currFlags) { |
Dianne Hackborn | a2fd9d1 | 2010-03-11 23:40:24 -0800 | [diff] [blame] | 9662 | Slog.w(TAG, "No move required. Trying to move to same location"); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9663 | returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION; |
| 9664 | } |
| 9665 | } |
| 9666 | } |
| 9667 | if (returnCode != PackageManager.MOVE_SUCCEEDED) { |
| 9668 | processPendingMove(new MoveParams(null, observer, 0, null), returnCode); |
| 9669 | } else { |
| 9670 | Message msg = mHandler.obtainMessage(INIT_COPY); |
| 9671 | InstallArgs srcArgs = createInstallArgs(currFlags, pkg.applicationInfo.sourceDir, |
| 9672 | pkg.applicationInfo.publicSourceDir); |
| 9673 | MoveParams mp = new MoveParams(srcArgs, observer, newFlags, |
| 9674 | packageName); |
| 9675 | msg.obj = mp; |
| 9676 | mHandler.sendMessage(msg); |
| 9677 | } |
| 9678 | } |
| 9679 | } |
| 9680 | |
| 9681 | private void processPendingMove(final MoveParams mp, final int currentStatus) { |
| 9682 | // Queue up an async operation since the package deletion may take a little while. |
| 9683 | mHandler.post(new Runnable() { |
| 9684 | public void run() { |
| 9685 | mHandler.removeCallbacks(this); |
| 9686 | int returnCode = currentStatus; |
| 9687 | boolean moveSucceeded = (returnCode == PackageManager.MOVE_SUCCEEDED); |
| 9688 | if (moveSucceeded) { |
| 9689 | int uid = -1; |
| 9690 | synchronized (mPackages) { |
| 9691 | uid = mPackages.get(mp.packageName).applicationInfo.uid; |
| 9692 | } |
| 9693 | ArrayList<String> pkgList = new ArrayList<String>(); |
| 9694 | pkgList.add(mp.packageName); |
| 9695 | int uidArr[] = new int[] { uid }; |
| 9696 | // Send resources unavailable broadcast |
| 9697 | sendResourcesChangedBroadcast(false, pkgList, uidArr); |
| 9698 | |
| 9699 | // Update package code and resource paths |
| 9700 | synchronized (mPackages) { |
| 9701 | PackageParser.Package pkg = mPackages.get(mp.packageName); |
| 9702 | if (pkg != null) { |
| 9703 | String oldCodePath = pkg.mPath; |
| 9704 | String newCodePath = mp.targetArgs.getCodePath(); |
| 9705 | String newResPath = mp.targetArgs.getResourcePath(); |
| 9706 | pkg.mPath = newCodePath; |
| 9707 | // Move dex files around |
| 9708 | if (moveDexFiles(pkg) |
| 9709 | != PackageManager.INSTALL_SUCCEEDED) { |
| 9710 | // Moving of dex files failed. Set |
| 9711 | // error code and abort move. |
| 9712 | pkg.mPath = pkg.mScanPath; |
| 9713 | returnCode = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE; |
| 9714 | moveSucceeded = false; |
| 9715 | } else { |
| 9716 | pkg.mScanPath = newCodePath; |
| 9717 | pkg.applicationInfo.sourceDir = newCodePath; |
| 9718 | pkg.applicationInfo.publicSourceDir = newResPath; |
| 9719 | PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 9720 | ps.codePath = new File(pkg.applicationInfo.sourceDir); |
| 9721 | ps.codePathString = ps.codePath.getPath(); |
| 9722 | ps.resourcePath = new File(pkg.applicationInfo.publicSourceDir); |
| 9723 | ps.resourcePathString = ps.resourcePath.getPath(); |
| 9724 | // Set the application info flag correctly. |
| 9725 | if ((mp.flags & PackageManager.INSTALL_EXTERNAL) != 0) { |
Suchi Amalapurapu | 6069beb | 2010-03-10 09:46:49 -0800 | [diff] [blame] | 9726 | pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9727 | } else { |
Suchi Amalapurapu | 6069beb | 2010-03-10 09:46:49 -0800 | [diff] [blame] | 9728 | pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_EXTERNAL_STORAGE; |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9729 | } |
| 9730 | ps.setFlags(pkg.applicationInfo.flags); |
| 9731 | mAppDirs.remove(oldCodePath); |
| 9732 | mAppDirs.put(newCodePath, pkg); |
| 9733 | // Persist settings |
| 9734 | mSettings.writeLP(); |
| 9735 | } |
| 9736 | } |
| 9737 | } |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9738 | // Send resources available broadcast |
| 9739 | sendResourcesChangedBroadcast(true, pkgList, uidArr); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9740 | } |
| 9741 | if (!moveSucceeded){ |
| 9742 | // Clean up failed installation |
| 9743 | if (mp.targetArgs != null) { |
| 9744 | mp.targetArgs.doPostInstall( |
Suchi Amalapurapu | 9b10ef5 | 2010-03-03 09:45:24 -0800 | [diff] [blame] | 9745 | returnCode); |
| 9746 | } |
| 9747 | } else { |
| 9748 | // Force a gc to clear things up. |
| 9749 | Runtime.getRuntime().gc(); |
| 9750 | // Delete older code |
| 9751 | synchronized (mInstallLock) { |
| 9752 | mp.srcArgs.doPostDeleteLI(true); |
Suchi Amalapurapu | 8946dd3 | 2010-02-19 09:19:34 -0800 | [diff] [blame] | 9753 | } |
| 9754 | } |
| 9755 | IPackageMoveObserver observer = mp.observer; |
| 9756 | if (observer != null) { |
| 9757 | try { |
| 9758 | observer.packageMoved(mp.packageName, returnCode); |
| 9759 | } catch (RemoteException e) { |
| 9760 | Log.i(TAG, "Observer no longer exists."); |
| 9761 | } |
| 9762 | } |
| 9763 | } |
| 9764 | }); |
| 9765 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9766 | } |